@kashdao/cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +78 -0
- package/CONTRIBUTING.md +159 -0
- package/LICENSE +21 -0
- package/README.md +868 -0
- package/SECURITY.md +110 -0
- package/dist/account-AVFLEM5D.js +90 -0
- package/dist/account-AVFLEM5D.js.map +1 -0
- package/dist/auth-GUJCVKTD.js +239 -0
- package/dist/auth-GUJCVKTD.js.map +1 -0
- package/dist/chunk-BN2CUM42.js +9 -0
- package/dist/chunk-BN2CUM42.js.map +1 -0
- package/dist/chunk-BRK7KJ4O.js +154 -0
- package/dist/chunk-BRK7KJ4O.js.map +1 -0
- package/dist/chunk-KMBMQIZ7.js +393 -0
- package/dist/chunk-KMBMQIZ7.js.map +1 -0
- package/dist/chunk-LBIRQHX5.js +133 -0
- package/dist/chunk-LBIRQHX5.js.map +1 -0
- package/dist/chunk-MIXOZU2S.js +366 -0
- package/dist/chunk-MIXOZU2S.js.map +1 -0
- package/dist/chunk-QJMF73M5.js +129 -0
- package/dist/chunk-QJMF73M5.js.map +1 -0
- package/dist/chunk-UZNSYATZ.js +680 -0
- package/dist/chunk-UZNSYATZ.js.map +1 -0
- package/dist/chunk-VIADBYFY.js +94 -0
- package/dist/chunk-VIADBYFY.js.map +1 -0
- package/dist/chunk-YHCG2SUC.js +159 -0
- package/dist/chunk-YHCG2SUC.js.map +1 -0
- package/dist/chunk-YJX3JJ4M.js +174 -0
- package/dist/chunk-YJX3JJ4M.js.map +1 -0
- package/dist/client-IOM55ZCS.js +14 -0
- package/dist/client-IOM55ZCS.js.map +1 -0
- package/dist/completion-ZZGX5BQC.js +100 -0
- package/dist/completion-ZZGX5BQC.js.map +1 -0
- package/dist/config-XJL5TSYK.js +690 -0
- package/dist/config-XJL5TSYK.js.map +1 -0
- package/dist/config-store-3ZSYGXMQ.js +44 -0
- package/dist/config-store-3ZSYGXMQ.js.map +1 -0
- package/dist/docs-MDKKSJDC.js +102 -0
- package/dist/docs-MDKKSJDC.js.map +1 -0
- package/dist/eoa-IQ72EIHR.js +551 -0
- package/dist/eoa-IQ72EIHR.js.map +1 -0
- package/dist/errors-WMZIEGQI.js +18 -0
- package/dist/errors-WMZIEGQI.js.map +1 -0
- package/dist/explain-H4EH3KH3.js +165 -0
- package/dist/explain-H4EH3KH3.js.map +1 -0
- package/dist/global-options-XOLJUPTT.js +18 -0
- package/dist/global-options-XOLJUPTT.js.map +1 -0
- package/dist/health-VZEIII74.js +98 -0
- package/dist/health-VZEIII74.js.map +1 -0
- package/dist/help-footer-GTANVDNP.js +43 -0
- package/dist/help-footer-GTANVDNP.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +251 -0
- package/dist/index.js.map +1 -0
- package/dist/intro-PQQTYWR7.js +41 -0
- package/dist/intro-PQQTYWR7.js.map +1 -0
- package/dist/markets-C37JZDPE.js +295 -0
- package/dist/markets-C37JZDPE.js.map +1 -0
- package/dist/output-VCBZ3FM7.js +22 -0
- package/dist/output-VCBZ3FM7.js.map +1 -0
- package/dist/portfolio-2AEPIJIG.js +115 -0
- package/dist/portfolio-2AEPIJIG.js.map +1 -0
- package/dist/protocol-XEQXF2GW.js +1572 -0
- package/dist/protocol-XEQXF2GW.js.map +1 -0
- package/dist/quote-I4DVJ7ZB.js +144 -0
- package/dist/quote-I4DVJ7ZB.js.map +1 -0
- package/dist/schema-PIFQ65TS.js +410 -0
- package/dist/schema-PIFQ65TS.js.map +1 -0
- package/dist/setup-USZ6IODD.js +260 -0
- package/dist/setup-USZ6IODD.js.map +1 -0
- package/dist/stdin-YW2CEQXU.js +28 -0
- package/dist/stdin-YW2CEQXU.js.map +1 -0
- package/dist/trace-IZBYTUFO.js +103 -0
- package/dist/trace-IZBYTUFO.js.map +1 -0
- package/dist/trade-IIZSEXEI.js +586 -0
- package/dist/trade-IIZSEXEI.js.map +1 -0
- package/dist/version-JDK3PEP5.js +117 -0
- package/dist/version-JDK3PEP5.js.map +1 -0
- package/dist/version-check-TDCION37.js +138 -0
- package/dist/version-check-TDCION37.js.map +1 -0
- package/dist/webhooks-PTVRKICZ.js +680 -0
- package/dist/webhooks-PTVRKICZ.js.map +1 -0
- package/dist/with-retry-4FIZG3A7.js +223 -0
- package/dist/with-retry-4FIZG3A7.js.map +1 -0
- package/package.json +99 -0
|
@@ -0,0 +1 @@
|
|
|
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}\\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|
+
} 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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
log
|
|
4
|
+
} from "./chunk-VIADBYFY.js";
|
|
5
|
+
import "./chunk-MIXOZU2S.js";
|
|
6
|
+
import {
|
|
7
|
+
CliError
|
|
8
|
+
} from "./chunk-UZNSYATZ.js";
|
|
9
|
+
|
|
10
|
+
// src/completion.ts
|
|
11
|
+
import { Command } from "commander";
|
|
12
|
+
var COMMANDS = {
|
|
13
|
+
auth: ["set-key", "status", "logout"],
|
|
14
|
+
account: ["usage"],
|
|
15
|
+
markets: ["list", "get", "predictions"],
|
|
16
|
+
quote: ["buy", "sell"],
|
|
17
|
+
trade: ["buy", "sell", "status", "list", "confirm"],
|
|
18
|
+
portfolio: ["show", "positions"],
|
|
19
|
+
protocol: [
|
|
20
|
+
"balance",
|
|
21
|
+
"market",
|
|
22
|
+
"quote",
|
|
23
|
+
"position",
|
|
24
|
+
"allowance",
|
|
25
|
+
"smart-account",
|
|
26
|
+
"fees",
|
|
27
|
+
"token-id",
|
|
28
|
+
"decode-revert",
|
|
29
|
+
"trade",
|
|
30
|
+
"userop",
|
|
31
|
+
"watch"
|
|
32
|
+
],
|
|
33
|
+
eoa: ["balance", "market", "quote", "position", "allowance", "fees", "trade"],
|
|
34
|
+
webhooks: ["list", "rotate-secret", "redeliver", "verify", "replay"],
|
|
35
|
+
config: ["show", "set", "profiles", "use", "remove", "reset", "export", "import"],
|
|
36
|
+
health: [],
|
|
37
|
+
version: [],
|
|
38
|
+
explain: [],
|
|
39
|
+
schema: [],
|
|
40
|
+
setup: [],
|
|
41
|
+
trace: [],
|
|
42
|
+
"with-retry": [],
|
|
43
|
+
docs: [],
|
|
44
|
+
completion: ["install", "uninstall"]
|
|
45
|
+
};
|
|
46
|
+
async function initCompletion() {
|
|
47
|
+
const argv = process.argv.slice(2);
|
|
48
|
+
const isCompletionArg = argv.some(
|
|
49
|
+
(a) => a === "--compbash" || a === "--compzsh" || a === "--compfish" || a === "--completion"
|
|
50
|
+
);
|
|
51
|
+
if (!isCompletionArg) return;
|
|
52
|
+
const { default: omelette } = await import("omelette");
|
|
53
|
+
const completion = omelette("kash <command> <subcommand>");
|
|
54
|
+
completion.on("command", () => Object.keys(COMMANDS));
|
|
55
|
+
completion.on("subcommand", ({ before }) => COMMANDS[before] ?? []);
|
|
56
|
+
completion.init();
|
|
57
|
+
}
|
|
58
|
+
function createCompletionCommand() {
|
|
59
|
+
const cmd = new Command("completion").description("Shell tab-completion utilities.");
|
|
60
|
+
cmd.command("install").description("Install bash/zsh/fish completion to your shell config.").action(async () => {
|
|
61
|
+
const detectedShell = process.env["SHELL"] ?? "(unknown)";
|
|
62
|
+
log.info(`Detected shell: ${detectedShell}`);
|
|
63
|
+
if (process.platform === "win32") {
|
|
64
|
+
log.warn("Native Windows shells are not supported by omelette. Use WSL or Git Bash.");
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const { default: omelette } = await import("omelette");
|
|
68
|
+
const completion = omelette("kash");
|
|
69
|
+
completion.setupShellInitFile();
|
|
70
|
+
log.success("Shell completions installed.");
|
|
71
|
+
log.info("Restart your shell or source your shell config to activate.");
|
|
72
|
+
} catch (cause) {
|
|
73
|
+
throw new CliError("Failed to install shell completions.", {
|
|
74
|
+
code: "UNEXPECTED",
|
|
75
|
+
suggestion: "Verify your shell config is writable and rerun.",
|
|
76
|
+
cause
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
cmd.command("uninstall").description("Remove kash completions from your shell config.").action(async () => {
|
|
81
|
+
try {
|
|
82
|
+
const { default: omelette } = await import("omelette");
|
|
83
|
+
const completion = omelette("kash");
|
|
84
|
+
completion.cleanupShellInitFile();
|
|
85
|
+
log.success("Shell completions removed.");
|
|
86
|
+
} catch (cause) {
|
|
87
|
+
throw new CliError("Failed to remove shell completions.", {
|
|
88
|
+
code: "UNEXPECTED",
|
|
89
|
+
suggestion: "Verify your shell config is writable and rerun.",
|
|
90
|
+
cause
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
return cmd;
|
|
95
|
+
}
|
|
96
|
+
export {
|
|
97
|
+
createCompletionCommand,
|
|
98
|
+
initCompletion
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=completion-ZZGX5BQC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/completion.ts"],"sourcesContent":["/**\n * Shell completion (bash + zsh + fish via omelette).\n *\n * The completion tree mirrors the registered command groups. Adding a\n * command means updating both the Commander wiring in `index.ts` and\n * the `COMMANDS` map below — they don't auto-derive because omelette\n * resolves at startup based on positional args, not the Commander\n * instance.\n *\n * **Cold-start.** `omelette` is dynamically imported inside the action\n * handlers and `initCompletion()` rather than at module top — bash/zsh\n * completion is a one-shot install path, and 99% of CLI invocations\n * never hit it. Skipping the eager import shaves ~3ms off every other\n * command.\n */\n\nimport { Command } from 'commander';\n\nimport { CliError } from './errors.js';\nimport { log } from './utils/output.js';\n\nconst COMMANDS: Record<string, string[]> = {\n auth: ['set-key', 'status', 'logout'],\n account: ['usage'],\n markets: ['list', 'get', 'predictions'],\n quote: ['buy', 'sell'],\n trade: ['buy', 'sell', 'status', 'list', 'confirm'],\n portfolio: ['show', 'positions'],\n protocol: [\n 'balance',\n 'market',\n 'quote',\n 'position',\n 'allowance',\n 'smart-account',\n 'fees',\n 'token-id',\n 'decode-revert',\n 'trade',\n 'userop',\n 'watch',\n ],\n eoa: ['balance', 'market', 'quote', 'position', 'allowance', 'fees', 'trade'],\n webhooks: ['list', 'rotate-secret', 'redeliver', 'verify', 'replay'],\n config: ['show', 'set', 'profiles', 'use', 'remove', 'reset', 'export', 'import'],\n health: [],\n version: [],\n explain: [],\n schema: [],\n setup: [],\n trace: [],\n 'with-retry': [],\n docs: [],\n completion: ['install', 'uninstall'],\n};\n\nexport async function initCompletion(): Promise<void> {\n // Only `kash --compbash`/`--compzsh`/`--compfish` invocations need\n // omelette. For every other command, we'd be paying ~3ms to load a\n // module we never use. Detect the completion-handshake args before\n // touching omelette.\n const argv = process.argv.slice(2);\n const isCompletionArg = argv.some(\n (a) => a === '--compbash' || a === '--compzsh' || a === '--compfish' || a === '--completion'\n );\n if (!isCompletionArg) return;\n\n const { default: omelette } = await import('omelette');\n const completion = omelette('kash <command> <subcommand>');\n\n completion.on('command', () => Object.keys(COMMANDS));\n completion.on('subcommand', ({ before }: { before: string }) => COMMANDS[before] ?? []);\n\n completion.init();\n}\n\nexport function createCompletionCommand(): Command {\n const cmd = new Command('completion').description('Shell tab-completion utilities.');\n\n cmd\n .command('install')\n .description('Install bash/zsh/fish completion to your shell config.')\n .action(async () => {\n // Surface which shell omelette will target so users can confirm\n // it picked the right rc file. omelette inspects $SHELL.\n const detectedShell = process.env['SHELL'] ?? '(unknown)';\n log.info(`Detected shell: ${detectedShell}`);\n if (process.platform === 'win32') {\n log.warn('Native Windows shells are not supported by omelette. Use WSL or Git Bash.');\n }\n\n try {\n const { default: omelette } = await import('omelette');\n const completion = omelette('kash');\n completion.setupShellInitFile();\n log.success('Shell completions installed.');\n log.info('Restart your shell or source your shell config to activate.');\n } catch (cause) {\n // Throw a typed CliError so the top-level boundary in\n // `index.ts` renders the JSON envelope in --json mode and\n // surfaces the catalog's `UNEXPECTED` action — instead of\n // hand-rolling `process.exit(1)`.\n throw new CliError('Failed to install shell completions.', {\n code: 'UNEXPECTED',\n suggestion: 'Verify your shell config is writable and rerun.',\n cause,\n });\n }\n });\n\n cmd\n .command('uninstall')\n .description('Remove kash completions from your shell config.')\n .action(async () => {\n try {\n const { default: omelette } = await import('omelette');\n const completion = omelette('kash');\n completion.cleanupShellInitFile();\n log.success('Shell completions removed.');\n } catch (cause) {\n throw new CliError('Failed to remove shell completions.', {\n code: 'UNEXPECTED',\n suggestion: 'Verify your shell config is writable and rerun.',\n cause,\n });\n }\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;;;;;AAgBA,SAAS,eAAe;AAKxB,IAAM,WAAqC;AAAA,EACzC,MAAM,CAAC,WAAW,UAAU,QAAQ;AAAA,EACpC,SAAS,CAAC,OAAO;AAAA,EACjB,SAAS,CAAC,QAAQ,OAAO,aAAa;AAAA,EACtC,OAAO,CAAC,OAAO,MAAM;AAAA,EACrB,OAAO,CAAC,OAAO,QAAQ,UAAU,QAAQ,SAAS;AAAA,EAClD,WAAW,CAAC,QAAQ,WAAW;AAAA,EAC/B,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,KAAK,CAAC,WAAW,UAAU,SAAS,YAAY,aAAa,QAAQ,OAAO;AAAA,EAC5E,UAAU,CAAC,QAAQ,iBAAiB,aAAa,UAAU,QAAQ;AAAA,EACnE,QAAQ,CAAC,QAAQ,OAAO,YAAY,OAAO,UAAU,SAAS,UAAU,QAAQ;AAAA,EAChF,QAAQ,CAAC;AAAA,EACT,SAAS,CAAC;AAAA,EACV,SAAS,CAAC;AAAA,EACV,QAAQ,CAAC;AAAA,EACT,OAAO,CAAC;AAAA,EACR,OAAO,CAAC;AAAA,EACR,cAAc,CAAC;AAAA,EACf,MAAM,CAAC;AAAA,EACP,YAA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