@kashdao/cli 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/CHANGELOG.md +108 -0
  2. package/README.md +87 -37
  3. package/dist/{account-AVFLEM5D.js → account-QHPOIZ6I.js} +9 -9
  4. package/dist/{auth-GUJCVKTD.js → auth-TE7BCN5Q.js} +13 -13
  5. package/dist/auth-TE7BCN5Q.js.map +1 -0
  6. package/dist/{chunk-VIADBYFY.js → chunk-2HFKULGG.js} +2 -2
  7. package/dist/{chunk-YHCG2SUC.js → chunk-2SR77BYA.js} +10 -9
  8. package/dist/chunk-2SR77BYA.js.map +1 -0
  9. package/dist/chunk-6QSTFU4R.js +9 -0
  10. package/dist/{chunk-BN2CUM42.js.map → chunk-6QSTFU4R.js.map} +1 -1
  11. package/dist/{chunk-BRK7KJ4O.js → chunk-6UU43MF5.js} +5 -3
  12. package/dist/chunk-6UU43MF5.js.map +1 -0
  13. package/dist/{chunk-LBIRQHX5.js → chunk-AROIP4EQ.js} +3 -3
  14. package/dist/chunk-AROIP4EQ.js.map +1 -0
  15. package/dist/{chunk-QJMF73M5.js → chunk-H2QGFDZP.js} +9 -11
  16. package/dist/chunk-H2QGFDZP.js.map +1 -0
  17. package/dist/{chunk-YJX3JJ4M.js → chunk-IOLKGV45.js} +3 -3
  18. package/dist/chunk-IOLKGV45.js.map +1 -0
  19. package/dist/{chunk-MIXOZU2S.js → chunk-VFBQVUL4.js} +2 -2
  20. package/dist/{chunk-UZNSYATZ.js → chunk-WL7XUYPH.js} +25 -26
  21. package/dist/chunk-WL7XUYPH.js.map +1 -0
  22. package/dist/{chunk-KMBMQIZ7.js → chunk-ZSMI63N3.js} +109 -37
  23. package/dist/chunk-ZSMI63N3.js.map +1 -0
  24. package/dist/client-REDY6K7J.js +14 -0
  25. package/dist/{completion-ZZGX5BQC.js → completion-MXTJYK3D.js} +4 -4
  26. package/dist/{config-XJL5TSYK.js → config-TIJXUJ5N.js} +32 -23
  27. package/dist/config-TIJXUJ5N.js.map +1 -0
  28. package/dist/{config-store-3ZSYGXMQ.js → config-store-INJY4DDT.js} +6 -4
  29. package/dist/{docs-MDKKSJDC.js → docs-M5RZAQ6P.js} +5 -5
  30. package/dist/{eoa-IQ72EIHR.js → eoa-N55DYIN3.js} +18 -16
  31. package/dist/eoa-N55DYIN3.js.map +1 -0
  32. package/dist/{errors-WMZIEGQI.js → errors-SMR7X5DU.js} +2 -2
  33. package/dist/{explain-H4EH3KH3.js → explain-HIDEZVLV.js} +32 -9
  34. package/dist/explain-HIDEZVLV.js.map +1 -0
  35. package/dist/{global-options-XOLJUPTT.js → global-options-YONBFB7N.js} +4 -4
  36. package/dist/{health-VZEIII74.js → health-LSJKP3NH.js} +10 -10
  37. package/dist/health-LSJKP3NH.js.map +1 -0
  38. package/dist/index.js +31 -28
  39. package/dist/index.js.map +1 -1
  40. package/dist/{markets-C37JZDPE.js → markets-AGL6Q2ES.js} +23 -12
  41. package/dist/markets-AGL6Q2ES.js.map +1 -0
  42. package/dist/{output-VCBZ3FM7.js → output-M4NFSWGW.js} +4 -4
  43. package/dist/{portfolio-2AEPIJIG.js → portfolio-RBRVUEYP.js} +11 -11
  44. package/dist/{portfolio-2AEPIJIG.js.map → portfolio-RBRVUEYP.js.map} +1 -1
  45. package/dist/{protocol-XEQXF2GW.js → protocol-WYQAKN6N.js} +18 -16
  46. package/dist/protocol-WYQAKN6N.js.map +1 -0
  47. package/dist/{quote-I4DVJ7ZB.js → quote-6CNHU36A.js} +10 -10
  48. package/dist/redeem-JESSTZ46.js +108 -0
  49. package/dist/redeem-JESSTZ46.js.map +1 -0
  50. package/dist/{schema-PIFQ65TS.js → schema-6EXADLRW.js} +12 -8
  51. package/dist/{schema-PIFQ65TS.js.map → schema-6EXADLRW.js.map} +1 -1
  52. package/dist/{setup-USZ6IODD.js → setup-H46GTSVW.js} +12 -12
  53. package/dist/setup-H46GTSVW.js.map +1 -0
  54. package/dist/{trace-IZBYTUFO.js → trace-VDBWWTYL.js} +10 -10
  55. package/dist/{trade-IIZSEXEI.js → trade-FTSY23QG.js} +10 -10
  56. package/dist/trade-FTSY23QG.js.map +1 -0
  57. package/dist/{version-JDK3PEP5.js → version-JTLF3464.js} +7 -7
  58. package/dist/{version-check-TDCION37.js → version-check-7JGBY6FZ.js} +4 -4
  59. package/dist/{webhooks-PTVRKICZ.js → webhooks-JEWNX5HZ.js} +10 -10
  60. package/dist/{webhooks-PTVRKICZ.js.map → webhooks-JEWNX5HZ.js.map} +1 -1
  61. package/dist/{with-retry-4FIZG3A7.js → with-retry-DYSHNLG7.js} +12 -6
  62. package/dist/with-retry-DYSHNLG7.js.map +1 -0
  63. package/package.json +5 -5
  64. package/dist/auth-GUJCVKTD.js.map +0 -1
  65. package/dist/chunk-BN2CUM42.js +0 -9
  66. package/dist/chunk-BRK7KJ4O.js.map +0 -1
  67. package/dist/chunk-KMBMQIZ7.js.map +0 -1
  68. package/dist/chunk-LBIRQHX5.js.map +0 -1
  69. package/dist/chunk-QJMF73M5.js.map +0 -1
  70. package/dist/chunk-UZNSYATZ.js.map +0 -1
  71. package/dist/chunk-YHCG2SUC.js.map +0 -1
  72. package/dist/chunk-YJX3JJ4M.js.map +0 -1
  73. package/dist/client-IOM55ZCS.js +0 -14
  74. package/dist/config-XJL5TSYK.js.map +0 -1
  75. package/dist/eoa-IQ72EIHR.js.map +0 -1
  76. package/dist/explain-H4EH3KH3.js.map +0 -1
  77. package/dist/health-VZEIII74.js.map +0 -1
  78. package/dist/markets-C37JZDPE.js.map +0 -1
  79. package/dist/protocol-XEQXF2GW.js.map +0 -1
  80. package/dist/setup-USZ6IODD.js.map +0 -1
  81. package/dist/trade-IIZSEXEI.js.map +0 -1
  82. package/dist/with-retry-4FIZG3A7.js.map +0 -1
  83. /package/dist/{account-AVFLEM5D.js.map → account-QHPOIZ6I.js.map} +0 -0
  84. /package/dist/{chunk-VIADBYFY.js.map → chunk-2HFKULGG.js.map} +0 -0
  85. /package/dist/{chunk-MIXOZU2S.js.map → chunk-VFBQVUL4.js.map} +0 -0
  86. /package/dist/{client-IOM55ZCS.js.map → client-REDY6K7J.js.map} +0 -0
  87. /package/dist/{completion-ZZGX5BQC.js.map → completion-MXTJYK3D.js.map} +0 -0
  88. /package/dist/{config-store-3ZSYGXMQ.js.map → config-store-INJY4DDT.js.map} +0 -0
  89. /package/dist/{docs-MDKKSJDC.js.map → docs-M5RZAQ6P.js.map} +0 -0
  90. /package/dist/{errors-WMZIEGQI.js.map → errors-SMR7X5DU.js.map} +0 -0
  91. /package/dist/{global-options-XOLJUPTT.js.map → global-options-YONBFB7N.js.map} +0 -0
  92. /package/dist/{output-VCBZ3FM7.js.map → output-M4NFSWGW.js.map} +0 -0
  93. /package/dist/{quote-I4DVJ7ZB.js.map → quote-6CNHU36A.js.map} +0 -0
  94. /package/dist/{trace-IZBYTUFO.js.map → trace-VDBWWTYL.js.map} +0 -0
  95. /package/dist/{version-JDK3PEP5.js.map → version-JTLF3464.js.map} +0 -0
  96. /package/dist/{version-check-TDCION37.js.map → version-check-7JGBY6FZ.js.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils/config-store.ts"],"sourcesContent":["/**\n * Persistent CLI configuration with multi-profile support.\n *\n * The on-disk shape (v1+):\n *\n * {\n * \"version\": 1,\n * \"currentProfile\": \"default\",\n * \"profiles\": {\n * \"default\": { \"apiKey\": \"kash_live_…\", \"baseUrl\": \"…\", \"defaultChainId\": 8453 },\n * \"test\": { \"apiKey\": \"kash_test_…\" }\n * }\n * }\n *\n * Flat-shape configs from earlier CLI versions are migrated transparently\n * on first read into a `default` profile. The on-disk file is rewritten\n * in the new shape only on the next write — readers don't mutate state.\n *\n * The file is created and re-written at mode `0600` on POSIX. The\n * directory is created with `0700`. chmod is best-effort — Windows and\n * some network filesystems silently ignore it.\n *\n * Resolution order (highest precedence first):\n *\n * 1. Environment variables: `KASH_API_KEY`, `KASH_BASE_URL`,\n * `KASH_CHAIN_ID`. Always win.\n * 2. The active profile's fields.\n * 3. Built-in defaults (api.kash.bot/v1, chain 8453).\n *\n * Active-profile resolution (highest precedence first):\n *\n * 1. Explicit `--profile <name>` flag (via `options.profile`).\n * 2. `KASH_PROFILE` env var.\n * 3. `currentProfile` field in the config file.\n * 4. `'default'`.\n *\n * Pinning env-var precedence makes CI runs predictable and lets a\n * human override a profile field without editing the file.\n */\n\nimport { existsSync } from 'node:fs';\nimport { chmod, mkdir, readFile, unlink, writeFile } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { dirname, join } from 'node:path';\n\nimport { z } from 'zod';\n\nimport { CliConfigurationError } from '../errors.js';\n\nimport { HEX_ADDRESS_REGEX } from './trade-input.js';\n\n/**\n * Return a shallow copy of `obj` without the named property. Cleaner\n * than the `const { [k]: _removed, ...rest } = obj` rest-spread idiom\n * because it avoids the unused-variable lint dance.\n */\nfunction omitKey<T extends Record<string, unknown>, K extends keyof T>(obj: T, key: K): Omit<T, K> {\n const result: Record<string, unknown> = {};\n for (const k of Object.keys(obj)) {\n if (k !== key) result[k] = obj[k];\n }\n return result as Omit<T, K>;\n}\n\n/** Filesystem layout for the config — exposed for tests to override `home`. */\nexport type ConfigPaths = {\n readonly home: string;\n readonly dir: string;\n readonly file: string;\n};\n\nexport function resolveConfigPaths(home: string = homedir()): ConfigPaths {\n const dir = join(home, '.kash');\n return { home, dir, file: join(dir, 'config.json') };\n}\n\n/**\n * Resolve config paths with an optional explicit override path\n * (typically from the `--config` flag or `KASH_CONFIG` env var). The\n * explicit override sets the file directly and derives `dir`/`home`\n * from it for chmod-on-write.\n */\nexport function resolveConfigPathsForOverride(\n override: string | undefined,\n envOverride: string | undefined = process.env['KASH_CONFIG']\n): ConfigPaths {\n const explicit = override ?? envOverride;\n if (explicit) {\n const dir = dirname(explicit);\n return { home: dirname(dir), dir, file: explicit };\n }\n return resolveConfigPaths();\n}\n\nexport const DEFAULT_PROFILE = 'default';\n\n/**\n * Profile-name reserved words. Even though the regex below already\n * blocks the most-dangerous shapes (no `[`, no `<`, no whitespace),\n * the `__proto__` / `constructor` / `prototype` strings ARE allowed\n * by `[A-Za-z0-9_.-]+` — and using them as keys on a plain object\n * (`file.profiles`) walks the prototype chain on read. The denylist\n * makes the prototype-walk impossible at the schema layer.\n *\n * Defence-in-depth: the file format already uses `Object.create(null)`\n * boundaries downstream where possible, but pinning the validator\n * here makes the invariant grep-discoverable.\n */\nconst RESERVED_PROFILE_NAMES = new Set(['__proto__', 'constructor', 'prototype']);\n\n/** Profile name validator — keeps file structure deterministic. */\nconst profileNameSchema = z\n .string()\n .min(1, 'profile name cannot be empty')\n .max(64, 'profile name must be ≤ 64 characters')\n .regex(/^[A-Za-z0-9_.-]+$/, 'profile name allows letters, digits, underscore, dot, and dash only')\n .refine((name) => !RESERVED_PROFILE_NAMES.has(name), {\n message:\n 'profile name uses a reserved word (__proto__, constructor, prototype) — would walk the object prototype chain',\n });\n\n/**\n * Schema for a single profile. Every field is optional so the profile\n * can hold partial state — e.g. only override `baseUrl` while\n * inheriting the API key from env.\n */\n/**\n * Reference to a private key the CLI will load when constructing the\n * direct-mode signer. We never persist the raw key — only a reference\n * to where to read it from at invocation time:\n *\n * - `file:<path>` — read the key from a file (mode 0600 enforced\n * at read time, not write).\n * - `env:<name>` — read the key from an environment variable.\n *\n * This keeps `~/.kash/config.json` free of secret material; the\n * config file itself is only `0600`-protected for the API key, not\n * for arbitrary private keys that could fund-drain a smart account.\n *\n * Future extensions: `keystore:<path>`, `aws-kms:<key-id>`,\n * `gcp-kms:<resource>`, `ledger:<derivation-path>`.\n */\nconst signerKeyRefSchema = z\n .string()\n .regex(/^(file:|env:)\\S+$/, 'signerKeyRef must start with \"file:<path>\" or \"env:<NAME>\"');\n\n/** Bundler provider preset. */\nconst bundlerProviderSchema = z.enum(['flashbots', 'pimlico', 'alchemy', 'generic']);\n\nconst hexAddressSchema = z\n .string()\n .regex(HEX_ADDRESS_REGEX, 'must be a 0x-prefixed 40-char hex address');\n\n/**\n * Custom-chain config — bypasses the protocol-sdk's static chain\n * registry. Required for any chain Kash hasn't deployed canonical\n * contracts on (local Anvil, Hardhat, Tenderly forks, sidechains).\n *\n * The CLI derives the `viemChain` argument the SDK needs from the\n * profile's `defaultChainId` + `rpcUrl` + `customChain.name`; the\n * consumer never has to hand-construct a viem Chain. `addresses`\n * mirrors the SDK's `CustomChainAddresses`. `smartAccount` is required\n * only when the consumer is using SA mode (`kash protocol …`) on a\n * custom chain — EOA mode ignores it.\n */\n/**\n * Custom-chain schema. Every field is optional at the persistence\n * layer because `kash config set customChain.<leaf>` writes one leaf\n * at a time — requiring the full shape at write time would force the\n * user into a single mega-set call. Completeness (name +\n * factoryAddress + usdcAddress required, smartAccount triple all-or-\n * nothing) is enforced at use time in `resolveCliCustomChain`,\n * where the missing field has actionable error context (the SDK call\n * that needs it).\n */\nconst customChainSchema = z\n .object({\n /** Human-readable label, surfaced on `client.addresses.name`. */\n name: z.string().min(1, 'customChain.name must not be empty').optional(),\n factoryAddress: hexAddressSchema.optional(),\n usdcAddress: hexAddressSchema.optional(),\n oracleAddress: hexAddressSchema.optional(),\n vaultAddress: hexAddressSchema.optional(),\n tokens1155Address: hexAddressSchema.optional(),\n paramRegistryAddress: hexAddressSchema.optional(),\n /** Smart-account factory + EntryPoint config (SA mode only). */\n smartAccount: z\n .object({\n factoryAddress: hexAddressSchema.optional(),\n implementationAddress: hexAddressSchema.optional(),\n entryPointAddress: hexAddressSchema.optional(),\n })\n .strict()\n .optional(),\n })\n .strict();\n\nexport const cliConfigSchema = z\n .object({\n // ── Kash-orchestrated mode (API-backed) ─────────────────────────────\n apiKey: z\n .string()\n .startsWith('kash_', 'API keys start with \"kash_\"')\n .min(16, 'API key looks too short')\n .optional(),\n baseUrl: z.string().url('baseUrl must be a valid URL').optional(),\n defaultChainId: z.number().int().positive().optional(),\n\n // ── Direct mode (`kash protocol …`, on-chain) ───────────────\n /** RPC endpoint for the chain. Consumer-owned; the CLI never proxies. */\n rpcUrl: z.string().url('rpcUrl must be a valid URL').optional(),\n /** Smart account address (the ERC-4337 account whose funds are used). */\n smartAccount: z\n .string()\n .regex(HEX_ADDRESS_REGEX, 'smartAccount must be a 0x-prefixed 40-char hex address')\n .optional(),\n /** Bundler URL (overrides the protocol-sdk's Flashbots Protect default). */\n bundlerUrl: z.string().url('bundlerUrl must be a valid URL').optional(),\n /** Bundler provider preset (selects the right header dialect). */\n bundlerProvider: bundlerProviderSchema.optional(),\n /** Reference to the EOA private key that owns the smart account. */\n signerKeyRef: signerKeyRefSchema.optional(),\n /**\n * Custom-chain addresses for chains outside the static registry\n * (local Anvil, forks, sidechains). When present, the CLI's\n * direct-mode and EOA-mode commands use these addresses instead\n * of looking the chain up in the registry. Required for chainId\n * 31337 (Anvil); optional for Base mainnet/testnet (registry covers them).\n */\n customChain: customChainSchema.optional(),\n })\n .strict();\n\nexport type CliConfig = z.infer<typeof cliConfigSchema>;\n\n/**\n * Schema for the v1 multi-profile file shape.\n *\n * `currentProfile` is intentionally optional (no `.default()`) so the\n * source-attribution logic in `pickProfileName` can distinguish\n * \"user explicitly persisted `default` via `kash config use default`\"\n * (source: 'file') from \"we fell through to the built-in default\n * because the file didn't carry a `currentProfile` field\" (source:\n * 'default'). Both result in `'default'` as the active profile, but\n * the source attribution they report is different.\n */\nconst cliFileSchema = z\n .object({\n version: z.literal(1),\n currentProfile: profileNameSchema.optional(),\n profiles: z.record(profileNameSchema, cliConfigSchema).default({}),\n })\n .strict();\n\nexport type CliFile = z.infer<typeof cliFileSchema>;\n\n/**\n * Canonical API base URLs by environment. The CLI auto-routes based on\n * the API-key prefix: a `kash_test_*` key targets staging, a\n * `kash_live_*` key (or no key) targets production. An explicit\n * `baseUrl` config or `KASH_BASE_URL` env var always wins so consumers\n * can target a private mirror, a local mock, or a future region.\n *\n * Mirrors the `inferBaseUrlFromApiKey()` logic in `@kashdao/sdk`'s\n * `internal/config.ts` so the CLI and the SDK route a given key to the\n * same environment without the user having to configure two places.\n */\nexport const PRODUCTION_BASE_URL = 'https://api.kash.bot/v1' as const;\nexport const STAGING_BASE_URL = 'https://api-staging.kash.bot/v1' as const;\n\n/**\n * Derive the API base URL from an API key when neither config nor env\n * sets one explicitly. Returns `undefined` if the key shape isn't\n * recognised — the caller then falls back to {@link DEFAULTS.baseUrl}.\n */\nexport function inferBaseUrlFromApiKey(apiKey: string | undefined): string | undefined {\n if (!apiKey) return undefined;\n if (apiKey.startsWith('kash_test_')) return STAGING_BASE_URL;\n if (apiKey.startsWith('kash_live_')) return PRODUCTION_BASE_URL;\n return undefined;\n}\n\n/** Default values applied when a field is missing from both file and env. */\nexport const DEFAULTS = {\n baseUrl: PRODUCTION_BASE_URL,\n defaultChainId: 8453,\n} as const;\n\nexport type ResolvedConfig = {\n // ── Kash-orchestrated fields ──────────────────────────────────────────\n readonly apiKey: string | undefined;\n readonly baseUrl: string;\n readonly defaultChainId: number;\n // ── Direct-mode fields (`kash protocol …`) ────────────────────\n readonly rpcUrl: string | undefined;\n readonly smartAccount: string | undefined;\n readonly bundlerUrl: string | undefined;\n readonly bundlerProvider: 'flashbots' | 'pimlico' | 'alchemy' | 'generic' | undefined;\n readonly signerKeyRef: string | undefined;\n /**\n * Custom-chain config — present only when the profile explicitly sets\n * `customChain.*`. Bypasses the protocol-sdk's static chain registry\n * and is required for chains the registry doesn't cover (Anvil,\n * forks, sidechains).\n */\n readonly customChain: CliConfig['customChain'];\n // ── Meta ──────────────────────────────────────────────────────\n /** Active profile name. */\n readonly profile: string;\n /** Where each non-default value came from — useful for `kash config show`. */\n readonly sources: {\n readonly apiKey: 'env' | 'file' | 'unset';\n readonly baseUrl: 'env' | 'file' | 'inferred' | 'default';\n readonly defaultChainId: 'env' | 'file' | 'default';\n readonly profile: 'flag' | 'env' | 'file' | 'default';\n readonly rpcUrl: 'env' | 'file' | 'unset';\n readonly smartAccount: 'env' | 'file' | 'unset';\n readonly bundlerUrl: 'env' | 'file' | 'unset';\n readonly bundlerProvider: 'env' | 'file' | 'unset';\n readonly signerKeyRef: 'env' | 'file' | 'unset';\n readonly customChain: 'file' | 'unset';\n };\n};\n\nexport type ReadConfigOptions = {\n /** Override which profile to read; takes precedence over env + file. */\n readonly profile?: string;\n /** Override the config file path; takes precedence over `KASH_CONFIG`. */\n readonly configPath?: string;\n};\n\n/**\n * Read the config file and return the resolved active profile merged\n * with environment variables and defaults.\n */\nexport async function readConfig(opts: ReadConfigOptions = {}): Promise<ResolvedConfig> {\n const paths = resolveConfigPathsForOverride(opts.configPath);\n const file = await readFileConfig(paths);\n return resolveActive(file, opts.profile);\n}\n\nasync function readFileConfig(paths: ConfigPaths): Promise<CliFile> {\n if (!existsSync(paths.file)) return emptyFile();\n let raw: string;\n try {\n raw = await readFile(paths.file, 'utf8');\n } catch (cause) {\n throw new CliConfigurationError(\n `Failed to read config file at ${paths.file}: ${(cause as Error).message}`,\n \"Run 'kash config reset' to start fresh.\"\n );\n }\n return parseFileContents(raw, paths.file);\n}\n\nfunction parseFileContents(raw: string, file: string): CliFile {\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (cause) {\n throw new CliConfigurationError(\n `Config file at ${file} is not valid JSON: ${(cause as Error).message}`,\n \"Run 'kash config reset' to overwrite it with defaults.\"\n );\n }\n // Guard against valid-JSON-but-wrong-top-level (e.g. someone wrote\n // a string, a number, an array, or `null` to the file). Without this,\n // the v1 schema's \"Expected object, received string\" Zod error\n // bubbles up with no actionable hint.\n if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {\n throw new CliConfigurationError(\n `Config file at ${file} must contain a JSON object at the top level (got ${describeJsonRoot(parsed)}).`,\n \"Run 'kash config reset' to overwrite it with defaults.\"\n );\n }\n const migrated = migrateLegacyShape(parsed);\n const result = cliFileSchema.safeParse(migrated);\n if (!result.success) {\n const first = result.error.issues[0];\n const path = first?.path.join('.') ?? '(root)';\n throw new CliConfigurationError(\n `Config file at ${file} is invalid (${path}): ${first?.message ?? 'validation failed'}`,\n \"Run 'kash config reset' to overwrite it with defaults.\"\n );\n }\n return result.data;\n}\n\n/** Describe a non-object JSON root for the user-facing error message. */\nfunction describeJsonRoot(value: unknown): string {\n if (value === null) return 'null';\n if (Array.isArray(value)) return 'array';\n return typeof value;\n}\n\n/**\n * If the file looks like the legacy flat shape ({ apiKey?, baseUrl?,\n * defaultChainId? } at the root), wrap it as the default profile of a\n * v1 file. Otherwise pass through.\n */\nfunction migrateLegacyShape(parsed: unknown): unknown {\n if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {\n return parsed;\n }\n const obj = parsed as Record<string, unknown>;\n if ('version' in obj || 'profiles' in obj) {\n return parsed; // already in v1 shape\n }\n // Legacy flat shape — wrap it as the default profile.\n const flat = cliConfigSchema.safeParse(obj);\n if (!flat.success) {\n return parsed; // let the v1 schema raise the structured error\n }\n return {\n version: 1,\n currentProfile: DEFAULT_PROFILE,\n profiles: { [DEFAULT_PROFILE]: flat.data },\n };\n}\n\nfunction emptyFile(): CliFile {\n return cliFileSchema.parse({ version: 1 });\n}\n\n/**\n * Compute the active profile name. Order: explicit flag > env >\n * file's `currentProfile` (when present) > built-in `'default'`.\n *\n * Crucially, when the file persists `currentProfile: \"default\"`\n * (e.g. after `kash config use default`), source is `'file'` — not\n * `'default'`. That keeps the JSON contract honest: agents debugging\n * \"why is my profile X?\" need to know it came from a write, not a\n * fallback.\n */\nfunction pickProfileName(\n file: CliFile,\n flagOverride: string | undefined\n): { name: string; source: 'flag' | 'env' | 'file' | 'default' } {\n if (flagOverride !== undefined) {\n validateProfileName(flagOverride, '--profile flag');\n return { name: flagOverride, source: 'flag' };\n }\n const env = process.env['KASH_PROFILE'];\n if (env !== undefined && env.length > 0) {\n validateProfileName(env, 'KASH_PROFILE environment variable');\n return { name: env, source: 'env' };\n }\n if (file.currentProfile !== undefined) {\n return { name: file.currentProfile, source: 'file' };\n }\n return { name: DEFAULT_PROFILE, source: 'default' };\n}\n\n/**\n * Wrap `profileNameSchema.parse` so a malformed value surfaces as a\n * typed `CliConfigurationError` with a `check_input`-friendly\n * suggestion, instead of a raw `ZodError` that the top-level\n * boundary maps to `UNEXPECTED`.\n */\nfunction validateProfileName(value: string, source: string): void {\n const result = profileNameSchema.safeParse(value);\n if (!result.success) {\n const issue = result.error.issues[0];\n throw new CliConfigurationError(\n `Profile name from ${source} is invalid: ${issue?.message ?? 'validation failed'}.`,\n 'Profile names accept letters, digits, underscore, dot, and dash; must be 1-64 characters.'\n );\n }\n}\n\nfunction resolveActive(file: CliFile, flagOverride: string | undefined): ResolvedConfig {\n const { name: profileName, source: profileSource } = pickProfileName(file, flagOverride);\n const profile = file.profiles[profileName];\n // It's not an error to ask for a profile that isn't in the file —\n // env-only setups (CI, agents) are normal. We surface this via the\n // `sources.apiKey === 'unset'` value if no env var fills the gap.\n //\n // BUT: when the missing profile was named via `KASH_PROFILE` or\n // `--profile`, an intentional env-only setup is the rare case and\n // a typo (e.g. `KASH_PROFILE=staing` vs `staging`) is the common\n // case. The operator otherwise sees an empty config + a confusing\n // `AUTH_REQUIRED` later. Nudge them on stderr (no JSON pollution,\n // no behaviour change). `KASH_QUIET=1` mutes the warning for CI.\n if (\n profile === undefined &&\n (profileSource === 'env' || profileSource === 'flag') &&\n Object.keys(file.profiles).length > 0 &&\n !isTruthyEnv(process.env['KASH_QUIET'])\n ) {\n const known = Object.keys(file.profiles).sort().join(', ');\n const sourceLabel = profileSource === 'env' ? 'KASH_PROFILE' : '--profile';\n process.stderr.write(\n `\\u26a0 Profile \"${profileName}\" (${sourceLabel}) is not in the config file. ` +\n `Known profiles: ${known}. ` +\n `Did you typo the name? (Set KASH_QUIET=1 to mute this warning.)\\n`\n );\n }\n return mergeWithEnv(profile ?? {}, profileName, profileSource);\n}\n\n/** Same truthy-env recognizer as `utils/global-options.ts:isTruthyEnv`. */\nfunction isTruthyEnv(value: string | undefined): boolean {\n if (value === undefined) return false;\n const v = value.trim().toLowerCase();\n return v === '1' || v === 'true' || v === 'yes' || v === 'on';\n}\n\nfunction mergeWithEnv(\n profile: CliConfig,\n profileName: string,\n profileSource: 'flag' | 'env' | 'file' | 'default'\n): ResolvedConfig {\n const envApiKey = process.env['KASH_API_KEY'];\n const envBaseUrl = process.env['KASH_BASE_URL'];\n const envChainIdRaw = process.env['KASH_CHAIN_ID'];\n // Direct-mode env vars\n const envRpcUrl = process.env['KASH_RPC_URL'];\n const envSmartAccount = process.env['KASH_SMART_ACCOUNT'];\n const envBundlerUrl = process.env['KASH_BUNDLER_URL'];\n const envBundlerProviderRaw = process.env['KASH_BUNDLER_PROVIDER'];\n const envSignerKeyRef = process.env['KASH_SIGNER_KEY_REF'];\n\n let envChainId: number | undefined;\n if (envChainIdRaw !== undefined) {\n const n = Number.parseInt(envChainIdRaw, 10);\n if (Number.isNaN(n) || n <= 0) {\n throw new CliConfigurationError(\n `KASH_CHAIN_ID is not a positive integer: ${envChainIdRaw}`,\n 'Set KASH_CHAIN_ID to a chain id like 8453 or 84532, or unset it to use the default.'\n );\n }\n envChainId = n;\n }\n\n let envBundlerProvider: ResolvedConfig['bundlerProvider'];\n if (envBundlerProviderRaw !== undefined) {\n const allowed = ['flashbots', 'pimlico', 'alchemy', 'generic'] as const;\n if (!(allowed as readonly string[]).includes(envBundlerProviderRaw)) {\n throw new CliConfigurationError(\n `KASH_BUNDLER_PROVIDER must be one of ${allowed.join(', ')} (got \"${envBundlerProviderRaw}\").`,\n 'Unset the variable or set it to a supported preset.'\n );\n }\n envBundlerProvider = envBundlerProviderRaw as ResolvedConfig['bundlerProvider'];\n }\n\n const apiKey = envApiKey ?? profile.apiKey;\n // Resolution order for `baseUrl`:\n // 1. KASH_BASE_URL env var — always wins\n // 2. profile.baseUrl — explicit profile config\n // 3. inferred from apiKey prefix — kash_test_* → staging, kash_live_* → production\n // 4. DEFAULTS.baseUrl — production (final fallback)\n //\n // Step 3 mirrors `@kashdao/sdk`'s `inferBaseUrlFromApiKey()` so the\n // CLI and the SDK route the same key to the same environment without\n // requiring the user to configure two places. Without this, a user\n // with only a `kash_test_*` key would hit production (and a DNS error\n // pre-launch) until they remembered to also set `--base-url`.\n const baseUrl =\n envBaseUrl ?? profile.baseUrl ?? inferBaseUrlFromApiKey(apiKey) ?? DEFAULTS.baseUrl;\n const defaultChainId = envChainId ?? profile.defaultChainId ?? DEFAULTS.defaultChainId;\n const rpcUrl = envRpcUrl ?? profile.rpcUrl;\n const smartAccount = envSmartAccount ?? profile.smartAccount;\n const bundlerUrl = envBundlerUrl ?? profile.bundlerUrl;\n const bundlerProvider = envBundlerProvider ?? profile.bundlerProvider;\n const signerKeyRef = envSignerKeyRef ?? profile.signerKeyRef;\n // customChain has no env-var override — it's a structured object,\n // not a single string, and the right place to set it is `kash\n // config set customChain.<leaf>` so partial sets compose. CI use\n // cases that need a custom chain mount the config file directly\n // (KASH_CONFIG=...).\n const customChain = profile.customChain;\n\n return {\n apiKey,\n baseUrl,\n defaultChainId,\n rpcUrl,\n smartAccount,\n bundlerUrl,\n bundlerProvider,\n signerKeyRef,\n customChain,\n profile: profileName,\n sources: {\n apiKey: envApiKey ? 'env' : profile.apiKey ? 'file' : 'unset',\n baseUrl: envBaseUrl\n ? 'env'\n : profile.baseUrl\n ? 'file'\n : inferBaseUrlFromApiKey(apiKey)\n ? 'inferred'\n : 'default',\n defaultChainId:\n envChainId !== undefined\n ? 'env'\n : profile.defaultChainId !== undefined\n ? 'file'\n : 'default',\n profile: profileSource,\n rpcUrl: envRpcUrl ? 'env' : profile.rpcUrl ? 'file' : 'unset',\n smartAccount: envSmartAccount ? 'env' : profile.smartAccount ? 'file' : 'unset',\n bundlerUrl: envBundlerUrl ? 'env' : profile.bundlerUrl ? 'file' : 'unset',\n bundlerProvider: envBundlerProvider ? 'env' : profile.bundlerProvider ? 'file' : 'unset',\n signerKeyRef: envSignerKeyRef ? 'env' : profile.signerKeyRef ? 'file' : 'unset',\n customChain: profile.customChain ? 'file' : 'unset',\n },\n };\n}\n\nexport type WriteConfigOptions = {\n /** Profile to write to. Defaults to the current active profile. */\n readonly profile?: string;\n /** Override the config file path. */\n readonly configPath?: string;\n};\n\n/**\n * Result of {@link updateConfig} / {@link clearConfigField}. Carries\n * the resolved profile name so callers can render an accurate\n * \"wrote to profile X\" message instead of guessing — important for\n * the JSON contract that `kash auth set-key --json` ships, since\n * `--profile` may be unset and we want to report the actually-written\n * profile (which falls back to the file's `currentProfile`).\n */\nexport type UpdateConfigResult = {\n readonly profile: string;\n readonly stored: CliConfig;\n};\n\n/**\n * Mutate (and persist) a single field of the active (or named) profile.\n * Used by `auth set-key`, `auth logout`, `config set`. Writes the file\n * with `0600` permissions.\n */\nexport async function updateConfig(\n patch: Partial<CliConfig>,\n opts: WriteConfigOptions = {}\n): Promise<UpdateConfigResult> {\n const paths = resolveConfigPathsForOverride(opts.configPath);\n const file = await readFileConfig(paths);\n const profileName = opts.profile ?? file.currentProfile ?? DEFAULT_PROFILE;\n profileNameSchema.parse(profileName);\n const current = file.profiles[profileName] ?? {};\n const next = cliConfigSchema.parse({ ...current, ...patch });\n const updated: CliFile = {\n ...file,\n profiles: { ...file.profiles, [profileName]: next },\n };\n await writeFileConfig(paths, updated);\n return { profile: profileName, stored: next };\n}\n\n/** Wipe a single field from a profile (used by `auth logout`). */\nexport async function clearConfigField(\n field: keyof CliConfig,\n opts: WriteConfigOptions = {}\n): Promise<UpdateConfigResult> {\n const paths = resolveConfigPathsForOverride(opts.configPath);\n const file = await readFileConfig(paths);\n const profileName = opts.profile ?? file.currentProfile ?? DEFAULT_PROFILE;\n const current = file.profiles[profileName] ?? {};\n if (!(field in current)) return { profile: profileName, stored: current };\n const next = cliConfigSchema.parse(omitKey(current, field));\n const updated: CliFile = {\n ...file,\n profiles: { ...file.profiles, [profileName]: next },\n };\n await writeFileConfig(paths, updated);\n return { profile: profileName, stored: next };\n}\n\n/** List every profile name present in the config file. */\nexport async function listProfiles(\n opts: { configPath?: string } = {}\n): Promise<{ readonly current: string; readonly profiles: readonly string[] }> {\n const paths = resolveConfigPathsForOverride(opts.configPath);\n const file = await readFileConfig(paths);\n return {\n current: file.currentProfile ?? DEFAULT_PROFILE,\n profiles: Object.keys(file.profiles).sort(),\n };\n}\n\n/** Set the file's `currentProfile` field. Validates the name. */\nexport async function setCurrentProfile(\n name: string,\n opts: { configPath?: string } = {}\n): Promise<CliFile> {\n profileNameSchema.parse(name);\n const paths = resolveConfigPathsForOverride(opts.configPath);\n const file = await readFileConfig(paths);\n const updated: CliFile = { ...file, currentProfile: name };\n await writeFileConfig(paths, updated);\n return updated;\n}\n\n/** Remove a named profile. Refuses to remove the active one. */\nexport async function deleteProfile(\n name: string,\n opts: { configPath?: string } = {}\n): Promise<CliFile> {\n profileNameSchema.parse(name);\n const paths = resolveConfigPathsForOverride(opts.configPath);\n const file = await readFileConfig(paths);\n if (file.currentProfile === name) {\n throw new CliConfigurationError(\n `Cannot delete the active profile \"${name}\".`,\n 'Switch to another profile first with `kash config use <name>`.'\n );\n }\n if (!(name in file.profiles)) {\n return file;\n }\n const updated: CliFile = { ...file, profiles: omitKey(file.profiles, name) };\n await writeFileConfig(paths, updated);\n return updated;\n}\n\n/** Delete the entire config file. Used by `config reset`. */\nexport async function deleteConfig(opts: { configPath?: string } = {}): Promise<void> {\n const paths = resolveConfigPathsForOverride(opts.configPath);\n if (!existsSync(paths.file)) return;\n await unlink(paths.file);\n}\n\n/**\n * Return the full multi-profile file as-is. Used by `kash config\n * export` to dump every profile (vs `readConfig` which resolves a\n * single active profile). When the file doesn't exist, returns an\n * empty file shape so callers don't have to special-case \"no config\n * yet\".\n */\nexport async function readWholeFile(opts: { configPath?: string } = {}): Promise<CliFile> {\n const paths = resolveConfigPathsForOverride(opts.configPath);\n return await readFileConfig(paths);\n}\n\n/**\n * Replace the entire on-disk file with the supplied shape. Used by\n * `kash config import`. Validates against the `cliFileSchema` to\n * prevent garbage from landing on disk.\n *\n * Caller-side concerns (merge vs. overwrite, redaction policy, etc.)\n * are handled in the import command — this helper is pure persistence.\n */\nexport async function writeWholeFile(\n file: CliFile,\n opts: { configPath?: string } = {}\n): Promise<void> {\n const paths = resolveConfigPathsForOverride(opts.configPath);\n const validated = cliFileSchema.parse(file);\n await writeFileConfig(paths, validated);\n}\n\n/** Public re-export of the file-level schema for the import command. */\nexport { cliFileSchema };\n\nasync function writeFileConfig(paths: ConfigPaths, file: CliFile): Promise<void> {\n await ensureDir(paths.dir);\n // Use writeFile + chmod rather than writeFile({mode}) because the\n // mode flag only takes effect on first creation; rewrites would\n // keep the old (potentially looser) permissions.\n await writeFile(paths.file, JSON.stringify(file, null, 2), 'utf8');\n await chmodSafe(paths.file, 0o600);\n}\n\nasync function ensureDir(dir: string): Promise<void> {\n await mkdir(dir, { recursive: true, mode: 0o700 });\n await chmodSafe(dir, 0o700);\n}\n\nasync function chmodSafe(target: string, mode: number | undefined): Promise<void> {\n if (mode === undefined) return;\n if (process.platform === 'win32') return;\n try {\n await chmod(target, mode);\n } catch {\n // chmod can fail on some filesystems (e.g. mounted FAT volumes,\n // network shares). Treat as best-effort — the user's data still\n // landed, we just couldn't tighten perms.\n }\n}\n"],"mappings":";;;;;;;;;AAwCA,SAAS,kBAAkB;AAC3B,SAAS,OAAO,OAAO,UAAU,QAAQ,iBAAiB;AAC1D,SAAS,eAAe;AACxB,SAAS,SAAS,YAAY;AAE9B,SAAS,SAAS;AAWlB,SAAS,QAA8D,KAAQ,KAAoB;AACjG,QAAM,SAAkC,CAAC;AACzC,aAAW,KAAK,OAAO,KAAK,GAAG,GAAG;AAChC,QAAI,MAAM,IAAK,QAAO,CAAC,IAAI,IAAI,CAAC;AAAA,EAClC;AACA,SAAO;AACT;AASO,SAAS,mBAAmB,OAAe,QAAQ,GAAgB;AACxE,QAAM,MAAM,KAAK,MAAM,OAAO;AAC9B,SAAO,EAAE,MAAM,KAAK,MAAM,KAAK,KAAK,aAAa,EAAE;AACrD;AAQO,SAAS,8BACd,UACA,cAAkC,QAAQ,IAAI,aAAa,GAC9C;AACb,QAAM,WAAW,YAAY;AAC7B,MAAI,UAAU;AACZ,UAA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M,KAAK,UAAU,MAAM,MAAM,CAAC,GAAG,MAAM;AACjE,QAAM,UAAU,MAAM,MAAM,GAAK;AACnC;AAEA,eAAe,UAAU,KAA4B;AACnD,QAAM,MAAM,KAAK,EAAE,WAAW,MAAM,MAAM,IAAM,CAAC;AACjD,QAAM,UAAU,KAAK,GAAK;AAC5B;AAEA,eAAe,UAAU,QAAgB,MAAyC;AAChF,MAAI,SAAS,OAAW;AACxB,MAAI,QAAQ,aAAa,QAAS;AAClC,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AAAA,EAC1B,QAAQ;AAAA,EAIR;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils/global-options.ts"],"sourcesContent":["/**\n * Global option resolution.\n *\n * Commander 13 makes the root program's options available on every\n * subcommand via `cmd.optsWithGlobals()`. This helper centralises the\n * shape so command modules type their access to it once.\n *\n * The flags fall into three buckets:\n *\n * 1. **Output controls** — `--json`, `--quiet`, `--no-color`, `--debug`.\n * Drive how output and traces are rendered.\n * 2. **Config selection** — `--profile`, `--config`. Decide which\n * credentials get loaded.\n * 3. **SDK overrides** — `--base-url`, `--max-retries`, `--timeout-ms`.\n * Per-invocation overrides for the SDK config; useful for CI\n * matrix builds and ad-hoc staging tests.\n */\n\nimport { CliValidationError } from '../errors.js';\n\nimport { parseFieldsList } from './fields.js';\nimport { parseFilter, type FilterAst } from './filter.js';\n\nimport type { Command } from 'commander';\n\nexport type GlobalOptions = {\n /** `--json` — emit machine-readable JSON instead of human output. */\n readonly json: boolean;\n /** `--quiet` — suppress informational human-mode output. */\n readonly quiet: boolean;\n /** `--no-color` — disable ANSI escapes (also honors `NO_COLOR`). */\n readonly noColor: boolean;\n /** `--debug` — emit SDK lifecycle traces (request/response/retry/error) to stderr. */\n readonly debug: boolean;\n /** `--profile <name>` — pick a named profile from `~/.kash/config.json`. */\n readonly profile: string | undefined;\n /** `--config <path>` — explicit config file path; overrides default + env. */\n readonly configPath: string | undefined;\n /** `--base-url <url>` — override the API base URL for this invocation. */\n readonly baseUrl: string | undefined;\n /** `--max-retries <n>` — override SDK retry budget for this invocation. */\n readonly maxRetries: number | undefined;\n /** `--timeout-ms <n>` — override SDK request timeout for this invocation. */\n readonly timeoutMs: number | undefined;\n /**\n * `--api-version <date>` — pin against a public-API contract date.\n * The value is sent as `X-Kash-Api-Version` on every request. The\n * server runs a version-appropriate code path; sending an\n * unrecognised date returns `410 API_VERSION_UNSUPPORTED`. Omit\n * (or `undefined`) → server uses its canonical `PUBLIC_API_VERSION`.\n */\n readonly apiVersion: string | undefined;\n /**\n * `--fields <list>` — gh-style projection on `--json` output. Parsed\n * into dot-segmented paths; `undefined` when the flag was not passed\n * (commands then emit the full payload).\n */\n readonly fields: ReadonlyArray<readonly string[]> | undefined;\n /**\n * `--filter <expr>` — boolean DSL applied before `--fields`\n * projection. Filters list/get-style payloads to entries matching\n * the predicate. `undefined` when the flag was not passed.\n */\n readonly filter: FilterAst | undefined;\n};\n\ntype RawGlobalOptions = {\n json?: boolean;\n quiet?: boolean;\n // Commander stores `--no-color` as `{ color: false }` — the default for a\n // `--no-X` boolean is `true`, so the explicit `false` means \"disabled.\"\n color?: boolean;\n debug?: boolean;\n profile?: string;\n config?: string;\n baseUrl?: string;\n maxRetries?: string;\n timeoutMs?: string;\n apiVersion?: string;\n fields?: string;\n filter?: string;\n};\n\n/**\n * Pull the globals from the active command. Falls back to defaults\n * for any flag the user did not pass. Validates numeric inputs with\n * structured errors (so an agent gets a `INVALID_INPUT` code, not a\n * cryptic NaN cascade).\n */\nexport function readGlobals(cmd: Command): GlobalOptions {\n const opts = cmd.optsWithGlobals<RawGlobalOptions>();\n return {\n json: opts.json === true,\n quiet: opts.quiet === true,\n noColor: opts.color === false,\n // `KASH_DEBUG=1` (or any truthy value) mirrors `--debug`. Common\n // case: CI matrix configs and parent processes that can't easily\n // edit the invocation. Explicit `--debug` always wins (a user can\n // force it on even when the env says off).\n debug: opts.debug === true || isTruthyEnv(process.env['KASH_DEBUG']),\n profile: opts.profile,\n configPath: opts.config,\n baseUrl: opts.baseUrl === undefined ? undefined : parseUrl(opts.baseUrl, 'base-url'),\n maxRetries:\n opts.maxRetries === undefined\n ? undefined\n : // Cap at 10 to match the SDK's `kashClientConfigSchema`\n // (`maxRetries: z.number().int().min(0).max(10)`). Bouncing\n // out-of-range values here gives the agent an `INVALID_INPUT`\n // with a clear field, instead of a cryptic SDK\n // `KashConfigurationError` after the client tries to construct.\n parseBoundedUnsigned(opts.maxRetries, 'max-retries', 0, 10),\n timeoutMs:\n opts.timeoutMs === undefined ? undefined : parsePositive(opts.timeoutMs, 'timeout-ms'),\n // `--api-version` is forwarded to the SDK as `apiVersion`. Format\n // validation (`YYYY-MM-DD`) is enforced by the SDK's\n // `kashClientConfigSchema`. We don't pre-validate here — letting\n // the SDK be the single source of truth keeps the format rule in\n // one place. A malformed value surfaces as\n // `KashConfigurationError` from client construction, which the\n // CLI's error mapper converts to a structured envelope.\n apiVersion: opts.apiVersion,\n fields: opts.fields === undefined ? undefined : parseFieldsList(opts.fields),\n filter: opts.filter === undefined ? undefined : parseFilter(opts.filter),\n };\n}\n\nfunction parseBoundedUnsigned(raw: string, name: string, min: number, max: number): number {\n // Same strict-shape rationale as `parsePositiveInt`: reject decimals\n // and scientific notation BEFORE `parseInt`'s silent precision loss\n // (`1.5 → 1`, `1e3 → 1`). Bounded numeric flags like `--max-retries`\n // shouldn't accept either form.\n if (!/^\\+?\\d+$/.test(raw)) {\n throw new CliValidationError(\n `--${name} must be an integer between ${String(min)} and ${String(max)}.`,\n `Got \"${raw}\". Pass digits only — no decimals or scientific notation.`,\n name\n );\n }\n const n = Number.parseInt(raw, 10);\n if (!Number.isFinite(n) || n < min || n > max) {\n throw new CliValidationError(\n `--${name} must be an integer between ${String(min)} and ${String(max)}.`,\n `Got \"${raw}\".`,\n name\n );\n }\n return n;\n}\n\nfunction parseUrl(raw: string, name: string): string {\n let url: URL;\n try {\n // `new URL()` catches \"no scheme\", \"no host\", \"malformed escape\",\n // etc. — but it's permissive about the scheme. `file:`, `data:`,\n // `javascript:`, `about:` all parse cleanly. For an HTTP API\n // base URL, restricting to http/https is the right invariant\n // (defence-in-depth: even if the SDK forwards the URL to fetch\n // and refuses non-http schemes, we surface the error with a\n // clear field name).\n url = new URL(raw);\n } catch {\n throw new CliValidationError(\n `--${name} must be a valid URL.`,\n `Got \"${raw}\". Include the scheme, e.g. https://api.kash.bot/v1.`,\n name\n );\n }\n if (url.protocol !== 'http:' && url.protocol !== 'https:') {\n throw new CliValidationError(\n `--${name} must use http:// or https:// (got \"${url.protocol}\").`,\n `Schemes like file:, data:, javascript:, and about: are rejected — they would either silently fail in the SDK or open an attack vector.`,\n name\n );\n }\n return raw;\n}\n\n/**\n * Parse a CLI flag value as a strictly positive integer.\n *\n * Throws a structured `CliValidationError` (with a `check_input`\n * action naming the bad field) so an AI agent gets `INVALID_INPUT`\n * with a concrete recovery hint instead of a NaN cascade.\n *\n * Exported because every command that takes a positive-integer flag\n * (`--limit`, `--timeout`, `--poll-interval`, …) routes through it\n * — keeps validation messages and error envelopes uniform.\n */\nexport function parsePositiveInt(raw: string, name: string): number {\n // `Number.parseInt('1.5', 10)` returns 1 and `Number.parseInt('1e3', 10)`\n // returns 1 — both are silent precision losses for what looks like\n // a typo. Reject the raw shape first (bare digits only, optional\n // leading +) so the user sees an explicit error instead of a value\n // they didn't type.\n if (!/^\\+?\\d+$/.test(raw)) {\n throw new CliValidationError(\n `--${name} must be a positive integer.`,\n `Got \"${raw}\". Pass digits only — no decimals, scientific notation, or sign except a leading +.`,\n name\n );\n }\n const n = Number.parseInt(raw, 10);\n if (!Number.isFinite(n) || n <= 0) {\n throw new CliValidationError(\n `--${name} must be a positive integer.`,\n `Got \"${raw}\". Pass an integer > 0.`,\n name\n );\n }\n return n;\n}\n\n// Internal alias kept so the existing call sites in this file don't\n// need to change. New consumers should import `parsePositiveInt`.\nconst parsePositive = parsePositiveInt;\n\n/**\n * Optional variant of {@link parsePositiveInt}. Returns `undefined`\n * when the flag is absent (the common \"default to SDK behaviour\"\n * pattern); otherwise validates and returns the integer.\n *\n * Hoisted from per-command copies so flag wording, bounds, and\n * envelope shape stay uniform across `--wait-timeout-ms`,\n * `--poll-interval-ms`, etc.\n */\nexport function parseOptionalPositiveInt(\n raw: string | undefined,\n name: string\n): number | undefined {\n return raw === undefined ? undefined : parsePositiveInt(raw, name);\n}\n\n/**\n * Positive-finite-float variant of {@link parsePositiveInt}. Used by\n * gas-percentile flags and similar continuous-quantity bounds where\n * an integer-only parser would surprise operators (e.g.\n * `--max-tip-gwei 1.5`).\n */\nexport function parsePositiveFloat(raw: string, name: string): number {\n const n = Number.parseFloat(raw);\n if (!Number.isFinite(n) || n <= 0) {\n throw new CliValidationError(\n `--${name} must be a positive number.`,\n `Got \"${raw}\". Pass a finite number > 0.`,\n name\n );\n }\n return n;\n}\n\n/** Optional variant of {@link parsePositiveFloat}. */\nexport function parseOptionalPositiveFloat(\n raw: string | undefined,\n name: string\n): number | undefined {\n return raw === undefined ? undefined : parsePositiveFloat(raw, name);\n}\n\n/**\n * Recognise truthy env values the way every other tool does: `1`,\n * `true`, `yes`, `on` (case-insensitive). Empty string and `0` are\n * falsy. Anything else is a no-op rather than an error — env\n * pollution is common and shouldn't fail builds.\n */\nfunction isTruthyEnv(value: string | undefined): boolean {\n if (value === undefined) return false;\n const v = value.trim().toLowerCase();\n return v === '1' || v === 'true' || v === 'yes' || v === 'on';\n}\n"],"mappings":";;;;;;;;;;AAyFO,SAAS,YAAY,KAA6B;AACvD,QAAM,OAAO,IAAI,gBAAkC;AACnD,SAAO;AAAA,IACL,MAAM,KAAK,SAAS;AAAA,IACpB,OAAO,KAAK,UAAU;AAAA,IACtB,SAAS,KAAK,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA,IAKxB,OAAO,KAAK,UAAU,QAAQ,YAAY,QAAQ,IAAI,YAAY,CAAC;AAAA,IACnE,SAAS,KAAK;AAAA,IACd,YAAY,KAAK;AAAA,IACjB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AAAA,MACR,KAAK,IAAI,uCAAuC,IAAI,QAAQ;AAAA,MAC5D;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAaO,SAAS,iBAAiB,KAAa,MAAsB;AAMlE,MAAI,CAAC,WAAW,KAAK,GAAG,GAAG;AACzB,UAAM,IAAI;AAAA,MACR,KAAK,IAAI;AAAA,MACT,QAAQ,GAAG;AAAA,MACX;AAAA,IACF;AAAA,EACF;AACA,QAAM,IAAI,OAAO,SAAS,KAAK,EAAE;AACjC,MAAI,CAAC,OAAO,SAAS,CAAC,KAAK,KAAK,GAAG;AACjC,UAAM,IAAI;AAAA,MACR,KAAK,IAAI;AAAA,MACT,QAAQ,GAAG;AAAA,MACX;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAIA,IAAM,gBAAgB;AAWf,SAAS,yBACd,KACA,MACoB;AACpB,SAAO,QAAQ,SAAY,SAAY,iBAAiB,KAAK,IAAI;AACnE;AAQO,SAAS,mBAAmB,KAAa,MAAsB;AACpE,QAAM,IAAI,OAAO,WAAW,GAAG;AAC/B,MAAI,CAAC,OAAO,SAAS,CAAC,KAAK,KAAK,GAAG;AACjC,UAAM,IAAI;AAAA,MACR,KAAK,IAAI;AAAA,MACT,QAAQ,GAAG;AAAA,MACX;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAGO,SAAS,2BACd,KACA,MACoB;AACpB,SAAO,QAAQ,SAAY,SAAY,mBAAmB,KAAK,IAAI;AACrE;AAQA,SAAS,YAAY,OAAoC;AACvD,MAAI,UAAU,OAAW,QAAO;AAChC,QAAM,IAAI,MAAM,KAAK,EAAE,YAAY;AACnC,SAAO,MAAM,OAAO,MAAM,UAAU,MAAM,SAAS,MAAM;AAC3D;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils/client.ts"],"sourcesContent":["/**\n * Build a `KashClient` from the resolved CLI configuration plus\n * per-invocation global flag overrides.\n *\n * Centralised here so command modules don't each have to know how to\n * read config, surface \"missing API key\" errors, or thread base URLs.\n * Every command that hits `api.kash.bot` must pass `requireAuth: true`\n * so a missing API key fails fast at the call site with a structured\n * `CliError` pointing the user at `kash auth set-key`. Only the offline\n * commands (`kash explain`, `kash --version`, `kash --help`) and the\n * `kash health` probe construct a client without `requireAuth`.\n *\n * Three layers feed the final SDK config:\n *\n * 1. The active profile + env vars (resolved by config-store).\n * 2. Per-invocation `--profile` / `--config` overrides (which select\n * *which* profile and file feed step 1).\n * 3. Per-invocation `--base-url` / `--max-retries` / `--timeout-ms`\n * flags, which override the SDK's runtime config directly.\n *\n * `--debug` wires a stderr-emitting hook into the SDK's lifecycle so\n * a developer or AI agent can see request/response/retry/error\n * traces without instrumenting the SDK.\n */\n\nimport { KashClient, type KashClientHooks } from '@kashdao/sdk';\n\nimport { CliError, EXIT_CODES } from '../errors.js';\nimport { CLI_VERSION } from '../version.js';\n\nimport { readConfig, type ResolvedConfig } from './config-store.js';\nimport { style } from './output.js';\n\nimport type { GlobalOptions } from './global-options.js';\n\nexport type ClientOptions = {\n /** When true, throw `CliError` if no API key is configured. */\n readonly requireAuth?: boolean;\n /**\n * Global flags from the root program. Optional so internal callers\n * (and tests) can build a client without going through Commander.\n */\n readonly globals?: GlobalOptions;\n};\n\nexport type BuiltClient = {\n readonly client: KashClient;\n readonly config: ResolvedConfig;\n};\n\nexport async function buildClient(opts: ClientOptions = {}): Promise<BuiltClient> {\n const globals = opts.globals;\n const config = await readConfig({\n ...(globals?.profile === undefined ? {} : { profile: globals.profile }),\n ...(globals?.configPath === undefined ? {} : { configPath: globals.configPath }),\n });\n\n if (opts.requireAuth && !config.apiKey) {\n throw new CliError('No API key configured.', {\n code: 'AUTH_REQUIRED',\n exitCode: EXIT_CODES.AUTH,\n suggestion:\n \"First-time setup: run 'kash setup' (interactive wizard). Otherwise: 'kash auth set-key' or set KASH_API_KEY.\",\n });\n }\n\n // Per-invocation overrides win over the resolved profile+env config.\n const baseUrl = globals?.baseUrl ?? config.baseUrl;\n\n const client = new KashClient({\n ...(config.apiKey === undefined ? {} : { apiKey: config.apiKey }),\n baseUrl,\n ...(globals?.maxRetries === undefined ? {} : { maxRetries: globals.maxRetries }),\n ...(globals?.timeoutMs === undefined ? {} : { timeoutMs: globals.timeoutMs }),\n // Forward the public-API contract pin from `--api-version` (or\n // `KASH_API_VERSION` env, if a future iteration plumbs it). The\n // SDK validates the date format and sends the value as the\n // `X-Kash-Api-Version` request header; the public-api routes the\n // request through a version-appropriate code path.\n ...(globals?.apiVersion === undefined ? {} : { apiVersion: globals.apiVersion }),\n userAgentSuffix: `kash-cli/${CLI_VERSION}`,\n ...(globals?.debug === true ? { hooks: buildDebugHooks(globals.json) } : {}),\n });\n\n return { client, config };\n}\n\n/**\n * Build SDK lifecycle hooks that emit traces to stderr.\n *\n * In `--debug --json` mode each event is a one-line JSON record so an\n * AI agent can stream-parse them. In human mode they're a compact\n * prefix plus method/path/status — close to what an HTTP client like\n * `curl -v` would surface, but at the SDK boundary so retries are\n * visible.\n *\n * Quiet mode silences nothing here: `--debug` is opt-in and the user\n * who passed it wants to see traces, full stop.\n */\nfunction buildDebugHooks(json: boolean): KashClientHooks {\n // Use stderr directly rather than the `log` helpers because the\n // hooks fire synchronously inside the SDK and we want zero overhead\n // in the common case (no quiet check, no chalk wrapping).\n const emit = (record: Record<string, unknown>): void => {\n if (json) {\n process.stderr.write(`${JSON.stringify(record)}\\n`);\n return;\n }\n const { event, method, url, status, attempt, durationMs, reason, delayMs, code } = record;\n const prefix = style.dim('[debug]');\n const path = typeof url === 'string' ? url : '';\n const tag = String(event);\n if (event === 'request') {\n process.stderr.write(\n `${prefix} ${tag} ${String(method)} ${path} (attempt ${String(attempt)})\\n`\n );\n } else if (event === 'response') {\n process.stderr.write(\n `${prefix} ${tag} ${String(status)} ${String(method)} ${path} ${String(durationMs)}ms\\n`\n );\n } else if (event === 'retry') {\n process.stderr.write(\n `${prefix} ${tag} ${String(method)} ${path} reason=${String(reason)} delay=${String(delayMs)}ms\\n`\n );\n } else if (event === 'error') {\n process.stderr.write(\n `${prefix} ${tag} ${String(code)} ${String(method)} ${path} ${String(status ?? '-')} ${String(durationMs)}ms\\n`\n );\n }\n };\n\n return {\n onRequest: (event) => {\n emit({\n event: 'request',\n method: event.method,\n url: event.url,\n attempt: event.attempt,\n idempotencyKey: event.idempotencyKey ?? null,\n });\n },\n onResponse: (event) => {\n emit({\n event: 'response',\n method: event.method,\n url: event.url,\n attempt: event.attempt,\n status: event.status,\n durationMs: event.durationMs,\n requestId: event.requestId ?? null,\n });\n },\n onRetry: (event) => {\n emit({\n event: 'retry',\n method: event.method,\n url: event.url,\n attempt: event.attempt,\n reason: event.reason,\n delayMs: event.delayMs,\n });\n },\n onError: (event) => {\n emit({\n event: 'error',\n method: event.method,\n url: event.url,\n attempt: event.attempt,\n status: event.status ?? null,\n code: event.code,\n durationMs: event.durationMs,\n });\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAyBA,SAAS,kBAAwC;AAyBjD,eAAsB,YAAY,OAAsB,CAAC,GAAyB;AAChF,QAAM,UAAU,KAAK;AACrB,QAAM,SAAS,MAAM,WAAW;AAAA,IAC9B,GAAI,SAAS,YAAY,SAAY,CAAC,IAAI,EAAE,SAAS,QAAQ,QAAQ;AAAA,IACrE,GAAI,SAAS,eAAe,SAAY,CAAC,IAAI,EAAE,YAAY,QAAQ,WAAW;AAAA,EAChF,CAAC;AAED,MAAI,KAAK,eAAe,CAAC,OAAO,QAAQ;AACtC,UAAM,IAAI,SAAS,0BAA0B;AAAA,MAC3C,MAAM;AAAA,MACN,UAAU,WAAW;AAAA,MACrB,YACE;AAAA,IACJ,CAAC;AAAA,EACH;AAGA,QAAM,UAAU,SAAS,WAAW,OAAO;AAE3C,QAAM,SAAS,IAAI,WAAW;AAAA,IAC5B,GAAI,OAAO,WAAW,SAAY,CAAC,IAAI,EAAE,QAAQ,OAAO,OAAO;AAAA,IAC/D;AAAA,IACA,GAAI,SAAS,eAAe,SAAY,CAAC,IAA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"],"sourcesContent":["/**\n * CLI error hierarchy + SDK-error mapper.\n *\n * The CliError shape is **the contract** between this CLI and any\n * agent or script that consumes it. The fields below are SemVer-stable\n * — additions are minor bumps, removals/renames are major bumps.\n *\n * Exit code convention:\n * 0 — success\n * 1 — generic error (validation, server, network, etc.)\n * 2 — auth failure (missing/invalid API key, missing scope)\n *\n * Mapping a `KashRateLimitError` to exit 1 is deliberate: a rate-limit\n * is recoverable, but the CLI should still fail loudly so scripts\n * don't silently move on. The `recoverable` boolean and `retryAfterMs`\n * field tell agents how to handle it.\n *\n * The `actions` array is the agent-friendly recovery path. Each entry\n * is one of a small, well-defined set of variants — agents can branch\n * on `actions[0].type` without parsing prose.\n *\n * **Catalog as source of truth.** Static fields (`recoverable`,\n * `docsUrl`, base `actions`) are read from\n * `error-catalog.ts#ERROR_CATALOG` based on the error's `code`, so\n * `kash explain RATE_LIMITED` always shows the same metadata as the\n * envelope on a real `RATE_LIMITED` failure. The `toCliError` mapper\n * adds runtime-only data (`retryAfterMs` from the server's\n * `Retry-After`, an extra `wait_and_retry` action derived from it).\n * Callers can override any field explicitly, but the default path\n * pulls from the catalog so drift is structurally impossible.\n */\n\nimport {\n KashAbortedError,\n KashAuthenticationError,\n KashAuthorizationError,\n KashConfigurationError as SdkKashConfigurationError,\n KashConflictError,\n KashError,\n KashMaintenanceError,\n KashNetworkError,\n KashNotFoundError,\n KashRateLimitError,\n KashServerError,\n KashTimeoutError,\n KashValidationError,\n} from '@kashdao/sdk';\n\nimport { lookupErrorCodeWithFallback } from './error-catalog.js';\n\n/** Exit codes used by the CLI. */\nexport const EXIT_CODES = {\n OK: 0,\n GENERIC: 1,\n AUTH: 2,\n} as const;\n\nexport type ExitCode = (typeof EXIT_CODES)[keyof typeof EXIT_CODES];\n\n/**\n * Machine-readable next-step hint. Agents inspect `type` and act\n * without parsing the human-prose `suggestion`. Adding new variants\n * is a minor bump (agents that don't recognise them ignore them);\n * removing or renaming is a major bump.\n *\n * **Templates.** A `run_command` action MAY carry `template: true` to\n * signal that `command` contains `<placeholder>` substrings that the\n * agent must substitute (or skip) before executing. Templates exist\n * because the static error catalog can't always know the concrete\n * command id / trade id / market id at the point the catalog is\n * authored — they're carved at runtime when the SDK error is mapped.\n * Agents that auto-execute `run_command` actions MUST honour the\n * `template` flag: substitute, prompt, or skip. Treating templated\n * commands as concrete will literally shell `kash trade status <id>`\n * (with the angle brackets) and fail.\n */\nexport type CliErrorAction =\n | {\n readonly type: 'run_command';\n readonly command: string;\n readonly description: string;\n /**\n * `true` when `command` contains `<placeholder>` tokens the\n * caller must substitute. Absent or `false` means the command\n * is concrete and safe to auto-execute. Agents that lack\n * substitution support should skip templated commands and fall\n * back to the catalog's `description` / `suggestion`.\n */\n readonly template?: boolean;\n }\n | { readonly type: 'set_env'; readonly variable: string; readonly description: string }\n | { readonly type: 'wait_and_retry'; readonly delayMs: number; readonly description: string }\n | { readonly type: 'open_url'; readonly url: string; readonly description: string }\n | { readonly type: 'check_input'; readonly field: string; readonly description: string };\n\nexport type CliErrorOptions = {\n readonly code: string;\n readonly suggestion?: string | undefined;\n readonly exitCode?: ExitCode;\n readonly requestId?: string | undefined;\n /**\n * Override the catalog's `recoverable`. If omitted the catalog's\n * value is used; if the code isn't in the catalog, defaults to\n * `false` via the UNEXPECTED fallback.\n */\n readonly recoverable?: boolean;\n /** Suggested delay before retrying. No catalog default. */\n readonly retryAfterMs?: number | undefined;\n /** Override the catalog's `docsUrl`. */\n readonly docsUrl?: string | undefined;\n /**\n * Additional `actions` to append to the catalog's static set. Use\n * this for runtime-derived hints (e.g. a `wait_and_retry` with the\n * server's exact Retry-After). Pass `actionsOverride` to replace\n * the catalog set entirely.\n */\n readonly actions?: readonly CliErrorAction[];\n /**\n * Replace the catalog's `actions` entirely (instead of appending\n * via `actions`). Use sparingly — the catalog is the source of\n * truth for static actions.\n */\n readonly actionsOverride?: readonly CliErrorAction[];\n readonly cause?: unknown;\n};\n\nexport class CliError extends Error {\n readonly code: string;\n readonly suggestion: string | undefined;\n readonly exitCode: ExitCode;\n readonly requestId: string | undefined;\n /** True iff a sensible retry/recovery path exists. */\n readonly recoverable: boolean;\n /** Suggested delay before retrying (rate limit, server error). */\n readonly retryAfterMs: number | undefined;\n /** Stable docs URL agents can fetch for richer context. */\n readonly docsUrl: string | undefined;\n /** Machine-readable next-step hints. Empty array if none. */\n readonly actions: readonly CliErrorAction[];\n override readonly cause: unknown;\n\n constructor(message: string, options: CliErrorOptions) {\n super(message);\n this.name = 'CliError';\n const catalogEntry = lookupErrorCodeWithFallback(options.code);\n this.code = options.code;\n this.suggestion = options.suggestion;\n this.exitCode = options.exitCode ?? EXIT_CODES.GENERIC;\n this.requestId = options.requestId;\n this.recoverable = options.recoverable ?? catalogEntry.recoverable;\n this.retryAfterMs = options.retryAfterMs;\n this.docsUrl = options.docsUrl ?? catalogEntry.docsUrl;\n if (options.actionsOverride !== undefined) {\n this.actions = options.actionsOverride;\n } else {\n // Caller-provided actions first (they're contextually specific:\n // a `wait_and_retry` derived from the server's actual\n // Retry-After, or a `check_input` naming a concrete bad field),\n // catalog actions second (generic fallbacks). Agents act on the\n // first applicable hint, so the more specific one needs to win.\n this.actions = [...(options.actions ?? []), ...catalogEntry.actions];\n }\n this.cause = options.cause;\n Error.captureStackTrace?.(this, this.constructor);\n }\n\n /**\n * Render the error as the stable JSON envelope agents pin to. Kept\n * as a method so the index.ts emitError can serialise consistently\n * regardless of caller.\n */\n toEnvelope(): Record<string, unknown> {\n return {\n ok: false,\n error: {\n code: this.code,\n message: this.message,\n recoverable: this.recoverable,\n ...(this.suggestion === undefined ? {} : { suggestion: this.suggestion }),\n ...(this.retryAfterMs === undefined ? {} : { retryAfterMs: this.retryAfterMs }),\n ...(this.docsUrl === undefined ? {} : { docsUrl: this.docsUrl }),\n ...(this.requestId === undefined ? {} : { requestId: this.requestId }),\n actions: this.actions,\n },\n };\n }\n}\n\nexport class CliValidationError extends CliError {\n constructor(message: string, suggestion?: string, field?: string) {\n super(message, {\n code: 'INVALID_INPUT',\n ...(suggestion === undefined ? {} : { suggestion }),\n ...(field === undefined\n ? {}\n : {\n actions: [\n {\n type: 'check_input' as const,\n field,\n description: `Verify the value of \"${field}\".`,\n },\n ],\n }),\n });\n this.name = 'CliValidationError';\n }\n}\n\nexport class CliConfigurationError extends CliError {\n constructor(message: string, suggestion?: string) {\n super(message, {\n code: 'CONFIGURATION',\n ...(suggestion === undefined ? {} : { suggestion }),\n });\n this.name = 'CliConfigurationError';\n }\n}\n\n/**\n * Translate any `unknown` error coming out of the SDK or the CLI\n * itself into a `CliError`. Pass-through for existing `CliError`\n * instances so callers can re-throw without re-wrapping.\n *\n * Each branch only sets runtime fields (suggestion, requestId,\n * retryAfterMs, runtime-derived actions). Static fields like\n * `recoverable`, `docsUrl`, and base `actions` come from the catalog\n * via the CliError constructor.\n */\nexport function toCliError(err: unknown): CliError {\n if (err instanceof CliError) {\n return err;\n }\n // Commander-thrown errors (we call `program.exitOverride()` so\n // unknown commands / unknown options surface here instead of\n // exiting via process.exit). Help and version short-circuits also\n // come through — they're not errors and exit cleanly.\n const commander = mapCommanderError(err);\n if (commander) return commander;\n if (err instanceof KashAuthenticationError) {\n return new CliError(err.message, {\n code: 'AUTH_REQUIRED',\n exitCode: EXIT_CODES.AUTH,\n suggestion:\n \"First-time setup: run 'kash setup' (interactive wizard). Otherwise: 'kash auth set-key' or set KASH_API_KEY.\",\n ...(err.requestId === undefined ? {} : { requestId: err.requestId }),\n cause: err,\n });\n }\n if (err instanceof KashAuthorizationError) {\n return new CliError(err.message, {\n code: 'INSUFFICIENT_SCOPE',\n exitCode: EXIT_CODES.AUTH,\n suggestion:\n 'The API key is valid but is missing the scope this command needs. Email `engineering@kash.bot` to request a key with broader scope.',\n ...(err.requestId === undefined ? {} : { requestId: err.requestId }),\n cause: err,\n });\n }\n if (err instanceof KashRateLimitError) {\n const retrySec = err.retryAfterSeconds;\n const retryAfterMs = retrySec === undefined ? undefined : retrySec * 1000;\n const suggestion =\n retrySec !== undefined\n ? `Retry in ${String(retrySec)}s. Upgrade for higher limits: https://kash.bot/pricing`\n : 'Slow down request rate. Upgrade for higher limits: https://kash.bot/pricing';\n return new CliError(err.message, {\n code: 'RATE_LIMITED',\n suggestion,\n ...(retryAfterMs === undefined ? {} : { retryAfterMs }),\n ...(retryAfterMs === undefined\n ? {}\n : {\n actions: [\n {\n type: 'wait_and_retry' as const,\n delayMs: retryAfterMs,\n description: `Wait ${String(retrySec)}s then re-run the same command.`,\n },\n ],\n }),\n ...(err.requestId === undefined ? {} : { requestId: err.requestId }),\n cause: err,\n });\n }\n if (err instanceof KashNotFoundError) {\n return new CliError(err.message, {\n code: 'NOT_FOUND',\n suggestion: 'Double-check the resource id (markets and trades use UUIDs).',\n ...(err.requestId === undefined ? {} : { requestId: err.requestId }),\n cause: err,\n });\n }\n if (err instanceof KashConflictError) {\n return new CliError(err.message, {\n code: 'CONFLICT',\n suggestion:\n 'A conflicting request is already in flight or the resource state changed underneath you. Inspect the trade with `kash trade status <id>` before retrying.',\n ...(err.requestId === undefined ? {} : { requestId: err.requestId }),\n cause: err,\n });\n }\n if (err instanceof KashValidationError) {\n return new CliError(err.message, {\n code: 'INVALID_INPUT',\n suggestion: 'Verify the request shape matches `kash <command> --help`.',\n ...(err.requestId === undefined ? {} : { requestId: err.requestId }),\n cause: err,\n });\n }\n if (err instanceof KashMaintenanceError) {\n const retrySec = err.retryAfterSeconds;\n const retryAfterMs = retrySec === undefined ? undefined : retrySec * 1000;\n return new CliError(err.message, {\n code: 'MAINTENANCE',\n suggestion:\n 'The Kash trade pipeline is temporarily disabled (incident response or planned maintenance). Honor `retryAfterMs` and retry once the window closes.',\n ...(retryAfterMs === undefined ? {} : { retryAfterMs }),\n ...(retryAfterMs === undefined\n ? {}\n : {\n actions: [\n {\n type: 'wait_and_retry' as const,\n delayMs: retryAfterMs,\n description: `Wait ${String(retrySec)}s before retrying.`,\n },\n ],\n }),\n ...(err.requestId === undefined ? {} : { requestId: err.requestId }),\n cause: err,\n });\n }\n if (err instanceof KashTimeoutError) {\n return new CliError(err.message, {\n code: 'TIMEOUT',\n suggestion:\n 'The request exceeded the configured timeout. Retry, or pass --timeout-ms to raise the cap.',\n ...(err.requestId === undefined ? {} : { requestId: err.requestId }),\n cause: err,\n });\n }\n if (err instanceof KashNetworkError) {\n // Inspect the underlying cause for DNS-resolution failures so we\n // can route the user to the right recovery action. The most common\n // failure mode pre-mainnet-launch is \"configured for production\n // but production isn't deployed yet\" — point them at staging via\n // their test key rather than a generic \"check connectivity\" line.\n const causeStr = `${String(err.message ?? '')} ${String((err.cause as Error)?.message ?? '')}`;\n const isDnsError =\n causeStr.includes('ENOTFOUND') ||\n causeStr.includes('getaddrinfo') ||\n causeStr.includes('EAI_AGAIN') ||\n causeStr.includes('Could not resolve');\n const suggestion = isDnsError\n ? 'The configured API host did not resolve in DNS. ' +\n 'For staging, use a `kash_test_*` key — the CLI auto-routes to ' +\n '`https://api-staging.kash.bot/v1`. ' +\n 'For a custom host, pass `--base-url <url>` or set `KASH_BASE_URL`. ' +\n 'Production (`https://api.kash.bot/v1`) is not yet live; track launch ' +\n 'status at https://docs.kash.bot.'\n : 'The request did not reach the API. Check network connectivity and retry.';\n return new CliError(err.message, {\n code: 'NETWORK',\n suggestion,\n ...(err.requestId === undefined ? {} : { requestId: err.requestId }),\n cause: err,\n });\n }\n if (err instanceof KashAbortedError) {\n return new CliError(err.message, {\n code: 'ABORTED',\n suggestion:\n 'The request was cancelled before it completed. If the command is idempotent, you can safely retry with the same Idempotency-Key.',\n ...(err.requestId === undefined ? {} : { requestId: err.requestId }),\n cause: err,\n });\n }\n if (err instanceof KashServerError) {\n return new CliError(err.message, {\n code: 'SERVER_ERROR',\n suggestion:\n 'The API returned a 5xx after retries. The request is safe to retry; if the failure persists, file a bug at https://github.com/KashDAO/cli/issues with the requestId.',\n ...(err.requestId === undefined ? {} : { requestId: err.requestId }),\n cause: err,\n });\n }\n if (err instanceof SdkKashConfigurationError) {\n // Surface the first Zod issue's path as a check_input action so\n // an agent can localise the broken field without parsing prose.\n const firstIssue = err.issues[0];\n const fieldPath = firstIssue?.path.join('.') ?? '';\n return new CliError(err.message, {\n code: 'CONFIGURATION',\n suggestion:\n firstIssue !== undefined\n ? `SDK rejected ${fieldPath || '(root)'}: ${firstIssue.message}`\n : 'The SDK rejected the configuration provided to the client.',\n ...(fieldPath\n ? {\n actions: [\n {\n type: 'check_input' as const,\n field: fieldPath,\n description: `Fix the value of \"${fieldPath}\" and re-run.`,\n },\n ],\n }\n : {}),\n cause: err,\n });\n }\n // ── Protocol-SDK (`@kashdao/protocol-sdk`) errors ───────────────\n // We don't eager-import the protocol-sdk just to use `instanceof`\n // checks (it pulls in viem). Duck-type on `err.name` instead — the\n // protocol-sdk's error classes set their `name` field deterministically\n // in the base constructor.\n const protocolErrorMapping = mapProtocolError(err);\n if (protocolErrorMapping !== undefined) {\n return protocolErrorMapping;\n }\n if (err instanceof KashError) {\n // Any KashError subclass we haven't enumerated above. Falls back\n // to the catalog's UNEXPECTED entry for `recoverable`/`docsUrl`\n // (so `kash explain` always returns *something*) but preserves\n // the SDK's `isRetryable` value.\n return new CliError(err.message, {\n code: 'UNEXPECTED',\n recoverable: err.isRetryable,\n ...(err.requestId === undefined ? {} : { requestId: err.requestId }),\n cause: err,\n });\n }\n if (err instanceof Error) {\n return new CliError(err.message, { code: 'UNEXPECTED', cause: err });\n }\n return new CliError(String(err), { code: 'UNEXPECTED', cause: err });\n}\n\n/**\n * Structural shape of Commander's `CommanderError`. Commander documents\n * `code` and `message` as stable public API and namespaces every code\n * with the `commander.` prefix (`commander.unknownCommand`,\n * `commander.help`, etc.).\n *\n * We type-guard against this shape rather than `instanceof CommanderError`\n * because importing the constructor here would force the Commander\n * module to load on the cold path even for invocations that never\n * touch it. Going through a structural check keeps the import lazy\n * AND keeps TypeScript safety at every use site.\n */\nexport type CommanderErrorLike = {\n readonly code: string;\n readonly message: string;\n};\n\n/**\n * Type guard — true iff `err` looks like a Commander-thrown error.\n * Commander always sets `code` to a string starting with `commander.`,\n * so the prefix check is the load-bearing test (filters out other\n * errors that happen to have a `code` field, e.g. `EACCES`).\n */\nexport function isCommanderError(err: unknown): err is CommanderErrorLike {\n if (!(err instanceof Error)) return false;\n const candidate = err as { code?: unknown; message?: unknown };\n return (\n typeof candidate.code === 'string' &&\n candidate.code.startsWith('commander.') &&\n typeof candidate.message === 'string'\n );\n}\n\n/**\n * Map a Commander-thrown error to either a clean exit (help/version)\n * or a structured `CliError` (unknown command, unknown option, missing\n * argument, etc.). Returns undefined for non-Commander errors so the\n * outer mapper can keep walking its switch.\n */\nfunction mapCommanderError(err: unknown): CliError | undefined {\n if (!isCommanderError(err)) return undefined;\n const { code, message } = err;\n\n // `commander.help`, `commander.helpDisplayed`, `commander.version` —\n // user asked for `--help` or `--version`. Commander already wrote\n // the output; surfacing this as a real error would be wrong. Use\n // `EXIT_CODES.OK` and code `'NOOP'` so the top-level boundary in\n // `index.ts` exits cleanly and prints nothing extra.\n if (\n code === 'commander.help' ||\n code === 'commander.helpDisplayed' ||\n code === 'commander.version'\n ) {\n return new CliError('', {\n code: 'NOOP',\n exitCode: EXIT_CODES.OK,\n recoverable: false,\n cause: err,\n });\n }\n\n // Unknown command — the most common typo case. Commander appends\n // a \"Did you mean X?\" suggestion to the message; we extract it so\n // the structured envelope carries a `run_command` recovery action\n // an agent can execute directly.\n if (code === 'commander.unknownCommand') {\n const match = /Did you mean (\\S+?)\\??\\)?$/m.exec(message);\n const suggested = match?.[1];\n const suggestion = suggested\n ? `Did you mean \\`kash ${suggested}\\`? Run \\`kash --help\\` for the full command tree.`\n : 'Run `kash --help` for the full command tree.';\n return new CliError(stripTrailingNewlines(message), {\n code: 'INVALID_INPUT',\n recoverable: true,\n suggestion,\n ...(suggested === undefined\n ? {}\n : {\n actions: [\n {\n type: 'run_command' as const,\n command: `kash ${suggested}`,\n description: 'Run the suggested command instead.',\n },\n ],\n }),\n cause: err,\n });\n }\n\n // Unknown option — adjacent typo case. Commander doesn't always\n // include a suggestion for options; fall back to a generic check.\n if (code === 'commander.unknownOption') {\n return new CliError(stripTrailingNewlines(message), {\n code: 'INVALID_INPUT',\n recoverable: true,\n suggestion:\n 'Run `kash <command> --help` for the supported flags, or `kash docs --json` for the full surface.',\n cause: err,\n });\n }\n\n // Missing required argument / option — Commander surfaces these\n // before the action runs. Keep the original message (it names the\n // flag) and add a generic check_input action.\n if (\n code === 'commander.missingArgument' ||\n code === 'commander.missingMandatoryOptionValue' ||\n code === 'commander.optionMissingArgument'\n ) {\n return new CliError(stripTrailingNewlines(message), {\n code: 'INVALID_INPUT',\n recoverable: true,\n suggestion: 'Run the command with `--help` to see required arguments.',\n cause: err,\n });\n }\n\n // Anything else from Commander (excess arguments, invalid choice,\n // etc.) — generic mapping with the original message preserved.\n return new CliError(stripTrailingNewlines(message), {\n code: 'INVALID_INPUT',\n recoverable: true,\n cause: err,\n });\n}\n\n/** Trim trailing newlines so error messages don't render double-spaced. */\nfunction stripTrailingNewlines(s: string): string {\n return s.replace(/\\n+$/, '');\n}\n\n/**\n * Map an `@kashdao/protocol-sdk` error to the corresponding CLI code,\n * by class name. Returns `undefined` if the error is not a recognised\n * protocol-sdk error.\n *\n * **Why duck-typing instead of `instanceof`?** Importing the\n * protocol-sdk eagerly here would defeat the cold-start optimisation\n * that lazy-loads `@kashdao/protocol-sdk` only when `kash protocol …`\n * commands run. Kash-orchestrated-only invocations (markets/trade/portfolio)\n * keep their fast path. The protocol-sdk's error base class sets\n * `name` to the constructor name in its constructor, so a name check\n * is reliable across module-instance boundaries.\n */\nfunction mapProtocolError(err: unknown): CliError | undefined {\n if (!(err instanceof Error)) return undefined;\n switch (err.name) {\n case 'KashConfigError': {\n const cliErr = new CliError(err.message, {\n code: 'DIRECT_CONFIG_MISSING',\n suggestion:\n 'Set the missing field via `kash config set <field> <value>` (rpcUrl, smartAccount, signerKeyRef, defaultChainId).',\n cause: err,\n });\n return cliErr;\n }\n case 'KashSignerError':\n return new CliError(err.message, {\n code: 'SIGNER_FAILED',\n suggestion: 'Verify the signerKeyRef target is readable (file:<path>) or set (env:<NAME>).',\n cause: err,\n });\n case 'KashChainError':\n return new CliError(err.message, {\n code: 'CHAIN_ERROR',\n suggestion: 'On-chain read or contract interaction failed unexpectedly.',\n cause: err,\n });\n case 'KashBundlerError':\n return new CliError(err.message, {\n code: 'BUNDLER_REJECTED',\n suggestion: 'Inspect the bundler-specific reason in the message and adjust.',\n cause: err,\n });\n case 'KashSimulationRevertedError':\n return new CliError(err.message, {\n code: 'TRANSACTION_REVERTED',\n suggestion: 'Re-run with `kash protocol simulate` to see the decoded revert reason.',\n cause: err,\n });\n case 'KashProtocolError':\n // Base class — ChainError is the closest fallback for any\n // protocol-sdk error not covered above.\n return new CliError(err.message, {\n code: 'CHAIN_ERROR',\n suggestion: 'Unrecognised protocol-sdk error. File an issue with `kash version --json`.',\n cause: err,\n });\n default:\n return undefined;\n }\n}\n","/**\n * Single source of truth for every error `code` the CLI emits.\n *\n * Both `toCliError` (the SDK-error mapper) and `kash explain <code>`\n * read from this catalog so an AI agent that hits a `RATE_LIMITED`\n * error and asks `kash explain RATE_LIMITED --json` gets the same\n * `recoverable`, `docsUrl`, and `actions` it would have seen on the\n * error envelope.\n *\n * Adding a new code: append an entry. Removing one: major bump.\n * Renaming a field: major bump.\n *\n * Runtime-only data (the server's `retryAfterMs`, the specific\n * `requestId`, an extra `wait_and_retry` action computed from the\n * Retry-After header) is layered on top by `toCliError` — the\n * catalog is for static metadata only.\n */\n\nimport type { CliErrorAction } from './errors.js';\n\nexport type ErrorCatalogEntry = {\n /** Stable machine-readable code. */\n readonly code: string;\n /** One-sentence summary in plain English. */\n readonly summary: string;\n /** Longer explanation suitable for human troubleshooting. */\n readonly description: string;\n /** Whether retrying the original request might succeed. */\n readonly recoverable: boolean;\n /** Stable docs URL, when one exists. */\n readonly docsUrl?: string;\n /**\n * Concrete recovery steps the agent can take. These are the\n * *static* actions for this code; runtime-only actions (e.g. a\n * `wait_and_retry` derived from the server's Retry-After header)\n * are appended by `toCliError`.\n */\n readonly actions: readonly CliErrorAction[];\n};\n\nexport const ERROR_CATALOG: readonly ErrorCatalogEntry[] = [\n {\n code: 'AUTH_REQUIRED',\n summary: 'No API key was provided, or the key is invalid / expired / revoked.',\n description:\n 'The Kash public API requires a kash_live_… or kash_test_… key on every authenticated route. First-time users should run `kash setup` (interactive wizard). Existing users can `kash auth set-key`, set KASH_API_KEY, or pass --profile to switch to a stored profile.',\n recoverable: true,\n docsUrl: 'https://kash.bot/docs/cli/authentication',\n actions: [\n {\n type: 'run_command',\n command: 'kash setup',\n description: 'First-run wizard — issues a key, configures profile, validates it.',\n },\n {\n type: 'run_command',\n command: 'kash auth set-key',\n description:\n 'Store an API key for the active profile (paste interactively or pipe via stdin).',\n },\n {\n type: 'set_env',\n variable: 'KASH_API_KEY',\n description: 'Provide the key via environment variable.',\n },\n {\n type: 'open_url',\n url: 'mailto:engineering@kash.bot?subject=Kash%20staging%20API%20key%20request',\n description:\n 'Email `engineering@kash.bot` to request a `kash_test_*` staging key (self-service issuance ships with the production launch).',\n },\n ],\n },\n {\n code: 'INSUFFICIENT_SCOPE',\n summary: 'The API key is valid but lacks the scope this command requires.',\n description:\n \"Authentication succeeded but the key's scope (read-only / trade / admin) doesn't cover the route. Request a key with broader scope, or move to a tier that includes it.\",\n recoverable: true,\n docsUrl: 'https://docs.kash.bot/developer-docs/rest-api/authentication',\n actions: [\n {\n type: 'open_url',\n url: 'mailto:engineering@kash.bot?subject=Kash%20API%20key%20scope%20request',\n description: 'Email `engineering@kash.bot` for a key with broader scope.',\n },\n ],\n },\n {\n code: 'RATE_LIMITED',\n summary: 'You have exceeded the per-key rate limit for this tier.',\n description:\n 'Slow down or upgrade for higher limits. The error envelope carries `retryAfterMs`; honor it via `kash --max-retries` or back off in your application.',\n recoverable: true,\n docsUrl: 'https://kash.bot/docs/api/rate-limits',\n actions: [\n {\n type: 'open_url',\n url: 'https://kash.bot/pricing',\n description: 'Upgrade tier for higher rate limits.',\n },\n ],\n },\n {\n code: 'NOT_FOUND',\n summary: 'The requested resource (market, trade, position) does not exist.',\n description:\n 'Markets and trades are identified by UUID. Confirm the id is correct (especially after copy-paste truncation) and that the resource is visible to the active key.',\n recoverable: true,\n docsUrl: 'https://kash.bot/docs/api/errors',\n actions: [],\n },\n {\n code: 'CONFLICT',\n summary: 'A conflicting request is already in flight or the resource state changed.',\n description:\n 'Common cases: you sent a duplicate Idempotency-Key, the trade is awaiting high-value confirmation, or the market closed between fetch and trade. Inspect the resource before retrying.',\n recoverable: true,\n docsUrl: 'https://kash.bot/docs/api/errors',\n actions: [\n {\n type: 'run_command',\n command: 'kash trade status <id>',\n description: 'Inspect the conflicting trade resource. Substitute <id> with the trade UUID.',\n template: true,\n },\n ],\n },\n {\n code: 'INVALID_INPUT',\n summary: 'The request body or arguments failed validation.',\n description:\n 'Check the field names and types against `kash <command> --help` or `kash schema <command>`. USDC amounts are decimal strings with up to 6 fractional digits.',\n recoverable: true,\n docsUrl: 'https://kash.bot/docs/cli/commands',\n actions: [\n {\n type: 'run_command',\n command: 'kash <command> --help',\n description:\n 'Inspect the command signature. Substitute <command> with the failing path (e.g. `trade buy`, `markets list`).',\n template: true,\n },\n {\n type: 'run_command',\n command: 'kash schema <command>',\n description:\n 'Get the JSON Schema for the command inputs. Substitute <command> with the failing path.',\n template: true,\n },\n ],\n },\n {\n code: 'MAINTENANCE',\n summary: 'The Kash trade pipeline is temporarily disabled (kill switch).',\n description:\n 'API trade processing is halted, typically during incident response or planned maintenance. Read state is unaffected. Honor the `retryAfterMs` and retry once the window closes.',\n recoverable: true,\n docsUrl: 'https://docs.kash.bot/developer-docs/api-errors/API_TRADE_PROCESSING_HALTED',\n actions: [\n {\n type: 'wait_and_retry',\n delayMs: 30_000,\n description: 'Wait 30s then retry. Surface the requestId if the failure persists.',\n },\n ],\n },\n {\n code: 'TIMEOUT',\n summary: 'The request exceeded the SDK timeout (default 30s).',\n description:\n 'Either the server is slow or the network path is degraded. Retry, or pass --timeout-ms to raise the cap. Repeated timeouts are worth investigating against the status page.',\n recoverable: true,\n docsUrl: 'https://kash.bot/docs/cli/troubleshooting',\n actions: [\n {\n type: 'run_command',\n command: 'kash --timeout-ms 60000 <same command>',\n description:\n 'Re-run with a longer timeout. Substitute <same command> with the original invocation tail.',\n template: true,\n },\n ],\n },\n {\n code: 'NETWORK',\n summary: 'A transport-layer failure (DNS, TLS, connection refused) before any HTTP response.',\n description:\n 'The SDK never received a response. Check connectivity to api.kash.bot. The CLI retries network errors automatically; this means retries were exhausted.',\n recoverable: true,\n docsUrl: 'https://kash.bot/docs/cli/troubleshooting',\n actions: [],\n },\n {\n code: 'ABORTED',\n summary: 'The request was cancelled by the caller before it completed.',\n description:\n 'An AbortSignal you passed (or the spinner you cancelled) fired while the request was in flight. The server may or may not have processed the request — if it did, the side effect already landed. Idempotent requests can be safely retried with the same Idempotency-Key.',\n recoverable: false,\n docsUrl: 'https://kash.bot/docs/cli/troubleshooting',\n actions: [],\n },\n {\n code: 'SERVER_ERROR',\n summary: 'The API returned a 5xx response after retries.',\n description:\n 'The request is safe to retry. If the issue persists, file a bug at https://github.com/KashDAO/cli/issues with the requestId on the error envelope.',\n recoverable: true,\n docsUrl: 'https://docs.kash.bot/developer-docs/api-errors/DEPENDENCY_UNAVAILABLE',\n actions: [\n {\n type: 'wait_and_retry',\n delayMs: 5_000,\n description: 'Wait 5s and retry. The CLI may have already exhausted its retry budget.',\n },\n ],\n },\n {\n code: 'CONFIGURATION',\n summary: 'The CLI configuration file or environment is invalid.',\n description:\n \"The on-disk ~/.kash/config.json failed to parse, an env var (KASH_CHAIN_ID) doesn't match its expected shape, or a per-invocation flag (--max-retries, --timeout-ms, --base-url) was rejected by the SDK. Run `kash config show` to inspect what loaded.\",\n recoverable: true,\n docsUrl: 'https://kash.bot/docs/cli/configuration',\n actions: [\n {\n type: 'run_command',\n command: 'kash config show',\n description: 'Inspect the loaded configuration and its sources.',\n },\n ],\n },\n // ─── Direct-mode (kash protocol ...) ─────────────────────────────\n {\n code: 'DIRECT_CONFIG_MISSING',\n summary: 'Direct-mode configuration is incomplete.',\n description:\n \"Direct-mode commands (`kash protocol ...`) require RPC URL, smart account address, signer key reference, and chain ID. One or more of these is missing from the active profile and the environment. Run `kash config show` to see what's loaded; set the missing fields with `kash config set rpcUrl …`, `kash config set smartAccount 0x…`, etc.\",\n recoverable: true,\n docsUrl: 'https://kash.bot/docs/cli/direct-mode',\n actions: [\n {\n type: 'run_command',\n command: 'kash config show',\n description: 'Inspect the loaded configuration and source attribution.',\n },\n {\n type: 'run_command',\n command: 'kash config set rpcUrl https://your-rpc.example.com',\n description: 'Set the RPC URL for direct-mode operations.',\n },\n ],\n },\n {\n code: 'SIGNER_FAILED',\n summary: 'The configured signer (file/env/KMS) failed to load or sign.',\n description:\n \"The signer adapter referenced by `signerKeyRef` couldn't load the private key, or signing the UserOp hash failed. Common causes: missing/unreadable file, missing env var, malformed hex, or a KMS permission denial.\",\n recoverable: true,\n docsUrl: 'https://kash.bot/docs/cli/direct-mode',\n actions: [\n {\n type: 'check_input',\n field: 'signerKeyRef',\n description: 'Verify the signer reference (file:<path> or env:<VAR>) and its target.',\n },\n ],\n },\n {\n code: 'RPC_FAILED',\n summary: 'The RPC endpoint refused the request or timed out.',\n description:\n 'Network call to the configured `rpcUrl` failed. Could be a rate-limit at the RPC provider, a transient network issue, or a misconfigured URL. The protocol-sdk does NOT retry RPC calls — fail fast so the operator sees the issue.',\n recoverable: true,\n docsUrl: 'https://kash.bot/docs/cli/troubleshooting',\n actions: [\n {\n type: 'check_input',\n field: 'rpcUrl',\n description: 'Verify the RPC URL is reachable and the API key (if any) is valid.',\n },\n ],\n },\n {\n code: 'BUNDLER_REJECTED',\n summary: 'The bundler refused to relay the UserOp.',\n description:\n 'Common rejection reasons: replacement-underpriced, sender-mempool-full, gas estimation drift, or a UserOp that the bundler suspects will revert. The error message carries the bundler-specific reason verbatim.',\n recoverable: true,\n docsUrl: 'https://kash.bot/docs/cli/direct-mode',\n actions: [],\n },\n {\n code: 'TRANSACTION_REVERTED',\n summary: 'The UserOp executed but the on-chain call reverted.',\n description:\n 'The transaction landed on-chain but the contract call reverted. The error message carries the decoded revert reason when the protocol-sdk recognises it (e.g. `MarketFrozen`, `InsufficientReserve`). Re-running with `kash protocol simulate` first will catch most reverts before they cost gas.',\n recoverable: false,\n docsUrl: 'https://kash.bot/docs/cli/direct-mode',\n actions: [\n {\n type: 'run_command',\n command:\n 'kash protocol simulate <market-address> --action <buy|sell> --outcome <i> --amount <n>',\n description:\n 'Dry-run the trade against current chain state before re-submitting. Substitute every <placeholder>.',\n template: true,\n },\n ],\n },\n {\n code: 'CHAIN_ERROR',\n summary: 'A protocol-level chain interaction failed.',\n description:\n \"An on-chain read or simulation returned an unexpected shape, decoded to an unknown revert, or the contract addresses don't match the configured chain ID. Verify the chain ID and that the protocol contracts are deployed at the expected addresses for that chain.\",\n recoverable: false,\n docsUrl: 'https://kash.bot/docs/cli/direct-mode',\n actions: [\n {\n type: 'check_input',\n field: 'chainId',\n description: 'Confirm chainId matches the network your RPC and bundler target.',\n },\n ],\n },\n {\n code: 'UNEXPECTED',\n summary: 'An unrecognised error escaped the SDK or the CLI.',\n description:\n \"This means the CLI's error mapper didn't recognise the underlying failure — the most likely cause is an SDK or runtime issue. File an issue with the message, the command, and the runtime info from `kash version --json`.\",\n recoverable: false,\n docsUrl: 'https://github.com/KashDAO/cli/issues',\n actions: [\n {\n type: 'run_command',\n command: 'kash version --json',\n description: 'Capture runtime info to attach to the bug report.',\n },\n ],\n },\n {\n code: 'NOOP',\n summary: 'No-op exit (Commander emitted output and asked us to stop).',\n description:\n \"Commander's help/version paths don't represent a failure — it printed `--help` or `--version` output and signalled the CLI to exit cleanly. This code surfaces in JSON-output contexts so consumers know the run completed without doing real work; the human path exits 0 with no error envelope.\",\n recoverable: true,\n docsUrl: 'https://kash.bot/docs/cli/exit-codes',\n actions: [],\n },\n];\n\nconst CATALOG_BY_CODE = new Map<string, ErrorCatalogEntry>(\n ERROR_CATALOG.map((entry) => [entry.code, entry])\n);\n\nexport function lookupErrorCode(code: string): ErrorCatalogEntry | undefined {\n return CATALOG_BY_CODE.get(code);\n}\n\n/**\n * Resolve the catalog entry for a code, falling back to the\n * `UNEXPECTED` entry when the code isn't recognised.\n *\n * The fallback exists so opaque SDK codes (e.g. a new `KashError`\n * subclass that hasn't been mapped CLI-side yet) still produce a\n * usable `kash explain <code>` response — the agent learns \"we don't\n * recognise this code, file an issue\" instead of \"Unknown error\n * code\", which would be a dead end.\n */\nexport function lookupErrorCodeWithFallback(code: string): ErrorCatalogEntry {\n const entry = CATALOG_BY_CODE.get(code);\n if (entry) return entry;\n // The UNEXPECTED entry is always present; safe to assert.\n return CATALOG_BY_CODE.get('UNEXPECTED')!;\n}\n\n/** Set of every catalog code, exposed for invariant tests. */\nexport const ERROR_CODES: ReadonlySet<string> = new Set(ERROR_CATALOG.map((e) => e.code));\n"],"mappings":";;;AAgCA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,0BAA0B;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACNA,IAAM,gBAA8C;AAAA,EACzD;AAAA,IACE,MAAM;AAAA,IACN,SAAS;AAAA,IACT,aACE;AAAA,IACF,aAAa;AAAA,IACb,SAAS;AAAA,IACT,SAAS;AAAA,MACP;AAAA,QACE,MAAM;AAAA,QACN,SAAS;AAAA,QACT,aAAa;AAAA,MACf;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,SAAS;AAAA,QACT,aACE;AAAA,MACJ;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,UAAU;AAAA,QACV,aAAa;AAAA,MACf;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,KAAK;AAAA,QACL,aACE;AAAA,MACJ;AAAA,IACF;AAAA,EACF;AAAA,EACA;AAAA,IACE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AC;AAAA,IACH,KAAK;AACH,aAAO,IAAI,SAAS,IAAI,SAAS;AAAA,QAC/B,MAAM;AAAA,QACN,YAAY;AAAA,QACZ,OAAO;AAAA,MACT,CAAC;AAAA,IACH,KAAK;AACH,aAAO,IAAI,SAAS,IAAI,SAAS;AAAA,QAC/B,MAAM;AAAA,QACN,YAAY;AAAA,QACZ,OAAO;AAAA,MACT,CAAC;AAAA,IACH,KAAK;AAGH,aAAO,IAAI,SAAS,IAAI,SAAS;AAAA,QAC/B,MAAM;AAAA,QACN,YAAY;AAAA,QACZ,OAAO;AAAA,MACT,CAAC;AAAA,IACH;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils/trade-input.ts"],"sourcesContent":["/**\n * Shared input parsers for every trade-execution command.\n *\n * Three modes share these primitives:\n *\n * - SA mode (`kash protocol trade …`, `kash protocol userop build …`)\n * — converts to atomic units (bigint) for the protocol-sdk.\n * - EOA mode (`kash eoa trade …`) — same atomic-unit conversion.\n * - Public-API mode (`kash trade buy/sell`) — ships the raw string\n * to the hosted-API SDK, so it uses the shape validators\n * (`validateUsdcDecimalShape`, `parseOutcomeIndex`) rather than\n * the atomic-unit converters.\n *\n * Centralising the parsers eliminates three sources of drift:\n *\n * 1. **Validation messages** — the same flag should produce the\n * same error wording regardless of mode.\n * 2. **Bounds** — slippage caps, outcome-index ceilings, USDC\n * decimal precision must be identical across modes (otherwise\n * operators get different errors for the same value).\n * 3. **Real-money correctness** — these inputs feed the SDK's\n * atomic-unit math (or the API's server-side conversion); one\n * drift between modes would silently change a trade's effective\n * amount.\n */\n\nimport { CliValidationError } from '../errors.js';\n\n/** Standard 0x-prefixed 40-char EVM address. */\nexport const HEX_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;\n/** 32-byte hash (UserOp hashes, tx hashes). */\nexport const HEX_HASH_REGEX = /^0x[0-9a-fA-F]{64}$/;\n/**\n * Stringified non-negative bigint (canonical decimal). Used by Zod\n * envelopes that must round-trip a `bigint` field through JSON without\n * losing precision — the wire shape is \"every digit, no scientific\n * notation, no leading sign\". Single source of truth so the SA-mode\n * direct-client envelopes (`OnChainBalanceSchema`, `MarketStateSchema`,\n * `QuoteSchema`) can't drift on what counts as a valid encoding.\n */\nexport const BIGINT_STRING_REGEX = /^\\d+$/;\n/**\n * Human USDC decimal: whole digits with up to 6 fractional digits.\n * Backs both the `validateUsdcDecimalShape` runtime check and the\n * `kash trade buy/sell --dry-run --json` envelope schema, so the\n * runtime parser and the JSON contract can't disagree on what\n * counts as a valid amount.\n */\nexport const USDC_DECIMAL_REGEX = /^\\d+(\\.\\d{1,6})?$/;\n\n/** Default slippage tolerance in basis points (50 = 0.5%). */\nexport const DEFAULT_SLIPPAGE_BPS = 50;\n/** ERC-20's `MAX_UINT256` — sentinel for \"infinite\" approval. */\nexport const MAX_UINT256 = 2n ** 256n - 1n;\n\n/**\n * Validate a market / spender / account address. Throws\n * `INVALID_INPUT` with the supplied field name (so the structured\n * error envelope's `check_input` action points at the right flag).\n */\nexport function validateAddress(value: string, field: string): `0x${string}` {\n if (!HEX_ADDRESS_REGEX.test(value)) {\n throw new CliValidationError(\n `<${field}> must be a 0x-prefixed 40-char hex address.`,\n `Got \"${value}\".`,\n field\n );\n }\n return value as `0x${string}`;\n}\n\n/**\n * Optional variant of {@link validateAddress}. Returns `undefined`\n * when the input is `undefined` (the common \"default to active\n * profile's account\" pattern); otherwise validates and returns the\n * narrowed type.\n */\nexport function validateAddressOptional(\n value: string | undefined,\n field: string\n): `0x${string}` | undefined {\n return value === undefined ? undefined : validateAddress(value, field);\n}\n\n/**\n * Strict-shape regex for unsigned integer flag values. Bare digits\n * only (with optional leading `+`). Anything else — `1.5`, `1e3`,\n * `0x10`, ` 42`, `42 `, `1 2` — must be rejected.\n *\n * Plain `Number.parseInt('1.5', 10)` returns `1` and\n * `Number.parseInt('1e3', 10)` returns `1` too. Both are silent\n * precision losses on inputs that look like real-money typos:\n * - `--outcome 1.5` would buy outcome 1 (wrong outcome).\n * - `--slippage-bps 1e3` would use 1 bps instead of 1000 (10%\n * slippage clipped to 0.01% — catastrophic).\n *\n * Every flag-parser in this module that consumes integers MUST\n * gate its `Number.parseInt` call on this regex.\n */\nconst UNSIGNED_INT_REGEX = /^\\+?\\d+$/;\n\n/**\n * Outcome index in `[0, 7]` (Pythagorean AMM ceiling — markets carry\n * 2-8 outcomes). Throws `INVALID_INPUT` on missing or out-of-range.\n */\nexport function parseOutcomeIndex(raw: string | undefined): number {\n if (raw === undefined) {\n throw new CliValidationError('--outcome is required.', undefined, 'outcome');\n }\n if (!UNSIGNED_INT_REGEX.test(raw)) {\n throw new CliValidationError(\n '--outcome must be an integer between 0 and 7.',\n `Got \"${raw}\". Pass digits only — no decimals (\\`1.5\\` would silently round to 1) or scientific notation.`,\n 'outcome'\n );\n }\n const n = Number.parseInt(raw, 10);\n if (!Number.isFinite(n) || n < 0 || n > 7) {\n throw new CliValidationError(\n '--outcome must be an integer between 0 and 7.',\n 'Markets carry 2-8 outcomes; the index is 0-based.',\n 'outcome'\n );\n }\n return n;\n}\n\n/**\n * `--side` parser shared by `kash protocol quote` and `kash eoa trade`.\n * Returns the canonical uppercase form (`'BUY' | 'SELL'`) the SDKs\n * expect. Case-insensitive on input.\n *\n * The lowercase variant (`'buy' | 'sell'`) used by the public-API\n * predictions feed (`kash markets predictions --side buy`) lives at\n * its sole call site — it has different semantics (filter rather\n * than execute) and routes through a separate API endpoint.\n */\nexport function parseUppercaseSide(raw: string, name = 'side'): 'BUY' | 'SELL' {\n const upper = raw.toUpperCase();\n if (upper !== 'BUY' && upper !== 'SELL') {\n throw new CliValidationError(\n `--${name} must be one of: BUY, SELL (case-insensitive).`,\n `Got \"${raw}\".`,\n name\n );\n }\n return upper;\n}\n\n/**\n * One-shot trade-execution side. SA mode (`kash protocol trade …`)\n * and EOA mode (`kash eoa trade …`) share this enum — `close` is the\n * \"sell my entire balance for outcome N\" sugar.\n */\nexport type TradeOpSide = 'buy' | 'sell' | 'close';\n\n/**\n * Slippage in basis points (0..10000 → 0%..100%).\n *\n * Strict integer shape: `parseInt('1e3', 10)` returns 1, which would\n * silently clip 10% slippage to 0.01% (catastrophic for any real\n * trade). The shape check rejects any non-bare-integer before the\n * range check runs.\n */\nexport function parseSlippageBps(raw: string): number {\n if (!UNSIGNED_INT_REGEX.test(raw)) {\n throw new CliValidationError(\n '--slippage-bps must be an integer between 0 and 10000.',\n `Got \"${raw}\". Pass digits only — \\`1e3\\` would silently parse as 1 (0.01%) instead of 1000 (10%).`,\n 'slippage-bps'\n );\n }\n const n = Number.parseInt(raw, 10);\n if (!Number.isFinite(n) || n < 0 || n > 10_000) {\n throw new CliValidationError(\n '--slippage-bps must be an integer between 0 and 10000.',\n `Got \"${raw}\". 50 = 0.5%, 100 = 1%, 10000 = 100%.`,\n 'slippage-bps'\n );\n }\n return n;\n}\n\n/**\n * Unix-seconds deadline as a bigint. Caps the value at\n * `Number.MAX_SAFE_INTEGER` to catch the common ms-vs-sec confusion\n * (a JS `Date.now()` value passed verbatim would overflow into the\n * year 50000+ AD, which the AMM treats as \"no deadline\" and is\n * indistinguishable from the user's intent).\n */\nexport function parseDeadlineSec(raw: string): bigint {\n let parsed: bigint;\n try {\n parsed = BigInt(raw);\n } catch {\n throw new CliValidationError(\n '--deadline-sec must be a unix timestamp in seconds.',\n `Got \"${raw}\".`,\n 'deadline-sec'\n );\n }\n if (parsed <= 0n) {\n throw new CliValidationError(\n '--deadline-sec must be positive.',\n `Got \"${raw}\".`,\n 'deadline-sec'\n );\n }\n // Sanity check: the largest value that fits in a JS safe integer is\n // ~9e15. Anything above that is almost certainly the user passing\n // milliseconds instead of seconds, and `Number(parsed)` would lose\n // precision in downstream code.\n if (parsed > BigInt(Number.MAX_SAFE_INTEGER)) {\n throw new CliValidationError(\n '--deadline-sec is impossibly far in the future.',\n `Got ${String(parsed)}. Did you pass milliseconds by mistake? Convert to seconds first.`,\n 'deadline-sec'\n );\n }\n return parsed;\n}\n\n/**\n * Validate that a string is a well-formed USDC decimal (whole or up\n * to 6 fractional digits). Used by call sites that need the\n * shape check but pass the raw string downstream rather than\n * converting to atomic units (e.g. `kash trade buy/sell` ships the\n * decimal verbatim to the public-API SDK, which handles atomic\n * conversion server-side).\n */\nexport function validateUsdcDecimalShape(decimal: string, name: string): void {\n if (!USDC_DECIMAL_REGEX.test(decimal)) {\n throw new CliValidationError(\n `--${name} must be a USDC decimal with up to 6 fractional digits.`,\n `Got \"${decimal}\". USDC accepts up to 6 fractional digits (e.g. \"10\", \"12.50\", \"0.000001\").`,\n name\n );\n }\n}\n\n/**\n * Generic partial-completion hash extractor. SA-mode and EOA-mode\n * trade runners catch SDK errors that may carry an already-landed\n * hash (`userOpHash` for SA, `transactionHash` for EOA) in the\n * cause's `context` field — we surface that hash so the operator\n * can resume rather than pay for a duplicate sign/submit cycle.\n *\n * **Discrimination matters here.** Multiple SDK error classes\n * populate `context.<hash>` with the same shape, so we narrow on\n * the SDK's own `code` enum first:\n *\n * - SA mode: `code === 'BUNDLER_RECEIPT_TIMEOUT'` (genuine partial\n * completion — submit succeeded, wait timed out). Other SA\n * errors like `KashSignerError` (`SIGNER_SIGN_FAILED`) ALSO\n * carry `context.userOpHash` but happen pre-submit, so reporting\n * them as partial completions would be actively misleading.\n * - EOA mode: `code === 'WAIT_RECEIPT_FAILED'` (post-submit wait\n * timeout). Other `KashChainError` variants like\n * `CHAIN_RPC_FAILED` carry no transactionHash and would fail\n * the `contextKey` lookup anyway, but the code-narrow catches\n * them earlier.\n *\n * The `cause` argument is `unknown` because it crosses the SDK ↔\n * CLI boundary; reads are defensive at every step.\n */\nexport function extractPartialHash(\n cause: unknown,\n options: { code: string; contextKey: 'userOpHash' | 'transactionHash' }\n): `0x${string}` | undefined {\n if (cause === null || typeof cause !== 'object') return undefined;\n const code = (cause as { code?: unknown }).code;\n if (code !== options.code) return undefined;\n const ctx = (cause as { context?: unknown }).context;\n if (ctx === null || typeof ctx !== 'object') return undefined;\n const hash = (ctx as Record<string, unknown>)[options.contextKey];\n return typeof hash === 'string' && HEX_HASH_REGEX.test(hash)\n ? (hash as `0x${string}`)\n : undefined;\n}\n\n/**\n * Convert a USDC decimal string (`\"10\"`, `\"12.50\"`, `\"0.000001\"`)\n * to the 6-decimal atomic representation the AMM expects.\n *\n * Rejects strings with more than 6 fractional digits — silently\n * truncating could lose precision the user expected to preserve.\n */\nexport function decimalToAtomicUsdc(decimal: string, name: string): bigint {\n validateUsdcDecimalShape(decimal, name);\n const [whole, frac = ''] = decimal.split('.');\n const fracPadded = frac.padEnd(6, '0');\n return BigInt(`${whole}${fracPadded}`);\n}\n\n/**\n * Convert a token decimal string (`\"1.5\"`, `\"0.0001\"`) to WAD-18\n * atomic units. Outcome tokens use 18-decimal precision throughout\n * the protocol.\n */\nexport function decimalToAtomicWad(decimal: string, name: string): bigint {\n if (!/^\\d+(\\.\\d{1,18})?$/.test(decimal)) {\n throw new CliValidationError(\n `--${name} must be a token decimal with up to 18 fractional digits.`,\n `Got \"${decimal}\". Outcome tokens use WAD-18 precision.`,\n name\n );\n }\n const [whole, frac = ''] = decimal.split('.');\n const fracPadded = frac.padEnd(18, '0');\n return BigInt(`${whole}${fracPadded}`);\n}\n"],"mappings":";;;;;;AA6BO,IAAM,oBAAoB;AAE1B,IAAM,iBAAiB;AASvB,IAAM,sBAAsB;AAQ5B,IAAM,qBAAqB;AAG3B,IAAM,uBAAuB;AAE7B,IAAM,cAAc,MAAM,OAAO;AAOjC,SAAS,gBAAgB,OAAe,OAA8B;AAC3E,MAAI,CAAC,kBAAkB,KAAK,KAAK,GAAG;AAClC,UAAM,IAAI;AAAA,MACR,IAAI,KAAK;AAAA,MACT,QAAQ,KAAK;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAQO,SAAS,wBACd,OACA,OAC2B;AAC3B,SAAO,UAAU,SAAY,SAAY,gBAAgB,OAAO,KAAK;AACvE;AAiBA,IAAM,qBAAqB;AAMpB,SAA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AAI,GAAG;AACtC,SAAO,OAAO,GAAG,KAAK,GAAG,UAAU,EAAE;AACvC;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils/custom-chain.ts","../src/utils/signer-key.ts"],"sourcesContent":["/**\n * Translate the CLI's profile-level `customChain` config into the\n * `@kashdao/protocol-sdk` `CustomChain` shape (viem chain + protocol\n * addresses + optional smart-account factory config).\n *\n * The CLI never asks the user to hand-construct a viem Chain object —\n * we synthesise one from the profile's `defaultChainId + rpcUrl +\n * customChain.name`, matching what the\n * `packages/protocol-sdk/examples/local-anvil/` quickstarts do inline.\n *\n * This is the only place in the CLI that imports `viem.defineChain`.\n * The dynamic import keeps viem off the cold-start path for non-direct\n * commands (markets list / trade buy / portfolio / health all skip\n * this module).\n *\n * @module utils/custom-chain\n */\n\nimport { CliError, EXIT_CODES } from '../errors.js';\n\nimport type { CliConfig } from './config-store.js';\nimport type { CustomChain } from '@kashdao/protocol-sdk';\n\nexport type ResolveCustomChainOptions = {\n /** The profile's `customChain` block — required, validated by Zod upstream. */\n readonly customChain: NonNullable<CliConfig['customChain']>;\n /**\n * `defaultChainId` from the profile. Required at the call site (the\n * caller raises `DIRECT_CONFIG_MISSING` if missing) — we accept it\n * non-optional here so this helper is total.\n */\n readonly chainId: number;\n /**\n * RPC URL used to construct the viem chain's `rpcUrls.default.http`.\n * Same URL the CLI passes as the SDK's `rpc` field — duplicated\n * because the viem chain object carries its own RPC array for any\n * downstream callers that read from `chain.rpcUrls` rather than the\n * `transport`.\n */\n readonly rpc: string;\n};\n\n/**\n * Materialise a CustomChain. Use it like:\n *\n * ```ts\n * const customChain = await resolveCliCustomChain({ customChain, chainId, rpc });\n * createEoaClient({ ..., customChain });\n * ```\n *\n * The viem chain is given `Ether` as the native currency by default —\n * which is correct for every chain the protocol-sdk supports today\n * (Base + Anvil derivatives). If we ever launch on a chain whose\n * native currency isn't ETH-shaped, surface that as a separate\n * `customChain.nativeCurrency` config field; for now the constant\n * keeps the config minimal.\n */\nexport async function resolveCliCustomChain(opts: ResolveCustomChainOptions): Promise<CustomChain> {\n const { customChain, chainId, rpc } = opts;\n\n // Required-at-use validation. The persisted schema marks every field\n // optional so `kash config set customChain.<leaf>` can build the\n // object up one leaf at a time. The SDK's CustomChain shape requires\n // `name + addresses.factory + addresses.usdc`. We surface the\n // missing field here, where the consumer just tried to run an\n // `eoa`/`protocol` command, with the exact `kash config set` line\n // they need to fix it.\n if (customChain.name === undefined) {\n throw missingCustomChainField(\n 'customChain.name',\n '`kash config set customChain.name \"Anvil local\"` (or whatever label you want surfaced on client.addresses.name)'\n );\n }\n if (customChain.factoryAddress === undefined) {\n throw missingCustomChainField(\n 'customChain.factoryAddress',\n '`kash config set customChain.factoryAddress 0x…` (the deployed Kash factory address on this chain)'\n );\n }\n if (customChain.usdcAddress === undefined) {\n throw missingCustomChainField(\n 'customChain.usdcAddress',\n '`kash config set customChain.usdcAddress 0x…` (the deployed USDC token address on this chain)'\n );\n }\n\n // Smart-account triple is all-or-nothing — surfacing each missing\n // leaf separately is more actionable than \"smartAccount is incomplete\".\n let smartAccount: CustomChain['smartAccount'];\n if (customChain.smartAccount !== undefined) {\n const sa = customChain.smartAccount;\n if (\n sa.factoryAddress !== undefined ||\n sa.implementationAddress !== undefined ||\n sa.entryPointAddress !== undefined\n ) {\n if (sa.factoryAddress === undefined) {\n throw missingCustomChainField(\n 'customChain.smartAccount.factoryAddress',\n '`kash config set customChain.smartAccount.factoryAddress 0x…`'\n );\n }\n if (sa.implementationAddress === undefined) {\n throw missingCustomChainField(\n 'customChain.smartAccount.implementationAddress',\n '`kash config set customChain.smartAccount.implementationAddress 0x…`'\n );\n }\n if (sa.entryPointAddress === undefined) {\n throw missingCustomChainField(\n 'customChain.smartAccount.entryPointAddress',\n '`kash config set customChain.smartAccount.entryPointAddress 0x…`'\n );\n }\n smartAccount = {\n factoryAddress: sa.factoryAddress as `0x${string}`,\n implementationAddress: sa.implementationAddress as `0x${string}`,\n entryPointAddress: sa.entryPointAddress as `0x${string}`,\n };\n }\n }\n\n // Lazy-load viem so this module's import doesn't drag viem onto the\n // non-direct command paths. Same firewall pattern as the\n // `eoa-client.ts` / `direct-client.ts` `await import('@kashdao/protocol-sdk')`.\n const { defineChain } = await import('viem');\n\n return {\n name: customChain.name,\n viemChain: defineChain({\n id: chainId,\n name: customChain.name,\n nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },\n rpcUrls: { default: { http: [rpc] } },\n }),\n addresses: {\n factory: customChain.factoryAddress as `0x${string}`,\n usdc: customChain.usdcAddress as `0x${string}`,\n ...(customChain.oracleAddress === undefined\n ? {}\n : { oracle: customChain.oracleAddress as `0x${string}` }),\n ...(customChain.vaultAddress === undefined\n ? {}\n : { vault: customChain.vaultAddress as `0x${string}` }),\n ...(customChain.tokens1155Address === undefined\n ? {}\n : { tokens1155: customChain.tokens1155Address as `0x${string}` }),\n ...(customChain.paramRegistryAddress === undefined\n ? {}\n : { paramRegistry: customChain.paramRegistryAddress as `0x${string}` }),\n },\n ...(smartAccount === undefined ? {} : { smartAccount }),\n };\n}\n\nfunction missingCustomChainField(field: string, hint: string): CliError {\n return new CliError(`Custom-chain config missing: ${field}.`, {\n code: 'DIRECT_CONFIG_MISSING',\n exitCode: EXIT_CODES.GENERIC,\n suggestion: `Set ${field} via ${hint}.`,\n actions: [\n {\n type: 'check_input',\n field,\n description: hint,\n },\n ],\n });\n}\n","/**\n * Shared `signerKeyRef` resolution for direct-mode + EOA-mode clients.\n *\n * Both modes pull the EOA's private key from the same place:\n *\n * - `file:<absolute-path>` — read a 0x-prefixed hex key from disk.\n * On POSIX, the file mode is checked and\n * a warning is emitted (but the load is\n * not refused) if the file is readable\n * by group or other — the same discipline\n * as ssh / aws-cli warning on\n * `~/.ssh/id_rsa` permissions, but\n * non-fatal because a CI runner may\n * legitimately stage keys with broader\n * modes inside an ephemeral container.\n * - `env:<NAME>` — read a 0x-prefixed hex key from a\n * process env var. (No mode check\n * applies — the OS does not expose\n * env-var ACLs.)\n *\n * The CLI never persists raw keys (the config schema only stores the\n * reference, not the key itself). This helper validates the format\n * and resolves the raw bytes; the caller wraps them in the right\n * adapter for its mode (`viemAccountSigner` for SA UserOps,\n * `viemAccountEoaSigner` for vanilla EIP-1559 txs).\n *\n * Centralised so the SA and EOA paths can never drift on the\n * file/env reading, hex validation, or error wording — drift here is\n * a real-money risk.\n */\n\nimport { readFile, stat } from 'node:fs/promises';\n\nimport { CliError } from '../errors.js';\n\nimport { log } from './output.js';\n\n/** 0x-prefixed 32-byte hex private key. */\nexport type RawPrivateKey = `0x${string}`;\n\n/** Loosely-typed regex for a private key — not a cryptographic check. */\nconst PRIVATE_KEY_REGEX = /^0x[0-9a-fA-F]{64}$/;\n\n/**\n * Resolve a `signerKeyRef` to its raw 0x-prefixed hex private key.\n * Throws `CliError(SIGNER_FAILED)` for every failure mode (missing\n * scheme, missing file/env, malformed key) so callers get a uniform\n * structured envelope.\n */\nexport async function loadRawPrivateKey(ref: string | undefined): Promise<RawPrivateKey> {\n if (!ref) {\n throw new CliError('signerKeyRef is required.', {\n code: 'SIGNER_FAILED',\n suggestion:\n '`kash config set signerKeyRef file:<path>` or `env:<NAME>` (CLI never persists raw keys).',\n });\n }\n\n const [scheme, ...rest] = ref.split(':');\n const target = rest.join(':');\n\n let rawKey: string;\n if (scheme === 'file') {\n if (target === '') {\n throw new CliError('signerKeyRef: file path is empty.', {\n code: 'SIGNER_FAILED',\n suggestion: 'Use `signerKeyRef = file:<absolute-path>` with a path to the private key.',\n });\n }\n try {\n rawKey = (await readFile(target, 'utf8')).trim();\n } catch (cause) {\n throw new CliError(`signerKeyRef: failed to read ${target}.`, {\n code: 'SIGNER_FAILED',\n suggestion: 'Verify the file exists, is readable, and contains a 0x-prefixed hex key.',\n cause,\n });\n }\n await warnIfWorldReadable(target);\n } else if (scheme === 'env') {\n if (target === '') {\n throw new CliError('signerKeyRef: env variable name is empty.', {\n code: 'SIGNER_FAILED',\n suggestion: 'Use `signerKeyRef = env:<NAME>` referencing an environment variable.',\n });\n }\n const fromEnv = process.env[target];\n if (!fromEnv) {\n throw new CliError(`signerKeyRef: environment variable ${target} is not set or empty.`, {\n code: 'SIGNER_FAILED',\n suggestion: `Set ${target} to a 0x-prefixed hex private key, or rotate to a file:<path> reference.`,\n });\n }\n rawKey = fromEnv.trim();\n } else {\n throw new CliError(`signerKeyRef: unknown scheme \"${scheme ?? ''}\".`, {\n code: 'SIGNER_FAILED',\n suggestion: 'Supported schemes: `file:<path>`, `env:<NAME>`.',\n });\n }\n\n if (!PRIVATE_KEY_REGEX.test(rawKey)) {\n throw new CliError('signerKeyRef target is not a 0x-prefixed 32-byte hex private key.', {\n code: 'SIGNER_FAILED',\n suggestion: 'The key must be exactly 0x followed by 64 hex characters (32 bytes).',\n });\n }\n\n return rawKey as RawPrivateKey;\n}\n\n/**\n * POSIX-only: warn (don't refuse) if the key file is readable by\n * group or other. Mirrors ssh / aws-cli's \"you should `chmod 600`\"\n * banner on `~/.ssh/id_rsa`. Skipped on Windows (no-op) because\n * Windows uses ACLs rather than POSIX modes — `mode & 0o077` is\n * meaningless. Skipped on stat failure because we just successfully\n * read the file; the stat is purely advisory.\n */\nasync function warnIfWorldReadable(path: string): Promise<void> {\n if (process.platform === 'win32') return;\n let mode: number;\n try {\n const info = await stat(path);\n mode = info.mode;\n } catch {\n return; // advisory only — we already loaded the key successfully\n }\n // Lower 9 bits are rwxrwxrwx. Group + other read bits are 0o044.\n // Lower 6 bits (group + other rwx) are 0o077 — anything set in\n // those positions means somebody other than the owner can touch\n // the key.\n if ((mode & 0o077) !== 0) {\n log.warn(\n `signerKeyRef file mode is 0${(mode & 0o777).toString(8)} (group/other readable). ` +\n `Run \\`chmod 600 ${path}\\` to restrict access. (warning only — load succeeded.)`\n );\n }\n}\n"],"mappings":";;;;;;;;;;AAyDA,eAAsB,sBAAsB,MAAuD;AACjG,QAAM,EAAE,aAAa,SAAS,IAAI,IAAI;AAStC,MAAI,YAAY,SAAS,QAAW;AAClC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BAAoB,MAAM;AAAA,EAClC,WAAW,WAAW,OAAO;AAC3B,QAAI,WAAW,IAAI;AACjB,YAAM,IAAI,SAAS,6CAA6C;AAAA,QAC9D,MAAM;AAAA,QACN,YAAY;AAAA,MACd,CAAC;AAAA,IACH;AACA,UAAM,UAAU,QAAQ,IAAI,MAAM;AAClC,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI,SAAS,sCAAsC,MAAM,yBAAyB;AAAA,QACtF,MAAM;AAAA,QACN,YAAY,OAAO,MAAM;AAAA,MAC3B,CAAC;AAAA,IACH;AACA,aAAS,QAAQ,KAAK;AAAA,EACxB,OAAO;AACL,UAAM,IAAI,SAAS,iCAAiC,UAAU,EAAE,MAAM;AAAA,MACpE,MAAM;AAAA,MACN,YAAY;AAAA,IACd,CAAC;AAAA,EACH;AAEA,MAAI,CAAC,kBAAkB,KAAK,MAAM,GAAG;AACnC,UAAM,IAAI,SAAS,qEAAqE;AAAA,MACtF,MAAM;AAAA,MACN,YAAY;AAAA,IACd,CAAC;AAAA,EACH;AAEA,SAAO;AACT;AAUA,eAAe,oBAAoB,MAA6B;AAC9D,MAAI,QAAQ,aAAa,QAAS;AAClC,MAAI;AACJ,MAAI;AACF,UAAM,OAAO,MAAM,KAAK,IAAI;AAC5B,WAAO,KAAK;AAAA,EACd,QAAQ;AACN;AAAA,EACF;AAKA,OAAK,OAAO,QAAW,GAAG;AACxB,QAAI;AAAA,MACF,+BAA+B,OAAO,KAAO,SAAS,CAAC,CAAC,4CACnC,IAAI;AAAA,IAC3B;AAAA,EACF;AACF;","names":[]}
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- buildClient
4
- } from "./chunk-QJMF73M5.js";
5
- import "./chunk-KMBMQIZ7.js";
6
- import "./chunk-YHCG2SUC.js";
7
- import "./chunk-BN2CUM42.js";
8
- import "./chunk-VIADBYFY.js";
9
- import "./chunk-MIXOZU2S.js";
10
- import "./chunk-UZNSYATZ.js";
11
- export {
12
- buildClient
13
- };
14
- //# sourceMappingURL=client-IOM55ZCS.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/commands/config/index.ts","../src/commands/config/export.ts","../src/commands/config/import.ts","../src/commands/config/profiles.ts","../src/commands/config/remove.ts","../src/commands/config/reset.ts","../src/commands/config/set.ts","../src/commands/config/show.ts","../src/commands/config/use.ts"],"sourcesContent":["/**\n * `kash config` — inspect and edit the local CLI configuration.\n */\n\nimport { Command } from 'commander';\n\nimport { exportConfigCommand } from './export.js';\nimport { importConfigCommand } from './import.js';\nimport { profilesCommand } from './profiles.js';\nimport { removeProfileCommand } from './remove.js';\nimport { resetConfigCommand } from './reset.js';\nimport { setConfigCommand } from './set.js';\nimport { showConfigCommand } from './show.js';\nimport { useProfileCommand } from './use.js';\n\nexport const configCommand = new Command('config')\n .description('Inspect and edit ~/.kash/config.json (multi-profile).')\n .addCommand(showConfigCommand)\n .addCommand(setConfigCommand)\n .addCommand(profilesCommand)\n .addCommand(useProfileCommand)\n .addCommand(removeProfileCommand)\n .addCommand(resetConfigCommand)\n .addCommand(exportConfigCommand)\n .addCommand(importConfigCommand);\n","/**\n * `kash config export` — dump the entire multi-profile config to\n * stdout (or a file via `--out`).\n *\n * **Default redaction.** API keys are replaced with the literal string\n * `<redacted>` so the dump is safe to commit to a shared bucket or\n * paste into a support ticket. Pass `--include-secrets` to opt into\n * round-trippable export (e.g. moving a profile to a new machine).\n *\n * **Round-trip pairing.** Output of this command is the canonical\n * input for `kash config import`. The file format mirrors the\n * on-disk shape: `{ version: 1, currentProfile, profiles: {...} }`.\n */\n\nimport { writeFile } from 'node:fs/promises';\n\nimport { Command } from 'commander';\n\nimport { CliError, toCliError } from '../../errors.js';\nimport { readWholeFile, type CliFile, type CliConfig } from '../../utils/config-store.js';\nimport { readGlobals } from '../../utils/global-options.js';\nimport { log, print, printJson } from '../../utils/output.js';\n\nconst REDACTED = '<redacted>';\n\ntype ExportOptions = {\n out?: string;\n includeSecrets?: boolean;\n};\n\nexport const exportConfigCommand = new Command('export')\n .description('Dump the entire multi-profile config (API keys redacted by default).')\n .option('-o, --out <path>', 'write to a file instead of stdout (mode 0600)')\n .option('--include-secrets', 'include raw API keys in the export (round-trippable)')\n .addHelpText(\n 'after',\n `\nExamples:\n $ kash config export # safe-by-default; redacted JSON to stdout\n $ kash config export --out kash-config.json # write to a file (mode 0600)\n $ kash config export --include-secrets --out kash.json # round-trippable (DO NOT commit)\n\nNotes:\n - Without --include-secrets, every \\`apiKey\\` is replaced with \\`${REDACTED}\\` —\n safe to commit and share for debugging without leaking credentials.\n - The output is the canonical input for \\`kash config import\\`. Imports\n refuse to apply a profile whose apiKey is still \\`${REDACTED}\\`.\n - Use --out to route to a file the CLI can write at mode 0600. Stdout\n inherits whatever umask the parent shell has.\n`\n )\n .action(async (options: ExportOptions, cmd: Command) => {\n const globals = readGlobals(cmd);\n try {\n const file = await readWholeFile({\n ...(globals.configPath === undefined ? {} : { configPath: globals.configPath }),\n });\n\n // Walk every profile and redact apiKey unless the caller asked\n // to include secrets. Other direct-mode fields (rpcUrl,\n // smartAccount, bundlerUrl, signerKeyRef) are kept as-is —\n // they're configuration, not secrets. Raw private keys never\n // live in the config (signerKeyRef is a `file:`/`env:` pointer).\n const sanitized: CliFile = {\n ...file,\n profiles: Object.fromEntries(\n Object.entries(file.profiles).map(([name, profile]) => [\n name,\n sanitizeProfile(profile, options.includeSecrets ?? false),\n ])\n ),\n };\n\n const payload = JSON.stringify(sanitized, null, 2);\n\n if (options.out) {\n try {\n await writeFile(options.out, `${payload}\\n`, { encoding: 'utf8', mode: 0o600 });\n if (!globals.json) {\n log.success(`Wrote ${options.out} (mode 0600).`);\n if (!options.includeSecrets) {\n log.info(\n `Secrets redacted. Pass --include-secrets to produce a round-trippable export.`\n );\n }\n }\n } catch (cause) {\n throw new CliError(`Failed to write ${options.out}.`, {\n code: 'CONFIGURATION',\n recoverable: true,\n suggestion: 'Verify the path is writable and the parent directory exists.',\n cause,\n });\n }\n return;\n }\n\n // No --out: dump JSON to stdout. Honor --json by emitting the\n // file shape (same payload, but routed through printJson so\n // pretty/compact respects --quiet). Without --json we still emit\n // JSON because that's the only sensible export format — but skip\n // the human-mode banner.\n if (globals.json) {\n printJson(sanitized);\n } else {\n // Plain stdout. Append a header to stderr (so it doesn't\n // pollute the JSON pipe) noting the redaction policy.\n if (!options.includeSecrets) {\n log.info(`API keys redacted. Pass --include-secrets for round-trippable export.`);\n }\n print(payload);\n }\n } catch (cause) {\n throw toCliError(cause);\n }\n });\n\nfunction sanitizeProfile(profile: CliConfig, includeSecrets: boolean): CliConfig {\n if (includeSecrets) return profile;\n if (profile.apiKey === undefined) return profile;\n // Use a marker the importer can detect; real keys never collide\n // because they all start with `kash_`.\n return { ...profile, apiKey: REDACTED };\n}\n\nexport { REDACTED as REDACTED_API_KEY_MARKER };\n","/**\n * `kash config import` — merge a config bundle (produced by\n * `kash config export`) into the local config file.\n *\n * **Source.** Reads from `<file>` argument, or stdin when no argument\n * is given. The input must match the v1 file shape; anything else is\n * rejected as INVALID_INPUT.\n *\n * **Merge policy.** Profiles in the imported file are merged into the\n * existing profiles map. By default, existing profiles with the same\n * name are OVERWRITTEN. Pass `--no-overwrite` to skip those — useful\n * when restoring a backup against a partial config.\n *\n * **Redaction guard.** Profiles whose `apiKey` is still the literal\n * marker (`<redacted>` from `config export` without\n * `--include-secrets`) are refused with a clear error. We don't want\n * to silently overwrite a working key with a placeholder string.\n *\n * **currentProfile.** If the imported file specifies a\n * `currentProfile`, we use it — but only if that profile actually\n * lands in the merged file. Otherwise we keep the existing\n * `currentProfile` unchanged.\n */\n\nimport { readFile } from 'node:fs/promises';\n\nimport { Command } from 'commander';\n\nimport { CliError, toCliError } from '../../errors.js';\nimport {\n cliFileSchema,\n readWholeFile,\n writeWholeFile,\n type CliFile,\n type CliConfig,\n} from '../../utils/config-store.js';\nimport { readGlobals } from '../../utils/global-options.js';\nimport { log, print, printJson, style } from '../../utils/output.js';\n\nimport { REDACTED_API_KEY_MARKER } from './export.js';\n\ntype ImportOptions = {\n // Commander stores `--no-overwrite` as `{ overwrite: false }` —\n // the default for a `--no-X` boolean option is `true`, so the\n // explicit `false` means the user passed `--no-overwrite`.\n overwrite?: boolean;\n dryRun?: boolean;\n};\n\nexport const importConfigCommand = new Command('import')\n .description('Merge a `kash config export` bundle into the local config (mode 0600).')\n .argument('[file]', 'path to a JSON bundle (omit to read from stdin)')\n .option('--no-overwrite', 'skip profiles whose name already exists locally')\n .option('--dry-run', 'preview the merge without writing to disk')\n .addHelpText(\n 'after',\n `\nExamples:\n $ kash config import kash.json\n $ kash config export --include-secrets | ssh prod-host kash config import\n $ kash config import kash.json --no-overwrite # never replace existing profiles\n $ kash config import kash.json --dry-run --json # preview the merged result\n\nNotes:\n - The input format is exactly what \\`kash config export\\` produces.\n - Profiles whose apiKey is still \\`${REDACTED_API_KEY_MARKER}\\` are refused — re-export\n with --include-secrets to get a round-trippable bundle.\n - --dry-run emits the merged file shape without persisting it. Useful\n for diffing against the on-disk file before committing to a write.\n`\n )\n .action(async (file: string | undefined, options: ImportOptions, cmd: Command) => {\n const globals = readGlobals(cmd);\n try {\n const raw = await readSource(file);\n // Redaction check runs first on the raw JSON so users get the\n // \"you exported without --include-secrets\" message rather than\n // a generic schema-validation error (because `<redacted>`\n // doesn't match the `kash_` prefix the schema enforces).\n validateRedactionRaw(raw);\n const parsed = parseAndValidate(raw);\n\n const existing = await readWholeFile({\n ...(globals.configPath === undefined ? {} : { configPath: globals.configPath }),\n });\n const merged = mergeFiles(existing, parsed, options.overwrite === false);\n\n if (options.dryRun === true) {\n if (globals.json) {\n printJson({ merged, written: false });\n } else {\n log.info('Dry run — no changes written.');\n print(JSON.stringify(merged, null, 2));\n }\n return;\n }\n\n await writeWholeFile(merged, {\n ...(globals.configPath === undefined ? {} : { configPath: globals.configPath }),\n });\n\n if (globals.json) {\n printJson({\n merged,\n written: true,\n profiles: Object.keys(merged.profiles).sort(),\n currentProfile: merged.currentProfile ?? null,\n });\n return;\n }\n\n const importedNames = Object.keys(parsed.profiles);\n const merged_n = Object.keys(merged.profiles).length;\n log.success(\n `Imported ${String(importedNames.length)} profile(s); local config now has ${String(merged_n)} profile(s).`\n );\n if (merged.currentProfile) {\n log.info(`Active profile: ${style.bold(merged.currentProfile)}`);\n }\n } catch (cause) {\n throw toCliError(cause);\n }\n });\n\nasync function readSource(file: string | undefined): Promise<string> {\n if (file !== undefined) {\n try {\n return await readFile(file, 'utf8');\n } catch (cause) {\n throw new CliError(`Failed to read ${file}.`, {\n code: 'CONFIGURATION',\n recoverable: true,\n suggestion: 'Verify the path exists and is readable.',\n cause,\n });\n }\n }\n // No file: read from stdin. process.stdin is async iterable in Node 22+.\n const chunks: Buffer[] = [];\n for await (const chunk of process.stdin) {\n // process.stdin emits Buffer in binary streams and string in\n // text mode; coerce both into Buffer so concat is well-typed.\n if (typeof chunk === 'string') {\n chunks.push(Buffer.from(chunk));\n } else if (chunk instanceof Buffer) {\n chunks.push(chunk);\n } else {\n chunks.push(Buffer.from(chunk as Uint8Array));\n }\n }\n if (chunks.length === 0) {\n throw new CliError('No input received on stdin.', {\n code: 'INVALID_INPUT',\n recoverable: true,\n suggestion: 'Pass a path argument or pipe a `kash config export` bundle into stdin.',\n });\n }\n // Strip a leading UTF-8 BOM. Notepad / VSCode-with-utf8bom and many\n // Windows tools prepend U+FEFF to UTF-8 files; without the strip,\n // `JSON.parse` chokes on the leading non-whitespace character.\n const { stripBom } = await import('../../utils/stdin.js');\n return stripBom(Buffer.concat(chunks).toString('utf8'));\n}\n\nfunction parseAndValidate(raw: string): CliFile {\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (cause) {\n throw new CliError('Input is not valid JSON.', {\n code: 'INVALID_INPUT',\n recoverable: true,\n suggestion:\n 'The bundle must match the output of `kash config export`. Re-run that command and pipe the result.',\n cause,\n });\n }\n const result = cliFileSchema.safeParse(parsed);\n if (!result.success) {\n const first = result.error.issues[0];\n throw new CliError(\n `Input does not match the config file shape${\n first ? `: ${first.path.join('.')}: ${first.message}` : '.'\n }`,\n {\n code: 'INVALID_INPUT',\n recoverable: true,\n suggestion: 'Re-export from a known-good machine via `kash config export`.',\n }\n );\n }\n return result.data;\n}\n\n/**\n * Cheap raw-text scan for the redaction marker before strict schema\n * validation runs. The marker is a literal sentinel that real API\n * keys can't collide with (real keys start with `kash_`), so a\n * substring check is safe.\n */\nfunction validateRedactionRaw(raw: string): void {\n if (raw.includes(`\"apiKey\": \"${REDACTED_API_KEY_MARKER}\"`)) {\n throw new CliError('Bundle contains redacted API keys — cannot import.', {\n code: 'INVALID_INPUT',\n recoverable: true,\n suggestion:\n 'Re-run `kash config export --include-secrets` on the source machine to produce a round-trippable bundle.',\n });\n }\n}\n\nfunction mergeFiles(existing: CliFile, incoming: CliFile, noOverwrite: boolean): CliFile {\n const profiles: Record<string, CliConfig> = { ...existing.profiles };\n for (const [name, profile] of Object.entries(incoming.profiles)) {\n if (noOverwrite && name in profiles) continue;\n profiles[name] = profile;\n }\n\n // Decide currentProfile: incoming wins only if it points at a real\n // profile post-merge. Otherwise keep the existing setting.\n let currentProfile = existing.currentProfile;\n if (incoming.currentProfile && incoming.currentProfile in profiles) {\n currentProfile = incoming.currentProfile;\n }\n\n return {\n version: 1,\n ...(currentProfile === undefined ? {} : { currentProfile }),\n profiles,\n };\n}\n","/**\n * `kash config profiles` — list every profile in the config file.\n */\n\nimport { Command } from 'commander';\n\nimport { toCliError } from '../../errors.js';\nimport { listProfiles } from '../../utils/config-store.js';\nimport { createTable } from '../../utils/formatting.js';\nimport { readGlobals } from '../../utils/global-options.js';\nimport { log, print, printJson, style } from '../../utils/output.js';\n\nexport const profilesCommand = new Command('profiles')\n .description('List configured profiles in the config file.')\n .addHelpText(\n 'after',\n `\nExamples:\n $ kash config profiles\n $ kash config profiles --json --quiet | jq -r '.profiles[]'\n`\n )\n .action(async (_opts, cmd: Command) => {\n const globals = readGlobals(cmd);\n let result;\n try {\n result = await listProfiles({\n ...(globals.configPath === undefined ? {} : { configPath: globals.configPath }),\n });\n } catch (cause) {\n throw toCliError(cause);\n }\n\n if (globals.json) {\n printJson(result);\n return;\n }\n\n if (result.profiles.length === 0) {\n log.info('No profiles configured.');\n log.detail('Hint', \"Run 'kash auth set-key <key>' to create the default profile.\");\n return;\n }\n\n const table = createTable(['Active', 'Profile']);\n for (const name of result.profiles) {\n table.push([name === result.current ? style.success('•') : ' ', name]);\n }\n print(table.toString());\n });\n","/**\n * `kash config remove <profile>` — delete a named profile from the\n * config file. Refuses to delete the active profile (consistent with\n * `kash auth logout` which only clears the apiKey).\n *\n * Symmetric with `kash config use` and `kash config profiles`: every\n * write surface a multi-profile setup needs is now a first-class\n * command.\n */\n\nimport { Command } from 'commander';\n\nimport { toCliError } from '../../errors.js';\nimport { deleteProfile } from '../../utils/config-store.js';\nimport { readGlobals } from '../../utils/global-options.js';\nimport { log, printJson } from '../../utils/output.js';\n\nexport const removeProfileCommand = new Command('remove')\n .description('Delete a named profile from the config file.')\n .argument('<profile>', 'profile name to remove')\n .addHelpText(\n 'after',\n `\nExamples:\n $ kash config remove staging\n $ kash config remove old-profile --json --quiet\n`\n )\n .action(async (profile: string, _opts, cmd: Command) => {\n const globals = readGlobals(cmd);\n let updated;\n try {\n updated = await deleteProfile(profile, {\n ...(globals.configPath === undefined ? {} : { configPath: globals.configPath }),\n });\n } catch (cause) {\n throw toCliError(cause);\n }\n\n if (globals.json) {\n printJson({\n ok: true,\n removed: profile,\n profiles: Object.keys(updated.profiles).sort(),\n });\n return;\n }\n log.success(`Profile \"${profile}\" removed.`);\n });\n","/**\n * `kash config reset` — delete the on-disk config file.\n *\n * Asks for confirmation when stdin is a TTY (the common interactive\n * case). In `--json` or `--quiet` mode, runs unconditionally so\n * scripts don't hang waiting for input.\n */\n\nimport readline from 'node:readline/promises';\n\nimport { Command } from 'commander';\n\nimport { toCliError } from '../../errors.js';\nimport { deleteConfig, resolveConfigPathsForOverride } from '../../utils/config-store.js';\nimport { readGlobals } from '../../utils/global-options.js';\nimport { log, printJson } from '../../utils/output.js';\n\ntype ResetOptions = {\n yes?: boolean;\n};\n\nexport const resetConfigCommand = new Command('reset')\n .description('Delete ~/.kash/config.json.')\n .option('-y, --yes', 'skip the interactive confirmation')\n .addHelpText(\n 'after',\n `\nExamples:\n $ kash config reset\n $ kash config reset --yes --json --quiet\n`\n )\n .action(async (options: ResetOptions, cmd: Command) => {\n const globals = readGlobals(cmd);\n const paths = resolveConfigPathsForOverride(globals.configPath);\n\n const interactive = process.stdin.isTTY && !globals.quiet && !globals.json;\n const confirmed = options.yes || !interactive ? true : await confirm(paths.file);\n if (!confirmed) {\n log.info('Aborted.');\n return;\n }\n\n try {\n await deleteConfig({\n ...(globals.configPath === undefined ? {} : { configPath: globals.configPath }),\n });\n } catch (cause) {\n throw toCliError(cause);\n }\n\n if (globals.json) {\n printJson({ ok: true, deleted: paths.file });\n return;\n }\n log.success(`Deleted ${paths.file}.`);\n });\n\nasync function confirm(path: string): Promise<boolean> {\n const rl = readline.createInterface({ input: process.stdin, output: process.stderr });\n try {\n const answer = await rl.question(`Delete ${path}? [y/N] `);\n return answer.trim().toLowerCase().startsWith('y');\n } finally {\n rl.close();\n }\n}\n","/**\n * `kash config set <key> <value>` — write a single config field.\n *\n * The value is parsed and validated by the same Zod schema used to\n * read the file, so corruption is impossible without bypassing the\n * CLI.\n *\n * Three field families:\n *\n * - **Kash-orchestrated** (API-backed): `apiKey`, `baseUrl`, `defaultChainId`.\n * - **Direct mode** (`kash protocol …`): `rpcUrl`, `smartAccount`,\n * `bundlerUrl`, `bundlerProvider`, `signerKeyRef`.\n * - **Custom chain** (Anvil / forks / sidechains, dot-path syntax):\n * `customChain.name`, `customChain.factoryAddress`, etc. Including\n * `customChain.smartAccount.factoryAddress`/`implementationAddress`/\n * `entryPointAddress` for SA mode on chains the protocol-sdk\n * registry doesn't cover.\n */\n\nimport { Command } from 'commander';\n\nimport { CliValidationError, toCliError } from '../../errors.js';\nimport {\n cliConfigSchema,\n readConfig,\n updateConfig,\n type CliConfig,\n type UpdateConfigResult,\n} from '../../utils/config-store.js';\nimport { readGlobals } from '../../utils/global-options.js';\nimport { log, printJson } from '../../utils/output.js';\n\nconst TOP_LEVEL_KEYS = [\n // Kash-orchestrated\n 'apiKey',\n 'baseUrl',\n 'defaultChainId',\n // Direct mode\n 'rpcUrl',\n 'smartAccount',\n 'bundlerUrl',\n 'bundlerProvider',\n 'signerKeyRef',\n] as const;\ntype TopLevelKey = (typeof TOP_LEVEL_KEYS)[number];\n\nconst CUSTOM_CHAIN_LEAVES = [\n 'name',\n 'factoryAddress',\n 'usdcAddress',\n 'oracleAddress',\n 'vaultAddress',\n 'tokens1155Address',\n 'paramRegistryAddress',\n] as const;\ntype CustomChainLeaf = (typeof CUSTOM_CHAIN_LEAVES)[number];\n\nconst CUSTOM_CHAIN_SA_LEAVES = [\n 'factoryAddress',\n 'implementationAddress',\n 'entryPointAddress',\n] as const;\ntype CustomChainSaLeaf = (typeof CUSTOM_CHAIN_SA_LEAVES)[number];\n\nconst ALL_KEYS_FOR_HELP = [\n ...TOP_LEVEL_KEYS,\n ...CUSTOM_CHAIN_LEAVES.map((l) => `customChain.${l}`),\n ...CUSTOM_CHAIN_SA_LEAVES.map((l) => `customChain.smartAccount.${l}`),\n];\n\nexport const setConfigCommand = new Command('set')\n .description('Set a single config field.')\n .argument(\n '<key>',\n 'top-level key OR `customChain.<leaf>` / `customChain.smartAccount.<leaf>` dot-path'\n )\n .argument('<value>', 'value to set')\n .addHelpText(\n 'after',\n `\nExamples:\n $ kash config set baseUrl https://api-staging.kash.bot/v1 --profile staging\n $ kash config set defaultChainId 84532 --profile staging\n\nDirect-mode (kash protocol …):\n $ kash config set rpcUrl https://base-mainnet.g.alchemy.com/v2/... --profile mm\n $ kash config set smartAccount 0xabc... --profile mm\n $ kash config set signerKeyRef file:~/.kash/keys/mm-owner.key --profile mm\n $ kash config set bundlerProvider flashbots --profile mm\n\nCustom chain (local Anvil / forks / sidechains, bypasses static registry):\n $ kash config set defaultChainId 31337 --profile anvil\n $ kash config set rpcUrl http://localhost:8545 --profile anvil\n $ kash config set customChain.name \"Anvil local\" --profile anvil\n $ kash config set customChain.factoryAddress 0xCf7Ed... --profile anvil\n $ kash config set customChain.usdcAddress 0x5FbDB... --profile anvil\n $ kash config set customChain.smartAccount.factoryAddress 0x3Aa5e... --profile anvil\n`\n )\n .action(async (key: string, value: string, _opts, cmd: Command) => {\n const globals = readGlobals(cmd);\n let patch: Partial<CliConfig>;\n try {\n patch = await buildPatchForKey(key, value, {\n ...(globals.profile === undefined ? {} : { profile: globals.profile }),\n ...(globals.configPath === undefined ? {} : { configPath: globals.configPath }),\n });\n } catch (cause) {\n throw toCliError(cause);\n }\n\n let result: UpdateConfigResult;\n try {\n result = await updateConfig(patch, {\n ...(globals.profile === undefined ? {} : { profile: globals.profile }),\n ...(globals.configPath === undefined ? {} : { configPath: globals.configPath }),\n });\n } catch (cause) {\n throw toCliError(cause);\n }\n\n if (globals.json) {\n // The resolved profile (from updateConfig) is the truth — when\n // the user runs `kash config set foo bar` with no flag, the\n // value lands in whatever profile the file's `currentProfile`\n // points at, NOT in the unconditional 'default'.\n const top = key.split('.', 1)[0] as keyof CliConfig;\n printJson({\n ok: true,\n key,\n value: result.stored[top] ?? null,\n profile: result.profile,\n });\n return;\n }\n log.success(`Set ${key} on profile \"${result.profile}\".`);\n });\n\nfunction isTopLevelKey(value: string): value is TopLevelKey {\n return (TOP_LEVEL_KEYS as readonly string[]).includes(value);\n}\n\nfunction isCustomChainLeaf(value: string): value is CustomChainLeaf {\n return (CUSTOM_CHAIN_LEAVES as readonly string[]).includes(value);\n}\n\nfunction isCustomChainSaLeaf(value: string): value is CustomChainSaLeaf {\n return (CUSTOM_CHAIN_SA_LEAVES as readonly string[]).includes(value);\n}\n\n/**\n * Resolve a (possibly dot-pathed) key to a partial-config patch. For\n * `customChain.*` paths we read-modify-write the existing object so\n * the user can set leaves one at a time without losing prior fields.\n */\nasync function buildPatchForKey(\n key: string,\n value: string,\n readOpts: { readonly profile?: string; readonly configPath?: string }\n): Promise<Partial<CliConfig>> {\n if (isTopLevelKey(key)) {\n return buildTopLevelPatch(key, value);\n }\n\n // customChain.<leaf> or customChain.smartAccount.<leaf> — read the\n // existing customChain object so partial sets compose, then validate\n // the merged shape against the full schema.\n if (key.startsWith('customChain.')) {\n const existing = await readConfig(readOpts);\n const existingChain = existing.customChain ?? {};\n const merged = mergeCustomChainLeaf(existingChain, key, value);\n const candidate: Partial<CliConfig> = { customChain: merged };\n // Validate the merged customChain against the schema. If the\n // user has only set a name + factoryAddress so far this will\n // fail the required usdcAddress check — that's the correct\n // behaviour: customChain on disk is always a complete object.\n cliConfigSchema.parse(candidate);\n return candidate;\n }\n\n throw new CliValidationError(\n `Unknown config key \"${key}\".`,\n `Allowed keys: ${ALL_KEYS_FOR_HELP.join(', ')}.`\n );\n}\n\nfunction buildTopLevelPatch(key: TopLevelKey, value: string): Partial<CliConfig> {\n switch (key) {\n case 'apiKey':\n case 'baseUrl':\n case 'rpcUrl':\n case 'smartAccount':\n case 'bundlerUrl':\n case 'bundlerProvider':\n case 'signerKeyRef': {\n const candidate: Partial<CliConfig> = { [key]: value };\n cliConfigSchema.parse(candidate);\n return candidate;\n }\n case 'defaultChainId': {\n const n = Number.parseInt(value, 10);\n if (!Number.isFinite(n) || n <= 0) {\n throw new CliValidationError(\n 'defaultChainId must be a positive integer.',\n undefined,\n 'defaultChainId'\n );\n }\n const candidate: Partial<CliConfig> = { defaultChainId: n };\n cliConfigSchema.parse(candidate);\n return candidate;\n }\n }\n}\n\n/**\n * Merge a single dot-pathed leaf into the existing `customChain`\n * object. Handles both flat leaves (`customChain.factoryAddress`) and\n * the one nested level (`customChain.smartAccount.factoryAddress`).\n *\n * The returned object is then re-validated against the full\n * `customChainSchema` by the caller — leaves that violate the leaf\n * regex (e.g. malformed hex) surface their schema error there, and\n * the required-field check (factoryAddress + usdcAddress) ensures we\n * never persist a half-built customChain.\n */\nfunction mergeCustomChainLeaf(\n existing: NonNullable<CliConfig['customChain']> | Record<string, unknown>,\n key: string,\n value: string\n): NonNullable<CliConfig['customChain']> {\n const path = key.slice('customChain.'.length);\n\n if (path.startsWith('smartAccount.')) {\n const leaf = path.slice('smartAccount.'.length);\n if (!isCustomChainSaLeaf(leaf)) {\n throw new CliValidationError(\n `Unknown customChain.smartAccount leaf \"${leaf}\".`,\n `Allowed: ${CUSTOM_CHAIN_SA_LEAVES.map((l) => `customChain.smartAccount.${l}`).join(', ')}.`\n );\n }\n const sa = (existing as { smartAccount?: Record<string, unknown> }).smartAccount ?? {};\n return {\n ...(existing as NonNullable<CliConfig['customChain']>),\n smartAccount: { ...sa, [leaf]: value } as NonNullable<\n NonNullable<CliConfig['customChain']>['smartAccount']\n >,\n };\n }\n\n if (!isCustomChainLeaf(path)) {\n throw new CliValidationError(\n `Unknown customChain leaf \"${path}\".`,\n `Allowed: ${CUSTOM_CHAIN_LEAVES.map((l) => `customChain.${l}`).join(', ')}, customChain.smartAccount.<leaf>.`\n );\n }\n return {\n ...(existing as NonNullable<CliConfig['customChain']>),\n [path]: value,\n };\n}\n","/**\n * `kash config show` — print the resolved configuration.\n *\n * Sources are surfaced (env vs file vs default) so users can debug\n * \"why is my key not picking up?\" without reading the source.\n */\n\nimport { Command } from 'commander';\n\nimport { readConfig } from '../../utils/config-store.js';\nimport { redact } from '../../utils/formatting.js';\nimport { readGlobals } from '../../utils/global-options.js';\nimport { print, printJson, style } from '../../utils/output.js';\n\nexport const showConfigCommand = new Command('show')\n .description('Print the resolved CLI configuration.')\n .addHelpText(\n 'after',\n `\nExamples:\n $ kash config show\n $ kash config show --profile staging\n $ kash config show --json --quiet | jq -r '.baseUrl'\n`\n )\n .action(async (_opts, cmd: Command) => {\n const globals = readGlobals(cmd);\n const config = await readConfig({\n ...(globals.profile === undefined ? {} : { profile: globals.profile }),\n ...(globals.configPath === undefined ? {} : { configPath: globals.configPath }),\n });\n\n if (globals.json) {\n // Shape pinned by `CliConfigEnvelopeSchema` in `cli-schemas.ts`.\n // Includes `authenticated` so it agrees with `auth status` —\n // agents that bind one shape can consume the other. Direct-mode\n // fields are always emitted (`null` when unset) so operators\n // can introspect the full profile via JSON.\n printJson({\n profile: config.profile,\n authenticated: Boolean(config.apiKey),\n apiKey: config.apiKey ? redact(config.apiKey) : null,\n baseUrl: config.baseUrl,\n defaultChainId: config.defaultChainId,\n rpcUrl: config.rpcUrl ?? null,\n smartAccount: config.smartAccount ?? null,\n bundlerUrl: config.bundlerUrl ?? null,\n bundlerProvider: config.bundlerProvider ?? null,\n signerKeyRef: config.signerKeyRef ?? null,\n customChain: config.customChain ?? null,\n sources: config.sources,\n });\n return;\n }\n\n print('');\n print(` ${style.dim('Profile ')} ${config.profile} (${config.sources.profile})`);\n print(\n ` ${style.dim('API key ')} ${config.apiKey ? redact(config.apiKey) : '(unset)'} (${config.sources.apiKey})`\n );\n print(` ${style.dim('Base URL ')} ${config.baseUrl} (${config.sources.baseUrl})`);\n print(\n ` ${style.dim('Default chain ')} ${String(config.defaultChainId)} (${config.sources.defaultChainId})`\n );\n // Surface direct-mode fields when any are set. Skip the section\n // entirely on a Kash-orchestrated-only profile so human output\n // stays terse.\n const hasDirectMode =\n config.rpcUrl !== undefined ||\n config.smartAccount !== undefined ||\n config.bundlerUrl !== undefined ||\n config.bundlerProvider !== undefined ||\n config.signerKeyRef !== undefined;\n if (hasDirectMode) {\n print('');\n print(` ${style.dim('Direct mode ')}`);\n print(\n ` ${style.dim(' RPC URL ')} ${config.rpcUrl ?? '(unset)'} (${config.sources.rpcUrl})`\n );\n print(\n ` ${style.dim(' Smart account')} ${config.smartAccount ?? '(unset)'} (${config.sources.smartAccount})`\n );\n print(\n ` ${style.dim(' Bundler URL ')} ${config.bundlerUrl ?? '(unset)'} (${config.sources.bundlerUrl})`\n );\n print(\n ` ${style.dim(' Bundler kind ')} ${config.bundlerProvider ?? '(unset)'} (${config.sources.bundlerProvider})`\n );\n print(\n ` ${style.dim(' Signer ref ')} ${config.signerKeyRef ?? '(unset)'} (${config.sources.signerKeyRef})`\n );\n }\n\n // Custom-chain section — surfaces when the profile bypasses the\n // protocol-sdk's static chain registry (Anvil / forks / sidechains).\n if (config.customChain !== undefined) {\n const cc = config.customChain;\n print('');\n print(` ${style.dim('Custom chain ')} (${config.sources.customChain})`);\n print(` ${style.dim(' Name ')} ${cc.name}`);\n print(` ${style.dim(' Factory ')} ${cc.factoryAddress}`);\n print(` ${style.dim(' USDC ')} ${cc.usdcAddress}`);\n if (cc.oracleAddress) print(` ${style.dim(' Oracle ')} ${cc.oracleAddress}`);\n if (cc.vaultAddress) print(` ${style.dim(' Vault ')} ${cc.vaultAddress}`);\n if (cc.tokens1155Address) print(` ${style.dim(' Tokens1155 ')} ${cc.tokens1155Address}`);\n if (cc.paramRegistryAddress)\n print(` ${style.dim(' ParamRegistry')} ${cc.paramRegistryAddress}`);\n if (cc.smartAccount) {\n print(` ${style.dim(' Smart account')}`);\n print(` ${style.dim(' Factory ')} ${cc.smartAccount.factoryAddress}`);\n print(` ${style.dim(' Implement. ')} ${cc.smartAccount.implementationAddress}`);\n print(` ${style.dim(' EntryPoint ')} ${cc.smartAccount.entryPointAddress}`);\n }\n }\n });\n","/**\n * `kash config use <profile>` — switch the active profile by writing\n * the file's `currentProfile` field.\n *\n * **Existence check.** By default we refuse to switch to a profile\n * that doesn't already exist — `kash config use staing` (typo) used\n * to silently succeed and the next command would fail with a\n * confusing `AUTH_REQUIRED`. Now we surface the typo with a list of\n * known profile names. The \"set up a fresh profile\" flow opts in via\n * `--allow-new`: `kash config use newprofile --allow-new` followed by\n * `kash auth set-key --profile newprofile <key>`.\n */\n\nimport { Command } from 'commander';\n\nimport { CliValidationError, toCliError } from '../../errors.js';\nimport { readWholeFile, setCurrentProfile } from '../../utils/config-store.js';\nimport { readGlobals } from '../../utils/global-options.js';\nimport { log, printJson } from '../../utils/output.js';\n\ntype UseProfileOptions = {\n allowNew?: boolean;\n};\n\nexport const useProfileCommand = new Command('use')\n .description('Switch the active profile (writes currentProfile to the config file).')\n .argument('<profile>', 'profile name')\n .option(\n '--allow-new',\n 'permit switching to a profile that does not yet exist (you must populate it via `kash auth set-key --profile <name>` afterwards)'\n )\n .addHelpText(\n 'after',\n `\nExamples:\n $ kash config use staging\n $ kash config use prod --json --quiet\n $ kash config use newprofile --allow-new # explicitly create a fresh profile\n\nNotes:\n - By default \\`kash config use\\` refuses unknown profile names and\n lists the known ones — a typo of an existing profile name would\n otherwise surface later as a confusing AUTH_REQUIRED.\n - Use \\`--allow-new\\` for the bootstrapping flow when you genuinely\n want to switch to a not-yet-populated profile.\n`\n )\n .action(async (profile: string, options: UseProfileOptions, cmd: Command) => {\n const globals = readGlobals(cmd);\n const configPathOpt =\n globals.configPath === undefined ? {} : { configPath: globals.configPath };\n\n // Existence check: load the file once to see which profiles\n // exist, then either surface a structured \"did you mean\" error or\n // proceed with the write.\n let knownProfiles: readonly string[];\n try {\n const file = await readWholeFile(configPathOpt);\n knownProfiles = Object.keys(file.profiles).sort();\n } catch (cause) {\n throw toCliError(cause);\n }\n\n if (!knownProfiles.includes(profile) && options.allowNew !== true) {\n const known = knownProfiles.length === 0 ? '(none yet)' : knownProfiles.join(', ');\n throw new CliValidationError(\n `Profile \"${profile}\" does not exist.`,\n `Known profiles: ${known}. Pass --allow-new to create + switch to a fresh profile (you'll then need to populate it with \\`kash auth set-key --profile ${profile}\\`).`,\n 'profile'\n );\n }\n\n let updated;\n try {\n updated = await setCurrentProfile(profile, configPathOpt);\n } catch (cause) {\n throw toCliError(cause);\n }\n\n if (globals.json) {\n printJson({\n ok: true,\n currentProfile: updated.currentProfile,\n profiles: Object.keys(updated.profiles).sort(),\n // Surface whether this was a new-profile switch — agents can\n // pipe to `kash auth set-key --profile <p>` automatically when\n // `created` is true.\n created: !knownProfiles.includes(profile),\n });\n return;\n }\n log.success(`Active profile is now \"${profile}\".`);\n if (!knownProfiles.includes(profile)) {\n log.info(`Profile is empty. Populate it with: kash auth set-key --profile ${profile} <key>`);\n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,SAAS,OAAO,GAAG;AACpC,QAAI,KAAK,mEAAmE,OAAO,QAAQ;AAAA,EAC7F;AACF,CAAC;;;ARhFI,IAAM,gBAAgB,IAAIC,SAAQ,QAAQ,EAC9C,YAAY,uDAAuD,EACnE,WAAW,iBAAiB,EAC5B,WAAW,gBAAgB,EAC3B,WAAW,eAAe,EAC1B,WAAW,iBAAiB,EAC5B,WAAW,oBAAoB,EAC/B,WAAW,kBAAkB,EAC7B,WAAW,mBAAmB,EAC9B,WAAW,mBAAmB;","names":["Command","Command","Command","Command","Command","Command","Command","Command","Command","Command","Command","Command","Command","Command","Command","Command"]}