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,318 @@
1
+ import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ channelTag,
4
+ fetchDistTags,
5
+ isNewer,
6
+ resolveTarget
7
+ } from "./chunk-MJSXP4LW.js";
8
+ import {
9
+ emitWriteNotice,
10
+ sanitizeForTerminal
11
+ } from "./chunk-B676GPS2.js";
12
+ import "./chunk-LSWP7MU2.js";
13
+ import {
14
+ package_default
15
+ } from "./chunk-ETKZWJ4B.js";
16
+ import "./chunk-ZQIQ55KK.js";
17
+ import "./chunk-QWBUKIP2.js";
18
+ import {
19
+ CliError
20
+ } from "./chunk-PAOVPSP6.js";
21
+ import "./chunk-ZXTAQYNA.js";
22
+
23
+ // src/commands/update.ts
24
+ import { spawn } from "child_process";
25
+ import { homedir } from "os";
26
+ import { fileURLToPath } from "url";
27
+
28
+ // src/lib/install-location.ts
29
+ import { existsSync, realpathSync, statSync } from "fs";
30
+ import { delimiter, dirname, join, sep } from "path";
31
+ var REFUSALS = [
32
+ {
33
+ test: isSourceCheckout,
34
+ error: () => new CliError("REFUSED", "tenjin-cli is running from a source checkout, not an install", {
35
+ fix: "Update the checkout instead: git pull && pnpm install"
36
+ }),
37
+ needsVersion: false,
38
+ appliesToCheck: false
39
+ },
40
+ {
41
+ test: (moduleDir) => moduleDir.split(sep).includes("_npx"),
42
+ error: (spec) => new CliError("REFUSED", "tenjin-cli is running from the npx cache, not an install", {
43
+ // Writing a global here would "succeed" and change nothing: the next
44
+ // `npx tenjin` still resolves its own cached copy.
45
+ fix: `npx fetches its own copy every time. To keep one: npm i -g ${spec}`
46
+ }),
47
+ needsVersion: true,
48
+ appliesToCheck: false
49
+ },
50
+ {
51
+ // The ONLY manager still refused. `yarn global add` is yarn-1 only, and
52
+ // berry dropped global installs altogether, so there is no one command this
53
+ // can drive across the versions a user might have. Every other manager is
54
+ // delegated to rather than refused (see MANAGERS).
55
+ test: (moduleDir) => classifyManager(moduleDir) === "yarn",
56
+ error: (spec) => new CliError(
57
+ "REFUSED",
58
+ "This tenjin-cli was installed with yarn, whose global install exists only in yarn 1",
59
+ { fix: `yarn global add ${spec}` }
60
+ ),
61
+ needsVersion: true,
62
+ appliesToCheck: false
63
+ },
64
+ {
65
+ // Scoped to npm on purpose: the prefix-vs-project-root test is written for
66
+ // npm's layout. pnpm's global store and bun's global dir both keep a
67
+ // package.json beside `node_modules`, so an unscoped test would read either
68
+ // as a project-local install and refuse the very case we now delegate.
69
+ test: (moduleDir) => classifyManager(moduleDir) === "npm" && !isGlobalTree(moduleDir),
70
+ error: (spec) => new CliError(
71
+ "REFUSED",
72
+ "This tenjin-cli is a project-local dependency, not a global install",
73
+ {
74
+ fix: `Update it where it is declared: npm i ${spec}`
75
+ }
76
+ ),
77
+ needsVersion: true,
78
+ appliesToCheck: false
79
+ }
80
+ ];
81
+ function refuse(moduleDir, opts) {
82
+ for (const entry of REFUSALS) {
83
+ if (opts.check && !entry.appliesToCheck) continue;
84
+ if (entry.needsVersion !== (opts.spec !== null)) continue;
85
+ if (entry.test(moduleDir)) throw entry.error(opts.spec ?? "", moduleDir);
86
+ }
87
+ }
88
+ function isSourceCheckout(moduleDir) {
89
+ let dir = moduleDir;
90
+ for (let i = 0; i < 8; i += 1) {
91
+ if (existsSync(join(dir, "package.json"))) return existsSync(join(dir, "src"));
92
+ const parent = dirname(dir);
93
+ if (parent === dir) break;
94
+ dir = parent;
95
+ }
96
+ return false;
97
+ }
98
+ function isGlobalTree(moduleDir) {
99
+ const segs = moduleDir.split(sep);
100
+ const i = segs.lastIndexOf("node_modules");
101
+ if (i <= 0) return false;
102
+ return !existsSync(join(segs.slice(0, i).join(sep), "package.json"));
103
+ }
104
+ function classifyManager(moduleDir) {
105
+ const segs = moduleDir.split(sep);
106
+ const pair = (a, b) => segs.includes(a) && segs.includes(b);
107
+ if (segs.includes(".pnpm") || pair("pnpm", "global")) return "pnpm";
108
+ if (segs.includes(".bun")) return "bun";
109
+ if (segs.includes(".yarn") || pair("yarn", "global")) return "yarn";
110
+ return "npm";
111
+ }
112
+ var MANAGERS = {
113
+ npm: {
114
+ bin: "npm",
115
+ scriptSuffixes: ["npm-cli.js"],
116
+ besideNode: true,
117
+ args: (spec) => ["install", "-g", "--ignore-scripts", spec],
118
+ manual: (spec) => `npm i -g ${spec}`
119
+ },
120
+ pnpm: {
121
+ bin: "pnpm",
122
+ // corepack's shim resolves to `pnpm.js`, a standalone install to `pnpm.cjs`.
123
+ scriptSuffixes: [".cjs", ".js"],
124
+ besideNode: false,
125
+ args: (spec) => ["add", "-g", "--ignore-scripts", spec],
126
+ manual: (spec) => `pnpm add -g ${spec}`
127
+ },
128
+ bun: {
129
+ bin: "bun",
130
+ scriptSuffixes: [],
131
+ besideNode: false,
132
+ // No --ignore-scripts: bun's flag surface for it is not stable across the
133
+ // versions in the wild, and an unknown flag would fail the install outright.
134
+ args: (spec) => ["add", "-g", spec],
135
+ manual: (spec) => `bun add -g ${spec}`
136
+ }
137
+ };
138
+ function resolveManagerScript(manager, execPath, env = process.env) {
139
+ const plan = MANAGERS[manager];
140
+ if (plan.scriptSuffixes.length === 0) return null;
141
+ const beside = plan.besideNode ? scriptNear(dirname(execPath), plan.bin) : null;
142
+ return beside ?? scriptOnPath(plan.bin, plan.scriptSuffixes, env);
143
+ }
144
+ function scriptNear(dir, bin) {
145
+ const candidates = [
146
+ join(dir, "node_modules", bin, "bin", `${bin}-cli.js`),
147
+ join(dir, "..", "lib", "node_modules", bin, "bin", `${bin}-cli.js`)
148
+ ];
149
+ return candidates.find(isFile) ?? null;
150
+ }
151
+ function scriptOnPath(bin, suffixes, env) {
152
+ const exts = process.platform === "win32" ? ["", ...(env.PATHEXT ?? ".EXE;.CMD;.BAT;.COM").split(";").filter((e) => e.length > 0)] : [""];
153
+ for (const part of (env.PATH ?? "").split(delimiter)) {
154
+ if (part.length === 0) continue;
155
+ for (const ext of exts) {
156
+ if (!isFile(join(part, `${bin}${ext}`))) continue;
157
+ const real = realpathOrNull(join(part, `${bin}${ext}`));
158
+ if (real !== null && suffixes.some((suffix) => real.endsWith(suffix))) return real;
159
+ const near = scriptNear(part, bin);
160
+ if (near !== null) return near;
161
+ }
162
+ }
163
+ return null;
164
+ }
165
+ function isFile(p) {
166
+ try {
167
+ return statSync(p).isFile();
168
+ } catch {
169
+ return false;
170
+ }
171
+ }
172
+ function realpathOrNull(p) {
173
+ try {
174
+ return realpathSync(p);
175
+ } catch {
176
+ return null;
177
+ }
178
+ }
179
+
180
+ // src/commands/update.ts
181
+ var INSTALL_TIMEOUT_MS = 3e5;
182
+ function resolveManager(manager, deps) {
183
+ const script = deps.managerScript !== void 0 ? deps.managerScript : resolveManagerScript(manager, process.execPath);
184
+ return script === null ? { cmd: MANAGERS[manager].bin, prefix: [] } : { cmd: process.execPath, prefix: [script] };
185
+ }
186
+ async function runUpdate(opts, ctx, deps = {}) {
187
+ const current = deps.currentVersion ?? package_default.version;
188
+ const channel = channelTag(current);
189
+ const moduleDir = deps.moduleDir ?? fileURLToPath(new URL(".", import.meta.url));
190
+ if (channel === null) {
191
+ throw new CliError("REFUSED", `tenjin-cli reports an unrecognizable version (${current})`, {
192
+ fix: "Reinstall a published build: npm i -g tenjin-cli"
193
+ });
194
+ }
195
+ refuse(moduleDir, { check: opts.check, spec: null });
196
+ const tags = await fetchDistTags({
197
+ fetchImpl: deps.fetchImpl,
198
+ timeoutMs: ctx.flags.timeout
199
+ });
200
+ if (tags === null) {
201
+ throw new CliError("NETWORK_ERROR", "Could not read tenjin-cli dist-tags from npm", {
202
+ fix: "Check access to registry.npmjs.org and retry"
203
+ });
204
+ }
205
+ const latest = resolveTarget(current, tags);
206
+ if (latest === null) {
207
+ const raw = tags[channel];
208
+ throw raw === void 0 ? new CliError("RESOURCE_NOT_FOUND", "npm has no published tenjin-cli on the latest tag", {
209
+ fix: "Pick a version yourself: npm view tenjin-cli versions"
210
+ }) : new CliError(
211
+ "RESOURCE_NOT_FOUND",
212
+ // Registry-controlled: bounded here, escaped by the error emitter.
213
+ `npm's latest tenjin-cli (${raw.slice(0, 40)}) is not a version this build can read`,
214
+ {
215
+ fix: "Install it by name: npm i -g tenjin-cli@<version> (npm view tenjin-cli versions)"
216
+ }
217
+ );
218
+ }
219
+ const updateAvailable = isNewer(latest, current);
220
+ const data = (updated) => ({
221
+ current,
222
+ latest,
223
+ updateAvailable,
224
+ updated
225
+ });
226
+ if (!updateAvailable) {
227
+ return {
228
+ data: data(false),
229
+ humanLines: [`tenjin-cli ${current} is up to date`]
230
+ };
231
+ }
232
+ if (opts.check) {
233
+ return {
234
+ data: data(false),
235
+ humanLines: [
236
+ `tenjin-cli ${latest} is available (you have ${current}).`,
237
+ "Run tenjin update to install it."
238
+ ]
239
+ };
240
+ }
241
+ const spec = `tenjin-cli@${latest}`;
242
+ refuse(moduleDir, { check: false, spec });
243
+ const human = ctx.io.isTTY && !ctx.flags.json;
244
+ let tail = "";
245
+ const onOutput = (chunk) => {
246
+ tail = (tail + chunk).slice(-2e3);
247
+ if (human) ctx.io.stderr.write(chunk.split("\n").map(sanitizeForTerminal).join("\n"));
248
+ };
249
+ const manager = classifyManager(moduleDir);
250
+ const plan = MANAGERS[manager];
251
+ const args = plan.args(spec);
252
+ const resolved = resolveManager(manager, deps);
253
+ const manual = `Run it yourself: ${plan.manual(spec)}`;
254
+ const outcome = await (deps.spawnImpl ?? spawnCapture)(
255
+ resolved.cmd,
256
+ [...resolved.prefix, ...args],
257
+ { cwd: homedir(), timeoutMs: INSTALL_TIMEOUT_MS },
258
+ onOutput
259
+ );
260
+ if (outcome.kind === "start-failed") {
261
+ throw new CliError("UPDATE_FAILED", `Could not start ${manager}`, {
262
+ fix: manual,
263
+ cause: outcome.cause
264
+ });
265
+ }
266
+ if (outcome.kind === "timeout") {
267
+ throw new CliError(
268
+ "UPDATE_FAILED",
269
+ `${manager} did not finish in ${INSTALL_TIMEOUT_MS / 1e3}s`,
270
+ { fix: manual, details: { output: tail } }
271
+ );
272
+ }
273
+ if (outcome.code !== 0) {
274
+ throw new CliError("UPDATE_FAILED", `${manager} ${args.join(" ")} exited ${outcome.code}`, {
275
+ // EACCES on a root-owned global prefix is the common cause; the operator
276
+ // fixing that themselves beats this CLI ever escalating.
277
+ fix: manual,
278
+ details: { output: tail }
279
+ });
280
+ }
281
+ emitWriteNotice(
282
+ ctx.io,
283
+ `tenjin update: replaced the global tenjin-cli with ${latest} via ${manager}`
284
+ );
285
+ return {
286
+ data: data(true),
287
+ humanLines: [`Updated tenjin-cli ${current} -> ${latest}. New builds pick it up immediately.`]
288
+ };
289
+ }
290
+ var spawnCapture = (cmd, args, opts, onOutput) => new Promise((res) => {
291
+ let child;
292
+ try {
293
+ child = spawn(cmd, args, { stdio: ["ignore", "pipe", "pipe"], cwd: opts.cwd });
294
+ } catch (cause) {
295
+ res({ kind: "start-failed", cause });
296
+ return;
297
+ }
298
+ let timedOut = false;
299
+ const timer = setTimeout(() => {
300
+ timedOut = true;
301
+ child.kill("SIGKILL");
302
+ }, opts.timeoutMs);
303
+ child.stdout?.on("data", (chunk) => onOutput(chunk.toString()));
304
+ child.stderr?.on("data", (chunk) => onOutput(chunk.toString()));
305
+ child.on("error", (cause) => {
306
+ clearTimeout(timer);
307
+ res({ kind: "start-failed", cause });
308
+ });
309
+ child.on("close", (code) => {
310
+ clearTimeout(timer);
311
+ res(timedOut ? { kind: "timeout" } : { kind: "exit", code: code ?? 1 });
312
+ });
313
+ });
314
+ export {
315
+ runUpdate,
316
+ spawnCapture
317
+ };
318
+ //# sourceMappingURL=update-24Y2CQTT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/update.ts","../src/lib/install-location.ts"],"sourcesContent":["import { spawn } from 'node:child_process';\nimport { homedir } from 'node:os';\nimport { fileURLToPath } from 'node:url';\nimport pkg from '../../package.json';\nimport { CliError } from '../lib/errors';\nimport { MANAGERS, classifyManager, refuse, resolveManagerScript } from '../lib/install-location';\nimport type { Delegable } from '../lib/install-location';\nimport { emitWriteNotice, sanitizeForTerminal } from '../lib/output';\nimport { channelTag, fetchDistTags, isNewer, resolveTarget } from '../lib/update-check';\nimport type { CommandContext, CommandResult } from '../context';\n\n/**\n * `tenjin update`: replace this install with the newest version npm offers it,\n * by spawning the package manager that OWNS the install rather than\n * reimplementing one. Four invariants:\n *\n * - The argv pins the EXACT version the registry just named, never the tag, so\n * the check and the install cannot disagree about what ships, and the version\n * string is certified parseable by the same `isNewer` gate the nudge trusts\n * before it goes anywhere near an argv.\n * - The owner performs the install. npm, pnpm and bun are each driven with their\n * own global-add command, because the PATH race that makes a second install\n * dangerous comes from CROSS-manager writes, not from asking the owner to do\n * what it already owns. What cannot be driven is refused instead of guessed\n * at: a source checkout updates by git, an npx run has nothing installed to\n * replace, a project-local copy updates where it is declared, and yarn's\n * global install exists only in yarn 1. See lib/install-location.\n * - The child is a binary or `node <script>`, never a shell. That is what makes\n * the pinned argv worth pinning, and it is the only form that works on win32.\n * - The manager's chatter goes to stderr (live, human mode only, sanitized) and\n * its failure into the error envelope; stdout stays the one envelope every\n * command emits.\n */\n\n/** How long the npm child gets before it is killed. npm's own retry budget runs\n * into minutes, and an agent's turn should not hang on a wedged registry. */\nconst INSTALL_TIMEOUT_MS = 300_000;\n\nexport interface UpdateOptions {\n /** Report whether a newer version exists; never install. */\n check: boolean;\n}\n\n/**\n * How the child ended. Never rejects: all three outcomes are envelope-shaped\n * facts the caller reports, not exceptions, and each is separately testable.\n */\nexport type SpawnResult =\n { kind: 'exit'; code: number } | { kind: 'start-failed'; cause: unknown } | { kind: 'timeout' };\n\nexport type UpdateSpawn = (\n cmd: string,\n args: string[],\n opts: { cwd: string; timeoutMs: number },\n onOutput: (chunk: string) => void,\n) => Promise<SpawnResult>;\n\n/** What to spawn for one manager: a command and any argv that must precede its own. */\ninterface ResolvedManager {\n cmd: string;\n prefix: readonly string[];\n}\n\n/**\n * Turn a manager into a spawnable command. A resolved script runs under THIS\n * node, keeping `shell` unset on every platform; otherwise the bare binary name\n * is used, which is correct for a native binary and fails closed on win32 for a\n * `.cmd` shim.\n */\nfunction resolveManager(manager: Delegable, deps: UpdateDeps): ResolvedManager {\n const script =\n deps.managerScript !== undefined\n ? deps.managerScript\n : resolveManagerScript(manager, process.execPath);\n return script === null\n ? { cmd: MANAGERS[manager].bin, prefix: [] }\n : { cmd: process.execPath, prefix: [script] };\n}\n\nexport interface UpdateDeps {\n fetchImpl?: typeof fetch;\n spawnImpl?: UpdateSpawn;\n /** Where this build's code lives on disk; tests point it at fixture trees. */\n moduleDir?: string;\n /** The running version; defaults to this build's. Injectable for tests. */\n currentVersion?: string;\n /** The owning manager's entry script, or null when it has none to find.\n * Injectable so the argv shape is asserted without depending on the runner. */\n managerScript?: string | null;\n}\n\ninterface UpdateData {\n current: string;\n latest: string;\n updateAvailable: boolean;\n updated: boolean;\n}\n\nexport async function runUpdate(\n opts: UpdateOptions,\n ctx: CommandContext,\n deps: UpdateDeps = {},\n): Promise<CommandResult> {\n const current = deps.currentVersion ?? pkg.version;\n const channel = channelTag(current);\n const moduleDir = deps.moduleDir ?? fileURLToPath(new URL('.', import.meta.url));\n\n // Refused, not defaulted to a channel: a build whose version this package\n // cannot parse has no release line to compare against, and guessing one is how\n // a foreign build gets told it is up to date forever.\n if (channel === null) {\n throw new CliError('REFUSED', `tenjin-cli reports an unrecognizable version (${current})`, {\n fix: 'Reinstall a published build: npm i -g tenjin-cli',\n });\n }\n\n // First stage: everything whose fix string does not need a resolved version,\n // so it answers without the network. An offline contributor in a checkout is\n // told they are in a checkout, not told to go debug their registry access.\n refuse(moduleDir, { check: opts.check, spec: null });\n\n const tags = await fetchDistTags({\n fetchImpl: deps.fetchImpl,\n timeoutMs: ctx.flags.timeout,\n });\n if (tags === null) {\n throw new CliError('NETWORK_ERROR', 'Could not read tenjin-cli dist-tags from npm', {\n fix: 'Check access to registry.npmjs.org and retry',\n });\n }\n const latest = resolveTarget(current, tags);\n // Not a NETWORK_ERROR: nothing about the connection is wrong, and telling the\n // user to check their access sends them after a fault that is not there.\n if (latest === null) {\n const raw = tags[channel];\n throw raw === undefined\n ? new CliError('RESOURCE_NOT_FOUND', 'npm has no published tenjin-cli on the latest tag', {\n fix: 'Pick a version yourself: npm view tenjin-cli versions',\n })\n : new CliError(\n 'RESOURCE_NOT_FOUND',\n // Registry-controlled: bounded here, escaped by the error emitter.\n `npm's latest tenjin-cli (${raw.slice(0, 40)}) is not a version this build can read`,\n {\n fix: 'Install it by name: npm i -g tenjin-cli@<version> (npm view tenjin-cli versions)',\n },\n );\n }\n\n const updateAvailable = isNewer(latest, current);\n const data = (updated: boolean): UpdateData => ({\n current,\n latest,\n updateAvailable,\n updated,\n });\n\n if (!updateAvailable) {\n return {\n data: data(false),\n humanLines: [`tenjin-cli ${current} is up to date`],\n };\n }\n if (opts.check) {\n return {\n data: data(false),\n humanLines: [\n `tenjin-cli ${latest} is available (you have ${current}).`,\n 'Run tenjin update to install it.',\n ],\n };\n }\n\n // `latest` is argv-safe here: isNewer returned true, so it matched VERSION_RE.\n const spec = `tenjin-cli@${latest}`;\n\n // Second stage: the entries whose fix strings name the version just resolved.\n // Reached only on the install path, since --check has already returned.\n refuse(moduleDir, { check: false, spec });\n\n // Live chatter is a human courtesy only; the tail rides in the error envelope\n // so a piped failure is still diagnosable. Sanitized per line, because npm\n // relays publisher-controlled text (deprecation notices) and a line break is\n // the one control character this stream must keep.\n const human = ctx.io.isTTY && !ctx.flags.json;\n let tail = '';\n const onOutput = (chunk: string): void => {\n tail = (tail + chunk).slice(-2000);\n if (human) ctx.io.stderr.write(chunk.split('\\n').map(sanitizeForTerminal).join('\\n'));\n };\n\n // Whoever owns the install performs it. The PATH-race objection that used to\n // make this a refusal only applies to CROSS-manager writes; invoking the owner\n // is exactly what the refusal used to tell the user to type by hand.\n //\n // The cast is sound only because `refuse` ran directly above and yarn is one\n // of its entries, so the one non-delegable manager has already thrown. Move\n // this line above that call and it becomes a lie.\n const manager = classifyManager(moduleDir) as Delegable;\n const plan = MANAGERS[manager];\n // --ignore-scripts where the manager has it (tenjin-cli has no runtime\n // dependencies and no registry install runs its own `prepare`), and cwd is the\n // home directory so the child never reads a project's config by accident.\n const args = plan.args(spec);\n const resolved = resolveManager(manager, deps);\n const manual = `Run it yourself: ${plan.manual(spec)}`;\n\n const outcome = await (deps.spawnImpl ?? spawnCapture)(\n resolved.cmd,\n [...resolved.prefix, ...args],\n { cwd: homedir(), timeoutMs: INSTALL_TIMEOUT_MS },\n onOutput,\n );\n if (outcome.kind === 'start-failed') {\n throw new CliError('UPDATE_FAILED', `Could not start ${manager}`, {\n fix: manual,\n cause: outcome.cause,\n });\n }\n if (outcome.kind === 'timeout') {\n throw new CliError(\n 'UPDATE_FAILED',\n `${manager} did not finish in ${INSTALL_TIMEOUT_MS / 1000}s`,\n { fix: manual, details: { output: tail } },\n );\n }\n if (outcome.code !== 0) {\n throw new CliError('UPDATE_FAILED', `${manager} ${args.join(' ')} exited ${outcome.code}`, {\n // EACCES on a root-owned global prefix is the common cause; the operator\n // fixing that themselves beats this CLI ever escalating.\n fix: manual,\n details: { output: tail },\n });\n }\n\n emitWriteNotice(\n ctx.io,\n `tenjin update: replaced the global tenjin-cli with ${latest} via ${manager}`,\n );\n return {\n data: data(true),\n humanLines: [`Updated tenjin-cli ${current} -> ${latest}. New builds pick it up immediately.`],\n };\n}\n\n/**\n * Default spawn: merged stdout+stderr chunks out, an outcome back, no shell.\n * Bounded by its own timer rather than Node's `timeout` option so that a kill\n * this code ordered is distinguishable from any other death by signal.\n */\nexport const spawnCapture: UpdateSpawn = (cmd, args, opts, onOutput) =>\n new Promise((res) => {\n let child;\n try {\n child = spawn(cmd, args, { stdio: ['ignore', 'pipe', 'pipe'], cwd: opts.cwd });\n } catch (cause) {\n // An argv or option Node rejects outright throws here; ENOENT arrives on\n // the 'error' event instead. Both mean the same thing to the caller.\n res({ kind: 'start-failed', cause });\n return;\n }\n let timedOut = false;\n const timer = setTimeout(() => {\n timedOut = true;\n child.kill('SIGKILL');\n }, opts.timeoutMs);\n child.stdout?.on('data', (chunk: Buffer) => onOutput(chunk.toString()));\n child.stderr?.on('data', (chunk: Buffer) => onOutput(chunk.toString()));\n child.on('error', (cause) => {\n clearTimeout(timer);\n res({ kind: 'start-failed', cause });\n });\n child.on('close', (code) => {\n clearTimeout(timer);\n res(timedOut ? { kind: 'timeout' } : { kind: 'exit', code: code ?? 1 });\n });\n });\n","import { existsSync, realpathSync, statSync } from 'node:fs';\nimport { delimiter, dirname, join, sep } from 'node:path';\nimport { CliError } from './errors';\n\n/**\n * WHERE this build is installed, and what that implies about replacing it.\n *\n * Its own module because it answers a different question from the command that\n * uses it: \"what IS this install\" rather than \"how do I replace it\". The\n * refusal set is the load-bearing part, and it got re-cut in three consecutive\n * reviews while it was expressed positionally inside the command body.\n */\n\n/** Managers a global install can be handed back to. yarn is deliberately absent\n * from the delegable set: see the yarn entry in REFUSALS. */\nexport type Delegable = 'npm' | 'pnpm' | 'bun';\n\n/**\n * One reason `npm install -g` would not actually replace THIS build.\n *\n * Each entry carries the three properties that decide WHEN it is evaluated,\n * because expressing them by where the line sat is what made this set get\n * re-cut three times: a missing entry, then a copy on the wrong side of the\n * fetch, then a duplicate that could not run. Declaring them means adding a\n * refusal is a matter of answering three questions, not of guessing a position.\n */\ninterface Refusal {\n /** Does this install location refuse? Pure filesystem, never the network. */\n test: (moduleDir: string) => boolean;\n error: (spec: string, moduleDir: string) => CliError;\n /**\n * Does the fix string name the version the registry just resolved? This is\n * also what decides whether the entry may run BEFORE the fetch: one that does\n * not need a version is evaluated first, so an offline user in a checkout is\n * told they are in a checkout rather than told to go debug their network.\n */\n needsVersion: boolean;\n /**\n * Does it apply to `--check`? Everything here is a reason not to WRITE, and\n * `--check` only reports, so today nothing does. An entry that ever answers\n * yes is one whose test says the REPORT would be wrong, not the install.\n */\n appliesToCheck: boolean;\n}\n\n/**\n * Ordered most-specific first: a checkout and an npx cache are recognizable\n * before any question of which manager or which tree, and the manager entry\n * precedes the global/local one because a pnpm or bun store has its own layout\n * that `isGlobalTree` is not written for.\n */\nexport const REFUSALS: readonly Refusal[] = [\n {\n test: isSourceCheckout,\n error: () =>\n new CliError('REFUSED', 'tenjin-cli is running from a source checkout, not an install', {\n fix: 'Update the checkout instead: git pull && pnpm install',\n }),\n needsVersion: false,\n appliesToCheck: false,\n },\n {\n test: (moduleDir) => moduleDir.split(sep).includes('_npx'),\n error: (spec) =>\n new CliError('REFUSED', 'tenjin-cli is running from the npx cache, not an install', {\n // Writing a global here would \"succeed\" and change nothing: the next\n // `npx tenjin` still resolves its own cached copy.\n fix: `npx fetches its own copy every time. To keep one: npm i -g ${spec}`,\n }),\n needsVersion: true,\n appliesToCheck: false,\n },\n {\n // The ONLY manager still refused. `yarn global add` is yarn-1 only, and\n // berry dropped global installs altogether, so there is no one command this\n // can drive across the versions a user might have. Every other manager is\n // delegated to rather than refused (see MANAGERS).\n test: (moduleDir) => classifyManager(moduleDir) === 'yarn',\n error: (spec) =>\n new CliError(\n 'REFUSED',\n 'This tenjin-cli was installed with yarn, whose global install exists only in yarn 1',\n { fix: `yarn global add ${spec}` },\n ),\n needsVersion: true,\n appliesToCheck: false,\n },\n {\n // Scoped to npm on purpose: the prefix-vs-project-root test is written for\n // npm's layout. pnpm's global store and bun's global dir both keep a\n // package.json beside `node_modules`, so an unscoped test would read either\n // as a project-local install and refuse the very case we now delegate.\n test: (moduleDir) => classifyManager(moduleDir) === 'npm' && !isGlobalTree(moduleDir),\n error: (spec) =>\n new CliError(\n 'REFUSED',\n 'This tenjin-cli is a project-local dependency, not a global install',\n {\n fix: `Update it where it is declared: npm i ${spec}`,\n },\n ),\n needsVersion: true,\n appliesToCheck: false,\n },\n];\n\n/**\n * Evaluate the refusal set, once per stage. `spec` is null before the registry\n * has been asked and the resolved `tenjin-cli@<version>` after, which is what\n * selects the eligible entries: every entry runs in exactly one stage, so no\n * refusal can be reached twice or, as in round three, be written twice and\n * reached once.\n */\nexport function refuse(moduleDir: string, opts: { check: boolean; spec: string | null }): void {\n for (const entry of REFUSALS) {\n if (opts.check && !entry.appliesToCheck) continue;\n if (entry.needsVersion !== (opts.spec !== null)) continue;\n if (entry.test(moduleDir)) throw entry.error(opts.spec ?? '', moduleDir);\n }\n}\n\n/**\n * The published package ships `dist/`, `docs/`, and `skills/` with no `src/`\n * beside them (the `files` array), so a `src/` next to the nearest package.json\n * means a checkout, whose version number says nothing about what HEAD holds.\n * Same test skill-heal uses to keep its hands off working-tree skills.\n */\nexport function isSourceCheckout(moduleDir: string): boolean {\n let dir = moduleDir;\n for (let i = 0; i < 8; i += 1) {\n if (existsSync(join(dir, 'package.json'))) return existsSync(join(dir, 'src'));\n const parent = dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n return false;\n}\n\n/**\n * Is this a GLOBAL npm tree? A global install sits under a prefix directory that\n * is not itself a package (`<prefix>/lib/node_modules/tenjin-cli` on POSIX,\n * `<prefix>\\node_modules\\tenjin-cli` on win32), while a project-local one sits\n * under the project root, which by definition has a package.json. That parent is\n * the whole test, which is why it holds for homebrew, nvm, volta and a\n * user-set `npm config prefix` alike without this code enumerating any of them.\n */\nexport function isGlobalTree(moduleDir: string): boolean {\n const segs = moduleDir.split(sep);\n const i = segs.lastIndexOf('node_modules');\n if (i <= 0) return false;\n return !existsSync(join(segs.slice(0, i).join(sep), 'package.json'));\n}\n\n/**\n * Which package manager owns this install, read off the on-disk path. Node\n * resolved the bin symlink before loading us, so the segments name the real\n * store: pnpm's virtual store keeps a literal `.pnpm` segment (or\n * `pnpm/global` for older layouts), bun installs under `.bun`, yarn under\n * `.yarn` or `yarn/global`. Everything else is treated as npm's tree; that\n * covers nvm and volta, both of which route `npm i -g` correctly.\n */\nexport function classifyManager(moduleDir: string): Delegable | 'yarn' {\n const segs = moduleDir.split(sep);\n const pair = (a: string, b: string): boolean => segs.includes(a) && segs.includes(b);\n if (segs.includes('.pnpm') || pair('pnpm', 'global')) return 'pnpm';\n if (segs.includes('.bun')) return 'bun';\n if (segs.includes('.yarn') || pair('yarn', 'global')) return 'yarn';\n return 'npm';\n}\n\n/**\n * How to perform a global install with each manager we delegate to.\n *\n * `scriptSuffixes` is what a PATH shim may resolve to that Node can run\n * directly, which is how win32 is served without a shell: npm and pnpm ship as\n * JS, so the child becomes `node <script>`. An empty list means the binary is\n * native (bun), where spawning it by name already works on every platform.\n */\nexport const MANAGERS: Record<\n Delegable,\n {\n bin: string;\n scriptSuffixes: readonly string[];\n /** Ships beside the running node, as npm does inside the Node distribution. */\n besideNode: boolean;\n args: (spec: string) => string[];\n manual: (spec: string) => string;\n }\n> = {\n npm: {\n bin: 'npm',\n scriptSuffixes: ['npm-cli.js'],\n besideNode: true,\n args: (spec) => ['install', '-g', '--ignore-scripts', spec],\n manual: (spec) => `npm i -g ${spec}`,\n },\n pnpm: {\n bin: 'pnpm',\n // corepack's shim resolves to `pnpm.js`, a standalone install to `pnpm.cjs`.\n scriptSuffixes: ['.cjs', '.js'],\n besideNode: false,\n args: (spec) => ['add', '-g', '--ignore-scripts', spec],\n manual: (spec) => `pnpm add -g ${spec}`,\n },\n bun: {\n bin: 'bun',\n scriptSuffixes: [],\n besideNode: false,\n // No --ignore-scripts: bun's flag surface for it is not stable across the\n // versions in the wild, and an unknown flag would fail the install outright.\n args: (spec) => ['add', '-g', spec],\n manual: (spec) => `bun add -g ${spec}`,\n },\n};\n\n/**\n * npm's own entry script, so the child can be `node npm-cli.js` rather than the\n * `npm` shim.\n *\n * On win32 the shim is `npm.cmd`, which Node refuses to spawn without\n * `shell: true`, and `shell: true` is exactly what this command must not do —\n * it would hand back the argv safety the pinned version buys.\n *\n * Deliberately NOT \"npm ships inside the Node distribution\". That is a property\n * of the installer, not of Node: Homebrew's plain `node` formula keeps only\n * corepack in the keg and puts npm at the brew prefix, so a probe relative to\n * `process.execPath` alone returns null on one of the most common macOS setups.\n * So the layout is searched, not assumed — beside the running binary first\n * (official tarball and installer, nvm, volta, versioned brew kegs), then off\n * PATH, where on POSIX the `npm` shim is itself a symlink to `npm-cli.js` and on\n * win32 `npm.cmd` has `node_modules` beside it. Still null when npm cannot be\n * found at all; the caller then falls back to the bare shim, which works\n * everywhere but win32 and fails closed there into UPDATE_FAILED carrying the\n * manual command.\n */\nexport function resolveNpmCli(\n execPath: string,\n env: NodeJS.ProcessEnv = process.env,\n): string | null {\n return resolveManagerScript('npm', execPath, env);\n}\n\n/**\n * The JS entry script for `manager`, or null when it has none to find (a native\n * binary, or a shim this cannot see through). Null means \"spawn the bare name\",\n * which works everywhere but win32 and fails closed there.\n */\nexport function resolveManagerScript(\n manager: Delegable,\n execPath: string,\n env: NodeJS.ProcessEnv = process.env,\n): string | null {\n const plan = MANAGERS[manager];\n if (plan.scriptSuffixes.length === 0) return null;\n const beside = plan.besideNode ? scriptNear(dirname(execPath), plan.bin) : null;\n return beside ?? scriptOnPath(plan.bin, plan.scriptSuffixes, env);\n}\n\n/** A manager's script relative to a directory holding `node` or its own shim. */\nfunction scriptNear(dir: string, bin: string): string | null {\n const candidates = [\n join(dir, 'node_modules', bin, 'bin', `${bin}-cli.js`),\n join(dir, '..', 'lib', 'node_modules', bin, 'bin', `${bin}-cli.js`),\n ];\n return candidates.find(isFile) ?? null;\n}\n\n/**\n * Walk PATH for the manager's shim and turn it into its script. Probes the\n * PATHEXT extensions on win32 for the same reason `onPath` in skill-wiring.ts\n * does: the real file there is `npm.cmd`, never a bare `npm`.\n */\nfunction scriptOnPath(\n bin: string,\n suffixes: readonly string[],\n env: NodeJS.ProcessEnv,\n): string | null {\n const exts =\n process.platform === 'win32'\n ? ['', ...(env.PATHEXT ?? '.EXE;.CMD;.BAT;.COM').split(';').filter((e) => e.length > 0)]\n : [''];\n for (const part of (env.PATH ?? '').split(delimiter)) {\n if (part.length === 0) continue;\n for (const ext of exts) {\n if (!isFile(join(part, `${bin}${ext}`))) continue;\n // POSIX package managers link the shim straight at the script, which is\n // what makes this layout-independent rather than a longer guess list.\n //\n // The endsWith is a CORRECTNESS check, not a security guard: it asks \"did\n // this symlink land on npm's script or on something else\", and a shim\n // pointed elsewhere returns null, which falls back to spawning that same\n // retargeted shim anyway. PATH poisoning is out of scope by construction —\n // an attacker ahead of npm on PATH owns every tool the user runs, and the\n // pre-existing fallback `spawn('npm', ...)` resolved through the same PATH.\n const real = realpathOrNull(join(part, `${bin}${ext}`));\n if (real !== null && suffixes.some((suffix) => real.endsWith(suffix))) return real;\n const near = scriptNear(part, bin);\n if (near !== null) return near;\n }\n }\n return null;\n}\n\nfunction isFile(p: string): boolean {\n try {\n return statSync(p).isFile();\n } catch {\n return false;\n }\n}\n\nfunction realpathOrNull(p: string): string | null {\n try {\n return realpathSync(p);\n } catch {\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,eAAe;AACxB,SAAS,qBAAqB;;;ACF9B,SAAS,YAAY,cAAc,gBAAgB;AACnD,SAAS,WAAW,SAAS,MAAM,WAAW;AAkDvC,IAAM,WAA+B;AAAA,EAC1C;AAAA,IACE,MAAM;AAAA,IACN,OAAO,MACL,IAAI,SAAS,WAAW,gEAAgE;AAAA,MACtF,KAAK;AAAA,IACP,CAAC;AAAA,IACH,cAAc;AAAA,IACd,gBAAgB;AAAA,EAClB;AAAA,EACA;AAAA,IACE,MAAM,CAAC,cAAc,UAAU,MAAM,GAAG,EAAE,SAAS,MAAM;AAAA,IACzD,OAAO,CAAC,SACN,IAAI,SAAS,WAAW,4DAA4D;AAAA;AAAA;AAAA,MAGlF,KAAK,8DAA8D,IAAI;AAAA,IACzE,CAAC;AAAA,IACH,cAAc;AAAA,IACd,gBAAgB;AAAA,EAClB;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKE,MAAM,CAAC,cAAc,gBAAgB,SAAS,MAAM;AAAA,IACpD,OAAO,CAAC,SACN,IAAI;AAAA,MACF;AAAA,MACA;AAAA,MACA,EAAE,KAAK,mBAAmB,IAAI,GAAG;AAAA,IACnC;AAAA,IACF,cAAc;AAAA,IACd,gBAAgB;AAAA,EAClB;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKE,MAAM,CAAC,cAAc,gBAAgB,SAAS,MAAM,SAAS,CAAC,aAAa,SAAS;AAAA,IACpF,OAAO,CAAC,SACN,IAAI;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,QACE,KAAK,yCAAyC,IAAI;AAAA,MACpD;AAAA,IACF;AAAA,IACF,cAAc;AAAA,IACd,gBAAgB;AAAA,EAClB;AACF;AASO,SAAS,OAAO,WAAmB,M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M,eAA4B,CAAC,KAAK,MAAM,MAAM,aACzD,IAAI,QAAQ,CAAC,QAAQ;AACnB,MAAI;AACJ,MAAI;AACF,YAAQ,MAAM,KAAK,MAAM,EAAE,OAAO,CAAC,UAAU,QAAQ,MAAM,GAAG,KAAK,KAAK,IAAI,CAAC;AAAA,EAC/E,SAAS,OAAO;AAGd,QAAI,EAAE,MAAM,gBAAgB,MAAM,CAAC;AACnC;AAAA,EACF;AACA,MAAI,WAAW;AACf,QAAM,QAAQ,WAAW,MAAM;AAC7B,eAAW;AACX,UAAM,KAAK,SAAS;AAAA,EACtB,GAAG,KAAK,SAAS;AACjB,QAAM,QAAQ,GAAG,QAAQ,CAAC,UAAkB,SAAS,MAAM,SAAS,CAAC,CAAC;AACtE,QAAM,QAAQ,GAAG,QAAQ,CAAC,UAAkB,SAAS,MAAM,SAAS,CAAC,CAAC;AACtE,QAAM,GAAG,SAAS,CAAC,UAAU;AAC3B,iBAAa,KAAK;AAClB,QAAI,EAAE,MAAM,gBAAgB,MAAM,CAAC;AAAA,EACrC,CAAC;AACD,QAAM,GAAG,SAAS,CAAC,SAAS;AAC1B,iBAAa,KAAK;AAClB,QAAI,WAAW,EAAE,MAAM,UAAU,IAAI,EAAE,MAAM,QAAQ,MAAM,QAAQ,EAAE,CAAC;AAAA,EACxE,CAAC;AACH,CAAC;","names":[]}
@@ -3,17 +3,18 @@ import {
3
3
  runWalletBalance,
4
4
  runWalletCreate,
5
5
  runWalletShow
6
- } from "./chunk-UFPJBS4C.js";
6
+ } from "./chunk-ACBEHJAH.js";
7
7
  import "./chunk-MJZZTKCC.js";
8
- import "./chunk-CNUXRXI2.js";
9
- import "./chunk-Y7ERTA7D.js";
10
- import "./chunk-IB63U6BM.js";
11
- import "./chunk-FKSAUOJU.js";
12
- import "./chunk-ALUNME53.js";
8
+ import "./chunk-7GJQ5RGA.js";
9
+ import "./chunk-3P3ES4XU.js";
10
+ import "./chunk-B676GPS2.js";
11
+ import "./chunk-ZOBNS7CX.js";
12
+ import "./chunk-736DW4V3.js";
13
+ import "./chunk-UO22YNY4.js";
14
+ import "./chunk-LSWP7MU2.js";
13
15
  import "./chunk-ZQIQ55KK.js";
14
- import "./chunk-P74I3WH4.js";
15
- import "./chunk-2I4QTOLB.js";
16
- import "./chunk-PZRAAAY2.js";
16
+ import "./chunk-QWBUKIP2.js";
17
+ import "./chunk-PAOVPSP6.js";
17
18
  import "./chunk-7FK2UN2T.js";
18
19
  import "./chunk-M2O56UK7.js";
19
20
  import "./chunk-UHTVXQ2O.js";
@@ -29,4 +30,4 @@ export {
29
30
  runWalletCreate,
30
31
  runWalletShow
31
32
  };
32
- //# sourceMappingURL=wallet-WJ6UP5OU.js.map
33
+ //# sourceMappingURL=wallet-OFXDIIGP.js.map
@@ -11,13 +11,13 @@ import {
11
11
  restoreParkedWallet,
12
12
  verifyAndPreserveOutgoingWallet,
13
13
  verifyLocalWallet
14
- } from "./chunk-CNUXRXI2.js";
15
- import "./chunk-Y7ERTA7D.js";
16
- import "./chunk-IB63U6BM.js";
17
- import "./chunk-FKSAUOJU.js";
14
+ } from "./chunk-7GJQ5RGA.js";
15
+ import "./chunk-3P3ES4XU.js";
16
+ import "./chunk-B676GPS2.js";
17
+ import "./chunk-ZOBNS7CX.js";
18
+ import "./chunk-UO22YNY4.js";
18
19
  import "./chunk-ZQIQ55KK.js";
19
- import "./chunk-2I4QTOLB.js";
20
- import "./chunk-PZRAAAY2.js";
20
+ import "./chunk-PAOVPSP6.js";
21
21
  import "./chunk-M2O56UK7.js";
22
22
  import "./chunk-UHTVXQ2O.js";
23
23
  import "./chunk-W6R3HAAG.js";
@@ -39,4 +39,4 @@ export {
39
39
  verifyAndPreserveOutgoingWallet,
40
40
  verifyLocalWallet
41
41
  };
42
- //# sourceMappingURL=wallet-UL4P2JRO.js.map
42
+ //# sourceMappingURL=wallet-SLRIYJ2U.js.map
@@ -74,21 +74,27 @@ three. It cannot unlock a keystore and never consults the spend policy.
74
74
 
75
75
  ## Getting the rules onto your machine
76
76
 
77
- `tenjin install` writes the nine rules into `~/.claude/settings.json` for you. It
78
- is one of the four setup decisions, and at a terminal it asks:
77
+ `tenjin install` writes the nine rules into `~/.claude/settings.json` for you,
78
+ plus the two rules your publish mode carries (below). It is one of the four setup
79
+ decisions, and at a terminal it asks:
79
80
 
80
- > Let your agent search tenjin without permission popups? Adds 9 free commands to
81
- > `~/.claude/settings.json`. None can spend USDC or move your keys; doctor may
82
- > check your wallet still opens. Three send or store data (search, outcome,
83
- > read). Full caveats:
81
+ > Let your agent use tenjin without permission popups? Adds 9 command rules to
82
+ > `~/.claude/settings.json`. None of them can spend your money. Details:
84
83
  > https://github.com/BackTrackCo/tenjin-agent/blob/main/docs/agent-permissions.md
85
84
 
86
- Answer yes and it merges them in. The write is additive only: it appends the rules
87
- that are missing and never removes, reorders, or rewrites an existing entry or any
88
- other key in the file, so a re-run adds nothing. A settings file it cannot parse is
89
- reported and left exactly as it is, never repaired. The rules it may write are a
90
- fixed constant, so no flag or config value can widen it to `buy`, `publish`,
91
- `session start`, or a blanket `Bash(tenjin:*)`.
85
+ On an `auto` or `full-auto` publish mode the same question says 11 rules, and adds
86
+ that your agent will publish under your identity on its own. The question is two
87
+ sentences and a link on purpose: this page is where the detail lives, and an
88
+ operator answering a yes/no cannot act on a rule string they have not met yet.
89
+
90
+ Answer yes and it merges them in. The write appends the rules that are missing and
91
+ never reorders or rewrites an existing entry or any other key in the file. It
92
+ removes exactly two things: a rule an older version of this CLI wrote and this one
93
+ no longer does, and, when your `publish.mode` is back to `review`, the two rules
94
+ that mode carries. A settings file it cannot parse is reported and left exactly as
95
+ it is, never repaired. The rules it may write are fixed constants selected by your
96
+ publish mode, so no flag or config value can widen it to `buy`, `session start`,
97
+ `send`, `config set`, or a blanket `Bash(tenjin:*)`.
92
98
 
93
99
  A non-interactive install (piped, or under `--json`) does the same write BY
94
100
  DEFAULT, with no flag: the machine most likely to be denied mid-task is the
@@ -98,8 +104,8 @@ reports how many rules landed, in which file, and that deleting those lines undo
98
104
  it.
99
105
 
100
106
  `tenjin doctor --json` carries this whole recommendation as data under
101
- `permissions` — every rule, every per-verb note, both caveats, on the failure
102
- envelope as well as the success one — so an agent that just got denied can point
107
+ `permissions` (every rule, every per-verb note, both caveats, on the failure
108
+ envelope as well as the success one) so an agent that just got denied can point
103
109
  you at the exact line. Its human render is the check list plus one link back
104
110
  here.
105
111
 
@@ -187,16 +193,105 @@ Deliberately **never** recommended, because each is a human decision:
187
193
  | Verb | Why it stays a human decision |
188
194
  | ---------------------- | ------------------------------------------------------------------------------------ |
189
195
  | `tenjin send` | Moves USDC out of the wallet, and is not bounded by the buy spend policy. See below. |
190
- | `tenjin publish` | Puts your content on a public marketplace under your identity. |
191
- | `tenjin edit` | Edits live posts and prices; a prefix rule cannot clear its read half only. |
196
+ | `tenjin publish` | Publishes publicly under your identity. Cleared only by `publish.mode`; see below. |
197
+ | `tenjin edit` | Edits live posts and prices. Cleared only by `publish.mode`; see below. |
192
198
  | `tenjin wallet create` | Creates the payment credential. |
193
199
  | `tenjin config set` | It can widen the agent's own spend policy. |
194
200
  | `tenjin install` | Writes into harness config and skills directories. |
195
201
  | `tenjin mcp` | It re-exposes every command core, so clearing it clears everything. |
202
+ | `tenjin update` | It replaces the tenjin binary the agent then runs. See below. |
196
203
 
197
204
  For the same reason, prefer the narrow rules above over a broad `Bash(tenjin:*)`,
198
205
  `Bash(tenjin wallet:*)`, or `Bash(tenjin config:*)`, which would swallow them.
199
206
 
207
+ ## The two rules your publish mode carries
208
+
209
+ `publish.mode` is where you say whether publishing asks you first. On `auto` or
210
+ `full-auto` it does not, and a harness prompt in front of every publish asks that
211
+ same question again somewhere the mode cannot answer it, so the agent stops and
212
+ the mode you chose does nothing. That is why two rules track the mode:
213
+
214
+ - `Bash(tenjin publish:*)` puts new content on the marketplace under your identity.
215
+ It publishes the contents of any local file the agent can read, gated only by the
216
+ deterministic scan below. It also opens your wallet keystore unattended and mints
217
+ a `read+write` session credential to disk when no usable one exists, which is a
218
+ strictly broader credential than the read-only one `tenjin session start` asks
219
+ for as an explicit opt-in.
220
+ - `Bash(tenjin edit:*)` updates posts your wallet already owns: reprices, refreshes
221
+ an as-of date, repairs an answer card. Owner-scoped on both legs, spends nothing,
222
+ and creates no new public content, but it opens the keystore on the same terms,
223
+ and it runs the same `publish.mode` gate in the CLI. A mode that can publish a
224
+ post unattended but cannot fix that post's price is the asymmetry the mode exists
225
+ to remove.
226
+
227
+ Neither is in any block above: there is nothing to paste here, because the mode is
228
+ the decision and the rules only follow it. Neither can spend: `publish` and `edit`
229
+ carry no payment path, so what they reach is your identity and your keystore, not
230
+ your balance.
231
+
232
+ **Installing Tenjin is the consent for these.** `tenjin install` settles
233
+ `publish.mode` at `auto` unless you say otherwise, and writes both rules alongside
234
+ the free tier on the FIRST install, headless runs included. Pass
235
+ `--publish-mode review` if you want the mode without the rules; at a terminal the
236
+ install asks the question outright, with auto as the default answer.
237
+
238
+ Each surface discloses the grant at the depth its reader can use. At a terminal
239
+ the install says which mode it settled, what your agent will now do in plain
240
+ words, and the one command that turns it off (`tenjin config set publish.mode
241
+ review`); it deliberately prints no rule strings, because a `Bash(...)` line an
242
+ operator is meeting for the first time mid-install is not something they can act
243
+ on. `tenjin install --json` and `tenjin doctor --json` carry the whole thing as
244
+ data: both rule strings, what they clear including the keystore and the
245
+ `read+write` session mint, and all three undos. This page is the long form.
246
+
247
+ The bare CLI, on a machine where `install` never ran, still defaults to `review`
248
+ and grants nothing. Install is the consent anchor: nothing here is granted to
249
+ someone who never ran it.
250
+
251
+ Going back to `review` takes them away, on the next `install` or immediately
252
+ with `tenjin config set publish.mode review`. `tenjin uninstall` reclaims them
253
+ like every other rule this CLI wrote. There is no flag that adds them and no line
254
+ to paste: change the mode.
255
+
256
+ Your `publish.mode` lives in `~/.tenjin/config.json` and survives `tenjin
257
+ uninstall` along with the rest of your config, so a later `tenjin install` resumes
258
+ it and writes both rules again: installing is the consent, each time. Set the mode
259
+ to `review` before uninstalling, or pass `--publish-mode review` when you come
260
+ back, if you want the rules to stay gone.
261
+
262
+ `tenjin config set publish.mode` keeps the two in step without waiting for the
263
+ next `install`. Moving to `auto` or `full-auto` asks you once, naming both rules,
264
+ and writes them on yes; a run with no terminal, a `--json` run, or a no leaves
265
+ the file alone and prints where the rules go. Moving back to `review` retracts
266
+ them without asking, because that direction can only take back what this CLI
267
+ wrote. It runs through a pass that removes and never appends, so it retracts on
268
+ any machine carrying the rules, including one whose free tier no longer matches
269
+ what this release ships. The one case it cannot handle is a settings file it
270
+ cannot parse, which it reports by name along with `tenjin uninstall`.
271
+
272
+ What still stops a bad publish is the CLI, not the harness prompt: the
273
+ deterministic secret scan blocks in every mode and is never clearable by `--yes`,
274
+ `auto` stops on any finding, and `full-auto` stops only on a hard block. These
275
+ rules clear the harness prompt and nothing else.
276
+
277
+ Read "`auto` stops on any finding" as a stop rather than as a human, though.
278
+ These are prefix rules: they pin the verb, not the flags. `--yes` is an ordinary
279
+ flag on the same allowlisted verb, and it clears exactly the WARN findings `auto`
280
+ stopped on, so a re-run with it collapses `auto` into `full-auto` with nobody
281
+ asked, the same hazard the `tenjin buy` line carries. What holds that line is the
282
+ skills, which render the findings as the question rather than asking a generic
283
+ one first.
284
+
285
+ ### `tenjin update`, a human decision
286
+
287
+ `tenjin update` replaces the globally installed `tenjin` with whatever npm serves
288
+ next, which is the binary the agent goes on to run for the rest of the session and
289
+ every session after it. Which build an agent executes is an operator decision, so
290
+ no recommended rule pre-clears it. `tenjin update --check` only reports, but a
291
+ prefix rule pins the **verb**, not the flags, so clearing the check would clear
292
+ the install with it. Nothing stops you adding the rule yourself; it stays off the
293
+ recommended set.
294
+
200
295
  ### `tenjin fund`, free on both surfaces
201
296
 
202
297
  Free by owner decision (2026-08-12), because on either surface the command just