tenjin-cli 0.1.0-alpha.30 → 0.1.0-alpha.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -116
- package/dist/{_esm-CE7KNONL.js → _esm-MEXZI5DL.js} +4 -4
- package/dist/{alive-3J3CHOQP.js → alive-J64H46HI.js} +14 -4
- package/dist/{chunk-O2FRQ2L2.js → chunk-27EPWVOY.js} +4 -64
- package/dist/chunk-27EPWVOY.js.map +1 -0
- package/dist/{chunk-OSYTBCUC.js → chunk-2XLC3AEX.js} +16 -14
- package/dist/{chunk-OSYTBCUC.js.map → chunk-2XLC3AEX.js.map} +1 -1
- package/dist/chunk-3623BLPV.js +184 -0
- package/dist/chunk-3623BLPV.js.map +1 -0
- package/dist/chunk-3UCIG4TG.js +65 -0
- package/dist/chunk-3UCIG4TG.js.map +1 -0
- package/dist/{chunk-PAYV4XUA.js → chunk-4ZZO6ULA.js} +2 -2
- package/dist/{chunk-VUFAK2LW.js → chunk-5C32RLTA.js} +2 -2
- package/dist/{chunk-VUFAK2LW.js.map → chunk-5C32RLTA.js.map} +1 -1
- package/dist/{chunk-YHKXNYTB.js → chunk-5K5W4S66.js} +2 -2
- package/dist/{chunk-3O2BQIF6.js → chunk-5MARFNSB.js} +273 -482
- package/dist/chunk-5MARFNSB.js.map +1 -0
- package/dist/{chunk-HPWO4O6S.js → chunk-6E5R45ZO.js} +2 -2
- package/dist/{chunk-JMM6YE7J.js → chunk-77TCKDEC.js} +125 -312
- package/dist/chunk-77TCKDEC.js.map +1 -0
- package/dist/{chunk-LFZJM56J.js → chunk-7Q5FDF65.js} +2 -2
- package/dist/chunk-7WEQQJLG.js +68 -0
- package/dist/chunk-7WEQQJLG.js.map +1 -0
- package/dist/{chunk-AWFUPKTM.js → chunk-7WU4OPLP.js} +12 -6
- package/dist/{chunk-AWFUPKTM.js.map → chunk-7WU4OPLP.js.map} +1 -1
- package/dist/{chunk-AEG2PXBP.js → chunk-7ZRL2LBQ.js} +3 -3
- package/dist/{chunk-IOODYAXL.js → chunk-AGZ7PJKY.js} +6 -4
- package/dist/{chunk-IOODYAXL.js.map → chunk-AGZ7PJKY.js.map} +1 -1
- package/dist/{chunk-VFMQTSXG.js → chunk-B7HUUJOK.js} +3 -3
- package/dist/{chunk-EL56RW2J.js → chunk-BL3332HQ.js} +7 -7
- package/dist/{chunk-5LJCEMFD.js → chunk-D65GNPS3.js} +35 -27
- package/dist/{chunk-5LJCEMFD.js.map → chunk-D65GNPS3.js.map} +1 -1
- package/dist/{chunk-P7LABKCW.js → chunk-DOQGNFHM.js} +33 -2
- package/dist/{chunk-P7LABKCW.js.map → chunk-DOQGNFHM.js.map} +1 -1
- package/dist/{chunk-OK2TDZQU.js → chunk-FW75G2W4.js} +7 -5
- package/dist/chunk-FW75G2W4.js.map +1 -0
- package/dist/chunk-GA7JETVM.js +150 -0
- package/dist/chunk-GA7JETVM.js.map +1 -0
- package/dist/{chunk-6W5GYG3W.js → chunk-I3EQFHCD.js} +48 -1
- package/dist/chunk-I3EQFHCD.js.map +1 -0
- package/dist/{chunk-EBVIKMCH.js → chunk-JKKAIPTU.js} +2 -2
- package/dist/{chunk-N35E6CM2.js → chunk-K3I7C2MO.js} +6 -6
- package/dist/{chunk-KYFZTGMC.js → chunk-K72RURN3.js} +5 -3
- package/dist/{chunk-KYFZTGMC.js.map → chunk-K72RURN3.js.map} +1 -1
- package/dist/{chunk-RAULEAZ6.js → chunk-KXQ4UIP7.js} +3 -3
- package/dist/{chunk-VZGAONSJ.js → chunk-KXVP2VKA.js} +5 -5
- package/dist/chunk-LEFIX6RS.js +100 -0
- package/dist/chunk-LEFIX6RS.js.map +1 -0
- package/dist/{chunk-TTBKWWTV.js → chunk-MNXS2U45.js} +246 -83
- package/dist/chunk-MNXS2U45.js.map +1 -0
- package/dist/{chunk-AWQPGIR6.js → chunk-NEFNKLBE.js} +5 -5
- package/dist/chunk-OHRR5OYM.js +63 -0
- package/dist/chunk-OHRR5OYM.js.map +1 -0
- package/dist/{chunk-U6YQ6FRI.js → chunk-P4NH7OUK.js} +31 -11
- package/dist/chunk-P4NH7OUK.js.map +1 -0
- package/dist/chunk-QSCPK4F5.js +145 -0
- package/dist/chunk-QSCPK4F5.js.map +1 -0
- package/dist/chunk-QXP3Z3JN.js +131 -0
- package/dist/chunk-QXP3Z3JN.js.map +1 -0
- package/dist/{chunk-YFQOA5AU.js → chunk-R5LCN54M.js} +4 -4
- package/dist/{chunk-KHE6L6TD.js → chunk-UKY4CHNC.js} +92 -10
- package/dist/chunk-UKY4CHNC.js.map +1 -0
- package/dist/{chunk-QUVVWYJW.js → chunk-UQUOVWBG.js} +8 -6
- package/dist/{chunk-QUVVWYJW.js.map → chunk-UQUOVWBG.js.map} +1 -1
- package/dist/{chunk-HE2MS4QO.js → chunk-V6BSF6OC.js} +17 -13
- package/dist/{chunk-HE2MS4QO.js.map → chunk-V6BSF6OC.js.map} +1 -1
- package/dist/{chunk-WVUSXNIE.js → chunk-WJXLQXJY.js} +6 -2
- package/dist/{chunk-WVUSXNIE.js.map → chunk-WJXLQXJY.js.map} +1 -1
- package/dist/{chunk-NZIP4PA2.js → chunk-WK7F3B2E.js} +2 -2
- package/dist/chunk-XQJXNMSB.js +23 -0
- package/dist/chunk-XQJXNMSB.js.map +1 -0
- package/dist/chunk-Y527D4TV.js +56 -0
- package/dist/chunk-Y527D4TV.js.map +1 -0
- package/dist/{chunk-SPAVAYSW.js → chunk-YFPY4ONH.js} +6 -4
- package/dist/{chunk-SPAVAYSW.js.map → chunk-YFPY4ONH.js.map} +1 -1
- package/dist/{chunk-WO5BJNIB.js → chunk-YVFXE7RR.js} +9 -129
- package/dist/chunk-YVFXE7RR.js.map +1 -0
- package/dist/clack-EZ7TDWQU.js +19 -0
- package/dist/claude-cli-2YKABJJZ.js +31 -0
- package/dist/{cli-O5SN7ZJ4.js → cli-D5OE3URZ.js} +128 -56
- package/dist/{cli-O5SN7ZJ4.js.map → cli-D5OE3URZ.js.map} +1 -1
- package/dist/codex-event-PPNVRRDH.js +16 -0
- package/dist/codex-host-2RJOJW2B.js +28 -0
- package/dist/codex-install-UUZ6QMBQ.js +221 -0
- package/dist/codex-install-UUZ6QMBQ.js.map +1 -0
- package/dist/{config-OJQI27LT.js → config-ZD4OB2DO.js} +18 -12
- package/dist/{doctor-IQQJHGGM.js → doctor-KBR34Q4B.js} +48 -37
- package/dist/doctor-KBR34Q4B.js.map +1 -0
- package/dist/{fund-WEV6DMTD.js → fund-5ITKQGYF.js} +38 -31
- package/dist/{fund-WEV6DMTD.js.map → fund-5ITKQGYF.js.map} +1 -1
- package/dist/hook-command-4TYCHHRL.js +39 -0
- package/dist/hosts/claude/.claude-plugin/marketplace.json +2 -2
- package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +3 -2
- package/dist/hosts/claude/tenjin/hooks/hooks.json +4 -1
- package/dist/hosts/claude/tenjin/hooks/register.tsx +589 -0
- package/dist/hosts/claude/tenjin/types/index.d.ts +41 -0
- package/dist/hosts/codex/.agents/plugins/marketplace.json +20 -0
- package/dist/hosts/codex/tenjin/.codex-plugin/plugin.json +16 -0
- package/dist/hosts/codex/tenjin/.mcp.json +12 -0
- package/dist/hosts/codex/tenjin/hooks/hooks.json +52 -0
- package/dist/hosts-FWZOV26H.js +216 -0
- package/dist/hosts-FWZOV26H.js.map +1 -0
- package/dist/index.js +5 -5
- package/dist/{install-TUCRF32I.js → install-XWGE4Q7L.js} +38 -21
- package/dist/{install-identity-WHPNMNMQ.js → install-identity-K7EJIQFP.js} +11 -7
- package/dist/{install-wallet-MA27FTQ5.js → install-wallet-XQ6XFZV4.js} +27 -23
- package/dist/{install-wallet-MA27FTQ5.js.map → install-wallet-XQ6XFZV4.js.map} +1 -1
- package/dist/{mcp-QML7ZMPH.js → mcp-3LIJSSJB.js} +184 -58
- package/dist/mcp-3LIJSSJB.js.map +1 -0
- package/dist/{package-LGKYOEPV.js → package-ZKQFDWLE.js} +2 -2
- package/dist/{pay-2C2UBBXJ.js → pay-WHBERZ3W.js} +27 -23
- package/dist/{payments-C44QUFXU.js → payments-KVICEKD2.js} +14 -10
- package/dist/{payments-C44QUFXU.js.map → payments-KVICEKD2.js.map} +1 -1
- package/dist/plugin-registration-5TIA564H.js +54 -0
- package/dist/plugin-registration-5TIA564H.js.map +1 -0
- package/dist/{send-KVJX4XIR.js → send-7G7Y7DLN.js} +25 -19
- package/dist/{send-KVJX4XIR.js.map → send-7G7Y7DLN.js.map} +1 -1
- package/dist/{status-S7C3WMSH.js → status-OF7RH5HM.js} +26 -21
- package/dist/{status-S7C3WMSH.js.map → status-OF7RH5HM.js.map} +1 -1
- package/dist/{status-line-YR2T5HC4.js → status-line-XOUE6MPL.js} +10 -6
- package/dist/{status-line-YR2T5HC4.js.map → status-line-XOUE6MPL.js.map} +1 -1
- package/dist/{uninstall-HY6LKIIT.js → uninstall-JXUAFNDB.js} +30 -21
- package/dist/{uninstall-HY6LKIIT.js.map → uninstall-JXUAFNDB.js.map} +1 -1
- package/dist/update-ZKUERSO2.js +44 -0
- package/dist/update-ZKUERSO2.js.map +1 -0
- package/dist/{usdc-JK4RRFFQ.js → usdc-OGOGEHV2.js} +7 -6
- package/dist/usdc-OGOGEHV2.js.map +1 -0
- package/dist/{viemAdapter-By13KInL-X2VY6CY3.js → viemAdapter-By13KInL-S3DA7DFW.js} +2 -2
- package/dist/viemAdapter-By13KInL-S3DA7DFW.js.map +1 -0
- package/dist/{wallet-PD2IMZDU.js → wallet-2HA6W4R4.js} +24 -20
- package/dist/wallet-2HA6W4R4.js.map +1 -0
- package/docs/agent-permissions.md +21 -5
- package/package.json +1 -1
- package/dist/chunk-3O2BQIF6.js.map +0 -1
- package/dist/chunk-6W5GYG3W.js.map +0 -1
- package/dist/chunk-JMM6YE7J.js.map +0 -1
- package/dist/chunk-KHE6L6TD.js.map +0 -1
- package/dist/chunk-O2FRQ2L2.js.map +0 -1
- package/dist/chunk-OK2TDZQU.js.map +0 -1
- package/dist/chunk-TTBKWWTV.js.map +0 -1
- package/dist/chunk-U6YQ6FRI.js.map +0 -1
- package/dist/chunk-WO5BJNIB.js.map +0 -1
- package/dist/doctor-IQQJHGGM.js.map +0 -1
- package/dist/hook-command-D2P3ILRV.js +0 -32
- package/dist/mcp-QML7ZMPH.js.map +0 -1
- package/dist/update-OJV22LR3.js +0 -36
- /package/dist/{_esm-CE7KNONL.js.map → _esm-MEXZI5DL.js.map} +0 -0
- /package/dist/{alive-3J3CHOQP.js.map → alive-J64H46HI.js.map} +0 -0
- /package/dist/{chunk-PAYV4XUA.js.map → chunk-4ZZO6ULA.js.map} +0 -0
- /package/dist/{chunk-YHKXNYTB.js.map → chunk-5K5W4S66.js.map} +0 -0
- /package/dist/{chunk-HPWO4O6S.js.map → chunk-6E5R45ZO.js.map} +0 -0
- /package/dist/{chunk-LFZJM56J.js.map → chunk-7Q5FDF65.js.map} +0 -0
- /package/dist/{chunk-AEG2PXBP.js.map → chunk-7ZRL2LBQ.js.map} +0 -0
- /package/dist/{chunk-VFMQTSXG.js.map → chunk-B7HUUJOK.js.map} +0 -0
- /package/dist/{chunk-EL56RW2J.js.map → chunk-BL3332HQ.js.map} +0 -0
- /package/dist/{chunk-EBVIKMCH.js.map → chunk-JKKAIPTU.js.map} +0 -0
- /package/dist/{chunk-N35E6CM2.js.map → chunk-K3I7C2MO.js.map} +0 -0
- /package/dist/{chunk-RAULEAZ6.js.map → chunk-KXQ4UIP7.js.map} +0 -0
- /package/dist/{chunk-VZGAONSJ.js.map → chunk-KXVP2VKA.js.map} +0 -0
- /package/dist/{chunk-AWQPGIR6.js.map → chunk-NEFNKLBE.js.map} +0 -0
- /package/dist/{chunk-YFQOA5AU.js.map → chunk-R5LCN54M.js.map} +0 -0
- /package/dist/{chunk-NZIP4PA2.js.map → chunk-WK7F3B2E.js.map} +0 -0
- /package/dist/{config-OJQI27LT.js.map → clack-EZ7TDWQU.js.map} +0 -0
- /package/dist/{hook-command-D2P3ILRV.js.map → claude-cli-2YKABJJZ.js.map} +0 -0
- /package/dist/{install-TUCRF32I.js.map → codex-event-PPNVRRDH.js.map} +0 -0
- /package/dist/{install-identity-WHPNMNMQ.js.map → codex-host-2RJOJW2B.js.map} +0 -0
- /package/dist/{package-LGKYOEPV.js.map → config-ZD4OB2DO.js.map} +0 -0
- /package/dist/{pay-2C2UBBXJ.js.map → hook-command-4TYCHHRL.js.map} +0 -0
- /package/dist/{update-OJV22LR3.js.map → install-XWGE4Q7L.js.map} +0 -0
- /package/dist/{usdc-JK4RRFFQ.js.map → install-identity-K7EJIQFP.js.map} +0 -0
- /package/dist/{viemAdapter-By13KInL-X2VY6CY3.js.map → package-ZKQFDWLE.js.map} +0 -0
- /package/dist/{wallet-PD2IMZDU.js.map → pay-WHBERZ3W.js.map} +0 -0
|
@@ -2,7 +2,7 @@ import { createRequire as __tenjinCreateRequire } from 'node:module'; const requ
|
|
|
2
2
|
import {
|
|
3
3
|
writeFileAtomic,
|
|
4
4
|
writeFileAtomicExclusive
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-7WEQQJLG.js";
|
|
6
6
|
|
|
7
7
|
// src/router/progress.ts
|
|
8
8
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -75,20 +75,32 @@ async function bindDecision(dataDir, sessionId, decisionId, now = Date.now()) {
|
|
|
75
75
|
at: now
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
|
-
async function markOffered(dataDir, sessionId, toolUseId, now = Date.now()) {
|
|
79
|
-
|
|
78
|
+
async function markOffered(dataDir, sessionId, toolUseId, offer, now = Date.now()) {
|
|
79
|
+
const saved = {
|
|
80
80
|
version: 1,
|
|
81
|
-
at: now
|
|
82
|
-
|
|
81
|
+
at: now,
|
|
82
|
+
...offer.offerId !== void 0 && /^[\w.:-]{1,200}$/.test(offer.offerId) ? { offerId: offer.offerId } : {},
|
|
83
|
+
...offer.label !== void 0 ? { label: sanitize(offer.label, 32) } : {},
|
|
84
|
+
.../^\d{1,78}$/.test(offer.priceAtomic) ? { priceAtomic: offer.priceAtomic } : {}
|
|
85
|
+
};
|
|
86
|
+
await write(
|
|
87
|
+
join(sessionDir(dataDir, sessionId), `${OFFER_PREFIX}${digest(toolUseId)}.json`),
|
|
88
|
+
saved
|
|
89
|
+
);
|
|
83
90
|
}
|
|
84
91
|
async function wasOffered(dataDir, sessionId, toolUseId, now = Date.now()) {
|
|
85
92
|
const path = join(sessionDir(dataDir, sessionId), `${OFFER_PREFIX}${digest(toolUseId)}.json`);
|
|
86
93
|
const stamp = await readStamp(path);
|
|
87
94
|
return stamp !== null && now - stamp.at <= EXPIRY_MS;
|
|
88
95
|
}
|
|
89
|
-
async function markAugment(dataDir, sessionId, toolUseId,
|
|
96
|
+
async function markAugment(dataDir, sessionId, toolUseId, docs, now = Date.now()) {
|
|
90
97
|
const base = join(sessionDir(dataDir, sessionId), `${AUGMENT_PREFIX}${digest(toolUseId)}`);
|
|
91
|
-
const saved = {
|
|
98
|
+
const saved = {
|
|
99
|
+
version: 1,
|
|
100
|
+
at: now,
|
|
101
|
+
provider: sanitize(docs.provider, 60),
|
|
102
|
+
...docs.label !== void 0 ? { label: sanitize(docs.label, 32) } : {}
|
|
103
|
+
};
|
|
92
104
|
return await write(`${base}.json`, saved) ? `${base}${AUGMENT_BODY_SUFFIX}` : null;
|
|
93
105
|
}
|
|
94
106
|
async function augmentOf(dataDir, sessionId, toolUseId, now = Date.now()) {
|
|
@@ -97,7 +109,13 @@ async function augmentOf(dataDir, sessionId, toolUseId, now = Date.now()) {
|
|
|
97
109
|
const stamp = stampOf(row);
|
|
98
110
|
if (row === null || stamp === null || now - stamp.at > EXPIRY_MS) return null;
|
|
99
111
|
const provider = typeof row.provider === "string" ? sanitize(row.provider, 60) : "";
|
|
100
|
-
|
|
112
|
+
const label = typeof row.label === "string" ? sanitize(row.label, 32) : "";
|
|
113
|
+
return {
|
|
114
|
+
at: stamp.at,
|
|
115
|
+
provider,
|
|
116
|
+
...label !== "" ? { label } : {},
|
|
117
|
+
body: `${base}${AUGMENT_BODY_SUFFIX}`
|
|
118
|
+
};
|
|
101
119
|
}
|
|
102
120
|
async function claimQuery(dataDir, sessionId, agentId, query, now = Date.now()) {
|
|
103
121
|
const key = digest(JSON.stringify([agentId ?? "", query]));
|
|
@@ -179,6 +197,7 @@ async function writeProgress(directory, callId, step, now = Date.now()) {
|
|
|
179
197
|
operation: sanitize(step.operation ?? "request", 24) || "request",
|
|
180
198
|
...step.outcome !== void 0 ? { outcome: sanitize(step.outcome, 40) } : {},
|
|
181
199
|
...endpoint !== void 0 ? { endpoint } : {},
|
|
200
|
+
...step.label !== void 0 ? { label: sanitize(step.label, 32) } : {},
|
|
182
201
|
...parameters !== void 0 ? { parameters } : {},
|
|
183
202
|
...step.price !== void 0 ? { price: sanitize(step.price, 24) } : {}
|
|
184
203
|
};
|
|
@@ -306,7 +325,8 @@ function line(row, now) {
|
|
|
306
325
|
return `x402 \xB7 ${operation}: stale, no outcome recorded`;
|
|
307
326
|
}
|
|
308
327
|
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}` +
|
|
328
|
+
return `x402 \xB7 ${operation}: ${state}` + // The service's name where its decision gave one, else the URL called.
|
|
329
|
+
(row.label !== void 0 ? ` ${sanitize(row.label, 32)}` : 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
330
|
}
|
|
311
331
|
async function write(path, body) {
|
|
312
332
|
try {
|
|
@@ -328,7 +348,7 @@ async function readCall(path) {
|
|
|
328
348
|
const stamp = stampOf(row);
|
|
329
349
|
if (row === null || stamp === null || typeof row.operation !== "string") return null;
|
|
330
350
|
if (!["routing", "calling", "done"].includes(row.phase)) return null;
|
|
331
|
-
const optional = ["outcome", "endpoint", "parameters", "price"];
|
|
351
|
+
const optional = ["outcome", "endpoint", "label", "parameters", "price"];
|
|
332
352
|
if (!optional.every((key) => row[key] === void 0 || typeof row[key] === "string")) return null;
|
|
333
353
|
return {
|
|
334
354
|
...stamp,
|
|
@@ -375,4 +395,4 @@ export {
|
|
|
375
395
|
pruneSessions,
|
|
376
396
|
renderProgress
|
|
377
397
|
};
|
|
378
|
-
//# sourceMappingURL=chunk-
|
|
398
|
+
//# sourceMappingURL=chunk-P4NH7OUK.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 service's display name as the server gave it. */\n label?: 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: the service's\n * `label` when the decision carried one, else its provider's name. */\ninterface SavedAugment extends Stamp {\n provider: string;\n label?: string;\n}\n\n/**\n * THE OFFER RECORD, one per native call a hook redirected, keyed by its\n * `tool_use_id`: when it was made, the offer's id, its `label` when the\n * decision carried one, and its price in atomic USDC. Part of the state\n * contract between this CLI and the plugin's mod (`mod-state.ts`), which reads\n * it to draw the redirected row and to find the `request` call that takes the\n * offer up by its id; it never parses the reason the model read. Version 1\n * grows by optional fields only, so a reader ignores one it does not know, and\n * an older CLI's prune still reads it as a record.\n */\ninterface SavedOffer extends Stamp {\n offerId?: string;\n label?: string;\n priceAtomic?: string;\n}\n\n/** What the offer record names: the offer's id, display name and price. */\nexport interface OfferedTerms {\n offerId?: string;\n label?: string;\n priceAtomic: 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 /** The service's display name, from its decision, shown in place of the URL. */\n label?: 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 offer: OfferedTerms,\n now = Date.now(),\n): Promise<void> {\n const saved: SavedOffer = {\n version: 1,\n at: now,\n ...(offer.offerId !== undefined && /^[\\w.:-]{1,200}$/.test(offer.offerId)\n ? { offerId: offer.offerId }\n : {}),\n ...(offer.label !== undefined ? { label: sanitize(offer.label, 32) } : {}),\n ...(/^\\d{1,78}$/.test(offer.priceAtomic) ? { priceAtomic: offer.priceAtomic } : {}),\n };\n await write(\n join(sessionDir(dataDir, sessionId), `${OFFER_PREFIX}${digest(toolUseId)}.json`),\n saved,\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 docs: { provider: string; label?: string },\n now = Date.now(),\n): Promise<string | null> {\n const base = join(sessionDir(dataDir, sessionId), `${AUGMENT_PREFIX}${digest(toolUseId)}`);\n const saved: SavedAugment = {\n version: 1,\n at: now,\n provider: sanitize(docs.provider, 60),\n ...(docs.label !== undefined ? { label: sanitize(docs.label, 32) } : {}),\n };\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; label?: 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 const label = typeof row.label === 'string' ? sanitize(row.label, 32) : '';\n return {\n at: stamp.at,\n provider,\n ...(label !== '' ? { label } : {}),\n body: `${base}${AUGMENT_BODY_SUFFIX}`,\n };\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 ...(step.label !== undefined ? { label: sanitize(step.label, 32) } : {}),\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; label?: 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; label?: 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> <label or 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 // The service's name where its decision gave one, else the URL called.\n (row.label !== undefined\n ? ` ${sanitize(row.label, 32)}`\n : row.endpoint !== undefined\n ? ` ${sanitize(row.endpoint, 110)}`\n : '') +\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', 'label', '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;AAsEzB,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;AAC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Q,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,145 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/lib/codex-bin.ts
|
|
4
|
+
import { statSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
var NPM_SCRIPT = ["node_modules", "@openai", "codex", "bin", "codex.js"];
|
|
7
|
+
function isFile(path) {
|
|
8
|
+
try {
|
|
9
|
+
return statSync(path).isFile();
|
|
10
|
+
} catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function resolveCodex(env = process.env, platform = process.platform, execPath = process.execPath) {
|
|
15
|
+
const win = platform === "win32";
|
|
16
|
+
const exts = win ? (env.PATHEXT ?? ".EXE;.CMD;.BAT;.COM").split(";").filter((e) => e.length > 0) : [""];
|
|
17
|
+
for (const part of (env.PATH ?? "").split(win ? ";" : ":")) {
|
|
18
|
+
if (part.length === 0) continue;
|
|
19
|
+
for (const ext of exts) {
|
|
20
|
+
const candidate = [ext, ext.toLowerCase()].map((e) => join(part, `codex${e}`)).find(isFile);
|
|
21
|
+
if (candidate === void 0) continue;
|
|
22
|
+
if (/^\.(cmd|bat)$/i.test(ext)) {
|
|
23
|
+
const script = join(part, ...NPM_SCRIPT);
|
|
24
|
+
if (isFile(script)) return { cmd: execPath, prefix: [script] };
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
return { cmd: candidate, prefix: [] };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/lib/codex-app-server.ts
|
|
34
|
+
import { spawn } from "node:child_process";
|
|
35
|
+
|
|
36
|
+
// src/lib/codex-home.ts
|
|
37
|
+
import { join as join2 } from "node:path";
|
|
38
|
+
function codexHome(home, env = process.env) {
|
|
39
|
+
const override = env.CODEX_HOME;
|
|
40
|
+
return override !== void 0 && override.length > 0 ? override : join2(home, ".codex");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/lib/codex-app-server.ts
|
|
44
|
+
function isRecord(v) {
|
|
45
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
46
|
+
}
|
|
47
|
+
async function withAppServer(home, env, timeoutMs, fn) {
|
|
48
|
+
const codex = resolveCodex(env);
|
|
49
|
+
if (codex === null) return null;
|
|
50
|
+
let child;
|
|
51
|
+
try {
|
|
52
|
+
child = spawn(codex.cmd, [...codex.prefix, "app-server"], {
|
|
53
|
+
env: { ...env, CODEX_HOME: codexHome(home, env) },
|
|
54
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
55
|
+
windowsHide: true
|
|
56
|
+
});
|
|
57
|
+
} catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
let dead = false;
|
|
61
|
+
const pending = /* @__PURE__ */ new Map();
|
|
62
|
+
const fail = () => {
|
|
63
|
+
dead = true;
|
|
64
|
+
for (const resolve of pending.values()) resolve(void 0);
|
|
65
|
+
pending.clear();
|
|
66
|
+
};
|
|
67
|
+
child.on("error", fail);
|
|
68
|
+
child.on("exit", fail);
|
|
69
|
+
let buffered = "";
|
|
70
|
+
child.stdout?.setEncoding("utf8");
|
|
71
|
+
child.stdout?.on("data", (chunk) => {
|
|
72
|
+
buffered += chunk;
|
|
73
|
+
let cut = buffered.indexOf("\n");
|
|
74
|
+
while (cut !== -1) {
|
|
75
|
+
const line = buffered.slice(0, cut);
|
|
76
|
+
buffered = buffered.slice(cut + 1);
|
|
77
|
+
cut = buffered.indexOf("\n");
|
|
78
|
+
let msg;
|
|
79
|
+
try {
|
|
80
|
+
msg = JSON.parse(line);
|
|
81
|
+
} catch {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (!isRecord(msg) || typeof msg.id !== "number") continue;
|
|
85
|
+
const waiting = pending.get(msg.id);
|
|
86
|
+
if (waiting === void 0) continue;
|
|
87
|
+
pending.delete(msg.id);
|
|
88
|
+
waiting(msg.error !== void 0 ? void 0 : msg.result);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
let nextId = 1;
|
|
92
|
+
const send = (payload) => {
|
|
93
|
+
try {
|
|
94
|
+
child.stdin?.write(`${JSON.stringify(payload)}
|
|
95
|
+
`);
|
|
96
|
+
return true;
|
|
97
|
+
} catch {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const request = async (method, params) => {
|
|
102
|
+
if (dead) return void 0;
|
|
103
|
+
const id = ++nextId;
|
|
104
|
+
return await new Promise((resolve) => {
|
|
105
|
+
const timer = setTimeout(() => {
|
|
106
|
+
pending.delete(id);
|
|
107
|
+
resolve(void 0);
|
|
108
|
+
}, timeoutMs);
|
|
109
|
+
pending.set(id, (value) => {
|
|
110
|
+
clearTimeout(timer);
|
|
111
|
+
resolve(value);
|
|
112
|
+
});
|
|
113
|
+
if (!send({ jsonrpc: "2.0", id, method, params })) {
|
|
114
|
+
pending.delete(id);
|
|
115
|
+
clearTimeout(timer);
|
|
116
|
+
resolve(void 0);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
try {
|
|
121
|
+
send({
|
|
122
|
+
jsonrpc: "2.0",
|
|
123
|
+
id: 1,
|
|
124
|
+
method: "initialize",
|
|
125
|
+
params: { clientInfo: { name: "tenjin", title: "tenjin", version: "1" } }
|
|
126
|
+
});
|
|
127
|
+
send({ jsonrpc: "2.0", method: "initialized", params: {} });
|
|
128
|
+
return await fn(request);
|
|
129
|
+
} catch {
|
|
130
|
+
return null;
|
|
131
|
+
} finally {
|
|
132
|
+
try {
|
|
133
|
+
child.stdin?.end();
|
|
134
|
+
} catch {
|
|
135
|
+
}
|
|
136
|
+
child.kill("SIGTERM");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export {
|
|
141
|
+
codexHome,
|
|
142
|
+
resolveCodex,
|
|
143
|
+
withAppServer
|
|
144
|
+
};
|
|
145
|
+
//# sourceMappingURL=chunk-QSCPK4F5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/codex-bin.ts","../src/lib/codex-app-server.ts","../src/lib/codex-home.ts"],"sourcesContent":["import { statSync } from 'node:fs';\nimport { join } from 'node:path';\n\n/**\n * WHAT TO START TO RUN `codex`, WITH NO SHELL. The PATH walk tries the PATHEXT\n * extensions on win32, as `findClaudeBinary` does for `claude`. A native\n * `codex.exe` runs as found. npm's `codex.cmd` shim cannot be started without\n * a shell, so the script it points at, `@openai/codex/bin/codex.js` beside it,\n * runs under this Node instead.\n */\nexport interface CodexCommand {\n cmd: string;\n /** Arguments that go before Codex's own: the script, for an npm shim. */\n prefix: string[];\n}\n\nconst NPM_SCRIPT = ['node_modules', '@openai', 'codex', 'bin', 'codex.js'];\n\nfunction isFile(path: string): boolean {\n try {\n return statSync(path).isFile();\n } catch {\n return false;\n }\n}\n\n/** The `codex` this machine runs, or null when PATH holds none that can start. */\nexport function resolveCodex(\n env: NodeJS.ProcessEnv = process.env,\n platform: NodeJS.Platform = process.platform,\n execPath: string = process.execPath,\n): CodexCommand | null {\n const win = platform === 'win32';\n const exts = win\n ? (env.PATHEXT ?? '.EXE;.CMD;.BAT;.COM').split(';').filter((e) => e.length > 0)\n : [''];\n for (const part of (env.PATH ?? '').split(win ? ';' : ':')) {\n if (part.length === 0) continue;\n for (const ext of exts) {\n // PATHEXT is upper case; Windows matches names in any case, so try both.\n const candidate = [ext, ext.toLowerCase()].map((e) => join(part, `codex${e}`)).find(isFile);\n if (candidate === undefined) continue;\n if (/^\\.(cmd|bat)$/i.test(ext)) {\n const script = join(part, ...NPM_SCRIPT);\n if (isFile(script)) return { cmd: execPath, prefix: [script] };\n continue;\n }\n return { cmd: candidate, prefix: [] };\n }\n }\n return null;\n}\n","import { spawn } from 'node:child_process';\nimport { resolveCodex } from './codex-bin';\nimport { codexHome } from './codex-home';\nfunction isRecord(v: unknown): v is Record<string, unknown> {\n return v !== null && typeof v === 'object' && !Array.isArray(v);\n}\n\nexport async function withAppServer<T>(\n home: string,\n env: NodeJS.ProcessEnv,\n timeoutMs: number,\n fn: (request: (method: string, params: unknown) => Promise<unknown>) => Promise<T>,\n): Promise<T | null> {\n const codex = resolveCodex(env);\n if (codex === null) return null;\n let child: ReturnType<typeof spawn>;\n try {\n child = spawn(codex.cmd, [...codex.prefix, 'app-server'], {\n env: { ...env, CODEX_HOME: codexHome(home, env) },\n stdio: ['pipe', 'pipe', 'ignore'],\n windowsHide: true,\n });\n } catch {\n return null;\n }\n\n let dead = false;\n const pending = new Map<number, (value: unknown) => void>();\n const fail = (): void => {\n dead = true;\n for (const resolve of pending.values()) resolve(undefined);\n pending.clear();\n };\n child.on('error', fail);\n child.on('exit', fail);\n\n let buffered = '';\n child.stdout?.setEncoding('utf8');\n child.stdout?.on('data', (chunk: string) => {\n buffered += chunk;\n let cut = buffered.indexOf('\\n');\n while (cut !== -1) {\n const line = buffered.slice(0, cut);\n buffered = buffered.slice(cut + 1);\n cut = buffered.indexOf('\\n');\n let msg: unknown;\n try {\n msg = JSON.parse(line);\n } catch {\n continue;\n }\n if (!isRecord(msg) || typeof msg.id !== 'number') continue;\n const waiting = pending.get(msg.id);\n if (waiting === undefined) continue;\n pending.delete(msg.id);\n waiting(msg.error !== undefined ? undefined : msg.result);\n }\n });\n\n let nextId = 1;\n const send = (payload: unknown): boolean => {\n try {\n child.stdin?.write(`${JSON.stringify(payload)}\\n`);\n return true;\n } catch {\n return false;\n }\n };\n const request = async (method: string, params: unknown): Promise<unknown> => {\n if (dead) return undefined;\n const id = ++nextId;\n return await new Promise<unknown>((resolve) => {\n const timer = setTimeout(() => {\n pending.delete(id);\n resolve(undefined);\n }, timeoutMs);\n pending.set(id, (value) => {\n clearTimeout(timer);\n resolve(value);\n });\n if (!send({ jsonrpc: '2.0', id, method, params })) {\n pending.delete(id);\n clearTimeout(timer);\n resolve(undefined);\n }\n });\n };\n\n try {\n // Load-bearing in this order: a request sent before the `initialized`\n // notification is dropped with no reply and no error.\n send({\n jsonrpc: '2.0',\n id: 1,\n method: 'initialize',\n params: { clientInfo: { name: 'tenjin', title: 'tenjin', version: '1' } },\n });\n send({ jsonrpc: '2.0', method: 'initialized', params: {} });\n return await fn(request);\n } catch {\n return null;\n } finally {\n try {\n child.stdin?.end();\n } catch {\n // Already closed.\n }\n child.kill('SIGTERM');\n }\n}\n","import { join } from 'node:path';\n\n/** `$CODEX_HOME`, else `~/.codex`: the same root the CLI reads its config from. */\nexport function codexHome(home: string, env: NodeJS.ProcessEnv = process.env): string {\n const override = env.CODEX_HOME;\n return override !== undefined && override.length > 0 ? override : join(home, '.codex');\n}\n"],"mappings":";;;AAAA,SAAS,gBAAgB;AACzB,SAAS,YAAY;AAerB,IAAM,aAAa,CAAC,gBAAgB,WAAW,SAAS,OAAO,UAAU;AAEzE,SAAS,OAAO,MAAuB;AACrC,MAAI;AACF,WAAO,SAAS,IAAI,EAAE,OAAO;AAAA,EAC/B,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGO,SAAS,aACd,MAAyB,QAAQ,KACjC,WAA4B,QAAQ,UACpC,WAAmB,QAAQ,UACN;AACrB,QAAM,MAAM,aAAa;AACzB,QAAM,OAAO,OACR,IAAI,WAAW,uBAAuB,MAAM,GAAG,EAAE,OAAO,CAAC,MAAM,EAAE,SAAS,CAAC,IAC5E,CAAC,EAAE;AACP,aAAW,SAAS,IAAI,QAAQ,IA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I,IAAI,CAAC,UAAU;AACzB,qBAAa,KAAK;AAClB,gBAAQ,KAAK;AAAA,MACf,CAAC;AACD,UAAI,CAAC,KAAK,EAAE,SAAS,OAAO,IAAI,QAAQ,OAAO,CAAC,GAAG;AACjD,gBAAQ,OAAO,EAAE;AACjB,qBAAa,KAAK;AAClB,gBAAQ,MAAS;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,EACH;AAEA,MAAI;AAGF,SAAK;AAAA,MACH,SAAS;AAAA,MACT,IAAI;AAAA,MACJ,QAAQ;AAAA,MACR,QAAQ,EAAE,YAAY,EAAE,MAAM,UAAU,OAAO,UAAU,SAAS,IAAI,EAAE;AAAA,IAC1E,CAAC;AACD,SAAK,EAAE,SAAS,OAAO,QAAQ,eAAe,QAAQ,CAAC,EAAE,CAAC;AAC1D,WAAO,MAAM,GAAG,OAAO;AAAA,EACzB,QAAQ;AACN,WAAO;AAAA,EACT,UAAE;AACA,QAAI;AACF,YAAM,OAAO,IAAI;AAAA,IACnB,QAAQ;AAAA,IAER;AACA,UAAM,KAAK,SAAS;AAAA,EACtB;AACF;","names":["join"]}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/router/claude-cli.ts
|
|
4
|
+
import { execFile } from "node:child_process";
|
|
5
|
+
import { statSync } from "node:fs";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { delimiter, isAbsolute, join } from "node:path";
|
|
8
|
+
var CLAUDE_CODE_FLOOR = "2.1.287";
|
|
9
|
+
function claudeConfigDir(env, home = homedir()) {
|
|
10
|
+
const dir = env.CLAUDE_CONFIG_DIR;
|
|
11
|
+
return dir !== void 0 && dir.length > 0 ? dir : join(home, ".claude");
|
|
12
|
+
}
|
|
13
|
+
function userSettingsPath(env, home = homedir()) {
|
|
14
|
+
return join(claudeConfigDir(env, home), "settings.json");
|
|
15
|
+
}
|
|
16
|
+
function userMcpFile(env, home = homedir()) {
|
|
17
|
+
const dir = env.CLAUDE_CONFIG_DIR;
|
|
18
|
+
return dir !== void 0 && dir.length > 0 ? join(dir, ".claude.json") : join(home, ".claude.json");
|
|
19
|
+
}
|
|
20
|
+
function isFile(path) {
|
|
21
|
+
try {
|
|
22
|
+
return statSync(path).isFile();
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function findClaudeBinary(env) {
|
|
28
|
+
const exts = process.platform === "win32" ? ["", ...(env.PATHEXT ?? ".EXE;.CMD;.BAT;.COM").split(";").filter((e) => e.length > 0)] : [""];
|
|
29
|
+
for (const part of (env.PATH ?? "").split(delimiter)) {
|
|
30
|
+
if (part.length === 0) continue;
|
|
31
|
+
for (const ext of exts) {
|
|
32
|
+
const candidate = join(part, `claude${ext}`);
|
|
33
|
+
if (isFile(candidate)) return { path: candidate, source: "path" };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const exec = env.CLAUDE_CODE_EXECPATH;
|
|
37
|
+
if (exec !== void 0 && isAbsolute(exec) && isFile(exec)) {
|
|
38
|
+
return { path: exec, source: "execpath" };
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
function runClaude(bin, args, opts) {
|
|
43
|
+
return new Promise((resolve) => {
|
|
44
|
+
execFile(
|
|
45
|
+
bin.path,
|
|
46
|
+
args,
|
|
47
|
+
{
|
|
48
|
+
env: opts.env,
|
|
49
|
+
cwd: opts.cwd,
|
|
50
|
+
timeout: opts.timeoutMs ?? 3e4,
|
|
51
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
52
|
+
windowsHide: true
|
|
53
|
+
},
|
|
54
|
+
(err, stdout, stderr) => {
|
|
55
|
+
const code = err === null ? 0 : typeof err.code === "number" ? err.code : null;
|
|
56
|
+
resolve({ code, stdout: String(stdout), stderr: String(stderr) });
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function jsonResult(stdout) {
|
|
62
|
+
const lines = stdout.split("\n").map((l) => l.trim());
|
|
63
|
+
for (let i = lines.length - 1; i >= 0; i -= 1) {
|
|
64
|
+
const line = lines[i];
|
|
65
|
+
if (!line.startsWith("{")) continue;
|
|
66
|
+
try {
|
|
67
|
+
const parsed = JSON.parse(line);
|
|
68
|
+
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
69
|
+
return parsed;
|
|
70
|
+
}
|
|
71
|
+
} catch {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
function jsonList(stdout) {
|
|
78
|
+
const start = stdout.indexOf("[");
|
|
79
|
+
if (start === -1) return null;
|
|
80
|
+
try {
|
|
81
|
+
const parsed = JSON.parse(stdout.slice(start));
|
|
82
|
+
return Array.isArray(parsed) ? parsed.filter(
|
|
83
|
+
(row) => row !== null && typeof row === "object" && !Array.isArray(row)
|
|
84
|
+
) : null;
|
|
85
|
+
} catch {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function parseClaudeVersion(text) {
|
|
90
|
+
return /(\d+)\.(\d+)\.(\d+)/.exec(text)?.[0] ?? null;
|
|
91
|
+
}
|
|
92
|
+
function meetsFloor(version, floor = CLAUDE_CODE_FLOOR) {
|
|
93
|
+
const a = version.split(".").map(Number);
|
|
94
|
+
const b = floor.split(".").map(Number);
|
|
95
|
+
for (let i = 0; i < 3; i += 1) {
|
|
96
|
+
const x = a[i] ?? 0;
|
|
97
|
+
const y = b[i] ?? 0;
|
|
98
|
+
if (x !== y) return x > y;
|
|
99
|
+
}
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
var CLAUDE_UPDATE_FIX = "Run `claude update` in this session, then start a new Claude Code session so the newer version loads.";
|
|
103
|
+
async function readClaudeCode(env, cwd, find = findClaudeBinary) {
|
|
104
|
+
const binary = find(env);
|
|
105
|
+
if (binary === null) return { binary, version: null, meetsFloor: true };
|
|
106
|
+
const run = await runClaude(binary, ["--version"], { env, cwd, timeoutMs: 15e3 });
|
|
107
|
+
const version = run.code === 0 ? parseClaudeVersion(run.stdout) : null;
|
|
108
|
+
const ok = version === null || meetsFloor(version);
|
|
109
|
+
return {
|
|
110
|
+
binary,
|
|
111
|
+
version,
|
|
112
|
+
meetsFloor: ok,
|
|
113
|
+
...ok ? {} : { fix: CLAUDE_UPDATE_FIX }
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export {
|
|
118
|
+
CLAUDE_CODE_FLOOR,
|
|
119
|
+
claudeConfigDir,
|
|
120
|
+
userSettingsPath,
|
|
121
|
+
userMcpFile,
|
|
122
|
+
findClaudeBinary,
|
|
123
|
+
runClaude,
|
|
124
|
+
jsonResult,
|
|
125
|
+
jsonList,
|
|
126
|
+
parseClaudeVersion,
|
|
127
|
+
meetsFloor,
|
|
128
|
+
CLAUDE_UPDATE_FIX,
|
|
129
|
+
readClaudeCode
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=chunk-QXP3Z3JN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/router/claude-cli.ts"],"sourcesContent":["import { execFile } from 'node:child_process';\nimport { statSync } from 'node:fs';\nimport { homedir } from 'node:os';\nimport { delimiter, isAbsolute, join } from 'node:path';\n\n/**\n * CLAUDE CODE'S OWN COMMANDS, AND WHERE ITS CONFIG LIVES. Install, update,\n * uninstall and doctor register and read the plugin through `claude plugin`\n * and `claude mcp` rather than editing Claude Code's files, so every write is\n * Claude Code's and lands where it would put it. This module finds the binary,\n * runs it without a shell, and reads its `--json` answers. It never throws on a\n * failed command: each caller decides what a failure means.\n */\n\n/** The oldest Claude Code the plugin is built for: `mcp_tool` legs on a plugin server. */\nexport const CLAUDE_CODE_FLOOR = '2.1.287';\n\n/**\n * Claude Code's config directory: `CLAUDE_CONFIG_DIR` when set, else\n * `~/.claude`. Every path this CLI reads or writes for Claude Code goes through\n * here, so the plugin, the migration and doctor see the config the `claude`\n * commands they run see.\n */\nexport function claudeConfigDir(env: NodeJS.ProcessEnv, home: string = homedir()): string {\n const dir = env.CLAUDE_CONFIG_DIR;\n return dir !== undefined && dir.length > 0 ? dir : join(home, '.claude');\n}\n\n/** The user settings file, under {@link claudeConfigDir}. */\nexport function userSettingsPath(env: NodeJS.ProcessEnv, home: string = homedir()): string {\n return join(claudeConfigDir(env, home), 'settings.json');\n}\n\n/**\n * Where `claude mcp add -s user` writes: `.claude.json` inside\n * `CLAUDE_CONFIG_DIR` when it is set, else `~/.claude.json` beside `~/.claude`.\n */\nexport function userMcpFile(env: NodeJS.ProcessEnv, home: string = homedir()): string {\n const dir = env.CLAUDE_CONFIG_DIR;\n return dir !== undefined && dir.length > 0\n ? join(dir, '.claude.json')\n : join(home, '.claude.json');\n}\n\nexport interface ClaudeBinary {\n /** The absolute path this run executes. */\n path: string;\n /** `path` when found on PATH, `execpath` when it came from `CLAUDE_CODE_EXECPATH`. */\n source: 'path' | 'execpath';\n}\n\nfunction isFile(path: string): boolean {\n try {\n return statSync(path).isFile();\n } catch {\n return false;\n }\n}\n\n/**\n * THE BINARY, WITHOUT ASKING ANYONE TO INSTALL IT: `claude` on PATH first,\n * then `CLAUDE_CODE_EXECPATH`, which Claude Code exports to the commands its\n * Bash tool runs (so an agent's install finds it even where PATH does not, as\n * in Claude Desktop). Null when neither exists; the caller then writes the\n * plugin folder, which needs no binary.\n */\nexport function findClaudeBinary(env: NodeJS.ProcessEnv): ClaudeBinary | null {\n const exts =\n process.platform === 'win32'\n ? ['', ...(env.PATHEXT ?? '.EXE;.CMD;.BAT;.COM').split(';').filter((e) => e.length > 0)]\n : [''];\n for (const part of (env.PATH ?? '').split(delimiter)) {\n if (part.length === 0) continue;\n for (const ext of exts) {\n const candidate = join(part, `claude${ext}`);\n if (isFile(candidate)) return { path: candidate, source: 'path' };\n }\n }\n const exec = env.CLAUDE_CODE_EXECPATH;\n if (exec !== undefined && isAbsolute(exec) && isFile(exec)) {\n return { path: exec, source: 'execpath' };\n }\n return null;\n}\n\nexport interface ClaudeRun {\n /** The exit code, or null when the binary could not be started or was killed. */\n code: number | null;\n stdout: string;\n stderr: string;\n}\n\nexport interface ClaudeRunOptions {\n env: NodeJS.ProcessEnv;\n cwd: string;\n timeoutMs?: number;\n}\n\n/** One `claude` command, no shell. Never rejects. */\nexport function runClaude(\n bin: ClaudeBinary,\n args: string[],\n opts: ClaudeRunOptions,\n): Promise<ClaudeRun> {\n return new Promise((resolve) => {\n execFile(\n bin.path,\n args,\n {\n env: opts.env,\n cwd: opts.cwd,\n timeout: opts.timeoutMs ?? 30_000,\n maxBuffer: 4 * 1024 * 1024,\n windowsHide: true,\n },\n (err, stdout, stderr) => {\n const code =\n err === null\n ? 0\n : typeof (err as { code?: unknown }).code === 'number'\n ? (err as { code: number }).code\n : null;\n resolve({ code, stdout: String(stdout), stderr: String(stderr) });\n },\n );\n });\n}\n\n/**\n * The one result line a `--json` plugin command prints: the last stdout line\n * that parses as an object. Failures also print a human line on stderr, which\n * is ignored here.\n */\nexport function jsonResult(stdout: string): Record<string, unknown> | null {\n const lines = stdout.split('\\n').map((l) => l.trim());\n for (let i = lines.length - 1; i >= 0; i -= 1) {\n const line = lines[i]!;\n if (!line.startsWith('{')) continue;\n try {\n const parsed = JSON.parse(line) as unknown;\n if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {\n return parsed as Record<string, unknown>;\n }\n } catch {\n continue;\n }\n }\n return null;\n}\n\n/** A `--json` list (`plugin list`, `marketplace list`), or null when it is not one. */\nexport function jsonList(stdout: string): Record<string, unknown>[] | null {\n const start = stdout.indexOf('[');\n if (start === -1) return null;\n try {\n const parsed = JSON.parse(stdout.slice(start)) as unknown;\n return Array.isArray(parsed)\n ? parsed.filter(\n (row): row is Record<string, unknown> =>\n row !== null && typeof row === 'object' && !Array.isArray(row),\n )\n : null;\n } catch {\n return null;\n }\n}\n\n/** `2.1.296 (Claude Code)` to `2.1.296`. */\nexport function parseClaudeVersion(text: string): string | null {\n return /(\\d+)\\.(\\d+)\\.(\\d+)/.exec(text)?.[0] ?? null;\n}\n\n/** Is `version` at or above {@link CLAUDE_CODE_FLOOR}? */\nexport function meetsFloor(version: string, floor: string = CLAUDE_CODE_FLOOR): boolean {\n const a = version.split('.').map(Number);\n const b = floor.split('.').map(Number);\n for (let i = 0; i < 3; i += 1) {\n const x = a[i] ?? 0;\n const y = b[i] ?? 0;\n if (x !== y) return x > y;\n }\n return true;\n}\n\nexport interface ClaudeCodeState {\n binary: ClaudeBinary | null;\n /** The version `claude --version` printed, or null when it could not be read. */\n version: string | null;\n /** False only for a version read and found below the floor. */\n meetsFloor: boolean;\n /** What to do about it, worded for the session the agent runs in. */\n fix?: string;\n}\n\n/**\n * THE FLOOR'S FIX IS ONE THE AGENT RUNS: `claude update` updates the binary in\n * place, and a new session picks it up. Nobody is sent out of the session to\n * do it.\n */\nexport const CLAUDE_UPDATE_FIX =\n 'Run `claude update` in this session, then start a new Claude Code session so the newer version loads.';\n\n/** The binary and its version, read once per command. */\nexport async function readClaudeCode(\n env: NodeJS.ProcessEnv,\n cwd: string,\n find: (env: NodeJS.ProcessEnv) => ClaudeBinary | null = findClaudeBinary,\n): Promise<ClaudeCodeState> {\n const binary = find(env);\n if (binary === null) return { binary, version: null, meetsFloor: true };\n const run = await runClaude(binary, ['--version'], { env, cwd, timeoutMs: 15_000 });\n const version = run.code === 0 ? parseClaudeVersion(run.stdout) : null;\n const ok = version === null || meetsFloor(version);\n return {\n binary,\n version,\n meetsFloor: ok,\n ...(ok ? {} : { fix: CLAUDE_UPDATE_FIX }),\n };\n}\n"],"mappings":";;;AAAA,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,SAAS,WAAW,YAAY,YAAY;AAYrC,IAAM,oBAAoB;AAQ1B,SAAS,gBAAgB,KAA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SAAS,WAAW,SAAiB,QAAgB,mBAA4B;AACtF,QAAM,IAAI,QAAQ,MAAM,GAAG,EAAE,IAAI,MAAM;AACvC,QAAM,IAAI,MAAM,MAAM,GAAG,EAAE,IAAI,MAAM;AACrC,WAAS,IAAI,GAAG,IAAI,GAAG,KAAK,GAAG;AAC7B,UAAM,IAAI,EAAE,CAAC,KAAK;AAClB,UAAM,IAAI,EAAE,CAAC,KAAK;AAClB,QAAI,MAAM,EAAG,QAAO,IAAI;AAAA,EAC1B;AACA,SAAO;AACT;AAiBO,IAAM,oBACX;AAGF,eAAsB,eACpB,KACA,KACA,OAAwD,kBAC9B;AAC1B,QAAM,SAAS,KAAK,GAAG;AACvB,MAAI,WAAW,KAAM,QAAO,EAAE,QAAQ,SAAS,MAAM,YAAY,KAAK;AACtE,QAAM,MAAM,MAAM,UAAU,QAAQ,CAAC,WAAW,GAAG,EAAE,KAAK,KAAK,WAAW,KAAO,CAAC;AAClF,QAAM,UAAU,IAAI,SAAS,IAAI,mBAAmB,IAAI,MAAM,IAAI;AAClE,QAAM,KAAK,YAAY,QAAQ,WAAW,OAAO;AACjD,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,YAAY;AAAA,IACZ,GAAI,KAAK,CAAC,IAAI,EAAE,KAAK,kBAAkB;AAAA,EACzC;AACF;","names":[]}
|
|
@@ -7,11 +7,11 @@ import {
|
|
|
7
7
|
defineTransactionReceipt,
|
|
8
8
|
formatTransaction,
|
|
9
9
|
http
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-NEFNKLBE.js";
|
|
11
11
|
import {
|
|
12
12
|
serializeTransaction,
|
|
13
13
|
toRlp
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-K3I7C2MO.js";
|
|
15
15
|
import {
|
|
16
16
|
decodeFunctionData,
|
|
17
17
|
encodeFunctionData,
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
} from "./chunk-EGELTSPU.js";
|
|
28
28
|
import {
|
|
29
29
|
USDC_ADDRESS
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-27EPWVOY.js";
|
|
31
31
|
|
|
32
32
|
// node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/_esm/op-stack/contracts.js
|
|
33
33
|
var contracts = {
|
|
@@ -323,4 +323,4 @@ export {
|
|
|
323
323
|
prepareUsdcSend,
|
|
324
324
|
broadcastUsdcSend
|
|
325
325
|
};
|
|
326
|
-
//# sourceMappingURL=chunk-
|
|
326
|
+
//# sourceMappingURL=chunk-R5LCN54M.js.map
|