tenjin-cli 0.1.0-alpha.13 → 0.1.0-alpha.14

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.
Files changed (131) hide show
  1. package/README.md +35 -2
  2. package/dist/{buy-X4VPHFUA.js → buy-2JBYPHAI.js} +16 -14
  3. package/dist/{chunk-6JKD46OJ.js → chunk-3ZW7HPY5.js} +4 -4
  4. package/dist/chunk-4UHNXY6B.js +786 -0
  5. package/dist/chunk-4UHNXY6B.js.map +1 -0
  6. package/dist/{chunk-IFPKA32J.js → chunk-4Y53PDH6.js} +2 -2
  7. package/dist/{chunk-SPUORKD7.js → chunk-54AJIO3E.js} +11 -12
  8. package/dist/chunk-54AJIO3E.js.map +1 -0
  9. package/dist/{chunk-JVBMPU5G.js → chunk-7GJQ5RGA.js} +5 -3
  10. package/dist/{chunk-JVBMPU5G.js.map → chunk-7GJQ5RGA.js.map} +1 -1
  11. package/dist/{chunk-BRAVLUGI.js → chunk-7NADDA2V.js} +9 -6
  12. package/dist/{chunk-BRAVLUGI.js.map → chunk-7NADDA2V.js.map} +1 -1
  13. package/dist/{chunk-T4UWMVKV.js → chunk-ACBEHJAH.js} +4 -4
  14. package/dist/{chunk-XXY77EZJ.js → chunk-DAZAXFSF.js} +7 -7
  15. package/dist/{chunk-OE36HRWG.js → chunk-DTCXO7HS.js} +257 -405
  16. package/dist/chunk-DTCXO7HS.js.map +1 -0
  17. package/dist/{chunk-CA3JV7FX.js → chunk-ETKZWJ4B.js} +2 -2
  18. package/dist/{chunk-CA3JV7FX.js.map → chunk-ETKZWJ4B.js.map} +1 -1
  19. package/dist/{chunk-NKN4YC5C.js → chunk-FDUD3W5V.js} +2 -2
  20. package/dist/{chunk-L4XNT3UW.js → chunk-GEHL43VE.js} +49 -17
  21. package/dist/chunk-GEHL43VE.js.map +1 -0
  22. package/dist/chunk-IU2HVT3Y.js +313 -0
  23. package/dist/chunk-IU2HVT3Y.js.map +1 -0
  24. package/dist/{chunk-OXUJ3FXU.js → chunk-IUQZ4Z7M.js} +36 -8
  25. package/dist/chunk-IUQZ4Z7M.js.map +1 -0
  26. package/dist/{chunk-YMUJZWHB.js → chunk-IXZJ3JOO.js} +5 -5
  27. package/dist/{chunk-47YKYDOF.js → chunk-L6G35FU5.js} +2 -2
  28. package/dist/{chunk-ELVDOTU7.js → chunk-LSWP7MU2.js} +4 -4
  29. package/dist/chunk-LSWP7MU2.js.map +1 -0
  30. package/dist/{chunk-OUJDDY5L.js → chunk-MJSXP4LW.js} +30 -28
  31. package/dist/chunk-MJSXP4LW.js.map +1 -0
  32. package/dist/{chunk-WVHPGQH5.js → chunk-NAAMHWSI.js} +5 -2
  33. package/dist/chunk-NAAMHWSI.js.map +1 -0
  34. package/dist/{chunk-IKAJSA7E.js → chunk-O75FOHXS.js} +29 -11
  35. package/dist/chunk-O75FOHXS.js.map +1 -0
  36. package/dist/{chunk-WMFRCSNC.js → chunk-PCX2JQ2J.js} +3 -3
  37. package/dist/{chunk-IGHSLJUF.js → chunk-PKW3H26Z.js} +5 -5
  38. package/dist/{chunk-3NZCU6SD.js → chunk-PQZVDCCA.js} +4 -4
  39. package/dist/{chunk-OC3EIDCP.js → chunk-QWBUKIP2.js} +7 -1
  40. package/dist/chunk-QWBUKIP2.js.map +1 -0
  41. package/dist/{chunk-FKSAUOJU.js → chunk-UO22YNY4.js} +1 -69
  42. package/dist/chunk-UO22YNY4.js.map +1 -0
  43. package/dist/chunk-VEAERJVJ.js +43 -0
  44. package/dist/chunk-VEAERJVJ.js.map +1 -0
  45. package/dist/{chunk-GCGMXA2O.js → chunk-VRPLZERE.js} +16 -5
  46. package/dist/chunk-VRPLZERE.js.map +1 -0
  47. package/dist/{chunk-IAR25V2E.js → chunk-W4VW5XYB.js} +4 -4
  48. package/dist/chunk-WYLMJQVH.js +240 -0
  49. package/dist/chunk-WYLMJQVH.js.map +1 -0
  50. package/dist/{chunk-TXVC46SA.js → chunk-XVPQGCH4.js} +11 -10
  51. package/dist/chunk-XVPQGCH4.js.map +1 -0
  52. package/dist/chunk-ZOBNS7CX.js +73 -0
  53. package/dist/chunk-ZOBNS7CX.js.map +1 -0
  54. package/dist/{cli-XK5JZWU6.js → cli-U2BEUA55.js} +34 -36
  55. package/dist/{cli-XK5JZWU6.js.map → cli-U2BEUA55.js.map} +1 -1
  56. package/dist/{config-CNK7MYUR.js → config-CNUIX23Q.js} +12 -6
  57. package/dist/{doctor-R7N7FUX5.js → doctor-QJJXRWTO.js} +11 -7
  58. package/dist/{edit-QSUEG7CL.js → edit-HJ44P44P.js} +13 -11
  59. package/dist/{fund-JF6A76YS.js → fund-Y5IAHZ5D.js} +10 -8
  60. package/dist/index.js +1 -1
  61. package/dist/{inspect-NFNAA4LA.js → inspect-NFQ6SQQQ.js} +14 -12
  62. package/dist/{install-YQVM3SUW.js → install-DXX7PVUP.js} +122 -401
  63. package/dist/install-DXX7PVUP.js.map +1 -0
  64. package/dist/outcome-ANV4QIED.js +24 -0
  65. package/dist/{publish-O2I6IAEL.js → publish-PCBTCXCZ.js} +14 -12
  66. package/dist/{read-UF7QVQOU.js → read-W7QVRBVD.js} +14 -12
  67. package/dist/{read-UF7QVQOU.js.map → read-W7QVRBVD.js.map} +1 -1
  68. package/dist/{run-GDZWHNWZ.js → run-CJWPGMIQ.js} +26 -24
  69. package/dist/{run-GDZWHNWZ.js.map → run-CJWPGMIQ.js.map} +1 -1
  70. package/dist/search-JGAVKTYJ.js +25 -0
  71. package/dist/{send-SI254H3R.js → send-C5EOKXOU.js} +7 -6
  72. package/dist/{send-SI254H3R.js.map → send-C5EOKXOU.js.map} +1 -1
  73. package/dist/{session-GJZJEXLJ.js → session-OBCUUIFX.js} +7 -6
  74. package/dist/{session-GJZJEXLJ.js.map → session-OBCUUIFX.js.map} +1 -1
  75. package/dist/{skill-heal-BPFT22XS.js → skill-heal-D6EPLPS6.js} +3 -3
  76. package/dist/skill-heal-D6EPLPS6.js.map +1 -0
  77. package/dist/{uninstall-7ZZG6WQ5.js → uninstall-OWJNJ5LI.js} +11 -5
  78. package/dist/uninstall-OWJNJ5LI.js.map +1 -0
  79. package/dist/{update-FPSBITLB.js → update-24Y2CQTT.js} +16 -13
  80. package/dist/update-24Y2CQTT.js.map +1 -0
  81. package/dist/{wallet-TZVD2M4I.js → wallet-OFXDIIGP.js} +7 -6
  82. package/dist/{wallet-NS7TYWNN.js → wallet-SLRIYJ2U.js} +4 -3
  83. package/docs/agent-permissions.md +100 -16
  84. package/docs/command-reference.md +21 -11
  85. package/package.json +1 -1
  86. package/skills/tenjin-publish/SKILL.md +181 -205
  87. package/skills/tenjin-publish/references/maintain.md +39 -0
  88. package/skills/tenjin-search/SKILL.md +86 -279
  89. package/skills/tenjin-search/references/permissions.md +106 -0
  90. package/dist/chunk-ELVDOTU7.js.map +0 -1
  91. package/dist/chunk-FKSAUOJU.js.map +0 -1
  92. package/dist/chunk-GCGMXA2O.js.map +0 -1
  93. package/dist/chunk-IKAJSA7E.js.map +0 -1
  94. package/dist/chunk-L4XNT3UW.js.map +0 -1
  95. package/dist/chunk-OC3EIDCP.js.map +0 -1
  96. package/dist/chunk-OE36HRWG.js.map +0 -1
  97. package/dist/chunk-OUJDDY5L.js.map +0 -1
  98. package/dist/chunk-OXUJ3FXU.js.map +0 -1
  99. package/dist/chunk-SPUORKD7.js.map +0 -1
  100. package/dist/chunk-TXVC46SA.js.map +0 -1
  101. package/dist/chunk-UUARTUY2.js +0 -349
  102. package/dist/chunk-UUARTUY2.js.map +0 -1
  103. package/dist/chunk-WVHPGQH5.js.map +0 -1
  104. package/dist/install-YQVM3SUW.js.map +0 -1
  105. package/dist/outcome-IUSYFJTN.js +0 -22
  106. package/dist/search-JVOHEF3E.js +0 -23
  107. package/dist/skill-heal-BPFT22XS.js.map +0 -1
  108. package/dist/uninstall-7ZZG6WQ5.js.map +0 -1
  109. package/dist/update-FPSBITLB.js.map +0 -1
  110. /package/dist/{buy-X4VPHFUA.js.map → buy-2JBYPHAI.js.map} +0 -0
  111. /package/dist/{chunk-6JKD46OJ.js.map → chunk-3ZW7HPY5.js.map} +0 -0
  112. /package/dist/{chunk-IFPKA32J.js.map → chunk-4Y53PDH6.js.map} +0 -0
  113. /package/dist/{chunk-T4UWMVKV.js.map → chunk-ACBEHJAH.js.map} +0 -0
  114. /package/dist/{chunk-XXY77EZJ.js.map → chunk-DAZAXFSF.js.map} +0 -0
  115. /package/dist/{chunk-NKN4YC5C.js.map → chunk-FDUD3W5V.js.map} +0 -0
  116. /package/dist/{chunk-YMUJZWHB.js.map → chunk-IXZJ3JOO.js.map} +0 -0
  117. /package/dist/{chunk-47YKYDOF.js.map → chunk-L6G35FU5.js.map} +0 -0
  118. /package/dist/{chunk-WMFRCSNC.js.map → chunk-PCX2JQ2J.js.map} +0 -0
  119. /package/dist/{chunk-IGHSLJUF.js.map → chunk-PKW3H26Z.js.map} +0 -0
  120. /package/dist/{chunk-3NZCU6SD.js.map → chunk-PQZVDCCA.js.map} +0 -0
  121. /package/dist/{chunk-IAR25V2E.js.map → chunk-W4VW5XYB.js.map} +0 -0
  122. /package/dist/{config-CNK7MYUR.js.map → config-CNUIX23Q.js.map} +0 -0
  123. /package/dist/{doctor-R7N7FUX5.js.map → doctor-QJJXRWTO.js.map} +0 -0
  124. /package/dist/{edit-QSUEG7CL.js.map → edit-HJ44P44P.js.map} +0 -0
  125. /package/dist/{fund-JF6A76YS.js.map → fund-Y5IAHZ5D.js.map} +0 -0
  126. /package/dist/{inspect-NFNAA4LA.js.map → inspect-NFQ6SQQQ.js.map} +0 -0
  127. /package/dist/{outcome-IUSYFJTN.js.map → outcome-ANV4QIED.js.map} +0 -0
  128. /package/dist/{publish-O2I6IAEL.js.map → publish-PCBTCXCZ.js.map} +0 -0
  129. /package/dist/{search-JVOHEF3E.js.map → search-JGAVKTYJ.js.map} +0 -0
  130. /package/dist/{wallet-NS7TYWNN.js.map → wallet-OFXDIIGP.js.map} +0 -0
  131. /package/dist/{wallet-TZVD2M4I.js.map → wallet-SLRIYJ2U.js.map} +0 -0
@@ -0,0 +1,786 @@
1
+ import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ LockTimeoutError,
4
+ withFileLock
5
+ } from "./chunk-ZOBNS7CX.js";
6
+ import {
7
+ modeGatedPointer
8
+ } from "./chunk-IUQZ4Z7M.js";
9
+ import {
10
+ loadProjectConfig
11
+ } from "./chunk-PKW3H26Z.js";
12
+ import {
13
+ parseUsdToAtomic,
14
+ toMoney
15
+ } from "./chunk-736DW4V3.js";
16
+ import {
17
+ STOP_HOOK_FILE,
18
+ WEBSEARCH_HOOK_FILE,
19
+ stopHookScript,
20
+ websearchHookScript
21
+ } from "./chunk-DTCXO7HS.js";
22
+ import {
23
+ MODE_GATED_RULES,
24
+ claudeSettingsPath,
25
+ inspectFreeVerbRules,
26
+ retractModeGatedRules,
27
+ wireFreeVerbAllowlist
28
+ } from "./chunk-IU2HVT3Y.js";
29
+ import {
30
+ CONFIG_KEYS,
31
+ HOOKS_CONFIG_KEYS,
32
+ PUBLISH_CONFIG_KEYS,
33
+ PublishModeSchema,
34
+ RawConfigSchema,
35
+ SEND_MAX_UNSET,
36
+ UPDATE_CONFIG_KEYS,
37
+ loadRawConfig,
38
+ parseSearchHookModeFlag,
39
+ parseStopNagFlag,
40
+ parseUpdateModeFlag,
41
+ resolveSettings
42
+ } from "./chunk-LSWP7MU2.js";
43
+ import {
44
+ configPath,
45
+ hooksDir
46
+ } from "./chunk-ZQIQ55KK.js";
47
+ import {
48
+ detectHarnesses,
49
+ harnessInPlay,
50
+ harnessTargetDir,
51
+ onPath
52
+ } from "./chunk-QWBUKIP2.js";
53
+ import {
54
+ CliError,
55
+ writeFileAtomic
56
+ } from "./chunk-PAOVPSP6.js";
57
+
58
+ // src/commands/config.ts
59
+ import { mkdir } from "fs/promises";
60
+ import { homedir } from "os";
61
+ import { styleText } from "util";
62
+
63
+ // src/lib/clack.ts
64
+ var SHOW_CURSOR = "\x1B[?25h";
65
+ function withInputEnd(streams, onEnd, run) {
66
+ const controller = new AbortController();
67
+ let settleEnd;
68
+ const ended = new Promise((resolve) => {
69
+ settleEnd = () => {
70
+ streams.output.write(SHOW_CURSOR);
71
+ resolve(onEnd);
72
+ };
73
+ });
74
+ const end = () => {
75
+ controller.abort();
76
+ settleEnd?.();
77
+ };
78
+ const onKeypress = (_text, key) => {
79
+ if (key?.ctrl === true && key.name === "d") end();
80
+ };
81
+ streams.input.on("keypress", onKeypress);
82
+ if (streams.input.readableEnded) {
83
+ queueMicrotask(end);
84
+ } else {
85
+ streams.input.once("end", end);
86
+ streams.input.once("close", end);
87
+ }
88
+ return Promise.race([run(controller.signal), ended]).finally(() => {
89
+ streams.input.off("keypress", onKeypress);
90
+ streams.input.off("end", end);
91
+ streams.input.off("close", end);
92
+ });
93
+ }
94
+ function resolveStreams(streams) {
95
+ return { input: streams.input ?? process.stdin, output: streams.output ?? process.stderr };
96
+ }
97
+ async function selectOne(opts) {
98
+ const { select, isCancel } = await import("./dist-U4M6QCKE.js");
99
+ const streams = resolveStreams(opts.streams ?? {});
100
+ return withInputEnd(streams, null, async (signal) => {
101
+ const answer = await select({
102
+ message: opts.message,
103
+ options: opts.choices.map((c) => ({
104
+ value: c.value,
105
+ label: c.label,
106
+ ...c.hint !== void 0 ? { hint: c.hint } : {}
107
+ })),
108
+ initialValue: opts.initialValue,
109
+ input: streams.input,
110
+ output: streams.output,
111
+ signal
112
+ });
113
+ return isCancel(answer) ? null : answer;
114
+ });
115
+ }
116
+ async function confirmChoice(message, initialValue = true, streams = {}) {
117
+ const { confirm, isCancel } = await import("./dist-U4M6QCKE.js");
118
+ const resolved = resolveStreams(streams);
119
+ return withInputEnd(resolved, false, async (signal) => {
120
+ const answer = await confirm({
121
+ message,
122
+ initialValue,
123
+ input: resolved.input,
124
+ output: resolved.output,
125
+ signal
126
+ });
127
+ return isCancel(answer) ? false : answer;
128
+ });
129
+ }
130
+ async function intro(message) {
131
+ const clack = await import("./dist-U4M6QCKE.js");
132
+ clack.intro(message, { output: process.stderr });
133
+ }
134
+ async function outro(message) {
135
+ const clack = await import("./dist-U4M6QCKE.js");
136
+ clack.outro(message, { output: process.stderr });
137
+ }
138
+
139
+ // src/lib/harness-hooks.ts
140
+ import { lstat, readFile, realpath } from "fs/promises";
141
+ import { join } from "path";
142
+ var WEBSEARCH_MATCHER = "WebSearch";
143
+ var HOOK_TIMEOUT_SECONDS = 5;
144
+ function hooksUndo(settingsPath, scriptsDir) {
145
+ return `Undo anytime: \`tenjin config set hooks.searchMode off\` disarms them, or delete the tenjin hook entries from ${settingsPath} and the scripts in ${scriptsDir}.`;
146
+ }
147
+ function skip(reason, args) {
148
+ return {
149
+ harness: args.harness,
150
+ ...args.path !== void 0 ? { path: args.path } : {},
151
+ scriptsDir: args.scriptsDir,
152
+ mode: args.mode,
153
+ added: [],
154
+ alreadyPresent: [],
155
+ updated: [],
156
+ scripts: [],
157
+ skipped: reason,
158
+ ...args.warning !== void 0 ? { warning: args.warning } : {},
159
+ ...args.fix !== void 0 ? { fix: args.fix } : {}
160
+ };
161
+ }
162
+ function hooksSkipped(harness, homeDir, dataDir, mode, reason) {
163
+ return skip(reason, {
164
+ harness,
165
+ ...harness === "claude" ? { path: claudeSettingsPath(homeDir) } : {},
166
+ scriptsDir: hooksDir(dataDir),
167
+ mode,
168
+ fix: fixFor(reason)
169
+ });
170
+ }
171
+ function fixFor(reason) {
172
+ switch (reason) {
173
+ case "harness-not-claude":
174
+ return "Hooks are wired for Claude Code only. Re-run `tenjin install --harness claude` on a machine with Claude Code.";
175
+ case "mode-off":
176
+ return "Enable them with `tenjin config set hooks.searchMode auto`, then re-run `tenjin install`.";
177
+ case "declined":
178
+ case "dry-run":
179
+ return "Wire them with `tenjin install --search-hooks auto`.";
180
+ case "changed-since-read":
181
+ return "Another process changed the file mid-run; re-run `tenjin install`.";
182
+ default:
183
+ return "Fix the reported file, then re-run `tenjin install --search-hooks auto`.";
184
+ }
185
+ }
186
+ function isPlainObject(value) {
187
+ return typeof value === "object" && value !== null && !Array.isArray(value);
188
+ }
189
+ function quoteForShell(path, platform = process.platform) {
190
+ if (platform === "win32") return `"${path}"`;
191
+ return `'${path.replaceAll("'", `'\\''`)}'`;
192
+ }
193
+ function commandFor(scriptPath, platform) {
194
+ return `node ${quoteForShell(scriptPath, platform)}`;
195
+ }
196
+ function handlerFor(scriptPath, platform) {
197
+ return {
198
+ type: "command",
199
+ command: commandFor(scriptPath, platform),
200
+ timeout: HOOK_TIMEOUT_SECONDS
201
+ };
202
+ }
203
+ function ownsEntry(entry, scriptFile) {
204
+ if (!isPlainObject(entry)) return false;
205
+ const handlers = entry.hooks;
206
+ if (!Array.isArray(handlers)) return false;
207
+ return handlers.some(
208
+ (h) => isPlainObject(h) && typeof h.command === "string" && h.command.includes(scriptFile)
209
+ );
210
+ }
211
+ function specs(dataDir) {
212
+ return [
213
+ {
214
+ event: "PreToolUse",
215
+ scriptFile: WEBSEARCH_HOOK_FILE,
216
+ script: websearchHookScript(dataDir),
217
+ matcher: WEBSEARCH_MATCHER
218
+ },
219
+ { event: "Stop", scriptFile: STOP_HOOK_FILE, script: stopHookScript(dataDir) }
220
+ ];
221
+ }
222
+ async function stopHookIsCurrent(dataDir) {
223
+ const spec = specs(dataDir).find((h) => h.scriptFile === STOP_HOOK_FILE);
224
+ if (spec === void 0) return true;
225
+ const path = join(hooksDir(dataDir), STOP_HOOK_FILE);
226
+ const onDisk = await readFile(path, "utf8").catch(() => null);
227
+ return onDisk === null || onDisk === spec.script;
228
+ }
229
+ async function wireSearchHooks(opts) {
230
+ const { homeDir, dataDir, mode, platform } = opts;
231
+ const scriptsDir = hooksDir(dataDir);
232
+ const plan = specs(dataDir);
233
+ const found = await inspectSettings(homeDir, scriptsDir, mode);
234
+ if ("result" in found) return found.result;
235
+ const { path, raw, settings, hooks } = found;
236
+ const added = [];
237
+ const alreadyPresent = [];
238
+ const updated = [];
239
+ const nextHooks = { ...hooks };
240
+ for (const spec of plan) {
241
+ const existing = hooks[spec.event];
242
+ if (existing !== void 0 && !Array.isArray(existing)) {
243
+ return refuse(
244
+ path,
245
+ scriptsDir,
246
+ mode,
247
+ "unexpected-shape",
248
+ `${path} has a "hooks.${spec.event}" key that is not an array; it was left exactly as it is.`
249
+ );
250
+ }
251
+ const list = existing ?? [];
252
+ const desired = {
253
+ ...spec.matcher !== void 0 ? { matcher: spec.matcher } : {},
254
+ hooks: [handlerFor(join(scriptsDir, spec.scriptFile), platform)]
255
+ };
256
+ const idx = list.findIndex((e) => ownsEntry(e, spec.scriptFile));
257
+ if (idx === -1) {
258
+ nextHooks[spec.event] = [...list, desired];
259
+ added.push(spec.event);
260
+ continue;
261
+ }
262
+ if (JSON.stringify(list[idx]) === JSON.stringify(desired)) {
263
+ alreadyPresent.push(spec.event);
264
+ continue;
265
+ }
266
+ nextHooks[spec.event] = list.map((e, i) => i === idx ? desired : e);
267
+ updated.push(spec.event);
268
+ }
269
+ if (added.length === 0 && updated.length === 0) {
270
+ const scripts2 = await writeScripts(plan, scriptsDir);
271
+ return { harness: "claude", path, scriptsDir, mode, added, alreadyPresent, updated, scripts: scripts2 };
272
+ }
273
+ const next = { ...settings, hooks: nextHooks };
274
+ const changed = async () => await readFile(path, "utf8").catch(() => null) !== raw;
275
+ if (await changed()) return refuseChanged(path, scriptsDir, mode, []);
276
+ const scripts = await writeScripts(plan, scriptsDir);
277
+ if (await changed()) return refuseChanged(path, scriptsDir, mode, scripts);
278
+ await writeFileAtomic(path, `${JSON.stringify(next, null, 2)}
279
+ `);
280
+ return { harness: "claude", path, scriptsDir, mode, added, alreadyPresent, updated, scripts };
281
+ }
282
+ function refuseChanged(path, scriptsDir, mode, scripts) {
283
+ return {
284
+ ...refuse(
285
+ path,
286
+ scriptsDir,
287
+ mode,
288
+ "changed-since-read",
289
+ `${path} changed while it was being updated, so no hooks were registered. Re-run \`tenjin install\`.`
290
+ ),
291
+ scripts
292
+ };
293
+ }
294
+ async function writeScripts(plan, scriptsDir) {
295
+ const written = [];
296
+ for (const spec of plan) {
297
+ const target = join(scriptsDir, spec.scriptFile);
298
+ const onDisk = await readFile(target, "utf8").catch(() => null);
299
+ if (onDisk === spec.script) continue;
300
+ await writeFileAtomic(target, spec.script, { mode: 493, dirMode: 448 });
301
+ written.push(target);
302
+ }
303
+ return written;
304
+ }
305
+ function refuse(path, scriptsDir, mode, reason, warning) {
306
+ return skip(reason, { harness: "claude", path, scriptsDir, mode, warning, fix: fixFor(reason) });
307
+ }
308
+ async function inspectSettings(homeDir, scriptsDir, mode) {
309
+ const declaredPath = claudeSettingsPath(homeDir);
310
+ const entry = await lstat(declaredPath).catch(() => null);
311
+ let path = declaredPath;
312
+ if (entry !== null) {
313
+ try {
314
+ path = await realpath(declaredPath);
315
+ } catch (err) {
316
+ return {
317
+ result: refuse(
318
+ declaredPath,
319
+ scriptsDir,
320
+ mode,
321
+ "unresolvable",
322
+ `${declaredPath} could not be resolved (${err.message}); it was left exactly as it is.`
323
+ )
324
+ };
325
+ }
326
+ }
327
+ let settings = {};
328
+ let raw = null;
329
+ if (entry !== null) {
330
+ try {
331
+ raw = await readFile(path, "utf8");
332
+ } catch (err) {
333
+ return {
334
+ result: refuse(
335
+ path,
336
+ scriptsDir,
337
+ mode,
338
+ "unreadable",
339
+ `${path} could not be read (${err.message}); no hooks were registered.`
340
+ )
341
+ };
342
+ }
343
+ let parsed;
344
+ try {
345
+ parsed = JSON.parse(raw);
346
+ } catch (err) {
347
+ return {
348
+ result: refuse(
349
+ path,
350
+ scriptsDir,
351
+ mode,
352
+ "unparsable",
353
+ `${path} is not valid JSON (${err.message}); it was left exactly as it is.`
354
+ )
355
+ };
356
+ }
357
+ if (!isPlainObject(parsed)) {
358
+ return {
359
+ result: refuse(
360
+ path,
361
+ scriptsDir,
362
+ mode,
363
+ "unexpected-shape",
364
+ `${path} is not a JSON object; it was left exactly as it is.`
365
+ )
366
+ };
367
+ }
368
+ settings = parsed;
369
+ }
370
+ const hooksValue = settings.hooks;
371
+ if (hooksValue !== void 0 && !isPlainObject(hooksValue)) {
372
+ return {
373
+ result: refuse(
374
+ path,
375
+ scriptsDir,
376
+ mode,
377
+ "unexpected-shape",
378
+ `${path} has a "hooks" key that is not an object; it was left exactly as it is.`
379
+ )
380
+ };
381
+ }
382
+ return { path, raw, settings, hooks: hooksValue ?? {} };
383
+ }
384
+
385
+ // src/commands/config.ts
386
+ var CONFIRM_ABOVE = "above:";
387
+ var KEY_WIDTH = Math.max(
388
+ ...[...CONFIG_KEYS, ...PUBLISH_CONFIG_KEYS, ...HOOKS_CONFIG_KEYS, ...UPDATE_CONFIG_KEYS].map(
389
+ (key) => key.length
390
+ )
391
+ );
392
+ var KEY_DESCRIPTIONS = {
393
+ maxAutoSpend: "auto-approve a read up to this amount",
394
+ sessionBudget: "cap on total auto-spend per session",
395
+ confirm: "when to ask before paying",
396
+ sendMaxAmount: "hard cap per tenjin send; unset = send refuses until set, 0 disables send, none = uncapped; never bypassed by --yes",
397
+ allowlistCreators: "only auto-pay these creators (empty = any)",
398
+ baseUrl: "Tenjin API base URL",
399
+ rpcUrl: "Base RPC endpoint for balance reads",
400
+ evalCohort: "opt in to the search evaluation cohort",
401
+ "publish.mode": "review=always ask, auto=ask on findings, full-auto=only hard blocks stop it",
402
+ "publish.defaultPrice": "price used when none is given",
403
+ "hooks.searchMode": "harness WebSearch hook: auto=ask Tenjin first, remind=static reminder, off=inert",
404
+ "hooks.stopNag": "end-of-turn reminder about searches nothing answered yet: on=both arms, deliberate-only=drop the batched web-search arm, off=neither",
405
+ "update.mode": "nudge=report a newer version (stderr line, JSON envelope, hook output), off=neither report nor ask npm"
406
+ };
407
+ function isPublishKey(key) {
408
+ return PUBLISH_CONFIG_KEYS.includes(key);
409
+ }
410
+ function isHooksKey(key) {
411
+ return HOOKS_CONFIG_KEYS.includes(key);
412
+ }
413
+ function isUpdateKey(key) {
414
+ return UPDATE_CONFIG_KEYS.includes(key);
415
+ }
416
+ async function runConfigList(ctx) {
417
+ const settings = await resolveFromContext(ctx);
418
+ const data = {};
419
+ const humanLines = [];
420
+ for (const key of CONFIG_KEYS) {
421
+ const entry = renderSetting(key, settings[key].value, settings[key].source);
422
+ data[key] = entry;
423
+ humanLines.push(describedLine(key, entry));
424
+ }
425
+ for (const key of PUBLISH_CONFIG_KEYS) {
426
+ const entry = renderPublishSetting(key, settings);
427
+ data[key] = entry;
428
+ humanLines.push(describedLine(key, entry, downgradeNote(key, settings)));
429
+ }
430
+ for (const key of HOOKS_CONFIG_KEYS) {
431
+ const entry = renderHooksSetting(key, settings);
432
+ data[key] = entry;
433
+ humanLines.push(describedLine(key, entry));
434
+ }
435
+ for (const key of UPDATE_CONFIG_KEYS) {
436
+ const entry = {
437
+ value: settings.updateMode.value,
438
+ source: settings.updateMode.source
439
+ };
440
+ data[key] = entry;
441
+ humanLines.push(describedLine(key, entry));
442
+ }
443
+ return { data, humanLines };
444
+ }
445
+ async function runConfigGet({ key }, ctx) {
446
+ if (isPublishKey(key)) {
447
+ const settings2 = await resolveFromContext(ctx);
448
+ const entry2 = renderPublishSetting(key, settings2);
449
+ return {
450
+ data: { key, ...entry2 },
451
+ humanLines: [withNote(formatLine(key, entry2), downgradeNote(key, settings2))]
452
+ };
453
+ }
454
+ if (isHooksKey(key)) {
455
+ const entry2 = renderHooksSetting(key, await resolveFromContext(ctx));
456
+ return { data: { key, ...entry2 }, humanLines: [formatLine(key, entry2)] };
457
+ }
458
+ if (isUpdateKey(key)) {
459
+ const { updateMode } = await resolveFromContext(ctx);
460
+ const entry2 = { value: updateMode.value, source: updateMode.source };
461
+ return { data: { key, ...entry2 }, humanLines: [formatLine(key, entry2)] };
462
+ }
463
+ const configKey = assertKey(key);
464
+ const settings = await resolveFromContext(ctx);
465
+ const entry = renderSetting(configKey, settings[configKey].value, settings[configKey].source);
466
+ return { data: { key: configKey, ...entry }, humanLines: [formatLine(configKey, entry)] };
467
+ }
468
+ async function runConfigSet({ key, value }, ctx, deps = {}) {
469
+ if (isPublishKey(key)) return setPublishKey(key, value, ctx, deps);
470
+ if (isHooksKey(key)) return setHooksKey(key, value, ctx, deps);
471
+ if (isUpdateKey(key)) return setUpdateKey(key, value, ctx);
472
+ const configKey = assertKey(key);
473
+ const stored = parseValue(configKey, value);
474
+ await persist(ctx.dataDir, (existing) => ({ ...existing, [configKey]: stored }));
475
+ const entry = renderSetting(configKey, stored, "file");
476
+ return { data: { key: configKey, ...entry }, humanLines: [formatLine(configKey, entry)] };
477
+ }
478
+ async function setPublishKey(key, value, ctx, deps) {
479
+ const entry = key === "publish.mode" ? { value: parsePublishMode(value), source: "file" } : { value: toMoney(parseUsdToAtomic(value)), source: "file" };
480
+ const subkey = key === "publish.mode" ? "mode" : "defaultPrice";
481
+ const stored = key === "publish.mode" ? entry.value : entry.value.atomic;
482
+ await persist(ctx.dataDir, (existing) => ({
483
+ ...existing,
484
+ publish: { ...existing.publish, [subkey]: stored }
485
+ }));
486
+ const humanLines = [formatLine(key, entry)];
487
+ if (key !== "publish.mode") return { data: { key, ...entry }, humanLines };
488
+ const allowlist = await syncPublishRule(entry.value, ctx, deps);
489
+ return {
490
+ data: { key, ...entry, allowlist },
491
+ humanLines: [...humanLines, ...allowlistLines(allowlist)]
492
+ };
493
+ }
494
+ function publishRuleQuestion(mode, pending) {
495
+ const gated = new Set(MODE_GATED_RULES);
496
+ const others = pending.filter((rule) => !gated.has(rule)).length;
497
+ const also = others > 0 ? ` Also adds the ${others} free-verb rule(s) \`tenjin install\` writes.` : "";
498
+ return `publish.mode ${mode} is unattended only if your harness allowlist carries ${MODE_GATED_RULES.join(" and ")}. Add them to ~/.claude/settings.json now?${also}`;
499
+ }
500
+ async function syncPublishRule(mode, ctx, deps) {
501
+ const home = deps.homeDir ?? homedir();
502
+ const nothing = { added: [], removed: [] };
503
+ const write = async () => {
504
+ const result = await (deps.wireAllowlist ?? wireFreeVerbAllowlist)(home, mode);
505
+ if (result.skipped !== void 0) {
506
+ return {
507
+ added: [],
508
+ removed: [],
509
+ skipped: "unwritable",
510
+ ...result.fix !== void 0 ? { pointer: result.fix } : {}
511
+ };
512
+ }
513
+ return { added: result.added, removed: result.removed };
514
+ };
515
+ const isClaude = deps.harnessIsClaude ?? await claudeInPlay(home, ctx, deps);
516
+ if (!isClaude) {
517
+ return { ...nothing, skipped: "not-claude" };
518
+ }
519
+ const probe = await (deps.inspectAllowlist ?? inspectFreeVerbRules)(home, mode);
520
+ const gated = new Set(MODE_GATED_RULES);
521
+ const missing = (probe.pending ?? []).filter((r) => gated.has(r));
522
+ const pointer = modeGatedPointer(mode, missing) ?? void 0;
523
+ if (mode === "review") {
524
+ const retracted = await (deps.retractModeGated ?? retractModeGatedRules)(home);
525
+ if (retracted.skipped !== void 0) {
526
+ return {
527
+ ...nothing,
528
+ skipped: "unwritable",
529
+ ...retracted.fix !== void 0 ? { pointer: retracted.fix } : {}
530
+ };
531
+ }
532
+ return { added: [], removed: retracted.removed };
533
+ }
534
+ if (probe.satisfied !== void 0) return nothing;
535
+ const canPrompt = ctx.flags.json === true ? false : deps.isInteractive ?? Boolean(process.stdin.isTTY);
536
+ if (!canPrompt) return { ...nothing, skipped: "no-tty", ...pointer ? { pointer } : {} };
537
+ const confirm = deps.confirmRule ?? ((label) => confirmChoice(label, true));
538
+ if (!await confirm(publishRuleQuestion(mode, probe.pending ?? []))) {
539
+ return { ...nothing, skipped: "declined", ...pointer ? { pointer } : {} };
540
+ }
541
+ return write();
542
+ }
543
+ async function claudeInPlay(home, ctx, deps) {
544
+ const env = deps.env ?? process.env;
545
+ const which = deps.which ?? ((bin) => onPath(bin, env));
546
+ const requested = await loadRawConfig(ctx.dataDir).then((c) => c.install?.harness ?? []).catch(() => []);
547
+ return harnessInPlay(
548
+ home,
549
+ harnessTargetDir(home, "claude"),
550
+ detectHarnesses(home, which),
551
+ requested
552
+ );
553
+ }
554
+ function allowlistLines(sync) {
555
+ const lines = [];
556
+ if (sync.added.length > 0) {
557
+ lines.push(`Added ${sync.added.length} harness rule(s) to your allowlist.`);
558
+ }
559
+ if (sync.removed.length > 0) {
560
+ lines.push(`Removed ${sync.removed.join(", ")} from your allowlist.`);
561
+ }
562
+ if (sync.pointer !== void 0) lines.push(sync.pointer);
563
+ return lines;
564
+ }
565
+ async function setHooksKey(key, value, ctx, deps) {
566
+ const subkey = key === "hooks.searchMode" ? "searchMode" : "stopNag";
567
+ const parsed = key === "hooks.searchMode" ? parseSearchHookModeFlag(value, key) : parseStopNagFlag(value, key);
568
+ await persist(ctx.dataDir, (existing) => ({
569
+ ...existing,
570
+ hooks: { ...existing.hooks, [subkey]: parsed }
571
+ }));
572
+ const entry = { value: parsed, source: "file" };
573
+ const current = await (deps.stopHookIsCurrent ?? stopHookIsCurrent)(ctx.dataDir);
574
+ const stale = parsed === "deliberate-only" && !current ? `The installed Stop hook predates ${JSON.stringify(parsed)} and will keep treating it as "on". Run \`tenjin install\` to update it.` : void 0;
575
+ return {
576
+ data: { key, ...entry, ...stale !== void 0 ? { hookScriptStale: true } : {} },
577
+ humanLines: [formatLine(key, entry), ...stale !== void 0 ? [stale] : []]
578
+ };
579
+ }
580
+ async function setUpdateKey(key, value, ctx) {
581
+ const parsed = parseUpdateModeFlag(value, key);
582
+ await persist(ctx.dataDir, (existing) => ({
583
+ ...existing,
584
+ update: { ...existing.update, mode: parsed }
585
+ }));
586
+ const entry = { value: parsed, source: "file" };
587
+ return { data: { key, ...entry }, humanLines: [formatLine(key, entry)] };
588
+ }
589
+ function parsePublishMode(value) {
590
+ const parsed = PublishModeSchema.safeParse(value);
591
+ if (parsed.success) return parsed.data;
592
+ throw new CliError("USAGE", `Invalid publish mode: ${JSON.stringify(value)}`, {
593
+ fix: 'Use "review", "auto", or "full-auto".'
594
+ });
595
+ }
596
+ async function persistPublishMode(dir, mode) {
597
+ await persist(dir, (existing) => ({
598
+ ...existing,
599
+ publish: { ...existing.publish, mode }
600
+ }));
601
+ }
602
+ async function persistSearchHookMode(dir, mode) {
603
+ await persist(dir, (existing) => ({
604
+ ...existing,
605
+ hooks: { ...existing.hooks, searchMode: mode }
606
+ }));
607
+ }
608
+ async function persistInstallHarness(dir, harness) {
609
+ await persist(dir, (existing) => ({
610
+ ...existing,
611
+ install: { ...existing.install, harness: [...harness] }
612
+ }));
613
+ }
614
+ async function resolveFromContext(ctx) {
615
+ const config = await loadRawConfig(ctx.dataDir);
616
+ const project = await loadProjectConfig(process.cwd());
617
+ return resolveSettings({
618
+ config,
619
+ flags: { baseUrl: ctx.flags.baseUrl },
620
+ env: process.env,
621
+ project: project?.layer
622
+ });
623
+ }
624
+ function assertKey(key) {
625
+ if (CONFIG_KEYS.includes(key)) return key;
626
+ throw new CliError("USAGE", `Unknown config key: ${JSON.stringify(key)}`, {
627
+ fix: `Valid keys: ${[...CONFIG_KEYS, ...PUBLISH_CONFIG_KEYS, ...HOOKS_CONFIG_KEYS].join(", ")}.`
628
+ });
629
+ }
630
+ function renderSetting(key, stored, source) {
631
+ return { ...renderValue(key, stored), source };
632
+ }
633
+ function renderPublishSetting(key, settings) {
634
+ if (key === "publish.mode") {
635
+ return { value: settings.publishMode.value, source: settings.publishMode.source };
636
+ }
637
+ return {
638
+ value: toMoney(settings.publishDefaultPrice.value),
639
+ source: settings.publishDefaultPrice.source
640
+ };
641
+ }
642
+ function renderHooksSetting(key, settings) {
643
+ const resolved = key === "hooks.searchMode" ? settings.hooksSearchMode : settings.hooksStopNag;
644
+ return { value: resolved.value, source: resolved.source };
645
+ }
646
+ function renderValue(key, stored) {
647
+ if (Array.isArray(stored) || typeof stored === "boolean") return { value: stored };
648
+ if (key === "maxAutoSpend" || key === "sessionBudget") return { value: toMoney(stored) };
649
+ if (key === "sendMaxAmount") {
650
+ return { value: stored === "none" || stored === SEND_MAX_UNSET ? stored : toMoney(stored) };
651
+ }
652
+ if (key === "confirm" && stored.startsWith(CONFIRM_ABOVE)) {
653
+ return { value: stored, threshold: toMoney(stored.slice(CONFIRM_ABOVE.length)) };
654
+ }
655
+ return { value: stored };
656
+ }
657
+ function parseValue(key, value) {
658
+ switch (key) {
659
+ case "maxAutoSpend":
660
+ case "sessionBudget":
661
+ return parseUsdToAtomic(value);
662
+ // throws USAGE on a bad amount
663
+ case "sendMaxAmount":
664
+ return value === "none" ? "none" : parseUsdToAtomic(value);
665
+ case "confirm":
666
+ return parseConfirm(value);
667
+ case "allowlistCreators":
668
+ return parseAllowlist(value);
669
+ case "baseUrl":
670
+ case "rpcUrl":
671
+ return parseHttpUrl(value);
672
+ case "evalCohort":
673
+ return parseBoolean(value);
674
+ }
675
+ }
676
+ function parseBoolean(value) {
677
+ if (value === "true") return true;
678
+ if (value === "false") return false;
679
+ throw new CliError("USAGE", `Invalid boolean value: ${JSON.stringify(value)}`, {
680
+ fix: 'Use "true" or "false".'
681
+ });
682
+ }
683
+ function parseConfirm(value) {
684
+ if (value === "always") return "always";
685
+ if (value.startsWith(CONFIRM_ABOVE)) {
686
+ return `${CONFIRM_ABOVE}${parseUsdToAtomic(value.slice(CONFIRM_ABOVE.length))}`;
687
+ }
688
+ throw new CliError("USAGE", `Invalid confirm value: ${JSON.stringify(value)}`, {
689
+ fix: 'Use "always" or "above:<usd>", e.g. above:0.25.'
690
+ });
691
+ }
692
+ function parseAllowlist(value) {
693
+ const entries = value.split(",").map((entry) => entry.trim()).filter((entry) => entry.length > 0);
694
+ for (const entry of entries) {
695
+ if (/\s/.test(entry)) {
696
+ throw new CliError("USAGE", `Invalid creator entry: ${JSON.stringify(entry)}`, {
697
+ fix: "Creator entries cannot contain spaces; separate multiple with commas."
698
+ });
699
+ }
700
+ }
701
+ return entries;
702
+ }
703
+ function parseHttpUrl(value) {
704
+ let url;
705
+ try {
706
+ url = new URL(value);
707
+ } catch {
708
+ throw new CliError("USAGE", `Invalid URL: ${JSON.stringify(value)}`, {
709
+ fix: "Pass an absolute http(s) URL like https://tenjin.blog."
710
+ });
711
+ }
712
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
713
+ throw new CliError("USAGE", `URL must be http or https: ${JSON.stringify(value)}`, {
714
+ fix: "Pass an absolute http(s) URL like https://tenjin.blog."
715
+ });
716
+ }
717
+ return value;
718
+ }
719
+ async function persist(dir, merge) {
720
+ await mkdir(dir, { recursive: true, mode: 448 });
721
+ const lockPath = `${configPath(dir)}.lock`;
722
+ try {
723
+ await withFileLock(lockPath, async () => {
724
+ const existing = await loadRawConfig(dir);
725
+ const merged = merge(existing);
726
+ const validated = RawConfigSchema.parse(merged);
727
+ await writeFileAtomic(configPath(dir), `${JSON.stringify(validated, null, 2)}
728
+ `, {
729
+ mode: 420,
730
+ dirMode: 448
731
+ });
732
+ });
733
+ } catch (err) {
734
+ if (err instanceof LockTimeoutError) {
735
+ throw new CliError("INTERNAL", err.message, {
736
+ fix: `If no other tenjin process is running, remove ${lockPath} and retry.`,
737
+ cause: err
738
+ });
739
+ }
740
+ throw err;
741
+ }
742
+ }
743
+ function formatLine(key, entry) {
744
+ const label = key.padEnd(KEY_WIDTH);
745
+ return ` ${label} ${displayValue(entry)} ${styleText("dim", `(${entry.source})`)}`;
746
+ }
747
+ function describedLine(key, entry, note) {
748
+ const description = KEY_DESCRIPTIONS[key];
749
+ let line = formatLine(key, entry);
750
+ if (description !== void 0) line += ` ${styleText("dim", `- ${description}`)}`;
751
+ return withNote(line, note);
752
+ }
753
+ function withNote(line, note) {
754
+ return note !== void 0 ? `${line} ${styleText("dim", `(${note})`)}` : line;
755
+ }
756
+ function downgradeNote(key, settings) {
757
+ if (key !== "publish.mode" || settings.publishMode.downgradedWarning === void 0) {
758
+ return void 0;
759
+ }
760
+ return "downgraded from full-auto: committed .tenjin.json (gitignore it to opt in)";
761
+ }
762
+ function displayValue(entry) {
763
+ const { value } = entry;
764
+ if (Array.isArray(value)) return value.length > 0 ? value.join(", ") : "(empty)";
765
+ if (typeof value === "boolean") return value ? "true" : "false";
766
+ if (typeof value === "object") return `${value.usd} USD`;
767
+ if (entry.threshold !== void 0) return `above ${entry.threshold.usd} USD`;
768
+ return value;
769
+ }
770
+
771
+ export {
772
+ selectOne,
773
+ confirmChoice,
774
+ intro,
775
+ outro,
776
+ hooksUndo,
777
+ hooksSkipped,
778
+ wireSearchHooks,
779
+ runConfigList,
780
+ runConfigGet,
781
+ runConfigSet,
782
+ persistPublishMode,
783
+ persistSearchHookMode,
784
+ persistInstallHarness
785
+ };
786
+ //# sourceMappingURL=chunk-4UHNXY6B.js.map