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
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
writeFileAtomic,
|
|
4
|
+
writeFileAtomicExclusive
|
|
5
|
+
} from "./chunk-O2FRQ2L2.js";
|
|
6
|
+
|
|
7
|
+
// src/router/progress.ts
|
|
8
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
9
|
+
import { constants } from "node:fs";
|
|
10
|
+
import { lstat, open, opendir, rm } from "node:fs/promises";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
var PROGRESS_DIR = "progress";
|
|
13
|
+
var BINDING_PREFIX = "id-";
|
|
14
|
+
var OFFER_PREFIX = "offer-";
|
|
15
|
+
var SESSION_FILE = "session.json";
|
|
16
|
+
var REDIRECT_PREFIX = "redirect-";
|
|
17
|
+
var AUGMENT_PREFIX = "augment-";
|
|
18
|
+
var AUGMENT_BODY_SUFFIX = ".docs";
|
|
19
|
+
var QUERY_PREFIX = "query-";
|
|
20
|
+
var CALL_FILE_RE = /^[a-f0-9]{64}\.json$/;
|
|
21
|
+
var STALE_AFTER_MS = 9e4;
|
|
22
|
+
var RECENT_MS = 1e4;
|
|
23
|
+
var EXPIRY_MS = 10 * 6e4;
|
|
24
|
+
var SESSION_ACTIVE_MS = 10 * 6e4;
|
|
25
|
+
var AUGMENT_REPEAT_MS = 5 * 6e4;
|
|
26
|
+
var MAX_RECORDS = 256;
|
|
27
|
+
var MAX_SESSIONS = 4096;
|
|
28
|
+
var MAX_RECORD_BYTES = 4096;
|
|
29
|
+
var digest = (value) => createHash("sha256").update(value).digest("hex");
|
|
30
|
+
function bounded(value, limit) {
|
|
31
|
+
const chars = Array.from(value);
|
|
32
|
+
return chars.length <= limit ? value : `${chars.slice(0, limit - 1).join("")}\u2026`;
|
|
33
|
+
}
|
|
34
|
+
function sanitize(value, limit) {
|
|
35
|
+
return bounded(
|
|
36
|
+
value.replace(/[\p{Cc}\p{Cf}]/gu, " ").replace(/\s+/g, " ").trim(),
|
|
37
|
+
limit
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
async function clean(value, limit) {
|
|
41
|
+
const { mask } = await import("./redact-6W23GGJC.js");
|
|
42
|
+
return sanitize(mask(value), limit);
|
|
43
|
+
}
|
|
44
|
+
async function endpointOf(value) {
|
|
45
|
+
let url;
|
|
46
|
+
try {
|
|
47
|
+
url = new URL(value);
|
|
48
|
+
} catch {
|
|
49
|
+
return "invalid endpoint";
|
|
50
|
+
}
|
|
51
|
+
if (url.username !== "" || url.password !== "") return "invalid endpoint";
|
|
52
|
+
return clean(`${url.host}${url.pathname === "/" ? "" : url.pathname}`, 110);
|
|
53
|
+
}
|
|
54
|
+
async function parametersOf(value) {
|
|
55
|
+
let json;
|
|
56
|
+
try {
|
|
57
|
+
json = JSON.stringify(value);
|
|
58
|
+
} catch {
|
|
59
|
+
return void 0;
|
|
60
|
+
}
|
|
61
|
+
return json === void 0 ? void 0 : clean(json, 180);
|
|
62
|
+
}
|
|
63
|
+
function sessionDir(dataDir, sessionId) {
|
|
64
|
+
return join(dataDir, PROGRESS_DIR, digest(sessionId));
|
|
65
|
+
}
|
|
66
|
+
function newCallId() {
|
|
67
|
+
return randomUUID();
|
|
68
|
+
}
|
|
69
|
+
async function noteSession(dataDir, sessionId, now = Date.now()) {
|
|
70
|
+
await write(join(sessionDir(dataDir, sessionId), SESSION_FILE), { version: 1, at: now });
|
|
71
|
+
}
|
|
72
|
+
async function bindDecision(dataDir, sessionId, decisionId, now = Date.now()) {
|
|
73
|
+
await write(join(sessionDir(dataDir, sessionId), `${BINDING_PREFIX}${digest(decisionId)}.json`), {
|
|
74
|
+
version: 1,
|
|
75
|
+
at: now
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
async function markOffered(dataDir, sessionId, toolUseId, now = Date.now()) {
|
|
79
|
+
await write(join(sessionDir(dataDir, sessionId), `${OFFER_PREFIX}${digest(toolUseId)}.json`), {
|
|
80
|
+
version: 1,
|
|
81
|
+
at: now
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async function wasOffered(dataDir, sessionId, toolUseId, now = Date.now()) {
|
|
85
|
+
const path = join(sessionDir(dataDir, sessionId), `${OFFER_PREFIX}${digest(toolUseId)}.json`);
|
|
86
|
+
const stamp = await readStamp(path);
|
|
87
|
+
return stamp !== null && now - stamp.at <= EXPIRY_MS;
|
|
88
|
+
}
|
|
89
|
+
async function markAugment(dataDir, sessionId, toolUseId, provider, now = Date.now()) {
|
|
90
|
+
const base = join(sessionDir(dataDir, sessionId), `${AUGMENT_PREFIX}${digest(toolUseId)}`);
|
|
91
|
+
const saved = { version: 1, at: now, provider: sanitize(provider, 60) };
|
|
92
|
+
return await write(`${base}.json`, saved) ? `${base}${AUGMENT_BODY_SUFFIX}` : null;
|
|
93
|
+
}
|
|
94
|
+
async function augmentOf(dataDir, sessionId, toolUseId, now = Date.now()) {
|
|
95
|
+
const base = join(sessionDir(dataDir, sessionId), `${AUGMENT_PREFIX}${digest(toolUseId)}`);
|
|
96
|
+
const row = await readJson(`${base}.json`);
|
|
97
|
+
const stamp = stampOf(row);
|
|
98
|
+
if (row === null || stamp === null || now - stamp.at > EXPIRY_MS) return null;
|
|
99
|
+
const provider = typeof row.provider === "string" ? sanitize(row.provider, 60) : "";
|
|
100
|
+
return { at: stamp.at, provider, body: `${base}${AUGMENT_BODY_SUFFIX}` };
|
|
101
|
+
}
|
|
102
|
+
async function claimQuery(dataDir, sessionId, agentId, query, now = Date.now()) {
|
|
103
|
+
const key = digest(JSON.stringify([agentId ?? "", query]));
|
|
104
|
+
const path = join(sessionDir(dataDir, sessionId), `${QUERY_PREFIX}${key}.json`);
|
|
105
|
+
const stamp = { version: 1, at: now };
|
|
106
|
+
try {
|
|
107
|
+
await writeFileAtomicExclusive(path, JSON.stringify(stamp), { mode: 384, dirMode: 448 });
|
|
108
|
+
return true;
|
|
109
|
+
} catch {
|
|
110
|
+
}
|
|
111
|
+
const last = await readStamp(path);
|
|
112
|
+
if (last === null || now - last.at <= AUGMENT_REPEAT_MS) return false;
|
|
113
|
+
return write(path, stamp);
|
|
114
|
+
}
|
|
115
|
+
function redirectPath(dataDir, sessionId, agentId, target, window) {
|
|
116
|
+
const key = digest(JSON.stringify([agentId ?? "", target, window]));
|
|
117
|
+
return join(sessionDir(dataDir, sessionId), `${REDIRECT_PREFIX}${key}.json`);
|
|
118
|
+
}
|
|
119
|
+
async function claimRedirect(dataDir, sessionId, agentId, target, now = Date.now()) {
|
|
120
|
+
const window = Math.floor(now / EXPIRY_MS);
|
|
121
|
+
const previous = await readStamp(redirectPath(dataDir, sessionId, agentId, target, window - 1));
|
|
122
|
+
if (previous !== null && now - previous.at <= EXPIRY_MS) return false;
|
|
123
|
+
const stamp = { version: 1, at: now };
|
|
124
|
+
try {
|
|
125
|
+
await writeFileAtomicExclusive(
|
|
126
|
+
redirectPath(dataDir, sessionId, agentId, target, window),
|
|
127
|
+
JSON.stringify(stamp),
|
|
128
|
+
{ mode: 384, dirMode: 448 }
|
|
129
|
+
);
|
|
130
|
+
return true;
|
|
131
|
+
} catch {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async function redirectClaimed(dataDir, sessionId, agentId, target, now = Date.now()) {
|
|
136
|
+
const window = Math.floor(now / EXPIRY_MS);
|
|
137
|
+
for (const at of [window, window - 1]) {
|
|
138
|
+
const stamp = await readStamp(redirectPath(dataDir, sessionId, agentId, target, at));
|
|
139
|
+
if (stamp !== null && now - stamp.at <= EXPIRY_MS) return true;
|
|
140
|
+
}
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
async function resolveProgressSession(dataDir, opts = {}) {
|
|
144
|
+
const now = opts.now ?? Date.now();
|
|
145
|
+
const root = join(dataDir, PROGRESS_DIR);
|
|
146
|
+
let names;
|
|
147
|
+
try {
|
|
148
|
+
const directory = await opendir(root);
|
|
149
|
+
names = [];
|
|
150
|
+
for await (const entry of directory) {
|
|
151
|
+
if (entry.isDirectory() && /^[a-f0-9]{64}$/.test(entry.name)) names.push(entry.name);
|
|
152
|
+
if (names.length >= MAX_SESSIONS) break;
|
|
153
|
+
}
|
|
154
|
+
} catch {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
if (opts.id !== void 0 && opts.id.length > 0) {
|
|
158
|
+
const marker = `${BINDING_PREFIX}${digest(opts.id)}.json`;
|
|
159
|
+
for (const name of names) {
|
|
160
|
+
const bound = await readStamp(join(root, name, marker));
|
|
161
|
+
if (bound !== null && now - bound.at <= EXPIRY_MS) return join(root, name);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const live = [];
|
|
165
|
+
for (const name of names) {
|
|
166
|
+
const touched = await readStamp(join(root, name, SESSION_FILE));
|
|
167
|
+
if (touched !== null && now - touched.at <= SESSION_ACTIVE_MS) live.push(name);
|
|
168
|
+
if (live.length > 1) return null;
|
|
169
|
+
}
|
|
170
|
+
return live.length === 1 ? join(root, live[0]) : null;
|
|
171
|
+
}
|
|
172
|
+
async function writeProgress(directory, callId, step, now = Date.now()) {
|
|
173
|
+
const endpoint = step.provider === void 0 ? void 0 : await endpointOf(step.provider);
|
|
174
|
+
const parameters = step.parameters === void 0 ? void 0 : await parametersOf(step.parameters);
|
|
175
|
+
const saved = {
|
|
176
|
+
version: 1,
|
|
177
|
+
at: now,
|
|
178
|
+
phase: step.phase,
|
|
179
|
+
operation: sanitize(step.operation ?? "request", 24) || "request",
|
|
180
|
+
...step.outcome !== void 0 ? { outcome: sanitize(step.outcome, 40) } : {},
|
|
181
|
+
...endpoint !== void 0 ? { endpoint } : {},
|
|
182
|
+
...parameters !== void 0 ? { parameters } : {},
|
|
183
|
+
...step.price !== void 0 ? { price: sanitize(step.price, 24) } : {}
|
|
184
|
+
};
|
|
185
|
+
await write(join(directory, `${digest(callId)}.json`), saved);
|
|
186
|
+
}
|
|
187
|
+
var SILENT_FOOTER = {
|
|
188
|
+
routing: async () => void 0,
|
|
189
|
+
calling: async () => void 0,
|
|
190
|
+
done: async () => void 0
|
|
191
|
+
};
|
|
192
|
+
async function openLookupFooter(dataDir, opts = {}) {
|
|
193
|
+
const now = opts.now ?? Date.now;
|
|
194
|
+
const directory = await resolveProgressSession(dataDir, {
|
|
195
|
+
...opts.id !== void 0 ? { id: opts.id } : {},
|
|
196
|
+
now: now()
|
|
197
|
+
}).catch(() => null);
|
|
198
|
+
if (directory === null) return SILENT_FOOTER;
|
|
199
|
+
const callId = newCallId();
|
|
200
|
+
const operation = opts.operation ?? "request";
|
|
201
|
+
const step = async (patch) => {
|
|
202
|
+
await writeProgress(directory, callId, { operation, ...patch }, now());
|
|
203
|
+
};
|
|
204
|
+
return {
|
|
205
|
+
routing: async () => {
|
|
206
|
+
await step({ phase: "routing" });
|
|
207
|
+
await pruneProgress(directory, now());
|
|
208
|
+
},
|
|
209
|
+
calling: async (calling) => step({ phase: "calling", ...calling }),
|
|
210
|
+
done: async (outcome, detail) => step({ phase: "done", outcome, ...detail })
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
async function pruneProgress(directory, now = Date.now()) {
|
|
214
|
+
try {
|
|
215
|
+
const dir = await opendir(directory);
|
|
216
|
+
let count = 0;
|
|
217
|
+
for await (const entry of dir) {
|
|
218
|
+
if (++count > MAX_RECORDS) return;
|
|
219
|
+
if (!entry.isFile() || entry.name === SESSION_FILE) continue;
|
|
220
|
+
const path = join(directory, entry.name);
|
|
221
|
+
const record = agesByMtime(entry.name) ? await mtimeOf(path) : await readStamp(path);
|
|
222
|
+
if (record === null || now - record.at > EXPIRY_MS) {
|
|
223
|
+
await rm(path, { force: true }).catch(() => void 0);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
} catch {
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
function agesByMtime(name) {
|
|
230
|
+
return name.startsWith(".") || name.startsWith(AUGMENT_PREFIX) && !name.endsWith(".json");
|
|
231
|
+
}
|
|
232
|
+
async function mtimeOf(path) {
|
|
233
|
+
try {
|
|
234
|
+
return { version: 1, at: (await lstat(path)).mtimeMs };
|
|
235
|
+
} catch {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async function pruneSessions(dataDir, now = Date.now()) {
|
|
240
|
+
const root = join(dataDir, PROGRESS_DIR);
|
|
241
|
+
try {
|
|
242
|
+
const directory = await opendir(root);
|
|
243
|
+
let seen = 0;
|
|
244
|
+
for await (const entry of directory) {
|
|
245
|
+
if (++seen > MAX_SESSIONS) return;
|
|
246
|
+
if (!entry.isDirectory() || !/^[a-f0-9]{64}$/.test(entry.name)) continue;
|
|
247
|
+
const path = join(root, entry.name);
|
|
248
|
+
const session = await readStamp(join(path, SESSION_FILE));
|
|
249
|
+
if (session !== null && now - session.at <= SESSION_ACTIVE_MS) continue;
|
|
250
|
+
if (await hasLiveRecord(path, now)) continue;
|
|
251
|
+
await rm(path, { recursive: true, force: true }).catch(() => void 0);
|
|
252
|
+
}
|
|
253
|
+
} catch {
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
async function hasLiveRecord(directory, now) {
|
|
257
|
+
try {
|
|
258
|
+
const dir = await opendir(directory);
|
|
259
|
+
let count = 0;
|
|
260
|
+
for await (const entry of dir) {
|
|
261
|
+
if (++count > MAX_RECORDS) return true;
|
|
262
|
+
if (!entry.isFile() || entry.name === SESSION_FILE) continue;
|
|
263
|
+
const record = await readStamp(join(directory, entry.name));
|
|
264
|
+
if (record !== null && now - record.at <= EXPIRY_MS) return true;
|
|
265
|
+
}
|
|
266
|
+
} catch {
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
async function renderProgress(dataDir, sessionId, options = {}) {
|
|
272
|
+
const now = options.now ?? Date.now();
|
|
273
|
+
const columns = Math.max(45, Math.min(400, options.columns || 160));
|
|
274
|
+
const directory = sessionDir(dataDir, sessionId);
|
|
275
|
+
const records = [];
|
|
276
|
+
try {
|
|
277
|
+
const dir = await opendir(directory);
|
|
278
|
+
let count = 0;
|
|
279
|
+
for await (const entry of dir) {
|
|
280
|
+
if (++count > MAX_RECORDS) return bounded("x402 \xB7 activity exceeds display limit", columns);
|
|
281
|
+
if (!entry.isFile() || !CALL_FILE_RE.test(entry.name)) continue;
|
|
282
|
+
const record = await readCall(join(directory, entry.name));
|
|
283
|
+
if (record !== null && now - record.at <= EXPIRY_MS) records.push(record);
|
|
284
|
+
}
|
|
285
|
+
} catch (error) {
|
|
286
|
+
return error.code === "ENOENT" ? READY : "";
|
|
287
|
+
}
|
|
288
|
+
const running = records.filter((row) => row.phase !== "done" && now - row.at <= holdMs(row)).sort((a, b) => b.at - a.at);
|
|
289
|
+
const stale = records.filter(
|
|
290
|
+
(row) => row.phase !== "done" && now - row.at > holdMs(row) && row.operation === "request"
|
|
291
|
+
);
|
|
292
|
+
const finished = records.filter((row) => row.phase === "done" && now - row.at <= RECENT_MS).sort((a, b) => b.at - a.at);
|
|
293
|
+
const head = running[0] ?? finished[0] ?? stale.sort((a, b) => b.at - a.at)[0];
|
|
294
|
+
if (head === void 0) return READY;
|
|
295
|
+
const alsoRunning = running.length - (running[0] === head ? 1 : 0);
|
|
296
|
+
const suffix = alsoRunning > 0 ? ` \xB7 +${alsoRunning} more` : "";
|
|
297
|
+
return bounded(`${line(head, now)}${suffix}`, columns);
|
|
298
|
+
}
|
|
299
|
+
var READY = "x402 \xB7 ready";
|
|
300
|
+
function holdMs(row) {
|
|
301
|
+
return row.phase !== "done" && row.operation === "request" ? STALE_AFTER_MS : RECENT_MS;
|
|
302
|
+
}
|
|
303
|
+
function line(row, now) {
|
|
304
|
+
const operation = sanitize(row.operation, 24) || "request";
|
|
305
|
+
if (row.phase !== "done" && now - row.at > STALE_AFTER_MS) {
|
|
306
|
+
return `x402 \xB7 ${operation}: stale, no outcome recorded`;
|
|
307
|
+
}
|
|
308
|
+
const state = row.phase === "routing" ? sanitize(row.outcome ?? "selecting service", 40) : row.phase === "calling" ? "calling" : sanitize(row.outcome ?? "done", 40);
|
|
309
|
+
return `x402 \xB7 ${operation}: ${state}` + (row.endpoint !== void 0 ? ` ${sanitize(row.endpoint, 110)}` : "") + (row.parameters !== void 0 ? ` \xB7 ${sanitize(row.parameters, 180)}` : "") + (row.price !== void 0 ? ` \xB7 ${sanitize(row.price, 24)}` : "");
|
|
310
|
+
}
|
|
311
|
+
async function write(path, body) {
|
|
312
|
+
try {
|
|
313
|
+
await writeFileAtomic(path, JSON.stringify(body), { mode: 384, dirMode: 448 });
|
|
314
|
+
return true;
|
|
315
|
+
} catch {
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
async function readStamp(path) {
|
|
320
|
+
return stampOf(await readJson(path));
|
|
321
|
+
}
|
|
322
|
+
function stampOf(row) {
|
|
323
|
+
if (row === null) return null;
|
|
324
|
+
return row.version === 1 && typeof row.at === "number" && Number.isFinite(row.at) ? { version: 1, at: row.at } : null;
|
|
325
|
+
}
|
|
326
|
+
async function readCall(path) {
|
|
327
|
+
const row = await readJson(path);
|
|
328
|
+
const stamp = stampOf(row);
|
|
329
|
+
if (row === null || stamp === null || typeof row.operation !== "string") return null;
|
|
330
|
+
if (!["routing", "calling", "done"].includes(row.phase)) return null;
|
|
331
|
+
const optional = ["outcome", "endpoint", "parameters", "price"];
|
|
332
|
+
if (!optional.every((key) => row[key] === void 0 || typeof row[key] === "string")) return null;
|
|
333
|
+
return {
|
|
334
|
+
...stamp,
|
|
335
|
+
phase: row.phase,
|
|
336
|
+
operation: row.operation,
|
|
337
|
+
...Object.fromEntries(
|
|
338
|
+
optional.filter((key) => row[key] !== void 0).map((key) => [key, row[key]])
|
|
339
|
+
)
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
async function readJson(path) {
|
|
343
|
+
const file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW).catch(() => void 0);
|
|
344
|
+
if (file === void 0) return null;
|
|
345
|
+
try {
|
|
346
|
+
if ((await file.stat()).size > MAX_RECORD_BYTES) return null;
|
|
347
|
+
const buffer = Buffer.alloc(MAX_RECORD_BYTES + 1);
|
|
348
|
+
const { bytesRead } = await file.read(buffer, 0, buffer.length, 0);
|
|
349
|
+
if (bytesRead > MAX_RECORD_BYTES) return null;
|
|
350
|
+
const parsed = JSON.parse(buffer.subarray(0, bytesRead).toString("utf8"));
|
|
351
|
+
return parsed === null || typeof parsed !== "object" || Array.isArray(parsed) ? null : parsed;
|
|
352
|
+
} catch {
|
|
353
|
+
return null;
|
|
354
|
+
} finally {
|
|
355
|
+
await file.close().catch(() => void 0);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export {
|
|
360
|
+
sessionDir,
|
|
361
|
+
newCallId,
|
|
362
|
+
noteSession,
|
|
363
|
+
bindDecision,
|
|
364
|
+
markOffered,
|
|
365
|
+
wasOffered,
|
|
366
|
+
markAugment,
|
|
367
|
+
augmentOf,
|
|
368
|
+
claimQuery,
|
|
369
|
+
claimRedirect,
|
|
370
|
+
redirectClaimed,
|
|
371
|
+
writeProgress,
|
|
372
|
+
SILENT_FOOTER,
|
|
373
|
+
openLookupFooter,
|
|
374
|
+
pruneProgress,
|
|
375
|
+
pruneSessions,
|
|
376
|
+
renderProgress
|
|
377
|
+
};
|
|
378
|
+
//# sourceMappingURL=chunk-U6YQ6FRI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/router/progress.ts"],"sourcesContent":["import { createHash, randomUUID } from 'node:crypto';\nimport { constants } from 'node:fs';\nimport { lstat, open, opendir, rm } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { writeFileAtomic, writeFileAtomicExclusive } from '../lib/atomic-json';\n\n/**\n * The live status line's evidence: what this session is looking up right now,\n * which provider is actually being called, and what it cost.\n *\n * DISPLAY ONLY, AND STRICTLY DOWNSTREAM. Nothing here is read by the gate, the\n * decision, the spend policy or the paying leg; every write is best effort and\n * every failure is swallowed, so a full disk or a read-only data dir loses the\n * footer and changes no routing or payment outcome. That is the whole contract\n * this module has to keep. Two markers are read back by the hooks, the offer\n * mark and the redirect claims, and both only ever make a hook say less: losing\n * either routes a call exactly as a session with no record would, and a claim\n * that cannot be written denies nothing. The free-docs\n * records are the same kind: a lost augment marker is a search with no docs\n * added, and a lost query claim is one more free fetch.\n *\n * KEYED TO THE SESSION, NEVER GUESSED FROM IT. A record lives under the SHA-256\n * of the harness's own `session_id`, so the renderer for one session cannot see\n * another's. The hook knows that id; the tool, which runs inside the MCP server\n * process, does not, so it resolves the session in one of exactly two ways:\n *\n * - BY BINDING. An `execute` decision leaves an `id-<hash>.json` marker in the\n * session that produced it, and the model passes that id back on the tool\n * call. Resolving through the marker is proof, not inference.\n * - BY SOLE ACTIVITY. With no id, the request belongs to the only session that\n * has been active recently, and when two have been, it belongs to neither as\n * far as this module is concerned: {@link resolveProgressSession} returns\n * null and nothing is written. A missing footer is the correct failure;\n * showing one session's lookup in another session's terminal is not.\n */\n\nconst PROGRESS_DIR = 'progress';\n/** The binding marker's prefix, so it can never be read back as a call record. */\nconst BINDING_PREFIX = 'id-';\n/** A pre-call redirect's marker, keyed by the harness's `tool_use_id`. */\nconst OFFER_PREFIX = 'offer-';\n/** The session's own liveness touch, likewise outside the call-record pattern. */\nconst SESSION_FILE = 'session.json';\n/** A pre-call redirect, one file per agent and target in the session. */\nconst REDIRECT_PREFIX = 'redirect-';\n/** A search the pre-call hook is adding free docs to, keyed by its `tool_use_id`. */\nconst AUGMENT_PREFIX = 'augment-';\n/** What the docs prefetch got, beside its marker. The provider's text sets its\n * size, so it is never read as a record: it ages by its mtime. */\nconst AUGMENT_BODY_SUFFIX = '.docs';\n/** One agent's search query that was augmented, so the same one is not fetched twice. */\nconst QUERY_PREFIX = 'query-';\n/** Call records are named by a 64-hex digest and nothing else is read as one. */\nconst CALL_FILE_RE = /^[a-f0-9]{64}\\.json$/;\n\n/** An in-flight call older than this is shown as stale, never as running. */\nexport const STALE_AFTER_MS = 90_000;\n/**\n * How long a state stays on the footer once nothing has replaced it. The demo\n * holds each one for about ten seconds, which is what makes a decision that\n * takes a second readable at a one-second refresh; after that the line is\n * `x402 · ready` again.\n */\nexport const RECENT_MS = 10_000;\n/** Older than this and a record is ignored by the renderer and pruned on write. */\nexport const EXPIRY_MS = 10 * 60_000;\n/** How recently a session must have been touched to claim an id-less request. */\nexport const SESSION_ACTIVE_MS = 10 * 60_000;\n/** How long one agent's identical search is not given the same docs again. */\nexport const AUGMENT_REPEAT_MS = 5 * 60_000;\n/** Above this many files a session directory is reported rather than scanned. */\nconst MAX_RECORDS = 256;\n/** A ceiling on the root scan. {@link pruneSessions} keeps it far below this:\n * a directory is one LIVE session, not one session this machine ever had. */\nconst MAX_SESSIONS = 4_096;\n/** A record larger than this is damaged or not ours; it is skipped unread. */\nconst MAX_RECORD_BYTES = 4_096;\n\nexport type ProgressPhase = 'routing' | 'calling' | 'done';\n\n/** The two markers: a session's liveness touch and a decision-id binding. */\ninterface Stamp {\n version: 1;\n at: number;\n}\n\n/** What one call looks like on disk. Every string is already masked and bounded. */\ninterface SavedProgress extends Stamp {\n phase: ProgressPhase;\n /** The tool whose activity this is, as the footer names it. */\n operation: string;\n /** What the state SAYS: the outcome on `done`, and on an in-flight record the\n * stage, when it is not the tool's own `selecting service`. */\n outcome?: string;\n /** Host plus path of the provider actually called, without a scheme. */\n endpoint?: string;\n /** The call's parameters as compact JSON. */\n parameters?: string;\n /** What the provider was paid, as USD. */\n price?: string;\n}\n\n/** A search being given free docs, and whose docs they are. */\ninterface SavedAugment extends Stamp {\n provider: string;\n}\n\nexport interface ProgressStep {\n phase: ProgressPhase;\n operation?: string;\n outcome?: string;\n /** The executed provider's URL. It can differ from the hint's suggestion. */\n provider?: string;\n parameters?: unknown;\n price?: string;\n}\n\nconst digest = (value: string): string => createHash('sha256').update(value).digest('hex');\n\nfunction bounded(value: string, limit: number): string {\n const chars = Array.from(value);\n return chars.length <= limit ? value : `${chars.slice(0, limit - 1).join('')}…`;\n}\n\n/**\n * Provider text reaches a terminal here, so it is treated as hostile: control\n * characters, format characters and directional overrides are replaced before\n * anything is written, and again before anything is printed. A footer that can\n * be made to repaint the line above it is a spoofing surface, not a display.\n */\nexport function sanitize(value: string, limit: number): string {\n return bounded(\n value\n .replace(/[\\p{Cc}\\p{Cf}]/gu, ' ')\n .replace(/\\s+/g, ' ')\n .trim(),\n limit,\n );\n}\n\n/**\n * The CLI's own redaction, behind a dynamic import ON PURPOSE: the rule corpus\n * and the BIP-39 wordlist are a real parse cost, the renderer runs once a\n * second, and only the write path needs them. `dist-chunks.test.ts` pins it.\n */\nasync function clean(value: string, limit: number): Promise<string> {\n const { mask } = await import('../lib/redact');\n return sanitize(mask(value), limit);\n}\n\n/** Host plus path, which is what names a provider to a person watching. */\nasync function endpointOf(value: string): Promise<string> {\n let url: URL;\n try {\n url = new URL(value);\n } catch {\n return 'invalid endpoint';\n }\n if (url.username !== '' || url.password !== '') return 'invalid endpoint';\n return clean(`${url.host}${url.pathname === '/' ? '' : url.pathname}`, 110);\n}\n\nasync function parametersOf(value: unknown): Promise<string | undefined> {\n let json: string | undefined;\n try {\n json = JSON.stringify(value);\n } catch {\n return undefined;\n }\n return json === undefined ? undefined : clean(json, 180);\n}\n\nexport function sessionDir(dataDir: string, sessionId: string): string {\n return join(dataDir, PROGRESS_DIR, digest(sessionId));\n}\n\n/** A fresh key for one call, so two overlapping lookups never share a record. */\nexport function newCallId(): string {\n return randomUUID();\n}\n\n/**\n * Mark this session live, so an id-less tool call made from it can be\n * attributed. Written on every hook event, including the ones that route\n * nothing: an open session has to be distinguishable from a closed one.\n */\nexport async function noteSession(\n dataDir: string,\n sessionId: string,\n now = Date.now(),\n): Promise<void> {\n await write(join(sessionDir(dataDir, sessionId), SESSION_FILE), { version: 1, at: now });\n}\n\n/** Record that this decision id was produced in this session. */\nexport async function bindDecision(\n dataDir: string,\n sessionId: string,\n decisionId: string,\n now = Date.now(),\n): Promise<void> {\n await write(join(sessionDir(dataDir, sessionId), `${BINDING_PREFIX}${digest(decisionId)}.json`), {\n version: 1,\n at: now,\n });\n}\n\n/**\n * ONE ROUTING ANSWER PER LOOKUP. The pre-call hook marks the native call it\n * redirected, by the harness's own `tool_use_id`, and the after-call hook reads\n * the mark before it asks again about the same call. Expires and is pruned like every\n * other record here.\n */\nexport async function markOffered(\n dataDir: string,\n sessionId: string,\n toolUseId: string,\n now = Date.now(),\n): Promise<void> {\n await write(join(sessionDir(dataDir, sessionId), `${OFFER_PREFIX}${digest(toolUseId)}.json`), {\n version: 1,\n at: now,\n });\n}\n\nexport async function wasOffered(\n dataDir: string,\n sessionId: string,\n toolUseId: string,\n now = Date.now(),\n): Promise<boolean> {\n const path = join(sessionDir(dataDir, sessionId), `${OFFER_PREFIX}${digest(toolUseId)}.json`);\n const stamp = await readStamp(path);\n return stamp !== null && now - stamp.at <= EXPIRY_MS;\n}\n\n/**\n * FREE DOCS BESIDE A SEARCH. The pre-call hook marks the search it let run with\n * a free offer, by the harness's own `tool_use_id` and with the provider's name\n * for the line the after-call hook writes, and returns where the prefetch puts\n * what it got: beside the marker, under the same key. Null when the marker could\n * not be written, since nothing could then find the body.\n */\nexport async function markAugment(\n dataDir: string,\n sessionId: string,\n toolUseId: string,\n provider: string,\n now = Date.now(),\n): Promise<string | null> {\n const base = join(sessionDir(dataDir, sessionId), `${AUGMENT_PREFIX}${digest(toolUseId)}`);\n const saved: SavedAugment = { version: 1, at: now, provider: sanitize(provider, 60) };\n return (await write(`${base}.json`, saved)) ? `${base}${AUGMENT_BODY_SUFFIX}` : null;\n}\n\n/** The marker {@link markAugment} left for this call, or null when it left none. */\nexport async function augmentOf(\n dataDir: string,\n sessionId: string,\n toolUseId: string,\n now = Date.now(),\n): Promise<{ at: number; provider: string; body: string } | null> {\n const base = join(sessionDir(dataDir, sessionId), `${AUGMENT_PREFIX}${digest(toolUseId)}`);\n const row = await readJson(`${base}.json`);\n const stamp = stampOf(row);\n if (row === null || stamp === null || now - stamp.at > EXPIRY_MS) return null;\n const provider = typeof row.provider === 'string' ? sanitize(row.provider, 60) : '';\n return { at: stamp.at, provider, body: `${base}${AUGMENT_BODY_SUFFIX}` };\n}\n\n/**\n * ONE FETCH PER QUERY. True when this agent has not had this exact search\n * augmented in the last {@link AUGMENT_REPEAT_MS}, and the claim is now its:\n * the create is exclusive, so two parallel copies of one search fetch once.\n */\nexport async function claimQuery(\n dataDir: string,\n sessionId: string,\n agentId: string | undefined,\n query: string,\n now = Date.now(),\n): Promise<boolean> {\n const key = digest(JSON.stringify([agentId ?? '', query]));\n const path = join(sessionDir(dataDir, sessionId), `${QUERY_PREFIX}${key}.json`);\n const stamp: Stamp = { version: 1, at: now };\n try {\n await writeFileAtomicExclusive(path, JSON.stringify(stamp), { mode: 0o600, dirMode: 0o700 });\n return true;\n } catch {\n // Taken: by a recent search, which wins, or by an old one, which does not.\n }\n const last = await readStamp(path);\n if (last === null || now - last.at <= AUGMENT_REPEAT_MS) return false;\n return write(path, stamp);\n}\n\n/**\n * ONE RECORD PER AGENT, TARGET AND WINDOW. Subagents share the session id, so\n * the agent is in the key, and the main agent's part is the empty string, which\n * no `agent_id` can be: the decoder refuses an empty one. The target is in it\n * too, one file each, so parallel calls never share a record: one call's\n * redirect can be neither overwritten nor spent by another's. And so is the\n * {@link EXPIRY_MS} window the claim was made in, so a claim is only ever\n * created, never replaced: see {@link claimRedirect}.\n */\nfunction redirectPath(\n dataDir: string,\n sessionId: string,\n agentId: string | undefined,\n target: string,\n window: number,\n): string {\n const key = digest(JSON.stringify([agentId ?? '', target, window]));\n return join(sessionDir(dataDir, sessionId), `${REDIRECT_PREFIX}${key}.json`);\n}\n\n/**\n * NEVER REDIRECTED TWICE FOR ONE TARGET. True, once, when this agent has not\n * been redirected on this exact search or URL in the last {@link EXPIRY_MS},\n * and the claim is now its; the pre-call hook denies only on true. So the\n * agent's own retry of a redirected call runs, whether the lookup it was sent\n * to delivered, failed or was never called, and whatever other calls ran in\n * between.\n *\n * ONLY EVER AN EXCLUSIVE CREATE. Replacing an expired claim let two parallel\n * copies of one call both read the old stamp and both write, and both deny.\n * The claim's file is named by its window instead, so the one create per\n * window decides, and the previous window's claim, while it is still inside\n * {@link EXPIRY_MS}, is read and never touched: a claim made just before a\n * boundary still lasts its full span. A claim that cannot be written is false:\n * the call runs.\n */\nexport async function claimRedirect(\n dataDir: string,\n sessionId: string,\n agentId: string | undefined,\n target: string,\n now = Date.now(),\n): Promise<boolean> {\n const window = Math.floor(now / EXPIRY_MS);\n const previous = await readStamp(redirectPath(dataDir, sessionId, agentId, target, window - 1));\n if (previous !== null && now - previous.at <= EXPIRY_MS) return false;\n const stamp: Stamp = { version: 1, at: now };\n try {\n await writeFileAtomicExclusive(\n redirectPath(dataDir, sessionId, agentId, target, window),\n JSON.stringify(stamp),\n { mode: 0o600, dirMode: 0o700 },\n );\n return true;\n } catch {\n // Taken in this window, which is always inside EXPIRY_MS, or not writable.\n return false;\n }\n}\n\n/**\n * THE READ HALF OF {@link claimRedirect}: true when this agent already holds a\n * live claim on this exact search or URL. The pre-call arms ask it BEFORE the\n * router, so the retry of a call they already redirected, which they would\n * only withhold, costs no decision and leaves no offer nobody sees. It never\n * writes and never decides on its own: a false here still goes through the\n * exclusive create, which is what keeps two parallel copies to one deny.\n */\nexport async function redirectClaimed(\n dataDir: string,\n sessionId: string,\n agentId: string | undefined,\n target: string,\n now = Date.now(),\n): Promise<boolean> {\n const window = Math.floor(now / EXPIRY_MS);\n for (const at of [window, window - 1]) {\n const stamp = await readStamp(redirectPath(dataDir, sessionId, agentId, target, at));\n if (stamp !== null && now - stamp.at <= EXPIRY_MS) return true;\n }\n return false;\n}\n\n/**\n * Which session directory a tool call belongs to, or null for \"cannot tell\".\n * Null is a normal answer and its only consequence is a footer that stays quiet.\n */\nexport async function resolveProgressSession(\n dataDir: string,\n opts: { id?: string; now?: number } = {},\n): Promise<string | null> {\n const now = opts.now ?? Date.now();\n const root = join(dataDir, PROGRESS_DIR);\n let names: string[];\n try {\n const directory = await opendir(root);\n names = [];\n for await (const entry of directory) {\n if (entry.isDirectory() && /^[a-f0-9]{64}$/.test(entry.name)) names.push(entry.name);\n if (names.length >= MAX_SESSIONS) break;\n }\n } catch {\n return null;\n }\n if (opts.id !== undefined && opts.id.length > 0) {\n const marker = `${BINDING_PREFIX}${digest(opts.id)}.json`;\n for (const name of names) {\n const bound = await readStamp(join(root, name, marker));\n if (bound !== null && now - bound.at <= EXPIRY_MS) return join(root, name);\n }\n // A stale or unknown id says nothing about which session asked, so the\n // sole-activity rule below still applies rather than a wrong attribution.\n }\n const live: string[] = [];\n for (const name of names) {\n const touched = await readStamp(join(root, name, SESSION_FILE));\n if (touched !== null && now - touched.at <= SESSION_ACTIVE_MS) live.push(name);\n if (live.length > 1) return null;\n }\n return live.length === 1 ? join(root, live[0] as string) : null;\n}\n\n/**\n * Record one step of one call. The caller holds the directory (from\n * {@link sessionDir} or {@link resolveProgressSession}) and the call id, so a\n * step never has to re-resolve anything on the hot path.\n */\nexport async function writeProgress(\n directory: string,\n callId: string,\n step: ProgressStep,\n now = Date.now(),\n): Promise<void> {\n const endpoint = step.provider === undefined ? undefined : await endpointOf(step.provider);\n const parameters =\n step.parameters === undefined ? undefined : await parametersOf(step.parameters);\n const saved: SavedProgress = {\n version: 1,\n at: now,\n phase: step.phase,\n operation: sanitize(step.operation ?? 'request', 24) || 'request',\n ...(step.outcome !== undefined ? { outcome: sanitize(step.outcome, 40) } : {}),\n ...(endpoint !== undefined ? { endpoint } : {}),\n ...(parameters !== undefined ? { parameters } : {}),\n ...(step.price !== undefined ? { price: sanitize(step.price, 24) } : {}),\n };\n await write(join(directory, `${digest(callId)}.json`), saved);\n}\n\nexport interface LookupFooter {\n /** A decision is in flight. */\n routing(): Promise<void>;\n /** The EXECUTED provider, which can differ from what the hint suggested. */\n calling(step: { provider: string; parameters?: unknown }): Promise<void>;\n /** The outcome, and what the provider was paid for it. */\n done(\n outcome: string,\n step?: { provider?: string; parameters?: unknown; price?: string },\n ): Promise<void>;\n}\n\n/** A footer for a session this call cannot be attributed to, or for one step\n * of a call whose own footer speaks for it: it writes nothing. */\nexport const SILENT_FOOTER: LookupFooter = {\n routing: async () => undefined,\n calling: async () => undefined,\n done: async () => undefined,\n};\n\n/**\n * The `request` tool's footer: the session is resolved ONCE, at the top of the\n * call, and each later step is one small write. An unresolvable session yields\n * {@link SILENT_FOOTER}, and the lookup runs exactly as it would have.\n */\nexport async function openLookupFooter(\n dataDir: string,\n opts: { id?: string; operation?: string; now?: () => number } = {},\n): Promise<LookupFooter> {\n const now = opts.now ?? Date.now;\n const directory = await resolveProgressSession(dataDir, {\n ...(opts.id !== undefined ? { id: opts.id } : {}),\n now: now(),\n }).catch(() => null);\n if (directory === null) return SILENT_FOOTER;\n const callId = newCallId();\n const operation = opts.operation ?? 'request';\n const step = async (patch: ProgressStep): Promise<void> => {\n await writeProgress(directory, callId, { operation, ...patch }, now());\n };\n return {\n routing: async () => {\n await step({ phase: 'routing' });\n await pruneProgress(directory, now());\n },\n calling: async (calling) => step({ phase: 'calling', ...calling }),\n done: async (outcome, detail) => step({ phase: 'done', outcome, ...detail }),\n };\n}\n\n/**\n * Remove records past {@link EXPIRY_MS}. Run from a writer, never from the\n * renderer: the footer refreshes once a second and must stay read-only.\n */\nexport async function pruneProgress(directory: string, now = Date.now()): Promise<void> {\n try {\n const dir = await opendir(directory);\n let count = 0;\n for await (const entry of dir) {\n if (++count > MAX_RECORDS) return;\n if (!entry.isFile() || entry.name === SESSION_FILE) continue;\n const path = join(directory, entry.name);\n const record = agesByMtime(entry.name) ? await mtimeOf(path) : await readStamp(path);\n if (record === null || now - record.at > EXPIRY_MS) {\n await rm(path, { force: true }).catch(() => undefined);\n }\n }\n } catch {\n // Housekeeping only. Nothing downstream depends on it having run.\n }\n}\n\n/**\n * A FILE THAT IS NOT A WHOLE RECORD is aged by its mtime, never read as one: a\n * temp file between its write and its rename (every writer here names them\n * `.<name>.<suffix>`), and a docs body, whose size is the provider's. Read as\n * records they are damaged, and the prune deleted them out from under a\n * parallel hook's rename.\n */\nfunction agesByMtime(name: string): boolean {\n return name.startsWith('.') || (name.startsWith(AUGMENT_PREFIX) && !name.endsWith('.json'));\n}\n\nasync function mtimeOf(path: string): Promise<Stamp | null> {\n try {\n return { version: 1, at: (await lstat(path)).mtimeMs };\n } catch {\n return null;\n }\n}\n\n/**\n * Remove the directories of sessions that are over.\n *\n * WITHOUT THIS THE ROOT ONLY GROWS, one directory per session this machine has\n * ever had, and a root big enough to hit {@link MAX_SESSIONS} would leave\n * {@link resolveProgressSession} scanning an arbitrary subset that need not\n * contain the session asking. Run from the hook, which is the one writer that\n * fires on every turn; a directory whose session is still live is never touched.\n */\nexport async function pruneSessions(dataDir: string, now = Date.now()): Promise<void> {\n const root = join(dataDir, PROGRESS_DIR);\n try {\n const directory = await opendir(root);\n let seen = 0;\n for await (const entry of directory) {\n if (++seen > MAX_SESSIONS) return;\n if (!entry.isDirectory() || !/^[a-f0-9]{64}$/.test(entry.name)) continue;\n const path = join(root, entry.name);\n const session = await readStamp(join(path, SESSION_FILE));\n if (session !== null && now - session.at <= SESSION_ACTIVE_MS) continue;\n // The touch is gone or old, so the only thing that can keep this\n // directory is a record still inside the renderer's window.\n if (await hasLiveRecord(path, now)) continue;\n await rm(path, { recursive: true, force: true }).catch(() => undefined);\n }\n } catch {\n // Housekeeping only. Nothing downstream depends on it having run.\n }\n}\n\nasync function hasLiveRecord(directory: string, now: number): Promise<boolean> {\n try {\n const dir = await opendir(directory);\n let count = 0;\n for await (const entry of dir) {\n if (++count > MAX_RECORDS) return true;\n if (!entry.isFile() || entry.name === SESSION_FILE) continue;\n const record = await readStamp(join(directory, entry.name));\n if (record !== null && now - record.at <= EXPIRY_MS) return true;\n }\n } catch {\n return true;\n }\n return false;\n}\n\n/**\n * The footer for one session: one line, bounded, sanitized, and empty of\n * everything but this session's own calls. Read-only by construction.\n */\nexport async function renderProgress(\n dataDir: string,\n sessionId: string,\n options: { now?: number; columns?: number } = {},\n): Promise<string> {\n const now = options.now ?? Date.now();\n // The harness truncates to the real terminal width, and `COLUMNS` rarely\n // survives into a status-line process, so the default is a wide terminal\n // rather than a narrow one: cutting a provider's path off at 80 columns on a\n // 200-column terminal loses exactly the part worth reading.\n const columns = Math.max(45, Math.min(400, options.columns || 160));\n const directory = sessionDir(dataDir, sessionId);\n const records: SavedProgress[] = [];\n try {\n const dir = await opendir(directory);\n let count = 0;\n for await (const entry of dir) {\n if (++count > MAX_RECORDS) return bounded('x402 · activity exceeds display limit', columns);\n if (!entry.isFile() || !CALL_FILE_RE.test(entry.name)) continue;\n const record = await readCall(join(directory, entry.name));\n if (record !== null && now - record.at <= EXPIRY_MS) records.push(record);\n }\n } catch (error) {\n // A SESSION WITH NO DIRECTORY IS IDLE, not broken: it has simply not looked\n // anything up yet, and the router being on is the thing the idle line says.\n // Any OTHER read failure is this display failing, and a display that failed\n // prints nothing rather than a status it did not read.\n return (error as NodeJS.ErrnoException).code === 'ENOENT' ? READY : '';\n }\n const running = records\n .filter((row) => row.phase !== 'done' && now - row.at <= holdMs(row))\n .sort((a, b) => b.at - a.at);\n // Only a LOOKUP goes stale out loud. A hook decision has a five-second budget,\n // so one still in flight after its hold is a dead hook, and the footer says\n // ready rather than naming a stage nothing is working on.\n const stale = records.filter(\n (row) => row.phase !== 'done' && now - row.at > holdMs(row) && row.operation === 'request',\n );\n const finished = records\n .filter((row) => row.phase === 'done' && now - row.at <= RECENT_MS)\n .sort((a, b) => b.at - a.at);\n const head = running[0] ?? finished[0] ?? stale.sort((a, b) => b.at - a.at)[0];\n if (head === undefined) return READY;\n // OVERLAPPING CALLS ARE COUNTED, NOT HIDDEN. The newest running call is the\n // one worth naming; the rest are a count, because a second endpoint and its\n // parameters do not fit a line beside the first.\n const alsoRunning = running.length - (running[0] === head ? 1 : 0);\n const suffix = alsoRunning > 0 ? ` · +${alsoRunning} more` : '';\n return bounded(`${line(head, now)}${suffix}`, columns);\n}\n\n/** What the footer says when this session has nothing running or just finished.\n * It is the visible proof that the router is on, so it is never blank. */\nconst READY = 'x402 · ready';\n\n/**\n * How long this state holds the line. A lookup in flight holds it until it\n * lands, because a provider call can take a minute; everything else holds it\n * for {@link RECENT_MS}, which is how the demo reads: one state per second or\n * so, each one still there when the next arrives.\n */\nfunction holdMs(row: SavedProgress): number {\n return row.phase !== 'done' && row.operation === 'request' ? STALE_AFTER_MS : RECENT_MS;\n}\n\n/**\n * One call, as the footer says it: `x402 · <tool>: <state> <host/path> ·\n * <parameters> · <price>`. Every field is sanitized AGAIN here, because what is\n * on disk is input to this process even when this process wrote it.\n */\nfunction line(row: SavedProgress, now: number): string {\n const operation = sanitize(row.operation, 24) || 'request';\n if (row.phase !== 'done' && now - row.at > STALE_AFTER_MS) {\n return `x402 · ${operation}: stale, no outcome recorded`;\n }\n // `selecting service` is the demo's own word for a decision in flight, and a\n // stage the hook names for itself wins over it.\n const state =\n row.phase === 'routing'\n ? sanitize(row.outcome ?? 'selecting service', 40)\n : row.phase === 'calling'\n ? 'calling'\n : sanitize(row.outcome ?? 'done', 40);\n return (\n `x402 · ${operation}: ${state}` +\n (row.endpoint !== undefined ? ` ${sanitize(row.endpoint, 110)}` : '') +\n (row.parameters !== undefined ? ` · ${sanitize(row.parameters, 180)}` : '') +\n (row.price !== undefined ? ` · ${sanitize(row.price, 24)}` : '')\n );\n}\n\n/** Whether it landed. Every caller but the augment marker ignores the answer. */\nasync function write(path: string, body: Stamp | SavedProgress | SavedAugment): Promise<boolean> {\n try {\n await writeFileAtomic(path, JSON.stringify(body), { mode: 0o600, dirMode: 0o700 });\n return true;\n } catch {\n // The footer is the only thing that can be lost here, by design.\n return false;\n }\n}\n\n/** A marker's timestamp, or null for absent, damaged or not ours. */\nasync function readStamp(path: string): Promise<Stamp | null> {\n return stampOf(await readJson(path));\n}\n\nfunction stampOf(row: Record<string, unknown> | null): Stamp | null {\n if (row === null) return null;\n return row.version === 1 && typeof row.at === 'number' && Number.isFinite(row.at)\n ? { version: 1, at: row.at }\n : null;\n}\n\n/** A call record, or null. Every field is re-checked: what is on disk is input. */\nasync function readCall(path: string): Promise<SavedProgress | null> {\n const row = await readJson(path);\n const stamp = stampOf(row);\n if (row === null || stamp === null || typeof row.operation !== 'string') return null;\n if (!['routing', 'calling', 'done'].includes(row.phase as string)) return null;\n const optional = ['outcome', 'endpoint', 'parameters', 'price'] as const;\n if (!optional.every((key) => row[key] === undefined || typeof row[key] === 'string')) return null;\n return {\n ...stamp,\n phase: row.phase as ProgressPhase,\n operation: row.operation,\n ...Object.fromEntries(\n optional.filter((key) => row[key] !== undefined).map((key) => [key, row[key]]),\n ),\n };\n}\n\n/**\n * One bounded JSON object, or null. `O_NOFOLLOW` because these files live under\n * a directory the user can write: a symlink planted here must not turn a footer\n * read into a read of something else.\n */\nasync function readJson(path: string): Promise<Record<string, unknown> | null> {\n const file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW).catch(() => undefined);\n if (file === undefined) return null;\n try {\n if ((await file.stat()).size > MAX_RECORD_BYTES) return null;\n const buffer = Buffer.alloc(MAX_RECORD_BYTES + 1);\n const { bytesRead } = await file.read(buffer, 0, buffer.length, 0);\n if (bytesRead > MAX_RECORD_BYTES) return null;\n const parsed: unknown = JSON.parse(buffer.subarray(0, bytesRead).toString('utf8'));\n return parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)\n ? null\n : (parsed as Record<string, unknown>);\n } catch {\n return null;\n } finally {\n await file.close().catch(() => undefined);\n }\n}\n"],"mappings":";;;;;;;AAAA,SAAS,YAAY,kBAAkB;AACvC,SAAS,iBAAiB;AAC1B,SAAS,OAAO,MAAM,SAAS,UAAU;AACzC,SAAS,YAAY;AAiCrB,IAAM,eAAe;AAErB,IAAM,iBAAiB;AAEvB,IAAM,eAAe;AAErB,IAAM,eAAe;AAErB,IAAM,kBAAkB;AAExB,IAAM,iBAAiB;AAGvB,IAAM,sBAAsB;AAE5B,IAAM,eAAe;AAErB,IAAM,eAAe;AAGd,IAAM,iBAAiB;AAOvB,IAAM,YAAY;AAElB,IAAM,YAAY,KAAK;AAEvB,IAAM,oBAAoB,KAAK;AAE/B,IAAM,oBAAoB,IAAI;AAErC,IAAM,cAAc;AAGpB,IAAM,eAAe;AAErB,IAAM,mBAAmB;AAyCzB,IAAM,SAAS,CAAC,UAA0B,WAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK;AAEzF,SAAS,QAAQ,OAAe,OAAuB;AACrD,QAAM,QAAQ,MAAM,KAAK,KAAK;AAC9B,SAAO,MAAM,UAAU,QAAQ,QAAQ,GAAG,MAAM,MAAM,GAAG,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC;AAC9E;AAQO,SAAS,SAAS,OAAe,OAAuB;AAC7D,SAAO;AAAA,IACL,MACG,QAAQ,oBAAoB,GAAG,EAC/B,QAAQ,QAAQ,GAAG,EACnB,KAAK;AAAA,IACR;AAAA,EACF;AACF;AAOA,eAAe,MAAM,OAAe,OAAgC;AAClE,QAAM,EAAE,KAAK,IAAI,MAAM,OAAO,sBAAe;AAC7C,SAAO,SAAS,KAAK,KAAK,GAAG,KAAK;AACpC;AAGA,eAAe,WAAW,OAAgC;AACxD,MAAI;AACJ,MAAI;AACF,UAAM,IAAI,IAAI,KAAK;AAAA,EACrB,QAAQ;AACN,WAAO;AAAA,E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MAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC;AAAA,IAC/E;AAAA,EACF;AACF;AAOA,eAAe,SAAS,MAAuD;AAC7E,QAAM,OAAO,MAAM,KAAK,MAAM,UAAU,WAAW,UAAU,UAAU,EAAE,MAAM,MAAM,MAAS;AAC9F,MAAI,SAAS,OAAW,QAAO;AAC/B,MAAI;AACF,SAAK,MAAM,KAAK,KAAK,GAAG,OAAO,iBAAkB,QAAO;AACxD,UAAM,SAAS,OAAO,MAAM,mBAAmB,CAAC;AAChD,UAAM,EAAE,UAAU,IAAI,MAAM,KAAK,KAAK,QAAQ,GAAG,OAAO,QAAQ,CAAC;AACjE,QAAI,YAAY,iBAAkB,QAAO;AACzC,UAAM,SAAkB,KAAK,MAAM,OAAO,SAAS,GAAG,SAAS,EAAE,SAAS,MAAM,CAAC;AACjF,WAAO,WAAW,QAAQ,OAAO,WAAW,YAAY,MAAM,QAAQ,MAAM,IACxE,OACC;AAAA,EACP,QAAQ;AACN,WAAO;AAAA,EACT,UAAE;AACA,UAAM,KAAK,MAAM,EAAE,MAAM,MAAM,MAAS;AAAA,EAC1C;AACF;","names":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
FileClientChannelStorage
|
|
4
|
+
} from "./chunk-YHKXNYTB.js";
|
|
5
|
+
import {
|
|
6
|
+
payerDir
|
|
7
|
+
} from "./chunk-PAYV4XUA.js";
|
|
8
|
+
|
|
9
|
+
// src/router/channel-credit.ts
|
|
10
|
+
import { readdir } from "node:fs/promises";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
async function channelCredit(dataDir, address) {
|
|
13
|
+
const dir = payerDir(dataDir, address);
|
|
14
|
+
const storage = new FileClientChannelStorage({ directory: dir });
|
|
15
|
+
let best = 0n;
|
|
16
|
+
for (const name of await readdir(join(dir, "client")).catch(() => [])) {
|
|
17
|
+
const id = /^(0x[0-9a-f]{64})\.json$/.exec(name)?.[1];
|
|
18
|
+
const channel = id === void 0 ? void 0 : await storage.get(id).catch(() => void 0);
|
|
19
|
+
if (channel === void 0) continue;
|
|
20
|
+
const credit = BigInt(channel.balance ?? "0") - BigInt(channel.chargedCumulativeAmount ?? "0");
|
|
21
|
+
if (credit > best) best = credit;
|
|
22
|
+
}
|
|
23
|
+
return best;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
channelCredit
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=chunk-VFMQTSXG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/router/channel-credit.ts"],"sourcesContent":["import { readdir } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { FileClientChannelStorage } from '@x402/evm/batch-settlement/client/file-storage';\nimport { payerDir } from './fee';\n\n/**\n * What the wallet's routing channel still holds for fees, from the SDK's own\n * files: what was deposited less what the router has charged against it. It is\n * the prepaid routing credit `tenjin status` and `tenjin wallet balance` show,\n * and what `tenjin doctor` reads to know whether the next call needs a deposit.\n *\n * Not hook-safe (it loads the x402 SDK's storage), so `fee.ts` does not carry it.\n */\nexport async function channelCredit(dataDir: string, address: string): Promise<bigint> {\n const dir = payerDir(dataDir, address);\n const storage = new FileClientChannelStorage({ directory: dir });\n let best = 0n;\n for (const name of await readdir(join(dir, 'client')).catch(() => [] as string[])) {\n const id = /^(0x[0-9a-f]{64})\\.json$/.exec(name)?.[1];\n const channel = id === undefined ? undefined : await storage.get(id).catch(() => undefined);\n if (channel === undefined) continue;\n const credit = BigInt(channel.balance ?? '0') - BigInt(channel.chargedCumulativeAmount ?? '0');\n if (credit > best) best = credit;\n }\n return best;\n}\n"],"mappings":";;;;;;;;;AAAA,SAAS,eAAe;AACxB,SAAS,YAAY;AAYrB,eAAsB,cAAc,SAAiB,SAAkC;AACrF,QAAM,MAAM,SAAS,SAAS,OAAO;AACrC,QAAM,UAAU,IAAI,yBAAyB,EAAE,WAAW,IAAI,CAAC;AAC/D,MAAI,OAAO;AACX,aAAW,QAAQ,MAAM,QAAQ,KAAK,KAAK,QAAQ,CAAC,EAAE,MAAM,MAAM,CAAC,CAAa,GAAG;AACjF,UAAM,KAAK,2BAA2B,KAAK,IAAI,IAAI,CAAC;AACpD,UAAM,UAAU,OAAO,SAAY,SAAY,MAAM,QAAQ,IAAI,EAAE,EAAE,MAAM,MAAM,MAAS;AAC1F,QAAI,YAAY,OAAW;AAC3B,UAAM,SAAS,OAAO,QAAQ,WAAW,GAAG,IAAI,OAAO,QAAQ,2BAA2B,GAAG;AAC7F,QAAI,SAAS,KAAM,QAAO;AAAA,EAC5B;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// package.json
|
|
4
|
+
var name = "tenjin-cli";
|
|
5
|
+
var version = "0.1.0-alpha.30";
|
|
6
|
+
var type = "module";
|
|
7
|
+
var description = "The tool router for coding agents. Tenjin picks the right tool when your agent needs one, and one wallet pays for every call.";
|
|
8
|
+
var repository = {
|
|
9
|
+
type: "git",
|
|
10
|
+
url: "git+https://github.com/BackTrackCo/tenjin-agent.git"
|
|
11
|
+
};
|
|
12
|
+
var homepage = "https://tenjin.sh/agents";
|
|
13
|
+
var bugs = "https://github.com/BackTrackCo/tenjin-agent/issues";
|
|
14
|
+
var keywords = [
|
|
15
|
+
"claude-code",
|
|
16
|
+
"coding-agents",
|
|
17
|
+
"tool-router",
|
|
18
|
+
"ai-agents",
|
|
19
|
+
"agent-tools",
|
|
20
|
+
"mcp",
|
|
21
|
+
"x402",
|
|
22
|
+
"usdc",
|
|
23
|
+
"base",
|
|
24
|
+
"micropayments",
|
|
25
|
+
"agent-payments",
|
|
26
|
+
"claude",
|
|
27
|
+
"codex",
|
|
28
|
+
"cli"
|
|
29
|
+
];
|
|
30
|
+
var bin = {
|
|
31
|
+
tenjin: "dist/index.js"
|
|
32
|
+
};
|
|
33
|
+
var engines = {
|
|
34
|
+
node: ">=22.0.0"
|
|
35
|
+
};
|
|
36
|
+
var files = [
|
|
37
|
+
"dist",
|
|
38
|
+
"docs",
|
|
39
|
+
"NOTICE.md"
|
|
40
|
+
];
|
|
41
|
+
var packageManager = "pnpm@11.11.0";
|
|
42
|
+
var scripts = {
|
|
43
|
+
build: "rm -rf dist && tsup",
|
|
44
|
+
test: "vitest run",
|
|
45
|
+
typecheck: "tsc --noEmit",
|
|
46
|
+
lint: "eslint .",
|
|
47
|
+
format: "prettier --write .",
|
|
48
|
+
"format:check": "prettier --check .",
|
|
49
|
+
check: "pnpm run build && pnpm run test",
|
|
50
|
+
"sync:skill": "node scripts/sync-skill.mjs",
|
|
51
|
+
"pack-smoke": "bash scripts/pack-smoke.sh",
|
|
52
|
+
changeset: "changeset",
|
|
53
|
+
prepublishOnly: "pnpm run build",
|
|
54
|
+
githooks: "git config core.hooksPath .githooks"
|
|
55
|
+
};
|
|
56
|
+
var devDependencies = {
|
|
57
|
+
"@changesets/cli": "^3.0.3",
|
|
58
|
+
"@clack/prompts": "^1.7.0",
|
|
59
|
+
"@eslint/js": "^10",
|
|
60
|
+
"@modelcontextprotocol/sdk": "1.32.0",
|
|
61
|
+
"@types/node": "^22.20.5",
|
|
62
|
+
"@x402/core": "2.28.0",
|
|
63
|
+
"@x402/evm": "2.28.0",
|
|
64
|
+
"@x402/extensions": "2.28.0",
|
|
65
|
+
"@x402/fetch": "2.28.0",
|
|
66
|
+
ajv: "^8.20.0",
|
|
67
|
+
"ajv-formats": "^3.0.1",
|
|
68
|
+
commander: "^14.0.1",
|
|
69
|
+
eslint: "^10",
|
|
70
|
+
"eslint-config-prettier": "^10",
|
|
71
|
+
"lean-qr": "^2.7.4",
|
|
72
|
+
ox: "0.14.30",
|
|
73
|
+
prettier: "^3",
|
|
74
|
+
tsup: "^8.5.0",
|
|
75
|
+
typescript: "^6",
|
|
76
|
+
"typescript-eslint": "^8",
|
|
77
|
+
viem: "^2.53.1",
|
|
78
|
+
vitest: "^4.1.9",
|
|
79
|
+
zod: "^4.4.3"
|
|
80
|
+
};
|
|
81
|
+
var package_default = {
|
|
82
|
+
name,
|
|
83
|
+
version,
|
|
84
|
+
type,
|
|
85
|
+
description,
|
|
86
|
+
repository,
|
|
87
|
+
homepage,
|
|
88
|
+
bugs,
|
|
89
|
+
keywords,
|
|
90
|
+
bin,
|
|
91
|
+
engines,
|
|
92
|
+
files,
|
|
93
|
+
packageManager,
|
|
94
|
+
scripts,
|
|
95
|
+
devDependencies
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export {
|
|
99
|
+
name,
|
|
100
|
+
version,
|
|
101
|
+
type,
|
|
102
|
+
description,
|
|
103
|
+
repository,
|
|
104
|
+
homepage,
|
|
105
|
+
bugs,
|
|
106
|
+
keywords,
|
|
107
|
+
bin,
|
|
108
|
+
engines,
|
|
109
|
+
files,
|
|
110
|
+
packageManager,
|
|
111
|
+
scripts,
|
|
112
|
+
devDependencies,
|
|
113
|
+
package_default
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=chunk-VUFAK2LW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../package.json"],"sourcesContent":["{\n \"name\": \"tenjin-cli\",\n \"version\": \"0.1.0-alpha.30\",\n \"type\": \"module\",\n \"description\": \"The tool router for coding agents. Tenjin picks the right tool when your agent needs one, and one wallet pays for every call.\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/BackTrackCo/tenjin-agent.git\"\n },\n \"homepage\": \"https://tenjin.sh/agents\",\n \"bugs\": \"https://github.com/BackTrackCo/tenjin-agent/issues\",\n \"keywords\": [\n \"claude-code\",\n \"coding-agents\",\n \"tool-router\",\n \"ai-agents\",\n \"agent-tools\",\n \"mcp\",\n \"x402\",\n \"usdc\",\n \"base\",\n \"micropayments\",\n \"agent-payments\",\n \"claude\",\n \"codex\",\n \"cli\"\n ],\n \"bin\": {\n \"tenjin\": \"dist/index.js\"\n },\n \"engines\": {\n \"node\": \">=22.0.0\"\n },\n \"files\": [\n \"dist\",\n \"docs\",\n \"NOTICE.md\"\n ],\n \"packageManager\": \"pnpm@11.11.0\",\n \"scripts\": {\n \"build\": \"rm -rf dist && tsup\",\n \"test\": \"vitest run\",\n \"typecheck\": \"tsc --noEmit\",\n \"lint\": \"eslint .\",\n \"format\": \"prettier --write .\",\n \"format:check\": \"prettier --check .\",\n \"check\": \"pnpm run build && pnpm run test\",\n \"sync:skill\": \"node scripts/sync-skill.mjs\",\n \"pack-smoke\": \"bash scripts/pack-smoke.sh\",\n \"changeset\": \"changeset\",\n \"prepublishOnly\": \"pnpm run build\",\n \"githooks\": \"git config core.hooksPath .githooks\"\n },\n \"devDependencies\": {\n \"@changesets/cli\": \"^3.0.3\",\n \"@clack/prompts\": \"^1.7.0\",\n \"@eslint/js\": \"^10\",\n \"@modelcontextprotocol/sdk\": \"1.32.0\",\n \"@types/node\": \"^22.20.5\",\n \"@x402/core\": \"2.28.0\",\n \"@x402/evm\": \"2.28.0\",\n \"@x402/extensions\": \"2.28.0\",\n \"@x402/fetch\": \"2.28.0\",\n \"ajv\": \"^8.20.0\",\n \"ajv-formats\": \"^3.0.1\",\n \"commander\": \"^14.0.1\",\n \"eslint\": \"^10\",\n \"eslint-config-prettier\": \"^10\",\n \"lean-qr\": \"^2.7.4\",\n \"ox\": \"0.14.30\",\n \"prettier\": \"^3\",\n \"tsup\": \"^8.5.0\",\n \"typescript\": \"^6\",\n \"typescript-eslint\": \"^8\",\n \"viem\": \"^2.53.1\",\n \"vitest\": \"^4.1.9\",\n \"zod\": \"^4.4.3\"\n }\n}\n"],"mappings":";;;AACE,WAAQ;AACR,cAAW;AACX,WAAQ;AACR,kBAAe;AACf,iBAAc;AAAA,EACZ,MAAQ;AAAA,EACR,KAAO;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