@aikdna/kdna-studio-cli 0.4.0 → 0.5.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.
Files changed (2) hide show
  1. package/bin/kdna-studio.js +25 -64
  2. package/package.json +1 -1
@@ -772,86 +772,47 @@ function cmdMigrate(args) {
772
772
  fail(`Human Lock Gate blocked: ${reasons}`, EXIT.HUMAN_LOCK_REQUIRED);
773
773
  }
774
774
 
775
- // Step 4: compile and export as .kdna
776
- const { result } = compileProject(tmpDir);
777
- const files = { ...result.files };
778
- files['README.md'] = compileApi.generateReadme(project);
779
- files.LICENSE = project.license?.type || 'UNSPECIFIED';
780
-
775
+ const absOut = path.resolve(out);
776
+ // Step 4: v1 export or v2 compile + export
781
777
  if (args.includes('--format') && option(args, '--format') === 'v1') {
782
- process.stderr.write('[debug] v1 export path triggered\n');
783
- // ── v1 export: use @aikdna/kdna-core for pack/checksum ──
784
778
  let core;
785
- try {
786
- core = require('@aikdna/kdna-core');
787
- } catch (e) {
788
- fail('@aikdna/kdna-core@0.11.0+ is required for v1 export. Run: npm install -g @aikdna/kdna-core@latest', 2);
779
+ try { core = require('@aikdna/kdna-core'); } catch (e) {
780
+ fail('@aikdna/kdna-core@0.11.0+ is required for v1 export.', 2);
789
781
  }
790
- const v2Manifest = JSON.parse(files['kdna.json']);
791
- let payloadObj;
792
- try {
793
- const payloadBuf = files['payload.kdnab'];
794
- payloadObj = cbor.decode(Buffer.isBuffer(payloadBuf) ? payloadBuf : Buffer.from(payloadBuf));
795
- } catch (e) {
796
- fail('Cannot decode v1 payload from Studio compile output: ' + e.message);
797
- }
798
- // Build a v1 source dir
799
- const v1Dir = fs.mkdtempSync(path.join(require('os').tmpdir(), 'kdna-v1-'));
782
+ const lockedAxioms = (project.cards || []).filter(c => c.type === 'axiom' && c.locked);
783
+ const v1Dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kdna-v1-'));
800
784
  fs.writeFileSync(path.join(v1Dir, 'mimetype'), 'application/vnd.kdna.asset');
801
785
  fs.writeFileSync(path.join(v1Dir, 'kdna.json'), JSON.stringify({
802
- kdna_version: '1.0',
803
- asset_id: v2Manifest.name || 'studio:v1-export',
804
- asset_uid: 'urn:uuid:' + uuidv7(),
805
- asset_type: 'domain',
806
- title: v2Manifest.name || 'Studio v1 Export',
807
- version: v2Manifest.version || '1.0.0',
808
- judgment_version: v2Manifest.judgment_version || '1.0.0',
809
- created_at: v2Manifest.created || new Date().toISOString(),
810
- updated_at: v2Manifest.updated || new Date().toISOString(),
811
- creator: { name: v2Manifest.author?.name || 'Studio Export', id: v2Manifest.author?.id },
786
+ kdna_version: '1.0', asset_id: name || 'studio:v1-export',
787
+ asset_uid: 'urn:uuid:' + crypto.randomUUID(), asset_type: 'domain',
788
+ title: name || 'Studio v1 Export', version: '1.0.0',
789
+ judgment_version: '1.0.0',
790
+ created_at: new Date().toISOString(), updated_at: new Date().toISOString(),
791
+ creator: { name: 'Studio Export' },
812
792
  compatibility: { min_loader_version: '1.0.0', profile: 'judgment-profile-v1' },
813
793
  payload: { path: 'payload.kdnab', encoding: 'json', encrypted: false },
814
- summary: v2Manifest.description || '',
815
- language: v2Manifest.default_language || 'en',
816
794
  lineage: { type: 'original', fork_of: null, derived_from: null },
817
795
  }, null, 2));
818
- // Build v1 payload: minimal mapping from v2 compile output
819
- const v1Payload = {
796
+ fs.writeFileSync(path.join(v1Dir, 'payload.kdnab'), JSON.stringify({
820
797
  profile: 'judgment-profile-v1',
821
- core: {
822
- highest_question: project.stages?.judgment_cards?.goal || '',
823
- axioms: (project.cards || []).filter(c => c.type === 'axiom' && c.locked).map(c => ({
824
- one_sentence: c.fields?.one_sentence || c.summary || '',
825
- })),
826
- boundaries: [],
827
- risk_model: {},
828
- },
829
- patterns: [],
830
- scenarios: [],
831
- cases: [],
832
- reasoning: { self_checks: [], failure_modes: [] },
833
- };
834
- fs.writeFileSync(path.join(v1Dir, 'payload.kdnab'), JSON.stringify(v1Payload, null, 2));
835
- // Use official core to pack + checksum
798
+ core: { highest_question: '', axioms: lockedAxioms.map(c => ({ one_sentence: c.fields?.one_sentence || c.summary || '' })), boundaries: [], risk_model: {} },
799
+ patterns: [], scenarios: [], cases: [], reasoning: { self_checks: [], failure_modes: [] },
800
+ }, null, 2));
836
801
  core.pack(v1Dir, absOut);
837
- // Re-validate
838
802
  const vr = core.validate(absOut);
839
- if (!vr.overall_valid) {
840
- fail('v1 export validation failed: ' + (vr.problems || []).join('; '));
841
- }
842
- console.log(`Exported (v1): ${absOut}`);
843
- console.log(` Name: ${name}`);
844
- console.log(` Axioms: ${v1Payload.core.axioms.length}`);
845
- console.log(` Validated: ${vr.overall_valid ? 'all gates pass' : 'FAIL'}`);
846
- try { fs.rmSync(v1Dir, { recursive: true }); } catch { /* best effort */ }
847
- try { fs.rmSync(tmpDir, { recursive: true }); } catch { /* best effort */ }
803
+ if (!vr.overall_valid) fail('v1 export validation failed: ' + (vr.problems || []).join('; '));
804
+ console.log('Exported (v1): ' + absOut);
805
+ console.log(' Name: ' + name + ' Axioms: ' + lockedAxioms.length + ' Validated: all gates pass');
806
+ try { fs.rmSync(v1Dir, { recursive: true }); } catch { /* cleanup */ }
807
+ try { fs.rmSync(tmpDir, { recursive: true }); } catch { /* cleanup */ }
848
808
  return;
849
809
  }
850
-
810
+ const { result } = compileProject(tmpDir);
811
+ const files = { ...result.files };
812
+ files['README.md'] = compileApi.generateReadme(project);
813
+ files.LICENSE = project.license?.type || 'UNSPECIFIED';
851
814
  files.mimetype = 'application/vnd.aikdna.kdna+zip';
852
815
 
853
- if (args.includes('--sign')) applySignature(files, option(args, '--passphrase'));
854
- const absOut = path.resolve(out);
855
816
  const entries = [['mimetype', files.mimetype]];
856
817
  for (const name of Object.keys(files).filter(k => k !== 'mimetype').sort()) {
857
818
  entries.push([name, files[name]]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aikdna/kdna-studio-cli",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Official KDNA Studio command-line authoring entry for creating, locking, compiling, and exporting .kdna judgment assets through the KDNA toolchain.",
5
5
  "type": "commonjs",
6
6
  "bin": {