tenjin-cli 0.1.0-alpha.0 → 0.1.0-alpha.10

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 (191) hide show
  1. package/NOTICE.md +33 -0
  2. package/README.md +575 -50
  3. package/dist/{_esm-ZH2J4QEH.js → _esm-C5CRWCYU.js} +2 -2
  4. package/dist/_esm-N4KAVXQR.js +881 -0
  5. package/dist/buy-FMDBZ4NY.js +44 -0
  6. package/dist/candidate-7LAELUQD.js +23 -0
  7. package/dist/ccip-RPPPKTJR.js +19 -0
  8. package/dist/{ccip-FXWZDDF5.js → ccip-ZGGWQN4X.js} +6 -5
  9. package/dist/chunk-2GSRYTZS.js +127 -0
  10. package/dist/chunk-2GSRYTZS.js.map +1 -0
  11. package/dist/chunk-2I4QTOLB.js +11 -0
  12. package/dist/chunk-2I4QTOLB.js.map +1 -0
  13. package/dist/chunk-36X2CA3N.js +311 -0
  14. package/dist/chunk-36X2CA3N.js.map +1 -0
  15. package/dist/{chunk-F5DZJLU3.js → chunk-47PP7TAG.js} +1441 -634
  16. package/dist/chunk-47PP7TAG.js.map +1 -0
  17. package/dist/chunk-5JMKIDMM.js +316 -0
  18. package/dist/chunk-5JMKIDMM.js.map +1 -0
  19. package/dist/chunk-5JXAZP7H.js +206 -0
  20. package/dist/chunk-5JXAZP7H.js.map +1 -0
  21. package/dist/chunk-5SE6BJRP.js +135 -0
  22. package/dist/chunk-5SE6BJRP.js.map +1 -0
  23. package/dist/chunk-6BZLSRNU.js +149 -0
  24. package/dist/chunk-6BZLSRNU.js.map +1 -0
  25. package/dist/{chunk-PAAL45FJ.js → chunk-7FK2UN2T.js} +3410 -412
  26. package/dist/chunk-7FK2UN2T.js.map +1 -0
  27. package/dist/chunk-7WDY4AXV.js +14620 -0
  28. package/dist/chunk-7WDY4AXV.js.map +1 -0
  29. package/dist/chunk-A6KCZPNQ.js +83 -0
  30. package/dist/chunk-A6KCZPNQ.js.map +1 -0
  31. package/dist/chunk-AWQ6A4CI.js +341 -0
  32. package/dist/chunk-AWQ6A4CI.js.map +1 -0
  33. package/dist/chunk-BJJ5BQO6.js +162 -0
  34. package/dist/chunk-BJJ5BQO6.js.map +1 -0
  35. package/dist/chunk-BUDHTDKL.js +612 -0
  36. package/dist/chunk-BUDHTDKL.js.map +1 -0
  37. package/dist/chunk-DKQMJTG7.js +188 -0
  38. package/dist/chunk-DKQMJTG7.js.map +1 -0
  39. package/dist/chunk-FKSAUOJU.js +137 -0
  40. package/dist/chunk-FKSAUOJU.js.map +1 -0
  41. package/dist/chunk-GECSWJ7O.js +1645 -0
  42. package/dist/chunk-GECSWJ7O.js.map +1 -0
  43. package/dist/chunk-GSDZRCGF.js +105 -0
  44. package/dist/chunk-GSDZRCGF.js.map +1 -0
  45. package/dist/chunk-JSSIMGQT.js +174 -0
  46. package/dist/chunk-JSSIMGQT.js.map +1 -0
  47. package/dist/chunk-KYH4KPE5.js +1357 -0
  48. package/dist/chunk-KYH4KPE5.js.map +1 -0
  49. package/dist/chunk-KYQVEKP5.js +209 -0
  50. package/dist/chunk-KYQVEKP5.js.map +1 -0
  51. package/dist/chunk-KZAAWQNP.js +6199 -0
  52. package/dist/chunk-KZAAWQNP.js.map +1 -0
  53. package/dist/{chunk-SXQQ2ZSR.js → chunk-M2O56UK7.js} +243 -75
  54. package/dist/chunk-M2O56UK7.js.map +1 -0
  55. package/dist/chunk-MD7WGYYI.js +125 -0
  56. package/dist/chunk-MD7WGYYI.js.map +1 -0
  57. package/dist/chunk-MJZZTKCC.js +323 -0
  58. package/dist/chunk-MJZZTKCC.js.map +1 -0
  59. package/dist/chunk-O6CAUZGY.js +317 -0
  60. package/dist/chunk-O6CAUZGY.js.map +1 -0
  61. package/dist/chunk-P74I3WH4.js +204 -0
  62. package/dist/chunk-P74I3WH4.js.map +1 -0
  63. package/dist/chunk-POF7HPRV.js +145 -0
  64. package/dist/chunk-POF7HPRV.js.map +1 -0
  65. package/dist/chunk-POJRB2AE.js +83 -0
  66. package/dist/chunk-POJRB2AE.js.map +1 -0
  67. package/dist/{chunk-FIYZLITH.js → chunk-PZRAAAY2.js} +107 -18
  68. package/dist/chunk-PZRAAAY2.js.map +1 -0
  69. package/dist/chunk-PZSUWDF2.js +35 -0
  70. package/dist/chunk-PZSUWDF2.js.map +1 -0
  71. package/dist/chunk-QW2Q2KAH.js +27 -0
  72. package/dist/chunk-QW2Q2KAH.js.map +1 -0
  73. package/dist/chunk-R2VLGNFD.js +181 -0
  74. package/dist/chunk-R2VLGNFD.js.map +1 -0
  75. package/dist/{chunk-CPUZRZ2A.js → chunk-RBJPAZFI.js} +25 -170
  76. package/dist/chunk-RBJPAZFI.js.map +1 -0
  77. package/dist/chunk-S5RYMCV6.js +70 -0
  78. package/dist/chunk-S5RYMCV6.js.map +1 -0
  79. package/dist/chunk-SGK2B724.js +67 -0
  80. package/dist/chunk-SGK2B724.js.map +1 -0
  81. package/dist/chunk-STND72DS.js +242 -0
  82. package/dist/chunk-STND72DS.js.map +1 -0
  83. package/dist/chunk-TEL27PR5.js +124 -0
  84. package/dist/chunk-TEL27PR5.js.map +1 -0
  85. package/dist/chunk-TWRYSGAW.js +134 -0
  86. package/dist/chunk-TWRYSGAW.js.map +1 -0
  87. package/dist/{chunk-WOHCAMDQ.js → chunk-U5S527PP.js} +1887 -1029
  88. package/dist/chunk-U5S527PP.js.map +1 -0
  89. package/dist/chunk-UHTVXQ2O.js +140 -0
  90. package/dist/chunk-UHTVXQ2O.js.map +1 -0
  91. package/dist/chunk-UOJRKQTZ.js +213 -0
  92. package/dist/chunk-UOJRKQTZ.js.map +1 -0
  93. package/dist/chunk-V4WWTZHZ.js +233 -0
  94. package/dist/chunk-V4WWTZHZ.js.map +1 -0
  95. package/dist/chunk-VRRLTZ2Q.js +651 -0
  96. package/dist/chunk-VRRLTZ2Q.js.map +1 -0
  97. package/dist/{chunk-TX5T3LKJ.js → chunk-W6R3HAAG.js} +21 -17
  98. package/dist/{chunk-TX5T3LKJ.js.map → chunk-W6R3HAAG.js.map} +1 -1
  99. package/dist/chunk-X3OOVSPX.js +154 -0
  100. package/dist/chunk-X3OOVSPX.js.map +1 -0
  101. package/dist/chunk-XJN5WUKL.js +204 -0
  102. package/dist/chunk-XJN5WUKL.js.map +1 -0
  103. package/dist/chunk-Y7ERTA7D.js +146 -0
  104. package/dist/chunk-Y7ERTA7D.js.map +1 -0
  105. package/dist/chunk-YLYINX2H.js +7806 -0
  106. package/dist/chunk-YLYINX2H.js.map +1 -0
  107. package/dist/chunk-ZQIQ55KK.js +51 -0
  108. package/dist/chunk-ZQIQ55KK.js.map +1 -0
  109. package/dist/chunk-ZUAQRIVP.js +1369 -0
  110. package/dist/chunk-ZUAQRIVP.js.map +1 -0
  111. package/dist/{chunk-3IMLRUZE.js → chunk-ZXTAQYNA.js} +6 -2
  112. package/dist/chunk-ZXTAQYNA.js.map +1 -0
  113. package/dist/{cli-LMHGCZ5S.js → cli-HK2XAWNW.js} +438 -177
  114. package/dist/cli-HK2XAWNW.js.map +1 -0
  115. package/dist/config-LYCHHNAJ.js +26 -0
  116. package/dist/config-LYCHHNAJ.js.map +1 -0
  117. package/dist/dist-U4M6QCKE.js +2842 -0
  118. package/dist/dist-U4M6QCKE.js.map +1 -0
  119. package/dist/doctor-2KPUQURC.js +27 -0
  120. package/dist/doctor-2KPUQURC.js.map +1 -0
  121. package/dist/edit-TST3OCKQ.js +38 -0
  122. package/dist/edit-TST3OCKQ.js.map +1 -0
  123. package/dist/ethersCompat-Df4a6QIZ-WHYKB6HA.js +18 -0
  124. package/dist/ethersCompat-Df4a6QIZ-WHYKB6HA.js.map +1 -0
  125. package/dist/index.js +1 -1
  126. package/dist/inspect-TPTHVPBB.js +35 -0
  127. package/dist/inspect-TPTHVPBB.js.map +1 -0
  128. package/dist/install-PT3XEDJ6.js +1869 -0
  129. package/dist/install-PT3XEDJ6.js.map +1 -0
  130. package/dist/{mine.wasm-GQECMSGN.js → mine.wasm-6PIT3DK6.js} +2 -2
  131. package/dist/outcome-NPNSF2Q7.js +22 -0
  132. package/dist/outcome-NPNSF2Q7.js.map +1 -0
  133. package/dist/publish-XP5SEWST.js +41 -0
  134. package/dist/publish-XP5SEWST.js.map +1 -0
  135. package/dist/read-D4VXRWOG.js +158 -0
  136. package/dist/read-D4VXRWOG.js.map +1 -0
  137. package/dist/run-3IPGEXW7.js +16902 -0
  138. package/dist/run-3IPGEXW7.js.map +1 -0
  139. package/dist/search-YOBD6VDI.js +24 -0
  140. package/dist/search-YOBD6VDI.js.map +1 -0
  141. package/dist/{secp256k1-35YNNB6F.js → secp256k1-XRPVBC6V.js} +5 -4
  142. package/dist/secp256k1-XRPVBC6V.js.map +1 -0
  143. package/dist/send-BWNP6WN4.js +223 -0
  144. package/dist/send-BWNP6WN4.js.map +1 -0
  145. package/dist/session-GZEZBOMI.js +88 -0
  146. package/dist/session-GZEZBOMI.js.map +1 -0
  147. package/dist/skill-heal-OK6YALW6.js +85 -0
  148. package/dist/skill-heal-OK6YALW6.js.map +1 -0
  149. package/dist/usdc-4VCDHFWX.js +38 -0
  150. package/dist/usdc-4VCDHFWX.js.map +1 -0
  151. package/dist/viemAdapter-By13KInL-TUQJBMHM.js +14 -0
  152. package/dist/viemAdapter-By13KInL-TUQJBMHM.js.map +1 -0
  153. package/dist/wallet-5RHDFPN2.js +32 -0
  154. package/dist/wallet-5RHDFPN2.js.map +1 -0
  155. package/dist/wallet-YEGQBWWL.js +42 -0
  156. package/dist/wallet-YEGQBWWL.js.map +1 -0
  157. package/docs/agent-permissions.md +281 -0
  158. package/package.json +26 -17
  159. package/skills/tenjin/SKILL.md +364 -0
  160. package/skills/tenjin-publish/SKILL.md +219 -0
  161. package/skills/tenjin-search/SKILL.md +335 -0
  162. package/dist/chunk-376LHMK2.js +0 -100
  163. package/dist/chunk-376LHMK2.js.map +0 -1
  164. package/dist/chunk-CPUZRZ2A.js.map +0 -1
  165. package/dist/chunk-F5DZJLU3.js.map +0 -1
  166. package/dist/chunk-FIYZLITH.js.map +0 -1
  167. package/dist/chunk-LTTRND4A.js +0 -135
  168. package/dist/chunk-LTTRND4A.js.map +0 -1
  169. package/dist/chunk-PAAL45FJ.js.map +0 -1
  170. package/dist/chunk-QHIEYBLV.js +0 -320
  171. package/dist/chunk-QHIEYBLV.js.map +0 -1
  172. package/dist/chunk-SXQQ2ZSR.js.map +0 -1
  173. package/dist/chunk-WOHCAMDQ.js.map +0 -1
  174. package/dist/chunk-ZPZFPVDN.js +0 -67
  175. package/dist/chunk-ZPZFPVDN.js.map +0 -1
  176. package/dist/cli-LMHGCZ5S.js.map +0 -1
  177. package/dist/config-XVXZ3V2Q.js +0 -206
  178. package/dist/config-XVXZ3V2Q.js.map +0 -1
  179. package/dist/doctor-MVLZRVPU.js +0 -338
  180. package/dist/doctor-MVLZRVPU.js.map +0 -1
  181. package/dist/usdc-OQUOFF6R.js +0 -18
  182. package/dist/wallet-NRKWLKHX.js +0 -153
  183. package/dist/wallet-NRKWLKHX.js.map +0 -1
  184. package/dist/wallet-QUWK2PA4.js +0 -22
  185. /package/dist/{_esm-ZH2J4QEH.js.map → _esm-C5CRWCYU.js.map} +0 -0
  186. /package/dist/{ccip-FXWZDDF5.js.map → _esm-N4KAVXQR.js.map} +0 -0
  187. /package/dist/{chunk-3IMLRUZE.js.map → buy-FMDBZ4NY.js.map} +0 -0
  188. /package/dist/{secp256k1-35YNNB6F.js.map → candidate-7LAELUQD.js.map} +0 -0
  189. /package/dist/{usdc-OQUOFF6R.js.map → ccip-RPPPKTJR.js.map} +0 -0
  190. /package/dist/{wallet-QUWK2PA4.js.map → ccip-ZGGWQN4X.js.map} +0 -0
  191. /package/dist/{mine.wasm-GQECMSGN.js.map → mine.wasm-6PIT3DK6.js.map} +0 -0
@@ -0,0 +1,651 @@
1
+ import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ permissionsPointer,
4
+ recommendedPermissions
5
+ } from "./chunk-TWRYSGAW.js";
6
+ import {
7
+ isSessionPresentable,
8
+ readSessionFile
9
+ } from "./chunk-5JXAZP7H.js";
10
+ import {
11
+ walletFileExists
12
+ } from "./chunk-Y7ERTA7D.js";
13
+ import {
14
+ fetchJson
15
+ } from "./chunk-DKQMJTG7.js";
16
+ import {
17
+ trimSlash,
18
+ tryOriginOf
19
+ } from "./chunk-PZSUWDF2.js";
20
+ import {
21
+ sanitizeForTerminal
22
+ } from "./chunk-R2VLGNFD.js";
23
+ import {
24
+ loadRawConfig,
25
+ resolveSettings,
26
+ toMoney
27
+ } from "./chunk-36X2CA3N.js";
28
+ import {
29
+ configPath,
30
+ sessionPath
31
+ } from "./chunk-ZQIQ55KK.js";
32
+ import {
33
+ CLI_SKILL_NAMES,
34
+ HOSTED_SKILL_NAME,
35
+ anyTenjinSkill,
36
+ cliSkillsWired,
37
+ detectHarnesses,
38
+ harnessFlagFor,
39
+ harnessInPlay,
40
+ harnessReads,
41
+ harnessRequested,
42
+ missingCliSkills,
43
+ onPath,
44
+ readAllWiring,
45
+ readSkillFile,
46
+ resolveSkillsSource,
47
+ shadowedCliSkills
48
+ } from "./chunk-P74I3WH4.js";
49
+ import {
50
+ CliError
51
+ } from "./chunk-PZRAAAY2.js";
52
+
53
+ // src/commands/doctor.ts
54
+ import { styleText } from "util";
55
+ import { Stream } from "stream";
56
+ import { homedir } from "os";
57
+ import { join } from "path";
58
+ import { fileURLToPath } from "url";
59
+ var POCKET_MONEY_CEILING_ATOMIC = 20000000n;
60
+ var FIX_POINT_AT_TENJIN_API = "Point the configured base URL at a Tenjin API (expected an OpenAPI document): `tenjin config set baseUrl <url>`.";
61
+ var FIX_CHECK_NETWORK_AND_BASE_URL = "Check your network connection and the configured base URL (`tenjin config get baseUrl`).";
62
+ async function collectDoctorChecks(ctx, deps = {}) {
63
+ const env = deps.env ?? process.env;
64
+ const { config, check: configCheck } = await loadConfigForDoctor(ctx.dataDir);
65
+ const settings = resolveSettings({ config, flags: { baseUrl: ctx.flags.baseUrl }, env });
66
+ const baseUrl = settings.baseUrl.value;
67
+ const built = [
68
+ checkNode(),
69
+ configCheck,
70
+ await checkApiContract(baseUrl, ctx.flags.timeout, deps.fetchImpl),
71
+ await checkReadPath(baseUrl, ctx.flags.timeout, deps.fetchImpl),
72
+ await checkSearchContract(baseUrl, ctx.flags.timeout, deps.fetchImpl),
73
+ await checkSkills(
74
+ deps.homeDir ?? homedir(),
75
+ deps.which ?? ((bin) => onPath(bin, env)),
76
+ config.install?.harness ?? [],
77
+ deps.skillsSourceDir
78
+ ),
79
+ await checkSession(ctx.dataDir, deps.now ?? Date.now, tryOriginOf(baseUrl))
80
+ ];
81
+ for (const result of await checkWallet(ctx, deps, env, settings.rpcUrl.value)) {
82
+ built.push({ result });
83
+ }
84
+ const checks = built.map((b) => b.result);
85
+ const firstFail = built.find((b) => b.result.required && b.result.status === "fail");
86
+ if (firstFail === void 0) return { checks };
87
+ return { checks, failure: { code: firstFail.failCode ?? "INTERNAL", result: firstFail.result } };
88
+ }
89
+ async function runDoctor(ctx, deps = {}) {
90
+ const { checks, failure } = await collectDoctorChecks(ctx, deps);
91
+ if (failure !== void 0) {
92
+ const r = failure.result;
93
+ throw new CliError(failure.code, r.detail, {
94
+ ...r.fix !== void 0 ? { fix: r.fix } : {},
95
+ details: { checks, permissions: recommendedPermissions() }
96
+ });
97
+ }
98
+ return {
99
+ data: { status: "pass", checks, permissions: recommendedPermissions() },
100
+ humanLines: [...renderDoctorHuman(ctx.io, checks), "", permissionsPointer()]
101
+ };
102
+ }
103
+ function checkNode() {
104
+ const version = process.versions.node;
105
+ const major = Number.parseInt(version.split(".")[0] ?? "0", 10);
106
+ if (major >= 22) {
107
+ return { result: { name: "node", status: "ok", required: true, detail: `Node ${version}` } };
108
+ }
109
+ return {
110
+ result: {
111
+ name: "node",
112
+ status: "fail",
113
+ required: true,
114
+ detail: `Node ${version} is unsupported (need >= 22)`,
115
+ fix: "Install Node 22 or newer"
116
+ },
117
+ failCode: "NODE_UNSUPPORTED"
118
+ };
119
+ }
120
+ async function loadConfigForDoctor(dataDir) {
121
+ try {
122
+ const config = await loadRawConfig(dataDir);
123
+ const detail = Object.keys(config).length === 0 ? "No config file; using defaults" : `Config at ${configPath(dataDir)} is valid`;
124
+ return { config, check: { result: { name: "config", status: "ok", required: true, detail } } };
125
+ } catch (err) {
126
+ if (err instanceof CliError && err.code === "CONFIG_INVALID") {
127
+ return {
128
+ config: {},
129
+ check: {
130
+ result: {
131
+ name: "config",
132
+ status: "fail",
133
+ required: true,
134
+ detail: err.message,
135
+ ...err.fix !== void 0 ? { fix: err.fix } : {}
136
+ },
137
+ failCode: "CONFIG_INVALID"
138
+ }
139
+ };
140
+ }
141
+ throw err;
142
+ }
143
+ }
144
+ async function checkApiContract(baseUrl, timeoutMs, fetchImpl) {
145
+ const url = `${trimSlash(baseUrl)}/openapi.json`;
146
+ const res = await fetchJson(url, { timeoutMs, fetchImpl });
147
+ if (!res.ok) {
148
+ const malformed = res.kind === "invalid-json";
149
+ return {
150
+ result: {
151
+ name: "api-contract",
152
+ status: "fail",
153
+ required: true,
154
+ detail: malformed ? `OpenAPI document at ${url} was not valid JSON` : `Could not reach the Tenjin API at ${url}: ${res.message}`,
155
+ fix: malformed ? FIX_POINT_AT_TENJIN_API : FIX_CHECK_NETWORK_AND_BASE_URL
156
+ },
157
+ failCode: malformed ? "CONTRACT_MISMATCH" : "API_UNREACHABLE"
158
+ };
159
+ }
160
+ const version = infoVersion(res.json);
161
+ if (version === void 0) {
162
+ return {
163
+ result: {
164
+ name: "api-contract",
165
+ status: "fail",
166
+ required: true,
167
+ detail: `OpenAPI document at ${url} is missing a string info.version`,
168
+ fix: FIX_POINT_AT_TENJIN_API
169
+ },
170
+ failCode: "CONTRACT_MISMATCH"
171
+ };
172
+ }
173
+ return {
174
+ result: {
175
+ name: "api-contract",
176
+ status: "ok",
177
+ required: true,
178
+ detail: `Tenjin API ${version} at ${baseUrl}`
179
+ }
180
+ };
181
+ }
182
+ async function checkSearchContract(baseUrl, timeoutMs, fetchImpl) {
183
+ const url = `${trimSlash(baseUrl)}/openapi.json`;
184
+ const res = await fetchJson(url, { timeoutMs, fetchImpl });
185
+ if (!res.ok) {
186
+ return {
187
+ result: {
188
+ name: "search-contract",
189
+ status: "warn",
190
+ required: false,
191
+ detail: `Could not confirm the search endpoint at ${url}`,
192
+ fix: "Check the configured base URL (`tenjin config get baseUrl`); search/buy need the A2 endpoints deployed."
193
+ }
194
+ };
195
+ }
196
+ const present = hasSearchPath(res.json);
197
+ return {
198
+ result: present ? {
199
+ name: "search-contract",
200
+ status: "ok",
201
+ required: false,
202
+ detail: "Search endpoint advertised"
203
+ } : {
204
+ name: "search-contract",
205
+ status: "warn",
206
+ required: false,
207
+ detail: "This deployment does not advertise POST /api/agent/search (A2 not deployed)",
208
+ fix: "search/buy need A2 deployed; point the configured base URL at a deploy that has it (`tenjin config set baseUrl <url>`)."
209
+ }
210
+ };
211
+ }
212
+ function hasSearchPath(json) {
213
+ if (!isRecord(json)) return false;
214
+ const paths = json.paths;
215
+ return isRecord(paths) && "/api/agent/search" in paths;
216
+ }
217
+ async function checkSkills(home, which, requested, skillsSourceDir) {
218
+ const present = detectHarnesses(home, which);
219
+ const wiring = await readAllWiring(home);
220
+ const data = {
221
+ directories: wiring.map((w) => ({
222
+ ...w,
223
+ harnessPresent: harnessReads(home, w.dir, present),
224
+ requested: harnessRequested(home, w.dir, requested)
225
+ }))
226
+ };
227
+ const inPlay = wiring.filter((w) => anyTenjinSkill(w));
228
+ if (inPlay.length === 0) {
229
+ const targeted = requested.length > 0 ? wiring.filter((w) => harnessInPlay(home, w.dir, present, requested)) : [];
230
+ return {
231
+ result: {
232
+ name: "skills",
233
+ status: "warn",
234
+ required: false,
235
+ detail: `No Tenjin skills wired under ${home} (looked in .claude/skills and .agents/skills)`,
236
+ fix: targeted.length > 0 ? fixFor(home, targeted) : "tenjin install",
237
+ data
238
+ }
239
+ };
240
+ }
241
+ const broken = wiring.filter(
242
+ (w) => harnessInPlay(home, w.dir, present, requested) && !cliSkillsWired(w)
243
+ );
244
+ if (broken.length > 0) {
245
+ return {
246
+ result: {
247
+ name: "skills",
248
+ status: "warn",
249
+ required: false,
250
+ detail: `${broken.map(describeProblem).join("; ")}. Full state: ${describeWiring(inPlay)}`,
251
+ fix: fixFor(home, broken),
252
+ data
253
+ }
254
+ };
255
+ }
256
+ const { stale, verifiable } = await compareWiredSkills(
257
+ wiring.map((w) => w.dir),
258
+ skillsSourceDir
259
+ );
260
+ if (!verifiable) {
261
+ return {
262
+ result: {
263
+ name: "skills",
264
+ status: "warn",
265
+ required: false,
266
+ detail: `${CLI_SKILL_NAMES.join(" + ")} wired, but this build's packaged copies could not be read, so whether they are current is unknown`,
267
+ fix: "Reinstall the CLI: `npm i -g tenjin-cli`, then `tenjin install`.",
268
+ data
269
+ }
270
+ };
271
+ }
272
+ if (stale.length > 0) {
273
+ return {
274
+ result: {
275
+ name: "skills",
276
+ status: "warn",
277
+ required: false,
278
+ detail: `${CLI_SKILL_NAMES.join(" + ")} wired but not from this CLI build (${stale.join(", ")}); agents are reading an older version's instructions`,
279
+ // fixFor, like every neighbouring branch: a plain `tenjin install` targets
280
+ // DETECTED harnesses only, so for a directory that exists because someone
281
+ // passed --harness it would be a fix that never clears the warning.
282
+ fix: fixFor(
283
+ home,
284
+ wiring.filter((w) => stale.includes(w.dir))
285
+ ),
286
+ data
287
+ }
288
+ };
289
+ }
290
+ return {
291
+ result: {
292
+ name: "skills",
293
+ status: "ok",
294
+ required: false,
295
+ detail: `${CLI_SKILL_NAMES.join(" + ")} wired: ${describeWiring(inPlay)}`,
296
+ data
297
+ }
298
+ };
299
+ }
300
+ async function compareWiredSkills(dirs, sourceDir) {
301
+ let source;
302
+ try {
303
+ source = sourceDir ?? resolveSkillsSource(fileURLToPath(new URL(".", import.meta.url)));
304
+ } catch {
305
+ return { stale: [], verifiable: false };
306
+ }
307
+ const packaged = /* @__PURE__ */ new Map();
308
+ for (const name of CLI_SKILL_NAMES) {
309
+ const read = await readSkillFile(join(source, name, "SKILL.md"));
310
+ if (read.kind === "ok") packaged.set(name, read.bytes);
311
+ }
312
+ if (packaged.size !== CLI_SKILL_NAMES.length) return { stale: [], verifiable: false };
313
+ const stale = [];
314
+ for (const dir of dirs) {
315
+ for (const name of CLI_SKILL_NAMES) {
316
+ const onDisk = await readSkillFile(join(dir, name, "SKILL.md"));
317
+ if (onDisk.kind !== "ok") continue;
318
+ if (!packaged.get(name).equals(onDisk.bytes)) {
319
+ stale.push(dir);
320
+ break;
321
+ }
322
+ }
323
+ }
324
+ return { stale, verifiable: true };
325
+ }
326
+ function describeProblem(w) {
327
+ const shadowed = shadowedCliSkills(w);
328
+ const missing = missingCliSkills(w);
329
+ const parts = [];
330
+ const unreadable = shadowed.filter((n) => reasonFor(w, n) === "unreadable");
331
+ const disabled = shadowed.filter((n) => reasonFor(w, n) !== "unreadable");
332
+ if (disabled.length > 0) {
333
+ parts.push(
334
+ `${disabled.join(", ")} installed but not model-invocable (disable-model-invocation: true)`
335
+ );
336
+ }
337
+ if (unreadable.length > 0) {
338
+ parts.push(
339
+ `${unreadable.join(", ")} installed but not model-invocable (unreadable or disable-model-invocation: true)`
340
+ );
341
+ }
342
+ if (missing.length === CLI_SKILL_NAMES.length) {
343
+ parts.push(
344
+ w.state === "hosted-only" ? `the hosted ${HOSTED_SKILL_NAME} skill is here but neither CLI skill is wired` : "neither CLI skill is wired"
345
+ );
346
+ } else if (missing.length > 0) parts.push(`${missing.join(", ")} missing`);
347
+ return `${w.dir}: ${parts.join(" and ")}`;
348
+ }
349
+ function reasonFor(w, name) {
350
+ return w.skills.find((s) => s.name === name)?.reason;
351
+ }
352
+ function hostedHere(w) {
353
+ return w.skills.find((s) => s.name === HOSTED_SKILL_NAME)?.present === true;
354
+ }
355
+ function fixFor(home, dirs) {
356
+ const flags = [...new Set(dirs.map((w) => harnessFlagFor(home, w.dir)))];
357
+ return `tenjin install ${flags.map((f) => `--harness ${f}`).join(" ")}`;
358
+ }
359
+ function describeWiring(wiring) {
360
+ return wiring.map((w) => {
361
+ const parts = w.skills.filter((s) => s.present).map(
362
+ (s) => s.modelInvocable === false ? `${s.name} [${s.reason ?? "shadowed"}]` : s.name
363
+ );
364
+ return `${w.dir} -> ${parts.join(", ")} (${posture(w)})`;
365
+ }).join("; ");
366
+ }
367
+ function posture(w) {
368
+ if (w.state !== "wired") return POSTURE[w.state];
369
+ return hostedHere(w) ? "CLI skills wired, take precedence over the hosted mirror" : "CLI skills wired";
370
+ }
371
+ var POSTURE = {
372
+ empty: "no Tenjin skills",
373
+ "hosted-only": "hosted skill only, no CLI skills here",
374
+ partial: "only one CLI skill",
375
+ // "at least one": a directory with one CLI skill shadowed and the other absent
376
+ // classifies as `shadowed` too, and "CLI skills present" would be false there.
377
+ shadowed: "at least one CLI skill present but not model-invocable",
378
+ wired: "CLI skills wired, take precedence over the hosted mirror"
379
+ };
380
+ async function checkSession(dataDir, now, origin) {
381
+ const warn = (detail, data2) => ({
382
+ result: {
383
+ name: "session",
384
+ status: "warn",
385
+ required: false,
386
+ detail,
387
+ fix: "tenjin session start --scope read",
388
+ ...data2 !== void 0 ? { data: data2 } : {}
389
+ }
390
+ });
391
+ const state = await readSessionFile(dataDir);
392
+ if (state.kind === "absent") {
393
+ return {
394
+ result: {
395
+ name: "session",
396
+ status: "ok",
397
+ required: false,
398
+ detail: "No session key; `tenjin read` delivers free and locally-cached pieces (`tenjin session start --scope read` adds owned-piece recovery)"
399
+ }
400
+ };
401
+ }
402
+ if (state.kind === "loosened") {
403
+ return warn(
404
+ `Session key at ${sessionPath(dataDir)} is mode 0${state.mode.toString(8)}, not 0600, so it is refused; it holds a wallet-derived credential and was changed out of band. Delete it and re-mint`
405
+ );
406
+ }
407
+ if (state.kind === "outdated") {
408
+ return {
409
+ result: {
410
+ name: "session",
411
+ status: "ok",
412
+ required: false,
413
+ detail: `Cached session key at ${sessionPath(dataDir)} predates this CLI version (no \`${state.field}\`) and is not used; \`tenjin session start --scope read\` mints a current one`
414
+ }
415
+ };
416
+ }
417
+ if (state.kind === "corrupt") {
418
+ return warn(`Session key at ${sessionPath(dataDir)} could not be parsed (${state.reason})`);
419
+ }
420
+ if (state.kind === "unreadable") {
421
+ return warn(`Session key at ${sessionPath(dataDir)} could not be read: ${state.message}`);
422
+ }
423
+ const file = state.file;
424
+ if (origin === null) {
425
+ return {
426
+ result: {
427
+ name: "session",
428
+ status: "warn",
429
+ required: false,
430
+ detail: `Session key was minted for ${file.origin}, but the configured base URL is not an http(s) origin, so it cannot be matched`,
431
+ fix: "Set an absolute http(s) base URL: `tenjin config set baseUrl <url>`.",
432
+ data: { address: file.address, origin: file.origin, scope: file.scope, exp: file.exp }
433
+ }
434
+ };
435
+ }
436
+ const data = { address: file.address, origin: file.origin, scope: file.scope, exp: file.exp };
437
+ if (file.origin !== origin) {
438
+ return warn(
439
+ `Session key was minted for ${file.origin}, but the configured base URL is ${origin}; it is not presented off its own origin`,
440
+ data
441
+ );
442
+ }
443
+ if (!isSessionPresentable(file, now(), "read", origin)) {
444
+ return warn(
445
+ `Session key for ${file.address} is expired or out of scope (scope ${file.scope}, exp ${file.exp})`,
446
+ data
447
+ );
448
+ }
449
+ return {
450
+ result: {
451
+ name: "session",
452
+ status: "ok",
453
+ required: false,
454
+ detail: `Session key ${file.address}, scope ${file.scope}, for ${file.origin}, expires ${file.exp}`,
455
+ data
456
+ }
457
+ };
458
+ }
459
+ async function checkReadPath(baseUrl, timeoutMs, fetchImpl) {
460
+ const url = `${trimSlash(baseUrl)}/api/articles?limit=1`;
461
+ const res = await fetchJson(url, { timeoutMs, fetchImpl });
462
+ if (!res.ok) {
463
+ return {
464
+ result: {
465
+ name: "read-path",
466
+ status: "fail",
467
+ required: true,
468
+ detail: `Read path ${url} failed: ${res.message}`,
469
+ fix: FIX_CHECK_NETWORK_AND_BASE_URL
470
+ },
471
+ failCode: "API_UNREACHABLE"
472
+ };
473
+ }
474
+ const items = isRecord(res.json) ? res.json.items : void 0;
475
+ if (!Array.isArray(items)) {
476
+ return {
477
+ result: {
478
+ name: "read-path",
479
+ status: "fail",
480
+ required: true,
481
+ detail: `Read path ${url} did not return an items array`,
482
+ fix: "Point the configured base URL at a Tenjin API: `tenjin config set baseUrl <url>`."
483
+ },
484
+ failCode: "API_UNREACHABLE"
485
+ };
486
+ }
487
+ return {
488
+ result: { name: "read-path", status: "ok", required: true, detail: `Read path OK at ${url}` }
489
+ };
490
+ }
491
+ async function checkWallet(ctx, deps, env, rpcUrl) {
492
+ const provider = deps.provider ?? await resolveLocalProviderOrNull(ctx, env, deps);
493
+ if (provider === null) return [noWalletCheck()];
494
+ const { describeWallet } = await import("./wallet-YEGQBWWL.js");
495
+ let desc;
496
+ try {
497
+ desc = await describeWallet(provider);
498
+ } catch (err) {
499
+ if (err instanceof CliError && err.code === "WALLET_MISSING") return [noWalletCheck()];
500
+ return [walletWarn(err)];
501
+ }
502
+ const checks = [walletCheck(desc, await verifyWallet(provider))];
503
+ for (const warning of (await provider.diagnostics()).warnings) {
504
+ checks.push({ name: "wallet-custody", status: "warn", required: false, detail: warning });
505
+ }
506
+ checks.push(await checkBalance(desc.address, rpcUrl));
507
+ return checks;
508
+ }
509
+ async function resolveLocalProviderOrNull(ctx, env, deps) {
510
+ const envKey = env.TENJIN_WALLET_KEY;
511
+ const envKeySet = typeof envKey === "string" && envKey.length > 0;
512
+ if (!envKeySet && !await walletFileExists(ctx.dataDir)) return null;
513
+ const { resolveWalletProvider } = await import("./wallet-YEGQBWWL.js");
514
+ return resolveWalletProvider(ctx, {
515
+ ...deps.walletPassphrase !== void 0 ? { passphrase: deps.walletPassphrase } : {}
516
+ });
517
+ }
518
+ async function verifyWallet(provider) {
519
+ if (provider.verify === void 0) {
520
+ return {
521
+ status: "unverified",
522
+ detail: `provider "${provider.id}" cannot verify without a key`
523
+ };
524
+ }
525
+ try {
526
+ return await provider.verify();
527
+ } catch (err) {
528
+ return {
529
+ status: "unverified",
530
+ detail: `verification could not run (${err instanceof Error ? err.message : String(err)})`
531
+ };
532
+ }
533
+ }
534
+ function walletCheck(desc, v) {
535
+ const head = `Wallet ${desc.address} (${desc.credentialSource})`;
536
+ if (v.status === "broken") {
537
+ return {
538
+ name: "wallet",
539
+ status: "warn",
540
+ required: false,
541
+ detail: `${head}: ${v.detail}`,
542
+ fix: v.fix
543
+ };
544
+ }
545
+ if (v.status === "unverified") {
546
+ return {
547
+ name: "wallet",
548
+ status: "warn",
549
+ required: false,
550
+ detail: `${head} present, not verified: ${v.detail}`,
551
+ fix: "Set TENJIN_WALLET_PASSPHRASE, or store the passphrase in your OS credential store, so doctor can prove the keystore still opens."
552
+ };
553
+ }
554
+ return { name: "wallet", status: "ok", required: false, detail: `${head}, ${v.detail}` };
555
+ }
556
+ function noWalletCheck() {
557
+ return {
558
+ name: "wallet",
559
+ status: "warn",
560
+ required: false,
561
+ detail: "No wallet; needed only for buy/publish",
562
+ fix: "tenjin wallet create",
563
+ data: { credential: "absent" }
564
+ };
565
+ }
566
+ function isNoWalletCheck(c) {
567
+ return c.name === "wallet" && isRecord(c.data) && c.data.credential === "absent";
568
+ }
569
+ function walletWarn(err) {
570
+ return {
571
+ name: "wallet",
572
+ status: "warn",
573
+ required: false,
574
+ detail: err instanceof Error ? err.message : String(err),
575
+ ...err instanceof CliError && err.fix !== void 0 ? { fix: err.fix } : {}
576
+ };
577
+ }
578
+ async function checkBalance(address, rpcUrl) {
579
+ try {
580
+ const { getUsdcBalance } = await import("./usdc-4VCDHFWX.js");
581
+ const balance = await getUsdcBalance(address, rpcUrl);
582
+ if (balance === 0n) {
583
+ return {
584
+ name: "balance",
585
+ status: "warn",
586
+ required: false,
587
+ detail: "Wallet USDC balance is 0",
588
+ fix: "Send USDC on Base. $5 covers ~50 typical resources."
589
+ };
590
+ }
591
+ const money = toMoney(balance.toString());
592
+ if (balance > POCKET_MONEY_CEILING_ATOMIC) {
593
+ return {
594
+ name: "balance",
595
+ status: "warn",
596
+ required: false,
597
+ detail: `Balance ${money.usd} USDC is above the ~$20 pocket-money ceiling`,
598
+ fix: "Keep only small change in the CLI wallet; sweep the excess to cold storage."
599
+ };
600
+ }
601
+ return {
602
+ name: "balance",
603
+ status: "ok",
604
+ required: false,
605
+ detail: `Balance ${money.usd} USDC (${money.atomic} atomic)`
606
+ };
607
+ } catch (err) {
608
+ return {
609
+ name: "balance",
610
+ status: "warn",
611
+ required: false,
612
+ detail: `Could not read balance: ${err instanceof Error ? err.message : String(err)}`,
613
+ fix: "Check rpcUrl or retry; a balance read failure never fails doctor."
614
+ };
615
+ }
616
+ }
617
+ function renderDoctorHuman(io, checks) {
618
+ const nameWidth = Math.max(...checks.map((c) => c.name.length));
619
+ const lines = [];
620
+ for (const c of checks) {
621
+ const icon = c.status === "ok" ? paint(io, "green", "\u2713") : c.status === "warn" ? paint(io, "yellow", "!") : paint(io, "red", "\u2717");
622
+ lines.push(
623
+ `${icon} ${c.name.padEnd(nameWidth)} ${paint(io, "dim", sanitizeForTerminal(c.detail))}`
624
+ );
625
+ if (c.status !== "ok" && c.fix !== void 0) {
626
+ lines.push(` ${paint(io, "dim", `fix: ${sanitizeForTerminal(c.fix)}`)}`);
627
+ }
628
+ }
629
+ return lines;
630
+ }
631
+ function paint(io, format, text) {
632
+ if (io.stdout instanceof Stream) return styleText(format, text, { stream: io.stdout });
633
+ return styleText(format, text);
634
+ }
635
+ function infoVersion(json) {
636
+ if (!isRecord(json)) return void 0;
637
+ const info = json.info;
638
+ if (!isRecord(info)) return void 0;
639
+ return typeof info.version === "string" ? info.version : void 0;
640
+ }
641
+ function isRecord(value) {
642
+ return typeof value === "object" && value !== null;
643
+ }
644
+
645
+ export {
646
+ collectDoctorChecks,
647
+ runDoctor,
648
+ isNoWalletCheck,
649
+ renderDoctorHuman
650
+ };
651
+ //# sourceMappingURL=chunk-VRRLTZ2Q.js.map