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
|
@@ -3,7 +3,7 @@ import { createRequire as __tenjinCreateRequire } from 'node:module'; const requ
|
|
|
3
3
|
// package.json
|
|
4
4
|
var package_default = {
|
|
5
5
|
name: "tenjin-cli",
|
|
6
|
-
version: "0.1.0-alpha.
|
|
6
|
+
version: "0.1.0-alpha.18",
|
|
7
7
|
mcpName: "blog.tenjin/tenjin",
|
|
8
8
|
type: "module",
|
|
9
9
|
description: "x402 router for coding agents: one paid decision per lookup, a local wallet that pays each provider per call in USDC on Base.",
|
|
@@ -80,4 +80,4 @@ var package_default = {
|
|
|
80
80
|
export {
|
|
81
81
|
package_default
|
|
82
82
|
};
|
|
83
|
-
//# sourceMappingURL=chunk-
|
|
83
|
+
//# sourceMappingURL=chunk-NRQMOVKM.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json"],"sourcesContent":["{\n \"name\": \"tenjin-cli\",\n \"version\": \"0.1.0-alpha.
|
|
1
|
+
{"version":3,"sources":["../package.json"],"sourcesContent":["{\n \"name\": \"tenjin-cli\",\n \"version\": \"0.1.0-alpha.18\",\n \"mcpName\": \"blog.tenjin/tenjin\",\n \"type\": \"module\",\n \"description\": \"x402 router for coding agents: one paid decision per lookup, a local wallet that pays each provider per call in USDC on Base.\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/BackTrackCo/tenjin-agent.git\"\n },\n \"homepage\": \"https://tenjin.blog/agents\",\n \"bugs\": \"https://github.com/BackTrackCo/tenjin-agent/issues\",\n \"keywords\": [\n \"x402\",\n \"usdc\",\n \"base\",\n \"ai-agents\",\n \"agent-payments\",\n \"mcp\",\n \"knowledge-marketplace\",\n \"micropayments\",\n \"claude\",\n \"codex\",\n \"cli\"\n ],\n \"bin\": {\n \"tenjin\": \"dist/index.js\"\n },\n \"engines\": {\n \"node\": \">=24\"\n },\n \"files\": [\n \"dist\",\n \"docs\",\n \"NOTICE.md\"\n ],\n \"packageManager\": \"pnpm@11.11.0\",\n \"scripts\": {\n \"build\": \"rm -rf dist && tsup\",\n \"test\": \"vitest run\",\n \"typecheck\": \"tsc --noEmit\",\n \"lint\": \"eslint .\",\n \"format\": \"prettier --write .\",\n \"format:check\": \"prettier --check .\",\n \"check\": \"pnpm run build && pnpm run test\",\n \"sync:skill\": \"node scripts/sync-skill.mjs\",\n \"pack-smoke\": \"bash scripts/pack-smoke.sh\",\n \"changeset\": \"changeset\",\n \"prepublishOnly\": \"pnpm run build\",\n \"githooks\": \"git config core.hooksPath .githooks\"\n },\n \"devDependencies\": {\n \"@changesets/cli\": \"^2.31.1\",\n \"@clack/prompts\": \"^1.7.0\",\n \"@eslint/js\": \"^10\",\n \"@modelcontextprotocol/sdk\": \"1.29.0\",\n \"@types/node\": \"^25\",\n \"@x402/core\": \"2.17.0\",\n \"@x402/evm\": \"2.17.0\",\n \"@x402/extensions\": \"2.17.0\",\n \"ajv\": \"^8.20.0\",\n \"ajv-formats\": \"^3.0.1\",\n \"commander\": \"^14.0.1\",\n \"eslint\": \"^10\",\n \"eslint-config-prettier\": \"^10\",\n \"ox\": \"0.14.30\",\n \"prettier\": \"^3\",\n \"tsup\": \"^8.5.0\",\n \"typescript\": \"^6\",\n \"typescript-eslint\": \"^8\",\n \"viem\": \"^2.53.1\",\n \"vitest\": \"^4.1.9\",\n \"zod\": \"^4.4.3\"\n }\n}\n"],"mappings":";;;AAAA;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,SAAW;AAAA,EACX,MAAQ;AAAA,EACR,aAAe;AAAA,EACf,YAAc;AAAA,IACZ,MAAQ;AAAA,IACR,KAAO;AAAA,EACT;AAAA,EACA,UAAY;AAAA,EACZ,MAAQ;AAAA,EACR,UAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,KAAO;AAAA,IACL,QAAU;AAAA,EACZ;AAAA,EACA,SAAW;AAAA,IACT,MAAQ;AAAA,EACV;AAAA,EACA,OAAS;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,gBAAkB;AAAA,EAClB,SAAW;AAAA,IACT,OAAS;AAAA,IACT,MAAQ;AAAA,IACR,WAAa;AAAA,IACb,MAAQ;AAAA,IACR,QAAU;AAAA,IACV,gBAAgB;AAAA,IAChB,OAAS;AAAA,IACT,cAAc;AAAA,IACd,cAAc;AAAA,IACd,WAAa;AAAA,IACb,gBAAkB;AAAA,IAClB,UAAY;AAAA,EACd;AAAA,EACA,iBAAmB;AAAA,IACjB,mBAAmB;AAAA,IACnB,kBAAkB;AAAA,IAClB,cAAc;AAAA,IACd,6BAA6B;AAAA,IAC7B,eAAe;AAAA,IACf,cAAc;AAAA,IACd,aAAa;AAAA,IACb,oBAAoB;AAAA,IACpB,KAAO;AAAA,IACP,eAAe;AAAA,IACf,WAAa;AAAA,IACb,QAAU;AAAA,IACV,0BAA0B;AAAA,IAC1B,IAAM;AAAA,IACN,UAAY;AAAA,IACZ,MAAQ;AAAA,IACR,YAAc;AAAA,IACd,qBAAqB;AAAA,IACrB,MAAQ;AAAA,IACR,QAAU;AAAA,IACV,KAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -9,20 +9,25 @@ import {
|
|
|
9
9
|
LockTimeoutError,
|
|
10
10
|
withFileLock
|
|
11
11
|
} from "./chunk-MEFB5KHA.js";
|
|
12
|
+
import {
|
|
13
|
+
projectRouterPath,
|
|
14
|
+
readProjectRouterFile,
|
|
15
|
+
routerSettings
|
|
16
|
+
} from "./chunk-TP4D47BY.js";
|
|
12
17
|
import {
|
|
13
18
|
detectHarnesses,
|
|
14
19
|
harnessInPlay,
|
|
15
20
|
harnessTargetDir,
|
|
16
21
|
onPath
|
|
17
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-WS4JA6TC.js";
|
|
18
23
|
import {
|
|
19
24
|
isTeamShelfOrigin,
|
|
20
25
|
loadProjectConfig
|
|
21
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-PDA2BVFY.js";
|
|
22
27
|
import {
|
|
23
28
|
parseUsdToAtomic,
|
|
24
29
|
toMoney
|
|
25
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-U2DZISAH.js";
|
|
26
31
|
import {
|
|
27
32
|
CONFIG_KEYS,
|
|
28
33
|
HOOKS_CONFIG_KEYS,
|
|
@@ -30,6 +35,8 @@ import {
|
|
|
30
35
|
PRODUCTION_ORIGIN,
|
|
31
36
|
PUBLISH_CONFIG_KEYS,
|
|
32
37
|
PublishModeSchema,
|
|
38
|
+
ROUTER_CONFIG_KEYS,
|
|
39
|
+
ROUTER_CONTEXTS,
|
|
33
40
|
RawConfigSchema,
|
|
34
41
|
SEND_MAX_UNSET,
|
|
35
42
|
TEAM_CONFIG_KEYS,
|
|
@@ -41,7 +48,7 @@ import {
|
|
|
41
48
|
parsePublicFallbackFlag,
|
|
42
49
|
parseUpdateModeFlag,
|
|
43
50
|
resolveSettings
|
|
44
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-AR7U7BRG.js";
|
|
45
52
|
import {
|
|
46
53
|
ADAPTERS,
|
|
47
54
|
MODE_GATED_RULES,
|
|
@@ -49,20 +56,19 @@ import {
|
|
|
49
56
|
registeredHooks,
|
|
50
57
|
retractModeGatedRules,
|
|
51
58
|
wireFreeVerbAllowlist
|
|
52
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-TJMCBIZU.js";
|
|
53
60
|
import {
|
|
54
|
-
CliError
|
|
55
|
-
|
|
61
|
+
CliError,
|
|
62
|
+
writeFileAtomic
|
|
63
|
+
} from "./chunk-JLEF5WHM.js";
|
|
56
64
|
import {
|
|
57
65
|
configPath
|
|
58
66
|
} from "./chunk-2BKS2FVE.js";
|
|
59
|
-
import {
|
|
60
|
-
writeFileAtomic
|
|
61
|
-
} from "./chunk-7WEQQJLG.js";
|
|
62
67
|
|
|
63
68
|
// src/commands/config.ts
|
|
64
69
|
import { mkdir } from "node:fs/promises";
|
|
65
70
|
import { homedir } from "node:os";
|
|
71
|
+
import { dirname } from "node:path";
|
|
66
72
|
import { styleText } from "node:util";
|
|
67
73
|
|
|
68
74
|
// src/lib/harness-presence.ts
|
|
@@ -89,7 +95,8 @@ var KEY_WIDTH = Math.max(
|
|
|
89
95
|
...HOOKS_CONFIG_KEYS,
|
|
90
96
|
...UPDATE_CONFIG_KEYS,
|
|
91
97
|
...LOOP_CONFIG_KEYS,
|
|
92
|
-
...TEAM_CONFIG_KEYS
|
|
98
|
+
...TEAM_CONFIG_KEYS,
|
|
99
|
+
...ROUTER_CONFIG_KEYS
|
|
93
100
|
].map((key) => key.length)
|
|
94
101
|
);
|
|
95
102
|
var KEY_DESCRIPTIONS = {
|
|
@@ -120,7 +127,9 @@ var KEY_DESCRIPTIONS = {
|
|
|
120
127
|
"loop.tool_wait_ms": "ms a hook fire may take when a tool call is waiting on it",
|
|
121
128
|
"loop.idle_exit_min": "minutes without a hook fire before the loop daemon exits",
|
|
122
129
|
"loop.port": "the loop daemon's loopback port; null derives one from the data dir (set only when doctor reports a foreign listener)",
|
|
123
|
-
"team.publicFallback": "on=a team-shelf miss falls through to the public marketplace, off=team-only (public-only lookup stages are dropped)"
|
|
130
|
+
"team.publicFallback": "on=a team-shelf miss falls through to the public marketplace, off=team-only (public-only lookup stages are dropped)",
|
|
131
|
+
"router.enabled": "false stops every router hook and the request tool; --project sets it for this repository, --project --local for you alone in it",
|
|
132
|
+
"router.context": "session=a hook packet carries up to six prior messages, turn=the current turn only; --project and --local as for router.enabled"
|
|
124
133
|
};
|
|
125
134
|
function isLoopKey(key) {
|
|
126
135
|
return LOOP_CONFIG_KEYS.includes(key);
|
|
@@ -128,6 +137,16 @@ function isLoopKey(key) {
|
|
|
128
137
|
function isTeamKey(key) {
|
|
129
138
|
return TEAM_CONFIG_KEYS.includes(key);
|
|
130
139
|
}
|
|
140
|
+
function isRouterKey(key) {
|
|
141
|
+
return ROUTER_CONFIG_KEYS.includes(key);
|
|
142
|
+
}
|
|
143
|
+
function renderRouterSetting(key, settings) {
|
|
144
|
+
const { value, source, path } = key === "router.enabled" ? settings.enabled : settings.context;
|
|
145
|
+
return { value, source, ...path !== void 0 ? { path } : {} };
|
|
146
|
+
}
|
|
147
|
+
async function resolveRouterFromContext(ctx) {
|
|
148
|
+
return routerSettings({ cwd: process.cwd(), dataDir: ctx.dataDir });
|
|
149
|
+
}
|
|
131
150
|
function renderLoopSetting(key, settings) {
|
|
132
151
|
const field = key.slice("loop.".length);
|
|
133
152
|
const { value, source } = settings.loop[field];
|
|
@@ -182,6 +201,12 @@ async function runConfigList(ctx) {
|
|
|
182
201
|
data[key] = entry;
|
|
183
202
|
humanLines.push(describedLine(key, entry));
|
|
184
203
|
}
|
|
204
|
+
const router = await resolveRouterFromContext(ctx);
|
|
205
|
+
for (const key of ROUTER_CONFIG_KEYS) {
|
|
206
|
+
const entry = renderRouterSetting(key, router);
|
|
207
|
+
data[key] = entry;
|
|
208
|
+
humanLines.push(describedLine(key, entry));
|
|
209
|
+
}
|
|
185
210
|
return { data, humanLines };
|
|
186
211
|
}
|
|
187
212
|
async function runConfigGet({ key }, ctx) {
|
|
@@ -214,12 +239,34 @@ async function runConfigGet({ key }, ctx) {
|
|
|
214
239
|
};
|
|
215
240
|
return { data: { key, ...entry2 }, humanLines: [formatLine(key, entry2)] };
|
|
216
241
|
}
|
|
242
|
+
if (isRouterKey(key)) {
|
|
243
|
+
const entry2 = renderRouterSetting(key, await resolveRouterFromContext(ctx));
|
|
244
|
+
return { data: { key, ...entry2 }, humanLines: [formatLine(key, entry2)] };
|
|
245
|
+
}
|
|
217
246
|
const configKey = assertKey(key);
|
|
218
247
|
const settings = await resolveFromContext(ctx);
|
|
219
248
|
const entry = renderSetting(configKey, settings[configKey].value, settings[configKey].source);
|
|
220
249
|
return { data: { key: configKey, ...entry }, humanLines: [formatLine(configKey, entry)] };
|
|
221
250
|
}
|
|
222
|
-
async function runConfigSet({
|
|
251
|
+
async function runConfigSet({
|
|
252
|
+
key,
|
|
253
|
+
value,
|
|
254
|
+
project,
|
|
255
|
+
local
|
|
256
|
+
}, ctx, deps = {}) {
|
|
257
|
+
if (local === true && project !== true) {
|
|
258
|
+
throw new CliError("USAGE", "--local names the personal project file, so it needs --project", {
|
|
259
|
+
fix: `Run \`tenjin config set --project --local ${key} ${value}\`.`
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
if (isRouterKey(key)) {
|
|
263
|
+
return setRouterKey(key, value, ctx, project === true ? { local: local === true } : void 0);
|
|
264
|
+
}
|
|
265
|
+
if (project === true) {
|
|
266
|
+
throw new CliError("USAGE", `${key} is not a project key`, {
|
|
267
|
+
fix: `--project applies to ${ROUTER_CONFIG_KEYS.join(" and ")} only; drop it to set ${key} for this machine.`
|
|
268
|
+
});
|
|
269
|
+
}
|
|
223
270
|
if (isPublishKey(key)) return setPublishKey(key, value, ctx, deps);
|
|
224
271
|
if (isHooksKey(key)) return setHooksKey(key, value, ctx);
|
|
225
272
|
if (isUpdateKey(key)) return setUpdateKey(key, value, ctx);
|
|
@@ -230,7 +277,7 @@ async function runConfigSet({ key, value }, ctx, deps = {}) {
|
|
|
230
277
|
await persist(ctx.dataDir, (existing) => ({ ...existing, [configKey]: stored }));
|
|
231
278
|
if (configKey === "bazaarPay") {
|
|
232
279
|
try {
|
|
233
|
-
const { syncBazaarSkill } = await import("./skill-placement-
|
|
280
|
+
const { syncBazaarSkill } = await import("./skill-placement-JMDPSKE6.js");
|
|
234
281
|
await syncBazaarSkill(
|
|
235
282
|
stored === true,
|
|
236
283
|
deps.placeSkill ?? { io: ctx.io, dataDir: ctx.dataDir }
|
|
@@ -446,6 +493,68 @@ async function setTeamKey(key, value, ctx) {
|
|
|
446
493
|
const entry = { value: parsed, source: "file" };
|
|
447
494
|
return { data: { key, ...entry }, humanLines: [formatLine(key, entry)] };
|
|
448
495
|
}
|
|
496
|
+
async function setRouterKey(key, value, ctx, project) {
|
|
497
|
+
const field = key === "router.enabled" ? "enabled" : "context";
|
|
498
|
+
const parsed = field === "enabled" ? parseBoolean(value) : parseRouterContext(value);
|
|
499
|
+
let written;
|
|
500
|
+
if (project === void 0) {
|
|
501
|
+
await persist(ctx.dataDir, (existing) => ({
|
|
502
|
+
...existing,
|
|
503
|
+
router: { ...existing.router, [field]: parsed }
|
|
504
|
+
}));
|
|
505
|
+
written = { value: parsed, source: "file", path: configPath(ctx.dataDir) };
|
|
506
|
+
} else {
|
|
507
|
+
const path = await projectRouterPath({ cwd: process.cwd(), local: project.local });
|
|
508
|
+
await persistProjectRouter(path, field, parsed);
|
|
509
|
+
written = { value: parsed, source: project.local ? "local" : "project", path };
|
|
510
|
+
}
|
|
511
|
+
const effective = renderRouterSetting(key, await resolveRouterFromContext(ctx));
|
|
512
|
+
const humanLines = [formatLine(key, written)];
|
|
513
|
+
if (effective.value !== written.value) {
|
|
514
|
+
humanLines.push(
|
|
515
|
+
`Still ${String(effective.value)} here: ${effective.path ?? "the default"} is tighter, and a nearer file can only tighten an outer one.`
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
if (project?.local === true) {
|
|
519
|
+
humanLines.push("Keep .tenjin/config.local.json out of git: add it to .gitignore.");
|
|
520
|
+
}
|
|
521
|
+
return { data: { key, ...written, effective }, humanLines };
|
|
522
|
+
}
|
|
523
|
+
function parseRouterContext(value) {
|
|
524
|
+
const found = ROUTER_CONTEXTS.find((context) => context === value);
|
|
525
|
+
if (found !== void 0) return found;
|
|
526
|
+
throw new CliError("USAGE", `Invalid router.context: ${JSON.stringify(value)}`, {
|
|
527
|
+
fix: 'Use "session" or "turn".'
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
async function persistProjectRouter(path, field, value) {
|
|
531
|
+
await mkdir(dirname(path), { recursive: true, mode: 493 });
|
|
532
|
+
const lockPath = `${path}.lock`;
|
|
533
|
+
try {
|
|
534
|
+
await withFileLock(lockPath, () => mergeProjectRouter(path, field, value));
|
|
535
|
+
} catch (err) {
|
|
536
|
+
if (err instanceof LockTimeoutError) {
|
|
537
|
+
throw new CliError("INTERNAL", err.message, {
|
|
538
|
+
fix: `If no other tenjin process is running, remove ${lockPath} and retry.`,
|
|
539
|
+
cause: err
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
throw err;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
async function mergeProjectRouter(path, field, value) {
|
|
546
|
+
const existing = await readProjectRouterFile(path);
|
|
547
|
+
const block = existing?.json.router;
|
|
548
|
+
const next = {
|
|
549
|
+
...existing?.json ?? {},
|
|
550
|
+
router: { ...block !== void 0 ? block : {}, [field]: value }
|
|
551
|
+
};
|
|
552
|
+
await writeFileAtomic(path, `${JSON.stringify(next, null, 2)}
|
|
553
|
+
`, {
|
|
554
|
+
mode: 420,
|
|
555
|
+
dirMode: 493
|
|
556
|
+
});
|
|
557
|
+
}
|
|
449
558
|
function parsePublishMode(value) {
|
|
450
559
|
const parsed = PublishModeSchema.safeParse(value);
|
|
451
560
|
if (parsed.success) return parsed.data;
|
|
@@ -520,7 +629,7 @@ async function resolveFromContext(ctx) {
|
|
|
520
629
|
function assertKey(key) {
|
|
521
630
|
if (CONFIG_KEYS.includes(key)) return key;
|
|
522
631
|
throw new CliError("USAGE", `Unknown config key: ${JSON.stringify(key)}`, {
|
|
523
|
-
fix: `Valid keys: ${[...CONFIG_KEYS, ...PUBLISH_CONFIG_KEYS, ...HOOKS_CONFIG_KEYS].join(", ")}.`
|
|
632
|
+
fix: `Valid keys: ${[...CONFIG_KEYS, ...PUBLISH_CONFIG_KEYS, ...HOOKS_CONFIG_KEYS, ...ROUTER_CONFIG_KEYS].join(", ")}.`
|
|
524
633
|
});
|
|
525
634
|
}
|
|
526
635
|
function renderSetting(key, stored, source) {
|
|
@@ -656,7 +765,8 @@ async function persist(dir, merge) {
|
|
|
656
765
|
}
|
|
657
766
|
function formatLine(key, entry) {
|
|
658
767
|
const label = key.padEnd(KEY_WIDTH);
|
|
659
|
-
|
|
768
|
+
const where = entry.path !== void 0 && (entry.source === "project" || entry.source === "local") ? ` ${entry.path}` : "";
|
|
769
|
+
return ` ${label} ${displayValue(entry)} ${styleText("dim", `(${entry.source}${where})`)}`;
|
|
660
770
|
}
|
|
661
771
|
function describedLine(key, entry, note) {
|
|
662
772
|
const description = KEY_DESCRIPTIONS[key];
|
|
@@ -695,4 +805,4 @@ export {
|
|
|
695
805
|
persistInstallHarness,
|
|
696
806
|
persistGrantDeclined
|
|
697
807
|
};
|
|
698
|
-
//# sourceMappingURL=chunk-
|
|
808
|
+
//# sourceMappingURL=chunk-ON6C6WOX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/config.ts","../src/lib/harness-presence.ts"],"sourcesContent":["import { mkdir } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { dirname } from 'node:path';\nimport { styleText } from 'node:util';\nimport { CliError } from '../lib/errors';\nimport { confirmChoice } from '../lib/clack';\nimport type { CodexGrantResult } from '../lib/harness-permissions';\nimport {\n inspectFreeVerbRules,\n MODE_GATED_RULES,\n retractModeGatedRules,\n wireFreeVerbAllowlist,\n type PermissionsResult,\n} from '../lib/harness-permissions';\nimport { modeGatedPointer } from '../lib/permissions';\nimport { PRODUCTION_ORIGIN, isSameDeployment } from '../lib/production-origin';\nimport {\n CONFIG_KEYS,\n HOOKS_CONFIG_KEYS,\n PUBLISH_CONFIG_KEYS,\n PublishModeSchema,\n RawConfigSchema,\n SEND_MAX_UNSET,\n UPDATE_CONFIG_KEYS,\n LOOP_CONFIG_KEYS,\n TEAM_CONFIG_KEYS,\n ROUTER_CONFIG_KEYS,\n ROUTER_CONTEXTS,\n loadRawConfig,\n parseLoopValue,\n parsePublicFallbackFlag,\n parseAckServerWarnings,\n parseUpdateModeFlag,\n resolveSettings,\n} from '../lib/config';\nimport type {\n EffectiveSettings,\n HookArm,\n HooksConfigKey,\n PartialConfig,\n Provenance,\n PublishConfigKey,\n PublishMode,\n ScalarConfigKey,\n UpdateConfigKey,\n LoopConfigKey,\n TeamConfigKey,\n RouterConfigKey,\n RouterContext,\n} from '../lib/config';\nimport { onPath } from '../lib/skill-wiring';\nimport type { Harness, HarnessAdapter } from '../adapters/types';\nimport { ADAPTERS } from '../adapters/registry';\nimport { isTeamShelfOrigin, loadProjectConfig } from '../lib/settings';\nimport { configPath } from '../lib/paths';\nimport { writeFileAtomic } from '../lib/atomic-json';\nimport { installedHarnessInPlay } from '../lib/harness-presence';\nimport { withFileLock, LockTimeoutError } from '../lib/lock';\nimport { parseUsdToAtomic, toMoney } from '../lib/money';\nimport type { Money } from '../schemas';\nimport type { CommandContext, CommandResult } from '../context';\nimport {\n projectRouterPath,\n readProjectRouterFile,\n routerSettings,\n type RouterSettings,\n} from '../router/settings';\n\n/**\n * How one config key is presented in `data`. `value` is the machine form: dual\n * Money for the spend keys, the stored string for `confirm`/URLs, the string[]\n * for the allowlist. `threshold` rides along only for `confirm: above:<atomic>`\n * so an agent reads the dollar amount without re-parsing the string.\n */\ninterface RenderedValue {\n value: Money | string | string[] | boolean;\n threshold?: Money;\n}\ninterface RenderedSetting extends RenderedValue {\n source: Provenance;\n /** The file a router key came from, when one did. */\n path?: string;\n}\n\n/**\n * Seams for the one `config set` path that touches a file outside the data dir.\n * Tests inject all of them; nothing here is reachable from a flag.\n */\nexport interface ConfigSetDeps {\n /** Harness lifecycle implementations; tests inject adapters at this boundary. */\n adapters?: Readonly<Record<Harness, HarnessAdapter>>;\n /** Home whose `.claude/settings.json` is synced; defaults to os.homedir(). */\n homeDir?: string;\n /** Overrides TTY detection, exactly as install's own seam does. */\n isInteractive?: boolean;\n /** The yes/no for a loosening write; defaults to the clack confirm (default yes). */\n confirmRule?: (label: string) => Promise<boolean>;\n /** Settled harness selection; absent, each registered adapter is detected normally. */\n harnessesInPlay?: readonly Harness[];\n /** The retraction-only pass `review` runs; defaults to the real writer. */\n retractModeGated?: (home: string) => Promise<PermissionsResult>;\n /** PATH probe for harness detection; defaults to probing `env.PATH`. */\n which?: (bin: string) => boolean;\n /** Environment for that probe; defaults to process.env. */\n env?: NodeJS.ProcessEnv;\n inspectAllowlist?: typeof inspectFreeVerbRules;\n wireAllowlist?: (home: string, mode: PublishMode) => Promise<PermissionsResult>;\n}\n\nconst CONFIRM_ABOVE = 'above:';\nconst KEY_WIDTH = Math.max(\n ...[\n ...CONFIG_KEYS,\n ...PUBLISH_CONFIG_KEYS,\n ...HOOKS_CONFIG_KEYS,\n ...UPDATE_CONFIG_KEYS,\n ...LOOP_CONFIG_KEYS,\n ...TEAM_CONFIG_KEYS,\n ...ROUTER_CONFIG_KEYS,\n ].map((key) => key.length),\n);\n\n/**\n * A one-line human description per key, appended (dim) to the bare `config`\n * listing only. Machine `data` is unchanged; these are humanLines decoration.\n */\nconst KEY_DESCRIPTIONS: Record<string, string> = {\n maxAutoSpend: 'auto-approve a read up to this amount',\n sessionBudget: 'cap on total auto-spend per session',\n confirm: 'when to ask before paying',\n sendMaxAmount:\n 'hard cap per tenjin wallet send; unset = send refuses until set, 0 disables send, none = uncapped; never bypassed by --yes',\n allowlistCreators: 'only auto-pay these creators (empty = any)',\n baseUrl: 'Tenjin API base URL: what publish/read/search go to (the team shelf, in team mode)',\n publicShelfUrl:\n 'the public marketplace, consume-only: the second shelf a team-mode search falls through to',\n shelfBypassSecret:\n \"the team shelf's Vercel protection-bypass secret; setting it is what turns team mode on (printed as set/unset)\",\n rpcUrl: 'Base RPC endpoint for balance reads',\n evalCohort: 'opt in to the search evaluation cohort',\n bazaarPay: 'let `tenjin pay` spend at registry-listed non-Tenjin endpoints',\n bazaarRegistries: 'x402 discovery registries for `discover` and the pay lane',\n 'publish.mode': 'review=always ask, auto=ask on findings, full-auto=only hard blocks stop it',\n 'publish.defaultPrice': 'price used when none is given',\n 'publish.ackServerWarnings':\n \"whether a yes covers the MARKETPLACE scan's warn findings: mode=only the ones an earlier render already showed you (full-auto still acks), on=any of them, off=never\",\n 'hooks.prompt': 'answer the prompt you just typed with what the shelves already know',\n 'hooks.web-search': 'ask Tenjin before the agent runs a WebSearch',\n 'hooks.web-fetch': 'ask Tenjin before the agent fetches a page',\n 'hooks.subagent':\n 'ask Tenjin with a subagent work order (the most sensitive payload any hook sees) and hand the answer to the child at its start',\n 'hooks.failure': 'answer a failing command with the fix this machine or a shelf already has',\n 'hooks.publish':\n 'the turn-end ask to publish what this turn settled, spoken to you and to each subagent at its own end',\n 'hooks.primer': 'one-paragraph search-first primer at session start',\n 'update.mode':\n 'nudge=report a newer version (stderr line, JSON envelope, hook output), off=neither report nor ask npm',\n 'loop.human_wait_ms':\n 'ms a hook fire may take when a human is waiting on it (prompt, Stop, SessionStart)',\n 'loop.tool_wait_ms': 'ms a hook fire may take when a tool call is waiting on it',\n 'loop.idle_exit_min': 'minutes without a hook fire before the loop daemon exits',\n 'loop.port':\n \"the loop daemon's loopback port; null derives one from the data dir (set only when doctor reports a foreign listener)\",\n 'team.publicFallback':\n 'on=a team-shelf miss falls through to the public marketplace, off=team-only (public-only lookup stages are dropped)',\n 'router.enabled':\n 'false stops every router hook and the request tool; --project sets it for this repository, --project --local for you alone in it',\n 'router.context':\n 'session=a hook packet carries up to six prior messages, turn=the current turn only; --project and --local as for router.enabled',\n};\n\nfunction isLoopKey(key: string): key is LoopConfigKey {\n return (LOOP_CONFIG_KEYS as readonly string[]).includes(key);\n}\n\nfunction isTeamKey(key: string): key is TeamConfigKey {\n return (TEAM_CONFIG_KEYS as readonly string[]).includes(key);\n}\n\nfunction isRouterKey(key: string): key is RouterConfigKey {\n return (ROUTER_CONFIG_KEYS as readonly string[]).includes(key);\n}\n\n/** The list/get shape for a router key, with the file that set it. */\nfunction renderRouterSetting(key: RouterConfigKey, settings: RouterSettings): RenderedSetting {\n const { value, source, path } = key === 'router.enabled' ? settings.enabled : settings.context;\n return { value, source, ...(path !== undefined ? { path } : {}) };\n}\n\n/** Router keys resolve against the directory the command runs in, as a hook would. */\nasync function resolveRouterFromContext(ctx: CommandContext): Promise<RouterSettings> {\n return routerSettings({ cwd: process.cwd(), dataDir: ctx.dataDir });\n}\n\nfunction renderLoopSetting(key: LoopConfigKey, settings: EffectiveSettings): RenderedSetting {\n const field = key.slice('loop.'.length) as keyof EffectiveSettings['loop'];\n const { value, source } = settings.loop[field];\n return { value: value === null ? 'null' : String(value), source };\n}\n\nfunction isPublishKey(key: string): key is PublishConfigKey {\n return (PUBLISH_CONFIG_KEYS as readonly string[]).includes(key);\n}\n\nfunction isHooksKey(key: string): key is HooksConfigKey {\n return (HOOKS_CONFIG_KEYS as readonly string[]).includes(key);\n}\n\nfunction isUpdateKey(key: string): key is UpdateConfigKey {\n return (UPDATE_CONFIG_KEYS as readonly string[]).includes(key);\n}\n\n/**\n * Show every effective key with its value and provenance. `data` is keyed by\n * config key; provenance comes from resolveSettings over the *raw* file (not the\n * defaults-merged config), so a key the user never set reads `default`, not\n * `file`.\n */\nexport async function runConfigList(ctx: CommandContext): Promise<CommandResult> {\n const settings = await resolveFromContext(ctx);\n const data: Record<string, RenderedSetting> = {};\n const humanLines: string[] = [];\n for (const key of CONFIG_KEYS) {\n const entry = renderSetting(key, settings[key].value, settings[key].source);\n data[key] = entry;\n humanLines.push(describedLine(key, entry));\n }\n for (const key of PUBLISH_CONFIG_KEYS) {\n const entry = renderPublishSetting(key, settings);\n data[key] = entry;\n humanLines.push(describedLine(key, entry, downgradeNote(key, settings)));\n }\n for (const key of HOOKS_CONFIG_KEYS) {\n const entry = renderHooksSetting(key, settings);\n data[key] = entry;\n humanLines.push(describedLine(key, entry));\n }\n for (const key of UPDATE_CONFIG_KEYS) {\n const entry: RenderedSetting = {\n value: settings.updateMode.value,\n source: settings.updateMode.source,\n };\n data[key] = entry;\n humanLines.push(describedLine(key, entry));\n }\n for (const key of LOOP_CONFIG_KEYS) {\n const entry = renderLoopSetting(key, settings);\n data[key] = entry;\n humanLines.push(describedLine(key, entry));\n }\n for (const key of TEAM_CONFIG_KEYS) {\n const entry: RenderedSetting = {\n value: settings.teamPublicFallback.value,\n source: settings.teamPublicFallback.source,\n };\n data[key] = entry;\n humanLines.push(describedLine(key, entry));\n }\n const router = await resolveRouterFromContext(ctx);\n for (const key of ROUTER_CONFIG_KEYS) {\n const entry = renderRouterSetting(key, router);\n data[key] = entry;\n humanLines.push(describedLine(key, entry));\n }\n return { data, humanLines };\n}\n\n/** Same per-key shape as list, for one key. Unknown key is a USAGE failure. */\nexport async function runConfigGet(\n { key }: { key: string },\n ctx: CommandContext,\n): Promise<CommandResult> {\n if (isPublishKey(key)) {\n const settings = await resolveFromContext(ctx);\n const entry = renderPublishSetting(key, settings);\n return {\n data: { key, ...entry },\n humanLines: [withNote(formatLine(key, entry), downgradeNote(key, settings))],\n };\n }\n if (isHooksKey(key)) {\n const entry = renderHooksSetting(key, await resolveFromContext(ctx));\n return { data: { key, ...entry }, humanLines: [formatLine(key, entry)] };\n }\n if (isUpdateKey(key)) {\n const { updateMode } = await resolveFromContext(ctx);\n const entry: RenderedSetting = { value: updateMode.value, source: updateMode.source };\n return { data: { key, ...entry }, humanLines: [formatLine(key, entry)] };\n }\n if (isLoopKey(key)) {\n const entry = renderLoopSetting(key, await resolveFromContext(ctx));\n return { data: { key, ...entry }, humanLines: [formatLine(key, entry)] };\n }\n if (isTeamKey(key)) {\n const { teamPublicFallback } = await resolveFromContext(ctx);\n const entry: RenderedSetting = {\n value: teamPublicFallback.value,\n source: teamPublicFallback.source,\n };\n return { data: { key, ...entry }, humanLines: [formatLine(key, entry)] };\n }\n if (isRouterKey(key)) {\n const entry = renderRouterSetting(key, await resolveRouterFromContext(ctx));\n return { data: { key, ...entry }, humanLines: [formatLine(key, entry)] };\n }\n const configKey = assertKey(key);\n const settings = await resolveFromContext(ctx);\n const entry = renderSetting(configKey, settings[configKey].value, settings[configKey].source);\n return { data: { key: configKey, ...entry }, humanLines: [formatLine(configKey, entry)] };\n}\n\n/**\n * Parse the value for this key, then persist it merged into the existing raw\n * file — never materializing defaults for keys the user did not set, so\n * provenance stays truthful. The written key now reads `file`.\n */\nexport interface ConfigSetDeps {\n /** Seam for the tenjin-pay skill placement (tests inject homeDir/source). */\n placeSkill?: { io: CommandContext['io']; homeDir?: string; skillsSourceDir?: string };\n}\n\nexport async function runConfigSet(\n {\n key,\n value,\n project,\n local,\n }: { key: string; value: string; project?: boolean; local?: boolean },\n ctx: CommandContext,\n deps: ConfigSetDeps = {},\n): Promise<CommandResult> {\n if (local === true && project !== true) {\n throw new CliError('USAGE', '--local names the personal project file, so it needs --project', {\n fix: `Run \\`tenjin config set --project --local ${key} ${value}\\`.`,\n });\n }\n if (isRouterKey(key)) {\n return setRouterKey(key, value, ctx, project === true ? { local: local === true } : undefined);\n }\n if (project === true) {\n throw new CliError('USAGE', `${key} is not a project key`, {\n fix: `--project applies to ${ROUTER_CONFIG_KEYS.join(' and ')} only; drop it to set ${key} for this machine.`,\n });\n }\n if (isPublishKey(key)) return setPublishKey(key, value, ctx, deps);\n if (isHooksKey(key)) return setHooksKey(key, value, ctx);\n if (isUpdateKey(key)) return setUpdateKey(key, value, ctx);\n if (isLoopKey(key)) return setLoopKey(key, value, ctx);\n if (isTeamKey(key)) return setTeamKey(key, value, ctx);\n const configKey = assertKey(key);\n const stored = parseValue(configKey, value);\n await persist(ctx.dataDir, (existing) => ({ ...existing, [configKey]: stored }));\n // The Bazaar lane's teaching is an OPTIONAL skill whose presence follows\n // this toggle: flipping it places or removes the tenjin-pay skill in every\n // wired skills directory, immediately (a config set is an operator act, the\n // same trust class as install). Best-effort AFTER the persist: the set\n // itself already succeeded, and skill drift is doctor's to report.\n if (configKey === 'bazaarPay') {\n try {\n const { syncBazaarSkill } = await import('../lib/skill-placement');\n await syncBazaarSkill(\n stored === true,\n deps.placeSkill ?? { io: ctx.io, dataDir: ctx.dataDir },\n );\n } catch {\n // `tenjin doctor` reports a presence that does not match the toggle.\n }\n }\n const entry = renderSetting(configKey, stored, 'file');\n const warning = await halfWiredTeamShelf(configKey, ctx.dataDir);\n return {\n data: { key: configKey, ...entry, ...(warning !== undefined ? { warning } : {}) },\n humanLines: [formatLine(configKey, entry), ...(warning !== undefined ? [warning] : [])],\n };\n}\n\n/**\n * The half-wired team shelf, said out loud at the moment it is created.\n *\n * Team mode takes TWO settings — a private deployment in `baseUrl` and its\n * bypass secret — and the setup is two independent commands, so a machine can\n * easily end up with the secret and no shelf (run in the other order, or the\n * secret line alone on a second machine). The CLI fails that state safe to\n * public mode, which means an operator who thinks they are on the team shelf\n * would otherwise get no signal at all: publishes would go to the marketplace\n * under the public gates. Warn, do not refuse — the pair is legitimately\n * half-set between two commands, and refusing would make the documented order\n * the only order.\n *\n * THREE KEYS, not two. `isTeamShelfOrigin` also returns false when `baseUrl`\n * matches `publicShelfUrl`, so pointing `publicShelfUrl` at the team deployment\n * drops the machine out of team mode just as surely as unsetting the secret\n * would. It fails safe and doctor catches it later; this is the warning at the\n * moment it happens, on the third key of the same triple.\n */\nasync function halfWiredTeamShelf(\n configKey: ScalarConfigKey,\n dataDir: string,\n): Promise<string | undefined> {\n if (\n configKey !== 'shelfBypassSecret' &&\n configKey !== 'baseUrl' &&\n configKey !== 'publicShelfUrl'\n ) {\n return undefined;\n }\n const config = await loadRawConfig(dataDir).catch(() => undefined);\n if (config === undefined) return undefined;\n const s = resolveSettings({ config, flags: {}, env: {} });\n if (s.shelfBypassSecret.value.length === 0) return undefined;\n const baseUrl = s.baseUrl.value;\n if (isTeamShelfOrigin(new URL(baseUrl).origin, s.publicShelfUrl.value)) return undefined;\n // WHICH KEY BROKE THE PAIR decides which fix to name. A baseUrl that now\n // matches publicShelfUrl is not \"the marketplace\" in any recognizable sense —\n // it is the operator's own two keys pointed at one place — and telling them to\n // re-point baseUrl would be advice for the other half of the same collision.\n const isProduction = isSameDeployment(new URL(baseUrl).origin, PRODUCTION_ORIGIN);\n const cause = isProduction\n ? `baseUrl is the public marketplace (${baseUrl})`\n : `baseUrl and publicShelfUrl are the same shelf (${baseUrl})`;\n const fix = isProduction\n ? 'Point baseUrl at the team deployment to finish team mode: `tenjin config set baseUrl <team shelf url>`.'\n : `A team shelf must differ from the shelf it falls through to: \\`tenjin config set publicShelfUrl ${PRODUCTION_ORIGIN}\\`.`;\n return (\n `Warning: shelfBypassSecret is set, but ${cause}, ` +\n 'so this machine stays in PUBLIC mode — publishes go to the marketplace with the scan’s ' +\n 'warn tier and the confirm cascade on. ' +\n fix\n );\n}\n\n/**\n * `config set publish.mode|publish.defaultPrice|publish.ackServerWarnings`. mode\n * and ackServerWarnings validate to their enums; defaultPrice parses decimal USD\n * at the edge into atomic (matching the spend keys). The subkey is merged into\n * the nested publish block, so a sibling subkey (or an unknown one a newer CLI\n * wrote) is preserved.\n */\nasync function setPublishKey(\n key: PublishConfigKey,\n value: string,\n ctx: CommandContext,\n deps: ConfigSetDeps,\n): Promise<CommandResult> {\n const entry: RenderedSetting =\n key === 'publish.mode'\n ? { value: parsePublishMode(value), source: 'file' }\n : key === 'publish.ackServerWarnings'\n ? { value: parseAckServerWarnings(value, key), source: 'file' }\n : { value: toMoney(parseUsdToAtomic(value)), source: 'file' };\n const subkey =\n key === 'publish.mode'\n ? 'mode'\n : key === 'publish.ackServerWarnings'\n ? 'ackServerWarnings'\n : 'defaultPrice';\n const stored =\n key === 'publish.defaultPrice' ? (entry.value as Money).atomic : (entry.value as string);\n const persistEntry = async (): Promise<void> =>\n persist(ctx.dataDir, (existing) => ({\n ...existing,\n publish: { ...existing.publish, [subkey]: stored },\n }));\n const humanLines = [formatLine(key, entry)];\n if (key !== 'publish.mode') {\n await persistEntry();\n return { data: { key, ...entry }, humanLines };\n }\n\n // The mode decides whether a publish asks; the harness rule decides whether the\n // harness asks ANYWAY. Settling one and leaving the other to the next `tenjin\n // install` is the seam that made publish.mode look broken (tenjin-agent #161),\n // so the two move together from here too.\n // Synchronize before committing the mode. A grant writer may refuse after\n // consent (permissions, concurrent edits, an unwritable parent); persisting\n // first made the command exit successfully with an unattended mode that its\n // harness could not carry. Grant-first is also the least-authority failure\n // order: if a later config write fails, the CLI still resolves the old mode.\n const allowlist = await syncPublishRule(entry.value as PublishMode, ctx, deps);\n const failure = grantSyncFailure(allowlist);\n if (failure !== undefined) {\n throw new CliError(\n 'REFUSED',\n `publish.mode was not changed because the ${failure.harness} grant could not be updated: ${failure.reason}`,\n {\n fix:\n failure.fix ??\n `Fix the permissions for ${failure.path}, then re-run \\`tenjin config set publish.mode ${entry.value as string}\\`.`,\n details: { key, value: entry.value, allowlist },\n },\n );\n }\n await persistEntry();\n return {\n data: { key, ...entry, allowlist },\n humanLines: [...humanLines, ...allowlistLines(allowlist)],\n };\n}\n\n/**\n * What `config set publish.mode` did about the harness rule the mode carries.\n * `skipped` names why nothing was written; `pointer` is the line to show when it\n * is the operator's move.\n */\ninterface AllowlistSync {\n byHarness: Partial<Record<Harness, PermissionsResult | CodexGrantResult>>;\n skipped?: 'not-claude' | 'no-tty' | 'declined' | 'unwritable';\n pointer?: string;\n}\n\n/** A writer refusal is an error, not informational output: the mode and every\n * harness grant are one operator decision and may not report success apart. */\nfunction grantSyncFailure(\n sync: AllowlistSync,\n): { harness: Harness; path: string; reason: string; fix?: string } | undefined {\n for (const [harness, result] of Object.entries(sync.byHarness) as [\n Harness,\n PermissionsResult | CodexGrantResult,\n ][]) {\n if ('error' in result && result.error !== undefined) {\n return { harness, path: result.path, reason: result.error };\n }\n if ('warning' in result && result.warning !== undefined) {\n return {\n harness,\n path: result.path ?? '(unknown path)',\n reason: result.warning,\n ...(result.fix !== undefined ? { fix: result.fix } : {}),\n };\n }\n }\n return undefined;\n}\n\n/** Names what the write actually carries: on a machine that never ran `install`,\n * the free tier is pending too, and a question naming two lines while eleven\n * land is asking about something else. */\nfunction publishRuleQuestion(\n mode: PublishMode,\n pending: readonly string[],\n harnesses: readonly Harness[],\n): string {\n const gated = new Set<string>(MODE_GATED_RULES);\n const others = pending.filter((rule) => !gated.has(rule)).length;\n const also =\n others > 0 ? ` Also adds the ${others} command-grant rule(s) \\`tenjin install\\` writes.` : '';\n const targets = harnesses\n .map((harness) =>\n harness === 'claude' ? 'Claude Code' : harness === 'codex' ? 'Codex' : harness,\n )\n .join(' and ');\n return (\n `publish.mode ${mode} is unattended only if ${targets} carries the matching grant for ` +\n `${MODE_GATED_RULES.join(' and ')}. Update the ${targets} grant now?${also}`\n );\n}\n\n/**\n * Keep the harness allowlist in step with the mode just written.\n *\n * ASYMMETRIC ON PURPOSE, and the asymmetry is the consent rule:\n * - Loosening (auto/full-auto) ADDS a grant, so it needs a human in the loop.\n * No TTY, `--json`, or a declined prompt all leave the file alone and return\n * the pointer instead; nothing here writes on silence.\n * - Tightening (review) only ever REMOVES a rule this CLI wrote under a setting\n * the operator has just changed, so it runs unconditionally — the same reason\n * install sweeps a retired rule without asking. Leaving it behind would keep\n * publishing pre-cleared after the operator said \"ask me first\", which is the\n * failure that matters.\n */\nasync function syncPublishRule(\n mode: PublishMode,\n ctx: CommandContext,\n deps: ConfigSetDeps,\n): Promise<AllowlistSync> {\n const home = deps.homeDir ?? homedir();\n const nothing: AllowlistSync = { byHarness: {} };\n\n const write = async (): Promise<AllowlistSync> => {\n const result = await (deps.wireAllowlist ?? wireFreeVerbAllowlist)(home, mode);\n if (result.skipped !== undefined) {\n return {\n byHarness: { claude: result },\n skipped: 'unwritable',\n ...(result.fix !== undefined ? { pointer: result.fix } : {}),\n };\n }\n return { byHarness: { claude: result } };\n };\n\n const adapters = deps.adapters ?? ADAPTERS;\n const env = deps.env ?? process.env;\n const which = deps.which ?? ((bin: string) => onPath(bin, env));\n const requested = await loadRawConfig(ctx.dataDir)\n .then((config) => config.install?.harness ?? [])\n .catch(() => [] as Harness[]);\n const inPlay =\n deps.harnessesInPlay ??\n (\n await Promise.all(\n Object.values(adapters).map(async (adapter) => ({\n adapter,\n selected: await installedHarnessInPlay(adapter, home, ctx.dataDir, {\n env,\n which,\n requested,\n }),\n })),\n )\n )\n .filter((entry) => entry.selected)\n .map((entry) => entry.adapter.id);\n const selectedAdapters = inPlay.map((harness) => adapters[harness]);\n const isClaude = inPlay.includes('claude');\n\n const withOtherGrants = async (sync: AllowlistSync): Promise<AllowlistSync> => {\n const byHarness = { ...sync.byHarness };\n for (const adapter of selectedAdapters) {\n if (adapter.id === 'claude' || adapter.registrar.grant === undefined) continue;\n const result = await adapter.registrar.grant.write(home, mode, env);\n byHarness[adapter.id] = result;\n }\n return { ...sync, byHarness };\n };\n\n // Only Claude Code has a settings file of this shape; guessing at another\n // harness's config is the uninvited write lib/harness-permissions.ts avoids.\n // DETECTED, never assumed: a codex-only machine has a ~/.claude/settings.json\n // that nothing reads, so prompting about it is noise and writing to it is an\n // uninvited edit — and the retraction would sweep a file we never owned.\n if (selectedAdapters.every((adapter) => adapter.registrar.grant === undefined)) {\n // No settings file of ours to be missing anything, so the pointer would be\n // advice about a machine this is not.\n return { ...nothing, skipped: 'not-claude' };\n }\n\n const probe = isClaude\n ? await (deps.inspectAllowlist ?? inspectFreeVerbRules)(home, mode)\n : { pending: [] as string[] };\n const gated = new Set<string>(MODE_GATED_RULES);\n const missing = (probe.pending ?? []).filter((r) => gated.has(r));\n // Only ever names rules this machine does not have. A pointer built from the\n // mode alone told a fully-wired operator to go add what they already had.\n const pointer = modeGatedPointer(mode, missing) ?? undefined;\n\n // Tightening runs with no question and with no precondition, through a pass\n // that can only ever REMOVE. Riding the additive writer made this decline\n // whenever the free tier was not byte-exact — silently, and in the tightening\n // direction, on the undo the operator just typed.\n if (mode === 'review') {\n const retracted = isClaude\n ? await (deps.retractModeGated ?? retractModeGatedRules)(home)\n : undefined;\n if (retracted?.skipped !== undefined) {\n return {\n ...nothing,\n skipped: 'unwritable',\n ...(retracted.fix !== undefined ? { pointer: retracted.fix } : {}),\n };\n }\n return await withOtherGrants({\n byHarness: retracted === undefined ? {} : { claude: retracted },\n });\n }\n\n // SATISFIED BEFORE TTY, and the order is the point: a fully-wired machine has\n // nothing to ask about and nothing to write, so a `--json` or headless run\n // there is a no-op rather than a `no-tty` skip carrying a pointer at rules it\n // already has.\n if (probe.satisfied !== undefined && selectedAdapters.length === 1 && isClaude) return nothing;\n\n const canPrompt =\n ctx.flags.json === true ? false : (deps.isInteractive ?? Boolean(process.stdin.isTTY));\n if (!canPrompt) {\n return { ...nothing, skipped: 'no-tty', ...(pointer ? { pointer } : {}) };\n }\n\n const confirm = deps.confirmRule ?? ((label: string) => confirmChoice(label, true));\n const grantable = selectedAdapters\n .filter((adapter) => adapter.registrar.grant !== undefined)\n .map((adapter) => adapter.id);\n if (!(await confirm(publishRuleQuestion(mode, probe.pending ?? [], grantable)))) {\n return { ...nothing, skipped: 'declined', ...(pointer ? { pointer } : {}) };\n }\n return await withOtherGrants(isClaude ? await write() : nothing);\n}\n\n/** The human rendering of {@link syncPublishRule}, or nothing when it was a no-op. */\nfunction allowlistLines(sync: AllowlistSync): string[] {\n const lines: string[] = [];\n const claude = sync.byHarness.claude as PermissionsResult | undefined;\n if ((claude?.added.length ?? 0) > 0) {\n lines.push(`Added ${claude?.added.length ?? 0} harness rule(s) to your allowlist.`);\n }\n if ((claude?.removed.length ?? 0) > 0) {\n lines.push(`Removed ${claude?.removed.join(', ')} from your allowlist.`);\n }\n const grant = sync.byHarness.codex as CodexGrantResult | undefined;\n if (grant !== undefined && grant.error === undefined && grant.wrote) {\n lines.push(\n `Codex now allows ${grant.granted.length} tenjin command prefix(es) in ${grant.path}.`,\n );\n }\n if (grant?.error !== undefined) {\n lines.push(`Codex's grant at ${grant.path} could not be updated (${grant.error}).`);\n }\n if (sync.pointer !== undefined) lines.push(sync.pointer);\n return lines;\n}\n\n/**\n * `config set hooks.<arm>`. Merged into the nested hooks block through the same\n * locked read-modify-write every other set uses, so a subkey a newer CLI wrote\n * survives. The daemon re-stats this file per fire, so every value takes effect\n * on the next prompt with no re-install and no process to restart.\n */\nasync function setHooksKey(\n key: HooksConfigKey,\n value: string,\n ctx: CommandContext,\n): Promise<CommandResult> {\n const arm = key.slice('hooks.'.length) as HookArm;\n const parsed = parseBoolean(value);\n await persistHookArm(ctx.dataDir, arm, parsed);\n const entry: RenderedSetting = { value: parsed, source: 'file' };\n // NO STALENESS WARNING, and there is nothing left to warn about: every hooks\n // key is read out of `config.json` by the daemon on each fire, so a value set\n // here takes effect on the next prompt with nothing to re-install.\n return { data: { key, ...entry }, humanLines: [formatLine(key, entry)] };\n}\n\n/**\n * `config set update.mode`. Same locked merge-write as every other set, so the\n * next command reports (or stops reporting) under the new mode immediately,\n * with nothing to re-install and no process to restart.\n */\nasync function setUpdateKey(\n key: UpdateConfigKey,\n value: string,\n ctx: CommandContext,\n): Promise<CommandResult> {\n const parsed = parseUpdateModeFlag(value, key);\n await persist(ctx.dataDir, (existing) => ({\n ...existing,\n update: { ...existing.update, mode: parsed },\n }));\n const entry: RenderedSetting = { value: parsed, source: 'file' };\n return { data: { key, ...entry }, humanLines: [formatLine(key, entry)] };\n}\n\n/**\n * `config set loop.*` and `config set team.publicFallback`. The daemon stats\n * `config.json` per fire and reloads on an mtime change, so a set takes effect\n * on the next hook fire with no restart (02-redesign.md §4a).\n */\nasync function setLoopKey(\n key: LoopConfigKey,\n value: string,\n ctx: CommandContext,\n): Promise<CommandResult> {\n const parsed = parseLoopValue(key, value);\n const field = key.slice('loop.'.length);\n await persist(ctx.dataDir, (existing) => ({\n ...existing,\n loop: { ...existing.loop, [field]: parsed },\n }));\n const entry: RenderedSetting = {\n value: parsed === null ? 'null' : String(parsed),\n source: 'file',\n };\n return { data: { key, ...entry }, humanLines: [formatLine(key, entry)] };\n}\n\nasync function setTeamKey(\n key: TeamConfigKey,\n value: string,\n ctx: CommandContext,\n): Promise<CommandResult> {\n const parsed = parsePublicFallbackFlag(value, key);\n await persist(ctx.dataDir, (existing) => ({\n ...existing,\n team: { ...existing.team, publicFallback: parsed },\n }));\n const entry: RenderedSetting = { value: parsed, source: 'file' };\n return { data: { key, ...entry }, humanLines: [formatLine(key, entry)] };\n}\n\n/**\n * `config set [--project [--local]] router.enabled|router.context`. Without\n * `--project` the key goes into the global config through the same locked merge\n * every set uses. With it, into the project file {@link projectRouterPath}\n * names from here, merged so a sibling key survives. The line after the write\n * is what a hook here would now resolve, which differs from the value written\n * when an outer layer is tighter.\n */\nasync function setRouterKey(\n key: RouterConfigKey,\n value: string,\n ctx: CommandContext,\n project: { local: boolean } | undefined,\n): Promise<CommandResult> {\n const field = key === 'router.enabled' ? 'enabled' : 'context';\n const parsed = field === 'enabled' ? parseBoolean(value) : parseRouterContext(value);\n let written: RenderedSetting;\n if (project === undefined) {\n await persist(ctx.dataDir, (existing) => ({\n ...existing,\n router: { ...existing.router, [field]: parsed },\n }));\n written = { value: parsed, source: 'file', path: configPath(ctx.dataDir) };\n } else {\n const path = await projectRouterPath({ cwd: process.cwd(), local: project.local });\n await persistProjectRouter(path, field, parsed);\n written = { value: parsed, source: project.local ? 'local' : 'project', path };\n }\n const effective = renderRouterSetting(key, await resolveRouterFromContext(ctx));\n const humanLines = [formatLine(key, written)];\n if (effective.value !== written.value) {\n humanLines.push(\n `Still ${String(effective.value)} here: ${effective.path ?? 'the default'} is tighter, and a nearer file can only tighten an outer one.`,\n );\n }\n if (project?.local === true) {\n humanLines.push('Keep .tenjin/config.local.json out of git: add it to .gitignore.');\n }\n return { data: { key, ...written, effective }, humanLines };\n}\n\nfunction parseRouterContext(value: string): RouterContext {\n const found = ROUTER_CONTEXTS.find((context) => context === value);\n if (found !== undefined) return found;\n throw new CliError('USAGE', `Invalid router.context: ${JSON.stringify(value)}`, {\n fix: 'Use \"session\" or \"turn\".',\n });\n}\n\n/**\n * Merge one router key into a project file. It holds the router block and\n * nothing else this CLI reads, so it is written 0644 like any committed file;\n * an existing file that is not a JSON object is refused rather than replaced.\n * The read, merge and write run under the same cross-process lock the global\n * writer takes, so two concurrent sets both land.\n */\nasync function persistProjectRouter(\n path: string,\n field: 'enabled' | 'context',\n value: boolean | RouterContext,\n): Promise<void> {\n await mkdir(dirname(path), { recursive: true, mode: 0o755 });\n const lockPath = `${path}.lock`;\n try {\n await withFileLock(lockPath, () => mergeProjectRouter(path, field, value));\n } catch (err) {\n if (err instanceof LockTimeoutError) {\n throw new CliError('INTERNAL', err.message, {\n fix: `If no other tenjin process is running, remove ${lockPath} and retry.`,\n cause: err,\n });\n }\n throw err;\n }\n}\n\nasync function mergeProjectRouter(\n path: string,\n field: 'enabled' | 'context',\n value: boolean | RouterContext,\n): Promise<void> {\n // Through the one parser: a file that is not an object, or whose block is\n // invalid, is refused rather than replaced. A router subkey this build does\n // not know rides along untouched, as in the global file; it is never read.\n const existing = await readProjectRouterFile(path);\n const block = existing?.json.router;\n const next = {\n ...(existing?.json ?? {}),\n router: { ...(block !== undefined ? (block as object) : {}), [field]: value },\n };\n await writeFileAtomic(path, `${JSON.stringify(next, null, 2)}\\n`, {\n mode: 0o644,\n dirMode: 0o755,\n });\n}\n\nfunction parsePublishMode(value: string): string {\n const parsed = PublishModeSchema.safeParse(value);\n if (parsed.success) return parsed.data;\n throw new CliError('USAGE', `Invalid publish mode: ${JSON.stringify(value)}`, {\n fix: 'Use \"review\", \"auto\", or \"full-auto\".',\n });\n}\n\n/**\n * The one writer of a `hooks.<arm>` boolean, through the same locked merge-write\n * every `config set` uses, so a sibling arm or an unknown block a newer CLI\n * wrote survives. `config set hooks.<arm>` and `tenjin hooks enable|disable`\n * are two spellings of this call and never two writers.\n */\nexport async function persistHookArm(dir: string, arm: HookArm, value: boolean): Promise<void> {\n await persist(dir, (existing) => ({\n ...existing,\n hooks: { ...existing.hooks, [arm]: value },\n }));\n}\n\n/**\n * Persist just `publish.mode` into the global config through the same locked\n * merge-write every `config set` uses (never a raw overwrite), so a sibling\n * subkey or an unknown block a newer CLI wrote is preserved. Used by `install`'s\n * setup prompt; the mode is a validated PublishMode.\n */\nexport async function persistPublishMode(dir: string, mode: PublishMode): Promise<void> {\n await persist(dir, (existing) => ({\n ...existing,\n publish: { ...existing.publish, mode },\n }));\n}\n\n/** install's Bazaar-lane decision writer; the same locked read-modify-write every\n * `config set` uses, so a concurrent set never loses a sibling key. */\nexport async function persistBazaarPay(dir: string, enabled: boolean): Promise<void> {\n await persist(dir, (existing) => ({ ...existing, bazaarPay: enabled }));\n}\n\n/**\n * Remember, or forget, a project directory this machine wired with\n * `install --project`. `tenjin update` spawns its refresh from the HOME\n * directory, so a project install is unfindable by looking around; this list is\n * how a later refresh reaches it. Absolute paths, de-duplicated, and pruned\n * when a project is uninstalled or its settings file stops carrying our\n * entries.\n */\nexport async function persistRouterProject(\n dir: string,\n projectDir: string,\n present = true,\n): Promise<void> {\n await persist(dir, (existing) => {\n const known = new Set(existing.install?.routerProjects ?? []);\n if (present) known.add(projectDir);\n else known.delete(projectDir);\n return { ...existing, install: { ...existing.install, routerProjects: [...known].sort() } };\n });\n}\n\n/**\n * The spend keys `tenjin install` settles for the router, in atomic USDC.\n *\n * SIZED FOR A REAL SESSION, not for a demo. At 0.10 and 1.00 a research turn\n * stalled after about twenty lookups on a refusal the user had done nothing to\n * deserve; 0.25 a call inside 5.00 a day is the alpha's answer, and `confirm`\n * stays above the per-call cap so nothing under it ever asks. The cap is also\n * the whole money story: a wrong or hostile decision spends at most one\n * `maxAutoSpend` inside `sessionBudget`, whatever it names as a destination.\n */\nexport const ROUTER_DEFAULTS = {\n maxAutoSpend: '250000',\n sessionBudget: '5000000',\n confirm: 'above:250000',\n} as const;\n\nexport interface RouterDefaultsResult {\n /** Keys this run wrote, because the file did not name them. */\n set: string[];\n /** Keys the operator had already written, left exactly as they are. */\n kept: string[];\n}\n\n/**\n * The router's spend defaults, written ONLY where the file is silent. A\n * `confirm` the operator put in `config.json` is never touched, which is why\n * an explicit `always` keeps returning `needs_approval` from the tool handler\n * instead of being quietly loosened by an install.\n *\n * `bazaarPay` is different and is turned on either way: it is the lane the\n * router pays providers through, so an install that left it off would wire a\n * product that refuses every lookup.\n */\nexport async function persistRouterDefaults(dir: string): Promise<RouterDefaultsResult> {\n const result: RouterDefaultsResult = { set: [], kept: [] };\n await persist(dir, (existing) => {\n const next: PartialConfig = { ...existing, bazaarPay: true };\n for (const [key, value] of Object.entries(ROUTER_DEFAULTS) as [\n keyof typeof ROUTER_DEFAULTS,\n string,\n ][]) {\n if (existing[key] === undefined) {\n next[key] = value;\n result.set.push(key);\n } else result.kept.push(key);\n }\n return next;\n });\n return result;\n}\n\n/**\n * Record the settled harness selection through the same locked merge-write. It\n * replaces the previous record rather than unioning with it: the last operator\n * answer is the current intent. Doctor still re-probes detection independently;\n * the record keeps a deliberately selected but currently undetected harness in play.\n */\nexport async function persistInstallHarness(\n dir: string,\n harness: readonly Harness[],\n): Promise<void> {\n await persist(dir, (existing) => ({\n ...existing,\n install: { ...existing.install, harness: [...harness] },\n }));\n}\n\n/**\n * Record the EXACT free-verb rules `install` declined, through the same locked\n * read-modify-write every `config set` uses. Set to whatever was pending at the\n * moment of `--no-grant`; cleared back to `[]` the moment an install\n * actually wires the allowlist, or finds it already fully satisfied. `--refresh` subtracts this list from what it would otherwise\n * report as pending, so a settled no stays settled per rule — without also\n * silencing a genuinely NEW rule a later version adds (tenjin-agent#234).\n */\nexport async function persistGrantDeclined(dir: string, declined: string[]): Promise<void> {\n await persist(dir, (existing) => ({\n ...existing,\n install: { ...existing.install, grantDeclined: declined },\n }));\n}\n\nasync function resolveFromContext(ctx: CommandContext): Promise<EffectiveSettings> {\n const config = await loadRawConfig(ctx.dataDir);\n // Feed the per-project `.tenjin.json` layer so the publish keys read out what a\n // real `publish` would resolve (project/env included), not a global-only guess.\n const project = await loadProjectConfig(process.cwd());\n return resolveSettings({\n config,\n flags: { baseUrl: ctx.flags.baseUrl },\n env: process.env,\n project: project?.layer,\n });\n}\n\nfunction assertKey(key: string): ScalarConfigKey {\n if ((CONFIG_KEYS as string[]).includes(key)) return key as ScalarConfigKey;\n throw new CliError('USAGE', `Unknown config key: ${JSON.stringify(key)}`, {\n fix: `Valid keys: ${[...CONFIG_KEYS, ...PUBLISH_CONFIG_KEYS, ...HOOKS_CONFIG_KEYS, ...ROUTER_CONFIG_KEYS].join(', ')}.`,\n });\n}\n\nfunction renderSetting(\n key: ScalarConfigKey,\n stored: string | string[] | boolean,\n source: Provenance,\n): RenderedSetting {\n return { ...renderValue(key, stored), source };\n}\n\n/**\n * The list/get shape for a publish key, read from the resolved effective\n * settings, which now include the per-project `.tenjin.json` layer (see\n * resolveFromContext) so the source reflects what a publish would actually use.\n */\nfunction renderPublishSetting(key: PublishConfigKey, settings: EffectiveSettings): RenderedSetting {\n if (key === 'publish.mode') {\n return { value: settings.publishMode.value, source: settings.publishMode.source };\n }\n if (key === 'publish.ackServerWarnings') {\n return {\n value: settings.publishAckServerWarnings.value,\n source: settings.publishAckServerWarnings.source,\n };\n }\n return {\n value: toMoney(settings.publishDefaultPrice.value),\n source: settings.publishDefaultPrice.source,\n };\n}\n\n/** The list/get shape for a hooks key: the arm's boolean and where it came from. */\nfunction renderHooksSetting(key: HooksConfigKey, settings: EffectiveSettings): RenderedSetting {\n const { value, source } = settings.hooks[key.slice('hooks.'.length) as HookArm];\n return { value, source };\n}\n\nfunction renderValue(key: ScalarConfigKey, stored: string | string[] | boolean): RenderedValue {\n // REDACTED IN THE MACHINE ENVELOPE TOO, not just in the human line. `config\n // --json` is what an agent reads and what a bug report pastes, and the whole\n // point of a door key is that it opens the door for whoever holds it. What a\n // caller actually needs from this key is whether team mode is on, and\n // set/unset says exactly that. The value is still readable, by the operator,\n // in ~/.tenjin/config.json.\n if (key === 'shelfBypassSecret') {\n return { value: typeof stored === 'string' && stored.length > 0 ? 'set' : 'unset' };\n }\n if (Array.isArray(stored) || typeof stored === 'boolean') return { value: stored };\n if (key === 'maxAutoSpend' || key === 'sessionBudget') return { value: toMoney(stored) };\n if (key === 'sendMaxAmount') {\n // 'unset' is the resolved sentinel for an absent key (send refuses), never\n // a stored value; 'none' is the explicit uncapped opt-in.\n return { value: stored === 'none' || stored === SEND_MAX_UNSET ? stored : toMoney(stored) };\n }\n if (key === 'confirm' && stored.startsWith(CONFIRM_ABOVE)) {\n return { value: stored, threshold: toMoney(stored.slice(CONFIRM_ABOVE.length)) };\n }\n return { value: stored };\n}\n\n/** Per-key edge parsing. Returns the persisted form; throws USAGE on bad input. */\nfunction parseValue(key: ScalarConfigKey, value: string): string | string[] | boolean {\n switch (key) {\n case 'maxAutoSpend':\n case 'sessionBudget':\n return parseUsdToAtomic(value); // throws USAGE on a bad amount\n case 'sendMaxAmount':\n return value === 'none' ? 'none' : parseUsdToAtomic(value);\n case 'confirm':\n return parseConfirm(value);\n case 'allowlistCreators':\n return parseAllowlist(value);\n case 'baseUrl':\n case 'publicShelfUrl':\n case 'rpcUrl':\n return parseHttpUrl(value);\n case 'shelfBypassSecret':\n // A free string: it is whatever Vercel generated. Empty clears it, which\n // is how team mode is turned back off.\n return value.trim();\n case 'evalCohort':\n case 'bazaarPay':\n return parseBoolean(value);\n case 'bazaarRegistries':\n return parseRegistryList(value);\n }\n}\n\n/** \"\" clears to []; comma-split, each entry an absolute http(s) URL. */\nfunction parseRegistryList(value: string): string[] {\n return value\n .split(',')\n .map((entry) => entry.trim())\n .filter((entry) => entry.length > 0)\n .map((entry) => parseHttpUrl(entry));\n}\n\n// on/off ride along with true/false because that is how the CLI's own refusal\n// texts coach these keys (`tenjin config set bazaarPay on`); a coached command\n// that exits USAGE teaches an agent the remediation is broken.\nfunction parseBoolean(value: string): boolean {\n if (value === 'true' || value === 'on') return true;\n if (value === 'false' || value === 'off') return false;\n throw new CliError('USAGE', `Invalid boolean value: ${JSON.stringify(value)}`, {\n fix: 'Use \"on\" or \"off\" (or \"true\"/\"false\").',\n });\n}\n\nfunction parseConfirm(value: string): string {\n if (value === 'always') return 'always';\n if (value.startsWith(CONFIRM_ABOVE)) {\n return `${CONFIRM_ABOVE}${parseUsdToAtomic(value.slice(CONFIRM_ABOVE.length))}`;\n }\n throw new CliError('USAGE', `Invalid confirm value: ${JSON.stringify(value)}`, {\n fix: 'Use \"always\" or \"above:<usd>\", e.g. above:0.25.',\n });\n}\n\nfunction parseAllowlist(value: string): string[] {\n // \"\" clears to []; comma-split, trim, drop empties. Reject an entry with\n // internal whitespace — a creator handle/address is a single token.\n const entries = value\n .split(',')\n .map((entry) => entry.trim())\n .filter((entry) => entry.length > 0);\n for (const entry of entries) {\n if (/\\s/.test(entry)) {\n throw new CliError('USAGE', `Invalid creator entry: ${JSON.stringify(entry)}`, {\n fix: 'Creator entries cannot contain spaces; separate multiple with commas.',\n });\n }\n }\n return entries;\n}\n\nfunction parseHttpUrl(value: string): string {\n let url: URL;\n try {\n url = new URL(value);\n } catch {\n throw new CliError('USAGE', `Invalid URL: ${JSON.stringify(value)}`, {\n fix: `Pass an absolute http(s) URL like ${PRODUCTION_ORIGIN}.`,\n });\n }\n if (url.protocol !== 'http:' && url.protocol !== 'https:') {\n throw new CliError('USAGE', `URL must be http or https: ${JSON.stringify(value)}`, {\n fix: `Pass an absolute http(s) URL like ${PRODUCTION_ORIGIN}.`,\n });\n }\n return value;\n}\n\n/**\n * Apply `merge` to the raw file and write it back atomically. Uses the partial\n * schema and writeFileAtomic (not writeConfig, which would materialize every\n * default into the file and corrupt provenance). loadRawConfig surfaces a\n * corrupt existing file as CONFIG_INVALID, which propagates.\n *\n * The whole read-merge-write runs under a cross-process file lock: without it two\n * concurrent `config set` on different keys race on the read, and the last writer\n * drops the other's update (worst case, a zeroed maxAutoSpend resurrected). The\n * data dir is ensured first so the lock's mkdir has a parent on a fresh install.\n */\nasync function persist(\n dir: string,\n merge: (existing: PartialConfig) => PartialConfig,\n): Promise<void> {\n await mkdir(dir, { recursive: true, mode: 0o700 });\n const lockPath = `${configPath(dir)}.lock`;\n try {\n await withFileLock(lockPath, async () => {\n const existing = await loadRawConfig(dir);\n const merged = merge(existing);\n const validated = RawConfigSchema.parse(merged);\n // 0600, matching lib/config.ts's `writeConfig`: this file holds\n // `shelfBypassSecret`, and this is the writer `config set` uses to put it\n // there. See that function for why dirMode alone is not enough.\n await writeFileAtomic(configPath(dir), `${JSON.stringify(validated, null, 2)}\\n`, {\n mode: 0o600,\n dirMode: 0o700,\n });\n });\n } catch (err) {\n // A lock timeout is not the user's malformed input; surface it as INTERNAL with\n // the one manual step (there is no auto-steal), keeping the JSON error contract.\n if (err instanceof LockTimeoutError) {\n throw new CliError('INTERNAL', err.message, {\n fix: `If no other tenjin process is running, remove ${lockPath} and retry.`,\n cause: err,\n });\n }\n throw err;\n }\n}\n\nfunction formatLine(key: string, entry: RenderedSetting): string {\n const label = key.padEnd(KEY_WIDTH);\n // A router key from a project names its file: which of several is in force is the question.\n const where =\n entry.path !== undefined && (entry.source === 'project' || entry.source === 'local')\n ? ` ${entry.path}`\n : '';\n return ` ${label} ${displayValue(entry)} ${styleText('dim', `(${entry.source}${where})`)}`;\n}\n\n/** The list variant: the value line, a dim description, and an optional dim note. */\nfunction describedLine(key: string, entry: RenderedSetting, note?: string): string {\n const description = KEY_DESCRIPTIONS[key];\n let line = formatLine(key, entry);\n if (description !== undefined) line += ` ${styleText('dim', `- ${description}`)}`;\n return withNote(line, note);\n}\n\n/** Append a dim parenthetical note (e.g. the full-auto downgrade) when present. */\nfunction withNote(line: string, note?: string): string {\n return note !== undefined ? `${line} ${styleText('dim', `(${note})`)}` : line;\n}\n\n/**\n * The `publish.mode` line gains a downgrade note when the effective mode came from\n * a committed `.tenjin.json` asking for `full-auto` (the loosening gate demoted it\n * to `auto`). Human-only; the machine `data` shape is unchanged.\n */\nfunction downgradeNote(key: PublishConfigKey, settings: EffectiveSettings): string | undefined {\n if (key !== 'publish.mode' || settings.publishMode.downgradedWarning === undefined) {\n return undefined;\n }\n return 'downgraded from full-auto: committed .tenjin.json (gitignore it to opt in)';\n}\n\nfunction displayValue(entry: RenderedSetting): string {\n const { value } = entry;\n if (Array.isArray(value)) return value.length > 0 ? value.join(', ') : '(empty)';\n if (typeof value === 'boolean') return value ? 'true' : 'false'; // evalCohort\n if (typeof value === 'object') return `${value.usd} USD`; // Money (spend keys)\n if (entry.threshold !== undefined) return `above ${entry.threshold.usd} USD`; // confirm\n return value; // 'always', baseUrl, rpcUrl\n}\n","import type { Harness, HarnessAdapter } from '../adapters/types';\nimport { registeredHooks } from './harness-hooks';\nimport { detectHarnesses, harnessInPlay, harnessTargetDir, onPath } from './skill-wiring';\n\n/**\n * Is one adapter part of this machine's settled installation?\n *\n * An explicit install selection outranks current detection; homes predating\n * that record fall back to the harness directory/PATH probes. Registered hook\n * entries are final evidence, so config and doctor agree even if the binary or\n * home-directory marker later moves.\n */\nexport async function installedHarnessInPlay(\n adapter: HarnessAdapter,\n home: string,\n dataDir: string,\n options: {\n env?: NodeJS.ProcessEnv;\n which?: (bin: string) => boolean;\n requested?: readonly Harness[];\n } = {},\n): Promise<boolean> {\n const env = options.env ?? process.env;\n const which = options.which ?? ((bin: string) => onPath(bin, env));\n if (\n harnessInPlay(\n home,\n harnessTargetDir(home, adapter.id),\n detectHarnesses(home, which),\n options.requested ?? [],\n )\n ) {\n return true;\n }\n return (await registeredHooks(adapter, home, dataDir, env)).entries > 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,eAAe;AACxB,SAAS,eAAe;AACxB,SAAS,iBAAiB;;;ACS1B,eAAsB,uBACpB,SACA,MACA,SACA,UAII,CAAC,GACa;AAClB,QAAM,MAAM,QAAQ,OAAO,QAAQ;AACnC,QAAM,QAAQ,QAAQ,UAAU,CAAC,QAAgB,OAAO,KAAK,GAAG;AAChE,MACE;AAAA,IACE;AAAA,IACA,iBAAiB,MAAM,QAAQ,EAAE;AAAA,IACjC,gBAAgB,MAAM,KAAK;AAAA,IAC3B,QAAQ,aAAa,CAAC;AAAA,EACxB,GACA;AACA,WAAO;AAAA,EACT;AACA,UAAQ,MAAM,gBAAgB,SAAS,MAA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,KAAK,EAAG,QAAO,MAAM,SAAS,IAAI,MAAM,KAAK,IAAI,IAAI;AACvE,MAAI,OAAO,UAAU,UAAW,QAAO,QAAQ,SAAS;AACxD,MAAI,OAAO,UAAU,SAAU,QAAO,GAAG,MAAM,GAAG;AAClD,MAAI,MAAM,cAAc,OAAW,QAAO,SAAS,MAAM,UAAU,GAAG;AACtE,SAAO;AACT;","names":["settings","entry"]}
|
|
@@ -2,7 +2,7 @@ import { createRequire as __tenjinCreateRequire } from 'node:module'; const requ
|
|
|
2
2
|
import {
|
|
3
3
|
parseConfirmPolicy,
|
|
4
4
|
parseUsdToAtomic
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-U2DZISAH.js";
|
|
6
6
|
import {
|
|
7
7
|
CONFIG_DEFAULTS,
|
|
8
8
|
PRODUCTION_ORIGIN,
|
|
@@ -12,16 +12,16 @@ import {
|
|
|
12
12
|
isSameDeployment,
|
|
13
13
|
loadRawConfig,
|
|
14
14
|
resolveSettings
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-AR7U7BRG.js";
|
|
16
16
|
import {
|
|
17
17
|
CliError
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-JLEF5WHM.js";
|
|
19
19
|
|
|
20
20
|
// src/lib/settings.ts
|
|
21
21
|
import { execFile } from "node:child_process";
|
|
22
22
|
import { readFile, stat } from "node:fs/promises";
|
|
23
23
|
import { homedir } from "node:os";
|
|
24
|
-
import { dirname, join } from "node:path";
|
|
24
|
+
import { basename, dirname, join, resolve, sep } from "node:path";
|
|
25
25
|
function tryOrigin(url) {
|
|
26
26
|
try {
|
|
27
27
|
return new URL(url).origin;
|
|
@@ -128,20 +128,16 @@ function parseProjectPrice(decimalUsd, path) {
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
async function findProjectConfigFile(cwd, deps) {
|
|
131
|
+
const hit = await findNearestProjectFiles(cwd, [PROJECT_CONFIG_FILE], deps);
|
|
132
|
+
return hit?.found[0] ?? null;
|
|
133
|
+
}
|
|
134
|
+
async function findNearestProjectFiles(cwd, names, deps = {}) {
|
|
131
135
|
const homeDir = deps.homeDir ?? homedir();
|
|
132
|
-
const isForeignOwned = deps.isForeignOwned ?? defaultIsForeignOwned;
|
|
133
|
-
const warn = deps.warn ?? ((message) => process.stderr.write(`${message}
|
|
134
|
-
`));
|
|
135
136
|
let dir = cwd;
|
|
136
137
|
for (; ; ) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
warn(`Ignoring ${candidate}: not owned by the current user.`);
|
|
141
|
-
} else {
|
|
142
|
-
return candidate;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
138
|
+
if (dir === homeDir && deps.homeIsProject === false) return null;
|
|
139
|
+
const found = await ownedCandidates(dir, names, deps);
|
|
140
|
+
if (found.length > 0) return { dir, found };
|
|
145
141
|
if (await pathExists(join(dir, ".git"))) return null;
|
|
146
142
|
if (dir === homeDir) return null;
|
|
147
143
|
const parent = dirname(dir);
|
|
@@ -149,6 +145,63 @@ async function findProjectConfigFile(cwd, deps) {
|
|
|
149
145
|
dir = parent;
|
|
150
146
|
}
|
|
151
147
|
}
|
|
148
|
+
async function findAllProjectFiles(cwd, names, deps = {}) {
|
|
149
|
+
const homeDir = deps.homeDir ?? homedir();
|
|
150
|
+
const levels = [];
|
|
151
|
+
let dir = cwd;
|
|
152
|
+
for (; ; ) {
|
|
153
|
+
if (dir === homeDir && deps.homeIsProject === false) return { levels, gitRoot: null };
|
|
154
|
+
const found = await ownedCandidates(dir, names, deps);
|
|
155
|
+
if (found.length > 0) levels.push({ dir, found });
|
|
156
|
+
if (await pathExists(join(dir, ".git"))) return { levels, gitRoot: dir };
|
|
157
|
+
if (dir === homeDir) return { levels, gitRoot: null };
|
|
158
|
+
const parent = dirname(dir);
|
|
159
|
+
if (parent === dir) return { levels, gitRoot: null };
|
|
160
|
+
dir = parent;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async function mainWorktreeOf(gitRoot, homeDir = homedir()) {
|
|
164
|
+
try {
|
|
165
|
+
const dotGit = join(gitRoot, ".git");
|
|
166
|
+
if (!(await stat(dotGit)).isFile()) return null;
|
|
167
|
+
const line = /^gitdir:\s*(.+?)\s*$/m.exec(await readFile(dotGit, "utf8"));
|
|
168
|
+
if (line === null) return null;
|
|
169
|
+
const gitdir = resolve(gitRoot, line[1]);
|
|
170
|
+
const commonDir = resolve(gitdir, (await readFile(join(gitdir, "commondir"), "utf8")).trim());
|
|
171
|
+
if (basename(commonDir) !== ".git" || !(await stat(commonDir)).isDirectory()) return null;
|
|
172
|
+
const main = dirname(commonDir);
|
|
173
|
+
if (main === gitRoot || !main.startsWith(`${homeDir}${sep}`)) return null;
|
|
174
|
+
return main;
|
|
175
|
+
} catch {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async function ownedCandidates(dir, names, deps = {}) {
|
|
180
|
+
const isForeignOwned = deps.isForeignOwned ?? defaultIsForeignOwned;
|
|
181
|
+
const warn = deps.warn ?? ((message) => process.stderr.write(`${message}
|
|
182
|
+
`));
|
|
183
|
+
const found = [];
|
|
184
|
+
for (const name of names) {
|
|
185
|
+
const candidate = join(dir, name);
|
|
186
|
+
if (!await pathExists(candidate)) continue;
|
|
187
|
+
if (await isForeignOwned(candidate)) {
|
|
188
|
+
warn(`Ignoring ${candidate}: not owned by the current user.`);
|
|
189
|
+
} else {
|
|
190
|
+
found.push(candidate);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return found;
|
|
194
|
+
}
|
|
195
|
+
async function projectRoot(cwd, homeDir = homedir()) {
|
|
196
|
+
let dir = cwd;
|
|
197
|
+
for (; ; ) {
|
|
198
|
+
if (await pathExists(join(dir, ".git"))) return dir;
|
|
199
|
+
if (dir === homeDir) return cwd;
|
|
200
|
+
const parent = dirname(dir);
|
|
201
|
+
if (parent === dir) return cwd;
|
|
202
|
+
dir = parent;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
152
205
|
async function defaultIsForeignOwned(filePath) {
|
|
153
206
|
const uid = process.getuid?.();
|
|
154
207
|
if (uid === void 0) return false;
|
|
@@ -167,12 +220,12 @@ async function pathExists(path) {
|
|
|
167
220
|
}
|
|
168
221
|
}
|
|
169
222
|
function defaultIsGitignored(filePath) {
|
|
170
|
-
return new Promise((
|
|
223
|
+
return new Promise((resolve2) => {
|
|
171
224
|
execFile(
|
|
172
225
|
"git",
|
|
173
226
|
["check-ignore", "--quiet", "--", filePath],
|
|
174
227
|
{ cwd: dirname(filePath) },
|
|
175
|
-
(err) =>
|
|
228
|
+
(err) => resolve2(err === null)
|
|
176
229
|
);
|
|
177
230
|
});
|
|
178
231
|
}
|
|
@@ -181,6 +234,11 @@ export {
|
|
|
181
234
|
isTeamShelfOrigin,
|
|
182
235
|
isTeamModeConfig,
|
|
183
236
|
resolveContextSettings,
|
|
184
|
-
loadProjectConfig
|
|
237
|
+
loadProjectConfig,
|
|
238
|
+
findNearestProjectFiles,
|
|
239
|
+
findAllProjectFiles,
|
|
240
|
+
mainWorktreeOf,
|
|
241
|
+
ownedCandidates,
|
|
242
|
+
projectRoot
|
|
185
243
|
};
|
|
186
|
-
//# sourceMappingURL=chunk-
|
|
244
|
+
//# sourceMappingURL=chunk-PDA2BVFY.js.map
|