@aikdna/kdna-cli 0.17.0 → 0.19.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/src/diff.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * kdna diff <name>@<ver1> <name>@<ver2> — Judgment-level diff between versions.
3
3
  *
4
- * Downloads two .kdna packages from the registry, extracts to temp dirs,
4
+ * Downloads two .kdna dev packages from the registry, extracts to temp dirs,
5
5
  * compares axioms / misunderstandings / banned_terms / stances / boundary,
6
6
  * and surfaces what would change for an agent loading the new version.
7
7
  *
@@ -19,11 +19,10 @@
19
19
  const fs = require('fs');
20
20
  const path = require('path');
21
21
  const { execSync, execFileSync } = require('child_process');
22
- const { RegistryResolver, parseName } = require('./registry');
22
+ const { RegistryResolver } = require('./registry');
23
23
  const { EXIT } = require('./cmds/_common');
24
+ const { getInstalled, readContainer } = require('./package-store');
24
25
 
25
- const USER_KDNA_DIR = path.join(process.env.HOME || process.env.USERPROFILE || '.', '.kdna');
26
- const INSTALL_DIR = path.join(USER_KDNA_DIR, 'domains');
27
26
  const TMP_DIR = '/tmp';
28
27
 
29
28
  function error(msg, code = EXIT.VALIDATION_FAILED) {
@@ -58,14 +57,15 @@ function parseNameVersion(input) {
58
57
  // ─── Download specific version ────────────────────────────────────────
59
58
 
60
59
  function downloadVersion(entry, version, destDir) {
61
- // entry.kdna_url is for the registry-current version. For older versions
60
+ const assetUrl = entry.asset_url;
61
+ // assetUrl is for the registry-current version. For older versions
62
62
  // we infer the URL pattern from the registry-current URL.
63
63
  if (entry.version === version) {
64
- return downloadAndExtract(entry.kdna_url, destDir);
64
+ return downloadAndExtract(assetUrl, destDir);
65
65
  }
66
66
 
67
67
  // Infer pattern: replace v<current> in the URL with v<requested>
68
- const inferredUrl = entry.kdna_url
68
+ const inferredUrl = assetUrl
69
69
  .replace(`/v${entry.version}/`, `/v${version}/`)
70
70
  .replace(`-${entry.version}.kdna`, `-${version}.kdna`);
71
71
 
@@ -80,7 +80,10 @@ function downloadAndExtract(url, destDir) {
80
80
  stdio: 'pipe',
81
81
  });
82
82
  } catch (e) {
83
- error(`Failed to download ${url}: ${e.stderr?.toString().trim() || e.message}`, EXIT.PROVIDER_ERROR);
83
+ error(
84
+ `Failed to download ${url}: ${e.stderr?.toString().trim() || e.message}`,
85
+ EXIT.PROVIDER_ERROR,
86
+ );
84
87
  }
85
88
 
86
89
  fs.mkdirSync(destDir, { recursive: true });
@@ -232,19 +235,20 @@ async function cmdDiff(a, b, args = []) {
232
235
  newEntry = entryB;
233
236
  } else {
234
237
  // single-arg form: installed vs registry-current
235
- const parsed = parseName(aParsed.full);
236
- const localDir = path.join(INSTALL_DIR, parsed.scope, parsed.ident);
237
- if (!fs.existsSync(localDir)) {
238
+ const installed = getInstalled(aParsed.full);
239
+ if (!installed) {
238
240
  error(`${aParsed.full} not installed. Run: kdna install ${aParsed.full}`, EXIT.INPUT_ERROR);
239
241
  }
240
- const localManifest = readJson(path.join(localDir, 'kdna.json'));
242
+ const localManifest = readContainer(installed.asset_path).manifest || {};
241
243
  oldVersion = localManifest?.version || '?';
242
244
  newVersion = entryA.version;
243
245
  oldEntry = entryA;
244
246
  newEntry = entryA;
245
247
  if (oldVersion === newVersion) {
246
248
  if (jsonMode) {
247
- console.log(JSON.stringify({ error: `${aParsed.full}@${oldVersion}: only one version found.` }));
249
+ console.log(
250
+ JSON.stringify({ error: `${aParsed.full}@${oldVersion}: only one version found.` }),
251
+ );
248
252
  process.exit(EXIT.OK);
249
253
  }
250
254
  console.log(
@@ -284,8 +288,14 @@ async function cmdDiff(a, b, args = []) {
284
288
  );
285
289
  }
286
290
 
287
- const axiomsDiff = diffMaps('axioms', oldJ.axioms, newJ.axioms, (a) => a.one_sentence || a.id, jsonMode);
288
- const ontologyDiff = diffMaps('ontology', oldJ.ontology, newJ.ontology, (o) => o.one_sentence || o.id, jsonMode);
291
+ const axiomsDiff = diffMaps(
292
+ 'axioms',
293
+ oldJ.axioms,
294
+ newJ.axioms,
295
+ (a) => a.one_sentence || a.id,
296
+ jsonMode,
297
+ );
298
+ diffMaps('ontology', oldJ.ontology, newJ.ontology, (o) => o.one_sentence || o.id, jsonMode);
289
299
  const misunderstandingsDiff = diffMaps(
290
300
  'misunderstandings',
291
301
  oldJ.misunderstandings,
@@ -293,7 +303,13 @@ async function cmdDiff(a, b, args = []) {
293
303
  (m) => m.wrong || m.id,
294
304
  jsonMode,
295
305
  );
296
- const bannedDiff = diffMaps('banned_terms', oldJ.banned_terms, newJ.banned_terms, (t) => t.term || '', jsonMode);
306
+ const bannedDiff = diffMaps(
307
+ 'banned_terms',
308
+ oldJ.banned_terms,
309
+ newJ.banned_terms,
310
+ (t) => t.term || '',
311
+ jsonMode,
312
+ );
297
313
  const stancesDiff = diffStanceList(oldJ.stances, newJ.stances, jsonMode);
298
314
 
299
315
  // Cleanup
@@ -333,11 +349,7 @@ async function cmdDiff(a, b, args = []) {
333
349
  }));
334
350
 
335
351
  const affectedScenarios = axiomsDiff.changedDetails
336
- .filter(
337
- (d) =>
338
- d.boundary_changes.applies_when ||
339
- d.boundary_changes.does_not_apply_when,
340
- )
352
+ .filter((d) => d.boundary_changes.applies_when || d.boundary_changes.does_not_apply_when)
341
353
  .map((d) => ({
342
354
  axiom_id: d.id,
343
355
  applies_when: d.boundary_changes.applies_when || null,
@@ -345,14 +357,14 @@ async function cmdDiff(a, b, args = []) {
345
357
  }));
346
358
 
347
359
  // Determine recommended version bump
348
- const axiomDrift = Object.keys(newJ.axioms).length - Object.keys(oldJ.axioms).length;
349
360
  const hasRemoved = axiomsDiff.removed.length > 0 || misunderstandingsDiff.removed.length > 0;
350
361
  const hasAdded = axiomsDiff.added.length > 0 || misunderstandingsDiff.added.length > 0;
351
362
  const hasChanged = axiomsDiff.changed.length > 0 || bannedDiff.changed.length > 0;
352
363
  let recommendedVersionBump = 'none';
353
364
  if (hasRemoved) recommendedVersionBump = 'major';
354
365
  else if (hasAdded || hasChanged) recommendedVersionBump = 'minor';
355
- else if (stancesDiff.added.length > 0 || stancesDiff.removed.length > 0) recommendedVersionBump = 'patch';
366
+ else if (stancesDiff.added.length > 0 || stancesDiff.removed.length > 0)
367
+ recommendedVersionBump = 'patch';
356
368
 
357
369
  if (jsonMode) {
358
370
  const result = {
@@ -378,7 +390,9 @@ async function cmdDiff(a, b, args = []) {
378
390
  const drift = Object.keys(newJ.axioms).length - Object.keys(oldJ.axioms).length;
379
391
  const note = drift !== 0 ? ` (axiom count drift: ${drift > 0 ? '+' : ''}${drift})` : '';
380
392
  console.log(` Judgment surface change: ${oldVersion} → ${newVersion}${note}`);
381
- console.log(` Agent loading the new version may classify, diagnose, or recommend differently.`);
393
+ console.log(
394
+ ` Agent loading the new version may classify, diagnose, or recommend differently.`,
395
+ );
382
396
  console.log('═'.repeat(64));
383
397
  }
384
398
  }
package/src/identity.js CHANGED
@@ -90,13 +90,15 @@ function cmdIdentityShow(jsonMode = false) {
90
90
  const fp = fingerprint(pub);
91
91
 
92
92
  if (jsonMode) {
93
- console.log(JSON.stringify({
94
- pubkey: pub.trim(),
95
- buyer_id: id,
96
- fingerprint: fp,
97
- public_key_path: PUBLIC_KEY_PATH,
98
- private_key_exists: fs.existsSync(PRIVATE_KEY_PATH),
99
- }));
93
+ console.log(
94
+ JSON.stringify({
95
+ pubkey: pub.trim(),
96
+ buyer_id: id,
97
+ fingerprint: fp,
98
+ public_key_path: PUBLIC_KEY_PATH,
99
+ private_key_exists: fs.existsSync(PRIVATE_KEY_PATH),
100
+ }),
101
+ );
100
102
  process.exit(EXIT.OK);
101
103
  }
102
104
 
package/src/init.js CHANGED
@@ -91,7 +91,7 @@ function cmdInit(name) {
91
91
  ` 2. Edit ${targetDir}/KDNA_Patterns.json — replace terminology and misunderstandings`,
92
92
  );
93
93
  console.log(` 3. Edit ${targetDir}/kdna.json — set author, description, repo`);
94
- console.log(` 4. Run: kdna validate ${name} (structural check)`);
94
+ console.log(` 4. Run: kdna dev validate ${name} (structural check)`);
95
95
  console.log(` 5. Run: kdna publish --check ${name} (content quality gate)`);
96
96
  console.log(` 6. Run: kdna verify ${name} (full judgment scoring)`);
97
97
  }
@@ -162,7 +162,7 @@ function cmdClusterInit(name) {
162
162
  console.log(
163
163
  ` 3. Add more sub-domains: cp -r ${targetDir}/domain_one ${targetDir}/your_new_domain`,
164
164
  );
165
- console.log(` 4. Run: kdna validate ${name} (check all sub-domains)`);
165
+ console.log(` 4. Run: kdna dev validate ${name} (check all sub-domains)`);
166
166
  }
167
167
 
168
168
  module.exports = { cmdInit, cmdClusterInit };