tenjin-cli 0.1.0-alpha.29 → 0.1.0-alpha.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -5
- package/dist/{chunk-25GGN553.js → chunk-3O2BQIF6.js} +86 -22
- package/dist/chunk-3O2BQIF6.js.map +1 -0
- package/dist/{chunk-R4AO7GC2.js → chunk-5LJCEMFD.js} +14 -12
- package/dist/{chunk-R4AO7GC2.js.map → chunk-5LJCEMFD.js.map} +1 -1
- package/dist/{chunk-QTGUDCIR.js → chunk-AEG2PXBP.js} +3 -3
- package/dist/{chunk-AMEUXNJT.js → chunk-AWFUPKTM.js} +2 -2
- package/dist/{chunk-XJQ6CH7X.js → chunk-EBVIKMCH.js} +2 -2
- package/dist/{chunk-XDYKZRLN.js → chunk-HE2MS4QO.js} +6 -6
- package/dist/{chunk-RJEPZMYY.js → chunk-IOODYAXL.js} +3 -3
- package/dist/{chunk-SBL4THYT.js → chunk-JMM6YE7J.js} +190 -90
- package/dist/chunk-JMM6YE7J.js.map +1 -0
- package/dist/{chunk-VKQXVCZR.js → chunk-KHE6L6TD.js} +3 -3
- package/dist/chunk-KOGZDMHO.js +21 -0
- package/dist/chunk-KOGZDMHO.js.map +1 -0
- package/dist/{chunk-TROZ6HL4.js → chunk-KYFZTGMC.js} +2 -2
- package/dist/{chunk-LX5OT4TQ.js → chunk-NZIP4PA2.js} +2 -2
- package/dist/chunk-O2FRQ2L2.js +168 -0
- package/dist/chunk-O2FRQ2L2.js.map +1 -0
- package/dist/{chunk-3FY5HG7R.js → chunk-OK2TDZQU.js} +4 -4
- package/dist/{chunk-ZQNGTLOC.js → chunk-OSYTBCUC.js} +7 -5
- package/dist/{chunk-ZQNGTLOC.js.map → chunk-OSYTBCUC.js.map} +1 -1
- package/dist/{chunk-MRUPDSUM.js → chunk-PAYV4XUA.js} +3 -5
- package/dist/chunk-PAYV4XUA.js.map +1 -0
- package/dist/{chunk-USOLCBKC.js → chunk-QUVVWYJW.js} +7 -5
- package/dist/{chunk-USOLCBKC.js.map → chunk-QUVVWYJW.js.map} +1 -1
- package/dist/{chunk-MOG7PB3A.js → chunk-RAULEAZ6.js} +3 -3
- package/dist/{chunk-MG3G644T.js → chunk-SPAVAYSW.js} +3 -3
- package/dist/{chunk-4FYMDRD3.js → chunk-TTBKWWTV.js} +22 -20
- package/dist/chunk-TTBKWWTV.js.map +1 -0
- package/dist/{chunk-OOSRB3OF.js → chunk-U6YQ6FRI.js} +2 -2
- package/dist/{chunk-P4LVLFO4.js → chunk-VFMQTSXG.js} +2 -2
- package/dist/{chunk-LRCJ2IZ5.js → chunk-VUFAK2LW.js} +2 -2
- package/dist/{chunk-LRCJ2IZ5.js.map → chunk-VUFAK2LW.js.map} +1 -1
- package/dist/{chunk-WM7TJEBP.js → chunk-VZGAONSJ.js} +7 -5
- package/dist/{chunk-WM7TJEBP.js.map → chunk-VZGAONSJ.js.map} +1 -1
- package/dist/{chunk-VVAHFCX2.js → chunk-WO5BJNIB.js} +45 -194
- package/dist/chunk-WO5BJNIB.js.map +1 -0
- package/dist/chunk-WVUSXNIE.js +39 -0
- package/dist/chunk-WVUSXNIE.js.map +1 -0
- package/dist/chunk-XKESD27X.js +10 -0
- package/dist/chunk-XKESD27X.js.map +1 -0
- package/dist/{chunk-SFEQGENI.js → chunk-YFQOA5AU.js} +7 -2
- package/dist/{chunk-SFEQGENI.js.map → chunk-YFQOA5AU.js.map} +1 -1
- package/dist/{cli-JPTDHGRX.js → cli-O5SN7ZJ4.js} +38 -30
- package/dist/{cli-JPTDHGRX.js.map → cli-O5SN7ZJ4.js.map} +1 -1
- package/dist/{config-YYKDH2TH.js → config-OJQI27LT.js} +13 -12
- package/dist/{doctor-SSTXGCHX.js → doctor-IQQJHGGM.js} +36 -62
- package/dist/doctor-IQQJHGGM.js.map +1 -0
- package/dist/{fund-QWVWRVDK.js → fund-WEV6DMTD.js} +17 -12
- package/dist/{fund-QWVWRVDK.js.map → fund-WEV6DMTD.js.map} +1 -1
- package/dist/hook-command-D2P3ILRV.js +32 -0
- package/dist/hosts/claude/.claude-plugin/marketplace.json +2 -2
- package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +2 -2
- package/dist/index.js +4 -4
- package/dist/{install-2GXXD4DK.js → install-TUCRF32I.js} +23 -14
- package/dist/{install-identity-FK3YF227.js → install-identity-WHPNMNMQ.js} +7 -6
- package/dist/{install-wallet-TC22U52X.js → install-wallet-MA27FTQ5.js} +11 -10
- package/dist/{install-wallet-TC22U52X.js.map → install-wallet-MA27FTQ5.js.map} +1 -1
- package/dist/{mcp-42H2F4NY.js → mcp-QML7ZMPH.js} +33 -40
- package/dist/mcp-QML7ZMPH.js.map +1 -0
- package/dist/{package-6DJA3Y2O.js → package-LGKYOEPV.js} +2 -2
- package/dist/{pay-LSDJBIAZ.js → pay-2C2UBBXJ.js} +14 -13
- package/dist/{payments-SPECLBRQ.js → payments-C44QUFXU.js} +10 -9
- package/dist/{payments-SPECLBRQ.js.map → payments-C44QUFXU.js.map} +1 -1
- package/dist/{send-MHAOLPK3.js → send-KVJX4XIR.js} +9 -8
- package/dist/{send-MHAOLPK3.js.map → send-KVJX4XIR.js.map} +1 -1
- package/dist/{status-O2RWLPS5.js → status-S7C3WMSH.js} +10 -9
- package/dist/{status-O2RWLPS5.js.map → status-S7C3WMSH.js.map} +1 -1
- package/dist/{status-line-45TVCRM3.js → status-line-YR2T5HC4.js} +6 -5
- package/dist/{status-line-45TVCRM3.js.map → status-line-YR2T5HC4.js.map} +1 -1
- package/dist/{uninstall-VOK2Z5M4.js → uninstall-HY6LKIIT.js} +17 -14
- package/dist/{uninstall-VOK2Z5M4.js.map → uninstall-HY6LKIIT.js.map} +1 -1
- package/dist/{update-FGP3HNLD.js → update-OJV22LR3.js} +17 -14
- package/dist/usdc-JK4RRFFQ.js +39 -0
- package/dist/{wallet-DA7OFNEW.js → wallet-PD2IMZDU.js} +11 -10
- package/dist/wallet-PD2IMZDU.js.map +1 -0
- package/docs/agent-permissions.md +16 -4
- package/package.json +1 -1
- package/dist/chunk-25GGN553.js.map +0 -1
- package/dist/chunk-4FYMDRD3.js.map +0 -1
- package/dist/chunk-EWLU46J6.js +0 -100
- package/dist/chunk-EWLU46J6.js.map +0 -1
- package/dist/chunk-MRUPDSUM.js.map +0 -1
- package/dist/chunk-SBL4THYT.js.map +0 -1
- package/dist/chunk-VVAHFCX2.js.map +0 -1
- package/dist/doctor-SSTXGCHX.js.map +0 -1
- package/dist/hook-command-VWJXRT7H.js +0 -31
- package/dist/mcp-42H2F4NY.js.map +0 -1
- /package/dist/{chunk-QTGUDCIR.js.map → chunk-AEG2PXBP.js.map} +0 -0
- /package/dist/{chunk-AMEUXNJT.js.map → chunk-AWFUPKTM.js.map} +0 -0
- /package/dist/{chunk-XJQ6CH7X.js.map → chunk-EBVIKMCH.js.map} +0 -0
- /package/dist/{chunk-XDYKZRLN.js.map → chunk-HE2MS4QO.js.map} +0 -0
- /package/dist/{chunk-RJEPZMYY.js.map → chunk-IOODYAXL.js.map} +0 -0
- /package/dist/{chunk-VKQXVCZR.js.map → chunk-KHE6L6TD.js.map} +0 -0
- /package/dist/{chunk-TROZ6HL4.js.map → chunk-KYFZTGMC.js.map} +0 -0
- /package/dist/{chunk-LX5OT4TQ.js.map → chunk-NZIP4PA2.js.map} +0 -0
- /package/dist/{chunk-3FY5HG7R.js.map → chunk-OK2TDZQU.js.map} +0 -0
- /package/dist/{chunk-MOG7PB3A.js.map → chunk-RAULEAZ6.js.map} +0 -0
- /package/dist/{chunk-MG3G644T.js.map → chunk-SPAVAYSW.js.map} +0 -0
- /package/dist/{chunk-OOSRB3OF.js.map → chunk-U6YQ6FRI.js.map} +0 -0
- /package/dist/{chunk-P4LVLFO4.js.map → chunk-VFMQTSXG.js.map} +0 -0
- /package/dist/{config-YYKDH2TH.js.map → config-OJQI27LT.js.map} +0 -0
- /package/dist/{hook-command-VWJXRT7H.js.map → hook-command-D2P3ILRV.js.map} +0 -0
- /package/dist/{install-2GXXD4DK.js.map → install-TUCRF32I.js.map} +0 -0
- /package/dist/{install-identity-FK3YF227.js.map → install-identity-WHPNMNMQ.js.map} +0 -0
- /package/dist/{package-6DJA3Y2O.js.map → package-LGKYOEPV.js.map} +0 -0
- /package/dist/{pay-LSDJBIAZ.js.map → pay-2C2UBBXJ.js.map} +0 -0
- /package/dist/{update-FGP3HNLD.js.map → update-OJV22LR3.js.map} +0 -0
- /package/dist/{wallet-DA7OFNEW.js.map → usdc-JK4RRFFQ.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/update-check.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { z } from 'zod';\nimport pkg from '../../package.json';\nimport { writeFileAtomic } from './atomic-json';\nimport { loadConfig } from './config';\nimport type { UpdateMode } from './config';\nimport { emitNotice } from './output';\nimport type { Io } from './output';\nimport type { UpdateAvailable } from '../schemas';\nimport { updateCheckPath } from './paths';\n\n/**\n * \"A newer tenjin-cli exists\", asked of npm at most once a day and reported\n * three ways: one dim stderr line for a human at a terminal, `updateAvailable`\n * on the JSON envelope, and a line on the generated hook scripts' output.\n *\n * It REPORTS and never installs. A CLI that starts a fresh process per\n * invocation has no deferred-activation window to hide a binary swap in — \"next\n * start\" is \"mid-session\" for whatever is driving it — so the decision to run\n * `tenjin update` belongs to the agent or the human, not to this check.\n *\n * Everything here is subordinate to the command that ran: the fetch happens\n * AFTER the envelope is written, it never touches stdout, it never changes an\n * exit code, and every failure it can have (offline, slow registry, junk JSON, a\n * tag that does not exist) is swallowed. CI skips the whole thing: a build log\n * can act on none of it. `update.mode off` is the opt-out and silences all three\n * surfaces, including the request to npm.\n */\n\n/**\n * Silences this check for one process, cache write and registry request\n * included. Set by `update` on the `install --refresh` children it spawns: their\n * data dirs come out of a settings file this CLI does not own, and this check is\n * the one thing in a refresh that would CREATE such a directory — `writeCache`\n * mkdirs the tree — where the refresh itself only converges what exists.\n *\n * A separate switch rather than `CI`, which would also stand the skills heal\n * down (lib/skill-heal) and so gut the refresh it was set for.\n */\nexport const NUDGE_OPT_OUT = 'TENJIN_NO_UPDATE_CHECK';\n\nconst CHECK_INTERVAL_MS = 86_400_000; // 24h\nconst FETCH_TIMEOUT_MS = 1500;\nconst DIST_TAGS_URL = 'https://registry.npmjs.org/-/package/tenjin-cli/dist-tags';\n\n/** What is known about ONE dist-tag: when it was asked, and what it said. */\nconst TagEntrySchema = z.object({\n checkedAtMs: z.number(),\n /** The version the tag named. Absent when the answer was unusable. */\n latest: z.string().optional(),\n /** When the nudge was last PRINTED for this tag. Absent until one has been. */\n notifiedAtMs: z.number().optional(),\n});\n\n/**\n * The cache is a pure optimization, so a bad one is re-fetched, never repaired.\n * Keyed by dist-tag: an entry this build did not ask about is carried forward\n * untouched rather than evicted.\n */\nconst CacheSchema = z.object({\n schemaVersion: z.literal(1),\n tags: z.record(z.string(), TagEntrySchema),\n /**\n * The resolved \"you could upgrade\" fact, written whenever it changes and\n * cleared when it stops being true.\n *\n * Denormalized from `tags` on purpose: the generated hook scripts are\n * standalone .mjs that cannot import this module and do not know which\n * version is running, so a per-tag entry would leave them unable to tell an\n * upgrade from a match. Storing the comparison's ANSWER is what lets a hook\n * report it without reimplementing any of it.\n */\n signal: z.object({ current: z.string(), latest: z.string() }).optional(),\n});\ntype Cache = z.infer<typeof CacheSchema>;\n\n/** `{\"latest\":\"1.2.3\",\"alpha\":\"1.3.0-alpha.1\"}` — tag names are not fixed. */\nconst DistTagsSchema = z.record(z.string(), z.string());\n\nexport interface UpdateCheckDeps {\n dir: string;\n io: Io;\n /** The global --json flag; ANDed with io.isTTY exactly as the emit path does. */\n json: boolean;\n env?: NodeJS.ProcessEnv;\n /** Clock seam (ms since epoch) for deterministic TTL tests. */\n now?: () => number;\n /** Override global fetch (tests inject a stub returning canned Responses). */\n fetchImpl?: typeof fetch;\n /** The running version; defaults to this build's. Injectable for tests. */\n currentVersion?: string;\n /** Resolved update.mode; defaults to reading the config file. */\n mode?: UpdateMode;\n}\n\n/**\n * Print the update nudge if one is due. NEVER rejects — the caller awaits it\n * between a command's output and its exit, so a throw here would replace a\n * finished command's result with an internal error.\n */\nexport async function maybeUpdate(deps: UpdateCheckDeps): Promise<void> {\n try {\n const env = deps.env ?? process.env;\n // Never in CI, in either mode: a build log cannot act on a nudge, and a\n // build machine must not silently acquire a different binary mid-pipeline.\n if (env.CI !== undefined && env.CI.length > 0) return;\n if (env[NUDGE_OPT_OUT] === '1') return;\n\n const mode = deps.mode ?? (await loadConfig(deps.dir)).update.mode;\n if (mode === 'off') return;\n\n const nowMs = (deps.now ?? Date.now)();\n const current = deps.currentVersion ?? pkg.version;\n const path = updateCheckPath(deps.dir);\n const tag = channelTag(current);\n if (tag === null) return; // a version this build cannot parse follows no channel\n\n // Only this tag's entry answers this binary's question; the other channel's\n // is neither used nor disturbed.\n const cached = await readCache(path);\n const entry = cached?.tags[tag];\n const fresh = entry !== undefined && nowMs - entry.checkedAtMs < CHECK_INTERVAL_MS;\n\n // Resolved through the same function `tenjin update` uses, so the nudge can\n // never advertise a version the command would decline to install, nor stay\n // quiet about one it would.\n //\n // Only a registry that could not be ASKED returns without caching; an answer\n // this build cannot use has still been answered, and moves the clock below.\n let latest: string | null;\n if (fresh) {\n latest = entry.latest ?? null;\n } else {\n const answer = await resolveLatest(current, deps);\n if (answer === null) return;\n latest = answer.latest;\n }\n\n const upgradeable = latest !== null && isNewer(latest, current);\n\n // Once a day means once a day, not once per FETCH: a fresh cache would\n // otherwise repeat the same line on every command for 24h. The two clocks are\n // separate because they answer separate questions — when we last asked npm,\n // and when we last interrupted the human.\n //\n // `human` is part of `due` for the second of those: this code now runs on\n // every surface, to feed the envelope signal, so without it an agent run\n // would stamp the nudge clock having printed nothing and leave a shared\n // machine's terminal quiet for 24h.\n const human = deps.io.isTTY && !deps.json;\n const notifiedAtMs = entry?.notifiedAtMs;\n const due =\n human &&\n upgradeable &&\n (notifiedAtMs === undefined || nowMs - notifiedAtMs >= CHECK_INTERVAL_MS);\n\n // Carried forward when nothing is printed: the day since the last nudge does\n // not restart just because the registry was asked again.\n const nudgedAtMs = due ? nowMs : notifiedAtMs;\n\n // Carries the agent-visible half of the answer, so a hook or an envelope can\n // report it without knowing which version is running.\n const signal = upgradeable && latest !== null ? { current, latest } : undefined;\n const signalChanged =\n cached?.signal?.current !== signal?.current || cached?.signal?.latest !== signal?.latest;\n\n // Nothing learned and nothing said means nothing to write. Deliberately NOT\n // locked: two concurrent CLI processes can both nudge, and one duplicated\n // line is cheaper than a lock on the exit path of every command.\n if (!fresh || due || signalChanged) {\n await writeCache(path, {\n schemaVersion: 1,\n ...(signal !== undefined ? { signal } : {}),\n // Read-modify-write: the tag this run did not ask about keeps whatever it\n // knew, including its own nudge clock.\n tags: {\n ...cached?.tags,\n [tag]: {\n checkedAtMs: fresh ? entry.checkedAtMs : nowMs,\n ...(latest !== null ? { latest } : {}),\n ...(nudgedAtMs !== undefined ? { notifiedAtMs: nudgedAtMs } : {}),\n },\n },\n });\n }\n\n // Named as the command, not the npm invocation it wraps: `update` prints the\n // right instructions itself for an install it cannot perform (a source\n // checkout, a yarn global), so this line is correct everywhere.\n if (due && latest !== null) {\n emitNotice(\n deps.io,\n `tenjin-cli ${latest} is available (you have ${current}). Update: run tenjin update`,\n { json: deps.json },\n );\n }\n } catch {\n // Unreachable by construction (every step below is already guarded); here so\n // that staying invisible does not depend on that remaining true.\n }\n}\n\n/**\n * What the last check learned, for the envelope. Cache only: this runs before\n * every command's output, so it may not fetch, may not block, and may not throw.\n * Null when nothing newer is known, when the cache is absent or stale-shaped, or\n * when `update.mode` is `off` — off silences BOTH surfaces, not just the line a\n * human sees.\n *\n * Reporting rather than installing is the whole design. A CLI that starts a\n * fresh process per invocation has no deferred-activation moment to hide a\n * binary swap in, so the agent is told and decides for itself.\n */\nexport async function readUpdateSignal(\n dir: string,\n currentVersion?: string,\n): Promise<UpdateAvailable | null> {\n try {\n const current = currentVersion ?? pkg.version;\n const tag = channelTag(current);\n if (tag === null) return null;\n if ((await loadConfig(dir)).update.mode === 'off') return null;\n const cached = await readCache(updateCheckPath(dir));\n const latest = cached?.tags[tag]?.latest;\n if (latest === undefined || !isNewer(latest, current)) return null;\n return { current, latest };\n } catch {\n return null; // never the command's business\n }\n}\n\n/**\n * Which dist-tag this build follows, or null for a version string this package\n * has no channel for. Null rather than a default, because every caller's right\n * answer differs: the nudge goes quiet, and `tenjin update` refuses instead of\n * silently reporting a foreign build \"up to date\" against a tag it never\n * belonged to.\n *\n * Every build follows `latest`; see RELEASING.md, which changes with this.\n */\nexport function channelTag(version: string): 'latest' | null {\n return parseVersion(version) === null ? null : 'latest';\n}\n\n/**\n * The version this build can move to: whatever sits on the tag it follows.\n * Consulting a second tag added no reachable version and one way to be wrong: a\n * tag sitting ahead of `latest` could redirect the self-update to a build the\n * release line never promoted. Null both when that tag is absent and when it\n * names a version VERSION_RE rejects; `runUpdate` separates those, and neither\n * means the registry was unreachable.\n */\nexport function resolveTarget(current: string, tags: Record<string, string>): string | null {\n const channel = channelTag(current);\n if (channel === null) return null;\n const candidate = tags[channel];\n // Unparseable counts as absent: isNewer loses every comparison against junk,\n // so admitting one would read as \"up to date\" forever.\n if (candidate === undefined || parseVersion(candidate) === null) return null;\n return candidate;\n}\n\n/**\n * Ask the registry for tenjin-cli's whole dist-tag map. Returns null for every\n * failure there is, INCLUDING a response that arrives too late — the AbortSignal\n * is what bounds the delay a finished command can suffer. Nothing is written\n * here: a failed check caches nothing, so the next command retries rather than\n * going quiet for 24h over one dropped packet. The nudge passes its own short\n * budget; `tenjin update` passes the run's request timeout, because there the\n * fetch IS the command rather than a stowaway on someone else's exit path.\n *\n * The whole map rather than one tag, so a caller can tell an unreachable\n * registry (null) from one that answered without the tag it asked for (a map\n * that lacks the key) — two failures with two different fixes.\n */\nexport async function fetchDistTags(opts: {\n fetchImpl?: typeof fetch;\n timeoutMs: number;\n}): Promise<Record<string, string> | null> {\n const doFetch = opts.fetchImpl ?? fetch;\n let json: unknown;\n try {\n const res = await doFetch(DIST_TAGS_URL, { signal: AbortSignal.timeout(opts.timeoutMs) });\n if (!res.ok) return null;\n json = await res.json();\n } catch {\n return null;\n }\n const parsed = DistTagsSchema.safeParse(json);\n return parsed.success ? parsed.data : null;\n}\n\n/**\n * The nudge's one-shot: fetch, then resolve. Null when the registry could not be\n * asked; `{ latest: null }` when it answered with nothing usable.\n */\nasync function resolveLatest(\n current: string,\n deps: UpdateCheckDeps,\n): Promise<{ latest: string | null } | null> {\n const tags = await fetchDistTags({ fetchImpl: deps.fetchImpl, timeoutMs: FETCH_TIMEOUT_MS });\n return tags === null ? null : { latest: resolveTarget(current, tags) };\n}\n\nasync function writeCache(path: string, cache: Cache): Promise<void> {\n await writeFileAtomic(path, `${JSON.stringify(cache, null, 2)}\\n`, {\n mode: 0o600,\n dirMode: 0o700,\n });\n}\n\nasync function readCache(path: string): Promise<Cache | null> {\n try {\n const parsed = CacheSchema.safeParse(JSON.parse(await readFile(path, 'utf8')));\n return parsed.success ? parsed.data : null;\n } catch {\n return null;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Version comparison: this package's shape only, no semver dependency.\n// ---------------------------------------------------------------------------\n\n/** `major.minor.patch` with an optional `-alpha.N` — every version tenjin-cli\n * has ever published. Anything else is unparseable ON PURPOSE (see isNewer). */\nconst VERSION_RE = /^(\\d+)\\.(\\d+)\\.(\\d+)(?:-alpha\\.(\\d+))?$/;\n\ninterface Version {\n major: number;\n minor: number;\n patch: number;\n /** null = a release; a number = that prerelease counter. */\n alpha: number | null;\n}\n\nfunction parseVersion(raw: string): Version | null {\n const m = VERSION_RE.exec(raw);\n if (m === null) return null;\n const [, major, minor, patch, alpha] = m;\n if (major === undefined || minor === undefined || patch === undefined) return null;\n return {\n major: Number(major),\n minor: Number(minor),\n patch: Number(patch),\n alpha: alpha !== undefined ? Number(alpha) : null,\n };\n}\n\n/**\n * Is `candidate` newer than `current`? An unparseable version on EITHER side is\n * \"not newer\": the registry is untrusted input, and the failure mode of guessing\n * is nagging every single command with a line the user cannot act on. A true\n * return therefore also certifies that BOTH sides parse, which is what lets\n * `tenjin update` splice the candidate into an npm argv without re-validating.\n */\nexport function isNewer(candidate: string, current: string): boolean {\n const a = parseVersion(candidate);\n const b = parseVersion(current);\n if (a === null || b === null) return false;\n if (a.major !== b.major) return a.major > b.major;\n if (a.minor !== b.minor) return a.minor > b.minor;\n if (a.patch !== b.patch) return a.patch > b.patch;\n // Same release triple: semver says a prerelease precedes its own release, so\n // 0.1.0 beats 0.1.0-alpha.9 and never the other way around.\n if (a.alpha === null) return b.alpha !== null;\n if (b.alpha === null) return false;\n return a.alpha > b.alpha;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAS,gBAAgB;AAuClB,IAAM,gBAAgB;AAE7B,IAAM,oBAAoB;AAC1B,IAAM,mBAAmB;AACzB,IAAM,gBAAgB;AAGtB,IAAM,iBAAiB,iBAAE,OAAO;AAAA,EAC9B,aAAa,iBAAE,OAAO;AAAA;AAAA,EAEtB,QAAQ,iBAAE,OAAO,EAAE,SAAS;AAAA;AAAA,EAE5B,cAAc,iBAAE,OAAO,EAAE,SAAS;AACpC,CAAC;AAOD,IAAM,cAAc,iBAAE,OAAO;AAAA,EAC3B,eAAe,iBAAE,QAAQ,CAAC;AAAA,EAC1B,MAAM,iBAAE,OAAO,iBAAE,OAAO,GAAG,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWzC,QAAQ,iBAAE,OAAO,EAAE,SAAS,iBAAE,OAAO,GAAG,QAAQ,iBAAE,OAAO,EAAE,CAAC,EAAE,SAAS;AACzE,CAAC;AAID,IAAM,iBAAiB,iBAAE,OAAO,iBAAE,OAAO,GAAG,iBAAE,OAAO,CAAC;AAuBtD,eAAsB,YAAY,MAAsC;AACtE,MAAI;AACF,UAAM,MAAM,KAAK,OAAO,QAAQ;AAGhC,QAAI,IAAI,OAAO,UAAa,IAAI,GAAG,SAAS,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AAM,QAAO;AACrC,MAAI,EAAE,UAAU,EAAE,MAAO,QAAO,EAAE,QAAQ,EAAE;AAC5C,MAAI,EAAE,UAAU,EAAE,MAAO,QAAO,EAAE,QAAQ,EAAE;AAC5C,MAAI,EAAE,UAAU,EAAE,MAAO,QAAO,EAAE,QAAQ,EAAE;AAG5C,MAAI,EAAE,UAAU,KAAM,QAAO,EAAE,UAAU;AACzC,MAAI,EAAE,UAAU,KAAM,QAAO;AAC7B,SAAO,EAAE,QAAQ,EAAE;AACrB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/lib/update-check.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { z } from 'zod';\nimport pkg from '../../package.json';\nimport { writeFileAtomic } from './atomic-json';\nimport { loadConfig } from './config';\nimport type { UpdateMode } from './config';\nimport { emitNotice } from './output';\nimport type { Io } from './output';\nimport type { UpdateAvailable } from '../schemas';\nimport { updateCheckPath } from './paths';\n\n/**\n * \"A newer tenjin-cli exists\", asked of npm at most once a day and reported\n * three ways: one dim stderr line for a human at a terminal, `updateAvailable`\n * on the JSON envelope, and a line on the generated hook scripts' output.\n *\n * It REPORTS and never installs. A CLI that starts a fresh process per\n * invocation has no deferred-activation window to hide a binary swap in — \"next\n * start\" is \"mid-session\" for whatever is driving it — so the decision to run\n * `tenjin update` belongs to the agent or the human, not to this check.\n *\n * Everything here is subordinate to the command that ran: the fetch happens\n * AFTER the envelope is written, it never touches stdout, it never changes an\n * exit code, and every failure it can have (offline, slow registry, junk JSON, a\n * tag that does not exist) is swallowed. CI skips the whole thing: a build log\n * can act on none of it. `update.mode off` is the opt-out and silences all three\n * surfaces, including the request to npm.\n */\n\n/**\n * Silences this check for one process, cache write and registry request\n * included. Set by `update` on the `install --refresh` children it spawns: their\n * data dirs come out of a settings file this CLI does not own, and this check is\n * the one thing in a refresh that would CREATE such a directory — `writeCache`\n * mkdirs the tree — where the refresh itself only converges what exists.\n *\n * A separate switch rather than `CI`, which would also stand the skills heal\n * down (lib/skill-heal) and so gut the refresh it was set for.\n */\nexport const NUDGE_OPT_OUT = 'TENJIN_NO_UPDATE_CHECK';\n\nconst CHECK_INTERVAL_MS = 86_400_000; // 24h\nconst FETCH_TIMEOUT_MS = 1500;\nconst DIST_TAGS_URL = 'https://registry.npmjs.org/-/package/tenjin-cli/dist-tags';\n\n/** What is known about ONE dist-tag: when it was asked, and what it said. */\nconst TagEntrySchema = z.object({\n checkedAtMs: z.number(),\n /** The version the tag named. Absent when the answer was unusable. */\n latest: z.string().optional(),\n /** When the nudge was last PRINTED for this tag. Absent until one has been. */\n notifiedAtMs: z.number().optional(),\n});\n\n/**\n * The cache is a pure optimization, so a bad one is re-fetched, never repaired.\n * Keyed by dist-tag: an entry this build did not ask about is carried forward\n * untouched rather than evicted.\n */\nconst CacheSchema = z.object({\n schemaVersion: z.literal(1),\n tags: z.record(z.string(), TagEntrySchema),\n /**\n * The resolved \"you could upgrade\" fact, written whenever it changes and\n * cleared when it stops being true.\n *\n * Denormalized from `tags` on purpose: the generated hook scripts are\n * standalone .mjs that cannot import this module and do not know which\n * version is running, so a per-tag entry would leave them unable to tell an\n * upgrade from a match. Storing the comparison's ANSWER is what lets a hook\n * report it without reimplementing any of it.\n */\n signal: z.object({ current: z.string(), latest: z.string() }).optional(),\n});\ntype Cache = z.infer<typeof CacheSchema>;\n\n/** `{\"latest\":\"1.2.3\",\"alpha\":\"1.3.0-alpha.1\"}` — tag names are not fixed. */\nconst DistTagsSchema = z.record(z.string(), z.string());\n\nexport interface UpdateCheckDeps {\n dir: string;\n io: Io;\n /** The global --json flag; ANDed with io.isTTY exactly as the emit path does. */\n json: boolean;\n env?: NodeJS.ProcessEnv;\n /** Clock seam (ms since epoch) for deterministic TTL tests. */\n now?: () => number;\n /** Override global fetch (tests inject a stub returning canned Responses). */\n fetchImpl?: typeof fetch;\n /** The running version; defaults to this build's. Injectable for tests. */\n currentVersion?: string;\n /** Resolved update.mode; defaults to reading the config file. */\n mode?: UpdateMode;\n}\n\n/**\n * Print the update nudge if one is due. NEVER rejects — the caller awaits it\n * between a command's output and its exit, so a throw here would replace a\n * finished command's result with an internal error.\n */\nexport async function maybeUpdate(deps: UpdateCheckDeps): Promise<void> {\n try {\n const env = deps.env ?? process.env;\n // Never in CI, in either mode: a build log cannot act on a nudge, and a\n // build machine must not silently acquire a different binary mid-pipeline.\n if (env.CI !== undefined && env.CI.length > 0) return;\n if (env[NUDGE_OPT_OUT] === '1') return;\n\n const mode = deps.mode ?? (await loadConfig(deps.dir)).update.mode;\n if (mode === 'off') return;\n\n const nowMs = (deps.now ?? Date.now)();\n const current = deps.currentVersion ?? pkg.version;\n const path = updateCheckPath(deps.dir);\n const tag = channelTag(current);\n if (tag === null) return; // a version this build cannot parse follows no channel\n\n // Only this tag's entry answers this binary's question; the other channel's\n // is neither used nor disturbed.\n const cached = await readCache(path);\n const entry = cached?.tags[tag];\n const fresh = entry !== undefined && nowMs - entry.checkedAtMs < CHECK_INTERVAL_MS;\n\n // Resolved through the same function `tenjin update` uses, so the nudge can\n // never advertise a version the command would decline to install, nor stay\n // quiet about one it would.\n //\n // Only a registry that could not be ASKED returns without caching; an answer\n // this build cannot use has still been answered, and moves the clock below.\n let latest: string | null;\n if (fresh) {\n latest = entry.latest ?? null;\n } else {\n const answer = await resolveLatest(current, deps);\n if (answer === null) return;\n latest = answer.latest;\n }\n\n const upgradeable = latest !== null && isNewer(latest, current);\n\n // Once a day means once a day, not once per FETCH: a fresh cache would\n // otherwise repeat the same line on every command for 24h. The two clocks are\n // separate because they answer separate questions — when we last asked npm,\n // and when we last interrupted the human.\n //\n // `human` is part of `due` for the second of those: this code now runs on\n // every surface, to feed the envelope signal, so without it an agent run\n // would stamp the nudge clock having printed nothing and leave a shared\n // machine's terminal quiet for 24h.\n const human = deps.io.isTTY && !deps.json;\n const notifiedAtMs = entry?.notifiedAtMs;\n const due =\n human &&\n upgradeable &&\n (notifiedAtMs === undefined || nowMs - notifiedAtMs >= CHECK_INTERVAL_MS);\n\n // Carried forward when nothing is printed: the day since the last nudge does\n // not restart just because the registry was asked again.\n const nudgedAtMs = due ? nowMs : notifiedAtMs;\n\n // Carries the agent-visible half of the answer, so a hook or an envelope can\n // report it without knowing which version is running.\n const signal = upgradeable && latest !== null ? { current, latest } : undefined;\n const signalChanged =\n cached?.signal?.current !== signal?.current || cached?.signal?.latest !== signal?.latest;\n\n // Nothing learned and nothing said means nothing to write. Deliberately NOT\n // locked: two concurrent CLI processes can both nudge, and one duplicated\n // line is cheaper than a lock on the exit path of every command.\n if (!fresh || due || signalChanged) {\n await writeCache(path, {\n schemaVersion: 1,\n ...(signal !== undefined ? { signal } : {}),\n // Read-modify-write: the tag this run did not ask about keeps whatever it\n // knew, including its own nudge clock.\n tags: {\n ...cached?.tags,\n [tag]: {\n checkedAtMs: fresh ? entry.checkedAtMs : nowMs,\n ...(latest !== null ? { latest } : {}),\n ...(nudgedAtMs !== undefined ? { notifiedAtMs: nudgedAtMs } : {}),\n },\n },\n });\n }\n\n // Named as the command, not the npm invocation it wraps: `update` prints the\n // right instructions itself for an install it cannot perform (a source\n // checkout, a yarn global), so this line is correct everywhere.\n if (due && latest !== null) {\n emitNotice(\n deps.io,\n `tenjin-cli ${latest} is available (you have ${current}). Update: run tenjin update`,\n { json: deps.json },\n );\n }\n } catch {\n // Unreachable by construction (every step below is already guarded); here so\n // that staying invisible does not depend on that remaining true.\n }\n}\n\n/**\n * What the last check learned, for the envelope. Cache only: this runs before\n * every command's output, so it may not fetch, may not block, and may not throw.\n * Null when nothing newer is known, when the cache is absent or stale-shaped, or\n * when `update.mode` is `off` — off silences BOTH surfaces, not just the line a\n * human sees.\n *\n * Reporting rather than installing is the whole design. A CLI that starts a\n * fresh process per invocation has no deferred-activation moment to hide a\n * binary swap in, so the agent is told and decides for itself.\n */\nexport async function readUpdateSignal(\n dir: string,\n currentVersion?: string,\n): Promise<UpdateAvailable | null> {\n try {\n const current = currentVersion ?? pkg.version;\n const tag = channelTag(current);\n if (tag === null) return null;\n if ((await loadConfig(dir)).update.mode === 'off') return null;\n const cached = await readCache(updateCheckPath(dir));\n const latest = cached?.tags[tag]?.latest;\n if (latest === undefined || !isNewer(latest, current)) return null;\n return { current, latest };\n } catch {\n return null; // never the command's business\n }\n}\n\n/**\n * Which dist-tag this build follows, or null for a version string this package\n * has no channel for. Null rather than a default, because every caller's right\n * answer differs: the nudge goes quiet, and `tenjin update` refuses instead of\n * silently reporting a foreign build \"up to date\" against a tag it never\n * belonged to.\n *\n * Every build follows `latest`; see RELEASING.md, which changes with this.\n */\nexport function channelTag(version: string): 'latest' | null {\n return parseVersion(version) === null ? null : 'latest';\n}\n\n/**\n * The version this build can move to: whatever sits on the tag it follows.\n * Consulting a second tag added no reachable version and one way to be wrong: a\n * tag sitting ahead of `latest` could redirect the self-update to a build the\n * release line never promoted. Null both when that tag is absent and when it\n * names a version VERSION_RE rejects; `runUpdate` separates those, and neither\n * means the registry was unreachable.\n */\nexport function resolveTarget(current: string, tags: Record<string, string>): string | null {\n const channel = channelTag(current);\n if (channel === null) return null;\n const candidate = tags[channel];\n // Unparseable counts as absent: isNewer loses every comparison against junk,\n // so admitting one would read as \"up to date\" forever.\n if (candidate === undefined || parseVersion(candidate) === null) return null;\n return candidate;\n}\n\n/**\n * Ask the registry for tenjin-cli's whole dist-tag map. Returns null for every\n * failure there is, INCLUDING a response that arrives too late — the AbortSignal\n * is what bounds the delay a finished command can suffer. Nothing is written\n * here: a failed check caches nothing, so the next command retries rather than\n * going quiet for 24h over one dropped packet. The nudge passes its own short\n * budget; `tenjin update` passes the run's request timeout, because there the\n * fetch IS the command rather than a stowaway on someone else's exit path.\n *\n * The whole map rather than one tag, so a caller can tell an unreachable\n * registry (null) from one that answered without the tag it asked for (a map\n * that lacks the key) — two failures with two different fixes.\n */\nexport async function fetchDistTags(opts: {\n fetchImpl?: typeof fetch;\n timeoutMs: number;\n}): Promise<Record<string, string> | null> {\n const doFetch = opts.fetchImpl ?? fetch;\n let json: unknown;\n try {\n const res = await doFetch(DIST_TAGS_URL, { signal: AbortSignal.timeout(opts.timeoutMs) });\n if (!res.ok) return null;\n json = await res.json();\n } catch {\n return null;\n }\n const parsed = DistTagsSchema.safeParse(json);\n return parsed.success ? parsed.data : null;\n}\n\n/**\n * The nudge's one-shot: fetch, then resolve. Null when the registry could not be\n * asked; `{ latest: null }` when it answered with nothing usable.\n */\nasync function resolveLatest(\n current: string,\n deps: UpdateCheckDeps,\n): Promise<{ latest: string | null } | null> {\n const tags = await fetchDistTags({ fetchImpl: deps.fetchImpl, timeoutMs: FETCH_TIMEOUT_MS });\n return tags === null ? null : { latest: resolveTarget(current, tags) };\n}\n\nasync function writeCache(path: string, cache: Cache): Promise<void> {\n await writeFileAtomic(path, `${JSON.stringify(cache, null, 2)}\\n`, {\n mode: 0o600,\n dirMode: 0o700,\n });\n}\n\nasync function readCache(path: string): Promise<Cache | null> {\n try {\n const parsed = CacheSchema.safeParse(JSON.parse(await readFile(path, 'utf8')));\n return parsed.success ? parsed.data : null;\n } catch {\n return null;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Version comparison: this package's shape only, no semver dependency.\n// ---------------------------------------------------------------------------\n\n/** `major.minor.patch` with an optional `-alpha.N` — every version tenjin-cli\n * has ever published. Anything else is unparseable ON PURPOSE (see isNewer). */\nconst VERSION_RE = /^(\\d+)\\.(\\d+)\\.(\\d+)(?:-alpha\\.(\\d+))?$/;\n\ninterface Version {\n major: number;\n minor: number;\n patch: number;\n /** null = a release; a number = that prerelease counter. */\n alpha: number | null;\n}\n\nfunction parseVersion(raw: string): Version | null {\n const m = VERSION_RE.exec(raw);\n if (m === null) return null;\n const [, major, minor, patch, alpha] = m;\n if (major === undefined || minor === undefined || patch === undefined) return null;\n return {\n major: Number(major),\n minor: Number(minor),\n patch: Number(patch),\n alpha: alpha !== undefined ? Number(alpha) : null,\n };\n}\n\n/**\n * Is `candidate` newer than `current`? An unparseable version on EITHER side is\n * \"not newer\": the registry is untrusted input, and the failure mode of guessing\n * is nagging every single command with a line the user cannot act on. A true\n * return therefore also certifies that BOTH sides parse, which is what lets\n * `tenjin update` splice the candidate into an npm argv without re-validating.\n */\nexport function isNewer(candidate: string, current: string): boolean {\n const a = parseVersion(candidate);\n const b = parseVersion(current);\n if (a === null || b === null) return false;\n if (a.major !== b.major) return a.major > b.major;\n if (a.minor !== b.minor) return a.minor > b.minor;\n if (a.patch !== b.patch) return a.patch > b.patch;\n // Same release triple: semver says a prerelease precedes its own release, so\n // 0.1.0 beats 0.1.0-alpha.9 and never the other way around.\n if (a.alpha === null) return b.alpha !== null;\n if (b.alpha === null) return false;\n return a.alpha > b.alpha;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,SAAS,gBAAgB;AAuClB,IAAM,gBAAgB;AAE7B,IAAM,oBAAoB;AAC1B,IAAM,mBAAmB;AACzB,IAAM,gBAAgB;AAGtB,IAAM,iBAAiB,iBAAE,OAAO;AAAA,EAC9B,aAAa,iBAAE,OAAO;AAAA;AAAA,EAEtB,QAAQ,iBAAE,OAAO,EAAE,SAAS;AAAA;AAAA,EAE5B,cAAc,iBAAE,OAAO,EAAE,SAAS;AACpC,CAAC;AAOD,IAAM,cAAc,iBAAE,OAAO;AAAA,EAC3B,eAAe,iBAAE,QAAQ,CAAC;AAAA,EAC1B,MAAM,iBAAE,OAAO,iBAAE,OAAO,GAAG,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWzC,QAAQ,iBAAE,OAAO,EAAE,SAAS,iBAAE,OAAO,GAAG,QAAQ,iBAAE,OAAO,EAAE,CAAC,EAAE,SAAS;AACzE,CAAC;AAID,IAAM,iBAAiB,iBAAE,OAAO,iBAAE,OAAO,GAAG,iBAAE,OAAO,CAAC;AAuBtD,eAAsB,YAAY,MAAsC;AACtE,MAAI;AACF,UAAM,MAAM,KAAK,OAAO,QAAQ;AAGhC,QAAI,IAAI,OAAO,UAAa,IAAI,GAAG,SAAS,EAAG;AAC/C,QAAI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AAI,EAAE,UAAU,EAAE,MAAO,QAAO,EAAE,QAAQ,EAAE;AAC5C,MAAI,EAAE,UAAU,EAAE,MAAO,QAAO,EAAE,QAAQ,EAAE;AAC5C,MAAI,EAAE,UAAU,EAAE,MAAO,QAAO,EAAE,QAAQ,EAAE;AAG5C,MAAI,EAAE,UAAU,KAAM,QAAO,EAAE,UAAU;AACzC,MAAI,EAAE,UAAU,KAAM,QAAO;AAC7B,SAAO,EAAE,QAAQ,EAAE;AACrB;","names":[]}
|
|
@@ -1,72 +1,14 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
DEFAULT_RPC_URL
|
|
4
|
+
} from "./chunk-O2FRQ2L2.js";
|
|
5
|
+
import {
|
|
4
6
|
configPath
|
|
5
7
|
} from "./chunk-SJLTEINJ.js";
|
|
6
8
|
import {
|
|
7
9
|
__export
|
|
8
10
|
} from "./chunk-ZXTAQYNA.js";
|
|
9
11
|
|
|
10
|
-
// src/lib/atomic-json.ts
|
|
11
|
-
import { chmod, link, mkdir, open, rename, rm, writeFile } from "node:fs/promises";
|
|
12
|
-
import { randomBytes } from "node:crypto";
|
|
13
|
-
import { basename, dirname, join } from "node:path";
|
|
14
|
-
var isWindows = process.platform === "win32";
|
|
15
|
-
async function writeFileAtomic(targetPath, data, opts = {}) {
|
|
16
|
-
const dir = dirname(targetPath);
|
|
17
|
-
const fileMode = opts.mode ?? 420;
|
|
18
|
-
const dirMode = opts.dirMode ?? 493;
|
|
19
|
-
await mkdir(dir, { recursive: true, ...isWindows ? {} : { mode: dirMode } });
|
|
20
|
-
const tmpPath = join(dir, `.${basename(targetPath)}.${randomBytes(6).toString("hex")}.tmp`);
|
|
21
|
-
try {
|
|
22
|
-
await writeFile(tmpPath, data, isWindows ? void 0 : { mode: fileMode });
|
|
23
|
-
if (!isWindows) await chmod(tmpPath, fileMode);
|
|
24
|
-
await rename(tmpPath, targetPath);
|
|
25
|
-
} catch (err) {
|
|
26
|
-
await rm(tmpPath, { force: true }).catch(() => void 0);
|
|
27
|
-
throw err;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async function writeFileAtomicExclusive(targetPath, data, opts = {}) {
|
|
31
|
-
const dir = dirname(targetPath);
|
|
32
|
-
const fileMode = opts.mode ?? 420;
|
|
33
|
-
const dirMode = opts.dirMode ?? 493;
|
|
34
|
-
await mkdir(dir, { recursive: true, ...isWindows ? {} : { mode: dirMode } });
|
|
35
|
-
if (isWindows) {
|
|
36
|
-
const handle = await open(targetPath, "wx");
|
|
37
|
-
try {
|
|
38
|
-
await handle.writeFile(data);
|
|
39
|
-
await handle.sync();
|
|
40
|
-
} finally {
|
|
41
|
-
await handle.close();
|
|
42
|
-
}
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const tmpPath = join(dir, `.${basename(targetPath)}.${randomBytes(6).toString("hex")}.tmp`);
|
|
46
|
-
try {
|
|
47
|
-
const handle = await open(tmpPath, "wx", fileMode);
|
|
48
|
-
try {
|
|
49
|
-
await handle.writeFile(data);
|
|
50
|
-
await handle.chmod(fileMode);
|
|
51
|
-
await handle.sync();
|
|
52
|
-
} finally {
|
|
53
|
-
await handle.close();
|
|
54
|
-
}
|
|
55
|
-
await link(tmpPath, targetPath);
|
|
56
|
-
await fsyncDir(dir);
|
|
57
|
-
} finally {
|
|
58
|
-
await rm(tmpPath, { force: true }).catch(() => void 0);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
async function fsyncDir(dir) {
|
|
62
|
-
const handle = await open(dir, "r");
|
|
63
|
-
try {
|
|
64
|
-
await handle.sync();
|
|
65
|
-
} finally {
|
|
66
|
-
await handle.close();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
12
|
// node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/external.js
|
|
71
13
|
var external_exports = {};
|
|
72
14
|
__export(external_exports, {
|
|
@@ -573,7 +515,7 @@ __export(core_exports2, {
|
|
|
573
515
|
parse: () => parse,
|
|
574
516
|
parseAsync: () => parseAsync,
|
|
575
517
|
prettifyError: () => prettifyError,
|
|
576
|
-
process: () =>
|
|
518
|
+
process: () => process,
|
|
577
519
|
regexes: () => regexes_exports,
|
|
578
520
|
registry: () => registry,
|
|
579
521
|
safeDecode: () => safeDecode,
|
|
@@ -11498,7 +11440,7 @@ function initializeContext(params) {
|
|
|
11498
11440
|
external: params?.external ?? void 0
|
|
11499
11441
|
};
|
|
11500
11442
|
}
|
|
11501
|
-
function
|
|
11443
|
+
function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
|
|
11502
11444
|
var _a3;
|
|
11503
11445
|
const def = schema._zod.def;
|
|
11504
11446
|
const seen = ctx.seen.get(schema);
|
|
@@ -11535,7 +11477,7 @@ function process2(schema, ctx, _params = { path: [], schemaPath: [] }) {
|
|
|
11535
11477
|
if (parent) {
|
|
11536
11478
|
if (!result.ref)
|
|
11537
11479
|
result.ref = parent;
|
|
11538
|
-
|
|
11480
|
+
process(parent, ctx, params);
|
|
11539
11481
|
ctx.seen.get(parent).isParent = true;
|
|
11540
11482
|
}
|
|
11541
11483
|
}
|
|
@@ -11823,14 +11765,14 @@ function isTransforming(_schema, _ctx) {
|
|
|
11823
11765
|
}
|
|
11824
11766
|
var createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
|
|
11825
11767
|
const ctx = initializeContext({ ...params, processors });
|
|
11826
|
-
|
|
11768
|
+
process(schema, ctx);
|
|
11827
11769
|
extractDefs(ctx, schema);
|
|
11828
11770
|
return finalize(ctx, schema);
|
|
11829
11771
|
};
|
|
11830
11772
|
var createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
|
|
11831
11773
|
const { libraryOptions, target } = params ?? {};
|
|
11832
11774
|
const ctx = initializeContext({ ...libraryOptions ?? {}, target, io, processors });
|
|
11833
|
-
|
|
11775
|
+
process(schema, ctx);
|
|
11834
11776
|
extractDefs(ctx, schema);
|
|
11835
11777
|
return finalize(ctx, schema);
|
|
11836
11778
|
};
|
|
@@ -12076,7 +12018,7 @@ var arrayProcessor = (schema, ctx, _json, params) => {
|
|
|
12076
12018
|
if (typeof maximum === "number")
|
|
12077
12019
|
json2.maxItems = maximum;
|
|
12078
12020
|
json2.type = "array";
|
|
12079
|
-
json2.items =
|
|
12021
|
+
json2.items = process(def.element, ctx, {
|
|
12080
12022
|
...params,
|
|
12081
12023
|
path: [...params.path, "items"]
|
|
12082
12024
|
});
|
|
@@ -12088,7 +12030,7 @@ var objectProcessor = (schema, ctx, _json, params) => {
|
|
|
12088
12030
|
json2.properties = {};
|
|
12089
12031
|
const shape = def.shape;
|
|
12090
12032
|
for (const key in shape) {
|
|
12091
|
-
json2.properties[key] =
|
|
12033
|
+
json2.properties[key] = process(shape[key], ctx, {
|
|
12092
12034
|
...params,
|
|
12093
12035
|
path: [...params.path, "properties", key]
|
|
12094
12036
|
});
|
|
@@ -12111,7 +12053,7 @@ var objectProcessor = (schema, ctx, _json, params) => {
|
|
|
12111
12053
|
if (ctx.io === "output")
|
|
12112
12054
|
json2.additionalProperties = false;
|
|
12113
12055
|
} else if (def.catchall) {
|
|
12114
|
-
json2.additionalProperties =
|
|
12056
|
+
json2.additionalProperties = process(def.catchall, ctx, {
|
|
12115
12057
|
...params,
|
|
12116
12058
|
path: [...params.path, "additionalProperties"]
|
|
12117
12059
|
});
|
|
@@ -12120,7 +12062,7 @@ var objectProcessor = (schema, ctx, _json, params) => {
|
|
|
12120
12062
|
var unionProcessor = (schema, ctx, json2, params) => {
|
|
12121
12063
|
const def = schema._zod.def;
|
|
12122
12064
|
const isExclusive = def.inclusive === false;
|
|
12123
|
-
const options = def.options.map((x, i) =>
|
|
12065
|
+
const options = def.options.map((x, i) => process(x, ctx, {
|
|
12124
12066
|
...params,
|
|
12125
12067
|
path: [...params.path, isExclusive ? "oneOf" : "anyOf", i]
|
|
12126
12068
|
}));
|
|
@@ -12132,11 +12074,11 @@ var unionProcessor = (schema, ctx, json2, params) => {
|
|
|
12132
12074
|
};
|
|
12133
12075
|
var intersectionProcessor = (schema, ctx, json2, params) => {
|
|
12134
12076
|
const def = schema._zod.def;
|
|
12135
|
-
const a =
|
|
12077
|
+
const a = process(def.left, ctx, {
|
|
12136
12078
|
...params,
|
|
12137
12079
|
path: [...params.path, "allOf", 0]
|
|
12138
12080
|
});
|
|
12139
|
-
const b =
|
|
12081
|
+
const b = process(def.right, ctx, {
|
|
12140
12082
|
...params,
|
|
12141
12083
|
path: [...params.path, "allOf", 1]
|
|
12142
12084
|
});
|
|
@@ -12153,11 +12095,11 @@ var tupleProcessor = (schema, ctx, _json, params) => {
|
|
|
12153
12095
|
json2.type = "array";
|
|
12154
12096
|
const prefixPath = ctx.target === "draft-2020-12" ? "prefixItems" : "items";
|
|
12155
12097
|
const restPath = ctx.target === "draft-2020-12" ? "items" : ctx.target === "openapi-3.0" ? "items" : "additionalItems";
|
|
12156
|
-
const prefixItems = def.items.map((x, i) =>
|
|
12098
|
+
const prefixItems = def.items.map((x, i) => process(x, ctx, {
|
|
12157
12099
|
...params,
|
|
12158
12100
|
path: [...params.path, prefixPath, i]
|
|
12159
12101
|
}));
|
|
12160
|
-
const rest = def.rest ?
|
|
12102
|
+
const rest = def.rest ? process(def.rest, ctx, {
|
|
12161
12103
|
...params,
|
|
12162
12104
|
path: [...params.path, restPath, ...ctx.target === "openapi-3.0" ? [def.items.length] : []]
|
|
12163
12105
|
}) : null;
|
|
@@ -12197,7 +12139,7 @@ var recordProcessor = (schema, ctx, _json, params) => {
|
|
|
12197
12139
|
const keyBag = keyType._zod.bag;
|
|
12198
12140
|
const patterns = keyBag?.patterns;
|
|
12199
12141
|
if (def.mode === "loose" && patterns && patterns.size > 0) {
|
|
12200
|
-
const valueSchema =
|
|
12142
|
+
const valueSchema = process(def.valueType, ctx, {
|
|
12201
12143
|
...params,
|
|
12202
12144
|
path: [...params.path, "patternProperties", "*"]
|
|
12203
12145
|
});
|
|
@@ -12207,12 +12149,12 @@ var recordProcessor = (schema, ctx, _json, params) => {
|
|
|
12207
12149
|
}
|
|
12208
12150
|
} else {
|
|
12209
12151
|
if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
|
|
12210
|
-
json2.propertyNames =
|
|
12152
|
+
json2.propertyNames = process(def.keyType, ctx, {
|
|
12211
12153
|
...params,
|
|
12212
12154
|
path: [...params.path, "propertyNames"]
|
|
12213
12155
|
});
|
|
12214
12156
|
}
|
|
12215
|
-
json2.additionalProperties =
|
|
12157
|
+
json2.additionalProperties = process(def.valueType, ctx, {
|
|
12216
12158
|
...params,
|
|
12217
12159
|
path: [...params.path, "additionalProperties"]
|
|
12218
12160
|
});
|
|
@@ -12227,7 +12169,7 @@ var recordProcessor = (schema, ctx, _json, params) => {
|
|
|
12227
12169
|
};
|
|
12228
12170
|
var nullableProcessor = (schema, ctx, json2, params) => {
|
|
12229
12171
|
const def = schema._zod.def;
|
|
12230
|
-
const inner =
|
|
12172
|
+
const inner = process(def.innerType, ctx, params);
|
|
12231
12173
|
const seen = ctx.seen.get(schema);
|
|
12232
12174
|
if (ctx.target === "openapi-3.0") {
|
|
12233
12175
|
seen.ref = def.innerType;
|
|
@@ -12238,20 +12180,20 @@ var nullableProcessor = (schema, ctx, json2, params) => {
|
|
|
12238
12180
|
};
|
|
12239
12181
|
var nonoptionalProcessor = (schema, ctx, _json, params) => {
|
|
12240
12182
|
const def = schema._zod.def;
|
|
12241
|
-
|
|
12183
|
+
process(def.innerType, ctx, params);
|
|
12242
12184
|
const seen = ctx.seen.get(schema);
|
|
12243
12185
|
seen.ref = def.innerType;
|
|
12244
12186
|
};
|
|
12245
12187
|
var defaultProcessor = (schema, ctx, json2, params) => {
|
|
12246
12188
|
const def = schema._zod.def;
|
|
12247
|
-
|
|
12189
|
+
process(def.innerType, ctx, params);
|
|
12248
12190
|
const seen = ctx.seen.get(schema);
|
|
12249
12191
|
seen.ref = def.innerType;
|
|
12250
12192
|
json2.default = JSON.parse(JSON.stringify(def.defaultValue));
|
|
12251
12193
|
};
|
|
12252
12194
|
var prefaultProcessor = (schema, ctx, json2, params) => {
|
|
12253
12195
|
const def = schema._zod.def;
|
|
12254
|
-
|
|
12196
|
+
process(def.innerType, ctx, params);
|
|
12255
12197
|
const seen = ctx.seen.get(schema);
|
|
12256
12198
|
seen.ref = def.innerType;
|
|
12257
12199
|
if (ctx.io === "input")
|
|
@@ -12259,7 +12201,7 @@ var prefaultProcessor = (schema, ctx, json2, params) => {
|
|
|
12259
12201
|
};
|
|
12260
12202
|
var catchProcessor = (schema, ctx, json2, params) => {
|
|
12261
12203
|
const def = schema._zod.def;
|
|
12262
|
-
|
|
12204
|
+
process(def.innerType, ctx, params);
|
|
12263
12205
|
const seen = ctx.seen.get(schema);
|
|
12264
12206
|
seen.ref = def.innerType;
|
|
12265
12207
|
let catchValue;
|
|
@@ -12274,32 +12216,32 @@ var pipeProcessor = (schema, ctx, _json, params) => {
|
|
|
12274
12216
|
const def = schema._zod.def;
|
|
12275
12217
|
const inIsTransform = def.in._zod.traits.has("$ZodTransform");
|
|
12276
12218
|
const innerType = ctx.io === "input" ? inIsTransform ? def.out : def.in : def.out;
|
|
12277
|
-
|
|
12219
|
+
process(innerType, ctx, params);
|
|
12278
12220
|
const seen = ctx.seen.get(schema);
|
|
12279
12221
|
seen.ref = innerType;
|
|
12280
12222
|
};
|
|
12281
12223
|
var readonlyProcessor = (schema, ctx, json2, params) => {
|
|
12282
12224
|
const def = schema._zod.def;
|
|
12283
|
-
|
|
12225
|
+
process(def.innerType, ctx, params);
|
|
12284
12226
|
const seen = ctx.seen.get(schema);
|
|
12285
12227
|
seen.ref = def.innerType;
|
|
12286
12228
|
json2.readOnly = true;
|
|
12287
12229
|
};
|
|
12288
12230
|
var promiseProcessor = (schema, ctx, _json, params) => {
|
|
12289
12231
|
const def = schema._zod.def;
|
|
12290
|
-
|
|
12232
|
+
process(def.innerType, ctx, params);
|
|
12291
12233
|
const seen = ctx.seen.get(schema);
|
|
12292
12234
|
seen.ref = def.innerType;
|
|
12293
12235
|
};
|
|
12294
12236
|
var optionalProcessor = (schema, ctx, _json, params) => {
|
|
12295
12237
|
const def = schema._zod.def;
|
|
12296
|
-
|
|
12238
|
+
process(def.innerType, ctx, params);
|
|
12297
12239
|
const seen = ctx.seen.get(schema);
|
|
12298
12240
|
seen.ref = def.innerType;
|
|
12299
12241
|
};
|
|
12300
12242
|
var lazyProcessor = (schema, ctx, _json, params) => {
|
|
12301
12243
|
const innerType = schema._zod.innerType;
|
|
12302
|
-
|
|
12244
|
+
process(innerType, ctx, params);
|
|
12303
12245
|
const seen = ctx.seen.get(schema);
|
|
12304
12246
|
seen.ref = innerType;
|
|
12305
12247
|
};
|
|
@@ -12351,7 +12293,7 @@ function toJSONSchema(input, params) {
|
|
|
12351
12293
|
const defs = {};
|
|
12352
12294
|
for (const entry of registry2._idmap.entries()) {
|
|
12353
12295
|
const [_, schema] = entry;
|
|
12354
|
-
|
|
12296
|
+
process(schema, ctx2);
|
|
12355
12297
|
}
|
|
12356
12298
|
const schemas = {};
|
|
12357
12299
|
const external = {
|
|
@@ -12374,7 +12316,7 @@ function toJSONSchema(input, params) {
|
|
|
12374
12316
|
return { schemas };
|
|
12375
12317
|
}
|
|
12376
12318
|
const ctx = initializeContext({ ...params, processors: allProcessors });
|
|
12377
|
-
|
|
12319
|
+
process(input, ctx);
|
|
12378
12320
|
extractDefs(ctx, input);
|
|
12379
12321
|
return finalize(ctx, input);
|
|
12380
12322
|
}
|
|
@@ -12432,7 +12374,7 @@ var JSONSchemaGenerator = class {
|
|
|
12432
12374
|
* This must be called before emit().
|
|
12433
12375
|
*/
|
|
12434
12376
|
process(schema, _params = { path: [], schemaPath: [] }) {
|
|
12435
|
-
return
|
|
12377
|
+
return process(schema, this.ctx, _params);
|
|
12436
12378
|
}
|
|
12437
12379
|
/**
|
|
12438
12380
|
* Emit the final JSON Schema after processing.
|
|
@@ -14655,100 +14597,8 @@ function knownDeploymentOrigins() {
|
|
|
14655
14597
|
return [...KNOWN_DEPLOYMENT_ORIGINS];
|
|
14656
14598
|
}
|
|
14657
14599
|
|
|
14658
|
-
// src/lib/usdc-balance.ts
|
|
14659
|
-
import { readFile } from "node:fs/promises";
|
|
14660
|
-
var USDC_ADDRESS = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
14661
|
-
var BALANCE_OF_SELECTOR = "0x70a08231";
|
|
14662
|
-
var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
14663
|
-
var WORD_RE = /^0x[0-9a-fA-F]{64}$/;
|
|
14664
|
-
async function readUsdcBalance(address, rpcUrl, opts) {
|
|
14665
|
-
if (!ADDRESS_RE.test(address) || opts.timeoutMs <= 0) return null;
|
|
14666
|
-
try {
|
|
14667
|
-
const res = await (opts.fetchImpl ?? fetch)(rpcUrl, {
|
|
14668
|
-
method: "POST",
|
|
14669
|
-
headers: { "content-type": "application/json" },
|
|
14670
|
-
body: JSON.stringify({
|
|
14671
|
-
jsonrpc: "2.0",
|
|
14672
|
-
id: 1,
|
|
14673
|
-
method: "eth_call",
|
|
14674
|
-
params: [
|
|
14675
|
-
{
|
|
14676
|
-
to: USDC_ADDRESS,
|
|
14677
|
-
data: `${BALANCE_OF_SELECTOR}${address.slice(2).toLowerCase().padStart(64, "0")}`
|
|
14678
|
-
},
|
|
14679
|
-
"latest"
|
|
14680
|
-
]
|
|
14681
|
-
}),
|
|
14682
|
-
signal: AbortSignal.timeout(opts.timeoutMs)
|
|
14683
|
-
});
|
|
14684
|
-
if (!res.ok) return null;
|
|
14685
|
-
const result = (await res.json())?.result;
|
|
14686
|
-
return typeof result === "string" && WORD_RE.test(result) ? BigInt(result) : null;
|
|
14687
|
-
} catch {
|
|
14688
|
-
return null;
|
|
14689
|
-
}
|
|
14690
|
-
}
|
|
14691
|
-
var DEFAULT_RPC_URL = "https://mainnet.base.org";
|
|
14692
|
-
var FALLBACK_RPC_URLS = [
|
|
14693
|
-
"https://base-rpc.publicnode.com",
|
|
14694
|
-
"https://base.drpc.org"
|
|
14695
|
-
];
|
|
14696
|
-
async function readUsdcBalanceWithFallback(address, rpcUrl, opts) {
|
|
14697
|
-
const urls = sameUrl(rpcUrl, DEFAULT_RPC_URL) ? [rpcUrl, ...FALLBACK_RPC_URLS] : [rpcUrl];
|
|
14698
|
-
const deadline = Date.now() + opts.timeoutMs;
|
|
14699
|
-
for (const [index, url2] of urls.entries()) {
|
|
14700
|
-
const left = deadline - Date.now();
|
|
14701
|
-
if (left <= 0) return null;
|
|
14702
|
-
const timeoutMs = index === urls.length - 1 ? left : Math.ceil(left / 2);
|
|
14703
|
-
const balance = await readUsdcBalance(address, url2, { ...opts, timeoutMs });
|
|
14704
|
-
if (balance !== null) return balance;
|
|
14705
|
-
}
|
|
14706
|
-
return null;
|
|
14707
|
-
}
|
|
14708
|
-
function sameUrl(a, b) {
|
|
14709
|
-
try {
|
|
14710
|
-
return new URL(a).href === new URL(b).href;
|
|
14711
|
-
} catch {
|
|
14712
|
-
return a === b;
|
|
14713
|
-
}
|
|
14714
|
-
}
|
|
14715
|
-
var LAST_KNOWN_BALANCE_MS = 6e4;
|
|
14716
|
-
function rememberingBalanceReader(dataDir, opts = {}) {
|
|
14717
|
-
const read = opts.read ?? readUsdcBalanceWithFallback;
|
|
14718
|
-
const now = opts.now ?? Date.now;
|
|
14719
|
-
const path = balanceCachePath(dataDir);
|
|
14720
|
-
return async (address, rpcUrl, readOpts) => {
|
|
14721
|
-
const remembered = await recallBalance(path, address, now());
|
|
14722
|
-
if (remembered !== null) return remembered;
|
|
14723
|
-
const live = await read(address, rpcUrl, readOpts);
|
|
14724
|
-
if (live === null) return null;
|
|
14725
|
-
const record2 = {
|
|
14726
|
-
version: 1,
|
|
14727
|
-
address: address.toLowerCase(),
|
|
14728
|
-
atomic: live.toString(),
|
|
14729
|
-
at: now()
|
|
14730
|
-
};
|
|
14731
|
-
try {
|
|
14732
|
-
await writeFileAtomic(path, JSON.stringify(record2), { mode: 384, dirMode: 448 });
|
|
14733
|
-
} catch {
|
|
14734
|
-
}
|
|
14735
|
-
return live;
|
|
14736
|
-
};
|
|
14737
|
-
}
|
|
14738
|
-
async function recallBalance(path, address, now) {
|
|
14739
|
-
try {
|
|
14740
|
-
const row = JSON.parse(await readFile(path, "utf8"));
|
|
14741
|
-
if (row?.version !== 1 || row.address !== address.toLowerCase() || typeof row.atomic !== "string" || !/^\d{1,40}$/.test(row.atomic) || typeof row.at !== "number" || now - row.at < 0 || now - row.at > LAST_KNOWN_BALANCE_MS) {
|
|
14742
|
-
return null;
|
|
14743
|
-
}
|
|
14744
|
-
return BigInt(row.atomic);
|
|
14745
|
-
} catch {
|
|
14746
|
-
return null;
|
|
14747
|
-
}
|
|
14748
|
-
}
|
|
14749
|
-
|
|
14750
14600
|
// src/lib/config.ts
|
|
14751
|
-
import { readFile
|
|
14601
|
+
import { readFile } from "node:fs/promises";
|
|
14752
14602
|
|
|
14753
14603
|
// src/adapters/types.ts
|
|
14754
14604
|
var HARNESSES = ["claude", "codex"];
|
|
@@ -14971,9 +14821,13 @@ var DEFAULT_BAZAAR_REGISTRIES = [
|
|
|
14971
14821
|
"https://facilitator.ultravioletadao.xyz",
|
|
14972
14822
|
"https://facilitator.payai.network"
|
|
14973
14823
|
];
|
|
14824
|
+
var DEFAULT_MAX_AUTO_SPEND = "250000";
|
|
14825
|
+
var DEFAULT_SESSION_BUDGET = "5000000";
|
|
14826
|
+
var MAX_AUTO_SPEND_FLOOR_ATOMIC = 250000n;
|
|
14827
|
+
var MAX_AUTO_SPEND_FLOOR_WHY = "The $0.25 minimum is the routing deposit: below it, routing cannot pay at all. To stop automatic payments, turn the router off with `tenjin config set router.enabled false`.";
|
|
14974
14828
|
var CONFIG_DEFAULTS = {
|
|
14975
|
-
maxAutoSpend:
|
|
14976
|
-
sessionBudget:
|
|
14829
|
+
maxAutoSpend: DEFAULT_MAX_AUTO_SPEND,
|
|
14830
|
+
sessionBudget: DEFAULT_SESSION_BUDGET,
|
|
14977
14831
|
// A type placeholder only, never honored: Config requires every key (and
|
|
14978
14832
|
// CONFIG_KEYS derives from these). resolveSendMaxAmount never reads it — an
|
|
14979
14833
|
// absent key resolves to SEND_MAX_UNSET and `tenjin wallet send` refuses until the
|
|
@@ -15055,7 +14909,7 @@ async function loadRawConfig(dir) {
|
|
|
15055
14909
|
const path = configPath(dir);
|
|
15056
14910
|
let raw;
|
|
15057
14911
|
try {
|
|
15058
|
-
raw = await
|
|
14912
|
+
raw = await readFile(path, "utf8");
|
|
15059
14913
|
} catch (err) {
|
|
15060
14914
|
if (isNotFound(err)) return {};
|
|
15061
14915
|
throw new CliError("CONFIG_INVALID", `Could not read config at ${path}`, {
|
|
@@ -15299,9 +15153,6 @@ function formatUsdDisplay(atomic) {
|
|
|
15299
15153
|
}
|
|
15300
15154
|
|
|
15301
15155
|
export {
|
|
15302
|
-
writeFileAtomic,
|
|
15303
|
-
writeFileAtomicExclusive,
|
|
15304
|
-
fsyncDir,
|
|
15305
15156
|
$constructor,
|
|
15306
15157
|
defineLazy,
|
|
15307
15158
|
clone,
|
|
@@ -15338,10 +15189,6 @@ export {
|
|
|
15338
15189
|
isSameDeployment,
|
|
15339
15190
|
knownDeploymentOrigins,
|
|
15340
15191
|
HARNESSES,
|
|
15341
|
-
USDC_ADDRESS,
|
|
15342
|
-
readUsdcBalance,
|
|
15343
|
-
readUsdcBalanceWithFallback,
|
|
15344
|
-
rememberingBalanceReader,
|
|
15345
15192
|
PublishModeSchema,
|
|
15346
15193
|
parseAckServerWarnings,
|
|
15347
15194
|
ROUTER_CONTEXTS,
|
|
@@ -15351,6 +15198,10 @@ export {
|
|
|
15351
15198
|
parseUpdateModeFlag,
|
|
15352
15199
|
RawConfigSchema,
|
|
15353
15200
|
SEND_MAX_UNSET,
|
|
15201
|
+
DEFAULT_MAX_AUTO_SPEND,
|
|
15202
|
+
DEFAULT_SESSION_BUDGET,
|
|
15203
|
+
MAX_AUTO_SPEND_FLOOR_ATOMIC,
|
|
15204
|
+
MAX_AUTO_SPEND_FLOOR_WHY,
|
|
15354
15205
|
CONFIG_DEFAULTS,
|
|
15355
15206
|
CONFIG_KEYS,
|
|
15356
15207
|
PUBLISH_CONFIG_KEYS,
|
|
@@ -15371,4 +15222,4 @@ export {
|
|
|
15371
15222
|
toMoney,
|
|
15372
15223
|
formatUsdDisplay
|
|
15373
15224
|
};
|
|
15374
|
-
//# sourceMappingURL=chunk-
|
|
15225
|
+
//# sourceMappingURL=chunk-WO5BJNIB.js.map
|