@elisym/sdk 0.24.1 → 0.25.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.
@@ -98,14 +98,17 @@ var GITIGNORE_FILENAME = ".gitignore";
98
98
  var SKILLS_DIRNAME = "skills";
99
99
  var POLICIES_DIRNAME = "policies";
100
100
  var MAX_WALK_UP_DEPTH = 64;
101
+ function userHome() {
102
+ return process.env.HOME ?? os.homedir();
103
+ }
101
104
  function homeElisymDir() {
102
- return path.join(os.homedir(), ELISYM_DIRNAME);
105
+ return path.join(userHome(), ELISYM_DIRNAME);
103
106
  }
104
107
  function globalConfigPath() {
105
108
  return path.join(homeElisymDir(), "config.yaml");
106
109
  }
107
110
  function findProjectElisymDir(startDir) {
108
- const home = os.homedir();
111
+ const home = userHome();
109
112
  let current = path.resolve(startDir);
110
113
  let previous = null;
111
114
  for (let depth = 0; depth < MAX_WALK_UP_DEPTH; depth++) {
@@ -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/template.ts","../src/agent-store/writer.ts","../src/agent-store/list.ts","../src/agent-store/media-cache.ts","../src/agent-store/policies.ts"],"names":["z","join","homedir","resolve","existsSync","dirname","statSync","randomBytes","scryptSync","createCipheriv","Buffer","createDecipheriv","readFile","YAML","writeFile","mkdir","path","rename","readdir","createHash","readdirSync","readFileSync"],"mappings":";;;;;;;;;;;;;;;;;;AAEO,IAAM,MAAA,GAAS;AAAA,EACpB,sBAAA;AAAA,EACA,eAAA;AAAA,EACA,wBAAA;AAAA,EACA,wBAAA;AAAA,EACA;AACF,CAAA;AAcO,IAAM,iBAAA,GAAoB,wCAAA;AA2F1B,IAAM,MAAA,GAAS;AAAA,EAsBF;AAAA;AAAA;AAAA;AAAA,EAKlB,kBAAA,EAAoB,OAAA;AAAA,EAEpB,s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AS,CAAA,GAC3E,WAAA,CAAY,QAAQ,IAAA,EAAK,CAAE,MAAM,CAAA,EAAG,MAAA,CAAO,yBAAyB,CAAA,GACpE,MAAA;AAEN,IAAA,MAAA,CAAO,KAAK,EAAE,IAAA,EAAM,SAAS,KAAA,EAAO,OAAA,EAAS,SAAS,CAAA;AAAA,EACxD;AAEA,EAAA,OAAO,MAAA;AACT","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_LONG_FORM_ARTICLE = 30023;\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/** Discovery tag attached to elisym agent policy events (kind 30023). */\nexport const POLICY_T_TAG = 'elisym-policy';\n/** d-tag prefix for policy events: full d-tag = `<prefix><type>` (e.g. `elisym-policy-tos`). */\nexport const POLICY_D_TAG_PREFIX = 'elisym-policy-';\n/** Validation regex for policy `type` slug. Lowercase ASCII + hyphen, 1-32 chars, no leading/trailing hyphen. */\nexport const POLICY_TYPE_REGEX = /^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$/;\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 // Default ceiling for a single iroh file transfer (seed/fetch). A tunable\n // default, not a protocol constant - the transfer is resumable and its own\n // budget, decoupled from the result-wait window.\n IROH_FETCH_TIMEOUT_MS: 300_000,\n} as const;\n\n/** Protocol limits for input validation. */\nexport const LIMITS = {\n MAX_INPUT_LENGTH: 100_000,\n // NIP-44 v2 hard cap on encrypted plaintext: the pad() length prefix is a u16,\n // so the plaintext can be at most 65_535 BYTES (not chars). Encrypting anything\n // larger throws `invalid plaintext size` inside nip44Encrypt. This is the binding\n // limit for TARGETED (encrypted) jobs - lower than every relay's NIP-11 cap.\n NIP44_MAX_PLAINTEXT_BYTES: 65_535,\n // Spill threshold for encrypted content: above this many UTF-8 bytes, callers\n // route the text through iroh out-of-band instead of inlining it. A non-spilled\n // job is encrypted RAW (no envelope - see marketplace.submitJobRequest), so a\n // 60_000-byte input is a 60_000-byte plaintext; the ~5.5KB gap under the hard cap\n // is plain slack, and NIP44_MAX_PLAINTEXT_BYTES is the SDK backstop.\n MAX_ENCRYPTED_INLINE_BYTES: 60_000,\n // Ceiling above which a text/* attachment is NOT materialized back into a string\n // (re-inlined into SkillInput.data) - the consumer gets a filePath / explicit\n // fetch instead. Also bounds the in-memory git-diff buffer (memory-DoS guard).\n MAX_REINLINE_TEXT_BYTES: 4_194_304, // 4 MiB\n // Hard safety cap on a single file transferred via iroh, enforced on the\n // actual streamed bytes (never the sender-declared `size`). A tunable default;\n // providers may lower it per deployment.\n MAX_FILE_SIZE: 1_073_741_824, // 1 GiB\n\n MAX_TIMEOUT_SECS: 600,\n // Upper bound for execution budgets (`max_execution_secs` / `execution_timeout_secs`).\n // Distinct from MAX_TIMEOUT_SECS (the result-wait cap): execution budgets may be\n // hours, so this exists only to keep `secs * 1000` within Node's setTimeout limit\n // (2_147_483_647 ms) - a larger value overflows and fires the timer immediately.\n MAX_EXECUTION_SECS: 2_147_483,\n MAX_CAPABILITIES: 20,\n MAX_DESCRIPTION_LENGTH: 500,\n MAX_AGENT_NAME_LENGTH: 64,\n MAX_CAPABILITY_LENGTH: 64,\n MAX_POLICY_CONTENT_LENGTH: 50_000,\n MAX_POLICIES_PER_AGENT: 12,\n MAX_POLICY_TYPE_LENGTH: 32,\n MAX_POLICY_TITLE_LENGTH: 120,\n MAX_POLICY_SUMMARY_LENGTH: 280,\n MAX_POLICY_VERSION_LENGTH: 32,\n} as const;\n\nconst UTF8_ENCODER = new TextEncoder();\n\n/**\n * UTF-8 byte length of a string. All size guards on encrypted content measure\n * BYTES, not `String.length` (UTF-16 code units): NIP-44's plaintext cap is a\n * byte cap, so a multibyte string under the char cap can still exceed it.\n */\nexport function utf8ByteLength(value: string): number {\n return UTF8_ENCODER.encode(value).length;\n}\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 * Agent-level default execution budget in seconds for every skill that does\n * not set its own `max_execution_secs`. `0` => unlimited. Omitted =>\n * unlimited (the operator owns this; the protocol imposes no default).\n */\n execution_timeout_secs: z.number().int().min(0).max(LIMITS.MAX_EXECUTION_SECS).optional(),\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';\nexport const POLICIES_DIRNAME = 'policies';\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 policies: 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 policies: join(agentDir, POLICIES_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 description:\n 'Default execution budget (seconds) for skills without their own ' +\n 'max_execution_secs. 0 = unlimited. Omit for unlimited - the protocol ' +\n 'imposes no default, so this is operator-owned.',\n key: 'execution_timeout_secs',\n value: yaml.execution_timeout_secs,\n placeholder: 1800,\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, readFile, 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\n/** Bare per-agent `.iroh/` store dir; ignored at any depth under `.elisym/`. */\nconst IROH_GITIGNORE_ENTRY = '.iroh/';\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 IROH_GITIGNORE_ENTRY,\n '',\n].join('\\n');\n\n/**\n * Ensure the project-local `.elisym/.gitignore` ignores the iroh blob store.\n * Idempotent migration for agents created before `.iroh/` was added to the\n * default ignore list; a no-op when no `.gitignore` exists (e.g. home-global,\n * which relies on directory permissions instead). The iroh store holds job\n * payloads in cleartext, so it must never be committed.\n */\nexport async function ensureGitignoreHasIrohEntry(elisymRoot: string): Promise<void> {\n const gitignorePath = join(elisymRoot, '.gitignore');\n let current: string;\n try {\n current = await readFile(gitignorePath, 'utf-8');\n } catch {\n return;\n }\n const hasEntry = current.split('\\n').some((line) => line.trim() === IROH_GITIGNORE_ENTRY);\n if (hasEntry) {\n return;\n }\n const separator = current.length === 0 || current.endsWith('\\n') ? '' : '\\n';\n await writeFile(gitignorePath, `${current}${separator}${IROH_GITIGNORE_ENTRY}\\n`, {\n mode: 0o644,\n });\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# # Per-skill execution budget (any mode) --------------------------\n# # Caps skill.execute (seconds). 0 = unlimited; omit to inherit the\n# # agent-level execution_timeout_secs (unlimited if that is unset too).\n# # max_execution_secs: 1800\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","/**\n * Disk-side loader for agent policies. Reads `<agent-root>/policies/*.md`,\n * parses optional YAML frontmatter, and returns validated policy records ready\n * to be passed to `PoliciesService.publishPolicy`.\n *\n * Filename without `.md` becomes the policy `type` slug (lowercase normalized).\n * Frontmatter fields are all optional - sensible defaults apply.\n *\n * Node.js only - relies on `node:fs` and `yaml`.\n */\n\nimport { readFileSync, readdirSync, statSync } from 'node:fs';\nimport { join } from 'node:path';\nimport YAML from 'yaml';\nimport { LIMITS, POLICY_TYPE_REGEX } from '../constants';\n\nexport interface LoadedPolicy {\n /** Slug derived from filename (e.g. `tos`, `privacy`, `refund`). */\n type: string;\n version: string;\n title: string;\n summary?: string;\n /** Markdown body without frontmatter. */\n content: string;\n}\n\ninterface PolicyFrontmatter {\n title?: string;\n version?: string;\n summary?: string;\n}\n\nfunction humanizeType(type: string): string {\n return type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(' ');\n}\n\nfunction parseFrontmatter(raw: string): { frontmatter: PolicyFrontmatter; body: string } {\n const lines = raw.split('\\n');\n if (lines[0]?.trim() !== '---') {\n return { frontmatter: {}, body: raw };\n }\n let endIndex = -1;\n for (let i = 1; i < lines.length; i++) {\n if (lines[i]?.trim() === '---') {\n endIndex = i;\n break;\n }\n }\n if (endIndex === -1) {\n throw new Error('frontmatter opened with --- but never closed');\n }\n const yamlStr = lines.slice(1, endIndex).join('\\n');\n const parsed = YAML.parse(yamlStr) as unknown;\n const frontmatter: PolicyFrontmatter =\n parsed !== null && typeof parsed === 'object' ? (parsed as PolicyFrontmatter) : {};\n const body = lines\n .slice(endIndex + 1)\n .join('\\n')\n .replace(/^\\n+/, '');\n return { frontmatter, body };\n}\n\n/**\n * Load all policy markdown files from `dir`. Returns an empty array if the\n * directory does not exist. Does not recurse into subdirectories.\n *\n * Edge cases:\n * - Skips non-`.md` files silently\n * - Logs a warning and skips files with malformed frontmatter or empty body\n * - Logs an error and skips files exceeding `MAX_POLICY_CONTENT_LENGTH`\n * - Throws if two files normalize to the same `type` slug (case-insensitive)\n * - At most `MAX_POLICIES_PER_AGENT` policies returned (alphabetical, rest skipped with warning)\n */\nexport function loadPoliciesFromDir(dir: string): LoadedPolicy[] {\n let entries: string[];\n try {\n if (!statSync(dir).isDirectory()) {\n return [];\n }\n entries = readdirSync(dir);\n } catch {\n return [];\n }\n\n const mdFiles = entries\n .filter((name) => name.toLowerCase().endsWith('.md'))\n .sort((a, b) => a.localeCompare(b));\n\n const seenTypes = new Set<string>();\n const loaded: LoadedPolicy[] = [];\n\n for (const filename of mdFiles) {\n const type = filename.slice(0, -'.md'.length).toLowerCase();\n if (!POLICY_TYPE_REGEX.test(type)) {\n console.warn(\n ` ! Skipping policy \"${filename}\": invalid type slug. Allowed: lowercase ASCII + hyphen, 1-${LIMITS.MAX_POLICY_TYPE_LENGTH} chars.`,\n );\n continue;\n }\n if (seenTypes.has(type)) {\n throw new Error(\n `Duplicate policy type \"${type}\" (case-insensitive collision in ${dir}). Policy filenames must be unique when lowercased.`,\n );\n }\n seenTypes.add(type);\n\n if (loaded.length >= LIMITS.MAX_POLICIES_PER_AGENT) {\n console.warn(\n ` ! Skipping policy \"${filename}\": agent has more than ${LIMITS.MAX_POLICIES_PER_AGENT} policies (cap).`,\n );\n continue;\n }\n\n const fullPath = join(dir, filename);\n let raw: string;\n try {\n raw = readFileSync(fullPath, 'utf-8');\n } catch (err) {\n console.warn(` ! Skipping policy \"${filename}\": ${(err as Error).message}`);\n continue;\n }\n\n let frontmatter: PolicyFrontmatter;\n let body: string;\n try {\n const parsed = parseFrontmatter(raw);\n frontmatter = parsed.frontmatter;\n body = parsed.body;\n } catch (err) {\n console.warn(` ! Skipping policy \"${filename}\": ${(err as Error).message}`);\n continue;\n }\n\n const content = body.trim();\n if (content.length === 0) {\n console.warn(` ! Skipping policy \"${filename}\": empty body.`);\n continue;\n }\n if (content.length > LIMITS.MAX_POLICY_CONTENT_LENGTH) {\n console.error(\n ` ! Skipping policy \"${filename}\": ${content.length} chars exceeds ${LIMITS.MAX_POLICY_CONTENT_LENGTH} limit.`,\n );\n continue;\n }\n\n const title =\n typeof frontmatter.title === 'string' && frontmatter.title.trim().length > 0\n ? frontmatter.title.trim().slice(0, LIMITS.MAX_POLICY_TITLE_LENGTH)\n : humanizeType(type);\n const version =\n typeof frontmatter.version === 'string' && frontmatter.version.trim().length > 0\n ? frontmatter.version.trim().slice(0, LIMITS.MAX_POLICY_VERSION_LENGTH)\n : '1.0';\n const summary =\n typeof frontmatter.summary === 'string' && frontmatter.summary.trim().length > 0\n ? frontmatter.summary.trim().slice(0, LIMITS.MAX_POLICY_SUMMARY_LENGTH)\n : undefined;\n\n loaded.push({ type, version, title, summary, content });\n }\n\n return loaded;\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","../src/agent-store/policies.ts"],"names":["z","homedir","join","resolve","existsSync","dirname","statSync","randomBytes","scryptSync","createCipheriv","Buffer","createDecipheriv","readFile","YAML","writeFile","mkdir","path","rename","readdir","createHash","readdirSync","readFileSync"],"mappings":";;;;;;;;;;;;;;;;;;AAEO,IAAM,MAAA,GAAS;AAAA,EACpB,sBAAA;AAAA,EACA,eAAA;AAAA,EACA,wBAAA;AAAA,EACA,wBAAA;AAAA,EACA;AACF,CAAA;AAcO,IAAM,iBAAA,GAAoB,wCAAA;AA8F1B,IAAM,MAAA,GAAS;AAAA,EAsBF;AAAA;AAAA;AAAA;AAAA,EAKlB,kBAAA,EAAoB,OAAA;AAAA,EAEpB,sBAAA,EAAwB,GAAA;AAAA,EACxB,qBAAA,EAAuB,EAAA;AAAA,EAEvB,yBAAA,EAA2B,GAAA;AAAA,EAC3B,sBAAA,EAAwB,EAAA;AAAA,EACxB,sBAAA,EAAwB,EAAA;AAAA,EACxB,uBAAA,EAAyB,GAAA;AAAA,EACzB,yBAAA,EAA2B,GAAA;AAAA,EAC3B,yBAAA,EAA2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E,IAAA,EAAM,SAAS,KAAA,EAAO,OAAA,EAAS,SAAS,CAAA;AAAA,EACxD;AAEA,EAAA,OAAO,MAAA;AACT","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_LONG_FORM_ARTICLE = 30023;\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/** Discovery tag attached to elisym agent policy events (kind 30023). */\nexport const POLICY_T_TAG = 'elisym-policy';\n/** d-tag prefix for policy events: full d-tag = `<prefix><type>` (e.g. `elisym-policy-tos`). */\nexport const POLICY_D_TAG_PREFIX = 'elisym-policy-';\n/** Validation regex for policy `type` slug. Lowercase ASCII + hyphen, 1-32 chars, no leading/trailing hyphen. */\nexport const POLICY_TYPE_REGEX = /^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$/;\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 // Default ceiling for a single iroh file transfer (seed/fetch). A tunable\n // default, not a protocol constant - the transfer is resumable and its own\n // budget, decoupled from the result-wait window.\n IROH_FETCH_TIMEOUT_MS: 300_000,\n // Ceiling for a single Blossom blob upload (PUT /upload). Large blobs (up to\n // LIMITS.MAX_FILE_SIZE) need far more than the 30s used for small media images.\n BLOSSOM_UPLOAD_TIMEOUT_MS: 300_000,\n} as const;\n\n/** Protocol limits for input validation. */\nexport const LIMITS = {\n MAX_INPUT_LENGTH: 100_000,\n // NIP-44 v2 hard cap on encrypted plaintext: the pad() length prefix is a u16,\n // so the plaintext can be at most 65_535 BYTES (not chars). Encrypting anything\n // larger throws `invalid plaintext size` inside nip44Encrypt. This is the binding\n // limit for TARGETED (encrypted) jobs - lower than every relay's NIP-11 cap.\n NIP44_MAX_PLAINTEXT_BYTES: 65_535,\n // Spill threshold for encrypted content: above this many UTF-8 bytes, callers\n // route the text through iroh out-of-band instead of inlining it. A non-spilled\n // job is encrypted RAW (no envelope - see marketplace.submitJobRequest), so a\n // 60_000-byte input is a 60_000-byte plaintext; the ~5.5KB gap under the hard cap\n // is plain slack, and NIP44_MAX_PLAINTEXT_BYTES is the SDK backstop.\n MAX_ENCRYPTED_INLINE_BYTES: 60_000,\n // Ceiling above which a text/* attachment is NOT materialized back into a string\n // (re-inlined into SkillInput.data) - the consumer gets a filePath / explicit\n // fetch instead. Also bounds the in-memory git-diff buffer (memory-DoS guard).\n MAX_REINLINE_TEXT_BYTES: 4_194_304, // 4 MiB\n // Hard safety cap on a single file transferred via iroh, enforced on the\n // actual streamed bytes (never the sender-declared `size`). A tunable default;\n // providers may lower it per deployment.\n MAX_FILE_SIZE: 1_073_741_824, // 1 GiB\n\n MAX_TIMEOUT_SECS: 600,\n // Upper bound for execution budgets (`max_execution_secs` / `execution_timeout_secs`).\n // Distinct from MAX_TIMEOUT_SECS (the result-wait cap): execution budgets may be\n // hours, so this exists only to keep `secs * 1000` within Node's setTimeout limit\n // (2_147_483_647 ms) - a larger value overflows and fires the timer immediately.\n MAX_EXECUTION_SECS: 2_147_483,\n MAX_CAPABILITIES: 20,\n MAX_DESCRIPTION_LENGTH: 500,\n MAX_AGENT_NAME_LENGTH: 64,\n MAX_CAPABILITY_LENGTH: 64,\n MAX_POLICY_CONTENT_LENGTH: 50_000,\n MAX_POLICIES_PER_AGENT: 12,\n MAX_POLICY_TYPE_LENGTH: 32,\n MAX_POLICY_TITLE_LENGTH: 120,\n MAX_POLICY_SUMMARY_LENGTH: 280,\n MAX_POLICY_VERSION_LENGTH: 32,\n} as const;\n\nconst UTF8_ENCODER = new TextEncoder();\n\n/**\n * UTF-8 byte length of a string. All size guards on encrypted content measure\n * BYTES, not `String.length` (UTF-16 code units): NIP-44's plaintext cap is a\n * byte cap, so a multibyte string under the char cap can still exceed it.\n */\nexport function utf8ByteLength(value: string): number {\n return UTF8_ENCODER.encode(value).length;\n}\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 * Agent-level default execution budget in seconds for every skill that does\n * not set its own `max_execution_secs`. `0` => unlimited. Omitted =>\n * unlimited (the operator owns this; the protocol imposes no default).\n */\n execution_timeout_secs: z.number().int().min(0).max(LIMITS.MAX_EXECUTION_SECS).optional(),\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';\nexport const POLICIES_DIRNAME = 'policies';\n\n/** Max depth for walk-up search (safety guard against unbounded loops). */\nconst MAX_WALK_UP_DEPTH = 64;\n\nfunction userHome(): string {\n return process.env.HOME ?? homedir();\n}\n\n/** ~/.elisym/ */\nexport function homeElisymDir(): string {\n return join(userHome(), 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 = userHome();\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 policies: 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 policies: join(agentDir, POLICIES_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 description:\n 'Default execution budget (seconds) for skills without their own ' +\n 'max_execution_secs. 0 = unlimited. Omit for unlimited - the protocol ' +\n 'imposes no default, so this is operator-owned.',\n key: 'execution_timeout_secs',\n value: yaml.execution_timeout_secs,\n placeholder: 1800,\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, readFile, 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\n/** Bare per-agent `.iroh/` store dir; ignored at any depth under `.elisym/`. */\nconst IROH_GITIGNORE_ENTRY = '.iroh/';\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 IROH_GITIGNORE_ENTRY,\n '',\n].join('\\n');\n\n/**\n * Ensure the project-local `.elisym/.gitignore` ignores the iroh blob store.\n * Idempotent migration for agents created before `.iroh/` was added to the\n * default ignore list; a no-op when no `.gitignore` exists (e.g. home-global,\n * which relies on directory permissions instead). The iroh store holds job\n * payloads in cleartext, so it must never be committed.\n */\nexport async function ensureGitignoreHasIrohEntry(elisymRoot: string): Promise<void> {\n const gitignorePath = join(elisymRoot, '.gitignore');\n let current: string;\n try {\n current = await readFile(gitignorePath, 'utf-8');\n } catch {\n return;\n }\n const hasEntry = current.split('\\n').some((line) => line.trim() === IROH_GITIGNORE_ENTRY);\n if (hasEntry) {\n return;\n }\n const separator = current.length === 0 || current.endsWith('\\n') ? '' : '\\n';\n await writeFile(gitignorePath, `${current}${separator}${IROH_GITIGNORE_ENTRY}\\n`, {\n mode: 0o644,\n });\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# # Per-skill execution budget (any mode) --------------------------\n# # Caps skill.execute (seconds). 0 = unlimited; omit to inherit the\n# # agent-level execution_timeout_secs (unlimited if that is unset too).\n# # max_execution_secs: 1800\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","/**\n * Disk-side loader for agent policies. Reads `<agent-root>/policies/*.md`,\n * parses optional YAML frontmatter, and returns validated policy records ready\n * to be passed to `PoliciesService.publishPolicy`.\n *\n * Filename without `.md` becomes the policy `type` slug (lowercase normalized).\n * Frontmatter fields are all optional - sensible defaults apply.\n *\n * Node.js only - relies on `node:fs` and `yaml`.\n */\n\nimport { readFileSync, readdirSync, statSync } from 'node:fs';\nimport { join } from 'node:path';\nimport YAML from 'yaml';\nimport { LIMITS, POLICY_TYPE_REGEX } from '../constants';\n\nexport interface LoadedPolicy {\n /** Slug derived from filename (e.g. `tos`, `privacy`, `refund`). */\n type: string;\n version: string;\n title: string;\n summary?: string;\n /** Markdown body without frontmatter. */\n content: string;\n}\n\ninterface PolicyFrontmatter {\n title?: string;\n version?: string;\n summary?: string;\n}\n\nfunction humanizeType(type: string): string {\n return type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(' ');\n}\n\nfunction parseFrontmatter(raw: string): { frontmatter: PolicyFrontmatter; body: string } {\n const lines = raw.split('\\n');\n if (lines[0]?.trim() !== '---') {\n return { frontmatter: {}, body: raw };\n }\n let endIndex = -1;\n for (let i = 1; i < lines.length; i++) {\n if (lines[i]?.trim() === '---') {\n endIndex = i;\n break;\n }\n }\n if (endIndex === -1) {\n throw new Error('frontmatter opened with --- but never closed');\n }\n const yamlStr = lines.slice(1, endIndex).join('\\n');\n const parsed = YAML.parse(yamlStr) as unknown;\n const frontmatter: PolicyFrontmatter =\n parsed !== null && typeof parsed === 'object' ? (parsed as PolicyFrontmatter) : {};\n const body = lines\n .slice(endIndex + 1)\n .join('\\n')\n .replace(/^\\n+/, '');\n return { frontmatter, body };\n}\n\n/**\n * Load all policy markdown files from `dir`. Returns an empty array if the\n * directory does not exist. Does not recurse into subdirectories.\n *\n * Edge cases:\n * - Skips non-`.md` files silently\n * - Logs a warning and skips files with malformed frontmatter or empty body\n * - Logs an error and skips files exceeding `MAX_POLICY_CONTENT_LENGTH`\n * - Throws if two files normalize to the same `type` slug (case-insensitive)\n * - At most `MAX_POLICIES_PER_AGENT` policies returned (alphabetical, rest skipped with warning)\n */\nexport function loadPoliciesFromDir(dir: string): LoadedPolicy[] {\n let entries: string[];\n try {\n if (!statSync(dir).isDirectory()) {\n return [];\n }\n entries = readdirSync(dir);\n } catch {\n return [];\n }\n\n const mdFiles = entries\n .filter((name) => name.toLowerCase().endsWith('.md'))\n .sort((a, b) => a.localeCompare(b));\n\n const seenTypes = new Set<string>();\n const loaded: LoadedPolicy[] = [];\n\n for (const filename of mdFiles) {\n const type = filename.slice(0, -'.md'.length).toLowerCase();\n if (!POLICY_TYPE_REGEX.test(type)) {\n console.warn(\n ` ! Skipping policy \"${filename}\": invalid type slug. Allowed: lowercase ASCII + hyphen, 1-${LIMITS.MAX_POLICY_TYPE_LENGTH} chars.`,\n );\n continue;\n }\n if (seenTypes.has(type)) {\n throw new Error(\n `Duplicate policy type \"${type}\" (case-insensitive collision in ${dir}). Policy filenames must be unique when lowercased.`,\n );\n }\n seenTypes.add(type);\n\n if (loaded.length >= LIMITS.MAX_POLICIES_PER_AGENT) {\n console.warn(\n ` ! Skipping policy \"${filename}\": agent has more than ${LIMITS.MAX_POLICIES_PER_AGENT} policies (cap).`,\n );\n continue;\n }\n\n const fullPath = join(dir, filename);\n let raw: string;\n try {\n raw = readFileSync(fullPath, 'utf-8');\n } catch (err) {\n console.warn(` ! Skipping policy \"${filename}\": ${(err as Error).message}`);\n continue;\n }\n\n let frontmatter: PolicyFrontmatter;\n let body: string;\n try {\n const parsed = parseFrontmatter(raw);\n frontmatter = parsed.frontmatter;\n body = parsed.body;\n } catch (err) {\n console.warn(` ! Skipping policy \"${filename}\": ${(err as Error).message}`);\n continue;\n }\n\n const content = body.trim();\n if (content.length === 0) {\n console.warn(` ! Skipping policy \"${filename}\": empty body.`);\n continue;\n }\n if (content.length > LIMITS.MAX_POLICY_CONTENT_LENGTH) {\n console.error(\n ` ! Skipping policy \"${filename}\": ${content.length} chars exceeds ${LIMITS.MAX_POLICY_CONTENT_LENGTH} limit.`,\n );\n continue;\n }\n\n const title =\n typeof frontmatter.title === 'string' && frontmatter.title.trim().length > 0\n ? frontmatter.title.trim().slice(0, LIMITS.MAX_POLICY_TITLE_LENGTH)\n : humanizeType(type);\n const version =\n typeof frontmatter.version === 'string' && frontmatter.version.trim().length > 0\n ? frontmatter.version.trim().slice(0, LIMITS.MAX_POLICY_VERSION_LENGTH)\n : '1.0';\n const summary =\n typeof frontmatter.summary === 'string' && frontmatter.summary.trim().length > 0\n ? frontmatter.summary.trim().slice(0, LIMITS.MAX_POLICY_SUMMARY_LENGTH)\n : undefined;\n\n loaded.push({ type, version, title, summary, content });\n }\n\n return loaded;\n}\n"]}
@@ -92,14 +92,17 @@ var GITIGNORE_FILENAME = ".gitignore";
92
92
  var SKILLS_DIRNAME = "skills";
93
93
  var POLICIES_DIRNAME = "policies";
94
94
  var MAX_WALK_UP_DEPTH = 64;
95
+ function userHome() {
96
+ return process.env.HOME ?? homedir();
97
+ }
95
98
  function homeElisymDir() {
96
- return join(homedir(), ELISYM_DIRNAME);
99
+ return join(userHome(), ELISYM_DIRNAME);
97
100
  }
98
101
  function globalConfigPath() {
99
102
  return join(homeElisymDir(), "config.yaml");
100
103
  }
101
104
  function findProjectElisymDir(startDir) {
102
- const home = homedir();
105
+ const home = userHome();
103
106
  let current = resolve(startDir);
104
107
  let previous = null;
105
108
  for (let depth = 0; depth < MAX_WALK_UP_DEPTH; depth++) {