activitysmith-cli 1.1.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 +184 -35
  2. package/package.json +2 -2
  3. package/src/cli.js +94 -8
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
@@ -117,35 +140,61 @@ activitysmith push \
117
140
  ## Live Activities
118
141
 
119
142
  <p align="center">
120
- <img src="https://cdn.activitysmith.com/features/metrics-live-activity-action.png" alt="Live Activities example" width="680" />
143
+ <img src="https://cdn.activitysmith.com/features/metrics-live-activity-action.png" alt="Metrics Live Activity screenshot" width="680" />
121
144
  </p>
122
145
 
123
- ActivitySmith supports two ways to drive Live Activities:
146
+ There are four types of Live Activities:
124
147
 
125
- - Recommended: stream updates with `activitysmith activity stream ...`
126
- - Advanced: manual lifecycle control with `activity start`, `activity update`, and `activity end`
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
127
152
 
128
- Use stream updates when you want the easiest, stateless flow. You do not need to
129
- store `activity_id` or manage lifecycle state yourself. Send the latest state
130
- for a stable `stream_key` and ActivitySmith will start or update the Live
131
- Activity for you. When the tracked process is over, call `activity end-stream`.
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.
132
157
 
133
- Use the manual lifecycle commands when you need direct control over a specific
134
- Live Activity instance.
158
+ This is ideal if you want minimal complexity, perfect for automated workflows
159
+ like cron jobs.
135
160
 
136
- Live Activity UI types:
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.
137
164
 
138
- - `metrics`: best for live operational stats like server CPU and memory, queue depth, or replica lag
139
- - `segmented_progress`: best for step-based workflows like deployments, backups, and ETL pipelines
140
- - `progress`: best for continuous jobs like uploads, reindexes, and long-running migrations tracked as a percentage
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.
141
167
 
142
- ### Recommended: Stream updates
168
+ ### Simple: Let ActivitySmith manage the Live Activity for you
143
169
 
144
170
  Use a stable `stream_key` to identify the system or workflow you are tracking,
145
171
  such as a server, deployment, build pipeline, cron job, or charging session.
146
172
  This is especially useful for cron jobs and other scheduled tasks where you do
147
173
  not want to store `activity_id` between runs.
148
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
+ ```
197
+
149
198
  #### Metrics
150
199
 
151
200
  <p align="center">
@@ -232,11 +281,9 @@ Stream responses include an `operation` field:
232
281
  - `paused`: the stream is paused, so no Live Activity was started or updated
233
282
  - `ended`: returned by `activity end-stream` after the stream is ended
234
283
 
235
- ### Advanced: Manual lifecycle control
236
-
237
- Use these commands when you want to manage the Live Activity lifecycle yourself.
284
+ ### Advanced: Full lifecycle control
238
285
 
239
- #### Shared flow
286
+ Use these commands when you want to manage the Live Activity lifecycle yourself:
240
287
 
241
288
  1. Run `activitysmith activity start ...`.
242
289
  2. Save the returned `activity_id`.
@@ -246,6 +293,78 @@ Use these commands when you want to manage the Live Activity lifecycle yourself.
246
293
  You can use `--content-state <json>` for the examples below, or build the same
247
294
  payload with flags as documented in `Content State Options`.
248
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
+
249
368
  ### Metrics Type
250
369
 
251
370
  Use `metrics` when you want to keep a small set of live stats visible, such as
@@ -313,10 +432,10 @@ activitysmith activity end \
313
432
 
314
433
  ### Segmented Progress Type
315
434
 
316
- Use `segmented_progress` when progress is easier to follow as steps instead of a
317
- raw percentage. It fits jobs like deployments, backups, ETL pipelines, and
318
- checklists where "step 2 of 3" is more useful than "67%". `numberOfSteps` is
319
- dynamic, so you can increase or decrease it later if the workflow changes.
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.
437
+ `numberOfSteps` is dynamic, so you can increase or decrease it later if the
438
+ workflow changes.
320
439
 
321
440
  #### Start
322
441
 
@@ -428,7 +547,7 @@ activitysmith activity end \
428
547
 
429
548
  ### Live Activity Action
430
549
 
431
- Just like Actionable Push Notifications, Live Activities can have a button that opens a URL in a browser or triggers a webhook. Webhooks are executed by the ActivitySmith backend.
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.
432
551
 
433
552
  <p align="center">
434
553
  <img src="https://cdn.activitysmith.com/features/metrics-live-activity-action.png" alt="Metrics Live Activity with action" width="680" />
@@ -456,25 +575,26 @@ activitysmith activity start \
456
575
 
457
576
  #### Webhook action
458
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
+
459
582
  ```bash
460
583
  activitysmith activity update \
461
584
  --activity-id "<activityId>" \
462
585
  --content-state '{
463
- "title": "Server Health",
464
- "subtitle": "prod-web-1",
465
- "type": "metrics",
466
- "metrics": [
467
- { "label": "CPU", "value": 91, "unit": "%" },
468
- { "label": "MEM", "value": 57, "unit": "%" }
469
- ]
586
+ "title": "Reindexing product search",
587
+ "subtitle": "Shard 7 of 12",
588
+ "numberOfSteps": 12,
589
+ "currentStep": 7
470
590
  }' \
471
591
  --action '{
472
- "title": "Restart Service",
592
+ "title": "Pause Reindex",
473
593
  "type": "webhook",
474
- "url": "https://ops.example.com/hooks/servers/prod-web-1/restart",
594
+ "url": "https://ops.example.com/hooks/search/reindex/pause",
475
595
  "method": "POST",
476
596
  "body": {
477
- "server_id": "prod-web-1",
597
+ "job_id": "reindex-2026-03-19",
478
598
  "requested_by": "activitysmith-cli"
479
599
  }
480
600
  }'
@@ -491,6 +611,30 @@ activitysmith push \
491
611
  --channels "devs,ops"
492
612
  ```
493
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
+
494
638
  ## Aliases
495
639
 
496
640
  The CLI installs two bin names:
@@ -505,7 +649,7 @@ For `activity stream|start|update|end|end-stream`, you can pass content state vi
505
649
  - `--content-state <json>`
506
650
  - `--content-state-file <path>`
507
651
 
508
- For `metrics`, you can also pass the metrics array directly:
652
+ For `metrics` and `stats`, you can also pass the metrics array directly:
509
653
 
510
654
  - `--metrics <json-array>`
511
655
  - `--metrics-file <path>`
@@ -533,6 +677,11 @@ Targeting options:
533
677
 
534
678
  - `--channels <comma-separated-slugs>` (for `push`, `activity stream`, and `activity start`)
535
679
 
680
+ Widget metric options:
681
+
682
+ - `activitysmith metrics update <metric-key> <value>`
683
+ - `activitysmith metric update <metric-key> <value>` (alias)
684
+
536
685
  Required fields:
537
686
 
538
687
  - `activity stream`: `--title`, `--type`, plus `--metrics`, `--number-of-steps` and `--current-step`, `--percentage`, or `--value` with `--upper-limit`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "activitysmith-cli",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "Command-line interface for ActivitySmith. Send push notifications and manage Live Activities from your terminal.",
5
5
  "keywords": [
6
6
  "activitysmith",
@@ -40,7 +40,7 @@
40
40
  "lint": "node --check src/cli.js"
41
41
  },
42
42
  "dependencies": {
43
- "activitysmith": "^1.1.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`);
@@ -212,6 +236,18 @@ const isNonEmptyString = (value) =>
212
236
  const hasOwn = (object, key) =>
213
237
  Object.prototype.hasOwnProperty.call(object, key);
214
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
+
215
251
  const validateContentState = (contentState, mode) => {
216
252
  const normalizedType =
217
253
  typeof contentState.type === "string" ? contentState.type.trim() : undefined;
@@ -224,10 +260,11 @@ const validateContentState = (contentState, mode) => {
224
260
  normalizedType !== undefined &&
225
261
  normalizedType !== "segmented_progress" &&
226
262
  normalizedType !== "progress" &&
227
- normalizedType !== "metrics"
263
+ normalizedType !== "metrics" &&
264
+ normalizedType !== "stats"
228
265
  ) {
229
266
  throw new Error(
230
- "contentState.type must be one of: segmented_progress, progress, metrics"
267
+ "contentState.type must be one of: segmented_progress, progress, metrics, stats"
231
268
  );
232
269
  }
233
270
 
@@ -284,17 +321,41 @@ const validateContentState = (contentState, mode) => {
284
321
  throw new Error("contentState.metrics must be a non-empty array");
285
322
  }
286
323
 
324
+ if (normalizedType === "stats" && contentState.metrics.length > 8) {
325
+ throw new Error("stats contentState.metrics supports up to 8 items");
326
+ }
327
+
287
328
  contentState.metrics.forEach((metric, index) => {
288
329
  assertPlainObject(metric, `contentState.metrics[${index}]`);
289
330
  if (!isNonEmptyString(metric.label)) {
290
331
  throw new Error(`contentState.metrics[${index}].label is required`);
291
332
  }
292
- if (!Number.isFinite(metric.value)) {
293
- throw new Error(`contentState.metrics[${index}].value must be a number`);
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
+ );
294
343
  }
295
344
  if (metric.unit !== undefined && typeof metric.unit !== "string") {
296
345
  throw new Error(`contentState.metrics[${index}].unit must be a string`);
297
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
+ }
298
359
  });
299
360
  }
300
361
 
@@ -314,9 +375,9 @@ const validateContentState = (contentState, mode) => {
314
375
  return;
315
376
  }
316
377
 
317
- if (effectiveType === "metrics") {
378
+ if (effectiveType === "metrics" || effectiveType === "stats") {
318
379
  if (!hasMetrics) {
319
- throw new Error(`metrics ${mode} requires contentState.metrics`);
380
+ throw new Error(`${effectiveType} ${mode} requires contentState.metrics`);
320
381
  }
321
382
  return;
322
383
  }
@@ -347,9 +408,9 @@ const validateContentState = (contentState, mode) => {
347
408
  return;
348
409
  }
349
410
 
350
- if (effectiveType === "metrics") {
411
+ if (effectiveType === "metrics" || effectiveType === "stats") {
351
412
  if (!hasMetrics) {
352
- throw new Error(`metrics ${mode} requires contentState.metrics`);
413
+ throw new Error(`${effectiveType} ${mode} requires contentState.metrics`);
353
414
  }
354
415
  return;
355
416
  }
@@ -903,6 +964,31 @@ program
903
964
  }
904
965
  });
905
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
+
906
992
  const activityCommand = program
907
993
  .command("activity")
908
994
  .description("Manage Live Activities");