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
@@ -0,0 +1,313 @@
1
+ import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ writeFileAtomic
4
+ } from "./chunk-PAOVPSP6.js";
5
+
6
+ // src/lib/harness-permissions.ts
7
+ import { lstat, readFile, realpath, stat } from "fs/promises";
8
+ import { join } from "path";
9
+ function claudeSettingsPath(homeDir) {
10
+ return join(homeDir, ".claude", "settings.json");
11
+ }
12
+ var FREE_VERB_RULES = [
13
+ "Bash(tenjin search:*)",
14
+ "Bash(tenjin fund:*)",
15
+ "Bash(tenjin inspect:*)",
16
+ "Bash(tenjin read:*)",
17
+ "Bash(tenjin outcome:*)",
18
+ "Bash(tenjin doctor:*)",
19
+ "Bash(tenjin wallet show:*)",
20
+ "Bash(tenjin wallet balance:*)",
21
+ "Bash(tenjin config get:*)"
22
+ ];
23
+ var PUBLISH_MODE_RULE = "Bash(tenjin publish:*)";
24
+ var EDIT_MODE_RULE = "Bash(tenjin edit:*)";
25
+ var MODE_GATED_RULES = [PUBLISH_MODE_RULE, EDIT_MODE_RULE];
26
+ function rulesForPublishMode(mode) {
27
+ return mode === "review" ? FREE_VERB_RULES : [...FREE_VERB_RULES, ...MODE_GATED_RULES];
28
+ }
29
+ function retiredFor(mode) {
30
+ const retired = new Set(LEGACY_ALLOWLIST_RULES);
31
+ if (mode === "review") for (const rule of MODE_GATED_RULES) retired.add(rule);
32
+ return retired;
33
+ }
34
+ var LEGACY_ALLOWLIST_RULES = ["Bash(tenjin candidate list:*)"];
35
+ var MODE_GRANT_UNDO = [
36
+ "tenjin install --publish-mode review",
37
+ "tenjin config set publish.mode review",
38
+ "tenjin uninstall"
39
+ ];
40
+ function modeGrantFor(mode, added, present, planned) {
41
+ const wasAdded = MODE_GATED_RULES.filter((r) => added.includes(r));
42
+ const wasPresent = MODE_GATED_RULES.filter((r) => present.includes(r));
43
+ const rules = [...wasAdded, ...wasPresent];
44
+ if (rules.length === 0) return void 0;
45
+ const state = wasAdded.length === 0 ? "already-present" : wasPresent.length === 0 ? "added" : "mixed";
46
+ const verb = state === "already-present" ? "already present" : state === "mixed" ? planned ? "would be in place" : "in place" : planned ? "would be added" : "added";
47
+ return {
48
+ rules: MODE_GATED_RULES.filter((r) => rules.includes(r)),
49
+ state,
50
+ disclosure: `${MODE_GATED_RULES.join(" and ")} ${verb}: on publish.mode ${mode} your agent can publish to the public marketplace under your identity, update its own posts, and open your wallet keystore to sign, without a harness prompt.`,
51
+ undo: [...MODE_GRANT_UNDO]
52
+ };
53
+ }
54
+ function fixFor(reason) {
55
+ switch (reason) {
56
+ case "harness-not-claude":
57
+ return "This allowlist is Claude Code only. Run `tenjin doctor` for the lines your harness needs.";
58
+ case "not-requested":
59
+ case "declined":
60
+ case "dry-run":
61
+ return "Add them with `tenjin install --allow-free-verbs`.";
62
+ case "changed-since-read":
63
+ return "Another process changed the file mid-run; re-run `tenjin install`.";
64
+ default:
65
+ return "Fix the reported file, then run `tenjin install --allow-free-verbs`.";
66
+ }
67
+ }
68
+ function tiers(added, alreadyPresent, mode, planned = false) {
69
+ const gated = new Set(MODE_GATED_RULES);
70
+ const grant = modeGrantFor(mode, added, alreadyPresent, planned);
71
+ return {
72
+ addedFree: added.filter((r) => !gated.has(r)),
73
+ alreadyPresentFree: alreadyPresent.filter((r) => !gated.has(r)),
74
+ ...grant !== void 0 ? { modeGrant: grant } : {}
75
+ };
76
+ }
77
+ function skip(harness, path, reason, warning) {
78
+ return {
79
+ harness,
80
+ ...path !== void 0 ? { path } : {},
81
+ added: [],
82
+ removed: [],
83
+ alreadyPresent: [],
84
+ addedFree: [],
85
+ alreadyPresentFree: [],
86
+ skipped: reason,
87
+ ...warning !== void 0 ? { warning } : {},
88
+ fix: fixFor(reason)
89
+ };
90
+ }
91
+ function permissionsSkipped(harness, homeDir, reason) {
92
+ const path = harness === "claude" ? claudeSettingsPath(homeDir) : void 0;
93
+ return skip(harness, path, reason);
94
+ }
95
+ function isPlainObject(value) {
96
+ return typeof value === "object" && value !== null && !Array.isArray(value);
97
+ }
98
+ async function writeSettings(path, next) {
99
+ const current = await stat(path).catch(() => null);
100
+ await writeFileAtomic(
101
+ path,
102
+ `${JSON.stringify(next, null, 2)}
103
+ `,
104
+ current === null ? {} : { mode: current.mode & 511 }
105
+ );
106
+ }
107
+ async function retractModeGatedRules(homeDir) {
108
+ const found = await inspectAllowlist(homeDir, "review");
109
+ if ("result" in found) {
110
+ const refused = found.result;
111
+ return {
112
+ ...refused,
113
+ fix: `${refused.path ?? claudeSettingsPath(homeDir)} could not be read, so ${MODE_GATED_RULES.join(" and ")} may still be allowed there. Remove those lines by hand, or run \`tenjin uninstall\`.`
114
+ };
115
+ }
116
+ const { path, raw, settings, permissions, allow } = found;
117
+ const gated = new Set(MODE_GATED_RULES);
118
+ const removed = allow.filter((r) => typeof r === "string" && gated.has(r));
119
+ if (removed.length === 0) {
120
+ return {
121
+ harness: "claude",
122
+ path,
123
+ added: [],
124
+ alreadyPresent: [],
125
+ addedFree: [],
126
+ alreadyPresentFree: [],
127
+ removed: []
128
+ };
129
+ }
130
+ const kept = allow.filter((r) => !(typeof r === "string" && gated.has(r)));
131
+ const next = { ...settings, permissions: { ...permissions, allow: kept } };
132
+ const current = await readFile(path, "utf8").catch(() => null);
133
+ if (current !== raw) {
134
+ return skip(
135
+ "claude",
136
+ path,
137
+ "changed-since-read",
138
+ `${path} changed while it was being updated, so nothing was written. Re-run to retract ${MODE_GATED_RULES.join(" and ")}.`
139
+ );
140
+ }
141
+ await writeSettings(path, next);
142
+ return {
143
+ harness: "claude",
144
+ path,
145
+ added: [],
146
+ alreadyPresent: [],
147
+ addedFree: [],
148
+ alreadyPresentFree: [],
149
+ removed
150
+ };
151
+ }
152
+ async function planFreeVerbAllowlist(homeDir, mode = "review") {
153
+ const found = await inspectAllowlist(homeDir, mode);
154
+ if ("result" in found) return { ...found.result, planned: true };
155
+ const retired = retiredFor(mode);
156
+ const wouldRemove = found.allow.filter(
157
+ (r) => typeof r === "string" && retired.has(r)
158
+ );
159
+ return {
160
+ harness: "claude",
161
+ path: found.path,
162
+ planned: true,
163
+ skipped: "dry-run",
164
+ fix: fixFor("dry-run"),
165
+ added: [...found.added],
166
+ alreadyPresent: [...found.alreadyPresent],
167
+ ...tiers(found.added, found.alreadyPresent, mode, true),
168
+ removed: wouldRemove
169
+ };
170
+ }
171
+ async function wireFreeVerbAllowlist(homeDir, mode = "review") {
172
+ const found = await inspectAllowlist(homeDir, mode);
173
+ if ("result" in found) return found.result;
174
+ const { path, raw, settings, permissions, allow, added, alreadyPresent } = found;
175
+ const retired = retiredFor(mode);
176
+ const removed = allow.filter((r) => typeof r === "string" && retired.has(r));
177
+ if (added.length === 0 && removed.length === 0) {
178
+ return {
179
+ harness: "claude",
180
+ path,
181
+ added: [],
182
+ alreadyPresent,
183
+ ...tiers([], alreadyPresent, mode),
184
+ removed: []
185
+ };
186
+ }
187
+ const kept = allow.filter((r) => !(typeof r === "string" && retired.has(r)));
188
+ const next = {
189
+ ...settings,
190
+ permissions: { ...permissions, allow: [...kept, ...added] }
191
+ };
192
+ const current = await readFile(path, "utf8").catch(() => null);
193
+ if (current !== raw) {
194
+ return skip(
195
+ "claude",
196
+ path,
197
+ "changed-since-read",
198
+ `${path} changed while it was being updated, so nothing was written. Re-run \`tenjin install\`.`
199
+ );
200
+ }
201
+ await writeSettings(path, next);
202
+ return {
203
+ harness: "claude",
204
+ path,
205
+ added,
206
+ alreadyPresent,
207
+ ...tiers(added, alreadyPresent, mode),
208
+ removed
209
+ };
210
+ }
211
+ async function inspectFreeVerbRules(homeDir, mode = "review") {
212
+ const found = await inspectAllowlist(homeDir, mode);
213
+ if ("result" in found) return { pending: null };
214
+ if (found.added.length > 0) return { pending: found.added };
215
+ const retired = retiredFor(mode);
216
+ if (found.allow.some((r) => typeof r === "string" && retired.has(r))) return { pending: [] };
217
+ return {
218
+ pending: [],
219
+ satisfied: {
220
+ harness: "claude",
221
+ path: found.path,
222
+ added: [],
223
+ alreadyPresent: found.alreadyPresent,
224
+ ...tiers([], found.alreadyPresent, mode),
225
+ removed: []
226
+ }
227
+ };
228
+ }
229
+ async function inspectAllowlist(homeDir, mode) {
230
+ const declaredPath = claudeSettingsPath(homeDir);
231
+ const refuse = (p, reason, warning) => ({ result: skip("claude", p, reason, warning) });
232
+ const entry = await lstat(declaredPath).catch(() => null);
233
+ let path = declaredPath;
234
+ if (entry !== null) {
235
+ try {
236
+ path = await realpath(declaredPath);
237
+ } catch (err) {
238
+ return refuse(
239
+ declaredPath,
240
+ "unresolvable",
241
+ `${declaredPath} could not be resolved (${err.message}); it was left exactly as it is.`
242
+ );
243
+ }
244
+ }
245
+ let settings = {};
246
+ let raw = null;
247
+ if (entry !== null) {
248
+ try {
249
+ raw = await readFile(path, "utf8");
250
+ } catch (err) {
251
+ return refuse(
252
+ path,
253
+ "unreadable",
254
+ `${path} could not be read (${err.message}); no permissions were written.`
255
+ );
256
+ }
257
+ let parsed;
258
+ try {
259
+ parsed = JSON.parse(raw);
260
+ } catch (err) {
261
+ return refuse(
262
+ path,
263
+ "unparsable",
264
+ `${path} is not valid JSON (${err.message}); it was left exactly as it is.`
265
+ );
266
+ }
267
+ if (!isPlainObject(parsed)) {
268
+ return refuse(
269
+ path,
270
+ "unexpected-shape",
271
+ `${path} is not a JSON object; it was left exactly as it is.`
272
+ );
273
+ }
274
+ settings = parsed;
275
+ }
276
+ const permissionsValue = settings.permissions;
277
+ if (permissionsValue !== void 0 && !isPlainObject(permissionsValue)) {
278
+ return refuse(
279
+ path,
280
+ "unexpected-shape",
281
+ `${path} has a "permissions" key that is not an object; it was left exactly as it is.`
282
+ );
283
+ }
284
+ const permissions = permissionsValue ?? {};
285
+ const allowValue = permissions.allow;
286
+ if (allowValue !== void 0 && !Array.isArray(allowValue)) {
287
+ return refuse(
288
+ path,
289
+ "unexpected-shape",
290
+ `${path} has a "permissions.allow" key that is not an array; it was left exactly as it is.`
291
+ );
292
+ }
293
+ const allow = allowValue ?? [];
294
+ const present = new Set(allow.filter((e) => typeof e === "string"));
295
+ const writable = rulesForPublishMode(mode);
296
+ const added = writable.filter((rule) => !present.has(rule));
297
+ const alreadyPresent = writable.filter((rule) => present.has(rule));
298
+ return { path, raw, settings, permissions, allow, added, alreadyPresent: [...alreadyPresent] };
299
+ }
300
+
301
+ export {
302
+ claudeSettingsPath,
303
+ FREE_VERB_RULES,
304
+ MODE_GATED_RULES,
305
+ rulesForPublishMode,
306
+ LEGACY_ALLOWLIST_RULES,
307
+ permissionsSkipped,
308
+ retractModeGatedRules,
309
+ planFreeVerbAllowlist,
310
+ wireFreeVerbAllowlist,
311
+ inspectFreeVerbRules
312
+ };
313
+ //# sourceMappingURL=chunk-IU2HVT3Y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/harness-permissions.ts"],"sourcesContent":["import { lstat, readFile, realpath, stat } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { writeFileAtomic } from './atomic-json';\nimport type { PublishMode } from './config';\n\n/**\n * The one place the CLI WRITES a permission grant into a harness's own settings\n * file, so the invariants live here rather than at the call site:\n *\n * - OPT-OUT, AND DISCLOSED. An interactive install asks; a non-interactive one\n * writes the free tier by default, because an unattended agent that gets\n * denied is the failure this whole file exists to prevent, and a machine run\n * has no one to ask. `--no-allow-free-verbs` refuses it outright, and every\n * run that writes says which rules landed, in which file, and how to remove\n * them. What keeps that defensible is the next two invariants: the grant is a\n * fixed free tier, and it can never widen.\n * - TWO FIXED SETS, AND NOT PARAMETERIZED. The writer takes no rule argument.\n * It takes a {@link PublishMode}, and that selects between exactly two\n * hardcoded constants: {@link FREE_VERB_RULES}, and those plus\n * {@link MODE_GATED_RULES}. So there is no call path — no flag, no config\n * key, no future caller — that can make it write `buy`, `session start`,\n * `send`, `config set`, `wallet create`, `mcp`, `install`, or a broad\n * `Bash(tenjin:*)`. A CLI that could widen its own permission grant is exactly\n * what this shape rules out.\n *\n * The publish rule is gated on the mode and on nothing else. INSTALLING\n * TENJIN IS THE CONSENT for it (owner call, PR #164): every install settles\n * `publish.mode` at `auto` unless told otherwise, and the FIRST install\n * writes this rule alongside the free tier rather than waiting for a second\n * run to read that default back as a choice. What keeps it defensible is\n * disclosure rather than provenance — the install output names the mode,\n * this rule, and the three ways out. Being on `auto` already means \"a clean\n * publish proceeds without asking\", and a harness prompt in front of it asks\n * that same question again somewhere the mode cannot answer (#161). Going\n * back to `review` RETRACTS the rule, on the next `install` or immediately\n * through `config set publish.mode review`, so a grant never outlives the\n * mode that justified it; `uninstall` reclaims it outright.\n *\n * What this does NOT loosen: the rule clears the HARNESS prompt and nothing\n * else. The CLI's own gates are untouched — the deterministic scan blocks a\n * hard finding in every mode and no `--yes` clears it, and `review` still\n * asks per publish. An agent cannot reach `install` or `config set` on its\n * own either; both are never-allowlisted.\n * - ADDITIVE, PLUS ONE RETRACTION THAT IS STILL OURS. Every other key in the\n * file, and every allow-rule we did not write, is copied through verbatim in\n * its original order; missing rules are appended. The single exception is\n * {@link LEGACY_ALLOWLIST_RULES}: a rule an EARLIER version of this same\n * writer put there and this one no longer recommends. Leaving it would mean\n * a user who updates and re-runs `install` keeps a grant for a command that\n * no longer exists, which is bloat we created and only we can clear. It\n * widens nothing — the set is disjoint from what we write, a test pins that\n * — and every removal is reported like every addition. A re-run on a current\n * machine still changes nothing.\n * - NEVER CLOBBERS. A settings file we cannot parse, or whose `permissions` /\n * `permissions.allow` is not the shape we expect, is left untouched and\n * reported as skipped. We do not \"repair\" someone's hand-edited config.\n *\n * The rules mirror lib/permissions.ts's ALWAYS_SAFE_ALLOWLIST (the block\n * `doctor` prints and the README quotes) and are duplicated as literals on\n * purpose: that module is a DOCUMENT whose safe tier could grow, and a widened\n * tier must not silently widen what install writes. A test pins the two lists\n * equal, so drift is a red build rather than a broader grant.\n */\n\n/** Claude Code's user-level settings file, the only file this module writes. */\nexport function claudeSettingsPath(homeDir: string): string {\n return join(homeDir, '.claude', 'settings.json');\n}\n\n/**\n * The exact rules install may add. Free verbs only: none of them can spend USDC\n * or move your keys. See lib/permissions.ts for the per-verb notes and for\n * the flag caveat that qualifies every prefix rule.\n */\nexport const FREE_VERB_RULES: readonly string[] = [\n 'Bash(tenjin search:*)',\n 'Bash(tenjin fund:*)',\n 'Bash(tenjin inspect:*)',\n 'Bash(tenjin read:*)',\n 'Bash(tenjin outcome:*)',\n 'Bash(tenjin doctor:*)',\n 'Bash(tenjin wallet show:*)',\n 'Bash(tenjin wallet balance:*)',\n 'Bash(tenjin config get:*)',\n];\n\n/**\n * The rule `publish.mode` gates, mirroring lib/permissions.ts's\n * PUBLISH_MODE_ALLOWLIST and duplicated as a literal for the same reason\n * {@link FREE_VERB_RULES} is: that module is a DOCUMENT, and an edit there must\n * not silently change what this file writes. A test pins the two together.\n *\n * Deliberately NOT a member of {@link FREE_VERB_RULES}: it can neither spend nor\n * move keys, but it publishes publicly under the operator's identity, so it is\n * not free-tier and never rides along with it.\n */\nexport const PUBLISH_MODE_RULE = 'Bash(tenjin publish:*)';\n\n/**\n * The other half of the mode-gated pair. `edit` runs the SAME publish.mode\n * consent gate in the CLI (lib/consent.ts's needsConfirmation), touches only\n * posts this wallet already owns, spends nothing, and creates no new public\n * content — strictly narrower than the publish rule it travels with. A mode that\n * can publish a new post unattended but cannot fix that post's price is the\n * asymmetry the mode exists to remove.\n */\nexport const EDIT_MODE_RULE = 'Bash(tenjin edit:*)';\n\n/** The pair the publish modes carry, in the order they are written and reported. */\nexport const MODE_GATED_RULES: readonly string[] = [PUBLISH_MODE_RULE, EDIT_MODE_RULE];\n\n/**\n * Verb fragments that must never appear in {@link MODE_GATED_RULES}: the rail\n * {@link FORBIDDEN_VERB_FRAGMENTS} gives the free tier, minus the two verbs this\n * set exists to carry.\n *\n * It needs that rail more than the free tier does. This set was mode-conditional\n * prose before and is WRITTEN BY DEFAULT on every install now, so a line added\n * here ships a grant to every machine — and without this, adding\n * `Bash(tenjin buy:*)` to the pair passes the entire suite, because every other\n * assertion on it compares against PUBLISH_MODE_ALLOWLIST, a document editable in\n * the same commit.\n */\nexport const MODE_GATED_FORBIDDEN_FRAGMENTS: readonly string[] = [\n 'tenjin buy',\n 'tenjin session',\n 'tenjin send',\n 'tenjin config set',\n 'tenjin wallet create',\n 'tenjin mcp',\n 'tenjin install',\n 'tenjin update',\n];\n\n/**\n * Exactly what may be written for `mode`. The two return values are the only two\n * rule sets this module can produce.\n */\nexport function rulesForPublishMode(mode: PublishMode): readonly string[] {\n return mode === 'review' ? FREE_VERB_RULES : [...FREE_VERB_RULES, ...MODE_GATED_RULES];\n}\n\n/**\n * What this run should sweep out: what an older version wrote, plus the publish\n * rule when the mode no longer justifies it. A retraction is always a rule this\n * CLI wrote under a setting the operator has since changed, and it is reported\n * exactly like an addition.\n */\nfunction retiredFor(mode: PublishMode): Set<string> {\n const retired = new Set<string>(LEGACY_ALLOWLIST_RULES);\n if (mode === 'review') for (const rule of MODE_GATED_RULES) retired.add(rule);\n return retired;\n}\n\n/**\n * Rules a PRIOR version of this writer put in `permissions.allow` and this one\n * no longer writes — FREE TIER OR MODE-GATED, which is why this is not\n * `LEGACY_FREE_VERB_RULES` any more. Nothing is stranded today, but the day a\n * mode-gated rule is renamed or dropped, every machine holding it would keep a\n * publish-capable allow-line that no `install` and no `uninstall` reclaims. That\n * is one layer above the bug this list was created to fix, so the list covers\n * both layers. BOTH paths read it: `install` removes them on its next\n * run, `uninstall` reclaims them as its own. NEITHER path ever writes one — the\n * writable set is {@link FREE_VERB_RULES} and this list is disjoint from it, so\n * a retired rule can only ever be deleted, never re-added. A test pins that\n * disjointness, because the day the two overlap is the day install starts\n * re-adding a grant for a command that does not exist.\n *\n * Why it has to exist at all: a rule dropped from FREE_VERB_RULES is otherwise\n * invisible to every later version. The operator keeps an allow-line for a\n * command that no longer exists, `install` walks past it because it is not in\n * the set it writes, and `uninstall` walks past it because it is no longer\n * \"ours\". It IS ours — we wrote it — and a user who updates and re-runs\n * `install` should end up with exactly the current tier and nothing we left\n * behind. Anything retired from the free tier belongs here.\n *\n * `Bash(tenjin candidate list:*)` is the first entry: the candidate pen was\n * removed, and machines installed before that still carry its rule.\n */\nexport const LEGACY_ALLOWLIST_RULES: readonly string[] = ['Bash(tenjin candidate list:*)'];\n\n/**\n * Verb fragments that must never appear in {@link FREE_VERB_RULES}. Asserted by\n * a test rather than at runtime: the constant above is not reachable from any\n * input, so the only way one of these lands in it is an edit to this file, and a\n * test is what catches an edit.\n */\nexport const FORBIDDEN_VERB_FRAGMENTS: readonly string[] = [\n 'tenjin buy',\n 'tenjin publish',\n 'tenjin edit',\n 'tenjin session',\n 'tenjin send',\n 'tenjin config set',\n 'tenjin wallet create',\n 'tenjin mcp',\n 'tenjin install',\n 'Bash(tenjin:*)',\n];\n\n/**\n * Why no rules were written. Every value is a reason to leave the file alone,\n * never a partial write: the writer either appends all missing rules or none.\n */\nexport type PermissionsSkipReason =\n | 'harness-not-claude'\n | 'not-requested'\n | 'declined'\n | 'dry-run'\n | 'unresolvable'\n | 'unreadable'\n | 'unparsable'\n | 'unexpected-shape'\n | 'changed-since-read';\n\n/**\n * The mode-gated half of a write, as DATA rather than as prose a caller\n * re-derives.\n *\n * Every surface that reports the grant reads this one object: the walkthrough's\n * disclosure line, the `--json` envelope on the headless path (where nobody was\n * asked and the output is the only disclosure there is), and the tests. The\n * earlier shape returned one undifferentiated `added`, so each surface split the\n * tiers itself — and two of them counted `publish` and `edit` as free verbs while\n * a third never rendered at all.\n */\nexport interface ModeGrant {\n /** The mode-gated rules now in effect on this machine. */\n rules: string[];\n /**\n * Written by THIS run, already there, or one of each. On a `--dry-run` plan it\n * is what a real run WOULD produce, and {@link PermissionsResult.planned} is the\n * field that says so; the `disclosure` sentence changes tense to match.\n */\n state: 'added' | 'already-present' | 'mixed';\n /** The plain sentence naming what the grant allows; the walkthrough colorizes it. */\n disclosure: string;\n /** Every command that takes it back, in the order the walkthrough prints them. */\n undo: string[];\n}\n\n/** The three undos, named wherever a mode-gated grant is reported. */\nexport const MODE_GRANT_UNDO: readonly string[] = [\n 'tenjin install --publish-mode review',\n 'tenjin config set publish.mode review',\n 'tenjin uninstall',\n];\n\n/**\n * Build the grant record for `mode`, or undefined when the mode carries no rules\n * or none of them ended up on this machine.\n */\nfunction modeGrantFor(\n mode: PublishMode,\n added: readonly string[],\n present: readonly string[],\n planned: boolean,\n): ModeGrant | undefined {\n const wasAdded = MODE_GATED_RULES.filter((r) => added.includes(r));\n const wasPresent = MODE_GATED_RULES.filter((r) => present.includes(r));\n const rules = [...wasAdded, ...wasPresent];\n if (rules.length === 0) return undefined;\n const state =\n wasAdded.length === 0 ? 'already-present' : wasPresent.length === 0 ? 'added' : 'mixed';\n // A plan says \"would be added\". The `planned` flag alone left this sentence in\n // the past tense, and it is the one string a reader quotes back.\n const verb =\n state === 'already-present'\n ? 'already present'\n : state === 'mixed'\n ? planned\n ? 'would be in place'\n : 'in place'\n : planned\n ? 'would be added'\n : 'added';\n return {\n rules: MODE_GATED_RULES.filter((r) => rules.includes(r)),\n state,\n disclosure: `${MODE_GATED_RULES.join(' and ')} ${verb}: on publish.mode ${mode} your agent can publish to the public marketplace under your identity, update its own posts, and open your wallet keystore to sign, without a harness prompt.`,\n undo: [...MODE_GRANT_UNDO],\n };\n}\n\nexport interface PermissionsResult {\n /** The harness this outcome is about; only `claude` has a settings file we write. */\n harness: string;\n /**\n * The settings file, reported even when nothing was written so a human can go\n * look. ABSENT when the harness has no such file: naming a Claude path on a\n * Codex-only install would point the envelope's reader at a file that has\n * nothing to do with their harness.\n *\n * ONE EXCEPTION, in `install`'s `withRetraction`: a `review` run retracts from\n * `~/.claude/settings.json` above the harness guard, so a non-Claude result\n * carrying a non-empty `removed` carries that path too. The reason the general\n * rule exists is inverted there, because the run did change that file and the\n * operator cannot check which one without its name.\n */\n path?: string;\n added: string[];\n alreadyPresent: string[];\n /**\n * The FREE-TIER halves of the two lists above. Every count line reads these:\n * `publish` and `edit` are not free verbs, and a line calling eleven rules\n * \"free tenjin commands\" contradicts both this module and the `doctor` pointer\n * printed on the next screen.\n */\n /**\n * True when this result is a PLAN rather than a record: `--dry-run` fills\n * `added`, `alreadyPresent` and `modeGrant` with what a real run would do and\n * writes nothing. Every reader that treats a non-empty `added` as \"this landed\"\n * has to check it, which is the point of a flag rather than a parallel shape.\n */\n planned?: boolean;\n addedFree: string[];\n alreadyPresentFree: string[];\n /** The mode-gated half, or absent when this write carried none. */\n modeGrant?: ModeGrant;\n /**\n * Rules an EARLIER version of this writer wrote and this one retired, removed\n * on this run. Almost always empty; non-empty exactly once, on the first\n * install after an update that retired something.\n */\n removed: string[];\n skipped?: PermissionsSkipReason;\n /** Human-readable detail for a skip that is a problem rather than a choice. */\n warning?: string;\n /**\n * The exact command that changes this outcome, present on EVERY skipped state.\n * Same contract as a CliError's `fix`: a machine consumer reading the envelope\n * gets the remedy as a field, never as prose it has to interpret. The human\n * walkthrough renders its own wording from `skipped`, so the two never collide.\n */\n fix?: string;\n}\n\n/**\n * The command that turns a skip into a write. Kept beside the reason vocabulary\n * so a new reason cannot ship without one.\n */\nfunction fixFor(reason: PermissionsSkipReason): string {\n switch (reason) {\n case 'harness-not-claude':\n return 'This allowlist is Claude Code only. Run `tenjin doctor` for the lines your harness needs.';\n case 'not-requested':\n case 'declined':\n case 'dry-run':\n return 'Add them with `tenjin install --allow-free-verbs`.';\n case 'changed-since-read':\n return 'Another process changed the file mid-run; re-run `tenjin install`.';\n default:\n return 'Fix the reported file, then run `tenjin install --allow-free-verbs`.';\n }\n}\n\n/**\n * The tier split plus the grant record, derived once from the two rule lists so\n * no caller re-derives it. Spread into every non-skipped result.\n */\nfunction tiers(\n added: readonly string[],\n alreadyPresent: readonly string[],\n mode: PublishMode,\n planned = false,\n): Pick<PermissionsResult, 'addedFree' | 'alreadyPresentFree'> & { modeGrant?: ModeGrant } {\n const gated = new Set<string>(MODE_GATED_RULES);\n const grant = modeGrantFor(mode, added, alreadyPresent, planned);\n return {\n addedFree: added.filter((r) => !gated.has(r)),\n alreadyPresentFree: alreadyPresent.filter((r) => !gated.has(r)),\n ...(grant !== undefined ? { modeGrant: grant } : {}),\n };\n}\n\nfunction skip(\n harness: string,\n path: string | undefined,\n reason: PermissionsSkipReason,\n warning?: string,\n): PermissionsResult {\n return {\n harness,\n ...(path !== undefined ? { path } : {}),\n added: [],\n removed: [],\n alreadyPresent: [],\n addedFree: [],\n alreadyPresentFree: [],\n skipped: reason,\n ...(warning !== undefined ? { warning } : {}),\n fix: fixFor(reason),\n };\n}\n\n/** A decision NOT to write, shaped like a write outcome so the caller has one type. */\nexport function permissionsSkipped(\n harness: string,\n homeDir: string,\n reason: PermissionsSkipReason,\n): PermissionsResult {\n const path = harness === 'claude' ? claudeSettingsPath(homeDir) : undefined;\n return skip(harness, path, reason);\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Write settings.json KEEPING THE MODE IT HAS. Operators `chmod 600` this file —\n * it commonly holds an `env` block and `apiKeyHelper` — and handing it back\n * world-readable because we appended a permission line is a downgrade nobody\n * asked for. A file we are creating gets the platform default. Mirrors\n * lib/skill-writer.ts, which already does this for skills.\n */\nasync function writeSettings(path: string, next: Record<string, unknown>): Promise<void> {\n const current = await stat(path).catch(() => null);\n await writeFileAtomic(\n path,\n `${JSON.stringify(next, null, 2)}\\n`,\n current === null ? {} : { mode: current.mode & 0o777 },\n );\n}\n\n/**\n * Remove {@link MODE_GATED_RULES}, and nothing else, from `permissions.allow`.\n *\n * SEPARATE FROM THE ADDITIVE WRITER, and that separation is the point. Retraction\n * used to ride the same call that appends the free tier, so it inherited that\n * call's precondition and bailed out whenever the free tier was not byte-exact —\n * silently, in the tightening direction, on two of the three commands the consent\n * decision names as its own undo. The stated rationale (a publish rule without\n * the free tier beside it was not written by our install) does not survive the\n * ordinary case: the first release that adds a tenth free verb makes every\n * existing machine's tier incomplete while the pair is genuinely ours, and an\n * unparsable file is UNKNOWN rather than not-ours.\n *\n * So `review` always retracts. This adds nothing, ever: it can only shorten the\n * allow list, which is why it needs no consent and no complete-tier precondition.\n */\nexport async function retractModeGatedRules(homeDir: string): Promise<PermissionsResult> {\n const found = await inspectAllowlist(homeDir, 'review');\n if ('result' in found) {\n // Unknown, not absent. The one case that cannot proceed says so, names the\n // rules and the file, and hands over the command that always works.\n const refused = found.result;\n return {\n ...refused,\n fix: `${refused.path ?? claudeSettingsPath(homeDir)} could not be read, so ${MODE_GATED_RULES.join(' and ')} may still be allowed there. Remove those lines by hand, or run \\`tenjin uninstall\\`.`,\n };\n }\n const { path, raw, settings, permissions, allow } = found;\n const gated = new Set<string>(MODE_GATED_RULES);\n const removed = allow.filter((r): r is string => typeof r === 'string' && gated.has(r));\n if (removed.length === 0) {\n return {\n harness: 'claude',\n path,\n added: [],\n alreadyPresent: [],\n addedFree: [],\n alreadyPresentFree: [],\n removed: [],\n };\n }\n const kept = allow.filter((r) => !(typeof r === 'string' && gated.has(r)));\n const next = { ...settings, permissions: { ...permissions, allow: kept } };\n const current = await readFile(path, 'utf8').catch(() => null);\n if (current !== raw) {\n return skip(\n 'claude',\n path,\n 'changed-since-read',\n `${path} changed while it was being updated, so nothing was written. Re-run to retract ${MODE_GATED_RULES.join(' and ')}.`,\n );\n }\n await writeSettings(path, next);\n return {\n harness: 'claude',\n path,\n added: [],\n alreadyPresent: [],\n addedFree: [],\n alreadyPresentFree: [],\n removed,\n };\n}\n\n/**\n * Add the rules `mode` calls for to `permissions.allow` in\n * ~/.claude/settings.json. Creates the file (and the `permissions.allow` path)\n * when absent, appends only the rules that are missing, and rewrites nothing\n * else. Idempotent: a second run at the same mode returns `added: []` with every\n * rule under `alreadyPresent` and does not touch the file at all.\n */\n/**\n * What {@link wireFreeVerbAllowlist} WOULD do, without doing it.\n *\n * `--dry-run` used to report the allowlist as a bare `dry-run` skip with an empty\n * `added` and no `modeGrant`, so an operator dry-running precisely to learn\n * whether `publish` and `edit` would be granted learned nothing. It reads through\n * the same `inspectAllowlist` the writer does and fills the same fields, marked\n * `planned` so nothing mistakes a plan for a record.\n */\nexport async function planFreeVerbAllowlist(\n homeDir: string,\n mode: PublishMode = 'review',\n): Promise<PermissionsResult> {\n const found = await inspectAllowlist(homeDir, mode);\n // Unreadable, unparsable, wrong shape: a real run could not write either, and\n // the reason it gives is the honest plan.\n if ('result' in found) return { ...found.result, planned: true };\n const retired = retiredFor(mode);\n const wouldRemove = found.allow.filter(\n (r): r is string => typeof r === 'string' && retired.has(r),\n );\n return {\n harness: 'claude',\n path: found.path,\n planned: true,\n skipped: 'dry-run',\n fix: fixFor('dry-run'),\n added: [...found.added],\n alreadyPresent: [...found.alreadyPresent],\n ...tiers(found.added, found.alreadyPresent, mode, true),\n removed: wouldRemove,\n };\n}\n\nexport async function wireFreeVerbAllowlist(\n homeDir: string,\n mode: PublishMode = 'review',\n): Promise<PermissionsResult> {\n const found = await inspectAllowlist(homeDir, mode);\n if ('result' in found) return found.result;\n const { path, raw, settings, permissions, allow, added, alreadyPresent } = found;\n // Rules an earlier version of this writer left behind, and the publish rule\n // when the mode no longer carries it. Swept on the same pass that appends, so\n // one `tenjin install` leaves a settings.json holding exactly what this\n // machine's current mode calls for and no residue from what it used to be.\n const retired = retiredFor(mode);\n const removed = allow.filter((r): r is string => typeof r === 'string' && retired.has(r));\n if (added.length === 0 && removed.length === 0) {\n return {\n harness: 'claude',\n path,\n added: [],\n alreadyPresent,\n ...tiers([], alreadyPresent, mode),\n removed: [],\n };\n }\n\n // Object spreads keep the original key order and land the rebuilt `permissions`\n // in the slot it already occupied, so a diff of the file is the appended rules,\n // the retired ones dropped, and nothing else.\n const kept = allow.filter((r) => !(typeof r === 'string' && retired.has(r)));\n const next = {\n ...settings,\n permissions: { ...permissions, allow: [...kept, ...added] },\n };\n // This is a whole-file read-modify-write, so a change landing between the read\n // and the rename would be erased in full, including keys that have nothing to do\n // with permissions. Claude Code writes this file too, so the other writer is not\n // hypothetical. Compare the bytes we based the edit on and refuse rather than\n // clobber; the operator re-runs and the merge is recomputed against what is\n // actually there.\n const current = await readFile(path, 'utf8').catch(() => null);\n if (current !== raw) {\n return skip(\n 'claude',\n path,\n 'changed-since-read',\n `${path} changed while it was being updated, so nothing was written. Re-run \\`tenjin install\\`.`,\n );\n }\n await writeSettings(path, next);\n return {\n harness: 'claude',\n path,\n added,\n alreadyPresent,\n ...tiers(added, alreadyPresent, mode),\n removed,\n };\n}\n\n/**\n * The probe the install walkthrough uses: what is still missing, plus the outcome\n * to report when nothing is. Returning the SNAPSHOT's own result matters. Calling\n * the writer again after a zero-pending probe re-reads the file, so a rule revoked\n * between the two reads was silently re-added with no prompt, which is the one\n * thing a consent gate must not do.\n *\n * `pending` is null when the file cannot be understood; that is \"unknown\", never\n * \"already allowed\", and the caller must still ask.\n *\n * `satisfied` is returned ONLY when there is nothing to add AND nothing retired\n * to sweep. A machine that already carries every current rule plus one an older\n * version wrote is NOT satisfied: reporting it as such would short-circuit the\n * writer and strand exactly the rule the sweep exists to clear. `pending` stays\n * empty there, so the caller can tell \"nothing to grant, but work to do\" from\n * \"something to grant\" and skip the consent prompt for a run that only removes.\n */\nexport async function inspectFreeVerbRules(\n homeDir: string,\n mode: PublishMode = 'review',\n): Promise<{ pending: string[] | null; satisfied?: PermissionsResult }> {\n const found = await inspectAllowlist(homeDir, mode);\n if ('result' in found) return { pending: null };\n if (found.added.length > 0) return { pending: found.added };\n const retired = retiredFor(mode);\n if (found.allow.some((r) => typeof r === 'string' && retired.has(r))) return { pending: [] };\n return {\n pending: [],\n satisfied: {\n harness: 'claude',\n path: found.path,\n added: [],\n alreadyPresent: found.alreadyPresent,\n ...tiers([], found.alreadyPresent, mode),\n removed: [],\n },\n };\n}\n\ninterface AllowlistInspection {\n path: string;\n /** The exact bytes read, so the commit can prove nothing changed underneath it. */\n raw: string | null;\n settings: Record<string, unknown>;\n permissions: Record<string, unknown>;\n allow: unknown[];\n added: string[];\n alreadyPresent: string[];\n}\n\n/**\n * Resolve and read the settings file, and work out which rules are missing.\n * Every refusal this module can reach is decided here, so the probe and the\n * write agree by construction about what is untouchable.\n */\nasync function inspectAllowlist(\n homeDir: string,\n mode: PublishMode,\n): Promise<AllowlistInspection | { result: PermissionsResult }> {\n const declaredPath = claudeSettingsPath(homeDir);\n const refuse = (\n p: string,\n reason: PermissionsSkipReason,\n warning: string,\n ): { result: PermissionsResult } => ({ result: skip('claude', p, reason, warning) });\n\n // `lstat`, not `existsSync`: existsSync FOLLOWS a symlink, so a link pointing at\n // a file that is not there reads as \"absent\" and the create path below would\n // rename a regular file over the link. We need to know whether an ENTRY is\n // there, whatever it points at.\n const entry = await lstat(declaredPath).catch(() => null);\n\n // Resolve symlinks BEFORE writing. `writeFileAtomic` commits with a rename,\n // which replaces a symlink with a regular file: a settings.json linked into a\n // dotfiles repo would be severed, its target left stale, and future edits there\n // would stop reaching Claude Code. Renaming over the RESOLVED path edits the\n // file the operator actually maintains and leaves the link intact, which is\n // what this module's additive-only, never-clobber invariants promise. A link we\n // cannot resolve is left alone rather than overwritten; for a genuinely absent\n // file there is nothing to follow and we create it at the declared path.\n let path = declaredPath;\n if (entry !== null) {\n try {\n path = await realpath(declaredPath);\n } catch (err) {\n return refuse(\n declaredPath,\n 'unresolvable',\n `${declaredPath} could not be resolved (${(err as Error).message}); it was left exactly as it is.`,\n );\n }\n }\n\n let settings: Record<string, unknown> = {};\n let raw: string | null = null;\n if (entry !== null) {\n try {\n raw = await readFile(path, 'utf8');\n } catch (err) {\n return refuse(\n path,\n 'unreadable',\n `${path} could not be read (${(err as Error).message}); no permissions were written.`,\n );\n }\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (err) {\n return refuse(\n path,\n 'unparsable',\n `${path} is not valid JSON (${(err as Error).message}); it was left exactly as it is.`,\n );\n }\n if (!isPlainObject(parsed)) {\n return refuse(\n path,\n 'unexpected-shape',\n `${path} is not a JSON object; it was left exactly as it is.`,\n );\n }\n settings = parsed;\n }\n\n // `permissions` and `permissions.allow` may be absent (we create them), but a\n // present one of the wrong type is someone else's structure: refuse rather\n // than replace it. Unknown entry types inside `allow` are fine and ride\n // through verbatim; they simply never match a rule.\n const permissionsValue = settings.permissions;\n if (permissionsValue !== undefined && !isPlainObject(permissionsValue)) {\n return refuse(\n path,\n 'unexpected-shape',\n `${path} has a \"permissions\" key that is not an object; it was left exactly as it is.`,\n );\n }\n const permissions: Record<string, unknown> = permissionsValue ?? {};\n const allowValue = permissions.allow;\n if (allowValue !== undefined && !Array.isArray(allowValue)) {\n return refuse(\n path,\n 'unexpected-shape',\n `${path} has a \"permissions.allow\" key that is not an array; it was left exactly as it is.`,\n );\n }\n const allow: unknown[] = allowValue ?? [];\n\n const present = new Set(allow.filter((e): e is string => typeof e === 'string'));\n const writable = rulesForPublishMode(mode);\n const added = writable.filter((rule) => !present.has(rule));\n const alreadyPresent = writable.filter((rule) => present.has(rule));\n return { path, raw, settings, permissions, allow, added, alreadyPresent: [...alreadyPresent] };\n}\n"],"mappings":";;;;;;AAAA,SAAS,OAAO,UAAU,UAAU,YAAY;AAChD,SAAS,YAAY;AAgEd,SAAS,mBAAmB,SAAyB;AAC1D,SAAO,KAAK,SAAS,WAAW,eAAe;AACjD;AAOO,IAAM,kBAAqC;AAAA,EAChD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAYO,IAAM,oBAAoB;AAU1B,IAAM,iBAAiB;AAGvB,IAAM,mBAAsC,CAAC,mBAAmB,cAAc;AA6B9E,SAAS,oBAAoB,MAAsC;AACxE,SAAO,SAAS,WAAW,kBAAkB,CAAC,GAAG,iBAAiB,GAAG,gBAAgB;AACvF;AAQA,SAAS,WAAW,MAAgC;AAClD,QAAM,UAAU,IAAI,IAAY,sBAAsB;AACtD,MAAI,SAAS,SAAU,YAAW,QAAQ,iBAAkB,SAAQ,IAAI,IAAI;AAC5E,SAAO;AACT;AA2BO,IAAM,yBAA4C,CAAC,+BAA+B;AA+DlF,IAAM,kBAAqC;AAAA,EAChD;AAAA,EACA;AAAA,EACA;AACF;AAMA,SAAS,aACP,MACA,OACA,SACA,SACuB;AACvB,QAAM,WAAW,iBAAiB,OAAO,CAAC,MAAM,MAAM,SAAS,CAAC,CAAC;AACjE,QAAM,aAAa,iBAAiB,OAAO,CAAC,MAAM,QAAQ,SAAS,CAAC,CAAC;AACrE,QAAM,QAAQ,CAAC,GAAG,UAAU,GAAG,UAAU;AACzC,MAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,QAAM,QACJ,SAAS,W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Ac,MAAM,GAAG;AAC1B,aAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA,GAAG,IAAI;AAAA,MACT;AAAA,IACF;AACA,eAAW;AAAA,EACb;AAMA,QAAM,mBAAmB,SAAS;AAClC,MAAI,qBAAqB,UAAa,CAAC,cAAc,gBAAgB,GAAG;AACtE,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,GAAG,IAAI;AAAA,IACT;AAAA,EACF;AACA,QAAM,cAAuC,oBAAoB,CAAC;AAClE,QAAM,aAAa,YAAY;AAC/B,MAAI,eAAe,UAAa,CAAC,MAAM,QAAQ,UAAU,GAAG;AAC1D,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,GAAG,IAAI;AAAA,IACT;AAAA,EACF;AACA,QAAM,QAAmB,cAAc,CAAC;AAExC,QAAM,UAAU,IAAI,IAAI,MAAM,OAAO,CAAC,MAAmB,OAAO,MAAM,QAAQ,CAAC;AAC/E,QAAM,WAAW,oBAAoB,IAAI;AACzC,QAAM,QAAQ,SAAS,OAAO,CAAC,SAAS,CAAC,QAAQ,IAAI,IAAI,CAAC;AAC1D,QAAM,iBAAiB,SAAS,OAAO,CAAC,SAAS,QAAQ,IAAI,IAAI,CAAC;AAClE,SAAO,EAAE,MAAM,KAAK,UAAU,aAAa,OAAO,OAAO,gBAAgB,CAAC,GAAG,cAAc,EAAE;AAC/F;","names":[]}
@@ -20,7 +20,7 @@ var ALWAYS_SAFE_ALLOWLIST = [
20
20
  {
21
21
  rule: "Bash(tenjin read:*)",
22
22
  command: "tenjin read",
23
- note: "Free-only delivery: free pieces, local-library re-reads, and pieces this wallet already owns when a read-scoped session key is cached. Cannot spend and cannot open the keystore \u2014 the wallet, payment, and session-MINTING modules are all absent from its import graph, so the key it may present is a P-256 delegation loaded from disk, which is the wrong curve to authorize a payment. TRANSMITS A CREDENTIAL: when a session key exists, a cold 402 sends that wallet-derived delegation to the server. It goes only to the origin the delegation was minted for, which is what stops a stray `--base-url` from redirecting it, and no scope on it limits what a holder could do with it. Not read-only: a freshly delivered piece is saved to the library."
23
+ note: "Free-only delivery: free pieces, local-library re-reads, and pieces this wallet already owns when a read-scoped session key is cached. Cannot spend and cannot open the keystore: the wallet, payment, and session-MINTING modules are all absent from its import graph, so the key it may present is a P-256 delegation loaded from disk, which is the wrong curve to authorize a payment. TRANSMITS A CREDENTIAL: when a session key exists, a cold 402 sends that wallet-derived delegation to the server. It goes only to the origin the delegation was minted for, which is what stops a stray `--base-url` from redirecting it, and no scope on it limits what a holder could do with it. Not read-only: a freshly delivered piece is saved to the library."
24
24
  },
25
25
  {
26
26
  rule: "Bash(tenjin outcome:*)",
@@ -57,9 +57,24 @@ var OPT_IN_ALLOWLIST = [
57
57
  {
58
58
  rule: "Bash(tenjin session start:*)",
59
59
  command: "tenjin session start",
60
- note: "OPENS THE KEYSTORE (one wallet signature), but SPENDS NOTHING and cannot: it mints a \u226424h P-256 session key so `tenjin read` can recover pieces you already own without paying. The delegated key is the wrong curve for a payment authorization, so no session file can ever move money. Do NOT read the `read` scope as a bound on the rest: the file it leaves is a wallet-derived credential, and what limits it is that it expires in 24h, lives 0600, and is refused off the origin it was minted for \u2014 not its scope. What you are opting into is unattended keystore access: on an encrypted wallet the passphrase prompt is skipped or answered from the environment, and the `--base-url` caveat below bites hardest here, because a mint against an attacker-chosen host is a wallet signature you did not intend to make."
60
+ note: "OPENS THE KEYSTORE (one wallet signature), but SPENDS NOTHING and cannot: it mints a \u226424h P-256 session key so `tenjin read` can recover pieces you already own without paying. The delegated key is the wrong curve for a payment authorization, so no session file can ever move money. Do NOT read the `read` scope as a bound on the rest: the file it leaves is a wallet-derived credential, and what limits it is that it expires in 24h, lives 0600, and is refused off the origin it was minted for, not its scope. What you are opting into is unattended keystore access: on an encrypted wallet the passphrase prompt is skipped or answered from the environment, and the `--base-url` caveat below bites hardest here, because a mint against an attacker-chosen host is a wallet signature you did not intend to make."
61
61
  }
62
62
  ];
63
+ var PUBLISH_MODE_ALLOWLIST = [
64
+ {
65
+ rule: "Bash(tenjin publish:*)",
66
+ command: "tenjin publish",
67
+ note: "PUBLISHES PUBLICLY under your identity, and is cleared only while publish.mode is auto or full-auto: the mode is the consent, and the harness prompt would ask for it twice. Three things it clears that the free tier never did. It OPENS THE KEYSTORE: publish always resolves a signer, and with no usable session it mints one at read+write scope, which is strictly broader than the read-only key `tenjin session start` exists as a deliberate opt-in for. It publishes the contents of ANY LOCAL FILE the agent can read, gated only by the heuristic scan. And it is a PREFIX rule, so it pins the verb and not the flags: `--base-url` rides it (see the flag caveat), and `--yes` is an ordinary flag on the same verb that clears exactly the WARN findings auto stopped on, so a re-run collapses auto into full-auto with nobody asked. What still gates a publish is the CLI: the deterministic secret scan blocks in every mode and no --yes clears it. The skills hold the rest of that line. Set publish.mode back to review and the rule is retracted."
68
+ },
69
+ {
70
+ rule: "Bash(tenjin edit:*)",
71
+ command: "tenjin edit",
72
+ note: "Updates posts your wallet ALREADY OWNS: reprices, refreshes an as-of date, repairs an answer card. Owner-scoped on both legs (GET and PUT /api/posts/<id> are signed and owner-only), spends nothing, moves no keys, and creates no new public content: a narrower blast radius than the publish rule beside it. It rides the same mode for the same reason: edit runs the identical publish.mode consent gate in the CLI (lib/consent.ts needsConfirmation), so a mode that publishes unattended and then cannot fix its own post\u2019s price is the asymmetry the mode exists to remove. It opens the keystore on the same terms as the publish rule beside it, and takes the same prefix-rule caveats. Removed by the same return to review."
73
+ }
74
+ ];
75
+ function modeGatedAllowlist(mode) {
76
+ return mode === "review" ? [] : PUBLISH_MODE_ALLOWLIST.map((e) => ({ ...e }));
77
+ }
63
78
  var NEVER_ALLOWLISTED = [
64
79
  {
65
80
  command: "tenjin send",
@@ -67,11 +82,11 @@ var NEVER_ALLOWLISTED = [
67
82
  },
68
83
  {
69
84
  command: "tenjin publish",
70
- reason: "Puts your content on a public marketplace under your identity."
85
+ reason: "Puts your content on a public marketplace under your identity. Never pre-cleared by the free tier or an opt-in line: the only thing that clears it is `publish.mode` auto or full-auto, which is the same human decision said once instead of twice (see PUBLISH_MODE_ALLOWLIST). Back on review, `install` takes the rule away again."
71
86
  },
72
87
  {
73
88
  command: "tenjin edit",
74
- reason: "Write-capable despite the no-flag form reading as a pure show: it edits live posts and answer cards under your identity, and moves prices. A prefix rule pins the verb, not the flags, so no rule can clear the read half without clearing the write half."
89
+ reason: "Write-capable despite the no-flag form reading as a pure show: it edits live posts and answer cards under your identity, and moves prices. A prefix rule pins the verb, not the flags, so no rule can clear the read half without clearing the write half. Never pre-cleared as a recommendation: like `tenjin publish`, the only thing that clears it is `publish.mode` auto or full-auto, whose consent gate it already shares (see PUBLISH_MODE_ALLOWLIST). Back on review, `install` takes the rule away again."
75
90
  },
76
91
  {
77
92
  command: "tenjin wallet create",
@@ -88,6 +103,10 @@ var NEVER_ALLOWLISTED = [
88
103
  {
89
104
  command: "tenjin mcp",
90
105
  reason: "Long-running server that re-exposes every command core over stdio; clearing it would indirectly clear everything above."
106
+ },
107
+ {
108
+ command: "tenjin update",
109
+ reason: "Replaces the tenjin binary the agent then runs, with whatever npm serves next. Which build an agent executes is an operator decision, not something a rule pre-clears. `--check` only reports, but a prefix rule pins the verb, not the flags."
91
110
  }
92
111
  ];
93
112
  var FLAG_CAVEAT = [
@@ -100,20 +119,28 @@ var FLAG_CAVEAT = [
100
119
  "Allowlist these verbs only if you are content for the agent to choose the destination",
101
120
  "host, and set the base URL in config instead of letting it be an argument. The skills",
102
121
  "tell agents never to pass --base-url on an allowlisted verb, but that is a convention,",
103
- "not an enforced boundary."
122
+ "not an enforced boundary.",
123
+ "This covers the two rules your publish.mode carries as well, and bites hardest there:",
124
+ "`tenjin publish --base-url <host>` is cleared by default on auto, and it signs against",
125
+ "the host it is given."
104
126
  ];
105
127
  var MCP_CAVEAT = [
128
+ "Note the asymmetry: publish.mode writes the Bash rules for `publish` and `edit`, and",
129
+ "deliberately does not touch the MCP tool grants below. The mode is a CLI-side consent",
130
+ "gate, and nothing reads it on the MCP surface, so clearing those tools would hand out",
131
+ "the same authority with none of the same gate. Aligning the two is tracked separately.",
106
132
  "Running the local MCP server (`tenjin mcp`) instead? That is a different permission",
107
133
  "surface: the harness gates TOOLS there, and these Bash rules do not apply. Leave",
108
134
  "`mcp__tenjin__tenjin_publish`, `mcp__tenjin__tenjin_edit`, and",
109
135
  "`mcp__tenjin__tenjin_wallet` gated. `tenjin_buy` is the same opt-in decision as the",
110
136
  "buy line above."
111
137
  ];
112
- function recommendedPermissions() {
138
+ function recommendedPermissions(mode = "review") {
113
139
  return {
114
140
  alwaysSafe: ALWAYS_SAFE_ALLOWLIST.map((e) => ({ ...e })),
115
141
  optIn: OPT_IN_ALLOWLIST.map((e) => ({ ...e })),
116
142
  neverAllowlisted: NEVER_ALLOWLISTED.map((e) => ({ ...e })),
143
+ modeGated: modeGatedAllowlist(mode),
117
144
  caveats: { flags: [...FLAG_CAVEAT], mcp: [...MCP_CAVEAT] }
118
145
  };
119
146
  }
@@ -121,10 +148,15 @@ var PERMISSIONS_DOC_URL = "https://github.com/BackTrackCo/tenjin-agent/blob/main
121
148
  function permissionsPointer() {
122
149
  return `Auto-mode permission allowlist and subagent delegation (${ALWAYS_SAFE_ALLOWLIST.length} free verbs, ${OPT_IN_ALLOWLIST.length} opt-ins, the --base-url caveat): ${PERMISSIONS_DOC_URL}`;
123
150
  }
151
+ function modeGatedPointer(mode, missing, remedy = "tenjin install") {
152
+ if (modeGatedAllowlist(mode).length === 0 || missing.length === 0) return null;
153
+ return `publish.mode=${mode} also needs ${missing.join(" and ")} in your harness allowlist, or it will prompt anyway; \`${remedy}\` writes them.`;
154
+ }
124
155
 
125
156
  export {
126
157
  recommendedPermissions,
127
158
  PERMISSIONS_DOC_URL,
128
- permissionsPointer
159
+ permissionsPointer,
160
+ modeGatedPointer
129
161
  };
130
- //# sourceMappingURL=chunk-4TCU3YRD.js.map
162
+ //# sourceMappingURL=chunk-IUQZ4Z7M.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/permissions.ts"],"sourcesContent":["/**\n * The recommended HARNESS permission allowlist: the exact rule lines an operator\n * pastes into Claude Code (or an equivalent harness) so auto mode stops denying\n * the free Tenjin verbs, and so the one paying verb is cleared deliberately\n * rather than by accident.\n *\n * This is a HARNESS-side allowlist (which shell commands the agent may run at\n * all). It is NOT the CLI's spend policy and shares nothing with it: the shipped\n * `allowlistCreators` config key gates WHO you may pay, this file gates WHICH\n * COMMANDS the harness will run without a prompt. The two are deliberately kept\n * apart in name and in code — clearing `Bash(tenjin buy:*)` here never raises a\n * spend cap. That is a claim about this file, NOT a claim that the spend policy\n * stops an allowlisted `buy`: `--yes` is an ordinary flag on an allowlisted verb\n * and `confirmSpend` returns true on it before any TTY check\n * (src/commands/buy.ts), so under CONFIG_DEFAULTS nothing denies. See\n * OPT_IN_ALLOWLIST's note for the walk-through.\n *\n * These are static, shipped constants on purpose: there is NO config key for\n * them. An operator-editable \"which commands may run\" list stored next to the\n * spend policy would be a second, weaker copy of a control the harness already\n * owns, and a CLI that could widen its own permission grant is exactly the shape\n * this file exists to avoid.\n *\n * Scope: `tenjin mcp` exposes the same command cores over MCP, where the harness\n * gates TOOLS, not Bash lines. These rules say nothing about that surface, which\n * is why `tenjin mcp` is itself never recommended here: clearing it would route\n * around every rule below. MCP_CAVEAT names the tools to leave gated for an\n * operator who runs the server anyway.\n *\n * LIMIT OF A PREFIX RULE, read this before adding an entry: the rule constrains\n * the VERB and nothing else. `addGlobalFlags` (src/cli.ts) puts `--json`,\n * `--timeout`, and `--base-url` on every leaf command, so every rule below also\n * clears `--base-url <url>` in trailing position. `--base-url` is validated as a\n * URL and nothing more, and it wins settings precedence, so it re-points the\n * trust boundary itself: the `search` question goes to that host, `doctor` probes\n * it, and `assertOnBaseOrigin` only checks that a resource URL shares an origin\n * with the CONFIGURED base, so an attacker-controlled pair satisfies the pin. No\n * prefix syntax expresses \"this verb but not that flag\", so the mitigation is\n * disclosure rather than a narrower rule: FLAG_CAVEAT rides the `--json` payload\n * and docs/agent-permissions.md, every human surface points at that page, and the\n * skills tell the agent never to pass `--base-url` on an allowlisted verb. Pinning\n * the paying path to a constant origin instead is the real fix and is an\n * x402/payments-semantics change, tracked separately.\n */\n\nimport type { PublishMode } from './config';\n\n/** One pasteable allowlist rule plus why it is safe (or what it costs). */\nexport interface AllowlistEntry {\n /** The exact line to add to the harness permission allowlist. */\n rule: string;\n /** The verb it clears. */\n command: string;\n /** Why it is safe to pre-clear, or what the operator is opting into. */\n note: string;\n}\n\n/** A verb deliberately kept OUT of the recommended allowlist, and why. */\nexport interface ExcludedVerb {\n command: string;\n reason: string;\n}\n\n/**\n * FREE verbs: they CANNOT SPEND AND CANNOT MOVE YOUR KEYS. That is the whole\n * definition of this tier, and it is deliberately narrower than the older \"no\n * wallet, no signing, no payment\" — which stopped being true the moment `read`\n * gained the ability to PRESENT a cached session key. `read` signs, with a P-256\n * delegation loaded from disk; it cannot mint one (that needs the wallet, and its\n * import graph is test-pinned clear of it) and cannot produce the\n * secp256k1/EIP-712 signature a payment authorization needs (wrong curve). Money\n * stays out of reach; a signature as such no longer does, so the tier says what\n * it means. `doctor` decrypts locally to check the wallet still opens.\n *\n * What the tier does NOT claim, because it is not true: that the read scope\n * limits what a leaked delegation is worth. Scope is enforced only on the request\n * shape that carries both a session signature and the delegation header; the same\n * delegation replayed as a plain `SIGN-IN-WITH-X` takes a different server path\n * where no scope logic runs. So a session file is a wallet-derived credential\n * with the authority of the wallet behind it, and the mitigations that actually\n * hold are the ones in this repo: it is 0600, short-lived (≤24h, server-clamped),\n * bound to the origin it was minted for, and never presented off that origin.\n * Treat \"read is allowlisted\" as \"read may transmit that credential to the\n * configured origin\", and see FLAG_CAVEAT for why the configured origin is not\n * automatically the one you configured.\n *\n * Not all of them are read-only, and the difference is disclosed rather than\n * papered over — `search` POSTs the (generalized, anonymous) question off-machine\n * and records it locally, `outcome` POSTs a report that moves the marketplace's\n * reuse signal (both unauthenticated remote writes), and `read` writes locally,\n * saving a delivered piece to the library, and `doctor` decrypts the keystore\n * locally to check it opens. Pre-clearing them is defensible because they cost\n * nothing and none of it leaves the machine; calling them read-only to justify it\n * would not be.\n *\n * Rules are PREFIX rules: `Bash(tenjin search:*)` clears commands that start with\n * `tenjin search` and nothing else. The narrow `wallet show` / `wallet balance` /\n * The `config get` form is deliberate: a `Bash(tenjin wallet:*)`\n * or `Bash(tenjin config:*)` rule would silently swallow `wallet create` and\n * `config set`, and `config set` can raise the spend caps.\n *\n * Two known gaps, both fail-closed (denied, never wrongly allowed):\n * - Bare `tenjin config` (runConfigList) is as read-only as `config get`, but no\n * prefix rule reaches it without also covering `config set`, so it stays out.\n * Use `tenjin config get <key>`, which is a different supported command rather\n * than a reworded one.\n * - Group-level flag forms like `tenjin wallet --json show` are not covered.\n * Put global flags AFTER the leaf verb (`tenjin wallet show --json`); the\n * CLI parses either, and only the trailing form matches these rules.\n */\nexport const ALWAYS_SAFE_ALLOWLIST: readonly AllowlistEntry[] = [\n {\n rule: 'Bash(tenjin search:*)',\n command: 'tenjin search',\n note:\n 'Free anonymous marketplace search. No wallet, no signing, no payment. ' +\n 'Not read-only: it POSTs the generalized question off-machine and records ' +\n 'the search locally.',\n },\n {\n rule: 'Bash(tenjin fund:*)',\n command: 'tenjin fund',\n note:\n 'Owner call (2026-08-12): free on both surfaces, because the command just opens the ' +\n 'fund modal. Minting moves no money: the destination is server-pinned to the wallet ' +\n 'that signed, the CLI refuses any checkout host but pay.coinbase.com, and payment ' +\n 'happens behind Coinbase\\u2019s own human gate. The usual --base-url caveat does not ' +\n 'apply: fund is pinned to the production origin and takes no override from flag, ' +\n 'env, or config.',\n },\n {\n rule: 'Bash(tenjin inspect:*)',\n command: 'tenjin inspect',\n note: 'Free pre-purchase card and preview. Never signs, never pays, never saves.',\n },\n {\n rule: 'Bash(tenjin read:*)',\n command: 'tenjin read',\n note:\n 'Free-only delivery: free pieces, local-library re-reads, and pieces this ' +\n 'wallet already owns when a read-scoped session key is cached. Cannot spend ' +\n 'and cannot open the keystore: the wallet, payment, and session-MINTING ' +\n 'modules are all absent from its import graph, so the key it may present is ' +\n 'a P-256 delegation loaded from disk, which is the wrong curve to authorize ' +\n 'a payment. TRANSMITS A CREDENTIAL: when a session key exists, a cold 402 ' +\n 'sends that wallet-derived delegation to the server. It goes only to the ' +\n 'origin the delegation was minted for, which is what stops a stray ' +\n '`--base-url` from redirecting it, and no scope on it limits what a holder ' +\n 'could do with it. Not read-only: a freshly delivered piece is saved to the ' +\n 'library.',\n },\n {\n rule: 'Bash(tenjin outcome:*)',\n command: 'tenjin outcome',\n note:\n 'Free honest outcome report on a past search. No wallet, no payment. ' +\n 'Not read-only: it POSTs a report that moves the marketplace reuse signal.',\n },\n {\n rule: 'Bash(tenjin doctor:*)',\n command: 'tenjin doctor',\n note:\n 'Local environment and API reachability diagnostics. Decrypts the wallet ' +\n 'locally to check it still opens; signs nothing and sends nothing.',\n },\n {\n rule: 'Bash(tenjin wallet show:*)',\n command: 'tenjin wallet show',\n note: 'Prints the wallet address and key source. Never prints the key.',\n },\n {\n rule: 'Bash(tenjin wallet balance:*)',\n command: 'tenjin wallet balance',\n note: 'Read-only USDC balance query on Base.',\n },\n {\n rule: 'Bash(tenjin config get:*)',\n command: 'tenjin config get',\n note:\n 'Reads one effective config value. `config set` is excluded on purpose. ' +\n 'Note `config get rpcUrl` returns your RPC URL, which commonly embeds a ' +\n 'provider API key: no wallet secret, but a credential-adjacent read.',\n },\n];\n\n/**\n * The verbs offered as EXPLICIT opt-in lines rather than shipped in the safe set:\n * the one that spends, and the one that opens the keystore.\n *\n * Read the buy note carefully before pasting the line: on the DEFAULT config this\n * rule authorizes unattended spending up to the wallet balance. Walking\n * evaluateSpendPolicy (lib/policy.ts) against CONFIG_DEFAULTS with an agent that\n * passes `--yes` (which this repo's own skill snippet offers):\n * - `maxPriceAtomic` is unset unless the agent chooses to pass `--max-price`;\n * - `allowlistCreators` is empty, so the creator gate is off;\n * - `sessionBudget` is '0', which `if (policy.sessionBudgetAtomic > 0n)` reads\n * as DISABLED, not as a zero ceiling;\n * - `maxAutoSpend` '0' and `confirm` 'always' both land on `confirm`, and\n * `confirmSpend` returns true on `--yes` before any TTY check.\n * Nothing denies. Note the asymmetry that makes the pair read safer than it is:\n * `maxAutoSpend: '0'` means \"auto-approve nothing\" while `sessionBudget: '0'`\n * means \"no ceiling at all\".\n */\nexport const OPT_IN_ALLOWLIST: readonly AllowlistEntry[] = [\n {\n rule: 'Bash(tenjin buy:*)',\n command: 'tenjin buy',\n note:\n 'SPENDS USDC on Base, unrefundably. This authorizes UNATTENDED purchases: ' +\n '`--yes` is an ordinary flag on the same allowlisted verb and it clears the ' +\n 'confirm gate, so on the default config nothing stops a spend up to your ' +\n 'wallet balance. Set a real ceiling first with ' +\n '`tenjin config set maxAutoSpend <usd>` and ' +\n '`tenjin config set sessionBudget <usd>` (sessionBudget 0 means NO ceiling, ' +\n 'not a zero one). This line never raises a spend cap by itself, but do not ' +\n 'read that as a human being on every purchase. Fund small.',\n },\n {\n rule: 'Bash(tenjin session start:*)',\n command: 'tenjin session start',\n note:\n 'OPENS THE KEYSTORE (one wallet signature), but SPENDS NOTHING and cannot: ' +\n 'it mints a ≤24h P-256 session key so `tenjin read` can recover pieces you ' +\n 'already own without paying. The delegated key is the wrong curve for a ' +\n 'payment authorization, so no session file can ever move money. Do NOT read ' +\n 'the `read` scope as a bound on the rest: the file it leaves is a ' +\n 'wallet-derived credential, and what limits it is that it expires in 24h, ' +\n 'lives 0600, and is refused off the origin it was minted for, not its ' +\n 'scope. What you are opting into is unattended keystore access: on an ' +\n 'encrypted wallet the passphrase prompt is skipped or answered from the ' +\n 'environment, and the `--base-url` caveat below bites hardest here, because ' +\n 'a mint against an attacker-chosen host is a wallet signature you did not ' +\n 'intend to make.',\n },\n];\n\n/**\n * The one rule that is neither always-safe nor a standing opt-in: it exists only\n * while `publish.mode` is `auto` or `full-auto`.\n *\n * The mode IS the consent. An operator who set auto has already said a clean\n * publish should proceed without asking; leaving the harness prompt in front of\n * it asks the same question a second time, in a place the mode cannot answer,\n * and the agent that hits it does the only safe thing and stops. That was the\n * observed failure: a session ran `tenjin config get publish.mode` mid-publish to\n * discover it had permission it had already been given (#161).\n *\n * NOT part of {@link recommendedRules}, and not a tier an operator picks from.\n * There is no line to paste and no flag that adds it: `install` writes it when\n * the mode it just settled is auto or full-auto, takes it back when the mode is\n * review, and `uninstall` reclaims it like every other rule this CLI wrote.\n */\nexport const PUBLISH_MODE_ALLOWLIST: readonly AllowlistEntry[] = [\n {\n rule: 'Bash(tenjin publish:*)',\n command: 'tenjin publish',\n note:\n 'PUBLISHES PUBLICLY under your identity, and is cleared only while publish.mode is ' +\n 'auto or full-auto: the mode is the consent, and the harness prompt would ask for it ' +\n 'twice. Three things it clears that the free tier never did. It OPENS THE KEYSTORE: ' +\n 'publish always resolves a signer, and with no usable session it mints one at ' +\n 'read+write scope, which is strictly broader than the read-only key ' +\n '`tenjin session start` exists as a deliberate opt-in for. It publishes the contents ' +\n 'of ANY LOCAL FILE the agent can read, gated only by the heuristic scan. And it is a ' +\n 'PREFIX rule, so it pins the verb and not the flags: `--base-url` rides it (see the ' +\n 'flag caveat), and `--yes` is an ordinary flag on the same verb that clears exactly ' +\n 'the WARN findings auto stopped on, so a re-run collapses auto into full-auto with ' +\n 'nobody asked. What still gates a publish is the CLI: the deterministic secret scan ' +\n 'blocks in every mode and no --yes clears it. The skills hold the rest of that line. ' +\n 'Set publish.mode back to review and the rule is retracted.',\n },\n {\n rule: 'Bash(tenjin edit:*)',\n command: 'tenjin edit',\n note:\n 'Updates posts your wallet ALREADY OWNS: reprices, refreshes an as-of date, repairs an ' +\n 'answer card. Owner-scoped on both legs (GET and PUT /api/posts/<id> are signed and ' +\n 'owner-only), spends nothing, moves no keys, and creates no new public content: a ' +\n 'narrower blast radius than the publish rule beside it. It rides the same mode for the ' +\n 'same reason: edit runs the identical publish.mode consent gate in the CLI ' +\n '(lib/consent.ts needsConfirmation), so a mode that publishes unattended and then ' +\n 'cannot fix its own post\\u2019s price is the asymmetry the mode exists to remove. It ' +\n 'opens the keystore on the same terms as the publish rule beside it, and takes the ' +\n 'same prefix-rule caveats. Removed by the same return to review.',\n },\n];\n\n/** The mode-gated rules in effect for `mode`; empty on review. */\nexport function modeGatedAllowlist(mode: PublishMode): AllowlistEntry[] {\n return mode === 'review' ? [] : PUBLISH_MODE_ALLOWLIST.map((e) => ({ ...e }));\n}\n\n/**\n * Verbs that must NEVER appear in the recommended allowlist, with the reason each\n * one is a human decision. `tenjin send` is the wallet escape hatch (tenjin-agent\n * #40) and heads this list: it moves USDC to an arbitrary address, outside the\n * spend policy that bounds `buy`. Naming it here is load-bearing even in versions\n * where the verb does not exist yet — the exclusion ships before the verb does.\n *\n * `tenjin publish` stays on this list under its own terms: nothing RECOMMENDS it,\n * and no line here or on the doc page adds it. {@link PUBLISH_MODE_ALLOWLIST} is\n * not a recommendation — it is what one specific operator choice already means.\n */\nexport const NEVER_ALLOWLISTED: readonly ExcludedVerb[] = [\n {\n command: 'tenjin send',\n reason:\n 'Moves USDC out of the wallet to an arbitrary address (the escape hatch, #40). ' +\n 'Irreversible and not bounded by the buy spend policy. Always a human decision.',\n },\n {\n command: 'tenjin publish',\n reason:\n 'Puts your content on a public marketplace under your identity. Never pre-cleared by the ' +\n 'free tier or an opt-in line: the only thing that clears it is `publish.mode` auto or ' +\n 'full-auto, which is the same human decision said once instead of twice (see ' +\n 'PUBLISH_MODE_ALLOWLIST). Back on review, `install` takes the rule away again.',\n },\n {\n command: 'tenjin edit',\n reason:\n 'Write-capable despite the no-flag form reading as a pure show: it edits live posts ' +\n 'and answer cards under your identity, and moves prices. A prefix rule pins the verb, ' +\n 'not the flags, so no rule can clear the read half without clearing the write half. ' +\n 'Never pre-cleared as a recommendation: like `tenjin publish`, the only thing that ' +\n 'clears it is `publish.mode` auto or full-auto, whose consent gate it already shares ' +\n '(see PUBLISH_MODE_ALLOWLIST). Back on review, `install` takes the rule away again.',\n },\n {\n command: 'tenjin wallet create',\n reason: 'Creates the payment credential; a stray run is a wallet you did not mean to have.',\n },\n {\n command: 'tenjin config set',\n reason:\n 'Can raise maxAutoSpend / sessionBudget / confirm, i.e. widen the agent’s own spend policy.',\n },\n {\n command: 'tenjin install',\n reason: 'Writes into harness config and skills directories.',\n },\n {\n command: 'tenjin mcp',\n reason:\n 'Long-running server that re-exposes every command core over stdio; ' +\n 'clearing it would indirectly clear everything above.',\n },\n {\n command: 'tenjin update',\n reason:\n 'Replaces the tenjin binary the agent then runs, with whatever npm serves ' +\n 'next. Which build an agent executes is an operator decision, not something ' +\n 'a rule pre-clears. `--check` only reports, but a prefix rule pins the verb, ' +\n 'not the flags.',\n },\n];\n\n/**\n * The flag-surface caveat. A prefix rule pins the verb, never the flags, and the\n * flag that matters is `--base-url`: it is accepted on every leaf, validated only\n * as a URL, and it wins settings precedence, so it moves the destination of every\n * allowlisted verb. Printed with the rules everywhere they are printed, because\n * an operator who only reads the verb list would never learn it.\n */\nexport const FLAG_CAVEAT: readonly string[] = [\n 'Caveat: a prefix rule pins the VERB, not the flags. Every line above also clears',\n '`--base-url <url>` on that verb, which re-points where the question, the probe, the',\n 'session key `read` may present, and (for buy) the signature and payment go. Signed',\n 'and credential-bearing traffic is NOT confined to the paying verb: `read` is in the',\n 'safe tier and still transmits a wallet-derived delegation once one is cached, which is',\n 'why that delegation is bound to the origin it was minted for and refused elsewhere.',\n 'Allowlist these verbs only if you are content for the agent to choose the destination',\n 'host, and set the base URL in config instead of letting it be an argument. The skills',\n 'tell agents never to pass --base-url on an allowlisted verb, but that is a convention,',\n 'not an enforced boundary.',\n 'This covers the two rules your publish.mode carries as well, and bites hardest there:',\n '`tenjin publish --base-url <host>` is cleared by default on auto, and it signs against',\n 'the host it is given.',\n];\n\n/**\n * The MCP caveat. `tenjin mcp` is never recommended as a Bash rule, but an\n * operator who registers the server anyway is on a different permission surface\n * (tools, not command strings) where three excluded verbs come back.\n */\nexport const MCP_CAVEAT: readonly string[] = [\n 'Note the asymmetry: publish.mode writes the Bash rules for `publish` and `edit`, and',\n 'deliberately does not touch the MCP tool grants below. The mode is a CLI-side consent',\n 'gate, and nothing reads it on the MCP surface, so clearing those tools would hand out',\n 'the same authority with none of the same gate. Aligning the two is tracked separately.',\n 'Running the local MCP server (`tenjin mcp`) instead? That is a different permission',\n 'surface: the harness gates TOOLS there, and these Bash rules do not apply. Leave',\n '`mcp__tenjin__tenjin_publish`, `mcp__tenjin__tenjin_edit`, and',\n '`mcp__tenjin__tenjin_wallet` gated. `tenjin_buy` is the same opt-in decision as the',\n 'buy line above.',\n];\n\n/** The machine shape emitted by `tenjin doctor --json` and `tenjin install --json`. */\nexport interface RecommendedPermissions {\n alwaysSafe: AllowlistEntry[];\n optIn: AllowlistEntry[];\n neverAllowlisted: ExcludedVerb[];\n /**\n * Rules the CURRENT publish.mode carries, empty on review. Separate from the\n * three tiers above because it is not a recommendation to weigh: it is what\n * this machine's mode already means, so a consumer that renders it beside the\n * others would be offering a choice that has been made.\n */\n modeGated: AllowlistEntry[];\n /** Caveats that qualify the rules above; never omit them when rendering. */\n caveats: { flags: string[]; mcp: string[] };\n}\n\n/** `mode` defaults to the shipped `review`, i.e. no mode-gated rules. */\nexport function recommendedPermissions(mode: PublishMode = 'review'): RecommendedPermissions {\n return {\n alwaysSafe: ALWAYS_SAFE_ALLOWLIST.map((e) => ({ ...e })),\n optIn: OPT_IN_ALLOWLIST.map((e) => ({ ...e })),\n neverAllowlisted: NEVER_ALLOWLISTED.map((e) => ({ ...e })),\n modeGated: modeGatedAllowlist(mode),\n caveats: { flags: [...FLAG_CAVEAT], mcp: [...MCP_CAVEAT] },\n };\n}\n\n/** Every rule this module recommends adding (safe + opt-in). */\nexport function recommendedRules(): string[] {\n return [...ALWAYS_SAFE_ALLOWLIST, ...OPT_IN_ALLOWLIST].map((e) => e.rule);\n}\n\n/**\n * The permission caveats' one home. `doctor` used to print the whole thing —\n * nine rules, both opt-in notes, every exclusion, the flag caveat and the MCP\n * caveat, ~60 lines ahead of the check list it was actually run for. No doctor\n * command in the wider ecosystem carries security prose, and an operator reading\n * a wall of it in a terminal cannot paste from it, search it, or link a colleague\n * to a section. The page can do all three, so it is where the caveats live and\n * where every human surface points; `--json` still carries them as data\n * (`recommendedPermissions`), which is what an agent reads.\n */\nexport const PERMISSIONS_DOC_URL =\n 'https://github.com/BackTrackCo/tenjin-agent/blob/main/docs/agent-permissions.md';\n\n/**\n * The single line that replaced the block: what is on the page, and its URL. It\n * names the counts rather than the rules so the operator knows whether the page\n * answers their question before they open it.\n *\n * Subagent delegation is named here rather than on a second line, because doctor\n * deliberately closes with ONE pointer (#81) and the operator deciding what to\n * hand a subagent is reading exactly this line. The free tier IS the\n * subagent-safe set, so the counts already answer the question; which verbs stay\n * human-gated lives on the page with every other caveat.\n */\nexport function permissionsPointer(): string {\n return (\n `Auto-mode permission allowlist and subagent delegation (${ALWAYS_SAFE_ALLOWLIST.length} free verbs, ` +\n `${OPT_IN_ALLOWLIST.length} opt-ins, the --base-url caveat): ${PERMISSIONS_DOC_URL}`\n );\n}\n\n/**\n * The rules the current mode is missing, or null when it needs none. This one\n * DOES name them,\n * unlike {@link permissionsPointer}: they are not a tier to weigh and paste, they\n * are lines that should already be in the operator's settings file, and an\n * operator whose agent is being prompted for work the mode said not to ask about\n * needs to see exactly which rules are missing.\n *\n * CONSULTS THE MACHINE. Rendering from the mode alone told operators to add\n * rules their settings file already had, and named a remedy that in one case\n * would not have written anything — a nag that is wrong twice over on a line\n * whose whole job is to prevent an agent stalling on a prompt (#161).\n */\nexport function modeGatedPointer(\n mode: PublishMode,\n /** The mode-gated rules this machine is actually MISSING. Empty renders nothing. */\n missing: readonly string[],\n /**\n * The command that would fix it. `tenjin install` for the ordinary case; a\n * mode coming from TENJIN_PUBLISH_MODE needs `config set` instead, because\n * install resolves the mode from the global file and would write nothing.\n */\n remedy = 'tenjin install',\n): string | null {\n if (modeGatedAllowlist(mode).length === 0 || missing.length === 0) return null;\n return `publish.mode=${mode} also needs ${missing.join(' and ')} in your harness allowlist, or it will prompt an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BAAmB;AAEtF;AAeO,SAAS,iBACd,MAEA,SAMA,SAAS,kBACM;AACf,MAAI,mBAAmB,IAAI,EAAE,WAAW,KAAK,QAAQ,WAAW,EAAG,QAAO;AAC1E,SAAO,gBAAgB,IAAI,eAAe,QAAQ,KAAK,OAAO,CAAC,2DAA2D,MAAM;AAClI;","names":[]}
@@ -15,27 +15,29 @@ import {
15
15
  scan,
16
16
  updatePost,
17
17
  writeModeNotices
18
- } from "./chunk-ILDVGY7K.js";
18
+ } from "./chunk-VRPLZERE.js";
19
19
  import {
20
20
  describeWallet,
21
21
  resolveWalletProvider
22
- } from "./chunk-CNUXRXI2.js";
22
+ } from "./chunk-7GJQ5RGA.js";
23
23
  import {
24
24
  sanitizeForTerminal
25
- } from "./chunk-IB63U6BM.js";
25
+ } from "./chunk-B676GPS2.js";
26
26
  import {
27
27
  resolveContextSettings,
28
28
  resolvePublishSettings
29
- } from "./chunk-JTYIX6OD.js";
29
+ } from "./chunk-PKW3H26Z.js";
30
30
  import {
31
31
  UUID_RE,
32
- parsePublishModeFlag,
33
32
  parseUsdToAtomic,
34
33
  toMoney
35
- } from "./chunk-ALUNME53.js";
34
+ } from "./chunk-736DW4V3.js";
35
+ import {
36
+ parsePublishModeFlag
37
+ } from "./chunk-LSWP7MU2.js";
36
38
  import {
37
39
  CliError
38
- } from "./chunk-PZRAAAY2.js";
40
+ } from "./chunk-PAOVPSP6.js";
39
41
 
40
42
  // src/commands/edit.ts
41
43
  import { readFile } from "fs/promises";
@@ -609,4 +611,4 @@ function hasText(value) {
609
611
  export {
610
612
  runEdit
611
613
  };
612
- //# sourceMappingURL=chunk-CBNXUQGM.js.map
614
+ //# sourceMappingURL=chunk-IXZJ3JOO.js.map