tenjin-cli 0.1.0-alpha.15 → 0.1.0-alpha.17
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 +54 -7
- package/README.md +43 -310
- package/dist/{_esm-N4KAVXQR.js → _esm-CE7KNONL.js} +9 -10
- package/dist/{ccip-ZGGWQN4X.js → ccip-7RMRLAGV.js} +4 -4
- package/dist/{ccip-RPPPKTJR.js → ccip-NLCSCHKI.js} +5 -5
- package/dist/chunk-2BKS2FVE.js +93 -0
- package/dist/chunk-2BKS2FVE.js.map +1 -0
- package/dist/chunk-2G2WLVHB.js +102 -0
- package/dist/chunk-2G2WLVHB.js.map +1 -0
- package/dist/chunk-2I4QTOLB.js +11 -0
- package/dist/chunk-2I4QTOLB.js.map +1 -0
- package/dist/chunk-2JGT3KDW.js +172 -0
- package/dist/chunk-2JGT3KDW.js.map +1 -0
- package/dist/chunk-2QYORQBF.js +55 -0
- package/dist/chunk-2QYORQBF.js.map +1 -0
- package/dist/chunk-35M3VITA.js +102 -0
- package/dist/chunk-35M3VITA.js.map +1 -0
- package/dist/{chunk-KINZ23CV.js → chunk-3AUDA53C.js} +4740 -23
- package/dist/chunk-3AUDA53C.js.map +1 -0
- package/dist/{chunk-MJZZTKCC.js → chunk-56MOAIP5.js} +5 -10
- package/dist/chunk-56MOAIP5.js.map +1 -0
- package/dist/{chunk-U5S527PP.js → chunk-5IEP5EGE.js} +3 -3
- package/dist/chunk-5QHHRMRA.js +227 -0
- package/dist/chunk-5QHHRMRA.js.map +1 -0
- package/dist/{chunk-JBIKAAT3.js → chunk-5UDD5VSY.js} +8 -8
- package/dist/chunk-5UDD5VSY.js.map +1 -0
- package/dist/chunk-7QKHZQKW.js +1680 -0
- package/dist/chunk-7QKHZQKW.js.map +1 -0
- package/dist/{chunk-ZFJJ3EXC.js → chunk-AR7U7BRG.js} +550 -182
- package/dist/chunk-AR7U7BRG.js.map +1 -0
- package/dist/chunk-AUKDYPPX.js +130 -0
- package/dist/chunk-AUKDYPPX.js.map +1 -0
- package/dist/{chunk-7FK2UN2T.js → chunk-AWQPGIR6.js} +65 -67
- package/dist/{chunk-7FK2UN2T.js.map → chunk-AWQPGIR6.js.map} +1 -1
- package/dist/{chunk-KYQVEKP5.js → chunk-BPMWXTFX.js} +8 -8
- package/dist/{chunk-47PP7TAG.js → chunk-EGELTSPU.js} +1356 -1356
- package/dist/chunk-EGELTSPU.js.map +1 -0
- package/dist/{chunk-S5RYMCV6.js → chunk-HPWO4O6S.js} +3 -3
- package/dist/chunk-J5INH7WB.js +299 -0
- package/dist/chunk-J5INH7WB.js.map +1 -0
- package/dist/chunk-JLEF5WHM.js +132 -0
- package/dist/chunk-JLEF5WHM.js.map +1 -0
- package/dist/{chunk-W6R3HAAG.js → chunk-JRGFKVAZ.js} +2 -2
- package/dist/{chunk-XJN5WUKL.js → chunk-KG3D7FIF.js} +2 -2
- package/dist/chunk-KK4YGYTV.js +808 -0
- package/dist/chunk-KK4YGYTV.js.map +1 -0
- package/dist/{chunk-CPCX67TI.js → chunk-KUBEYXSO.js} +1076 -1038
- package/dist/chunk-KUBEYXSO.js.map +1 -0
- package/dist/{chunk-QW2Q2KAH.js → chunk-LHHMV4GU.js} +2 -2
- package/dist/{chunk-NIKXHWOL.js → chunk-LJ4DMVFI.js} +16 -16
- package/dist/chunk-LJ4DMVFI.js.map +1 -0
- package/dist/{chunk-ZOBNS7CX.js → chunk-MEFB5KHA.js} +4 -18
- package/dist/chunk-MEFB5KHA.js.map +1 -0
- package/dist/{chunk-HPJGOLTN.js → chunk-MRGADYDD.js} +13 -8
- package/dist/chunk-MRGADYDD.js.map +1 -0
- package/dist/{chunk-M2O56UK7.js → chunk-N35E6CM2.js} +293 -163
- package/dist/chunk-N35E6CM2.js.map +1 -0
- package/dist/chunk-O4ZNKFRU.js +366 -0
- package/dist/chunk-O4ZNKFRU.js.map +1 -0
- package/dist/chunk-PDA2BVFY.js +244 -0
- package/dist/chunk-PDA2BVFY.js.map +1 -0
- package/dist/{chunk-POJRB2AE.js → chunk-POUWHWID.js} +2 -2
- package/dist/chunk-QDD2RN7G.js +10238 -0
- package/dist/chunk-QDD2RN7G.js.map +1 -0
- package/dist/chunk-S2NRVRPF.js +171 -0
- package/dist/chunk-S2NRVRPF.js.map +1 -0
- package/dist/chunk-TGLKKLQG.js +11 -0
- package/dist/chunk-TGLKKLQG.js.map +1 -0
- package/dist/chunk-TP4D47BY.js +127 -0
- package/dist/chunk-TP4D47BY.js.map +1 -0
- package/dist/{chunk-KZAAWQNP.js → chunk-TTNESUPQ.js} +3 -3
- package/dist/{chunk-UO22YNY4.js → chunk-U2DZISAH.js} +43 -1
- package/dist/chunk-U2DZISAH.js.map +1 -0
- package/dist/chunk-WGQVJM56.js +165 -0
- package/dist/chunk-WGQVJM56.js.map +1 -0
- package/dist/{chunk-OLWTRUTS.js → chunk-WLMJE3GJ.js} +35 -16
- package/dist/chunk-WLMJE3GJ.js.map +1 -0
- package/dist/chunk-WS4JA6TC.js +137 -0
- package/dist/chunk-WS4JA6TC.js.map +1 -0
- package/dist/chunk-WXC57XGG.js +29 -0
- package/dist/chunk-WXC57XGG.js.map +1 -0
- package/dist/{chunk-YLYINX2H.js → chunk-XZKD7DIF.js} +3 -3
- package/dist/chunk-XZOEUYMX.js +1784 -0
- package/dist/chunk-XZOEUYMX.js.map +1 -0
- package/dist/{cli-KKRKBU5T.js → cli-VHYYYYXM.js} +303 -374
- package/dist/cli-VHYYYYXM.js.map +1 -0
- package/dist/config-5ADBAAXU.js +42 -0
- package/dist/{dist-U4M6QCKE.js → dist-3LOO6M4U.js} +10 -10
- package/dist/doctor-Q35VQW3S.js +436 -0
- package/dist/doctor-Q35VQW3S.js.map +1 -0
- package/dist/{ethersCompat-Df4a6QIZ-WHYKB6HA.js → ethersCompat-Df4a6QIZ-THAVUGIJ.js} +5 -5
- package/dist/{chunk-KAJZHIQ4.js → fund-GDDPL2BB.js} +81 -24
- package/dist/fund-GDDPL2BB.js.map +1 -0
- package/dist/hook-command-PBERPRE3.js +763 -0
- package/dist/hook-command-PBERPRE3.js.map +1 -0
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/install-OKDKGUXM.js +60 -0
- package/dist/install-wallet-SI4LZ73K.js +106 -0
- package/dist/install-wallet-SI4LZ73K.js.map +1 -0
- package/dist/{run-XYTQ5TWQ.js → mcp-XX3WRQEZ.js} +3766 -10677
- package/dist/mcp-XX3WRQEZ.js.map +1 -0
- package/dist/paths-P2N4JTDZ.js +49 -0
- package/dist/pay-3SYKHKWJ.js +39 -0
- package/dist/redact-6W23GGJC.js +15 -0
- package/dist/{secp256k1-XRPVBC6V.js → secp256k1-ZZZT2CAX.js} +3 -3
- package/dist/{send-G746D7PQ.js → send-LQRKTEJT.js} +29 -29
- package/dist/send-LQRKTEJT.js.map +1 -0
- package/dist/{chunk-QZ6ROAJU.js → skill-placement-JMDPSKE6.js} +155 -10
- package/dist/skill-placement-JMDPSKE6.js.map +1 -0
- package/dist/status-FFC6FO72.js +64 -0
- package/dist/status-FFC6FO72.js.map +1 -0
- package/dist/status-line-SAXSU6CR.js +87 -0
- package/dist/status-line-SAXSU6CR.js.map +1 -0
- package/dist/status-line-wiring-L2WYIYBM.js +29 -0
- package/dist/tenjin-daemon.mjs +20421 -0
- package/dist/tenjin-shim.mjs +251 -0
- package/dist/tenjin-vitest-reporter.mjs +49 -0
- package/dist/uninstall-OACH27UV.js +147 -0
- package/dist/uninstall-OACH27UV.js.map +1 -0
- package/dist/{update-R76LHOZW.js → update-4W6EKLGZ.js} +132 -16
- package/dist/update-4W6EKLGZ.js.map +1 -0
- package/dist/{viemAdapter-By13KInL-TUQJBMHM.js → viemAdapter-By13KInL-X2VY6CY3.js} +5 -5
- package/dist/wallet-BMEXRR3P.js +32 -0
- package/dist/wallet-kdf-worker.mjs +980 -0
- package/docs/agent-permissions.md +71 -352
- package/docs/safety-model.md +16 -6
- package/package.json +8 -7
- package/LICENSE +0 -21
- package/dist/buy-VIRNSYGN.js +0 -47
- package/dist/chunk-2MYQN7HM.js +0 -247
- package/dist/chunk-2MYQN7HM.js.map +0 -1
- package/dist/chunk-2RF2GIJQ.js +0 -1188
- package/dist/chunk-2RF2GIJQ.js.map +0 -1
- package/dist/chunk-3GL2Z5QK.js +0 -57
- package/dist/chunk-3GL2Z5QK.js.map +0 -1
- package/dist/chunk-47PP7TAG.js.map +0 -1
- package/dist/chunk-4CQIDQOT.js +0 -167
- package/dist/chunk-4CQIDQOT.js.map +0 -1
- package/dist/chunk-4KG27W2S.js +0 -614
- package/dist/chunk-4KG27W2S.js.map +0 -1
- package/dist/chunk-5QQTYWEU.js +0 -199
- package/dist/chunk-5QQTYWEU.js.map +0 -1
- package/dist/chunk-65DTCCJ7.js +0 -21
- package/dist/chunk-65DTCCJ7.js.map +0 -1
- package/dist/chunk-A5DKHMUN.js +0 -173
- package/dist/chunk-A5DKHMUN.js.map +0 -1
- package/dist/chunk-B63XPWQ4.js +0 -246
- package/dist/chunk-B63XPWQ4.js.map +0 -1
- package/dist/chunk-CAR6FHK6.js +0 -105
- package/dist/chunk-CAR6FHK6.js.map +0 -1
- package/dist/chunk-CPCX67TI.js.map +0 -1
- package/dist/chunk-CQBVCYI2.js +0 -162
- package/dist/chunk-CQBVCYI2.js.map +0 -1
- package/dist/chunk-DBU5CXBV.js +0 -4731
- package/dist/chunk-DBU5CXBV.js.map +0 -1
- package/dist/chunk-DHJD77OW.js +0 -81
- package/dist/chunk-DHJD77OW.js.map +0 -1
- package/dist/chunk-EDZSNPE5.js +0 -35
- package/dist/chunk-EDZSNPE5.js.map +0 -1
- package/dist/chunk-EFWZPUTC.js +0 -65
- package/dist/chunk-EFWZPUTC.js.map +0 -1
- package/dist/chunk-EPFL6CTE.js +0 -448
- package/dist/chunk-EPFL6CTE.js.map +0 -1
- package/dist/chunk-GHLVXVZD.js +0 -142
- package/dist/chunk-GHLVXVZD.js.map +0 -1
- package/dist/chunk-H3SOOJ2I.js +0 -580
- package/dist/chunk-H3SOOJ2I.js.map +0 -1
- package/dist/chunk-HPJGOLTN.js.map +0 -1
- package/dist/chunk-HRGBS2PA.js +0 -203
- package/dist/chunk-HRGBS2PA.js.map +0 -1
- package/dist/chunk-ITUXPJIS.js +0 -314
- package/dist/chunk-ITUXPJIS.js.map +0 -1
- package/dist/chunk-JBIKAAT3.js.map +0 -1
- package/dist/chunk-KAJZHIQ4.js.map +0 -1
- package/dist/chunk-KINZ23CV.js.map +0 -1
- package/dist/chunk-LRYV3SK7.js +0 -235
- package/dist/chunk-LRYV3SK7.js.map +0 -1
- package/dist/chunk-M2O56UK7.js.map +0 -1
- package/dist/chunk-MJZZTKCC.js.map +0 -1
- package/dist/chunk-NIKXHWOL.js.map +0 -1
- package/dist/chunk-OKDRDT74.js +0 -209
- package/dist/chunk-OKDRDT74.js.map +0 -1
- package/dist/chunk-OKYSNAS3.js +0 -2144
- package/dist/chunk-OKYSNAS3.js.map +0 -1
- package/dist/chunk-OLWTRUTS.js.map +0 -1
- package/dist/chunk-QQ6ELLSA.js +0 -143
- package/dist/chunk-QQ6ELLSA.js.map +0 -1
- package/dist/chunk-QZ6ROAJU.js.map +0 -1
- package/dist/chunk-R7RSCBI7.js +0 -794
- package/dist/chunk-R7RSCBI7.js.map +0 -1
- package/dist/chunk-SGK2B724.js +0 -67
- package/dist/chunk-SGK2B724.js.map +0 -1
- package/dist/chunk-U6VPKMGC.js +0 -390
- package/dist/chunk-U6VPKMGC.js.map +0 -1
- package/dist/chunk-UHTVXQ2O.js +0 -140
- package/dist/chunk-UHTVXQ2O.js.map +0 -1
- package/dist/chunk-UO22YNY4.js.map +0 -1
- package/dist/chunk-US456VUI.js +0 -149
- package/dist/chunk-US456VUI.js.map +0 -1
- package/dist/chunk-V44J2MXV.js +0 -400
- package/dist/chunk-V44J2MXV.js.map +0 -1
- package/dist/chunk-VJQKL3YH.js +0 -216
- package/dist/chunk-VJQKL3YH.js.map +0 -1
- package/dist/chunk-VJSQSLBM.js +0 -1442
- package/dist/chunk-VJSQSLBM.js.map +0 -1
- package/dist/chunk-VYOJOX4Z.js +0 -165
- package/dist/chunk-VYOJOX4Z.js.map +0 -1
- package/dist/chunk-WY2K35OL.js +0 -269
- package/dist/chunk-WY2K35OL.js.map +0 -1
- package/dist/chunk-ZFJJ3EXC.js.map +0 -1
- package/dist/chunk-ZOBNS7CX.js.map +0 -1
- package/dist/cli-KKRKBU5T.js.map +0 -1
- package/dist/config-JMRUNYE6.js +0 -37
- package/dist/discover-B5HF6SHM.js +0 -102
- package/dist/discover-B5HF6SHM.js.map +0 -1
- package/dist/doctor-ZBG7X66D.js +0 -32
- package/dist/edit-PZJIILQE.js +0 -40
- package/dist/fund-EUDH5KPA.js +0 -40
- package/dist/inspect-QC6WEQPN.js +0 -37
- package/dist/install-GNK2W3PI.js +0 -972
- package/dist/install-GNK2W3PI.js.map +0 -1
- package/dist/outcome-KSGWZHUS.js +0 -24
- package/dist/pay-BC4UICPA.js +0 -361
- package/dist/pay-BC4UICPA.js.map +0 -1
- package/dist/publish-LXWFDIKF.js +0 -42
- package/dist/read-JMNUQ56P.js +0 -160
- package/dist/read-JMNUQ56P.js.map +0 -1
- package/dist/run-XYTQ5TWQ.js.map +0 -1
- package/dist/search-TSQAB45E.js +0 -25
- package/dist/secp256k1-XRPVBC6V.js.map +0 -1
- package/dist/send-G746D7PQ.js.map +0 -1
- package/dist/session-JBKWMJ24.js +0 -89
- package/dist/session-JBKWMJ24.js.map +0 -1
- package/dist/skill-heal-WKD67SLJ.js +0 -92
- package/dist/skill-heal-WKD67SLJ.js.map +0 -1
- package/dist/skill-placement-RIU4AMC2.js +0 -20
- package/dist/skill-placement-RIU4AMC2.js.map +0 -1
- package/dist/uninstall-5E263VTS.js +0 -73
- package/dist/uninstall-5E263VTS.js.map +0 -1
- package/dist/update-R76LHOZW.js.map +0 -1
- package/dist/usdc-4VCDHFWX.js +0 -38
- package/dist/usdc-4VCDHFWX.js.map +0 -1
- package/dist/viemAdapter-By13KInL-TUQJBMHM.js.map +0 -1
- package/dist/wallet-TQ7D5EQ7.js +0 -41
- package/dist/wallet-TQ7D5EQ7.js.map +0 -1
- package/dist/wallet-ZAVXWLWP.js +0 -32
- package/dist/wallet-ZAVXWLWP.js.map +0 -1
- package/docs/command-reference.md +0 -303
- package/skills/tenjin/SKILL.md +0 -373
- package/skills/tenjin-pay/SKILL.md +0 -76
- package/skills/tenjin-publish/SKILL.md +0 -227
- package/skills/tenjin-publish/references/maintain.md +0 -39
- package/skills/tenjin-search/SKILL.md +0 -154
- package/skills/tenjin-search/references/permissions.md +0 -112
- /package/dist/{_esm-N4KAVXQR.js.map → _esm-CE7KNONL.js.map} +0 -0
- /package/dist/{buy-VIRNSYGN.js.map → ccip-7RMRLAGV.js.map} +0 -0
- /package/dist/{ccip-RPPPKTJR.js.map → ccip-NLCSCHKI.js.map} +0 -0
- /package/dist/{chunk-U5S527PP.js.map → chunk-5IEP5EGE.js.map} +0 -0
- /package/dist/{chunk-KYQVEKP5.js.map → chunk-BPMWXTFX.js.map} +0 -0
- /package/dist/{chunk-S5RYMCV6.js.map → chunk-HPWO4O6S.js.map} +0 -0
- /package/dist/{chunk-W6R3HAAG.js.map → chunk-JRGFKVAZ.js.map} +0 -0
- /package/dist/{chunk-XJN5WUKL.js.map → chunk-KG3D7FIF.js.map} +0 -0
- /package/dist/{chunk-QW2Q2KAH.js.map → chunk-LHHMV4GU.js.map} +0 -0
- /package/dist/{chunk-POJRB2AE.js.map → chunk-POUWHWID.js.map} +0 -0
- /package/dist/{chunk-KZAAWQNP.js.map → chunk-TTNESUPQ.js.map} +0 -0
- /package/dist/{chunk-YLYINX2H.js.map → chunk-XZKD7DIF.js.map} +0 -0
- /package/dist/{ccip-ZGGWQN4X.js.map → config-5ADBAAXU.js.map} +0 -0
- /package/dist/{dist-U4M6QCKE.js.map → dist-3LOO6M4U.js.map} +0 -0
- /package/dist/{config-JMRUNYE6.js.map → ethersCompat-Df4a6QIZ-THAVUGIJ.js.map} +0 -0
- /package/dist/{doctor-ZBG7X66D.js.map → install-OKDKGUXM.js.map} +0 -0
- /package/dist/{edit-PZJIILQE.js.map → paths-P2N4JTDZ.js.map} +0 -0
- /package/dist/{ethersCompat-Df4a6QIZ-WHYKB6HA.js.map → pay-3SYKHKWJ.js.map} +0 -0
- /package/dist/{fund-EUDH5KPA.js.map → redact-6W23GGJC.js.map} +0 -0
- /package/dist/{inspect-QC6WEQPN.js.map → secp256k1-ZZZT2CAX.js.map} +0 -0
- /package/dist/{outcome-KSGWZHUS.js.map → status-line-wiring-L2WYIYBM.js.map} +0 -0
- /package/dist/{publish-LXWFDIKF.js.map → viemAdapter-By13KInL-X2VY6CY3.js.map} +0 -0
- /package/dist/{search-TSQAB45E.js.map → wallet-BMEXRR3P.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/config.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { z } from 'zod';\nimport { CliError } from './errors';\nimport { PRODUCTION_ORIGIN } from './production-origin';\nimport { configPath } from './paths';\nimport { HARNESS_TARGETS } from './skill-wiring';\nimport { writeFileAtomic } from './atomic-json';\n\n/** A non-negative integer string in USDC atomic units (6-decimal base). */\nconst atomicString = z.string().regex(/^\\d+$/, 'expected an atomic USDC integer string');\n\n/** The publish consent mode (B3, D38). `full-auto` is loosening-gated, below. */\nexport const PublishModeSchema = z.enum(['review', 'auto', 'full-auto']);\nexport type PublishMode = z.infer<typeof PublishModeSchema>;\n\n/**\n * Validate a publish-mode value at a command edge (`--mode`, `--publish-mode`):\n * an unrecognized value is USAGE (exit 2), never silently dropped. `flagName` is\n * woven into the message so the failing flag is named.\n */\nexport function parsePublishModeFlag(value: string, flagName: string): PublishMode {\n const parsed = PublishModeSchema.safeParse(value);\n if (parsed.success) return parsed.data;\n throw new CliError('USAGE', `Invalid ${flagName} ${JSON.stringify(value)}`, {\n fix: 'Use \"review\", \"auto\", or \"full-auto\".',\n });\n}\n\n/**\n * The publish block (B3): `mode` governs the confirm cascade a `publish` runs,\n * `defaultPrice` is the atomic USDC price a card is published at when no\n * per-publish price is given. Stored atomic like the spend keys.\n */\nconst PublishConfigSchema = z.object({\n mode: PublishModeSchema,\n defaultPrice: atomicString,\n});\n\n/**\n * What the harness WebSearch hook does when the agent is about to search the web\n * (see lib/hook-scripts.ts). `auto` asks Tenjin first and mentions a tested\n * answer when one exists, `remind` says the marketplace is there without sending\n * the query anywhere, `off` leaves the installed hook inert.\n */\nexport const WebSearchModeSchema = z.enum(['auto', 'remind', 'off']);\nexport type WebSearchMode = z.infer<typeof WebSearchModeSchema>;\n\n/**\n * What the subagent-dispatch hook does, on its own switch. Disjoint from\n * `hooks.webSearch`: both default `auto`, no `inherit`. The split exists because\n * a dispatch prompt is the most sensitive payload any hook sees: a fleet can keep\n * `webSearch auto` and still run dispatch as `remind` (a local nudge, nothing\n * sent) or `off`.\n */\nexport const AgentDispatchModeSchema = z.enum(['auto', 'remind', 'off']);\nexport type AgentDispatchMode = z.infer<typeof AgentDispatchModeSchema>;\n\n// Backward compat aliases — old keys still parse, new code uses the WebSearch/AgentDispatch names.\nexport const SearchHookModeSchema = WebSearchModeSchema;\nexport type SearchHookMode = WebSearchMode;\n/** Legacy: accepted on read for old config files that stored `inherit`. */\nexport const DispatchHookModeSchema = z.enum(['inherit', 'auto', 'remind', 'off']);\nexport type DispatchHookMode = z.infer<typeof DispatchHookModeSchema>;\n\n/** Validate a dispatch-hook mode at a command edge for the new disjoint key. */\nexport function parseAgentDispatchHookModeFlag(value: string, flagName: string): AgentDispatchMode {\n const parsed = AgentDispatchModeSchema.safeParse(value);\n if (parsed.success) return parsed.data;\n throw new CliError('USAGE', `Invalid ${flagName} ${JSON.stringify(value)}`, {\n fix: 'Use \"auto\", \"remind\", or \"off\".',\n });\n}\n\n/** Validate a web-search hook mode at a command edge. */\nexport function parseWebSearchHookModeFlag(value: string, flagName: string): WebSearchMode {\n const parsed = WebSearchModeSchema.safeParse(value);\n if (parsed.success) return parsed.data;\n throw new CliError('USAGE', `Invalid ${flagName} ${JSON.stringify(value)}`, {\n fix: 'Use \"auto\", \"remind\", or \"off\".',\n });\n}\n\n/** @deprecated use parseAgentDispatchHookModeFlag — kept for `hooks.dispatchMode` alias */\nexport function parseDispatchHookModeFlag(value: string, flagName: string): DispatchHookMode {\n const parsed = DispatchHookModeSchema.safeParse(value);\n if (parsed.success) return parsed.data;\n throw new CliError('USAGE', `Invalid ${flagName} ${JSON.stringify(value)}`, {\n fix: 'Use \"inherit\", \"auto\", \"remind\", or \"off\".',\n });\n}\n\n/**\n * @deprecated use parseWebSearchHookModeFlag — kept for `hooks.searchMode` alias\n */\nexport function parseSearchHookModeFlag(value: string, flagName: string): SearchHookMode {\n return parseWebSearchHookModeFlag(value, flagName);\n}\n\n/**\n * Which open loops the Stop hook may raise at the end of a turn.\n *\n * `deliberate-only` is the middle setting the two-value toggle was missing. The\n * hook has two arms, and they are not equally welcome: a deliberate `tenjin\n * search` MISS is a question the agent chose to ask, while the batched\n * ride-along web searches are a firehose in a research session. With only `on`\n * and `off`, silencing the noisy arm meant silencing both, and nothing ever\n * prompts turning them back on (tenjin-agent #162). This keeps the high-signal\n * arm and drops the batch.\n */\nexport const StopNagModeSchema = z.enum(['on', 'deliberate-only', 'off']);\nexport type StopNagMode = z.infer<typeof StopNagModeSchema>;\n\nexport function parseStopNagFlag(value: string, flagName: string): StopNagMode {\n const parsed = StopNagModeSchema.safeParse(value);\n if (parsed.success) return parsed.data;\n throw new CliError('USAGE', `Invalid ${flagName} ${JSON.stringify(value)}`, {\n fix: 'Use \"on\", \"deliberate-only\", or \"off\".',\n });\n}\n\n/** Whether the SessionStart hook prints its primer. Two values and no middle\n * one: one paragraph either belongs at the top of a session or does not. */\nexport const SessionPrimerModeSchema = z.enum(['on', 'off']);\nexport type SessionPrimerMode = z.infer<typeof SessionPrimerModeSchema>;\n\nexport function parseSessionPrimerFlag(value: string, flagName: string): SessionPrimerMode {\n const parsed = SessionPrimerModeSchema.safeParse(value);\n if (parsed.success) return parsed.data;\n throw new CliError('USAGE', `Invalid ${flagName} ${JSON.stringify(value)}`, {\n fix: 'Use \"on\" or \"off\".',\n });\n}\n\n/**\n * The harness-hook block. EVERY key is read by the installed scripts at run\n * time, which is what makes them runtime toggles rather than install-time\n * choices: `tenjin config set hooks.webSearch off`, `hooks.agentDispatch off`,\n * `hooks.stopNag off` or `hooks.sessionPrimer off` silences a hook immediately,\n * with no re-install and nothing to unwire. The scripts stay registered and\n * no-op, which is also what lets turning one back on be a single `config set`.\n */\nconst HooksConfigSchema = z.object({\n webSearch: WebSearchModeSchema,\n agentDispatch: AgentDispatchModeSchema,\n stopNag: StopNagModeSchema,\n sessionPrimer: SessionPrimerModeSchema,\n});\n\n/**\n * Legacy hook fields kept for one release so an old config.json still parses.\n * `searchMode` maps to `webSearch`; `dispatchMode` (including `inherit`) maps\n * to `agentDispatch` per the migration in loadConfig / resolve* below.\n */\nconst LegacyHooksFields = z.object({\n searchMode: SearchHookModeSchema.optional(),\n dispatchMode: DispatchHookModeSchema.optional(),\n});\n\n/**\n * What the daily update check is allowed to do about a newer version.\n *\n * `nudge` reports it — one dim line for a human at a terminal, and an\n * `updateAvailable` field on the JSON envelope for everyone else, which is how\n * an agent learns to run `tenjin update` itself. `off` reports neither and stops\n * asking npm entirely.\n *\n * There is deliberately no mode that installs on its own. Replacing the binary\n * under a running agent has no safe moment in a CLI that starts a fresh process\n * per invocation: \"next start\" IS \"mid-session\". Reporting is the part that was\n * missing, so reporting is what this key controls.\n */\nexport const UpdateModeSchema = z.enum(['nudge', 'off']);\nexport type UpdateMode = z.infer<typeof UpdateModeSchema>;\n\nconst UpdateConfigSchema = z.object({\n mode: UpdateModeSchema,\n});\n\nexport function parseUpdateModeFlag(value: string, flagName: string): UpdateMode {\n const parsed = UpdateModeSchema.safeParse(value);\n if (parsed.success) return parsed.data;\n throw new CliError('USAGE', `Invalid ${flagName} ${JSON.stringify(value)}`, {\n fix: 'Use \"nudge\" or \"off\".',\n });\n}\n\n/**\n * What `install` recorded about its OWN targets. `harness` is the explicit\n * `--harness` set of the last install that passed the flag, and it exists so\n * `doctor` keeps judging a directory the user named by hand: detection cannot see a\n * harness this CLI does not probe for, and without the record such a directory is a\n * target for one run and invisible to every later check. Written by `install`, not a\n * `config set` key.\n */\nconst InstallConfigSchema = z.object({\n harness: z.array(z.enum(HARNESS_TARGETS)),\n});\n\n/**\n * The persisted config shape. Spend keys are stored atomic (accepted as decimal\n * USD at the command edge, see lib/money); `confirm` is the stored form\n * \"always\" | \"above:<atomic>\". These are client-enforced guardrails, not a\n * security boundary — any process that runs the CLI can also edit this file.\n */\nexport const ConfigSchema = z.object({\n maxAutoSpend: atomicString,\n sessionBudget: atomicString,\n confirm: z.union([z.literal('always'), z.string().regex(/^above:\\d+$/)]),\n /**\n * Hard per-send cap for `tenjin send`, NOT satisfiable by --yes or a prompt\n * (the spend-policy posture): an atomic amount caps each send, \"0\" disables\n * the verb entirely, and \"none\" = explicitly uncapped (send exists to drain\n * the wallet, but uncapped is an opt-in, never a default). The key has NO\n * usable default: absent from config.json, `tenjin send` refuses until it is\n * set (see resolveSendMaxAmount). Client-enforced like every spend key (see\n * the note above).\n */\n sendMaxAmount: z.union([z.literal('none'), atomicString]),\n allowlistCreators: z.array(z.string()),\n baseUrl: z.url(),\n rpcUrl: z.url(),\n /**\n * Evaluation-cohort opt-in (spec 09 §3): when true, search sends\n * X-Tenjin-Eval-Cohort: 1 and the server stores the generalized question for\n * 90 days. Off by default; no query text is retained server-side without it.\n */\n evalCohort: z.boolean(),\n /**\n * The Bazaar pay lane opt-in: when true, `tenjin pay` may pay a NON-Tenjin\n * x402 endpoint, provided a configured registry lists that exact resource and\n * the live 402 matches the listed deal. Off by default; `install` asks once.\n * The lane's teaching is the OPTIONAL tenjin-pay skill, present on disk\n * exactly while this is on (lib/skill-placement).\n */\n bazaarPay: z.boolean(),\n /** x402 discovery registries (facilitator base URLs) `discover` queries and\n * the Bazaar pay lane verifies against. */\n bazaarRegistries: z.array(z.url()),\n publish: PublishConfigSchema,\n install: InstallConfigSchema,\n hooks: HooksConfigSchema,\n update: UpdateConfigSchema,\n});\nexport type Config = z.infer<typeof ConfigSchema>;\n\n/**\n * Values as they may appear in config.json — every known key optional; absent =\n * default. `.passthrough()` PRESERVES unknown keys through load + persist: without\n * it an older binary's `config set` would strip (and re-serialize away) any newer\n * block a later CLI wrote, e.g. B3's `publish.*`. Known keys are still validated;\n * unknown keys ride along untouched.\n */\nexport const RawConfigSchema = ConfigSchema.partial()\n // The publish block is itself partial + passthrough: `config set publish.mode`\n // writes only the one subkey, and a subkey a newer CLI adds (e.g. publish.*\n // beyond mode/defaultPrice) survives an older binary's set, same reason the\n // outer object passes unknown keys through.\n .extend({\n publish: PublishConfigSchema.partial().passthrough().optional(),\n install: InstallConfigSchema.partial().passthrough().optional(),\n hooks: HooksConfigSchema.partial().merge(LegacyHooksFields).passthrough().optional(),\n update: UpdateConfigSchema.partial().passthrough().optional(),\n })\n .passthrough();\nexport type PartialConfig = z.infer<typeof RawConfigSchema>;\n\n/**\n * The resolved-view sentinel for an absent sendMaxAmount. Never a persistable\n * value (ConfigSchema rejects it, and `config set` has no way to produce it);\n * while the resolved value is this sentinel, `tenjin send` refuses —\n * require-set-before-first-send.\n */\nexport const SEND_MAX_UNSET = 'unset';\n\n/**\n * Registries verified keyless (CDP/UV on 2026-08-14, PayAI on 2026-08-18): all\n * answer GET /discovery/resources with no credential in the Bazaar envelope\n * the sweep parses. CDP's Bazaar is settlement-derived (it indexes what its\n * facilitator settles, Tenjin's endpoints included); UltraVioleta is the\n * registry Tenjin also announces to; PayAI's facilitator is settlement-derived\n * like CDP's (26k+ listings at verification). PayAI has no /discovery/search\n * and ignores payTo filters, the same shapes UV and CDP already exhibit, which\n * the query sweep's per-registry errors and the stored-sweep evidence cover.\n */\nexport const DEFAULT_BAZAAR_REGISTRIES = [\n 'https://api.cdp.coinbase.com/platform/v2/x402',\n 'https://facilitator.ultravioletadao.xyz',\n 'https://facilitator.payai.network',\n];\n\nexport const CONFIG_DEFAULTS: Config = {\n maxAutoSpend: '0',\n sessionBudget: '0',\n confirm: 'always',\n // A type placeholder only, never honored: Config requires every key (and\n // CONFIG_KEYS derives from these). resolveSendMaxAmount never reads it — an\n // absent key resolves to SEND_MAX_UNSET and `tenjin send` refuses until the\n // cap is set. '0' (send disabled) rather than 'none' (uncapped) so that if a\n // future caller ever DOES read the cap through loadConfig/fileOrDefault, the\n // leak fails closed instead of silently running uncapped.\n sendMaxAmount: '0',\n allowlistCreators: [],\n baseUrl: PRODUCTION_ORIGIN,\n rpcUrl: 'https://mainnet.base.org',\n evalCohort: false,\n bazaarPay: false,\n bazaarRegistries: DEFAULT_BAZAAR_REGISTRIES,\n publish: { mode: 'review', defaultPrice: '100000' },\n install: { harness: [] },\n // `auto` is the default because the hook exists to be useful without being\n // asked for; the disclosure and the undo ride the install output, and `off`\n // leaves the installed script inert without touching settings.json. Both hooks\n // are `auto` by default and disjoint — no `inherit`.\n hooks: { webSearch: 'auto', agentDispatch: 'auto', stopNag: 'on', sessionPrimer: 'on' },\n update: { mode: 'nudge' },\n};\n\n/**\n * Scalar keys `config get/set/list` render one line each. The nested blocks are\n * excluded: `publish` and `hooks` are addressed by their dotted keys (see\n * PUBLISH_CONFIG_KEYS / HOOKS_CONFIG_KEYS), and `install` is a record `install`\n * writes about itself rather than a setting to hand-edit, so none is ever a bare\n * scalar.\n */\nexport type ScalarConfigKey = Exclude<keyof Config, 'publish' | 'install' | 'hooks' | 'update'>;\nconst NESTED_CONFIG_KEYS: ReadonlySet<string> = new Set(['publish', 'install', 'hooks', 'update']);\nexport const CONFIG_KEYS = (Object.keys(CONFIG_DEFAULTS) as Array<keyof Config>).filter(\n (key): key is ScalarConfigKey => !NESTED_CONFIG_KEYS.has(key),\n);\n\n/** The dotted keys `config get/set` accept for the nested publish block. */\nexport const PUBLISH_CONFIG_KEYS = ['publish.mode', 'publish.defaultPrice'] as const;\nexport type PublishConfigKey = (typeof PUBLISH_CONFIG_KEYS)[number];\n\n/** The dotted keys `config get/set` accept for the nested hooks block. */\nexport const HOOKS_CONFIG_KEYS = [\n 'hooks.webSearch',\n 'hooks.agentDispatch',\n 'hooks.stopNag',\n 'hooks.sessionPrimer',\n] as const;\nexport type HooksConfigKey = (typeof HOOKS_CONFIG_KEYS)[number];\n\n/** Legacy aliases still accepted on `config set/get` for one release. */\nexport const LEGACY_HOOKS_CONFIG_KEYS = ['hooks.searchMode', 'hooks.dispatchMode'] as const;\nexport type LegacyHooksConfigKey = (typeof LEGACY_HOOKS_CONFIG_KEYS)[number];\n\n/** The dotted key `config get/set` accepts for the nested update block. */\nexport const UPDATE_CONFIG_KEYS = ['update.mode'] as const;\nexport type UpdateConfigKey = (typeof UPDATE_CONFIG_KEYS)[number];\n\n/**\n * Read and validate config.json WITHOUT applying defaults, so provenance can\n * distinguish \"present in file\" from \"absent\". Missing file is fine (returns\n * {}); malformed JSON or a failed schema is CONFIG_INVALID with a fix.\n */\nexport async function loadRawConfig(dir: string): Promise<PartialConfig> {\n const path = configPath(dir);\n let raw: string;\n try {\n raw = await readFile(path, 'utf8');\n } catch (err) {\n if (isNotFound(err)) return {};\n throw new CliError('CONFIG_INVALID', `Could not read config at ${path}`, {\n fix: `Check file permissions on ${path}.`,\n cause: err,\n });\n }\n let json: unknown;\n try {\n json = JSON.parse(raw);\n } catch (err) {\n throw new CliError('CONFIG_INVALID', `Config at ${path} is not valid JSON`, {\n fix: `Fix the JSON syntax in ${path}, or delete it to restore defaults.`,\n cause: err,\n });\n }\n const parsed = RawConfigSchema.safeParse(json);\n if (!parsed.success) {\n throw new CliError('CONFIG_INVALID', `Config at ${path} is invalid`, {\n fix: `Correct the reported keys in ${path}, or delete it to restore defaults.`,\n details: parsed.error.issues,\n });\n }\n return parsed.data;\n}\n\n/** File values merged over defaults — the effective persisted config. The nested\n * publish block is merged per-subkey so a file that sets only publish.mode keeps\n * the default defaultPrice (a shallow spread would drop it). */\nexport async function loadConfig(dir: string): Promise<Config> {\n const raw = await loadRawConfig(dir);\n const rawHooks = raw.hooks as\n | {\n webSearch?: WebSearchMode;\n agentDispatch?: AgentDispatchMode;\n searchMode?: WebSearchMode;\n dispatchMode?: DispatchHookMode;\n stopNag?: StopNagMode;\n sessionPrimer?: SessionPrimerMode;\n }\n | undefined;\n // Backward compat: new webSearch wins, else legacy searchMode, else default.\n const resolvedWebSearch =\n rawHooks?.webSearch ?? rawHooks?.searchMode ?? CONFIG_DEFAULTS.hooks.webSearch;\n // Migration for agentDispatch: new key wins; else legacy dispatchMode (if not inherit) wins;\n // else if legacy is inherit or missing but webSearch resolved, copy webSearch; else default.\n // Since dispatch never shipped to npm (only searchMode did), the elaborate branch is only\n // for the unreleased `inherit` branch; the important legacy is searchMode -> webSearch.\n let resolvedAgentDispatch: AgentDispatchMode;\n if (rawHooks?.agentDispatch !== undefined) {\n resolvedAgentDispatch = rawHooks.agentDispatch;\n } else if (rawHooks?.dispatchMode !== undefined && rawHooks.dispatchMode !== 'inherit') {\n resolvedAgentDispatch = rawHooks.dispatchMode as AgentDispatchMode;\n } else if (rawHooks?.dispatchMode === 'inherit') {\n resolvedAgentDispatch = resolvedWebSearch;\n } else if (rawHooks?.dispatchMode === undefined && rawHooks?.searchMode !== undefined) {\n // Old file had only searchMode (dispatch inherited): preserve previous behavior for one release.\n resolvedAgentDispatch = resolvedWebSearch;\n } else if (\n rawHooks?.dispatchMode === undefined &&\n rawHooks?.webSearch !== undefined &&\n rawHooks?.agentDispatch === undefined\n ) {\n // New file with only webSearch set after the rename — keep disjoint: do NOT copy.\n resolvedAgentDispatch = CONFIG_DEFAULTS.hooks.agentDispatch;\n } else {\n resolvedAgentDispatch = CONFIG_DEFAULTS.hooks.agentDispatch;\n }\n // If the file had neither new nor legacy hooks at all, loadSettings' file-or-default\n // semantics would say `default` rather than `file` — but loadConfig's job is to produce\n // the effective Config object, so defaults are correct here regardless. The provenance\n // question lives in resolve* below.\n return {\n ...CONFIG_DEFAULTS,\n ...raw,\n publish: {\n mode: raw.publish?.mode ?? CONFIG_DEFAULTS.publish.mode,\n defaultPrice: raw.publish?.defaultPrice ?? CONFIG_DEFAULTS.publish.defaultPrice,\n },\n install: { harness: raw.install?.harness ?? CONFIG_DEFAULTS.install.harness },\n hooks: {\n webSearch: resolvedWebSearch,\n agentDispatch: resolvedAgentDispatch,\n stopNag: rawHooks?.stopNag ?? CONFIG_DEFAULTS.hooks.stopNag,\n sessionPrimer: rawHooks?.sessionPrimer ?? CONFIG_DEFAULTS.hooks.sessionPrimer,\n },\n update: { mode: raw.update?.mode ?? CONFIG_DEFAULTS.update.mode },\n };\n}\n\nexport type Provenance = 'default' | 'file' | 'project' | 'env' | 'flag';\n\nexport interface ResolvedSetting<T> {\n value: T;\n source: Provenance;\n}\n\n/**\n * The per-project `.tenjin.json` layer (B3, D38): publish overrides discovered by\n * walking up from cwd, plus whether that file is gitignored. `gitignored` gates\n * `full-auto` — a committed file requesting it is downgraded (loosening gate).\n */\nexport interface ProjectPublishLayer {\n publish?: { mode?: PublishMode; defaultPrice?: string };\n gitignored: boolean;\n}\n\n/** publish.mode resolution: value, source, and the downgrade warning (if any). */\nexport interface PublishModeResolution {\n value: PublishMode;\n source: Provenance;\n /** Set when a committed `.tenjin.json`'s `full-auto` was downgraded to `auto`. */\n downgradedWarning?: string;\n}\n\n/** Effective value + where it came from, per key. What `config` (bare) renders. */\nexport interface EffectiveSettings {\n maxAutoSpend: ResolvedSetting<string>;\n sessionBudget: ResolvedSetting<string>;\n confirm: ResolvedSetting<string>;\n sendMaxAmount: ResolvedSetting<string>;\n allowlistCreators: ResolvedSetting<string[]>;\n baseUrl: ResolvedSetting<string>;\n rpcUrl: ResolvedSetting<string>;\n evalCohort: ResolvedSetting<boolean>;\n bazaarPay: ResolvedSetting<boolean>;\n bazaarRegistries: ResolvedSetting<string[]>;\n publishMode: PublishModeResolution;\n publishDefaultPrice: ResolvedSetting<string>;\n hooksWebSearch: ResolvedSetting<WebSearchMode>;\n hooksAgentDispatch: ResolvedSetting<AgentDispatchMode>;\n hooksStopNag: ResolvedSetting<StopNagMode>;\n hooksSessionPrimer: ResolvedSetting<SessionPrimerMode>;\n updateMode: ResolvedSetting<UpdateMode>;\n /** @deprecated use hooksWebSearch — kept for backward compat */\n hooksSearchMode: ResolvedSetting<WebSearchMode>;\n /** @deprecated use hooksAgentDispatch — kept for backward compat (never `inherit`) */\n hooksDispatchMode: ResolvedSetting<AgentDispatchMode>;\n}\n\n/** CLI flags that participate in settings precedence (`--base-url`). */\nexport interface SettingsFlags {\n baseUrl?: string;\n}\n\nexport interface ResolveSettingsInput {\n /** Raw file values (present keys only) — from loadRawConfig, not loadConfig. */\n config: PartialConfig;\n flags: SettingsFlags;\n env: NodeJS.ProcessEnv;\n /** The nearest `.tenjin.json` layer, when one was found (see publish-settings). */\n project?: ProjectPublishLayer;\n}\n\n/**\n * Apply precedence flag > env > file > default per key, returning each effective\n * value with its source. In B1 only baseUrl has flag/env overrides\n * (`--base-url`, TENJIN_BASE_URL); the rest resolve file-or-default. B3 adds the\n * publish keys, which additionally fold in the per-project `.tenjin.json` layer.\n */\nexport function resolveSettings(input: ResolveSettingsInput): EffectiveSettings {\n const { config, flags, env, project } = input;\n const webSearch = resolveHooksWebSearch(config);\n const agentDispatch = resolveHooksAgentDispatch(config);\n return {\n maxAutoSpend: fileOrDefault('maxAutoSpend', config),\n sessionBudget: fileOrDefault('sessionBudget', config),\n confirm: fileOrDefault('confirm', config),\n sendMaxAmount: resolveSendMaxAmount(config),\n allowlistCreators: fileOrDefault('allowlistCreators', config),\n baseUrl: resolveBaseUrl(config, flags, env),\n rpcUrl: fileOrDefault('rpcUrl', config),\n evalCohort: fileOrDefault('evalCohort', config),\n bazaarPay: fileOrDefault('bazaarPay', config),\n bazaarRegistries: fileOrDefault('bazaarRegistries', config),\n publishMode: resolvePublishMode({ config, project, env }),\n publishDefaultPrice: resolvePublishDefaultPrice({ config, project }),\n hooksWebSearch: webSearch,\n hooksAgentDispatch: agentDispatch,\n hooksSearchMode: webSearch,\n hooksDispatchMode: agentDispatch,\n hooksStopNag: resolveHooksStopNag(config),\n hooksSessionPrimer: resolveHooksSessionPrimer(config),\n updateMode: resolveUpdateMode(config),\n };\n}\n\n/** update.mode: file or default, no env or flag. Every surface that reports a\n * newer version reads this one resolved value, so they cannot disagree. */\nfunction resolveUpdateMode(config: PartialConfig): ResolvedSetting<UpdateMode> {\n const fromFile = config.update?.mode;\n if (fromFile !== undefined) return { value: fromFile, source: 'file' };\n return { value: CONFIG_DEFAULTS.update.mode, source: 'default' };\n}\n\n/** hooks.webSearch: file or default. Legacy `hooks.searchMode` counts as `file`. */\nexport function resolveHooksWebSearch(config: PartialConfig): ResolvedSetting<WebSearchMode> {\n const hooks = config.hooks as\n { webSearch?: WebSearchMode; searchMode?: WebSearchMode } | undefined;\n if (hooks?.webSearch !== undefined) return { value: hooks.webSearch, source: 'file' };\n if (hooks?.searchMode !== undefined) return { value: hooks.searchMode, source: 'file' };\n return { value: CONFIG_DEFAULTS.hooks.webSearch, source: 'default' };\n}\n\n/** @deprecated use resolveHooksWebSearch */\nexport function resolveHooksSearchMode(config: PartialConfig): ResolvedSetting<WebSearchMode> {\n return resolveHooksWebSearch(config);\n}\n\n/** hooks.agentDispatch: file or default, disjoint from webSearch. Legacy `dispatchMode` (including `inherit`) honoured on read. */\nexport function resolveHooksAgentDispatch(\n config: PartialConfig,\n): ResolvedSetting<AgentDispatchMode> {\n const hooks = config.hooks as\n | {\n agentDispatch?: AgentDispatchMode;\n dispatchMode?: DispatchHookMode;\n webSearch?: WebSearchMode;\n searchMode?: WebSearchMode;\n }\n | undefined;\n if (hooks?.agentDispatch !== undefined) return { value: hooks.agentDispatch, source: 'file' };\n const legacy = hooks?.dispatchMode;\n if (legacy !== undefined && legacy !== 'inherit') {\n return { value: legacy as AgentDispatchMode, source: 'file' };\n }\n if (legacy === 'inherit') {\n const webSearch = hooks?.webSearch ?? hooks?.searchMode ?? CONFIG_DEFAULTS.hooks.webSearch;\n return { value: webSearch as AgentDispatchMode, source: 'file' };\n }\n // File had only legacy searchMode (dispatch inherited implicitly) — preserve prior behaviour for one release.\n if (\n hooks?.searchMode !== undefined &&\n hooks?.dispatchMode === undefined &&\n hooks?.agentDispatch === undefined\n ) {\n const webSearch = hooks.webSearch ?? hooks.searchMode ?? CONFIG_DEFAULTS.hooks.webSearch;\n return { value: webSearch as AgentDispatchMode, source: 'file' };\n }\n return { value: CONFIG_DEFAULTS.hooks.agentDispatch, source: 'default' };\n}\n\n/** @deprecated use resolveHooksAgentDispatch — `inherit` never surfaces; value is already resolved */\nexport function resolveHooksDispatchMode(\n config: PartialConfig,\n): ResolvedSetting<AgentDispatchMode> {\n return resolveHooksAgentDispatch(config);\n}\n\n/** hooks.sessionPrimer: file or default, same shape as hooks.webSearch. */\nfunction resolveHooksSessionPrimer(config: PartialConfig): ResolvedSetting<SessionPrimerMode> {\n const fromFile = (config.hooks as { sessionPrimer?: SessionPrimerMode } | undefined)\n ?.sessionPrimer;\n if (fromFile !== undefined) return { value: fromFile, source: 'file' };\n return { value: CONFIG_DEFAULTS.hooks.sessionPrimer, source: 'default' };\n}\n\n/** hooks.stopNag: file or default, same shape as hooks.webSearch. */\nfunction resolveHooksStopNag(config: PartialConfig): ResolvedSetting<StopNagMode> {\n const fromFile = (config.hooks as { stopNag?: StopNagMode } | undefined)?.stopNag;\n if (fromFile !== undefined) return { value: fromFile, source: 'file' };\n return { value: CONFIG_DEFAULTS.hooks.stopNag, source: 'default' };\n}\n\n/**\n * The loosening gate (D38): a committed (not-gitignored) `.tenjin.json` requesting\n * `full-auto` is downgraded to `auto`, never silently honored — cloning a repo\n * must not enable auto-publish. `full-auto` from global config / env / flag (all\n * inherently local, not cloned) is always honored.\n */\nconst FULL_AUTO_DOWNGRADE_WARNING =\n 'Ignoring publish.mode \"full-auto\" from a committed .tenjin.json (cloning a repo must not enable auto-publish); using \"auto\". Add .tenjin.json to .gitignore to opt in.';\n\nfunction coercePublishMode(raw: string | undefined): PublishMode | undefined {\n if (raw === undefined || raw.length === 0) return undefined;\n const parsed = PublishModeSchema.safeParse(raw);\n return parsed.success ? parsed.data : undefined;\n}\n\n/**\n * Resolve publish.mode through global file < project `.tenjin.json` < env\n * (TENJIN_PUBLISH_MODE) < flag (`--mode`). Total: an invalid env/flag value is\n * ignored (validation lives at the command edge, like baseUrl). The project\n * layer's `full-auto` is gated on that file being gitignored.\n */\nexport function resolvePublishMode(input: {\n config: PartialConfig;\n project?: ProjectPublishLayer;\n env: NodeJS.ProcessEnv;\n flag?: string;\n}): PublishModeResolution {\n const { config, project, env, flag } = input;\n let winner: PublishModeResolution = { value: CONFIG_DEFAULTS.publish.mode, source: 'default' };\n\n const fromFile = config.publish?.mode;\n if (fromFile !== undefined) winner = { value: fromFile, source: 'file' };\n\n if (project !== undefined && project.publish?.mode !== undefined) {\n const fromProject = project.publish.mode;\n if (fromProject === 'full-auto' && !project.gitignored) {\n winner = { value: 'auto', source: 'project', downgradedWarning: FULL_AUTO_DOWNGRADE_WARNING };\n } else {\n winner = { value: fromProject, source: 'project' };\n }\n }\n\n const fromEnv = coercePublishMode(env.TENJIN_PUBLISH_MODE);\n if (fromEnv !== undefined) winner = { value: fromEnv, source: 'env' };\n\n const fromFlag = coercePublishMode(flag);\n if (fromFlag !== undefined) winner = { value: fromFlag, source: 'flag' };\n\n return winner;\n}\n\n/** Resolve publish.defaultPrice (atomic) through global file < project < default. */\nexport function resolvePublishDefaultPrice(input: {\n config: PartialConfig;\n project?: ProjectPublishLayer;\n}): ResolvedSetting<string> {\n const { config, project } = input;\n let result: ResolvedSetting<string> = {\n value: CONFIG_DEFAULTS.publish.defaultPrice,\n source: 'default',\n };\n if (config.publish?.defaultPrice !== undefined) {\n result = { value: config.publish.defaultPrice, source: 'file' };\n }\n if (project?.publish?.defaultPrice !== undefined) {\n result = { value: project.publish.defaultPrice, source: 'project' };\n }\n return result;\n}\n\n/** Persist a full, validated config via the atomic writer (0700 dir, 0644 file). */\nexport async function writeConfig(dir: string, config: Config): Promise<void> {\n const validated = ConfigSchema.parse(config);\n await writeFileAtomic(configPath(dir), `${JSON.stringify(validated, null, 2)}\\n`, {\n mode: 0o644,\n dirMode: 0o700,\n });\n}\n\n/**\n * sendMaxAmount deliberately bypasses fileOrDefault: it has no usable default\n * (the operator's require-set-before-first-send posture). Absent from\n * config.json it resolves to the SEND_MAX_UNSET sentinel with source 'default',\n * which `tenjin send` refuses outright — the cap must be set to an amount, \"0\"\n * (disable), or an explicit \"none\" (uncapped opt-in) before the first send.\n */\nfunction resolveSendMaxAmount(config: PartialConfig): ResolvedSetting<string> {\n if (config.sendMaxAmount !== undefined) return { value: config.sendMaxAmount, source: 'file' };\n return { value: SEND_MAX_UNSET, source: 'default' };\n}\n\nfunction fileOrDefault<K extends keyof Config>(\n key: K,\n config: PartialConfig,\n): ResolvedSetting<Config[K]> {\n const fromFile = config[key];\n // PartialConfig[K] is Config[K] | undefined; narrowing an indexed access of a\n // type parameter doesn't refine K, so assert the excluded-undefined type.\n if (fromFile !== undefined) return { value: fromFile as Config[K], source: 'file' };\n return { value: CONFIG_DEFAULTS[key], source: 'default' };\n}\n\nfunction resolveBaseUrl(\n config: PartialConfig,\n flags: SettingsFlags,\n env: NodeJS.ProcessEnv,\n): ResolvedSetting<string> {\n if (flags.baseUrl !== undefined && flags.baseUrl.length > 0) {\n return { value: flags.baseUrl, source: 'flag' };\n }\n const fromEnv = env.TENJIN_BASE_URL;\n if (fromEnv !== undefined && fromEnv.length > 0) {\n return { value: fromEnv, source: 'env' };\n }\n if (config.baseUrl !== undefined) return { value: config.baseUrl, source: 'file' };\n return { value: CONFIG_DEFAULTS.baseUrl, source: 'default' };\n}\n\nfunction isNotFound(err: unknown): boolean {\n return (\n typeof err === 'object' &&\n err !== null &&\n 'code' in err &&\n (err as { code?: unknown }).code === 'ENOENT'\n );\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,gBAAgB;AASzB,IAAM,eAAe,iBAAE,OAA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EAAE,OAAO,gBAAgB,QAAQ,UAAU;AACpD;AAEA,SAAS,cACP,KACA,QAC4B;AAC5B,QAAM,WAAW,OAAO,GAAG;AAG3B,MAAI,aAAa,OAAW,QAAO,EAAE,OAAO,UAAuB,QAAQ,OAAO;AAClF,SAAO,EAAE,OAAO,gBAAgB,GAAG,GAAG,QAAQ,UAAU;AAC1D;AAEA,SAAS,eACP,QACA,OACA,KACyB;AACzB,MAAI,MAAM,YAAY,UAAa,MAAM,QAAQ,SAAS,GAAG;AAC3D,WAAO,EAAE,OAAO,MAAM,SAAS,QAAQ,OAAO;AAAA,EAChD;AACA,QAAM,UAAU,IAAI;AACpB,MAAI,YAAY,UAAa,QAAQ,SAAS,GAAG;AAC/C,WAAO,EAAE,OAAO,SAAS,QAAQ,MAAM;AAAA,EACzC;AACA,MAAI,OAAO,YAAY,OAAW,QAAO,EAAE,OAAO,OAAO,SAAS,QAAQ,OAAO;AACjF,SAAO,EAAE,OAAO,gBAAgB,SAAS,QAAQ,UAAU;AAC7D;AAEA,SAAS,WAAW,KAAuB;AACzC,SACE,OAAO,QAAQ,YACf,QAAQ,QACR,UAAU,OACT,IAA2B,SAAS;AAEzC;","names":[]}
|
package/dist/chunk-UHTVXQ2O.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
HashMD,
|
|
4
|
-
sha256
|
|
5
|
-
} from "./chunk-W6R3HAAG.js";
|
|
6
|
-
import {
|
|
7
|
-
clean,
|
|
8
|
-
createHasher,
|
|
9
|
-
rotl
|
|
10
|
-
} from "./chunk-KYQVEKP5.js";
|
|
11
|
-
|
|
12
|
-
// node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/sha256.js
|
|
13
|
-
var sha2562 = sha256;
|
|
14
|
-
|
|
15
|
-
// node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/legacy.js
|
|
16
|
-
var Rho160 = /* @__PURE__ */ Uint8Array.from([
|
|
17
|
-
7,
|
|
18
|
-
4,
|
|
19
|
-
13,
|
|
20
|
-
1,
|
|
21
|
-
10,
|
|
22
|
-
6,
|
|
23
|
-
15,
|
|
24
|
-
3,
|
|
25
|
-
12,
|
|
26
|
-
0,
|
|
27
|
-
9,
|
|
28
|
-
5,
|
|
29
|
-
2,
|
|
30
|
-
14,
|
|
31
|
-
11,
|
|
32
|
-
8
|
|
33
|
-
]);
|
|
34
|
-
var Id160 = /* @__PURE__ */ (() => Uint8Array.from(new Array(16).fill(0).map((_, i) => i)))();
|
|
35
|
-
var Pi160 = /* @__PURE__ */ (() => Id160.map((i) => (9 * i + 5) % 16))();
|
|
36
|
-
var idxLR = /* @__PURE__ */ (() => {
|
|
37
|
-
const L = [Id160];
|
|
38
|
-
const R = [Pi160];
|
|
39
|
-
const res = [L, R];
|
|
40
|
-
for (let i = 0; i < 4; i++)
|
|
41
|
-
for (let j of res)
|
|
42
|
-
j.push(j[i].map((k) => Rho160[k]));
|
|
43
|
-
return res;
|
|
44
|
-
})();
|
|
45
|
-
var idxL = /* @__PURE__ */ (() => idxLR[0])();
|
|
46
|
-
var idxR = /* @__PURE__ */ (() => idxLR[1])();
|
|
47
|
-
var shifts160 = /* @__PURE__ */ [
|
|
48
|
-
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
49
|
-
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
50
|
-
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
51
|
-
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
52
|
-
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
53
|
-
].map((i) => Uint8Array.from(i));
|
|
54
|
-
var shiftsL160 = /* @__PURE__ */ idxL.map((idx, i) => idx.map((j) => shifts160[i][j]));
|
|
55
|
-
var shiftsR160 = /* @__PURE__ */ idxR.map((idx, i) => idx.map((j) => shifts160[i][j]));
|
|
56
|
-
var Kl160 = /* @__PURE__ */ Uint32Array.from([
|
|
57
|
-
0,
|
|
58
|
-
1518500249,
|
|
59
|
-
1859775393,
|
|
60
|
-
2400959708,
|
|
61
|
-
2840853838
|
|
62
|
-
]);
|
|
63
|
-
var Kr160 = /* @__PURE__ */ Uint32Array.from([
|
|
64
|
-
1352829926,
|
|
65
|
-
1548603684,
|
|
66
|
-
1836072691,
|
|
67
|
-
2053994217,
|
|
68
|
-
0
|
|
69
|
-
]);
|
|
70
|
-
function ripemd_f(group, x, y, z) {
|
|
71
|
-
if (group === 0)
|
|
72
|
-
return x ^ y ^ z;
|
|
73
|
-
if (group === 1)
|
|
74
|
-
return x & y | ~x & z;
|
|
75
|
-
if (group === 2)
|
|
76
|
-
return (x | ~y) ^ z;
|
|
77
|
-
if (group === 3)
|
|
78
|
-
return x & z | y & ~z;
|
|
79
|
-
return x ^ (y | ~z);
|
|
80
|
-
}
|
|
81
|
-
var BUF_160 = /* @__PURE__ */ new Uint32Array(16);
|
|
82
|
-
var RIPEMD160 = class extends HashMD {
|
|
83
|
-
constructor() {
|
|
84
|
-
super(64, 20, 8, true);
|
|
85
|
-
this.h0 = 1732584193 | 0;
|
|
86
|
-
this.h1 = 4023233417 | 0;
|
|
87
|
-
this.h2 = 2562383102 | 0;
|
|
88
|
-
this.h3 = 271733878 | 0;
|
|
89
|
-
this.h4 = 3285377520 | 0;
|
|
90
|
-
}
|
|
91
|
-
get() {
|
|
92
|
-
const { h0, h1, h2, h3, h4 } = this;
|
|
93
|
-
return [h0, h1, h2, h3, h4];
|
|
94
|
-
}
|
|
95
|
-
set(h0, h1, h2, h3, h4) {
|
|
96
|
-
this.h0 = h0 | 0;
|
|
97
|
-
this.h1 = h1 | 0;
|
|
98
|
-
this.h2 = h2 | 0;
|
|
99
|
-
this.h3 = h3 | 0;
|
|
100
|
-
this.h4 = h4 | 0;
|
|
101
|
-
}
|
|
102
|
-
process(view, offset) {
|
|
103
|
-
for (let i = 0; i < 16; i++, offset += 4)
|
|
104
|
-
BUF_160[i] = view.getUint32(offset, true);
|
|
105
|
-
let al = this.h0 | 0, ar = al, bl = this.h1 | 0, br = bl, cl = this.h2 | 0, cr = cl, dl = this.h3 | 0, dr = dl, el = this.h4 | 0, er = el;
|
|
106
|
-
for (let group = 0; group < 5; group++) {
|
|
107
|
-
const rGroup = 4 - group;
|
|
108
|
-
const hbl = Kl160[group], hbr = Kr160[group];
|
|
109
|
-
const rl = idxL[group], rr = idxR[group];
|
|
110
|
-
const sl = shiftsL160[group], sr = shiftsR160[group];
|
|
111
|
-
for (let i = 0; i < 16; i++) {
|
|
112
|
-
const tl = rotl(al + ripemd_f(group, bl, cl, dl) + BUF_160[rl[i]] + hbl, sl[i]) + el | 0;
|
|
113
|
-
al = el, el = dl, dl = rotl(cl, 10) | 0, cl = bl, bl = tl;
|
|
114
|
-
}
|
|
115
|
-
for (let i = 0; i < 16; i++) {
|
|
116
|
-
const tr = rotl(ar + ripemd_f(rGroup, br, cr, dr) + BUF_160[rr[i]] + hbr, sr[i]) + er | 0;
|
|
117
|
-
ar = er, er = dr, dr = rotl(cr, 10) | 0, cr = br, br = tr;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
this.set(this.h1 + cl + dr | 0, this.h2 + dl + er | 0, this.h3 + el + ar | 0, this.h4 + al + br | 0, this.h0 + bl + cr | 0);
|
|
121
|
-
}
|
|
122
|
-
roundClean() {
|
|
123
|
-
clean(BUF_160);
|
|
124
|
-
}
|
|
125
|
-
destroy() {
|
|
126
|
-
this.destroyed = true;
|
|
127
|
-
clean(this.buffer);
|
|
128
|
-
this.set(0, 0, 0, 0, 0);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
var ripemd160 = /* @__PURE__ */ createHasher(() => new RIPEMD160());
|
|
132
|
-
|
|
133
|
-
// node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/ripemd160.js
|
|
134
|
-
var ripemd1602 = ripemd160;
|
|
135
|
-
|
|
136
|
-
export {
|
|
137
|
-
sha2562 as sha256,
|
|
138
|
-
ripemd1602 as ripemd160
|
|
139
|
-
};
|
|
140
|
-
//# sourceMappingURL=chunk-UHTVXQ2O.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/src/sha256.ts","../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/src/legacy.ts","../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/src/ripemd160.ts"],"sourcesContent":["/**\n * SHA2-256 a.k.a. sha256. In JS, it is the fastest hash, even faster than Blake3.\n *\n * To break sha256 using birthday attack, attackers need to try 2^128 hashes.\n * BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.\n *\n * Check out [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).\n * @module\n * @deprecated\n */\nimport {\n SHA224 as SHA224n,\n sha224 as sha224n,\n SHA256 as SHA256n,\n sha256 as sha256n,\n} from './sha2.ts';\n/** @deprecated Use import from `noble/hashes/sha2` module */\nexport const SHA256: typeof SHA256n = SHA256n;\n/** @deprecated Use import from `noble/hashes/sha2` module */\nexport const sha256: typeof sha256n = sha256n;\n/** @deprecated Use import from `noble/hashes/sha2` module */\nexport const SHA224: typeof SHA224n = SHA224n;\n/** @deprecated Use import from `noble/hashes/sha2` module */\nexport const sha224: typeof sha224n = sha224n;\n","/**\n\nSHA1 (RFC 3174), MD5 (RFC 1321) and RIPEMD160 (RFC 2286) legacy, weak hash functions.\nDon't use them in a new protocol. What \"weak\" means:\n\n- Collisions can be made with 2^18 effort in MD5, 2^60 in SHA1, 2^80 in RIPEMD160.\n- No practical pre-image attacks (only theoretical, 2^123.4)\n- HMAC seems kinda ok: https://datatracker.ietf.org/doc/html/rfc6151\n * @module\n */\nimport { Chi, HashMD, Maj } from './_md.ts';\nimport { type CHash, clean, createHasher, rotl } from './utils.ts';\n\n/** Initial SHA1 state */\nconst SHA1_IV = /* @__PURE__ */ Uint32Array.from([\n 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0,\n]);\n\n// Reusable temporary buffer\nconst SHA1_W = /* @__PURE__ */ new Uint32Array(80);\n\n/** SHA1 legacy hash class. */\nexport class SHA1 extends HashMD<SHA1> {\n private A = SHA1_IV[0] | 0;\n private B = SHA1_IV[1] | 0;\n private C = SHA1_IV[2] | 0;\n private D = SHA1_IV[3] | 0;\n private E = SHA1_IV[4] | 0;\n\n constructor() {\n super(64, 20, 8, false);\n }\n protected get(): [number, number, number, number, number] {\n const { A, B, C, D, E } = this;\n return [A, B, C, D, E];\n }\n protected set(A: number, B: number, C: number, D: number, E: number): void {\n this.A = A | 0;\n this.B = B | 0;\n this.C = C | 0;\n this.D = D | 0;\n this.E = E | 0;\n }\n protected process(view: DataView, offset: number): void {\n for (let i = 0; i < 16; i++, offset += 4) SHA1_W[i] = view.getUint32(offset, false);\n for (let i = 16; i < 80; i++)\n SHA1_W[i] = rotl(SHA1_W[i - 3] ^ SHA1_W[i - 8] ^ SHA1_W[i - 14] ^ SHA1_W[i - 16], 1);\n // Compression function main loop, 80 rounds\n let { A, B, C, D, E } = this;\n for (let i = 0; i < 80; i++) {\n let F, K;\n if (i < 20) {\n F = Chi(B, C, D);\n K = 0x5a827999;\n } else if (i < 40) {\n F = B ^ C ^ D;\n K = 0x6ed9eba1;\n } else if (i < 60) {\n F = Maj(B, C, D);\n K = 0x8f1bbcdc;\n } else {\n F = B ^ C ^ D;\n K = 0xca62c1d6;\n }\n const T = (rotl(A, 5) + F + E + K + SHA1_W[i]) | 0;\n E = D;\n D = C;\n C = rotl(B, 30);\n B = A;\n A = T;\n }\n // Add the compressed chunk to the current hash value\n A = (A + this.A) | 0;\n B = (B + this.B) | 0;\n C = (C + this.C) | 0;\n D = (D + this.D) | 0;\n E = (E + this.E) | 0;\n this.set(A, B, C, D, E);\n }\n protected roundClean(): void {\n clean(SHA1_W);\n }\n destroy(): void {\n this.set(0, 0, 0, 0, 0);\n clean(this.buffer);\n }\n}\n\n/** SHA1 (RFC 3174) legacy hash function. It was cryptographically broken. */\nexport const sha1: CHash = /* @__PURE__ */ createHasher(() => new SHA1());\n\n/** Per-round constants */\nconst p32 = /* @__PURE__ */ Math.pow(2, 32);\nconst K = /* @__PURE__ */ Array.from({ length: 64 }, (_, i) =>\n Math.floor(p32 * Math.abs(Math.sin(i + 1)))\n);\n\n/** md5 initial state: same as sha1, but 4 u32 instead of 5. */\nconst MD5_IV = /* @__PURE__ */ SHA1_IV.slice(0, 4);\n\n// Reusable temporary buffer\nconst MD5_W = /* @__PURE__ */ new Uint32Array(16);\n/** MD5 legacy hash class. */\nexport class MD5 extends HashMD<MD5> {\n private A = MD5_IV[0] | 0;\n private B = MD5_IV[1] | 0;\n private C = MD5_IV[2] | 0;\n private D = MD5_IV[3] | 0;\n\n constructor() {\n super(64, 16, 8, true);\n }\n protected get(): [number, number, number, number] {\n const { A, B, C, D } = this;\n return [A, B, C, D];\n }\n protected set(A: number, B: number, C: number, D: number): void {\n this.A = A | 0;\n this.B = B | 0;\n this.C = C | 0;\n this.D = D | 0;\n }\n protected process(view: DataView, offset: number): void {\n for (let i = 0; i < 16; i++, offset += 4) MD5_W[i] = view.getUint32(offset, true);\n // Compression function main loop, 64 rounds\n let { A, B, C, D } = this;\n for (let i = 0; i < 64; i++) {\n let F, g, s;\n if (i < 16) {\n F = Chi(B, C, D);\n g = i;\n s = [7, 12, 17, 22];\n } else if (i < 32) {\n F = Chi(D, B, C);\n g = (5 * i + 1) % 16;\n s = [5, 9, 14, 20];\n } else if (i < 48) {\n F = B ^ C ^ D;\n g = (3 * i + 5) % 16;\n s = [4, 11, 16, 23];\n } else {\n F = C ^ (B | ~D);\n g = (7 * i) % 16;\n s = [6, 10, 15, 21];\n }\n F = F + A + K[i] + MD5_W[g];\n A = D;\n D = C;\n C = B;\n B = B + rotl(F, s[i % 4]);\n }\n // Add the compressed chunk to the current hash value\n A = (A + this.A) | 0;\n B = (B + this.B) | 0;\n C = (C + this.C) | 0;\n D = (D + this.D) | 0;\n this.set(A, B, C, D);\n }\n protected roundClean(): void {\n clean(MD5_W);\n }\n destroy(): void {\n this.set(0, 0, 0, 0);\n clean(this.buffer);\n }\n}\n\n/**\n * MD5 (RFC 1321) legacy hash function. It was cryptographically broken.\n * MD5 architecture is similar to SHA1, with some differences:\n * - Reduced output length: 16 bytes (128 bit) instead of 20\n * - 64 rounds, instead of 80\n * - Little-endian: could be faster, but will require more code\n * - Non-linear index selection: huge speed-up for unroll\n * - Per round constants: more memory accesses, additional speed-up for unroll\n */\nexport const md5: CHash = /* @__PURE__ */ createHasher(() => new MD5());\n\n// RIPEMD-160\n\nconst Rho160 = /* @__PURE__ */ Uint8Array.from([\n 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,\n]);\nconst Id160 = /* @__PURE__ */ (() => Uint8Array.from(new Array(16).fill(0).map((_, i) => i)))();\nconst Pi160 = /* @__PURE__ */ (() => Id160.map((i) => (9 * i + 5) % 16))();\nconst idxLR = /* @__PURE__ */ (() => {\n const L = [Id160];\n const R = [Pi160];\n const res = [L, R];\n for (let i = 0; i < 4; i++) for (let j of res) j.push(j[i].map((k) => Rho160[k]));\n return res;\n})();\nconst idxL = /* @__PURE__ */ (() => idxLR[0])();\nconst idxR = /* @__PURE__ */ (() => idxLR[1])();\n// const [idxL, idxR] = idxLR;\n\nconst shifts160 = /* @__PURE__ */ [\n [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],\n [12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],\n [13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],\n [14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],\n [15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5],\n].map((i) => Uint8Array.from(i));\nconst shiftsL160 = /* @__PURE__ */ idxL.map((idx, i) => idx.map((j) => shifts160[i][j]));\nconst shiftsR160 = /* @__PURE__ */ idxR.map((idx, i) => idx.map((j) => shifts160[i][j]));\nconst Kl160 = /* @__PURE__ */ Uint32Array.from([\n 0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e,\n]);\nconst Kr160 = /* @__PURE__ */ Uint32Array.from([\n 0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000,\n]);\n// It's called f() in spec.\nfunction ripemd_f(group: number, x: number, y: number, z: number): number {\n if (group === 0) return x ^ y ^ z;\n if (group === 1) return (x & y) | (~x & z);\n if (group === 2) return (x | ~y) ^ z;\n if (group === 3) return (x & z) | (y & ~z);\n return x ^ (y | ~z);\n}\n// Reusable temporary buffer\nconst BUF_160 = /* @__PURE__ */ new Uint32Array(16);\nexport class RIPEMD160 extends HashMD<RIPEMD160> {\n private h0 = 0x67452301 | 0;\n private h1 = 0xefcdab89 | 0;\n private h2 = 0x98badcfe | 0;\n private h3 = 0x10325476 | 0;\n private h4 = 0xc3d2e1f0 | 0;\n\n constructor() {\n super(64, 20, 8, true);\n }\n protected get(): [number, number, number, number, number] {\n const { h0, h1, h2, h3, h4 } = this;\n return [h0, h1, h2, h3, h4];\n }\n protected set(h0: number, h1: number, h2: number, h3: number, h4: number): void {\n this.h0 = h0 | 0;\n this.h1 = h1 | 0;\n this.h2 = h2 | 0;\n this.h3 = h3 | 0;\n this.h4 = h4 | 0;\n }\n protected process(view: DataView, offset: number): void {\n for (let i = 0; i < 16; i++, offset += 4) BUF_160[i] = view.getUint32(offset, true);\n // prettier-ignore\n let al = this.h0 | 0, ar = al,\n bl = this.h1 | 0, br = bl,\n cl = this.h2 | 0, cr = cl,\n dl = this.h3 | 0, dr = dl,\n el = this.h4 | 0, er = el;\n\n // Instead of iterating 0 to 80, we split it into 5 groups\n // And use the groups in constants, functions, etc. Much simpler\n for (let group = 0; group < 5; group++) {\n const rGroup = 4 - group;\n const hbl = Kl160[group], hbr = Kr160[group]; // prettier-ignore\n const rl = idxL[group], rr = idxR[group]; // prettier-ignore\n const sl = shiftsL160[group], sr = shiftsR160[group]; // prettier-ignore\n for (let i = 0; i < 16; i++) {\n const tl = (rotl(al + ripemd_f(group, bl, cl, dl) + BUF_160[rl[i]] + hbl, sl[i]) + el) | 0;\n al = el, el = dl, dl = rotl(cl, 10) | 0, cl = bl, bl = tl; // prettier-ignore\n }\n // 2 loops are 10% faster\n for (let i = 0; i < 16; i++) {\n const tr = (rotl(ar + ripemd_f(rGroup, br, cr, dr) + BUF_160[rr[i]] + hbr, sr[i]) + er) | 0;\n ar = er, er = dr, dr = rotl(cr, 10) | 0, cr = br, br = tr; // prettier-ignore\n }\n }\n // Add the compressed chunk to the current hash value\n this.set(\n (this.h1 + cl + dr) | 0,\n (this.h2 + dl + er) | 0,\n (this.h3 + el + ar) | 0,\n (this.h4 + al + br) | 0,\n (this.h0 + bl + cr) | 0\n );\n }\n protected roundClean(): void {\n clean(BUF_160);\n }\n destroy(): void {\n this.destroyed = true;\n clean(this.buffer);\n this.set(0, 0, 0, 0, 0);\n }\n}\n\n/**\n * RIPEMD-160 - a legacy hash function from 1990s.\n * * https://homes.esat.kuleuven.be/~bosselae/ripemd160.html\n * * https://homes.esat.kuleuven.be/~bosselae/ripemd160/pdf/AB-9601/AB-9601.pdf\n */\nexport const ripemd160: CHash = /* @__PURE__ */ createHasher(() => new RIPEMD160());\n","/**\n * RIPEMD-160 legacy hash function.\n * https://homes.esat.kuleuven.be/~bosselae/ripemd160.html\n * https://homes.esat.kuleuven.be/~bosselae/ripemd160/pdf/AB-9601/AB-9601.pdf\n * @module\n * @deprecated\n */\nimport { RIPEMD160 as RIPEMD160n, ripemd160 as ripemd160n } from './legacy.ts';\n/** @deprecated Use import from `noble/hashes/legacy` module */\nexport const RIPEMD160: typeof RIPEMD160n = RIPEMD160n;\n/** @deprecated Use import from `noble/hashes/legacy` module */\nexport const ripemd160: typeof ripemd160n = ripemd160n;\n"],"mappings":";;;;;;;;;;;;AAmBO,IAAMA,UAAyB;;;ACiKtC,IAAM,SAAyB,2BAAW,KAAK;EAC7C;EAAG;EAAG;EAAI;EAAG;EAAI;EAAG;EAAI;EAAG;EAAI;EAAG;EAAG;EAAG;EAAG;EAAI;EAAI;CACpD;AACD,IAAM,QAAyB,uBAAM,WAAW,KAAK,IAAI,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,GAAE;AAC7F,IAAM,QAAyB,uBAAM,MAAM,IAAI,CAAC,OAAO,IAAI,IAAI,KAAK,EAAE,GAAE;AACxE,IAAM,QAAyB,uBAAK;AAClC,QAAM,IAAI,CAAC,KAAK;AAChB,QAAM,IAAI,CAAC,KAAK;AAChB,QAAM,MAAM,CAAC,GAAG,CAAC;AACjB,WAAS,IAAI,GAAG,IAAI,GAAG;AAAK,aAAS,KAAK;AAAK,QAAE,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC;AAChF,SAAO;AACT,GAAE;AACF,IAAM,OAAwB,uBAAM,MAAM,CAAC,GAAE;AAC7C,IAAM,OAAwB,uBAAM,MAAM,CAAC,GAAE;AAG7C,IAAM,YAA4B;EAChC,CAAC,IAAI,IAAI,IAAI,IAAI,GAAG,GAAG,GAAG,GAAG,IAAI,IAAI,IAAI,IAAI,GAAG,GAAG,GAAG,CAAC;EACvD,CAAC,IAAI,IAAI,IAAI,IAAI,GAAG,GAAG,GAAG,GAAG,IAAI,IAAI,IAAI,IAAI,GAAG,GAAG,GAAG,CAAC;EACvD,CAAC,IAAI,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AAC,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,IAAI,KAAM;AAC1F,aAAK,IAAI,KAAK,IAAI,KAAK,KAAK,IAAI,EAAE,IAAI,GAAG,KAAK,IAAI,KAAK;MACzD;IACF;AAEA,SAAK,IACF,KAAK,KAAK,KAAK,KAAM,GACrB,KAAK,KAAK,KAAK,KAAM,GACrB,KAAK,KAAK,KAAK,KAAM,GACrB,KAAK,KAAK,KAAK,KAAM,GACrB,KAAK,KAAK,KAAK,KAAM,CAAC;EAE3B;EACU,aAAU;AAClB,UAAM,OAAO;EACf;EACA,UAAO;AACL,SAAK,YAAY;AACjB,UAAM,KAAK,MAAM;AACjB,SAAK,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC;EACxB;;AAQK,IAAM,YAAmC,6BAAa,MAAM,IAAI,UAAS,CAAE;;;ACzR3E,IAAMC,aAA+B;","names":["sha256","ripemd160"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/policy.ts"],"sourcesContent":["/**\n * Spend-policy evaluation, pure and provider-agnostic. The wallet provider layer\n * (lib/wallet/spend.ts) owns the ledger and calls this; a future hosted provider\n * (Privy, B5) reuses the same decision rules, so the knobs live in exactly one\n * place. Nothing here does IO, the caller supplies the already-spent total and\n * decides how to satisfy a `confirm` decision (a `--yes`, a TTY prompt, or a\n * non-interactive refusal).\n */\n\n/** How a `confirm` gate is configured (parsed from the stored config string). */\nexport type ConfirmPolicy = { mode: 'always' } | { mode: 'above'; thresholdAtomic: bigint };\n\nexport interface SpendPolicy {\n /** Amounts at or below this auto-approve WITHOUT a prompt (still subject to the\n * confirm gate below). Default 0 → nothing auto-approves. */\n maxAutoSpendAtomic: bigint;\n /** Rolling local ceiling on cumulative session spend. 0 = disabled (no ceiling). */\n sessionBudgetAtomic: bigint;\n /** When a human confirmation is requested. */\n confirm: ConfirmPolicy;\n /** Creators (handle or 0x-address, lowercased) auto-payment is restricted to.\n * Empty = no restriction. A non-empty list is a hard gate: a non-member is\n * denied even with `--yes`. */\n allowlistCreators: string[];\n}\n\nexport interface SpendRequest {\n amountAtomic: bigint;\n /** Creator identity from the 402 preview / candidate, handle or 0x address. */\n creator: string;\n /** The caller's `--max-price` cap, if given. A hard ceiling, never bypassable. */\n maxPriceAtomic?: bigint;\n /** Cumulative spend already recorded in this rolling session window. */\n sessionSpentAtomic: bigint;\n}\n\n/**\n * `allow`: within policy, proceed silently. `confirm`: an approval is required ,\n * the caller satisfies it with `--yes`, an interactive prompt, or refuses. `deny`:\n * a hard gate blocked it (price cap, allowlist, session budget); NOT satisfiable\n * by `--yes` or a prompt.\n */\nexport type SpendDecision = 'allow' | 'confirm' | 'deny';\n\nexport type PolicyReason =\n | 'within_policy'\n | 'price_cap_exceeded'\n | 'not_allowlisted'\n | 'session_budget_exceeded'\n | 'above_auto_spend'\n | 'confirm_always'\n | 'above_confirm_threshold';\n\nexport interface PolicyEvaluation {\n decision: SpendDecision;\n reason: PolicyReason;\n message: string;\n}\n\n/** Normalize a creator identity for allowlist comparison (case-insensitive; a\n * word-handle and a 0x address are both single tokens). */\nfunction normCreator(value: string): string {\n return value.trim().toLowerCase();\n}\n\n/**\n * Evaluate one spend against the policy. Hard gates run first (price cap →\n * allowlist → session budget); only if all pass is the confirm gate consulted. A\n * spend at or below `maxAutoSpend` that the confirm policy would not prompt for is\n * the only `allow`; everything else within the hard gates is `confirm`.\n */\nexport function evaluateSpendPolicy(policy: SpendPolicy, req: SpendRequest): PolicyEvaluation {\n if (req.maxPriceAtomic !== undefined && req.amountAtomic > req.maxPriceAtomic) {\n return {\n decision: 'deny',\n reason: 'price_cap_exceeded',\n message: `Price ${req.amountAtomic} exceeds the --max-price cap ${req.maxPriceAtomic}.`,\n };\n }\n\n if (policy.allowlistCreators.length > 0) {\n const allowed = policy.allowlistCreators.map(normCreator);\n if (!allowed.includes(normCreator(req.creator))) {\n return {\n decision: 'deny',\n reason: 'not_allowlisted',\n message: `Creator \"${req.creator}\" is not in allowlistCreators.`,\n };\n }\n }\n\n if (policy.sessionBudgetAtomic > 0n) {\n const projected = req.sessionSpentAtomic + req.amountAtomic;\n if (projected > policy.sessionBudgetAtomic) {\n return {\n decision: 'deny',\n reason: 'session_budget_exceeded',\n message: `This spend would bring the session total to ${projected}, over sessionBudget ${policy.sessionBudgetAtomic}.`,\n };\n }\n }\n\n if (req.amountAtomic > policy.maxAutoSpendAtomic) {\n return {\n decision: 'confirm',\n reason: 'above_auto_spend',\n message: `Price ${req.amountAtomic} is above maxAutoSpend ${policy.maxAutoSpendAtomic}; confirmation required.`,\n };\n }\n\n if (policy.confirm.mode === 'always') {\n return {\n decision: 'confirm',\n reason: 'confirm_always',\n message: 'confirm policy is \"always\"; confirmation required.',\n };\n }\n\n if (req.amountAtomic > policy.confirm.thresholdAtomic) {\n return {\n decision: 'confirm',\n reason: 'above_confirm_threshold',\n message: `Price ${req.amountAtomic} is above the confirm threshold ${policy.confirm.thresholdAtomic}; confirmation required.`,\n };\n }\n\n return { decision: 'allow', reason: 'within_policy', message: 'within spend policy' };\n}\n\n/** Parse the stored `confirm` config value (\"always\" | \"above:<atomic>\"). */\nexport function parseConfirmPolicy(stored: string): ConfirmPolicy {\n if (stored === 'always') return { mode: 'always' };\n const m = /^above:(\\d+)$/.exec(stored);\n if (m && m[1] !== undefined) return { mode: 'above', thresholdAtomic: BigInt(m[1]) };\n // The config schema already constrains this; a malformed value here is a bug,\n // so fail closed to the safest interpretation rather than throwing mid-buy.\n return { mode: 'always' };\n}\n"],"mappings":";;;AA6DA,SAAS,YAAY,OAAuB;AAC1C,SAAO,MAAM,KAAK,EAAE,YAAY;AAClC;AAQO,SAAS,oBAAoB,QAAqB,KAAqC;AAC5F,MAAI,IAAI,mBAAmB,UAAa,IAAI,eAAe,IAAI,gBAAgB;AAC7E,WAAO;AAAA,MACL,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,SAAS,SAAS,IAAI,YAAY,gCAAgC,IAAI,cAAc;AAAA,IACtF;AAAA,EACF;AA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,CAAC,CAAC,EAAE;AAGnF,SAAO,EAAE,MAAM,SAAS;AAC1B;","names":[]}
|
package/dist/chunk-US456VUI.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
fetchRead
|
|
4
|
-
} from "./chunk-LRYV3SK7.js";
|
|
5
|
-
import {
|
|
6
|
-
headingOutline
|
|
7
|
-
} from "./chunk-SGK2B724.js";
|
|
8
|
-
import {
|
|
9
|
-
resolveResourceRef
|
|
10
|
-
} from "./chunk-VJQKL3YH.js";
|
|
11
|
-
import {
|
|
12
|
-
sanitizeForTerminal
|
|
13
|
-
} from "./chunk-OLWTRUTS.js";
|
|
14
|
-
import {
|
|
15
|
-
resolveContextSettings
|
|
16
|
-
} from "./chunk-VYOJOX4Z.js";
|
|
17
|
-
import {
|
|
18
|
-
toMoney
|
|
19
|
-
} from "./chunk-EFWZPUTC.js";
|
|
20
|
-
|
|
21
|
-
// src/commands/inspect.ts
|
|
22
|
-
async function runInspect(args, ctx, deps = {}) {
|
|
23
|
-
const settings = await resolveContextSettings(ctx);
|
|
24
|
-
const ref = await resolveResourceRef(args.ref, ctx.dataDir, settings.baseUrl);
|
|
25
|
-
const result = await fetchRead(ref.url, {
|
|
26
|
-
timeoutMs: ctx.flags.timeout,
|
|
27
|
-
...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
|
|
28
|
-
});
|
|
29
|
-
if (result.kind === "entitled") {
|
|
30
|
-
const body = result.body;
|
|
31
|
-
return {
|
|
32
|
-
data: {
|
|
33
|
-
url: ref.url,
|
|
34
|
-
resourceId: body.id,
|
|
35
|
-
access: "free",
|
|
36
|
-
title: body.title,
|
|
37
|
-
price: toMoney(body.price),
|
|
38
|
-
headings: headingOutline(body.bodyMd),
|
|
39
|
-
// The free/owned half of the verb split (#42): delivery here costs nothing,
|
|
40
|
-
// so point at the free-only verb, not at the paying one. Machine consumers
|
|
41
|
-
// read this; the human line below says the same thing.
|
|
42
|
-
nextCommand: `tenjin read ${ref.url}`
|
|
43
|
-
},
|
|
44
|
-
humanLines: [
|
|
45
|
-
`${sanitizeForTerminal(body.title)}, free (${body.price} atomic). Read it with \`tenjin read ${sanitizeForTerminal(ref.url)}\`.`
|
|
46
|
-
]
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
if (result.kind === "payment_required") {
|
|
50
|
-
const requirement = result.paymentRequired.accepts[0];
|
|
51
|
-
const price = requirement !== void 0 ? toMoney(requirement.amount) : void 0;
|
|
52
|
-
const card = result.preview.card;
|
|
53
|
-
return {
|
|
54
|
-
data: {
|
|
55
|
-
url: ref.url,
|
|
56
|
-
...ref.resourceId !== void 0 ? { resourceId: ref.resourceId } : {},
|
|
57
|
-
access: "paid",
|
|
58
|
-
...price !== void 0 ? { price } : {},
|
|
59
|
-
payment: requirement !== void 0 ? {
|
|
60
|
-
scheme: requirement.scheme,
|
|
61
|
-
network: requirement.network,
|
|
62
|
-
asset: requirement.asset,
|
|
63
|
-
payTo: requirement.payTo,
|
|
64
|
-
amount: requirement.amount
|
|
65
|
-
} : void 0,
|
|
66
|
-
// The card stays where the wire puts it, inside `preview`, and is emitted
|
|
67
|
-
// exactly once: it is the largest object in this envelope, and a second
|
|
68
|
-
// hoisted copy would double every inspect payload to save one key of
|
|
69
|
-
// depth.
|
|
70
|
-
preview: result.preview,
|
|
71
|
-
...result.cardError === true ? { cardError: true } : {},
|
|
72
|
-
// Paid and unowned: this one really does cost money, so it keeps pointing at
|
|
73
|
-
// `buy`. `tenjin read` would refuse it with exit 3.
|
|
74
|
-
nextCommand: `tenjin buy ${ref.url}`
|
|
75
|
-
},
|
|
76
|
-
humanLines: [
|
|
77
|
-
`Paid resource${price !== void 0 ? `, ${price.usd} USD (${price.atomic} atomic)` : ""}.`,
|
|
78
|
-
...cardLines(card),
|
|
79
|
-
// Three distinct states behind an absent card, and they call for three
|
|
80
|
-
// different actions: the piece attests nothing (a signal, judge on that),
|
|
81
|
-
// the server could not load a card it has (transient, retry), or this CLI
|
|
82
|
-
// could not parse what arrived (a client-side bug or server drift). Only
|
|
83
|
-
// the last is ours. `cardUnavailable` is server-sent and never rides
|
|
84
|
-
// alongside a card, so it is only worth saying when there is no card.
|
|
85
|
-
...card === void 0 && result.preview.cardUnavailable === true ? ["The piece has a card the server could not load; retry later."] : [],
|
|
86
|
-
...result.cardError === true ? [
|
|
87
|
-
"The server sent an answer card this CLI could not parse; judging on price and preview only."
|
|
88
|
-
] : [],
|
|
89
|
-
"This is the pre-purchase card; run `tenjin buy` to pay and read (`tenjin read` refuses paid pieces)."
|
|
90
|
-
]
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
data: {
|
|
95
|
-
url: ref.url,
|
|
96
|
-
access: "entitled",
|
|
97
|
-
message: result.message,
|
|
98
|
-
nextCommand: `tenjin read ${ref.url}`
|
|
99
|
-
},
|
|
100
|
-
humanLines: [
|
|
101
|
-
`${sanitizeForTerminal(result.message)} Read it with \`tenjin read ${sanitizeForTerminal(ref.url)}\`.`
|
|
102
|
-
]
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
var CARD_BOUNDS = {
|
|
106
|
-
list: 10 * 200 + 9 * 2,
|
|
107
|
-
appliesTo: 8 * (32 + 1 + 20 * 120 + 19 * 2) + 7 * 2,
|
|
108
|
-
prose: 500,
|
|
109
|
-
cadence: 120,
|
|
110
|
-
// artifactType and temporalMode are open strings on the wire, so the composed
|
|
111
|
-
// freshness line gets a bound of its own rather than trusting them.
|
|
112
|
-
freshness: 200
|
|
113
|
-
};
|
|
114
|
-
var CLIP_MARKER = "...";
|
|
115
|
-
function cardLine(label, value, max) {
|
|
116
|
-
if (value === null) return [];
|
|
117
|
-
const text = sanitizeForTerminal(value).trim();
|
|
118
|
-
if (text.length === 0) return [];
|
|
119
|
-
return [`${label}: ${text.length > max ? `${text.slice(0, max)}${CLIP_MARKER}` : text}`];
|
|
120
|
-
}
|
|
121
|
-
function cardLines(card) {
|
|
122
|
-
if (card === void 0) return [];
|
|
123
|
-
const list = (items) => items.length > 0 ? items.join("; ") : null;
|
|
124
|
-
const appliesTo = Object.entries(card.appliesTo).map(
|
|
125
|
-
([key, values]) => `${key}=${values.join(", ")}`
|
|
126
|
-
);
|
|
127
|
-
return [
|
|
128
|
-
...cardLine("Answers", list(card.questionsAnswered), CARD_BOUNDS.list),
|
|
129
|
-
...cardLine("Tasks", list(card.tasksSupported), CARD_BOUNDS.list),
|
|
130
|
-
...cardLine("Applies to", list(appliesTo), CARD_BOUNDS.appliesTo),
|
|
131
|
-
...cardLine("Scope", card.scope, CARD_BOUNDS.prose),
|
|
132
|
-
...cardLine("Excludes", card.exclusions, CARD_BOUNDS.prose),
|
|
133
|
-
...cardLine("Freshness", freshness(card), CARD_BOUNDS.freshness),
|
|
134
|
-
...cardLine("Provenance", card.provenanceSummary, CARD_BOUNDS.prose),
|
|
135
|
-
...cardLine("Method", card.methodologySummary, CARD_BOUNDS.prose),
|
|
136
|
-
...cardLine("Maintenance", card.maintenanceCadence, CARD_BOUNDS.cadence)
|
|
137
|
-
];
|
|
138
|
-
}
|
|
139
|
-
function freshness(card) {
|
|
140
|
-
const parts = [card.artifactType, card.temporalMode].filter((s) => s.trim().length > 0);
|
|
141
|
-
if (card.asOf !== null) parts.push(`as of ${card.asOf}`);
|
|
142
|
-
if (card.validUntil !== null) parts.push(`valid until ${card.validUntil}`);
|
|
143
|
-
return parts.join(", ");
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export {
|
|
147
|
-
runInspect
|
|
148
|
-
};
|
|
149
|
-
//# sourceMappingURL=chunk-US456VUI.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/commands/inspect.ts"],"sourcesContent":["import { resolveResourceRef } from '../lib/resource-ref';\nimport { resolveContextSettings } from '../lib/settings';\nimport { fetchRead, type PreviewCard } from '../lib/read-client';\nimport { toMoney } from '../lib/money';\nimport { headingOutline } from '../lib/markdown';\nimport { sanitizeForTerminal } from '../lib/output';\nimport type { CommandContext, CommandResult } from '../context';\n\n/**\n * `tenjin inspect <resource-url-or-id>`, fetch the pre-purchase answer card /\n * preview from the read route's 402 body WITHOUT paying (spec 10). A free\n * resource returns 200 with the whole body; a paid one returns the leak-safe\n * preview plus the advertised price/network, and the answer card when the piece\n * carries one. Never signs, never pays, never saves.\n *\n * The card is the depth half of the search/inspect split: search v2 candidates are\n * lean, so this free call is where an agent gets what it answers, what it applies\n * to, what it excludes, and how it is dated, before spending anything.\n */\n\nexport interface InspectArgs {\n ref: string;\n}\n\nexport interface InspectDeps {\n fetchImpl?: typeof fetch;\n}\n\nexport async function runInspect(\n args: InspectArgs,\n ctx: CommandContext,\n deps: InspectDeps = {},\n): Promise<CommandResult> {\n const settings = await resolveContextSettings(ctx);\n const ref = await resolveResourceRef(args.ref, ctx.dataDir, settings.baseUrl);\n\n const result = await fetchRead(ref.url, {\n timeoutMs: ctx.flags.timeout,\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n });\n\n if (result.kind === 'entitled') {\n // Free (or already-entitled) resource: the body is readable now, no payment.\n const body = result.body;\n return {\n data: {\n url: ref.url,\n resourceId: body.id,\n access: 'free',\n title: body.title,\n price: toMoney(body.price),\n headings: headingOutline(body.bodyMd),\n // The free/owned half of the verb split (#42): delivery here costs nothing,\n // so point at the free-only verb, not at the paying one. Machine consumers\n // read this; the human line below says the same thing.\n nextCommand: `tenjin read ${ref.url}`,\n },\n humanLines: [\n `${sanitizeForTerminal(body.title)}, free (${body.price} atomic). Read it with \\`tenjin read ${sanitizeForTerminal(ref.url)}\\`.`,\n ],\n };\n }\n\n if (result.kind === 'payment_required') {\n const requirement = result.paymentRequired.accepts[0];\n const price = requirement !== undefined ? toMoney(requirement.amount) : undefined;\n const card = result.preview.card;\n return {\n data: {\n url: ref.url,\n ...(ref.resourceId !== undefined ? { resourceId: ref.resourceId } : {}),\n access: 'paid',\n ...(price !== undefined ? { price } : {}),\n payment:\n requirement !== undefined\n ? {\n scheme: requirement.scheme,\n network: requirement.network,\n asset: requirement.asset,\n payTo: requirement.payTo,\n amount: requirement.amount,\n }\n : undefined,\n // The card stays where the wire puts it, inside `preview`, and is emitted\n // exactly once: it is the largest object in this envelope, and a second\n // hoisted copy would double every inspect payload to save one key of\n // depth.\n preview: result.preview,\n ...(result.cardError === true ? { cardError: true } : {}),\n // Paid and unowned: this one really does cost money, so it keeps pointing at\n // `buy`. `tenjin read` would refuse it with exit 3.\n nextCommand: `tenjin buy ${ref.url}`,\n },\n humanLines: [\n `Paid resource${price !== undefined ? `, ${price.usd} USD (${price.atomic} atomic)` : ''}.`,\n ...cardLines(card),\n // Three distinct states behind an absent card, and they call for three\n // different actions: the piece attests nothing (a signal, judge on that),\n // the server could not load a card it has (transient, retry), or this CLI\n // could not parse what arrived (a client-side bug or server drift). Only\n // the last is ours. `cardUnavailable` is server-sent and never rides\n // alongside a card, so it is only worth saying when there is no card.\n ...(card === undefined && result.preview.cardUnavailable === true\n ? ['The piece has a card the server could not load; retry later.']\n : []),\n ...(result.cardError === true\n ? [\n 'The server sent an answer card this CLI could not parse; judging on price and preview only.',\n ]\n : []),\n 'This is the pre-purchase card; run `tenjin buy` to pay and read (`tenjin read` refuses paid pieces).',\n ],\n };\n }\n\n // already_purchased without a payment header is unexpected; report it plainly.\n // Owned means delivery is free, so this branch points at `read` too.\n return {\n data: {\n url: ref.url,\n access: 'entitled',\n message: result.message,\n nextCommand: `tenjin read ${ref.url}`,\n },\n humanLines: [\n `${sanitizeForTerminal(result.message)} Read it with \\`tenjin read ${sanitizeForTerminal(ref.url)}\\`.`,\n ],\n };\n}\n\n/**\n * Per-line caps for the rendered card, each derived from the server's write-time\n * bound for that field, so a VALID card is never clipped: the two lists are 10\n * items x 200 chars joined with '; '; appliesTo is 8 keys (<=32 chars) x 20\n * values x 120 chars; the prose fields have a 500-char column bound and cadence\n * 120. Exceeding one means a server that broke its own bounds.\n *\n * When that happens the clip is MARKED. A silently shortened claim reads as a\n * whole one, and \"applies to Postgres 14, 15\" is a different promise from\n * \"applies to Postgres 14, 15, 16\". The `--json` payload stays verbatim either\n * way, because that copy is what an agent decides a non-refundable purchase on.\n */\nconst CARD_BOUNDS = {\n list: 10 * 200 + 9 * 2,\n appliesTo: 8 * (32 + 1 + 20 * 120 + 19 * 2) + 7 * 2,\n prose: 500,\n cadence: 120,\n // artifactType and temporalMode are open strings on the wire, so the composed\n // freshness line gets a bound of its own rather than trusting them.\n freshness: 200,\n} as const;\n\nconst CLIP_MARKER = '...';\n\nfunction cardLine(label: string, value: string | null, max: number): string[] {\n if (value === null) return [];\n const text = sanitizeForTerminal(value).trim();\n if (text.length === 0) return [];\n return [`${label}: ${text.length > max ? `${text.slice(0, max)}${CLIP_MARKER}` : text}`];\n}\n\n/**\n * The answer card off the 402 body, as human lines. This is the depth half of the\n * search/inspect split: search v2 returns lean hits, and the card an agent judges\n * fit on arrives here, for free. Empty when the piece carries no card, so an\n * uncarded inspect renders exactly as it did before.\n */\nfunction cardLines(card: PreviewCard | undefined): string[] {\n if (card === undefined) return [];\n const list = (items: string[]): string | null => (items.length > 0 ? items.join('; ') : null);\n const appliesTo = Object.entries(card.appliesTo).map(\n ([key, values]) => `${key}=${values.join(', ')}`,\n );\n return [\n ...cardLine('Answers', list(card.questionsAnswered), CARD_BOUNDS.list),\n ...cardLine('Tasks', list(card.tasksSupported), CARD_BOUNDS.list),\n ...cardLine('Applies to', list(appliesTo), CARD_BOUNDS.appliesTo),\n ...cardLine('Scope', card.scope, CARD_BOUNDS.prose),\n ...cardLine('Excludes', card.exclusions, CARD_BOUNDS.prose),\n ...cardLine('Freshness', freshness(card), CARD_BOUNDS.freshness),\n ...cardLine('Provenance', card.provenanceSummary, CARD_BOUNDS.prose),\n ...cardLine('Method', card.methodologySummary, CARD_BOUNDS.prose),\n ...cardLine('Maintenance', card.maintenanceCadence, CARD_BOUNDS.cadence),\n ];\n}\n\n/** Type, temporal mode and the two dates on one line: they answer the single\n * question a buyer asks of freshness, which is whether this is still true here.\n *\n * Both labels are open strings on the wire, so an empty one is dropped rather\n * than joined: otherwise the line leads with a comma and reads as a rendering\n * bug. All four empty yields '', and cardLine then omits the line entirely. */\nfunction freshness(card: PreviewCard): string {\n const parts = [card.artifactType, card.temporalMode].filter((s) => s.trim().length > 0);\n if (card.asOf !== null) parts.push(`as of ${card.asOf}`);\n if (card.validUntil !== null) parts.push(`valid until ${card.validUntil}`);\n return parts.join(', ');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA4BA,eAAsB,WACpB,MACA,KACA,OAAoB,CAAC,GACG;AACxB,QAAM,WAAW,MAAM,uBAAuB,GAAG;AACjD,QAAM,MAAM,MAAM,mBAAmB,KAAK,KAAK,IAAI,SAAS,SAAS,OAAO;AAE5E,QAAM,SAAS,MAAM,UAAU,IAAI,KAAK;AAAA,IACtC,WAAW,IAAI,MAAM;AAAA,IACrB,GAAI,KAAK,cAAc,SAAY,EAAE,WAAW,KAAK,UAAU,IAAI,CAAC;AAAA,EACtE,CAAC;AAED,MAAI,OAAO,SAAS,YAAY;AAE9B,UAAM,OAAO,OAAO;AACpB,WAAO;AAAA,MACL,MAAM;AAAA,QACJ,KAAK,IAAI;AAAA,QACT,YAAY,KAAK;AAAA,QACjB,QAAQ;AAAA,QACR,OAAO,KAAK;AAAA,QACZ,OAAO,QAAQ,KAAK,KAAK;AAAA,QACzB,UAAU,eAAe,KAAK,MAAM;AAAA;AAAA;AAAA;AAAA,QAIpC,aAAa,eAAe,IAAI,GAAG;AAAA,MACrC;AAAA,MACA,YAAY;AAAA,QACV,GAAG,oBAAoB,KAAK,KAAK,CAAC,WAAW,KAAK,KAAK,wCAAwC,oBAAoB,IAAI,GAAG,CAAC;AAAA,MAC7H;AAAA,IACF;AAAA,EACF;AAEA,MAAI,OAAO,SAAS,oBAAoB;AACtC,UAAM,cAAc,OAAO,g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