@knolo/cli 6.2.5 → 6.2.6

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,9 @@ 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.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
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.5`. `knolo kite` is in this
24
+ package file. It is not in published `@knolo/cli@6.2.5`. `knolo exchange` hands
24
25
  a verified V5 image to another agent. Shipped configs keep `adopt: deny`.
25
26
  Discover reads a public advertisement and does not download a pack. They do
26
27
  not fetch Hub for that handoff. Verification
@@ -386,7 +387,7 @@ This ensures:
386
387
  ## 🗺 Roadmap
387
388
 
388
389
  The active roadmap is maintained in [`../../docs/ROADMAP.md`](../../docs/ROADMAP.md).
389
- The published npm release is `6.2.4`. It preserves the V4 CLI, keeps V5 verification,
390
+ The published npm release is `6.2.5`. This tree's package file is `6.2.6` and adds `knolo kite`. The published release preserves the V4 CLI, keeps V5 verification,
390
391
  migration, diagnostics, and read-only Studio management, and adds offline
391
392
  composition, attestation, and `knolo cortex`. Cortex verification does not
392
393
  mean an answer is true.
package/bin/kite.mjs ADDED
@@ -0,0 +1,199 @@
1
+ /**
2
+ * knolo kite evaluate | verify
3
+ *
4
+ * Replays a typed contract against a local V5 image.
5
+ * It does not call a model and it does not download an image.
6
+ * A certificate is an integrity check. It does not mean a claim is true.
7
+ */
8
+ import { existsSync, unlinkSync, writeFileSync } from 'node:fs';
9
+ import path from 'node:path';
10
+ import { fileURLToPath, pathToFileURL } from 'node:url';
11
+ import {
12
+ KAR_CLI_MAX_IMAGE_BYTES,
13
+ KAR_CLI_MAX_TEXT_BYTES,
14
+ readBounded,
15
+ } from './kar-limits.mjs';
16
+
17
+ const USAGE = `Usage: knolo kite <evaluate|verify> [options]
18
+
19
+ 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]
20
+ 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]
21
+
22
+ Evaluation names unmet obligations and derives a verdict inside the declared changes.
23
+ Verification recomputes that derivation.
24
+ A certificate is an integrity check. It does not mean the claim is true.
25
+ BOUND_EXCEEDED means the search did not finish and is not a certificate.`;
26
+
27
+ export async function runKiteCli(argv) {
28
+ if (
29
+ argv.length === 0 ||
30
+ argv[0] === 'help' ||
31
+ argv[0] === '--help' ||
32
+ argv[0] === '-h'
33
+ ) {
34
+ console.log(USAGE);
35
+ return;
36
+ }
37
+ const command = argv[0];
38
+ if (command !== 'evaluate' && command !== 'verify') {
39
+ throw new Error(`Unknown kite command "${command}".\n${USAGE}`);
40
+ }
41
+ const flags = parseFlags(argv.slice(1));
42
+ if (flags.help) {
43
+ console.log(USAGE);
44
+ return;
45
+ }
46
+ try {
47
+ if (command === 'evaluate') await evaluate(flags);
48
+ else await verify(flags);
49
+ } catch (error) {
50
+ if (
51
+ error &&
52
+ typeof error.code === 'string' &&
53
+ error.code.startsWith('KITE')
54
+ ) {
55
+ throw new Error(`${error.code}: ${error.message}`);
56
+ }
57
+ if (error && error.code === 'BOUND_EXCEEDED') {
58
+ throw new Error(`${error.code}: ${error.message}`);
59
+ }
60
+ throw error;
61
+ }
62
+ }
63
+
64
+ async function evaluate(flags) {
65
+ const api = await loadKite();
66
+ const session = createSession(api, flags);
67
+ const result = await api.evaluateKiteSession(session, optionsFrom(flags));
68
+ const body = `${JSON.stringify(result, null, 2)}\n`;
69
+ if (flags.out) writeNew(flags.out, body);
70
+ if (flags.json || !flags.out) {
71
+ if (flags.json) process.stdout.write(body);
72
+ else if (result.certificate) {
73
+ console.log(`${result.verdict} ${result.certificate.invarianceRoot}`);
74
+ } else console.log(result.verdict);
75
+ }
76
+ }
77
+
78
+ async function verify(flags) {
79
+ const api = await loadKite();
80
+ const certificate = readJson(required(flags.certificate, '--certificate'));
81
+ const verified = await api.verifyKiteCertificate({
82
+ ...inputFrom(flags),
83
+ ...optionsFrom(flags),
84
+ certificate,
85
+ });
86
+ if (!verified.ok) throw new Error(`${verified.code}: ${verified.message}`);
87
+ console.log(`ok ${verified.invarianceRoot}`);
88
+ }
89
+
90
+ function createSession(api, flags) {
91
+ return api.createKiteSession(inputFrom(flags));
92
+ }
93
+
94
+ function inputFrom(flags) {
95
+ const input = {
96
+ image: new Uint8Array(
97
+ readBounded(required(flags.image, '--image'), KAR_CLI_MAX_IMAGE_BYTES)
98
+ ),
99
+ contract: readJson(required(flags.contract, '--contract')),
100
+ rules: readJson(required(flags.rules, '--rules')),
101
+ };
102
+ if (flags.completeness) input.completeness = readJson(flags.completeness);
103
+ if (flags.changes) input.changes = readJson(flags.changes);
104
+ if (flags.bounds) input.bounds = readJson(flags.bounds);
105
+ if (flags.graph) input.graph = readJson(flags.graph);
106
+ return input;
107
+ }
108
+
109
+ function optionsFrom(flags) {
110
+ const options = {};
111
+ if (flags.question) options.question = flags.question;
112
+ if (flags.asOf) options.asOf = flags.asOf;
113
+ return options;
114
+ }
115
+
116
+ function readJson(file) {
117
+ const bytes = readBounded(file, KAR_CLI_MAX_TEXT_BYTES);
118
+ try {
119
+ return JSON.parse(new TextDecoder().decode(bytes));
120
+ } catch (error) {
121
+ throw new Error(
122
+ `KITE_CONTRACT_INVALID: ${path.basename(file)} is not JSON.`
123
+ );
124
+ }
125
+ }
126
+
127
+ function writeNew(file, body) {
128
+ const resolved = path.resolve(process.cwd(), file);
129
+ if (existsSync(resolved)) throw new Error(`Refusing to overwrite ${file}`);
130
+ try {
131
+ writeFileSync(resolved, body, { flag: 'wx' });
132
+ } catch (error) {
133
+ if (error && error.code !== 'EEXIST') {
134
+ try {
135
+ unlinkSync(resolved);
136
+ } catch {
137
+ // The file was not created.
138
+ }
139
+ }
140
+ throw error;
141
+ }
142
+ }
143
+
144
+ function hasKite(loaded) {
145
+ return Boolean(
146
+ loaded?.createKiteSession &&
147
+ loaded?.evaluateKiteSession &&
148
+ loaded?.verifyKiteCertificate
149
+ );
150
+ }
151
+
152
+ async function loadKite() {
153
+ const candidate = path.resolve(
154
+ path.dirname(fileURLToPath(import.meta.url)),
155
+ '../../core/dist/kite/index.js'
156
+ );
157
+ try {
158
+ const loaded = await import(pathToFileURL(candidate).href);
159
+ if (hasKite(loaded)) return loaded;
160
+ } catch {
161
+ // An installed package does not have the checkout dist path.
162
+ }
163
+ try {
164
+ const loaded = await import('@knolo/core/kite');
165
+ if (hasKite(loaded)) return loaded;
166
+ } catch {
167
+ // The package fallback is absent until core is installed.
168
+ }
169
+ throw new Error(
170
+ 'Could not load @knolo/core/kite. Build packages/core first.'
171
+ );
172
+ }
173
+
174
+ function required(value, name) {
175
+ if (!value) throw new Error(`Missing ${name}.\n${USAGE}`);
176
+ return value;
177
+ }
178
+
179
+ function parseFlags(args) {
180
+ const flags = {};
181
+ for (let index = 0; index < args.length; index += 1) {
182
+ const arg = args[index];
183
+ if (arg === '--help' || arg === '-h') flags.help = true;
184
+ else if (arg === '--json') flags.json = true;
185
+ else if (arg === '--image') flags.image = args[++index];
186
+ else if (arg === '--contract') flags.contract = args[++index];
187
+ else if (arg === '--rules') flags.rules = args[++index];
188
+ else if (arg === '--completeness') flags.completeness = args[++index];
189
+ else if (arg === '--changes') flags.changes = args[++index];
190
+ else if (arg === '--bounds') flags.bounds = args[++index];
191
+ else if (arg === '--graph') flags.graph = args[++index];
192
+ else if (arg === '--certificate') flags.certificate = args[++index];
193
+ else if (arg === '--as-of') flags.asOf = args[++index];
194
+ else if (arg === '--question') flags.question = args[++index];
195
+ else if (arg === '--out') flags.out = args[++index];
196
+ else throw new Error(`Unknown kite option "${arg}".\n${USAGE}`);
197
+ }
198
+ return flags;
199
+ }
package/bin/knolo.mjs CHANGED
@@ -77,6 +77,7 @@ const SUBCOMMANDS = new Set([
77
77
  'attest',
78
78
  'verify-attestation',
79
79
  'cortex',
80
+ 'kite',
80
81
  'flight',
81
82
  'skill',
82
83
  'setup',
@@ -180,6 +181,7 @@ Commands:
180
181
  compose Compose Knowledge Images, packs, and attestations offline
181
182
  attest Create or verify a composition attestation
182
183
  cortex Bounded evidence retrieval with a verifiable trace
184
+ kite Check a typed contract and replay its certificate
183
185
  flight Pack a flight-events-1 document into a V5 Knowledge Image
184
186
  skill Create and share a Knolo skill pack
185
187
  research Package local research files into a V5 Knowledge Image
@@ -224,6 +226,7 @@ function printCommandHelp(command) {
224
226
  compose: 'Usage: knolo compose <create|verify|excerpt|query> [options]\n\nOffline composition of Knowledge Images, packs, KAR sidecars, Domain Packs, and bounded excerpts.\n\n knolo compose create --members members.json --out composition/ [--host knowledge.knolo] [--availability material|digest] [--policy policy.json]\n knolo compose verify composition/ [--require-material] [--member alias=path]\n knolo compose excerpt --image knowledge.knolo --object <id> --out excerpt.json\n knolo compose query --composition composition/ --eql "FROM chunk SEARCH \\"valve\\"" [--question "..."] [--json]\n\ncompositionRoot does not change a V5 state root or a KAR root. statement used means a query or evaluation ran. It does not mean SATISFIED, and it does not mean a claim is true or false. Hub attested: true is a listing flag and is not an attestation root. The CLI does not fetch Hub.',
225
227
  attest: 'Usage: knolo attest <create|verify> [options]\n\n knolo attest create --composition composition/composition.json --subject composition --statement mount|used|cited --out attestation.json [--sign-key key.json --principal <id> --key-id <id> --issued-at <ms> --expires-at <ms>]\n knolo attest verify attestation.json [--composition composition.json] [--public-key key.json] [--now <ms>] [--content-only]\n\nstatement used means a query or KAR evaluation ran. It does not mean the claim is true or false. Hub attested: true is unrelated. Signing uses the supplied times. The CLI does not read the clock.',
226
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
+ 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.',
227
230
  research:
228
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.',
229
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.',
@@ -1938,6 +1941,10 @@ async function main() {
1938
1941
  const { runCortexCli } = await import('./cortex.mjs');
1939
1942
  return await runCortexCli(commandArgs);
1940
1943
  }
1944
+ if (command === 'kite') {
1945
+ const { runKiteCli } = await import('./kite.mjs');
1946
+ return await runKiteCli(commandArgs);
1947
+ }
1941
1948
  if (command === 'flight') {
1942
1949
  const { runFlightCli } = await import('./flight.mjs');
1943
1950
  return await runFlightCli(commandArgs);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knolo/cli",
3
- "version": "6.2.5",
3
+ "version": "6.2.6",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "knolo": "bin/knolo.mjs"
@@ -28,11 +28,11 @@
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 && 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 test/research.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 test/research.test.mjs test/kite.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.3",
36
36
  "@knolo/exchange": "^0.1.0"
37
37
  },
38
38
  "private": false
@@ -4,7 +4,7 @@
4
4
  mod closure;
5
5
  mod cover;
6
6
  mod evaluate;
7
- mod json;
7
+ pub(crate) mod json;
8
8
  mod model;
9
9
  mod session;
10
10