insightfulpipe 0.3.0 → 0.4.1

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,76 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.1
4
+
5
+ - `--table` now works on `query`, `action`, `raw` and `helper` too. Result rows print as columns (one
6
+ per field), a single record as field and value, long values shortened. Footers state a partial
7
+ failure and the server's message, name any other fields beside the rows, say when the server has
8
+ more rows (any platform's paging marker; a count never hides one), point out partial errors, warnings
9
+ and notes, and name every other `meta` field that is not purely descriptive. Rows with more than 40
10
+ different fields, and `helper --actions` (the body to copy into `-b`), stay JSON with a note. JSON
11
+ stays the default and is unchanged.
12
+ - Text from the server printed under `--table` (tables, error sentences, `whoami`, `prompts --id`,
13
+ `doctor`, `skills` lines, JSON fallbacks) shows control characters and bidi overrides as `\uXXXX`,
14
+ so text from a connected platform cannot move the cursor, clear the screen or write to the clipboard.
15
+ - `skills list`, `update` and `remove` accept `--private` (private workspace skills only) instead of
16
+ failing with "unknown option". They already took each skill back to its own source without it.
17
+
18
+ ## 0.4.0
19
+
20
+ **Private skills, separate from the public library.**
21
+
22
+ - `skills search | info | install --private [--workspace <id>]` read your workspace's own skills (the
23
+ custom skills in the app's Skills Library) from the app API with your API key. The workspace is
24
+ `--workspace`, else the one saved with `insightfulpipe use`. Without `--private`, every command uses
25
+ only the public catalogue on insightfulpipe.com, with no key. Neither ever falls back to the other.
26
+ - A private skill is named by its folder name or its key (`custom-123`); a name two private skills
27
+ share must be given by key. It goes through the same checks as a public one (checksums, version,
28
+ safe paths, staging folder), and a refusal says to fix the skill in the Skills Library.
29
+ - Installed skills record their origin: public, or private with its key and workspace. `list` and
30
+ `update` take each one back to its own source; markers from 0.3.x count as public. When the app
31
+ refuses a private check (no key, no access, lapsed subscription), that row fails on its own and the
32
+ others still list and update.
33
+ - An install never silently replaces a different skill in the same folder (public over private,
34
+ or another private skill with the same name): it refuses unless `--force`. Two skills chosen in one
35
+ `install` that share a folder name never overwrite each other, even with `--force`.
36
+ - Private list entries whose name or key is not plain are dropped, like public ones.
37
+ - Requests to the app API no longer follow redirects. A 3xx is an error that names where it pointed
38
+ and says to set `INSIGHTFULPIPE_API_URL` to the final address; the server answered, so it is not
39
+ reported as `outcome_unknown`.
40
+ - Token whitespace is trimmed the way the app's header parser does (including no-break and other
41
+ Unicode spaces), not just spaces, tabs and line breaks.
42
+ - A private skill renamed in the Skills Library is left in place by `update`, with the command that
43
+ installs it under its new name.
44
+ - **Only your own private installs are trusted.** Each private install is recorded under
45
+ `~/.insightfulpipe/private-skills/` (one file per folder, readable by you only) with its real folder,
46
+ key, workspace and name. A private marker that record does not name, such as one that came with a
47
+ cloned repository, a folder that was moved, or a marker whose key was changed, is listed with
48
+ `trusted: false` and is never checked, updated or sent for; install it again with
49
+ `--private --force` to use it. `remove` clears the record entry. Of such a marker only its plain
50
+ folder name is ever printed, and folders whose names are not plain are not listed at all.
51
+ - Private errors keep the app's HTTP status in the JSON (`http_status`). `--workspace` without
52
+ `--private` is refused instead of ignored. A `--dir` spelled in another case on macOS or Windows is
53
+ the same folder. The command suggested for a renamed private skill keeps `--project` or `--dir`.
54
+ - A private skill in a project folder (`--project`, `--dir`) carries a warning to keep it out of
55
+ shared repositories. `download --private` is not available yet: use Download in the Skills Library.
56
+ - Bundled file names may contain single spaces (`Brand guide.md`). Still ASCII only, never at either
57
+ end, and `con .txt` and the like are refused like the other Windows device names.
58
+
59
+ ## 0.3.1
60
+
61
+ - Spaces and line breaks around an API token are dropped wherever it comes from (environment
62
+ variable, keychain, config file, or `auth`), as `fetch` already did when sending it.
63
+ - A token with a space, line break, control character or non-ASCII letter inside it is refused
64
+ before any request is made, and the message says why (the token is never echoed). Before, some of
65
+ those characters failed only once the request had started, and a write was then reported as
66
+ `outcome_unknown` although nothing had been sent. `auth` refuses to save such a token, and `doctor`
67
+ reports it with its source instead of failing.
68
+ - "Network unreachable" and "host unreachable" count as a request never sent only when they happen
69
+ while connecting. The same codes later in a request now report `outcome_unknown`, like any other
70
+ failure after the request may have arrived.
71
+ - `skills list` reports `"status": "partial"` when a skill folder could not be checked, matching its
72
+ exit code 1 and what `install` and `update` already do.
73
+
3
74
  ## 0.3.0
4
75
 
5
76
  **`insightfulpipe skills`: install InsightfulPipe skills from the terminal.** Modelled on
package/README.md CHANGED
@@ -80,9 +80,32 @@ project with `--project`, or any folder with `--dir`:
80
80
  | `cursor` | `~/.cursor/skills` | `.agents/skills` |
81
81
  | `gemini-cli` | `~/.gemini/skills` | `.agents/skills` |
82
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, so they need no flag;
96
+ add `--private` to `list`, `update` or `remove` to act on private skills only
97
+ (`insightfulpipe skills update --all --private`). Private skills go to
98
+ your personal skills folder by default; installing one with `--project` or `--dir` prints a warning to
99
+ keep it out of shared repositories. Only private skills you installed are trusted: each install is
100
+ recorded under `~/.insightfulpipe/private-skills/`, and a private skill folder that record does not
101
+ name (one that came with a cloned repository, or that was moved) is listed but never checked or
102
+ updated. To use it, install it again with `--private --force`. `--workspace` without `--private` is
103
+ refused. `download` is for public skills; for a private one, use Download in
104
+ the Skills Library.
105
+
83
106
  Every file is checked against its sha256 before anything is written, and each installed skill keeps
84
107
  a `.insightfulpipe-skill.json` marker. `list`, `update` and `remove` only touch folders that carry it,
85
- and `update` will not overwrite files you edited unless you add `--force`. The catalogue never
108
+ and `update` will not overwrite files you edited unless you add `--force`. The public catalogue never
86
109
  receives your API token. `INSIGHTFULPIPE_SKILLS_URL` can point the commands at a staging copy on an
87
110
  insightfulpipe.com subdomain or at localhost (for testing); any other host is refused.
88
111
 
@@ -166,8 +189,15 @@ Output is **JSON by default** — it is read by scripts and agents far more ofte
166
189
  ```bash
167
190
  insightfulpipe accounts # JSON
168
191
  insightfulpipe accounts --table # aligned columns
192
+ insightfulpipe query google-analytics -b '{…}' --table # one column per field
169
193
  ```
170
194
 
195
+ Under `--table`, the rows of a `query`, `action` or `raw` result print as columns, and a single record
196
+ as field and value. Long values are shortened (the JSON has them in full), and control characters in
197
+ the data are shown escaped. Footers state a partial failure and the server's message, say when the
198
+ server has more rows or sent errors, warnings or notes, and name any field the table leaves out.
199
+ `helper --actions` stays JSON, since that is the body you copy into `-b`.
200
+
171
201
  `--json` is still accepted and does nothing, so existing scripts and docs keep working. Errors follow
172
202
  the same rule: `{"status":"error","message":"…"}` on stderr, or a plain sentence under `--table`.
173
203
  Either way they go to stderr and exit 1, so `insightfulpipe … | jq` is never polluted.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "insightfulpipe",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "InsightfulPipe CLI \u2014 query your marketing data from the terminal",
5
5
  "bin": {
6
6
  "insightfulpipe": "bin/cli.js"
package/src/api.js CHANGED
@@ -1,19 +1,14 @@
1
1
  import { bounded, fail } from './cli/errors.js';
2
- import { getApiUrl, getRequestTimeoutMs, getToken } from './config.js';
2
+ import { getApiUrl, getRequestTimeoutMs, getToken, tokenProblem } from './config.js';
3
3
  import { readBody, USER_AGENT } from './http.js';
4
4
 
5
5
  let _insecureWarned = false;
6
6
  // Far above any real error body; past it the body is dropped unread instead of held in memory.
7
7
  const MAX_ERROR_BYTES = 10 * 1024 * 1024;
8
8
  // Failures before a request could reach the server: nothing can have been written.
9
- const NOT_SENT_CODES = new Set([
10
- 'ECONNREFUSED',
11
- 'ENOTFOUND',
12
- 'EAI_AGAIN',
13
- 'ENETUNREACH',
14
- 'EHOSTUNREACH',
15
- 'UND_ERR_CONNECT_TIMEOUT',
16
- ]);
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']);
17
12
  // Certificate checks happen in the handshake, before any request byte is sent.
18
13
  const TLS_FAILURE = /^(CERT_|UNABLE_TO_|ERR_TLS_CERT_)|SELF_SIGNED/;
19
14
 
@@ -39,6 +34,10 @@ function requireAuth() {
39
34
  if (!token) {
40
35
  fail('Not authenticated.', 'Run: insightfulpipe auth');
41
36
  }
37
+ const problem = tokenProblem(token);
38
+ if (problem) {
39
+ fail(problem, 'Check INSIGHTFULPIPE_TOKEN if you set it, or run: insightfulpipe auth');
40
+ }
42
41
  return token;
43
42
  }
44
43
 
@@ -103,12 +102,23 @@ function parseJsonResponse(text, res) {
103
102
  }
104
103
  }
105
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
+
106
112
  /** A request that failed once it may have reached the server is an unknown outcome, never a refusal:
107
113
  * a write can land even though no complete answer came back, so a script must not simply resend it. */
108
114
  function unanswered(error, res, timeoutMs, method) {
109
115
  const cause = error?.cause?.code;
110
116
  const notBuilt = !res && error?.name === 'TypeError' && !error.cause;
111
- const refused = NOT_SENT_CODES.has(cause) || TLS_FAILURE.test(cause ?? '') || error?.cause?.message === 'bad port';
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';
112
122
  const neverSent = notBuilt || (!res && refused);
113
123
  let message;
114
124
  if (error?.name === 'AbortError') {
@@ -128,6 +138,17 @@ function unanswered(error, res, timeoutMs, method) {
128
138
  };
129
139
  }
130
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
+
131
152
  /** One request under the shared timeout. An error body is read under that timeout and capped; a success
132
153
  * body has no size or total-time cap (query results are never cut), only an idle timeout, so a stalled
133
154
  * server still cannot hold the command open. Every non-2xx result carries its HTTP status. */
@@ -138,7 +159,11 @@ async function send(url, options, timeoutMs) {
138
159
  let res;
139
160
  let raw;
140
161
  try {
141
- res = await fetch(url, { ...options, signal: controller.signal });
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
+ }
142
167
  if (res.ok) {
143
168
  clearTimeout(timeout);
144
169
  }
@@ -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,6 +1,6 @@
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
- import { printJson, printTable, wantsJson } from '../../output.js';
3
+ import { printJson, printJsonForHumans, printResult, printTable, say, wantsJson } from '../../output.js';
4
4
  import {
5
5
  buildQueryString,
6
6
  parseIdList,
@@ -29,14 +29,14 @@ export function registerDiscoveryCommands(program) {
29
29
  return;
30
30
  }
31
31
 
32
- console.log(`User: ${data.user.email}`);
33
- console.log(`Name: ${data.user.full_name || '-'}`);
34
- console.log(`Workspaces: ${data.total_workspaces}`);
32
+ say(`User: ${data.user.email}`);
33
+ say(`Name: ${data.user.full_name || '-'}`);
34
+ say(`Workspaces: ${data.total_workspaces}`);
35
35
  for (const workspace of data.workspaces || []) {
36
36
  const subscription = workspace.subscription || {};
37
37
  const planName = subscription.plan_name || '-';
38
38
  const planStatus = subscription.status || (subscription.is_active ? 'active' : '-');
39
- console.log(` - ${workspace.name} (${workspace.role}; ${planName}; ${planStatus})`);
39
+ say(` - ${workspace.name} (${workspace.role}; ${planName}; ${planStatus})`);
40
40
  }
41
41
  });
42
42
 
@@ -210,10 +210,19 @@ export function registerDiscoveryCommands(program) {
210
210
  .argument('<platform>', 'Platform slug (e.g., google-analytics)')
211
211
  .description('Show available actions and schema for a platform')
212
212
  .option('-a, --actions <actions>', 'Comma-separated action names')
213
- .action(async (platform, opts) => {
213
+ .action(async (platform, opts, command) => {
214
214
  const actions = opts.actions ? opts.actions.split(',').map((value) => value.trim()).filter(Boolean) : undefined;
215
215
  const data = await fetchHelperPayload(platform, actions);
216
- printJson(data);
216
+ if (!actions) {
217
+ printResult(data, command, 'actions');
218
+ return;
219
+ }
220
+ if (wantsJson(command)) {
221
+ printJson(data);
222
+ return;
223
+ }
224
+ console.error('Request templates stay JSON under --table, so you can copy the body into -b.');
225
+ printJsonForHumans(data);
217
226
  });
218
227
 
219
228
  program
@@ -247,7 +256,7 @@ export function registerDiscoveryCommands(program) {
247
256
  printJson(data);
248
257
  return;
249
258
  }
250
- console.log(data.prompt_detail || '');
259
+ say(data.prompt_detail || '');
251
260
  return;
252
261
  }
253
262
 
@@ -263,7 +272,7 @@ export function registerDiscoveryCommands(program) {
263
272
  printJson(data);
264
273
  return;
265
274
  }
266
- console.log(data.prompt_detail || '');
275
+ say(data.prompt_detail || '');
267
276
  return;
268
277
  }
269
278
 
@@ -296,6 +305,7 @@ export function registerDiscoveryCommands(program) {
296
305
  .action(async (opts, command) => {
297
306
  const snapshot = getConfigSnapshot();
298
307
  const token = getToken();
308
+ const problem = token ? tokenProblem(token) : null;
299
309
  const checks = [
300
310
  {
301
311
  name: 'api_url',
@@ -305,8 +315,8 @@ export function registerDiscoveryCommands(program) {
305
315
  },
306
316
  {
307
317
  name: 'token',
308
- status: token ? 'ok' : 'error',
309
- details: token ? 'Configured' : 'Missing',
318
+ status: token && !problem ? 'ok' : 'error',
319
+ details: !token ? 'Missing' : problem || 'Configured',
310
320
  source: snapshot.sources.token,
311
321
  },
312
322
  {
@@ -319,10 +329,10 @@ export function registerDiscoveryCommands(program) {
319
329
 
320
330
  let connectivity = {
321
331
  status: 'skipped',
322
- details: 'Skipped because no token is configured.',
332
+ details: problem ? 'Skipped because the token cannot be sent.' : 'Skipped because no token is configured.',
323
333
  };
324
334
 
325
- if (token) {
335
+ if (token && !problem) {
326
336
  const data = await apiGet('/user-info/');
327
337
  if (data?.error) {
328
338
  connectivity = {
@@ -348,11 +358,11 @@ export function registerDiscoveryCommands(program) {
348
358
  if (wantsJson(command)) {
349
359
  printJson(payload);
350
360
  } else {
351
- console.log(`Config file: ${payload.config_file}`);
361
+ say(`Config file: ${payload.config_file}`);
352
362
  for (const item of payload.checks) {
353
- console.log(`${item.name}: ${item.status} (${item.details}; ${item.source})`);
363
+ say(`${item.name}: ${item.status} (${item.details}; ${item.source})`);
354
364
  }
355
- console.log(`connectivity: ${payload.connectivity.status} (${payload.connectivity.details})`);
365
+ say(`connectivity: ${payload.connectivity.status} (${payload.connectivity.details})`);
356
366
  }
357
367
 
358
368
  if (status === 'error') {
@@ -1,6 +1,6 @@
1
1
  import { apiPost } from '../../api.js';
2
2
  import { applyContextToBody } from '../../config.js';
3
- import { printJson } from '../../output.js';
3
+ import { printResult } from '../../output.js';
4
4
  import {
5
5
  confirmWriteAction,
6
6
  ensureJsonObject,
@@ -24,17 +24,17 @@ const SCOPE_OPTIONS = [
24
24
  ];
25
25
 
26
26
  export function registerExecutionCommands(program) {
27
- const readAction = async (platform, opts) => {
27
+ const readAction = async (platform, opts, command) => {
28
28
  const body = scopedBody(ensureJsonObject(await readJsonInput(opts, true), 'Request body'), opts);
29
29
  const data = handleApiError(await apiPost('/', withPlatform(platform, body)), { platform });
30
- printJson(data);
30
+ printResult(data, command);
31
31
  };
32
32
 
33
- const writeAction = async (platform, opts) => {
33
+ const writeAction = async (platform, opts, command) => {
34
34
  const body = scopedBody(ensureJsonObject(await readJsonInput(opts, true), 'Request body'), opts);
35
35
  await confirmWriteAction(platform, body, opts.yes);
36
36
  const data = handleApiError(await apiPost('/', withPlatform(platform, body)), { platform });
37
- printJson(data);
37
+ printResult(data, command);
38
38
  };
39
39
 
40
40
  program
@@ -83,9 +83,9 @@ export function registerExecutionCommands(program) {
83
83
  .option('-b, --body <json>', 'Request body as inline JSON')
84
84
  .option('-f, --file <path>', 'Request body from a JSON file')
85
85
  .description('Send a raw request to the universal dispatcher')
86
- .action(async (opts) => {
86
+ .action(async (opts, command) => {
87
87
  const body = ensureJsonObject(await readJsonInput(opts, true), 'Request body');
88
88
  const data = handleApiError(await apiPost('/', body), { platform: body.platform });
89
- printJson(data);
89
+ printResult(data, command);
90
90
  });
91
91
  }