insightfulpipe 0.2.0 → 0.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,106 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.0
4
+
5
+ **Private skills, separate from the public library.**
6
+
7
+ - `skills search | info | install --private [--workspace <id>]` read your workspace's own skills (the
8
+ custom skills in the app's Skills Library) from the app API with your API key. The workspace is
9
+ `--workspace`, else the one saved with `insightfulpipe use`. Without `--private`, every command uses
10
+ only the public catalogue on insightfulpipe.com, with no key. Neither ever falls back to the other.
11
+ - A private skill is named by its folder name or its key (`custom-123`); a name two private skills
12
+ share must be given by key. It goes through the same checks as a public one (checksums, version,
13
+ safe paths, staging folder), and a refusal says to fix the skill in the Skills Library.
14
+ - Installed skills record their origin: public, or private with its key and workspace. `list` and
15
+ `update` take each one back to its own source; markers from 0.3.x count as public. When the app
16
+ refuses a private check (no key, no access, lapsed subscription), that row fails on its own and the
17
+ others still list and update.
18
+ - An install never silently replaces a different skill in the same folder (public over private,
19
+ or another private skill with the same name): it refuses unless `--force`. Two skills chosen in one
20
+ `install` that share a folder name never overwrite each other, even with `--force`.
21
+ - Private list entries whose name or key is not plain are dropped, like public ones.
22
+ - Requests to the app API no longer follow redirects. A 3xx is an error that names where it pointed
23
+ and says to set `INSIGHTFULPIPE_API_URL` to the final address; the server answered, so it is not
24
+ reported as `outcome_unknown`.
25
+ - Token whitespace is trimmed the way the app's header parser does (including no-break and other
26
+ Unicode spaces), not just spaces, tabs and line breaks.
27
+ - A private skill renamed in the Skills Library is left in place by `update`, with the command that
28
+ installs it under its new name.
29
+ - **Only your own private installs are trusted.** Each private install is recorded under
30
+ `~/.insightfulpipe/private-skills/` (one file per folder, readable by you only) with its real folder,
31
+ key, workspace and name. A private marker that record does not name, such as one that came with a
32
+ cloned repository, a folder that was moved, or a marker whose key was changed, is listed with
33
+ `trusted: false` and is never checked, updated or sent for; install it again with
34
+ `--private --force` to use it. `remove` clears the record entry. Of such a marker only its plain
35
+ folder name is ever printed, and folders whose names are not plain are not listed at all.
36
+ - Private errors keep the app's HTTP status in the JSON (`http_status`). `--workspace` without
37
+ `--private` is refused instead of ignored. A `--dir` spelled in another case on macOS or Windows is
38
+ the same folder. The command suggested for a renamed private skill keeps `--project` or `--dir`.
39
+ - A private skill in a project folder (`--project`, `--dir`) carries a warning to keep it out of
40
+ shared repositories. `download --private` is not available yet: use Download in the Skills Library.
41
+ - Bundled file names may contain single spaces (`Brand guide.md`). Still ASCII only, never at either
42
+ end, and `con .txt` and the like are refused like the other Windows device names.
43
+
44
+ ## 0.3.1
45
+
46
+ - Spaces and line breaks around an API token are dropped wherever it comes from (environment
47
+ variable, keychain, config file, or `auth`), as `fetch` already did when sending it.
48
+ - A token with a space, line break, control character or non-ASCII letter inside it is refused
49
+ before any request is made, and the message says why (the token is never echoed). Before, some of
50
+ those characters failed only once the request had started, and a write was then reported as
51
+ `outcome_unknown` although nothing had been sent. `auth` refuses to save such a token, and `doctor`
52
+ reports it with its source instead of failing.
53
+ - "Network unreachable" and "host unreachable" count as a request never sent only when they happen
54
+ while connecting. The same codes later in a request now report `outcome_unknown`, like any other
55
+ failure after the request may have arrived.
56
+ - `skills list` reports `"status": "partial"` when a skill folder could not be checked, matching its
57
+ exit code 1 and what `install` and `update` already do.
58
+
59
+ ## 0.3.0
60
+
61
+ **`insightfulpipe skills`: install InsightfulPipe skills from the terminal.** Modelled on
62
+ `openclaw skills install`, for our catalogue on insightfulpipe.com.
63
+
64
+ - `skills search [words] [--category]`, `skills info <skill>`, and `skills install <skill...>` (or
65
+ `--category <c>`). Install writes into Claude Code's global folder by default; `--agent openclaw |
66
+ codex | cursor | gemini-cli`, `--project` and `--dir` pick another.
67
+ - Before writing, every file is checked against its sha256 and the skill's content version, paths
68
+ that would escape the folder are refused, and SKILL.md must be named after the skill. Files land in
69
+ a staging folder and are renamed into place, so a failure leaves nothing half-written.
70
+ - Each install keeps a `.insightfulpipe-skill.json` marker. `skills list` shows installed skills and
71
+ available updates. `skills update <skill> | --all` keeps local edits unless `--force`. `skills
72
+ remove` only deletes folders this CLI installed and asks first (`--yes` when non-interactive).
73
+ - `skills download <skill>` saves the ZIP for uploading in Claude.ai or Claude Desktop.
74
+ - No login needed. The catalogue never receives the API token. `INSIGHTFULPIPE_SKILLS_URL` accepts only
75
+ insightfulpipe.com, its subdomains or localhost, so installs can't be pointed at a look-alike catalogue.
76
+ - Added CI: unit tests on Node 18, 20 and 22, plus a live install of a real skill into a throwaway
77
+ home folder.
78
+
79
+ **Clearer errors from connected platforms.**
80
+
81
+ - A rejection from a connected platform now reads `Pinterest Pages error 50 (HTTP 404): Pin not
82
+ found.`: the platform (the one named in the response, otherwise the one the command was run for),
83
+ its own error code, the status it answered with and its message. Before, the error read
84
+ `"message": true`. JSON output also carries `api_status_code`, the raw `api_error`, `details`,
85
+ `error_type` and `retry_after`, plus the app's write-outcome fields (`write_state`,
86
+ `ambiguous_write`, `outcome_unknown`, `status_code` and the like) and the response's `http_status`,
87
+ so a script can tell a write may have landed (any of those flags, or a status of 500 or more)
88
+ before it retries. Like the app, an error body with no `status_code` gets the HTTP status as one.
89
+ - `details` that arrive as an object are shown as JSON instead of `[object Object]`; string `details`
90
+ still read as before. A message or any of those fields longer than 2,000 characters is cut with a marker that
91
+ says how much was omitted, and the error is written out whole before the CLI exits, so a piped
92
+ stderr never receives half a JSON document.
93
+ - A 429 keeps `retry_after` in the JSON and adds `Tip: Retry after N seconds.` under `--table`.
94
+ - An error body with no message reports the HTTP status (`Request failed with status 500`).
95
+ - A request that fails after it may have reached the server (connection dropped, response cut off,
96
+ timeout, a 2xx that is not JSON) reports `outcome_unknown: true`, the app's own sign that a write may
97
+ have landed. A request that never left (no connection, a failed certificate check, an invalid
98
+ header) does not, and an invalid header never echoes the token.
99
+ - A response that stops arriving ends after the timeout passes with no new data; a slow but steady
100
+ one is never cut, and query results have no size cap.
101
+ - Requests identify themselves as `insightfulpipe-cli/<version>` (User-Agent).
102
+ - Needs Node.js 18.20 or later: older 18.x releases print a fetch warning on stderr ahead of the JSON.
103
+
3
104
  ## 0.2.0
4
105
 
5
106
  **JSON is now the default output.** It is read by scripts and agents far more often than by eyes.
package/README.md CHANGED
@@ -12,7 +12,7 @@ Recommended workflow:
12
12
 
13
13
  ## Requirements
14
14
 
15
- - Node.js 18+
15
+ - Node.js 18.20+
16
16
  - An InsightfulPipe API token starting with `ip_sk_`
17
17
 
18
18
  ## Installation
@@ -46,6 +46,66 @@ The CLI also reads these environment variables:
46
46
  - `INSIGHTFULPIPE_TOKEN`
47
47
  - `INSIGHTFULPIPE_API_URL`
48
48
  - `INSIGHTFULPIPE_TIMEOUT_MS`
49
+ - `INSIGHTFULPIPE_SKILLS_URL` (skills catalogue: `https://insightfulpipe.com` by default; only its subdomains or localhost are accepted)
50
+
51
+ ## Skills
52
+
53
+ Install InsightfulPipe's marketing skills (Google Ads audits, GA4 reports, SEO and more) into your
54
+ AI agent's skills folder. No login is needed to install: skills are free to download. They read live
55
+ data through the InsightfulPipe MCP once it is connected.
56
+
57
+ ```bash
58
+ npx insightfulpipe skills search # browse every skill
59
+ npx insightfulpipe skills search google ads audit # search by words
60
+ npx insightfulpipe skills info google-ads-account-audit
61
+ npx insightfulpipe skills install google-ads-account-audit
62
+ npx insightfulpipe skills install --category seo # every skill in a category
63
+ npx insightfulpipe skills list # installed skills, and which have updates
64
+ npx insightfulpipe skills update --all # keeps your local edits unless --force
65
+ npx insightfulpipe skills remove google-ads-account-audit --yes
66
+ npx insightfulpipe skills download google-ads-account-audit # ZIP for Claude.ai or Claude Desktop
67
+ ```
68
+
69
+ Names can be `slug`, `category/slug` or `@insightfulpipe/slug`. A name that exists in two categories
70
+ must be written as `category/slug`.
71
+
72
+ Skills go to Claude Code's global folder by default. Choose another agent with `--agent`, the current
73
+ project with `--project`, or any folder with `--dir`:
74
+
75
+ | `--agent` | Global folder | `--project` folder |
76
+ |---|---|---|
77
+ | `claude-code` (default) | `~/.claude/skills` (or `$CLAUDE_CONFIG_DIR/skills`) | `.claude/skills` |
78
+ | `openclaw` | `~/.openclaw/skills` (or `$OPENCLAW_SKILLS_DIR`) | `skills` |
79
+ | `codex` | `~/.codex/skills` (or `$CODEX_HOME/skills`) | `.agents/skills` |
80
+ | `cursor` | `~/.cursor/skills` | `.agents/skills` |
81
+ | `gemini-cli` | `~/.gemini/skills` | `.agents/skills` |
82
+
83
+ ### Private skills
84
+
85
+ Your workspace's own skills (the custom skills in the app's Skills Library) come from the app API with
86
+ your API key, for one workspace. They never mix with the public library:
87
+
88
+ ```bash
89
+ insightfulpipe skills search --private --workspace 34
90
+ insightfulpipe skills install weekly-brief --private --workspace 34 # skill name or key (custom-123)
91
+ insightfulpipe use -w 34 # or save the workspace once
92
+ insightfulpipe skills install weekly-brief --private
93
+ ```
94
+
95
+ `list` and `update` take each installed skill back to the source it came from. Private skills go to
96
+ your personal skills folder by default; installing one with `--project` or `--dir` prints a warning to
97
+ keep it out of shared repositories. Only private skills you installed are trusted: each install is
98
+ recorded under `~/.insightfulpipe/private-skills/`, and a private skill folder that record does not
99
+ name (one that came with a cloned repository, or that was moved) is listed but never checked or
100
+ updated. To use it, install it again with `--private --force`. `--workspace` without `--private` is
101
+ refused. `download` is for public skills; for a private one, use Download in
102
+ the Skills Library.
103
+
104
+ Every file is checked against its sha256 before anything is written, and each installed skill keeps
105
+ a `.insightfulpipe-skill.json` marker. `list`, `update` and `remove` only touch folders that carry it,
106
+ and `update` will not overwrite files you edited unless you add `--force`. The public catalogue never
107
+ receives your API token. `INSIGHTFULPIPE_SKILLS_URL` can point the commands at a staging copy on an
108
+ insightfulpipe.com subdomain or at localhost (for testing); any other host is refused.
49
109
 
50
110
  ## Core Commands
51
111
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "insightfulpipe",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "InsightfulPipe CLI \u2014 query your marketing data from the terminal",
5
5
  "bin": {
6
6
  "insightfulpipe": "bin/cli.js"
@@ -25,7 +25,7 @@
25
25
  "test:live": "node --test test/live-smoke.test.js"
26
26
  },
27
27
  "engines": {
28
- "node": ">=18"
28
+ "node": ">=18.20"
29
29
  },
30
30
  "keywords": [
31
31
  "insightfulpipe",
package/src/api.js CHANGED
@@ -1,7 +1,16 @@
1
- import { fail } from './cli/errors.js';
2
- import { getApiUrl, getRequestTimeoutMs, getToken } from './config.js';
1
+ import { bounded, fail } from './cli/errors.js';
2
+ import { getApiUrl, getRequestTimeoutMs, getToken, tokenProblem } from './config.js';
3
+ import { readBody, USER_AGENT } from './http.js';
3
4
 
4
5
  let _insecureWarned = false;
6
+ // Far above any real error body; past it the body is dropped unread instead of held in memory.
7
+ const MAX_ERROR_BYTES = 10 * 1024 * 1024;
8
+ // Failures before a request could reach the server: nothing can have been written.
9
+ const NOT_SENT_CODES = new Set(['ECONNREFUSED', 'ENOTFOUND', 'EAI_AGAIN', 'UND_ERR_CONNECT_TIMEOUT']);
10
+ // Routing failures prove nothing was sent only while connecting; later they can follow a written request.
11
+ const CONNECT_ONLY_CODES = new Set(['ENETUNREACH', 'EHOSTUNREACH']);
12
+ // Certificate checks happen in the handshake, before any request byte is sent.
13
+ const TLS_FAILURE = /^(CERT_|UNABLE_TO_|ERR_TLS_CERT_)|SELF_SIGNED/;
5
14
 
6
15
  function warnIfInsecure() {
7
16
  if (_insecureWarned) return;
@@ -25,6 +34,10 @@ function requireAuth() {
25
34
  if (!token) {
26
35
  fail('Not authenticated.', 'Run: insightfulpipe auth');
27
36
  }
37
+ const problem = tokenProblem(token);
38
+ if (problem) {
39
+ fail(problem, 'Check INSIGHTFULPIPE_TOKEN if you set it, or run: insightfulpipe auth');
40
+ }
28
41
  return token;
29
42
  }
30
43
 
@@ -63,13 +76,11 @@ function summarizeTextError(text, res) {
63
76
  return {
64
77
  error: true,
65
78
  status: res.status,
66
- message: text,
79
+ message: bounded(text),
67
80
  };
68
81
  }
69
82
 
70
- async function parseJsonResponse(res) {
71
- const text = await res.text();
72
-
83
+ function parseJsonResponse(text, res) {
73
84
  if (!text.trim()) {
74
85
  return {};
75
86
  }
@@ -81,8 +92,9 @@ async function parseJsonResponse(res) {
81
92
  return {
82
93
  error: true,
83
94
  status: res.status,
95
+ outcome_unknown: true,
84
96
  message: 'Received invalid JSON from server.',
85
- details: text,
97
+ details: bounded(text),
86
98
  };
87
99
  }
88
100
 
@@ -90,6 +102,90 @@ async function parseJsonResponse(res) {
90
102
  }
91
103
  }
92
104
 
105
+ /** True when every underlying error came from connect(). A hostname with several addresses fails as an
106
+ * AggregateError that carries no syscall of its own, only its per-address errors do. */
107
+ function failedWhileConnecting(cause) {
108
+ const errors = Array.isArray(cause?.errors) ? cause.errors : [cause];
109
+ return errors.length > 0 && errors.every((err) => err?.syscall === 'connect');
110
+ }
111
+
112
+ /** A request that failed once it may have reached the server is an unknown outcome, never a refusal:
113
+ * a write can land even though no complete answer came back, so a script must not simply resend it. */
114
+ function unanswered(error, res, timeoutMs, method) {
115
+ const cause = error?.cause?.code;
116
+ const notBuilt = !res && error?.name === 'TypeError' && !error.cause;
117
+ const refused =
118
+ NOT_SENT_CODES.has(cause) ||
119
+ (CONNECT_ONLY_CODES.has(cause) && failedWhileConnecting(error.cause)) ||
120
+ TLS_FAILURE.test(cause ?? '') ||
121
+ error?.cause?.message === 'bad port';
122
+ const neverSent = notBuilt || (!res && refused);
123
+ let message;
124
+ if (error?.name === 'AbortError') {
125
+ message = `Network request timed out after ${timeoutMs} ms`;
126
+ } else if (notBuilt) {
127
+ message = 'The request could not be sent: a header is invalid. Check the API token for line breaks or other control characters.';
128
+ } else if (neverSent) {
129
+ message = `Network request failed: ${error.message} (${cause ?? error.cause?.message})`;
130
+ } else {
131
+ message = `Network request failed before a complete response arrived: ${error?.message}${cause ? ` (${cause})` : ''}`;
132
+ }
133
+ return {
134
+ error: true,
135
+ message,
136
+ ...(res ? { status: res.status } : {}),
137
+ ...(neverSent || method === 'GET' ? {} : { outcome_unknown: true }),
138
+ };
139
+ }
140
+
141
+ /** The app API never redirects. Following one would resend the request, a write too, to another address,
142
+ * so a 3xx is reported with where it pointed. The server answered, so the outcome is not unknown. */
143
+ function redirected(res) {
144
+ const location = res.headers.get('location');
145
+ return {
146
+ error: true,
147
+ message: `The API answered HTTP ${res.status}, a redirect${location ? ` to ${location}` : ''}, which the CLI does not follow. Set INSIGHTFULPIPE_API_URL to the final address.`,
148
+ status: res.status,
149
+ };
150
+ }
151
+
152
+ /** One request under the shared timeout. An error body is read under that timeout and capped; a success
153
+ * body has no size or total-time cap (query results are never cut), only an idle timeout, so a stalled
154
+ * server still cannot hold the command open. Every non-2xx result carries its HTTP status. */
155
+ async function send(url, options, timeoutMs) {
156
+ const controller = new AbortController();
157
+ const abort = () => controller.abort();
158
+ const timeout = setTimeout(abort, timeoutMs);
159
+ let res;
160
+ let raw;
161
+ try {
162
+ res = await fetch(url, { ...options, redirect: 'manual', signal: controller.signal });
163
+ if (res.status >= 300 && res.status < 400) {
164
+ res.body?.cancel().catch(() => {});
165
+ return redirected(res);
166
+ }
167
+ if (res.ok) {
168
+ clearTimeout(timeout);
169
+ }
170
+ raw = await readBody(res, res.ok ? { idleMs: timeoutMs, onIdle: abort } : { maxBytes: MAX_ERROR_BYTES });
171
+ } catch (error) {
172
+ return unanswered(error, res, timeoutMs, options.method);
173
+ } finally {
174
+ clearTimeout(timeout);
175
+ }
176
+
177
+ if (res.ok) {
178
+ return parseJsonResponse(new TextDecoder().decode(raw), res);
179
+ }
180
+ const data =
181
+ raw === null
182
+ ? { message: `The server sent an error response larger than ${MAX_ERROR_BYTES} bytes.` }
183
+ : parseJsonResponse(new TextDecoder().decode(raw), res);
184
+ const body = data && typeof data === 'object' ? data : { message: String(data) };
185
+ const statusCode = body.status_code || body.api_status_code ? {} : { status_code: res.status };
186
+ return { ...body, ...statusCode, error: body.error || true, status: res.status };
187
+ }
188
+
93
189
  async function apiRequest(method, path, body) {
94
190
  warnIfInsecure();
95
191
  const token = requireAuth();
@@ -110,6 +206,7 @@ async function apiRequest(method, path, body) {
110
206
  headers: {
111
207
  'Authorization': `Bearer ${token}`,
112
208
  'Accept': 'application/json',
209
+ 'User-Agent': USER_AGENT,
113
210
  },
114
211
  };
115
212
 
@@ -118,38 +215,7 @@ async function apiRequest(method, path, body) {
118
215
  options.body = JSON.stringify(body);
119
216
  }
120
217
 
121
- let res;
122
- const controller = new AbortController();
123
- const timeout = setTimeout(() => controller.abort(), timeoutMs);
124
- try {
125
- res = await fetch(url, { ...options, signal: controller.signal });
126
- } catch (error) {
127
- clearTimeout(timeout);
128
- return {
129
- error: true,
130
- message:
131
- error?.name === 'AbortError'
132
- ? `Network request timed out after ${timeoutMs} ms`
133
- : `Network request failed: ${error.message}`,
134
- };
135
- }
136
- clearTimeout(timeout);
137
-
138
- const data = await parseJsonResponse(res);
139
-
140
- if (data && data.error) {
141
- return data;
142
- }
143
-
144
- if (!res.ok) {
145
- return {
146
- error: true,
147
- status: res.status,
148
- ...(data && typeof data === 'object' ? data : { message: String(data) }),
149
- };
150
- }
151
-
152
- return data;
218
+ return send(url, options, timeoutMs);
153
219
  }
154
220
 
155
221
  export async function apiGet(path) {
@@ -174,43 +240,16 @@ export async function accountSummary() {
174
240
  };
175
241
  }
176
242
 
177
- let res;
178
- const controller = new AbortController();
179
- const timeout = setTimeout(() => controller.abort(), timeoutMs);
180
- try {
181
- res = await fetch(url, {
243
+ return send(
244
+ url,
245
+ {
182
246
  method: 'GET',
183
247
  headers: {
184
248
  'Authorization': `Bearer ${token}`,
185
249
  'Accept': 'application/json',
250
+ 'User-Agent': USER_AGENT,
186
251
  },
187
- signal: controller.signal,
188
- });
189
- } catch (error) {
190
- clearTimeout(timeout);
191
- return {
192
- error: true,
193
- message:
194
- error?.name === 'AbortError'
195
- ? `Network request timed out after ${timeoutMs} ms`
196
- : `Network request failed: ${error.message}`,
197
- };
198
- }
199
- clearTimeout(timeout);
200
-
201
- const data = await parseJsonResponse(res);
202
-
203
- if (data && data.error) {
204
- return data;
205
- }
206
-
207
- if (!res.ok) {
208
- return {
209
- error: true,
210
- status: res.status,
211
- ...(data && typeof data === 'object' ? data : { message: String(data) }),
212
- };
213
- }
214
-
215
- return data;
252
+ },
253
+ timeoutMs,
254
+ );
216
255
  }
@@ -1,4 +1,4 @@
1
- import { getConfigSnapshot, saveConfig } from '../../config.js';
1
+ import { cleanToken, getConfigSnapshot, saveConfig, tokenProblem } from '../../config.js';
2
2
  import { fail } from '../errors.js';
3
3
  import { promptSecret } from '../input.js';
4
4
 
@@ -8,7 +8,7 @@ export function registerAuthCommand(program) {
8
8
  .description('Save your InsightfulPipe API key')
9
9
  .option('--insecure-storage', 'Save token to config file instead of OS keyring')
10
10
  .action(async (opts) => {
11
- const token = await promptSecret('Enter your API token: ');
11
+ const token = cleanToken(await promptSecret('Enter your API token: '));
12
12
 
13
13
  if (!token) {
14
14
  fail('No token provided.');
@@ -18,6 +18,11 @@ export function registerAuthCommand(program) {
18
18
  fail('Token must start with ip_sk_.');
19
19
  }
20
20
 
21
+ const problem = tokenProblem(token);
22
+ if (problem) {
23
+ fail(problem, 'Copy the key again from the API keys page in the app.');
24
+ }
25
+
21
26
  const config = { ...getConfigSnapshot().rawValues, token };
22
27
  const { tokenInKeyring } = saveConfig(config, { insecure: opts.insecureStorage });
23
28
 
@@ -1,4 +1,4 @@
1
- import { getConfigSnapshot, getContext, getToken, saveContext } from '../../config.js';
1
+ import { getConfigSnapshot, getContext, getToken, saveContext, tokenProblem } from '../../config.js';
2
2
  import { apiGet } from '../../api.js';
3
3
  import { printJson, printTable, wantsJson } from '../../output.js';
4
4
  import {
@@ -7,7 +7,7 @@ import {
7
7
  parseIntegerOption,
8
8
  toPromptDataSource,
9
9
  } from '../options.js';
10
- import { fail, handleApiError } from '../errors.js';
10
+ import { errorMessage, fail, handleApiError } from '../errors.js';
11
11
  import {
12
12
  fetchBrandMetadata,
13
13
  fetchConnectedSources,
@@ -296,6 +296,7 @@ export function registerDiscoveryCommands(program) {
296
296
  .action(async (opts, command) => {
297
297
  const snapshot = getConfigSnapshot();
298
298
  const token = getToken();
299
+ const problem = token ? tokenProblem(token) : null;
299
300
  const checks = [
300
301
  {
301
302
  name: 'api_url',
@@ -305,8 +306,8 @@ export function registerDiscoveryCommands(program) {
305
306
  },
306
307
  {
307
308
  name: 'token',
308
- status: token ? 'ok' : 'error',
309
- details: token ? 'Configured' : 'Missing',
309
+ status: token && !problem ? 'ok' : 'error',
310
+ details: !token ? 'Missing' : problem || 'Configured',
310
311
  source: snapshot.sources.token,
311
312
  },
312
313
  {
@@ -319,15 +320,15 @@ export function registerDiscoveryCommands(program) {
319
320
 
320
321
  let connectivity = {
321
322
  status: 'skipped',
322
- details: 'Skipped because no token is configured.',
323
+ details: problem ? 'Skipped because the token cannot be sent.' : 'Skipped because no token is configured.',
323
324
  };
324
325
 
325
- if (token) {
326
+ if (token && !problem) {
326
327
  const data = await apiGet('/user-info/');
327
328
  if (data?.error) {
328
329
  connectivity = {
329
330
  status: 'error',
330
- details: data.message || data.details || 'Request failed',
331
+ details: errorMessage(data),
331
332
  };
332
333
  } else {
333
334
  connectivity = {
@@ -26,14 +26,14 @@ const SCOPE_OPTIONS = [
26
26
  export function registerExecutionCommands(program) {
27
27
  const readAction = async (platform, opts) => {
28
28
  const body = scopedBody(ensureJsonObject(await readJsonInput(opts, true), 'Request body'), opts);
29
- const data = handleApiError(await apiPost('/', withPlatform(platform, body)));
29
+ const data = handleApiError(await apiPost('/', withPlatform(platform, body)), { platform });
30
30
  printJson(data);
31
31
  };
32
32
 
33
33
  const writeAction = async (platform, opts) => {
34
34
  const body = scopedBody(ensureJsonObject(await readJsonInput(opts, true), 'Request body'), opts);
35
35
  await confirmWriteAction(platform, body, opts.yes);
36
- const data = handleApiError(await apiPost('/', withPlatform(platform, body)));
36
+ const data = handleApiError(await apiPost('/', withPlatform(platform, body)), { platform });
37
37
  printJson(data);
38
38
  };
39
39
 
@@ -85,7 +85,7 @@ export function registerExecutionCommands(program) {
85
85
  .description('Send a raw request to the universal dispatcher')
86
86
  .action(async (opts) => {
87
87
  const body = ensureJsonObject(await readJsonInput(opts, true), 'Request body');
88
- const data = handleApiError(await apiPost('/', body));
88
+ const data = handleApiError(await apiPost('/', body), { platform: body.platform });
89
89
  printJson(data);
90
90
  });
91
91
  }