@knolo/cli 6.2.3 → 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 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.3` and depends on `@knolo/core` `^6.2.0`. npm
17
- `latest` is `6.2.2` until `6.2.3` is published. They do not fetch Hub. Verification
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
@@ -361,7 +370,7 @@ This ensures:
361
370
  ## 🗺 Roadmap
362
371
 
363
372
  The active roadmap is maintained in [`../../docs/ROADMAP.md`](../../docs/ROADMAP.md).
364
- The published npm release is `6.2.2`. This package file is `6.2.3` until that version is published. It preserves the V4 CLI, keeps V5 verification,
373
+ The published npm release is `6.2.4`. It preserves the V4 CLI, keeps V5 verification,
365
374
  migration, diagnostics, and read-only Studio management, and adds offline
366
375
  composition, attestation, and `knolo cortex`. Cortex verification does not
367
376
  mean an answer is true.
@@ -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:
@@ -235,6 +237,23 @@ Pass --agent to set the caller name. Pass --auto-rebuild to rebuild on the next
235
237
  Does not prompt. Does not install a pack or call the hub.
236
238
  A missing knolo-box is printed, and setup still exits 0.
237
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.`,
238
257
  skill: `Usage: knolo skill <init|check|pack|publish|install|search|info|list>
239
258
 
240
259
  knolo skill init <name> [--dir <parent>]
@@ -1923,6 +1942,10 @@ async function main() {
1923
1942
  const { runSkillCli } = await import('./skill.mjs');
1924
1943
  return await runSkillCli(commandArgs);
1925
1944
  }
1945
+ if (command === 'exchange') {
1946
+ const { runExchangeCli } = await import('./exchange.mjs');
1947
+ return await runExchangeCli(commandArgs);
1948
+ }
1926
1949
  if (command === 'setup') {
1927
1950
  const { runKnoloSetup } = await import('./setup.mjs');
1928
1951
  return await runKnoloSetup(commandArgs);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knolo/cli",
3
- "version": "6.2.3",
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": "CLI for Knolo V4 packs, V5 Knowledge Images, KAR evidence-set retrieval, and offline composition.",
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
  }