tenjin-cli 0.1.0-alpha.3 → 0.1.0-alpha.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.md +54 -7
- package/README.md +149 -264
- package/dist/{_esm-FEASBWRP.js → _esm-CE7KNONL.js} +9 -10
- package/dist/alive-3J3CHOQP.js +21 -0
- package/dist/{ccip-NQXCEK2U.js → ccip-7RMRLAGV.js} +4 -4
- package/dist/{ccip-XR5NE5QK.js → ccip-NLCSCHKI.js} +5 -5
- package/dist/chunk-2SNUOHAT.js +75 -0
- package/dist/chunk-2SNUOHAT.js.map +1 -0
- package/dist/chunk-3O2BQIF6.js +2227 -0
- package/dist/chunk-3O2BQIF6.js.map +1 -0
- package/dist/{chunk-ZMHYXMO6.js → chunk-5IEP5EGE.js} +3 -3
- package/dist/chunk-5LJCEMFD.js +12700 -0
- package/dist/chunk-5LJCEMFD.js.map +1 -0
- package/dist/chunk-6W5GYG3W.js +128 -0
- package/dist/chunk-6W5GYG3W.js.map +1 -0
- package/dist/chunk-7EKYXMUO.js +7536 -0
- package/dist/chunk-7EKYXMUO.js.map +1 -0
- package/dist/chunk-7QKHZQKW.js +1680 -0
- package/dist/chunk-7QKHZQKW.js.map +1 -0
- package/dist/chunk-A36LQPHV.js +29 -0
- package/dist/chunk-A36LQPHV.js.map +1 -0
- package/dist/chunk-AEG2PXBP.js +192 -0
- package/dist/chunk-AEG2PXBP.js.map +1 -0
- package/dist/chunk-AKWGE6JQ.js +49 -0
- package/dist/chunk-AKWGE6JQ.js.map +1 -0
- package/dist/chunk-AWFUPKTM.js +238 -0
- package/dist/chunk-AWFUPKTM.js.map +1 -0
- package/dist/{chunk-UGX7YPX2.js → chunk-AWQPGIR6.js} +7 -9
- package/dist/{chunk-UGX7YPX2.js.map → chunk-AWQPGIR6.js.map} +1 -1
- package/dist/{chunk-5CLSD5YN.js → chunk-BPMWXTFX.js} +2 -2
- package/dist/chunk-EBVIKMCH.js +108 -0
- package/dist/chunk-EBVIKMCH.js.map +1 -0
- package/dist/{chunk-YALGASEU.js → chunk-EGELTSPU.js} +2 -2
- package/dist/{chunk-S3IGX57D.js → chunk-EL56RW2J.js} +166 -7237
- package/dist/chunk-EL56RW2J.js.map +1 -0
- package/dist/chunk-HE2MS4QO.js +256 -0
- package/dist/chunk-HE2MS4QO.js.map +1 -0
- package/dist/{chunk-CYOF7ROH.js → chunk-HPWO4O6S.js} +3 -3
- package/dist/chunk-IOODYAXL.js +324 -0
- package/dist/chunk-IOODYAXL.js.map +1 -0
- package/dist/chunk-JMM6YE7J.js +2174 -0
- package/dist/chunk-JMM6YE7J.js.map +1 -0
- package/dist/{chunk-QVX5MWJZ.js → chunk-JRGFKVAZ.js} +2 -2
- package/dist/{chunk-HIVZG55D.js → chunk-KG3D7FIF.js} +2 -2
- package/dist/chunk-KHE6L6TD.js +416 -0
- package/dist/chunk-KHE6L6TD.js.map +1 -0
- package/dist/chunk-KOGZDMHO.js +21 -0
- package/dist/chunk-KOGZDMHO.js.map +1 -0
- package/dist/chunk-KYFZTGMC.js +237 -0
- package/dist/chunk-KYFZTGMC.js.map +1 -0
- package/dist/chunk-LFZJM56J.js +159 -0
- package/dist/chunk-LFZJM56J.js.map +1 -0
- package/dist/chunk-LHHMV4GU.js +27 -0
- package/dist/chunk-LHHMV4GU.js.map +1 -0
- package/dist/{chunk-YBMMV4Y4.js → chunk-MEFB5KHA.js} +13 -5
- package/dist/chunk-MEFB5KHA.js.map +1 -0
- package/dist/{chunk-NCE5NSN6.js → chunk-N35E6CM2.js} +140 -10
- package/dist/chunk-N35E6CM2.js.map +1 -0
- package/dist/chunk-NZIP4PA2.js +114 -0
- package/dist/chunk-NZIP4PA2.js.map +1 -0
- package/dist/chunk-O2FRQ2L2.js +168 -0
- package/dist/chunk-O2FRQ2L2.js.map +1 -0
- package/dist/chunk-OK2TDZQU.js +404 -0
- package/dist/chunk-OK2TDZQU.js.map +1 -0
- package/dist/chunk-ORWL5BSN.js +269 -0
- package/dist/chunk-ORWL5BSN.js.map +1 -0
- package/dist/{chunk-Z6MFJV5Z.js → chunk-OSYTBCUC.js} +850 -499
- package/dist/chunk-OSYTBCUC.js.map +1 -0
- package/dist/chunk-P7LABKCW.js +90 -0
- package/dist/chunk-P7LABKCW.js.map +1 -0
- package/dist/chunk-PAYV4XUA.js +151 -0
- package/dist/chunk-PAYV4XUA.js.map +1 -0
- package/dist/{chunk-ZABPQJ3M.js → chunk-POUWHWID.js} +2 -2
- package/dist/chunk-QUVVWYJW.js +112 -0
- package/dist/chunk-QUVVWYJW.js.map +1 -0
- package/dist/chunk-RAULEAZ6.js +228 -0
- package/dist/chunk-RAULEAZ6.js.map +1 -0
- package/dist/chunk-S4SAZ7OD.js +30 -0
- package/dist/chunk-S4SAZ7OD.js.map +1 -0
- package/dist/chunk-SJLTEINJ.js +117 -0
- package/dist/chunk-SJLTEINJ.js.map +1 -0
- package/dist/chunk-SPAVAYSW.js +125 -0
- package/dist/chunk-SPAVAYSW.js.map +1 -0
- package/dist/chunk-TTBKWWTV.js +1605 -0
- package/dist/chunk-TTBKWWTV.js.map +1 -0
- package/dist/{chunk-RRN3YTK7.js → chunk-TTNESUPQ.js} +3 -3
- package/dist/chunk-U6YQ6FRI.js +378 -0
- package/dist/chunk-U6YQ6FRI.js.map +1 -0
- package/dist/chunk-VFMQTSXG.js +29 -0
- package/dist/chunk-VFMQTSXG.js.map +1 -0
- package/dist/chunk-VUFAK2LW.js +115 -0
- package/dist/chunk-VUFAK2LW.js.map +1 -0
- package/dist/chunk-VZGAONSJ.js +194 -0
- package/dist/chunk-VZGAONSJ.js.map +1 -0
- package/dist/{chunk-OYMYCW7J.js → chunk-WO5BJNIB.js} +682 -53
- package/dist/chunk-WO5BJNIB.js.map +1 -0
- package/dist/chunk-WVUSXNIE.js +39 -0
- package/dist/chunk-WVUSXNIE.js.map +1 -0
- package/dist/chunk-XKESD27X.js +10 -0
- package/dist/chunk-XKESD27X.js.map +1 -0
- package/dist/{chunk-HSDCI7OV.js → chunk-XZKD7DIF.js} +3 -3
- package/dist/{chunk-XJIW7USF.js → chunk-YFQOA5AU.js} +118 -9
- package/dist/chunk-YFQOA5AU.js.map +1 -0
- package/dist/chunk-YHKXNYTB.js +105 -0
- package/dist/chunk-YHKXNYTB.js.map +1 -0
- package/dist/{cli-SBXI5AMS.js → cli-O5SN7ZJ4.js} +382 -214
- package/dist/cli-O5SN7ZJ4.js.map +1 -0
- package/dist/config-OJQI27LT.js +45 -0
- package/dist/dist-3LOO6M4U.js +2842 -0
- package/dist/dist-3LOO6M4U.js.map +1 -0
- package/dist/doctor-IQQJHGGM.js +590 -0
- package/dist/doctor-IQQJHGGM.js.map +1 -0
- package/dist/env-proxy-XL4P73MZ.js +15 -0
- package/dist/{ethersCompat-Df4a6QIZ-3YZIAXDK.js → ethersCompat-Df4a6QIZ-THAVUGIJ.js} +5 -5
- package/dist/fund-WEV6DMTD.js +365 -0
- package/dist/fund-WEV6DMTD.js.map +1 -0
- package/dist/hook-command-D2P3ILRV.js +32 -0
- package/dist/hosts/claude/.claude-plugin/marketplace.json +19 -0
- package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +14 -0
- package/dist/hosts/claude/tenjin/.mcp.json +12 -0
- package/dist/hosts/claude/tenjin/hooks/hooks.json +221 -0
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/dist/install-TUCRF32I.js +60 -0
- package/dist/install-identity-WHPNMNMQ.js +26 -0
- package/dist/install-wallet-MA27FTQ5.js +113 -0
- package/dist/install-wallet-MA27FTQ5.js.map +1 -0
- package/dist/mcp-QML7ZMPH.js +13427 -0
- package/dist/mcp-QML7ZMPH.js.map +1 -0
- package/dist/package-LGKYOEPV.js +37 -0
- package/dist/package-LGKYOEPV.js.map +1 -0
- package/dist/paths-POPTXJO6.js +61 -0
- package/dist/paths-POPTXJO6.js.map +1 -0
- package/dist/pay-2C2UBBXJ.js +51 -0
- package/dist/pay-2C2UBBXJ.js.map +1 -0
- package/dist/payments-C44QUFXU.js +106 -0
- package/dist/payments-C44QUFXU.js.map +1 -0
- package/dist/redact-6W23GGJC.js +15 -0
- package/dist/redact-6W23GGJC.js.map +1 -0
- package/dist/{secp256k1-N3ZHU7LB.js → secp256k1-ZZZT2CAX.js} +3 -3
- package/dist/secp256k1-ZZZT2CAX.js.map +1 -0
- package/dist/send-KVJX4XIR.js +222 -0
- package/dist/send-KVJX4XIR.js.map +1 -0
- package/dist/status-S7C3WMSH.js +115 -0
- package/dist/status-S7C3WMSH.js.map +1 -0
- package/dist/status-line-YR2T5HC4.js +86 -0
- package/dist/status-line-YR2T5HC4.js.map +1 -0
- package/dist/uninstall-HY6LKIIT.js +149 -0
- package/dist/uninstall-HY6LKIIT.js.map +1 -0
- package/dist/update-OJV22LR3.js +36 -0
- package/dist/update-OJV22LR3.js.map +1 -0
- package/dist/usdc-JK4RRFFQ.js +39 -0
- package/dist/usdc-JK4RRFFQ.js.map +1 -0
- package/dist/{viemAdapter-By13KInL-ZZE6UV4Y.js → viemAdapter-By13KInL-X2VY6CY3.js} +5 -5
- package/dist/viemAdapter-By13KInL-X2VY6CY3.js.map +1 -0
- package/dist/wallet-PD2IMZDU.js +39 -0
- package/dist/wallet-PD2IMZDU.js.map +1 -0
- package/dist/wallet-kdf-worker.mjs +980 -0
- package/docs/agent-permissions.md +180 -0
- package/docs/safety-model.md +59 -0
- package/docs/troubleshooting.md +13 -0
- package/package.json +28 -19
- package/LICENSE +0 -21
- package/dist/buy-EE6SEXP6.js +0 -1598
- package/dist/buy-EE6SEXP6.js.map +0 -1
- package/dist/candidate-ERMSYYQZ.js +0 -127
- package/dist/candidate-ERMSYYQZ.js.map +0 -1
- package/dist/chunk-3OV7E5G5.js +0 -18
- package/dist/chunk-3OV7E5G5.js.map +0 -1
- package/dist/chunk-4ONXEEQL.js +0 -152
- package/dist/chunk-4ONXEEQL.js.map +0 -1
- package/dist/chunk-662MSGZB.js +0 -286
- package/dist/chunk-662MSGZB.js.map +0 -1
- package/dist/chunk-7KUW4MJD.js +0 -59
- package/dist/chunk-7KUW4MJD.js.map +0 -1
- package/dist/chunk-AWPAWHNX.js +0 -333
- package/dist/chunk-AWPAWHNX.js.map +0 -1
- package/dist/chunk-DXTQ3CSI.js +0 -171
- package/dist/chunk-DXTQ3CSI.js.map +0 -1
- package/dist/chunk-ESPNTPQ2.js +0 -207
- package/dist/chunk-ESPNTPQ2.js.map +0 -1
- package/dist/chunk-FJPLRISB.js +0 -79
- package/dist/chunk-FJPLRISB.js.map +0 -1
- package/dist/chunk-GO75V3NZ.js +0 -160
- package/dist/chunk-GO75V3NZ.js.map +0 -1
- package/dist/chunk-JPHG2JW3.js +0 -96
- package/dist/chunk-JPHG2JW3.js.map +0 -1
- package/dist/chunk-MUBUQVC3.js +0 -67
- package/dist/chunk-MUBUQVC3.js.map +0 -1
- package/dist/chunk-NCE5NSN6.js.map +0 -1
- package/dist/chunk-OYMYCW7J.js.map +0 -1
- package/dist/chunk-RY4XKNV3.js +0 -140
- package/dist/chunk-RY4XKNV3.js.map +0 -1
- package/dist/chunk-S3IGX57D.js.map +0 -1
- package/dist/chunk-TLCMMYLY.js +0 -126
- package/dist/chunk-TLCMMYLY.js.map +0 -1
- package/dist/chunk-UO22YNY4.js +0 -69
- package/dist/chunk-UO22YNY4.js.map +0 -1
- package/dist/chunk-XHC6FCGZ.js +0 -261
- package/dist/chunk-XHC6FCGZ.js.map +0 -1
- package/dist/chunk-XJIW7USF.js.map +0 -1
- package/dist/chunk-YBMMV4Y4.js.map +0 -1
- package/dist/chunk-YN5SHIXQ.js +0 -126
- package/dist/chunk-YN5SHIXQ.js.map +0 -1
- package/dist/chunk-Z52RA3NC.js +0 -137
- package/dist/chunk-Z52RA3NC.js.map +0 -1
- package/dist/chunk-Z6MFJV5Z.js.map +0 -1
- package/dist/cli-SBXI5AMS.js.map +0 -1
- package/dist/config-VELDKLHY.js +0 -21
- package/dist/doctor-T3KWNNP2.js +0 -20
- package/dist/inspect-LMKOXE4Y.js +0 -96
- package/dist/inspect-LMKOXE4Y.js.map +0 -1
- package/dist/install-LEX3ENQ6.js +0 -387
- package/dist/install-LEX3ENQ6.js.map +0 -1
- package/dist/lookup-ZPN2Q67N.js +0 -129
- package/dist/lookup-ZPN2Q67N.js.map +0 -1
- package/dist/outcome-N7TAK6WR.js +0 -66
- package/dist/outcome-N7TAK6WR.js.map +0 -1
- package/dist/publish-BKBQQAW4.js +0 -1478
- package/dist/publish-BKBQQAW4.js.map +0 -1
- package/dist/usdc-JIAJW4SV.js +0 -22
- package/dist/wallet-CWEMYVIH.js +0 -179
- package/dist/wallet-CWEMYVIH.js.map +0 -1
- package/dist/wallet-PA54CRBL.js +0 -30
- package/skills/tenjin/SKILL.md +0 -199
- package/skills/tenjin-publish/SKILL.md +0 -111
- package/skills/tenjin-search/SKILL.md +0 -133
- /package/dist/{_esm-FEASBWRP.js.map → _esm-CE7KNONL.js.map} +0 -0
- /package/dist/{ccip-NQXCEK2U.js.map → alive-3J3CHOQP.js.map} +0 -0
- /package/dist/{ccip-XR5NE5QK.js.map → ccip-7RMRLAGV.js.map} +0 -0
- /package/dist/{config-VELDKLHY.js.map → ccip-NLCSCHKI.js.map} +0 -0
- /package/dist/{chunk-ZMHYXMO6.js.map → chunk-5IEP5EGE.js.map} +0 -0
- /package/dist/{chunk-5CLSD5YN.js.map → chunk-BPMWXTFX.js.map} +0 -0
- /package/dist/{chunk-YALGASEU.js.map → chunk-EGELTSPU.js.map} +0 -0
- /package/dist/{chunk-CYOF7ROH.js.map → chunk-HPWO4O6S.js.map} +0 -0
- /package/dist/{chunk-QVX5MWJZ.js.map → chunk-JRGFKVAZ.js.map} +0 -0
- /package/dist/{chunk-HIVZG55D.js.map → chunk-KG3D7FIF.js.map} +0 -0
- /package/dist/{chunk-ZABPQJ3M.js.map → chunk-POUWHWID.js.map} +0 -0
- /package/dist/{chunk-RRN3YTK7.js.map → chunk-TTNESUPQ.js.map} +0 -0
- /package/dist/{chunk-HSDCI7OV.js.map → chunk-XZKD7DIF.js.map} +0 -0
- /package/dist/{doctor-T3KWNNP2.js.map → config-OJQI27LT.js.map} +0 -0
- /package/dist/{ethersCompat-Df4a6QIZ-3YZIAXDK.js.map → env-proxy-XL4P73MZ.js.map} +0 -0
- /package/dist/{secp256k1-N3ZHU7LB.js.map → ethersCompat-Df4a6QIZ-THAVUGIJ.js.map} +0 -0
- /package/dist/{usdc-JIAJW4SV.js.map → hook-command-D2P3ILRV.js.map} +0 -0
- /package/dist/{viemAdapter-By13KInL-ZZE6UV4Y.js.map → install-TUCRF32I.js.map} +0 -0
- /package/dist/{wallet-PA54CRBL.js.map → install-identity-WHPNMNMQ.js.map} +0 -0
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
offchainLookup,
|
|
5
5
|
offchainLookupAbiItem,
|
|
6
6
|
offchainLookupSignature
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-TTNESUPQ.js";
|
|
8
|
+
import "./chunk-KG3D7FIF.js";
|
|
9
9
|
import "./chunk-RBJPAZFI.js";
|
|
10
|
-
import "./chunk-
|
|
10
|
+
import "./chunk-BPMWXTFX.js";
|
|
11
11
|
import "./chunk-ZXTAQYNA.js";
|
|
12
12
|
export {
|
|
13
13
|
ccipRequest,
|
|
@@ -15,4 +15,4 @@ export {
|
|
|
15
15
|
offchainLookupAbiItem,
|
|
16
16
|
offchainLookupSignature
|
|
17
17
|
};
|
|
18
|
-
//# sourceMappingURL=ccip-
|
|
18
|
+
//# sourceMappingURL=ccip-7RMRLAGV.js.map
|
|
@@ -4,11 +4,11 @@ import {
|
|
|
4
4
|
offchainLookup,
|
|
5
5
|
offchainLookupAbiItem,
|
|
6
6
|
offchainLookupSignature
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-5IEP5EGE.js";
|
|
8
|
+
import "./chunk-EGELTSPU.js";
|
|
9
|
+
import "./chunk-KG3D7FIF.js";
|
|
10
10
|
import "./chunk-RBJPAZFI.js";
|
|
11
|
-
import "./chunk-
|
|
11
|
+
import "./chunk-BPMWXTFX.js";
|
|
12
12
|
import "./chunk-ZXTAQYNA.js";
|
|
13
13
|
export {
|
|
14
14
|
ccipRequest,
|
|
@@ -16,4 +16,4 @@ export {
|
|
|
16
16
|
offchainLookupAbiItem,
|
|
17
17
|
offchainLookupSignature
|
|
18
18
|
};
|
|
19
|
-
//# sourceMappingURL=ccip-
|
|
19
|
+
//# sourceMappingURL=ccip-NLCSCHKI.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/lib/policy.ts
|
|
4
|
+
function normCreator(value) {
|
|
5
|
+
return value.trim().toLowerCase();
|
|
6
|
+
}
|
|
7
|
+
function allowsCreator(policy, creator) {
|
|
8
|
+
return policy.allowlistCreators.length === 0 || policy.allowlistCreators.map(normCreator).includes(normCreator(creator));
|
|
9
|
+
}
|
|
10
|
+
function evaluateSpendPolicy(policy, req) {
|
|
11
|
+
if (req.maxPriceAtomic !== void 0 && req.amountAtomic > req.maxPriceAtomic) {
|
|
12
|
+
return {
|
|
13
|
+
decision: "deny",
|
|
14
|
+
reason: "price_cap_exceeded",
|
|
15
|
+
message: `Price ${req.amountAtomic} exceeds the --max-price cap ${req.maxPriceAtomic}.`
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (!allowsCreator(policy, req.creator)) {
|
|
19
|
+
return {
|
|
20
|
+
decision: "deny",
|
|
21
|
+
reason: "not_allowlisted",
|
|
22
|
+
message: `Creator "${req.creator}" is not in allowlistCreators.`
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (req.mode === "manual") {
|
|
26
|
+
return req.amountAtomic > 0n ? {
|
|
27
|
+
decision: "confirm",
|
|
28
|
+
reason: "confirm_always",
|
|
29
|
+
message: "Manual payment requires explicit consent."
|
|
30
|
+
} : { decision: "allow", reason: "within_policy", message: "No payment required." };
|
|
31
|
+
}
|
|
32
|
+
if (policy.sessionBudgetAtomic !== null) {
|
|
33
|
+
const projected = req.sessionSpentAtomic + req.amountAtomic;
|
|
34
|
+
if (projected > policy.sessionBudgetAtomic) {
|
|
35
|
+
return {
|
|
36
|
+
decision: "deny",
|
|
37
|
+
reason: "session_budget_exceeded",
|
|
38
|
+
message: `This spend would bring the session total to ${projected}, over sessionBudget ${policy.sessionBudgetAtomic}.`
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (req.amountAtomic > policy.maxAutoSpendAtomic) {
|
|
43
|
+
return {
|
|
44
|
+
decision: "deny",
|
|
45
|
+
reason: "above_auto_spend",
|
|
46
|
+
message: `Price ${req.amountAtomic} is above maxAutoSpend ${policy.maxAutoSpendAtomic}; automatic payment refused.`
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return { decision: "allow", reason: "within_policy", message: "within spend policy" };
|
|
50
|
+
}
|
|
51
|
+
function evaluatePlan(policy, payments, sessionSpentAtomic) {
|
|
52
|
+
const outside = payments.find((payment) => !allowsCreator(policy, payment.creator));
|
|
53
|
+
if (outside !== void 0) {
|
|
54
|
+
return {
|
|
55
|
+
decision: "deny",
|
|
56
|
+
reason: "not_allowlisted",
|
|
57
|
+
message: `Creator "${outside.creator}" is not in allowlistCreators.`
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (payments.length === 0) {
|
|
61
|
+
return { decision: "allow", reason: "within_policy", message: "No payment required." };
|
|
62
|
+
}
|
|
63
|
+
return evaluateSpendPolicy(policy, {
|
|
64
|
+
mode: "automatic",
|
|
65
|
+
amountAtomic: payments.reduce((sum, payment) => sum + payment.amountAtomic, 0n),
|
|
66
|
+
creator: payments[0].creator,
|
|
67
|
+
sessionSpentAtomic
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export {
|
|
72
|
+
evaluateSpendPolicy,
|
|
73
|
+
evaluatePlan
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=chunk-2SNUOHAT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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\nexport type PaymentMode = 'automatic' | 'manual';\n\nexport interface SpendPolicy {\n /** Automatic per-call ceiling; zero blocks positive automatic payments. */\n maxAutoSpendAtomic: bigint;\n /** Rolling ceiling on automatic exposure. null = no ceiling; zero blocks positive automatic payments. */\n sessionBudgetAtomic: bigint | null;\n /** Creators (handle or 0x-address, lowercased) all payments are 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 /** Omitted by legacy consumers: conservatively automatic. */\n mode?: PaymentMode;\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\n/**\n * `duplicate_in_flight` is the one reason this pure evaluator never returns: it\n * is a fact about the ledger (an identical request already holds a reservation\n * in this turn), so the authorizer raises it. It lives in the union because\n * every caller renders a decision's reason from one vocabulary.\n */\nexport type PolicyReason =\n | 'within_policy'\n | 'duplicate_in_flight'\n | 'price_cap_exceeded'\n | 'not_allowlisted'\n | 'session_budget_exceeded'\n | 'above_auto_spend'\n | 'confirm_always';\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/** Whether `allowlistCreators` lets this creator be paid: any, when it is empty. */\nfunction allowsCreator(policy: SpendPolicy, creator: string): boolean {\n return (\n policy.allowlistCreators.length === 0 ||\n policy.allowlistCreators.map(normCreator).includes(normCreator(creator))\n );\n}\n\n/** Hard price/creator checks apply in both modes. Manual payments require consent;\n * automatic payments must fit both configured ceilings without prompting. */\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 (!allowsCreator(policy, req.creator)) {\n return {\n decision: 'deny',\n reason: 'not_allowlisted',\n message: `Creator \"${req.creator}\" is not in allowlistCreators.`,\n };\n }\n\n if (req.mode === 'manual') {\n return req.amountAtomic > 0n\n ? {\n decision: 'confirm',\n reason: 'confirm_always',\n message: 'Manual payment requires explicit consent.',\n }\n : { decision: 'allow', reason: 'within_policy', message: 'No payment required.' };\n }\n\n if (policy.sessionBudgetAtomic !== null) {\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: 'deny',\n reason: 'above_auto_spend',\n message: `Price ${req.amountAtomic} is above maxAutoSpend ${policy.maxAutoSpendAtomic}; automatic payment refused.`,\n };\n }\n\n return { decision: 'allow', reason: 'within_policy', message: 'within spend policy' };\n}\n\n/**\n * WHETHER ONE CALL'S PAYMENTS FIT, AS A WHOLE, before any is signed. Every\n * payee meets the allowlist on its own; their TOTAL meets the session budget\n * with what the window already spent, and `maxAutoSpend`, which is the\n * automatic limit for the whole call however many payments it makes. The\n * first refusal is the answer; each payment still meets the gate when it is\n * signed.\n */\nexport function evaluatePlan(\n policy: SpendPolicy,\n payments: readonly { amountAtomic: bigint; creator: string }[],\n sessionSpentAtomic: bigint,\n): PolicyEvaluation {\n const outside = payments.find((payment) => !allowsCreator(policy, payment.creator));\n if (outside !== undefined) {\n return {\n decision: 'deny',\n reason: 'not_allowlisted',\n message: `Creator \"${outside.creator}\" is not in allowlistCreators.`,\n };\n }\n if (payments.length === 0) {\n return { decision: 'allow', reason: 'within_policy', message: 'No payment required.' };\n }\n return evaluateSpendPolicy(policy, {\n mode: 'automatic',\n amountAtomic: payments.reduce((sum, payment) => sum + payment.amountAtomic, 0n),\n creator: payments[0]!.creator,\n sessionSpentAtomic,\n });\n}\n"],"mappings":";;;AAiEA,SAAS,YAAY,OAAuB;AAC1C,SAAO,MAAM,KAAK,EAAE,YAAY;AAClC;AAGA,SAAS,cAAc,QAAqB,SAA0B;AACpE,SACE,OAAO,kBAAkB,WAAW,KACpC,OAAO,kBAAkB,IAAI,WAAW,EAAE,SAAS,YAAY,OAAO,CAAC;AAE3E;AAIO,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;AAEA,MAAI,CAAC,cAAc,QAAQ,IAAI,OAAO,GAAG;AACvC,WAAO;AAAA,MACL,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,SAAS,YAAY,IAAI,OAAO;AAAA,IAClC;AAAA,EACF;AAEA,MAAI,IAAI,SAAS,UAAU;AACzB,WAAO,IAAI,eAAe,KACtB;AAAA,MACE,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,SAAS;AAAA,IACX,IACA,EAAE,UAAU,SAAS,QAAQ,iBAAiB,SAAS,uBAAuB;AAAA,EACpF;AAEA,MAAI,OAAO,wBAAwB,MAAM;AACvC,UAAM,YAAY,IAAI,qBAAqB,IAAI;AAC/C,QAAI,YAAY,OAAO,qBAAqB;AAC1C,aAAO;AAAA,QACL,UAAU;AAAA,QACV,QAAQ;AAAA,QACR,SAAS,+CAA+C,SAAS,wBAAwB,OAAO,mBAAmB;AAAA,MACrH;AAAA,IACF;AAAA,EACF;AAEA,MAAI,IAAI,eAAe,OAAO,oBAAoB;AAChD,WAAO;AAAA,MACL,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,SAAS,SAAS,IAAI,YAAY,0BAA0B,OAAO,kBAAkB;AAAA,IACvF;AAAA,EACF;AAEA,SAAO,EAAE,UAAU,SAAS,QAAQ,iBAAiB,SAAS,sBAAsB;AACtF;AAUO,SAAS,aACd,QACA,UACA,oBACkB;AAClB,QAAM,UAAU,SAAS,KAAK,CAAC,YAAY,CAAC,cAAc,QAAQ,QAAQ,OAAO,CAAC;AAClF,MAAI,YAAY,QAAW;AACzB,WAAO;AAAA,MACL,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,SAAS,YAAY,QAAQ,OAAO;AAAA,IACtC;AAAA,EACF;AACA,MAAI,SAAS,WAAW,GAAG;AACzB,WAAO,EAAE,UAAU,SAAS,QAAQ,iBAAiB,SAAS,uBAAuB;AAAA,EACvF;AACA,SAAO,oBAAoB,QAAQ;AAAA,IACjC,MAAM;AAAA,IACN,cAAc,SAAS,OAAO,CAAC,KAAK,YAAY,MAAM,QAAQ,cAAc,EAAE;AAAA,IAC9E,SAAS,SAAS,CAAC,EAAG;AAAA,IACtB;AAAA,EACF,CAAC;AACH;","names":[]}
|