@knid/agentx 0.1.0 → 0.1.2

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/dist/index.js +92 -94
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import { Command } from "commander";
11
11
 
12
12
  // src/runtime/runner.ts
13
13
  import { execa } from "execa";
14
- import { unlinkSync, existsSync as existsSync4, readFileSync as readFileSync3 } from "fs";
14
+ import { unlinkSync as unlinkSync2, existsSync as existsSync6, readFileSync as readFileSync5 } from "fs";
15
15
 
16
16
  // src/config/agent-config.ts
17
17
  import { readFileSync, existsSync } from "fs";
@@ -346,6 +346,92 @@ function sendTelemetry(event) {
346
346
  }
347
347
  }
348
348
 
349
+ // src/secrets/store.ts
350
+ import { readFileSync as readFileSync4, writeFileSync as writeFileSync3, existsSync as existsSync5, unlinkSync, mkdirSync as mkdirSync3 } from "fs";
351
+ import { join as join4 } from "path";
352
+
353
+ // src/secrets/encrypt.ts
354
+ import { createCipheriv, createDecipheriv, randomBytes, scryptSync } from "crypto";
355
+ import { execFileSync } from "child_process";
356
+ import { readFileSync as readFileSync3, existsSync as existsSync4 } from "fs";
357
+ import { platform, hostname, homedir as homedir2 } from "os";
358
+ var ALGORITHM = "aes-256-gcm";
359
+ var IV_LENGTH = 12;
360
+ var KEY_LENGTH = 32;
361
+ var SALT = "agentx-salt";
362
+ function getMachineId() {
363
+ const os = platform();
364
+ if (os === "linux" && existsSync4("/etc/machine-id")) {
365
+ return readFileSync3("/etc/machine-id", "utf-8").trim();
366
+ }
367
+ if (os === "darwin") {
368
+ try {
369
+ const output = execFileSync(
370
+ "ioreg",
371
+ ["-rd1", "-c", "IOPlatformExpertDevice"],
372
+ { encoding: "utf-8" }
373
+ );
374
+ const match = output.match(/"IOPlatformUUID"\s*=\s*"([^"]+)"/);
375
+ if (match) return match[1];
376
+ } catch {
377
+ }
378
+ }
379
+ return `${hostname()}-${homedir2()}`;
380
+ }
381
+ function deriveKey() {
382
+ const machineId = getMachineId();
383
+ return scryptSync(machineId, SALT, KEY_LENGTH);
384
+ }
385
+ async function encrypt(secrets) {
386
+ const key = deriveKey();
387
+ const iv = randomBytes(IV_LENGTH);
388
+ const cipher = createCipheriv(ALGORITHM, key, iv);
389
+ const plaintext = JSON.stringify(secrets);
390
+ const encrypted = Buffer.concat([cipher.update(plaintext, "utf-8"), cipher.final()]);
391
+ const tag = cipher.getAuthTag();
392
+ return {
393
+ iv: iv.toString("hex"),
394
+ tag: tag.toString("hex"),
395
+ data: encrypted.toString("hex")
396
+ };
397
+ }
398
+ async function decrypt(store) {
399
+ const key = deriveKey();
400
+ const iv = Buffer.from(store.iv, "hex");
401
+ const tag = Buffer.from(store.tag, "hex");
402
+ const data = Buffer.from(store.data, "hex");
403
+ const decipher = createDecipheriv(ALGORITHM, key, iv);
404
+ decipher.setAuthTag(tag);
405
+ const decrypted = Buffer.concat([decipher.update(data), decipher.final()]);
406
+ return JSON.parse(decrypted.toString("utf-8"));
407
+ }
408
+
409
+ // src/secrets/store.ts
410
+ function getSecretsFilePath(agentName, secretsDir) {
411
+ return join4(secretsDir, `${agentName}.enc.json`);
412
+ }
413
+ async function saveSecrets(agentName, secrets, secretsDir = SECRETS_DIR) {
414
+ mkdirSync3(secretsDir, { recursive: true });
415
+ const encrypted = await encrypt(secrets);
416
+ const filePath = getSecretsFilePath(agentName, secretsDir);
417
+ writeFileSync3(filePath, JSON.stringify(encrypted, null, 2), "utf-8");
418
+ }
419
+ async function loadSecrets(agentName, secretsDir = SECRETS_DIR) {
420
+ const filePath = getSecretsFilePath(agentName, secretsDir);
421
+ if (!existsSync5(filePath)) {
422
+ return {};
423
+ }
424
+ const raw = readFileSync4(filePath, "utf-8");
425
+ const store = JSON.parse(raw);
426
+ return decrypt(store);
427
+ }
428
+ async function deleteSecrets(agentName, secretsDir = SECRETS_DIR) {
429
+ const filePath = getSecretsFilePath(agentName, secretsDir);
430
+ if (existsSync5(filePath)) {
431
+ unlinkSync(filePath);
432
+ }
433
+ }
434
+
349
435
  // src/runtime/runner.ts
350
436
  function buildClaudeArgs(options) {
351
437
  const args = [];
@@ -375,7 +461,7 @@ async function runAgent(agentName, options) {
375
461
  );
376
462
  let mcpConfigPath;
377
463
  if (manifest.mcp_servers && Object.keys(manifest.mcp_servers).length > 0) {
378
- const secrets = {};
464
+ const secrets = await loadSecrets(manifest.name);
379
465
  const resolved = resolveMCPConfig(manifest.mcp_servers, secrets);
380
466
  mcpConfigPath = await writeTempMCPConfig(resolved);
381
467
  }
@@ -390,7 +476,7 @@ async function runAgent(agentName, options) {
390
476
  finalPrompt = buildPromptWithPipe(finalPrompt, pipedContent);
391
477
  }
392
478
  if (options.file) {
393
- const fileContent = readFileSync3(options.file, "utf-8");
479
+ const fileContent = readFileSync5(options.file, "utf-8");
394
480
  finalPrompt = buildPromptWithPipe(finalPrompt, fileContent);
395
481
  }
396
482
  }
@@ -438,9 +524,9 @@ async function runAgent(agentName, options) {
438
524
  });
439
525
  throw error;
440
526
  } finally {
441
- if (mcpConfigPath && existsSync4(mcpConfigPath)) {
527
+ if (mcpConfigPath && existsSync6(mcpConfigPath)) {
442
528
  try {
443
- unlinkSync(mcpConfigPath);
529
+ unlinkSync2(mcpConfigPath);
444
530
  } catch {
445
531
  }
446
532
  }
@@ -496,94 +582,6 @@ import { Command as Command2 } from "commander";
496
582
 
497
583
  // src/secrets/configure-flow.ts
498
584
  import * as p from "@clack/prompts";
499
-
500
- // src/secrets/store.ts
501
- import { readFileSync as readFileSync5, writeFileSync as writeFileSync3, existsSync as existsSync6, unlinkSync as unlinkSync2, mkdirSync as mkdirSync3 } from "fs";
502
- import { join as join4 } from "path";
503
-
504
- // src/secrets/encrypt.ts
505
- import { createCipheriv, createDecipheriv, randomBytes, scryptSync } from "crypto";
506
- import { execFileSync } from "child_process";
507
- import { readFileSync as readFileSync4, existsSync as existsSync5 } from "fs";
508
- import { platform, hostname, homedir as homedir2 } from "os";
509
- var ALGORITHM = "aes-256-gcm";
510
- var IV_LENGTH = 12;
511
- var KEY_LENGTH = 32;
512
- var SALT = "agentx-salt";
513
- function getMachineId() {
514
- const os = platform();
515
- if (os === "linux" && existsSync5("/etc/machine-id")) {
516
- return readFileSync4("/etc/machine-id", "utf-8").trim();
517
- }
518
- if (os === "darwin") {
519
- try {
520
- const output = execFileSync(
521
- "ioreg",
522
- ["-rd1", "-c", "IOPlatformExpertDevice"],
523
- { encoding: "utf-8" }
524
- );
525
- const match = output.match(/"IOPlatformUUID"\s*=\s*"([^"]+)"/);
526
- if (match) return match[1];
527
- } catch {
528
- }
529
- }
530
- return `${hostname()}-${homedir2()}`;
531
- }
532
- function deriveKey() {
533
- const machineId = getMachineId();
534
- return scryptSync(machineId, SALT, KEY_LENGTH);
535
- }
536
- async function encrypt(secrets) {
537
- const key = deriveKey();
538
- const iv = randomBytes(IV_LENGTH);
539
- const cipher = createCipheriv(ALGORITHM, key, iv);
540
- const plaintext = JSON.stringify(secrets);
541
- const encrypted = Buffer.concat([cipher.update(plaintext, "utf-8"), cipher.final()]);
542
- const tag = cipher.getAuthTag();
543
- return {
544
- iv: iv.toString("hex"),
545
- tag: tag.toString("hex"),
546
- data: encrypted.toString("hex")
547
- };
548
- }
549
- async function decrypt(store) {
550
- const key = deriveKey();
551
- const iv = Buffer.from(store.iv, "hex");
552
- const tag = Buffer.from(store.tag, "hex");
553
- const data = Buffer.from(store.data, "hex");
554
- const decipher = createDecipheriv(ALGORITHM, key, iv);
555
- decipher.setAuthTag(tag);
556
- const decrypted = Buffer.concat([decipher.update(data), decipher.final()]);
557
- return JSON.parse(decrypted.toString("utf-8"));
558
- }
559
-
560
- // src/secrets/store.ts
561
- function getSecretsFilePath(agentName, secretsDir) {
562
- return join4(secretsDir, `${agentName}.enc.json`);
563
- }
564
- async function saveSecrets(agentName, secrets, secretsDir = SECRETS_DIR) {
565
- mkdirSync3(secretsDir, { recursive: true });
566
- const encrypted = await encrypt(secrets);
567
- const filePath = getSecretsFilePath(agentName, secretsDir);
568
- writeFileSync3(filePath, JSON.stringify(encrypted, null, 2), "utf-8");
569
- }
570
- async function loadSecrets(agentName, secretsDir = SECRETS_DIR) {
571
- const filePath = getSecretsFilePath(agentName, secretsDir);
572
- if (!existsSync6(filePath)) {
573
- return {};
574
- }
575
- const raw = readFileSync5(filePath, "utf-8");
576
- const store = JSON.parse(raw);
577
- return decrypt(store);
578
- }
579
- async function deleteSecrets(agentName, secretsDir = SECRETS_DIR) {
580
- const filePath = getSecretsFilePath(agentName, secretsDir);
581
- if (existsSync6(filePath)) {
582
- unlinkSync2(filePath);
583
- }
584
- }
585
-
586
- // src/secrets/configure-flow.ts
587
585
  async function runConfigureFlow(options) {
588
586
  const { agentName, declarations, secretsDir } = options;
589
587
  if (declarations.length === 0) {
@@ -1364,7 +1362,7 @@ async function publishAgent(agentDir, token) {
1364
1362
  formData.append("sha256", sha256);
1365
1363
  const client = createRegistryClient({ token });
1366
1364
  return client.put(
1367
- `/agents/${scope}/${manifest.name}`,
1365
+ `/agents`,
1368
1366
  formData
1369
1367
  );
1370
1368
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knid/agentx",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "The package manager for AI agents powered by Claude Code",
5
5
  "type": "module",
6
6
  "bin": {