insightfulpipe 0.3.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,61 @@
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
+
3
59
  ## 0.3.0
4
60
 
5
61
  **`insightfulpipe skills`: install InsightfulPipe skills from the terminal.** Modelled on
package/README.md CHANGED
@@ -80,9 +80,30 @@ 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. 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
+
83
104
  Every file is checked against its sha256 before anything is written, and each installed skill keeps
84
105
  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
106
+ and `update` will not overwrite files you edited unless you add `--force`. The public catalogue never
86
107
  receives your API token. `INSIGHTFULPIPE_SKILLS_URL` can point the commands at a staging copy on an
87
108
  insightfulpipe.com subdomain or at localhost (for testing); any other host is refused.
88
109
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "insightfulpipe",
3
- "version": "0.3.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"
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,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 {
@@ -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,10 +320,10 @@ 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 = {