insightfulpipe 0.4.2 → 0.5.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 +128 -0
- package/README.md +35 -22
- package/package.json +1 -1
- package/src/cli/commands/skills.js +367 -144
- package/src/cli/program.js +2 -0
- package/src/output.js +6 -1
- package/src/skills/folders.js +129 -0
- package/src/skills/installer.js +33 -31
- package/src/skills/keys.js +21 -0
- package/src/skills/moves.js +87 -0
- package/src/skills/names.js +40 -0
- package/src/skills/private.js +33 -46
- package/src/skills/records.js +14 -4
- package/src/skills/sources.js +62 -34
package/src/skills/sources.js
CHANGED
|
@@ -1,26 +1,41 @@
|
|
|
1
1
|
import { fetchCatalog, fetchSkillFiles, getCatalogUrl, pageUrl, resolveSkill, skillKey } from './catalog.js';
|
|
2
2
|
import { validateBundle } from './installer.js';
|
|
3
|
+
import { categoryFor, keyType } from './keys.js';
|
|
4
|
+
import { installNameFor, resolveWorkspaceSkill } from './names.js';
|
|
3
5
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
validatePrivateBundle,
|
|
6
|
+
fetchWorkspaceCatalog,
|
|
7
|
+
fetchWorkspaceSkillFiles,
|
|
8
|
+
validateWorkspaceBundle,
|
|
9
|
+
workspaceIdFor,
|
|
10
|
+
workspaceSourceUrl,
|
|
10
11
|
} from './private.js';
|
|
11
12
|
|
|
12
|
-
/** Where skills come from:
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
/** Where skills come from: insightfulpipe.com with no key, or a workspace (its Public and Custom skills)
|
|
14
|
+
* from the app API with the user's key. A command uses exactly one source and never falls back to the
|
|
15
|
+
* other; an installed skill goes back to the source its marker names. */
|
|
15
16
|
|
|
16
17
|
/** Markers written before 0.4.0 have no origin, and every one of those is public. */
|
|
17
18
|
export function markerOrigin(marker) {
|
|
18
19
|
return marker?.origin === 'private' ? 'private' : 'public';
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
/** A
|
|
22
|
+
/** A workspace marker's own category is never shown: it may have come with a cloned repository. The prefix
|
|
23
|
+
* comes from the key's form alone, a fixed word; nothing else the marker claims is shown. */
|
|
22
24
|
export function markerLabel(marker) {
|
|
23
|
-
return markerOrigin(marker) === 'private'
|
|
25
|
+
return markerOrigin(marker) === 'private'
|
|
26
|
+
? `${categoryFor(keyType(marker.key))}/${marker.slug}`
|
|
27
|
+
: `${marker.category}/${marker.slug}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** `public` or `custom` for a workspace marker with a valid key, else null. */
|
|
31
|
+
export function markerType(marker) {
|
|
32
|
+
return markerOrigin(marker) === 'private' ? keyType(marker.key) : null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** What `list` calls a skill's origin: a Public workspace skill is never called private. */
|
|
36
|
+
export function listedOrigin(marker) {
|
|
37
|
+
if (markerOrigin(marker) === 'public') return 'public';
|
|
38
|
+
return markerType(marker) === 'public' ? 'workspace' : 'private';
|
|
24
39
|
}
|
|
25
40
|
|
|
26
41
|
function publicSource(catalog) {
|
|
@@ -28,6 +43,7 @@ function publicSource(catalog) {
|
|
|
28
43
|
catalog.skills.filter((other) => other.slug === skill.slug).length > 1 ? skillKey(skill) : skill.slug;
|
|
29
44
|
return {
|
|
30
45
|
origin: 'public',
|
|
46
|
+
noFiles: 'The public source has no files for this skill.',
|
|
31
47
|
skills: catalog.skills,
|
|
32
48
|
resolve: (name) => resolveSkill(name, catalog.skills),
|
|
33
49
|
find: (marker) => catalog.skills.find((skill) => skill.category === marker.category && skill.slug === marker.slug),
|
|
@@ -46,38 +62,50 @@ function publicSource(catalog) {
|
|
|
46
62
|
};
|
|
47
63
|
}
|
|
48
64
|
|
|
49
|
-
|
|
50
|
-
|
|
65
|
+
/** `sourceName` is what the JSON calls the source: `private` when the user typed `--private`, as in 0.4. */
|
|
66
|
+
function workspaceSourceFor(workspaceId, skills, sourceName) {
|
|
67
|
+
const installName = (skill) => installNameFor(skill, skills);
|
|
51
68
|
return {
|
|
52
69
|
origin: 'private',
|
|
70
|
+
sourceName,
|
|
53
71
|
workspaceId,
|
|
72
|
+
noFiles: `Workspace ${workspaceId} has no files for this skill.`,
|
|
54
73
|
skills,
|
|
55
|
-
resolve: (name) =>
|
|
74
|
+
resolve: (name) => resolveWorkspaceSkill(name, skills, workspaceId),
|
|
56
75
|
find: (marker) => skills.find((skill) => skill.key === marker.key),
|
|
57
|
-
files: (skill) =>
|
|
58
|
-
validate:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
files: (skill) => fetchWorkspaceSkillFiles(workspaceId, skill.key),
|
|
77
|
+
validate: validateWorkspaceBundle,
|
|
78
|
+
installName,
|
|
79
|
+
installOptions: (skill) => ({ origin: 'private', source: workspaceSourceUrl(), key: skill.key, workspaceId }),
|
|
80
|
+
summarize: (skill) => summarizeWorkspaceSkill(skill, installName(skill), workspaceId),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function summarizeWorkspaceSkill(skill, name, workspaceId) {
|
|
85
|
+
return {
|
|
86
|
+
skill: skill.slug,
|
|
87
|
+
key: skill.key,
|
|
88
|
+
type: skill.type,
|
|
89
|
+
category: skill.category,
|
|
90
|
+
name: skill.name,
|
|
91
|
+
description: skill.description ?? '',
|
|
92
|
+
data_source: skill.data_source || null,
|
|
93
|
+
version: skill.version ?? null,
|
|
94
|
+
install: `insightfulpipe skills install ${name} --workspace ${workspaceId}`,
|
|
95
|
+
page: null,
|
|
71
96
|
};
|
|
72
97
|
}
|
|
73
98
|
|
|
74
|
-
async function
|
|
75
|
-
return
|
|
99
|
+
async function openWorkspace(workspaceId, sourceName = 'workspace') {
|
|
100
|
+
return workspaceSourceFor(workspaceId, await fetchWorkspaceCatalog(workspaceId), sourceName);
|
|
76
101
|
}
|
|
77
102
|
|
|
78
|
-
/** The source a command was asked for: `--private`
|
|
103
|
+
/** The source a command was asked for: `--workspace`, or `--private` with it or the saved scope, else
|
|
104
|
+
* insightfulpipe.com. The saved scope alone never switches the source. */
|
|
79
105
|
export async function openSource(opts) {
|
|
80
|
-
return opts.private
|
|
106
|
+
return opts.private || opts.workspace !== undefined
|
|
107
|
+
? openWorkspace(workspaceIdFor(opts), opts.private ? 'private' : 'workspace')
|
|
108
|
+
: publicSource(await fetchCatalog());
|
|
81
109
|
}
|
|
82
110
|
|
|
83
111
|
function markerWorkspace(marker) {
|
|
@@ -89,8 +117,8 @@ function openForMarker(marker) {
|
|
|
89
117
|
if (markerOrigin(marker) === 'public') return openSource({});
|
|
90
118
|
const workspaceId = markerWorkspace(marker);
|
|
91
119
|
return workspaceId
|
|
92
|
-
?
|
|
93
|
-
: Promise.reject(new Error('Its marker names no workspace. Install it again with --
|
|
120
|
+
? openWorkspace(workspaceId)
|
|
121
|
+
: Promise.reject(new Error('Its marker names no workspace. Install it again with --workspace <id>.'));
|
|
94
122
|
}
|
|
95
123
|
|
|
96
124
|
/** Opens each installed skill's own source once per command; a source that failed fails each of its skills. */
|