tenjin-cli 0.1.0-alpha.8 → 0.1.0-alpha.9

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 (124) hide show
  1. package/README.md +26 -0
  2. package/dist/{buy-K2G6XQY2.js → buy-3PPC2SRQ.js} +23 -21
  3. package/dist/{candidate-DJB2NNTG.js → candidate-FCBWDN4Y.js} +10 -8
  4. package/dist/{chunk-NVHQCTIC.js → chunk-3MQSXDWS.js} +10 -11
  5. package/dist/chunk-3MQSXDWS.js.map +1 -0
  6. package/dist/{chunk-DH6D6QIO.js → chunk-6DWKU4RH.js} +11 -9
  7. package/dist/{chunk-DH6D6QIO.js.map → chunk-6DWKU4RH.js.map} +1 -1
  8. package/dist/{chunk-DQDGBWWH.js → chunk-6L34JW52.js} +3 -2
  9. package/dist/chunk-6L34JW52.js.map +1 -0
  10. package/dist/{chunk-XFHZWORF.js → chunk-6RODLWPQ.js} +101 -35
  11. package/dist/chunk-6RODLWPQ.js.map +1 -0
  12. package/dist/{chunk-VZ3AJCO5.js → chunk-75G4REUY.js} +2 -2
  13. package/dist/{chunk-C3S6725N.js → chunk-7MJCZ2OX.js} +12 -12
  14. package/dist/{chunk-PCLPVJ3J.js → chunk-7WDY4AXV.js} +15 -15
  15. package/dist/{chunk-RGTTACP3.js → chunk-ATSCQETF.js} +5 -5
  16. package/dist/{chunk-QB2NNV6C.js → chunk-AX5WQ3H5.js} +8 -6
  17. package/dist/{chunk-QB2NNV6C.js.map → chunk-AX5WQ3H5.js.map} +1 -1
  18. package/dist/{chunk-WRWCDLVK.js → chunk-BFAFOBO3.js} +23 -4
  19. package/dist/chunk-BFAFOBO3.js.map +1 -0
  20. package/dist/{chunk-DAJ56EUU.js → chunk-CTFFFQFH.js} +3 -3
  21. package/dist/{chunk-B7YB4MMU.js → chunk-E5PZEPUO.js} +9 -9
  22. package/dist/{chunk-GABYDXWL.js → chunk-FFTWWJRW.js} +21 -5
  23. package/dist/{chunk-GABYDXWL.js.map → chunk-FFTWWJRW.js.map} +1 -1
  24. package/dist/{chunk-6OE2IJMH.js → chunk-G7ECLIN6.js} +22 -22
  25. package/dist/{chunk-CYRYVZPN.js → chunk-GJKDWZ6X.js} +3 -3
  26. package/dist/{chunk-RGFBBNGP.js → chunk-I4WQXOEL.js} +16 -13
  27. package/dist/chunk-I4WQXOEL.js.map +1 -0
  28. package/dist/{chunk-OTDI5FXG.js → chunk-JURZ2T2I.js} +3 -3
  29. package/dist/{chunk-UYP7G3GZ.js → chunk-KRHUDEIQ.js} +10 -172
  30. package/dist/chunk-KRHUDEIQ.js.map +1 -0
  31. package/dist/{chunk-P3FBESBB.js → chunk-MHRREGGN.js} +5 -10
  32. package/dist/chunk-MHRREGGN.js.map +1 -0
  33. package/dist/chunk-OQXHNWM3.js +47 -0
  34. package/dist/chunk-OQXHNWM3.js.map +1 -0
  35. package/dist/chunk-P74I3WH4.js +204 -0
  36. package/dist/chunk-P74I3WH4.js.map +1 -0
  37. package/dist/{chunk-6ZBZCBR7.js → chunk-PT2NJUGG.js} +6 -6
  38. package/dist/{chunk-J6CVKC4M.js → chunk-PZRAAAY2.js} +4 -46
  39. package/dist/chunk-PZRAAAY2.js.map +1 -0
  40. package/dist/{chunk-XBJ3VLWX.js → chunk-PZSUWDF2.js} +2 -2
  41. package/dist/{chunk-BBUYCDSG.js → chunk-R2VLGNFD.js} +7 -2
  42. package/dist/chunk-R2VLGNFD.js.map +1 -0
  43. package/dist/{chunk-ZA3RFDAV.js → chunk-S4IKXAUA.js} +6 -10
  44. package/dist/chunk-S4IKXAUA.js.map +1 -0
  45. package/dist/{chunk-EDENZN2Q.js → chunk-TMZIXYPL.js} +7 -7
  46. package/dist/{chunk-YBMMV4Y4.js → chunk-TYVLXAB5.js} +26 -4
  47. package/dist/chunk-TYVLXAB5.js.map +1 -0
  48. package/dist/{chunk-URSGGRO4.js → chunk-V7BWPOKT.js} +38 -19
  49. package/dist/chunk-V7BWPOKT.js.map +1 -0
  50. package/dist/{chunk-L6AV2Q73.js → chunk-VE5BALOI.js} +5 -5
  51. package/dist/{chunk-GM4RZUVU.js → chunk-WGXUVCUF.js} +8 -6
  52. package/dist/{chunk-GM4RZUVU.js.map → chunk-WGXUVCUF.js.map} +1 -1
  53. package/dist/chunk-X3OOVSPX.js +154 -0
  54. package/dist/chunk-X3OOVSPX.js.map +1 -0
  55. package/dist/{chunk-2YX6LTCD.js → chunk-XDW6GOHO.js} +5 -5
  56. package/dist/{cli-KNCYWMAG.js → cli-ATFP3O6Y.js} +36 -27
  57. package/dist/{cli-KNCYWMAG.js.map → cli-ATFP3O6Y.js.map} +1 -1
  58. package/dist/{config-SAQEQRFB.js → config-VT5WU47R.js} +9 -6
  59. package/dist/doctor-6PEYDTB5.js +24 -0
  60. package/dist/{edit-IZZ2HIMR.js → edit-GKI37CRM.js} +21 -19
  61. package/dist/index.js +1 -1
  62. package/dist/{inspect-BFWZ5XOP.js → inspect-ITZIRZDV.js} +19 -16
  63. package/dist/{install-QXZCHIBT.js → install-BMMUPFOK.js} +217 -118
  64. package/dist/install-BMMUPFOK.js.map +1 -0
  65. package/dist/outcome-F5KN3K3Y.js +23 -0
  66. package/dist/{publish-5NTCRF2V.js → publish-F5G5WIFI.js} +22 -20
  67. package/dist/{read-T6OTMU72.js → read-II2ZO4II.js} +20 -18
  68. package/dist/{read-T6OTMU72.js.map → read-II2ZO4II.js.map} +1 -1
  69. package/dist/{run-5OGX64IY.js → run-FJWMRXZ7.js} +65 -42
  70. package/dist/run-FJWMRXZ7.js.map +1 -0
  71. package/dist/search-Z2YALF6S.js +26 -0
  72. package/dist/{send-ENE47KQE.js → send-RWOBFOBK.js} +20 -18
  73. package/dist/{send-ENE47KQE.js.map → send-RWOBFOBK.js.map} +1 -1
  74. package/dist/{session-HY4QIWHV.js → session-DJV5T3BG.js} +16 -14
  75. package/dist/{session-HY4QIWHV.js.map → session-DJV5T3BG.js.map} +1 -1
  76. package/dist/skill-heal-OK6YALW6.js +85 -0
  77. package/dist/skill-heal-OK6YALW6.js.map +1 -0
  78. package/dist/{wallet-RBDVNZVR.js → wallet-AB4ISFMY.js} +8 -7
  79. package/dist/{wallet-OCCGEH6H.js → wallet-XVRLJZ63.js} +12 -10
  80. package/package.json +2 -1
  81. package/skills/tenjin/SKILL.md +76 -41
  82. package/skills/tenjin-search/SKILL.md +10 -6
  83. package/dist/chunk-BBUYCDSG.js.map +0 -1
  84. package/dist/chunk-DQDGBWWH.js.map +0 -1
  85. package/dist/chunk-J6CVKC4M.js.map +0 -1
  86. package/dist/chunk-NVHQCTIC.js.map +0 -1
  87. package/dist/chunk-P3FBESBB.js.map +0 -1
  88. package/dist/chunk-RGFBBNGP.js.map +0 -1
  89. package/dist/chunk-URSGGRO4.js.map +0 -1
  90. package/dist/chunk-UYP7G3GZ.js.map +0 -1
  91. package/dist/chunk-WRWCDLVK.js.map +0 -1
  92. package/dist/chunk-XFHZWORF.js.map +0 -1
  93. package/dist/chunk-YBMMV4Y4.js.map +0 -1
  94. package/dist/chunk-ZA3RFDAV.js.map +0 -1
  95. package/dist/doctor-FBRQNOUQ.js +0 -22
  96. package/dist/install-QXZCHIBT.js.map +0 -1
  97. package/dist/outcome-VXCBEGNC.js +0 -20
  98. package/dist/run-5OGX64IY.js.map +0 -1
  99. package/dist/search-LIIWUMWV.js +0 -24
  100. /package/dist/{buy-K2G6XQY2.js.map → buy-3PPC2SRQ.js.map} +0 -0
  101. /package/dist/{candidate-DJB2NNTG.js.map → candidate-FCBWDN4Y.js.map} +0 -0
  102. /package/dist/{chunk-VZ3AJCO5.js.map → chunk-75G4REUY.js.map} +0 -0
  103. /package/dist/{chunk-C3S6725N.js.map → chunk-7MJCZ2OX.js.map} +0 -0
  104. /package/dist/{chunk-PCLPVJ3J.js.map → chunk-7WDY4AXV.js.map} +0 -0
  105. /package/dist/{chunk-RGTTACP3.js.map → chunk-ATSCQETF.js.map} +0 -0
  106. /package/dist/{chunk-DAJ56EUU.js.map → chunk-CTFFFQFH.js.map} +0 -0
  107. /package/dist/{chunk-B7YB4MMU.js.map → chunk-E5PZEPUO.js.map} +0 -0
  108. /package/dist/{chunk-6OE2IJMH.js.map → chunk-G7ECLIN6.js.map} +0 -0
  109. /package/dist/{chunk-CYRYVZPN.js.map → chunk-GJKDWZ6X.js.map} +0 -0
  110. /package/dist/{chunk-OTDI5FXG.js.map → chunk-JURZ2T2I.js.map} +0 -0
  111. /package/dist/{chunk-6ZBZCBR7.js.map → chunk-PT2NJUGG.js.map} +0 -0
  112. /package/dist/{chunk-XBJ3VLWX.js.map → chunk-PZSUWDF2.js.map} +0 -0
  113. /package/dist/{chunk-EDENZN2Q.js.map → chunk-TMZIXYPL.js.map} +0 -0
  114. /package/dist/{chunk-L6AV2Q73.js.map → chunk-VE5BALOI.js.map} +0 -0
  115. /package/dist/{chunk-2YX6LTCD.js.map → chunk-XDW6GOHO.js.map} +0 -0
  116. /package/dist/{config-SAQEQRFB.js.map → config-VT5WU47R.js.map} +0 -0
  117. /package/dist/{doctor-FBRQNOUQ.js.map → doctor-6PEYDTB5.js.map} +0 -0
  118. /package/dist/{edit-IZZ2HIMR.js.map → edit-GKI37CRM.js.map} +0 -0
  119. /package/dist/{inspect-BFWZ5XOP.js.map → inspect-ITZIRZDV.js.map} +0 -0
  120. /package/dist/{outcome-VXCBEGNC.js.map → outcome-F5KN3K3Y.js.map} +0 -0
  121. /package/dist/{publish-5NTCRF2V.js.map → publish-F5G5WIFI.js.map} +0 -0
  122. /package/dist/{search-LIIWUMWV.js.map → search-Z2YALF6S.js.map} +0 -0
  123. /package/dist/{wallet-OCCGEH6H.js.map → wallet-AB4ISFMY.js.map} +0 -0
  124. /package/dist/{wallet-RBDVNZVR.js.map → wallet-XVRLJZ63.js.map} +0 -0
@@ -1,54 +1,69 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
2
  import {
3
3
  runWalletCreate
4
- } from "./chunk-DH6D6QIO.js";
4
+ } from "./chunk-6DWKU4RH.js";
5
5
  import {
6
6
  collectDoctorChecks,
7
7
  recommendedPermissions
8
- } from "./chunk-XFHZWORF.js";
9
- import "./chunk-GABYDXWL.js";
8
+ } from "./chunk-6RODLWPQ.js";
9
+ import "./chunk-FFTWWJRW.js";
10
+ import "./chunk-MJZZTKCC.js";
10
11
  import {
11
12
  describeWallet,
12
13
  resolveWalletProvider
13
- } from "./chunk-RGFBBNGP.js";
14
+ } from "./chunk-I4WQXOEL.js";
14
15
  import {
15
16
  walletFileExists
16
- } from "./chunk-WRWCDLVK.js";
17
- import "./chunk-URSGGRO4.js";
18
- import "./chunk-DQDGBWWH.js";
19
- import "./chunk-XBJ3VLWX.js";
20
- import "./chunk-2I4QTOLB.js";
17
+ } from "./chunk-BFAFOBO3.js";
18
+ import "./chunk-V7BWPOKT.js";
19
+ import "./chunk-6L34JW52.js";
20
+ import "./chunk-PZSUWDF2.js";
21
+ import {
22
+ deepestExisting,
23
+ installSkill,
24
+ resolveThroughLink,
25
+ wrapWriteError
26
+ } from "./chunk-X3OOVSPX.js";
21
27
  import {
22
28
  sanitizeForTerminal
23
- } from "./chunk-BBUYCDSG.js";
29
+ } from "./chunk-R2VLGNFD.js";
24
30
  import {
25
31
  persistInstallHarness,
26
32
  persistPublishMode
27
- } from "./chunk-GM4RZUVU.js";
28
- import "./chunk-DAJ56EUU.js";
29
- import "./chunk-YBMMV4Y4.js";
33
+ } from "./chunk-WGXUVCUF.js";
34
+ import "./chunk-CTFFFQFH.js";
35
+ import {
36
+ ownsAnyLock,
37
+ releaseOwnedLocks
38
+ } from "./chunk-TYVLXAB5.js";
30
39
  import "./chunk-UO22YNY4.js";
31
40
  import {
32
- CLI_SKILL_NAMES,
33
41
  CONFIG_DEFAULTS,
42
+ PublishModeSchema,
43
+ loadRawConfig,
44
+ parsePublishModeFlag
45
+ } from "./chunk-KRHUDEIQ.js";
46
+ import "./chunk-OQXHNWM3.js";
47
+ import {
48
+ CLI_SKILL_NAMES,
34
49
  HARNESS_TARGETS,
35
50
  HOSTED_SKILL_NAME,
36
- PublishModeSchema,
37
51
  SKILL_NAMES,
38
52
  harnessDetectedBy,
39
53
  harnessTargetDir,
40
54
  isModelInvocationDisabled,
41
- loadRawConfig,
42
55
  onPath,
43
- parsePublishModeFlag,
56
+ readSkillFile,
44
57
  resolveSkillsSource
45
- } from "./chunk-UYP7G3GZ.js";
58
+ } from "./chunk-P74I3WH4.js";
59
+ import {
60
+ hasCode
61
+ } from "./chunk-2I4QTOLB.js";
46
62
  import {
47
63
  CliError,
48
64
  external_exports,
49
65
  writeFileAtomic
50
- } from "./chunk-J6CVKC4M.js";
51
- import "./chunk-MJZZTKCC.js";
66
+ } from "./chunk-PZRAAAY2.js";
52
67
  import "./chunk-7FK2UN2T.js";
53
68
  import "./chunk-M2O56UK7.js";
54
69
  import "./chunk-UHTVXQ2O.js";
@@ -62,9 +77,9 @@ import "./chunk-ZXTAQYNA.js";
62
77
 
63
78
  // src/commands/install.ts
64
79
  import { existsSync } from "fs";
65
- import { readFile as readFile2, readdir, rm } from "fs/promises";
80
+ import { readFile as readFile2 } from "fs/promises";
66
81
  import { fileURLToPath } from "url";
67
- import { join as join2, relative } from "path";
82
+ import { dirname, isAbsolute, join as join2 } from "path";
68
83
  import { homedir } from "os";
69
84
  import { styleText } from "util";
70
85
  import { Stream } from "stream";
@@ -104,16 +119,51 @@ function isPlainObject(value) {
104
119
  return typeof value === "object" && value !== null && !Array.isArray(value);
105
120
  }
106
121
  async function wireFreeVerbAllowlist(homeDir) {
122
+ const found = await inspectAllowlist(homeDir);
123
+ if ("result" in found) return found.result;
124
+ const { path, raw, settings, permissions, allow, added, alreadyPresent } = found;
125
+ if (added.length === 0) return { harness: "claude", path, added: [], alreadyPresent };
126
+ const next = {
127
+ ...settings,
128
+ permissions: { ...permissions, allow: [...allow, ...added] }
129
+ };
130
+ const current = await readFile(path, "utf8").catch(() => null);
131
+ if (current !== raw) {
132
+ return skip(
133
+ "claude",
134
+ path,
135
+ "changed-since-read",
136
+ `${path} changed while it was being updated, so nothing was written. Re-run \`tenjin install\`.`
137
+ );
138
+ }
139
+ await writeFileAtomic(path, `${JSON.stringify(next, null, 2)}
140
+ `);
141
+ return { harness: "claude", path, added, alreadyPresent };
142
+ }
143
+ async function inspectFreeVerbRules(homeDir) {
144
+ const found = await inspectAllowlist(homeDir);
145
+ if ("result" in found) return { pending: null };
146
+ if (found.added.length > 0) return { pending: found.added };
147
+ return {
148
+ pending: [],
149
+ satisfied: {
150
+ harness: "claude",
151
+ path: found.path,
152
+ added: [],
153
+ alreadyPresent: found.alreadyPresent
154
+ }
155
+ };
156
+ }
157
+ async function inspectAllowlist(homeDir) {
107
158
  const declaredPath = claudeSettingsPath(homeDir);
108
- const harness = "claude";
159
+ const refuse = (p, reason, warning) => ({ result: skip("claude", p, reason, warning) });
109
160
  const entry = await lstat(declaredPath).catch(() => null);
110
161
  let path = declaredPath;
111
162
  if (entry !== null) {
112
163
  try {
113
164
  path = await realpath(declaredPath);
114
165
  } catch (err) {
115
- return skip(
116
- harness,
166
+ return refuse(
117
167
  declaredPath,
118
168
  "unresolvable",
119
169
  `${declaredPath} could not be resolved (${err.message}); it was left exactly as it is.`
@@ -121,13 +171,12 @@ async function wireFreeVerbAllowlist(homeDir) {
121
171
  }
122
172
  }
123
173
  let settings = {};
174
+ let raw = null;
124
175
  if (entry !== null) {
125
- let raw;
126
176
  try {
127
177
  raw = await readFile(path, "utf8");
128
178
  } catch (err) {
129
- return skip(
130
- harness,
179
+ return refuse(
131
180
  path,
132
181
  "unreadable",
133
182
  `${path} could not be read (${err.message}); no permissions were written.`
@@ -137,16 +186,14 @@ async function wireFreeVerbAllowlist(homeDir) {
137
186
  try {
138
187
  parsed = JSON.parse(raw);
139
188
  } catch (err) {
140
- return skip(
141
- harness,
189
+ return refuse(
142
190
  path,
143
191
  "unparsable",
144
192
  `${path} is not valid JSON (${err.message}); it was left exactly as it is.`
145
193
  );
146
194
  }
147
195
  if (!isPlainObject(parsed)) {
148
- return skip(
149
- harness,
196
+ return refuse(
150
197
  path,
151
198
  "unexpected-shape",
152
199
  `${path} is not a JSON object; it was left exactly as it is.`
@@ -156,8 +203,7 @@ async function wireFreeVerbAllowlist(homeDir) {
156
203
  }
157
204
  const permissionsValue = settings.permissions;
158
205
  if (permissionsValue !== void 0 && !isPlainObject(permissionsValue)) {
159
- return skip(
160
- harness,
206
+ return refuse(
161
207
  path,
162
208
  "unexpected-shape",
163
209
  `${path} has a "permissions" key that is not an object; it was left exactly as it is.`
@@ -166,8 +212,7 @@ async function wireFreeVerbAllowlist(homeDir) {
166
212
  const permissions = permissionsValue ?? {};
167
213
  const allowValue = permissions.allow;
168
214
  if (allowValue !== void 0 && !Array.isArray(allowValue)) {
169
- return skip(
170
- harness,
215
+ return refuse(
171
216
  path,
172
217
  "unexpected-shape",
173
218
  `${path} has a "permissions.allow" key that is not an array; it was left exactly as it is.`
@@ -177,14 +222,7 @@ async function wireFreeVerbAllowlist(homeDir) {
177
222
  const present = new Set(allow.filter((e) => typeof e === "string"));
178
223
  const added = FREE_VERB_RULES.filter((rule) => !present.has(rule));
179
224
  const alreadyPresent = FREE_VERB_RULES.filter((rule) => present.has(rule));
180
- if (added.length === 0) return { harness, path, added: [], alreadyPresent: [...alreadyPresent] };
181
- const next = {
182
- ...settings,
183
- permissions: { ...permissions, allow: [...allow, ...added] }
184
- };
185
- await writeFileAtomic(path, `${JSON.stringify(next, null, 2)}
186
- `);
187
- return { harness, path, added, alreadyPresent: [...alreadyPresent] };
225
+ return { path, raw, settings, permissions, allow, added, alreadyPresent: [...alreadyPresent] };
188
226
  }
189
227
 
190
228
  // src/lib/clack.ts
@@ -296,6 +334,36 @@ function upsertMarkerLine(existing, line) {
296
334
  }
297
335
  var CODEX_NETWORK_RULE = "[sandbox_workspace_write]\nnetwork_access = true";
298
336
  async function runInstall(input, ctx, deps = {}) {
337
+ return withInterruptGuard((markPhase) => installBody(input, ctx, deps, markPhase));
338
+ }
339
+ async function withInterruptGuard(fn) {
340
+ let phase;
341
+ const onSignal = (signal) => {
342
+ const wasWriting = ownsAnyLock() || phase === "writing-skills";
343
+ releaseOwnedLocks();
344
+ if (process.stdin.isTTY) process.stdin.setRawMode?.(false);
345
+ if (process.stdout.isTTY) process.stdout.write("\x1B[?25h");
346
+ process.stderr.write(
347
+ wasWriting ? `
348
+ Interrupted mid-write. Some files may be half-written; re-run \`tenjin install\` to finish.
349
+ ` : phase === "wired" ? `
350
+ Interrupted after the skills were written; later setup steps may not have finished. Re-run \`tenjin install\` to finish.
351
+ ` : "\nInterrupted before anything was written; nothing changed.\n"
352
+ );
353
+ process.exit(signal === "SIGINT" ? 130 : 143);
354
+ };
355
+ process.on("SIGINT", onSignal);
356
+ process.on("SIGTERM", onSignal);
357
+ try {
358
+ return await fn((p) => {
359
+ phase = p;
360
+ });
361
+ } finally {
362
+ process.off("SIGINT", onSignal);
363
+ process.off("SIGTERM", onSignal);
364
+ }
365
+ }
366
+ async function installBody(input, ctx, deps, markPhase) {
299
367
  const parsed = InstallInputSchema.safeParse(input);
300
368
  if (!parsed.success) {
301
369
  throw new CliError("USAGE", "Invalid install options", {
@@ -310,6 +378,15 @@ async function runInstall(input, ctx, deps = {}) {
310
378
  const publishModeFlag = parsed.data.publishMode !== void 0 ? parseModeFlag(parsed.data.publishMode) : void 0;
311
379
  const env = deps.env ?? process.env;
312
380
  const home = deps.homeDir ?? homedir();
381
+ if (!isAbsolute(home)) {
382
+ throw new CliError(
383
+ "INTERNAL",
384
+ "The home directory did not resolve to an absolute path, so nothing was installed.",
385
+ {
386
+ fix: "Set HOME to your home directory (`export HOME=...`), then re-run `tenjin install`."
387
+ }
388
+ );
389
+ }
313
390
  const which = deps.which ?? ((bin) => onPath(bin, env));
314
391
  const humanOutput = ctx.flags.json === true ? false : deps.isInteractive ?? ctx.io.isTTY;
315
392
  const canPrompt = humanOutput && (deps.isInteractive ?? Boolean(process.stdin.isTTY));
@@ -319,14 +396,19 @@ async function runInstall(input, ctx, deps = {}) {
319
396
  const explicitHarness = parsed.data.harness !== void 0 && parsed.data.harness.length > 0;
320
397
  const claudeMdWrite = claudeMdFlag === true;
321
398
  const harnesses = [];
399
+ if (!dryRun) markPhase("writing-skills");
322
400
  for (const plan of plans) {
323
401
  harnesses.push(await applyPlan(plan, skillsSource, dryRun, claudeMdWrite));
324
402
  }
325
403
  await assertSkillsLanded(plans, dryRun);
404
+ if (!dryRun) markPhase("wired");
326
405
  if (explicitHarness && !dryRun) {
327
- await persistInstallHarness(
406
+ await underDataDir(
328
407
  ctx.dataDir,
329
- plans.map((p) => p.harness)
408
+ () => persistInstallHarness(
409
+ ctx.dataDir,
410
+ plans.map((p) => p.harness)
411
+ )
330
412
  );
331
413
  }
332
414
  const doctorDeps = { ...deps.doctorDeps ?? {} };
@@ -335,7 +417,10 @@ async function runInstall(input, ctx, deps = {}) {
335
417
  const collect = deps.collectChecks ?? ((c) => collectDoctorChecks(c, doctorDeps));
336
418
  const doctor = await collect(ctx);
337
419
  if (canPrompt) await (deps.intro ?? intro)("tenjin install");
338
- const publishMode = await resolvePublishMode(publishModeFlag, ctx, deps, dryRun, canPrompt);
420
+ const publishMode = await underDataDir(
421
+ ctx.dataDir,
422
+ () => resolvePublishMode(publishModeFlag, ctx, deps, dryRun, canPrompt)
423
+ );
339
424
  const permissions = await resolvePermissions({
340
425
  plans,
341
426
  home,
@@ -371,6 +456,17 @@ async function runInstall(input, ctx, deps = {}) {
371
456
  });
372
457
  return { data, humanLines };
373
458
  }
459
+ async function underDataDir(dataDir, fn) {
460
+ try {
461
+ return await fn();
462
+ } catch (err) {
463
+ if (!hasCode(err, "EACCES") && !hasCode(err, "EPERM")) throw err;
464
+ throw new CliError("INTERNAL", `Could not use the Tenjin data directory ${dataDir}.`, {
465
+ fix: `Permission denied. Check that you can write to it (\`ls -ld ${dataDir}\`), then re-run \`tenjin install\`.`,
466
+ cause: err
467
+ });
468
+ }
469
+ }
374
470
  var EXAMPLE_QUESTION = "what actually changed in <library> v3's public API";
375
471
  function buildWalkthrough(io, s) {
376
472
  const lines = [];
@@ -383,12 +479,12 @@ function buildWalkthrough(io, s) {
383
479
  function noticeLines(io, s) {
384
480
  const lines = [];
385
481
  for (const h of s.harnesses) {
386
- if (h.hostedPreexisting) {
482
+ if (h.hostedArrivedFirst) {
387
483
  lines.push(
388
484
  paint(
389
485
  io,
390
486
  "dim",
391
- `The hosted ${HOSTED_SKILL_NAME} skill was already here: kept as the zero-install fallback, and the CLI skills now take precedence.`
487
+ `The hosted ${HOSTED_SKILL_NAME} skill was already in ${h.skillsDir}: kept as the zero-install fallback, and the CLI skills now take precedence.`
392
488
  )
393
489
  );
394
490
  }
@@ -466,6 +562,9 @@ function permissionsLine(io, p) {
466
562
  if (p.skipped === "not-requested") {
467
563
  return `${paint(io, "dim", "-")} ${label} unchanged. Allow the ${FREE_VERB_RULES.length} free tenjin commands with: tenjin install --allow-free-verbs`;
468
564
  }
565
+ if (p.skipped === "changed-since-read") {
566
+ return `${paint(io, "yellow", "!")} ${label} ${p.path} changed while it was being updated, so nothing was written. Re-run: tenjin install`;
567
+ }
469
568
  return `${paint(io, "yellow", "!")} ${label} ${p.path} was left untouched. Fix it, then: tenjin install --allow-free-verbs`;
470
569
  }
471
570
  function walletLine(io, w) {
@@ -589,6 +688,8 @@ async function resolvePermissions(args) {
589
688
  if (dryRun) return permissionsSkipped("claude", home, "dry-run");
590
689
  if (flag) return wireFreeVerbAllowlist(home);
591
690
  if (!canPrompt) return permissionsSkipped("claude", home, "not-requested");
691
+ const probe = await (deps.inspectPermissions ?? inspectFreeVerbRules)(home);
692
+ if (probe.satisfied !== void 0) return probe.satisfied;
592
693
  const confirm = deps.confirmPermissions ?? defaultConfirm;
593
694
  if (!await confirm(PERMISSIONS_QUESTION)) {
594
695
  return permissionsSkipped("claude", home, "declined");
@@ -650,6 +751,7 @@ async function applyPlan(plan, skillsSource, dryRun, claudeMdWrite) {
650
751
  if (warning !== void 0) warnings.push(warning);
651
752
  }
652
753
  const hostedPreexisting = skills.some((s) => s.name === HOSTED_SKILL_NAME && s.preexisting);
754
+ const hostedArrivedFirst = hostedPreexisting && !skills.some((s) => s.cli && s.preexisting);
653
755
  const result = {
654
756
  harness: plan.harness,
655
757
  detected: plan.detected,
@@ -657,7 +759,8 @@ async function applyPlan(plan, skillsSource, dryRun, claudeMdWrite) {
657
759
  skillsDir: plan.skillsDir,
658
760
  skills,
659
761
  hostedPreexisting,
660
- notes: notesFor(plan, hostedPreexisting),
762
+ hostedArrivedFirst,
763
+ notes: notesFor(plan, hostedArrivedFirst),
661
764
  warnings
662
765
  };
663
766
  if (plan.wiresAgentsMd) {
@@ -671,34 +774,31 @@ async function applyPlan(plan, skillsSource, dryRun, claudeMdWrite) {
671
774
  async function wireClaudeMd(plan, dryRun, write) {
672
775
  const path = join2(plan.home, ".claude", "CLAUDE.md");
673
776
  if (!write) return { path, status: "skipped" };
674
- const existing = existsSync(path) ? await readFile2(path, "utf8") : null;
675
- const { content, change } = upsertMarkerLine(existing, nudgeLine(plan.skillsDir));
777
+ const probe = await probeMarkerText(path);
778
+ const { content, change } = upsertMarkerLine(probe.text, nudgeLine(plan.skillsDir));
676
779
  if (change === "none") return { path, status: "up-to-date" };
677
- if (!dryRun && content !== null) await writeFileAtomic(path, content);
780
+ const writeTo = await prepareMarkerWrite(path, probe);
781
+ if (!dryRun && content !== null) await writeMarkerFile(path, writeTo, content);
678
782
  if (change === "append") return { path, status: dryRun ? "would-write" : "written" };
679
783
  return { path, status: dryRun ? "would-update" : "updated" };
680
784
  }
681
- function notesFor(plan, hostedPreexisting) {
785
+ function notesFor(plan, hostedArrivedFirst) {
682
786
  const notes = plan.harness === "claude" ? [
683
787
  "Installed at the user level (~/.claude/skills). A Claude Code plugin will later make this automatic."
684
788
  ] : [
685
789
  "Copied into the shared Agent Skills location (~/.agents/skills). Codex and any Agent-Skills-compatible harness read it there."
686
790
  ];
687
- if (hostedPreexisting) {
791
+ if (hostedArrivedFirst) {
688
792
  notes.push(
689
- `The hosted ${HOSTED_SKILL_NAME} skill was already here; it stays as the zero-install fallback and the CLI skills (${CLI_SKILL_NAMES.join(", ")}) take precedence while the CLI is installed.`
793
+ `The hosted ${HOSTED_SKILL_NAME} skill was already here; the skill stays as the zero-install fallback (its file is replaced by this package's mirror) and the CLI skills (${CLI_SKILL_NAMES.join(", ")}) take precedence while the CLI is installed.`
690
794
  );
691
795
  }
692
796
  return notes;
693
797
  }
694
798
  async function landedInvocable(skillsDir, skillsSource, name, dryRun) {
695
- const path = join2(dryRun ? skillsSource : skillsDir, name, "SKILL.md");
696
- if (!existsSync(path)) return false;
697
- try {
698
- return !isModelInvocationDisabled(await readFile2(path, "utf8"));
699
- } catch {
700
- return false;
701
- }
799
+ const read = await readSkillFile(join2(dryRun ? skillsSource : skillsDir, name, "SKILL.md"));
800
+ if (read.kind !== "ok") return false;
801
+ return !isModelInvocationDisabled(read.bytes.toString("utf8"));
702
802
  }
703
803
  async function assertSkillsLanded(plans, dryRun) {
704
804
  if (dryRun) return;
@@ -712,74 +812,73 @@ async function assertSkillsLanded(plans, dryRun) {
712
812
  }
713
813
  if (missing.length === 0) return;
714
814
  throw new CliError("INTERNAL", `Skills were not written: ${missing.join(", ")}`, {
715
- fix: "Check permissions on the skills directory and re-run `tenjin install`."
815
+ // Safe to point at permissions because nothing removes a landed file any more:
816
+ // each shipped file arrives by its own atomic rename. When this was a
817
+ // rm-then-write it also fired on a lost race, and sent people to chmod a
818
+ // directory that was fine.
819
+ fix: `Check that you can write to the skills directory (\`ls -ld ${dirname(missing[0] ?? "")}\`), then re-run \`tenjin install\`.`
716
820
  });
717
821
  }
718
- async function installSkill(srcDir, destDir, dryRun, name) {
719
- const src = await readTree(srcDir);
720
- const dest = await readTree(destDir);
721
- if (src === null) {
722
- throw new CliError("INTERNAL", `Packaged skill source ${srcDir} is empty`);
723
- }
724
- const preexisting = dest?.has("SKILL.md") === true;
725
- const change = dest === null || dest.size === 0 ? "create" : treesEqual(src, dest) ? "none" : "update";
726
- if (!dryRun && change !== "none") {
727
- await rm(destDir, { recursive: true, force: true });
728
- for (const [rel, content] of src) {
729
- await writeFileAtomic(join2(destDir, rel), content);
730
- }
731
- }
732
- if (change === "create") return { status: dryRun ? "would-install" : "installed", preexisting };
733
- if (change === "none") return { status: "up-to-date", preexisting };
734
- return {
735
- status: dryRun ? "would-update" : "updated",
736
- preexisting,
737
- // The hosted skill is a MIRROR of tenjin.blog/skills.md (roadmap G4), so a
738
- // differing local copy is a replacement, not the drift warning the CLI skills
739
- // get. Neither side carries a version or date, so the wording claims no
740
- // direction: the local file may well be a newer fetch than this package's copy.
741
- warning: name === HOSTED_SKILL_NAME ? `${destDir}: the hosted Tenjin skill differed and ${dryRun ? "would be" : "was"} replaced by this package's mirror of tenjin.blog/skills.md, which may be older; it stays as the zero-install fallback. Re-fetch it from tenjin.blog/skills.md if you need the current one.` : `${destDir}: local skill copy differed and ${dryRun ? "would be" : "was"} overwritten (the packaged copy is canonical).`
742
- };
743
- }
744
- async function readTree(dir) {
745
- if (!existsSync(dir)) return null;
746
- const entries = await readdir(dir, { recursive: true, withFileTypes: true });
747
- const files = /* @__PURE__ */ new Map();
748
- for (const entry of entries) {
749
- if (!entry.isFile()) continue;
750
- const full = join2(entry.parentPath, entry.name);
751
- files.set(relative(dir, full), await readFile2(full));
752
- }
753
- return files;
754
- }
755
- function treesEqual(a, b) {
756
- if (b === null) return false;
757
- if (a.size !== b.size) return false;
758
- for (const [k, v] of a) {
759
- const other = b.get(k);
760
- if (other === void 0 || !v.equals(other)) return false;
761
- }
762
- return true;
763
- }
764
822
  async function wireAgentsMd(plan, dryRun) {
765
823
  const shared = join2(plan.home, ".agents", "AGENTS.md");
766
824
  const codex = join2(plan.home, ".codex", "AGENTS.md");
767
825
  const line = nudgeLine(plan.skillsDir);
826
+ const probes = /* @__PURE__ */ new Map();
768
827
  for (const path of [shared, codex]) {
769
- if (existsSync(path) && (await readFile2(path, "utf8")).includes(SKILLS_MARKER)) {
770
- return upsertAgentsMd(path, line, dryRun);
828
+ const probe = await probeMarkerText(path);
829
+ probes.set(path, probe);
830
+ if (probe.text?.includes(SKILLS_MARKER) === true) {
831
+ return upsertAgentsMd(path, probe, line, dryRun);
771
832
  }
772
833
  }
773
- return upsertAgentsMd(chooseAgentsMdPath(plan.home), line, dryRun);
834
+ const chosen = chooseAgentsMdPath(plan.home);
835
+ return upsertAgentsMd(chosen, probes.get(chosen), line, dryRun);
774
836
  }
775
- async function upsertAgentsMd(path, line, dryRun) {
776
- const existing = existsSync(path) ? await readFile2(path, "utf8") : null;
777
- const { content, change } = upsertMarkerLine(existing, line);
837
+ async function upsertAgentsMd(path, probe, line, dryRun) {
838
+ const { content, change } = upsertMarkerLine(probe.text, line);
778
839
  if (change === "none") return { path, status: "already-present" };
779
- if (!dryRun && content !== null) await writeFileAtomic(path, content);
840
+ const writeTo = await prepareMarkerWrite(path, probe);
841
+ if (!dryRun && content !== null) await writeMarkerFile(path, writeTo, content);
780
842
  if (change === "append") return { path, status: dryRun ? "would-append" : "appended" };
781
843
  return { path, status: dryRun ? "would-update" : "updated" };
782
844
  }
845
+ async function prepareMarkerWrite(declared, probe) {
846
+ assertRegularMarker(declared, probe);
847
+ return resolveThroughLink(declared, "the Tenjin pointer");
848
+ }
849
+ async function probeMarkerText(declared) {
850
+ const read = await readSkillFile(declared);
851
+ if (read.kind === "absent") return { text: null, notRegular: false };
852
+ if (read.kind === "ok") return { text: read.bytes.toString("utf8"), notRegular: false };
853
+ if (read.kind === "not-regular") return { text: null, notRegular: true };
854
+ throw wrapWriteError(read.err, declared, "the Tenjin pointer", declared, {
855
+ verb: "read",
856
+ expected: ": the pointer lands in a regular markdown file"
857
+ });
858
+ }
859
+ function assertRegularMarker(declared, probe) {
860
+ if (!probe.notRegular) return;
861
+ throw new CliError(
862
+ "INTERNAL",
863
+ `${declared} is not a regular file, so the Tenjin pointer was not written.`,
864
+ {
865
+ fix: `Check what is there (\`ls -l ${declared}\`) and remove or replace it, then re-run \`tenjin install\`.`
866
+ }
867
+ );
868
+ }
869
+ async function writeMarkerFile(declared, writeTo, content) {
870
+ try {
871
+ await writeFileAtomic(writeTo, content);
872
+ } catch (err) {
873
+ throw wrapWriteError(
874
+ err,
875
+ declared,
876
+ "the Tenjin pointer",
877
+ await deepestExisting(dirname(writeTo)),
878
+ { expected: ": the pointer lands in a regular markdown file" }
879
+ );
880
+ }
881
+ }
783
882
  function chooseAgentsMdPath(home) {
784
883
  const shared = join2(home, ".agents", "AGENTS.md");
785
884
  const codex = join2(home, ".codex", "AGENTS.md");
@@ -820,4 +919,4 @@ export {
820
919
  WALLET_QUESTION,
821
920
  runInstall
822
921
  };
823
- //# sourceMappingURL=install-QXZCHIBT.js.map
922
+ //# sourceMappingURL=install-BMMUPFOK.js.map