tenjin-cli 0.1.0-alpha.4 → 0.1.0-alpha.7
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 +269 -38
- package/dist/{buy-OOOLUDND.js → buy-XVOMNWKN.js} +21 -18
- package/dist/{candidate-TWCWTFGA.js → candidate-DJB2NNTG.js} +7 -8
- package/dist/{chunk-KXIX7YDV.js → chunk-2KIDDWQO.js} +5 -5
- package/dist/{chunk-NXCJN2FJ.js → chunk-2L73UI6T.js} +51 -42
- package/dist/chunk-2L73UI6T.js.map +1 -0
- package/dist/{chunk-OJD54DIU.js → chunk-2YX6LTCD.js} +5 -5
- package/dist/{chunk-H5ETJRQD.js → chunk-5X4EBGGU.js} +22 -14
- package/dist/chunk-5X4EBGGU.js.map +1 -0
- package/dist/chunk-6S44OLND.js +699 -0
- package/dist/chunk-6S44OLND.js.map +1 -0
- package/dist/{chunk-FU6MCSLG.js → chunk-7WDY4AXV.js} +2 -64
- package/dist/chunk-7WDY4AXV.js.map +1 -0
- package/dist/{chunk-VV4P5RVK.js → chunk-BBUYCDSG.js} +16 -4
- package/dist/chunk-BBUYCDSG.js.map +1 -0
- package/dist/chunk-CYRYVZPN.js +213 -0
- package/dist/chunk-CYRYVZPN.js.map +1 -0
- package/dist/{chunk-FHB3VKZW.js → chunk-DAJ56EUU.js} +5 -3
- package/dist/chunk-DAJ56EUU.js.map +1 -0
- package/dist/chunk-DH6D6QIO.js +239 -0
- package/dist/chunk-DH6D6QIO.js.map +1 -0
- package/dist/chunk-E6BNARCS.js +614 -0
- package/dist/chunk-E6BNARCS.js.map +1 -0
- package/dist/chunk-GABYDXWL.js +190 -0
- package/dist/chunk-GABYDXWL.js.map +1 -0
- package/dist/{chunk-EUQN3L5X.js → chunk-GM4RZUVU.js} +21 -9
- package/dist/chunk-GM4RZUVU.js.map +1 -0
- package/dist/{chunk-C4TIWOAM.js → chunk-GXYNLMUQ.js} +28 -11
- package/dist/chunk-GXYNLMUQ.js.map +1 -0
- package/dist/{chunk-6WWVYYSB.js → chunk-J6CVKC4M.js} +86 -4
- package/dist/chunk-J6CVKC4M.js.map +1 -0
- package/dist/{chunk-5JH7ZB6Z.js → chunk-KT2DGKFT.js} +76 -10
- package/dist/chunk-KT2DGKFT.js.map +1 -0
- package/dist/chunk-L6AV2Q73.js +105 -0
- package/dist/chunk-L6AV2Q73.js.map +1 -0
- package/dist/{chunk-333FOTUJ.js → chunk-MJZZTKCC.js} +108 -2
- package/dist/chunk-MJZZTKCC.js.map +1 -0
- package/dist/{chunk-XNNOR7F7.js → chunk-OTDI5FXG.js} +3 -5
- package/dist/{chunk-XNNOR7F7.js.map → chunk-OTDI5FXG.js.map} +1 -1
- package/dist/chunk-PIIWLEEG.js +337 -0
- package/dist/chunk-PIIWLEEG.js.map +1 -0
- package/dist/{chunk-ULLWHHIT.js → chunk-PLU3E63S.js} +468 -559
- package/dist/chunk-PLU3E63S.js.map +1 -0
- package/dist/chunk-QW2Q2KAH.js +27 -0
- package/dist/chunk-QW2Q2KAH.js.map +1 -0
- package/dist/{chunk-S3KZ3PPK.js → chunk-RGFBBNGP.js} +291 -59
- package/dist/chunk-RGFBBNGP.js.map +1 -0
- package/dist/chunk-SGK2B724.js +67 -0
- package/dist/chunk-SGK2B724.js.map +1 -0
- package/dist/chunk-UYP7G3GZ.js +412 -0
- package/dist/chunk-UYP7G3GZ.js.map +1 -0
- package/dist/{chunk-DPUMEMGM.js → chunk-VZ3AJCO5.js} +3 -5
- package/dist/{chunk-DPUMEMGM.js.map → chunk-VZ3AJCO5.js.map} +1 -1
- package/dist/{chunk-QH6677FJ.js → chunk-WDJTGVKN.js} +2 -2
- package/dist/{chunk-QH6677FJ.js.map → chunk-WDJTGVKN.js.map} +1 -1
- package/dist/{chunk-4GR7DGD6.js → chunk-WI5EOAQQ.js} +33 -256
- package/dist/{chunk-4GR7DGD6.js.map → chunk-WI5EOAQQ.js.map} +1 -1
- package/dist/{chunk-DPET3TW5.js → chunk-WRWCDLVK.js} +13 -12
- package/dist/chunk-WRWCDLVK.js.map +1 -0
- package/dist/chunk-XBJ3VLWX.js +35 -0
- package/dist/chunk-XBJ3VLWX.js.map +1 -0
- package/dist/chunk-ZEWY3RJ3.js +149 -0
- package/dist/chunk-ZEWY3RJ3.js.map +1 -0
- package/dist/chunk-ZFE7STX7.js +143 -0
- package/dist/chunk-ZFE7STX7.js.map +1 -0
- package/dist/{cli-AFSLAKR6.js → cli-7B2QNJG3.js} +247 -26
- package/dist/cli-7B2QNJG3.js.map +1 -0
- package/dist/{config-DBEEM3UA.js → config-SAQEQRFB.js} +7 -6
- package/dist/{doctor-XDA3YU6H.js → doctor-ENJ22XWN.js} +10 -8
- package/dist/{publish-IH7RJXGB.js → edit-2QO5GQDU.js} +19 -17
- package/dist/index.js +1 -1
- package/dist/{inspect-YBGDAG47.js → inspect-IPKKQB2S.js} +16 -15
- package/dist/{install-7J6KKEEP.js → install-7ZIYISQ7.js} +180 -133
- package/dist/install-7ZIYISQ7.js.map +1 -0
- package/dist/outcome-NSDE2KAJ.js +20 -0
- package/dist/publish-7WIFFNFG.js +40 -0
- package/dist/read-5TQR7LCF.js +158 -0
- package/dist/read-5TQR7LCF.js.map +1 -0
- package/dist/{run-DCZFEW2C.js → run-NPKIP26Y.js} +109 -34
- package/dist/{run-DCZFEW2C.js.map → run-NPKIP26Y.js.map} +1 -1
- package/dist/search-63ELMRZH.js +24 -0
- package/dist/send-ENE47KQE.js +222 -0
- package/dist/send-ENE47KQE.js.map +1 -0
- package/dist/session-FZU4VFFE.js +87 -0
- package/dist/session-FZU4VFFE.js.map +1 -0
- package/dist/{usdc-AU6ZIKA6.js → usdc-4VCDHFWX.js} +20 -4
- package/dist/{wallet-UWHSHWC6.js → wallet-OCCGEH6H.js} +8 -8
- package/dist/{wallet-HKG3GSTX.js → wallet-RBDVNZVR.js} +17 -7
- package/dist/wallet-RBDVNZVR.js.map +1 -0
- package/package.json +1 -1
- package/skills/tenjin/SKILL.md +32 -7
- package/skills/tenjin-publish/SKILL.md +109 -16
- package/skills/tenjin-search/SKILL.md +174 -15
- package/dist/chunk-333FOTUJ.js.map +0 -1
- package/dist/chunk-5JH7ZB6Z.js.map +0 -1
- package/dist/chunk-6WWVYYSB.js.map +0 -1
- package/dist/chunk-BXUS5UCT.js +0 -212
- package/dist/chunk-BXUS5UCT.js.map +0 -1
- package/dist/chunk-C4TIWOAM.js.map +0 -1
- package/dist/chunk-CJU555P5.js +0 -333
- package/dist/chunk-CJU555P5.js.map +0 -1
- package/dist/chunk-DPET3TW5.js.map +0 -1
- package/dist/chunk-EUQN3L5X.js.map +0 -1
- package/dist/chunk-FHB3VKZW.js.map +0 -1
- package/dist/chunk-FU6MCSLG.js.map +0 -1
- package/dist/chunk-H5ETJRQD.js.map +0 -1
- package/dist/chunk-MM4TGTST.js +0 -59
- package/dist/chunk-MM4TGTST.js.map +0 -1
- package/dist/chunk-MUBUQVC3.js +0 -67
- package/dist/chunk-MUBUQVC3.js.map +0 -1
- package/dist/chunk-NXCJN2FJ.js.map +0 -1
- package/dist/chunk-R7BMDJZM.js +0 -167
- package/dist/chunk-R7BMDJZM.js.map +0 -1
- package/dist/chunk-S3KZ3PPK.js.map +0 -1
- package/dist/chunk-ULLWHHIT.js.map +0 -1
- package/dist/chunk-VV4P5RVK.js.map +0 -1
- package/dist/chunk-YFREUEUI.js +0 -78
- package/dist/chunk-YFREUEUI.js.map +0 -1
- package/dist/cli-AFSLAKR6.js.map +0 -1
- package/dist/install-7J6KKEEP.js.map +0 -1
- package/dist/outcome-ZFGHX2XW.js +0 -20
- package/dist/search-R6NIQFXI.js +0 -24
- /package/dist/{buy-OOOLUDND.js.map → buy-XVOMNWKN.js.map} +0 -0
- /package/dist/{candidate-TWCWTFGA.js.map → candidate-DJB2NNTG.js.map} +0 -0
- /package/dist/{chunk-KXIX7YDV.js.map → chunk-2KIDDWQO.js.map} +0 -0
- /package/dist/{chunk-OJD54DIU.js.map → chunk-2YX6LTCD.js.map} +0 -0
- /package/dist/{config-DBEEM3UA.js.map → config-SAQEQRFB.js.map} +0 -0
- /package/dist/{doctor-XDA3YU6H.js.map → doctor-ENJ22XWN.js.map} +0 -0
- /package/dist/{inspect-YBGDAG47.js.map → edit-2QO5GQDU.js.map} +0 -0
- /package/dist/{outcome-ZFGHX2XW.js.map → inspect-IPKKQB2S.js.map} +0 -0
- /package/dist/{publish-IH7RJXGB.js.map → outcome-NSDE2KAJ.js.map} +0 -0
- /package/dist/{search-R6NIQFXI.js.map → publish-7WIFFNFG.js.map} +0 -0
- /package/dist/{usdc-AU6ZIKA6.js.map → search-63ELMRZH.js.map} +0 -0
- /package/dist/{wallet-HKG3GSTX.js.map → usdc-4VCDHFWX.js.map} +0 -0
- /package/dist/{wallet-UWHSHWC6.js.map → wallet-OCCGEH6H.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/wallet.ts"],"sourcesContent":["import { mkdir } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { CliError } from '../lib/errors';\nimport { walletPath } from '../lib/paths';\nimport { withFileLock, LockTimeoutError } from '../lib/lock';\nimport { loadRawConfig, resolveSettings } from '../lib/config';\nimport { toMoney } from '../lib/money';\nimport { getUsdcBalance } from '../lib/usdc';\nimport {\n commitLocalWallet,\n createLocalWallet,\n describeWallet,\n parkOutgoingWallet,\n prepareLocalWallet,\n resolveWalletProvider,\n restoreParkedWallet,\n verifyAndPreserveOutgoingWallet,\n type ArchivedWalletInfo,\n type ResolveWalletProviderOptions,\n} from '../lib/wallet';\nimport { walletExistsError, walletFileExists } from '../lib/wallet/store';\nimport { resolvePassphraseForCreate, type PassphraseSource } from '../lib/wallet/passphrase';\nimport type { PassphraseOverrides } from '../lib/wallet/local';\nimport type { CommandContext, CommandResult } from '../context';\n\nconst FUNDING_LINE = 'Send USDC on Base. $5 covers ~50 typical resources.';\nconst KEY_STORAGE = 'encrypted (keystore v3, scrypt)';\nconst isWindows = process.platform === 'win32';\n\nexport interface WalletCreateOptions {\n /**\n * Explicitly replace the existing active wallet (mirrors the `--yes`-style\n * explicit-flag precedent): the outgoing wallet is ARCHIVED — passphrase\n * verified against its keystore and preserved under its own address, keystore\n * parked beside the new one — never destroyed. Without it, create refuses\n * when a wallet exists. There is always exactly ONE active wallet.\n */\n replace?: boolean;\n /** Test seam for passphrase resolution (keychain exec, TTY prompt, platform). */\n passphrase?: PassphraseOverrides;\n}\n\nexport async function runWalletCreate(\n ctx: CommandContext,\n opts: WalletCreateOptions = {},\n): Promise<CommandResult> {\n const {\n address,\n walletPath: path,\n source,\n replaced,\n } = await createWalletLocked(ctx.dataDir, opts);\n\n const warnings = custodyWarnings();\n return {\n data: {\n address,\n walletPath: path,\n provider: 'local',\n policyEnforcement: 'client-only',\n keyStorage: KEY_STORAGE,\n passphraseSource: source,\n ...(replaced !== undefined\n ? {\n replaced: {\n address: replaced.address,\n archivedWalletPath: replaced.archivedPath,\n passphrasePreserved: replaced.passphraseLocation,\n ...(replaced.unarchivedReason !== undefined\n ? { unarchivedReason: replaced.unarchivedReason }\n : {}),\n },\n }\n : {}),\n warnings,\n },\n humanLines: [\n `Wallet created: ${address}`,\n `Key stored ${KEY_STORAGE}.`,\n passphraseNote(source, address),\n ...(replaced !== undefined ? replacedNote(replaced, path) : []),\n FUNDING_LINE,\n ...warnings,\n ],\n };\n}\n\n/** Where the outgoing wallet's funds live, why they remain reachable, and how to restore it. */\nfunction replacedNote(replaced: ArchivedWalletInfo, activeWalletPath: string): string[] {\n const passphraseLine =\n replaced.passphraseLocation === 'store'\n ? `its passphrase is preserved in the OS credential store (service tenjin-cli, account ${replaced.account}).`\n : replaced.passphraseLocation === 'env'\n ? 'its passphrase is TENJIN_WALLET_PASSPHRASE — keep that value.'\n : replaced.unarchivedReason === 'rejected-characters'\n ? 'its passphrase was NOT archived: the macOS keychain writer only stores machine-generated (base64url) passphrases, and this typed one contains other characters. Keep it yourself, or set TENJIN_WALLET_PASSPHRASE to it.'\n : replaced.unarchivedReason === 'no-store'\n ? 'its passphrase was NOT archived: this platform has no OS credential store. It exists only where you keep it.'\n : 'its passphrase was NOT archived: the OS credential store write failed. It exists only where you keep it.';\n return [\n `Previous wallet archived: ${replaced.address} still holds any funds sent to it.`,\n `Its keystore was moved to ${replaced.archivedPath}; ${passphraseLine}`,\n `To make it the active wallet again later: move the current ${activeWalletPath} aside first, then \\`mv ${replaced.archivedPath} ${activeWalletPath}\\`.`,\n ];\n}\n\n/**\n * Run the whole create critical section under a cross-process file lock: the\n * existence pre-check, the passphrase generate-and-store, and the no-clobber\n * write. Without the lock these interleave across two concurrent creates — each\n * generates a distinct passphrase and persists it to the OS store BEFORE the\n * exclusive file write, so a different process could win the file while this\n * one's per-address entry names a wallet that never landed. Serializing means\n * the loser blocks until the winner commits, then trips the exists check and\n * exits WALLET_EXISTS having never generated or stored a passphrase. The\n * store-before-write ordering stays (it still guards the single-process crash\n * window), and the exclusive write stays the final authority.\n *\n * The passphrase is resolved inside the prepare step's address callback so the\n * OS-store entry is keyed to the new wallet's own address (issue #32).\n *\n * `--replace` ordering closes the no-active-wallet window: verify-and-preserve\n * the outgoing wallet (no file moves), fully PREPARE the replacement (key,\n * stored passphrase, encrypted keystore — every fallible step) while the old\n * wallet is still active, and only then park the old keystore and commit the\n * new one. A commit failure rolls the park back, so at every exit either the\n * old or the new wallet is the active one.\n */\nasync function createWalletLocked(\n dir: string,\n opts: WalletCreateOptions,\n): Promise<{\n address: string;\n walletPath: string;\n source: PassphraseSource;\n replaced?: ArchivedWalletInfo;\n}> {\n // Ensure the data dir exists so the lock's own mkdir has a parent on a fresh\n // install; the exclusive wallet write below re-ensures it at 0700 regardless.\n await mkdir(dir, { recursive: true, mode: 0o700 });\n const lockPath = join(dir, 'wallet.create.lock');\n try {\n return await withFileLock(lockPath, async () => {\n let source: PassphraseSource = 'env';\n const passphraseFor = async (forAddress: string): Promise<string> => {\n const resolved = await resolvePassphraseForCreate(\n { env: process.env, dir, ...opts.passphrase },\n forAddress,\n );\n source = resolved.source;\n return resolved.passphrase;\n };\n\n if (!(await walletFileExists(dir))) {\n const { address, walletPath: path } = await createLocalWallet(dir, passphraseFor);\n return { address, walletPath: path, source };\n }\n\n if (opts.replace !== true) throw walletExistsError(dir);\n const preserved = await verifyAndPreserveOutgoingWallet({\n dir,\n env: process.env,\n ...(opts.passphrase !== undefined ? { passphrase: opts.passphrase } : {}),\n });\n const prepared = await prepareLocalWallet(passphraseFor);\n const archivedPath = await parkOutgoingWallet(dir, preserved.account);\n try {\n const { address, walletPath: path } = await commitLocalWallet(dir, prepared);\n return { address, walletPath: path, source, replaced: { ...preserved, archivedPath } };\n } catch (err) {\n try {\n await restoreParkedWallet(dir, archivedPath);\n } catch (restoreErr) {\n // The no-clobber restore also refuses when a wallet.json appeared out\n // of band (commit EEXIST) — never overwrite it; name both files.\n throw new CliError(\n 'INTERNAL',\n 'Creating the replacement wallet failed after the old wallet was parked, and restoring it also failed.',\n {\n fix: `Your old wallet ${preserved.address} is intact at ${archivedPath} with its passphrase preserved. If a ${walletPath(dir)} now exists, another process wrote it — move it aside first. Then restore with \\`mv ${archivedPath} ${walletPath(dir)}\\`.`,\n cause: restoreErr,\n },\n );\n }\n // Old wallet restored as the active one; say so rather than surfacing a\n // raw fs error (or a WALLET_EXISTS whose fix suggests re-running --replace).\n throw new CliError(\n 'INTERNAL',\n 'Creating the replacement wallet failed; the previous wallet was restored and is the active wallet again.',\n {\n fix: 'Nothing was lost. Fix the underlying error, then retry `tenjin wallet create --replace`.',\n cause: err,\n },\n );\n }\n });\n } catch (err) {\n // A lock timeout is not the user's error; surface it as INTERNAL with the one\n // manual step (there is no auto-steal), keeping the JSON error contract. Every\n // other error — notably the loser's WALLET_EXISTS — propagates unchanged.\n if (err instanceof LockTimeoutError) {\n throw new CliError('INTERNAL', err.message, {\n fix: `If no other tenjin process is running, remove ${lockPath} and retry.`,\n cause: err,\n });\n }\n throw err;\n }\n}\n\n/** Where the encryption passphrase lives, and what the user must remember. */\nfunction passphraseNote(source: PassphraseSource, address: string): string {\n const account = address.toLowerCase();\n switch (source) {\n case 'keychain':\n return `Passphrase saved to your macOS keychain (service tenjin-cli, account ${account}); signing will be transparent on this machine.`;\n case 'dpapi':\n return `Passphrase saved to a DPAPI-encrypted per-wallet file (passphrase.${account}.dpapi), readable only by you on this Windows machine; signing will be transparent here.`;\n case 'secret-service':\n return `Passphrase saved to your Linux keyring (Secret Service, service tenjin-cli, account ${account}); signing will be transparent on this machine.`;\n case 'env':\n return 'Encrypted with TENJIN_WALLET_PASSPHRASE; keep that value to sign.';\n case 'prompt':\n return 'Remember your passphrase: it is required to sign and cannot be recovered.';\n }\n}\n\nexport async function runWalletShow(\n ctx: CommandContext,\n opts: ResolveWalletProviderOptions = {},\n): Promise<CommandResult> {\n const provider = resolveWalletProvider(ctx, opts);\n const desc = await describeWallet(provider);\n // Diagnostics are the provider's own: a remote provider reports no local file\n // path or perms warning, so `show` never contaminates a remote wallet's output\n // with a stale local wallet.json's state. keyStorage/passphraseSource are the\n // custody posture reported without decrypting or requiring a passphrase.\n const {\n walletPath: path,\n keyStorage,\n passphraseSource,\n archivedWallets,\n warnings,\n } = await provider.diagnostics();\n\n const humanLines = [`Address: ${desc.address}`, `Key source: ${desc.credentialSource}`];\n if (keyStorage !== undefined) humanLines.push(`Key storage: ${keyStorage}`);\n if (passphraseSource !== undefined) humanLines.push(`Passphrase: ${passphraseSource}`);\n if (archivedWallets !== undefined && archivedWallets.length > 0) {\n // A recovery hint, not a wallet switcher: exactly one wallet is ever active.\n humanLines.push(\n `Archived (replaced) wallets, funds recoverable via their preserved passphrases: ${archivedWallets.join(', ')}`,\n );\n }\n humanLines.push(...warnings);\n\n return {\n data: {\n address: desc.address,\n provider: desc.provider,\n credentialSource: desc.credentialSource,\n policyEnforcement: desc.policyEnforcement,\n ...(path !== undefined ? { walletPath: path } : {}),\n ...(keyStorage !== undefined ? { keyStorage } : {}),\n ...(passphraseSource !== undefined ? { passphraseSource } : {}),\n ...(archivedWallets !== undefined && archivedWallets.length > 0 ? { archivedWallets } : {}),\n warnings,\n },\n humanLines,\n };\n}\n\nexport async function runWalletBalance(\n ctx: CommandContext,\n opts: ResolveWalletProviderOptions = {},\n): Promise<CommandResult> {\n const provider = resolveWalletProvider(ctx, opts);\n const desc = await describeWallet(provider);\n\n const config = await loadRawConfig(ctx.dataDir);\n const rpcUrl = resolveSettings({\n config,\n flags: { baseUrl: ctx.flags.baseUrl },\n env: process.env,\n }).rpcUrl.value;\n\n let atomic: bigint;\n try {\n atomic = await getUsdcBalance(desc.address, rpcUrl);\n } catch (err) {\n throw new CliError('RPC_ERROR', `Could not read the USDC balance from ${rpcUrl}.`, {\n fix: 'Check your network, or set a working RPC with `tenjin config set rpcUrl <url>`.',\n cause: err,\n });\n }\n\n const balance = toMoney(atomic.toString());\n return {\n data: { address: desc.address, balance },\n humanLines: [`Balance: ${balance.usd} USDC on Base`],\n };\n}\n\nfunction custodyWarnings(): string[] {\n const warnings: string[] = [];\n if (hasEnvKey()) {\n warnings.push('TENJIN_WALLET_KEY is set and shadows this file at runtime.');\n }\n if (isWindows) {\n warnings.push('File permissions are not enforced on Windows; the key file is not restricted.');\n }\n return warnings;\n}\n\nfunction hasEnvKey(): boolean {\n const envKey = process.env.TENJIN_WALLET_KEY;\n return envKey !== undefined && envKey.length > 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,YAAY;AAwBrB,IAAM,eAAe;AACrB,IAAM,cAAc;AACpB,IAAM,YAAY,QAAQ,aAAa;AAevC,eAAsB,gBACpB,KACA,OAA4B,CAAC,GACL;AACxB,QAAM;AAAA,IACJ;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,EACF,IAAI,MAAM,mBAAmB,IAAI,SAAS,IAAI;AAE9C,QAAM,WAAW,gBAAgB;AACjC,SAAO;AAAA,IACL,MAAM;AAAA,MACJ;AAAA,MACA,YAAY;AA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,qBAAqB,SAAY,EAAE,iBAAiB,IAAI,CAAC;AAAA,MAC7D,GAAI,oBAAoB,UAAa,gBAAgB,SAAS,IAAI,EAAE,gBAAgB,IAAI,CAAC;AAAA,MACzF;AAAA,IACF;AAAA,IACA;AAAA,EACF;AACF;AAEA,eAAsB,iBACpB,KACA,OAAqC,CAAC,GACd;AACxB,QAAM,WAAW,sBAAsB,KAAK,IAAI;AAChD,QAAM,OAAO,MAAM,eAAe,QAAQ;AAE1C,QAAM,SAAS,MAAM,cAAc,IAAI,OAAO;AAC9C,QAAM,SAAS,gBAAgB;AAAA,IAC7B;AAAA,IACA,OAAO,EAAE,SAAS,IAAI,MAAM,QAAQ;AAAA,IACpC,KAAK,QAAQ;AAAA,EACf,CAAC,EAAE,OAAO;AAEV,MAAI;AACJ,MAAI;AACF,aAAS,MAAM,eAAe,KAAK,SAAS,MAAM;AAAA,EACpD,SAAS,KAAK;AACZ,UAAM,IAAI,SAAS,aAAa,wCAAwC,MAAM,KAAK;AAAA,MACjF,KAAK;AAAA,MACL,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,QAAM,UAAU,QAAQ,OAAO,SAAS,CAAC;AACzC,SAAO;AAAA,IACL,MAAM,EAAE,SAAS,KAAK,SAAS,QAAQ;AAAA,IACvC,YAAY,CAAC,YAAY,QAAQ,GAAG,eAAe;AAAA,EACrD;AACF;AAEA,SAAS,kBAA4B;AACnC,QAAM,WAAqB,CAAC;AAC5B,MAAI,UAAU,GAAG;AACf,aAAS,KAAK,4DAA4D;AAAA,EAC5E;AACA,MAAI,WAAW;AACb,aAAS,KAAK,+EAA+E;AAAA,EAC/F;AACA,SAAO;AACT;AAEA,SAAS,YAAqB;AAC5B,QAAM,SAAS,QAAQ,IAAI;AAC3B,SAAO,WAAW,UAAa,OAAO,SAAS;AACjD;","names":[]}
|
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
buildPostUpdateBody,
|
|
4
|
+
dedupeFindings,
|
|
5
|
+
deriveCard,
|
|
6
|
+
deriveProjectMarkers,
|
|
7
|
+
describeFindings,
|
|
8
|
+
getOwnPost,
|
|
9
|
+
missingSentences,
|
|
10
|
+
needsConfirmation,
|
|
11
|
+
parseAppliesToFlags,
|
|
12
|
+
parseFrontmatter,
|
|
13
|
+
publicFinding,
|
|
14
|
+
resolveWriteAuth,
|
|
15
|
+
scan,
|
|
16
|
+
updatePost,
|
|
17
|
+
writeModeNotices
|
|
18
|
+
} from "./chunk-PLU3E63S.js";
|
|
19
|
+
import {
|
|
20
|
+
describeWallet,
|
|
21
|
+
resolveWalletProvider
|
|
22
|
+
} from "./chunk-RGFBBNGP.js";
|
|
23
|
+
import {
|
|
24
|
+
UUID_RE
|
|
25
|
+
} from "./chunk-WWX32ML4.js";
|
|
26
|
+
import {
|
|
27
|
+
sanitizeForTerminal
|
|
28
|
+
} from "./chunk-BBUYCDSG.js";
|
|
29
|
+
import {
|
|
30
|
+
resolveContextSettings,
|
|
31
|
+
resolvePublishSettings
|
|
32
|
+
} from "./chunk-DAJ56EUU.js";
|
|
33
|
+
import {
|
|
34
|
+
parsePublishModeFlag,
|
|
35
|
+
parseUsdToAtomic,
|
|
36
|
+
toMoney
|
|
37
|
+
} from "./chunk-UYP7G3GZ.js";
|
|
38
|
+
import {
|
|
39
|
+
CliError
|
|
40
|
+
} from "./chunk-J6CVKC4M.js";
|
|
41
|
+
|
|
42
|
+
// src/commands/edit.ts
|
|
43
|
+
import { readFile } from "fs/promises";
|
|
44
|
+
import { dirname, resolve } from "path";
|
|
45
|
+
async function runEdit(args, ctx, deps = {}) {
|
|
46
|
+
const env = deps.env ?? process.env;
|
|
47
|
+
const cwd = deps.cwd ?? process.cwd();
|
|
48
|
+
if (!UUID_RE.test(args.postId)) {
|
|
49
|
+
throw new CliError("USAGE", `Invalid post id: ${JSON.stringify(args.postId)}`, {
|
|
50
|
+
fix: "Pass the post uuid from `tenjin publish`\u2019s receipt or your desk."
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (args.mode !== void 0) parsePublishModeFlag(args.mode, "--mode");
|
|
54
|
+
rejectEmptyValues(args);
|
|
55
|
+
assertAppendExclusivity(args);
|
|
56
|
+
const clears = parseClears(args);
|
|
57
|
+
const cardFlags = cardFlagsFrom(args);
|
|
58
|
+
const priceAtomic = args.price !== void 0 ? parseUsdToAtomic(args.price) : void 0;
|
|
59
|
+
const bodyFile = args.body !== void 0 ? await readBodyFile(args.body) : void 0;
|
|
60
|
+
const wantsChange = hasChangeFlags(args);
|
|
61
|
+
const runtime = await resolveContextSettings(ctx);
|
|
62
|
+
const provider = resolveWalletProvider(
|
|
63
|
+
ctx,
|
|
64
|
+
deps.provider !== void 0 ? { provider: deps.provider } : {}
|
|
65
|
+
);
|
|
66
|
+
await describeWallet(provider);
|
|
67
|
+
const signer = await provider.getSigner();
|
|
68
|
+
const auth = resolveWriteAuth({
|
|
69
|
+
signer,
|
|
70
|
+
baseUrl: runtime.baseUrl,
|
|
71
|
+
dataDir: ctx.dataDir,
|
|
72
|
+
scope: wantsChange ? "read+write" : "read",
|
|
73
|
+
...deps.useSession !== void 0 ? { useSession: deps.useSession } : {},
|
|
74
|
+
env
|
|
75
|
+
});
|
|
76
|
+
const client = {
|
|
77
|
+
baseUrl: runtime.baseUrl,
|
|
78
|
+
timeoutMs: ctx.flags.timeout,
|
|
79
|
+
...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
|
|
80
|
+
};
|
|
81
|
+
const stored = await getOwnPost(args.postId, auth, client);
|
|
82
|
+
if (!wantsChange) return showReceipt(stored);
|
|
83
|
+
if (args.addQuestion !== void 0 && args.addQuestion.length > 0) {
|
|
84
|
+
cardFlags.question = appendUnique(storedList(stored, "questionsAnswered"), args.addQuestion);
|
|
85
|
+
}
|
|
86
|
+
if (args.addTask !== void 0 && args.addTask.length > 0) {
|
|
87
|
+
cardFlags.task = appendUnique(storedList(stored, "tasksSupported"), args.addTask);
|
|
88
|
+
}
|
|
89
|
+
const intent = {
|
|
90
|
+
...args.title !== void 0 ? { title: args.title } : {},
|
|
91
|
+
...bodyFile !== void 0 ? { bodyMd: bodyFile.body } : {},
|
|
92
|
+
...args.excerpt !== void 0 ? { excerpt: args.excerpt } : {},
|
|
93
|
+
...priceAtomic !== void 0 ? { priceAtomic } : {},
|
|
94
|
+
...withClears(deriveCard({}, cardFlags), clears, stored.resource)
|
|
95
|
+
};
|
|
96
|
+
const { input, lines: changes } = diffUpdate(stored, intent);
|
|
97
|
+
if (changes.length === 0) return noChangeReceipt(stored);
|
|
98
|
+
buildPostUpdateBody(input);
|
|
99
|
+
const settings = await resolvePublishSettings({
|
|
100
|
+
dataDir: ctx.dataDir,
|
|
101
|
+
cwd,
|
|
102
|
+
...args.mode !== void 0 ? { flag: args.mode } : {},
|
|
103
|
+
env
|
|
104
|
+
});
|
|
105
|
+
writeModeNotices(
|
|
106
|
+
ctx.io.stderr,
|
|
107
|
+
settings,
|
|
108
|
+
env,
|
|
109
|
+
"each edit asks you once. Set auto to apply clean edits automatically"
|
|
110
|
+
);
|
|
111
|
+
const markerRoot = args.body !== void 0 ? dirname(resolve(cwd, args.body)) : cwd;
|
|
112
|
+
const scanContext = { projectMarkers: await deriveProjectMarkers(markerRoot) };
|
|
113
|
+
const findings = dedupeFindings([
|
|
114
|
+
...input.bodyMd !== void 0 ? scan(bodyFile?.raw ?? "", scanContext) : [],
|
|
115
|
+
...scan(shippedTypedText(args, input), scanContext)
|
|
116
|
+
]);
|
|
117
|
+
const blocking = findings.filter((f) => f.severity === "block");
|
|
118
|
+
const warns = findings.filter((f) => f.severity === "warn");
|
|
119
|
+
if (blocking.length > 0) {
|
|
120
|
+
throw new CliError("PUBLISH_BLOCKED", blockMessage(blocking), {
|
|
121
|
+
fix: "Remove the secret from the new content (it is never masked away by --yes), then re-run.",
|
|
122
|
+
details: { mode: settings.mode, findings: blocking.map(publicFinding) }
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
const notes = editNotes(args, stored, bodyFile, clears);
|
|
126
|
+
for (const line of [...notes, ...changes]) ctx.io.stderr.write(`${line}
|
|
127
|
+
`);
|
|
128
|
+
if (needsConfirmation(settings.mode, warns.length) && args.yes !== true) {
|
|
129
|
+
throw new CliError("NEEDS_CONFIRMATION", confirmMessage(warns.length, changes.length), {
|
|
130
|
+
fix: "Review the changes, then re-run with --yes.",
|
|
131
|
+
details: {
|
|
132
|
+
mode: settings.mode,
|
|
133
|
+
postId: stored.id,
|
|
134
|
+
title: sanitizeForTerminal(stored.title),
|
|
135
|
+
changes,
|
|
136
|
+
...notes.length > 0 ? { notes } : {},
|
|
137
|
+
findings: warns.map(publicFinding)
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
const updated = await updatePost(args.postId, input, auth, client);
|
|
142
|
+
return updateReceipt(updated, changes, notes, settings.mode);
|
|
143
|
+
}
|
|
144
|
+
function showReceipt(post) {
|
|
145
|
+
const price = toMoney(post.price);
|
|
146
|
+
const card = post.resource;
|
|
147
|
+
const lines = [
|
|
148
|
+
`${sanitizeForTerminal(post.title)} (${sanitizeForTerminal(post.status)}), ${price.usd} USD (${price.atomic} atomic)`,
|
|
149
|
+
`url: ${sanitizeForTerminal(post.url)}`,
|
|
150
|
+
...hasText(post.excerpt) ? [`excerpt: ${preview(post.excerpt)}`] : [],
|
|
151
|
+
...cardLines(card),
|
|
152
|
+
eligibilityLine(card)
|
|
153
|
+
];
|
|
154
|
+
return { data: post, humanLines: lines };
|
|
155
|
+
}
|
|
156
|
+
function updateReceipt(post, changes, notes, mode) {
|
|
157
|
+
const card = post.resource;
|
|
158
|
+
const lines = [
|
|
159
|
+
`Updated ${sanitizeForTerminal(post.title)} \u2192 ${sanitizeForTerminal(post.url)}`,
|
|
160
|
+
eligibilityLine(card),
|
|
161
|
+
...(post.warnings ?? []).map((w) => `warning: ${sanitizeForTerminal(w)}`)
|
|
162
|
+
];
|
|
163
|
+
return {
|
|
164
|
+
// `mode` is echoed because a per-call --mode (or the MCP `mode` argument) is
|
|
165
|
+
// otherwise invisible in a transcript: the receipt would look identical
|
|
166
|
+
// whether the caller loosened the gate for this run or not.
|
|
167
|
+
data: { ...post, mode, changes, ...notes.length > 0 ? { notes } : {} },
|
|
168
|
+
humanLines: lines
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function noChangeReceipt(post) {
|
|
172
|
+
return {
|
|
173
|
+
data: { ...post, changes: [] },
|
|
174
|
+
humanLines: [
|
|
175
|
+
`No changes: every value given already matches ${sanitizeForTerminal(post.title)}. Nothing was written.`
|
|
176
|
+
]
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function cardLines(card) {
|
|
180
|
+
if (card === void 0) return [];
|
|
181
|
+
const lines = [];
|
|
182
|
+
const list = (label, values) => {
|
|
183
|
+
if (values !== void 0 && values !== null && values.length > 0) {
|
|
184
|
+
lines.push(
|
|
185
|
+
`${label} (${values.length}): ${values.map((v) => sanitizeForTerminal(v)).join(" | ")}`
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
list("questionsAnswered", card.questionsAnswered);
|
|
190
|
+
list("tasksSupported", card.tasksSupported);
|
|
191
|
+
for (const [label, value] of [
|
|
192
|
+
["scope", card.scope],
|
|
193
|
+
["exclusions", card.exclusions],
|
|
194
|
+
["artifactType", card.artifactType],
|
|
195
|
+
["temporalMode", card.temporalMode],
|
|
196
|
+
["asOf", card.asOf],
|
|
197
|
+
["validUntil", card.validUntil],
|
|
198
|
+
["provenance", card.provenanceSummary],
|
|
199
|
+
["methodology", card.methodologySummary],
|
|
200
|
+
["supersedesPostId", card.supersedesPostId]
|
|
201
|
+
]) {
|
|
202
|
+
if (hasText(value)) lines.push(`${label}: ${preview(value)}`);
|
|
203
|
+
}
|
|
204
|
+
if (card.appliesTo !== void 0 && card.appliesTo !== null) {
|
|
205
|
+
for (const [key, values] of Object.entries(card.appliesTo)) {
|
|
206
|
+
lines.push(
|
|
207
|
+
`appliesTo ${sanitizeForTerminal(key)}: ${values.map((v) => sanitizeForTerminal(v)).join(", ")}`
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return lines;
|
|
212
|
+
}
|
|
213
|
+
function eligibilityLine(card) {
|
|
214
|
+
if (card === void 0) return "No answer card (browse-only document).";
|
|
215
|
+
const missing = missingSentences(card.cacheEligibleMissing).map(sanitizeForTerminal);
|
|
216
|
+
if (card.cacheEligible) return "Answer card is search-eligible.";
|
|
217
|
+
return missing.length > 0 ? `Answer card not search-eligible yet: ${missing.join(" ")}` : "Answer card is not search-eligible.";
|
|
218
|
+
}
|
|
219
|
+
function diffUpdate(stored, intent) {
|
|
220
|
+
const lines = [];
|
|
221
|
+
const input = {};
|
|
222
|
+
const title = intent.title?.trim();
|
|
223
|
+
if (title !== void 0 && title !== stored.title) {
|
|
224
|
+
input.title = title;
|
|
225
|
+
lines.push(`title: ${preview(stored.title)} \u2192 ${preview(title)}`);
|
|
226
|
+
}
|
|
227
|
+
if (intent.priceAtomic !== void 0 && intent.priceAtomic !== stored.price) {
|
|
228
|
+
const before = toMoney(stored.price);
|
|
229
|
+
const after = toMoney(intent.priceAtomic);
|
|
230
|
+
input.priceAtomic = intent.priceAtomic;
|
|
231
|
+
lines.push(
|
|
232
|
+
`price: ${before.usd} USD (${before.atomic} atomic) \u2192 ${after.usd} USD (${after.atomic} atomic)`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
if (intent.bodyMd !== void 0 && intent.bodyMd !== stored.bodyMd) {
|
|
236
|
+
input.bodyMd = intent.bodyMd;
|
|
237
|
+
lines.push(`body: ${(stored.bodyMd ?? "").length} \u2192 ${intent.bodyMd.length} characters`);
|
|
238
|
+
}
|
|
239
|
+
const excerpt = intent.excerpt?.trim();
|
|
240
|
+
if (excerpt !== void 0 && excerpt !== (stored.excerpt ?? "")) {
|
|
241
|
+
input.excerpt = excerpt;
|
|
242
|
+
lines.push(`excerpt: ${preview(stored.excerpt)} \u2192 ${preview(excerpt)}`);
|
|
243
|
+
}
|
|
244
|
+
const card = diffCard(stored.resource, intent.resource);
|
|
245
|
+
lines.push(...card.lines);
|
|
246
|
+
if (card.card !== void 0) input.resource = card.card;
|
|
247
|
+
return { input, lines };
|
|
248
|
+
}
|
|
249
|
+
var CARD_PASS = {
|
|
250
|
+
questionsAnswered: "list",
|
|
251
|
+
tasksSupported: "list",
|
|
252
|
+
asOf: "iso",
|
|
253
|
+
validUntil: "iso",
|
|
254
|
+
scope: "scalar",
|
|
255
|
+
exclusions: "scalar",
|
|
256
|
+
artifactType: "scalar",
|
|
257
|
+
temporalMode: "scalar",
|
|
258
|
+
provenanceSummary: "scalar",
|
|
259
|
+
methodologySummary: "scalar",
|
|
260
|
+
supersedesPostId: "scalar",
|
|
261
|
+
appliesTo: "map",
|
|
262
|
+
mediaType: "none",
|
|
263
|
+
maintenanceCadence: "none",
|
|
264
|
+
reproductionMinutes: "none",
|
|
265
|
+
estimatedPaidInputCost: "none"
|
|
266
|
+
};
|
|
267
|
+
function keysIn(pass) {
|
|
268
|
+
return Object.entries(CARD_PASS).filter(([, value]) => value === pass).map(([key]) => key);
|
|
269
|
+
}
|
|
270
|
+
var CARD_LABEL = {
|
|
271
|
+
provenanceSummary: "provenance",
|
|
272
|
+
methodologySummary: "methodology"
|
|
273
|
+
};
|
|
274
|
+
function cardLabel(key) {
|
|
275
|
+
return CARD_LABEL[key] ?? key;
|
|
276
|
+
}
|
|
277
|
+
function diffCard(stored, next) {
|
|
278
|
+
const lines = [];
|
|
279
|
+
const card = {};
|
|
280
|
+
const keep = (key, value, line) => {
|
|
281
|
+
card[key] = value;
|
|
282
|
+
lines.push(line);
|
|
283
|
+
};
|
|
284
|
+
if (next === void 0) return { lines };
|
|
285
|
+
for (const key of keysIn("list")) {
|
|
286
|
+
const after = next[key];
|
|
287
|
+
if (after === void 0) continue;
|
|
288
|
+
const old = stored?.[key] ?? [];
|
|
289
|
+
if (sameList(old, after)) continue;
|
|
290
|
+
const added = after.filter((v) => !old.includes(v));
|
|
291
|
+
const detail = after.length === 0 ? " (cleared)" : added.length > 0 ? ` (new: ${previewList(added)})` : "";
|
|
292
|
+
keep(key, after, `${key}: ${old.length} \u2192 ${after.length}${detail}`);
|
|
293
|
+
}
|
|
294
|
+
for (const key of keysIn("iso")) {
|
|
295
|
+
const after = next[key];
|
|
296
|
+
if (after === void 0) continue;
|
|
297
|
+
const from = isoInstant(stored?.[key]);
|
|
298
|
+
const to = isoInstant(after);
|
|
299
|
+
if (from === to) continue;
|
|
300
|
+
keep(key, to, `${key}: ${preview(from)} \u2192 ${to === null ? "(cleared)" : preview(to)}`);
|
|
301
|
+
}
|
|
302
|
+
for (const key of keysIn("scalar")) {
|
|
303
|
+
const after = next[key];
|
|
304
|
+
if (after === void 0) continue;
|
|
305
|
+
const from = stored?.[key] ?? null;
|
|
306
|
+
if (from === after) continue;
|
|
307
|
+
keep(
|
|
308
|
+
key,
|
|
309
|
+
after,
|
|
310
|
+
`${cardLabel(key)}: ${preview(from)} \u2192 ${after === null ? "(cleared)" : preview(after)}`
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
for (const key of keysIn("map")) {
|
|
314
|
+
const after = next[key];
|
|
315
|
+
if (after === void 0) continue;
|
|
316
|
+
const before = stored?.[key] ?? {};
|
|
317
|
+
if (sameAppliesTo(before, after)) continue;
|
|
318
|
+
keep(key, after, `${key}: ${appliesToPreview(before)} \u2192 ${appliesToPreview(after)}`);
|
|
319
|
+
}
|
|
320
|
+
return { ...Object.keys(card).length > 0 ? { card } : {}, lines };
|
|
321
|
+
}
|
|
322
|
+
function isoInstant(value) {
|
|
323
|
+
if (value === void 0 || value === null) return null;
|
|
324
|
+
const ms = Date.parse(value);
|
|
325
|
+
return Number.isFinite(ms) ? new Date(ms).toISOString() : value;
|
|
326
|
+
}
|
|
327
|
+
function sameAppliesTo(a, b) {
|
|
328
|
+
const aKeys = Object.keys(a).sort();
|
|
329
|
+
const bKeys = Object.keys(b).sort();
|
|
330
|
+
if (!sameList(aKeys, bKeys)) return false;
|
|
331
|
+
return aKeys.every((key) => sameList(a[key] ?? [], b[key] ?? []));
|
|
332
|
+
}
|
|
333
|
+
function editNotes(args, stored, bodyFile, clears) {
|
|
334
|
+
if (bodyFile === void 0) return [];
|
|
335
|
+
const notes = [];
|
|
336
|
+
if (bodyFile.hadFrontmatter) {
|
|
337
|
+
notes.push(
|
|
338
|
+
"note: frontmatter in the body file was ignored; metadata changes only through flags."
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
if (args.excerpt === void 0) {
|
|
342
|
+
notes.push(
|
|
343
|
+
`note: the excerpt stays as-is (${preview(stored.excerpt)}) and remains lexically indexed; the server does not re-derive it. Pass --excerpt to change it.`
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
const asOfMoves = args.asOf !== void 0 || clears.includes("asOf");
|
|
347
|
+
if (stored.resource?.temporalMode === "snapshot" && !asOfMoves) {
|
|
348
|
+
notes.push(
|
|
349
|
+
`note: asOf is unchanged (${preview(stored.resource.asOf)}) on this snapshot card, and search freshness gating uses it. Pass --as-of to move it.`
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
return notes;
|
|
353
|
+
}
|
|
354
|
+
var CLEAR_FIELDS = [
|
|
355
|
+
"scope",
|
|
356
|
+
"exclusions",
|
|
357
|
+
"asOf",
|
|
358
|
+
"validUntil",
|
|
359
|
+
"provenance",
|
|
360
|
+
"methodology",
|
|
361
|
+
"supersedesPostId",
|
|
362
|
+
"questionsAnswered",
|
|
363
|
+
"tasksSupported",
|
|
364
|
+
"appliesTo"
|
|
365
|
+
];
|
|
366
|
+
var CLEAR_KEY = {
|
|
367
|
+
scope: "scope",
|
|
368
|
+
exclusions: "exclusions",
|
|
369
|
+
asOf: "asOf",
|
|
370
|
+
validUntil: "validUntil",
|
|
371
|
+
provenance: "provenanceSummary",
|
|
372
|
+
methodology: "methodologySummary",
|
|
373
|
+
supersedesPostId: "supersedesPostId",
|
|
374
|
+
questionsAnswered: "questionsAnswered",
|
|
375
|
+
tasksSupported: "tasksSupported",
|
|
376
|
+
appliesTo: "appliesTo"
|
|
377
|
+
};
|
|
378
|
+
var CLEAR_VALUE = {
|
|
379
|
+
scope: null,
|
|
380
|
+
exclusions: null,
|
|
381
|
+
asOf: null,
|
|
382
|
+
validUntil: null,
|
|
383
|
+
provenance: null,
|
|
384
|
+
methodology: null,
|
|
385
|
+
supersedesPostId: null,
|
|
386
|
+
questionsAnswered: [],
|
|
387
|
+
tasksSupported: [],
|
|
388
|
+
appliesTo: {}
|
|
389
|
+
};
|
|
390
|
+
var CLEAR_CONFLICTS = {
|
|
391
|
+
scope: ["scope"],
|
|
392
|
+
exclusions: ["exclusions"],
|
|
393
|
+
asOf: ["asOf"],
|
|
394
|
+
validUntil: ["validUntil"],
|
|
395
|
+
provenance: ["provenance"],
|
|
396
|
+
methodology: ["methodology"],
|
|
397
|
+
supersedesPostId: [],
|
|
398
|
+
questionsAnswered: ["question", "addQuestion"],
|
|
399
|
+
tasksSupported: ["task", "addTask"],
|
|
400
|
+
appliesTo: ["appliesTo"]
|
|
401
|
+
};
|
|
402
|
+
var FLAG_NAME = {
|
|
403
|
+
question: "--question",
|
|
404
|
+
task: "--task",
|
|
405
|
+
addQuestion: "--add-question",
|
|
406
|
+
addTask: "--add-task",
|
|
407
|
+
scope: "--scope",
|
|
408
|
+
exclusions: "--exclusions",
|
|
409
|
+
appliesTo: "--applies-to",
|
|
410
|
+
asOf: "--as-of",
|
|
411
|
+
validUntil: "--valid-until",
|
|
412
|
+
artifactType: "--artifact-type",
|
|
413
|
+
temporalMode: "--temporal-mode",
|
|
414
|
+
provenance: "--provenance",
|
|
415
|
+
methodology: "--methodology",
|
|
416
|
+
title: "--title",
|
|
417
|
+
price: "--price",
|
|
418
|
+
body: "--body",
|
|
419
|
+
excerpt: "--excerpt"
|
|
420
|
+
};
|
|
421
|
+
var CHANGE_KEYS = [
|
|
422
|
+
"question",
|
|
423
|
+
"task",
|
|
424
|
+
"addQuestion",
|
|
425
|
+
"addTask",
|
|
426
|
+
"scope",
|
|
427
|
+
"exclusions",
|
|
428
|
+
"appliesTo",
|
|
429
|
+
"asOf",
|
|
430
|
+
"validUntil",
|
|
431
|
+
"artifactType",
|
|
432
|
+
"temporalMode",
|
|
433
|
+
"provenance",
|
|
434
|
+
"methodology",
|
|
435
|
+
"title",
|
|
436
|
+
"price",
|
|
437
|
+
"body",
|
|
438
|
+
"excerpt",
|
|
439
|
+
"clear"
|
|
440
|
+
];
|
|
441
|
+
function hasChangeFlags(args) {
|
|
442
|
+
return CHANGE_KEYS.some((key) => {
|
|
443
|
+
const value = args[key];
|
|
444
|
+
return Array.isArray(value) ? value.length > 0 : value !== void 0;
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
function rejectEmptyValues(args) {
|
|
448
|
+
for (const [key, flag] of Object.entries(FLAG_NAME)) {
|
|
449
|
+
const value = args[key];
|
|
450
|
+
const empties = typeof value === "string" ? [value] : Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
|
|
451
|
+
for (const v of empties) {
|
|
452
|
+
if (v.trim().length === 0) {
|
|
453
|
+
const clearable = CLEAR_FIELDS.includes(clearNameFor(key));
|
|
454
|
+
throw new CliError("USAGE", `${flag} cannot be empty.`, {
|
|
455
|
+
fix: clearable ? `Pass a value, or clear the field with \`--clear ${clearNameFor(key)}\`.` : "Pass a value, or omit the flag to keep the stored one."
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function clearNameFor(key) {
|
|
462
|
+
if (key === "question" || key === "addQuestion") return "questionsAnswered";
|
|
463
|
+
if (key === "task" || key === "addTask") return "tasksSupported";
|
|
464
|
+
return key;
|
|
465
|
+
}
|
|
466
|
+
function assertAppendExclusivity(args) {
|
|
467
|
+
const both = (a, b) => a !== void 0 && a.length > 0 && b !== void 0 && b.length > 0;
|
|
468
|
+
if (both(args.question, args.addQuestion)) {
|
|
469
|
+
throw new CliError("USAGE", "Pass either --question or --add-question, not both.", {
|
|
470
|
+
fix: "--question replaces the stored questions; --add-question appends to them."
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
if (both(args.task, args.addTask)) {
|
|
474
|
+
throw new CliError("USAGE", "Pass either --task or --add-task, not both.", {
|
|
475
|
+
fix: "--task replaces the stored tasks; --add-task appends to them."
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
function parseClears(args) {
|
|
480
|
+
const raw = args.clear ?? [];
|
|
481
|
+
const out = [];
|
|
482
|
+
for (const name of raw) {
|
|
483
|
+
if (!CLEAR_FIELDS.includes(name)) {
|
|
484
|
+
throw new CliError("USAGE", `Cannot clear ${JSON.stringify(name)}.`, {
|
|
485
|
+
fix: `Clearable fields: ${CLEAR_FIELDS.join(", ")}.`
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
const field = name;
|
|
489
|
+
for (const key of CLEAR_CONFLICTS[field]) {
|
|
490
|
+
const value = args[key];
|
|
491
|
+
const given = Array.isArray(value) ? value.length > 0 : value !== void 0;
|
|
492
|
+
if (given) {
|
|
493
|
+
throw new CliError(
|
|
494
|
+
"USAGE",
|
|
495
|
+
`--clear ${field} contradicts ${FLAG_NAME[key] ?? String(key)}.`,
|
|
496
|
+
{ fix: "Set the field or clear it, not both in the same run." }
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
if (!out.includes(field)) out.push(field);
|
|
501
|
+
}
|
|
502
|
+
return out;
|
|
503
|
+
}
|
|
504
|
+
function cardFlagsFrom(args) {
|
|
505
|
+
return {
|
|
506
|
+
...args.question !== void 0 && args.question.length > 0 ? { question: args.question } : {},
|
|
507
|
+
...args.task !== void 0 && args.task.length > 0 ? { task: args.task } : {},
|
|
508
|
+
...args.scope !== void 0 ? { scope: args.scope } : {},
|
|
509
|
+
...args.exclusions !== void 0 ? { exclusions: args.exclusions } : {},
|
|
510
|
+
...args.asOf !== void 0 ? { asOf: args.asOf } : {},
|
|
511
|
+
...args.validUntil !== void 0 ? { validUntil: args.validUntil } : {},
|
|
512
|
+
...args.artifactType !== void 0 ? { artifactType: args.artifactType } : {},
|
|
513
|
+
...args.temporalMode !== void 0 ? { temporalMode: args.temporalMode } : {},
|
|
514
|
+
...args.provenance !== void 0 ? { provenance: args.provenance } : {},
|
|
515
|
+
...args.methodology !== void 0 ? { methodology: args.methodology } : {},
|
|
516
|
+
...args.appliesTo !== void 0 && args.appliesTo.length > 0 ? { appliesTo: parseAppliesToFlags(args.appliesTo) } : {}
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
function withClears(set, clears, stored) {
|
|
520
|
+
const applicable = stored !== void 0 ? clears : [];
|
|
521
|
+
if (set === void 0 && applicable.length === 0) return {};
|
|
522
|
+
const card = { ...set ?? {} };
|
|
523
|
+
for (const name of applicable) {
|
|
524
|
+
card[CLEAR_KEY[name]] = CLEAR_VALUE[name];
|
|
525
|
+
}
|
|
526
|
+
return Object.keys(card).length > 0 ? { resource: card } : {};
|
|
527
|
+
}
|
|
528
|
+
async function readBodyFile(file) {
|
|
529
|
+
let raw;
|
|
530
|
+
try {
|
|
531
|
+
raw = await readFile(file, "utf8");
|
|
532
|
+
} catch (err) {
|
|
533
|
+
throw new CliError("USAGE", `Could not read ${JSON.stringify(file)}`, {
|
|
534
|
+
fix: "Pass a path to a readable Markdown file, e.g. `tenjin edit <id> --body post.md`.",
|
|
535
|
+
cause: err
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
const { frontmatter, body } = parseFrontmatter(raw);
|
|
539
|
+
return { raw, body, hadFrontmatter: Object.keys(frontmatter).length > 0 };
|
|
540
|
+
}
|
|
541
|
+
function storedList(post, key) {
|
|
542
|
+
return post.resource?.[key] ?? [];
|
|
543
|
+
}
|
|
544
|
+
function appendUnique(stored, additions) {
|
|
545
|
+
const out = [...stored];
|
|
546
|
+
for (const item of additions) {
|
|
547
|
+
if (!out.includes(item)) out.push(item);
|
|
548
|
+
}
|
|
549
|
+
return out;
|
|
550
|
+
}
|
|
551
|
+
function shippedTypedText(args, input) {
|
|
552
|
+
const parts = [];
|
|
553
|
+
const add = (v) => {
|
|
554
|
+
if (v !== void 0) parts.push(v);
|
|
555
|
+
};
|
|
556
|
+
if (input.title !== void 0) add(args.title);
|
|
557
|
+
if (input.excerpt !== void 0) add(args.excerpt);
|
|
558
|
+
const card = input.resource;
|
|
559
|
+
if (card === void 0) return parts.join("\n");
|
|
560
|
+
if (card.scope !== void 0) add(args.scope);
|
|
561
|
+
if (card.exclusions !== void 0) add(args.exclusions);
|
|
562
|
+
if (card.provenanceSummary !== void 0) add(args.provenance);
|
|
563
|
+
if (card.methodologySummary !== void 0) add(args.methodology);
|
|
564
|
+
if (card.asOf !== void 0) add(args.asOf);
|
|
565
|
+
if (card.validUntil !== void 0) add(args.validUntil);
|
|
566
|
+
if (card.questionsAnswered !== void 0) {
|
|
567
|
+
for (const item of args.question ?? args.addQuestion ?? []) add(item);
|
|
568
|
+
}
|
|
569
|
+
if (card.tasksSupported !== void 0) {
|
|
570
|
+
for (const item of args.task ?? args.addTask ?? []) add(item);
|
|
571
|
+
}
|
|
572
|
+
if (card.appliesTo !== void 0 && args.appliesTo !== void 0) {
|
|
573
|
+
for (const values of Object.values(parseAppliesToFlags(args.appliesTo))) parts.push(...values);
|
|
574
|
+
}
|
|
575
|
+
return parts.join("\n");
|
|
576
|
+
}
|
|
577
|
+
function blockMessage(blocking) {
|
|
578
|
+
return `Edit blocked: the new content contains ${describeFindings(blocking)}.`;
|
|
579
|
+
}
|
|
580
|
+
function confirmMessage(warnCount, changeCount) {
|
|
581
|
+
return warnCount > 0 ? `Edit needs confirmation: ${changeCount} change(s), ${warnCount} finding(s).` : `Edit needs confirmation: ${changeCount} change(s).`;
|
|
582
|
+
}
|
|
583
|
+
var PREVIEW_MAX = 60;
|
|
584
|
+
var LINE_MAX = 200;
|
|
585
|
+
function clip(value, max = PREVIEW_MAX) {
|
|
586
|
+
const clean = sanitizeForTerminal(value).replace(/\s+/g, " ").trim();
|
|
587
|
+
return clean.length > max ? `${clean.slice(0, max)}\u2026` : clean;
|
|
588
|
+
}
|
|
589
|
+
function preview(value) {
|
|
590
|
+
if (value === void 0 || value === null || value.length === 0) return "(unset)";
|
|
591
|
+
const clean = sanitizeForTerminal(value).replace(/\s+/g, " ").trim();
|
|
592
|
+
if (clean.length === 0) return "(unset)";
|
|
593
|
+
return clean.length > PREVIEW_MAX ? `${JSON.stringify(clean.slice(0, PREVIEW_MAX))}\u2026` : JSON.stringify(clean);
|
|
594
|
+
}
|
|
595
|
+
function previewList(values) {
|
|
596
|
+
return values.map((v) => preview(v)).join(", ");
|
|
597
|
+
}
|
|
598
|
+
function appliesToPreview(appliesTo) {
|
|
599
|
+
const entries = Object.entries(appliesTo);
|
|
600
|
+
if (entries.length === 0) return "(unset)";
|
|
601
|
+
const rendered = entries.map(([key, values]) => `${clip(key)}=${values.map((v) => clip(v)).join("|")}`).join(", ");
|
|
602
|
+
return clip(rendered, LINE_MAX);
|
|
603
|
+
}
|
|
604
|
+
function sameList(a, b) {
|
|
605
|
+
return a.length === b.length && a.every((v, i) => v === b[i]);
|
|
606
|
+
}
|
|
607
|
+
function hasText(value) {
|
|
608
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
export {
|
|
612
|
+
runEdit
|
|
613
|
+
};
|
|
614
|
+
//# sourceMappingURL=chunk-E6BNARCS.js.map
|