activitysmith-cli 1.0.0 → 1.3.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 (3) hide show
  1. package/README.md +438 -28
  2. package/package.json +3 -3
  3. package/src/cli.js +299 -7
package/README.md CHANGED
@@ -2,6 +2,29 @@
2
2
 
3
3
  CLI wrapper for the ActivitySmith API using the official Node SDK.
4
4
 
5
+ ## Table of Contents
6
+
7
+ - [Install](#install)
8
+ - [Install Skill (Codex/Claude/Other Skills-Compatible Agents)](#install-skill-codexclaudeother-skills-compatible-agents)
9
+ - [Auth](#auth)
10
+ - [Push Notifications](#push-notifications)
11
+ - [Send Push Notification](#send-push-notification)
12
+ - [Rich Push Notifications with Media](#rich-push-notifications-with-media)
13
+ - [Actionable Push Notifications](#actionable-push-notifications)
14
+ - [Live Activities](#live-activities)
15
+ - [Simple: Let ActivitySmith manage the Live Activity for you](#simple-let-activitysmith-manage-the-live-activity-for-you)
16
+ - [Advanced: Full lifecycle control](#advanced-full-lifecycle-control)
17
+ - [Stats](#stats)
18
+ - [Metrics](#metrics)
19
+ - [Segmented Progress](#segmented-progress)
20
+ - [Progress](#progress)
21
+ - [Live Activity Action](#live-activity-action)
22
+ - [Channels](#channels)
23
+ - [Widgets](#widgets)
24
+ - [Aliases](#aliases)
25
+ - [Content State Options](#content-state-options)
26
+ - [Output](#output)
27
+
5
28
  ## Install
6
29
 
7
30
  ```bash
@@ -85,7 +108,24 @@ activitysmith push \
85
108
  --title "Build Failed 🚨" \
86
109
  --message "CI pipeline failed on main branch" \
87
110
  --redirection "https://github.com/org/repo/actions/runs/123456789" \
88
- --actions '[{"title":"Open Failing Run","type":"open_url","url":"https://github.com/org/repo/actions/runs/123456789"},{"title":"Create Incident","type":"webhook","url":"https://hooks.example.com/incidents/create","method":"POST","body":{"service":"payments-api","severity":"high","source":"activitysmith-cli"}}]'
111
+ --actions '[
112
+ {
113
+ "title": "Open Failing Run",
114
+ "type": "open_url",
115
+ "url": "https://github.com/org/repo/actions/runs/123456789"
116
+ },
117
+ {
118
+ "title": "Create Incident",
119
+ "type": "webhook",
120
+ "url": "https://hooks.example.com/incidents/create",
121
+ "method": "POST",
122
+ "body": {
123
+ "service": "payments-api",
124
+ "severity": "high",
125
+ "source": "activitysmith-cli"
126
+ }
127
+ }
128
+ ]'
89
129
  ```
90
130
 
91
131
  You can also load actions from a file:
@@ -99,14 +139,151 @@ activitysmith push \
99
139
 
100
140
  ## Live Activities
101
141
 
102
- Live Activities come in two UI types, but the lifecycle stays the same:
103
- start the activity, keep the returned `activity_id`, update it as state
104
- changes, then end it when the work is done.
142
+ <p align="center">
143
+ <img src="https://cdn.activitysmith.com/features/metrics-live-activity-action.png" alt="Metrics Live Activity screenshot" width="680" />
144
+ </p>
145
+
146
+ There are four types of Live Activities:
147
+
148
+ - `stats`: best for compact business or product stats like revenue, orders, conversion, and average order value
149
+ - `metrics`: best for live operational stats like server CPU and memory, queue depth, or replica lag
150
+ - `segmented_progress`: best for step-based workflows like deployments, backups, and ETL pipelines
151
+ - `progress`: best for continuous jobs like uploads, reindexes, and long-running migrations tracked as a percentage
152
+
153
+ When working with Live Activities via our API, you have two approaches tailored
154
+ to different needs. First, the stateless mode is the simplest path - one API
155
+ call can initiate or update an activity, and another ends it - no state
156
+ tracking on your side.
157
+
158
+ This is ideal if you want minimal complexity, perfect for automated workflows
159
+ like cron jobs.
160
+
161
+ In contrast, if you need precise lifecycle control, the classic approach offers
162
+ distinct calls for start, updates, and end, giving you full control over the
163
+ activity's state.
164
+
165
+ In the following sections, we'll break down how to implement each method so you
166
+ can choose what fits your use case best.
105
167
 
106
- - `segmented_progress`: best for jobs tracked in steps
107
- - `progress`: best for jobs tracked as a percentage or numeric range
168
+ ### Simple: Let ActivitySmith manage the Live Activity for you
169
+
170
+ Use a stable `stream_key` to identify the system or workflow you are tracking,
171
+ such as a server, deployment, build pipeline, cron job, or charging session.
172
+ This is especially useful for cron jobs and other scheduled tasks where you do
173
+ not want to store `activity_id` between runs.
174
+
175
+ #### Stats
176
+
177
+ <p align="center">
178
+ <img src="https://cdn.activitysmith.com/features/stats-live-activity.png" alt="Stats stream example" width="680" />
179
+ </p>
180
+
181
+ ```bash
182
+ activitysmith activity stream sales-hourly \
183
+ --content-state '{
184
+ "title": "Sales",
185
+ "subtitle": "last hour",
186
+ "type": "stats",
187
+ "metrics": [
188
+ { "label": "Revenue", "value": "$2430", "color": "blue" },
189
+ { "label": "Orders", "value": "37", "color": "green" },
190
+ { "label": "Conversion", "value": "4.8%", "color": "magenta" },
191
+ { "label": "Avg Order", "value": "$65.68", "color": "yellow" },
192
+ { "label": "Refunds", "value": "$84", "color": "red" },
193
+ { "label": "New Buyers", "value": "18", "color": "cyan" }
194
+ ]
195
+ }'
196
+ ```
108
197
 
109
- ### Shared flow
198
+ #### Metrics
199
+
200
+ <p align="center">
201
+ <img src="https://cdn.activitysmith.com/features/metrics-live-activity-start.png" alt="Metrics stream example" width="680" />
202
+ </p>
203
+
204
+ ```bash
205
+ activitysmith activity stream prod-web-1 \
206
+ --content-state '{
207
+ "title": "Server Health",
208
+ "subtitle": "prod-web-1",
209
+ "type": "metrics",
210
+ "metrics": [
211
+ { "label": "CPU", "value": 9, "unit": "%" },
212
+ { "label": "MEM", "value": 45, "unit": "%" }
213
+ ]
214
+ }'
215
+ ```
216
+
217
+ #### Segmented progress
218
+
219
+ <p align="center">
220
+ <img src="https://cdn.activitysmith.com/features/update-live-activity.png" alt="Segmented progress stream example" width="680" />
221
+ </p>
222
+
223
+ ```bash
224
+ activitysmith activity stream nightly-backup \
225
+ --content-state '{
226
+ "title": "Nightly Backup",
227
+ "subtitle": "upload archive",
228
+ "type": "segmented_progress",
229
+ "numberOfSteps": 3,
230
+ "currentStep": 2
231
+ }'
232
+ ```
233
+
234
+ #### Progress
235
+
236
+ <p align="center">
237
+ <img src="https://cdn.activitysmith.com/features/progress-live-activity.png" alt="Progress stream example" width="680" />
238
+ </p>
239
+
240
+ ```bash
241
+ activitysmith activity stream search-reindex \
242
+ --content-state '{
243
+ "title": "Search Reindex",
244
+ "subtitle": "catalog-v2",
245
+ "type": "progress",
246
+ "percentage": 42
247
+ }'
248
+ ```
249
+
250
+ Run `activitysmith activity stream <stream-key> ...` again with the same
251
+ `stream_key` whenever the state changes.
252
+
253
+ #### End a stream
254
+
255
+ Use this when the tracked process is finished and you no longer want the Live
256
+ Activity on devices. `content_state` is optional here; include it if you want
257
+ to end the stream with a final state.
258
+
259
+ ```bash
260
+ activitysmith activity end-stream prod-web-1 \
261
+ --content-state '{
262
+ "title": "Server Health",
263
+ "subtitle": "prod-web-1",
264
+ "type": "metrics",
265
+ "metrics": [
266
+ { "label": "CPU", "value": 7, "unit": "%" },
267
+ { "label": "MEM", "value": 38, "unit": "%" }
268
+ ]
269
+ }'
270
+ ```
271
+
272
+ If you later send another `activity stream` request with the same `stream_key`,
273
+ ActivitySmith starts a new Live Activity for that stream again.
274
+
275
+ Stream responses include an `operation` field:
276
+
277
+ - `started`: ActivitySmith started a new Live Activity for this `stream_key`
278
+ - `updated`: ActivitySmith updated the current Live Activity
279
+ - `rotated`: ActivitySmith ended the previous Live Activity and started a new one
280
+ - `noop`: the incoming state matched the current state, so no update was sent
281
+ - `paused`: the stream is paused, so no Live Activity was started or updated
282
+ - `ended`: returned by `activity end-stream` after the stream is ended
283
+
284
+ ### Advanced: Full lifecycle control
285
+
286
+ Use these commands when you want to manage the Live Activity lifecycle yourself:
110
287
 
111
288
  1. Run `activitysmith activity start ...`.
112
289
  2. Save the returned `activity_id`.
@@ -116,11 +293,147 @@ changes, then end it when the work is done.
116
293
  You can use `--content-state <json>` for the examples below, or build the same
117
294
  payload with flags as documented in `Content State Options`.
118
295
 
296
+ ### Stats
297
+
298
+ Keep your key numbers on your Lock Screen. `stats` fits up to 8 labeled values,
299
+ such as revenue, orders, conversion, uptime, or any other business metric you
300
+ want visible at a glance. Each metric can use a formatted string or number as
301
+ its `value`. Add `color` to a metric to show an accent dot next to its label;
302
+ omit `color` to show the label without a dot.
303
+
304
+ #### Start
305
+
306
+ <p align="center">
307
+ <img src="https://cdn.activitysmith.com/features/stats-live-activity.png" alt="Stats Live Activity with sales revenue, orders, conversion, and average order value" width="680" />
308
+ </p>
309
+
310
+ ```bash
311
+ activitysmith activity start \
312
+ --content-state '{
313
+ "title": "Sales",
314
+ "subtitle": "last hour",
315
+ "type": "stats",
316
+ "metrics": [
317
+ { "label": "Revenue", "value": "$2430", "color": "blue" },
318
+ { "label": "Orders", "value": "37", "color": "green" },
319
+ { "label": "Conversion", "value": "4.8%", "color": "magenta" },
320
+ { "label": "Avg Order", "value": "$65.68", "color": "yellow" },
321
+ { "label": "Refunds", "value": "$84", "color": "red" },
322
+ { "label": "New Buyers", "value": "18", "color": "cyan" }
323
+ ]
324
+ }'
325
+ ```
326
+
327
+ #### Update
328
+
329
+ ```bash
330
+ activitysmith activity update \
331
+ --activity-id "<activityId>" \
332
+ --content-state '{
333
+ "title": "Sales",
334
+ "subtitle": "last hour",
335
+ "type": "stats",
336
+ "metrics": [
337
+ { "label": "Revenue", "value": "$3180", "color": "blue" },
338
+ { "label": "Orders", "value": "51", "color": "green" },
339
+ { "label": "Conversion", "value": "5.2%", "color": "magenta" },
340
+ { "label": "Avg Order", "value": "$62.35", "color": "yellow" },
341
+ { "label": "Refunds", "value": "$126", "color": "red" },
342
+ { "label": "New Buyers", "value": "24", "color": "cyan" }
343
+ ]
344
+ }'
345
+ ```
346
+
347
+ #### End
348
+
349
+ ```bash
350
+ activitysmith activity end \
351
+ --activity-id "<activityId>" \
352
+ --content-state '{
353
+ "title": "Sales",
354
+ "subtitle": "last hour",
355
+ "type": "stats",
356
+ "metrics": [
357
+ { "label": "Revenue", "value": "$3460", "color": "blue" },
358
+ { "label": "Orders", "value": "58", "color": "green" },
359
+ { "label": "Conversion", "value": "5.4%", "color": "magenta" },
360
+ { "label": "Avg Order", "value": "$59.66", "color": "yellow" },
361
+ { "label": "Refunds", "value": "$92", "color": "red" },
362
+ { "label": "New Buyers", "value": "31", "color": "cyan" }
363
+ ],
364
+ "autoDismissMinutes": 2
365
+ }'
366
+ ```
367
+
368
+ ### Metrics Type
369
+
370
+ Use `metrics` when you want to keep a small set of live stats visible, such as
371
+ server health, queue pressure, or database load.
372
+
373
+ #### Start
374
+
375
+ <p align="center">
376
+ <img src="https://cdn.activitysmith.com/features/metrics-live-activity-start.png" alt="Metrics start example" width="680" />
377
+ </p>
378
+
379
+ ```bash
380
+ activitysmith activity start \
381
+ --content-state '{
382
+ "title": "Server Health",
383
+ "subtitle": "prod-web-1",
384
+ "type": "metrics",
385
+ "metrics": [
386
+ { "label": "CPU", "value": 9, "unit": "%" },
387
+ { "label": "MEM", "value": 45, "unit": "%" }
388
+ ]
389
+ }'
390
+ ```
391
+
392
+ #### Update
393
+
394
+ <p align="center">
395
+ <img src="https://cdn.activitysmith.com/features/metrics-live-activity-update.png" alt="Metrics update example" width="680" />
396
+ </p>
397
+
398
+ ```bash
399
+ activitysmith activity update \
400
+ --activity-id "<activityId>" \
401
+ --content-state '{
402
+ "title": "Server Health",
403
+ "subtitle": "prod-web-1",
404
+ "type": "metrics",
405
+ "metrics": [
406
+ { "label": "CPU", "value": 76, "unit": "%" },
407
+ { "label": "MEM", "value": 52, "unit": "%" }
408
+ ]
409
+ }'
410
+ ```
411
+
412
+ #### End
413
+
414
+ <p align="center">
415
+ <img src="https://cdn.activitysmith.com/features/metrics-live-activity-end.png" alt="Metrics end example" width="680" />
416
+ </p>
417
+
418
+ ```bash
419
+ activitysmith activity end \
420
+ --activity-id "<activityId>" \
421
+ --content-state '{
422
+ "title": "Server Health",
423
+ "subtitle": "prod-web-1",
424
+ "type": "metrics",
425
+ "metrics": [
426
+ { "label": "CPU", "value": 7, "unit": "%" },
427
+ { "label": "MEM", "value": 38, "unit": "%" }
428
+ ],
429
+ "autoDismissMinutes": 2
430
+ }'
431
+ ```
432
+
119
433
  ### Segmented Progress Type
120
434
 
121
- Use `segmented_progress` when progress is easier to follow as steps instead of a
122
- raw percentage. It fits jobs like deployments, backups, ETL pipelines, and
123
- checklists where "step 2 of 3" is more useful than "67%".
435
+ Use `segmented_progress` for jobs and workflows that move through clear steps or
436
+ phases. It fits jobs like deployments, backups, ETL pipelines, and checklists.
124
437
  `numberOfSteps` is dynamic, so you can increase or decrease it later if the
125
438
  workflow changes.
126
439
 
@@ -132,8 +445,14 @@ workflow changes.
132
445
 
133
446
  ```bash
134
447
  activitysmith activity start \
135
- --content-state '{"title":"Nightly database backup","subtitle":"create snapshot","numberOfSteps":3,"currentStep":1,"type":"segmented_progress","color":"yellow"}' \
136
- --channels "devs,ops"
448
+ --content-state '{
449
+ "title": "Nightly database backup",
450
+ "subtitle": "create snapshot",
451
+ "numberOfSteps": 3,
452
+ "currentStep": 1,
453
+ "type": "segmented_progress",
454
+ "color": "yellow"
455
+ }'
137
456
  ```
138
457
 
139
458
  #### Update
@@ -145,7 +464,12 @@ activitysmith activity start \
145
464
  ```bash
146
465
  activitysmith activity update \
147
466
  --activity-id "<activityId>" \
148
- --content-state '{"title":"Nightly database backup","subtitle":"upload archive","numberOfSteps":4,"currentStep":2}'
467
+ --content-state '{
468
+ "title": "Nightly database backup",
469
+ "subtitle": "upload archive",
470
+ "numberOfSteps": 3,
471
+ "currentStep": 2
472
+ }'
149
473
  ```
150
474
 
151
475
  #### End
@@ -157,7 +481,13 @@ activitysmith activity update \
157
481
  ```bash
158
482
  activitysmith activity end \
159
483
  --activity-id "<activityId>" \
160
- --content-state '{"title":"Nightly database backup","subtitle":"verify restore","numberOfSteps":4,"currentStep":4,"autoDismissMinutes":2}'
484
+ --content-state '{
485
+ "title": "Nightly database backup",
486
+ "subtitle": "verify restore",
487
+ "numberOfSteps": 3,
488
+ "currentStep": 3,
489
+ "autoDismissMinutes": 2
490
+ }'
161
491
  ```
162
492
 
163
493
  ### Progress Type
@@ -174,7 +504,12 @@ numeric range is the clearest signal.
174
504
 
175
505
  ```bash
176
506
  activitysmith activity start \
177
- --content-state '{"title":"EV Charging","subtitle":"Added 30 mi range","percentage":15,"type":"progress","color":"lime"}'
507
+ --content-state '{
508
+ "title": "EV Charging",
509
+ "subtitle": "Added 30 mi range",
510
+ "type": "progress",
511
+ "percentage": 15
512
+ }'
178
513
  ```
179
514
 
180
515
  #### Update
@@ -186,7 +521,11 @@ activitysmith activity start \
186
521
  ```bash
187
522
  activitysmith activity update \
188
523
  --activity-id "<activityId>" \
189
- --content-state '{"title":"EV Charging","subtitle":"Added 120 mi range","percentage":60}'
524
+ --content-state '{
525
+ "title": "EV Charging",
526
+ "subtitle": "Added 120 mi range",
527
+ "percentage": 60
528
+ }'
190
529
  ```
191
530
 
192
531
  #### End
@@ -198,7 +537,12 @@ activitysmith activity update \
198
537
  ```bash
199
538
  activitysmith activity end \
200
539
  --activity-id "<activityId>" \
201
- --content-state '{"title":"EV Charging","subtitle":"Added 200 mi range","percentage":100,"autoDismissMinutes":2}'
540
+ --content-state '{
541
+ "title": "EV Charging",
542
+ "subtitle": "Added 200 mi range",
543
+ "percentage": 100,
544
+ "autoDismissMinutes": 2
545
+ }'
202
546
  ```
203
547
 
204
548
  ### Live Activity Action
@@ -206,24 +550,54 @@ activitysmith activity end \
206
550
  Just like Actionable Push Notifications, Live Activities can have a button that opens provided URL in a browser or triggers a webhook. Webhooks are executed by the ActivitySmith backend.
207
551
 
208
552
  <p align="center">
209
- <img src="https://cdn.activitysmith.com/features/live-activity-with-action.png?v=20260319-1" alt="Live Activity with action" width="680" />
553
+ <img src="https://cdn.activitysmith.com/features/metrics-live-activity-action.png" alt="Metrics Live Activity with action" width="680" />
210
554
  </p>
211
555
 
212
556
  #### Open URL action
213
557
 
214
558
  ```bash
215
559
  activitysmith activity start \
216
- --content-state '{"title":"Deploying payments-api","subtitle":"Running database migrations","numberOfSteps":5,"currentStep":3,"type":"segmented_progress"}' \
217
- --action '{"title":"Open Workflow","type":"open_url","url":"https://github.com/acme/payments-api/actions/runs/1234567890"}'
560
+ --content-state '{
561
+ "title": "Server Health",
562
+ "subtitle": "prod-web-1",
563
+ "type": "metrics",
564
+ "metrics": [
565
+ { "label": "CPU", "value": 76, "unit": "%" },
566
+ { "label": "MEM", "value": 52, "unit": "%" }
567
+ ]
568
+ }' \
569
+ --action '{
570
+ "title": "Open Dashboard",
571
+ "type": "open_url",
572
+ "url": "https://ops.example.com/servers/prod-web-1"
573
+ }'
218
574
  ```
219
575
 
220
576
  #### Webhook action
221
577
 
578
+ <p align="center">
579
+ <img src="https://cdn.activitysmith.com/features/live-activity-with-action.png?v=20260319-1" alt="Live Activity with action" width="680" />
580
+ </p>
581
+
222
582
  ```bash
223
583
  activitysmith activity update \
224
584
  --activity-id "<activityId>" \
225
- --content-state '{"title":"Reindexing product search","subtitle":"Shard 7 of 12","numberOfSteps":12,"currentStep":7}' \
226
- --action '{"title":"Pause Reindex","type":"webhook","url":"https://ops.example.com/hooks/search/reindex/pause","method":"POST","body":{"job_id":"reindex-2026-03-19","requested_by":"activitysmith-cli"}}'
585
+ --content-state '{
586
+ "title": "Reindexing product search",
587
+ "subtitle": "Shard 7 of 12",
588
+ "numberOfSteps": 12,
589
+ "currentStep": 7
590
+ }' \
591
+ --action '{
592
+ "title": "Pause Reindex",
593
+ "type": "webhook",
594
+ "url": "https://ops.example.com/hooks/search/reindex/pause",
595
+ "method": "POST",
596
+ "body": {
597
+ "job_id": "reindex-2026-03-19",
598
+ "requested_by": "activitysmith-cli"
599
+ }
600
+ }'
227
601
  ```
228
602
 
229
603
  ## Channels
@@ -237,6 +611,30 @@ activitysmith push \
237
611
  --channels "devs,ops"
238
612
  ```
239
613
 
614
+ ## Widgets
615
+
616
+ <p align="center">
617
+ <img src="https://cdn.activitysmith.com/features/lock-screen-widgets.png" alt="Lock screen widgets" width="680" />
618
+ </p>
619
+
620
+ ActivitySmith lets you display any value on your Lock Screen with widgets - SaaS metrics, revenue, signups, uptime, habits, or anything else you want to track. Create a metric in the <a href="https://activitysmith.com/app/widgets" target="_blank" rel="noopener noreferrer">web app</a>, then update the metric value using our API, add a widget to your lock screen and it will fetch the latest update automatically.
621
+
622
+ <p align="center">
623
+ <img src="https://cdn.activitysmith.com/features/create-widget-metric.png" alt="Create widget metric" width="680" />
624
+ </p>
625
+
626
+ Use the metric key to update its value.
627
+
628
+ ```bash
629
+ activitysmith metrics update deploy.success_rate 99.9
630
+ ```
631
+
632
+ String metric values work too.
633
+
634
+ ```bash
635
+ activitysmith metrics update prod.status healthy
636
+ ```
637
+
240
638
  ## Aliases
241
639
 
242
640
  The CLI installs two bin names:
@@ -246,12 +644,17 @@ The CLI installs two bin names:
246
644
 
247
645
  ## Content State Options
248
646
 
249
- For `activity start|update|end`, you can pass content state via JSON:
647
+ For `activity stream|start|update|end|end-stream`, you can pass content state via JSON:
250
648
 
251
649
  - `--content-state <json>`
252
650
  - `--content-state-file <path>`
253
651
 
254
- Or use flags to build the payload:
652
+ For `metrics` and `stats`, you can also pass the metrics array directly:
653
+
654
+ - `--metrics <json-array>`
655
+ - `--metrics-file <path>`
656
+
657
+ Or use flags to build the rest of the payload:
255
658
 
256
659
  - `--title <title>`
257
660
  - `--subtitle <subtitle>`
@@ -272,13 +675,20 @@ Live Activity action options:
272
675
 
273
676
  Targeting options:
274
677
 
275
- - `--channels <comma-separated-slugs>` (for `push` and `activity start`)
678
+ - `--channels <comma-separated-slugs>` (for `push`, `activity stream`, and `activity start`)
679
+
680
+ Widget metric options:
681
+
682
+ - `activitysmith metrics update <metric-key> <value>`
683
+ - `activitysmith metric update <metric-key> <value>` (alias)
276
684
 
277
685
  Required fields:
278
686
 
279
- - `activity start`: `--title`, `--type`, plus either `--number-of-steps` and `--current-step`, or `--percentage`, or `--value` with `--upper-limit`
280
- - `activity update`: `--title`, plus either `--current-step`, or `--percentage`, or `--value` with `--upper-limit`
281
- - `activity end`: `--title`, plus either `--current-step`, or `--percentage`, or `--value` with `--upper-limit`
687
+ - `activity stream`: `--title`, `--type`, plus `--metrics`, `--number-of-steps` and `--current-step`, `--percentage`, or `--value` with `--upper-limit`
688
+ - `activity start`: `--title`, `--type`, plus `--metrics`, `--number-of-steps` and `--current-step`, `--percentage`, or `--value` with `--upper-limit`
689
+ - `activity update`: `--title`, plus `--metrics`, `--current-step`, `--percentage`, or `--value` with `--upper-limit`
690
+ - `activity end`: `--title`, plus `--metrics`, `--current-step`, `--percentage`, or `--value` with `--upper-limit`
691
+ - `activity end-stream`: no content state is required, but if you provide one it follows the same rules as `activity end`
282
692
 
283
693
  ## Output
284
694
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "activitysmith-cli",
3
- "version": "1.0.0",
4
- "description": "Command-line interface for ActivitySmith. Send push notifications, start, update and end live activities directly from your terminal.",
3
+ "version": "1.3.0",
4
+ "description": "Command-line interface for ActivitySmith. Send push notifications and manage Live Activities from your terminal.",
5
5
  "keywords": [
6
6
  "activitysmith",
7
7
  "live-activities",
@@ -40,7 +40,7 @@
40
40
  "lint": "node --check src/cli.js"
41
41
  },
42
42
  "dependencies": {
43
- "activitysmith": "^1.0.0",
43
+ "activitysmith": "^1.3.0",
44
44
  "commander": "^12.1.0"
45
45
  }
46
46
  }
package/src/cli.js CHANGED
@@ -54,6 +54,30 @@ const parseChannelsOption = (value) => {
54
54
  return channels;
55
55
  };
56
56
 
57
+ const parseMetricValueArgument = (value) => {
58
+ if (typeof value !== "string") {
59
+ throw new InvalidArgumentError("value must be a string or number");
60
+ }
61
+
62
+ const trimmed = value.trim();
63
+ if (trimmed.length === 0) {
64
+ throw new InvalidArgumentError("value cannot be empty");
65
+ }
66
+
67
+ try {
68
+ const parsed = JSON.parse(trimmed);
69
+ if (typeof parsed === "string" || typeof parsed === "number") {
70
+ return parsed;
71
+ }
72
+ throw new InvalidArgumentError("value must be a string or number");
73
+ } catch (error) {
74
+ if (error instanceof InvalidArgumentError) {
75
+ throw error;
76
+ }
77
+ return value;
78
+ }
79
+ };
80
+
57
81
  const normalizeHttpsUrl = (value, label) => {
58
82
  if (typeof value !== "string" || value.trim().length === 0) {
59
83
  throw new Error(`${label} must be a non-empty string`);
@@ -77,6 +101,8 @@ const addContentStateOptions = (command, { includeAutoDismiss } = {}) => {
77
101
  command
78
102
  .option("--content-state <json>", "Content state as JSON string")
79
103
  .option("--content-state-file <path>", "Content state JSON file path")
104
+ .option("--metrics <json>", "Content state metrics as JSON array")
105
+ .option("--metrics-file <path>", "Content state metrics JSON file path")
80
106
  .option("--title <title>", "Content state title")
81
107
  .option("--subtitle <subtitle>", "Content state subtitle")
82
108
  .option("--type <type>", "Content state type")
@@ -210,6 +236,18 @@ const isNonEmptyString = (value) =>
210
236
  const hasOwn = (object, key) =>
211
237
  Object.prototype.hasOwnProperty.call(object, key);
212
238
 
239
+ const liveActivityMetricColors = new Set([
240
+ "blue",
241
+ "cyan",
242
+ "green",
243
+ "lime",
244
+ "magenta",
245
+ "orange",
246
+ "purple",
247
+ "red",
248
+ "yellow",
249
+ ]);
250
+
213
251
  const validateContentState = (contentState, mode) => {
214
252
  const normalizedType =
215
253
  typeof contentState.type === "string" ? contentState.type.trim() : undefined;
@@ -221,10 +259,12 @@ const validateContentState = (contentState, mode) => {
221
259
  if (
222
260
  normalizedType !== undefined &&
223
261
  normalizedType !== "segmented_progress" &&
224
- normalizedType !== "progress"
262
+ normalizedType !== "progress" &&
263
+ normalizedType !== "metrics" &&
264
+ normalizedType !== "stats"
225
265
  ) {
226
266
  throw new Error(
227
- "contentState.type must be one of: segmented_progress, progress"
267
+ "contentState.type must be one of: segmented_progress, progress, metrics, stats"
228
268
  );
229
269
  }
230
270
 
@@ -234,6 +274,7 @@ const validateContentState = (contentState, mode) => {
234
274
  const hasValue = hasOwn(contentState, "value");
235
275
  const hasUpperLimit = hasOwn(contentState, "upperLimit");
236
276
  const hasStepColor = hasOwn(contentState, "stepColor");
277
+ const hasMetrics = hasOwn(contentState, "metrics");
237
278
 
238
279
  if (hasValue !== hasUpperLimit) {
239
280
  throw new Error(
@@ -269,11 +310,60 @@ const validateContentState = (contentState, mode) => {
269
310
  );
270
311
  }
271
312
 
313
+ if (hasMetrics && (hasSegmentedFields || hasProgressFields)) {
314
+ throw new Error(
315
+ "Do not mix metrics fields with segmented_progress or progress fields in the same contentState"
316
+ );
317
+ }
318
+
319
+ if (hasMetrics) {
320
+ if (!Array.isArray(contentState.metrics) || contentState.metrics.length === 0) {
321
+ throw new Error("contentState.metrics must be a non-empty array");
322
+ }
323
+
324
+ if (normalizedType === "stats" && contentState.metrics.length > 8) {
325
+ throw new Error("stats contentState.metrics supports up to 8 items");
326
+ }
327
+
328
+ contentState.metrics.forEach((metric, index) => {
329
+ assertPlainObject(metric, `contentState.metrics[${index}]`);
330
+ if (!isNonEmptyString(metric.label)) {
331
+ throw new Error(`contentState.metrics[${index}].label is required`);
332
+ }
333
+ if (normalizedType === "stats") {
334
+ if (!Number.isFinite(metric.value) && !isNonEmptyString(metric.value)) {
335
+ throw new Error(
336
+ `contentState.metrics[${index}].value must be a number or non-empty string`
337
+ );
338
+ }
339
+ } else if (!Number.isFinite(metric.value)) {
340
+ throw new Error(
341
+ `contentState.metrics[${index}].value must be a number. Use contentState.type=stats for string values`
342
+ );
343
+ }
344
+ if (metric.unit !== undefined && typeof metric.unit !== "string") {
345
+ throw new Error(`contentState.metrics[${index}].unit must be a string`);
346
+ }
347
+ if (metric.color !== undefined) {
348
+ if (!isNonEmptyString(metric.color)) {
349
+ throw new Error(`contentState.metrics[${index}].color must be a string`);
350
+ }
351
+ if (!liveActivityMetricColors.has(metric.color.trim())) {
352
+ throw new Error(
353
+ `contentState.metrics[${index}].color must be one of: ${[
354
+ ...liveActivityMetricColors,
355
+ ].join(", ")}`
356
+ );
357
+ }
358
+ }
359
+ });
360
+ }
361
+
272
362
  const effectiveType = normalizedType;
273
363
 
274
- if (mode === "start") {
364
+ if (mode === "start" || mode === "stream") {
275
365
  if (!effectiveType) {
276
- throw new Error("contentState.type is required for activity start");
366
+ throw new Error(`contentState.type is required for activity ${mode}`);
277
367
  }
278
368
 
279
369
  if (effectiveType === "segmented_progress") {
@@ -285,9 +375,16 @@ const validateContentState = (contentState, mode) => {
285
375
  return;
286
376
  }
287
377
 
378
+ if (effectiveType === "metrics" || effectiveType === "stats") {
379
+ if (!hasMetrics) {
380
+ throw new Error(`${effectiveType} ${mode} requires contentState.metrics`);
381
+ }
382
+ return;
383
+ }
384
+
288
385
  if (!hasPercentage && !hasValue) {
289
386
  throw new Error(
290
- "progress start requires contentState.percentage, or contentState.value with contentState.upperLimit"
387
+ `progress ${mode} requires contentState.percentage, or contentState.value with contentState.upperLimit`
291
388
  );
292
389
  }
293
390
  return;
@@ -311,12 +408,23 @@ const validateContentState = (contentState, mode) => {
311
408
  return;
312
409
  }
313
410
 
314
- if (!hasSegmentedFields && !hasProgressFields) {
411
+ if (effectiveType === "metrics" || effectiveType === "stats") {
412
+ if (!hasMetrics) {
413
+ throw new Error(`${effectiveType} ${mode} requires contentState.metrics`);
414
+ }
415
+ return;
416
+ }
417
+
418
+ if (!hasSegmentedFields && !hasProgressFields && !hasMetrics) {
315
419
  throw new Error(
316
- `contentState for activity ${mode} must include either segmented_progress fields or progress fields`
420
+ `contentState for activity ${mode} must include metrics, segmented_progress fields, or progress fields`
317
421
  );
318
422
  }
319
423
 
424
+ if (hasMetrics) {
425
+ return;
426
+ }
427
+
320
428
  if (hasSegmentedFields && !hasCurrentStep) {
321
429
  throw new Error(
322
430
  `segmented_progress ${mode} requires contentState.currentStep`
@@ -487,6 +595,22 @@ const buildContentStateFromOptions = (options) => {
487
595
  return contentState;
488
596
  };
489
597
 
598
+ const loadMetrics = async (options) => {
599
+ if (options.metrics && options.metricsFile) {
600
+ throw new Error("Provide either --metrics or --metrics-file, not both.");
601
+ }
602
+
603
+ if (options.metricsFile) {
604
+ return readJsonArrayFile(options.metricsFile, "metrics-file");
605
+ }
606
+
607
+ if (options.metrics) {
608
+ return parseJsonArrayString(options.metrics, "metrics");
609
+ }
610
+
611
+ return undefined;
612
+ };
613
+
490
614
  const toApiContentState = (contentState) => {
491
615
  const keyMap = {
492
616
  numberOfSteps: "number_of_steps",
@@ -561,6 +685,32 @@ const toApiLiveActivityEndRequest = (activityId, contentState, action) => {
561
685
  return request;
562
686
  };
563
687
 
688
+ const toApiLiveActivityStreamRequest = (contentState, action) => {
689
+ const request = {
690
+ content_state: toApiContentState(contentState),
691
+ };
692
+
693
+ if (action !== undefined) {
694
+ request.action = action;
695
+ }
696
+
697
+ return request;
698
+ };
699
+
700
+ const toApiLiveActivityStreamDeleteRequest = (contentState, action) => {
701
+ const request = {};
702
+
703
+ if (contentState !== undefined) {
704
+ request.content_state = toApiContentState(contentState);
705
+ }
706
+
707
+ if (action !== undefined) {
708
+ request.action = action;
709
+ }
710
+
711
+ return request;
712
+ };
713
+
564
714
  const loadContentState = async (options, mode) => {
565
715
  let contentState = {};
566
716
 
@@ -583,6 +733,11 @@ const loadContentState = async (options, mode) => {
583
733
  const fromFlags = buildContentStateFromOptions(options);
584
734
  contentState = { ...contentState, ...fromFlags };
585
735
 
736
+ const metrics = await loadMetrics(options);
737
+ if (metrics !== undefined) {
738
+ contentState.metrics = metrics;
739
+ }
740
+
586
741
  if (Object.keys(contentState).length === 0) {
587
742
  throw new Error(
588
743
  "contentState is required. Provide --content-state, --content-state-file, or field flags."
@@ -594,6 +749,41 @@ const loadContentState = async (options, mode) => {
594
749
  return contentState;
595
750
  };
596
751
 
752
+ const loadOptionalContentState = async (options, mode) => {
753
+ let contentState = {};
754
+
755
+ if (options.contentStateFile) {
756
+ const fromFile = await readJsonFile(
757
+ options.contentStateFile,
758
+ "content-state-file"
759
+ );
760
+ contentState = { ...contentState, ...fromFile };
761
+ }
762
+
763
+ if (options.contentState) {
764
+ const fromString = parseJsonString(
765
+ options.contentState,
766
+ "content-state"
767
+ );
768
+ contentState = { ...contentState, ...fromString };
769
+ }
770
+
771
+ const fromFlags = buildContentStateFromOptions(options);
772
+ contentState = { ...contentState, ...fromFlags };
773
+
774
+ const metrics = await loadMetrics(options);
775
+ if (metrics !== undefined) {
776
+ contentState.metrics = metrics;
777
+ }
778
+
779
+ if (Object.keys(contentState).length === 0) {
780
+ return undefined;
781
+ }
782
+
783
+ validateContentState(contentState, mode);
784
+ return contentState;
785
+ };
786
+
597
787
  const formatError = (error) => {
598
788
  if (!error) {
599
789
  return "Unknown error";
@@ -774,10 +964,76 @@ program
774
964
  }
775
965
  });
776
966
 
967
+ const metricsCommand = program
968
+ .command("metrics")
969
+ .alias("metric")
970
+ .description("Update widget metric values");
971
+
972
+ metricsCommand
973
+ .command("update")
974
+ .description("Update a widget metric value")
975
+ .argument("<metric-key>", "Metric key")
976
+ .argument("<value>", "Metric value")
977
+ .action(async (metricKey, rawValue) => {
978
+ const globalOptions = program.opts();
979
+
980
+ try {
981
+ const apiKey = requireApiKey(globalOptions);
982
+ const client = createClient(apiKey);
983
+ const value = parseMetricValueArgument(rawValue);
984
+ const response = await client.metrics.update(metricKey, value);
985
+
986
+ outputResult(response, globalOptions, ["Metric value updated."]);
987
+ } catch (error) {
988
+ await handleError(error, globalOptions);
989
+ }
990
+ });
991
+
777
992
  const activityCommand = program
778
993
  .command("activity")
779
994
  .description("Manage Live Activities");
780
995
 
996
+ addLiveActivityActionOptions(addContentStateOptions(
997
+ activityCommand
998
+ .command("stream")
999
+ .description("Send a stateless Live Activity stream update")
1000
+ .argument("<stream-key>", "Stable stream key")
1001
+ .option(
1002
+ "--channels <channels>",
1003
+ "Comma-separated channel slugs (optional)",
1004
+ parseChannelsOption
1005
+ )
1006
+ .action(async (streamKey, options) => {
1007
+ const globalOptions = program.opts();
1008
+
1009
+ try {
1010
+ const apiKey = requireApiKey(globalOptions);
1011
+ const client = createClient(apiKey);
1012
+ const contentState = await loadContentState(options, "stream");
1013
+ const action = await loadLiveActivityAction(options);
1014
+
1015
+ const response = await client.liveActivities.stream(
1016
+ streamKey,
1017
+ withTargetChannels(
1018
+ toApiLiveActivityStreamRequest(contentState, action),
1019
+ options.channels
1020
+ )
1021
+ );
1022
+
1023
+ const activityId = response?.activityId ?? response?.activity_id;
1024
+ const operation = response?.operation;
1025
+ outputResult(response, globalOptions, [
1026
+ "Live Activity stream reconciled.",
1027
+ streamKey ? `Stream key: ${streamKey}` : null,
1028
+ operation ? `Operation: ${operation}` : null,
1029
+ activityId ? `Activity ID: ${activityId}` : null,
1030
+ ]);
1031
+ } catch (error) {
1032
+ await handleError(error, globalOptions);
1033
+ }
1034
+ })
1035
+ ));
1036
+
781
1037
  addLiveActivityActionOptions(addContentStateOptions(
782
1038
  activityCommand
783
1039
  .command("start")
@@ -879,5 +1135,41 @@ addLiveActivityActionOptions(addContentStateOptions(
879
1135
  { includeAutoDismiss: true }
880
1136
  ));
881
1137
 
1138
+ addLiveActivityActionOptions(addContentStateOptions(
1139
+ activityCommand
1140
+ .command("end-stream")
1141
+ .description("End a stateless Live Activity stream")
1142
+ .argument("<stream-key>", "Stable stream key")
1143
+ .action(async (streamKey, options) => {
1144
+ const globalOptions = program.opts();
1145
+
1146
+ try {
1147
+ const apiKey = requireApiKey(globalOptions);
1148
+ const client = createClient(apiKey);
1149
+ const contentState = await loadOptionalContentState(options, "end");
1150
+ const action = await loadLiveActivityAction(options);
1151
+
1152
+ const request =
1153
+ contentState !== undefined || action !== undefined
1154
+ ? toApiLiveActivityStreamDeleteRequest(contentState, action)
1155
+ : undefined;
1156
+
1157
+ const response = await client.liveActivities.endStream(streamKey, request);
1158
+
1159
+ const activityId = response?.activityId ?? response?.activity_id;
1160
+ const operation = response?.operation;
1161
+ outputResult(response, globalOptions, [
1162
+ "Live Activity stream ended.",
1163
+ streamKey ? `Stream key: ${streamKey}` : null,
1164
+ operation ? `Operation: ${operation}` : null,
1165
+ activityId ? `Activity ID: ${activityId}` : null,
1166
+ ]);
1167
+ } catch (error) {
1168
+ await handleError(error, globalOptions);
1169
+ }
1170
+ }),
1171
+ { includeAutoDismiss: true }
1172
+ ));
1173
+
882
1174
  program.showHelpAfterError(true);
883
1175
  program.parseAsync(process.argv);