@aikdna/kdna-studio-cli 0.1.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/LICENSE +202 -0
- package/README.md +46 -0
- package/bin/kdna-studio.js +428 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2025-2026 AIKDNA Contributors
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @aikdna/kdna-studio-cli
|
|
2
|
+
|
|
3
|
+
Official Studio command-line authoring entry for KDNA.
|
|
4
|
+
|
|
5
|
+
This package provides the `kdna-studio` command. It creates Studio projects,
|
|
6
|
+
imports evidence, manages judgment cards, checks Human Lock, compiles locked
|
|
7
|
+
cards, and exports canonical `.kdna` assets with build reports.
|
|
8
|
+
|
|
9
|
+
It is intentionally separate from `@aikdna/kdna-cli`:
|
|
10
|
+
|
|
11
|
+
| Package | Command | Role |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| `@aikdna/kdna-cli` | `kdna` | Runtime CLI: verify, install, load, compare, publish existing `.kdna` assets |
|
|
14
|
+
| `@aikdna/kdna-studio-cli` | `kdna-studio` | Authoring CLI: create, lock, compile, export trusted `.kdna` assets |
|
|
15
|
+
| `@aikdna/kdna-studio-core` | none | Studio SDK/compiler kernel used by apps and this CLI |
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install -g @aikdna/kdna-studio-cli
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
kdna-studio create my_domain --name @yourscope/my_domain
|
|
27
|
+
kdna-studio import my_domain ./notes.md
|
|
28
|
+
kdna-studio card add my_domain axiom \
|
|
29
|
+
--field one_sentence="Prefer specific evidence over broad claims" \
|
|
30
|
+
--field applies_when='["reviewing content"]' \
|
|
31
|
+
--field does_not_apply_when='["pure formatting"]' \
|
|
32
|
+
--field failure_risk="generic advice"
|
|
33
|
+
kdna-studio card approve my_domain <card-id> --by expert --statement "I confirm this judgment."
|
|
34
|
+
kdna-studio lock my_domain
|
|
35
|
+
kdna-studio export my_domain --out dist/my_domain.kdna --sign
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
After export, use the runtime CLI:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
kdna verify dist/my_domain.kdna --judgment
|
|
42
|
+
kdna publish dist/my_domain.kdna
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`kdna-studio` is the CLI entry for trusted KDNA creation. `kdna` is the runtime
|
|
46
|
+
control plane for existing `.kdna` assets.
|
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const crypto = require('crypto');
|
|
6
|
+
const zlib = require('zlib');
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
project: projectApi,
|
|
10
|
+
cards: cardApi,
|
|
11
|
+
evidence: evidenceApi,
|
|
12
|
+
compile: compileApi,
|
|
13
|
+
quality,
|
|
14
|
+
} = require('@aikdna/kdna-studio-core');
|
|
15
|
+
|
|
16
|
+
const EXIT = { OK: 0, INPUT_ERROR: 2, HUMAN_LOCK_REQUIRED: 4, TRUST_FAILED: 5 };
|
|
17
|
+
|
|
18
|
+
function usage() {
|
|
19
|
+
console.log(`kdna-studio — Studio-compatible KDNA authoring CLI
|
|
20
|
+
|
|
21
|
+
Usage:
|
|
22
|
+
kdna-studio create <project-dir> [--name <@scope/name|name>]
|
|
23
|
+
kdna-studio import <project> <source-file>
|
|
24
|
+
kdna-studio card list <project>
|
|
25
|
+
kdna-studio card add <project> <type> --field key=value [--field key=value]
|
|
26
|
+
kdna-studio card approve <project> <card-id> --by <id> --statement <text>
|
|
27
|
+
kdna-studio lock <project>
|
|
28
|
+
kdna-studio compile <project> --out <dir>
|
|
29
|
+
kdna-studio export <project> --out <file.kdna> [--sign]
|
|
30
|
+
kdna-studio report <project>
|
|
31
|
+
|
|
32
|
+
Project may be a directory containing studio.project.json or a project JSON file.`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function fail(message, code = EXIT.INPUT_ERROR) {
|
|
36
|
+
console.error(`Error: ${message}`);
|
|
37
|
+
process.exit(code);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function option(args, name, fallback = null) {
|
|
41
|
+
const idx = args.indexOf(name);
|
|
42
|
+
if (idx < 0) return fallback;
|
|
43
|
+
const value = args[idx + 1];
|
|
44
|
+
if (!value || value.startsWith('--')) fail(`Missing value for ${name}`);
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function optionsAll(args, name) {
|
|
49
|
+
const values = [];
|
|
50
|
+
for (let i = 0; i < args.length; i++) {
|
|
51
|
+
if (args[i] === name) {
|
|
52
|
+
const value = args[i + 1];
|
|
53
|
+
if (!value || value.startsWith('--')) fail(`Missing value for ${name}`);
|
|
54
|
+
values.push(value);
|
|
55
|
+
i++;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return values;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function resolveProjectPath(input) {
|
|
62
|
+
if (!input) fail('Project path required');
|
|
63
|
+
const abs = path.resolve(input);
|
|
64
|
+
return fs.existsSync(abs) && fs.statSync(abs).isDirectory()
|
|
65
|
+
? path.join(abs, 'studio.project.json')
|
|
66
|
+
: abs;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function readProject(input) {
|
|
70
|
+
const projectPath = resolveProjectPath(input);
|
|
71
|
+
if (!fs.existsSync(projectPath)) fail(`Project not found: ${projectPath}`);
|
|
72
|
+
return { projectPath, project: projectApi.loadProject(fs.readFileSync(projectPath, 'utf8')) };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function writeProject(projectPath, project) {
|
|
76
|
+
fs.mkdirSync(path.dirname(projectPath), { recursive: true });
|
|
77
|
+
fs.writeFileSync(projectPath, projectApi.saveProject(project));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function writeFiles(outDir, files) {
|
|
81
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
82
|
+
for (const [name, content] of Object.entries(files)) {
|
|
83
|
+
const target = path.join(outDir, name);
|
|
84
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
85
|
+
fs.writeFileSync(target, content);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function parseFields(args) {
|
|
90
|
+
const fields = {};
|
|
91
|
+
for (const pair of optionsAll(args, '--field')) {
|
|
92
|
+
const eq = pair.indexOf('=');
|
|
93
|
+
if (eq < 1) fail(`Invalid --field "${pair}". Use key=value.`);
|
|
94
|
+
const key = pair.slice(0, eq);
|
|
95
|
+
const raw = pair.slice(eq + 1);
|
|
96
|
+
if (raw.startsWith('[') || raw.startsWith('{')) {
|
|
97
|
+
try {
|
|
98
|
+
fields[key] = JSON.parse(raw);
|
|
99
|
+
} catch (_) {
|
|
100
|
+
fields[key] = raw;
|
|
101
|
+
}
|
|
102
|
+
} else if (raw.includes('|')) {
|
|
103
|
+
fields[key] = raw.split('|').map((s) => s.trim()).filter(Boolean);
|
|
104
|
+
} else {
|
|
105
|
+
fields[key] = raw;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return fields;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function cmdCreate(args) {
|
|
112
|
+
const dir = args[0];
|
|
113
|
+
if (!dir) fail('Usage: kdna-studio create <project-dir> [--name <name>]');
|
|
114
|
+
const abs = path.resolve(dir);
|
|
115
|
+
if (fs.existsSync(abs)) fail(`Directory already exists: ${abs}`);
|
|
116
|
+
const name = option(args, '--name', path.basename(abs));
|
|
117
|
+
const project = projectApi.createProject(name, 'domain', {
|
|
118
|
+
author: { name: option(args, '--author-name', ''), id: option(args, '--author-id', '') },
|
|
119
|
+
});
|
|
120
|
+
fs.mkdirSync(abs, { recursive: true });
|
|
121
|
+
writeProject(path.join(abs, 'studio.project.json'), project);
|
|
122
|
+
console.log(`Created Studio project: ${abs}`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function cmdImport(args) {
|
|
126
|
+
const [projectInput, source] = args;
|
|
127
|
+
if (!projectInput || !source) fail('Usage: kdna-studio import <project> <source-file>');
|
|
128
|
+
const { projectPath, project } = readProject(projectInput);
|
|
129
|
+
const sourcePath = path.resolve(source);
|
|
130
|
+
if (!fs.existsSync(sourcePath)) fail(`Source file not found: ${sourcePath}`);
|
|
131
|
+
const content = fs.readFileSync(sourcePath, 'utf8');
|
|
132
|
+
const evidence = evidenceApi.createEvidenceEntry('text', path.basename(sourcePath), content, sourcePath);
|
|
133
|
+
evidenceApi.addEvidence(project, evidence);
|
|
134
|
+
writeProject(projectPath, project);
|
|
135
|
+
console.log(`Imported evidence: ${evidence.id}`);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function cmdCard(args) {
|
|
139
|
+
const sub = args[0];
|
|
140
|
+
if (sub === 'list') {
|
|
141
|
+
const { project } = readProject(args[1]);
|
|
142
|
+
for (const card of project.cards || []) {
|
|
143
|
+
console.log(`${card.id}\t${card.type}\t${card.status}\t${card.locked ? 'locked' : 'unlocked'}`);
|
|
144
|
+
}
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (sub === 'add') {
|
|
148
|
+
const projectInput = args[1];
|
|
149
|
+
const type = args[2];
|
|
150
|
+
if (!projectInput || !type) fail('Usage: kdna-studio card add <project> <type> --field key=value');
|
|
151
|
+
const { projectPath, project } = readProject(projectInput);
|
|
152
|
+
const card = cardApi.createCard(type, parseFields(args.slice(3)));
|
|
153
|
+
project.cards.push(card);
|
|
154
|
+
if (project.stages?.judgment_cards) {
|
|
155
|
+
project.stages.judgment_cards.total = project.cards.length;
|
|
156
|
+
project.stages.judgment_cards.status = 'in_progress';
|
|
157
|
+
}
|
|
158
|
+
writeProject(projectPath, project);
|
|
159
|
+
console.log(`Added card: ${card.id}`);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (sub === 'approve') {
|
|
163
|
+
const projectInput = args[1];
|
|
164
|
+
const cardId = args[2];
|
|
165
|
+
if (!projectInput || !cardId) {
|
|
166
|
+
fail('Usage: kdna-studio card approve <project> <card-id> --by <id> --statement <text>');
|
|
167
|
+
}
|
|
168
|
+
const by = option(args, '--by');
|
|
169
|
+
const statement = option(args, '--statement');
|
|
170
|
+
if (!by || !statement) fail('card approve requires --by and --statement');
|
|
171
|
+
const { projectPath, project } = readProject(projectInput);
|
|
172
|
+
const idx = (project.cards || []).findIndex((c) => c.id === cardId);
|
|
173
|
+
if (idx < 0) fail(`Card not found: ${cardId}`);
|
|
174
|
+
let card = project.cards[idx];
|
|
175
|
+
if (card.status === 'draft') card = cardApi.transitionCard(card, 'revised', { by });
|
|
176
|
+
project.cards[idx] = cardApi.lockCard(card, {
|
|
177
|
+
by,
|
|
178
|
+
statement,
|
|
179
|
+
checked: { applies_when: true, does_not_apply_when: true, failure_risk: true },
|
|
180
|
+
});
|
|
181
|
+
if (project.stages?.judgment_cards) {
|
|
182
|
+
project.stages.judgment_cards.locked = project.cards.filter((c) => c.locked).length;
|
|
183
|
+
project.stages.judgment_cards.total = project.cards.length;
|
|
184
|
+
}
|
|
185
|
+
writeProject(projectPath, project);
|
|
186
|
+
console.log(`Approved and Human Locked: ${cardId}`);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
fail('Usage: kdna-studio card <list|add|approve> ...');
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function cmdLock(args) {
|
|
193
|
+
const { project } = readProject(args[0]);
|
|
194
|
+
const gate = projectApi.checkHumanLockGate(project);
|
|
195
|
+
if (gate.blocked) {
|
|
196
|
+
console.error('Human Lock Gate blocked export:');
|
|
197
|
+
for (const issue of gate.issues) console.error(` - ${issue.cardId}: ${issue.reason}`);
|
|
198
|
+
process.exit(EXIT.HUMAN_LOCK_REQUIRED);
|
|
199
|
+
}
|
|
200
|
+
console.log(`Human Lock Gate passed: ${gate.lockedJudgmentCards} locked judgment cards`);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function compileProject(projectInput) {
|
|
204
|
+
const { project } = readProject(projectInput);
|
|
205
|
+
const gate = projectApi.checkHumanLockGate(project);
|
|
206
|
+
if (gate.blocked) {
|
|
207
|
+
const reasons = gate.issues.map((i) => `${i.cardId}: ${i.reason}`).join('\n - ');
|
|
208
|
+
fail(`Human Lock Gate blocked compile:\n - ${reasons}`, EXIT.HUMAN_LOCK_REQUIRED);
|
|
209
|
+
}
|
|
210
|
+
return { project, result: compileApi.compileDomain(project) };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function cmdCompile(args) {
|
|
214
|
+
const projectInput = args[0];
|
|
215
|
+
const out = option(args, '--out', './dist/studio-build');
|
|
216
|
+
if (!projectInput) fail('Usage: kdna-studio compile <project> --out <dir>');
|
|
217
|
+
const { result } = compileProject(projectInput);
|
|
218
|
+
writeFiles(path.resolve(out), result.files);
|
|
219
|
+
console.log(`Compiled Studio build output: ${path.resolve(out)}`);
|
|
220
|
+
console.log(`Build ID: ${result.identity.build_id}`);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function crc32(data) {
|
|
224
|
+
let crc = ~0;
|
|
225
|
+
for (const byte of data) {
|
|
226
|
+
crc ^= byte;
|
|
227
|
+
for (let k = 0; k < 8; k++) crc = (crc >>> 1) ^ (0xedb88320 & -(crc & 1));
|
|
228
|
+
}
|
|
229
|
+
return (~crc) >>> 0;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function u16(parts, n) {
|
|
233
|
+
const b = Buffer.alloc(2);
|
|
234
|
+
b.writeUInt16LE(n);
|
|
235
|
+
parts.push(b);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function u32(parts, n) {
|
|
239
|
+
const b = Buffer.alloc(4);
|
|
240
|
+
b.writeUInt32LE(n >>> 0);
|
|
241
|
+
parts.push(b);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function buildZip(entries) {
|
|
245
|
+
const chunks = [];
|
|
246
|
+
const central = [];
|
|
247
|
+
let offset = 0;
|
|
248
|
+
for (const [name, content] of entries) {
|
|
249
|
+
const nameBuf = Buffer.from(name);
|
|
250
|
+
const raw = Buffer.isBuffer(content) ? content : Buffer.from(String(content));
|
|
251
|
+
const compressed = name === 'mimetype' ? raw : zlib.deflateRawSync(raw);
|
|
252
|
+
const method = name === 'mimetype' ? 0 : 8;
|
|
253
|
+
const crc = crc32(raw);
|
|
254
|
+
const local = [];
|
|
255
|
+
u32(local, 0x04034b50);
|
|
256
|
+
u16(local, 20);
|
|
257
|
+
u16(local, 0x0800);
|
|
258
|
+
u16(local, method);
|
|
259
|
+
u16(local, 0);
|
|
260
|
+
u16(local, 0);
|
|
261
|
+
u32(local, crc);
|
|
262
|
+
u32(local, compressed.length);
|
|
263
|
+
u32(local, raw.length);
|
|
264
|
+
u16(local, nameBuf.length);
|
|
265
|
+
u16(local, 0);
|
|
266
|
+
local.push(nameBuf, compressed);
|
|
267
|
+
const localBuf = Buffer.concat(local);
|
|
268
|
+
chunks.push(localBuf);
|
|
269
|
+
central.push({ nameBuf, method, crc, compressedSize: compressed.length, size: raw.length, offset });
|
|
270
|
+
offset += localBuf.length;
|
|
271
|
+
}
|
|
272
|
+
const centralStart = offset;
|
|
273
|
+
for (const entry of central) {
|
|
274
|
+
const cd = [];
|
|
275
|
+
u32(cd, 0x02014b50);
|
|
276
|
+
u16(cd, 20);
|
|
277
|
+
u16(cd, 20);
|
|
278
|
+
u16(cd, 0x0800);
|
|
279
|
+
u16(cd, entry.method);
|
|
280
|
+
u16(cd, 0);
|
|
281
|
+
u16(cd, 0);
|
|
282
|
+
u32(cd, entry.crc);
|
|
283
|
+
u32(cd, entry.compressedSize);
|
|
284
|
+
u32(cd, entry.size);
|
|
285
|
+
u16(cd, entry.nameBuf.length);
|
|
286
|
+
u16(cd, 0);
|
|
287
|
+
u16(cd, 0);
|
|
288
|
+
u16(cd, 0);
|
|
289
|
+
u16(cd, 0);
|
|
290
|
+
u32(cd, 0);
|
|
291
|
+
u32(cd, entry.offset);
|
|
292
|
+
cd.push(entry.nameBuf);
|
|
293
|
+
const cdBuf = Buffer.concat(cd);
|
|
294
|
+
chunks.push(cdBuf);
|
|
295
|
+
offset += cdBuf.length;
|
|
296
|
+
}
|
|
297
|
+
const eocd = [];
|
|
298
|
+
u32(eocd, 0x06054b50);
|
|
299
|
+
u16(eocd, 0);
|
|
300
|
+
u16(eocd, 0);
|
|
301
|
+
u16(eocd, central.length);
|
|
302
|
+
u16(eocd, central.length);
|
|
303
|
+
u32(eocd, offset - centralStart);
|
|
304
|
+
u32(eocd, centralStart);
|
|
305
|
+
u16(eocd, 0);
|
|
306
|
+
chunks.push(Buffer.concat(eocd));
|
|
307
|
+
return Buffer.concat(chunks);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function stableStringify(value) {
|
|
311
|
+
if (Array.isArray(value)) return `[${value.map(stableStringify).join(',')}]`;
|
|
312
|
+
if (value && typeof value === 'object') {
|
|
313
|
+
return `{${Object.keys(value).sort().map((k) => `${JSON.stringify(k)}:${stableStringify(value[k])}`).join(',')}}`;
|
|
314
|
+
}
|
|
315
|
+
return JSON.stringify(value);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function manifestForSigning(manifest) {
|
|
319
|
+
const copy = { ...manifest };
|
|
320
|
+
delete copy.signature;
|
|
321
|
+
delete copy.asset_digest;
|
|
322
|
+
delete copy.container_sha256;
|
|
323
|
+
return copy;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function canonicalPayload(files) {
|
|
327
|
+
return ['mimetype', ...Object.keys(files).filter((k) => k !== 'mimetype').sort()]
|
|
328
|
+
.filter((name) => name !== 'signature.json' && name !== '.DS_Store')
|
|
329
|
+
.map((name) => {
|
|
330
|
+
let content = name === 'mimetype' ? 'application/vnd.aikdna.kdna+zip' : files[name];
|
|
331
|
+
if (name.endsWith('.json')) {
|
|
332
|
+
const json = JSON.parse(content);
|
|
333
|
+
content = stableStringify(name === 'kdna.json' ? manifestForSigning(json) : json);
|
|
334
|
+
}
|
|
335
|
+
return `${name}:${crypto.createHash('sha256').update(Buffer.from(content)).digest('hex')}`;
|
|
336
|
+
})
|
|
337
|
+
.join('\n');
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function identityPaths() {
|
|
341
|
+
const dir = process.env.KDNA_IDENTITY_DIR || path.join(os.homedir(), '.kdna', 'identity');
|
|
342
|
+
return { privateKey: path.join(dir, 'kdna.key'), publicKey: path.join(dir, 'kdna.pub') };
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function publicKeyFingerprint(publicKeyPem) {
|
|
346
|
+
return `ed25519:${crypto.createHash('sha256').update(publicKeyPem).digest('hex')}`;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function applySignature(files) {
|
|
350
|
+
const paths = identityPaths();
|
|
351
|
+
if (!fs.existsSync(paths.privateKey) || !fs.existsSync(paths.publicKey)) {
|
|
352
|
+
fail('Signing requires KDNA identity keys. Run: kdna identity init', EXIT.TRUST_FAILED);
|
|
353
|
+
}
|
|
354
|
+
const manifest = JSON.parse(files['kdna.json']);
|
|
355
|
+
const publicKeyPem = fs.readFileSync(paths.publicKey, 'utf8');
|
|
356
|
+
manifest.author = manifest.author || {};
|
|
357
|
+
manifest.author.pubkey = publicKeyFingerprint(publicKeyPem);
|
|
358
|
+
manifest.author.public_key_pem = publicKeyPem;
|
|
359
|
+
files['kdna.json'] = JSON.stringify(manifest, null, 2);
|
|
360
|
+
|
|
361
|
+
const payload = canonicalPayload(files);
|
|
362
|
+
const privateKeyPem = fs.readFileSync(paths.privateKey, 'utf8');
|
|
363
|
+
manifest.signature = `ed25519:${crypto.sign(null, Buffer.from(payload), privateKeyPem).toString('hex')}`;
|
|
364
|
+
files['kdna.json'] = JSON.stringify(manifest, null, 2);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function cmdExport(args) {
|
|
368
|
+
const projectInput = args[0];
|
|
369
|
+
const out = option(args, '--out');
|
|
370
|
+
if (!projectInput || !out) fail('Usage: kdna-studio export <project> --out <file.kdna> [--sign]');
|
|
371
|
+
const { project, result } = compileProject(projectInput);
|
|
372
|
+
const files = { ...result.files };
|
|
373
|
+
files['README.md'] = compileApi.generateReadme(project);
|
|
374
|
+
files.LICENSE = project.license?.type || 'UNSPECIFIED';
|
|
375
|
+
if (args.includes('--sign')) applySignature(files);
|
|
376
|
+
|
|
377
|
+
const entries = [['mimetype', 'application/vnd.aikdna.kdna+zip']];
|
|
378
|
+
for (const name of Object.keys(files).sort()) entries.push([name, files[name]]);
|
|
379
|
+
const zip = buildZip(entries);
|
|
380
|
+
const outPath = path.resolve(out);
|
|
381
|
+
fs.mkdirSync(path.dirname(outPath), { recursive: true });
|
|
382
|
+
fs.writeFileSync(outPath, zip);
|
|
383
|
+
|
|
384
|
+
const assetDigest = `sha256:${crypto.createHash('sha256').update(zip).digest('hex')}`;
|
|
385
|
+
const receipt = JSON.parse(files['build-receipt.json']);
|
|
386
|
+
receipt.asset_path = outPath;
|
|
387
|
+
receipt.asset_digest = assetDigest;
|
|
388
|
+
receipt.signature_status = args.includes('--sign') ? 'signed' : 'unsigned';
|
|
389
|
+
fs.writeFileSync(path.join(path.dirname(outPath), 'build-receipt.json'), JSON.stringify(receipt, null, 2));
|
|
390
|
+
fs.writeFileSync(path.join(path.dirname(outPath), 'provenance-report.json'), files['reports/provenance-report.json']);
|
|
391
|
+
fs.writeFileSync(path.join(path.dirname(outPath), 'quality-gate-report.json'), files['reports/quality-gate-report.json']);
|
|
392
|
+
fs.writeFileSync(path.join(path.dirname(outPath), 'human-lock-report.json'), files['reports/human-lock-report.json']);
|
|
393
|
+
fs.writeFileSync(path.join(path.dirname(outPath), 'eval-report.json'), files['reports/eval-report.json']);
|
|
394
|
+
console.log(`Exported canonical .kdna asset: ${outPath}`);
|
|
395
|
+
console.log(`Asset digest: ${assetDigest}`);
|
|
396
|
+
console.log(`Build ID: ${result.identity.build_id}`);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function cmdReport(args) {
|
|
400
|
+
const { project } = readProject(args[0]);
|
|
401
|
+
const readiness = quality.computeReadiness(project);
|
|
402
|
+
const gate = projectApi.checkHumanLockGate(project);
|
|
403
|
+
console.log(JSON.stringify({ readiness, human_lock_gate: gate }, null, 2));
|
|
404
|
+
process.exit(gate.blocked ? EXIT.HUMAN_LOCK_REQUIRED : EXIT.OK);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const args = process.argv.slice(2);
|
|
408
|
+
const cmd = args[0];
|
|
409
|
+
if (!cmd || cmd === '--help' || cmd === '-h') {
|
|
410
|
+
usage();
|
|
411
|
+
process.exit(EXIT.OK);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
try {
|
|
415
|
+
if (cmd === 'create') cmdCreate(args.slice(1));
|
|
416
|
+
else if (cmd === 'import') cmdImport(args.slice(1));
|
|
417
|
+
else if (cmd === 'card') cmdCard(args.slice(1));
|
|
418
|
+
else if (cmd === 'lock') cmdLock(args.slice(1));
|
|
419
|
+
else if (cmd === 'compile') cmdCompile(args.slice(1));
|
|
420
|
+
else if (cmd === 'export') cmdExport(args.slice(1));
|
|
421
|
+
else if (cmd === 'report') cmdReport(args.slice(1));
|
|
422
|
+
else {
|
|
423
|
+
usage();
|
|
424
|
+
fail(`Unknown command: ${cmd}`);
|
|
425
|
+
}
|
|
426
|
+
} catch (err) {
|
|
427
|
+
fail(err.message || String(err));
|
|
428
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aikdna/kdna-studio-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official KDNA Studio command-line authoring entry for creating, locking, compiling, and exporting trusted .kdna assets.",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"bin": {
|
|
7
|
+
"kdna-studio": "bin/kdna-studio.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin/",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "node bin/kdna-studio.js --help >/dev/null"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"kdna",
|
|
18
|
+
"kdna-studio",
|
|
19
|
+
"kdna-studio-cli",
|
|
20
|
+
"authoring",
|
|
21
|
+
"human-lock",
|
|
22
|
+
"judgment-cards"
|
|
23
|
+
],
|
|
24
|
+
"license": "Apache-2.0",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/aikdna/kdna-studio-cli.git"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://aikdna.com",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/aikdna/kdna-studio-cli/issues"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=18"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@aikdna/kdna-studio-core": "^1.3.0"
|
|
38
|
+
}
|
|
39
|
+
}
|