activitysmith-cli 1.18.1 → 1.19.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.
- package/package.json +1 -1
- package/src/agent.js +49 -0
- package/src/cli.js +10 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "activitysmith-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"description": "Command-line interface for ActivitySmith. Send Push Notifications, start, update, and end Live Activities, and set App Icon Badge Counts from your terminal.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"activitysmith",
|
package/src/agent.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// The coding agent running the CLI, read from the environment it sets for its shell commands.
|
|
2
|
+
// Requests send it as X-ActivitySmith-Agent, so Push Notifications and approvals show the agent's
|
|
3
|
+
// name and icon, such as "Claude Code needs your approval", instead of the CLI's own sign-in name.
|
|
4
|
+
// The API accepts only the ids below and ignores anything else.
|
|
5
|
+
|
|
6
|
+
// AI_AGENT is the shared convention ("claude-code_2-1-321_agent"); check it by prefix.
|
|
7
|
+
const AI_AGENT_PREFIXES = [
|
|
8
|
+
["claude-code", "claude-code"],
|
|
9
|
+
["codex", "codex"],
|
|
10
|
+
["cursor", "cursor"],
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
/** Environment variables this reads, so tests can clear them. */
|
|
14
|
+
export const AGENT_ENV_VARS = [
|
|
15
|
+
"AI_AGENT",
|
|
16
|
+
"CLAUDECODE",
|
|
17
|
+
"CLAUDE_CODE",
|
|
18
|
+
"CLAUDE_CODE_IS_COWORK",
|
|
19
|
+
"CODEX_THREAD_ID",
|
|
20
|
+
"CODEX_SANDBOX",
|
|
21
|
+
"CODEX_CI",
|
|
22
|
+
"CURSOR_AGENT",
|
|
23
|
+
"CURSOR_EXTENSION_HOST_ROLE",
|
|
24
|
+
"CURSOR_TRACE_ID",
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
export function detectAgent(env = process.env) {
|
|
28
|
+
// Cowork runs Claude Code, so it is checked before AI_AGENT names Claude Code.
|
|
29
|
+
if ((env.CLAUDECODE || env.CLAUDE_CODE) && env.CLAUDE_CODE_IS_COWORK) return "claude-cowork";
|
|
30
|
+
|
|
31
|
+
const aiAgent = String(env.AI_AGENT ?? "").trim().toLowerCase();
|
|
32
|
+
const fromAiAgent = AI_AGENT_PREFIXES.find(([prefix]) => aiAgent.startsWith(prefix));
|
|
33
|
+
if (fromAiAgent) return fromAiAgent[1];
|
|
34
|
+
|
|
35
|
+
if (env.CLAUDECODE || env.CLAUDE_CODE) return "claude-code";
|
|
36
|
+
if (env.CODEX_THREAD_ID || env.CODEX_SANDBOX || env.CODEX_CI) return "codex";
|
|
37
|
+
if (env.CURSOR_AGENT || env.CURSOR_EXTENSION_HOST_ROLE === "agent-exec") return "cursor";
|
|
38
|
+
// Every terminal in Cursor sets this, so it comes last: Claude Code or Codex running inside
|
|
39
|
+
// Cursor's terminal is still that agent.
|
|
40
|
+
if (env.CURSOR_TRACE_ID) return "cursor";
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const AGENT_HEADER = "X-ActivitySmith-Agent";
|
|
45
|
+
|
|
46
|
+
export function agentHeaders(env = process.env) {
|
|
47
|
+
const agent = detectAgent(env);
|
|
48
|
+
return agent ? { [AGENT_HEADER]: agent } : {};
|
|
49
|
+
}
|
package/src/cli.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { Command, InvalidArgumentError, Option } from "commander";
|
|
4
|
+
import { agentHeaders } from "./agent.js";
|
|
4
5
|
import { loadMetadata } from "./metadata.js";
|
|
5
6
|
import {
|
|
6
7
|
API_KEYS_SCOPE,
|
|
@@ -285,6 +286,12 @@ const credentialSource = (options) => {
|
|
|
285
286
|
return readCredentials() ? "auth login" : null;
|
|
286
287
|
};
|
|
287
288
|
|
|
289
|
+
// Names the coding agent running the CLI, so its Push Notifications show that agent's icon.
|
|
290
|
+
const agentRequestInit = () => {
|
|
291
|
+
const headers = agentHeaders();
|
|
292
|
+
return Object.keys(headers).length > 0 ? { headers } : undefined;
|
|
293
|
+
};
|
|
294
|
+
|
|
288
295
|
const createClient = (apiKey) =>
|
|
289
296
|
new ActivitySmith({
|
|
290
297
|
apiKey,
|
|
@@ -1373,10 +1380,10 @@ const pushCommand = program
|
|
|
1373
1380
|
|
|
1374
1381
|
const isReplacement = options.replace !== undefined;
|
|
1375
1382
|
const response = isReplacement
|
|
1376
|
-
? await client.notifications.replace(options.replace.trim(), pushNotificationRequest)
|
|
1383
|
+
? await client.notifications.replace(options.replace.trim(), pushNotificationRequest, agentRequestInit())
|
|
1377
1384
|
: await client.notifications.sendPushNotification({
|
|
1378
1385
|
pushNotificationRequest,
|
|
1379
|
-
});
|
|
1386
|
+
}, agentRequestInit());
|
|
1380
1387
|
const devicesNotified = response?.devices_notified ?? response?.devicesNotified;
|
|
1381
1388
|
const notificationId = response?.notification_id ?? response?.notificationId;
|
|
1382
1389
|
|
|
@@ -1790,6 +1797,7 @@ const apiRequest = async (path, { token, method = "GET", body } = {}) => {
|
|
|
1790
1797
|
Authorization: `Bearer ${token}`,
|
|
1791
1798
|
Accept: "application/json",
|
|
1792
1799
|
"X-ActivitySmith-SDK": `cli-v${version}`,
|
|
1800
|
+
...agentHeaders(),
|
|
1793
1801
|
...(body ? { "Content-Type": "application/json" } : {}),
|
|
1794
1802
|
},
|
|
1795
1803
|
...(body ? { body: JSON.stringify(body) } : {}),
|