@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/README.md +120 -101
- package/SECURITY.md +1 -1
- package/package.json +6 -4
- package/skills/kdna-loader/SKILL.md +23 -22
- package/src/agent.js +290 -159
- package/src/cli.js +117 -67
- package/src/cmds/_common.js +40 -18
- package/src/cmds/badge.js +14 -9
- package/src/cmds/changelog.js +32 -12
- package/src/cmds/cluster.js +80 -85
- package/src/cmds/doctor.js +10 -27
- package/src/cmds/domain.js +114 -427
- package/src/cmds/explain.js +119 -0
- package/src/cmds/governance.js +111 -42
- package/src/cmds/legacy.js +8 -9
- package/src/cmds/license.js +491 -26
- package/src/cmds/quality.js +10 -3
- package/src/cmds/registry.js +15 -67
- package/src/cmds/studio.js +99 -47
- package/src/cmds/test.js +9 -6
- package/src/cmds/trace.js +11 -7
- package/src/compare.js +41 -22
- package/src/diff.js +38 -24
- package/src/identity.js +9 -7
- package/src/init.js +2 -2
- package/src/install.js +147 -459
- package/src/loader.js +10 -10
- package/src/package-store.js +232 -0
- package/src/paths.js +44 -0
- package/src/publish.js +150 -51
- package/src/registry.js +81 -9
- package/src/setup.js +19 -20
- package/src/verify.js +293 -140
- package/src/version.js +15 -7
- package/templates/minimal-domain/kdna.json +7 -7
- package/templates/standard-domain/README.md +10 -10
- package/templates/standard-domain/kdna.json +7 -3
- package/validators/kdna-lint.js +45 -11
- package/src/cmds/encrypt.js +0 -199
package/src/cmds/license.js
CHANGED
|
@@ -10,23 +10,346 @@
|
|
|
10
10
|
const fs = require('fs');
|
|
11
11
|
const path = require('path');
|
|
12
12
|
const crypto = require('crypto');
|
|
13
|
+
const http = require('http');
|
|
14
|
+
const https = require('https');
|
|
13
15
|
const { EXIT, error } = require('./_common');
|
|
14
|
-
const {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
verifyLicense,
|
|
18
|
-
verifyLicenseSignature,
|
|
19
|
-
machineFingerprint,
|
|
20
|
-
} = require('./encrypt');
|
|
21
|
-
|
|
22
|
-
const IDENTITY_DIR = path.join(
|
|
23
|
-
process.env.HOME || process.env.USERPROFILE || '.',
|
|
24
|
-
'.kdna',
|
|
25
|
-
'identity',
|
|
26
|
-
);
|
|
16
|
+
const { recordTrace } = require('./trace');
|
|
17
|
+
const PATHS = require('../paths');
|
|
18
|
+
const IDENTITY_DIR = PATHS.identity;
|
|
27
19
|
const PRIVATE_KEY_PATH = path.join(IDENTITY_DIR, 'kdna.key');
|
|
28
20
|
const PUBLIC_KEY_PATH = path.join(IDENTITY_DIR, 'kdna.pub');
|
|
29
21
|
|
|
22
|
+
function machineFingerprint() {
|
|
23
|
+
const os = require('os');
|
|
24
|
+
const parts = [os.hostname(), os.userInfo().uid.toString(), os.platform(), os.arch()];
|
|
25
|
+
try {
|
|
26
|
+
const { execSync } = require('child_process');
|
|
27
|
+
if (os.platform() === 'darwin') {
|
|
28
|
+
const uuid = execSync('ioreg -d2 -c IOPlatformExpertDevice | grep IOPlatformUUID', {
|
|
29
|
+
encoding: 'utf8',
|
|
30
|
+
timeout: 3000,
|
|
31
|
+
})
|
|
32
|
+
.match(/"[A-F0-9-]{36}"/)?.[0]
|
|
33
|
+
?.replace(/"/g, '');
|
|
34
|
+
if (uuid) parts.push(uuid);
|
|
35
|
+
}
|
|
36
|
+
if (os.platform() === 'linux') {
|
|
37
|
+
try {
|
|
38
|
+
const mid = fs.readFileSync('/etc/machine-id', 'utf8').trim();
|
|
39
|
+
if (mid) parts.push(mid);
|
|
40
|
+
} catch {
|
|
41
|
+
/* ignore */
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
} catch {
|
|
45
|
+
/* non-critical */
|
|
46
|
+
}
|
|
47
|
+
return crypto.createHash('sha256').update(parts.join('|')).digest('hex');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function createLicense(domain, options = {}) {
|
|
51
|
+
return {
|
|
52
|
+
version: '1.0',
|
|
53
|
+
license_id: `lic_${crypto.randomBytes(8).toString('hex')}`,
|
|
54
|
+
license_key: options.licenseKey || `KDNA-LIC-${crypto.randomBytes(18).toString('base64url')}`,
|
|
55
|
+
domain,
|
|
56
|
+
issued_to: options.issuedTo || 'licensee@example.com',
|
|
57
|
+
issued_at: new Date().toISOString(),
|
|
58
|
+
expires_at: options.expiresAt || null,
|
|
59
|
+
max_agents: options.maxAgents || 1,
|
|
60
|
+
require_machine_binding: options.requireMachineBinding !== false,
|
|
61
|
+
require_online_check: !!options.requireOnlineCheck,
|
|
62
|
+
offline_grace_days: options.offlineGraceDays || 7,
|
|
63
|
+
allowed_agents: options.allowedAgents || ['claude_code', 'codex', 'opencode'],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function signLicense(license, privateKeyPem) {
|
|
68
|
+
const payload = { ...license };
|
|
69
|
+
delete payload.signature;
|
|
70
|
+
const data = JSON.stringify(payload, Object.keys(payload).sort());
|
|
71
|
+
const sig = crypto.sign(null, Buffer.from(data), privateKeyPem);
|
|
72
|
+
return { ...license, signature: `ed25519:${sig.toString('hex')}` };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function verifyLicenseSignature(license, publicKeyPem) {
|
|
76
|
+
const signature = license.signature?.replace('ed25519:', '') || '';
|
|
77
|
+
if (!signature) return false;
|
|
78
|
+
const payload = { ...license };
|
|
79
|
+
delete payload.signature;
|
|
80
|
+
const data = JSON.stringify(payload, Object.keys(payload).sort());
|
|
81
|
+
try {
|
|
82
|
+
return crypto.verify(null, Buffer.from(data), publicKeyPem, Buffer.from(signature, 'hex'));
|
|
83
|
+
} catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function verifyLicense(license, _scopePubkey, fingerprint) {
|
|
89
|
+
const issues = [];
|
|
90
|
+
const now = new Date();
|
|
91
|
+
if (license.expires_at && new Date(license.expires_at) < new Date()) {
|
|
92
|
+
issues.push('License has expired');
|
|
93
|
+
}
|
|
94
|
+
if (license.revoked === true || license.status === 'revoked') {
|
|
95
|
+
issues.push('License has been revoked');
|
|
96
|
+
}
|
|
97
|
+
if (license.require_online_check) {
|
|
98
|
+
const offlineUntil = license.offline_valid_until ? new Date(license.offline_valid_until) : null;
|
|
99
|
+
if (!offlineUntil || Number.isNaN(offlineUntil.getTime()) || offlineUntil < now) {
|
|
100
|
+
issues.push('License offline grace has expired');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (license.require_machine_binding) {
|
|
104
|
+
if (!license.machine_fingerprint) {
|
|
105
|
+
issues.push('License is not bound to this machine');
|
|
106
|
+
} else if (license.machine_fingerprint !== fingerprint) {
|
|
107
|
+
issues.push('Machine fingerprint mismatch');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
valid: issues.length === 0,
|
|
112
|
+
issues,
|
|
113
|
+
domain: license.domain,
|
|
114
|
+
license_id: license.license_id,
|
|
115
|
+
issued_to: license.issued_to,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function licenseServerType(server) {
|
|
120
|
+
if (!server) return null;
|
|
121
|
+
if (server.startsWith('file://')) return 'file';
|
|
122
|
+
if (server.startsWith('/')) return 'local-file';
|
|
123
|
+
try {
|
|
124
|
+
return new URL(server).protocol.replace(':', '');
|
|
125
|
+
} catch {
|
|
126
|
+
return 'unknown';
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function recordLicenseTrace(action, license, extra = {}) {
|
|
131
|
+
const fingerprint = machineFingerprint();
|
|
132
|
+
const result = verifyLicense(license || {}, null, fingerprint);
|
|
133
|
+
recordTrace({
|
|
134
|
+
timestamp: new Date().toISOString(),
|
|
135
|
+
event: 'license',
|
|
136
|
+
action,
|
|
137
|
+
agent: 'kdna-cli',
|
|
138
|
+
domain: license?.domain || extra.domain || null,
|
|
139
|
+
license_id: license?.license_id || extra.license_id || null,
|
|
140
|
+
valid: result.valid,
|
|
141
|
+
issues: result.issues,
|
|
142
|
+
revoked: license?.revoked === true || license?.status === 'revoked',
|
|
143
|
+
require_online_check: !!license?.require_online_check,
|
|
144
|
+
offline_valid_until: license?.offline_valid_until || null,
|
|
145
|
+
server_type: licenseServerType(
|
|
146
|
+
extra.server || license?.activation_server || license?.license_server_url,
|
|
147
|
+
),
|
|
148
|
+
synced: extra.synced,
|
|
149
|
+
sync_error: extra.sync_error,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function safeLicenseName(domain) {
|
|
154
|
+
return domain.replace(/^@/, '').replace('/', '-');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function licensePathForDomain(domain) {
|
|
158
|
+
return path.join(PATHS.licenses, `${safeLicenseName(domain)}.json`);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function readLicenseForDomain(domain) {
|
|
162
|
+
const file = licensePathForDomain(domain);
|
|
163
|
+
if (!fs.existsSync(file)) return null;
|
|
164
|
+
try {
|
|
165
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
166
|
+
} catch {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function listInstalledLicenses() {
|
|
172
|
+
if (!fs.existsSync(PATHS.licenses)) return [];
|
|
173
|
+
return fs
|
|
174
|
+
.readdirSync(PATHS.licenses)
|
|
175
|
+
.filter((name) => name.endsWith('.json'))
|
|
176
|
+
.map((name) => {
|
|
177
|
+
const file = path.join(PATHS.licenses, name);
|
|
178
|
+
try {
|
|
179
|
+
return { file, license: JSON.parse(fs.readFileSync(file, 'utf8')) };
|
|
180
|
+
} catch {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
.filter(Boolean);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function licenseKey(license) {
|
|
188
|
+
return license?.license_key || license?.activation_key || license?.key || null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function licenseDecryptOptionsForManifest(manifest) {
|
|
192
|
+
const domain = manifest?.name || manifest?.asset_id;
|
|
193
|
+
if (!domain) {
|
|
194
|
+
return { ok: false, error: 'licensed asset missing manifest name' };
|
|
195
|
+
}
|
|
196
|
+
const license = readLicenseForDomain(domain);
|
|
197
|
+
if (!license) {
|
|
198
|
+
return { ok: false, error: `no installed license for ${domain}` };
|
|
199
|
+
}
|
|
200
|
+
if (license.domain !== domain) {
|
|
201
|
+
return { ok: false, error: `installed license domain mismatch: ${license.domain}` };
|
|
202
|
+
}
|
|
203
|
+
const fingerprint = machineFingerprint();
|
|
204
|
+
const result = verifyLicense(license, null, fingerprint);
|
|
205
|
+
if (!result.valid) {
|
|
206
|
+
return { ok: false, error: result.issues.join('; ') };
|
|
207
|
+
}
|
|
208
|
+
const key = licenseKey(license);
|
|
209
|
+
if (!key) {
|
|
210
|
+
return { ok: false, error: `installed license for ${domain} has no license_key` };
|
|
211
|
+
}
|
|
212
|
+
const { createLicensedDecryptEntry } = require('@aikdna/kdna-core');
|
|
213
|
+
return {
|
|
214
|
+
ok: true,
|
|
215
|
+
license,
|
|
216
|
+
decryptEntry: createLicensedDecryptEntry({
|
|
217
|
+
licenseKey: key,
|
|
218
|
+
machineFingerprint: license.machine_fingerprint || fingerprint,
|
|
219
|
+
}),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function argValue(args, flag) {
|
|
224
|
+
const idx = args.indexOf(flag);
|
|
225
|
+
return idx >= 0 ? args[idx + 1] : null;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function addOfflineLease(activation) {
|
|
229
|
+
const days = activation.offline_grace_days || 7;
|
|
230
|
+
const until = new Date();
|
|
231
|
+
until.setDate(until.getDate() + days);
|
|
232
|
+
return {
|
|
233
|
+
...activation,
|
|
234
|
+
last_checked_at: new Date().toISOString(),
|
|
235
|
+
offline_valid_until: activation.require_online_check
|
|
236
|
+
? until.toISOString()
|
|
237
|
+
: activation.offline_valid_until || null,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function normalizeActivation(domain, key, payload, server = null) {
|
|
242
|
+
const source = payload.activation || payload.license || payload;
|
|
243
|
+
if (source.ok === false || payload.ok === false) {
|
|
244
|
+
throw new Error(source.error || payload.error || 'activation denied');
|
|
245
|
+
}
|
|
246
|
+
if (Array.isArray(payload.activations)) {
|
|
247
|
+
const found = payload.activations.find(
|
|
248
|
+
(entry) => entry.domain === domain && licenseKey(entry) === key,
|
|
249
|
+
);
|
|
250
|
+
if (!found) throw new Error('activation not found for domain/key');
|
|
251
|
+
return normalizeActivation(domain, key, found, server);
|
|
252
|
+
}
|
|
253
|
+
if (source.domain && source.domain !== domain) {
|
|
254
|
+
throw new Error(`activation domain mismatch: ${source.domain}`);
|
|
255
|
+
}
|
|
256
|
+
if (licenseKey(source) && licenseKey(source) !== key) {
|
|
257
|
+
throw new Error('activation key mismatch');
|
|
258
|
+
}
|
|
259
|
+
const fingerprint = machineFingerprint();
|
|
260
|
+
return addOfflineLease({
|
|
261
|
+
version: source.version || '1.0',
|
|
262
|
+
license_id: source.license_id || `lic_${crypto.randomBytes(8).toString('hex')}`,
|
|
263
|
+
license_key: key,
|
|
264
|
+
domain,
|
|
265
|
+
issued_to: source.issued_to || source.email || null,
|
|
266
|
+
issued_at: source.issued_at || new Date().toISOString(),
|
|
267
|
+
expires_at: source.expires_at || null,
|
|
268
|
+
status: source.status || 'active',
|
|
269
|
+
revoked: source.revoked === true,
|
|
270
|
+
require_machine_binding: source.require_machine_binding !== false,
|
|
271
|
+
machine_fingerprint: source.machine_fingerprint || fingerprint,
|
|
272
|
+
require_online_check: source.require_online_check !== false,
|
|
273
|
+
offline_grace_days: source.offline_grace_days || 7,
|
|
274
|
+
allowed_agents: source.allowed_agents || [
|
|
275
|
+
'claude_code',
|
|
276
|
+
'codex',
|
|
277
|
+
'opencode',
|
|
278
|
+
'cursor',
|
|
279
|
+
'gemini',
|
|
280
|
+
],
|
|
281
|
+
activation_server: server || source.activation_server || source.license_server_url || null,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function readActivationFromFile(url, domain, key) {
|
|
286
|
+
const filePath = url.startsWith('file://') ? new URL(url).pathname : url;
|
|
287
|
+
const payload = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
288
|
+
return normalizeActivation(domain, key, payload, url);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function postJson(url, body) {
|
|
292
|
+
return new Promise((resolve, reject) => {
|
|
293
|
+
const u = new URL(url);
|
|
294
|
+
const client = u.protocol === 'http:' ? http : https;
|
|
295
|
+
const data = JSON.stringify(body);
|
|
296
|
+
const req = client.request(
|
|
297
|
+
{
|
|
298
|
+
method: 'POST',
|
|
299
|
+
hostname: u.hostname,
|
|
300
|
+
port: u.port || (u.protocol === 'http:' ? 80 : 443),
|
|
301
|
+
path: `${u.pathname}${u.search}`,
|
|
302
|
+
headers: {
|
|
303
|
+
'content-type': 'application/json',
|
|
304
|
+
'content-length': Buffer.byteLength(data),
|
|
305
|
+
},
|
|
306
|
+
timeout: 15000,
|
|
307
|
+
},
|
|
308
|
+
(res) => {
|
|
309
|
+
const chunks = [];
|
|
310
|
+
res.on('data', (chunk) => chunks.push(chunk));
|
|
311
|
+
res.on('end', () => {
|
|
312
|
+
const text = Buffer.concat(chunks).toString('utf8');
|
|
313
|
+
if (res.statusCode >= 400) {
|
|
314
|
+
reject(new Error(`activation server HTTP ${res.statusCode}: ${text.slice(0, 300)}`));
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
try {
|
|
318
|
+
resolve(JSON.parse(text));
|
|
319
|
+
} catch {
|
|
320
|
+
reject(new Error(`activation server returned invalid JSON`));
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
},
|
|
324
|
+
);
|
|
325
|
+
req.on('error', reject);
|
|
326
|
+
req.on('timeout', () => req.destroy(new Error('activation server timeout')));
|
|
327
|
+
req.write(data);
|
|
328
|
+
req.end();
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
async function requestActivation(domain, key, server) {
|
|
333
|
+
if (!server) throw new Error('--server <url> is required for activation');
|
|
334
|
+
if (server.startsWith('file://') || server.startsWith('/')) {
|
|
335
|
+
return readActivationFromFile(server, domain, key);
|
|
336
|
+
}
|
|
337
|
+
const payload = await postJson(server, {
|
|
338
|
+
domain,
|
|
339
|
+
license_key: key,
|
|
340
|
+
machine_fingerprint: machineFingerprint(),
|
|
341
|
+
client: 'kdna-cli',
|
|
342
|
+
});
|
|
343
|
+
return normalizeActivation(domain, key, payload, server);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function writeInstalledLicense(license) {
|
|
347
|
+
fs.mkdirSync(PATHS.licenses, { recursive: true });
|
|
348
|
+
const dest = licensePathForDomain(license.domain);
|
|
349
|
+
fs.writeFileSync(dest, JSON.stringify(license, null, 2) + '\n');
|
|
350
|
+
return dest;
|
|
351
|
+
}
|
|
352
|
+
|
|
30
353
|
function readIdentity() {
|
|
31
354
|
if (!fs.existsSync(PRIVATE_KEY_PATH) || !fs.existsSync(PUBLIC_KEY_PATH)) {
|
|
32
355
|
error('No identity found. Run: kdna identity init', EXIT.INPUT_ERROR);
|
|
@@ -90,7 +413,7 @@ function cmdLicenseGenerate(args) {
|
|
|
90
413
|
if (expiresAt) console.error(` Expires: ${expiresAt}`);
|
|
91
414
|
console.error(` Machine binding: ${requireBinding ? 'required' : 'disabled'}`);
|
|
92
415
|
console.error('');
|
|
93
|
-
console.error('Save this
|
|
416
|
+
console.error('Save this license activation outside the .kdna asset under ~/.kdna/licenses/.');
|
|
94
417
|
console.error('Share the license key with the licensee.');
|
|
95
418
|
}
|
|
96
419
|
|
|
@@ -171,7 +494,7 @@ function cmdLicenseBind(args) {
|
|
|
171
494
|
process.exit(EXIT.OK);
|
|
172
495
|
}
|
|
173
496
|
|
|
174
|
-
const { privateKey
|
|
497
|
+
const { privateKey } = readIdentity();
|
|
175
498
|
const fp = machineFingerprint();
|
|
176
499
|
|
|
177
500
|
// Remove old signature before re-signing
|
|
@@ -209,17 +532,8 @@ function cmdLicenseInstall(args) {
|
|
|
209
532
|
|
|
210
533
|
if (!license.domain) error('License missing domain field', EXIT.INPUT_ERROR);
|
|
211
534
|
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
'.kdna',
|
|
215
|
-
'licenses',
|
|
216
|
-
);
|
|
217
|
-
fs.mkdirSync(licenseDir, { recursive: true });
|
|
218
|
-
|
|
219
|
-
const safeName = license.domain.replace(/^@/, '').replace('/', '-');
|
|
220
|
-
const dest = path.join(licenseDir, `${safeName}.json`);
|
|
221
|
-
|
|
222
|
-
fs.writeFileSync(dest, JSON.stringify(license, null, 2) + '\n');
|
|
535
|
+
const dest = writeInstalledLicense(license);
|
|
536
|
+
recordLicenseTrace('install', license);
|
|
223
537
|
|
|
224
538
|
console.log(`License installed for ${license.domain}`);
|
|
225
539
|
console.log(` License ID: ${license.license_id || 'unknown'}`);
|
|
@@ -228,10 +542,161 @@ function cmdLicenseInstall(args) {
|
|
|
228
542
|
console.log(`Now install the domain: kdna install ${license.domain}`);
|
|
229
543
|
}
|
|
230
544
|
|
|
545
|
+
async function cmdLicenseActivate(args = []) {
|
|
546
|
+
const domain = args.find((arg) => !arg.startsWith('--'));
|
|
547
|
+
const key = argValue(args, '--key') || argValue(args, '--license-key');
|
|
548
|
+
const server = argValue(args, '--server');
|
|
549
|
+
const jsonMode = args.includes('--json');
|
|
550
|
+
if (!domain || !key) {
|
|
551
|
+
error(
|
|
552
|
+
'Usage: kdna license activate <domain> --key <license-key> --server <url>',
|
|
553
|
+
EXIT.INPUT_ERROR,
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
let activation;
|
|
558
|
+
try {
|
|
559
|
+
activation = await requestActivation(domain, key, server);
|
|
560
|
+
} catch (e) {
|
|
561
|
+
error(`License activation failed: ${e.message}`, EXIT.TRUST_FAILED);
|
|
562
|
+
}
|
|
563
|
+
const dest = writeInstalledLicense(activation);
|
|
564
|
+
recordLicenseTrace('activate', activation, { server });
|
|
565
|
+
const record = licenseStatusRecord(activation, dest);
|
|
566
|
+
if (jsonMode) {
|
|
567
|
+
console.log(JSON.stringify(record, null, 2));
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
console.log(`License activated for ${domain}`);
|
|
571
|
+
console.log(` License ID: ${activation.license_id}`);
|
|
572
|
+
console.log(` Status: ${record.valid ? 'valid' : 'invalid'}`);
|
|
573
|
+
if (activation.offline_valid_until) {
|
|
574
|
+
console.log(` Offline valid until: ${activation.offline_valid_until}`);
|
|
575
|
+
}
|
|
576
|
+
console.log(` Saved to: ${dest}`);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
async function syncOneLicense(entry, serverOverride = null) {
|
|
580
|
+
const license = entry.license;
|
|
581
|
+
const key = licenseKey(license);
|
|
582
|
+
const server = serverOverride || license.activation_server || license.license_server_url || null;
|
|
583
|
+
if (!license.domain || !key || !server) {
|
|
584
|
+
return {
|
|
585
|
+
...licenseStatusRecord(license, entry.file),
|
|
586
|
+
synced: false,
|
|
587
|
+
sync_error: 'missing domain, license key, or activation server',
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
try {
|
|
591
|
+
const activation = await requestActivation(license.domain, key, server);
|
|
592
|
+
const merged = {
|
|
593
|
+
...license,
|
|
594
|
+
...activation,
|
|
595
|
+
license_key: key,
|
|
596
|
+
activation_server: server,
|
|
597
|
+
};
|
|
598
|
+
fs.writeFileSync(entry.file, JSON.stringify(merged, null, 2) + '\n');
|
|
599
|
+
recordLicenseTrace('sync', merged, { server, synced: true });
|
|
600
|
+
return { ...licenseStatusRecord(merged, entry.file), synced: true };
|
|
601
|
+
} catch (e) {
|
|
602
|
+
recordLicenseTrace('sync', license, { server, synced: false, sync_error: e.message });
|
|
603
|
+
return {
|
|
604
|
+
...licenseStatusRecord(license, entry.file),
|
|
605
|
+
synced: false,
|
|
606
|
+
sync_error: e.message,
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
async function cmdLicenseSync(args = []) {
|
|
612
|
+
const jsonMode = args.includes('--json');
|
|
613
|
+
const server = argValue(args, '--server');
|
|
614
|
+
const filtered = args.filter((arg) => !arg.startsWith('--') && arg !== server);
|
|
615
|
+
const domain = filtered[0] || null;
|
|
616
|
+
const entries = domain
|
|
617
|
+
? [{ file: licensePathForDomain(domain), license: readLicenseForDomain(domain) }].filter(
|
|
618
|
+
(entry) => entry.license,
|
|
619
|
+
)
|
|
620
|
+
: listInstalledLicenses();
|
|
621
|
+
const records = [];
|
|
622
|
+
for (const entry of entries) records.push(await syncOneLicense(entry, server));
|
|
623
|
+
if (jsonMode) {
|
|
624
|
+
console.log(JSON.stringify(domain ? records[0] || null : records, null, 2));
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
if (!records.length) {
|
|
628
|
+
console.log(domain ? `No installed license for ${domain}.` : 'No installed KDNA licenses.');
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
for (const record of records) {
|
|
632
|
+
console.log(`${record.domain || '(unknown)'} ${record.license_id || '(no license_id)'}`);
|
|
633
|
+
console.log(` Sync: ${record.synced ? 'ok' : 'failed'}`);
|
|
634
|
+
console.log(` Status: ${record.valid ? 'valid' : 'invalid'}`);
|
|
635
|
+
if (record.sync_error) console.log(` Error: ${record.sync_error}`);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
function licenseStatusRecord(license, file) {
|
|
640
|
+
const fingerprint = machineFingerprint();
|
|
641
|
+
const result = verifyLicense(license, null, fingerprint);
|
|
642
|
+
return {
|
|
643
|
+
domain: license.domain || null,
|
|
644
|
+
license_id: license.license_id || null,
|
|
645
|
+
issued_to: license.issued_to || null,
|
|
646
|
+
valid: result.valid,
|
|
647
|
+
issues: result.issues,
|
|
648
|
+
require_machine_binding: !!license.require_machine_binding,
|
|
649
|
+
machine_bound: !license.require_machine_binding || license.machine_fingerprint === fingerprint,
|
|
650
|
+
expires_at: license.expires_at || null,
|
|
651
|
+
revoked: license.revoked === true || license.status === 'revoked',
|
|
652
|
+
file,
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
function cmdLicenseStatus(args = []) {
|
|
657
|
+
const jsonMode = args.includes('--json');
|
|
658
|
+
const filtered = args.filter((a) => !a.startsWith('--'));
|
|
659
|
+
const domain = filtered[0] || null;
|
|
660
|
+
const entries = domain
|
|
661
|
+
? [{ file: licensePathForDomain(domain), license: readLicenseForDomain(domain) }].filter(
|
|
662
|
+
(entry) => entry.license,
|
|
663
|
+
)
|
|
664
|
+
: listInstalledLicenses();
|
|
665
|
+
const records = entries.map((entry) => licenseStatusRecord(entry.license, entry.file));
|
|
666
|
+
|
|
667
|
+
if (jsonMode) {
|
|
668
|
+
console.log(JSON.stringify(domain ? records[0] || null : records, null, 2));
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
if (!records.length) {
|
|
673
|
+
console.log(domain ? `No installed license for ${domain}.` : 'No installed KDNA licenses.');
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
for (const record of records) {
|
|
677
|
+
console.log(`${record.domain || '(unknown)'} ${record.license_id || '(no license_id)'}`);
|
|
678
|
+
console.log(` Status: ${record.valid ? 'valid' : 'invalid'}`);
|
|
679
|
+
if (record.issued_to) console.log(` Issued to: ${record.issued_to}`);
|
|
680
|
+
if (record.expires_at) console.log(` Expires: ${record.expires_at}`);
|
|
681
|
+
console.log(` Machine bound: ${record.machine_bound ? 'yes' : 'no'}`);
|
|
682
|
+
if (record.issues.length) {
|
|
683
|
+
console.log(` Issues: ${record.issues.join('; ')}`);
|
|
684
|
+
}
|
|
685
|
+
console.log(` File: ${record.file}`);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
231
689
|
module.exports = {
|
|
232
690
|
cmdLicenseGenerate,
|
|
233
691
|
cmdLicenseVerify,
|
|
234
692
|
cmdLicenseBind,
|
|
235
693
|
cmdLicenseShow,
|
|
236
694
|
cmdLicenseInstall,
|
|
695
|
+
cmdLicenseStatus,
|
|
696
|
+
cmdLicenseActivate,
|
|
697
|
+
cmdLicenseSync,
|
|
698
|
+
licenseDecryptOptionsForManifest,
|
|
699
|
+
licensePathForDomain,
|
|
700
|
+
machineFingerprint,
|
|
701
|
+
verifyLicense,
|
|
237
702
|
};
|
package/src/cmds/quality.js
CHANGED
|
@@ -7,7 +7,7 @@ function cmdCompare(args) {
|
|
|
7
7
|
if (!target || !args.includes('--input')) {
|
|
8
8
|
error(
|
|
9
9
|
'Usage:\n' +
|
|
10
|
-
' kdna compare <name> --input "<text>" [--json]\n' +
|
|
10
|
+
' kdna compare <name|file.kdna> --input "<text>" [--json]\n' +
|
|
11
11
|
'\n' +
|
|
12
12
|
'Runs your input through the LLM twice (with/without KDNA loaded),\n' +
|
|
13
13
|
'then diffs the reasoning trajectory. Requires ANTHROPIC_API_KEY or\n' +
|
|
@@ -63,7 +63,11 @@ function cmdDiff(args) {
|
|
|
63
63
|
function cmdSearch(args) {
|
|
64
64
|
const { cmdSearch } = require('../search');
|
|
65
65
|
const json = args.includes('--json');
|
|
66
|
-
const query = args
|
|
66
|
+
const query = args
|
|
67
|
+
.slice(1)
|
|
68
|
+
.filter((a) => a !== '--json')
|
|
69
|
+
.join(' ')
|
|
70
|
+
.trim();
|
|
67
71
|
cmdSearch(query, json);
|
|
68
72
|
}
|
|
69
73
|
|
|
@@ -91,7 +95,10 @@ function cmdSelect(args) {
|
|
|
91
95
|
function cmdLoad(args) {
|
|
92
96
|
const { cmdLoad } = require('../agent');
|
|
93
97
|
const target = args.filter((a) => !a.startsWith('--'))[1];
|
|
94
|
-
if (!target)
|
|
98
|
+
if (!target)
|
|
99
|
+
error(
|
|
100
|
+
'Usage: kdna load <name|file.kdna> [--as=prompt|json|raw] [--profile=index|compact|scenario|full]',
|
|
101
|
+
);
|
|
95
102
|
cmdLoad(target, args);
|
|
96
103
|
}
|
|
97
104
|
|