tenjin-cli 0.1.0-alpha.16 → 0.1.0-alpha.18
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 +5 -0
- package/dist/chunk-2G2WLVHB.js +102 -0
- package/dist/chunk-2G2WLVHB.js.map +1 -0
- package/dist/chunk-2I4QTOLB.js +11 -0
- package/dist/chunk-2I4QTOLB.js.map +1 -0
- package/dist/chunk-35M3VITA.js +102 -0
- package/dist/chunk-35M3VITA.js.map +1 -0
- package/dist/chunk-3KKKB2AQ.js +40 -0
- package/dist/chunk-3KKKB2AQ.js.map +1 -0
- package/dist/{chunk-OIM4HLN6.js → chunk-7QKHZQKW.js} +295 -20
- package/dist/chunk-7QKHZQKW.js.map +1 -0
- package/dist/{chunk-BBVUVBUO.js → chunk-AR7U7BRG.js} +44 -7
- package/dist/{chunk-BBVUVBUO.js.map → chunk-AR7U7BRG.js.map} +1 -1
- package/dist/{chunk-DMZZLPZN.js → chunk-AUKDYPPX.js} +14 -89
- package/dist/chunk-AUKDYPPX.js.map +1 -0
- package/dist/{chunk-56MOAIP5.js → chunk-BTX2QE2Y.js} +9 -6
- package/dist/chunk-BTX2QE2Y.js.map +1 -0
- package/dist/{chunk-HVRC33OL.js → chunk-EPCOMXLF.js} +4 -6
- package/dist/{chunk-HVRC33OL.js.map → chunk-EPCOMXLF.js.map} +1 -1
- package/dist/{chunk-25TJPVBF.js → chunk-F3FUGWPZ.js} +28 -15
- package/dist/chunk-F3FUGWPZ.js.map +1 -0
- package/dist/{chunk-2U5ZVEV3.js → chunk-FGR734LZ.js} +6 -6
- package/dist/{chunk-PZEN5PHN.js → chunk-J5INH7WB.js} +17 -3
- package/dist/chunk-J5INH7WB.js.map +1 -0
- package/dist/{chunk-7WEQQJLG.js → chunk-JLEF5WHM.js} +66 -2
- package/dist/chunk-JLEF5WHM.js.map +1 -0
- package/dist/{chunk-YEETV6IW.js → chunk-KUBEYXSO.js} +10 -12
- package/dist/{chunk-YEETV6IW.js.map → chunk-KUBEYXSO.js.map} +1 -1
- package/dist/{chunk-L3PVMIYQ.js → chunk-N44H5TFB.js} +82 -150
- package/dist/chunk-N44H5TFB.js.map +1 -0
- package/dist/{chunk-BFFM2WFK.js → chunk-NRQMOVKM.js} +2 -2
- package/dist/{chunk-BFFM2WFK.js.map → chunk-NRQMOVKM.js.map} +1 -1
- package/dist/{chunk-GULLJQXA.js → chunk-ON6C6WOX.js} +127 -17
- package/dist/chunk-ON6C6WOX.js.map +1 -0
- package/dist/{chunk-OJLYNM4Z.js → chunk-PDA2BVFY.js} +77 -19
- package/dist/chunk-PDA2BVFY.js.map +1 -0
- package/dist/chunk-S2NRVRPF.js +171 -0
- package/dist/chunk-S2NRVRPF.js.map +1 -0
- package/dist/chunk-TGLKKLQG.js +11 -0
- package/dist/chunk-TGLKKLQG.js.map +1 -0
- package/dist/{chunk-SKAHDQH7.js → chunk-TJMCBIZU.js} +6 -7
- package/dist/{chunk-SKAHDQH7.js.map → chunk-TJMCBIZU.js.map} +1 -1
- package/dist/chunk-TP4D47BY.js +127 -0
- package/dist/chunk-TP4D47BY.js.map +1 -0
- package/dist/{chunk-WH7OWT6G.js → chunk-U2DZISAH.js} +2 -8
- package/dist/chunk-U2DZISAH.js.map +1 -0
- package/dist/{chunk-YJHHCWM3.js → chunk-WLMJE3GJ.js} +3 -3
- package/dist/{chunk-U5DXNFJC.js → chunk-WS4JA6TC.js} +3 -3
- package/dist/{chunk-5X4SZ5BF.js → chunk-WUHY2AXD.js} +4 -4
- package/dist/{chunk-USS336NF.js → chunk-YPQSMIDH.js} +5 -5
- package/dist/chunk-YPQSMIDH.js.map +1 -0
- package/dist/{chunk-3AJS6LLN.js → chunk-ZG7SFI34.js} +7 -7
- package/dist/{cli-M3XCSOU6.js → cli-MP3RAYHL.js} +43 -29
- package/dist/{cli-M3XCSOU6.js.map → cli-MP3RAYHL.js.map} +1 -1
- package/dist/{config-MXOX7XDR.js → config-BJK6U5VY.js} +11 -10
- package/dist/{doctor-LU4YIZWM.js → doctor-KJROWE5V.js} +108 -21
- package/dist/doctor-KJROWE5V.js.map +1 -0
- package/dist/{fund-A54P2QFK.js → fund-I5COXPEJ.js} +13 -11
- package/dist/{fund-A54P2QFK.js.map → fund-I5COXPEJ.js.map} +1 -1
- package/dist/hook-command-EJO2564A.js +821 -0
- package/dist/hook-command-EJO2564A.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/{install-XUM2XSHW.js → install-NUQLLHS2.js} +21 -14
- package/dist/{install-wallet-QIOFORTX.js → install-wallet-JPFTEC6H.js} +12 -10
- package/dist/{install-wallet-QIOFORTX.js.map → install-wallet-JPFTEC6H.js.map} +1 -1
- package/dist/{mcp-HJC2PLRV.js → mcp-I5XMVE64.js} +77 -34
- package/dist/{mcp-HJC2PLRV.js.map → mcp-I5XMVE64.js.map} +1 -1
- package/dist/{pay-SBXZEPEP.js → pay-WA3JSCNB.js} +21 -14
- package/dist/{redact-46ZHF2NH.js → redact-6W23GGJC.js} +4 -6
- package/dist/{send-ASD2ZXJD.js → send-KVUH5WDO.js} +12 -10
- package/dist/{send-ASD2ZXJD.js.map → send-KVUH5WDO.js.map} +1 -1
- package/dist/{skill-placement-NFVHY6A3.js → skill-placement-JMDPSKE6.js} +12 -13
- package/dist/{skill-placement-NFVHY6A3.js.map → skill-placement-JMDPSKE6.js.map} +1 -1
- package/dist/{status-T2SDB57A.js → status-FFC6FO72.js} +8 -7
- package/dist/{status-T2SDB57A.js.map → status-FFC6FO72.js.map} +1 -1
- package/dist/{status-line-CGPUSDMC.js → status-line-SAXSU6CR.js} +19 -3
- package/dist/status-line-SAXSU6CR.js.map +1 -0
- package/dist/{status-line-wiring-BYPHTYZE.js → status-line-wiring-DQZCWIUO.js} +5 -6
- package/dist/tenjin-daemon.mjs +384 -23
- package/dist/{uninstall-FKYZHAM3.js → uninstall-SWICHBTF.js} +41 -18
- package/dist/uninstall-SWICHBTF.js.map +1 -0
- package/dist/{update-ANJ2AOTN.js → update-W572AMXG.js} +6 -7
- package/dist/{update-ANJ2AOTN.js.map → update-W572AMXG.js.map} +1 -1
- package/dist/{wallet-PWAHVKWW.js → wallet-L2YLAJFN.js} +12 -10
- package/docs/agent-permissions.md +17 -9
- package/docs/safety-model.md +1 -1
- package/package.json +1 -1
- package/dist/chunk-25TJPVBF.js.map +0 -1
- package/dist/chunk-56MOAIP5.js.map +0 -1
- package/dist/chunk-7WEQQJLG.js.map +0 -1
- package/dist/chunk-DMZZLPZN.js.map +0 -1
- package/dist/chunk-GULLJQXA.js.map +0 -1
- package/dist/chunk-L3PVMIYQ.js.map +0 -1
- package/dist/chunk-OCBHUHWB.js +0 -69
- package/dist/chunk-OCBHUHWB.js.map +0 -1
- package/dist/chunk-OIM4HLN6.js.map +0 -1
- package/dist/chunk-OJLYNM4Z.js.map +0 -1
- package/dist/chunk-PZEN5PHN.js.map +0 -1
- package/dist/chunk-USS336NF.js.map +0 -1
- package/dist/chunk-WH7OWT6G.js.map +0 -1
- package/dist/doctor-LU4YIZWM.js.map +0 -1
- package/dist/hook-command-U6KWPEDQ.js +0 -377
- package/dist/hook-command-U6KWPEDQ.js.map +0 -1
- package/dist/status-line-CGPUSDMC.js.map +0 -1
- package/dist/uninstall-FKYZHAM3.js.map +0 -1
- /package/dist/{chunk-2U5ZVEV3.js.map → chunk-FGR734LZ.js.map} +0 -0
- /package/dist/{chunk-YJHHCWM3.js.map → chunk-WLMJE3GJ.js.map} +0 -0
- /package/dist/{chunk-U5DXNFJC.js.map → chunk-WS4JA6TC.js.map} +0 -0
- /package/dist/{chunk-5X4SZ5BF.js.map → chunk-WUHY2AXD.js.map} +0 -0
- /package/dist/{chunk-3AJS6LLN.js.map → chunk-ZG7SFI34.js.map} +0 -0
- /package/dist/{config-MXOX7XDR.js.map → config-BJK6U5VY.js.map} +0 -0
- /package/dist/{install-XUM2XSHW.js.map → install-NUQLLHS2.js.map} +0 -0
- /package/dist/{pay-SBXZEPEP.js.map → pay-WA3JSCNB.js.map} +0 -0
- /package/dist/{redact-46ZHF2NH.js.map → redact-6W23GGJC.js.map} +0 -0
- /package/dist/{status-line-wiring-BYPHTYZE.js.map → status-line-wiring-DQZCWIUO.js.map} +0 -0
- /package/dist/{wallet-PWAHVKWW.js.map → wallet-L2YLAJFN.js.map} +0 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
findAllProjectFiles,
|
|
4
|
+
findNearestProjectFiles,
|
|
5
|
+
mainWorktreeOf,
|
|
6
|
+
ownedCandidates,
|
|
7
|
+
projectRoot
|
|
8
|
+
} from "./chunk-PDA2BVFY.js";
|
|
9
|
+
import {
|
|
10
|
+
CONFIG_DEFAULTS,
|
|
11
|
+
loadRawConfig,
|
|
12
|
+
parseRouterLayer
|
|
13
|
+
} from "./chunk-AR7U7BRG.js";
|
|
14
|
+
import {
|
|
15
|
+
CliError
|
|
16
|
+
} from "./chunk-JLEF5WHM.js";
|
|
17
|
+
import {
|
|
18
|
+
configPath
|
|
19
|
+
} from "./chunk-2BKS2FVE.js";
|
|
20
|
+
|
|
21
|
+
// src/router/settings.ts
|
|
22
|
+
import { readFile } from "node:fs/promises";
|
|
23
|
+
import { homedir } from "node:os";
|
|
24
|
+
import { join, resolve } from "node:path";
|
|
25
|
+
var PROJECT_ROUTER_FILE = join(".tenjin", "config.json");
|
|
26
|
+
var LOCAL_ROUTER_FILE = join(".tenjin", "config.local.json");
|
|
27
|
+
async function routerSettings(input, deps = {}) {
|
|
28
|
+
const globalPath = configPath(input.dataDir);
|
|
29
|
+
const global = (input.config ?? await loadRawConfig(input.dataDir)).router;
|
|
30
|
+
let enabled = {
|
|
31
|
+
value: CONFIG_DEFAULTS.router.enabled,
|
|
32
|
+
source: "default"
|
|
33
|
+
};
|
|
34
|
+
let context = {
|
|
35
|
+
value: CONFIG_DEFAULTS.router.context,
|
|
36
|
+
source: "default"
|
|
37
|
+
};
|
|
38
|
+
if (global?.enabled !== void 0) {
|
|
39
|
+
enabled = { value: global.enabled, source: "file", path: globalPath };
|
|
40
|
+
}
|
|
41
|
+
if (global?.context !== void 0) {
|
|
42
|
+
context = { value: global.context, source: "file", path: globalPath };
|
|
43
|
+
}
|
|
44
|
+
for (const { source, path, layer } of await projectLayers(input, deps)) {
|
|
45
|
+
if (layer.enabled !== void 0 && (layer.enabled === false || enabled.value)) {
|
|
46
|
+
enabled = { value: layer.enabled, source, path };
|
|
47
|
+
}
|
|
48
|
+
if (layer.context !== void 0 && (layer.context === "turn" || context.value === "session")) {
|
|
49
|
+
context = { value: layer.context, source, path };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return { enabled, context };
|
|
53
|
+
}
|
|
54
|
+
var ROUTER_FILES = [PROJECT_ROUTER_FILE, LOCAL_ROUTER_FILE];
|
|
55
|
+
async function projectLayers(input, deps) {
|
|
56
|
+
const { levels, gitRoot } = await findAllProjectFiles(input.cwd, ROUTER_FILES, {
|
|
57
|
+
...deps,
|
|
58
|
+
// $HOME/.tenjin is the global scope, not a project.
|
|
59
|
+
homeIsProject: false
|
|
60
|
+
});
|
|
61
|
+
const main = gitRoot === null ? null : await mainWorktreeOf(gitRoot, deps.homeDir);
|
|
62
|
+
const outer = main === null ? [] : [{ dir: main, found: await ownedCandidates(main, ROUTER_FILES, deps) }];
|
|
63
|
+
const layers = [];
|
|
64
|
+
for (const { dir, found } of [...outer, ...levels.reverse()]) {
|
|
65
|
+
if (resolve(dir, ".tenjin") === resolve(input.dataDir)) continue;
|
|
66
|
+
for (const path of found) {
|
|
67
|
+
const file = await readProjectRouterFile(path);
|
|
68
|
+
if (file === null) continue;
|
|
69
|
+
layers.push({
|
|
70
|
+
source: path === join(dir, LOCAL_ROUTER_FILE) ? "local" : "project",
|
|
71
|
+
path,
|
|
72
|
+
layer: file.layer
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return layers;
|
|
77
|
+
}
|
|
78
|
+
var ABSENT = /* @__PURE__ */ new Set(["ENOENT", "ENOTDIR"]);
|
|
79
|
+
async function readProjectRouterFile(path) {
|
|
80
|
+
let raw;
|
|
81
|
+
try {
|
|
82
|
+
raw = await readFile(path, "utf8");
|
|
83
|
+
} catch (err) {
|
|
84
|
+
if (ABSENT.has(String(err.code))) return null;
|
|
85
|
+
throw invalid(path, "could not be read", err);
|
|
86
|
+
}
|
|
87
|
+
let json;
|
|
88
|
+
try {
|
|
89
|
+
json = JSON.parse(raw);
|
|
90
|
+
} catch (err) {
|
|
91
|
+
throw invalid(path, "is not valid JSON", err);
|
|
92
|
+
}
|
|
93
|
+
const layer = parseRouterLayer(json, path);
|
|
94
|
+
return { json, layer };
|
|
95
|
+
}
|
|
96
|
+
async function projectRouterPath(input, deps = {}) {
|
|
97
|
+
const home = deps.homeDir ?? homedir();
|
|
98
|
+
const hit = await findNearestProjectFiles(input.cwd, [PROJECT_ROUTER_FILE, LOCAL_ROUTER_FILE], {
|
|
99
|
+
...deps,
|
|
100
|
+
warn: () => void 0,
|
|
101
|
+
homeIsProject: false
|
|
102
|
+
});
|
|
103
|
+
const dir = hit?.dir ?? await projectRoot(input.cwd, home);
|
|
104
|
+
if (dir === home) {
|
|
105
|
+
throw new CliError(
|
|
106
|
+
"USAGE",
|
|
107
|
+
"Your home directory is not a project: its .tenjin is the global config.",
|
|
108
|
+
{
|
|
109
|
+
fix: "Run it from inside the project, or drop --project to set it for this machine."
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
return join(dir, input.local ? LOCAL_ROUTER_FILE : PROJECT_ROUTER_FILE);
|
|
114
|
+
}
|
|
115
|
+
function invalid(path, what, cause) {
|
|
116
|
+
return new CliError("CONFIG_INVALID", `Config at ${path} ${what}`, {
|
|
117
|
+
fix: `Fix ${path}, or delete it.`,
|
|
118
|
+
...cause !== void 0 ? { cause } : {}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export {
|
|
123
|
+
routerSettings,
|
|
124
|
+
readProjectRouterFile,
|
|
125
|
+
projectRouterPath
|
|
126
|
+
};
|
|
127
|
+
//# sourceMappingURL=chunk-TP4D47BY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/router/settings.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { join, resolve } from 'node:path';\nimport {\n CONFIG_DEFAULTS,\n loadRawConfig,\n parseRouterLayer,\n type PartialConfig,\n type RouterContext,\n type RouterLayer,\n} from '../lib/config';\nimport { CliError } from '../lib/errors';\nimport { configPath } from '../lib/paths';\nimport {\n findAllProjectFiles,\n findNearestProjectFiles,\n mainWorktreeOf,\n ownedCandidates,\n projectRoot,\n type ProjectWalkDeps,\n} from '../lib/settings';\n\n/**\n * THE ONE READER OF THE ROUTER'S OWN KEYS, `router.enabled` and\n * `router.context`. Both hooks, the `request` tool, doctor, the status line and\n * `tenjin config` call {@link routerSettings} first, and nothing reads a router\n * key any other way.\n *\n * THE LAYERS: the default, `~/.tenjin/config.json`, then EVERY\n * `.tenjin/config.json` and `config.local.json` from the working directory up\n * to the git root, and in a linked git worktree the main checkout's pair too.\n * No environment variable.\n *\n * EVERY LAYER IS A FLOOR. `enabled` is false when any layer says false, and\n * `context` is `turn` when any layer says turn; a key a file leaves out\n * inherits, and a looser value is not read. So a file a cloned repository\n * carries cannot undo `tenjin config set router.enabled false` on this\n * machine, a package in a monorepo cannot undo its root, and a\n * `config.local.json` a repository commits anyway cannot undo the committed\n * one. Both keys fail toward less data sent, and no project file has a spend\n * key to loosen. The source reported is the nearest layer at the value.\n *\n * ONE PARSER. The global block is the one `loadRawConfig` already validated,\n * and a project file goes through `parseRouterLayer` from the same schema.\n */\n\n/** The committed project file and the personal one beside it. */\nexport const PROJECT_ROUTER_FILE = join('.tenjin', 'config.json');\nexport const LOCAL_ROUTER_FILE = join('.tenjin', 'config.local.json');\n\nexport type RouterSource = 'default' | 'file' | 'project' | 'local';\n\nexport interface RouterSetting<T> {\n value: T;\n source: RouterSource;\n /** The file that set it; absent for the default. */\n path?: string;\n}\n\nexport interface RouterSettings {\n enabled: RouterSetting<boolean>;\n context: RouterSetting<RouterContext>;\n}\n\nexport interface RouterSettingsInput {\n /** The directory the harness is working in. */\n cwd: string;\n /** The data dir whose `config.json` is the global layer. */\n dataDir: string;\n /** That file, when the caller has already loaded it; read here otherwise. */\n config?: PartialConfig;\n}\n\nexport async function routerSettings(\n input: RouterSettingsInput,\n deps: ProjectWalkDeps = {},\n): Promise<RouterSettings> {\n const globalPath = configPath(input.dataDir);\n const global = (input.config ?? (await loadRawConfig(input.dataDir))).router;\n let enabled: RouterSetting<boolean> = {\n value: CONFIG_DEFAULTS.router.enabled,\n source: 'default',\n };\n let context: RouterSetting<RouterContext> = {\n value: CONFIG_DEFAULTS.router.context,\n source: 'default',\n };\n if (global?.enabled !== undefined) {\n enabled = { value: global.enabled, source: 'file', path: globalPath };\n }\n if (global?.context !== undefined) {\n context = { value: global.context, source: 'file', path: globalPath };\n }\n\n for (const { source, path, layer } of await projectLayers(input, deps)) {\n // Every layer is a floor: a value looser than the one so far is not read.\n if (layer.enabled !== undefined && (layer.enabled === false || enabled.value)) {\n enabled = { value: layer.enabled, source, path };\n }\n if (layer.context !== undefined && (layer.context === 'turn' || context.value === 'session')) {\n context = { value: layer.context, source, path };\n }\n }\n return { enabled, context };\n}\n\nconst ROUTER_FILES = [PROJECT_ROUTER_FILE, LOCAL_ROUTER_FILE];\n\n/**\n * Every project layer, outermost first so the nearest one at a value is the\n * one reported: the main checkout's pair when this is a linked worktree, then\n * each directory from the git root down to `cwd`, its project file before its\n * personal one.\n */\nasync function projectLayers(\n input: RouterSettingsInput,\n deps: ProjectWalkDeps,\n): Promise<{ source: 'project' | 'local'; path: string; layer: RouterLayer }[]> {\n const { levels, gitRoot } = await findAllProjectFiles(input.cwd, ROUTER_FILES, {\n ...deps,\n // $HOME/.tenjin is the global scope, not a project.\n homeIsProject: false,\n });\n const main = gitRoot === null ? null : await mainWorktreeOf(gitRoot, deps.homeDir);\n const outer =\n main === null ? [] : [{ dir: main, found: await ownedCandidates(main, ROUTER_FILES, deps) }];\n const layers = [];\n for (const { dir, found } of [...outer, ...levels.reverse()]) {\n // A data dir kept inside a project is the global file, already read.\n if (resolve(dir, '.tenjin') === resolve(input.dataDir)) continue;\n for (const path of found) {\n const file = await readProjectRouterFile(path);\n if (file === null) continue;\n layers.push({\n source: path === join(dir, LOCAL_ROUTER_FILE) ? ('local' as const) : ('project' as const),\n path,\n layer: file.layer,\n });\n }\n }\n return layers;\n}\n\nconst ABSENT = new Set(['ENOENT', 'ENOTDIR']);\n\n/**\n * One project file: its whole JSON, for a writer that keeps sibling keys, and\n * its router layer through the one parser. Null when there is no file.\n */\nexport async function readProjectRouterFile(\n path: string,\n): Promise<{ json: Record<string, unknown>; layer: RouterLayer } | null> {\n let raw: string;\n try {\n raw = await readFile(path, 'utf8');\n } catch (err) {\n if (ABSENT.has(String((err as { code?: unknown }).code))) return null;\n throw invalid(path, 'could not be read', err);\n }\n let json: unknown;\n try {\n json = JSON.parse(raw);\n } catch (err) {\n throw invalid(path, 'is not valid JSON', err);\n }\n const layer = parseRouterLayer(json, path);\n return { json: json as Record<string, unknown>, layer };\n}\n\n/**\n * Where `tenjin config set --project [--local]` writes from `cwd`: beside the\n * layer {@link routerSettings} already reads there, else at the git root, else\n * in `cwd`. Never in $HOME, whose `.tenjin/config.json` is the global file.\n */\nexport async function projectRouterPath(\n input: { cwd: string; local: boolean },\n deps: ProjectWalkDeps = {},\n): Promise<string> {\n const home = deps.homeDir ?? homedir();\n const hit = await findNearestProjectFiles(input.cwd, [PROJECT_ROUTER_FILE, LOCAL_ROUTER_FILE], {\n ...deps,\n warn: () => undefined,\n homeIsProject: false,\n });\n const dir = hit?.dir ?? (await projectRoot(input.cwd, home));\n if (dir === home) {\n throw new CliError(\n 'USAGE',\n 'Your home directory is not a project: its .tenjin is the global config.',\n {\n fix: 'Run it from inside the project, or drop --project to set it for this machine.',\n },\n );\n }\n return join(dir, input.local ? LOCAL_ROUTER_FILE : PROJECT_ROUTER_FILE);\n}\n\nfunction invalid(path: string, what: string, cause?: unknown): CliError {\n return new CliError('CONFIG_INVALID', `Config at ${path} ${what}`, {\n fix: `Fix ${path}, or delete it.`,\n ...(cause !== undefined ? { cause } : {}),\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,SAAS,MAAM,eAAe;AA6CvB,IAAM,sBAAsB,KAAK,WAAW,aAAa;AACzD,IAAM,oBAAoB,KAAK,WAAW,mBAAmB;AAyBpE,eAAsB,eACpB,OACA,OAAwB,CAAC,GACA;AACzB,QAAM,aAAa,WAAW,MAAM,OAAO;AAC3C,QAAM,UAAU,MAAM,UAAW,MAAM,cAAc,MAAM,OAAO,GAAI;AACtE,MAAI,UAAkC;AAAA,IACpC,OAAO,gBAAgB,OAAO;AAAA,IAC9B,QAAQ;AAAA,EACV;AACA,MAAI,UAAwC;AAAA,IAC1C,OAAO,gBAAgB,OAAO;AAAA,IAC9B,QAAQ;AAAA,EACV;AACA,MAAI,QAAQ,YAAY,QAAW;AACjC,cAAU,EAAE,OAAO,OAAO,SAAS,QAAQ,QAAQ,MAAM,WAAW;AAAA,EACtE;AACA,MAAI,QAAQ,YAAY,QAAW;AACjC,cAAU,EAAE,OAAO,OAAO,SAAS,QAAQ,QAAQ,MAAM,WAAW;AAAA,EACtE;AAEA,aAAW,EAAE,QAAQ,MAAM,MAAM,KAAK,MAAM,cAAc,OAAO,IAAI,GAAG;AAEtE,QAAI,MAAM,YAAY,WAAc,MAAM,YAAY,SAAS,QAAQ,QAAQ;AAC7E,gBAAU,EAAE,OAAO,MAAM,SAAS,QAAQ,KAAK;AAAA,IACjD;AACA,QAAI,MAAM,YAAY,WAAc,MAAM,YAAY,UAAU,QAAQ,UAAU,YAAY;AA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F,WAAO,KAAK,MAAM,GAAG;AAAA,EACvB,SAAS,KAAK;AACZ,UAAM,QAAQ,MAAM,qBAAqB,GAAG;AAAA,EAC9C;AACA,QAAM,QAAQ,iBAAiB,MAAM,IAAI;AACzC,SAAO,EAAE,MAAuC,MAAM;AACxD;AAOA,eAAsB,kBACpB,OACA,OAAwB,CAAC,GACR;AACjB,QAAM,OAAO,KAAK,WAAW,QAAQ;AACrC,QAAM,MAAM,MAAM,wBAAwB,MAAM,KAAK,CAAC,qBAAqB,iBAAiB,GAAG;AAAA,IAC7F,GAAG;AAAA,IACH,MAAM,MAAM;AAAA,IACZ,eAAe;AAAA,EACjB,CAAC;AACD,QAAM,MAAM,KAAK,OAAQ,MAAM,YAAY,MAAM,KAAK,IAAI;AAC1D,MAAI,QAAQ,MAAM;AAChB,UAAM,IAAI;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,QACE,KAAK;AAAA,MACP;AAAA,IACF;AAAA,EACF;AACA,SAAO,KAAK,KAAK,MAAM,QAAQ,oBAAoB,mBAAmB;AACxE;AAEA,SAAS,QAAQ,MAAc,MAAc,OAA2B;AACtE,SAAO,IAAI,SAAS,kBAAkB,aAAa,IAAI,IAAI,IAAI,IAAI;AAAA,IACjE,KAAK,OAAO,IAAI;AAAA,IAChB,GAAI,UAAU,SAAY,EAAE,MAAM,IAAI,CAAC;AAAA,EACzC,CAAC;AACH;","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-JLEF5WHM.js";
|
|
5
5
|
|
|
6
6
|
// src/lib/money.ts
|
|
7
7
|
var USDC_DECIMALS = 6;
|
|
@@ -40,11 +40,6 @@ function toMoney(atomic) {
|
|
|
40
40
|
return { atomic, usd: atomicToUsd(atomic) };
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
// src/lib/errno.ts
|
|
44
|
-
function hasCode(err, code) {
|
|
45
|
-
return typeof err === "object" && err !== null && "code" in err && err.code === code;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
43
|
// src/lib/policy.ts
|
|
49
44
|
function normCreator(value) {
|
|
50
45
|
return value.trim().toLowerCase();
|
|
@@ -108,10 +103,9 @@ function parseConfirmPolicy(stored) {
|
|
|
108
103
|
}
|
|
109
104
|
|
|
110
105
|
export {
|
|
111
|
-
hasCode,
|
|
112
106
|
parseUsdToAtomic,
|
|
113
107
|
toMoney,
|
|
114
108
|
evaluateSpendPolicy,
|
|
115
109
|
parseConfirmPolicy
|
|
116
110
|
};
|
|
117
|
-
//# sourceMappingURL=chunk-
|
|
111
|
+
//# sourceMappingURL=chunk-U2DZISAH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/money.ts","../src/lib/policy.ts"],"sourcesContent":["import { CliError } from './errors';\nimport { ATOMIC_RE } from './ids';\nimport type { Money } from '../schemas';\n\n/** USDC is a 6-decimal token; one dollar is 1_000_000 atomic units. */\nconst USDC_DECIMALS = 6;\n\n/**\n * Decimal USD at the CLI edge -> atomic USDC string (O1). Accepts \"0\", \"0.25\",\n * \"5\"; rejects negatives, non-numeric input, and more than 6 decimal places as\n * USAGE so a fat-fingered amount fails loudly instead of truncating money.\n * String math throughout — a float would lose precision at the 6th decimal.\n */\nexport function parseUsdToAtomic(input: string): string {\n const trimmed = input.trim();\n if (!/^\\d+(\\.\\d+)?$/.test(trimmed)) {\n throw new CliError('USAGE', `Invalid USD amount: ${JSON.stringify(input)}`, {\n fix: 'Pass a non-negative decimal like 0.25 or 5.',\n });\n }\n const [whole, frac = ''] = trimmed.split('.');\n if (frac.length > USDC_DECIMALS) {\n throw new CliError(\n 'USAGE',\n `USD amount ${JSON.stringify(input)} has more than 6 decimal places`,\n {\n fix: 'USDC supports at most 6 decimal places (micro-dollars).',\n },\n );\n }\n const atomic = BigInt(`${whole}${frac.padEnd(USDC_DECIMALS, '0')}`);\n return atomic.toString();\n}\n\n/**\n * Atomic USDC string -> decimal USD string, trailing zeros trimmed (\"250000\" ->\n * \"0.25\", \"5000000\" -> \"5\", \"0\" -> \"0\"). Throws INTERNAL on a malformed atomic\n * value: atomic strings come from validated config or on-chain reads, so a bad\n * one is a bug, not user input.\n */\nexport function atomicToUsd(atomic: string): string {\n const trimmed = atomic.trim();\n if (!/^\\d+$/.test(trimmed)) {\n throw new CliError('INTERNAL', `Malformed atomic amount: ${JSON.stringify(atomic)}`);\n }\n const value = BigInt(trimmed);\n const base = 10n ** BigInt(USDC_DECIMALS);\n const whole = value / base;\n const frac = (value % base).toString().padStart(USDC_DECIMALS, '0').replace(/0+$/, '');\n return frac.length > 0 ? `${whole}.${frac}` : whole.toString();\n}\n\n/**\n * Whether an atomic price would actually cost something: true paid, false free,\n * null when the string is not an atomic amount at all and so cannot answer.\n *\n * A Tenjin piece may be priced at zero and is then delivered by `read` with no\n * payment, so \"there is a price field\" and \"there is a purchase to make\" are\n * different questions. The third state is not decoration: only the wire schema\n * enforces ATOMIC_RE, and the local search store types `price` as a bare string,\n * so a hand-edited or half-written entry can hold \"-1\" or \"0.1\". Those must not\n * read as \"free\", or corrupt local data would start refusing honest reports.\n * Never throws, which is why the check is a regex and not a BigInt compare.\n *\n * Matched against the RAW string, with no trimming. The contract carries the\n * canonical form and nothing else, so \" 0 \" did not come off the wire; padding is\n * evidence the value was edited, and normalizing it away would launder a corrupt\n * entry into a confident \"free\" and hand back the false refusal this avoids.\n */\nexport function isPaidPrice(atomic: string): boolean | null {\n if (!ATOMIC_RE.test(atomic)) return null;\n return /[1-9]/.test(atomic);\n}\n\n/** Dual-form money object for machine output. */\nexport function toMoney(atomic: string): Money {\n return { atomic, usd: atomicToUsd(atomic) };\n}\n\n/**\n * Canonical USD for human COPY (a price a person reads): always at least two\n * decimals (\"0.10\", \"5.00\"), keeping any finer precision below a cent\n * (\"0.000001\"). Distinct from `atomicToUsd`, which trims to the shortest exact\n * form for machine output; use this only where a dollar amount is shown to a human.\n */\nexport function formatUsdDisplay(atomic: string): string {\n const [whole, frac = ''] = atomicToUsd(atomic).split('.');\n return `${whole}.${frac.padEnd(2, '0')}`;\n}\n","/**\n * Spend-policy evaluation, pure and provider-agnostic. The wallet provider layer\n * (lib/wallet/spend.ts) owns the ledger and calls this; a future hosted provider\n * (Privy, B5) reuses the same decision rules, so the knobs live in exactly one\n * place. Nothing here does IO, the caller supplies the already-spent total and\n * decides how to satisfy a `confirm` decision (a `--yes`, a TTY prompt, or a\n * non-interactive refusal).\n */\n\n/** How a `confirm` gate is configured (parsed from the stored config string). */\nexport type ConfirmPolicy = { mode: 'always' } | { mode: 'above'; thresholdAtomic: bigint };\n\nexport interface SpendPolicy {\n /** Amounts at or below this auto-approve WITHOUT a prompt (still subject to the\n * confirm gate below). Default 0 → nothing auto-approves. */\n maxAutoSpendAtomic: bigint;\n /** Rolling local ceiling on cumulative session spend. 0 = disabled (no ceiling). */\n sessionBudgetAtomic: bigint;\n /** When a human confirmation is requested. */\n confirm: ConfirmPolicy;\n /** Creators (handle or 0x-address, lowercased) auto-payment is restricted to.\n * Empty = no restriction. A non-empty list is a hard gate: a non-member is\n * denied even with `--yes`. */\n allowlistCreators: string[];\n}\n\nexport interface SpendRequest {\n amountAtomic: bigint;\n /** Creator identity from the 402 preview / candidate, handle or 0x address. */\n creator: string;\n /** The caller's `--max-price` cap, if given. A hard ceiling, never bypassable. */\n maxPriceAtomic?: bigint;\n /** Cumulative spend already recorded in this rolling session window. */\n sessionSpentAtomic: bigint;\n}\n\n/**\n * `allow`: within policy, proceed silently. `confirm`: an approval is required ,\n * the caller satisfies it with `--yes`, an interactive prompt, or refuses. `deny`:\n * a hard gate blocked it (price cap, allowlist, session budget); NOT satisfiable\n * by `--yes` or a prompt.\n */\nexport type SpendDecision = 'allow' | 'confirm' | 'deny';\n\n/**\n * `duplicate_in_flight` is the one reason this pure evaluator never returns: it\n * is a fact about the ledger (an identical request already holds a reservation\n * in this turn), so the authorizer raises it. It lives in the union because\n * every caller renders a decision's reason from one vocabulary.\n */\nexport type PolicyReason =\n | 'within_policy'\n | 'duplicate_in_flight'\n | 'price_cap_exceeded'\n | 'not_allowlisted'\n | 'session_budget_exceeded'\n | 'above_auto_spend'\n | 'confirm_always'\n | 'above_confirm_threshold';\n\nexport interface PolicyEvaluation {\n decision: SpendDecision;\n reason: PolicyReason;\n message: string;\n}\n\n/** Normalize a creator identity for allowlist comparison (case-insensitive; a\n * word-handle and a 0x address are both single tokens). */\nfunction normCreator(value: string): string {\n return value.trim().toLowerCase();\n}\n\n/**\n * Evaluate one spend against the policy. Hard gates run first (price cap →\n * allowlist → session budget); only if all pass is the confirm gate consulted. A\n * spend at or below `maxAutoSpend` that the confirm policy would not prompt for is\n * the only `allow`; everything else within the hard gates is `confirm`.\n */\nexport function evaluateSpendPolicy(policy: SpendPolicy, req: SpendRequest): PolicyEvaluation {\n if (req.maxPriceAtomic !== undefined && req.amountAtomic > req.maxPriceAtomic) {\n return {\n decision: 'deny',\n reason: 'price_cap_exceeded',\n message: `Price ${req.amountAtomic} exceeds the --max-price cap ${req.maxPriceAtomic}.`,\n };\n }\n\n if (policy.allowlistCreators.length > 0) {\n const allowed = policy.allowlistCreators.map(normCreator);\n if (!allowed.includes(normCreator(req.creator))) {\n return {\n decision: 'deny',\n reason: 'not_allowlisted',\n message: `Creator \"${req.creator}\" is not in allowlistCreators.`,\n };\n }\n }\n\n if (policy.sessionBudgetAtomic > 0n) {\n const projected = req.sessionSpentAtomic + req.amountAtomic;\n if (projected > policy.sessionBudgetAtomic) {\n return {\n decision: 'deny',\n reason: 'session_budget_exceeded',\n message: `This spend would bring the session total to ${projected}, over sessionBudget ${policy.sessionBudgetAtomic}.`,\n };\n }\n }\n\n if (req.amountAtomic > policy.maxAutoSpendAtomic) {\n return {\n decision: 'confirm',\n reason: 'above_auto_spend',\n message: `Price ${req.amountAtomic} is above maxAutoSpend ${policy.maxAutoSpendAtomic}; confirmation required.`,\n };\n }\n\n if (policy.confirm.mode === 'always') {\n return {\n decision: 'confirm',\n reason: 'confirm_always',\n message: 'confirm policy is \"always\"; confirmation required.',\n };\n }\n\n if (req.amountAtomic > policy.confirm.thresholdAtomic) {\n return {\n decision: 'confirm',\n reason: 'above_confirm_threshold',\n message: `Price ${req.amountAtomic} is above the confirm threshold ${policy.confirm.thresholdAtomic}; confirmation required.`,\n };\n }\n\n return { decision: 'allow', reason: 'within_policy', message: 'within spend policy' };\n}\n\n/** Parse the stored `confirm` config value (\"always\" | \"above:<atomic>\"). */\nexport function parseConfirmPolicy(stored: string): ConfirmPolicy {\n if (stored === 'always') return { mode: 'always' };\n const m = /^above:(\\d+)$/.exec(stored);\n if (m && m[1] !== undefined) return { mode: 'above', thresholdAtomic: BigInt(m[1]) };\n // The config schema already constrains this; a malformed value here is a bug,\n // so fail closed to the safest interpretation rather than throwing mid-buy.\n return { mode: 'always' };\n}\n"],"mappings":";;;;;;AAKA,IAAM,gBAAgB;AAQf,SAAS,iBAAiB,OAAuB;AACtD,QAAM,UAAU,MAAM,KAAK;AAC3B,MAAI,CAAC,gBAAgB,KAAK,OAAO,GAAG;AAClC,UAAM,IAAI,SAAS,SAAS,uBAAuB,KAAK,UAAU,KAAK,CAAC,IAAI;AAAA,MAC1E,KAAK;AAAA,IACP,CAAC;AAAA,EACH;AACA,QAAM,CAAC,OAAO,OAAO,EAAE,IAAI,QAAQ,MAAM,GAAG;AAC5C,MAAI,KAAK,SAAS,eAAe;AAC/B,UAAM,IAAI;AAAA,MACR;AAAA,MACA,cAAc,KAAK,UAAU,KAAK,CAAC;AAAA,MACnC;AAAA,QACE,KAAK;AAAA,MACP;AAAA,IACF;AAAA,EACF;AACA,QAAM,SAAS,OAAO,GAAG,KAAK,GAAG,KAAK,OAAO,eAAe,GAAG,CAAC,EAAE;AAClE,SAAO,OAAO,SAAS;AACzB;AAQO,SAAS,YAAY,QAAwB;AAClD,QAAM,UA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B,OAAO,mBAAmB;AAAA,MACrH;AAAA,IACF;AAAA,EACF;AAEA,MAAI,IAAI,eAAe,OAAO,oBAAoB;AAChD,WAAO;AAAA,MACL,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,SAAS,SAAS,IAAI,YAAY,0BAA0B,OAAO,kBAAkB;AAAA,IACvF;AAAA,EACF;AAEA,MAAI,OAAO,QAAQ,SAAS,UAAU;AACpC,WAAO;AAAA,MACL,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,SAAS;AAAA,IACX;AAAA,EACF;AAEA,MAAI,IAAI,eAAe,OAAO,QAAQ,iBAAiB;AACrD,WAAO;AAAA,MACL,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,SAAS,SAAS,IAAI,YAAY,mCAAmC,OAAO,QAAQ,eAAe;AAAA,IACrG;AAAA,EACF;AAEA,SAAO,EAAE,UAAU,SAAS,QAAQ,iBAAiB,SAAS,sBAAsB;AACtF;AAGO,SAAS,mBAAmB,QAA+B;AAChE,MAAI,WAAW,SAAU,QAAO,EAAE,MAAM,SAAS;AACjD,QAAM,IAAI,gBAAgB,KAAK,MAAM;AACrC,MAAI,KAAK,EAAE,CAAC,MAAM,OAAW,QAAO,EAAE,MAAM,SAAS,iBAAiB,OAAO,EAAE,CAAC,CAAC,EAAE;AAGnF,SAAO,EAAE,MAAM,SAAS;AAC1B;","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
|
external_exports
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-AR7U7BRG.js";
|
|
5
5
|
import {
|
|
6
6
|
CliError
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-JLEF5WHM.js";
|
|
8
8
|
|
|
9
9
|
// src/lib/output.ts
|
|
10
10
|
import { styleText } from "node:util";
|
|
@@ -228,4 +228,4 @@ export {
|
|
|
228
228
|
sanitizeForTerminal,
|
|
229
229
|
paint
|
|
230
230
|
};
|
|
231
|
-
//# sourceMappingURL=chunk-
|
|
231
|
+
//# sourceMappingURL=chunk-WLMJE3GJ.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
hasCode
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-2I4QTOLB.js";
|
|
5
5
|
import {
|
|
6
6
|
CliError
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-JLEF5WHM.js";
|
|
8
8
|
|
|
9
9
|
// src/lib/skills-source.ts
|
|
10
10
|
import { existsSync } from "node:fs";
|
|
@@ -134,4 +134,4 @@ export {
|
|
|
134
134
|
readSkillFile,
|
|
135
135
|
skillFrontmatterName
|
|
136
136
|
};
|
|
137
|
-
//# sourceMappingURL=chunk-
|
|
137
|
+
//# sourceMappingURL=chunk-WS4JA6TC.js.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
PRODUCTION_ORIGIN
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-AR7U7BRG.js";
|
|
5
5
|
import {
|
|
6
6
|
package_default
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-NRQMOVKM.js";
|
|
8
8
|
import {
|
|
9
9
|
CliError
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-JLEF5WHM.js";
|
|
11
11
|
|
|
12
12
|
// src/lib/client-meta.ts
|
|
13
13
|
var TENJIN_PRODUCT = `tenjin-cli/${package_default.version}`;
|
|
@@ -224,4 +224,4 @@ export {
|
|
|
224
224
|
httpRequest,
|
|
225
225
|
fetchFailureToCliError
|
|
226
226
|
};
|
|
227
|
-
//# sourceMappingURL=chunk-
|
|
227
|
+
//# sourceMappingURL=chunk-WUHY2AXD.js.map
|
|
@@ -2,10 +2,10 @@ import { createRequire as __tenjinCreateRequire } from 'node:module'; const requ
|
|
|
2
2
|
import {
|
|
3
3
|
fetchFailureToCliError,
|
|
4
4
|
httpRequest
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-WUHY2AXD.js";
|
|
6
6
|
import {
|
|
7
7
|
external_exports
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-AR7U7BRG.js";
|
|
9
9
|
|
|
10
10
|
// src/router/decision.ts
|
|
11
11
|
var ROUTER_PATH = "/api/x402-router";
|
|
@@ -41,8 +41,8 @@ var CapabilityFields = {
|
|
|
41
41
|
/** The service's own name, not the x402 reseller in front of it. */
|
|
42
42
|
provider: external_exports.string().min(1).max(120),
|
|
43
43
|
capabilityDescription: external_exports.string().min(1).max(500),
|
|
44
|
-
/** What the provider charges, atomic USDC.
|
|
45
|
-
*
|
|
44
|
+
/** What the provider charges, atomic USDC. The `request` tool refuses a live
|
|
45
|
+
* 402 above it; `gateSpend` still caps the amount actually signed. */
|
|
46
46
|
providerPriceAtomic: external_exports.string().regex(/^\d+$/)
|
|
47
47
|
};
|
|
48
48
|
var HookDecisionSchema = external_exports.discriminatedUnion("action", [
|
|
@@ -162,4 +162,4 @@ export {
|
|
|
162
162
|
ROUTER_PATH,
|
|
163
163
|
requestDecision
|
|
164
164
|
};
|
|
165
|
-
//# sourceMappingURL=chunk-
|
|
165
|
+
//# sourceMappingURL=chunk-YPQSMIDH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/router/decision.ts"],"sourcesContent":["import { z } from 'zod';\nimport { fetchFailureToCliError, httpRequest } from '../lib/http';\nimport type { HttpRequestOptions, HttpResult } from '../lib/http';\nimport type { CommandContext } from '../context';\nimport type { Packet } from './context';\n\n/**\n * `POST /api/x402-router`: ONE FREE DECISION PER LOOKUP.\n *\n * The routing decision costs nothing and nobody signs for it. The hook asks for\n * it from the user's own words, the backend answers with what it would do and\n * what the provider charges, and the only payment on the wire is the one\n * `runPay` makes to that provider. That deletes the router fee and everything\n * built to carry it: the 402 probe, the requirements cache, the stale-quote\n * retry, the settlement accounting and one Base settlement of about 1.5 s from\n * every paid lookup.\n *\n * NOTHING IS STORED LOCALLY. The bounded packet travels with the request and\n * the backend keeps it against the decision id until that id expires, which is\n * how `request({query})` reaches the same calibrated input with no session\n * file, no timestamp latch and no guess about which window this process serves.\n */\n\nexport const ROUTER_PATH = '/api/x402-router';\n\n/**\n * The request the server builds and this client sends verbatim. Query assembly,\n * body encoding and header choice are the server's; what stays here is every\n * check that decides whether to send it at all.\n */\nconst RequestSchema = z.object({\n url: z.string().min(1).max(16_384),\n method: z.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']),\n headers: z.record(z.string(), z.string()),\n body: z\n .string()\n .max(256 * 1024)\n .optional(),\n});\n\nconst ContractSchema = z.object({\n /** Flat, for display and for the result check; never re-encoded into a call:\n * the server built `request` from them and this client sends that verbatim. */\n arguments: z.record(z.string(), z.unknown()).optional(),\n resultSchema: z.record(z.string(), z.unknown()).optional(),\n request: RequestSchema,\n});\nexport type DecisionContract = z.infer<typeof ContractSchema>;\n\n/**\n * What stopped an outcome this client cannot execute, in terms the host can act\n * on: a stable reason code, the stage that stopped, the fields or scope choices\n * the user can supply, and one concrete next action.\n */\nconst DiagnosticsSchema = z.object({\n reasonCode: z.string().min(1).max(64),\n stage: z.string().min(1).max(32),\n missing: z.array(z.string().max(200)).max(60),\n nextAction: z.string().max(500),\n});\nexport type DecisionDiagnostics = z.infer<typeof DiagnosticsSchema>;\n\n/**\n * ONE VARIANT PER ANSWER, DISCRIMINATED ON THE ACTION. Optional fields made\n * every shape legal: an `execute` with no contract parsed and came back to the\n * host as a routine `needs_input`, a non-execute with no diagnostics parsed\n * with nothing to act on, and a hook answer carrying a contract parsed as\n * though the hook had quoted a price. Each of those is drift the shared\n * fixtures exist to catch, so each is now a parse failure that names itself.\n *\n * The two calls ask different questions and get different answers, so they get\n * different parsers. The HOOK asks whether a paid lookup is worth offering: an\n * id, or a reason it is not. The TOOL asks for the decision: the capability,\n * its price and the contract together, so a caller cannot approve one offer and\n * receive another.\n */\nconst IdSchema = z\n .string()\n .regex(/^[A-Za-z0-9_-]{8,64}$/)\n .describe(\n 'The turn id, an OPAQUE HANDLE: it is the one piece of server text this ' +\n 'client puts in a model-facing line, so the alphabet is pinned here ' +\n 'rather than escaped later.',\n );\n\n/** Every non-execute answer carries these, beside the action they explain. */\nconst RefusedSchema = z.strictObject({\n reason: z.string().max(2_000).optional(),\n diagnostics: DiagnosticsSchema,\n});\n\n/**\n * WHAT THE SERVICE IS, AND WHAT IT DOES. The hook answer used to be an id and\n * nothing else, so the line the host injected could only say \"a paid lookup is\n * available\", which a model follows 8 to 20 times in 40 where a line naming the\n * task and the service is followed 40 in 40. The gate knows which capability\n * serves the category it chose, so it now says so; the CONTRACT is still not\n * here, because the task the host will run does not exist yet.\n */\nconst CapabilityFields = {\n capabilityId: z.string().min(1).max(200),\n category: z.string().min(1).max(64),\n /** The service's own name, not the x402 reseller in front of it. */\n provider: z.string().min(1).max(120),\n capabilityDescription: z.string().min(1).max(500),\n /** What the provider charges, atomic USDC. The `request` tool refuses a live\n * 402 above it; `gateSpend` still caps the amount actually signed. */\n providerPriceAtomic: z.string().regex(/^\\d+$/),\n};\n\nconst HookDecisionSchema = z.discriminatedUnion('action', [\n z\n .strictObject({\n action: z.literal('execute'),\n id: IdSchema,\n ...CapabilityFields,\n /** The x402 URL a lookup would pay, for the line the server writes. */\n endpoint: z.string().min(1).max(2_048),\n /** What to pass in `query`, in the service's own terms. */\n usage: z.string().min(1).max(300),\n /**\n * THE LINE, FINISHED. The server writes it with the real id in it and, on a\n * native call, the exact search or URL that was denied. The client injects\n * it and composes nothing, which is why there is no hint builder here any\n * more: two sides writing the same sentence is how they drift.\n */\n hint: z.string().min(1).max(1_000),\n })\n .superRefine((decision, ctx) => {\n // STRUCTURE, NEVER WORDING. This line lands in the model's context\n // verbatim, so the shape is checked the way the id's alphabet is: one\n // line, no control characters, and it has to be the call it claims to be,\n // naming the id this same answer carries. A hint that fails any of these\n // is a protocol error and the turn falls back to the generic line; nothing\n // here rewrites a word of a hint that passes.\n if (/[\\p{Cc}\\p{Cf}]/u.test(decision.hint)) {\n ctx.addIssue({ code: 'custom', path: ['hint'], message: 'a hint is one plain line' });\n }\n if (!decision.hint.includes('request({')) {\n ctx.addIssue({ code: 'custom', path: ['hint'], message: 'a hint names the call to make' });\n }\n if (!decision.hint.includes(decision.id)) {\n ctx.addIssue({\n code: 'custom',\n path: ['hint'],\n message: \"a hint carries this answer's own id\",\n });\n }\n }),\n RefusedSchema.extend({ action: z.literal('native') }),\n RefusedSchema.extend({ action: z.literal('needs_input') }),\n]);\n\nconst ToolDecisionSchema = z.discriminatedUnion('action', [\n z.strictObject({\n action: z.literal('execute'),\n ...CapabilityFields,\n contract: ContractSchema,\n }),\n RefusedSchema.extend({ action: z.literal('native') }),\n RefusedSchema.extend({ action: z.literal('needs_input') }),\n]);\n\nfunction envelope<T extends z.ZodTypeAny>(decision: T) {\n return z.strictObject({\n schemaVersion: z.literal(1),\n routerVersion: z.string().min(1).max(64),\n decision,\n /** A plain sentence about the CALL, such as an id that had expired. Never a\n * failure: the decision beside it ran anyway. */\n note: z.string().max(500).optional(),\n jev: z.object({ calls: z.number(), latencyMs: z.number() }).optional(),\n });\n}\n\nconst HookResponseSchema = envelope(HookDecisionSchema);\nconst ToolResponseSchema = envelope(ToolDecisionSchema);\n\nexport type HookResponse = z.infer<typeof HookResponseSchema>;\nexport type ToolResponse = z.infer<typeof ToolResponseSchema>;\nexport type HookDecision = HookResponse['decision'];\nexport type ToolDecision = ToolResponse['decision'];\n\n/** Which call this is, and therefore which answer is legal for it. */\nexport type CallKind = 'hook' | 'tool';\n\n/**\n * The exact body the hook call sends, spelled once and pinned to the shared\n * fixtures. The route reads it with a strict object, so an extra field is a\n * 400, and a 400 is a turn with no hint.\n *\n * ONE BODY FOR BOTH HOOKS. Which hook is asking is not a field: the route reads\n * it from `packet.pendingCall`, which the native hook sets and the prompt hook\n * does not. A `source` beside the packet was the `/prepare` route's shape, and\n * that route is gone.\n */\nexport function buildHookBody(packet: Packet): Record<string, unknown> {\n return { schemaVersion: 1, packet };\n}\n\n/** The exact body the tool call sends. `id` is the turn whose packet decides\n * with this query; `gateHint` is evidence, never authority. */\nexport function buildToolBody(request: {\n query: string;\n id?: string;\n gateHint?: GateHint;\n}): Record<string, unknown> {\n return {\n schemaVersion: 1,\n query: request.query,\n ...(request.id !== undefined ? { id: request.id } : {}),\n ...(request.gateHint !== undefined ? { gateHint: request.gateHint } : {}),\n };\n}\n\n/** The parsers, exposed so the shared wire fixtures are checked against the\n * same schemas production parses with rather than against a copy of them. */\nexport function parseForTests(kind: CallKind, value: unknown): { success: boolean } {\n const schema = kind === 'hook' ? HookResponseSchema : ToolResponseSchema;\n return { success: schema.safeParse(value).success };\n}\n\n/**\n * The gate's own reading of this turn, travelling as EVIDENCE for the lookup it\n * was produced for. The backend may refine or reject it, and it authorizes no\n * money: the local spend policy does that. Optional on both call forms.\n */\nexport interface GateHint {\n category: string;\n turnId: string;\n lookupId: string;\n}\n\nexport interface DecisionDeps {\n ctx: CommandContext;\n baseUrl: string;\n fetchImpl?: typeof fetch;\n /** Overrides the per-call deadline; the hook passes its own, smaller one. */\n timeoutMs?: number;\n}\n\nexport type DecisionOutcome<T> =\n | { status: 'decided'; decision: T }\n /** Nothing was paid and nothing could be: the endpoint is free, so a failure\n * here costs the turn a routing answer and nothing else. */\n | { status: 'failed'; reason: string; errorCode?: string };\n\n/**\n * ONE FREE CALL, IN TWO FORMS. The hook sends `{ packet }`: the backend runs\n * the gate, and on `execute` stores that packet under an id. The tool sends\n * `{ query, id? }`: the backend makes THE decision from that query plus the\n * packet it stored, and answers with the contract to run.\n *\n * The tool never sends a packet of its own. The turn's context lives on the\n * backend against the id, and the query the model wrote is what the routing\n * corpus is calibrated against: 55 of 56 for query plus packet, 53 of 56 for\n * the raw prompt, measured on jev-1.13.0.\n */\nexport async function requestDecision(\n kind: 'hook',\n request: { packet: Packet },\n deps: DecisionDeps,\n): Promise<DecisionOutcome<HookResponse>>;\nexport async function requestDecision(\n kind: 'tool',\n request: { query: string; id?: string; gateHint?: GateHint },\n deps: DecisionDeps,\n): Promise<DecisionOutcome<ToolResponse>>;\nexport async function requestDecision(\n kind: CallKind,\n request: {\n query?: string;\n packet?: Packet;\n id?: string;\n gateHint?: GateHint;\n },\n deps: DecisionDeps,\n): Promise<DecisionOutcome<HookResponse | ToolResponse>> {\n const url = new URL(ROUTER_PATH, deps.baseUrl).toString();\n const options: HttpRequestOptions = {\n method: 'POST',\n timeoutMs: deps.timeoutMs ?? deps.ctx.flags.timeout,\n blockRedirects: true,\n jsonBody:\n kind === 'hook'\n ? buildHookBody(request.packet as Packet)\n : buildToolBody({\n query: request.query as string,\n ...(request.id !== undefined ? { id: request.id } : {}),\n ...(request.gateHint !== undefined ? { gateHint: request.gateHint } : {}),\n }),\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n };\n return readDecision(\n await httpRequest(url, options),\n kind === 'hook' ? HookResponseSchema : ToolResponseSchema,\n );\n}\n\nfunction readDecision<T extends z.ZodTypeAny>(\n response: HttpResult,\n schema: T,\n): DecisionOutcome<z.infer<T>> {\n // A transport failure says its own reason; nothing was paid either way,\n // because there is nothing to pay for on this route.\n if (!response.ok) return { status: 'failed', reason: fetchFailureToCliError(response).message };\n if (response.status < 200 || response.status >= 300) {\n const named = errorOf(response.json);\n return {\n status: 'failed',\n // The backend's own code and message, never a bare status line: a typed\n // refusal the host could act on was arriving as \"answered 400\".\n reason:\n named === null\n ? `The router endpoint answered ${response.status}.`\n : `The router endpoint answered ${response.status} (${named.code}): ${named.message}`,\n ...(named !== null ? { errorCode: named.code } : {}),\n };\n }\n const parsed = schema.safeParse(response.json);\n if (!parsed.success) {\n return { status: 'failed', reason: 'The router returned a decision this build cannot read.' };\n }\n return { status: 'decided', decision: parsed.data as z.infer<T> };\n}\n\n/** `{ error: { code, message } }`, the envelope every Tenjin route answers a\n * refusal with. Anything else reads as no code rather than as a guess. */\nfunction errorOf(body: unknown): { code: string; message: string } | null {\n if (body === null || typeof body !== 'object') return null;\n const error = (body as { error?: unknown }).error;\n if (error === null || typeof error !== 'object') return null;\n const { code, message } = error as { code?: unknown; message?: unknown };\n if (typeof code !== 'string' || code.length === 0 || code.length > 64) return null;\n const text = typeof message === 'string' ? message.slice(0, 500) : '';\n return { code, message: text };\n}\n"],"mappings":";;;;;;;;;;AAuBO,IAAM,cAAc;AAO3B,IAAM,gBAAgB,iBAAE,OAAO;AAAA,EAC7B,KAAK,iBAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,KAAM;AAAA,EACjC,QAAQ,iBAAE,KAAK,CAAC,OAAO,QAAQ,OAAO,SAAS,UAAU,QAAQ,SAAS,CAAC;AAAA,EAC3E,SAAS,iBAAE,OAAO,iBAAE,OAAO,GAAG,iBAAE,OAAO,CAAC;AAAA,EACxC,MAAM,iBACH,OAAO,EACP,IAAI,MAAM,IAAI,EACd,SAAS;AACd,CAAC;AAED,IAAM,iBAAiB,iBAAE,OAAO;AAAA;AAAA;AAAA,EAG9B,WAAW,iBAAE,OAAO,iBAAE,OAAO,GAAG,iBAAE,QAAQ,CAAC,EAAE,SAAS;AAAA,EACtD,cAAc,iBAAE,OAAO,iBAAE,OAAO,GAAG,iBAAE,QAAQ,CAAC,EAAE,SAAS;AAAA,EACzD,SAAS;AACX,CAAC;AAQD,IAAM,oBAAoB,iBAAE,OAAO;AAAA,EACjC,YAAY,iBAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE;AAAA,EACpC,OAAO,iBAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE;AAAA,EAC/B,SAAS,iBAAE,MAA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AAAA,MAGR,QACE,UAAU,OACN,gCAAgC,SAAS,MAAM,MAC/C,gCAAgC,SAAS,MAAM,KAAK,MAAM,IAAI,MAAM,MAAM,OAAO;AAAA,MACvF,GAAI,UAAU,OAAO,EAAE,WAAW,MAAM,KAAK,IAAI,CAAC;AAAA,IACpD;AAAA,EACF;AACA,QAAM,SAAS,OAAO,UAAU,SAAS,IAAI;AAC7C,MAAI,CAAC,OAAO,SAAS;AACnB,WAAO,EAAE,QAAQ,UAAU,QAAQ,yDAAyD;AAAA,EAC9F;AACA,SAAO,EAAE,QAAQ,WAAW,UAAU,OAAO,KAAmB;AAClE;AAIA,SAAS,QAAQ,MAAyD;AACxE,MAAI,SAAS,QAAQ,OAAO,SAAS,SAAU,QAAO;AACtD,QAAM,QAAS,KAA6B;AAC5C,MAAI,UAAU,QAAQ,OAAO,UAAU,SAAU,QAAO;AACxD,QAAM,EAAE,MAAM,QAAQ,IAAI;AAC1B,MAAI,OAAO,SAAS,YAAY,KAAK,WAAW,KAAK,KAAK,SAAS,GAAI,QAAO;AAC9E,QAAM,OAAO,OAAO,YAAY,WAAW,QAAQ,MAAM,GAAG,GAAG,IAAI;AACnE,SAAO,EAAE,MAAM,SAAS,KAAK;AAC/B;","names":[]}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
emitNotice
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-WLMJE3GJ.js";
|
|
5
5
|
import {
|
|
6
6
|
external_exports,
|
|
7
7
|
loadConfig
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-AR7U7BRG.js";
|
|
9
9
|
import {
|
|
10
10
|
package_default
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-NRQMOVKM.js";
|
|
12
|
+
import {
|
|
13
|
+
writeFileAtomic
|
|
14
|
+
} from "./chunk-JLEF5WHM.js";
|
|
12
15
|
import {
|
|
13
16
|
updateCheckPath
|
|
14
17
|
} from "./chunk-2BKS2FVE.js";
|
|
15
|
-
import {
|
|
16
|
-
writeFileAtomic
|
|
17
|
-
} from "./chunk-7WEQQJLG.js";
|
|
18
18
|
|
|
19
19
|
// src/lib/update-check.ts
|
|
20
20
|
import { readFile } from "node:fs/promises";
|
|
@@ -191,4 +191,4 @@ export {
|
|
|
191
191
|
fetchDistTags,
|
|
192
192
|
isNewer
|
|
193
193
|
};
|
|
194
|
-
//# sourceMappingURL=chunk-
|
|
194
|
+
//# sourceMappingURL=chunk-ZG7SFI34.js.map
|
|
@@ -2,28 +2,27 @@ import { createRequire as __tenjinCreateRequire } from 'node:module'; const requ
|
|
|
2
2
|
import {
|
|
3
3
|
maybeUpdate,
|
|
4
4
|
readUpdateSignal
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-ZG7SFI34.js";
|
|
6
6
|
import {
|
|
7
7
|
defaultIo,
|
|
8
8
|
emitFailure,
|
|
9
9
|
emitSuccess
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-WLMJE3GJ.js";
|
|
11
11
|
import {
|
|
12
12
|
PERMISSIONS_DOC_URL
|
|
13
13
|
} from "./chunk-WXC57XGG.js";
|
|
14
14
|
import {
|
|
15
15
|
external_exports
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-AR7U7BRG.js";
|
|
17
17
|
import {
|
|
18
18
|
package_default
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-NRQMOVKM.js";
|
|
20
20
|
import {
|
|
21
21
|
CliError
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-JLEF5WHM.js";
|
|
23
23
|
import {
|
|
24
24
|
dataDir
|
|
25
25
|
} from "./chunk-2BKS2FVE.js";
|
|
26
|
-
import "./chunk-7WEQQJLG.js";
|
|
27
26
|
import {
|
|
28
27
|
__commonJS,
|
|
29
28
|
__require,
|
|
@@ -3489,7 +3488,7 @@ var INTEGRATION = "Integration:";
|
|
|
3489
3488
|
function registerCore(reg) {
|
|
3490
3489
|
const { runCommand, leaf: leaf2, addGlobalFlags: addGlobalFlags2 } = reg;
|
|
3491
3490
|
leaf2(SETUP, "install", "set up Tenjin for Claude Code and create a wallet").description(
|
|
3492
|
-
"Set up Claude Code to use Tenjin:
|
|
3491
|
+
"Set up Claude Code to use Tenjin: five hook entries, the `x402` MCP server and its permission rule, spend limits for each lookup, and a wallet if this machine has none."
|
|
3493
3492
|
).option("--project", "write into this project's .claude/settings.json instead of your home one").option("--no-wallet", "create no wallet").option("--refresh", "re-register the hook entries this machine already has; add nothing").option(
|
|
3494
3493
|
"--status-line <mode>",
|
|
3495
3494
|
"the live footer: `own` registers it when you have no status line of your own, `compose` appends it to the one you do have, `skip` leaves the setting alone"
|
|
@@ -3507,8 +3506,8 @@ Learn more:
|
|
|
3507
3506
|
).action(async function() {
|
|
3508
3507
|
await runCommand("install", this, async (ctx) => {
|
|
3509
3508
|
const o = this.opts();
|
|
3510
|
-
const { runRouterInstall } = await import("./install-
|
|
3511
|
-
const { statusLineMode } = await import("./status-line-wiring-
|
|
3509
|
+
const { runRouterInstall } = await import("./install-NUQLLHS2.js");
|
|
3510
|
+
const { statusLineMode } = await import("./status-line-wiring-DQZCWIUO.js");
|
|
3512
3511
|
return runRouterInstall(
|
|
3513
3512
|
{
|
|
3514
3513
|
...o.project === true ? { project: true } : {},
|
|
@@ -3525,7 +3524,7 @@ Learn more:
|
|
|
3525
3524
|
).option("--project", "remove from this project's .claude/settings.json").action(async function() {
|
|
3526
3525
|
await runCommand("uninstall", this, async (ctx) => {
|
|
3527
3526
|
const o = this.opts();
|
|
3528
|
-
const { runRouterUninstall } = await import("./uninstall-
|
|
3527
|
+
const { runRouterUninstall } = await import("./uninstall-SWICHBTF.js");
|
|
3529
3528
|
return runRouterUninstall({ ...o.project === true ? { project: true } : {} }, ctx);
|
|
3530
3529
|
});
|
|
3531
3530
|
});
|
|
@@ -3541,7 +3540,7 @@ Examples:
|
|
|
3541
3540
|
`
|
|
3542
3541
|
).action(async function() {
|
|
3543
3542
|
await runCommand("doctor", this, async (ctx) => {
|
|
3544
|
-
const { runRouterDoctor } = await import("./doctor-
|
|
3543
|
+
const { runRouterDoctor } = await import("./doctor-KJROWE5V.js");
|
|
3545
3544
|
return runRouterDoctor(ctx, this.opts().project === true ? { project: true } : {});
|
|
3546
3545
|
});
|
|
3547
3546
|
});
|
|
@@ -3549,7 +3548,7 @@ Examples:
|
|
|
3549
3548
|
"Update tenjin-cli to the newest version npm publishes on the latest tag. It then runs `install --refresh` on the new binary, so every profile on this machine gets the skills and hook scripts of the build that just landed."
|
|
3550
3549
|
).option("--check", "report whether a newer version exists without installing it").action(async function() {
|
|
3551
3550
|
await runCommand("update", this, async (ctx) => {
|
|
3552
|
-
const { runUpdate } = await import("./update-
|
|
3551
|
+
const { runUpdate } = await import("./update-W572AMXG.js");
|
|
3553
3552
|
return runUpdate({ check: this.opts().check === true }, ctx);
|
|
3554
3553
|
});
|
|
3555
3554
|
});
|
|
@@ -3563,11 +3562,12 @@ Examples:
|
|
|
3563
3562
|
$ tenjin config
|
|
3564
3563
|
$ tenjin config set publish.mode review
|
|
3565
3564
|
$ tenjin config set maxAutoSpend 0.25
|
|
3565
|
+
$ tenjin config set --project router.enabled false
|
|
3566
3566
|
`
|
|
3567
3567
|
);
|
|
3568
3568
|
config.action(async function() {
|
|
3569
3569
|
await runCommand("config", this, async (ctx) => {
|
|
3570
|
-
const { runConfigList } = await import("./config-
|
|
3570
|
+
const { runConfigList } = await import("./config-BJK6U5VY.js");
|
|
3571
3571
|
return runConfigList(ctx);
|
|
3572
3572
|
});
|
|
3573
3573
|
});
|
|
@@ -3575,16 +3575,23 @@ Examples:
|
|
|
3575
3575
|
"Print one effective config value by key. The effective value is what the command would use, defaults and environment overrides included."
|
|
3576
3576
|
).action(async function(key) {
|
|
3577
3577
|
await runCommand("config.get", this, async (ctx) => {
|
|
3578
|
-
const { runConfigGet } = await import("./config-
|
|
3578
|
+
const { runConfigGet } = await import("./config-BJK6U5VY.js");
|
|
3579
3579
|
return runConfigGet({ key }, ctx);
|
|
3580
3580
|
});
|
|
3581
3581
|
});
|
|
3582
3582
|
addGlobalFlags2(config.command("set <key> <value>")).summary("set a config value").description(
|
|
3583
3583
|
"Write one config value, validated against the key it is for. Spend keys take decimal USD."
|
|
3584
|
-
).
|
|
3584
|
+
).option(
|
|
3585
|
+
"--project",
|
|
3586
|
+
"write a router key into this project's .tenjin/config.json, which is committed"
|
|
3587
|
+
).option("--local", "with --project, write .tenjin/config.local.json instead, which is yours").action(async function(key, value) {
|
|
3588
|
+
const o = this.opts();
|
|
3585
3589
|
await runCommand("config.set", this, async (ctx) => {
|
|
3586
|
-
const { runConfigSet } = await import("./config-
|
|
3587
|
-
return runConfigSet(
|
|
3590
|
+
const { runConfigSet } = await import("./config-BJK6U5VY.js");
|
|
3591
|
+
return runConfigSet(
|
|
3592
|
+
{ key, value, project: o.project === true, local: o.local === true },
|
|
3593
|
+
ctx
|
|
3594
|
+
);
|
|
3588
3595
|
});
|
|
3589
3596
|
});
|
|
3590
3597
|
const wallet = leaf2(
|
|
@@ -3602,7 +3609,7 @@ Examples:
|
|
|
3602
3609
|
).action(async function() {
|
|
3603
3610
|
await runCommand("wallet.create", this, async (ctx) => {
|
|
3604
3611
|
const o = this.opts();
|
|
3605
|
-
const { runWalletCreate } = await import("./wallet-
|
|
3612
|
+
const { runWalletCreate } = await import("./wallet-L2YLAJFN.js");
|
|
3606
3613
|
return runWalletCreate(ctx, o.replace === true ? { replace: true } : {});
|
|
3607
3614
|
});
|
|
3608
3615
|
});
|
|
@@ -3610,7 +3617,7 @@ Examples:
|
|
|
3610
3617
|
"Print the active wallet address and where its key comes from. The private key is never printed, by any flag."
|
|
3611
3618
|
).action(async function() {
|
|
3612
3619
|
await runCommand("wallet.show", this, async (ctx) => {
|
|
3613
|
-
const { runWalletShow } = await import("./wallet-
|
|
3620
|
+
const { runWalletShow } = await import("./wallet-L2YLAJFN.js");
|
|
3614
3621
|
return runWalletShow(ctx);
|
|
3615
3622
|
});
|
|
3616
3623
|
});
|
|
@@ -3618,7 +3625,7 @@ Examples:
|
|
|
3618
3625
|
"Read the wallet USDC balance on Base. It is a chain read: no key is unlocked and nothing is spent."
|
|
3619
3626
|
).action(async function() {
|
|
3620
3627
|
await runCommand("wallet.balance", this, async (ctx) => {
|
|
3621
|
-
const { runWalletBalance } = await import("./wallet-
|
|
3628
|
+
const { runWalletBalance } = await import("./wallet-L2YLAJFN.js");
|
|
3622
3629
|
return runWalletBalance(ctx);
|
|
3623
3630
|
});
|
|
3624
3631
|
});
|
|
@@ -3630,7 +3637,7 @@ Examples:
|
|
|
3630
3637
|
).action(async function(amountUsd) {
|
|
3631
3638
|
await runCommand("wallet.fund", this, async (ctx) => {
|
|
3632
3639
|
const o = this.opts();
|
|
3633
|
-
const { runFund } = await import("./fund-
|
|
3640
|
+
const { runFund } = await import("./fund-I5COXPEJ.js");
|
|
3634
3641
|
return runFund(ctx, {
|
|
3635
3642
|
...amountUsd !== void 0 ? { amountUsd } : {},
|
|
3636
3643
|
...o.open === false ? { open: false } : {},
|
|
@@ -3649,7 +3656,7 @@ Examples:
|
|
|
3649
3656
|
).action(async function(amount, token, to) {
|
|
3650
3657
|
await runCommand("wallet.send", this, async (ctx) => {
|
|
3651
3658
|
const o = this.opts();
|
|
3652
|
-
const { runSend } = await import("./send-
|
|
3659
|
+
const { runSend } = await import("./send-KVUH5WDO.js");
|
|
3653
3660
|
return runSend({ amount, token, to, ...o.yes === true ? { yes: true } : {} }, ctx);
|
|
3654
3661
|
});
|
|
3655
3662
|
});
|
|
@@ -3665,7 +3672,7 @@ Examples:
|
|
|
3665
3672
|
).action(async function(url) {
|
|
3666
3673
|
await runCommand("pay", this, async (ctx) => {
|
|
3667
3674
|
const o = this.opts();
|
|
3668
|
-
const { runPay } = await import("./pay-
|
|
3675
|
+
const { runPay } = await import("./pay-WA3JSCNB.js");
|
|
3669
3676
|
return runPay(
|
|
3670
3677
|
{
|
|
3671
3678
|
url,
|
|
@@ -3689,36 +3696,43 @@ function registerRouter(reg) {
|
|
|
3689
3696
|
).helpCommand(false);
|
|
3690
3697
|
for (const [name, summary] of [
|
|
3691
3698
|
["prompt", "UserPromptSubmit: build the session packet and ask the free gate"],
|
|
3692
|
-
["native", "PreToolUse on WebSearch|WebFetch: allow the call, or redirect it"]
|
|
3699
|
+
["native", "PreToolUse on WebSearch|WebFetch: allow the call, or redirect it"],
|
|
3700
|
+
[
|
|
3701
|
+
"shortfall",
|
|
3702
|
+
"PostToolUse(Failure) on WebSearch|WebFetch: offer a paid lookup when the result came back short"
|
|
3703
|
+
],
|
|
3704
|
+
["agent", "PreToolUse on Agent|Task: append any paid offer to the subagent's task"]
|
|
3693
3705
|
]) {
|
|
3694
3706
|
addGlobalFlags2(hook.command(name)).summary(summary).action(async function() {
|
|
3695
3707
|
const ctx = buildContext2(this);
|
|
3696
|
-
const { runHookCommand } = await import("./hook-command-
|
|
3708
|
+
const { runHookCommand } = await import("./hook-command-EJO2564A.js");
|
|
3697
3709
|
await runHookCommand(name, io, {
|
|
3698
3710
|
dataDir: ctx.dataDir,
|
|
3699
3711
|
...ctx.flags.baseUrl !== void 0 ? { baseUrl: ctx.flags.baseUrl } : {}
|
|
3700
3712
|
});
|
|
3701
3713
|
});
|
|
3702
3714
|
}
|
|
3715
|
+
hook.command("unknown", { hidden: true, isDefault: true }).argument("[args...]").allowUnknownOption().allowExcessArguments().action(() => {
|
|
3716
|
+
});
|
|
3703
3717
|
leaf2(INTEGRATION, "mcp", "run the local stdio MCP server").description(
|
|
3704
3718
|
"Run the local stdio MCP server that carries the `request` tool: one paid routing decision per lookup, then the provider call, under your local spend policy. It speaks on stdin and stdout and runs until the client disconnects, so it prints no envelope of its own."
|
|
3705
3719
|
).action(async function() {
|
|
3706
3720
|
const ctx = buildContext2(this);
|
|
3707
|
-
const { runRouterMcpServer } = await import("./mcp-
|
|
3721
|
+
const { runRouterMcpServer } = await import("./mcp-I5XMVE64.js");
|
|
3708
3722
|
await runRouterMcpServer({ dataDir: ctx.dataDir, flags: ctx.flags });
|
|
3709
3723
|
});
|
|
3710
3724
|
leaf2(INTEGRATION, "status-line", "the live footer, for Claude Code's status line").description(
|
|
3711
3725
|
"Print one line naming what this session is looking up right now: the provider actually being called, its bounded parameters, and what it cost. It reads Claude Code's status event on stdin for the session identity, reads that session's own progress records, writes nothing, and prints `x402 \xB7 ready` when this session has no activity. `tenjin install` registers it; you never run it by hand."
|
|
3712
3726
|
).action(async function() {
|
|
3713
3727
|
const ctx = buildContext2(this);
|
|
3714
|
-
const { runStatusLine } = await import("./status-line-
|
|
3728
|
+
const { runStatusLine } = await import("./status-line-SAXSU6CR.js");
|
|
3715
3729
|
await runStatusLine(io, { dataDir: ctx.dataDir });
|
|
3716
3730
|
});
|
|
3717
3731
|
leaf2(SETUP, "status", "what this machine has spent, and what is still open").description(
|
|
3718
3732
|
"Report the rolling 24h spend window from spend.json: what has settled, what is reserved by a request still in flight, and the per-call and per-day caps in force."
|
|
3719
3733
|
).action(async function() {
|
|
3720
3734
|
await runCommand("status", this, async (ctx) => {
|
|
3721
|
-
const { runRouterStatus } = await import("./status-
|
|
3735
|
+
const { runRouterStatus } = await import("./status-FFC6FO72.js");
|
|
3722
3736
|
return runRouterStatus(ctx);
|
|
3723
3737
|
});
|
|
3724
3738
|
});
|
|
@@ -3867,4 +3881,4 @@ export {
|
|
|
3867
3881
|
buildProgram,
|
|
3868
3882
|
main
|
|
3869
3883
|
};
|
|
3870
|
-
//# sourceMappingURL=cli-
|
|
3884
|
+
//# sourceMappingURL=cli-MP3RAYHL.js.map
|