@knolo/cli 6.2.2 → 6.2.4
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/README.md +17 -6
- package/bin/exchange.mjs +206 -0
- package/bin/knolo.mjs +34 -8
- package/bin/setup.mjs +43 -16
- package/bin/skill.mjs +50 -2
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @knolo/cli
|
|
2
2
|
|
|
3
|
+
`@knolo/cli` is how an agent publishes, pins, and installs shared knowledge.
|
|
4
|
+
Hub knowledge packs use `knolo publish` and `knolo add`. Skill packs use
|
|
5
|
+
`knolo skill pack`, `knolo skill publish`, and `knolo skill install`. The
|
|
6
|
+
pin is the digest. A receipt is an integrity check. It does not mean a
|
|
7
|
+
claim is proven.
|
|
8
|
+
|
|
3
9
|
The CLI preserves the Knolo V4 pack workflow and adds explicit V5 Knowledge
|
|
4
10
|
Image inspection and querying. Normal builds emit V4; the ICP legacy build path explicitly
|
|
5
11
|
emits V3 until the canister gains a V4 profile. V5 Studio output is a verified
|
|
@@ -13,8 +19,11 @@ reader.
|
|
|
13
19
|
|
|
14
20
|
`knolo compose`, `knolo attest`, and `knolo verify-attestation` cite local
|
|
15
21
|
Knowledge Images and write an attestation sidecar. This tree's `@knolo/cli`
|
|
16
|
-
package file is `6.2.
|
|
17
|
-
`latest` is `6.2.
|
|
22
|
+
package file is `6.2.4` and depends on `@knolo/core` `^6.2.0` and
|
|
23
|
+
`@knolo/exchange` `^0.1.0`. npm `latest` is `6.2.4`. `knolo exchange` hands
|
|
24
|
+
a verified V5 image to another agent. Shipped configs keep `adopt: deny`.
|
|
25
|
+
Discover reads a public advertisement and does not download a pack. They do
|
|
26
|
+
not fetch Hub for that handoff. Verification
|
|
18
27
|
recomputes `compositionRoot` and checks bundled excerpt bytes. A keyring key
|
|
19
28
|
must fall inside `notBefore`, `notAfter`, and `revokedAt`. `used` means a
|
|
20
29
|
query or evaluation ran. It does not mean `SATISFIED`, and it does not mean a
|
|
@@ -188,9 +197,11 @@ every `publisher/name`. `check` reads a source directory that contains
|
|
|
188
197
|
when `knolo-box` is on `PATH`. It scans `~/.grok` when that directory
|
|
189
198
|
exists, plus every `--root`. It does not require `~/.grok`. It always
|
|
190
199
|
includes `~/.knolo/skills`. An existing `~/.knolo/box/box.config.json` is
|
|
191
|
-
kept and rebuilt. `--reset` replaces it. `--agent
|
|
192
|
-
`--
|
|
193
|
-
|
|
200
|
+
kept and rebuilt. `--reset` replaces it. `--agent`, `--auto-rebuild`,
|
|
201
|
+
`--root`, and the scope paths merge into that file. `--root` may be the
|
|
202
|
+
parent of `agent-data`, or the `agent-data` directory itself. `--agent` sets
|
|
203
|
+
the caller name. `--auto-rebuild` turns on a rebuild at the next search.
|
|
204
|
+
Setup does not prompt,
|
|
194
205
|
install a pack, or call the hub. A missing `knolo-box` is one line, and
|
|
195
206
|
setup still exits 0. It prints the config path, `knolo skill install <publisher>/<name>`,
|
|
196
207
|
and `knolo-box mcp --config <path>`. The install path, auth, trust, and
|
|
@@ -359,7 +370,7 @@ This ensures:
|
|
|
359
370
|
## 🗺 Roadmap
|
|
360
371
|
|
|
361
372
|
The active roadmap is maintained in [`../../docs/ROADMAP.md`](../../docs/ROADMAP.md).
|
|
362
|
-
The published npm release is `6.2.
|
|
373
|
+
The published npm release is `6.2.4`. It preserves the V4 CLI, keeps V5 verification,
|
|
363
374
|
migration, diagnostics, and read-only Studio management, and adds offline
|
|
364
375
|
composition, attestation, and `knolo cortex`. Cortex verification does not
|
|
365
376
|
mean an answer is true.
|
package/bin/exchange.mjs
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import {
|
|
2
|
+
adoptExchangeReceipt,
|
|
3
|
+
exportExchangeDirectory,
|
|
4
|
+
importExchangeDirectory,
|
|
5
|
+
inspectExchangeReceipt,
|
|
6
|
+
loadExchangeConfig,
|
|
7
|
+
publishExchangeOffer,
|
|
8
|
+
pullExchangeOffer,
|
|
9
|
+
startExchangeServer,
|
|
10
|
+
} from '@knolo/exchange';
|
|
11
|
+
import { registryApiUrl, resolveRegistryUrl } from './registry/config.mjs';
|
|
12
|
+
|
|
13
|
+
export async function runExchangeCli(argv) {
|
|
14
|
+
const { command, flags, positional } = parse(argv);
|
|
15
|
+
if (!flags.config && command !== 'inspect' && command !== 'discover')
|
|
16
|
+
throw new Error(
|
|
17
|
+
'Usage: knolo exchange <serve|offer|pull|export|import|adopt|discover|inspect> --config <exchange.json>'
|
|
18
|
+
);
|
|
19
|
+
const config = flags.config ? loadExchangeConfig(flags.config) : undefined;
|
|
20
|
+
const now = flags.now === undefined ? Date.now() : Number(flags.now);
|
|
21
|
+
if (!Number.isSafeInteger(now))
|
|
22
|
+
throw new Error('V5 exchange --now must be an integer.');
|
|
23
|
+
if (command === 'serve') {
|
|
24
|
+
const truncateAfter = readTruncateHook();
|
|
25
|
+
const server = await startExchangeServer(config, {
|
|
26
|
+
...(flags.home ? { homeDir: flags.home } : {}),
|
|
27
|
+
...(flags.now === undefined ? {} : { now: () => now }),
|
|
28
|
+
...(truncateAfter === undefined ? {} : { truncateAfter }),
|
|
29
|
+
});
|
|
30
|
+
console.log(server.url);
|
|
31
|
+
await new Promise((resolve) => {
|
|
32
|
+
process.once('SIGINT', resolve);
|
|
33
|
+
process.once('SIGTERM', resolve);
|
|
34
|
+
});
|
|
35
|
+
await server.close();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (command === 'offer') {
|
|
39
|
+
const imagePath = positional[0];
|
|
40
|
+
if (!imagePath || !flags.to)
|
|
41
|
+
throw new Error(
|
|
42
|
+
'Usage: knolo exchange offer <image.knolo> --to <peer> --config <exchange.json>'
|
|
43
|
+
);
|
|
44
|
+
const published = await publishExchangeOffer(config, {
|
|
45
|
+
imagePath,
|
|
46
|
+
to: flags.to,
|
|
47
|
+
now,
|
|
48
|
+
...(flags.ttl === undefined ? {} : { ttlMs: Number(flags.ttl) }),
|
|
49
|
+
});
|
|
50
|
+
console.log(published.offerId);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (command === 'pull') {
|
|
54
|
+
const offerId = positional[0];
|
|
55
|
+
if (!offerId || !flags.from)
|
|
56
|
+
throw new Error(
|
|
57
|
+
'Usage: knolo exchange pull <offer-id> --from <peer> --config <exchange.json>'
|
|
58
|
+
);
|
|
59
|
+
const pulled = await pullExchangeOffer(config, {
|
|
60
|
+
offerId,
|
|
61
|
+
from: flags.from,
|
|
62
|
+
now,
|
|
63
|
+
...(flags.home ? { homeDir: flags.home } : {}),
|
|
64
|
+
...(flags.ttl === undefined ? {} : { ttlMs: Number(flags.ttl) }),
|
|
65
|
+
});
|
|
66
|
+
console.log(`cache: ${pulled.cachePath}`);
|
|
67
|
+
console.log(`sha256: ${pulled.sha256}`);
|
|
68
|
+
console.log(`stateRoot: ${pulled.stateRoot}`);
|
|
69
|
+
console.log(`receipt: ${pulled.receiptId}`);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (command === 'export') {
|
|
73
|
+
const imagePath = positional[0];
|
|
74
|
+
if (!imagePath || !flags.to || !flags.out)
|
|
75
|
+
throw new Error(
|
|
76
|
+
'Usage: knolo exchange export <image.knolo> --to <peer> --out <dir> --config <exchange.json>'
|
|
77
|
+
);
|
|
78
|
+
const exported = await exportExchangeDirectory(config, {
|
|
79
|
+
imagePath,
|
|
80
|
+
to: flags.to,
|
|
81
|
+
outDir: flags.out,
|
|
82
|
+
now,
|
|
83
|
+
...(flags.ttl === undefined ? {} : { ttlMs: Number(flags.ttl) }),
|
|
84
|
+
});
|
|
85
|
+
console.log(`directory: ${exported.directory}`);
|
|
86
|
+
console.log(`offer: ${exported.offerId}`);
|
|
87
|
+
console.log(`sha256: ${exported.sha256}`);
|
|
88
|
+
console.log(`stateRoot: ${exported.stateRoot}`);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (command === 'import') {
|
|
92
|
+
const directory = positional[0];
|
|
93
|
+
if (!directory)
|
|
94
|
+
throw new Error(
|
|
95
|
+
'Usage: knolo exchange import <dir> --config <exchange.json>'
|
|
96
|
+
);
|
|
97
|
+
const imported = await importExchangeDirectory(config, {
|
|
98
|
+
directory,
|
|
99
|
+
now,
|
|
100
|
+
...(flags.home ? { homeDir: flags.home } : {}),
|
|
101
|
+
});
|
|
102
|
+
console.log(`cache: ${imported.cachePath}`);
|
|
103
|
+
console.log(`sha256: ${imported.sha256}`);
|
|
104
|
+
console.log(`stateRoot: ${imported.stateRoot}`);
|
|
105
|
+
console.log(`receipt: ${imported.receiptId}`);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (command === 'adopt') {
|
|
109
|
+
const receiptId = positional[0];
|
|
110
|
+
if (!receiptId || !flags.store || !flags.home)
|
|
111
|
+
throw new Error(
|
|
112
|
+
'Usage: knolo exchange adopt <receipt-id> --store <file> --home <dir> --config <exchange.json>'
|
|
113
|
+
);
|
|
114
|
+
const adopted = await adoptExchangeReceipt(config, {
|
|
115
|
+
receiptId,
|
|
116
|
+
storePath: flags.store,
|
|
117
|
+
homeDir: flags.home,
|
|
118
|
+
now,
|
|
119
|
+
});
|
|
120
|
+
console.log(`store: ${adopted.storePath}`);
|
|
121
|
+
console.log(`relation: ${adopted.relation}`);
|
|
122
|
+
console.log(`stateRoot: ${adopted.stateRoot}`);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (command === 'discover') {
|
|
126
|
+
const handle = positional[0];
|
|
127
|
+
if (!handle || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(handle))
|
|
128
|
+
throw new Error(
|
|
129
|
+
'Usage: knolo exchange discover <handle> [--registry <url>]'
|
|
130
|
+
);
|
|
131
|
+
const registry = resolveRegistryUrl({ value: flags.registry });
|
|
132
|
+
const response = await fetch(
|
|
133
|
+
registryApiUrl(registry, ['publishers', handle])
|
|
134
|
+
);
|
|
135
|
+
if (!response.ok)
|
|
136
|
+
throw new Error(
|
|
137
|
+
`V5 exchange discover failed with status ${response.status}.`
|
|
138
|
+
);
|
|
139
|
+
const body = await response.json();
|
|
140
|
+
const exchange = body?.publisher?.exchange;
|
|
141
|
+
if (!Array.isArray(exchange) || exchange.length === 0)
|
|
142
|
+
throw new Error('V5 exchange advertisement is missing.');
|
|
143
|
+
for (const endpoint of exchange) {
|
|
144
|
+
console.log(`url: ${endpoint.url}`);
|
|
145
|
+
console.log(`keyId: ${endpoint.keyId}`);
|
|
146
|
+
console.log(`keyringRoot: ${endpoint.keyringRoot}`);
|
|
147
|
+
}
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (command === 'inspect') {
|
|
151
|
+
const receiptId = positional[0];
|
|
152
|
+
if (!receiptId || !flags.home)
|
|
153
|
+
throw new Error(
|
|
154
|
+
'Usage: knolo exchange inspect <receipt-id> --home <dir> [--config <exchange.json>]'
|
|
155
|
+
);
|
|
156
|
+
const receipt = await inspectExchangeReceipt(
|
|
157
|
+
flags.home,
|
|
158
|
+
receiptId,
|
|
159
|
+
config,
|
|
160
|
+
now
|
|
161
|
+
);
|
|
162
|
+
console.log(`role: ${receipt.role}`);
|
|
163
|
+
console.log(`offer: ${receipt.offerId}`);
|
|
164
|
+
console.log(`sha256: ${receipt.sha256}`);
|
|
165
|
+
console.log(`stateRoot: ${receipt.stateRoot}`);
|
|
166
|
+
console.log(`verification: ${receipt.verification}`);
|
|
167
|
+
console.log(`policy: ${receipt.policy}`);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
throw new Error(
|
|
171
|
+
'Usage: knolo exchange <serve|offer|pull|export|import|adopt|discover|inspect>'
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function readTruncateHook() {
|
|
176
|
+
const raw = process.env.KNOLO_EXCHANGE_TRUNCATE_AFTER;
|
|
177
|
+
if (raw === undefined || raw === '') return undefined;
|
|
178
|
+
const value = Number(raw);
|
|
179
|
+
if (!Number.isSafeInteger(value) || value < 1)
|
|
180
|
+
throw new Error('V5 exchange truncate hook is invalid.');
|
|
181
|
+
return value;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function parse(argv) {
|
|
185
|
+
const positional = [];
|
|
186
|
+
const flags = {};
|
|
187
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
188
|
+
const arg = argv[i];
|
|
189
|
+
if (
|
|
190
|
+
arg === '--config' ||
|
|
191
|
+
arg === '--to' ||
|
|
192
|
+
arg === '--from' ||
|
|
193
|
+
arg === '--home' ||
|
|
194
|
+
arg === '--ttl' ||
|
|
195
|
+
arg === '--now' ||
|
|
196
|
+
arg === '--out' ||
|
|
197
|
+
arg === '--store' ||
|
|
198
|
+
arg === '--registry'
|
|
199
|
+
) {
|
|
200
|
+
flags[arg.slice(2)] = argv[++i];
|
|
201
|
+
} else if (arg.startsWith('--')) {
|
|
202
|
+
throw new Error(`Unknown flag for exchange: ${arg}`);
|
|
203
|
+
} else positional.push(arg);
|
|
204
|
+
}
|
|
205
|
+
return { command: positional[0], positional: positional.slice(1), flags };
|
|
206
|
+
}
|
package/bin/knolo.mjs
CHANGED
|
@@ -80,6 +80,7 @@ const SUBCOMMANDS = new Set([
|
|
|
80
80
|
'flight',
|
|
81
81
|
'skill',
|
|
82
82
|
'setup',
|
|
83
|
+
'exchange',
|
|
83
84
|
]);
|
|
84
85
|
const ICP_SUBCOMMANDS = new Set([
|
|
85
86
|
'init',
|
|
@@ -181,6 +182,7 @@ Commands:
|
|
|
181
182
|
flight Pack a flight-events-1 document into a V5 Knowledge Image
|
|
182
183
|
skill Create and share a Knolo skill pack
|
|
183
184
|
setup Prepare a local index and print the hub next steps
|
|
185
|
+
exchange Offer or pull a verified Knowledge Image from a peer
|
|
184
186
|
icp Scaffold and operate an ICP-native knowledge canister
|
|
185
187
|
|
|
186
188
|
Global options:
|
|
@@ -225,13 +227,33 @@ function printCommandHelp(command) {
|
|
|
225
227
|
|
|
226
228
|
Resolves the hub the same way as the other hub commands.
|
|
227
229
|
Scans ~/.grok when that directory exists, plus every --root.
|
|
230
|
+
--root may be the parent of agent-data, or the agent-data directory itself.
|
|
228
231
|
Runs knolo-box init --tolerant, then knolo-box build --config.
|
|
229
232
|
Keeps an existing config and rebuilds it. Pass --reset to replace it.
|
|
233
|
+
--agent, --auto-rebuild, --root, and the scope paths merge into an existing config.
|
|
230
234
|
Always includes ~/.knolo/skills as a skills root.
|
|
235
|
+
When no skill folder is found, setup names the roots it scanned.
|
|
231
236
|
Pass --agent to set the caller name. Pass --auto-rebuild to rebuild on the next search.
|
|
232
237
|
Does not prompt. Does not install a pack or call the hub.
|
|
233
238
|
A missing knolo-box is printed, and setup still exits 0.
|
|
234
239
|
When more than one skill folder matches, pass --skills or --managed-skills.`,
|
|
240
|
+
exchange: `Usage: knolo exchange <serve|offer|pull|export|import|adopt|discover|inspect> --config <exchange.json>
|
|
241
|
+
|
|
242
|
+
knolo exchange serve --config exchange.json
|
|
243
|
+
knolo exchange offer <image.knolo> --to <peer> --config exchange.json
|
|
244
|
+
knolo exchange pull <offer-id> --from <peer> --config exchange.json
|
|
245
|
+
knolo exchange export <image.knolo> --to <peer> --out <dir> --config exchange.json
|
|
246
|
+
knolo exchange import <dir> --config exchange.json
|
|
247
|
+
knolo exchange adopt <receipt-id> --store <file> --home <dir> --config exchange.json
|
|
248
|
+
knolo exchange discover <handle> [--registry <url>]
|
|
249
|
+
knolo exchange inspect <receipt-id> --home <dir> [--config exchange.json]
|
|
250
|
+
|
|
251
|
+
Pull, export, and import do not call Knolo Hub and do not write knolo.lock.json.
|
|
252
|
+
export writes offer.cbor and the image into a directory. import reads that
|
|
253
|
+
directory. Receiving an image verifies SHA-256 and the V5 state root. It does
|
|
254
|
+
not mount the image into a store or activate a skill. adopt opens a local
|
|
255
|
+
store only when policy.adopt is allow. discover reads a public publisher
|
|
256
|
+
advertisement and does not download pack bytes.`,
|
|
235
257
|
skill: `Usage: knolo skill <init|check|pack|publish|install|search|info|list>
|
|
236
258
|
|
|
237
259
|
knolo skill init <name> [--dir <parent>]
|
|
@@ -1902,27 +1924,31 @@ async function main() {
|
|
|
1902
1924
|
return printCommandHelp(command);
|
|
1903
1925
|
if (command === 'kar') {
|
|
1904
1926
|
const { runKarCli } = await import('./kar.mjs');
|
|
1905
|
-
return runKarCli(commandArgs);
|
|
1927
|
+
return await runKarCli(commandArgs);
|
|
1906
1928
|
}
|
|
1907
1929
|
if (command === 'compose' || command === 'attest' || command === 'verify-attestation') {
|
|
1908
1930
|
const { runComposeCli } = await import('./compose.mjs');
|
|
1909
|
-
return runComposeCli(command, commandArgs);
|
|
1931
|
+
return await runComposeCli(command, commandArgs);
|
|
1910
1932
|
}
|
|
1911
1933
|
if (command === 'cortex') {
|
|
1912
1934
|
const { runCortexCli } = await import('./cortex.mjs');
|
|
1913
|
-
return runCortexCli(commandArgs);
|
|
1935
|
+
return await runCortexCli(commandArgs);
|
|
1914
1936
|
}
|
|
1915
1937
|
if (command === 'flight') {
|
|
1916
1938
|
const { runFlightCli } = await import('./flight.mjs');
|
|
1917
|
-
return runFlightCli(commandArgs);
|
|
1939
|
+
return await runFlightCli(commandArgs);
|
|
1918
1940
|
}
|
|
1919
1941
|
if (command === 'skill') {
|
|
1920
1942
|
const { runSkillCli } = await import('./skill.mjs');
|
|
1921
|
-
return runSkillCli(commandArgs);
|
|
1943
|
+
return await runSkillCli(commandArgs);
|
|
1944
|
+
}
|
|
1945
|
+
if (command === 'exchange') {
|
|
1946
|
+
const { runExchangeCli } = await import('./exchange.mjs');
|
|
1947
|
+
return await runExchangeCli(commandArgs);
|
|
1922
1948
|
}
|
|
1923
1949
|
if (command === 'setup') {
|
|
1924
1950
|
const { runKnoloSetup } = await import('./setup.mjs');
|
|
1925
|
-
return runKnoloSetup(commandArgs);
|
|
1951
|
+
return await runKnoloSetup(commandArgs);
|
|
1926
1952
|
}
|
|
1927
1953
|
if (command === 'init') return await cmdInit();
|
|
1928
1954
|
if (command === 'add') return await cmdAdd(commandArgs);
|
|
@@ -1931,8 +1957,8 @@ async function main() {
|
|
|
1931
1957
|
if (command === 'login') return await runHubLogin(commandArgs);
|
|
1932
1958
|
if (command === 'whoami') return await runHubWhoami(commandArgs);
|
|
1933
1959
|
if (command === 'logout') return await runHubLogout(commandArgs);
|
|
1934
|
-
if (command === 'publish') return runHubPublish(commandArgs);
|
|
1935
|
-
if (command === 'yank') return runHubYank(commandArgs);
|
|
1960
|
+
if (command === 'publish') return await runHubPublish(commandArgs);
|
|
1961
|
+
if (command === 'yank') return await runHubYank(commandArgs);
|
|
1936
1962
|
|
|
1937
1963
|
const core = await loadCore();
|
|
1938
1964
|
if (command === 'build') return await cmdBuild(core);
|
package/bin/setup.mjs
CHANGED
|
@@ -16,9 +16,12 @@ export const SETUP_HELP = `Usage: knolo setup [--registry <url>] [--root <dir>]
|
|
|
16
16
|
|
|
17
17
|
Resolves the hub the same way as the other hub commands.
|
|
18
18
|
Scans ~/.grok when that directory exists, plus every --root.
|
|
19
|
+
--root may be the parent of agent-data, or the agent-data directory itself.
|
|
19
20
|
Runs knolo-box init --tolerant, then knolo-box build --config.
|
|
20
21
|
Keeps an existing config and rebuilds it. Pass --reset to replace it.
|
|
22
|
+
--agent, --auto-rebuild, --root, and the scope paths merge into an existing config.
|
|
21
23
|
Always includes ~/.knolo/skills as a skills root.
|
|
24
|
+
When no skill folder is found, setup names the roots it scanned.
|
|
22
25
|
Pass --agent to set the caller name. Pass --auto-rebuild to rebuild on the next search.
|
|
23
26
|
Does not prompt. Does not install a pack or call the hub.
|
|
24
27
|
A missing knolo-box is printed, and setup still exits 0.
|
|
@@ -51,18 +54,16 @@ export async function runKnoloSetup(
|
|
|
51
54
|
for (const root of parsed.roots) roots.push(root);
|
|
52
55
|
|
|
53
56
|
const existing = await fileExists(configPath);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
`Config already exists: ${configPath}. Pass --reset to replace it.`
|
|
57
|
-
);
|
|
58
|
-
}
|
|
57
|
+
const hubPresent =
|
|
58
|
+
existing && (await configHasHubRoot(configPath, hubSkills, homeDir));
|
|
59
59
|
const replace = !existing || parsed.reset === true;
|
|
60
|
+
const merge = existing && !parsed.reset && (requestsNewConfig(parsed) || !hubPresent);
|
|
60
61
|
|
|
61
62
|
let built = false;
|
|
62
63
|
if (!box) {
|
|
63
64
|
printError('knolo-box is not on PATH. Skipping the local index.');
|
|
64
65
|
if (existing && !parsed.reset) printError('Kept the existing config.');
|
|
65
|
-
} else if (!replace) {
|
|
66
|
+
} else if (existing && !replace && !merge) {
|
|
66
67
|
const buildStatus = await spawnImpl(
|
|
67
68
|
box,
|
|
68
69
|
['build', '--config', configPath],
|
|
@@ -82,6 +83,8 @@ export async function runKnoloSetup(
|
|
|
82
83
|
'--hub-skills',
|
|
83
84
|
hubSkills,
|
|
84
85
|
];
|
|
86
|
+
if (parsed.reset && existing) initArgs.push('--force');
|
|
87
|
+
if (merge) initArgs.push('--merge');
|
|
85
88
|
for (const root of roots) initArgs.push('--root', root);
|
|
86
89
|
if (parsed.agent) initArgs.push('--agent', parsed.agent);
|
|
87
90
|
if (parsed.autoRebuild) initArgs.push('--auto-rebuild');
|
|
@@ -102,8 +105,13 @@ export async function runKnoloSetup(
|
|
|
102
105
|
throw new Error(`knolo-box build exited with status ${buildStatus}.`);
|
|
103
106
|
}
|
|
104
107
|
built = true;
|
|
105
|
-
if (
|
|
108
|
+
if (existing && !parsed.reset) printError('Kept the existing config.');
|
|
109
|
+
if ((await skillRootsBesideHub(configPath, hubSkills, homeDir)).length === 0) {
|
|
106
110
|
printError('No Grok skill folder was found.');
|
|
111
|
+
const scanned = roots.length > 0 ? roots.join(', ') : grokHome;
|
|
112
|
+
printError(
|
|
113
|
+
`Scanned ${scanned}. A root needs to contain agent-data or sand-data, or be the skill folder itself.`
|
|
114
|
+
);
|
|
107
115
|
}
|
|
108
116
|
}
|
|
109
117
|
|
|
@@ -217,7 +225,27 @@ async function directoryExists(candidate) {
|
|
|
217
225
|
}
|
|
218
226
|
}
|
|
219
227
|
|
|
220
|
-
async function
|
|
228
|
+
async function configHasHubRoot(configPath, hubSkills, homeDir) {
|
|
229
|
+
const roots = await skillRoots(configPath);
|
|
230
|
+
const hub = await canonicalDir(hubSkills);
|
|
231
|
+
for (const root of roots) {
|
|
232
|
+
if ((await canonicalDir(expandHome(root, homeDir))) === hub) return true;
|
|
233
|
+
}
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async function skillRootsBesideHub(configPath, hubSkills, homeDir) {
|
|
238
|
+
const roots = await skillRoots(configPath);
|
|
239
|
+
const hub = await canonicalDir(hubSkills);
|
|
240
|
+
const others = [];
|
|
241
|
+
for (const root of roots) {
|
|
242
|
+
if ((await canonicalDir(expandHome(root, homeDir))) === hub) continue;
|
|
243
|
+
others.push(root);
|
|
244
|
+
}
|
|
245
|
+
return others;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async function skillRoots(configPath) {
|
|
221
249
|
let config;
|
|
222
250
|
try {
|
|
223
251
|
config = JSON.parse(await readFile(configPath, 'utf8'));
|
|
@@ -226,14 +254,13 @@ async function skillRootsBesideHub(configPath, hubSkills) {
|
|
|
226
254
|
}
|
|
227
255
|
const roots = config?.scopes?.skills?.roots;
|
|
228
256
|
if (!Array.isArray(roots)) return [];
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return others;
|
|
257
|
+
return roots.filter((root) => typeof root === 'string' && root.length > 0);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function expandHome(input, homeDir) {
|
|
261
|
+
if (input === '~') return homeDir;
|
|
262
|
+
if (input.startsWith('~/')) return path.join(homeDir, input.slice(2));
|
|
263
|
+
return input;
|
|
237
264
|
}
|
|
238
265
|
|
|
239
266
|
async function canonicalDir(candidate) {
|
package/bin/skill.mjs
CHANGED
|
@@ -8,7 +8,17 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { spawn } from 'node:child_process';
|
|
10
10
|
import { createHash } from 'node:crypto';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
chmod,
|
|
13
|
+
lstat,
|
|
14
|
+
mkdir,
|
|
15
|
+
mkdtemp,
|
|
16
|
+
readdir,
|
|
17
|
+
readFile,
|
|
18
|
+
realpath,
|
|
19
|
+
rm,
|
|
20
|
+
writeFile,
|
|
21
|
+
} from 'node:fs/promises';
|
|
12
22
|
import { homedir, tmpdir } from 'node:os';
|
|
13
23
|
import path from 'node:path';
|
|
14
24
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
@@ -341,8 +351,19 @@ async function indexInstalledSkill(destRoot, flags) {
|
|
|
341
351
|
} catch {
|
|
342
352
|
config = null;
|
|
343
353
|
}
|
|
344
|
-
const roots = skillRootsFromConfig(config, env, home);
|
|
345
354
|
const dest = await canonicalDir(destRoot);
|
|
355
|
+
const hubSkills = path.resolve(path.join(home, '.knolo', 'skills'));
|
|
356
|
+
if (config && (await canonicalDir(hubSkills)) === dest) {
|
|
357
|
+
const added = await ensureHubSkillsRoot(configPath, config, dest, env, home);
|
|
358
|
+
if (added) {
|
|
359
|
+
try {
|
|
360
|
+
config = JSON.parse(await readFile(configPath, 'utf8'));
|
|
361
|
+
} catch {
|
|
362
|
+
config = null;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
const roots = skillRootsFromConfig(config, env, home);
|
|
346
367
|
let indexed = false;
|
|
347
368
|
for (const root of roots) {
|
|
348
369
|
if (typeof root !== 'string' || root.length === 0) continue;
|
|
@@ -370,6 +391,33 @@ async function indexInstalledSkill(destRoot, flags) {
|
|
|
370
391
|
}
|
|
371
392
|
}
|
|
372
393
|
|
|
394
|
+
async function ensureHubSkillsRoot(configPath, config, dest, env, home) {
|
|
395
|
+
const roots = skillRootsFromConfig(config, env, home);
|
|
396
|
+
for (const root of roots) {
|
|
397
|
+
if ((await canonicalDir(root)) === dest) return false;
|
|
398
|
+
}
|
|
399
|
+
const next = { ...config };
|
|
400
|
+
const scopes =
|
|
401
|
+
next.scopes && typeof next.scopes === 'object' && !Array.isArray(next.scopes)
|
|
402
|
+
? { ...next.scopes }
|
|
403
|
+
: {};
|
|
404
|
+
const skills =
|
|
405
|
+
scopes.skills && typeof scopes.skills === 'object' && !Array.isArray(scopes.skills)
|
|
406
|
+
? { ...scopes.skills }
|
|
407
|
+
: {};
|
|
408
|
+
const hadRoots = Array.isArray(skills.roots);
|
|
409
|
+
const prior = hadRoots
|
|
410
|
+
? skills.roots.filter((item) => typeof item === 'string' && item.length > 0)
|
|
411
|
+
: roots;
|
|
412
|
+
skills.roots = [...prior, dest];
|
|
413
|
+
scopes.skills = skills;
|
|
414
|
+
next.scopes = scopes;
|
|
415
|
+
await mkdir(path.dirname(configPath), { recursive: true, mode: 0o700 });
|
|
416
|
+
await writeFile(configPath, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
|
|
417
|
+
await chmod(configPath, 0o600);
|
|
418
|
+
return true;
|
|
419
|
+
}
|
|
420
|
+
|
|
373
421
|
function skillRootsFromConfig(config, env, home) {
|
|
374
422
|
if (!config || typeof config !== 'object' || Array.isArray(config)) return [];
|
|
375
423
|
const fallbackGrok = path.resolve(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knolo/cli",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"knolo": "bin/knolo.mjs"
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"bin/",
|
|
10
10
|
"templates/"
|
|
11
11
|
],
|
|
12
|
-
"description": "
|
|
12
|
+
"description": "Publish, pin, and install shared Knolo knowledge, including Hub packs and skills.",
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
@@ -28,11 +28,12 @@
|
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "node -e \"console.log('cli is executable via bin/knolo.mjs')\"",
|
|
31
|
-
"test": "npm run build --prefix ../core && node --test test/cli.test.mjs test/kar.test.mjs test/kar-graph.test.mjs test/kar-produce.test.mjs test/hub.integration.test.mjs test/compose.test.mjs test/cortex.test.mjs test/flight.test.mjs test/skill.test.mjs test/setup.test.mjs",
|
|
31
|
+
"test": "npm run build --prefix ../core && npm run build --prefix ../exchange && node --test test/cli.test.mjs test/kar.test.mjs test/kar-graph.test.mjs test/kar-produce.test.mjs test/hub.integration.test.mjs test/compose.test.mjs test/cortex.test.mjs test/flight.test.mjs test/skill.test.mjs test/setup.test.mjs test/exchange.test.mjs",
|
|
32
32
|
"test:hub": "node --test test/hub.integration.test.mjs"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@knolo/core": "^6.2.0"
|
|
35
|
+
"@knolo/core": "^6.2.0",
|
|
36
|
+
"@knolo/exchange": "^0.1.0"
|
|
36
37
|
},
|
|
37
38
|
"private": false
|
|
38
39
|
}
|