tenjin-cli 0.1.0-alpha.0 → 0.1.0-alpha.10
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/NOTICE.md +33 -0
- package/README.md +575 -50
- package/dist/{_esm-ZH2J4QEH.js → _esm-C5CRWCYU.js} +2 -2
- package/dist/_esm-N4KAVXQR.js +881 -0
- package/dist/buy-FMDBZ4NY.js +44 -0
- package/dist/candidate-7LAELUQD.js +23 -0
- package/dist/ccip-RPPPKTJR.js +19 -0
- package/dist/{ccip-FXWZDDF5.js → ccip-ZGGWQN4X.js} +6 -5
- package/dist/chunk-2GSRYTZS.js +127 -0
- package/dist/chunk-2GSRYTZS.js.map +1 -0
- package/dist/chunk-2I4QTOLB.js +11 -0
- package/dist/chunk-2I4QTOLB.js.map +1 -0
- package/dist/chunk-36X2CA3N.js +311 -0
- package/dist/chunk-36X2CA3N.js.map +1 -0
- package/dist/{chunk-F5DZJLU3.js → chunk-47PP7TAG.js} +1441 -634
- package/dist/chunk-47PP7TAG.js.map +1 -0
- package/dist/chunk-5JMKIDMM.js +316 -0
- package/dist/chunk-5JMKIDMM.js.map +1 -0
- package/dist/chunk-5JXAZP7H.js +206 -0
- package/dist/chunk-5JXAZP7H.js.map +1 -0
- package/dist/chunk-5SE6BJRP.js +135 -0
- package/dist/chunk-5SE6BJRP.js.map +1 -0
- package/dist/chunk-6BZLSRNU.js +149 -0
- package/dist/chunk-6BZLSRNU.js.map +1 -0
- package/dist/{chunk-PAAL45FJ.js → chunk-7FK2UN2T.js} +3410 -412
- package/dist/chunk-7FK2UN2T.js.map +1 -0
- package/dist/chunk-7WDY4AXV.js +14620 -0
- package/dist/chunk-7WDY4AXV.js.map +1 -0
- package/dist/chunk-A6KCZPNQ.js +83 -0
- package/dist/chunk-A6KCZPNQ.js.map +1 -0
- package/dist/chunk-AWQ6A4CI.js +341 -0
- package/dist/chunk-AWQ6A4CI.js.map +1 -0
- package/dist/chunk-BJJ5BQO6.js +162 -0
- package/dist/chunk-BJJ5BQO6.js.map +1 -0
- package/dist/chunk-BUDHTDKL.js +612 -0
- package/dist/chunk-BUDHTDKL.js.map +1 -0
- package/dist/chunk-DKQMJTG7.js +188 -0
- package/dist/chunk-DKQMJTG7.js.map +1 -0
- package/dist/chunk-FKSAUOJU.js +137 -0
- package/dist/chunk-FKSAUOJU.js.map +1 -0
- package/dist/chunk-GECSWJ7O.js +1645 -0
- package/dist/chunk-GECSWJ7O.js.map +1 -0
- package/dist/chunk-GSDZRCGF.js +105 -0
- package/dist/chunk-GSDZRCGF.js.map +1 -0
- package/dist/chunk-JSSIMGQT.js +174 -0
- package/dist/chunk-JSSIMGQT.js.map +1 -0
- package/dist/chunk-KYH4KPE5.js +1357 -0
- package/dist/chunk-KYH4KPE5.js.map +1 -0
- package/dist/chunk-KYQVEKP5.js +209 -0
- package/dist/chunk-KYQVEKP5.js.map +1 -0
- package/dist/chunk-KZAAWQNP.js +6199 -0
- package/dist/chunk-KZAAWQNP.js.map +1 -0
- package/dist/{chunk-SXQQ2ZSR.js → chunk-M2O56UK7.js} +243 -75
- package/dist/chunk-M2O56UK7.js.map +1 -0
- package/dist/chunk-MD7WGYYI.js +125 -0
- package/dist/chunk-MD7WGYYI.js.map +1 -0
- package/dist/chunk-MJZZTKCC.js +323 -0
- package/dist/chunk-MJZZTKCC.js.map +1 -0
- package/dist/chunk-O6CAUZGY.js +317 -0
- package/dist/chunk-O6CAUZGY.js.map +1 -0
- package/dist/chunk-P74I3WH4.js +204 -0
- package/dist/chunk-P74I3WH4.js.map +1 -0
- package/dist/chunk-POF7HPRV.js +145 -0
- package/dist/chunk-POF7HPRV.js.map +1 -0
- package/dist/chunk-POJRB2AE.js +83 -0
- package/dist/chunk-POJRB2AE.js.map +1 -0
- package/dist/{chunk-FIYZLITH.js → chunk-PZRAAAY2.js} +107 -18
- package/dist/chunk-PZRAAAY2.js.map +1 -0
- package/dist/chunk-PZSUWDF2.js +35 -0
- package/dist/chunk-PZSUWDF2.js.map +1 -0
- package/dist/chunk-QW2Q2KAH.js +27 -0
- package/dist/chunk-QW2Q2KAH.js.map +1 -0
- package/dist/chunk-R2VLGNFD.js +181 -0
- package/dist/chunk-R2VLGNFD.js.map +1 -0
- package/dist/{chunk-CPUZRZ2A.js → chunk-RBJPAZFI.js} +25 -170
- package/dist/chunk-RBJPAZFI.js.map +1 -0
- package/dist/chunk-S5RYMCV6.js +70 -0
- package/dist/chunk-S5RYMCV6.js.map +1 -0
- package/dist/chunk-SGK2B724.js +67 -0
- package/dist/chunk-SGK2B724.js.map +1 -0
- package/dist/chunk-STND72DS.js +242 -0
- package/dist/chunk-STND72DS.js.map +1 -0
- package/dist/chunk-TEL27PR5.js +124 -0
- package/dist/chunk-TEL27PR5.js.map +1 -0
- package/dist/chunk-TWRYSGAW.js +134 -0
- package/dist/chunk-TWRYSGAW.js.map +1 -0
- package/dist/{chunk-WOHCAMDQ.js → chunk-U5S527PP.js} +1887 -1029
- package/dist/chunk-U5S527PP.js.map +1 -0
- package/dist/chunk-UHTVXQ2O.js +140 -0
- package/dist/chunk-UHTVXQ2O.js.map +1 -0
- package/dist/chunk-UOJRKQTZ.js +213 -0
- package/dist/chunk-UOJRKQTZ.js.map +1 -0
- package/dist/chunk-V4WWTZHZ.js +233 -0
- package/dist/chunk-V4WWTZHZ.js.map +1 -0
- package/dist/chunk-VRRLTZ2Q.js +651 -0
- package/dist/chunk-VRRLTZ2Q.js.map +1 -0
- package/dist/{chunk-TX5T3LKJ.js → chunk-W6R3HAAG.js} +21 -17
- package/dist/{chunk-TX5T3LKJ.js.map → chunk-W6R3HAAG.js.map} +1 -1
- package/dist/chunk-X3OOVSPX.js +154 -0
- package/dist/chunk-X3OOVSPX.js.map +1 -0
- package/dist/chunk-XJN5WUKL.js +204 -0
- package/dist/chunk-XJN5WUKL.js.map +1 -0
- package/dist/chunk-Y7ERTA7D.js +146 -0
- package/dist/chunk-Y7ERTA7D.js.map +1 -0
- package/dist/chunk-YLYINX2H.js +7806 -0
- package/dist/chunk-YLYINX2H.js.map +1 -0
- package/dist/chunk-ZQIQ55KK.js +51 -0
- package/dist/chunk-ZQIQ55KK.js.map +1 -0
- package/dist/chunk-ZUAQRIVP.js +1369 -0
- package/dist/chunk-ZUAQRIVP.js.map +1 -0
- package/dist/{chunk-3IMLRUZE.js → chunk-ZXTAQYNA.js} +6 -2
- package/dist/chunk-ZXTAQYNA.js.map +1 -0
- package/dist/{cli-LMHGCZ5S.js → cli-HK2XAWNW.js} +438 -177
- package/dist/cli-HK2XAWNW.js.map +1 -0
- package/dist/config-LYCHHNAJ.js +26 -0
- package/dist/config-LYCHHNAJ.js.map +1 -0
- package/dist/dist-U4M6QCKE.js +2842 -0
- package/dist/dist-U4M6QCKE.js.map +1 -0
- package/dist/doctor-2KPUQURC.js +27 -0
- package/dist/doctor-2KPUQURC.js.map +1 -0
- package/dist/edit-TST3OCKQ.js +38 -0
- package/dist/edit-TST3OCKQ.js.map +1 -0
- package/dist/ethersCompat-Df4a6QIZ-WHYKB6HA.js +18 -0
- package/dist/ethersCompat-Df4a6QIZ-WHYKB6HA.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/inspect-TPTHVPBB.js +35 -0
- package/dist/inspect-TPTHVPBB.js.map +1 -0
- package/dist/install-PT3XEDJ6.js +1869 -0
- package/dist/install-PT3XEDJ6.js.map +1 -0
- package/dist/{mine.wasm-GQECMSGN.js → mine.wasm-6PIT3DK6.js} +2 -2
- package/dist/outcome-NPNSF2Q7.js +22 -0
- package/dist/outcome-NPNSF2Q7.js.map +1 -0
- package/dist/publish-XP5SEWST.js +41 -0
- package/dist/publish-XP5SEWST.js.map +1 -0
- package/dist/read-D4VXRWOG.js +158 -0
- package/dist/read-D4VXRWOG.js.map +1 -0
- package/dist/run-3IPGEXW7.js +16902 -0
- package/dist/run-3IPGEXW7.js.map +1 -0
- package/dist/search-YOBD6VDI.js +24 -0
- package/dist/search-YOBD6VDI.js.map +1 -0
- package/dist/{secp256k1-35YNNB6F.js → secp256k1-XRPVBC6V.js} +5 -4
- package/dist/secp256k1-XRPVBC6V.js.map +1 -0
- package/dist/send-BWNP6WN4.js +223 -0
- package/dist/send-BWNP6WN4.js.map +1 -0
- package/dist/session-GZEZBOMI.js +88 -0
- package/dist/session-GZEZBOMI.js.map +1 -0
- package/dist/skill-heal-OK6YALW6.js +85 -0
- package/dist/skill-heal-OK6YALW6.js.map +1 -0
- package/dist/usdc-4VCDHFWX.js +38 -0
- package/dist/usdc-4VCDHFWX.js.map +1 -0
- package/dist/viemAdapter-By13KInL-TUQJBMHM.js +14 -0
- package/dist/viemAdapter-By13KInL-TUQJBMHM.js.map +1 -0
- package/dist/wallet-5RHDFPN2.js +32 -0
- package/dist/wallet-5RHDFPN2.js.map +1 -0
- package/dist/wallet-YEGQBWWL.js +42 -0
- package/dist/wallet-YEGQBWWL.js.map +1 -0
- package/docs/agent-permissions.md +281 -0
- package/package.json +26 -17
- package/skills/tenjin/SKILL.md +364 -0
- package/skills/tenjin-publish/SKILL.md +219 -0
- package/skills/tenjin-search/SKILL.md +335 -0
- package/dist/chunk-376LHMK2.js +0 -100
- package/dist/chunk-376LHMK2.js.map +0 -1
- package/dist/chunk-CPUZRZ2A.js.map +0 -1
- package/dist/chunk-F5DZJLU3.js.map +0 -1
- package/dist/chunk-FIYZLITH.js.map +0 -1
- package/dist/chunk-LTTRND4A.js +0 -135
- package/dist/chunk-LTTRND4A.js.map +0 -1
- package/dist/chunk-PAAL45FJ.js.map +0 -1
- package/dist/chunk-QHIEYBLV.js +0 -320
- package/dist/chunk-QHIEYBLV.js.map +0 -1
- package/dist/chunk-SXQQ2ZSR.js.map +0 -1
- package/dist/chunk-WOHCAMDQ.js.map +0 -1
- package/dist/chunk-ZPZFPVDN.js +0 -67
- package/dist/chunk-ZPZFPVDN.js.map +0 -1
- package/dist/cli-LMHGCZ5S.js.map +0 -1
- package/dist/config-XVXZ3V2Q.js +0 -206
- package/dist/config-XVXZ3V2Q.js.map +0 -1
- package/dist/doctor-MVLZRVPU.js +0 -338
- package/dist/doctor-MVLZRVPU.js.map +0 -1
- package/dist/usdc-OQUOFF6R.js +0 -18
- package/dist/wallet-NRKWLKHX.js +0 -153
- package/dist/wallet-NRKWLKHX.js.map +0 -1
- package/dist/wallet-QUWK2PA4.js +0 -22
- /package/dist/{_esm-ZH2J4QEH.js.map → _esm-C5CRWCYU.js.map} +0 -0
- /package/dist/{ccip-FXWZDDF5.js.map → _esm-N4KAVXQR.js.map} +0 -0
- /package/dist/{chunk-3IMLRUZE.js.map → buy-FMDBZ4NY.js.map} +0 -0
- /package/dist/{secp256k1-35YNNB6F.js.map → candidate-7LAELUQD.js.map} +0 -0
- /package/dist/{usdc-OQUOFF6R.js.map → ccip-RPPPKTJR.js.map} +0 -0
- /package/dist/{wallet-QUWK2PA4.js.map → ccip-ZGGWQN4X.js.map} +0 -0
- /package/dist/{mine.wasm-GQECMSGN.js.map → mine.wasm-6PIT3DK6.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/settings.ts"],"sourcesContent":["import { execFile } from 'node:child_process';\nimport { readFile, stat } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { dirname, join } from 'node:path';\nimport { z } from 'zod';\nimport { CliError } from './errors';\nimport {\n PublishModeSchema,\n SEND_MAX_UNSET,\n loadRawConfig,\n resolvePublishDefaultPrice,\n resolvePublishMode,\n resolveSettings,\n} from './config';\nimport type { Provenance, ProjectPublishLayer, PublishMode } from './config';\nimport { parseUsdToAtomic } from './money';\nimport { parseConfirmPolicy, type SpendPolicy } from './policy';\nimport type { CommandContext } from '../context';\n\n/**\n * The effective runtime settings a B2 command needs, resolved once through the\n * same precedence (flag > env > file > default) config/doctor use. Spend values\n * arrive atomic from config and are handed on as bigint for the policy layer.\n */\nexport interface ResolvedSettings {\n baseUrl: string;\n rpcUrl: string;\n policy: SpendPolicy;\n /** Search-only privacy opt-in; sends X-Tenjin-Eval-Cohort: 1 when true. */\n evalCohort: boolean;\n /**\n * Hard per-send cap for `tenjin send`: SEND_MAX_UNSET = never configured\n * (send refuses until `config set sendMaxAmount`), null = explicit \"none\"\n * (uncapped opt-in), 0n = disabled, otherwise the atomic cap.\n */\n sendMaxAmountAtomic: bigint | null | typeof SEND_MAX_UNSET;\n}\n\nexport async function resolveContextSettings(ctx: CommandContext): Promise<ResolvedSettings> {\n const config = await loadRawConfig(ctx.dataDir);\n const s = resolveSettings({ config, flags: { baseUrl: ctx.flags.baseUrl }, env: process.env });\n return {\n baseUrl: s.baseUrl.value,\n rpcUrl: s.rpcUrl.value,\n evalCohort: s.evalCohort.value,\n sendMaxAmountAtomic:\n s.sendMaxAmount.value === SEND_MAX_UNSET\n ? SEND_MAX_UNSET\n : s.sendMaxAmount.value === 'none'\n ? null\n : BigInt(s.sendMaxAmount.value),\n policy: {\n maxAutoSpendAtomic: BigInt(s.maxAutoSpend.value),\n sessionBudgetAtomic: BigInt(s.sessionBudget.value),\n confirm: parseConfirmPolicy(s.confirm.value),\n allowlistCreators: s.allowlistCreators.value,\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// Publish consent settings (B3, D38)\n//\n// The publish mode/price cascade extends the same precedence machinery\n// (resolvePublishMode / resolvePublishDefaultPrice in lib/config) with a\n// per-project layer that needs I/O the pure resolvers can't do: it walks up from\n// cwd for a `.tenjin.json` and asks git whether that file is committed (the\n// loosening gate on `full-auto`). It lives here beside resolveContextSettings so\n// there is one settings resolver, not a parallel one.\n// ---------------------------------------------------------------------------\n\nexport const PROJECT_CONFIG_FILE = '.tenjin.json';\n\n/**\n * The per-project override file. `publish.defaultPrice` is DECIMAL USD (\"0.10\"),\n * because a hand-edited project file is a human edge (O1) — unlike config.json,\n * which stores atomic because `config set` converts at the command edge. The\n * decimal string is converted to atomic at load via the same money util the\n * config command uses. Partial + passthrough: forward-compatible with subkeys a\n * newer CLI adds, same posture as the global config.\n */\nconst ProjectConfigSchema = z\n .object({\n publish: z\n .object({\n mode: PublishModeSchema.optional(),\n defaultPrice: z.string().optional(),\n })\n .passthrough()\n .optional(),\n })\n .passthrough();\n\nexport interface LoadedProjectConfig {\n /** Absolute path of the discovered `.tenjin.json`. */\n path: string;\n layer: ProjectPublishLayer;\n}\n\nexport interface PublishSettingsDeps {\n /** git check-ignore seam; defaults to shelling out to git (see wallet/passphrase). */\n isGitignored?: (filePath: string) => Promise<boolean>;\n /** Ownership seam; defaults to stat().uid vs process uid. Gates a planted file. */\n isForeignOwned?: (filePath: string) => Promise<boolean>;\n /** One-line stderr warning sink; defaults to process.stderr. */\n warn?: (message: string) => void;\n /** Upper bound of the walk; defaults to the user's home directory. */\n homeDir?: string;\n}\n\nexport interface ResolvedPublishSettings {\n mode: PublishMode;\n modeSource: Provenance;\n defaultPriceAtomic: string;\n defaultPriceSource: Provenance;\n /** Non-fatal notices for stderr (e.g. the full-auto downgrade). */\n warnings: string[];\n /** The `.tenjin.json` that contributed the project layer, if one was found. */\n projectConfigPath?: string;\n}\n\n/**\n * Resolve the effective publish mode + default price across every layer:\n * global config.json < project `.tenjin.json` < env (TENJIN_PUBLISH_MODE) <\n * flag (`--mode`), with the `full-auto` loosening gate applied to the project\n * layer. The seam a `publish` command (B3.2) resolves its consent through.\n */\nexport async function resolvePublishSettings(\n input: { dataDir: string; cwd: string; flag?: string; env?: NodeJS.ProcessEnv },\n deps: PublishSettingsDeps = {},\n): Promise<ResolvedPublishSettings> {\n const env = input.env ?? process.env;\n const config = await loadRawConfig(input.dataDir);\n const project = await loadProjectConfig(input.cwd, deps);\n const layer = project?.layer;\n\n const mode = resolvePublishMode({ config, project: layer, env, flag: input.flag });\n const price = resolvePublishDefaultPrice({ config, project: layer });\n const warnings = mode.downgradedWarning !== undefined ? [mode.downgradedWarning] : [];\n\n return {\n mode: mode.value,\n modeSource: mode.source,\n defaultPriceAtomic: price.value,\n defaultPriceSource: price.source,\n warnings,\n ...(project !== null ? { projectConfigPath: project.path } : {}),\n };\n}\n\n/**\n * Find the nearest `.tenjin.json` walking up from cwd toward the repo root (the\n * first directory holding a `.git`, inclusive), never crossing above $HOME, then\n * load, validate, and check whether it is gitignored. A file not owned by the\n * current user is ignored with a stderr warning (a planted config on a shared\n * host must not become the honored project layer). Null when none is found; a\n * present-but-unreadable/malformed file is CONFIG_INVALID (never silently\n * skipped).\n */\nexport async function loadProjectConfig(\n cwd: string,\n deps: PublishSettingsDeps = {},\n): Promise<LoadedProjectConfig | null> {\n const path = await findProjectConfigFile(cwd, deps);\n if (path === null) return null;\n\n let json: unknown;\n try {\n // readFile is inside the try: a raced delete (ENOENT), a directory named\n // .tenjin.json (EISDIR), or a permission error (EACCES) is a bad project file,\n // not an INTERNAL fault.\n json = JSON.parse(await readFile(path, 'utf8'));\n } catch (err) {\n throw new CliError('CONFIG_INVALID', `${PROJECT_CONFIG_FILE} at ${path} could not be read`, {\n fix: `Fix or delete ${path} (must be a readable JSON file).`,\n cause: err,\n });\n }\n const parsed = ProjectConfigSchema.safeParse(json);\n if (!parsed.success) {\n throw new CliError('CONFIG_INVALID', `${PROJECT_CONFIG_FILE} at ${path} is invalid`, {\n fix: `Correct the reported keys in ${path}, or delete it.`,\n details: parsed.error.issues,\n });\n }\n\n const isGitignored = deps.isGitignored ?? defaultIsGitignored;\n const gitignored = await isGitignored(path);\n const layer: ProjectPublishLayer = { gitignored };\n if (parsed.data.publish !== undefined) {\n const { mode, defaultPrice } = parsed.data.publish;\n layer.publish = {\n ...(mode !== undefined ? { mode } : {}),\n ...(defaultPrice !== undefined\n ? { defaultPrice: parseProjectPrice(defaultPrice, path) }\n : {}),\n };\n }\n return { path, layer };\n}\n\n/**\n * Convert a `.tenjin.json` decimal-USD price to atomic via the shared money\n * parser. parseUsdToAtomic throws USAGE on a bad amount; re-raise as\n * CONFIG_INVALID naming the file, so it reads like the file's other errors.\n */\nfunction parseProjectPrice(decimalUsd: string, path: string): string {\n try {\n return parseUsdToAtomic(decimalUsd);\n } catch (err) {\n throw new CliError(\n 'CONFIG_INVALID',\n `${PROJECT_CONFIG_FILE} at ${path} has an invalid publish.defaultPrice`,\n { fix: 'Use a non-negative decimal USD amount like \"0.10\".', cause: err },\n );\n }\n}\n\nasync function findProjectConfigFile(\n cwd: string,\n deps: PublishSettingsDeps,\n): Promise<string | null> {\n const homeDir = deps.homeDir ?? homedir();\n const isForeignOwned = deps.isForeignOwned ?? defaultIsForeignOwned;\n const warn = deps.warn ?? ((message: string) => process.stderr.write(`${message}\\n`));\n\n let dir = cwd;\n // Bounded by $HOME (a shared-host trust boundary) and the filesystem root\n // (dirname('/') === '/'), whichever comes first.\n for (;;) {\n const candidate = join(dir, PROJECT_CONFIG_FILE);\n if (await pathExists(candidate)) {\n if (await isForeignOwned(candidate)) {\n // A file owned by another user (e.g. /tmp/.tenjin.json on a shared box)\n // must never become the honored layer; skip it and keep walking.\n warn(`Ignoring ${candidate}: not owned by the current user.`);\n } else {\n return candidate;\n }\n }\n if (await pathExists(join(dir, '.git'))) return null; // repo root, no file\n if (dir === homeDir) return null; // never cross above $HOME\n const parent = dirname(dir);\n if (parent === dir) return null;\n dir = parent;\n }\n}\n\n/**\n * True when the file is owned by a different uid than the process. On a platform\n * without a uid model (Windows: process.getuid is undefined) this is always\n * false — the ownership gate is a POSIX shared-host protection.\n */\nasync function defaultIsForeignOwned(filePath: string): Promise<boolean> {\n const uid = process.getuid?.();\n if (uid === undefined) return false;\n try {\n return (await stat(filePath)).uid !== uid;\n } catch {\n return false;\n }\n}\n\n/** True when a path exists (of any type). Shared with the candidate command's\n * repo-root walk so the two `.git`/file probes stay one implementation. */\nexport async function pathExists(path: string): Promise<boolean> {\n try {\n await stat(path);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * True only on a git check-ignore exit 0 (the path is ignored). Exit 1 (tracked)\n * and any error (git absent, not a repo) resolve false: `full-auto` is honored\n * from a project file ONLY when git positively confirms it is ignored. Uses\n * execFile with an argv array (never a shell), matching wallet/passphrase.ts.\n */\nfunction defaultIsGitignored(filePath: string): Promise<boolean> {\n return new Promise((resolve) => {\n execFile(\n 'git',\n ['check-ignore', '--quiet', '--', filePath],\n { cwd: dirname(filePath) },\n (err) => resolve(err === null),\n );\n });\n}\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,612 @@
|
|
|
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-ZUAQRIVP.js";
|
|
19
|
+
import {
|
|
20
|
+
describeWallet,
|
|
21
|
+
resolveWalletProvider
|
|
22
|
+
} from "./chunk-GECSWJ7O.js";
|
|
23
|
+
import {
|
|
24
|
+
sanitizeForTerminal
|
|
25
|
+
} from "./chunk-R2VLGNFD.js";
|
|
26
|
+
import {
|
|
27
|
+
resolveContextSettings,
|
|
28
|
+
resolvePublishSettings
|
|
29
|
+
} from "./chunk-BJJ5BQO6.js";
|
|
30
|
+
import {
|
|
31
|
+
UUID_RE,
|
|
32
|
+
parsePublishModeFlag,
|
|
33
|
+
parseUsdToAtomic,
|
|
34
|
+
toMoney
|
|
35
|
+
} from "./chunk-36X2CA3N.js";
|
|
36
|
+
import {
|
|
37
|
+
CliError
|
|
38
|
+
} from "./chunk-PZRAAAY2.js";
|
|
39
|
+
|
|
40
|
+
// src/commands/edit.ts
|
|
41
|
+
import { readFile } from "fs/promises";
|
|
42
|
+
import { dirname, resolve } from "path";
|
|
43
|
+
async function runEdit(args, ctx, deps = {}) {
|
|
44
|
+
const env = deps.env ?? process.env;
|
|
45
|
+
const cwd = deps.cwd ?? process.cwd();
|
|
46
|
+
if (!UUID_RE.test(args.postId)) {
|
|
47
|
+
throw new CliError("USAGE", `Invalid post id: ${JSON.stringify(args.postId)}`, {
|
|
48
|
+
fix: "Pass the post uuid from `tenjin publish`\u2019s receipt or your desk."
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (args.mode !== void 0) parsePublishModeFlag(args.mode, "--mode");
|
|
52
|
+
rejectEmptyValues(args);
|
|
53
|
+
assertAppendExclusivity(args);
|
|
54
|
+
const clears = parseClears(args);
|
|
55
|
+
const cardFlags = cardFlagsFrom(args);
|
|
56
|
+
const priceAtomic = args.price !== void 0 ? parseUsdToAtomic(args.price) : void 0;
|
|
57
|
+
const bodyFile = args.body !== void 0 ? await readBodyFile(args.body) : void 0;
|
|
58
|
+
const wantsChange = hasChangeFlags(args);
|
|
59
|
+
const runtime = await resolveContextSettings(ctx);
|
|
60
|
+
const provider = resolveWalletProvider(
|
|
61
|
+
ctx,
|
|
62
|
+
deps.provider !== void 0 ? { provider: deps.provider } : {}
|
|
63
|
+
);
|
|
64
|
+
await describeWallet(provider);
|
|
65
|
+
const signer = await provider.getSigner();
|
|
66
|
+
const auth = resolveWriteAuth({
|
|
67
|
+
signer,
|
|
68
|
+
baseUrl: runtime.baseUrl,
|
|
69
|
+
dataDir: ctx.dataDir,
|
|
70
|
+
scope: wantsChange ? "read+write" : "read",
|
|
71
|
+
...deps.useSession !== void 0 ? { useSession: deps.useSession } : {},
|
|
72
|
+
env
|
|
73
|
+
});
|
|
74
|
+
const client = {
|
|
75
|
+
baseUrl: runtime.baseUrl,
|
|
76
|
+
timeoutMs: ctx.flags.timeout,
|
|
77
|
+
...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
|
|
78
|
+
};
|
|
79
|
+
const stored = await getOwnPost(args.postId, auth, client);
|
|
80
|
+
if (!wantsChange) return showReceipt(stored);
|
|
81
|
+
if (args.addQuestion !== void 0 && args.addQuestion.length > 0) {
|
|
82
|
+
cardFlags.question = appendUnique(storedList(stored, "questionsAnswered"), args.addQuestion);
|
|
83
|
+
}
|
|
84
|
+
if (args.addTask !== void 0 && args.addTask.length > 0) {
|
|
85
|
+
cardFlags.task = appendUnique(storedList(stored, "tasksSupported"), args.addTask);
|
|
86
|
+
}
|
|
87
|
+
const intent = {
|
|
88
|
+
...args.title !== void 0 ? { title: args.title } : {},
|
|
89
|
+
...bodyFile !== void 0 ? { bodyMd: bodyFile.body } : {},
|
|
90
|
+
...args.excerpt !== void 0 ? { excerpt: args.excerpt } : {},
|
|
91
|
+
...priceAtomic !== void 0 ? { priceAtomic } : {},
|
|
92
|
+
...withClears(deriveCard({}, cardFlags), clears, stored.resource)
|
|
93
|
+
};
|
|
94
|
+
const { input, lines: changes } = diffUpdate(stored, intent);
|
|
95
|
+
if (changes.length === 0) return noChangeReceipt(stored);
|
|
96
|
+
buildPostUpdateBody(input);
|
|
97
|
+
const settings = await resolvePublishSettings({
|
|
98
|
+
dataDir: ctx.dataDir,
|
|
99
|
+
cwd,
|
|
100
|
+
...args.mode !== void 0 ? { flag: args.mode } : {},
|
|
101
|
+
env
|
|
102
|
+
});
|
|
103
|
+
writeModeNotices(
|
|
104
|
+
ctx.io.stderr,
|
|
105
|
+
settings,
|
|
106
|
+
env,
|
|
107
|
+
"each edit asks you once. Set auto to apply clean edits automatically"
|
|
108
|
+
);
|
|
109
|
+
const markerRoot = args.body !== void 0 ? dirname(resolve(cwd, args.body)) : cwd;
|
|
110
|
+
const scanContext = { projectMarkers: await deriveProjectMarkers(markerRoot) };
|
|
111
|
+
const findings = dedupeFindings([
|
|
112
|
+
...input.bodyMd !== void 0 ? scan(bodyFile?.raw ?? "", scanContext) : [],
|
|
113
|
+
...scan(shippedTypedText(args, input), scanContext)
|
|
114
|
+
]);
|
|
115
|
+
const blocking = findings.filter((f) => f.severity === "block");
|
|
116
|
+
const warns = findings.filter((f) => f.severity === "warn");
|
|
117
|
+
if (blocking.length > 0) {
|
|
118
|
+
throw new CliError("PUBLISH_BLOCKED", blockMessage(blocking), {
|
|
119
|
+
fix: "Remove the secret from the new content (it is never masked away by --yes), then re-run.",
|
|
120
|
+
details: { mode: settings.mode, findings: blocking.map(publicFinding) }
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
const notes = editNotes(args, stored, bodyFile, clears);
|
|
124
|
+
for (const line of [...notes, ...changes]) ctx.io.stderr.write(`${line}
|
|
125
|
+
`);
|
|
126
|
+
if (needsConfirmation(settings.mode, warns.length) && args.yes !== true) {
|
|
127
|
+
throw new CliError("NEEDS_CONFIRMATION", confirmMessage(warns.length, changes.length), {
|
|
128
|
+
fix: "Review the changes, then re-run with --yes.",
|
|
129
|
+
details: {
|
|
130
|
+
mode: settings.mode,
|
|
131
|
+
postId: stored.id,
|
|
132
|
+
title: sanitizeForTerminal(stored.title),
|
|
133
|
+
changes,
|
|
134
|
+
...notes.length > 0 ? { notes } : {},
|
|
135
|
+
findings: warns.map(publicFinding)
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
const updated = await updatePost(args.postId, input, auth, client);
|
|
140
|
+
return updateReceipt(updated, changes, notes, settings.mode);
|
|
141
|
+
}
|
|
142
|
+
function showReceipt(post) {
|
|
143
|
+
const price = toMoney(post.price);
|
|
144
|
+
const card = post.resource;
|
|
145
|
+
const lines = [
|
|
146
|
+
`${sanitizeForTerminal(post.title)} (${sanitizeForTerminal(post.status)}), ${price.usd} USD (${price.atomic} atomic)`,
|
|
147
|
+
`url: ${sanitizeForTerminal(post.url)}`,
|
|
148
|
+
...hasText(post.excerpt) ? [`excerpt: ${preview(post.excerpt)}`] : [],
|
|
149
|
+
...cardLines(card),
|
|
150
|
+
eligibilityLine(card)
|
|
151
|
+
];
|
|
152
|
+
return { data: post, humanLines: lines };
|
|
153
|
+
}
|
|
154
|
+
function updateReceipt(post, changes, notes, mode) {
|
|
155
|
+
const card = post.resource;
|
|
156
|
+
const lines = [
|
|
157
|
+
`Updated ${sanitizeForTerminal(post.title)} \u2192 ${sanitizeForTerminal(post.url)}`,
|
|
158
|
+
eligibilityLine(card),
|
|
159
|
+
...(post.warnings ?? []).map((w) => `warning: ${sanitizeForTerminal(w)}`)
|
|
160
|
+
];
|
|
161
|
+
return {
|
|
162
|
+
// `mode` is echoed because a per-call --mode (or the MCP `mode` argument) is
|
|
163
|
+
// otherwise invisible in a transcript: the receipt would look identical
|
|
164
|
+
// whether the caller loosened the gate for this run or not.
|
|
165
|
+
data: { ...post, mode, changes, ...notes.length > 0 ? { notes } : {} },
|
|
166
|
+
humanLines: lines
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function noChangeReceipt(post) {
|
|
170
|
+
return {
|
|
171
|
+
data: { ...post, changes: [] },
|
|
172
|
+
humanLines: [
|
|
173
|
+
`No changes: every value given already matches ${sanitizeForTerminal(post.title)}. Nothing was written.`
|
|
174
|
+
]
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function cardLines(card) {
|
|
178
|
+
if (card === void 0) return [];
|
|
179
|
+
const lines = [];
|
|
180
|
+
const list = (label, values) => {
|
|
181
|
+
if (values !== void 0 && values !== null && values.length > 0) {
|
|
182
|
+
lines.push(
|
|
183
|
+
`${label} (${values.length}): ${values.map((v) => sanitizeForTerminal(v)).join(" | ")}`
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
list("questionsAnswered", card.questionsAnswered);
|
|
188
|
+
list("tasksSupported", card.tasksSupported);
|
|
189
|
+
for (const [label, value] of [
|
|
190
|
+
["scope", card.scope],
|
|
191
|
+
["exclusions", card.exclusions],
|
|
192
|
+
["artifactType", card.artifactType],
|
|
193
|
+
["temporalMode", card.temporalMode],
|
|
194
|
+
["asOf", card.asOf],
|
|
195
|
+
["validUntil", card.validUntil],
|
|
196
|
+
["provenance", card.provenanceSummary],
|
|
197
|
+
["methodology", card.methodologySummary],
|
|
198
|
+
["supersedesPostId", card.supersedesPostId]
|
|
199
|
+
]) {
|
|
200
|
+
if (hasText(value)) lines.push(`${label}: ${preview(value)}`);
|
|
201
|
+
}
|
|
202
|
+
if (card.appliesTo !== void 0 && card.appliesTo !== null) {
|
|
203
|
+
for (const [key, values] of Object.entries(card.appliesTo)) {
|
|
204
|
+
lines.push(
|
|
205
|
+
`appliesTo ${sanitizeForTerminal(key)}: ${values.map((v) => sanitizeForTerminal(v)).join(", ")}`
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return lines;
|
|
210
|
+
}
|
|
211
|
+
function eligibilityLine(card) {
|
|
212
|
+
if (card === void 0) return "No answer card (browse-only document).";
|
|
213
|
+
const missing = missingSentences(card.cacheEligibleMissing).map(sanitizeForTerminal);
|
|
214
|
+
if (card.cacheEligible) return "Answer card is search-eligible.";
|
|
215
|
+
return missing.length > 0 ? `Answer card not search-eligible yet: ${missing.join(" ")}` : "Answer card is not search-eligible.";
|
|
216
|
+
}
|
|
217
|
+
function diffUpdate(stored, intent) {
|
|
218
|
+
const lines = [];
|
|
219
|
+
const input = {};
|
|
220
|
+
const title = intent.title?.trim();
|
|
221
|
+
if (title !== void 0 && title !== stored.title) {
|
|
222
|
+
input.title = title;
|
|
223
|
+
lines.push(`title: ${preview(stored.title)} \u2192 ${preview(title)}`);
|
|
224
|
+
}
|
|
225
|
+
if (intent.priceAtomic !== void 0 && intent.priceAtomic !== stored.price) {
|
|
226
|
+
const before = toMoney(stored.price);
|
|
227
|
+
const after = toMoney(intent.priceAtomic);
|
|
228
|
+
input.priceAtomic = intent.priceAtomic;
|
|
229
|
+
lines.push(
|
|
230
|
+
`price: ${before.usd} USD (${before.atomic} atomic) \u2192 ${after.usd} USD (${after.atomic} atomic)`
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
if (intent.bodyMd !== void 0 && intent.bodyMd !== stored.bodyMd) {
|
|
234
|
+
input.bodyMd = intent.bodyMd;
|
|
235
|
+
lines.push(`body: ${(stored.bodyMd ?? "").length} \u2192 ${intent.bodyMd.length} characters`);
|
|
236
|
+
}
|
|
237
|
+
const excerpt = intent.excerpt?.trim();
|
|
238
|
+
if (excerpt !== void 0 && excerpt !== (stored.excerpt ?? "")) {
|
|
239
|
+
input.excerpt = excerpt;
|
|
240
|
+
lines.push(`excerpt: ${preview(stored.excerpt)} \u2192 ${preview(excerpt)}`);
|
|
241
|
+
}
|
|
242
|
+
const card = diffCard(stored.resource, intent.resource);
|
|
243
|
+
lines.push(...card.lines);
|
|
244
|
+
if (card.card !== void 0) input.resource = card.card;
|
|
245
|
+
return { input, lines };
|
|
246
|
+
}
|
|
247
|
+
var CARD_PASS = {
|
|
248
|
+
questionsAnswered: "list",
|
|
249
|
+
tasksSupported: "list",
|
|
250
|
+
asOf: "iso",
|
|
251
|
+
validUntil: "iso",
|
|
252
|
+
scope: "scalar",
|
|
253
|
+
exclusions: "scalar",
|
|
254
|
+
artifactType: "scalar",
|
|
255
|
+
temporalMode: "scalar",
|
|
256
|
+
provenanceSummary: "scalar",
|
|
257
|
+
methodologySummary: "scalar",
|
|
258
|
+
supersedesPostId: "scalar",
|
|
259
|
+
appliesTo: "map",
|
|
260
|
+
mediaType: "none",
|
|
261
|
+
maintenanceCadence: "none",
|
|
262
|
+
reproductionMinutes: "none",
|
|
263
|
+
estimatedPaidInputCost: "none"
|
|
264
|
+
};
|
|
265
|
+
function keysIn(pass) {
|
|
266
|
+
return Object.entries(CARD_PASS).filter(([, value]) => value === pass).map(([key]) => key);
|
|
267
|
+
}
|
|
268
|
+
var CARD_LABEL = {
|
|
269
|
+
provenanceSummary: "provenance",
|
|
270
|
+
methodologySummary: "methodology"
|
|
271
|
+
};
|
|
272
|
+
function cardLabel(key) {
|
|
273
|
+
return CARD_LABEL[key] ?? key;
|
|
274
|
+
}
|
|
275
|
+
function diffCard(stored, next) {
|
|
276
|
+
const lines = [];
|
|
277
|
+
const card = {};
|
|
278
|
+
const keep = (key, value, line) => {
|
|
279
|
+
card[key] = value;
|
|
280
|
+
lines.push(line);
|
|
281
|
+
};
|
|
282
|
+
if (next === void 0) return { lines };
|
|
283
|
+
for (const key of keysIn("list")) {
|
|
284
|
+
const after = next[key];
|
|
285
|
+
if (after === void 0) continue;
|
|
286
|
+
const old = stored?.[key] ?? [];
|
|
287
|
+
if (sameList(old, after)) continue;
|
|
288
|
+
const added = after.filter((v) => !old.includes(v));
|
|
289
|
+
const detail = after.length === 0 ? " (cleared)" : added.length > 0 ? ` (new: ${previewList(added)})` : "";
|
|
290
|
+
keep(key, after, `${key}: ${old.length} \u2192 ${after.length}${detail}`);
|
|
291
|
+
}
|
|
292
|
+
for (const key of keysIn("iso")) {
|
|
293
|
+
const after = next[key];
|
|
294
|
+
if (after === void 0) continue;
|
|
295
|
+
const from = isoInstant(stored?.[key]);
|
|
296
|
+
const to = isoInstant(after);
|
|
297
|
+
if (from === to) continue;
|
|
298
|
+
keep(key, to, `${key}: ${preview(from)} \u2192 ${to === null ? "(cleared)" : preview(to)}`);
|
|
299
|
+
}
|
|
300
|
+
for (const key of keysIn("scalar")) {
|
|
301
|
+
const after = next[key];
|
|
302
|
+
if (after === void 0) continue;
|
|
303
|
+
const from = stored?.[key] ?? null;
|
|
304
|
+
if (from === after) continue;
|
|
305
|
+
keep(
|
|
306
|
+
key,
|
|
307
|
+
after,
|
|
308
|
+
`${cardLabel(key)}: ${preview(from)} \u2192 ${after === null ? "(cleared)" : preview(after)}`
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
for (const key of keysIn("map")) {
|
|
312
|
+
const after = next[key];
|
|
313
|
+
if (after === void 0) continue;
|
|
314
|
+
const before = stored?.[key] ?? {};
|
|
315
|
+
if (sameAppliesTo(before, after)) continue;
|
|
316
|
+
keep(key, after, `${key}: ${appliesToPreview(before)} \u2192 ${appliesToPreview(after)}`);
|
|
317
|
+
}
|
|
318
|
+
return { ...Object.keys(card).length > 0 ? { card } : {}, lines };
|
|
319
|
+
}
|
|
320
|
+
function isoInstant(value) {
|
|
321
|
+
if (value === void 0 || value === null) return null;
|
|
322
|
+
const ms = Date.parse(value);
|
|
323
|
+
return Number.isFinite(ms) ? new Date(ms).toISOString() : value;
|
|
324
|
+
}
|
|
325
|
+
function sameAppliesTo(a, b) {
|
|
326
|
+
const aKeys = Object.keys(a).sort();
|
|
327
|
+
const bKeys = Object.keys(b).sort();
|
|
328
|
+
if (!sameList(aKeys, bKeys)) return false;
|
|
329
|
+
return aKeys.every((key) => sameList(a[key] ?? [], b[key] ?? []));
|
|
330
|
+
}
|
|
331
|
+
function editNotes(args, stored, bodyFile, clears) {
|
|
332
|
+
if (bodyFile === void 0) return [];
|
|
333
|
+
const notes = [];
|
|
334
|
+
if (bodyFile.hadFrontmatter) {
|
|
335
|
+
notes.push(
|
|
336
|
+
"note: frontmatter in the body file was ignored; metadata changes only through flags."
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
if (args.excerpt === void 0) {
|
|
340
|
+
notes.push(
|
|
341
|
+
`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.`
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
const asOfMoves = args.asOf !== void 0 || clears.includes("asOf");
|
|
345
|
+
if (stored.resource?.temporalMode === "snapshot" && !asOfMoves) {
|
|
346
|
+
notes.push(
|
|
347
|
+
`note: asOf is unchanged (${preview(stored.resource.asOf)}) on this snapshot card, and search freshness gating uses it. Pass --as-of to move it.`
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
return notes;
|
|
351
|
+
}
|
|
352
|
+
var CLEAR_FIELDS = [
|
|
353
|
+
"scope",
|
|
354
|
+
"exclusions",
|
|
355
|
+
"asOf",
|
|
356
|
+
"validUntil",
|
|
357
|
+
"provenance",
|
|
358
|
+
"methodology",
|
|
359
|
+
"supersedesPostId",
|
|
360
|
+
"questionsAnswered",
|
|
361
|
+
"tasksSupported",
|
|
362
|
+
"appliesTo"
|
|
363
|
+
];
|
|
364
|
+
var CLEAR_KEY = {
|
|
365
|
+
scope: "scope",
|
|
366
|
+
exclusions: "exclusions",
|
|
367
|
+
asOf: "asOf",
|
|
368
|
+
validUntil: "validUntil",
|
|
369
|
+
provenance: "provenanceSummary",
|
|
370
|
+
methodology: "methodologySummary",
|
|
371
|
+
supersedesPostId: "supersedesPostId",
|
|
372
|
+
questionsAnswered: "questionsAnswered",
|
|
373
|
+
tasksSupported: "tasksSupported",
|
|
374
|
+
appliesTo: "appliesTo"
|
|
375
|
+
};
|
|
376
|
+
var CLEAR_VALUE = {
|
|
377
|
+
scope: null,
|
|
378
|
+
exclusions: null,
|
|
379
|
+
asOf: null,
|
|
380
|
+
validUntil: null,
|
|
381
|
+
provenance: null,
|
|
382
|
+
methodology: null,
|
|
383
|
+
supersedesPostId: null,
|
|
384
|
+
questionsAnswered: [],
|
|
385
|
+
tasksSupported: [],
|
|
386
|
+
appliesTo: {}
|
|
387
|
+
};
|
|
388
|
+
var CLEAR_CONFLICTS = {
|
|
389
|
+
scope: ["scope"],
|
|
390
|
+
exclusions: ["exclusions"],
|
|
391
|
+
asOf: ["asOf"],
|
|
392
|
+
validUntil: ["validUntil"],
|
|
393
|
+
provenance: ["provenance"],
|
|
394
|
+
methodology: ["methodology"],
|
|
395
|
+
supersedesPostId: [],
|
|
396
|
+
questionsAnswered: ["question", "addQuestion"],
|
|
397
|
+
tasksSupported: ["task", "addTask"],
|
|
398
|
+
appliesTo: ["appliesTo"]
|
|
399
|
+
};
|
|
400
|
+
var FLAG_NAME = {
|
|
401
|
+
question: "--question",
|
|
402
|
+
task: "--task",
|
|
403
|
+
addQuestion: "--add-question",
|
|
404
|
+
addTask: "--add-task",
|
|
405
|
+
scope: "--scope",
|
|
406
|
+
exclusions: "--exclusions",
|
|
407
|
+
appliesTo: "--applies-to",
|
|
408
|
+
asOf: "--as-of",
|
|
409
|
+
validUntil: "--valid-until",
|
|
410
|
+
artifactType: "--artifact-type",
|
|
411
|
+
temporalMode: "--temporal-mode",
|
|
412
|
+
provenance: "--provenance",
|
|
413
|
+
methodology: "--methodology",
|
|
414
|
+
title: "--title",
|
|
415
|
+
price: "--price",
|
|
416
|
+
body: "--body",
|
|
417
|
+
excerpt: "--excerpt"
|
|
418
|
+
};
|
|
419
|
+
var CHANGE_KEYS = [
|
|
420
|
+
"question",
|
|
421
|
+
"task",
|
|
422
|
+
"addQuestion",
|
|
423
|
+
"addTask",
|
|
424
|
+
"scope",
|
|
425
|
+
"exclusions",
|
|
426
|
+
"appliesTo",
|
|
427
|
+
"asOf",
|
|
428
|
+
"validUntil",
|
|
429
|
+
"artifactType",
|
|
430
|
+
"temporalMode",
|
|
431
|
+
"provenance",
|
|
432
|
+
"methodology",
|
|
433
|
+
"title",
|
|
434
|
+
"price",
|
|
435
|
+
"body",
|
|
436
|
+
"excerpt",
|
|
437
|
+
"clear"
|
|
438
|
+
];
|
|
439
|
+
function hasChangeFlags(args) {
|
|
440
|
+
return CHANGE_KEYS.some((key) => {
|
|
441
|
+
const value = args[key];
|
|
442
|
+
return Array.isArray(value) ? value.length > 0 : value !== void 0;
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
function rejectEmptyValues(args) {
|
|
446
|
+
for (const [key, flag] of Object.entries(FLAG_NAME)) {
|
|
447
|
+
const value = args[key];
|
|
448
|
+
const empties = typeof value === "string" ? [value] : Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
|
|
449
|
+
for (const v of empties) {
|
|
450
|
+
if (v.trim().length === 0) {
|
|
451
|
+
const clearable = CLEAR_FIELDS.includes(clearNameFor(key));
|
|
452
|
+
throw new CliError("USAGE", `${flag} cannot be empty.`, {
|
|
453
|
+
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."
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
function clearNameFor(key) {
|
|
460
|
+
if (key === "question" || key === "addQuestion") return "questionsAnswered";
|
|
461
|
+
if (key === "task" || key === "addTask") return "tasksSupported";
|
|
462
|
+
return key;
|
|
463
|
+
}
|
|
464
|
+
function assertAppendExclusivity(args) {
|
|
465
|
+
const both = (a, b) => a !== void 0 && a.length > 0 && b !== void 0 && b.length > 0;
|
|
466
|
+
if (both(args.question, args.addQuestion)) {
|
|
467
|
+
throw new CliError("USAGE", "Pass either --question or --add-question, not both.", {
|
|
468
|
+
fix: "--question replaces the stored questions; --add-question appends to them."
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
if (both(args.task, args.addTask)) {
|
|
472
|
+
throw new CliError("USAGE", "Pass either --task or --add-task, not both.", {
|
|
473
|
+
fix: "--task replaces the stored tasks; --add-task appends to them."
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
function parseClears(args) {
|
|
478
|
+
const raw = args.clear ?? [];
|
|
479
|
+
const out = [];
|
|
480
|
+
for (const name of raw) {
|
|
481
|
+
if (!CLEAR_FIELDS.includes(name)) {
|
|
482
|
+
throw new CliError("USAGE", `Cannot clear ${JSON.stringify(name)}.`, {
|
|
483
|
+
fix: `Clearable fields: ${CLEAR_FIELDS.join(", ")}.`
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
const field = name;
|
|
487
|
+
for (const key of CLEAR_CONFLICTS[field]) {
|
|
488
|
+
const value = args[key];
|
|
489
|
+
const given = Array.isArray(value) ? value.length > 0 : value !== void 0;
|
|
490
|
+
if (given) {
|
|
491
|
+
throw new CliError(
|
|
492
|
+
"USAGE",
|
|
493
|
+
`--clear ${field} contradicts ${FLAG_NAME[key] ?? String(key)}.`,
|
|
494
|
+
{ fix: "Set the field or clear it, not both in the same run." }
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
if (!out.includes(field)) out.push(field);
|
|
499
|
+
}
|
|
500
|
+
return out;
|
|
501
|
+
}
|
|
502
|
+
function cardFlagsFrom(args) {
|
|
503
|
+
return {
|
|
504
|
+
...args.question !== void 0 && args.question.length > 0 ? { question: args.question } : {},
|
|
505
|
+
...args.task !== void 0 && args.task.length > 0 ? { task: args.task } : {},
|
|
506
|
+
...args.scope !== void 0 ? { scope: args.scope } : {},
|
|
507
|
+
...args.exclusions !== void 0 ? { exclusions: args.exclusions } : {},
|
|
508
|
+
...args.asOf !== void 0 ? { asOf: args.asOf } : {},
|
|
509
|
+
...args.validUntil !== void 0 ? { validUntil: args.validUntil } : {},
|
|
510
|
+
...args.artifactType !== void 0 ? { artifactType: args.artifactType } : {},
|
|
511
|
+
...args.temporalMode !== void 0 ? { temporalMode: args.temporalMode } : {},
|
|
512
|
+
...args.provenance !== void 0 ? { provenance: args.provenance } : {},
|
|
513
|
+
...args.methodology !== void 0 ? { methodology: args.methodology } : {},
|
|
514
|
+
...args.appliesTo !== void 0 && args.appliesTo.length > 0 ? { appliesTo: parseAppliesToFlags(args.appliesTo) } : {}
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
function withClears(set, clears, stored) {
|
|
518
|
+
const applicable = stored !== void 0 ? clears : [];
|
|
519
|
+
if (set === void 0 && applicable.length === 0) return {};
|
|
520
|
+
const card = { ...set ?? {} };
|
|
521
|
+
for (const name of applicable) {
|
|
522
|
+
card[CLEAR_KEY[name]] = CLEAR_VALUE[name];
|
|
523
|
+
}
|
|
524
|
+
return Object.keys(card).length > 0 ? { resource: card } : {};
|
|
525
|
+
}
|
|
526
|
+
async function readBodyFile(file) {
|
|
527
|
+
let raw;
|
|
528
|
+
try {
|
|
529
|
+
raw = await readFile(file, "utf8");
|
|
530
|
+
} catch (err) {
|
|
531
|
+
throw new CliError("USAGE", `Could not read ${JSON.stringify(file)}`, {
|
|
532
|
+
fix: "Pass a path to a readable Markdown file, e.g. `tenjin edit <id> --body post.md`.",
|
|
533
|
+
cause: err
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
const { frontmatter, body } = parseFrontmatter(raw);
|
|
537
|
+
return { raw, body, hadFrontmatter: Object.keys(frontmatter).length > 0 };
|
|
538
|
+
}
|
|
539
|
+
function storedList(post, key) {
|
|
540
|
+
return post.resource?.[key] ?? [];
|
|
541
|
+
}
|
|
542
|
+
function appendUnique(stored, additions) {
|
|
543
|
+
const out = [...stored];
|
|
544
|
+
for (const item of additions) {
|
|
545
|
+
if (!out.includes(item)) out.push(item);
|
|
546
|
+
}
|
|
547
|
+
return out;
|
|
548
|
+
}
|
|
549
|
+
function shippedTypedText(args, input) {
|
|
550
|
+
const parts = [];
|
|
551
|
+
const add = (v) => {
|
|
552
|
+
if (v !== void 0) parts.push(v);
|
|
553
|
+
};
|
|
554
|
+
if (input.title !== void 0) add(args.title);
|
|
555
|
+
if (input.excerpt !== void 0) add(args.excerpt);
|
|
556
|
+
const card = input.resource;
|
|
557
|
+
if (card === void 0) return parts.join("\n");
|
|
558
|
+
if (card.scope !== void 0) add(args.scope);
|
|
559
|
+
if (card.exclusions !== void 0) add(args.exclusions);
|
|
560
|
+
if (card.provenanceSummary !== void 0) add(args.provenance);
|
|
561
|
+
if (card.methodologySummary !== void 0) add(args.methodology);
|
|
562
|
+
if (card.asOf !== void 0) add(args.asOf);
|
|
563
|
+
if (card.validUntil !== void 0) add(args.validUntil);
|
|
564
|
+
if (card.questionsAnswered !== void 0) {
|
|
565
|
+
for (const item of args.question ?? args.addQuestion ?? []) add(item);
|
|
566
|
+
}
|
|
567
|
+
if (card.tasksSupported !== void 0) {
|
|
568
|
+
for (const item of args.task ?? args.addTask ?? []) add(item);
|
|
569
|
+
}
|
|
570
|
+
if (card.appliesTo !== void 0 && args.appliesTo !== void 0) {
|
|
571
|
+
for (const values of Object.values(parseAppliesToFlags(args.appliesTo))) parts.push(...values);
|
|
572
|
+
}
|
|
573
|
+
return parts.join("\n");
|
|
574
|
+
}
|
|
575
|
+
function blockMessage(blocking) {
|
|
576
|
+
return `Edit blocked: the new content contains ${describeFindings(blocking)}.`;
|
|
577
|
+
}
|
|
578
|
+
function confirmMessage(warnCount, changeCount) {
|
|
579
|
+
return warnCount > 0 ? `Edit needs confirmation: ${changeCount} change(s), ${warnCount} finding(s).` : `Edit needs confirmation: ${changeCount} change(s).`;
|
|
580
|
+
}
|
|
581
|
+
var PREVIEW_MAX = 60;
|
|
582
|
+
var LINE_MAX = 200;
|
|
583
|
+
function clip(value, max = PREVIEW_MAX) {
|
|
584
|
+
const clean = sanitizeForTerminal(value).replace(/\s+/g, " ").trim();
|
|
585
|
+
return clean.length > max ? `${clean.slice(0, max)}\u2026` : clean;
|
|
586
|
+
}
|
|
587
|
+
function preview(value) {
|
|
588
|
+
if (value === void 0 || value === null || value.length === 0) return "(unset)";
|
|
589
|
+
const clean = sanitizeForTerminal(value).replace(/\s+/g, " ").trim();
|
|
590
|
+
if (clean.length === 0) return "(unset)";
|
|
591
|
+
return clean.length > PREVIEW_MAX ? `${JSON.stringify(clean.slice(0, PREVIEW_MAX))}\u2026` : JSON.stringify(clean);
|
|
592
|
+
}
|
|
593
|
+
function previewList(values) {
|
|
594
|
+
return values.map((v) => preview(v)).join(", ");
|
|
595
|
+
}
|
|
596
|
+
function appliesToPreview(appliesTo) {
|
|
597
|
+
const entries = Object.entries(appliesTo);
|
|
598
|
+
if (entries.length === 0) return "(unset)";
|
|
599
|
+
const rendered = entries.map(([key, values]) => `${clip(key)}=${values.map((v) => clip(v)).join("|")}`).join(", ");
|
|
600
|
+
return clip(rendered, LINE_MAX);
|
|
601
|
+
}
|
|
602
|
+
function sameList(a, b) {
|
|
603
|
+
return a.length === b.length && a.every((v, i) => v === b[i]);
|
|
604
|
+
}
|
|
605
|
+
function hasText(value) {
|
|
606
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
export {
|
|
610
|
+
runEdit
|
|
611
|
+
};
|
|
612
|
+
//# sourceMappingURL=chunk-BUDHTDKL.js.map
|