@elisym/sdk 0.15.1 → 0.16.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 CHANGED
@@ -64,6 +64,27 @@ client.close();
64
64
  | `MediaService` | NIP-96 media uploads for job attachments |
65
65
  | `SolanaPaymentStrategy` | Solana fee calculation, payment request creation/validation |
66
66
 
67
+ ## Agent config (`elisym.yaml`)
68
+
69
+ Each agent has its own directory at `<project>/.elisym/<name>/` (project-local) or `~/.elisym/<name>/` (home-global), containing a public `elisym.yaml` and a private `.secrets.json`. The full layout and helpers live in the `@elisym/sdk/agent-store` subpath. CLI `elisym init` and MCP `create_agent` scaffold a fresh `elisym.yaml` with descriptive comments and commented-out examples for every optional field.
70
+
71
+ Top-level fields (full schema reference: [`skills/elisym-config/SKILL.md`](../../skills/elisym-config/SKILL.md)):
72
+
73
+ <!-- fields:begin -->
74
+
75
+ | Field | Type / Example | Required | Notes |
76
+ | -------------- | ----------------------------------------------------------- | -------- | ---------------------------------------------------------------------------------------------- |
77
+ | `display_name` | `string` (`<=64`) | no | Human-readable name shown in UI. Falls back to the folder name. |
78
+ | `description` | `string` (`<=500`) | no | Public description shown in discovery results. Defaults to `""`. |
79
+ | `picture` | `string` - `./avatar.png` or `https://...` | no | Avatar. Relative paths resolve against the YAML; absolute URLs must be HTTPS. |
80
+ | `banner` | `string` - `./banner.png` or `https://...` | no | Cover image. Same resolution rules as `picture`. |
81
+ | `relays` | `string[]` - `["wss://relay.damus.io", ...]` | no | Nostr relays. Defaults to `relay.damus.io`, `nos.lol`, `relay.nostr.band` when empty. |
82
+ | `payments` | `[{ chain, network, address }]` | no | One entry per `(chain, network)`. Receives every asset on that chain (SOL directly, SPL ATAs). |
83
+ | `llm` | `{ provider, model, max_tokens }` | no | Required for provider mode. Omit for customer mode or non-LLM agents. |
84
+ | `security` | `{ withdrawals_enabled?, agent_switch_enabled? }` (partial) | no | Capability gates. Both default to `false`. |
85
+
86
+ <!-- fields:end -->
87
+
67
88
  ## How It Works
68
89
 
69
90
  ```
@@ -14,6 +14,15 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
14
  var YAML__default = /*#__PURE__*/_interopDefault(YAML);
15
15
 
16
16
  // src/agent-store/schema.ts
17
+
18
+ // src/constants.ts
19
+ var RELAYS = [
20
+ "wss://relay.damus.io",
21
+ "wss://nos.lol",
22
+ "wss://relay.nostr.band",
23
+ "wss://relay.primal.net",
24
+ "wss://relay.snort.social"
25
+ ];
17
26
  var LIMITS = {
18
27
  MAX_DESCRIPTION_LENGTH: 500,
19
28
  MAX_AGENT_NAME_LENGTH: 64};
@@ -305,6 +314,98 @@ function listEncryptedFields(secrets) {
305
314
  function homeElisymPathHint(name) {
306
315
  return `~/.elisym/${name}/elisym.yaml`;
307
316
  }
317
+ var PLACEHOLDER_DISPLAY_NAME = "My Agent";
318
+ var PLACEHOLDER_PICTURE = "./avatar.png";
319
+ var PLACEHOLDER_BANNER = "./banner.png";
320
+ var PLACEHOLDER_PAYMENTS = [
321
+ { chain: "solana", network: "devnet", address: "<your-solana-address>" }
322
+ ];
323
+ var PLACEHOLDER_LLM = {
324
+ provider: "anthropic",
325
+ model: "claude-sonnet-4-6",
326
+ max_tokens: 4096
327
+ };
328
+ var DEFAULT_SECURITY = { withdrawals_enabled: false, agent_switch_enabled: false };
329
+ function commentLines(text) {
330
+ return text.split("\n").map((line) => line.length > 0 ? `# ${line}` : "#").join("\n");
331
+ }
332
+ function isUnset(value) {
333
+ if (value === void 0) {
334
+ return true;
335
+ }
336
+ if (Array.isArray(value) && value.length === 0) {
337
+ return true;
338
+ }
339
+ return false;
340
+ }
341
+ function renderBlock(block) {
342
+ const header = commentLines(block.description);
343
+ const unset = isUnset(block.value);
344
+ const renderValue = unset ? block.placeholder : block.value;
345
+ const yamlBody = YAML__default.default.stringify({ [block.key]: renderValue }).trimEnd();
346
+ const body = unset ? commentLines(yamlBody) : yamlBody;
347
+ return `${header}
348
+ ${body}`;
349
+ }
350
+ function renderInitialYaml(yaml) {
351
+ const security = {
352
+ withdrawals_enabled: yaml.security.withdrawals_enabled ?? DEFAULT_SECURITY.withdrawals_enabled,
353
+ agent_switch_enabled: yaml.security.agent_switch_enabled ?? DEFAULT_SECURITY.agent_switch_enabled
354
+ };
355
+ const blocks = [
356
+ {
357
+ description: "Human-readable name shown in UI. Falls back to the folder name when omitted.",
358
+ key: "display_name",
359
+ value: yaml.display_name,
360
+ placeholder: PLACEHOLDER_DISPLAY_NAME
361
+ },
362
+ {
363
+ description: "Public description shown in discovery results.",
364
+ key: "description",
365
+ value: yaml.description,
366
+ placeholder: ""
367
+ },
368
+ {
369
+ description: "Avatar - relative path (to this YAML) or absolute URL.",
370
+ key: "picture",
371
+ value: yaml.picture,
372
+ placeholder: PLACEHOLDER_PICTURE
373
+ },
374
+ {
375
+ description: "Banner - relative path (to this YAML) or absolute URL.",
376
+ key: "banner",
377
+ value: yaml.banner,
378
+ placeholder: PLACEHOLDER_BANNER
379
+ },
380
+ {
381
+ description: "Nostr relays this agent connects to.",
382
+ key: "relays",
383
+ value: yaml.relays,
384
+ placeholder: [...RELAYS]
385
+ },
386
+ {
387
+ description: "Payment wallets per chain. Each entry receives every asset on that chain (SOL directly; SPL tokens via the ATA derived from this address).",
388
+ key: "payments",
389
+ value: yaml.payments,
390
+ placeholder: PLACEHOLDER_PAYMENTS
391
+ },
392
+ {
393
+ description: "LLM configuration. Omit (or comment out) to run as a non-LLM agent (static-file or script skills only).",
394
+ key: "llm",
395
+ value: yaml.llm,
396
+ placeholder: PLACEHOLDER_LLM
397
+ },
398
+ {
399
+ description: "Capability gates. Both default to false; flip to true to enable.",
400
+ key: "security",
401
+ value: security,
402
+ placeholder: DEFAULT_SECURITY
403
+ }
404
+ ];
405
+ return blocks.map(renderBlock).join("\n\n") + "\n";
406
+ }
407
+
408
+ // src/agent-store/writer.ts
308
409
  var GITIGNORE_CONTENT = [
309
410
  "# elisym private state - do not commit.",
310
411
  ".secrets.json",
@@ -349,6 +450,138 @@ async function writeYaml(agentDir, yaml) {
349
450
  const target = agentPaths(agentDir).yaml;
350
451
  await writeFileAtomic(target, body, 420);
351
452
  }
453
+ async function writeYamlInitial(agentDir, yaml) {
454
+ const validated = ElisymYamlSchema.parse(yaml);
455
+ const body = renderInitialYaml(validated);
456
+ const target = agentPaths(agentDir).yaml;
457
+ await writeFileAtomic(target, body, 420);
458
+ }
459
+ async function writeExampleSkillTemplate(agentDir) {
460
+ const target = path.join(agentDir, "skills", "EXAMPLE.md");
461
+ await writeFileIfMissing(target, EXAMPLE_SKILL_TEMPLATE, 420);
462
+ }
463
+ var EXAMPLE_SKILL_TEMPLATE = `# elisym skill template
464
+ #
465
+ # This is reference material, not an active skill. The agent runtime
466
+ # only loads skills from \`skills/<name>/SKILL.md\` (one folder per
467
+ # skill). To turn this template into a real skill:
468
+ #
469
+ # 1. mkdir skills/my-skill
470
+ # 2. cp skills/EXAMPLE.md skills/my-skill/SKILL.md
471
+ # 3. uncomment the fields you need and fill in real values
472
+ # 4. delete this comment block from the new file
473
+ #
474
+ # Full reference: see packages/cli/SKILLS.md in the elisym monorepo.
475
+
476
+ # ---
477
+ # # Required fields ---------------------------------------------------
478
+ #
479
+ # # Skill name. Must be unique within the agent. Used as the d-tag for
480
+ # # routing incoming jobs (NIP-89/NIP-90).
481
+ # name: My Skill
482
+ #
483
+ # # One-line description shown to customers in discovery UIs. Keep it
484
+ # # short and concrete - this is the "elevator pitch" for the skill.
485
+ # description: Send a prompt, get back a poem about it.
486
+ #
487
+ # # Capability tags. Customers filter and discover skills by these.
488
+ # # At least one entry required. Use lowercase kebab-case.
489
+ # capabilities:
490
+ # - poetry
491
+ # - text-generation
492
+ #
493
+ # # Price the customer pays per job. Number or numeric string. Free
494
+ # # skills (price: 0) are allowed only when the agent runtime is
495
+ # # configured with \`allowFreeSkills\`.
496
+ # price: 0.05
497
+ #
498
+ # # Asset the price is denominated in. Defaults to "sol" for back-compat
499
+ # # but USDC is the canonical paid-skill currency for examples.
500
+ # token: usdc
501
+ # # Optional explicit mint (base58). Resolved automatically for known
502
+ # # tokens, so usually omit this.
503
+ # # mint: 4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU
504
+ #
505
+ # # Execution mode. Defaults to "llm" if omitted.
506
+ # # - llm: feed input to an LLM with the system prompt below.
507
+ # # - static-file: return the contents of a fixed file (no input read).
508
+ # # - static-script: spawn a script with no stdin (no input read).
509
+ # # - dynamic-script: spawn a script and pipe the customer's input to stdin.
510
+ # mode: llm
511
+ #
512
+ # # ---
513
+ # # LLM configuration / dependency -----------------------------------
514
+ # #
515
+ # # For mode: 'llm', \`provider\` + \`model\` override the agent default
516
+ # # for runtime LLM execution. \`max_tokens\` overrides the default cap.
517
+ # #
518
+ # # For script modes (static-script / dynamic-script / static-file):
519
+ # # \`provider\` + \`model\` declare which LLM API key the script
520
+ # # depends on. The agent registers the (provider, model) pair with
521
+ # # the health monitor so it can:
522
+ # # - probe the key at startup (refuse to start on invalid/billing-out)
523
+ # # - reactively flip the pair to unhealthy if the script exits with
524
+ # # SCRIPT_EXIT_BILLING_EXHAUSTED (= 42), refusing future jobs
525
+ # # before payment until the key recovers
526
+ # # - run a 5-min lazy recovery probe loop that flips the pair back
527
+ # # to healthy as soon as the key works again
528
+ # # \`max_tokens\` is rejected for script modes (the script controls
529
+ # # its own token limits).
530
+ # # provider: anthropic
531
+ # # model: claude-haiku-4-5-20251001
532
+ # # max_tokens: 4096
533
+ #
534
+ # # ---
535
+ # # mode-specific fields -------------------------------------------
536
+ #
537
+ # # Required when mode === 'static-file'.
538
+ # # output_file: ./output.txt
539
+ #
540
+ # # Required when mode === 'static-script' | 'dynamic-script'.
541
+ # # script: ./scripts/run.sh
542
+ # # script_args:
543
+ # # - --flag
544
+ # # - value
545
+ # # script_timeout_ms: 60000
546
+ #
547
+ # # ---
548
+ # # mode === 'llm' extras ------------------------------------------
549
+ # #
550
+ # # External tools the LLM can invoke during a job. Each tool is a
551
+ # # named subprocess; the LLM decides whether/when to call it.
552
+ # # tools:
553
+ # # - name: lookup
554
+ # # description: Look up a record by id.
555
+ # # command:
556
+ # # - ./tools/lookup.sh
557
+ # # parameters:
558
+ # # - name: id
559
+ # # description: Record identifier (UUID).
560
+ # # required: true
561
+ #
562
+ # # Cap on tool-use rounds (LLM <-> tools loop). Default 10.
563
+ # # max_tool_rounds: 10
564
+ #
565
+ # # ---
566
+ # # Per-skill rate limit (any mode) --------------------------------
567
+ # # Snake-case in YAML, applied by the runtime regardless of mode.
568
+ # # rate_limit:
569
+ # # per_window_secs: 60
570
+ # # max_per_window: 30
571
+ #
572
+ # # ---
573
+ # # Imagery ---------------------------------------------------------
574
+ # # Either a local file path (uploaded on first start) or an absolute
575
+ # # URL. Local paths must stay inside the skill directory.
576
+ # # image_file: ./skill-icon.png
577
+ # # image: https://example.com/icon.png
578
+ # ---
579
+ #
580
+ # Markdown body below the frontmatter is the system prompt for
581
+ # mode === 'llm'. For other modes it's ignored.
582
+ #
583
+ # You are a helpful assistant. Reply concisely.
584
+ `;
352
585
  async function writeSecrets(agentDir, secrets, passphrase) {
353
586
  const validated = SecretsSchema.parse(secrets);
354
587
  let encryptedLlmKeys;
@@ -544,12 +777,15 @@ exports.lookupCachedUrl = lookupCachedUrl;
544
777
  exports.newCacheEntry = newCacheEntry;
545
778
  exports.readAgentPublic = readAgentPublic;
546
779
  exports.readMediaCache = readMediaCache;
780
+ exports.renderInitialYaml = renderInitialYaml;
547
781
  exports.resolveAgent = resolveAgent;
548
782
  exports.resolveInHome = resolveInHome;
549
783
  exports.resolveInProject = resolveInProject;
784
+ exports.writeExampleSkillTemplate = writeExampleSkillTemplate;
550
785
  exports.writeFileAtomic = writeFileAtomic;
551
786
  exports.writeMediaCache = writeMediaCache;
552
787
  exports.writeSecrets = writeSecrets;
553
788
  exports.writeYaml = writeYaml;
789
+ exports.writeYamlInitial = writeYamlInitial;
554
790
  //# sourceMappingURL=agent-store.cjs.map
555
791
  //# sourceMappingURL=agent-store.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/constants.ts","../src/agent-store/schema.ts","../src/agent-store/paths.ts","../src/agent-store/resolver.ts","../src/primitives/config.ts","../src/primitives/encryption.ts","../src/agent-store/loader.ts","../src/agent-store/writer.ts","../src/agent-store/list.ts","../src/agent-store/media-cache.ts"],"names":["z","join","homedir","resolve","existsSync","dirname","statSync","randomBytes","scryptSync","createCipheriv","Buffer","createDecipheriv","readFile","YAML","mkdir","path","writeFile","rename","readdir","createHash"],"mappings":";;;;;;;;;;;;;;;;AAqGO,IAAM,MAAA,GAAS;AAAA,EAIpB,sBAAA,EAAwB,GAAA;AAAA,EACxB,qBAAA,EAAuB,EAEzB,CAAA;;;ACpGA,IAAM,kBAAA,GAAqB,kBAAA;AAEpB,IAAM,eAAA,GAAkBA,KAAA,CAC5B,MAAA,EAAO,CACP,GAAA,CAAI,CAAC,CAAA,CACL,GAAA,CAAI,MAAA,CAAO,qBAAqB,CAAA,CAChC,KAAA,CAAM,oBAAoB,0CAA0C;AAQhE,IAAM,aAAA,GAAgBA,MAAE,MAAA,CAAO;AAAA,EACpC,KAAA,EAAOA,KAAA,CAAE,OAAA,CAAQ,QAAQ,CAAA;AAAA,EACzB,OAAA,EAASA,KAAA,CAAE,IAAA,CAAK,CAAC,QAAQ,CAAC,CAAA;AAAA,EAC1B,OAAA,EAASA,KAAA,CAAE,MAAA,EAAO,CAAE,IAAI,CAAC;AAC3B,CAAC;AAEM,IAAM,SAAA,GAAYA,MAAE,MAAA,CAAO;AAAA,EAChC,QAAA,EAAUA,KAAA,CAAE,MAAA,EAAO,CAAE,IAAI,CAAC,CAAA;AAAA,EAC1B,KAAA,EAAOA,KAAA,CAAE,MAAA,EAAO,CAAE,IAAI,CAAC,CAAA;AAAA,EACvB,UAAA,EAAYA,KAAA,CAAE,MAAA,EAAO,CAAE,GAAA,EAAI,CAAE,QAAA,EAAS,CAAE,GAAA,CAAI,GAAO,CAAA,CAAE,OAAA,CAAQ,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AA,CAAM,MAAA,GAAS,KAAA,CAAM,GAAA,GAAM,IAAA;AAC7C;AAEO,SAAS,aAAA,CAAc,KAAa,MAAA,EAAiC;AAC1E,EAAA,OAAO,EAAE,KAAK,MAAA,EAAQ,WAAA,EAAA,qBAAiB,IAAA,EAAK,EAAE,aAAY,EAAE;AAC9D","file":"agent-store.cjs","sourcesContent":["import type { Address } from '@solana/kit';\n\nexport const RELAYS = [\n 'wss://relay.damus.io',\n 'wss://nos.lol',\n 'wss://relay.nostr.band',\n 'wss://relay.primal.net',\n 'wss://relay.snort.social',\n];\n\nexport const KIND_APP_HANDLER = 31990;\nexport const KIND_JOB_REQUEST_BASE = 5000;\nexport const KIND_JOB_RESULT_BASE = 6000;\nexport const KIND_JOB_FEEDBACK = 7000;\nexport const DEFAULT_KIND_OFFSET = 100;\n\n/** Default job request kind (5000 + 100). */\nexport const KIND_JOB_REQUEST = KIND_JOB_REQUEST_BASE + DEFAULT_KIND_OFFSET;\n/** Default job result kind (6000 + 100). */\nexport const KIND_JOB_RESULT = KIND_JOB_RESULT_BASE + DEFAULT_KIND_OFFSET;\n\n/** Compute a job request kind from an offset (5000 + offset). */\nexport function jobRequestKind(offset: number): number {\n if (!Number.isInteger(offset) || offset < 0 || offset >= 1000) {\n throw new Error(`Invalid kind offset: ${offset}. Must be integer 0-999.`);\n }\n return KIND_JOB_REQUEST_BASE + offset;\n}\n\n/** Compute a job result kind from an offset (6000 + offset). */\nexport function jobResultKind(offset: number): number {\n if (!Number.isInteger(offset) || offset < 0 || offset >= 1000) {\n throw new Error(`Invalid kind offset: ${offset}. Must be integer 0-999.`);\n }\n return KIND_JOB_RESULT_BASE + offset;\n}\n\n/** Ephemeral ping/pong kinds (not stored by relays, forwarded in real-time). */\nexport const KIND_PING = 20200;\nexport const KIND_PONG = 20201;\n\nexport const LAMPORTS_PER_SOL = 1_000_000_000;\n\n/**\n * Solana program ID for the elisym protocol config (devnet deployment).\n *\n * The Anchor program at this address is the source of truth for fee bps,\n * treasury address, and admin rotation state. Read via `getProtocolConfig`.\n */\nexport const PROTOCOL_PROGRAM_ID_DEVNET = 'BrX1CRkSgvcjxBvc2bgc3QqgWjinusofDmeP7ZVxvwrE' as Address;\n\n/**\n * Read-only marker pubkey attached as a non-signer account to every elisym\n * payment transaction. Lets indexers enumerate every elisym tx network-wide\n * via a single `getSignaturesForAddress(ELISYM_PROTOCOL_TAG)` call,\n * independent of fee size or recipient.\n *\n * The account does not need to exist on-chain; including its pubkey as an\n * extra read-only account in the provider transfer instruction is enough for\n * Solana's tx-by-account index to pick it up. The corresponding secret key\n * was generated and discarded - the tag never signs and never holds funds.\n */\nexport const ELISYM_PROTOCOL_TAG = 'ELiZksgwDt41LaeuPDLkUfWgFXhGgVayTMP7L5nTSEL8' as Address;\n\nexport type ProtocolCluster = 'devnet' | 'mainnet' | 'localnet';\n\n/**\n * Resolve the elisym-config program ID for a given Solana cluster.\n * Mainnet is intentionally unsupported until the program ships there.\n */\nexport function getProtocolProgramId(cluster: ProtocolCluster): Address {\n switch (cluster) {\n case 'devnet':\n case 'localnet':\n return PROTOCOL_PROGRAM_ID_DEVNET;\n case 'mainnet':\n throw new Error('Protocol program is not deployed on mainnet yet');\n }\n}\n\n/** Default values for timeouts, retries, and batch sizes. */\nexport const DEFAULTS = {\n SUBSCRIPTION_TIMEOUT_MS: 120_000,\n PING_TIMEOUT_MS: 3_000,\n PING_RETRIES: 2,\n PING_CACHE_TTL_MS: 30_000,\n PAYMENT_EXPIRY_SECS: 600,\n BATCH_SIZE: 250,\n QUERY_TIMEOUT_MS: 15_000,\n EOSE_TIMEOUT_MS: 3_000,\n VERIFY_RETRIES: 10,\n VERIFY_INTERVAL_MS: 3_000,\n VERIFY_BY_REF_RETRIES: 15,\n VERIFY_BY_REF_INTERVAL_MS: 2_000,\n RESULT_RETRY_COUNT: 3,\n RESULT_RETRY_BASE_MS: 1_000,\n QUERY_MAX_CONCURRENCY: 6,\n VERIFY_SIGNATURE_LIMIT: 25,\n} as const;\n\n/** Protocol limits for input validation. */\nexport const LIMITS = {\n MAX_INPUT_LENGTH: 100_000,\n MAX_TIMEOUT_SECS: 600,\n MAX_CAPABILITIES: 20,\n MAX_DESCRIPTION_LENGTH: 500,\n MAX_AGENT_NAME_LENGTH: 64,\n MAX_CAPABILITY_LENGTH: 64,\n} as const;\n","/**\n * Zod schemas for elisym.yaml (public source of truth) and secrets.json (private).\n * Shared between CLI (provider mode) and MCP (customer mode, future provider mode).\n */\n\nimport { z } from 'zod';\nimport { LIMITS } from '../constants';\n\nconst AGENT_NAME_PATTERN = /^[a-zA-Z0-9_-]+$/;\n\nexport const AgentNameSchema = z\n .string()\n .min(1)\n .max(LIMITS.MAX_AGENT_NAME_LENGTH)\n .regex(AGENT_NAME_PATTERN, 'alphanumeric, underscore, or hyphen only');\n\n/**\n * Agent wallet entry. One entry per (chain, network) - the address receives\n * every asset on that chain (SOL directly, SPL tokens via their ATA derived\n * from (address, mint)). Per-asset pricing lives in each skill's `SKILL.md`;\n * the canonical mint registry lives in `KNOWN_ASSETS` (payment/assets.ts).\n */\nexport const PaymentSchema = z.object({\n chain: z.literal('solana'),\n network: z.enum(['devnet']),\n address: z.string().min(1),\n});\n\nexport const LlmSchema = z.object({\n provider: z.string().min(1),\n model: z.string().min(1),\n max_tokens: z.number().int().positive().max(200_000).default(4096),\n});\n\nexport const SecurityFlagsSchema = z.object({\n withdrawals_enabled: z.boolean().default(false),\n agent_switch_enabled: z.boolean().default(false),\n});\n\n/**\n * elisym.yaml schema. Public - committed to git.\n * Agent name NOT stored here - derived from containing folder name.\n *\n * The top-level field list is mirrored in `skills/elisym-config/SKILL.md`\n * so the elisym-config agent skill can patch this file directly. Drift\n * is guarded by `packages/sdk/tests/config-skill-drift.test.ts` - when\n * you add or remove a top-level field here, update that SKILL.md too.\n */\nexport const ElisymYamlSchema = z\n .object({\n /** Human-readable name shown in UI (optional). Falls back to folder name. */\n display_name: z.string().max(LIMITS.MAX_AGENT_NAME_LENGTH).optional(),\n description: z.string().max(LIMITS.MAX_DESCRIPTION_LENGTH).default(''),\n /** Relative path (to this YAML) or absolute URL. */\n picture: z.string().optional(),\n /** Relative path (to this YAML) or absolute URL. */\n banner: z.string().optional(),\n relays: z.array(z.string().url()).default([]),\n payments: z.array(PaymentSchema).default([]),\n llm: LlmSchema.optional(),\n security: SecurityFlagsSchema.partial().default({}),\n })\n .strict();\n\nexport type ElisymYaml = z.infer<typeof ElisymYamlSchema>;\nexport type PaymentEntry = z.infer<typeof PaymentSchema>;\nexport type LlmEntry = z.infer<typeof LlmSchema>;\nexport type SecurityFlags = z.infer<typeof SecurityFlagsSchema>;\n\n/**\n * secrets.json schema. Private - .gitignore.\n * Values may be plaintext or `encrypted:v1:...` blobs (AES-256-GCM + scrypt).\n *\n * `llm_api_keys` is a generic record keyed by provider id (e.g. `anthropic`,\n * `openai`, future `xai`/`google`/...). Adding a new LLM provider does not\n * require a schema change. Each value is a separate ciphertext blob when\n * encrypted.\n */\nexport const SecretsSchema = z\n .object({\n nostr_secret_key: z.string().min(1),\n solana_secret_key: z.string().optional(),\n /** Per-provider LLM API keys, keyed by descriptor id (e.g. `anthropic`, `openai`). */\n llm_api_keys: z.record(z.string(), z.string()).optional(),\n })\n .strict();\n\nexport type Secrets = z.infer<typeof SecretsSchema>;\n\nexport interface MediaCacheEntry {\n url: string;\n sha256: string;\n uploaded_at: string;\n}\n\nexport const MediaCacheEntrySchema: z.ZodType<MediaCacheEntry> = z\n .object({\n url: z.string().url(),\n sha256: z.string().regex(/^[a-f0-9]{64}$/),\n uploaded_at: z.string(),\n })\n .strict();\n\nexport const MediaCacheSchema = z.record(z.string(), MediaCacheEntrySchema);\n\nexport type MediaCache = z.infer<typeof MediaCacheSchema>;\n","/**\n * Path helpers for .elisym/ layout.\n *\n * Project-local (walk up from CWD until .git or $HOME):\n * <project>/.elisym/<name>/{elisym.yaml, .secrets.json, .media-cache.json, .jobs.json, .gitignore}\n *\n * Home-global (~/.elisym/<name>/): same file structure.\n *\n * Node.js only - relies on `node:fs`/`node:os`/`node:path`.\n */\n\nimport { existsSync, statSync } from 'node:fs';\nimport { homedir } from 'node:os';\nimport { dirname, join, resolve } from 'node:path';\n\nexport const ELISYM_DIRNAME = '.elisym';\nexport const YAML_FILENAME = 'elisym.yaml';\nexport const SECRETS_FILENAME = '.secrets.json';\nexport const MEDIA_CACHE_FILENAME = '.media-cache.json';\nexport const JOBS_FILENAME = '.jobs.json';\nexport const GITIGNORE_FILENAME = '.gitignore';\nexport const SKILLS_DIRNAME = 'skills';\n\n/** Max depth for walk-up search (safety guard against unbounded loops). */\nconst MAX_WALK_UP_DEPTH = 64;\n\n/** ~/.elisym/ */\nexport function homeElisymDir(): string {\n return join(homedir(), ELISYM_DIRNAME);\n}\n\n/** ~/.elisym/config.yaml — global (not per-agent) config file. */\nexport function globalConfigPath(): string {\n return join(homeElisymDir(), 'config.yaml');\n}\n\n/**\n * Walk up from `startDir` looking for `.elisym/` directory.\n * Stops at (a) the first `.git` directory/file, (b) `$HOME`, (c) filesystem root,\n * or (d) MAX_WALK_UP_DEPTH iterations. Returns absolute path or null.\n */\nexport function findProjectElisymDir(startDir: string): string | null {\n const home = homedir();\n let current = resolve(startDir);\n let previous: string | null = null;\n\n for (let depth = 0; depth < MAX_WALK_UP_DEPTH; depth++) {\n if (current === previous) {\n return null;\n }\n\n // At $HOME: ~/.elisym/ is the home-global layout, not a project-local one.\n // Stop without matching to avoid misclassifying home agents as project.\n if (current === home) {\n return null;\n }\n\n const elisymCandidate = join(current, ELISYM_DIRNAME);\n if (existsSync(elisymCandidate) && safeIsDir(elisymCandidate)) {\n return elisymCandidate;\n }\n\n const gitCandidate = join(current, '.git');\n if (existsSync(gitCandidate)) {\n return null;\n }\n\n previous = current;\n current = dirname(current);\n }\n\n return null;\n}\n\nexport interface AgentPaths {\n dir: string;\n yaml: string;\n secrets: string;\n mediaCache: string;\n jobs: string;\n gitignore: string;\n skills: string;\n}\n\n/** Compute all file/dir paths for an agent given its root directory. */\nexport function agentPaths(agentDir: string): AgentPaths {\n return {\n dir: agentDir,\n yaml: join(agentDir, YAML_FILENAME),\n secrets: join(agentDir, SECRETS_FILENAME),\n mediaCache: join(agentDir, MEDIA_CACHE_FILENAME),\n jobs: join(agentDir, JOBS_FILENAME),\n gitignore: join(agentDir, GITIGNORE_FILENAME),\n skills: join(agentDir, SKILLS_DIRNAME),\n };\n}\n\nfunction safeIsDir(path: string): boolean {\n try {\n return statSync(path).isDirectory();\n } catch {\n return false;\n }\n}\n","/**\n * Agent resolution: find <name>/elisym.yaml via project-local walk-up, fallback to home.\n */\n\nimport { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { ELISYM_DIRNAME, YAML_FILENAME, findProjectElisymDir, homeElisymDir } from './paths';\n\nexport type AgentSource = 'project' | 'home';\n\nexport interface ResolvedAgent {\n name: string;\n dir: string;\n source: AgentSource;\n /** true when both a project-local and a home-global agent exist with the same name. */\n shadowsGlobal: boolean;\n}\n\n/**\n * Resolve an agent by name. Precedence: project-local beats home-global.\n * Returns null if not found in either location.\n */\nexport function resolveAgent(name: string, cwd: string): ResolvedAgent | null {\n const projectDir = resolveInProject(name, cwd);\n const homeDir = resolveInHome(name);\n\n if (projectDir) {\n return {\n name,\n dir: projectDir,\n source: 'project',\n shadowsGlobal: homeDir !== null,\n };\n }\n\n if (homeDir) {\n return { name, dir: homeDir, source: 'home', shadowsGlobal: false };\n }\n\n return null;\n}\n\n/** Return project-local agent dir if its YAML exists, else null. */\nexport function resolveInProject(name: string, cwd: string): string | null {\n const projectElisym = findProjectElisymDir(cwd);\n if (!projectElisym) {\n return null;\n }\n const agentDir = join(projectElisym, name);\n const yamlPath = join(agentDir, YAML_FILENAME);\n return existsSync(yamlPath) ? agentDir : null;\n}\n\n/** Return home-global agent dir if its YAML exists, else null. */\nexport function resolveInHome(name: string): string | null {\n const agentDir = join(homeElisymDir(), name);\n const yamlPath = join(agentDir, YAML_FILENAME);\n return existsSync(yamlPath) ? agentDir : null;\n}\n\n/** Path to the .elisym root (project or home) for a given target. */\nexport function elisymRootFor(target: AgentSource, cwd: string): string | null {\n if (target === 'home') {\n return homeElisymDir();\n }\n return findProjectElisymDir(cwd);\n}\n\n/** Re-export for convenience. */\nexport { ELISYM_DIRNAME };\n","/**\n * Agent-name validation shared between CLI and MCP.\n * Browser-safe - no Node.js imports.\n */\n\nimport { LIMITS } from '../constants';\n\nexport function validateAgentName(name: string): void {\n if (!name || name.length > LIMITS.MAX_AGENT_NAME_LENGTH || !/^[a-zA-Z0-9_-]+$/.test(name)) {\n throw new Error('Agent name must be 1-64 characters, alphanumeric, underscore, or hyphen.');\n }\n}\n","/**\n * Secret encryption/decryption for agent config files.\n * Uses scrypt (KDF) + AES-256-GCM (cipher).\n * Format: \"encrypted:v1:\" + base64(salt[16] + iv[12] + ciphertext + tag[16])\n *\n * scrypt params: N=2^17, r=8, p=1 (~128 MB RAM per derivation).\n *\n * Node.js/Bun only - not available in browsers. Reachable only via the\n * '@elisym/sdk/node' subpath, which browser bundlers will not resolve.\n */\n\nimport { Buffer } from 'node:buffer';\nimport { createCipheriv, createDecipheriv, randomBytes, scryptSync } from 'node:crypto';\n\nconst PREFIX = 'encrypted:v1:';\nconst SALT_LENGTH = 16;\nconst IV_LENGTH = 12;\nconst TAG_LENGTH = 16;\nconst KEY_LENGTH = 32; // AES-256\n// v1: N=2^17 (OWASP minimum). v2 will use N=2^20 with format migration.\nconst SCRYPT_N = 2 ** 17;\nconst SCRYPT_R = 8;\nconst SCRYPT_P = 1;\nconst SCRYPT_MAXMEM = 128 * SCRYPT_N * SCRYPT_R * 2; // 2x the minimum required memory\n\n/** Check if a value is encrypted (has the encrypted:v1: prefix). */\nexport function isEncrypted(value: string): boolean {\n return value.startsWith(PREFIX);\n}\n\n/** Encrypt a plaintext secret with a passphrase. Returns \"encrypted:v1:base64...\". Node.js/Bun only. */\nexport function encryptSecret(plaintext: string, passphrase: string): string {\n if (!passphrase) {\n throw new Error('Passphrase must not be empty.');\n }\n\n const salt = randomBytes(SALT_LENGTH);\n const key = scryptSync(passphrase, salt, KEY_LENGTH, {\n N: SCRYPT_N,\n r: SCRYPT_R,\n p: SCRYPT_P,\n maxmem: SCRYPT_MAXMEM,\n });\n const iv = randomBytes(IV_LENGTH);\n\n const cipher = createCipheriv('aes-256-gcm', key, iv);\n const encrypted = Buffer.concat([cipher.update(plaintext, 'utf8'), cipher.final()]);\n const tag = cipher.getAuthTag();\n\n const payload = Buffer.concat([salt, iv, encrypted, tag]);\n return PREFIX + payload.toString('base64');\n}\n\n/** Decrypt an encrypted secret with a passphrase. Throws on wrong passphrase or corrupted data. Node.js/Bun only. */\nexport function decryptSecret(encrypted: string, passphrase: string): string {\n if (!isEncrypted(encrypted)) {\n throw new Error('Value is not encrypted (missing encrypted:v1: prefix).');\n }\n if (!passphrase) {\n throw new Error('Passphrase must not be empty.');\n }\n\n const payload = Buffer.from(encrypted.slice(PREFIX.length), 'base64');\n if (payload.length < SALT_LENGTH + IV_LENGTH + TAG_LENGTH) {\n throw new Error('Encrypted payload is too short.');\n }\n\n const salt = payload.subarray(0, SALT_LENGTH);\n const iv = payload.subarray(SALT_LENGTH, SALT_LENGTH + IV_LENGTH);\n const tag = payload.subarray(payload.length - TAG_LENGTH);\n const ciphertext = payload.subarray(SALT_LENGTH + IV_LENGTH, payload.length - TAG_LENGTH);\n\n const key = scryptSync(passphrase, salt, KEY_LENGTH, {\n N: SCRYPT_N,\n r: SCRYPT_R,\n p: SCRYPT_P,\n maxmem: SCRYPT_MAXMEM,\n });\n\n const decipher = createDecipheriv('aes-256-gcm', key, iv);\n decipher.setAuthTag(tag);\n\n try {\n const decrypted = Buffer.concat([decipher.update(ciphertext), decipher.final()]);\n return decrypted.toString('utf8');\n } catch {\n throw new Error('Decryption failed. Wrong passphrase or corrupted data.');\n }\n}\n","/**\n * Load an agent: parse elisym.yaml + .secrets.json, decrypt if encrypted.\n */\n\nimport { readFile } from 'node:fs/promises';\nimport YAML from 'yaml';\nimport { validateAgentName } from '../primitives/config';\nimport { isEncrypted, decryptSecret } from '../primitives/encryption';\nimport { agentPaths } from './paths';\nimport { resolveAgent, type AgentSource, type ResolvedAgent } from './resolver';\nimport { ElisymYamlSchema, SecretsSchema, type ElisymYaml, type Secrets } from './schema';\n\nexport interface LoadedAgent {\n name: string;\n dir: string;\n source: AgentSource;\n yaml: ElisymYaml;\n secrets: Secrets;\n /** true when at least one secret field was encrypted on disk. */\n encrypted: boolean;\n shadowsGlobal: boolean;\n}\n\n/** Raw resolve + read + parse, no decryption yet. Useful for ergonomic list views. */\nexport async function readAgentPublic(\n resolved: ResolvedAgent,\n): Promise<{ resolved: ResolvedAgent; yaml: ElisymYaml }> {\n const paths = agentPaths(resolved.dir);\n const yamlRaw = await readFile(paths.yaml, 'utf-8');\n const parsed = YAML.parse(yamlRaw);\n const yaml = ElisymYamlSchema.parse(parsed ?? {});\n return { resolved, yaml };\n}\n\n/**\n * Load an agent by name. Searches project-local first, then home.\n * Throws with clear error if missing or if encrypted secrets lack a passphrase.\n */\nexport async function loadAgent(\n name: string,\n cwd: string,\n passphrase?: string,\n): Promise<LoadedAgent> {\n validateAgentName(name);\n const resolved = resolveAgent(name, cwd);\n if (!resolved) {\n throw new Error(\n `Agent \"${name}\" not found. Looked for .elisym/${name}/elisym.yaml in project (walking up from ${cwd}) and in home (${homeElisymPathHint(name)}).`,\n );\n }\n return loadResolvedAgent(resolved, passphrase);\n}\n\n/** Load an agent whose location was already resolved. */\nexport async function loadResolvedAgent(\n resolved: ResolvedAgent,\n passphrase?: string,\n): Promise<LoadedAgent> {\n const paths = agentPaths(resolved.dir);\n\n const yamlRaw = await readFile(paths.yaml, 'utf-8');\n const parsedYaml = YAML.parse(yamlRaw);\n const yaml = ElisymYamlSchema.parse(parsedYaml ?? {});\n\n let secretsRaw: string;\n try {\n secretsRaw = await readFile(paths.secrets, 'utf-8');\n } catch {\n throw new Error(\n `Agent \"${resolved.name}\" has elisym.yaml but no secrets at ${paths.secrets}. Run \\`npx @elisym/cli init\\` to initialize secrets.`,\n );\n }\n\n const secrets = SecretsSchema.parse(JSON.parse(secretsRaw));\n const encryptedFields = listEncryptedFields(secrets);\n\n const effectivePassphrase = passphrase ?? process.env.ELISYM_PASSPHRASE;\n if (encryptedFields.length > 0 && !effectivePassphrase) {\n throw new Error(\n `Agent \"${resolved.name}\" has encrypted secrets [${encryptedFields.join(', ')}]. Set ELISYM_PASSPHRASE or pass a passphrase.`,\n );\n }\n\n const decrypted: Secrets = { ...secrets };\n if (effectivePassphrase) {\n if (isEncrypted(decrypted.nostr_secret_key)) {\n decrypted.nostr_secret_key = decryptSecret(decrypted.nostr_secret_key, effectivePassphrase);\n }\n if (decrypted.solana_secret_key && isEncrypted(decrypted.solana_secret_key)) {\n decrypted.solana_secret_key = decryptSecret(decrypted.solana_secret_key, effectivePassphrase);\n }\n if (decrypted.llm_api_keys) {\n const decryptedKeys: Record<string, string> = {};\n for (const [providerId, value] of Object.entries(decrypted.llm_api_keys)) {\n decryptedKeys[providerId] = isEncrypted(value)\n ? decryptSecret(value, effectivePassphrase)\n : value;\n }\n decrypted.llm_api_keys = decryptedKeys;\n }\n }\n\n return {\n name: resolved.name,\n dir: resolved.dir,\n source: resolved.source,\n yaml,\n secrets: decrypted,\n encrypted: encryptedFields.length > 0,\n shadowsGlobal: resolved.shadowsGlobal,\n };\n}\n\nfunction listEncryptedFields(secrets: Secrets): string[] {\n const out: string[] = [];\n if (isEncrypted(secrets.nostr_secret_key)) {\n out.push('nostr_secret_key');\n }\n if (secrets.solana_secret_key && isEncrypted(secrets.solana_secret_key)) {\n out.push('solana_secret_key');\n }\n if (secrets.llm_api_keys) {\n for (const [providerId, value] of Object.entries(secrets.llm_api_keys)) {\n if (isEncrypted(value)) {\n out.push(`llm_api_keys.${providerId}`);\n }\n }\n }\n return out;\n}\n\nfunction homeElisymPathHint(name: string): string {\n return `~/.elisym/${name}/elisym.yaml`;\n}\n","/**\n * Write agent files: elisym.yaml, .secrets.json, .gitignore, and create agent dirs.\n */\n\nimport { randomBytes } from 'node:crypto';\nimport { mkdir, rename, writeFile } from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\nimport YAML from 'yaml';\nimport { encryptSecret, isEncrypted } from '../primitives/encryption';\nimport { agentPaths, type AgentPaths } from './paths';\nimport { elisymRootFor, type AgentSource } from './resolver';\nimport { ElisymYamlSchema, SecretsSchema, type ElisymYaml, type Secrets } from './schema';\n\nconst GITIGNORE_CONTENT = [\n '# elisym private state - do not commit.',\n '.secrets.json',\n '.media-cache.json',\n '.jobs.json',\n '.jobs.json.corrupt.*',\n '.customer-history.json',\n '.contacts.json',\n '',\n].join('\\n');\n\nexport interface CreateAgentDirOptions {\n target: AgentSource;\n name: string;\n cwd: string;\n /**\n * For `target: 'project'`: if no .elisym/ dir exists above cwd,\n * where should we create one? Defaults to cwd.\n */\n projectRoot?: string;\n}\n\nexport interface CreatedAgentDir {\n dir: string;\n paths: AgentPaths;\n source: AgentSource;\n createdNewElisymRoot: boolean;\n}\n\n/**\n * Create (or reuse) the directory layout for a new agent. Idempotent: if the\n * agent directory already exists, returns its paths without overwriting.\n * Writes `.gitignore` in project-local .elisym/ on first creation.\n */\nexport async function createAgentDir(options: CreateAgentDirOptions): Promise<CreatedAgentDir> {\n const { target, name, cwd, projectRoot } = options;\n\n const existingRoot = elisymRootFor(target, cwd);\n let elisymRoot: string;\n let createdNewElisymRoot = false;\n\n if (existingRoot) {\n elisymRoot = existingRoot;\n } else if (target === 'project') {\n elisymRoot = join(projectRoot ?? cwd, '.elisym');\n createdNewElisymRoot = true;\n } else {\n throw new Error('homeElisymDir should always exist conceptually - this is unreachable');\n }\n\n const agentDir = join(elisymRoot, name);\n const mode = target === 'home' ? 0o700 : 0o755;\n await mkdir(agentDir, { recursive: true, mode });\n await mkdir(join(agentDir, 'skills'), { recursive: true, mode });\n\n if (target === 'project') {\n const gitignorePath = join(elisymRoot, '.gitignore');\n await writeFileIfMissing(gitignorePath, GITIGNORE_CONTENT, 0o644);\n }\n\n return {\n dir: agentDir,\n paths: agentPaths(agentDir),\n source: target,\n createdNewElisymRoot,\n };\n}\n\n/** Write elisym.yaml atomically. Validates via Zod before writing. */\nexport async function writeYaml(agentDir: string, yaml: ElisymYaml): Promise<void> {\n const validated = ElisymYamlSchema.parse(yaml);\n const body = YAML.stringify(validated);\n const target = agentPaths(agentDir).yaml;\n await writeFileAtomic(target, body, 0o644);\n}\n\n/**\n * Write .secrets.json atomically. If `passphrase` is given, encrypts all\n * plaintext secret fields (already-encrypted values are left as-is).\n * Generic over `llm_api_keys` so any registered provider's key is\n * encrypted without per-provider plumbing here.\n */\nexport async function writeSecrets(\n agentDir: string,\n secrets: Secrets,\n passphrase?: string,\n): Promise<void> {\n const validated = SecretsSchema.parse(secrets);\n let encryptedLlmKeys: Record<string, string> | undefined;\n if (validated.llm_api_keys) {\n encryptedLlmKeys = {};\n for (const [providerId, value] of Object.entries(validated.llm_api_keys)) {\n if (value) {\n encryptedLlmKeys[providerId] = maybeEncrypt(value, passphrase);\n }\n }\n if (Object.keys(encryptedLlmKeys).length === 0) {\n encryptedLlmKeys = undefined;\n }\n }\n const finalSecrets: Secrets = {\n nostr_secret_key: maybeEncrypt(validated.nostr_secret_key, passphrase),\n solana_secret_key: validated.solana_secret_key\n ? maybeEncrypt(validated.solana_secret_key, passphrase)\n : undefined,\n llm_api_keys: encryptedLlmKeys,\n };\n const body = JSON.stringify(finalSecrets, null, 2) + '\\n';\n const target = agentPaths(agentDir).secrets;\n await writeFileAtomic(target, body, 0o600);\n}\n\nfunction maybeEncrypt(value: string, passphrase: string | undefined): string {\n if (!passphrase) {\n return value;\n }\n if (isEncrypted(value)) {\n return value;\n }\n return encryptSecret(value, passphrase);\n}\n\n/** Atomic write: temp file + rename. Preserves mode. */\nexport async function writeFileAtomic(\n path: string,\n data: string | Buffer,\n mode: number,\n): Promise<void> {\n await mkdir(dirname(path), { recursive: true });\n const tmpPath = `${path}.tmp.${randomBytes(6).toString('hex')}`;\n await writeFile(tmpPath, data, { mode });\n try {\n await rename(tmpPath, path);\n } catch (e) {\n // Best-effort cleanup of temp file on rename failure.\n try {\n const { unlink } = await import('node:fs/promises');\n await unlink(tmpPath);\n } catch {\n /* ignore */\n }\n throw e;\n }\n}\n\nasync function writeFileIfMissing(path: string, data: string, mode: number): Promise<void> {\n try {\n await writeFile(path, data, { mode, flag: 'wx' });\n } catch (e: unknown) {\n // wx fails with EEXIST if file exists - that's fine.\n if (!isEexist(e)) {\n throw e;\n }\n }\n}\n\nfunction isEexist(e: unknown): boolean {\n return (\n typeof e === 'object' && e !== null && 'code' in e && (e as { code: string }).code === 'EEXIST'\n );\n}\n","/**\n * List all agents discoverable from the current working directory:\n * - project-local: nearest .elisym/ (walk up to first .git or $HOME)\n * - home-global: ~/.elisym/\n * Project-local entries shadow home-global entries with the same name.\n */\n\nimport { readdir, readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport YAML from 'yaml';\nimport { findProjectElisymDir, homeElisymDir, YAML_FILENAME } from './paths';\nimport type { AgentSource } from './resolver';\nimport { ElisymYamlSchema } from './schema';\n\nexport interface ListedAgent {\n name: string;\n source: AgentSource;\n dir: string;\n /** display_name from YAML, if present. */\n displayName?: string;\n /** true when this entry is project-local and a home-global agent with the same name exists. */\n shadowsGlobal: boolean;\n}\n\n/** List agents in both locations, deduping by name (project wins). */\nexport async function listAgents(cwd: string): Promise<ListedAgent[]> {\n const homeDir = homeElisymDir();\n const projectDir = findProjectElisymDir(cwd);\n\n const homeAgents = await listAgentsInDir(homeDir, 'home');\n const projectAgents = projectDir ? await listAgentsInDir(projectDir, 'project') : [];\n\n const homeNames = new Set(homeAgents.map((agent) => agent.name));\n\n const merged: ListedAgent[] = [];\n\n for (const entry of projectAgents) {\n merged.push({ ...entry, shadowsGlobal: homeNames.has(entry.name) });\n }\n const projectNames = new Set(projectAgents.map((agent) => agent.name));\n for (const entry of homeAgents) {\n if (!projectNames.has(entry.name)) {\n merged.push(entry);\n }\n }\n\n merged.sort((left, right) => left.name.localeCompare(right.name));\n return merged;\n}\n\nasync function listAgentsInDir(rootDir: string, source: AgentSource): Promise<ListedAgent[]> {\n let entries: string[];\n try {\n entries = await readdir(rootDir);\n } catch {\n return [];\n }\n\n const results: ListedAgent[] = [];\n for (const entry of entries) {\n if (entry.startsWith('.')) {\n continue;\n }\n const agentDir = join(rootDir, entry);\n const yamlPath = join(agentDir, YAML_FILENAME);\n const displayName = await tryReadDisplayName(yamlPath);\n if (displayName === null) {\n continue;\n }\n results.push({\n name: entry,\n source,\n dir: agentDir,\n displayName: displayName || undefined,\n shadowsGlobal: false,\n });\n }\n\n return results;\n}\n\n/**\n * Read display_name from a YAML file. Returns null if the file is missing\n * or cannot be parsed (agent directory is skipped in listings).\n */\nasync function tryReadDisplayName(yamlPath: string): Promise<string | null> {\n let raw: string;\n try {\n raw = await readFile(yamlPath, 'utf-8');\n } catch {\n return null;\n }\n try {\n const parsed = YAML.parse(raw);\n const yaml = ElisymYamlSchema.partial().safeParse(parsed ?? {});\n if (!yaml.success) {\n return '';\n }\n return yaml.data.display_name ?? '';\n } catch {\n return '';\n }\n}\n","/**\n * Media cache: maps local image paths to uploaded URLs + sha256.\n * On each start, the CLI hashes the file and skips re-upload if the hash matches.\n */\n\nimport { createHash } from 'node:crypto';\nimport { readFile } from 'node:fs/promises';\nimport { agentPaths } from './paths';\nimport { MediaCacheSchema, type MediaCache, type MediaCacheEntry } from './schema';\nimport { writeFileAtomic } from './writer';\n\n/** Read .media-cache.json. Returns empty object if missing or corrupt. */\nexport async function readMediaCache(agentDir: string): Promise<MediaCache> {\n const path = agentPaths(agentDir).mediaCache;\n let raw: string;\n try {\n raw = await readFile(path, 'utf-8');\n } catch {\n return {};\n }\n try {\n const parsed = JSON.parse(raw);\n const result = MediaCacheSchema.safeParse(parsed);\n return result.success ? result.data : {};\n } catch {\n return {};\n }\n}\n\nexport async function writeMediaCache(agentDir: string, cache: MediaCache): Promise<void> {\n const path = agentPaths(agentDir).mediaCache;\n const body = JSON.stringify(cache, null, 2) + '\\n';\n await writeFileAtomic(path, body, 0o600);\n}\n\n/** Compute sha256 hex of a file's contents. */\nexport async function hashFile(filePath: string): Promise<string> {\n const buf = await readFile(filePath);\n return createHash('sha256').update(buf).digest('hex');\n}\n\n/**\n * Look up a cached URL for a local file path. Returns the cached URL if\n * the file's current hash matches the cache entry; otherwise null.\n */\nexport async function lookupCachedUrl(\n cache: MediaCache,\n relativePath: string,\n absolutePath: string,\n): Promise<string | null> {\n const entry = cache[relativePath];\n if (!entry) {\n return null;\n }\n let hash: string;\n try {\n hash = await hashFile(absolutePath);\n } catch {\n return null;\n }\n return hash === entry.sha256 ? entry.url : null;\n}\n\nexport function newCacheEntry(url: string, sha256: string): MediaCacheEntry {\n return { url, sha256, uploaded_at: new Date().toISOString() };\n}\n"]}
1
+ {"version":3,"sources":["../src/constants.ts","../src/agent-store/schema.ts","../src/agent-store/paths.ts","../src/agent-store/resolver.ts","../src/primitives/config.ts","../src/primitives/encryption.ts","../src/agent-store/loader.ts","../src/agent-store/template.ts","../src/agent-store/writer.ts","../src/agent-store/list.ts","../src/agent-store/media-cache.ts"],"names":["z","join","homedir","resolve","existsSync","dirname","statSync","randomBytes","scryptSync","createCipheriv","Buffer","createDecipheriv","readFile","YAML","mkdir","path","writeFile","rename","readdir","createHash"],"mappings":";;;;;;;;;;;;;;;;;;AAEO,IAAM,MAAA,GAAS;AAAA,EACpB,sBAAA;AAAA,EACA,eAAA;AAAA,EACA,wBAAA;AAAA,EACA,wBAAA;AAAA,EACA;AACF,CAAA;AA6FO,IAAM,MAAA,GAAS;AAAA,EAIpB,sBAAA,EAAwB,GAAA;AAAA,EACxB,qBAAA,EAAuB,EAEzB,CAAA;;;ACpGA,IAAM,kBAAA,GAAqB,kBAAA;AAEpB,IAAM,eAAA,GAAkBA,KAAA,CAC5B,MAAA,EAAO,CACP,GAAA,CAAI,CAAC,CAAA,CACL,GAAA,CAAI,MAAA,CAAO,qBAAqB,CAAA,CAChC,KAAA,CAAM,oBAAoB,0CA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AK,MAAA,EAAQ,WAAA,EAAA,qBAAiB,IAAA,EAAK,EAAE,aAAY,EAAE;AAC9D","file":"agent-store.cjs","sourcesContent":["import type { Address } from '@solana/kit';\n\nexport const RELAYS = [\n 'wss://relay.damus.io',\n 'wss://nos.lol',\n 'wss://relay.nostr.band',\n 'wss://relay.primal.net',\n 'wss://relay.snort.social',\n];\n\nexport const KIND_APP_HANDLER = 31990;\nexport const KIND_JOB_REQUEST_BASE = 5000;\nexport const KIND_JOB_RESULT_BASE = 6000;\nexport const KIND_JOB_FEEDBACK = 7000;\nexport const DEFAULT_KIND_OFFSET = 100;\n\n/** Default job request kind (5000 + 100). */\nexport const KIND_JOB_REQUEST = KIND_JOB_REQUEST_BASE + DEFAULT_KIND_OFFSET;\n/** Default job result kind (6000 + 100). */\nexport const KIND_JOB_RESULT = KIND_JOB_RESULT_BASE + DEFAULT_KIND_OFFSET;\n\n/** Compute a job request kind from an offset (5000 + offset). */\nexport function jobRequestKind(offset: number): number {\n if (!Number.isInteger(offset) || offset < 0 || offset >= 1000) {\n throw new Error(`Invalid kind offset: ${offset}. Must be integer 0-999.`);\n }\n return KIND_JOB_REQUEST_BASE + offset;\n}\n\n/** Compute a job result kind from an offset (6000 + offset). */\nexport function jobResultKind(offset: number): number {\n if (!Number.isInteger(offset) || offset < 0 || offset >= 1000) {\n throw new Error(`Invalid kind offset: ${offset}. Must be integer 0-999.`);\n }\n return KIND_JOB_RESULT_BASE + offset;\n}\n\n/** Ephemeral ping/pong kinds (not stored by relays, forwarded in real-time). */\nexport const KIND_PING = 20200;\nexport const KIND_PONG = 20201;\n\nexport const LAMPORTS_PER_SOL = 1_000_000_000;\n\n/**\n * Solana program ID for the elisym protocol config (devnet deployment).\n *\n * The Anchor program at this address is the source of truth for fee bps,\n * treasury address, and admin rotation state. Read via `getProtocolConfig`.\n */\nexport const PROTOCOL_PROGRAM_ID_DEVNET = 'BrX1CRkSgvcjxBvc2bgc3QqgWjinusofDmeP7ZVxvwrE' as Address;\n\n/**\n * Read-only marker pubkey attached as a non-signer account to every elisym\n * payment transaction. Lets indexers enumerate every elisym tx network-wide\n * via a single `getSignaturesForAddress(ELISYM_PROTOCOL_TAG)` call,\n * independent of fee size or recipient.\n *\n * The account does not need to exist on-chain; including its pubkey as an\n * extra read-only account in the provider transfer instruction is enough for\n * Solana's tx-by-account index to pick it up. The corresponding secret key\n * was generated and discarded - the tag never signs and never holds funds.\n */\nexport const ELISYM_PROTOCOL_TAG = 'ELiZksgwDt41LaeuPDLkUfWgFXhGgVayTMP7L5nTSEL8' as Address;\n\nexport type ProtocolCluster = 'devnet' | 'mainnet' | 'localnet';\n\n/**\n * Resolve the elisym-config program ID for a given Solana cluster.\n * Mainnet is intentionally unsupported until the program ships there.\n */\nexport function getProtocolProgramId(cluster: ProtocolCluster): Address {\n switch (cluster) {\n case 'devnet':\n case 'localnet':\n return PROTOCOL_PROGRAM_ID_DEVNET;\n case 'mainnet':\n throw new Error('Protocol program is not deployed on mainnet yet');\n }\n}\n\n/** Default values for timeouts, retries, and batch sizes. */\nexport const DEFAULTS = {\n SUBSCRIPTION_TIMEOUT_MS: 120_000,\n PING_TIMEOUT_MS: 3_000,\n PING_RETRIES: 2,\n PING_CACHE_TTL_MS: 30_000,\n PAYMENT_EXPIRY_SECS: 600,\n BATCH_SIZE: 250,\n QUERY_TIMEOUT_MS: 15_000,\n EOSE_TIMEOUT_MS: 3_000,\n VERIFY_RETRIES: 10,\n VERIFY_INTERVAL_MS: 3_000,\n VERIFY_BY_REF_RETRIES: 15,\n VERIFY_BY_REF_INTERVAL_MS: 2_000,\n RESULT_RETRY_COUNT: 3,\n RESULT_RETRY_BASE_MS: 1_000,\n QUERY_MAX_CONCURRENCY: 6,\n VERIFY_SIGNATURE_LIMIT: 25,\n} as const;\n\n/** Protocol limits for input validation. */\nexport const LIMITS = {\n MAX_INPUT_LENGTH: 100_000,\n MAX_TIMEOUT_SECS: 600,\n MAX_CAPABILITIES: 20,\n MAX_DESCRIPTION_LENGTH: 500,\n MAX_AGENT_NAME_LENGTH: 64,\n MAX_CAPABILITY_LENGTH: 64,\n} as const;\n","/**\n * Zod schemas for elisym.yaml (public source of truth) and secrets.json (private).\n * Shared between CLI (provider mode) and MCP (customer mode, future provider mode).\n */\n\nimport { z } from 'zod';\nimport { LIMITS } from '../constants';\n\nconst AGENT_NAME_PATTERN = /^[a-zA-Z0-9_-]+$/;\n\nexport const AgentNameSchema = z\n .string()\n .min(1)\n .max(LIMITS.MAX_AGENT_NAME_LENGTH)\n .regex(AGENT_NAME_PATTERN, 'alphanumeric, underscore, or hyphen only');\n\n/**\n * Agent wallet entry. One entry per (chain, network) - the address receives\n * every asset on that chain (SOL directly, SPL tokens via their ATA derived\n * from (address, mint)). Per-asset pricing lives in each skill's `SKILL.md`;\n * the canonical mint registry lives in `KNOWN_ASSETS` (payment/assets.ts).\n */\nexport const PaymentSchema = z.object({\n chain: z.literal('solana'),\n network: z.enum(['devnet']),\n address: z.string().min(1),\n});\n\nexport const LlmSchema = z.object({\n provider: z.string().min(1),\n model: z.string().min(1),\n max_tokens: z.number().int().positive().max(200_000).default(4096),\n});\n\nexport const SecurityFlagsSchema = z.object({\n withdrawals_enabled: z.boolean().default(false),\n agent_switch_enabled: z.boolean().default(false),\n});\n\n/**\n * elisym.yaml schema. Public - committed to git.\n * Agent name NOT stored here - derived from containing folder name.\n *\n * The top-level field list is mirrored in `skills/elisym-config/SKILL.md`\n * so the elisym-config agent skill can patch this file directly. Drift\n * is guarded by `packages/sdk/tests/config-skill-drift.test.ts` - when\n * you add or remove a top-level field here, update that SKILL.md too.\n */\nexport const ElisymYamlSchema = z\n .object({\n /** Human-readable name shown in UI (optional). Falls back to folder name. */\n display_name: z.string().max(LIMITS.MAX_AGENT_NAME_LENGTH).optional(),\n description: z.string().max(LIMITS.MAX_DESCRIPTION_LENGTH).default(''),\n /** Relative path (to this YAML) or absolute URL. */\n picture: z.string().optional(),\n /** Relative path (to this YAML) or absolute URL. */\n banner: z.string().optional(),\n relays: z.array(z.string().url()).default([]),\n payments: z.array(PaymentSchema).default([]),\n llm: LlmSchema.optional(),\n security: SecurityFlagsSchema.partial().default({}),\n })\n .strict();\n\nexport type ElisymYaml = z.infer<typeof ElisymYamlSchema>;\nexport type PaymentEntry = z.infer<typeof PaymentSchema>;\nexport type LlmEntry = z.infer<typeof LlmSchema>;\nexport type SecurityFlags = z.infer<typeof SecurityFlagsSchema>;\n\n/**\n * secrets.json schema. Private - .gitignore.\n * Values may be plaintext or `encrypted:v1:...` blobs (AES-256-GCM + scrypt).\n *\n * `llm_api_keys` is a generic record keyed by provider id (e.g. `anthropic`,\n * `openai`, future `xai`/`google`/...). Adding a new LLM provider does not\n * require a schema change. Each value is a separate ciphertext blob when\n * encrypted.\n */\nexport const SecretsSchema = z\n .object({\n nostr_secret_key: z.string().min(1),\n solana_secret_key: z.string().optional(),\n /** Per-provider LLM API keys, keyed by descriptor id (e.g. `anthropic`, `openai`). */\n llm_api_keys: z.record(z.string(), z.string()).optional(),\n })\n .strict();\n\nexport type Secrets = z.infer<typeof SecretsSchema>;\n\nexport interface MediaCacheEntry {\n url: string;\n sha256: string;\n uploaded_at: string;\n}\n\nexport const MediaCacheEntrySchema: z.ZodType<MediaCacheEntry> = z\n .object({\n url: z.string().url(),\n sha256: z.string().regex(/^[a-f0-9]{64}$/),\n uploaded_at: z.string(),\n })\n .strict();\n\nexport const MediaCacheSchema = z.record(z.string(), MediaCacheEntrySchema);\n\nexport type MediaCache = z.infer<typeof MediaCacheSchema>;\n","/**\n * Path helpers for .elisym/ layout.\n *\n * Project-local (walk up from CWD until .git or $HOME):\n * <project>/.elisym/<name>/{elisym.yaml, .secrets.json, .media-cache.json, .jobs.json, .gitignore}\n *\n * Home-global (~/.elisym/<name>/): same file structure.\n *\n * Node.js only - relies on `node:fs`/`node:os`/`node:path`.\n */\n\nimport { existsSync, statSync } from 'node:fs';\nimport { homedir } from 'node:os';\nimport { dirname, join, resolve } from 'node:path';\n\nexport const ELISYM_DIRNAME = '.elisym';\nexport const YAML_FILENAME = 'elisym.yaml';\nexport const SECRETS_FILENAME = '.secrets.json';\nexport const MEDIA_CACHE_FILENAME = '.media-cache.json';\nexport const JOBS_FILENAME = '.jobs.json';\nexport const GITIGNORE_FILENAME = '.gitignore';\nexport const SKILLS_DIRNAME = 'skills';\n\n/** Max depth for walk-up search (safety guard against unbounded loops). */\nconst MAX_WALK_UP_DEPTH = 64;\n\n/** ~/.elisym/ */\nexport function homeElisymDir(): string {\n return join(homedir(), ELISYM_DIRNAME);\n}\n\n/** ~/.elisym/config.yaml — global (not per-agent) config file. */\nexport function globalConfigPath(): string {\n return join(homeElisymDir(), 'config.yaml');\n}\n\n/**\n * Walk up from `startDir` looking for `.elisym/` directory.\n * Stops at (a) the first `.git` directory/file, (b) `$HOME`, (c) filesystem root,\n * or (d) MAX_WALK_UP_DEPTH iterations. Returns absolute path or null.\n */\nexport function findProjectElisymDir(startDir: string): string | null {\n const home = homedir();\n let current = resolve(startDir);\n let previous: string | null = null;\n\n for (let depth = 0; depth < MAX_WALK_UP_DEPTH; depth++) {\n if (current === previous) {\n return null;\n }\n\n // At $HOME: ~/.elisym/ is the home-global layout, not a project-local one.\n // Stop without matching to avoid misclassifying home agents as project.\n if (current === home) {\n return null;\n }\n\n const elisymCandidate = join(current, ELISYM_DIRNAME);\n if (existsSync(elisymCandidate) && safeIsDir(elisymCandidate)) {\n return elisymCandidate;\n }\n\n const gitCandidate = join(current, '.git');\n if (existsSync(gitCandidate)) {\n return null;\n }\n\n previous = current;\n current = dirname(current);\n }\n\n return null;\n}\n\nexport interface AgentPaths {\n dir: string;\n yaml: string;\n secrets: string;\n mediaCache: string;\n jobs: string;\n gitignore: string;\n skills: string;\n}\n\n/** Compute all file/dir paths for an agent given its root directory. */\nexport function agentPaths(agentDir: string): AgentPaths {\n return {\n dir: agentDir,\n yaml: join(agentDir, YAML_FILENAME),\n secrets: join(agentDir, SECRETS_FILENAME),\n mediaCache: join(agentDir, MEDIA_CACHE_FILENAME),\n jobs: join(agentDir, JOBS_FILENAME),\n gitignore: join(agentDir, GITIGNORE_FILENAME),\n skills: join(agentDir, SKILLS_DIRNAME),\n };\n}\n\nfunction safeIsDir(path: string): boolean {\n try {\n return statSync(path).isDirectory();\n } catch {\n return false;\n }\n}\n","/**\n * Agent resolution: find <name>/elisym.yaml via project-local walk-up, fallback to home.\n */\n\nimport { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { ELISYM_DIRNAME, YAML_FILENAME, findProjectElisymDir, homeElisymDir } from './paths';\n\nexport type AgentSource = 'project' | 'home';\n\nexport interface ResolvedAgent {\n name: string;\n dir: string;\n source: AgentSource;\n /** true when both a project-local and a home-global agent exist with the same name. */\n shadowsGlobal: boolean;\n}\n\n/**\n * Resolve an agent by name. Precedence: project-local beats home-global.\n * Returns null if not found in either location.\n */\nexport function resolveAgent(name: string, cwd: string): ResolvedAgent | null {\n const projectDir = resolveInProject(name, cwd);\n const homeDir = resolveInHome(name);\n\n if (projectDir) {\n return {\n name,\n dir: projectDir,\n source: 'project',\n shadowsGlobal: homeDir !== null,\n };\n }\n\n if (homeDir) {\n return { name, dir: homeDir, source: 'home', shadowsGlobal: false };\n }\n\n return null;\n}\n\n/** Return project-local agent dir if its YAML exists, else null. */\nexport function resolveInProject(name: string, cwd: string): string | null {\n const projectElisym = findProjectElisymDir(cwd);\n if (!projectElisym) {\n return null;\n }\n const agentDir = join(projectElisym, name);\n const yamlPath = join(agentDir, YAML_FILENAME);\n return existsSync(yamlPath) ? agentDir : null;\n}\n\n/** Return home-global agent dir if its YAML exists, else null. */\nexport function resolveInHome(name: string): string | null {\n const agentDir = join(homeElisymDir(), name);\n const yamlPath = join(agentDir, YAML_FILENAME);\n return existsSync(yamlPath) ? agentDir : null;\n}\n\n/** Path to the .elisym root (project or home) for a given target. */\nexport function elisymRootFor(target: AgentSource, cwd: string): string | null {\n if (target === 'home') {\n return homeElisymDir();\n }\n return findProjectElisymDir(cwd);\n}\n\n/** Re-export for convenience. */\nexport { ELISYM_DIRNAME };\n","/**\n * Agent-name validation shared between CLI and MCP.\n * Browser-safe - no Node.js imports.\n */\n\nimport { LIMITS } from '../constants';\n\nexport function validateAgentName(name: string): void {\n if (!name || name.length > LIMITS.MAX_AGENT_NAME_LENGTH || !/^[a-zA-Z0-9_-]+$/.test(name)) {\n throw new Error('Agent name must be 1-64 characters, alphanumeric, underscore, or hyphen.');\n }\n}\n","/**\n * Secret encryption/decryption for agent config files.\n * Uses scrypt (KDF) + AES-256-GCM (cipher).\n * Format: \"encrypted:v1:\" + base64(salt[16] + iv[12] + ciphertext + tag[16])\n *\n * scrypt params: N=2^17, r=8, p=1 (~128 MB RAM per derivation).\n *\n * Node.js/Bun only - not available in browsers. Reachable only via the\n * '@elisym/sdk/node' subpath, which browser bundlers will not resolve.\n */\n\nimport { Buffer } from 'node:buffer';\nimport { createCipheriv, createDecipheriv, randomBytes, scryptSync } from 'node:crypto';\n\nconst PREFIX = 'encrypted:v1:';\nconst SALT_LENGTH = 16;\nconst IV_LENGTH = 12;\nconst TAG_LENGTH = 16;\nconst KEY_LENGTH = 32; // AES-256\n// v1: N=2^17 (OWASP minimum). v2 will use N=2^20 with format migration.\nconst SCRYPT_N = 2 ** 17;\nconst SCRYPT_R = 8;\nconst SCRYPT_P = 1;\nconst SCRYPT_MAXMEM = 128 * SCRYPT_N * SCRYPT_R * 2; // 2x the minimum required memory\n\n/** Check if a value is encrypted (has the encrypted:v1: prefix). */\nexport function isEncrypted(value: string): boolean {\n return value.startsWith(PREFIX);\n}\n\n/** Encrypt a plaintext secret with a passphrase. Returns \"encrypted:v1:base64...\". Node.js/Bun only. */\nexport function encryptSecret(plaintext: string, passphrase: string): string {\n if (!passphrase) {\n throw new Error('Passphrase must not be empty.');\n }\n\n const salt = randomBytes(SALT_LENGTH);\n const key = scryptSync(passphrase, salt, KEY_LENGTH, {\n N: SCRYPT_N,\n r: SCRYPT_R,\n p: SCRYPT_P,\n maxmem: SCRYPT_MAXMEM,\n });\n const iv = randomBytes(IV_LENGTH);\n\n const cipher = createCipheriv('aes-256-gcm', key, iv);\n const encrypted = Buffer.concat([cipher.update(plaintext, 'utf8'), cipher.final()]);\n const tag = cipher.getAuthTag();\n\n const payload = Buffer.concat([salt, iv, encrypted, tag]);\n return PREFIX + payload.toString('base64');\n}\n\n/** Decrypt an encrypted secret with a passphrase. Throws on wrong passphrase or corrupted data. Node.js/Bun only. */\nexport function decryptSecret(encrypted: string, passphrase: string): string {\n if (!isEncrypted(encrypted)) {\n throw new Error('Value is not encrypted (missing encrypted:v1: prefix).');\n }\n if (!passphrase) {\n throw new Error('Passphrase must not be empty.');\n }\n\n const payload = Buffer.from(encrypted.slice(PREFIX.length), 'base64');\n if (payload.length < SALT_LENGTH + IV_LENGTH + TAG_LENGTH) {\n throw new Error('Encrypted payload is too short.');\n }\n\n const salt = payload.subarray(0, SALT_LENGTH);\n const iv = payload.subarray(SALT_LENGTH, SALT_LENGTH + IV_LENGTH);\n const tag = payload.subarray(payload.length - TAG_LENGTH);\n const ciphertext = payload.subarray(SALT_LENGTH + IV_LENGTH, payload.length - TAG_LENGTH);\n\n const key = scryptSync(passphrase, salt, KEY_LENGTH, {\n N: SCRYPT_N,\n r: SCRYPT_R,\n p: SCRYPT_P,\n maxmem: SCRYPT_MAXMEM,\n });\n\n const decipher = createDecipheriv('aes-256-gcm', key, iv);\n decipher.setAuthTag(tag);\n\n try {\n const decrypted = Buffer.concat([decipher.update(ciphertext), decipher.final()]);\n return decrypted.toString('utf8');\n } catch {\n throw new Error('Decryption failed. Wrong passphrase or corrupted data.');\n }\n}\n","/**\n * Load an agent: parse elisym.yaml + .secrets.json, decrypt if encrypted.\n */\n\nimport { readFile } from 'node:fs/promises';\nimport YAML from 'yaml';\nimport { validateAgentName } from '../primitives/config';\nimport { isEncrypted, decryptSecret } from '../primitives/encryption';\nimport { agentPaths } from './paths';\nimport { resolveAgent, type AgentSource, type ResolvedAgent } from './resolver';\nimport { ElisymYamlSchema, SecretsSchema, type ElisymYaml, type Secrets } from './schema';\n\nexport interface LoadedAgent {\n name: string;\n dir: string;\n source: AgentSource;\n yaml: ElisymYaml;\n secrets: Secrets;\n /** true when at least one secret field was encrypted on disk. */\n encrypted: boolean;\n shadowsGlobal: boolean;\n}\n\n/** Raw resolve + read + parse, no decryption yet. Useful for ergonomic list views. */\nexport async function readAgentPublic(\n resolved: ResolvedAgent,\n): Promise<{ resolved: ResolvedAgent; yaml: ElisymYaml }> {\n const paths = agentPaths(resolved.dir);\n const yamlRaw = await readFile(paths.yaml, 'utf-8');\n const parsed = YAML.parse(yamlRaw);\n const yaml = ElisymYamlSchema.parse(parsed ?? {});\n return { resolved, yaml };\n}\n\n/**\n * Load an agent by name. Searches project-local first, then home.\n * Throws with clear error if missing or if encrypted secrets lack a passphrase.\n */\nexport async function loadAgent(\n name: string,\n cwd: string,\n passphrase?: string,\n): Promise<LoadedAgent> {\n validateAgentName(name);\n const resolved = resolveAgent(name, cwd);\n if (!resolved) {\n throw new Error(\n `Agent \"${name}\" not found. Looked for .elisym/${name}/elisym.yaml in project (walking up from ${cwd}) and in home (${homeElisymPathHint(name)}).`,\n );\n }\n return loadResolvedAgent(resolved, passphrase);\n}\n\n/** Load an agent whose location was already resolved. */\nexport async function loadResolvedAgent(\n resolved: ResolvedAgent,\n passphrase?: string,\n): Promise<LoadedAgent> {\n const paths = agentPaths(resolved.dir);\n\n const yamlRaw = await readFile(paths.yaml, 'utf-8');\n const parsedYaml = YAML.parse(yamlRaw);\n const yaml = ElisymYamlSchema.parse(parsedYaml ?? {});\n\n let secretsRaw: string;\n try {\n secretsRaw = await readFile(paths.secrets, 'utf-8');\n } catch {\n throw new Error(\n `Agent \"${resolved.name}\" has elisym.yaml but no secrets at ${paths.secrets}. Run \\`npx @elisym/cli init\\` to initialize secrets.`,\n );\n }\n\n const secrets = SecretsSchema.parse(JSON.parse(secretsRaw));\n const encryptedFields = listEncryptedFields(secrets);\n\n const effectivePassphrase = passphrase ?? process.env.ELISYM_PASSPHRASE;\n if (encryptedFields.length > 0 && !effectivePassphrase) {\n throw new Error(\n `Agent \"${resolved.name}\" has encrypted secrets [${encryptedFields.join(', ')}]. Set ELISYM_PASSPHRASE or pass a passphrase.`,\n );\n }\n\n const decrypted: Secrets = { ...secrets };\n if (effectivePassphrase) {\n if (isEncrypted(decrypted.nostr_secret_key)) {\n decrypted.nostr_secret_key = decryptSecret(decrypted.nostr_secret_key, effectivePassphrase);\n }\n if (decrypted.solana_secret_key && isEncrypted(decrypted.solana_secret_key)) {\n decrypted.solana_secret_key = decryptSecret(decrypted.solana_secret_key, effectivePassphrase);\n }\n if (decrypted.llm_api_keys) {\n const decryptedKeys: Record<string, string> = {};\n for (const [providerId, value] of Object.entries(decrypted.llm_api_keys)) {\n decryptedKeys[providerId] = isEncrypted(value)\n ? decryptSecret(value, effectivePassphrase)\n : value;\n }\n decrypted.llm_api_keys = decryptedKeys;\n }\n }\n\n return {\n name: resolved.name,\n dir: resolved.dir,\n source: resolved.source,\n yaml,\n secrets: decrypted,\n encrypted: encryptedFields.length > 0,\n shadowsGlobal: resolved.shadowsGlobal,\n };\n}\n\nfunction listEncryptedFields(secrets: Secrets): string[] {\n const out: string[] = [];\n if (isEncrypted(secrets.nostr_secret_key)) {\n out.push('nostr_secret_key');\n }\n if (secrets.solana_secret_key && isEncrypted(secrets.solana_secret_key)) {\n out.push('solana_secret_key');\n }\n if (secrets.llm_api_keys) {\n for (const [providerId, value] of Object.entries(secrets.llm_api_keys)) {\n if (isEncrypted(value)) {\n out.push(`llm_api_keys.${providerId}`);\n }\n }\n }\n return out;\n}\n\nfunction homeElisymPathHint(name: string): string {\n return `~/.elisym/${name}/elisym.yaml`;\n}\n","/**\n * Render a fresh `elisym.yaml` as a string with descriptive header comments\n * over each top-level field. Optional fields that are not set in the input\n * are emitted as commented-out examples so a new operator can see what else\n * is configurable without leaving the file.\n *\n * Used only at agent-creation time (CLI `init`, MCP `create_agent`). On\n * subsequent writes via `writeYaml`, the document is re-serialized without\n * comments - this template is a one-shot scaffold, not a round-tripping\n * format.\n */\n\nimport YAML from 'yaml';\nimport { RELAYS } from '../constants';\nimport type { ElisymYaml } from './schema';\n\nconst PLACEHOLDER_DISPLAY_NAME = 'My Agent';\nconst PLACEHOLDER_PICTURE = './avatar.png';\nconst PLACEHOLDER_BANNER = './banner.png';\nconst PLACEHOLDER_PAYMENTS = [\n { chain: 'solana', network: 'devnet', address: '<your-solana-address>' },\n];\nconst PLACEHOLDER_LLM = {\n provider: 'anthropic',\n model: 'claude-sonnet-4-6',\n max_tokens: 4096,\n};\nconst DEFAULT_SECURITY = { withdrawals_enabled: false, agent_switch_enabled: false };\n\ninterface FieldBlock {\n description: string;\n key: keyof ElisymYaml;\n value: unknown;\n placeholder: unknown;\n}\n\nfunction commentLines(text: string): string {\n return text\n .split('\\n')\n .map((line) => (line.length > 0 ? `# ${line}` : '#'))\n .join('\\n');\n}\n\nfunction isUnset(value: unknown): boolean {\n if (value === undefined) {\n return true;\n }\n if (Array.isArray(value) && value.length === 0) {\n return true;\n }\n return false;\n}\n\nfunction renderBlock(block: FieldBlock): string {\n const header = commentLines(block.description);\n const unset = isUnset(block.value);\n const renderValue = unset ? block.placeholder : block.value;\n const yamlBody = YAML.stringify({ [block.key]: renderValue }).trimEnd();\n const body = unset ? commentLines(yamlBody) : yamlBody;\n return `${header}\\n${body}`;\n}\n\nexport function renderInitialYaml(yaml: ElisymYaml): string {\n const security = {\n withdrawals_enabled: yaml.security.withdrawals_enabled ?? DEFAULT_SECURITY.withdrawals_enabled,\n agent_switch_enabled:\n yaml.security.agent_switch_enabled ?? DEFAULT_SECURITY.agent_switch_enabled,\n };\n\n const blocks: FieldBlock[] = [\n {\n description: 'Human-readable name shown in UI. Falls back to the folder name when omitted.',\n key: 'display_name',\n value: yaml.display_name,\n placeholder: PLACEHOLDER_DISPLAY_NAME,\n },\n {\n description: 'Public description shown in discovery results.',\n key: 'description',\n value: yaml.description,\n placeholder: '',\n },\n {\n description: 'Avatar - relative path (to this YAML) or absolute URL.',\n key: 'picture',\n value: yaml.picture,\n placeholder: PLACEHOLDER_PICTURE,\n },\n {\n description: 'Banner - relative path (to this YAML) or absolute URL.',\n key: 'banner',\n value: yaml.banner,\n placeholder: PLACEHOLDER_BANNER,\n },\n {\n description: 'Nostr relays this agent connects to.',\n key: 'relays',\n value: yaml.relays,\n placeholder: [...RELAYS],\n },\n {\n description:\n 'Payment wallets per chain. Each entry receives every asset on that chain ' +\n '(SOL directly; SPL tokens via the ATA derived from this address).',\n key: 'payments',\n value: yaml.payments,\n placeholder: PLACEHOLDER_PAYMENTS,\n },\n {\n description:\n 'LLM configuration. Omit (or comment out) to run as a non-LLM agent ' +\n '(static-file or script skills only).',\n key: 'llm',\n value: yaml.llm,\n placeholder: PLACEHOLDER_LLM,\n },\n {\n description: 'Capability gates. Both default to false; flip to true to enable.',\n key: 'security',\n value: security,\n placeholder: DEFAULT_SECURITY,\n },\n ];\n\n return blocks.map(renderBlock).join('\\n\\n') + '\\n';\n}\n","/**\n * Write agent files: elisym.yaml, .secrets.json, .gitignore, and create agent dirs.\n */\n\nimport { randomBytes } from 'node:crypto';\nimport { mkdir, rename, writeFile } from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\nimport YAML from 'yaml';\nimport { encryptSecret, isEncrypted } from '../primitives/encryption';\nimport { agentPaths, type AgentPaths } from './paths';\nimport { elisymRootFor, type AgentSource } from './resolver';\nimport { ElisymYamlSchema, SecretsSchema, type ElisymYaml, type Secrets } from './schema';\nimport { renderInitialYaml } from './template';\n\nconst GITIGNORE_CONTENT = [\n '# elisym private state - do not commit.',\n '.secrets.json',\n '.media-cache.json',\n '.jobs.json',\n '.jobs.json.corrupt.*',\n '.customer-history.json',\n '.contacts.json',\n '',\n].join('\\n');\n\nexport interface CreateAgentDirOptions {\n target: AgentSource;\n name: string;\n cwd: string;\n /**\n * For `target: 'project'`: if no .elisym/ dir exists above cwd,\n * where should we create one? Defaults to cwd.\n */\n projectRoot?: string;\n}\n\nexport interface CreatedAgentDir {\n dir: string;\n paths: AgentPaths;\n source: AgentSource;\n createdNewElisymRoot: boolean;\n}\n\n/**\n * Create (or reuse) the directory layout for a new agent. Idempotent: if the\n * agent directory already exists, returns its paths without overwriting.\n * Writes `.gitignore` in project-local .elisym/ on first creation.\n */\nexport async function createAgentDir(options: CreateAgentDirOptions): Promise<CreatedAgentDir> {\n const { target, name, cwd, projectRoot } = options;\n\n const existingRoot = elisymRootFor(target, cwd);\n let elisymRoot: string;\n let createdNewElisymRoot = false;\n\n if (existingRoot) {\n elisymRoot = existingRoot;\n } else if (target === 'project') {\n elisymRoot = join(projectRoot ?? cwd, '.elisym');\n createdNewElisymRoot = true;\n } else {\n throw new Error('homeElisymDir should always exist conceptually - this is unreachable');\n }\n\n const agentDir = join(elisymRoot, name);\n const mode = target === 'home' ? 0o700 : 0o755;\n await mkdir(agentDir, { recursive: true, mode });\n await mkdir(join(agentDir, 'skills'), { recursive: true, mode });\n\n if (target === 'project') {\n const gitignorePath = join(elisymRoot, '.gitignore');\n await writeFileIfMissing(gitignorePath, GITIGNORE_CONTENT, 0o644);\n }\n\n return {\n dir: agentDir,\n paths: agentPaths(agentDir),\n source: target,\n createdNewElisymRoot,\n };\n}\n\n/** Write elisym.yaml atomically. Validates via Zod before writing. */\nexport async function writeYaml(agentDir: string, yaml: ElisymYaml): Promise<void> {\n const validated = ElisymYamlSchema.parse(yaml);\n const body = YAML.stringify(validated);\n const target = agentPaths(agentDir).yaml;\n await writeFileAtomic(target, body, 0o644);\n}\n\n/**\n * Write a brand-new elisym.yaml with descriptive header comments and\n * commented-out examples for unset optional fields. Use only at agent\n * creation time (CLI `init`, MCP `create_agent`). Subsequent edits go\n * through `writeYaml`, which discards comments.\n */\nexport async function writeYamlInitial(agentDir: string, yaml: ElisymYaml): Promise<void> {\n const validated = ElisymYamlSchema.parse(yaml);\n const body = renderInitialYaml(validated);\n const target = agentPaths(agentDir).yaml;\n await writeFileAtomic(target, body, 0o644);\n}\n\n/**\n * Create a skills directory placeholder file with a commented-out SKILL.md\n * template covering every supported field, so operators have a reference\n * for what they can declare without having to read source. The file is\n * named `EXAMPLE.md` (not `SKILL.md`) and lives directly in `skills/`\n * (not in a subdirectory), so the skill loader skips it - it's reference\n * material, not an active skill. To turn it into a real skill: copy it\n * into `skills/<your-skill-name>/SKILL.md` and uncomment the lines you\n * need.\n *\n * Idempotent: written with `wx` flag so we never overwrite an operator's\n * edits on re-run of `init`.\n */\nexport async function writeExampleSkillTemplate(agentDir: string): Promise<void> {\n const target = join(agentDir, 'skills', 'EXAMPLE.md');\n await writeFileIfMissing(target, EXAMPLE_SKILL_TEMPLATE, 0o644);\n}\n\nconst EXAMPLE_SKILL_TEMPLATE = `# elisym skill template\n#\n# This is reference material, not an active skill. The agent runtime\n# only loads skills from \\`skills/<name>/SKILL.md\\` (one folder per\n# skill). To turn this template into a real skill:\n#\n# 1. mkdir skills/my-skill\n# 2. cp skills/EXAMPLE.md skills/my-skill/SKILL.md\n# 3. uncomment the fields you need and fill in real values\n# 4. delete this comment block from the new file\n#\n# Full reference: see packages/cli/SKILLS.md in the elisym monorepo.\n\n# ---\n# # Required fields ---------------------------------------------------\n#\n# # Skill name. Must be unique within the agent. Used as the d-tag for\n# # routing incoming jobs (NIP-89/NIP-90).\n# name: My Skill\n#\n# # One-line description shown to customers in discovery UIs. Keep it\n# # short and concrete - this is the \"elevator pitch\" for the skill.\n# description: Send a prompt, get back a poem about it.\n#\n# # Capability tags. Customers filter and discover skills by these.\n# # At least one entry required. Use lowercase kebab-case.\n# capabilities:\n# - poetry\n# - text-generation\n#\n# # Price the customer pays per job. Number or numeric string. Free\n# # skills (price: 0) are allowed only when the agent runtime is\n# # configured with \\`allowFreeSkills\\`.\n# price: 0.05\n#\n# # Asset the price is denominated in. Defaults to \"sol\" for back-compat\n# # but USDC is the canonical paid-skill currency for examples.\n# token: usdc\n# # Optional explicit mint (base58). Resolved automatically for known\n# # tokens, so usually omit this.\n# # mint: 4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU\n#\n# # Execution mode. Defaults to \"llm\" if omitted.\n# # - llm: feed input to an LLM with the system prompt below.\n# # - static-file: return the contents of a fixed file (no input read).\n# # - static-script: spawn a script with no stdin (no input read).\n# # - dynamic-script: spawn a script and pipe the customer's input to stdin.\n# mode: llm\n#\n# # ---\n# # LLM configuration / dependency -----------------------------------\n# #\n# # For mode: 'llm', \\`provider\\` + \\`model\\` override the agent default\n# # for runtime LLM execution. \\`max_tokens\\` overrides the default cap.\n# #\n# # For script modes (static-script / dynamic-script / static-file):\n# # \\`provider\\` + \\`model\\` declare which LLM API key the script\n# # depends on. The agent registers the (provider, model) pair with\n# # the health monitor so it can:\n# # - probe the key at startup (refuse to start on invalid/billing-out)\n# # - reactively flip the pair to unhealthy if the script exits with\n# # SCRIPT_EXIT_BILLING_EXHAUSTED (= 42), refusing future jobs\n# # before payment until the key recovers\n# # - run a 5-min lazy recovery probe loop that flips the pair back\n# # to healthy as soon as the key works again\n# # \\`max_tokens\\` is rejected for script modes (the script controls\n# # its own token limits).\n# # provider: anthropic\n# # model: claude-haiku-4-5-20251001\n# # max_tokens: 4096\n#\n# # ---\n# # mode-specific fields -------------------------------------------\n#\n# # Required when mode === 'static-file'.\n# # output_file: ./output.txt\n#\n# # Required when mode === 'static-script' | 'dynamic-script'.\n# # script: ./scripts/run.sh\n# # script_args:\n# # - --flag\n# # - value\n# # script_timeout_ms: 60000\n#\n# # ---\n# # mode === 'llm' extras ------------------------------------------\n# #\n# # External tools the LLM can invoke during a job. Each tool is a\n# # named subprocess; the LLM decides whether/when to call it.\n# # tools:\n# # - name: lookup\n# # description: Look up a record by id.\n# # command:\n# # - ./tools/lookup.sh\n# # parameters:\n# # - name: id\n# # description: Record identifier (UUID).\n# # required: true\n#\n# # Cap on tool-use rounds (LLM <-> tools loop). Default 10.\n# # max_tool_rounds: 10\n#\n# # ---\n# # Per-skill rate limit (any mode) --------------------------------\n# # Snake-case in YAML, applied by the runtime regardless of mode.\n# # rate_limit:\n# # per_window_secs: 60\n# # max_per_window: 30\n#\n# # ---\n# # Imagery ---------------------------------------------------------\n# # Either a local file path (uploaded on first start) or an absolute\n# # URL. Local paths must stay inside the skill directory.\n# # image_file: ./skill-icon.png\n# # image: https://example.com/icon.png\n# ---\n#\n# Markdown body below the frontmatter is the system prompt for\n# mode === 'llm'. For other modes it's ignored.\n#\n# You are a helpful assistant. Reply concisely.\n`;\n\n/**\n * Write .secrets.json atomically. If `passphrase` is given, encrypts all\n * plaintext secret fields (already-encrypted values are left as-is).\n * Generic over `llm_api_keys` so any registered provider's key is\n * encrypted without per-provider plumbing here.\n */\nexport async function writeSecrets(\n agentDir: string,\n secrets: Secrets,\n passphrase?: string,\n): Promise<void> {\n const validated = SecretsSchema.parse(secrets);\n let encryptedLlmKeys: Record<string, string> | undefined;\n if (validated.llm_api_keys) {\n encryptedLlmKeys = {};\n for (const [providerId, value] of Object.entries(validated.llm_api_keys)) {\n if (value) {\n encryptedLlmKeys[providerId] = maybeEncrypt(value, passphrase);\n }\n }\n if (Object.keys(encryptedLlmKeys).length === 0) {\n encryptedLlmKeys = undefined;\n }\n }\n const finalSecrets: Secrets = {\n nostr_secret_key: maybeEncrypt(validated.nostr_secret_key, passphrase),\n solana_secret_key: validated.solana_secret_key\n ? maybeEncrypt(validated.solana_secret_key, passphrase)\n : undefined,\n llm_api_keys: encryptedLlmKeys,\n };\n const body = JSON.stringify(finalSecrets, null, 2) + '\\n';\n const target = agentPaths(agentDir).secrets;\n await writeFileAtomic(target, body, 0o600);\n}\n\nfunction maybeEncrypt(value: string, passphrase: string | undefined): string {\n if (!passphrase) {\n return value;\n }\n if (isEncrypted(value)) {\n return value;\n }\n return encryptSecret(value, passphrase);\n}\n\n/** Atomic write: temp file + rename. Preserves mode. */\nexport async function writeFileAtomic(\n path: string,\n data: string | Buffer,\n mode: number,\n): Promise<void> {\n await mkdir(dirname(path), { recursive: true });\n const tmpPath = `${path}.tmp.${randomBytes(6).toString('hex')}`;\n await writeFile(tmpPath, data, { mode });\n try {\n await rename(tmpPath, path);\n } catch (e) {\n // Best-effort cleanup of temp file on rename failure.\n try {\n const { unlink } = await import('node:fs/promises');\n await unlink(tmpPath);\n } catch {\n /* ignore */\n }\n throw e;\n }\n}\n\nasync function writeFileIfMissing(path: string, data: string, mode: number): Promise<void> {\n try {\n await writeFile(path, data, { mode, flag: 'wx' });\n } catch (e: unknown) {\n // wx fails with EEXIST if file exists - that's fine.\n if (!isEexist(e)) {\n throw e;\n }\n }\n}\n\nfunction isEexist(e: unknown): boolean {\n return (\n typeof e === 'object' && e !== null && 'code' in e && (e as { code: string }).code === 'EEXIST'\n );\n}\n","/**\n * List all agents discoverable from the current working directory:\n * - project-local: nearest .elisym/ (walk up to first .git or $HOME)\n * - home-global: ~/.elisym/\n * Project-local entries shadow home-global entries with the same name.\n */\n\nimport { readdir, readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport YAML from 'yaml';\nimport { findProjectElisymDir, homeElisymDir, YAML_FILENAME } from './paths';\nimport type { AgentSource } from './resolver';\nimport { ElisymYamlSchema } from './schema';\n\nexport interface ListedAgent {\n name: string;\n source: AgentSource;\n dir: string;\n /** display_name from YAML, if present. */\n displayName?: string;\n /** true when this entry is project-local and a home-global agent with the same name exists. */\n shadowsGlobal: boolean;\n}\n\n/** List agents in both locations, deduping by name (project wins). */\nexport async function listAgents(cwd: string): Promise<ListedAgent[]> {\n const homeDir = homeElisymDir();\n const projectDir = findProjectElisymDir(cwd);\n\n const homeAgents = await listAgentsInDir(homeDir, 'home');\n const projectAgents = projectDir ? await listAgentsInDir(projectDir, 'project') : [];\n\n const homeNames = new Set(homeAgents.map((agent) => agent.name));\n\n const merged: ListedAgent[] = [];\n\n for (const entry of projectAgents) {\n merged.push({ ...entry, shadowsGlobal: homeNames.has(entry.name) });\n }\n const projectNames = new Set(projectAgents.map((agent) => agent.name));\n for (const entry of homeAgents) {\n if (!projectNames.has(entry.name)) {\n merged.push(entry);\n }\n }\n\n merged.sort((left, right) => left.name.localeCompare(right.name));\n return merged;\n}\n\nasync function listAgentsInDir(rootDir: string, source: AgentSource): Promise<ListedAgent[]> {\n let entries: string[];\n try {\n entries = await readdir(rootDir);\n } catch {\n return [];\n }\n\n const results: ListedAgent[] = [];\n for (const entry of entries) {\n if (entry.startsWith('.')) {\n continue;\n }\n const agentDir = join(rootDir, entry);\n const yamlPath = join(agentDir, YAML_FILENAME);\n const displayName = await tryReadDisplayName(yamlPath);\n if (displayName === null) {\n continue;\n }\n results.push({\n name: entry,\n source,\n dir: agentDir,\n displayName: displayName || undefined,\n shadowsGlobal: false,\n });\n }\n\n return results;\n}\n\n/**\n * Read display_name from a YAML file. Returns null if the file is missing\n * or cannot be parsed (agent directory is skipped in listings).\n */\nasync function tryReadDisplayName(yamlPath: string): Promise<string | null> {\n let raw: string;\n try {\n raw = await readFile(yamlPath, 'utf-8');\n } catch {\n return null;\n }\n try {\n const parsed = YAML.parse(raw);\n const yaml = ElisymYamlSchema.partial().safeParse(parsed ?? {});\n if (!yaml.success) {\n return '';\n }\n return yaml.data.display_name ?? '';\n } catch {\n return '';\n }\n}\n","/**\n * Media cache: maps local image paths to uploaded URLs + sha256.\n * On each start, the CLI hashes the file and skips re-upload if the hash matches.\n */\n\nimport { createHash } from 'node:crypto';\nimport { readFile } from 'node:fs/promises';\nimport { agentPaths } from './paths';\nimport { MediaCacheSchema, type MediaCache, type MediaCacheEntry } from './schema';\nimport { writeFileAtomic } from './writer';\n\n/** Read .media-cache.json. Returns empty object if missing or corrupt. */\nexport async function readMediaCache(agentDir: string): Promise<MediaCache> {\n const path = agentPaths(agentDir).mediaCache;\n let raw: string;\n try {\n raw = await readFile(path, 'utf-8');\n } catch {\n return {};\n }\n try {\n const parsed = JSON.parse(raw);\n const result = MediaCacheSchema.safeParse(parsed);\n return result.success ? result.data : {};\n } catch {\n return {};\n }\n}\n\nexport async function writeMediaCache(agentDir: string, cache: MediaCache): Promise<void> {\n const path = agentPaths(agentDir).mediaCache;\n const body = JSON.stringify(cache, null, 2) + '\\n';\n await writeFileAtomic(path, body, 0o600);\n}\n\n/** Compute sha256 hex of a file's contents. */\nexport async function hashFile(filePath: string): Promise<string> {\n const buf = await readFile(filePath);\n return createHash('sha256').update(buf).digest('hex');\n}\n\n/**\n * Look up a cached URL for a local file path. Returns the cached URL if\n * the file's current hash matches the cache entry; otherwise null.\n */\nexport async function lookupCachedUrl(\n cache: MediaCache,\n relativePath: string,\n absolutePath: string,\n): Promise<string | null> {\n const entry = cache[relativePath];\n if (!entry) {\n return null;\n }\n let hash: string;\n try {\n hash = await hashFile(absolutePath);\n } catch {\n return null;\n }\n return hash === entry.sha256 ? entry.url : null;\n}\n\nexport function newCacheEntry(url: string, sha256: string): MediaCacheEntry {\n return { url, sha256, uploaded_at: new Date().toISOString() };\n}\n"]}
@@ -298,6 +298,27 @@ interface CreatedAgentDir {
298
298
  declare function createAgentDir(options: CreateAgentDirOptions): Promise<CreatedAgentDir>;
299
299
  /** Write elisym.yaml atomically. Validates via Zod before writing. */
300
300
  declare function writeYaml(agentDir: string, yaml: ElisymYaml): Promise<void>;
301
+ /**
302
+ * Write a brand-new elisym.yaml with descriptive header comments and
303
+ * commented-out examples for unset optional fields. Use only at agent
304
+ * creation time (CLI `init`, MCP `create_agent`). Subsequent edits go
305
+ * through `writeYaml`, which discards comments.
306
+ */
307
+ declare function writeYamlInitial(agentDir: string, yaml: ElisymYaml): Promise<void>;
308
+ /**
309
+ * Create a skills directory placeholder file with a commented-out SKILL.md
310
+ * template covering every supported field, so operators have a reference
311
+ * for what they can declare without having to read source. The file is
312
+ * named `EXAMPLE.md` (not `SKILL.md`) and lives directly in `skills/`
313
+ * (not in a subdirectory), so the skill loader skips it - it's reference
314
+ * material, not an active skill. To turn it into a real skill: copy it
315
+ * into `skills/<your-skill-name>/SKILL.md` and uncomment the lines you
316
+ * need.
317
+ *
318
+ * Idempotent: written with `wx` flag so we never overwrite an operator's
319
+ * edits on re-run of `init`.
320
+ */
321
+ declare function writeExampleSkillTemplate(agentDir: string): Promise<void>;
301
322
  /**
302
323
  * Write .secrets.json atomically. If `passphrase` is given, encrypts all
303
324
  * plaintext secret fields (already-encrypted values are left as-is).
@@ -308,6 +329,20 @@ declare function writeSecrets(agentDir: string, secrets: Secrets, passphrase?: s
308
329
  /** Atomic write: temp file + rename. Preserves mode. */
309
330
  declare function writeFileAtomic(path: string, data: string | Buffer, mode: number): Promise<void>;
310
331
 
332
+ /**
333
+ * Render a fresh `elisym.yaml` as a string with descriptive header comments
334
+ * over each top-level field. Optional fields that are not set in the input
335
+ * are emitted as commented-out examples so a new operator can see what else
336
+ * is configurable without leaving the file.
337
+ *
338
+ * Used only at agent-creation time (CLI `init`, MCP `create_agent`). On
339
+ * subsequent writes via `writeYaml`, the document is re-serialized without
340
+ * comments - this template is a one-shot scaffold, not a round-tripping
341
+ * format.
342
+ */
343
+
344
+ declare function renderInitialYaml(yaml: ElisymYaml): string;
345
+
311
346
  /**
312
347
  * List all agents discoverable from the current working directory:
313
348
  * - project-local: nearest .elisym/ (walk up to first .git or $HOME)
@@ -344,4 +379,4 @@ declare function hashFile(filePath: string): Promise<string>;
344
379
  declare function lookupCachedUrl(cache: MediaCache, relativePath: string, absolutePath: string): Promise<string | null>;
345
380
  declare function newCacheEntry(url: string, sha256: string): MediaCacheEntry;
346
381
 
347
- export { AgentNameSchema, type AgentPaths, type AgentSource, type CreateAgentDirOptions, type CreatedAgentDir, ELISYM_DIRNAME, type ElisymYaml, ElisymYamlSchema, GITIGNORE_FILENAME, JOBS_FILENAME, type ListedAgent, type LlmEntry, LlmSchema, type LoadedAgent, MEDIA_CACHE_FILENAME, type MediaCache, type MediaCacheEntry, MediaCacheEntrySchema, MediaCacheSchema, type PaymentEntry, PaymentSchema, type ResolvedAgent, SECRETS_FILENAME, SKILLS_DIRNAME, type Secrets, SecretsSchema, type SecurityFlags, SecurityFlagsSchema, YAML_FILENAME, agentPaths, createAgentDir, elisymRootFor, findProjectElisymDir, globalConfigPath, hashFile, homeElisymDir, listAgents, loadAgent, loadResolvedAgent, lookupCachedUrl, newCacheEntry, readAgentPublic, readMediaCache, resolveAgent, resolveInHome, resolveInProject, writeFileAtomic, writeMediaCache, writeSecrets, writeYaml };
382
+ export { AgentNameSchema, type AgentPaths, type AgentSource, type CreateAgentDirOptions, type CreatedAgentDir, ELISYM_DIRNAME, type ElisymYaml, ElisymYamlSchema, GITIGNORE_FILENAME, JOBS_FILENAME, type ListedAgent, type LlmEntry, LlmSchema, type LoadedAgent, MEDIA_CACHE_FILENAME, type MediaCache, type MediaCacheEntry, MediaCacheEntrySchema, MediaCacheSchema, type PaymentEntry, PaymentSchema, type ResolvedAgent, SECRETS_FILENAME, SKILLS_DIRNAME, type Secrets, SecretsSchema, type SecurityFlags, SecurityFlagsSchema, YAML_FILENAME, agentPaths, createAgentDir, elisymRootFor, findProjectElisymDir, globalConfigPath, hashFile, homeElisymDir, listAgents, loadAgent, loadResolvedAgent, lookupCachedUrl, newCacheEntry, readAgentPublic, readMediaCache, renderInitialYaml, resolveAgent, resolveInHome, resolveInProject, writeExampleSkillTemplate, writeFileAtomic, writeMediaCache, writeSecrets, writeYaml, writeYamlInitial };