@knolo/cli 6.2.7 → 6.2.8

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
@@ -19,8 +19,8 @@ reader.
19
19
 
20
20
  `knolo compose`, `knolo attest`, and `knolo verify-attestation` cite local
21
21
  Knowledge Images and write an attestation sidecar. This tree's `@knolo/cli`
22
- package file is `6.2.6` and depends on `@knolo/core` `^6.2.3` and
23
- `@knolo/exchange` `^0.1.0`. npm `latest` is `6.2.6`. `knolo kite` is in this
22
+ package file is `6.2.7` and depends on `@knolo/core` `^6.2.3` and
23
+ `@knolo/exchange` `^0.1.0`. npm `latest` is `6.2.7`. `knolo kite` is in this
24
24
  package and in that release. It is not in published `@knolo/cli@6.2.5`. `knolo exchange` hands
25
25
  a verified V5 image to another agent. Shipped configs keep `adopt: deny`.
26
26
  Discover reads a public advertisement and does not download a pack. They do
@@ -55,6 +55,9 @@ the host-supplied caller. An optional Cortex trace is verified against
55
55
  record and does not copy the cited image. Pass `--graph` when that trace
56
56
  records KAR evaluations. The checked graph is stored in the image. The
57
57
  command does not call a model and does not download an image.
58
+ `knolo research verify <image>` re-checks those stored records.
59
+ `--cited` supplies the cited bytes. Without them, digest mode says the
60
+ bytes were not supplied. `--require-material` fails when they are missing.
58
61
  `examples/skills/research-and-cite` and `examples/skills/share-findings`
59
62
  install with `knolo skill install`. See
60
63
  [Research packs](../../docs/guides/research-packs.md).
@@ -387,7 +390,7 @@ This ensures:
387
390
  ## 🗺 Roadmap
388
391
 
389
392
  The active roadmap is maintained in [`../../docs/ROADMAP.md`](../../docs/ROADMAP.md).
390
- The published npm release is `6.2.6`. This tree's package file is `6.2.6` and adds `knolo kite`. `@knolo/cli@6.2.5` does not include that command. The published release preserves the V4 CLI, keeps V5 verification,
393
+ The published npm release is `6.2.7`. This tree's package file is `6.2.7` and adds `knolo kite`. `@knolo/cli@6.2.5` does not include that command. The published release preserves the V4 CLI, keeps V5 verification,
391
394
  migration, diagnostics, and read-only Studio management, and adds offline
392
395
  composition, attestation, and `knolo cortex`. Cortex verification does not
393
396
  mean an answer is true.
package/bin/exchange.mjs CHANGED
@@ -4,17 +4,32 @@ import {
4
4
  importExchangeDirectory,
5
5
  inspectExchangeReceipt,
6
6
  loadExchangeConfig,
7
+ loadRelayConfig,
7
8
  publishExchangeOffer,
8
9
  pullExchangeOffer,
10
+ startExchangeRelay,
9
11
  startExchangeServer,
10
12
  } from '@knolo/exchange';
11
13
  import { registryApiUrl, resolveRegistryUrl } from './registry/config.mjs';
12
14
 
13
15
  export async function runExchangeCli(argv) {
14
16
  const { command, flags, positional } = parse(argv);
17
+ if (command === 'relay') {
18
+ if (!flags.config)
19
+ throw new Error('Usage: knolo exchange relay --config <relay.json>');
20
+ const relayConfig = loadRelayConfig(flags.config);
21
+ const server = await startExchangeRelay(relayConfig);
22
+ console.log(server.url);
23
+ await new Promise((resolve) => {
24
+ process.once('SIGINT', resolve);
25
+ process.once('SIGTERM', resolve);
26
+ });
27
+ await server.close();
28
+ return;
29
+ }
15
30
  if (!flags.config && command !== 'inspect' && command !== 'discover')
16
31
  throw new Error(
17
- 'Usage: knolo exchange <serve|offer|pull|export|import|adopt|discover|inspect> --config <exchange.json>'
32
+ 'Usage: knolo exchange <serve|offer|pull|export|import|adopt|discover|inspect|relay> --config <exchange.json>'
18
33
  );
19
34
  const config = flags.config ? loadExchangeConfig(flags.config) : undefined;
20
35
  const now = flags.now === undefined ? Date.now() : Number(flags.now);
@@ -39,13 +54,14 @@ export async function runExchangeCli(argv) {
39
54
  const imagePath = positional[0];
40
55
  if (!imagePath || !flags.to)
41
56
  throw new Error(
42
- 'Usage: knolo exchange offer <image.knolo> --to <peer> --config <exchange.json>'
57
+ 'Usage: knolo exchange offer <image.knolo> --to <peer> [--via <https-url>] --config <exchange.json>'
43
58
  );
44
59
  const published = await publishExchangeOffer(config, {
45
60
  imagePath,
46
61
  to: flags.to,
47
62
  now,
48
63
  ...(flags.ttl === undefined ? {} : { ttlMs: Number(flags.ttl) }),
64
+ ...(flags.via === undefined ? {} : { via: flags.via }),
49
65
  });
50
66
  console.log(published.offerId);
51
67
  return;
@@ -54,7 +70,7 @@ export async function runExchangeCli(argv) {
54
70
  const offerId = positional[0];
55
71
  if (!offerId || !flags.from)
56
72
  throw new Error(
57
- 'Usage: knolo exchange pull <offer-id> --from <peer> --config <exchange.json>'
73
+ 'Usage: knolo exchange pull <offer-id> --from <peer-or-https-url> --config <exchange.json>'
58
74
  );
59
75
  const pulled = await pullExchangeOffer(config, {
60
76
  offerId,
@@ -168,7 +184,7 @@ export async function runExchangeCli(argv) {
168
184
  return;
169
185
  }
170
186
  throw new Error(
171
- 'Usage: knolo exchange <serve|offer|pull|export|import|adopt|discover|inspect>'
187
+ 'Usage: knolo exchange <serve|offer|pull|export|import|adopt|discover|inspect|relay>'
172
188
  );
173
189
  }
174
190
 
@@ -195,7 +211,8 @@ function parse(argv) {
195
211
  arg === '--now' ||
196
212
  arg === '--out' ||
197
213
  arg === '--store' ||
198
- arg === '--registry'
214
+ arg === '--registry' ||
215
+ arg === '--via'
199
216
  ) {
200
217
  flags[arg.slice(2)] = argv[++i];
201
218
  } else if (arg.startsWith('--')) {
package/bin/knolo.mjs CHANGED
@@ -186,7 +186,7 @@ Commands:
186
186
  skill Create and share a Knolo skill pack
187
187
  research Package local research files into a V5 Knowledge Image
188
188
  setup Prepare a local index and print the hub next steps
189
- exchange Offer or pull a verified Knowledge Image from a peer
189
+ exchange Offer or pull a verified Knowledge Image from a peer or relay
190
190
  icp Scaffold and operate an ICP-native knowledge canister
191
191
 
192
192
  Global options:
@@ -228,7 +228,7 @@ function printCommandHelp(command) {
228
228
  cortex: 'Usage: knolo cortex <find|ask|explain|verify> [options]\n\nBounded evidence retrieval. The CLI does not call a model.\n\n knolo cortex find <image> --question "..." [--top-k 100] --out candidates.json\n knolo cortex ask <image> --question "..." [--graph file] [--plan plan.json] [--mode find_relevant] --out answer.cortex.json\n knolo cortex explain answer.cortex.json\n knolo cortex verify --image <image> --answer answer.cortex.json [--graph file]\n\nVerification recomputes the trace roots. It does not mean the answer is true. A KAR status of SATISFIED means evidence requirements were met. It does not mean a claim is proven.',
229
229
  kite: 'Usage: knolo kite <evaluate|verify> [options]\n\n knolo kite evaluate --image <image.knolo> --contract <contract.json> --rules <rules.json> [--completeness <file>] [--changes <file>] [--bounds <file>] [--graph <file>] [--as-of YYYY-MM-DD] [--out <result.json>] [--json]\n knolo kite verify --image <image.knolo> --contract <contract.json> --rules <rules.json> --certificate <certificate.json> [--completeness <file>] [--changes <file>] [--bounds <file>] [--graph <file>] [--as-of YYYY-MM-DD]\n\nEvaluation names unmet obligations and derives a verdict inside the declared changes. Verification recomputes that derivation. A certificate is an integrity check. It does not mean the claim is true. BOUND_EXCEEDED means the search did not finish and is not a certificate. This command ships in this package. It loads @knolo/core/kite.',
230
230
  research:
231
- 'Usage: knolo research package --question <text> --agent <id> --out <image.knolo> --source <file> [--source <file>] [--cite <image.knolo> --trace <answer.cortex.json> [--graph <file>]] [--json]\n\nPacks local files into one V5 Knowledge Image. --agent is the host-supplied caller. --cite and --trace are both required or both omitted. --graph is required when the trace contains KAR evaluations, and it is the same file knolo cortex verify would use. A trace is verified against --cite before any write. A failed check writes nothing. When --cite is set, the image stores a digest-bound composition record for that image and does not copy its bytes. When --graph is set, the checked graph is stored. The command does not call a model and does not download an image. A packed trace is an integrity check. It does not mean a claim is proven. SATISFIED means the trace evidence requirements were met.',
231
+ 'Usage: knolo research package --question <text> --agent <id> --out <image.knolo> --source <file> [--source <file>] [--cite <image.knolo> --trace <answer.cortex.json> [--graph <file>]] [--json]\n\nPacks local files into one V5 Knowledge Image. --agent is the host-supplied caller. --cite and --trace are both required or both omitted. --graph is required when the trace contains KAR evaluations, and it is the same file knolo cortex verify would use. A trace is verified against --cite before any write. A failed check writes nothing. When --cite is set, the image stores a digest-bound composition record for that image and does not copy its bytes. When --graph is set, the checked graph is stored. The command does not call a model and does not download an image. A packed trace is an integrity check. It does not mean a claim is proven. SATISFIED means the trace evidence requirements were met.\n\nUsage: knolo research verify <image.knolo> [--cited <file>]... [--require-material] [--json]\n\nVerifies the image roots, then re-checks a stored composition record, Cortex trace, and KAR graph with the existing verifiers. --cited supplies member bytes in member order. Without those bytes, digest mode succeeds and says the cited bytes were not supplied. --require-material fails when a member has no bytes. The command does not call a model and does not download an image. A verified trace is an integrity check. It does not mean a claim is proven. SATISFIED means evidence requirements were met.',
232
232
  flight: 'Usage: knolo flight <ingest|verify-log> [options]\n\n knolo flight ingest --events <events.json> --log <file> --out <image.knolo> [--json]\n knolo flight verify-log --image <image.knolo> --log <file> [--json]\n\ningest packs a flight-events-1 document into a V5 Knowledge Image. It hashes --log and writes nothing when the hash or byte length differs. verify-log hashes --log again and compares it with the flight-log object. It writes nothing. A missing flight-log object fails closed. Neither command decodes the log. log.format is ulog, dataflash, or rosbag2. A later KAR status of SATISFIED means evidence requirements were met. It does not mean a flight was safe, legal, or compliant.',
233
233
  setup: `Usage: knolo setup [--registry <url>] [--root <dir>] [--agent <id>] [--auto-rebuild] [--reset] [--skills <path>] [--managed-skills <path>] [--memory <path>] [--transcripts <path>]
234
234
 
@@ -244,23 +244,26 @@ Pass --agent to set the caller name. Pass --auto-rebuild to rebuild on the next
244
244
  Does not prompt. Does not install a pack or call the hub.
245
245
  A missing knolo-box is printed, and setup still exits 0.
246
246
  When more than one skill folder matches, pass --skills or --managed-skills.`,
247
- exchange: `Usage: knolo exchange <serve|offer|pull|export|import|adopt|discover|inspect> --config <exchange.json>
247
+ exchange: `Usage: knolo exchange <serve|offer|pull|export|import|adopt|discover|inspect|relay> --config <exchange.json>
248
248
 
249
249
  knolo exchange serve --config exchange.json
250
- knolo exchange offer <image.knolo> --to <peer> --config exchange.json
251
- knolo exchange pull <offer-id> --from <peer> --config exchange.json
250
+ knolo exchange offer <image.knolo> --to <peer> [--via <https-url>] --config exchange.json
251
+ knolo exchange pull <offer-id> --from <peer-or-https-url> --config exchange.json
252
252
  knolo exchange export <image.knolo> --to <peer> --out <dir> --config exchange.json
253
253
  knolo exchange import <dir> --config exchange.json
254
254
  knolo exchange adopt <receipt-id> --store <file> --home <dir> --config exchange.json
255
255
  knolo exchange discover <handle> [--registry <url>]
256
256
  knolo exchange inspect <receipt-id> --home <dir> [--config exchange.json]
257
+ knolo exchange relay --config relay.json
257
258
 
258
259
  Pull, export, and import do not call Knolo Hub and do not write knolo.lock.json.
259
260
  export writes offer.cbor and the image into a directory. import reads that
260
261
  directory. Receiving an image verifies SHA-256 and the V5 state root. It does
261
262
  not mount the image into a store or activate a skill. adopt opens a local
262
263
  store only when policy.adopt is allow. discover reads a public publisher
263
- advertisement and does not download pack bytes.`,
264
+ advertisement and does not download pack bytes. relay stores the offer and
265
+ the image so the sender can go offline. It does not verify, mount, or adopt,
266
+ and it is not Knolo Hub. offer --via uploads to that relay instead of serve.`,
264
267
  skill: `Usage: knolo skill <init|check|pack|publish|install|search|info|list>
265
268
 
266
269
  knolo skill init <name> [--dir <parent>]
package/bin/research.mjs CHANGED
@@ -19,7 +19,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
19
19
  const ACTOR = 'knolo-research';
20
20
  const AGENT = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
21
21
 
22
- const USAGE = `Usage: knolo research package --question <text> --agent <id> --out <image.knolo> --source <file> [--source <file>] [--cite <image.knolo> --trace <answer.cortex.json> [--graph <file>]] [--json]
22
+ const PACKAGE_USAGE = `Usage: knolo research package --question <text> --agent <id> --out <image.knolo> --source <file> [--source <file>] [--cite <image.knolo> --trace <answer.cortex.json> [--graph <file>]] [--json]
23
23
 
24
24
  Packs local files into one V5 Knowledge Image. --agent is the host-supplied caller.
25
25
  --cite and --trace are both required or both omitted. --graph is required when the
@@ -31,6 +31,17 @@ The command does not call a model and does not download an image.
31
31
  A packed trace is an integrity check. It does not mean a claim is proven.
32
32
  SATISFIED means the trace evidence requirements were met.`;
33
33
 
34
+ const VERIFY_USAGE = `Usage: knolo research verify <image.knolo> [--cited <file>]... [--require-material] [--json]
35
+
36
+ Verifies the image roots, then re-checks a stored composition record, Cortex trace,
37
+ and KAR graph with the existing verifiers. --cited supplies member bytes in member
38
+ order. Without those bytes, digest mode succeeds and says the cited bytes were not
39
+ supplied. --require-material fails when a member has no bytes. The command does not
40
+ call a model and does not download an image. A verified trace is an integrity check.
41
+ It does not mean a claim is proven. SATISFIED means evidence requirements were met.`;
42
+
43
+ const USAGE = `${PACKAGE_USAGE}\n\n${VERIFY_USAGE}`;
44
+
34
45
  export async function runResearchCli(argv) {
35
46
  if (
36
47
  argv.length === 0 ||
@@ -41,15 +52,25 @@ export async function runResearchCli(argv) {
41
52
  console.log(USAGE);
42
53
  return;
43
54
  }
44
- if (argv[0] !== 'package') {
45
- throw new Error(`Unknown research command "${argv[0]}".\n${USAGE}`);
55
+ if (argv[0] === 'package') {
56
+ const flags = parseFlags(argv.slice(1));
57
+ if (flags.help) {
58
+ console.log(PACKAGE_USAGE);
59
+ return;
60
+ }
61
+ await packageResearch(flags);
62
+ return;
46
63
  }
47
- const flags = parseFlags(argv.slice(1));
48
- if (flags.help) {
49
- console.log(USAGE);
64
+ if (argv[0] === 'verify') {
65
+ const flags = parseVerifyFlags(argv.slice(1));
66
+ if (flags.help) {
67
+ console.log(VERIFY_USAGE);
68
+ return;
69
+ }
70
+ await verifyResearch(flags);
50
71
  return;
51
72
  }
52
- await packageResearch(flags);
73
+ throw new Error(`Unknown research command "${argv[0]}".\n${USAGE}`);
53
74
  }
54
75
 
55
76
  async function packageResearch(flags) {
@@ -202,6 +223,211 @@ async function packageResearch(flags) {
202
223
  );
203
224
  }
204
225
 
226
+ async function verifyResearch(flags) {
227
+ if (!flags.image) {
228
+ throw new Error(`RESEARCH_PACK_INVALID: pass the research image.\n${VERIFY_USAGE}`);
229
+ }
230
+ const bytes = readBounded(flags.image, KAR_CLI_MAX_IMAGE_BYTES);
231
+ const apis = await loadApis();
232
+ let verification;
233
+ try {
234
+ verification = apis.core.verifyKnowledgeImageV5(bytes);
235
+ } catch (error) {
236
+ const message = error instanceof Error ? error.message : String(error);
237
+ throw new Error(`KNOWLEDGE_IMAGE_INVALID: ${message}`);
238
+ }
239
+ if (!verification.valid) {
240
+ throw new Error('KNOWLEDGE_IMAGE_INVALID: Image roots do not verify.');
241
+ }
242
+ const image = apis.core.mountKnowledgeImageV5(bytes);
243
+ const packs = byRole(image, 'research-pack');
244
+ const traces = byRole(image, 'cortex-trace');
245
+ const compositions = byRole(image, 'composition');
246
+ const graphs = byRole(image, 'kar-graph');
247
+ if (packs.length !== 1) {
248
+ throw new Error('RESEARCH_PACK_INVALID: the image needs one research-pack object.');
249
+ }
250
+ const agent = packs[0].meta.agent;
251
+ if (typeof agent !== 'string' || !AGENT.test(agent)) {
252
+ throw new Error('RESEARCH_PACK_INVALID: the research pack has no caller.');
253
+ }
254
+ if (traces.length > 1 || compositions.length > 1 || graphs.length > 1) {
255
+ throw new Error('RESEARCH_PACK_INVALID: a research role is repeated.');
256
+ }
257
+ if (Boolean(traces.length) !== Boolean(compositions.length) || (graphs.length && !traces.length)) {
258
+ throw new Error('RESEARCH_PACK_INVALID: the citation, trace, and graph do not belong together.');
259
+ }
260
+
261
+ let members = [];
262
+ let citedBytesSupplied = false;
263
+ let compositionRoot = null;
264
+ const supplied = new Map();
265
+ if (compositions.length === 1) {
266
+ const record = parseJson(compositions[0].bytes, 'COMPOSITION_INVALID');
267
+ let parsed;
268
+ try {
269
+ parsed = apis.composition.parseCompositionRecord(record);
270
+ } catch (error) {
271
+ throw coded(error, 'COMPOSITION_INVALID');
272
+ }
273
+ if (compositions[0].meta.compositionRoot !== parsed.compositionRoot) {
274
+ throw new Error('COMPOSITION_ROOT_MISMATCH: Stored compositionRoot does not match the record.');
275
+ }
276
+ if (flags.cited.length > parsed.members.length) {
277
+ throw new Error('RESEARCH_PACK_INVALID: more --cited files than composition members.');
278
+ }
279
+ const material = {};
280
+ for (let index = 0; index < flags.cited.length; index += 1) {
281
+ const member = parsed.members[index];
282
+ const citedBytes = new Uint8Array(readBounded(flags.cited[index], KAR_CLI_MAX_IMAGE_BYTES));
283
+ material[member.alias] = { bytes: citedBytes };
284
+ supplied.set(member.alias, citedBytes);
285
+ }
286
+ citedBytesSupplied = flags.cited.length > 0;
287
+ const verdict = apis.composition.verifyCompositionRecord(record, {
288
+ members: material,
289
+ requireMaterial: flags.requireMaterial,
290
+ });
291
+ if (!verdict.ok) {
292
+ throw new Error(`${verdict.code}: composition check failed.`);
293
+ }
294
+ compositionRoot = verdict.compositionRoot;
295
+ members = verdict.members.map((status) => {
296
+ const member = parsed.members.find((item) => item.alias === status.alias);
297
+ return {
298
+ alias: status.alias,
299
+ status: status.status,
300
+ stateRoot: member && member.stateRoot ? member.stateRoot : null,
301
+ sha256: member && member.sha256 ? member.sha256 : null,
302
+ };
303
+ });
304
+ const cite = members.find((member) => member.alias === 'cite');
305
+ if (cite && compositions[0].meta.citedStateRoot !== cite.stateRoot) {
306
+ throw new Error('COMPOSITION_DIGEST_MISMATCH: Stored citedStateRoot does not match the record.');
307
+ }
308
+ } else if (flags.requireMaterial && flags.cited.length > 0) {
309
+ throw new Error('RESEARCH_PACK_INVALID: --cited was passed and the image has no composition record.');
310
+ } else if (flags.cited.length > 0) {
311
+ throw new Error('RESEARCH_PACK_INVALID: --cited was passed and the image has no composition record.');
312
+ }
313
+
314
+ let traceRoot = null;
315
+ let traceChecked = false;
316
+ let traceStatuses = [];
317
+ const citeBytes = supplied.get('cite');
318
+ if (traces.length === 1) {
319
+ const trace = parseJson(traces[0].bytes, 'CORTEX_TRACE_INVALID');
320
+ traceStatuses = Array.isArray(trace.karEvaluations)
321
+ ? trace.karEvaluations.map((item) => item && item.status).filter((status) => typeof status === 'string')
322
+ : [];
323
+ if (citeBytes) {
324
+ const graph = graphs.length === 1 ? parseJson(graphs[0].bytes, 'KAR_SIDECAR_INVALID') : undefined;
325
+ if (graph !== undefined) {
326
+ const kar = await loadKar();
327
+ try {
328
+ kar.createKarSession({ image: citeBytes, graph });
329
+ } catch (error) {
330
+ throw coded(error, 'KAR_GRAPH_INVALID');
331
+ }
332
+ }
333
+ const verified = await apis.cortex.verifyCortexAnswer({
334
+ image: citeBytes,
335
+ question: typeof trace.question === 'string' ? trace.question : '',
336
+ result: trace,
337
+ ...(graph === undefined ? {} : { graph }),
338
+ });
339
+ if (!verified.ok) throw new Error(`${verified.code}: ${verified.message}`);
340
+ if (traces[0].meta.traceRoot !== verified.traceRoot) {
341
+ throw new Error('CORTEX_ROOT_MISMATCH: Stored traceRoot does not match the trace.');
342
+ }
343
+ traceRoot = verified.traceRoot;
344
+ traceChecked = true;
345
+ } else {
346
+ traceRoot = typeof traces[0].meta.traceRoot === 'string' ? traces[0].meta.traceRoot : null;
347
+ }
348
+ }
349
+
350
+ let graphChecked = false;
351
+ if (graphs.length === 1) {
352
+ const graph = parseJson(graphs[0].bytes, 'KAR_SIDECAR_INVALID');
353
+ const kar = await loadKar();
354
+ if (citeBytes) {
355
+ if (!traceChecked) {
356
+ try {
357
+ kar.createKarSession({ image: citeBytes, graph });
358
+ } catch (error) {
359
+ throw coded(error, 'KAR_GRAPH_INVALID');
360
+ }
361
+ }
362
+ graphChecked = true;
363
+ } else {
364
+ const sidecar = kar.validateKarSidecar(graph);
365
+ if (!sidecar.ok) {
366
+ const issue = sidecar.errors[0];
367
+ throw new Error(`${issue.code}: ${issue.message}`);
368
+ }
369
+ }
370
+ }
371
+
372
+ const summary = {
373
+ ok: true,
374
+ stateRoot: verification.stateRoot,
375
+ sha256: digest(bytes),
376
+ agent,
377
+ compositionRoot,
378
+ citedBytesSupplied,
379
+ members,
380
+ traceRoot,
381
+ traceChecked,
382
+ traceStatuses,
383
+ graphChecked,
384
+ graphPresent: graphs.length === 1,
385
+ };
386
+ if (flags.json) {
387
+ console.log(JSON.stringify(summary, null, 2));
388
+ return;
389
+ }
390
+ const citedLines = members.length
391
+ ? members
392
+ .map((member) => `${member.alias} ${member.status} ${member.sha256} ${member.stateRoot}`)
393
+ .join('\n ')
394
+ : 'none';
395
+ const traceLine = !traces.length
396
+ ? 'none'
397
+ : traceChecked
398
+ ? `${traceRoot}${traceStatuses.length ? ` ${traceStatuses.join(',')}` : ''}`
399
+ : `${traceRoot ?? 'stored'} not re-checked`;
400
+ const graphLine = !graphs.length ? 'none' : graphChecked ? 'checked' : 'present, cited bytes were not supplied';
401
+ const digestNote =
402
+ compositions.length === 1 && !citedBytesSupplied
403
+ ? '\nCited bytes were not supplied.\n'
404
+ : '\n';
405
+ console.log(
406
+ `RESEARCH VERIFY\nstate root ${summary.stateRoot}\nfile sha256 ${summary.sha256}\nagent ${agent}\ncited ${citedLines}\ntrace ${traceLine}\ngraph ${graphLine}\n${digestNote}A verified trace is an integrity check. It does not mean a claim is proven.\nSATISFIED means evidence requirements were met.`
407
+ );
408
+ }
409
+
410
+ function byRole(image, role) {
411
+ return image.objects.filter((object) => object.meta && object.meta.role === role);
412
+ }
413
+
414
+ function parseJson(bytes, code) {
415
+ try {
416
+ return JSON.parse(new TextDecoder().decode(bytes));
417
+ } catch {
418
+ throw new Error(`${code}: stored JSON is not valid.`);
419
+ }
420
+ }
421
+
422
+ function coded(error, fallback) {
423
+ if (error && typeof error.code === 'string' && error.code.length > 0) {
424
+ return new Error(`${error.code}: ${error.message}`);
425
+ }
426
+ if (error instanceof Error && /^[A-Z0-9_]+:/.test(error.message)) return error;
427
+ const message = error instanceof Error ? error.message : String(error);
428
+ return new Error(`${fallback}: ${message}`);
429
+ }
430
+
205
431
  function writeNewFile(resolved, display, bytes) {
206
432
  try {
207
433
  writeFileSync(resolved, bytes, { flag: 'wx' });
@@ -260,6 +486,14 @@ function required(value, flag) {
260
486
  return value;
261
487
  }
262
488
 
489
+ async function loadKar() {
490
+ const dist = path.resolve(__dirname, '../../core/dist');
491
+ return importFirst(
492
+ [path.join(dist, 'experimental/kar/index.js'), '@knolo/core/experimental/kar'],
493
+ (loaded) => loaded.createKarSession && loaded.validateKarSidecar
494
+ );
495
+ }
496
+
263
497
  async function loadApis() {
264
498
  const dist = path.resolve(__dirname, '../../core/dist');
265
499
  const core = await importFirst(
@@ -292,6 +526,40 @@ async function importFirst(candidates, check) {
292
526
  throw new Error('Could not load @knolo/core. Build packages/core first.');
293
527
  }
294
528
 
529
+ function parseVerifyFlags(argv) {
530
+ const flags = { cited: [], help: false, json: false, requireMaterial: false, image: '' };
531
+ for (let index = 0; index < argv.length; index += 1) {
532
+ const arg = argv[index];
533
+ if (arg === '--help' || arg === '-h') {
534
+ flags.help = true;
535
+ continue;
536
+ }
537
+ if (arg === '--json') {
538
+ flags.json = true;
539
+ continue;
540
+ }
541
+ if (arg === '--require-material') {
542
+ flags.requireMaterial = true;
543
+ continue;
544
+ }
545
+ if (arg === '--cited') {
546
+ const value = argv[index + 1];
547
+ if (value === undefined || value.startsWith('--')) {
548
+ throw new Error('Missing value for --cited');
549
+ }
550
+ flags.cited.push(value);
551
+ index += 1;
552
+ continue;
553
+ }
554
+ if (arg.startsWith('--')) {
555
+ throw new Error(`Unknown option ${arg}.\n${VERIFY_USAGE}`);
556
+ }
557
+ if (flags.image) throw new Error(`Unexpected argument "${arg}".\n${VERIFY_USAGE}`);
558
+ flags.image = arg;
559
+ }
560
+ return flags;
561
+ }
562
+
295
563
  function parseFlags(argv) {
296
564
  const flags = { sources: [], help: false, json: false };
297
565
  for (let index = 0; index < argv.length; index += 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knolo/cli",
3
- "version": "6.2.7",
3
+ "version": "6.2.8",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "knolo": "bin/knolo.mjs"
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@knolo/core": "^6.2.3",
36
- "@knolo/exchange": "^0.1.0"
36
+ "@knolo/exchange": "^0.1.1"
37
37
  },
38
38
  "private": false
39
39
  }