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
|
@@ -53,6 +53,26 @@ async function selectOne(opts) {
|
|
|
53
53
|
return isCancel(answer) ? null : answer;
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
|
+
async function selectMany(opts) {
|
|
57
|
+
const { multiselect, isCancel } = await import("./dist-3LOO6M4U.js");
|
|
58
|
+
const streams = resolveStreams(opts.streams ?? {});
|
|
59
|
+
return withInputEnd(streams, null, async (signal) => {
|
|
60
|
+
const answer = await multiselect({
|
|
61
|
+
message: opts.message,
|
|
62
|
+
options: opts.choices.map((c) => ({
|
|
63
|
+
value: c.value,
|
|
64
|
+
label: c.label,
|
|
65
|
+
...c.hint !== void 0 ? { hint: c.hint } : {}
|
|
66
|
+
})),
|
|
67
|
+
initialValues: [...opts.initialValues],
|
|
68
|
+
required: opts.required ?? true,
|
|
69
|
+
input: streams.input,
|
|
70
|
+
output: streams.output,
|
|
71
|
+
signal
|
|
72
|
+
});
|
|
73
|
+
return isCancel(answer) ? null : answer;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
56
76
|
async function askText(opts) {
|
|
57
77
|
const { text, isCancel } = await import("./dist-3LOO6M4U.js");
|
|
58
78
|
const streams = resolveStreams(opts.streams ?? {});
|
|
@@ -81,10 +101,21 @@ async function confirmChoice(message, initialValue = true, streams = {}) {
|
|
|
81
101
|
return isCancel(answer) ? false : answer;
|
|
82
102
|
});
|
|
83
103
|
}
|
|
104
|
+
async function intro(message) {
|
|
105
|
+
const clack = await import("./dist-3LOO6M4U.js");
|
|
106
|
+
clack.intro(message, { output: process.stderr });
|
|
107
|
+
}
|
|
108
|
+
async function outro(message) {
|
|
109
|
+
const clack = await import("./dist-3LOO6M4U.js");
|
|
110
|
+
clack.outro(message, { output: process.stderr });
|
|
111
|
+
}
|
|
84
112
|
|
|
85
113
|
export {
|
|
86
114
|
selectOne,
|
|
115
|
+
selectMany,
|
|
87
116
|
askText,
|
|
88
|
-
confirmChoice
|
|
117
|
+
confirmChoice,
|
|
118
|
+
intro,
|
|
119
|
+
outro
|
|
89
120
|
};
|
|
90
|
-
//# sourceMappingURL=chunk-
|
|
121
|
+
//# sourceMappingURL=chunk-DOQGNFHM.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/clack.ts"],"sourcesContent":["import type { Readable, Writable } from 'node:stream';\n\n/**\n * The pretty-prompt renderer behind the install walkthrough's seams.\n *\n * @clack/prompts is a devDependency BUNDLED by tsup (published `dependencies`\n * stays `{}`), and every entry point here is behind a dynamic `import()` so it\n * lands in its own split chunk: a `search` or `doctor` run never parses it.\n *\n * Nothing in this module is reachable from a machine run. Commands call it only\n * on the real interactive path (a TTY on both stdout and stdin, no `--json`),\n * and always through an injectable seam, so unit tests supply answers directly\n * and never touch clack or a terminal.\n *\n * Prompts render on STDERR, like every other prompt in this CLI: stdout carries\n * the human walkthrough (or a single JSON envelope) and must not be interleaved\n * with prompt chrome.\n */\n\n/** Cancel (ctrl-C, escape) is not an answer. Callers map `null` to their own default. */\nexport type Cancelled = null;\n\nexport interface SelectChoice<T extends string> {\n value: T;\n label: string;\n /** The one line of consequence shown beside the label. */\n hint?: string;\n}\n\n/** Streams a prompt reads and draws on. Injected by tests; defaults to the real ones. */\ninterface PromptStreams {\n input?: Readable;\n output?: Writable;\n}\n\n/** DECTCUM show-cursor. Written on the EOF path in case the prompt did not get to. */\nconst SHOW_CURSOR = '\\x1b[?25h';\n\n/**\n * Settle a prompt when its input goes away instead of hanging forever.\n *\n * Ctrl-D at a clack prompt leaves its promise unsettled: no resolve, no reject,\n * no cancel symbol. The process then dies on an unsettled top-level await with\n * exit 13, nothing printed, and the cursor still hidden. The readline seam this\n * replaced handled it on purpose (\"ctrl-D mid-prompt reads as the default\"), and\n * that behavior has to survive the renderer swap.\n *\n * \"Input goes away\" is two different events, and only covering one of them was\n * the original bug:\n *\n * - The STREAM ends. A pipe closes, a harness detaches, stdin was already at\n * EOF. Caught via `end` / `close`.\n * - The ctrl-D BYTE (0x04) arrives with the stream still open. This is what a\n * real terminal sends, and it is the common case. A prompt puts stdin in raw\n * mode, where 0x04 is ordinary data rather than EOF, so no stream event ever\n * fires; clack has no binding for it and simply keeps waiting. Caught via the\n * `keypress` decoder readline installs, which is a read-only view of the same\n * bytes: listening there takes nothing away from the prompt, where a `data`\n * listener would risk flipping the stream to flowing before clack reads it.\n *\n * Two mechanisms settle it, because one of them is advisory. The AbortSignal is\n * clack's own teardown: it flips the prompt to `cancel`, which restores the\n * cursor and raw mode and resolves with the cancel symbol. The race is the\n * guarantee, for a prompt that is not yet listening or never settles anyway; on\n * that path we restore the cursor ourselves, since no prompt did.\n */\nfunction withInputEnd<T>(\n streams: Required<PromptStreams>,\n onEnd: T,\n run: (signal: AbortSignal) => Promise<T>,\n): Promise<T> {\n const controller = new AbortController();\n let settleEnd: (() => void) | undefined;\n const ended = new Promise<T>((resolve) => {\n settleEnd = () => {\n streams.output.write(SHOW_CURSOR);\n resolve(onEnd);\n };\n });\n\n const end = (): void => {\n controller.abort();\n settleEnd?.();\n };\n const onKeypress = (_text: string | undefined, key?: { name?: string; ctrl?: boolean }): void => {\n if (key?.ctrl === true && key.name === 'd') end();\n };\n\n streams.input.on('keypress', onKeypress);\n // A stream that finished before we got here never emits `end` again, so ask.\n if (streams.input.readableEnded) {\n queueMicrotask(end);\n } else {\n streams.input.once('end', end);\n streams.input.once('close', end);\n }\n\n return Promise.race([run(controller.signal), ended]).finally(() => {\n streams.input.off('keypress', onKeypress);\n streams.input.off('end', end);\n streams.input.off('close', end);\n });\n}\n\nfunction resolveStreams(streams: PromptStreams): Required<PromptStreams> {\n return { input: streams.input ?? process.stdin, output: streams.output ?? process.stderr };\n}\n\n/**\n * A single-choice list. Returns the chosen value, or `null` when the operator\n * cancelled or the input ended, both of which callers treat as \"leave everything\n * as it was\".\n */\nexport async function selectOne<T extends string>(opts: {\n message: string;\n choices: readonly SelectChoice<T>[];\n initialValue: T;\n streams?: PromptStreams;\n}): Promise<T | Cancelled> {\n const { select, isCancel } = await import('@clack/prompts');\n const streams = resolveStreams(opts.streams ?? {});\n return withInputEnd<T | Cancelled>(streams, null, async (signal) => {\n // Instantiated at `string`, not at `T`: clack's `Option<Value>` is a conditional\n // type that a generic `T extends string` cannot resolve. The values come from\n // this call's own choices, so narrowing the answer back is sound.\n const answer = await select<string>({\n message: opts.message,\n options: opts.choices.map((c) => ({\n value: c.value as string,\n label: c.label,\n ...(c.hint !== undefined ? { hint: c.hint } : {}),\n })),\n initialValue: opts.initialValue,\n input: streams.input,\n output: streams.output,\n signal,\n });\n return isCancel(answer) ? null : (answer as T);\n });\n}\n\n/** A multi-choice list. Returns the selected values, or `null` when cancelled. */\nexport async function selectMany<T extends string>(opts: {\n message: string;\n choices: readonly SelectChoice<T>[];\n initialValues: readonly T[];\n required?: boolean;\n streams?: PromptStreams;\n}): Promise<T[] | Cancelled> {\n const { multiselect, isCancel } = await import('@clack/prompts');\n const streams = resolveStreams(opts.streams ?? {});\n return withInputEnd<T[] | Cancelled>(streams, null, async (signal) => {\n const answer = await multiselect<string>({\n message: opts.message,\n options: opts.choices.map((c) => ({\n value: c.value as string,\n label: c.label,\n ...(c.hint !== undefined ? { hint: c.hint } : {}),\n })),\n initialValues: [...opts.initialValues] as string[],\n required: opts.required ?? true,\n input: streams.input,\n output: streams.output,\n signal,\n });\n return isCancel(answer) ? null : (answer as T[]);\n });\n}\n\n/** A one-line answer. Returns what was typed, or `null` when cancelled or the input ended. */\nexport async function askText(opts: {\n message: string;\n placeholder?: string;\n streams?: PromptStreams;\n}): Promise<string | Cancelled> {\n const { text, isCancel } = await import('@clack/prompts');\n const streams = resolveStreams(opts.streams ?? {});\n return withInputEnd<string | Cancelled>(streams, null, async (signal) => {\n const answer = await text({\n message: opts.message,\n ...(opts.placeholder !== undefined ? { placeholder: opts.placeholder } : {}),\n input: streams.input,\n output: streams.output,\n signal,\n });\n return isCancel(answer) ? null : answer;\n });\n}\n\n/** A yes/no confirm. Cancelling, or an input that ends, reads as no. */\nexport async function confirmChoice(\n message: string,\n initialValue = true,\n streams: PromptStreams = {},\n): Promise<boolean> {\n const { confirm, isCancel } = await import('@clack/prompts');\n const resolved = resolveStreams(streams);\n return withInputEnd<boolean>(resolved, false, async (signal) => {\n const answer = await confirm({\n message,\n initialValue,\n input: resolved.input,\n output: resolved.output,\n signal,\n });\n return isCancel(answer) ? false : answer;\n });\n}\n\n/** Open the walkthrough's prompt sequence with a title bar. */\nexport async function intro(message: string): Promise<void> {\n const clack = await import('@clack/prompts');\n clack.intro(message, { output: process.stderr });\n}\n\n/** Close it, so the last prompt is not left dangling above plain stdout lines. */\nexport async function outro(message: string): Promise<void> {\n const clack = await import('@clack/prompts');\n clack.outro(message, { output: process.stderr });\n}\n"],"mappings":";;;AAoCA,IAAM,cAAc;AA8BpB,SAAS,aACP,SACA,OACA,KACY;AACZ,QAAM,aAAa,IAAI,gBAAgB;AACvC,MAAI;AACJ,QAAM,QAAQ,IAAI,QAAW,CAAC,YAAY;AACxC,gBAAY,MAAM;AAChB,cAAQ,OAAO,MAAM,WAAW;AAChC,cAAQ,KAAK;AAAA,IACf;AAAA,EACF,CAAC;AAED,QAAM,MAAM,MAAY;AACtB,eAAW,MAAM;AACjB,gBAAY;AAAA,EACd;AACA,QAAM,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IE;AAC9B,QAAM,EAAE,MAAM,SAAS,IAAI,MAAM,OAAO,oBAAgB;AACxD,QAAM,UAAU,eAAe,KAAK,WAAW,CAAC,CAAC;AACjD,SAAO,aAAiC,SAAS,MAAM,OAAO,WAAW;AACvE,UAAM,SAAS,MAAM,KAAK;AAAA,MACxB,SAAS,KAAK;AAAA,MACd,GAAI,KAAK,gBAAgB,SAAY,EAAE,aAAa,KAAK,YAAY,IAAI,CAAC;AAAA,MAC1E,OAAO,QAAQ;AAAA,MACf,QAAQ,QAAQ;AAAA,MAChB;AAAA,IACF,CAAC;AACD,WAAO,SAAS,MAAM,IAAI,OAAO;AAAA,EACnC,CAAC;AACH;AAGA,eAAsB,cACpB,SACA,eAAe,MACf,UAAyB,CAAC,GACR;AAClB,QAAM,EAAE,SAAS,SAAS,IAAI,MAAM,OAAO,oBAAgB;AAC3D,QAAM,WAAW,eAAe,OAAO;AACvC,SAAO,aAAsB,UAAU,OAAO,OAAO,WAAW;AAC9D,UAAM,SAAS,MAAM,QAAQ;AAAA,MAC3B;AAAA,MACA;AAAA,MACA,OAAO,SAAS;AAAA,MAChB,QAAQ,SAAS;AAAA,MACjB;AAAA,IACF,CAAC;AACD,WAAO,SAAS,MAAM,IAAI,QAAQ;AAAA,EACpC,CAAC;AACH;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/lib/clack.ts"],"sourcesContent":["import type { Readable, Writable } from 'node:stream';\n\n/**\n * The pretty-prompt renderer behind the install walkthrough's seams.\n *\n * @clack/prompts is a devDependency BUNDLED by tsup (published `dependencies`\n * stays `{}`), and every entry point here is behind a dynamic `import()` so it\n * lands in its own split chunk: a `search` or `doctor` run never parses it.\n *\n * Nothing in this module is reachable from a machine run. Commands call it only\n * on the real interactive path (a TTY on both stdout and stdin, no `--json`),\n * and always through an injectable seam, so unit tests supply answers directly\n * and never touch clack or a terminal.\n *\n * Prompts render on STDERR, like every other prompt in this CLI: stdout carries\n * the human walkthrough (or a single JSON envelope) and must not be interleaved\n * with prompt chrome.\n */\n\n/** Cancel (ctrl-C, escape) is not an answer. Callers map `null` to their own default. */\nexport type Cancelled = null;\n\nexport interface SelectChoice<T extends string> {\n value: T;\n label: string;\n /** The one line of consequence shown beside the label. */\n hint?: string;\n}\n\n/** Streams a prompt reads and draws on. Injected by tests; defaults to the real ones. */\ninterface PromptStreams {\n input?: Readable;\n output?: Writable;\n}\n\n/** DECTCUM show-cursor. Written on the EOF path in case the prompt did not get to. */\nconst SHOW_CURSOR = '\\x1b[?25h';\n\n/**\n * Settle a prompt when its input goes away instead of hanging forever.\n *\n * Ctrl-D at a clack prompt leaves its promise unsettled: no resolve, no reject,\n * no cancel symbol. The process then dies on an unsettled top-level await with\n * exit 13, nothing printed, and the cursor still hidden. The readline seam this\n * replaced handled it on purpose (\"ctrl-D mid-prompt reads as the default\"), and\n * that behavior has to survive the renderer swap.\n *\n * \"Input goes away\" is two different events, and only covering one of them was\n * the original bug:\n *\n * - The STREAM ends. A pipe closes, a harness detaches, stdin was already at\n * EOF. Caught via `end` / `close`.\n * - The ctrl-D BYTE (0x04) arrives with the stream still open. This is what a\n * real terminal sends, and it is the common case. A prompt puts stdin in raw\n * mode, where 0x04 is ordinary data rather than EOF, so no stream event ever\n * fires; clack has no binding for it and simply keeps waiting. Caught via the\n * `keypress` decoder readline installs, which is a read-only view of the same\n * bytes: listening there takes nothing away from the prompt, where a `data`\n * listener would risk flipping the stream to flowing before clack reads it.\n *\n * Two mechanisms settle it, because one of them is advisory. The AbortSignal is\n * clack's own teardown: it flips the prompt to `cancel`, which restores the\n * cursor and raw mode and resolves with the cancel symbol. The race is the\n * guarantee, for a prompt that is not yet listening or never settles anyway; on\n * that path we restore the cursor ourselves, since no prompt did.\n */\nfunction withInputEnd<T>(\n streams: Required<PromptStreams>,\n onEnd: T,\n run: (signal: AbortSignal) => Promise<T>,\n): Promise<T> {\n const controller = new AbortController();\n let settleEnd: (() => void) | undefined;\n const ended = new Promise<T>((resolve) => {\n settleEnd = () => {\n streams.output.write(SHOW_CURSOR);\n resolve(onEnd);\n };\n });\n\n const end = (): void => {\n controller.abort();\n settleEnd?.();\n };\n const onKeypress = (_text: string | undefined, key?: { name?: string; ctrl?: boolean }): void => {\n if (key?.ctrl === true && key.name === 'd') end();\n };\n\n streams.input.on('keypress', onKeypress);\n // A stream that finished before we got here never emits `end` again, so ask.\n if (streams.input.readableEnded) {\n queueMicrotask(end);\n } else {\n streams.input.once('end', end);\n streams.input.once('close', end);\n }\n\n return Promise.race([run(controller.signal), ended]).finally(() => {\n streams.input.off('keypress', onKeypress);\n streams.input.off('end', end);\n streams.input.off('close', end);\n });\n}\n\nfunction resolveStreams(streams: PromptStreams): Required<PromptStreams> {\n return { input: streams.input ?? process.stdin, output: streams.output ?? process.stderr };\n}\n\n/**\n * A single-choice list. Returns the chosen value, or `null` when the operator\n * cancelled or the input ended, both of which callers treat as \"leave everything\n * as it was\".\n */\nexport async function selectOne<T extends string>(opts: {\n message: string;\n choices: readonly SelectChoice<T>[];\n initialValue: T;\n streams?: PromptStreams;\n}): Promise<T | Cancelled> {\n const { select, isCancel } = await import('@clack/prompts');\n const streams = resolveStreams(opts.streams ?? {});\n return withInputEnd<T | Cancelled>(streams, null, async (signal) => {\n // Instantiated at `string`, not at `T`: clack's `Option<Value>` is a conditional\n // type that a generic `T extends string` cannot resolve. The values come from\n // this call's own choices, so narrowing the answer back is sound.\n const answer = await select<string>({\n message: opts.message,\n options: opts.choices.map((c) => ({\n value: c.value as string,\n label: c.label,\n ...(c.hint !== undefined ? { hint: c.hint } : {}),\n })),\n initialValue: opts.initialValue,\n input: streams.input,\n output: streams.output,\n signal,\n });\n return isCancel(answer) ? null : (answer as T);\n });\n}\n\n/** A multi-choice list. Returns the selected values, or `null` when cancelled. */\nexport async function selectMany<T extends string>(opts: {\n message: string;\n choices: readonly SelectChoice<T>[];\n initialValues: readonly T[];\n required?: boolean;\n streams?: PromptStreams;\n}): Promise<T[] | Cancelled> {\n const { multiselect, isCancel } = await import('@clack/prompts');\n const streams = resolveStreams(opts.streams ?? {});\n return withInputEnd<T[] | Cancelled>(streams, null, async (signal) => {\n const answer = await multiselect<string>({\n message: opts.message,\n options: opts.choices.map((c) => ({\n value: c.value as string,\n label: c.label,\n ...(c.hint !== undefined ? { hint: c.hint } : {}),\n })),\n initialValues: [...opts.initialValues] as string[],\n required: opts.required ?? true,\n input: streams.input,\n output: streams.output,\n signal,\n });\n return isCancel(answer) ? null : (answer as T[]);\n });\n}\n\n/** A one-line answer. Returns what was typed, or `null` when cancelled or the input ended. */\nexport async function askText(opts: {\n message: string;\n placeholder?: string;\n streams?: PromptStreams;\n}): Promise<string | Cancelled> {\n const { text, isCancel } = await import('@clack/prompts');\n const streams = resolveStreams(opts.streams ?? {});\n return withInputEnd<string | Cancelled>(streams, null, async (signal) => {\n const answer = await text({\n message: opts.message,\n ...(opts.placeholder !== undefined ? { placeholder: opts.placeholder } : {}),\n input: streams.input,\n output: streams.output,\n signal,\n });\n return isCancel(answer) ? null : answer;\n });\n}\n\n/** A yes/no confirm. Cancelling, or an input that ends, reads as no. */\nexport async function confirmChoice(\n message: string,\n initialValue = true,\n streams: PromptStreams = {},\n): Promise<boolean> {\n const { confirm, isCancel } = await import('@clack/prompts');\n const resolved = resolveStreams(streams);\n return withInputEnd<boolean>(resolved, false, async (signal) => {\n const answer = await confirm({\n message,\n initialValue,\n input: resolved.input,\n output: resolved.output,\n signal,\n });\n return isCancel(answer) ? false : answer;\n });\n}\n\n/** Open the walkthrough's prompt sequence with a title bar. */\nexport async function intro(message: string): Promise<void> {\n const clack = await import('@clack/prompts');\n clack.intro(message, { output: process.stderr });\n}\n\n/** Close it, so the last prompt is not left dangling above plain stdout lines. */\nexport async function outro(message: string): Promise<void> {\n const clack = await import('@clack/prompts');\n clack.outro(message, { output: process.stderr });\n}\n"],"mappings":";;;AAoCA,IAAM,cAAc;AA8BpB,SAAS,aACP,SACA,OACA,KACY;AACZ,QAAM,aAAa,IAAI,gBAAgB;AACvC,MAAI;AACJ,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;AAAA,EACnC,CAAC;AACH;AAGA,eAAsB,cACpB,SACA,eAAe,MACf,UAAyB,CAAC,GACR;AAClB,QAAM,EAAE,SAAS,SAAS,IAAI,MAAM,OAAO,oBAAgB;AAC3D,QAAM,WAAW,eAAe,OAAO;AACvC,SAAO,aAAsB,UAAU,OAAO,OAAO,WAAW;AAC9D,UAAM,SAAS,MAAM,QAAQ;AAAA,MAC3B;AAAA,MACA;AAAA,MACA,OAAO,SAAS;AAAA,MAChB,QAAQ,SAAS;AAAA,MACjB;AAAA,IACF,CAAC;AACD,WAAO,SAAS,MAAM,IAAI,QAAQ;AAAA,EACpC,CAAC;AACH;AAGA,eAAsB,MAAM,SAAgC;AAC1D,QAAM,QAAQ,MAAM,OAAO,oBAAgB;AAC3C,QAAM,MAAM,SAAS,EAAE,QAAQ,QAAQ,OAAO,CAAC;AACjD;AAGA,eAAsB,MAAM,SAAgC;AAC1D,QAAM,QAAQ,MAAM,OAAO,oBAAgB;AAC3C,QAAM,MAAM,SAAS,EAAE,QAAQ,QAAQ,OAAO,CAAC;AACjD;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
resolvePublicDestination
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-JKKAIPTU.js";
|
|
5
5
|
import {
|
|
6
6
|
releaseUnchargedExposure
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-7ZRL2LBQ.js";
|
|
8
8
|
import {
|
|
9
9
|
withFileLock
|
|
10
10
|
} from "./chunk-MEFB5KHA.js";
|
|
@@ -15,9 +15,11 @@ import {
|
|
|
15
15
|
hasCode
|
|
16
16
|
} from "./chunk-2I4QTOLB.js";
|
|
17
17
|
import {
|
|
18
|
-
USDC_ADDRESS
|
|
18
|
+
USDC_ADDRESS
|
|
19
|
+
} from "./chunk-27EPWVOY.js";
|
|
20
|
+
import {
|
|
19
21
|
writeFileAtomic
|
|
20
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-7WEQQJLG.js";
|
|
21
23
|
import {
|
|
22
24
|
downloadsDir,
|
|
23
25
|
paidLedgerPath
|
|
@@ -401,4 +403,4 @@ export {
|
|
|
401
403
|
writeAll,
|
|
402
404
|
createUniqueFile
|
|
403
405
|
};
|
|
404
|
-
//# sourceMappingURL=chunk-
|
|
406
|
+
//# sourceMappingURL=chunk-FW75G2W4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/router/paid.ts"],"sourcesContent":["import { randomBytes } from 'node:crypto';\nimport { appendFile, mkdir, open, readFile, rm, type FileHandle } from 'node:fs/promises';\nimport { request as httpsRequest } from 'node:https';\nimport type { LookupFunction } from 'node:net';\nimport { dirname, join } from 'node:path';\nimport { writeFileAtomic } from '../lib/atomic-json';\nimport { resolvePublicDestination, type DestinationOptions } from '../lib/destination';\nimport { hasCode } from '../lib/errno';\nimport { withFileLock } from '../lib/lock';\nimport { downloadsDir, paidLedgerPath } from '../lib/paths';\nimport { mask } from '../lib/redact';\nimport { USDC_ADDRESS } from '../lib/usdc-balance';\nimport { releaseUnchargedExposure } from '../lib/wallet/spend';\n\n/**\n * WHAT A PAID ROUTER CALL BOUGHT, KEPT ON THIS MACHINE. One JSON line per paid\n * call in `~/.tenjin/paid/ledger.jsonl`: who was paid, for what, how much, the\n * settlement it carried and the files it saved. It is the user's own record\n * and the receipt `tenjin payments reconcile` resolves an unknown settlement\n * against. Nothing here can fail a lookup: every write swallows its own error.\n */\n\nexport type Settlement = 'settled' | 'unknown' | 'not_charged';\n\n/** The EIP-3009 authorization that was signed, enough to ask the token later\n * whether it was used. */\nexport interface SignedAuthorization {\n from: string;\n nonce: string;\n /** Unix seconds; after it the authorization can no longer be used. */\n validBefore: string;\n}\n\nexport interface PaidRecord {\n version: 1;\n ts: string;\n capabilityId: string;\n provider: string;\n /** The service's display name, when its decision or spec carried one. */\n label?: string;\n url: string;\n /** The input or query sent, masked and cut to {@link MAX_SENT_CHARS}. */\n sent: string;\n amountAtomic: string;\n txHash?: string;\n settlement: Settlement;\n savedFiles: string[];\n authorization?: SignedAuthorization;\n /** When reconcile last asked the chain about it, so a slow or rate-limited\n * RPC is not asked about the same record on every lookup. */\n lastCheckedAt?: string;\n}\n\nexport const MAX_SENT_CHARS = 4_096;\n\n/**\n * A JSON value with every object key and string leaf masked on its own. The\n * mask anchors on word boundaries, which a serialized string hides: after an\n * escaped `\\n` a key reads as `nsk-ant-…`, one word, and passes.\n */\nexport function maskDeep(value: unknown): unknown {\n if (typeof value === 'string') return mask(value);\n if (Array.isArray(value)) return value.map(maskDeep);\n if (value !== null && typeof value === 'object') {\n return Object.fromEntries(\n Object.entries(value as Record<string, unknown>).map(([key, entry]) => [\n mask(key),\n maskDeep(entry),\n ]),\n );\n }\n return value;\n}\n\n/** The input or query as it is recorded: secrets masked, then cut. */\nexport function recordedSent(sent: string): string {\n return mask(sent).slice(0, MAX_SENT_CHARS);\n}\n\nexport async function appendPaidRecord(dataDir: string, record: PaidRecord): Promise<void> {\n try {\n const path = paidLedgerPath(dataDir);\n await mkdir(dirname(path), { recursive: true, mode: 0o700 });\n // Under the lock reconcile rewrites with, so an append is never lost to it.\n await withFileLock(`${path}.lock`, () =>\n appendFile(path, `${JSON.stringify(record)}\\n`, { mode: 0o600 }),\n );\n } catch {\n // The record is the user's convenience; the lookup already happened.\n }\n}\n\n/**\n * A JOB'S ROW, FINISHED IN PLACE. A paid call whose seller was still working\n * is recorded when it is paid, so a crash mid-poll loses no row; the files the\n * job later saved, and the settlement its last answer named, are written onto\n * that same row, found by its authorization's nonce, under the lock reconcile\n * rewrites with. One payment, one row. Never throws.\n */\nexport async function updatePaidRecord(\n dataDir: string,\n nonce: string,\n patch: { savedFiles?: string[]; txHash?: string },\n): Promise<void> {\n try {\n const path = paidLedgerPath(dataDir);\n const key = nonce.toLowerCase();\n await withFileLock(`${path}.lock`, async () => {\n const current = parseLedger(await readFile(path, 'utf8').catch(() => ''));\n let found = false;\n const lines = current.map(({ line, record }) => {\n if (record?.authorization?.nonce.toLowerCase() !== key) return line;\n found = true;\n return JSON.stringify({\n ...record,\n ...(patch.savedFiles !== undefined ? { savedFiles: patch.savedFiles } : {}),\n ...(patch.txHash !== undefined && record.settlement === 'unknown'\n ? { txHash: patch.txHash, settlement: 'settled' }\n : {}),\n });\n });\n if (found) {\n await writeFileAtomic(path, lines.map((line) => `${line}\\n`).join(''), { mode: 0o600 });\n }\n });\n } catch {\n // The record is the user's convenience; the lookup already happened.\n }\n}\n\n/** `authorizationState(address,bytes32)`: the first four bytes of its keccak-256. */\nconst AUTHORIZATION_STATE_SELECTOR = '0xe94a0102';\nconst WORD_RE = /^0x[0-9a-fA-F]{64}$/;\n/** How many unknown settlements one pass asks the chain about. */\nexport const MAX_RECONCILE_CHECKS = 3;\n/** How long a record the chain could not answer for waits before it is asked\n * about again by the lookup-time pass. */\nexport const RECHECK_MS = 10 * 60_000;\nconst RECONCILE_TIMEOUT_MS = 1_500;\n\n/**\n * Whether USDC on Base has used this authorization: true once a facilitator\n * settled it, false while it has not. Null when the RPC could not say.\n */\nexport async function authorizationUsed(\n authorization: SignedAuthorization,\n rpcUrl: string,\n opts: { fetchImpl?: typeof fetch; timeoutMs?: number; blockTag?: string } = {},\n): Promise<boolean | null> {\n const result = await rpcCall(\n rpcUrl,\n 'eth_call',\n [\n {\n to: USDC_ADDRESS,\n data: `${AUTHORIZATION_STATE_SELECTOR}${authorization.from.slice(2).toLowerCase().padStart(64, '0')}${authorization.nonce.slice(2).toLowerCase()}`,\n },\n opts.blockTag ?? 'latest',\n ],\n opts,\n );\n if (typeof result !== 'string' || !WORD_RE.test(result)) return null;\n return BigInt(result) !== 0n;\n}\n\n/**\n * The chain's own clock: the latest block's number and timestamp (seconds).\n * Expiry is decided against it, not this machine's clock, and the state is\n * read at that same block: a node that lags, or a clock running ahead, then\n * agrees with itself. Null when the RPC could not say.\n */\nexport async function latestBlock(\n rpcUrl: string,\n opts: { fetchImpl?: typeof fetch; timeoutMs?: number } = {},\n): Promise<{ tag: string; timestamp: number } | null> {\n const result = await rpcCall(rpcUrl, 'eth_getBlockByNumber', ['latest', false], opts);\n if (result === null || typeof result !== 'object') return null;\n const { number, timestamp } = result as { number?: unknown; timestamp?: unknown };\n if (typeof number !== 'string' || !/^0x[0-9a-fA-F]+$/.test(number)) return null;\n if (typeof timestamp !== 'string' || !/^0x[0-9a-fA-F]+$/.test(timestamp)) return null;\n return { tag: number, timestamp: Number(BigInt(timestamp)) };\n}\n\nasync function rpcCall(\n rpcUrl: string,\n method: string,\n params: unknown[],\n opts: { fetchImpl?: typeof fetch; timeoutMs?: number },\n): Promise<unknown> {\n try {\n const res = await (opts.fetchImpl ?? fetch)(rpcUrl, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ jsonrpc: '2.0', id: 1, method, params }),\n signal: AbortSignal.timeout(opts.timeoutMs ?? RECONCILE_TIMEOUT_MS),\n });\n if (!res.ok) return null;\n return ((await res.json()) as { result?: unknown } | null)?.result ?? null;\n } catch {\n return null;\n }\n}\n\nexport interface ReconcileOutcome {\n /** Records asked about in this pass. */\n checked: number;\n /** The authorization was used: the amount was charged. */\n settled: number;\n /** It expired unused: nothing was charged. */\n notCharged: number;\n /** Still unknown: not yet expired, no authorization on record, or the RPC\n * could not answer. */\n unknown: number;\n /** What the not-charged payments gave back to today's automatic budget. */\n releasedAtomic: string;\n}\n\n/**\n * RESOLVE \"SETTLEMENT UNKNOWN\" FROM THE CHAIN. A paid call whose seller never\n * confirmed settlement leaves a record marked `unknown`. Once the chain's\n * latest block is past its authorization's `validBefore`, the token's own\n * `authorizationState(from, nonce)` read AT THAT BLOCK is final: used means\n * charged, unused means it can never be charged, since no later block can\n * carry it. This machine's clock only decides whether the chain is worth\n * asking. At most `max` records are asked about per pass, and\n * a record the RPC cannot answer for stays unknown, stamped `lastCheckedAt`,\n * and is not asked about again for `recheckMs`.\n *\n * The chain is asked outside the lock; the file is re-read and rewritten under\n * it, so an append made meanwhile is kept.\n */\nexport async function reconcilePayments(\n dataDir: string,\n opts: {\n rpcUrl: string;\n fetchImpl?: typeof fetch;\n now?: () => number;\n max?: number;\n timeoutMs?: number;\n /** Defaults to {@link RECHECK_MS}; the command passes 0. */\n recheckMs?: number;\n },\n): Promise<ReconcileOutcome> {\n const path = paidLedgerPath(dataDir);\n const now = (opts.now ?? Date.now)();\n const records = parseLedger(await readFile(path, 'utf8').catch(() => ''));\n const open = records.filter(\n (entry): entry is { line: string; record: PaidRecord } =>\n entry.record !== null && entry.record.settlement === 'unknown',\n );\n const recheckMs = opts.recheckMs ?? RECHECK_MS;\n const due = open.filter(\n ({ record }) =>\n record.authorization !== undefined &&\n Number(record.authorization.validBefore) * 1_000 < now &&\n (record.lastCheckedAt === undefined || now - Date.parse(record.lastCheckedAt) >= recheckMs),\n );\n const answers = new Map<string, Settlement>();\n const asked = new Set<string>();\n let checked = 0;\n const rpc = {\n ...(opts.fetchImpl !== undefined ? { fetchImpl: opts.fetchImpl } : {}),\n ...(opts.timeoutMs !== undefined ? { timeoutMs: opts.timeoutMs } : {}),\n };\n const block = due.length > 0 ? await latestBlock(opts.rpcUrl, rpc) : null;\n for (const { record } of due.slice(0, opts.max ?? MAX_RECONCILE_CHECKS)) {\n // Not past validBefore on the chain yet: not asked, and not stamped.\n if (block !== null && Number(record.authorization!.validBefore) >= block.timestamp) continue;\n checked += 1;\n asked.add(record.authorization!.nonce);\n if (block === null) continue;\n const used = await authorizationUsed(record.authorization!, opts.rpcUrl, {\n ...rpc,\n blockTag: block.tag,\n });\n if (used !== null) answers.set(record.authorization!.nonce, used ? 'settled' : 'not_charged');\n }\n // NOT CHARGED GIVES THE DAILY BUDGET BACK FIRST: exactly that payment's\n // exposure, by its nonce, while it is still inside the window that counted\n // it. Only then is the record marked; a release that could not be written\n // leaves it unknown, and the next pass asks again. A second release of the\n // same nonce finds nothing, so a retry never gives back twice.\n let releasedAtomic = 0n;\n for (const [nonce, answer] of [...answers]) {\n if (answer !== 'not_charged') continue;\n const released = await releaseUnchargedExposure(dataDir, nonce, {\n ...(opts.now !== undefined ? { now: opts.now } : {}),\n });\n if (released === null) answers.delete(nonce);\n else releasedAtomic += released;\n }\n if (asked.size > 0) {\n await withFileLock(`${path}.lock`, async () => {\n const current = parseLedger(await readFile(path, 'utf8').catch(() => ''));\n const lines = current.map(({ line, record }) => {\n const nonce =\n record?.settlement === 'unknown' && record.authorization !== undefined\n ? record.authorization.nonce\n : undefined;\n if (nonce === undefined || !asked.has(nonce)) return line;\n const answer = answers.get(nonce);\n const stamp = new Date(now).toISOString();\n return JSON.stringify(\n answer === undefined\n ? { ...record, lastCheckedAt: stamp }\n : { ...record, settlement: answer, lastCheckedAt: stamp, reconciledAt: stamp },\n );\n });\n await writeFileAtomic(path, lines.map((line) => `${line}\\n`).join(''), { mode: 0o600 });\n });\n }\n const settled = [...answers.values()].filter((value) => value === 'settled').length;\n return {\n checked,\n settled,\n notCharged: answers.size - settled,\n unknown: open.length - answers.size,\n releasedAtomic: releasedAtomic.toString(),\n };\n}\n\n/** Every paid record in the ledger, oldest first; a line that is not one is skipped. */\nexport async function readPaidRecords(dataDir: string): Promise<PaidRecord[]> {\n const raw = await readFile(paidLedgerPath(dataDir), 'utf8').catch(() => '');\n return parseLedger(raw).flatMap(({ record }) => (record === null ? [] : [record]));\n}\n\n/** Every line, and the record it holds when it is one; other lines ride along. */\nfunction parseLedger(raw: string): { line: string; record: PaidRecord | null }[] {\n return raw\n .split('\\n')\n .filter((line) => line.trim().length > 0)\n .map((line) => {\n try {\n const value = JSON.parse(line) as PaidRecord;\n return { line, record: value !== null && value.version === 1 ? value : null };\n } catch {\n return { line, record: null };\n }\n });\n}\n\n/** The media a paid result links to, by the extension its path ends in. */\nconst MEDIA_EXTENSIONS = new Set([\n 'png',\n 'jpg',\n 'jpeg',\n 'webp',\n 'gif',\n 'svg',\n 'mp3',\n 'wav',\n 'm4a',\n 'ogg',\n 'mp4',\n 'webm',\n 'mov',\n]);\nexport const MAX_MEDIA_FILES = 5;\nexport const MAX_MEDIA_BYTES = 200 * 1024 * 1024;\nexport const MEDIA_TIMEOUT_MS = 60_000;\nconst MAX_REDIRECTS = 3;\nconst URL_RE = /https:\\/\\/[^\\s\"'<>\\\\]+/g;\n\n/** Every https URL in the result whose path ends in a media extension, in\n * order and without repeats, at most {@link MAX_MEDIA_FILES}. */\nexport function mediaUrlsIn(result: string, limit = MAX_MEDIA_FILES): string[] {\n const found: string[] = [];\n for (const match of result.matchAll(URL_RE)) {\n if (found.length >= limit) break;\n let url: URL;\n try {\n url = new URL(match[0]);\n } catch {\n continue;\n }\n const ext = url.pathname.split('.').pop()?.toLowerCase() ?? '';\n if (!url.pathname.includes('.') || !MEDIA_EXTENSIONS.has(ext)) continue;\n if (!found.includes(url.toString())) found.push(url.toString());\n }\n return found;\n}\n\n/** One GET the media download makes, connected to the address it validated. */\nexport interface PinnedTarget {\n url: URL;\n /** The address `resolvePublicDestination` checked; the socket goes here. */\n address: string;\n family: 4 | 6;\n}\n\nexport interface MediaResponse {\n status: number;\n location?: string;\n contentLength?: number;\n body: AsyncIterable<Uint8Array>;\n /** Drop the connection without reading the rest. */\n discard: () => void;\n}\n\nexport type MediaTransport = (target: PinnedTarget, signal: AbortSignal) => Promise<MediaResponse>;\n\nexport interface MediaDeps {\n /** Test seam; production connects with {@link pinnedGet}. */\n transport?: MediaTransport;\n destination?: DestinationOptions;\n now?: () => number;\n timeoutMs?: number;\n maxBytes?: number;\n /** What the call may still write, shared by every file it saves, side by\n * side or not: charged as each chunk is written, so a download still in\n * flight holds only what it wrote. A chunk that would take it below zero\n * stops that file, and a file that is not kept gives its bytes back. */\n budget?: { leftBytes: number };\n}\n\n/**\n * CONNECT TO THE ADDRESS THAT WAS CHECKED. `fetch` resolves the name again on\n * its own, so a host answering publicly to the check and privately a moment\n * later (DNS rebinding) would get the request. `node:https` with a `lookup`\n * that hands back the one validated address closes that: the socket goes to\n * it, and TLS still verifies the certificate against the URL's own host name.\n */\nexport const pinnedGet: MediaTransport = (target, signal) =>\n new Promise((resolve, reject) => {\n const req = httpsRequest(\n target.url,\n {\n method: 'GET',\n signal,\n lookup: pinnedLookup(target),\n },\n (res) => {\n const length = Number(res.headers['content-length']);\n const location = res.headers.location;\n resolve({\n status: res.statusCode ?? 0,\n ...(typeof location === 'string' ? { location } : {}),\n ...(Number.isFinite(length) ? { contentLength: length } : {}),\n body: res,\n discard: () => res.destroy(),\n });\n },\n );\n req.on('error', reject);\n req.end();\n });\n\n/** A `lookup` that answers every name with the one validated address. */\nexport function pinnedLookup(target: Pick<PinnedTarget, 'address' | 'family'>): LookupFunction {\n return ((_host: string, options: { all?: boolean }, callback: LookupCallback) => {\n if (options.all === true) {\n callback(null, [{ address: target.address, family: target.family }]);\n } else {\n callback(null, target.address, target.family);\n }\n }) as unknown as LookupFunction;\n}\n\ntype LookupCallback = (\n err: Error | null,\n address: string | { address: string; family: number }[],\n family?: number,\n) => void;\n\n/** A file the budget left too little room for. */\nconst CAPPED = Symbol('capped');\n/** A file a later try could save: the network, the file's server or this\n * disk failed, not a rule of ours. */\nconst FAILED = Symbol('failed');\n\n/**\n * Download each URL into the downloads dir, one at a time, each under its own\n * size cap and deadline, every hop of a redirect validated and connected to\n * the address it validated. Returns the paths that were written, whether the\n * budget left a file too little room (`capped`), and whether a download\n * failed in a way a later try could get past (`failed`); a later call could\n * save either. A URL that fails is skipped and never fails the call.\n */\nexport async function saveMedia(\n dataDir: string,\n stem: string,\n urls: string[],\n deps: MediaDeps = {},\n): Promise<{ saved: string[]; capped: boolean; failed: boolean }> {\n const saved: string[] = [];\n let capped = false;\n let failed = false;\n for (const [index, url] of urls.entries()) {\n const path = await saveOne(dataDir, `${stem}-${index + 1}`, url, deps);\n if (path === CAPPED) capped = true;\n else if (path === FAILED) failed = true;\n else if (path !== null) saved.push(path);\n }\n return { saved, capped, failed };\n}\n\n/** Statuses a later try could get past: the server, not the link, failed. */\nconst RETRYABLE_STATUS = new Set([408, 429]);\n\nasync function saveOne(\n dataDir: string,\n stem: string,\n raw: string,\n deps: MediaDeps,\n): Promise<string | typeof CAPPED | typeof FAILED | null> {\n const transport = deps.transport ?? pinnedGet;\n const cap = deps.maxBytes ?? MAX_MEDIA_BYTES;\n const { budget } = deps;\n if (budget !== undefined && budget.leftBytes <= 0) return CAPPED;\n // What this file has taken from the call's budget, given back unless kept.\n let charged = 0;\n let kept = false;\n // Stopped by the call's budget, not by the file's own cap.\n let capped = false;\n // Stopped by a rule of ours (an address, the file's cap), which no later\n // try gets past.\n let refused = false;\n const signal = AbortSignal.timeout(deps.timeoutMs ?? MEDIA_TIMEOUT_MS);\n let target = raw;\n let path: string | null = null;\n try {\n let res: MediaResponse | null = null;\n for (let hop = 0; hop <= MAX_REDIRECTS; hop += 1) {\n const pinned = await resolvePublicDestination(target, deps.destination ?? {}).catch(\n (err: unknown) => {\n refused = true;\n throw err;\n },\n );\n res = await transport(pinned, signal);\n if (res.status < 300 || res.status >= 400 || res.location === undefined) break;\n res.discard();\n target = new URL(res.location, target).toString();\n res = null;\n }\n if (res === null || res.status < 200 || res.status >= 300) {\n res?.discard();\n const status = res?.status ?? 0;\n return status >= 500 || RETRYABLE_STATUS.has(status) ? FAILED : null;\n }\n const declared = res.contentLength ?? 0;\n if (declared > cap) {\n res.discard();\n return null;\n }\n if (budget !== undefined && declared > budget.leftBytes) {\n res.discard();\n return CAPPED;\n }\n const ext = new URL(target).pathname.split('.').pop()?.toLowerCase() ?? 'bin';\n const file = await createUniqueFile(\n downloadsDir(dataDir),\n `${stem}-${(deps.now ?? Date.now)()}`,\n MEDIA_EXTENSIONS.has(ext) ? ext : 'bin',\n );\n path = file.path;\n let size = 0;\n try {\n for await (const chunk of res.body) {\n size += chunk.byteLength;\n if (size > cap) {\n res.discard();\n refused = true;\n throw new Error('media over the size cap');\n }\n // Charged before the write, in the same turn as the check, so files\n // saving side by side can never write past the call's cap between\n // them.\n if (budget !== undefined) {\n if (chunk.byteLength > budget.leftBytes) {\n res.discard();\n capped = true;\n throw new Error(\"media over the call's download cap\");\n }\n budget.leftBytes -= chunk.byteLength;\n charged += chunk.byteLength;\n }\n await writeAll(file.handle, chunk);\n }\n } finally {\n await file.handle.close();\n }\n kept = true;\n return path;\n } catch {\n if (path !== null) await rm(path, { force: true }).catch(() => undefined);\n return capped ? CAPPED : refused ? null : FAILED;\n } finally {\n if (budget !== undefined && !kept) budget.leftBytes += charged;\n }\n}\n\n/**\n * EVERY BYTE, OR A THROW. `FileHandle.write` may write fewer bytes than it was\n * handed and says so only in `bytesWritten`; a caller that ignores it saves a\n * file with a hole in it. A write that makes no progress is an error.\n */\nexport async function writeAll(\n handle: Pick<FileHandle, 'write'>,\n bytes: Uint8Array,\n): Promise<void> {\n let offset = 0;\n while (offset < bytes.byteLength) {\n const { bytesWritten } = await handle.write(bytes, offset, bytes.byteLength - offset);\n if (bytesWritten <= 0) throw new Error('the file write made no progress');\n offset += bytesWritten;\n }\n}\n\n/**\n * A NEW FILE, NEVER ANOTHER CALL'S. The name is the stem plus a random suffix,\n * created with an exclusive flag, so two lookups finishing in the same\n * millisecond each get their own file; a clash is retried with a new suffix.\n */\nexport async function createUniqueFile(\n directory: string,\n stem: string,\n ext: string,\n): Promise<{ path: string; handle: FileHandle }> {\n await mkdir(directory, { recursive: true });\n const safe = stem.replace(/[^A-Za-z0-9_-]+/g, '-').slice(0, 100) || 'lookup';\n for (let attempt = 0; ; attempt += 1) {\n const path = join(directory, `${safe}-${randomBytes(4).toString('hex')}.${ext}`);\n try {\n return { path, handle: await open(path, 'wx', 0o600) };\n } catch (err) {\n if (attempt >= 4 || !hasCode(err, 'EEXIST')) throw err;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,mBAAmB;AAC5B,SAAS,YAAY,OAAO,MAAM,UAAU,UAA2B;AACvE,SAAS,WAAW,oBAAoB;AAExC,SAAS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AAI,GAAG,EAAE;AAC/E,QAAI;AACF,aAAO,EAAE,MAAM,QAAQ,MAAM,KAAK,MAAM,MAAM,GAAK,EAAE;AAAA,IACvD,SAAS,KAAK;AACZ,UAAI,WAAW,KAAK,CAAC,QAAQ,KAAK,QAAQ,EAAG,OAAM;AAAA,IACrD;AAAA,EACF;AACF;","names":["open"]}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
HOOK_TOOL,
|
|
4
|
+
hookToolInput
|
|
5
|
+
} from "./chunk-AKWGE6JQ.js";
|
|
6
|
+
import {
|
|
7
|
+
MCP_SERVER_NAME,
|
|
8
|
+
PLUGIN_HOOK_TOOL,
|
|
9
|
+
PLUGIN_NAME,
|
|
10
|
+
PLUGIN_SERVER,
|
|
11
|
+
REQUEST_TOOL
|
|
12
|
+
} from "./chunk-WJXLQXJY.js";
|
|
13
|
+
import {
|
|
14
|
+
PRODUCTION_ORIGIN
|
|
15
|
+
} from "./chunk-XQJXNMSB.js";
|
|
16
|
+
|
|
17
|
+
// src/router/plugin-files.ts
|
|
18
|
+
var ROUTE_HOOK_TIMEOUT_SECONDS = 5;
|
|
19
|
+
var AFTER_CALL_TIMEOUT_SECONDS = 15;
|
|
20
|
+
var LOCAL_HOOK_TIMEOUT_SECONDS = 5;
|
|
21
|
+
var DELEGATION_MATCHER = "Agent|Task";
|
|
22
|
+
var NATIVE_MATCHER = "WebSearch|WebFetch";
|
|
23
|
+
var ASK_MATCHER = "AskUserQuestion";
|
|
24
|
+
var PLUGIN_ROOT_ENTRY = "${CLAUDE_PLUGIN_ROOT}/../../../index.js";
|
|
25
|
+
function cliLaunch(args, entry = PLUGIN_ROOT_ENTRY) {
|
|
26
|
+
return { command: "node", args: [entry, ...args] };
|
|
27
|
+
}
|
|
28
|
+
var ALIVE_ARGS = ["hook", "alive"];
|
|
29
|
+
function permissionAnswer(decision, reason) {
|
|
30
|
+
return JSON.stringify({
|
|
31
|
+
hookSpecificOutput: {
|
|
32
|
+
hookEventName: "PreToolUse",
|
|
33
|
+
permissionDecision: decision,
|
|
34
|
+
permissionDecisionReason: reason
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
var PRINT_ARGUMENT = "process.stdout.write(process.argv[1])";
|
|
39
|
+
function printed(answer) {
|
|
40
|
+
return { command: "node", args: ["-e", PRINT_ARGUMENT, answer] };
|
|
41
|
+
}
|
|
42
|
+
var DENY_HOOK = printed(
|
|
43
|
+
permissionAnswer(
|
|
44
|
+
"deny",
|
|
45
|
+
`Only the Tenjin hooks call this tool. To make a lookup, call ${REQUEST_TOOL}.`
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
var ALLOW_HOOK = printed(permissionAnswer("allow", "Tenjin lookup"));
|
|
49
|
+
function leg(kind, timeout = ROUTE_HOOK_TIMEOUT_SECONDS) {
|
|
50
|
+
return [
|
|
51
|
+
{
|
|
52
|
+
type: "mcp_tool",
|
|
53
|
+
server: PLUGIN_SERVER,
|
|
54
|
+
tool: HOOK_TOOL,
|
|
55
|
+
input: hookToolInput(kind),
|
|
56
|
+
timeout
|
|
57
|
+
}
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
function command(launch) {
|
|
61
|
+
return [{ type: "command", ...launch, timeout: LOCAL_HOOK_TIMEOUT_SECONDS }];
|
|
62
|
+
}
|
|
63
|
+
function routerHookPlan() {
|
|
64
|
+
const afterCall = () => leg("shortfall", AFTER_CALL_TIMEOUT_SECONDS);
|
|
65
|
+
return [
|
|
66
|
+
{ event: "UserPromptSubmit", hooks: leg("prompt") },
|
|
67
|
+
{ event: "PreToolUse", matcher: NATIVE_MATCHER, hooks: leg("native") },
|
|
68
|
+
{ event: "PreToolUse", matcher: DELEGATION_MATCHER, hooks: leg("agent") },
|
|
69
|
+
{ event: "PostToolUse", matcher: NATIVE_MATCHER, hooks: afterCall() },
|
|
70
|
+
{ event: "PostToolUseFailure", matcher: NATIVE_MATCHER, hooks: afterCall() },
|
|
71
|
+
{ event: "PreToolUse", matcher: ASK_MATCHER, hooks: leg("ask") },
|
|
72
|
+
{ event: "PostToolUse", matcher: ASK_MATCHER, hooks: leg("answer") }
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
var MOD_MODULE = "./register.tsx";
|
|
76
|
+
function renderPluginHooks(entry = PLUGIN_ROOT_ENTRY, withMod = false) {
|
|
77
|
+
const plan = [
|
|
78
|
+
{ event: "SessionStart", hooks: command(cliLaunch(ALIVE_ARGS, entry)) },
|
|
79
|
+
...routerHookPlan(),
|
|
80
|
+
{ event: "PreToolUse", matcher: PLUGIN_HOOK_TOOL, hooks: command(DENY_HOOK) },
|
|
81
|
+
{ event: "PreToolUse", matcher: REQUEST_TOOL, hooks: command(ALLOW_HOOK) }
|
|
82
|
+
];
|
|
83
|
+
const hooks = {};
|
|
84
|
+
for (const { event, hooks: handlers, ...rest } of plan) {
|
|
85
|
+
(hooks[event] ??= []).push({ ...rest, hooks: handlers });
|
|
86
|
+
}
|
|
87
|
+
return { hooks, ...withMod ? { modules: [MOD_MODULE] } : {} };
|
|
88
|
+
}
|
|
89
|
+
var PLUGIN_MCP_ARGS = ["mcp", "--plugin"];
|
|
90
|
+
function renderPluginMcp(entry = PLUGIN_ROOT_ENTRY) {
|
|
91
|
+
return { mcpServers: { [MCP_SERVER_NAME]: cliLaunch(PLUGIN_MCP_ARGS, entry) } };
|
|
92
|
+
}
|
|
93
|
+
var OWNER_MARKER = "tenjin-cli";
|
|
94
|
+
var UNBUILT = "source";
|
|
95
|
+
var DESCRIPTION = "Tenjin picks the right tool when your agent needs one, and one wallet on this machine pays for every call.";
|
|
96
|
+
function renderPluginManifest(version, withMod = false) {
|
|
97
|
+
return {
|
|
98
|
+
name: PLUGIN_NAME,
|
|
99
|
+
...version !== void 0 ? { version } : {},
|
|
100
|
+
description: DESCRIPTION,
|
|
101
|
+
// The mod's `$.state` contract, which `claude plugin validate` checks.
|
|
102
|
+
...withMod ? { types: `./${MOD_TYPES}` } : {},
|
|
103
|
+
author: { name: "Tenjin", url: PRODUCTION_ORIGIN },
|
|
104
|
+
homepage: `${PRODUCTION_ORIGIN}/agents`,
|
|
105
|
+
repository: "https://github.com/BackTrackCo/tenjin-agent",
|
|
106
|
+
metadata: { [OWNER_MARKER]: version ?? UNBUILT }
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
var PLUGIN_DIR = PLUGIN_NAME;
|
|
110
|
+
var PLUGIN_FILES = [
|
|
111
|
+
".mcp.json",
|
|
112
|
+
"types/index.d.ts",
|
|
113
|
+
"hooks/register.tsx",
|
|
114
|
+
"hooks/hooks.json",
|
|
115
|
+
".claude-plugin/plugin.json"
|
|
116
|
+
];
|
|
117
|
+
var MOD_TYPES = "types/index.d.ts";
|
|
118
|
+
var MOD_FILES = [MOD_TYPES, "hooks/register.tsx"];
|
|
119
|
+
var json = (value) => `${JSON.stringify(value, null, 2)}
|
|
120
|
+
`;
|
|
121
|
+
function renderPluginFiles(version, entry, mod) {
|
|
122
|
+
const withMod = mod !== void 0;
|
|
123
|
+
return {
|
|
124
|
+
".mcp.json": json(renderPluginMcp(entry)),
|
|
125
|
+
...mod ?? {},
|
|
126
|
+
"hooks/hooks.json": json(renderPluginHooks(entry, withMod)),
|
|
127
|
+
".claude-plugin/plugin.json": json(renderPluginManifest(version, withMod))
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
var CODEX_LEGS = ["prompt", "native", "shortfall"];
|
|
131
|
+
var CODEX_ALLOW_ANSWER = JSON.stringify({
|
|
132
|
+
hookSpecificOutput: { hookEventName: "PermissionRequest", decision: { behavior: "allow" } }
|
|
133
|
+
});
|
|
134
|
+
var CODEX_ALLOW_HOOK_COMMAND = `echo '${CODEX_ALLOW_ANSWER}'`;
|
|
135
|
+
var CODEX_ALLOW_HOOK_COMMAND_WINDOWS = `echo ${CODEX_ALLOW_ANSWER}`;
|
|
136
|
+
var CODEX_HOOK_COUNT = CODEX_LEGS.length + 1;
|
|
137
|
+
|
|
138
|
+
export {
|
|
139
|
+
ROUTE_HOOK_TIMEOUT_SECONDS,
|
|
140
|
+
AFTER_CALL_TIMEOUT_SECONDS,
|
|
141
|
+
OWNER_MARKER,
|
|
142
|
+
PLUGIN_DIR,
|
|
143
|
+
PLUGIN_FILES,
|
|
144
|
+
MOD_FILES,
|
|
145
|
+
renderPluginFiles,
|
|
146
|
+
CODEX_ALLOW_HOOK_COMMAND,
|
|
147
|
+
CODEX_ALLOW_HOOK_COMMAND_WINDOWS,
|
|
148
|
+
CODEX_HOOK_COUNT
|
|
149
|
+
};
|
|
150
|
+
//# sourceMappingURL=chunk-GA7JETVM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/router/plugin-files.ts"],"sourcesContent":["import { PRODUCTION_ORIGIN } from '../lib/production-origin';\nimport { HOOK_TOOL, hookToolInput, type HookKind } from './hook-tool';\nimport {\n CODEX_REQUEST_TOOL,\n MARKETPLACE_NAME,\n MCP_SERVER_NAME,\n PLUGIN_HOOK_TOOL,\n PLUGIN_NAME,\n PLUGIN_SERVER,\n REQUEST_TOOL,\n} from './names';\n\n/**\n * THE CLAUDE CODE PLUGIN, AS FILES. `tenjin install` registers it with Claude\n * Code's own `claude plugin` commands from the package's `dist/hosts/claude`\n * folder, which the build renders from this module, and writes the same plugin\n * folder under the config dir's `skills/` when there is no `claude` binary to\n * run. The checked-in `hosts/claude/` templates are pinned to this render by a\n * test, so the two cannot drift.\n *\n * NOTHING HERE IMPORTS MORE THAN THE NAMES AND THE PRODUCTION ORIGIN:\n * `tsup.config.ts` loads this module to render the shipped files, and its\n * import graph is the build's.\n */\n\n/**\n * The harness's kill budget for each routing leg: a stuck server never holds a\n * prompt longer than this. Every wait inside the leg is cut from it: the gate's\n * 3.5 s, which holds the paid path's 402, the reads before a deposit and the\n * paid request, with 500 ms left for the transcript read and the reply\n * (`wire.test.ts` pins the sum). A whole leg whose call carried a deposit took\n * 2.8 to 3.3 s on Base Sepolia, so it fits; a slower one (a wallet unlock, a\n * slow settlement) loses only that prompt's hint, and the SDK recovers the\n * channel on the next call.\n */\nexport const ROUTE_HOOK_TIMEOUT_SECONDS = 5;\n/**\n * The after-call entries' kill budget, longer than the rest for the one wait\n * a leg makes: a search the pre-call leg is fetching free docs for waits up to\n * `AUGMENT_WAIT_MS` (9 s) for them, and when none came back and the search was\n * short, the gate's 3.5 s follow, with startup to spare (`wire.test.ts` pins\n * the sum). Every other after-call event returns as fast as before, so the\n * number is a ceiling, not a cost.\n */\nexport const AFTER_CALL_TIMEOUT_SECONDS = 15;\n/** The `alive` leg and the two permission answers do no network work. */\nexport const LOCAL_HOOK_TIMEOUT_SECONDS = 5;\n\n/** The subagent tool, under its current name and its older one. */\nexport const DELEGATION_MATCHER = 'Agent|Task';\n/** The native tools both native arms watch. */\nexport const NATIVE_MATCHER = 'WebSearch|WebFetch';\n/** The host's question to the user, watched before it is asked and after. */\nexport const ASK_MATCHER = 'AskUserQuestion';\n\n/**\n * EVERY COMMAND RUNS `node` IN EXEC FORM, with no shell (see `hook-form.ts`).\n * The shipped plugin loads in place from the package's `dist/hosts/claude/tenjin`,\n * so the bundle's entry is three folders above `${CLAUDE_PLUGIN_ROOT}`, which\n * Claude Code substitutes into each argument, and the checked-in template\n * stays static. The folder fallback lives under the config dir instead, and\n * `install` renders it with the absolute entry of the CLI that wrote it.\n */\nexport const PLUGIN_ROOT_ENTRY = '${CLAUDE_PLUGIN_ROOT}/../../../index.js';\n\n/** A process Claude Code spawns directly: a hook's `command` and `args`, or a stdio server's. */\nexport interface ExecLaunch {\n command: string;\n args: string[];\n}\n\n/** The CLI run by `node` from its entry script, never through the `tenjin` shim. */\nexport function cliLaunch(args: readonly string[], entry: string = PLUGIN_ROOT_ENTRY): ExecLaunch {\n return { command: 'node', args: [entry, ...args] };\n}\n\n/**\n * The `alive` leg: the plugin's `SessionStart` entry, so it runs before any\n * other event of a session. It marks the session as one the plugin serves, so\n * a settings-install leg in the same session stays silent, and stamps the\n * machine as one the plugin has loaded on, which the migration waits for. A\n * command, not an `mcp_tool` call: a session's MCP servers may still be\n * connecting when `SessionStart` fires, and a command needs nothing running.\n */\nexport const ALIVE_ARGS = ['hook', 'alive'] as const;\n\n/** A PreToolUse answer, as a hook command's stdout carries it. */\nfunction permissionAnswer(decision: 'allow' | 'deny', reason: string): string {\n return JSON.stringify({\n hookSpecificOutput: {\n hookEventName: 'PreToolUse',\n permissionDecision: decision,\n permissionDecisionReason: reason,\n },\n });\n}\n\n/** A fixed answer `node -e` prints from its own argument: no shell, no CLI, no quoting. */\nexport const PRINT_ARGUMENT = 'process.stdout.write(process.argv[1])';\n\nfunction printed(answer: string): ExecLaunch {\n return { command: 'node', args: ['-e', PRINT_ARGUMENT, answer] };\n}\n\n/**\n * THE HOOK LEGS' TOOL IS DENIED TO THE MODEL. Its event fields are plain\n * arguments, so the model calling it could forge a routing leg. This blocking\n * hook replaces the settings install's `permissions.deny` rule: a plugin cannot\n * carry permission rules, and a blocking hook takes precedence over allow rules\n * in every mode, bypass included, while Claude Code's own `mcp_tool` hook calls\n * still run (lab, Claude Code 2.1.296). The tool stays in the model's list. The\n * tool's transcript check (`admitHookEvent`) stays for a machine with hooks off.\n */\nexport const DENY_HOOK = printed(\n permissionAnswer(\n 'deny',\n `Only the Tenjin hooks call this tool. To make a lookup, call ${REQUEST_TOOL}.`,\n ),\n);\n\n/**\n * THE REQUEST TOOL IS ALLOWED BY THE PLUGIN ITSELF, replacing the settings\n * install's `permissions.allow` rule, so an install needs no rule the user\n * adds. A hook's allow never overrides the user's own `deny` or `ask` rule for\n * the tool. The tool still pays only within the local spend policy, and an\n * amount over it returns `needs_approval` with nothing paid.\n */\nexport const ALLOW_HOOK = printed(permissionAnswer('allow', 'Tenjin lookup'));\n\n/** One routing leg: Claude Code calls the plugin server's `hook` tool. */\nfunction leg(kind: HookKind, timeout = ROUTE_HOOK_TIMEOUT_SECONDS): unknown[] {\n return [\n {\n type: 'mcp_tool',\n server: PLUGIN_SERVER,\n tool: HOOK_TOOL,\n input: hookToolInput(kind),\n timeout,\n },\n ];\n}\n\nfunction command(launch: ExecLaunch): unknown[] {\n return [{ type: 'command', ...launch, timeout: LOCAL_HOOK_TIMEOUT_SECONDS }];\n}\n\n/**\n * The seven routing legs. The native tools are routed twice over one lookup:\n * BEFORE the call, with a line pointing to a paid lookup when one fits; and\n * AFTER it, only when it came back short and nothing was said before, or to\n * add the free docs the pre-call arm fetched to a search's results. A failed\n * call fires PostToolUseFailure rather than PostToolUse, so the second takes\n * both. The host's question to the user is routed the same two ways: before it\n * is asked, when a service could stand in for what it asks for, and after,\n * with the user's answers read as their own words.\n */\nexport function routerHookPlan(): { event: string; matcher?: string; hooks: unknown[] }[] {\n const afterCall = () => leg('shortfall', AFTER_CALL_TIMEOUT_SECONDS);\n return [\n { event: 'UserPromptSubmit', hooks: leg('prompt') },\n { event: 'PreToolUse', matcher: NATIVE_MATCHER, hooks: leg('native') },\n { event: 'PreToolUse', matcher: DELEGATION_MATCHER, hooks: leg('agent') },\n { event: 'PostToolUse', matcher: NATIVE_MATCHER, hooks: afterCall() },\n { event: 'PostToolUseFailure', matcher: NATIVE_MATCHER, hooks: afterCall() },\n { event: 'PreToolUse', matcher: ASK_MATCHER, hooks: leg('ask') },\n { event: 'PostToolUse', matcher: ASK_MATCHER, hooks: leg('answer') },\n ];\n}\n\n/** The mod's module, as `hooks/hooks.json` names it (relative to that file). */\nexport const MOD_MODULE = './register.tsx';\n\n/**\n * `hooks/hooks.json`: the `alive` leg, the seven routing legs and the two\n * permission answers, and the mod's module when the folder carries it.\n */\nexport function renderPluginHooks(\n entry: string = PLUGIN_ROOT_ENTRY,\n withMod = false,\n): {\n hooks: Record<string, unknown[]>;\n modules?: string[];\n} {\n const plan = [\n { event: 'SessionStart', hooks: command(cliLaunch(ALIVE_ARGS, entry)) },\n ...routerHookPlan(),\n { event: 'PreToolUse', matcher: PLUGIN_HOOK_TOOL, hooks: command(DENY_HOOK) },\n { event: 'PreToolUse', matcher: REQUEST_TOOL, hooks: command(ALLOW_HOOK) },\n ];\n const hooks: Record<string, unknown[]> = {};\n for (const { event, hooks: handlers, ...rest } of plan) {\n (hooks[event] ??= []).push({ ...rest, hooks: handlers });\n }\n return { hooks, ...(withMod ? { modules: [MOD_MODULE] } : {}) };\n}\n\n/**\n * `.mcp.json`: the server Claude Code starts for the plugin, the CLI's entry\n * run by `node`, which Windows can spawn where it cannot spawn the shim.\n *\n * `--plugin` KEEPS IT FROM BEING SUPPRESSED. Claude Code drops a plugin's MCP\n * server whose command and arguments match a server the user configured, and\n * a settings install's `x402` entry runs `tenjin mcp`; with the same command\n * the plugin's `router` server would not start while the two coexist, its legs\n * would fail, and the old ones stay silent (checked on Claude Code 2.1.296).\n */\nexport const PLUGIN_MCP_ARGS = ['mcp', '--plugin'] as const;\n\nexport function renderPluginMcp(entry: string = PLUGIN_ROOT_ENTRY): {\n mcpServers: Record<string, unknown>;\n} {\n return { mcpServers: { [MCP_SERVER_NAME]: cliLaunch(PLUGIN_MCP_ARGS, entry) } };\n}\n\n/** The key whose presence marks a plugin manifest as one this CLI wrote. */\nexport const OWNER_MARKER = 'tenjin-cli';\n/** The marker's value in the checked-in templates, which carry no version. */\nconst UNBUILT = 'source';\n\nconst DESCRIPTION =\n 'Tenjin picks the right tool when your agent needs one, and one wallet on this machine pays for every call.';\n\n/**\n * `.claude-plugin/plugin.json`. The version is the CLI's, stamped at build time,\n * so Claude Code's plugin list names the build that runs; the checked-in\n * template carries none. `metadata[tenjin-cli]` is the ownership marker the\n * folder fallback, `update` and `uninstall` check before they touch a folder.\n */\nexport function renderPluginManifest(version?: string, withMod = false): Record<string, unknown> {\n return {\n name: PLUGIN_NAME,\n ...(version !== undefined ? { version } : {}),\n description: DESCRIPTION,\n // The mod's `$.state` contract, which `claude plugin validate` checks.\n ...(withMod ? { types: `./${MOD_TYPES}` } : {}),\n author: { name: 'Tenjin', url: PRODUCTION_ORIGIN },\n homepage: `${PRODUCTION_ORIGIN}/agents`,\n repository: 'https://github.com/BackTrackCo/tenjin-agent',\n metadata: { [OWNER_MARKER]: version ?? UNBUILT },\n };\n}\n\n/** The plugin's folder inside the marketplace folder. */\nexport const PLUGIN_DIR = PLUGIN_NAME;\n\n/** `.claude-plugin/marketplace.json`: one plugin, read in place from the package. */\nexport function renderMarketplace(version?: string): Record<string, unknown> {\n return {\n name: MARKETPLACE_NAME,\n owner: { name: 'Tenjin', url: PRODUCTION_ORIGIN },\n description: \"Tenjin's tool router for Claude Code, installed by `tenjin install`.\",\n ...(version !== undefined ? { metadata: { version } } : {}),\n plugins: [\n {\n name: PLUGIN_NAME,\n source: `./${PLUGIN_DIR}`,\n description: DESCRIPTION,\n ...(version !== undefined ? { version } : {}),\n },\n ],\n };\n}\n\n/**\n * EVERY FILE THE PLUGIN FOLDER HOLDS, relative to the plugin's root, and the\n * only paths install, update and uninstall ever write or unlink in a folder.\n * The manifest is last: a crash mid-write never leaves a manifest pointing at\n * parts that are not there yet.\n */\nexport const PLUGIN_FILES = [\n '.mcp.json',\n 'types/index.d.ts',\n 'hooks/register.tsx',\n 'hooks/hooks.json',\n '.claude-plugin/plugin.json',\n] as const;\n\n/** The mod's `$.state` contract, shipped as written. */\nexport const MOD_TYPES = 'types/index.d.ts';\n/**\n * THE MOD SHIPS AS WRITTEN, NOT RENDERED: `hosts/claude/tenjin/` holds its\n * source, the build copies it into `dist/hosts/claude/tenjin/`, and the folder\n * fallback copies it from there. Claude Code compiles it at load (2.1.287 or\n * later); nothing here builds or imports it.\n */\nexport const MOD_FILES = [MOD_TYPES, 'hooks/register.tsx'] as const;\nexport type ModSources = Record<(typeof MOD_FILES)[number], string>;\n\nconst json = (value: unknown): string => `${JSON.stringify(value, null, 2)}\\n`;\n\n/**\n * The plugin folder's files, by {@link PLUGIN_FILES} path. `entry` is the CLI\n * entry the commands run, {@link PLUGIN_ROOT_ENTRY} unless the folder lives\n * outside the package. Without the mod's sources the folder carries the legs\n * and the server alone, and its hooks file names no module.\n */\nexport function renderPluginFiles(\n version?: string,\n entry?: string,\n mod?: ModSources,\n): Record<string, string> {\n const withMod = mod !== undefined;\n return {\n '.mcp.json': json(renderPluginMcp(entry)),\n ...(mod ?? {}),\n 'hooks/hooks.json': json(renderPluginHooks(entry, withMod)),\n '.claude-plugin/plugin.json': json(renderPluginManifest(version, withMod)),\n };\n}\n\n/** The marketplace folder's files: its catalog and the plugin under {@link PLUGIN_DIR}. */\nexport function renderHostFiles(version?: string, mod?: ModSources): Record<string, string> {\n const plugin = Object.entries(renderPluginFiles(version, undefined, mod)).map(\n ([path, body]) => [`${PLUGIN_DIR}/${path}`, body] as const,\n );\n return {\n '.claude-plugin/marketplace.json': json(renderMarketplace(version)),\n ...Object.fromEntries(plugin),\n };\n}\n\n/**\n * THE CODEX PLUGIN, AS FILES, shipped in `dist/hosts/codex` and pinned to the\n * checked-in `hosts/codex/` by the same test. Its legs are command hooks: the\n * prompt, and one web call before it runs and after (Codex has no\n * PostToolUseFailure). Nothing in it names a release, so `codex plugin add`\n * copies the same bytes from every build and the hooks' trust holds across a\n * `tenjin update`.\n */\nexport const CODEX_WEB_MATCHER = 'webrun';\nexport const CODEX_LEGS = ['prompt', 'native', 'shortfall'] as const;\n\nexport function codexHookCommand(kind: (typeof CODEX_LEGS)[number]): string {\n return `tenjin hook ${kind} --harness codex`;\n}\n\n/**\n * THE REQUEST TOOL IS ALLOWED BY THE PLUGIN ITSELF, as {@link ALLOW_HOOK_COMMAND}\n * is in Claude Code. Codex runs a `PermissionRequest` hook before its approval\n * policy, `never` included, so the tool runs without a prompt once the user\n * trusts this hook with the others in `/hooks`. It also overrides a user's own\n * `approval_mode = \"prompt\"` for the tool; that user turns this one hook off in\n * `/hooks`. The wallet's spend limits still bound every payment.\n */\nconst CODEX_ALLOW_ANSWER = JSON.stringify({\n hookSpecificOutput: { hookEventName: 'PermissionRequest', decision: { behavior: 'allow' } },\n});\nexport const CODEX_ALLOW_HOOK_COMMAND = `echo '${CODEX_ALLOW_ANSWER}'`;\n/**\n * The same answer under Windows' `cmd.exe /C`, through Codex's `commandWindows`\n * override: cmd's `echo` prints single quotes as written, and Codex then\n * rejects the output as JSON. The answer holds none of cmd's special\n * characters, so a bare `echo` prints it as is.\n */\nexport const CODEX_ALLOW_HOOK_COMMAND_WINDOWS = `echo ${CODEX_ALLOW_ANSWER}`;\n\n/** Every hook the Codex plugin carries: the three legs and the allow answer. */\nexport const CODEX_HOOK_COUNT = CODEX_LEGS.length + 1;\n\nfunction codexLeg(kind: (typeof CODEX_LEGS)[number], timeout = ROUTE_HOOK_TIMEOUT_SECONDS) {\n return [{ type: 'command', command: codexHookCommand(kind), timeout }];\n}\n\nexport function renderCodexHooks(): { hooks: Record<string, unknown[]> } {\n return {\n hooks: {\n UserPromptSubmit: [{ hooks: codexLeg('prompt') }],\n PreToolUse: [{ matcher: CODEX_WEB_MATCHER, hooks: codexLeg('native') }],\n PostToolUse: [\n { matcher: CODEX_WEB_MATCHER, hooks: codexLeg('shortfall', AFTER_CALL_TIMEOUT_SECONDS) },\n ],\n PermissionRequest: [\n {\n matcher: CODEX_REQUEST_TOOL,\n hooks: [\n {\n type: 'command',\n command: CODEX_ALLOW_HOOK_COMMAND,\n commandWindows: CODEX_ALLOW_HOOK_COMMAND_WINDOWS,\n timeout: LOCAL_HOOK_TIMEOUT_SECONDS,\n },\n ],\n },\n ],\n },\n };\n}\n\nexport const CODEX_MCP_ARGS = ['mcp', '--harness', 'codex'] as const;\n\nexport function renderCodexMcp(): { mcpServers: Record<string, unknown> } {\n return { mcpServers: { [MCP_SERVER_NAME]: { command: 'tenjin', args: [...CODEX_MCP_ARGS] } } };\n}\n\n/** `.codex-plugin/plugin.json`. No version: see {@link renderCodexHostFiles}. */\nexport function renderCodexManifest(): Record<string, unknown> {\n return {\n name: PLUGIN_NAME,\n description: DESCRIPTION,\n author: { name: 'Tenjin', url: PRODUCTION_ORIGIN },\n homepage: `${PRODUCTION_ORIGIN}/agents`,\n repository: 'https://github.com/BackTrackCo/tenjin-agent',\n interface: { displayName: 'Tenjin', developerName: 'Tenjin', category: 'Productivity' },\n mcpServers: './.mcp.json',\n };\n}\n\n/** `.agents/plugins/marketplace.json`: one local plugin, copied by `codex plugin add`. */\nexport function renderCodexMarketplace(): Record<string, unknown> {\n return {\n name: MARKETPLACE_NAME,\n interface: { displayName: 'Tenjin' },\n plugins: [\n {\n name: PLUGIN_NAME,\n source: { source: 'local', path: `./${PLUGIN_DIR}` },\n policy: { installation: 'AVAILABLE', authentication: 'ON_INSTALL' },\n category: 'Productivity',\n },\n ],\n };\n}\n\n/** The Codex marketplace folder's files: its catalog and the plugin under {@link PLUGIN_DIR}. */\nexport function renderCodexHostFiles(): Record<string, string> {\n return {\n '.agents/plugins/marketplace.json': json(renderCodexMarketplace()),\n [`${PLUGIN_DIR}/.mcp.json`]: json(renderCodexMcp()),\n [`${PLUGIN_DIR}/hooks/hooks.json`]: json(renderCodexHooks()),\n [`${PLUGIN_DIR}/.codex-plugin/plugin.json`]: json(renderCodexManifest()),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAmCO,IAAM,6BAA6B;AASnC,IAAM,6BAA6B;AAEnC,IAAM,6BAA6B;AAGnC,IAAM,qBAAqB;AAE3B,IAAM,iBAAiB;AAEvB,IAAM,cAAc;AAUpB,IAAM,oBAAoB;AAS1B,SAAS,UAAU,MAAyB,QAAgB,mBAA+B;AAChG,SAAO,EAAE,SAAS,QAAQ,MAAM,CAAC,OAAO,GAAG,IAAI,EAAE;AACnD;AAUO,IAAM,aAAa,CAAC,QAAQ,OAAO;AAG1C,SAAS,iBAAiB,UAA4B,QAAwB;AAC5E,SAAO,KAAK,UAAU;AAAA,IACpB,oBAAoB;AAAA,MAClB,eAAe;AAAA,MACf,oBAAoB;AAAA,MACpB,0BAA0B;AAAA,IAC5B;AAAA,EACF,CAAC;AACH;AAGO,IAAM,iBAAiB;AAE9B,SAAS,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AA2B,GAAG,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC;AAAA;AAQnE,SAAS,kBACd,SACA,OACA,KACwB;AACxB,QAAM,UAAU,QAAQ;AACxB,SAAO;AAAA,IACL,aAAa,KAAK,gBAAgB,KAAK,CAAC;AAAA,IACxC,GAAI,OAAO,CAAC;AAAA,IACZ,oBAAoB,KAAK,kBAAkB,OAAO,OAAO,CAAC;AAAA,IAC1D,8BAA8B,KAAK,qBAAqB,SAAS,OAAO,CAAC;AAAA,EAC3E;AACF;AAsBO,IAAM,aAAa,CAAC,UAAU,UAAU,WAAW;AAc1D,IAAM,qBAAqB,KAAK,UAAU;AAAA,EACxC,oBAAoB,EAAE,eAAe,qBAAqB,UAAU,EAAE,UAAU,QAAQ,EAAE;AAC5F,CAAC;AACM,IAAM,2BAA2B,SAAS,kBAAkB;AAO5D,IAAM,mCAAmC,QAAQ,kBAAkB;AAGnE,IAAM,mBAAmB,WAAW,SAAS;","names":[]}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_MAX_AUTO_SPEND
|
|
4
|
+
} from "./chunk-YVFXE7RR.js";
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_RPC_URL,
|
|
7
|
+
rememberingBalanceReader
|
|
8
|
+
} from "./chunk-27EPWVOY.js";
|
|
9
|
+
import {
|
|
10
|
+
configPath,
|
|
11
|
+
walletPath
|
|
12
|
+
} from "./chunk-SJLTEINJ.js";
|
|
2
13
|
|
|
3
14
|
// src/router/alive.ts
|
|
4
15
|
import { createHash } from "node:crypto";
|
|
@@ -68,9 +79,43 @@ async function removeAliveState(dataDir) {
|
|
|
68
79
|
await rmdir(dir).catch(() => void 0);
|
|
69
80
|
return true;
|
|
70
81
|
}
|
|
82
|
+
var WALLET_READ_MS = 2e3;
|
|
83
|
+
async function walletNotice(dataDir, opts = {}) {
|
|
84
|
+
const wallet = await readJson(walletPath(dataDir));
|
|
85
|
+
const address = typeof wallet?.address === "string" ? wallet.address : void 0;
|
|
86
|
+
if (address === void 0 || !/^0x[0-9a-fA-F]{40}$/.test(address)) return null;
|
|
87
|
+
const config = await readJson(configPath(dataDir));
|
|
88
|
+
const rpcUrl = typeof config?.rpcUrl === "string" ? config.rpcUrl : DEFAULT_RPC_URL;
|
|
89
|
+
const timeoutMs = opts.timeoutMs ?? WALLET_READ_MS;
|
|
90
|
+
const read = rememberingBalanceReader(dataDir, {
|
|
91
|
+
...opts.read !== void 0 ? { read: opts.read } : {}
|
|
92
|
+
});
|
|
93
|
+
const balance = await read(address, rpcUrl, { timeoutMs });
|
|
94
|
+
if (balance === null) return null;
|
|
95
|
+
const cap = BigInt(
|
|
96
|
+
typeof config?.maxAutoSpend === "string" && /^\d{1,30}$/.test(config.maxAutoSpend) ? config.maxAutoSpend : DEFAULT_MAX_AUTO_SPEND
|
|
97
|
+
);
|
|
98
|
+
if (balance > 0n && balance >= cap) return null;
|
|
99
|
+
return `Tenjin balance: $${dollars(balance)}. Ask your agent to add funds to Tenjin.`;
|
|
100
|
+
}
|
|
101
|
+
function dollars(atomic) {
|
|
102
|
+
const fraction = (atomic % 1000000n).toString().padStart(6, "0").replace(/0+$/, "");
|
|
103
|
+
return `${atomic / 1000000n}.${fraction.padEnd(2, "0")}`;
|
|
104
|
+
}
|
|
105
|
+
async function readJson(path) {
|
|
106
|
+
try {
|
|
107
|
+
const value = JSON.parse(await readFile(path, "utf8"));
|
|
108
|
+
return value !== null && typeof value === "object" ? value : null;
|
|
109
|
+
} catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
71
113
|
async function aliveMain(opts) {
|
|
72
114
|
const raw = await readStdin(1e3).catch(() => "");
|
|
73
115
|
await runAliveHook(parseEvent(raw), opts);
|
|
116
|
+
const notice = await walletNotice(opts.dataDir).catch(() => null);
|
|
117
|
+
if (notice !== null) process.stdout.write(`${JSON.stringify({ systemMessage: notice })}
|
|
118
|
+
`);
|
|
74
119
|
}
|
|
75
120
|
function parseEvent(raw) {
|
|
76
121
|
try {
|
|
@@ -122,7 +167,9 @@ export {
|
|
|
122
167
|
sessionServedByPlugin,
|
|
123
168
|
readAliveStamp,
|
|
124
169
|
removeAliveState,
|
|
170
|
+
WALLET_READ_MS,
|
|
171
|
+
walletNotice,
|
|
125
172
|
aliveMain,
|
|
126
173
|
markSessionServed
|
|
127
174
|
};
|
|
128
|
-
//# sourceMappingURL=chunk-
|
|
175
|
+
//# sourceMappingURL=chunk-I3EQFHCD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/router/alive.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport { mkdir, readdir, readFile, rm, rmdir, stat, writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { DEFAULT_MAX_AUTO_SPEND } from '../lib/config';\nimport { configPath, walletPath } from '../lib/paths';\nimport {\n DEFAULT_RPC_URL,\n readUsdcBalanceWithFallback,\n rememberingBalanceReader,\n} from '../lib/usdc-balance';\n\n/**\n * THE PLUGIN SAYS IT IS HERE. While a machine carries both the plugin and the\n * settings install it replaces, every event would run two sets of routing legs\n * and offer the same lookup twice. The plugin's `SessionStart` entry runs\n * `tenjin hook alive` before any other event of the session, and it writes:\n *\n * - a per-session marker, which every leg a settings install launched checks\n * first, staying silent in a session the plugin serves;\n * - a per-machine stamp, the proof the guarded migration waits for: the plugin\n * has loaded in a real session on this machine at least once, so the\n * settings install can be removed without leaving the machine unrouted.\n *\n * Outside `progress/`, whose files are pruned after ten minutes. Markers are\n * pruned here after a week, which outlasts any session that still matters.\n *\n * SHIM: the per-session check goes on or after 2026-12-01, the first release\n * cut 30 or more days after the plugin PR 2 ships; the stamp stays for doctor.\n */\n\nconst MARKER_TTL_MS = 7 * 24 * 60 * 60 * 1000;\nconst STAMP = 'plugin-loaded.json';\n/** A session id names a file only through its hash, so any string is safe. */\nconst MAX_SESSION_ID = 200;\n\nexport function aliveDir(dataDir: string): string {\n return join(dataDir, 'alive');\n}\n\nfunction markerName(sessionId: string): string {\n return createHash('sha256').update(sessionId).digest('hex').slice(0, 32);\n}\n\nfunction sessionIdOf(event: unknown): string | null {\n if (event === null || typeof event !== 'object') return null;\n const id = (event as { session_id?: unknown }).session_id;\n return typeof id === 'string' && id.length > 0 && id.length <= MAX_SESSION_ID ? id : null;\n}\n\nexport interface AliveStamp {\n at: string;\n /** The CLI version whose plugin loaded. */\n version: string;\n}\n\n/**\n * The `alive` leg: marker, stamp, prune. It prints nothing, because a\n * `SessionStart` hook's plain stdout is added to the session's context\n * ({@link aliveMain} adds the wallet notice as JSON), and it never fails the\n * session: every error is swallowed.\n */\nexport async function runAliveHook(\n event: unknown,\n opts: { dataDir: string; version: string; now?: number },\n): Promise<void> {\n const sessionId = sessionIdOf(event);\n const now = opts.now ?? Date.now();\n const dir = aliveDir(opts.dataDir);\n try {\n await mkdir(dir, { recursive: true, mode: 0o700 });\n if (sessionId !== null) {\n await writeFile(join(dir, markerName(sessionId)), `${new Date(now).toISOString()}\\n`);\n }\n const stamp: AliveStamp = { at: new Date(now).toISOString(), version: opts.version };\n await writeFile(join(dir, STAMP), `${JSON.stringify(stamp)}\\n`);\n await pruneMarkers(dir, now);\n } catch {\n // A marker that could not be written costs only a duplicate offer.\n }\n}\n\nasync function pruneMarkers(dir: string, now: number): Promise<void> {\n for (const name of await readdir(dir).catch(() => [] as string[])) {\n if (!/^[0-9a-f]{32}$/.test(name)) continue;\n const path = join(dir, name);\n const s = await stat(path).catch(() => null);\n if (s !== null && now - s.mtimeMs > MARKER_TTL_MS) await rm(path, { force: true });\n }\n}\n\n/** Has the plugin's `alive` leg marked this session? False on any doubt. */\nexport async function sessionServedByPlugin(dataDir: string, event: unknown): Promise<boolean> {\n const sessionId = sessionIdOf(event);\n if (sessionId === null) return false;\n return (await stat(join(aliveDir(dataDir), markerName(sessionId))).catch(() => null)) !== null;\n}\n\n/** The machine's stamp, or null when the plugin has never loaded here. */\nexport async function readAliveStamp(dataDir: string): Promise<AliveStamp | null> {\n try {\n const parsed = JSON.parse(await readFile(join(aliveDir(dataDir), STAMP), 'utf8')) as unknown;\n if (parsed === null || typeof parsed !== 'object') return null;\n const { at, version } = parsed as { at?: unknown; version?: unknown };\n return typeof at === 'string' && typeof version === 'string' ? { at, version } : null;\n } catch {\n return null;\n }\n}\n\n/** `uninstall`: the markers and the stamp, and nothing else under the data dir. */\nexport async function removeAliveState(dataDir: string): Promise<boolean> {\n const dir = aliveDir(dataDir);\n const existed = (await stat(dir).catch(() => null)) !== null;\n if (!existed) return false;\n for (const name of await readdir(dir).catch(() => [] as string[])) {\n if (name === STAMP || /^[0-9a-f]{32}$/.test(name)) await rm(join(dir, name), { force: true });\n }\n // Only when empty: a file somebody else put there keeps the folder.\n await rmdir(dir).catch(() => undefined);\n return true;\n}\n\n/** How long the leg waits on a balance read before it says nothing. */\nexport const WALLET_READ_MS = 2_000;\n\n/**\n * THE WALLET, SAID TO THE PERSON AT THE START OF A SESSION while it cannot\n * pay: the leg's `systemMessage`, which Claude Code shows the user and never\n * the model, on every surface and without the mod. Null when there is no\n * wallet, the balance could not be read in time, or the wallet holds at least\n * the per-call limit.\n */\nexport async function walletNotice(\n dataDir: string,\n opts: { read?: typeof readUsdcBalanceWithFallback; timeoutMs?: number } = {},\n): Promise<string | null> {\n const wallet = await readJson(walletPath(dataDir));\n const address = typeof wallet?.address === 'string' ? wallet.address : undefined;\n if (address === undefined || !/^0x[0-9a-fA-F]{40}$/.test(address)) return null;\n const config = await readJson(configPath(dataDir));\n const rpcUrl = typeof config?.rpcUrl === 'string' ? config.rpcUrl : DEFAULT_RPC_URL;\n const timeoutMs = opts.timeoutMs ?? WALLET_READ_MS;\n const read = rememberingBalanceReader(dataDir, {\n ...(opts.read !== undefined ? { read: opts.read } : {}),\n });\n const balance = await read(address, rpcUrl, { timeoutMs });\n if (balance === null) return null;\n // The per-call limit as the spend policy reads it: the file's, else the default.\n const cap = BigInt(\n typeof config?.maxAutoSpend === 'string' && /^\\d{1,30}$/.test(config.maxAutoSpend)\n ? config.maxAutoSpend\n : DEFAULT_MAX_AUTO_SPEND,\n );\n if (balance > 0n && balance >= cap) return null;\n // Only the person reads it, inside the session: they ask, the agent runs it.\n return `Tenjin balance: $${dollars(balance)}. Ask your agent to add funds to Tenjin.`;\n}\n\n/** `$0.00`, `$0.10`, `$0.007`: whole cents keep two decimals. */\nfunction dollars(atomic: bigint): string {\n const fraction = (atomic % 1_000_000n).toString().padStart(6, '0').replace(/0+$/, '');\n return `${atomic / 1_000_000n}.${fraction.padEnd(2, '0')}`;\n}\n\nasync function readJson(path: string): Promise<Record<string, unknown> | null> {\n try {\n const value: unknown = JSON.parse(await readFile(path, 'utf8'));\n return value !== null && typeof value === 'object' ? (value as Record<string, unknown>) : null;\n } catch {\n return null;\n }\n}\n\n/**\n * The command form's entry, read off stdin: `tenjin hook alive`. It prints\n * only a JSON `systemMessage`, which Claude Code shows the user; plain text\n * would be added to the session's context.\n */\nexport async function aliveMain(opts: { dataDir: string; version: string }): Promise<void> {\n const raw = await readStdin(1_000).catch(() => '');\n await runAliveHook(parseEvent(raw), opts);\n const notice = await walletNotice(opts.dataDir).catch(() => null);\n if (notice !== null) process.stdout.write(`${JSON.stringify({ systemMessage: notice })}\\n`);\n}\n\nfunction parseEvent(raw: string): unknown {\n try {\n return JSON.parse(raw) as unknown;\n } catch {\n return null;\n }\n}\n\nfunction readStdin(timeoutMs: number): Promise<string> {\n return new Promise((resolve, reject) => {\n const chunks: Buffer[] = [];\n let size = 0;\n const timer = setTimeout(() => reject(new Error('no harness event')), timeoutMs);\n process.stdin.on('data', (chunk: Buffer) => {\n size += chunk.length;\n if (size > 1_000_000) {\n clearTimeout(timer);\n reject(new Error('harness event too large'));\n return;\n }\n chunks.push(chunk);\n });\n process.stdin.once('end', () => {\n clearTimeout(timer);\n resolve(Buffer.concat(chunks).toString('utf8'));\n });\n process.stdin.once('error', () => {\n clearTimeout(timer);\n reject(new Error('harness event unreadable'));\n });\n });\n}\n\n/**\n * A plugin leg marks its own session too, for a session that loaded the plugin\n * without a `SessionStart` (a `/reload-plugins` mid-session): from the next\n * event on, the settings install's legs there stay silent. A stat when the\n * marker is already there.\n */\nexport async function markSessionServed(dataDir: string, event: unknown): Promise<void> {\n const sessionId = sessionIdOf(event);\n if (sessionId === null) return;\n const path = join(aliveDir(dataDir), markerName(sessionId));\n if ((await stat(path).catch(() => null)) !== null) return;\n try {\n await mkdir(aliveDir(dataDir), { recursive: true, mode: 0o700 });\n await writeFile(path, `${new Date().toISOString()}\\n`);\n } catch {\n // Costs only a duplicate offer.\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,OAAO,SAAS,UAAU,IAAI,OAAO,MAAM,iBAAiB;AACrE,SAAS,YAAY;AA4BrB,IAAM,gBAAgB,IAAI,KAAK,KAAK,KAAK;AACzC,IAAM,QAAQ;AAEd,IAAM,iBAAiB;AAEhB,SAAS,SAAS,SAAyB;AAChD,SAAO,KAAK,SAAS,OAAO;AAC9B;AAEA,SAAS,WAAW,WAA2B;AAC7C,SAAO,WAAW,QAAQ,EAAE,OAAO,SAAS,EAAE,OAAO,KAAK,EAAE,MAAM,GAAG,EAAE;AACzE;AAEA,SAAS,YAAY,OAA+B;AAClD,MAAI,UAAU,QAAQ,OAAO,UAAU,SAAU,QAAO;AACxD,QAAM,KAAM,MAAmC;AAC/C,SAAO,OAAO,OAAO,YAAY,GAAG,SAAS,KAAK,GAAG,UAAU,iBAAiB,KAAK;AACvF;AAcA,eAAsB,aACpB,OACA,MACe;AACf,QAAM,YAAY,YAAY,KAAK;AACnC,QAAM,MAAM,KAAK,OAAO,KAAK,IAAI;AACjC,QAAM,MAAM,SAAS,KAAK,OAAO;AACjC,MAAI;AACF,UAAM,MAAM,KAAK,EAAE,WAAW,MAAM,MAAM,IAAM,CAAC;AACjD,QAAI,cAAc,MAAM;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mBAAa,KAAK;AAClB,cAAQ,OAAO,OAAO,MAAM,EAAE,SAAS,MAAM,CAAC;AAAA,IAChD,CAAC;AACD,YAAQ,MAAM,KAAK,SAAS,MAAM;AAChC,mBAAa,KAAK;AAClB,aAAO,IAAI,MAAM,0BAA0B,CAAC;AAAA,IAC9C,CAAC;AAAA,EACH,CAAC;AACH;AAQA,eAAsB,kBAAkB,SAAiB,OAA+B;AACtF,QAAM,YAAY,YAAY,KAAK;AACnC,MAAI,cAAc,KAAM;AACxB,QAAM,OAAO,KAAK,SAAS,OAAO,GAAG,WAAW,SAAS,CAAC;AAC1D,MAAK,MAAM,KAAK,IAAI,EAAE,MAAM,MAAM,IAAI,MAAO,KAAM;AACnD,MAAI;AACF,UAAM,MAAM,SAAS,OAAO,GAAG,EAAE,WAAW,MAAM,MAAM,IAAM,CAAC;AAC/D,UAAM,UAAU,MAAM,IAAG,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,CAAI;AAAA,EACvD,QAAQ;AAAA,EAER;AACF;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
CliError
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-3UCIG4TG.js";
|
|
5
5
|
|
|
6
6
|
// src/lib/destination.ts
|
|
7
7
|
import { lookup } from "node:dns/promises";
|
|
@@ -105,4 +105,4 @@ export {
|
|
|
105
105
|
assertPublicDestination,
|
|
106
106
|
resolvePublicDestination
|
|
107
107
|
};
|
|
108
|
-
//# sourceMappingURL=chunk-
|
|
108
|
+
//# sourceMappingURL=chunk-JKKAIPTU.js.map
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
HashMD,
|
|
4
|
-
secp256k1,
|
|
5
|
-
sha256
|
|
6
|
-
} from "./chunk-JRGFKVAZ.js";
|
|
7
2
|
import {
|
|
8
3
|
BaseError,
|
|
9
4
|
BytesSizeMismatchError,
|
|
@@ -42,6 +37,11 @@ import {
|
|
|
42
37
|
toHex,
|
|
43
38
|
trim
|
|
44
39
|
} from "./chunk-EGELTSPU.js";
|
|
40
|
+
import {
|
|
41
|
+
HashMD,
|
|
42
|
+
secp256k1,
|
|
43
|
+
sha256
|
|
44
|
+
} from "./chunk-JRGFKVAZ.js";
|
|
45
45
|
import {
|
|
46
46
|
keccak_256
|
|
47
47
|
} from "./chunk-KG3D7FIF.js";
|
|
@@ -1182,4 +1182,4 @@ export {
|
|
|
1182
1182
|
ripemd1602 as ripemd160,
|
|
1183
1183
|
keccak2562 as keccak256
|
|
1184
1184
|
};
|
|
1185
|
-
//# sourceMappingURL=chunk-
|
|
1185
|
+
//# sourceMappingURL=chunk-K3I7C2MO.js.map
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
|
-
CliError,
|
|
4
3
|
external_exports
|
|
5
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-YVFXE7RR.js";
|
|
5
|
+
import {
|
|
6
|
+
CliError
|
|
7
|
+
} from "./chunk-3UCIG4TG.js";
|
|
6
8
|
|
|
7
9
|
// src/lib/output.ts
|
|
8
10
|
import { WriteStream } from "node:tty";
|
|
@@ -234,4 +236,4 @@ export {
|
|
|
234
236
|
style,
|
|
235
237
|
paint
|
|
236
238
|
};
|
|
237
|
-
//# sourceMappingURL=chunk-
|
|
239
|
+
//# sourceMappingURL=chunk-K72RURN3.js.map
|