tenjin-cli 0.1.0-alpha.12 → 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 (155) hide show
  1. package/README.md +36 -2
  2. package/dist/{buy-3DTBFZ4B.js → buy-2JBYPHAI.js} +23 -21
  3. package/dist/{chunk-Y7ERTA7D.js → chunk-3P3ES4XU.js} +4 -6
  4. package/dist/chunk-3P3ES4XU.js.map +1 -0
  5. package/dist/{chunk-WWIKAJFO.js → chunk-3ZW7HPY5.js} +12 -10
  6. package/dist/{chunk-WWIKAJFO.js.map → chunk-3ZW7HPY5.js.map} +1 -1
  7. package/dist/chunk-4UHNXY6B.js +786 -0
  8. package/dist/chunk-4UHNXY6B.js.map +1 -0
  9. package/dist/{chunk-6UY2UQMY.js → chunk-4Y53PDH6.js} +4 -4
  10. package/dist/{chunk-TUXKOIOU.js → chunk-54AJIO3E.js} +12 -13
  11. package/dist/chunk-54AJIO3E.js.map +1 -0
  12. package/dist/chunk-736DW4V3.js +65 -0
  13. package/dist/chunk-736DW4V3.js.map +1 -0
  14. package/dist/{chunk-CNUXRXI2.js → chunk-7GJQ5RGA.js} +9 -9
  15. package/dist/{chunk-4NTZETIL.js → chunk-7NADDA2V.js} +10 -7
  16. package/dist/{chunk-4NTZETIL.js.map → chunk-7NADDA2V.js.map} +1 -1
  17. package/dist/{chunk-UFPJBS4C.js → chunk-ACBEHJAH.js} +10 -8
  18. package/dist/{chunk-UFPJBS4C.js.map → chunk-ACBEHJAH.js.map} +1 -1
  19. package/dist/{chunk-IB63U6BM.js → chunk-B676GPS2.js} +34 -11
  20. package/dist/chunk-B676GPS2.js.map +1 -0
  21. package/dist/{chunk-MBKFZBB2.js → chunk-DAZAXFSF.js} +24 -24
  22. package/dist/{chunk-E6YOODH7.js → chunk-DTCXO7HS.js} +284 -406
  23. package/dist/chunk-DTCXO7HS.js.map +1 -0
  24. package/dist/{chunk-HWHYPCCH.js → chunk-ETKZWJ4B.js} +2 -2
  25. package/dist/{chunk-HWHYPCCH.js.map → chunk-ETKZWJ4B.js.map} +1 -1
  26. package/dist/{chunk-X2WZPGCF.js → chunk-FDUD3W5V.js} +5 -5
  27. package/dist/{chunk-6RMEX74N.js → chunk-GEHL43VE.js} +63 -26
  28. package/dist/chunk-GEHL43VE.js.map +1 -0
  29. package/dist/chunk-IU2HVT3Y.js +313 -0
  30. package/dist/chunk-IU2HVT3Y.js.map +1 -0
  31. package/dist/{chunk-4TCU3YRD.js → chunk-IUQZ4Z7M.js} +40 -8
  32. package/dist/chunk-IUQZ4Z7M.js.map +1 -0
  33. package/dist/{chunk-CBNXUQGM.js → chunk-IXZJ3JOO.js} +10 -8
  34. package/dist/{chunk-CBNXUQGM.js.map → chunk-IXZJ3JOO.js.map} +1 -1
  35. package/dist/{chunk-NUF2PKJO.js → chunk-J6FUAIRR.js} +4 -6
  36. package/dist/{chunk-NUF2PKJO.js.map → chunk-J6FUAIRR.js.map} +1 -1
  37. package/dist/{chunk-OZHJ3FLR.js → chunk-L6G35FU5.js} +5 -5
  38. package/dist/{chunk-ALUNME53.js → chunk-LSWP7MU2.js} +52 -68
  39. package/dist/chunk-LSWP7MU2.js.map +1 -0
  40. package/dist/chunk-MJSXP4LW.js +191 -0
  41. package/dist/chunk-MJSXP4LW.js.map +1 -0
  42. package/dist/{chunk-RSBN67PA.js → chunk-NAAMHWSI.js} +7 -6
  43. package/dist/chunk-NAAMHWSI.js.map +1 -0
  44. package/dist/{chunk-7MJVNALU.js → chunk-O75FOHXS.js} +35 -15
  45. package/dist/chunk-O75FOHXS.js.map +1 -0
  46. package/dist/{chunk-6BGYHARE.js → chunk-OWVVI4VQ.js} +15 -15
  47. package/dist/{chunk-PZRAAAY2.js → chunk-PAOVPSP6.js} +10 -3
  48. package/dist/chunk-PAOVPSP6.js.map +1 -0
  49. package/dist/{chunk-ROAK2DOX.js → chunk-PCX2JQ2J.js} +8 -8
  50. package/dist/{chunk-JTYIX6OD.js → chunk-PKW3H26Z.js} +7 -5
  51. package/dist/{chunk-JTYIX6OD.js.map → chunk-PKW3H26Z.js.map} +1 -1
  52. package/dist/{chunk-V5UHKC46.js → chunk-PQZVDCCA.js} +7 -7
  53. package/dist/{chunk-P74I3WH4.js → chunk-QWBUKIP2.js} +9 -5
  54. package/dist/chunk-QWBUKIP2.js.map +1 -0
  55. package/dist/{chunk-FKSAUOJU.js → chunk-UO22YNY4.js} +1 -69
  56. package/dist/chunk-UO22YNY4.js.map +1 -0
  57. package/dist/chunk-VEAERJVJ.js +43 -0
  58. package/dist/chunk-VEAERJVJ.js.map +1 -0
  59. package/dist/{chunk-ILDVGY7K.js → chunk-VRPLZERE.js} +25 -12
  60. package/dist/chunk-VRPLZERE.js.map +1 -0
  61. package/dist/{chunk-L3I2MVKR.js → chunk-W4VW5XYB.js} +6 -6
  62. package/dist/{chunk-TDDN5GXR.js → chunk-WU5CZPLD.js} +5 -5
  63. package/dist/chunk-WYLMJQVH.js +240 -0
  64. package/dist/chunk-WYLMJQVH.js.map +1 -0
  65. package/dist/{chunk-PZSUWDF2.js → chunk-XGZ5EVMB.js} +2 -2
  66. package/dist/{chunk-CLOEU7RA.js → chunk-XVPQGCH4.js} +14 -13
  67. package/dist/chunk-XVPQGCH4.js.map +1 -0
  68. package/dist/chunk-ZOBNS7CX.js +73 -0
  69. package/dist/chunk-ZOBNS7CX.js.map +1 -0
  70. package/dist/{cli-3WZGLZDP.js → cli-U2BEUA55.js} +53 -150
  71. package/dist/cli-U2BEUA55.js.map +1 -0
  72. package/dist/{config-WDGMZKHU.js → config-CNUIX23Q.js} +14 -8
  73. package/dist/doctor-QJJXRWTO.js +31 -0
  74. package/dist/edit-HJ44P44P.js +40 -0
  75. package/dist/{fund-JAPOFTUG.js → fund-Y5IAHZ5D.js} +19 -17
  76. package/dist/index.js +1 -1
  77. package/dist/inspect-NFQ6SQQQ.js +37 -0
  78. package/dist/{install-WXTOHDWC.js → install-DXX7PVUP.js} +128 -408
  79. package/dist/install-DXX7PVUP.js.map +1 -0
  80. package/dist/outcome-ANV4QIED.js +24 -0
  81. package/dist/publish-PCBTCXCZ.js +42 -0
  82. package/dist/{read-UAZGZ4UL.js → read-W7QVRBVD.js} +24 -22
  83. package/dist/{read-UAZGZ4UL.js.map → read-W7QVRBVD.js.map} +1 -1
  84. package/dist/{run-AJNCOT5R.js → run-CJWPGMIQ.js} +35 -33
  85. package/dist/{run-AJNCOT5R.js.map → run-CJWPGMIQ.js.map} +1 -1
  86. package/dist/search-JGAVKTYJ.js +25 -0
  87. package/dist/{send-F34ZDXDZ.js → send-C5EOKXOU.js} +13 -11
  88. package/dist/{send-F34ZDXDZ.js.map → send-C5EOKXOU.js.map} +1 -1
  89. package/dist/{session-4N4ZT3AH.js → session-OBCUUIFX.js} +16 -15
  90. package/dist/{session-4N4ZT3AH.js.map → session-OBCUUIFX.js.map} +1 -1
  91. package/dist/{skill-heal-XBEK272G.js → skill-heal-D6EPLPS6.js} +5 -6
  92. package/dist/skill-heal-D6EPLPS6.js.map +1 -0
  93. package/dist/{uninstall-BTKPHPDL.js → uninstall-OWJNJ5LI.js} +13 -8
  94. package/dist/uninstall-OWJNJ5LI.js.map +1 -0
  95. package/dist/update-24Y2CQTT.js +318 -0
  96. package/dist/update-24Y2CQTT.js.map +1 -0
  97. package/dist/{wallet-WJ6UP5OU.js → wallet-OFXDIIGP.js} +11 -10
  98. package/dist/{wallet-UL4P2JRO.js → wallet-SLRIYJ2U.js} +7 -7
  99. package/docs/agent-permissions.md +111 -16
  100. package/docs/command-reference.md +68 -11
  101. package/package.json +1 -1
  102. package/skills/tenjin-publish/SKILL.md +181 -192
  103. package/skills/tenjin-publish/references/maintain.md +39 -0
  104. package/skills/tenjin-search/SKILL.md +86 -279
  105. package/skills/tenjin-search/references/permissions.md +106 -0
  106. package/dist/chunk-2I4QTOLB.js +0 -11
  107. package/dist/chunk-2I4QTOLB.js.map +0 -1
  108. package/dist/chunk-4TCU3YRD.js.map +0 -1
  109. package/dist/chunk-6RMEX74N.js.map +0 -1
  110. package/dist/chunk-7MJVNALU.js.map +0 -1
  111. package/dist/chunk-ALUNME53.js.map +0 -1
  112. package/dist/chunk-CLOEU7RA.js.map +0 -1
  113. package/dist/chunk-E6YOODH7.js.map +0 -1
  114. package/dist/chunk-FKSAUOJU.js.map +0 -1
  115. package/dist/chunk-IB63U6BM.js.map +0 -1
  116. package/dist/chunk-ILDVGY7K.js.map +0 -1
  117. package/dist/chunk-P74I3WH4.js.map +0 -1
  118. package/dist/chunk-PZRAAAY2.js.map +0 -1
  119. package/dist/chunk-RSBN67PA.js.map +0 -1
  120. package/dist/chunk-SFGXAZ3M.js +0 -316
  121. package/dist/chunk-SFGXAZ3M.js.map +0 -1
  122. package/dist/chunk-TUXKOIOU.js.map +0 -1
  123. package/dist/chunk-Y7ERTA7D.js.map +0 -1
  124. package/dist/cli-3WZGLZDP.js.map +0 -1
  125. package/dist/doctor-EKVCP7JP.js +0 -27
  126. package/dist/edit-4UZQVFCK.js +0 -38
  127. package/dist/inspect-IEV75A42.js +0 -35
  128. package/dist/install-WXTOHDWC.js.map +0 -1
  129. package/dist/outcome-FYOFDOUK.js +0 -22
  130. package/dist/publish-6QNARH7E.js +0 -40
  131. package/dist/search-EEKTW6VK.js +0 -23
  132. package/dist/skill-heal-XBEK272G.js.map +0 -1
  133. package/dist/uninstall-BTKPHPDL.js.map +0 -1
  134. /package/dist/{buy-3DTBFZ4B.js.map → buy-2JBYPHAI.js.map} +0 -0
  135. /package/dist/{chunk-6UY2UQMY.js.map → chunk-4Y53PDH6.js.map} +0 -0
  136. /package/dist/{chunk-CNUXRXI2.js.map → chunk-7GJQ5RGA.js.map} +0 -0
  137. /package/dist/{chunk-MBKFZBB2.js.map → chunk-DAZAXFSF.js.map} +0 -0
  138. /package/dist/{chunk-X2WZPGCF.js.map → chunk-FDUD3W5V.js.map} +0 -0
  139. /package/dist/{chunk-OZHJ3FLR.js.map → chunk-L6G35FU5.js.map} +0 -0
  140. /package/dist/{chunk-6BGYHARE.js.map → chunk-OWVVI4VQ.js.map} +0 -0
  141. /package/dist/{chunk-ROAK2DOX.js.map → chunk-PCX2JQ2J.js.map} +0 -0
  142. /package/dist/{chunk-V5UHKC46.js.map → chunk-PQZVDCCA.js.map} +0 -0
  143. /package/dist/{chunk-L3I2MVKR.js.map → chunk-W4VW5XYB.js.map} +0 -0
  144. /package/dist/{chunk-TDDN5GXR.js.map → chunk-WU5CZPLD.js.map} +0 -0
  145. /package/dist/{chunk-PZSUWDF2.js.map → chunk-XGZ5EVMB.js.map} +0 -0
  146. /package/dist/{config-WDGMZKHU.js.map → config-CNUIX23Q.js.map} +0 -0
  147. /package/dist/{doctor-EKVCP7JP.js.map → doctor-QJJXRWTO.js.map} +0 -0
  148. /package/dist/{edit-4UZQVFCK.js.map → edit-HJ44P44P.js.map} +0 -0
  149. /package/dist/{fund-JAPOFTUG.js.map → fund-Y5IAHZ5D.js.map} +0 -0
  150. /package/dist/{inspect-IEV75A42.js.map → inspect-NFQ6SQQQ.js.map} +0 -0
  151. /package/dist/{outcome-FYOFDOUK.js.map → outcome-ANV4QIED.js.map} +0 -0
  152. /package/dist/{publish-6QNARH7E.js.map → publish-PCBTCXCZ.js.map} +0 -0
  153. /package/dist/{search-EEKTW6VK.js.map → search-JGAVKTYJ.js.map} +0 -0
  154. /package/dist/{wallet-UL4P2JRO.js.map → wallet-OFXDIIGP.js.map} +0 -0
  155. /package/dist/{wallet-WJ6UP5OU.js.map → wallet-SLRIYJ2U.js.map} +0 -0
@@ -1,194 +1,17 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
2
  import {
3
- resolveThroughLink
4
- } from "./chunk-RSBN67PA.js";
5
- import {
6
- hooksDir
7
- } from "./chunk-ZQIQ55KK.js";
8
- import {
9
- CLI_SKILL_NAMES,
10
- HOSTED_SKILL_NAME,
11
- readSkillFile,
12
- skillFrontmatterName,
13
- skillsDirsFor
14
- } from "./chunk-P74I3WH4.js";
15
- import {
16
- writeFileAtomic
17
- } from "./chunk-PZRAAAY2.js";
18
-
19
- // src/lib/harness-permissions.ts
20
- import { lstat, readFile, realpath } from "fs/promises";
21
- import { join } from "path";
22
- function claudeSettingsPath(homeDir) {
23
- return join(homeDir, ".claude", "settings.json");
24
- }
25
- var FREE_VERB_RULES = [
26
- "Bash(tenjin search:*)",
27
- "Bash(tenjin fund:*)",
28
- "Bash(tenjin inspect:*)",
29
- "Bash(tenjin read:*)",
30
- "Bash(tenjin outcome:*)",
31
- "Bash(tenjin doctor:*)",
32
- "Bash(tenjin wallet show:*)",
33
- "Bash(tenjin wallet balance:*)",
34
- "Bash(tenjin config get:*)"
35
- ];
36
- var LEGACY_FREE_VERB_RULES = ["Bash(tenjin candidate list:*)"];
37
- function fixFor(reason) {
38
- switch (reason) {
39
- case "harness-not-claude":
40
- return "This allowlist is Claude Code only. Run `tenjin doctor` for the lines your harness needs.";
41
- case "not-requested":
42
- case "declined":
43
- case "dry-run":
44
- return "Add them with `tenjin install --allow-free-verbs`.";
45
- case "changed-since-read":
46
- return "Another process changed the file mid-run; re-run `tenjin install`.";
47
- default:
48
- return "Fix the reported file, then run `tenjin install --allow-free-verbs`.";
49
- }
50
- }
51
- function skip(harness, path, reason, warning) {
52
- return {
53
- harness,
54
- ...path !== void 0 ? { path } : {},
55
- added: [],
56
- removed: [],
57
- alreadyPresent: [],
58
- skipped: reason,
59
- ...warning !== void 0 ? { warning } : {},
60
- fix: fixFor(reason)
61
- };
62
- }
63
- function permissionsSkipped(harness, homeDir, reason) {
64
- const path = harness === "claude" ? claudeSettingsPath(homeDir) : void 0;
65
- return skip(harness, path, reason);
66
- }
67
- function isPlainObject(value) {
68
- return typeof value === "object" && value !== null && !Array.isArray(value);
69
- }
70
- async function wireFreeVerbAllowlist(homeDir) {
71
- const found = await inspectAllowlist(homeDir);
72
- if ("result" in found) return found.result;
73
- const { path, raw, settings, permissions, allow, added, alreadyPresent } = found;
74
- const retired = new Set(LEGACY_FREE_VERB_RULES);
75
- const removed = allow.filter((r) => typeof r === "string" && retired.has(r));
76
- if (added.length === 0 && removed.length === 0) {
77
- return { harness: "claude", path, added: [], alreadyPresent, removed: [] };
78
- }
79
- const kept = allow.filter((r) => !(typeof r === "string" && retired.has(r)));
80
- const next = {
81
- ...settings,
82
- permissions: { ...permissions, allow: [...kept, ...added] }
83
- };
84
- const current = await readFile(path, "utf8").catch(() => null);
85
- if (current !== raw) {
86
- return skip(
87
- "claude",
88
- path,
89
- "changed-since-read",
90
- `${path} changed while it was being updated, so nothing was written. Re-run \`tenjin install\`.`
91
- );
92
- }
93
- await writeFileAtomic(path, `${JSON.stringify(next, null, 2)}
94
- `);
95
- return { harness: "claude", path, added, alreadyPresent, removed };
96
- }
97
- async function inspectFreeVerbRules(homeDir) {
98
- const found = await inspectAllowlist(homeDir);
99
- if ("result" in found) return { pending: null };
100
- if (found.added.length > 0) return { pending: found.added };
101
- const retired = new Set(LEGACY_FREE_VERB_RULES);
102
- if (found.allow.some((r) => typeof r === "string" && retired.has(r))) return { pending: [] };
103
- return {
104
- pending: [],
105
- satisfied: {
106
- harness: "claude",
107
- path: found.path,
108
- added: [],
109
- alreadyPresent: found.alreadyPresent,
110
- removed: []
111
- }
112
- };
113
- }
114
- async function inspectAllowlist(homeDir) {
115
- const declaredPath = claudeSettingsPath(homeDir);
116
- const refuse = (p, reason, warning) => ({ result: skip("claude", p, reason, warning) });
117
- const entry = await lstat(declaredPath).catch(() => null);
118
- let path = declaredPath;
119
- if (entry !== null) {
120
- try {
121
- path = await realpath(declaredPath);
122
- } catch (err) {
123
- return refuse(
124
- declaredPath,
125
- "unresolvable",
126
- `${declaredPath} could not be resolved (${err.message}); it was left exactly as it is.`
127
- );
128
- }
129
- }
130
- let settings = {};
131
- let raw = null;
132
- if (entry !== null) {
133
- try {
134
- raw = await readFile(path, "utf8");
135
- } catch (err) {
136
- return refuse(
137
- path,
138
- "unreadable",
139
- `${path} could not be read (${err.message}); no permissions were written.`
140
- );
141
- }
142
- let parsed;
143
- try {
144
- parsed = JSON.parse(raw);
145
- } catch (err) {
146
- return refuse(
147
- path,
148
- "unparsable",
149
- `${path} is not valid JSON (${err.message}); it was left exactly as it is.`
150
- );
151
- }
152
- if (!isPlainObject(parsed)) {
153
- return refuse(
154
- path,
155
- "unexpected-shape",
156
- `${path} is not a JSON object; it was left exactly as it is.`
157
- );
158
- }
159
- settings = parsed;
160
- }
161
- const permissionsValue = settings.permissions;
162
- if (permissionsValue !== void 0 && !isPlainObject(permissionsValue)) {
163
- return refuse(
164
- path,
165
- "unexpected-shape",
166
- `${path} has a "permissions" key that is not an object; it was left exactly as it is.`
167
- );
168
- }
169
- const permissions = permissionsValue ?? {};
170
- const allowValue = permissions.allow;
171
- if (allowValue !== void 0 && !Array.isArray(allowValue)) {
172
- return refuse(
173
- path,
174
- "unexpected-shape",
175
- `${path} has a "permissions.allow" key that is not an array; it was left exactly as it is.`
176
- );
177
- }
178
- const allow = allowValue ?? [];
179
- const present = new Set(allow.filter((e) => typeof e === "string"));
180
- const added = FREE_VERB_RULES.filter((rule) => !present.has(rule));
181
- const alreadyPresent = FREE_VERB_RULES.filter((rule) => present.has(rule));
182
- return { path, raw, settings, permissions, allow, added, alreadyPresent: [...alreadyPresent] };
183
- }
184
-
185
- // src/lib/uninstall.ts
186
- import { lstat as lstat2, readFile as readFile2, readdir, rm, rmdir, realpath as realpath2 } from "fs/promises";
187
- import { lstatSync } from "fs";
188
- import { join as join2 } from "path";
3
+ CALLER_USER_AGENT_ENV,
4
+ PRINTABLE_ASCII_RE,
5
+ PRODUCT_RE,
6
+ TENJIN_COMMENT,
7
+ TENJIN_PRODUCT,
8
+ TENJIN_PRODUCT_NAME,
9
+ TENJIN_USER_AGENT,
10
+ USER_AGENT_MAX_LENGTH
11
+ } from "./chunk-VEAERJVJ.js";
189
12
 
190
13
  // src/lib/hook-scripts.ts
191
- var HOOK_SCRIPT_VERSION = 12;
14
+ var HOOK_SCRIPT_VERSION = 17;
192
15
  var WEBSEARCH_HOOK_FILE = "tenjin-websearch.mjs";
193
16
  var STOP_HOOK_FILE = "tenjin-stop.mjs";
194
17
  var SEARCH_TIMEOUT_MS = 2e3;
@@ -206,8 +29,9 @@ var REMIND_LINE = 'Tenjin (a marketplace of tested, paid answers) may already ha
206
29
  function prelude(dataDir, watchdogMs) {
207
30
  return `#!/usr/bin/env node
208
31
  // tenjin-cli hook, generated by \`tenjin install\` (v${HOOK_SCRIPT_VERSION}). Safe to delete.
209
- import { readFileSync, writeFileSync, renameSync, mkdirSync, rmSync } from 'node:fs';
210
- import { join } from 'node:path';
32
+ import { readFileSync, writeFileSync, renameSync, mkdirSync, rmSync, statSync } from 'node:fs';
33
+ import { dirname, join } from 'node:path';
34
+ import { homedir } from 'node:os';
211
35
 
212
36
  const DATA_DIR = ${JSON.stringify(dataDir)};
213
37
 
@@ -247,6 +71,11 @@ function isRecord(v) {
247
71
  return typeof v === 'object' && v !== null && !Array.isArray(v);
248
72
  }
249
73
 
74
+ /** The three values \`publish.mode\` may take (lib/config.ts's PublishModeSchema). */
75
+ function isPublishMode(v) {
76
+ return v === 'review' || v === 'auto' || v === 'full-auto';
77
+ }
78
+
250
79
  /**
251
80
  * The harness session this event belongs to, or null when the payload does not
252
81
  * name one. \`session_id\` is the documented field on every hook input, and null
@@ -256,7 +85,102 @@ function isRecord(v) {
256
85
  function sessionIdOf(input) {
257
86
  if (!isRecord(input)) return null;
258
87
  const id = input.session_id;
259
- return typeof id === 'string' && id.length > 0 ? id : null;
88
+ // BOUNDED, because this becomes a hook-nags.json key held for a week and read
89
+ // at every turn end. Every other externally supplied string in that file is
90
+ // capped; an absurd one here falls back to the documented global behavior
91
+ // rather than growing the file it is stored in.
92
+ if (typeof id !== 'string' || id.length === 0 || id.length > 128) return null;
93
+ return id;
94
+ }
95
+
96
+ /**
97
+ * The session's working directory, which is where the next \`tenjin publish\`
98
+ * would run. Same parsed payload as the session id; null when unusable.
99
+ */
100
+ function cwdOf(input) {
101
+ if (!isRecord(input)) return null;
102
+ const dir = input.cwd;
103
+ return typeof dir === 'string' && dir.length > 0 && dir.length <= 4096 ? dir : null;
104
+ }
105
+
106
+ /**
107
+ * The project layer's publish.mode, walking up from \`start\` for a \`.tenjin.json\`.
108
+ *
109
+ * The Stop hook resolves this and the WebSearch hook does not, and the asymmetry
110
+ * is the point: a general hook's cwd may have nothing to do with the draft, but
111
+ * the Stop hook's cwd IS the session's working directory, so it is exactly where
112
+ * the publish it is talking about will run. Announcing the global mode there let
113
+ * an agent believe it held auto authority inside a repo the operator had pinned
114
+ * to review, and an exit 3 that is not a hard block is one \`--yes\` away from
115
+ * proceeding anyway.
116
+ *
117
+ * THE THREE BOUNDARIES ARE \`findProjectConfigFile\`'s, mirrored rule for rule. A
118
+ * generated hook cannot import lib/settings.ts, so the walk is duplicated, and a
119
+ * duplicate that drops a stop condition announces a mode the CLI will not run
120
+ * under. The first cut was a bare 12-level parent walk and diverged in BOTH
121
+ * directions: a \`~/.tenjin.json\` the CLI deliberately ignores made the hook
122
+ * promise unattended publishing that the CLI's own gate would then refuse.
123
+ *
124
+ * 1. Stop at the repo root. A directory's own \`.tenjin.json\` is checked BEFORE
125
+ * its \`.git\` probe, so a file AT the repo root is honored by both walks and
126
+ * the divergence begins strictly above it.
127
+ * 2. Never walk above \`$HOME\`.
128
+ * 3. Skip a file owned by another uid, then keep walking. On a shared host that
129
+ * is the difference between reading the operator's pin and reading a planted
130
+ * one; the CLI calls it a trust boundary and warns, and a hook stays silent.
131
+ *
132
+ * A project file may narrow, never widen, so \`full-auto\` from a project
133
+ * CONSERVATIVELY reads as \`auto\`. That is not an exact mirror: the CLI downgrades
134
+ * a committed project \`full-auto\` and honors a gitignored one, and this walk does
135
+ * not read .gitignore. It always announces the narrower of the two, which is the
136
+ * safe direction for a line an agent acts on. Every failure is silent and falls
137
+ * through to the global answer.
138
+ */
139
+ function projectPublishMode(start) {
140
+ try {
141
+ const home = homedir();
142
+ const uid = typeof process.getuid === 'function' ? process.getuid() : undefined;
143
+ // Owned by someone else: skip the file and keep walking, exactly as
144
+ // findProjectConfigFile does. A platform with no uid model has no such gate.
145
+ const foreign = (path) => {
146
+ if (uid === undefined) return false;
147
+ try {
148
+ return statSync(path).uid !== uid;
149
+ } catch {
150
+ return false;
151
+ }
152
+ };
153
+ const exists = (path) => {
154
+ try {
155
+ statSync(path);
156
+ return true;
157
+ } catch {
158
+ return false;
159
+ }
160
+ };
161
+
162
+ let dir = start;
163
+ for (;;) {
164
+ const candidate = join(dir, '.tenjin.json');
165
+ if (exists(candidate) && !foreign(candidate)) {
166
+ const found = readJsonFile(candidate);
167
+ if (isRecord(found)) {
168
+ const publish = isRecord(found.publish) ? found.publish : {};
169
+ const mode = publish.mode;
170
+ if (mode === 'review' || mode === 'auto') return mode;
171
+ if (mode === 'full-auto') return 'auto';
172
+ }
173
+ return null;
174
+ }
175
+ if (exists(join(dir, '.git'))) return null;
176
+ if (dir === home) return null;
177
+ const parent = dirname(dir);
178
+ if (parent === dir) return null;
179
+ dir = parent;
180
+ }
181
+ } catch {
182
+ return null;
183
+ }
260
184
  }
261
185
 
262
186
  /**
@@ -265,16 +189,31 @@ function sessionIdOf(input) {
265
189
  * off\` or \`hooks.stopNag off\` silences a hook immediately, with no re-install
266
190
  * and nothing to unwire. An unreadable or unrecognized value falls back to the
267
191
  * shipped default rather than failing.
192
+ *
193
+ * \`publishMode\` reads the global file and TENJIN_PUBLISH_MODE. \`envPinned\` says
194
+ * whether the env var decided it, because lib/config.ts resolves
195
+ * global < project < env < flag: an env var set for this process outranks a
196
+ * project file, so the caller must not layer one on top of it.
268
197
  */
269
198
  function readConfig() {
270
199
  const raw = readJsonFile(join(DATA_DIR, 'config.json'));
271
200
  const cfg = isRecord(raw) ? raw : {};
272
201
  const hooks = isRecord(cfg.hooks) ? cfg.hooks : {};
202
+ const publish = isRecord(cfg.publish) ? cfg.publish : {};
273
203
  const mode = hooks.searchMode;
204
+ const nag = hooks.stopNag;
205
+ // env over file, matching lib/config.ts's resolvePublishMode; an unrecognized
206
+ // value in either place falls through to the shipped default rather than
207
+ // failing, exactly like every other key here.
208
+ const fromEnv = process.env.TENJIN_PUBLISH_MODE;
209
+ const envPinned = isPublishMode(fromEnv);
210
+ const publishMode = envPinned ? fromEnv : publish.mode;
274
211
  const baseUrl = typeof cfg.baseUrl === 'string' ? cfg.baseUrl : 'https://tenjin.blog';
275
212
  return {
276
213
  mode: mode === 'off' || mode === 'remind' || mode === 'auto' ? mode : 'auto',
277
- stopNag: hooks.stopNag === 'off' ? 'off' : 'on',
214
+ stopNag: nag === 'off' || nag === 'deliberate-only' ? nag : 'on',
215
+ publishMode: isPublishMode(publishMode) ? publishMode : 'review',
216
+ envPinned,
278
217
  baseUrl,
279
218
  };
280
219
  }
@@ -330,6 +269,30 @@ function clean(value, max) {
330
269
  .slice(0, max);
331
270
  }
332
271
 
272
+ /**
273
+ * "A newer tenjin-cli exists", appended to whatever this hook was already going
274
+ * to say. The CLI's own nudge is one dim stderr line that only a human at a
275
+ * terminal sees; a harness reads additionalContext, so this is where the AGENT
276
+ * finds out it can update itself. Pure cache read, and the comparison was
277
+ * already made by the CLI (see update-check.ts, the cached signal), because it
278
+ * runs standalone and does not know which version is installed.
279
+ */
280
+ function updateLine() {
281
+ try {
282
+ const cfg = readJsonFile(join(DATA_DIR, 'config.json'));
283
+ const update = isRecord(cfg) && isRecord(cfg.update) ? cfg.update : {};
284
+ if (update.mode === 'off') return null;
285
+ const cache = readJsonFile(join(DATA_DIR, 'update-check.json'));
286
+ const signal = isRecord(cache) && isRecord(cache.signal) ? cache.signal : null;
287
+ if (signal === null) return null;
288
+ if (typeof signal.current !== 'string' || typeof signal.latest !== 'string') return null;
289
+ return 'tenjin-cli ' + clean(signal.latest, 40) + ' is available (you have ' +
290
+ clean(signal.current, 40) + '). Run tenjin update to install it.';
291
+ } catch {
292
+ return null;
293
+ }
294
+ }
295
+
333
296
  /**
334
297
  * Emit additionalContext for this event and leave. writeFileSync to fd 1, not
335
298
  * process.stdout.write: a write to a pipe is asynchronous, so exiting on the next
@@ -337,7 +300,9 @@ function clean(value, max) {
337
300
  */
338
301
  function emit(hookEventName, additionalContext) {
339
302
  try {
340
- writeFileSync(1, JSON.stringify({ hookSpecificOutput: { hookEventName, additionalContext } }));
303
+ const extra = updateLine();
304
+ const context = extra === null ? additionalContext : additionalContext + '\\n' + extra;
305
+ writeFileSync(1, JSON.stringify({ hookSpecificOutput: { hookEventName, additionalContext: context } }));
341
306
  } catch {
342
307
  // A closed or full stdout is not this hook's problem to report.
343
308
  }
@@ -345,8 +310,42 @@ function emit(hookEventName, additionalContext) {
345
310
  }
346
311
  `;
347
312
  }
313
+ function userAgentSource() {
314
+ return `
315
+ const TENJIN_PRODUCT = ${JSON.stringify(TENJIN_PRODUCT)};
316
+ const TENJIN_USER_AGENT = ${JSON.stringify(TENJIN_USER_AGENT)};
317
+ const UA_COMMENT = ${JSON.stringify(TENJIN_COMMENT)};
318
+ const UA_PRODUCT_NAME = ${JSON.stringify(TENJIN_PRODUCT_NAME.toLowerCase())};
319
+ const UA_MAX_LENGTH = ${USER_AGENT_MAX_LENGTH};
320
+ const UA_PRODUCT_RE = ${PRODUCT_RE.toString()};
321
+ const UA_PRINTABLE_RE = ${PRINTABLE_ASCII_RE.toString()};
322
+
323
+ /** A copy of our own identity inside a caller value, in any casing. */
324
+ function isOwnUaIdentity(token) {
325
+ const lower = token.toLowerCase();
326
+ return lower === UA_COMMENT.toLowerCase() || lower === UA_PRODUCT_NAME ||
327
+ lower.startsWith(UA_PRODUCT_NAME + '/');
328
+ }
329
+
330
+ /**
331
+ * Our product, then the launching harness's products in their order, then our
332
+ * comment. Rejection is TOTAL: a non-printable, non-product, or overlong handoff
333
+ * is omitted and the CLI identity travels alone, because truncating a product
334
+ * token would mint a different, false identity. This is self-reported telemetry
335
+ * and never trusted policy input.
336
+ */
337
+ function composedUserAgent() {
338
+ const raw = process.env[${JSON.stringify(CALLER_USER_AGENT_ENV)}];
339
+ if (typeof raw !== 'string' || !UA_PRINTABLE_RE.test(raw)) return TENJIN_USER_AGENT;
340
+ const tokens = raw.split(' ').filter((t) => t.length > 0 && !isOwnUaIdentity(t));
341
+ if (tokens.length === 0 || !tokens.every((t) => UA_PRODUCT_RE.test(t))) return TENJIN_USER_AGENT;
342
+ const composed = TENJIN_PRODUCT + ' ' + tokens.join(' ') + ' ' + UA_COMMENT;
343
+ return composed.length <= UA_MAX_LENGTH ? composed : TENJIN_USER_AGENT;
344
+ }
345
+ `;
346
+ }
348
347
  function websearchHookScript(dataDir) {
349
- return `${prelude(dataDir, WATCHDOG_MS)}
348
+ return `${prelude(dataDir, WATCHDOG_MS)}${userAgentSource()}
350
349
  const LOCK_PATH = SEARCH_STORE + '.lock';
351
350
 
352
351
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
@@ -478,7 +477,7 @@ async function main() {
478
477
 
479
478
  const res = await fetch(url, {
480
479
  method: 'POST',
481
- headers: { 'content-type': 'application/json' },
480
+ headers: { 'content-type': 'application/json', 'user-agent': composedUserAgent() },
482
481
  body: JSON.stringify({ schemaVersion: 2, question, limit: ${SEARCH_LIMIT} }),
483
482
  signal: AbortSignal.timeout(${SEARCH_TIMEOUT_MS}),
484
483
  });
@@ -587,23 +586,54 @@ function stopHookScript(dataDir) {
587
586
  return `${prelude(dataDir, STOP_WATCHDOG_MS)}
588
587
  const NAGS_PATH = join(DATA_DIR, 'hook-nags.json');
589
588
 
590
- function loadNags() {
591
- const raw = readJsonFile(NAGS_PATH);
592
- const nagged = isRecord(raw) && isRecord(raw.nagged) ? raw.nagged : {};
589
+ /** The string-valued members of a record, dropping anything else. */
590
+ function stampsOf(value) {
593
591
  const out = {};
594
- for (const [id, at] of Object.entries(nagged)) {
595
- if (typeof at === 'string') out[id] = at;
592
+ if (!isRecord(value)) return out;
593
+ for (const [key, at] of Object.entries(value)) {
594
+ if (typeof at === 'string') out[key] = at;
596
595
  }
597
596
  return out;
598
597
  }
599
598
 
599
+ /**
600
+ * What has already been raised: \`nagged\` per searchId, \`sessions\` per harness
601
+ * session that has had its weak batch. Both are additive on the same file, and a
602
+ * file written by an older hook simply has no \`sessions\` key, which reads as
603
+ * "no session has been batched yet" \u2014 one extra weak batch, never a lost nag.
604
+ */
605
+ function loadNags() {
606
+ const raw = readJsonFile(NAGS_PATH);
607
+ return {
608
+ nagged: stampsOf(isRecord(raw) ? raw.nagged : null),
609
+ sessions: stampsOf(isRecord(raw) ? raw.sessions : null),
610
+ };
611
+ }
612
+
600
613
  /** Persist through a temp file + rename, so a crash cannot leave a torn file. */
601
- function saveNags(nagged) {
614
+ function saveNags(nagged, sessions) {
602
615
  const tmp = NAGS_PATH + '.' + process.pid + '.tmp';
603
- writeFileSync(tmp, JSON.stringify({ schemaVersion: 1, nagged }, null, 2) + '\\n', { mode: 0o644 });
616
+ writeFileSync(tmp, JSON.stringify({ schemaVersion: 1, nagged, sessions }, null, 2) + '\\n', {
617
+ mode: 0o644,
618
+ });
604
619
  renameSync(tmp, NAGS_PATH);
605
620
  }
606
621
 
622
+ /**
623
+ * The publish consent mode the next \`tenjin publish\` will run under, stated in
624
+ * the terms that decide what the agent does next: whether it has to ask.
625
+ *
626
+ * NEVER EMITTED ALONE. It is context for the loops below it, not a standing
627
+ * announcement, so a turn with nothing open says nothing at all.
628
+ */
629
+ function modeLine(mode) {
630
+ if (mode === 'auto') return 'publish.mode=auto: a clean publish proceeds without asking.';
631
+ if (mode === 'full-auto') {
632
+ return 'publish.mode=full-auto: publish without asking; hedge warnings, stop only on hard blocks.';
633
+ }
634
+ return 'publish.mode=review: publishing asks first.';
635
+ }
636
+
607
637
  /**
608
638
  * One line per deliberate search nobody had answered, naming its searchId. The
609
639
  * publish arm is QUALIFIED: this line lands in a model's context at every turn
@@ -617,11 +647,11 @@ function saveNags(nagged) {
617
647
  function strongLine(s) {
618
648
  const id = clean(s.searchId, 64);
619
649
  return (
620
- "Open Tenjin loop: you searched '" +
650
+ "Open Tenjin loop: '" +
621
651
  clean(s.question, 160) +
622
- "' and got a MISS. If you solved it with a public, reusable, rights-clean finding, publish it back: tenjin publish <file> --search-id " +
652
+ "' was a MISS. Solved it with a public, reusable, rights-clean finding? Publish it: tenjin publish <file> --search-id " +
623
653
  id +
624
- '. If you will not, close it: tenjin outcome --search-id ' +
654
+ '. If not, close it: tenjin outcome --search-id ' +
625
655
  id +
626
656
  ' --status regenerated.'
627
657
  );
@@ -637,7 +667,7 @@ function weakLine(batch) {
637
667
  String(batch.length) +
638
668
  ' web search(es) this session had no Tenjin answer: ' +
639
669
  items +
640
- '. If any produced a durable public finding, publish it back: tenjin publish <file> --search-id <id>. Otherwise close them: tenjin outcome --search-id <id> --status regenerated.'
670
+ '. Durable public finding among them? Publish it: tenjin publish <file> --search-id <id>. If not, close them: tenjin outcome --search-id <id> --status regenerated.'
641
671
  );
642
672
  }
643
673
 
@@ -664,16 +694,40 @@ async function main() {
664
694
  // and tolerantly \u2014 a shape this hook does not recognize costs the scoping, not
665
695
  // the reminder.
666
696
  let sessionId = null;
697
+ let cwd = null;
667
698
  try {
668
- sessionId = sessionIdOf(JSON.parse(await readStdin()));
699
+ const input = JSON.parse(await readStdin());
700
+ sessionId = sessionIdOf(input);
701
+ cwd = cwdOf(input);
669
702
  } catch {
670
703
  // Unparseable stdin: fall back to machine-global behavior.
671
704
  }
672
- if (readConfig().stopNag === 'off') return quiet();
705
+ const config = readConfig();
706
+ if (config.stopNag === 'off') return quiet();
707
+ // The mode the next publish IN THIS DIRECTORY would actually run under. The
708
+ // Stop hook's cwd IS the session's working directory, so it is the place that
709
+ // publish runs. Precedence follows lib/config.ts: an env var outranks the
710
+ // project file, so the project layer is consulted only when nothing pinned it.
711
+ const project = cwd === null || config.envPinned ? null : projectPublishMode(cwd);
712
+ const publishMode = project === null ? config.publishMode : project;
673
713
 
674
714
  const searches = loadSearches();
675
715
  const now = Date.now();
676
- const nagged = loadNags();
716
+ const { nagged, sessions } = loadNags();
717
+
718
+ // ONE WEAK BATCH PER SESSION. Per-searchId dedupe cannot rate-limit the weak
719
+ // arm, because a research fan-out mints new ids every turn and each one is
720
+ // un-nagged by construction; the batch then fires at every turn end for the
721
+ // whole session and reads as harness debug output rather than a product
722
+ // (tenjin-agent #162). \`deliberate-only\` is the operator's standing version of
723
+ // the same suppression, and it exists so silencing this arm is not the cliff
724
+ // that \`off\` is: the strong arm, which is the high-signal half, keeps running.
725
+ //
726
+ // A null sessionId keeps the old behavior. There is nothing to key on, and
727
+ // refusing the batch outright would silence it on every harness that names no
728
+ // session.
729
+ const batchedThisSession = sessionId !== null && sessions[sessionId] !== undefined;
730
+ const weakAllowed = config.stopNag !== 'deliberate-only' && !batchedThisSession;
677
731
 
678
732
  const strong = [];
679
733
  const weak = [];
@@ -688,23 +742,38 @@ async function main() {
688
742
  const at = Date.parse(String(s.at));
689
743
  if (!Number.isFinite(at) || now - at > ${OPEN_LOOP_WINDOW_MS} || at > now) continue;
690
744
  // An entry with no source predates sources, and those were all deliberate.
691
- const bucket = s.source === 'websearch-hook' ? weak : strong;
692
- if (bucket === strong && strong.length < ${MAX_STRONG_LOOPS}) strong.push(s);
693
- else if (bucket === weak && weak.length < ${MAX_WEAK_LOOPS}) weak.push(s);
745
+ if (s.source === 'websearch-hook') {
746
+ // A suppressed weak entry is skipped UNNAGGED, exactly like an entry owned
747
+ // by another session: the batch was rate-limited, not delivered, so the id
748
+ // stays available to whatever raises it next.
749
+ if (!weakAllowed) continue;
750
+ if (weak.length < ${MAX_WEAK_LOOPS}) weak.push(s);
751
+ } else if (strong.length < ${MAX_STRONG_LOOPS}) {
752
+ strong.push(s);
753
+ }
694
754
  }
695
755
  const surfaced = strong.concat(weak);
696
756
  if (surfaced.length === 0) return quiet();
697
757
 
698
758
  const stamp = new Date(now).toISOString();
699
759
  for (const s of surfaced) nagged[s.searchId] = stamp;
760
+ if (weak.length > 0 && sessionId !== null) sessions[sessionId] = stamp;
700
761
  for (const [id, at] of Object.entries(nagged)) {
701
762
  const t = Date.parse(at);
702
763
  if (!Number.isFinite(t) || now - t > ${NAG_RETENTION_MS}) delete nagged[id];
703
764
  }
765
+ for (const [id, at] of Object.entries(sessions)) {
766
+ const t = Date.parse(at);
767
+ if (!Number.isFinite(t) || now - t > ${NAG_RETENTION_MS}) delete sessions[id];
768
+ }
704
769
  // Record first: a nag we cannot mark is a nag that would repeat every turn.
705
- saveNags(nagged);
770
+ saveNags(nagged, sessions);
706
771
 
707
- const lines = strong.map(strongLine);
772
+ // The mode heads the block: it is what decides whether the publish arm below
773
+ // needs the operator's word, and an agent that has to run \`tenjin config get\`
774
+ // to find out defaults to asking (tenjin-agent #161).
775
+ const lines = [modeLine(publishMode)];
776
+ for (const s of strong) lines.push(strongLine(s));
708
777
  if (weak.length > 0) lines.push(weakLine(weak));
709
778
  emit('Stop', lines.join('\\n'));
710
779
  }
@@ -713,201 +782,10 @@ main().catch(quiet);
713
782
  `;
714
783
  }
715
784
 
716
- // src/lib/uninstall.ts
717
- var KEPT_ITEMS = [
718
- "everything under ~/.tenjin: your wallet, config, library, and search history",
719
- "anything an older version left in ~/.tenjin/candidates (nothing reads it now)"
720
- ];
721
- var SKILLS_MARKER = "<!-- tenjin-cli:skills -->";
722
- function isPlainObject2(value) {
723
- return typeof value === "object" && value !== null && !Array.isArray(value);
724
- }
725
- function ownsHookEntry(entry) {
726
- if (!isPlainObject2(entry)) return false;
727
- const handlers = entry.hooks;
728
- if (!Array.isArray(handlers)) return false;
729
- return handlers.some(
730
- (h) => isPlainObject2(h) && typeof h.command === "string" && (h.command.includes(WEBSEARCH_HOOK_FILE) || h.command.includes(STOP_HOOK_FILE))
731
- );
732
- }
733
- async function removeFromSettings(homeDir) {
734
- const declaredPath = claudeSettingsPath(homeDir);
735
- const skip2 = (path2, skipped, warning) => ({
736
- path: path2,
737
- hooks: [],
738
- rules: [],
739
- skipped,
740
- ...warning !== void 0 ? { warning } : {}
741
- });
742
- const entry = await lstat2(declaredPath).catch(() => null);
743
- if (entry === null) return skip2(declaredPath, "absent");
744
- let path;
745
- try {
746
- path = await realpath2(declaredPath);
747
- } catch (err) {
748
- return skip2(
749
- declaredPath,
750
- "unresolvable",
751
- `${declaredPath} could not be resolved (${err.message}); it was left exactly as it is.`
752
- );
753
- }
754
- let raw;
755
- try {
756
- raw = await readFile2(path, "utf8");
757
- } catch (err) {
758
- return skip2(
759
- path,
760
- "unreadable",
761
- `${path} could not be read (${err.message}); it was left exactly as it is.`
762
- );
763
- }
764
- let parsed;
765
- try {
766
- parsed = JSON.parse(raw);
767
- } catch (err) {
768
- return skip2(
769
- path,
770
- "unparsable",
771
- `${path} is not valid JSON (${err.message}); it was left exactly as it is.`
772
- );
773
- }
774
- if (!isPlainObject2(parsed)) {
775
- return skip2(path, "unexpected-shape", `${path} is not a JSON object; it was left as it is.`);
776
- }
777
- const settings = parsed;
778
- const removedHooks = [];
779
- const removedRules = [];
780
- let next = settings;
781
- const hooksValue = settings.hooks;
782
- if (hooksValue !== void 0 && !isPlainObject2(hooksValue)) {
783
- return skip2(
784
- path,
785
- "unexpected-shape",
786
- `${path} has a "hooks" key that is not an object; it was left exactly as it is.`
787
- );
788
- }
789
- if (isPlainObject2(hooksValue)) {
790
- const nextHooks = {};
791
- for (const [event, value] of Object.entries(hooksValue)) {
792
- if (!Array.isArray(value)) {
793
- nextHooks[event] = value;
794
- continue;
795
- }
796
- const kept = value.filter((e) => !ownsHookEntry(e));
797
- if (kept.length !== value.length) removedHooks.push(event);
798
- const emptiedByUs = kept.length === 0 && value.length > 0;
799
- if (!emptiedByUs) nextHooks[event] = kept;
800
- }
801
- next = { ...next, hooks: nextHooks };
802
- if (Object.keys(nextHooks).length === 0) delete next.hooks;
803
- }
804
- const permissions = settings.permissions;
805
- if (isPlainObject2(permissions) && Array.isArray(permissions.allow)) {
806
- const ours = /* @__PURE__ */ new Set([...FREE_VERB_RULES, ...LEGACY_FREE_VERB_RULES]);
807
- const kept = permissions.allow.filter((r) => !(typeof r === "string" && ours.has(r)));
808
- if (kept.length !== permissions.allow.length) {
809
- for (const rule of permissions.allow) {
810
- if (typeof rule === "string" && ours.has(rule)) removedRules.push(rule);
811
- }
812
- const nextPermissions = { ...permissions, allow: kept };
813
- if (kept.length === 0) delete nextPermissions.allow;
814
- next = { ...next, permissions: nextPermissions };
815
- if (Object.keys(nextPermissions).length === 0) delete next.permissions;
816
- }
817
- }
818
- if (removedHooks.length === 0 && removedRules.length === 0) {
819
- return { path, hooks: [], rules: [] };
820
- }
821
- const current = await readFile2(path, "utf8").catch(() => null);
822
- if (current !== raw) {
823
- return skip2(
824
- path,
825
- "changed-since-read",
826
- `${path} changed while it was being updated, so nothing was removed from it. Re-run \`tenjin uninstall\`.`
827
- );
828
- }
829
- await writeFileAtomic(path, `${JSON.stringify(next, null, 2)}
830
- `);
831
- return { path, hooks: removedHooks, rules: removedRules };
832
- }
833
- async function removeHookScripts(dataDir) {
834
- const dir = hooksDir(dataDir);
835
- const removed = [];
836
- for (const file of [WEBSEARCH_HOOK_FILE, STOP_HOOK_FILE]) {
837
- const path = join2(dir, file);
838
- if (lstatSync(path, { throwIfNoEntry: false })?.isFile() !== true) continue;
839
- await rm(path, { force: true });
840
- removed.push(path);
841
- }
842
- const rest = await readdir(dir).catch(() => null);
843
- if (rest !== null && rest.length === 0) {
844
- const gone = await rmdir(dir).then(
845
- () => true,
846
- () => false
847
- );
848
- if (gone) return { scripts: removed, removedDir: dir };
849
- }
850
- return { scripts: removed };
851
- }
852
- async function removeSkills(homeDir) {
853
- const removed = [];
854
- const names = [...CLI_SKILL_NAMES, HOSTED_SKILL_NAME];
855
- for (const dir of skillsDirsFor(homeDir)) {
856
- if (lstatSync(dir, { throwIfNoEntry: false })?.isDirectory() !== true) continue;
857
- for (const name of names) {
858
- const skillDir = join2(dir, name);
859
- if (lstatSync(skillDir, { throwIfNoEntry: false })?.isDirectory() !== true) continue;
860
- const path = join2(skillDir, "SKILL.md");
861
- if (lstatSync(path, { throwIfNoEntry: false })?.isFile() !== true) continue;
862
- const read = await readSkillFile(path);
863
- if (read.kind !== "ok") continue;
864
- if (skillFrontmatterName(read.bytes.toString("utf8")) !== name) continue;
865
- await rm(path, { force: true });
866
- const rest = await readdir(skillDir).catch(() => null);
867
- if (rest !== null && rest.length === 0) {
868
- await rmdir(skillDir).catch(() => void 0);
869
- }
870
- removed.push(skillDir);
871
- }
872
- }
873
- return removed;
874
- }
875
- async function removeMarkerLines(homeDir) {
876
- const cleaned = [];
877
- for (const path of markerFiles(homeDir)) {
878
- const read = await readSkillFile(path);
879
- if (read.kind !== "ok") continue;
880
- const text = read.bytes.toString("utf8");
881
- if (!text.split("\n").some((l) => l.startsWith(SKILLS_MARKER))) continue;
882
- const kept = text.split("\n").filter((l) => !l.startsWith(SKILLS_MARKER));
883
- const writeTo = await resolveThroughLink(path, "the Tenjin pointer");
884
- await writeFileAtomic(writeTo, kept.join("\n"));
885
- cleaned.push(path);
886
- }
887
- return cleaned;
888
- }
889
- function markerFiles(homeDir) {
890
- return [
891
- join2(homeDir, ".claude", "CLAUDE.md"),
892
- join2(homeDir, ".agents", "AGENTS.md"),
893
- join2(homeDir, ".codex", "AGENTS.md")
894
- ];
895
- }
896
-
897
785
  export {
898
- claudeSettingsPath,
899
- FREE_VERB_RULES,
900
- permissionsSkipped,
901
- wireFreeVerbAllowlist,
902
- inspectFreeVerbRules,
903
786
  WEBSEARCH_HOOK_FILE,
904
787
  STOP_HOOK_FILE,
905
788
  websearchHookScript,
906
- stopHookScript,
907
- KEPT_ITEMS,
908
- removeFromSettings,
909
- removeHookScripts,
910
- removeSkills,
911
- removeMarkerLines
789
+ stopHookScript
912
790
  };
913
- //# sourceMappingURL=chunk-E6YOODH7.js.map
791
+ //# sourceMappingURL=chunk-DTCXO7HS.js.map