tenjin-cli 0.1.0-alpha.4 → 0.1.0-alpha.5

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 (108) hide show
  1. package/README.md +168 -11
  2. package/dist/{buy-OOOLUDND.js → buy-YMXXVNFH.js} +18 -17
  3. package/dist/{candidate-TWCWTFGA.js → candidate-H7FR4AU5.js} +8 -8
  4. package/dist/{chunk-MUBUQVC3.js → chunk-2JQ5JSG6.js} +3 -2
  5. package/dist/{chunk-MUBUQVC3.js.map → chunk-2JQ5JSG6.js.map} +1 -1
  6. package/dist/{chunk-NXCJN2FJ.js → chunk-3IRDP7TN.js} +48 -41
  7. package/dist/chunk-3IRDP7TN.js.map +1 -0
  8. package/dist/{chunk-4GR7DGD6.js → chunk-4WVKXKDK.js} +14 -28
  9. package/dist/chunk-4WVKXKDK.js.map +1 -0
  10. package/dist/chunk-5SCU253N.js +412 -0
  11. package/dist/chunk-5SCU253N.js.map +1 -0
  12. package/dist/chunk-ADJYSM45.js +135 -0
  13. package/dist/chunk-ADJYSM45.js.map +1 -0
  14. package/dist/{chunk-5JH7ZB6Z.js → chunk-BIKAUVC2.js} +40 -8
  15. package/dist/chunk-BIKAUVC2.js.map +1 -0
  16. package/dist/{chunk-S3KZ3PPK.js → chunk-C444K6MI.js} +254 -47
  17. package/dist/chunk-C444K6MI.js.map +1 -0
  18. package/dist/{chunk-XNNOR7F7.js → chunk-CVX6JNGD.js} +3 -3
  19. package/dist/{chunk-H5ETJRQD.js → chunk-HTDALK7M.js} +16 -11
  20. package/dist/chunk-HTDALK7M.js.map +1 -0
  21. package/dist/chunk-IOPWPMT2.js +239 -0
  22. package/dist/chunk-IOPWPMT2.js.map +1 -0
  23. package/dist/{chunk-MM4TGTST.js → chunk-L4IHCN6B.js} +8 -4
  24. package/dist/chunk-L4IHCN6B.js.map +1 -0
  25. package/dist/{chunk-EUQN3L5X.js → chunk-LAM66WFJ.js} +20 -6
  26. package/dist/chunk-LAM66WFJ.js.map +1 -0
  27. package/dist/{chunk-FHB3VKZW.js → chunk-MDDGEGSW.js} +5 -3
  28. package/dist/chunk-MDDGEGSW.js.map +1 -0
  29. package/dist/{chunk-333FOTUJ.js → chunk-MJZZTKCC.js} +108 -2
  30. package/dist/chunk-MJZZTKCC.js.map +1 -0
  31. package/dist/{chunk-VV4P5RVK.js → chunk-NFSOVL3C.js} +6 -3
  32. package/dist/{chunk-VV4P5RVK.js.map → chunk-NFSOVL3C.js.map} +1 -1
  33. package/dist/{chunk-QH6677FJ.js → chunk-NJF2WENW.js} +2 -2
  34. package/dist/{chunk-QH6677FJ.js.map → chunk-NJF2WENW.js.map} +1 -1
  35. package/dist/{chunk-6WWVYYSB.js → chunk-PAUXMRSF.js} +14 -3
  36. package/dist/{chunk-6WWVYYSB.js.map → chunk-PAUXMRSF.js.map} +1 -1
  37. package/dist/{chunk-ULLWHHIT.js → chunk-PYNSGYBE.js} +244 -32
  38. package/dist/chunk-PYNSGYBE.js.map +1 -0
  39. package/dist/{chunk-DPET3TW5.js → chunk-QONTBYQW.js} +12 -9
  40. package/dist/chunk-QONTBYQW.js.map +1 -0
  41. package/dist/chunk-QW2Q2KAH.js +27 -0
  42. package/dist/chunk-QW2Q2KAH.js.map +1 -0
  43. package/dist/chunk-RTJLLPFA.js +599 -0
  44. package/dist/chunk-RTJLLPFA.js.map +1 -0
  45. package/dist/{chunk-KXIX7YDV.js → chunk-TXPPMK4L.js} +5 -5
  46. package/dist/{chunk-C4TIWOAM.js → chunk-ZDY2KY5X.js} +2 -2
  47. package/dist/{chunk-DPUMEMGM.js → chunk-ZIYVN4CD.js} +3 -3
  48. package/dist/{chunk-OJD54DIU.js → chunk-ZW3B5LWX.js} +5 -5
  49. package/dist/{cli-AFSLAKR6.js → cli-IW76QTN3.js} +38 -25
  50. package/dist/{cli-AFSLAKR6.js.map → cli-IW76QTN3.js.map} +1 -1
  51. package/dist/{config-DBEEM3UA.js → config-VCOS7P5K.js} +8 -6
  52. package/dist/{doctor-XDA3YU6H.js → doctor-WS65JG3V.js} +9 -8
  53. package/dist/index.js +1 -1
  54. package/dist/{inspect-YBGDAG47.js → inspect-SFJWUQHO.js} +14 -14
  55. package/dist/{install-7J6KKEEP.js → install-RVPQPCKH.js} +177 -130
  56. package/dist/install-RVPQPCKH.js.map +1 -0
  57. package/dist/outcome-GNYCSZ7J.js +20 -0
  58. package/dist/{publish-IH7RJXGB.js → publish-DSFWQRUN.js} +14 -14
  59. package/dist/{run-DCZFEW2C.js → run-OMPKA43G.js} +29 -28
  60. package/dist/{run-DCZFEW2C.js.map → run-OMPKA43G.js.map} +1 -1
  61. package/dist/search-KOI6Y7P6.js +24 -0
  62. package/dist/send-3G4C64HJ.js +222 -0
  63. package/dist/send-3G4C64HJ.js.map +1 -0
  64. package/dist/{usdc-AU6ZIKA6.js → usdc-4VCDHFWX.js} +20 -4
  65. package/dist/{wallet-HKG3GSTX.js → wallet-B7KJS2R5.js} +17 -7
  66. package/dist/{wallet-UWHSHWC6.js → wallet-PP22LAX7.js} +8 -8
  67. package/package.json +1 -1
  68. package/skills/tenjin/SKILL.md +32 -7
  69. package/skills/tenjin-publish/SKILL.md +97 -12
  70. package/skills/tenjin-search/SKILL.md +115 -12
  71. package/dist/chunk-333FOTUJ.js.map +0 -1
  72. package/dist/chunk-4GR7DGD6.js.map +0 -1
  73. package/dist/chunk-5JH7ZB6Z.js.map +0 -1
  74. package/dist/chunk-BXUS5UCT.js +0 -212
  75. package/dist/chunk-BXUS5UCT.js.map +0 -1
  76. package/dist/chunk-CJU555P5.js +0 -333
  77. package/dist/chunk-CJU555P5.js.map +0 -1
  78. package/dist/chunk-DPET3TW5.js.map +0 -1
  79. package/dist/chunk-EUQN3L5X.js.map +0 -1
  80. package/dist/chunk-FHB3VKZW.js.map +0 -1
  81. package/dist/chunk-H5ETJRQD.js.map +0 -1
  82. package/dist/chunk-MM4TGTST.js.map +0 -1
  83. package/dist/chunk-NXCJN2FJ.js.map +0 -1
  84. package/dist/chunk-R7BMDJZM.js +0 -167
  85. package/dist/chunk-R7BMDJZM.js.map +0 -1
  86. package/dist/chunk-S3KZ3PPK.js.map +0 -1
  87. package/dist/chunk-ULLWHHIT.js.map +0 -1
  88. package/dist/chunk-YFREUEUI.js +0 -78
  89. package/dist/chunk-YFREUEUI.js.map +0 -1
  90. package/dist/install-7J6KKEEP.js.map +0 -1
  91. package/dist/outcome-ZFGHX2XW.js +0 -20
  92. package/dist/search-R6NIQFXI.js +0 -24
  93. /package/dist/{buy-OOOLUDND.js.map → buy-YMXXVNFH.js.map} +0 -0
  94. /package/dist/{candidate-TWCWTFGA.js.map → candidate-H7FR4AU5.js.map} +0 -0
  95. /package/dist/{chunk-XNNOR7F7.js.map → chunk-CVX6JNGD.js.map} +0 -0
  96. /package/dist/{chunk-KXIX7YDV.js.map → chunk-TXPPMK4L.js.map} +0 -0
  97. /package/dist/{chunk-C4TIWOAM.js.map → chunk-ZDY2KY5X.js.map} +0 -0
  98. /package/dist/{chunk-DPUMEMGM.js.map → chunk-ZIYVN4CD.js.map} +0 -0
  99. /package/dist/{chunk-OJD54DIU.js.map → chunk-ZW3B5LWX.js.map} +0 -0
  100. /package/dist/{config-DBEEM3UA.js.map → config-VCOS7P5K.js.map} +0 -0
  101. /package/dist/{doctor-XDA3YU6H.js.map → doctor-WS65JG3V.js.map} +0 -0
  102. /package/dist/{inspect-YBGDAG47.js.map → inspect-SFJWUQHO.js.map} +0 -0
  103. /package/dist/{outcome-ZFGHX2XW.js.map → outcome-GNYCSZ7J.js.map} +0 -0
  104. /package/dist/{publish-IH7RJXGB.js.map → publish-DSFWQRUN.js.map} +0 -0
  105. /package/dist/{search-R6NIQFXI.js.map → search-KOI6Y7P6.js.map} +0 -0
  106. /package/dist/{usdc-AU6ZIKA6.js.map → usdc-4VCDHFWX.js.map} +0 -0
  107. /package/dist/{wallet-HKG3GSTX.js.map → wallet-B7KJS2R5.js.map} +0 -0
  108. /package/dist/{wallet-UWHSHWC6.js.map → wallet-PP22LAX7.js.map} +0 -0
@@ -0,0 +1,599 @@
1
+ import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ walletFileExists
4
+ } from "./chunk-QONTBYQW.js";
5
+ import {
6
+ CLIENT_HEADER,
7
+ fetchJson,
8
+ trimSlash
9
+ } from "./chunk-ZDY2KY5X.js";
10
+ import {
11
+ sanitizeForTerminal
12
+ } from "./chunk-NFSOVL3C.js";
13
+ import {
14
+ CLI_SKILL_NAMES,
15
+ HOSTED_SKILL_NAME,
16
+ anyTenjinSkill,
17
+ cliSkillsWired,
18
+ detectHarnesses,
19
+ harnessFlagFor,
20
+ harnessInPlay,
21
+ harnessReads,
22
+ harnessRequested,
23
+ loadRawConfig,
24
+ missingCliSkills,
25
+ onPath,
26
+ readAllWiring,
27
+ resolveSettings,
28
+ shadowedCliSkills,
29
+ toMoney
30
+ } from "./chunk-5SCU253N.js";
31
+ import {
32
+ CliError,
33
+ configPath
34
+ } from "./chunk-PAUXMRSF.js";
35
+
36
+ // src/commands/doctor.ts
37
+ import { styleText } from "util";
38
+ import { Stream } from "stream";
39
+ import { homedir } from "os";
40
+
41
+ // src/lib/permissions.ts
42
+ var ALWAYS_SAFE_ALLOWLIST = [
43
+ {
44
+ rule: "Bash(tenjin search:*)",
45
+ command: "tenjin search",
46
+ note: "Free anonymous marketplace search. No wallet, no signing, no payment. Not read-only: it POSTs the generalized question off-machine and records the search locally."
47
+ },
48
+ {
49
+ rule: "Bash(tenjin inspect:*)",
50
+ command: "tenjin inspect",
51
+ note: "Free pre-purchase card and preview. Never signs, never pays, never saves."
52
+ },
53
+ {
54
+ rule: "Bash(tenjin outcome:*)",
55
+ command: "tenjin outcome",
56
+ note: "Free honest outcome report on a past search. No wallet, no payment. Not read-only: it POSTs a report that moves the marketplace reuse signal."
57
+ },
58
+ {
59
+ rule: "Bash(tenjin doctor:*)",
60
+ command: "tenjin doctor",
61
+ note: "Read-only local environment and API reachability diagnostics."
62
+ },
63
+ {
64
+ rule: "Bash(tenjin wallet show:*)",
65
+ command: "tenjin wallet show",
66
+ note: "Prints the wallet address and key source. Never prints the key."
67
+ },
68
+ {
69
+ rule: "Bash(tenjin wallet balance:*)",
70
+ command: "tenjin wallet balance",
71
+ note: "Read-only USDC balance query on Base."
72
+ },
73
+ {
74
+ rule: "Bash(tenjin config get:*)",
75
+ command: "tenjin config get",
76
+ note: "Reads one effective config value. `config set` is excluded on purpose. Note `config get rpcUrl` returns your RPC URL, which commonly embeds a provider API key: no wallet secret, but a credential-adjacent read."
77
+ },
78
+ {
79
+ rule: "Bash(tenjin candidate list:*)",
80
+ command: "tenjin candidate list",
81
+ note: "Lists local parked drafts. Candidates are local files; nothing uploads."
82
+ }
83
+ ];
84
+ var OPT_IN_ALLOWLIST = [
85
+ {
86
+ rule: "Bash(tenjin buy:*)",
87
+ command: "tenjin buy",
88
+ note: "SPENDS USDC on Base, unrefundably. This authorizes UNATTENDED purchases: `--yes` is an ordinary flag on the same allowlisted verb and it clears the confirm gate, so on the default config nothing stops a spend up to your wallet balance. Set a real ceiling first with `tenjin config set maxAutoSpend <usd>` and `tenjin config set sessionBudget <usd>` (sessionBudget 0 means NO ceiling, not a zero one). This line never raises a spend cap by itself, but do not read that as a human being on every purchase. Fund small."
89
+ }
90
+ ];
91
+ var NEVER_ALLOWLISTED = [
92
+ {
93
+ command: "tenjin send",
94
+ reason: "Moves USDC out of the wallet to an arbitrary address (the escape hatch, #40). Irreversible and not bounded by the buy spend policy. Always a human decision."
95
+ },
96
+ {
97
+ command: "tenjin publish",
98
+ reason: "Puts your content on a public marketplace under your identity."
99
+ },
100
+ {
101
+ command: "tenjin wallet create",
102
+ reason: "Creates the payment credential; a stray run is a wallet you did not mean to have."
103
+ },
104
+ {
105
+ command: "tenjin config set",
106
+ reason: "Can raise maxAutoSpend / sessionBudget / confirm, i.e. widen the agent\u2019s own spend policy."
107
+ },
108
+ {
109
+ command: "tenjin candidate add / tenjin candidate drop",
110
+ reason: "Writes or discards local drafts; `candidate list` is the read-only half."
111
+ },
112
+ {
113
+ command: "tenjin install",
114
+ reason: "Writes into harness config and skills directories."
115
+ },
116
+ {
117
+ command: "tenjin mcp",
118
+ reason: "Long-running server that re-exposes every command core over stdio; clearing it would indirectly clear everything above."
119
+ }
120
+ ];
121
+ var FLAG_CAVEAT = [
122
+ "Caveat: a prefix rule pins the VERB, not the flags. Every line above also clears",
123
+ "`--base-url <url>` on that verb, which re-points where the question, the probe, and",
124
+ "(for buy) the signature and payment go. Allowlist these verbs only if you are content",
125
+ "for the agent to choose the destination host, and set the base URL in config instead of",
126
+ "letting it be an argument. The skills tell agents never to pass --base-url on an",
127
+ "allowlisted verb, but that is a convention, not an enforced boundary."
128
+ ];
129
+ var MCP_CAVEAT = [
130
+ "Running the local MCP server (`tenjin mcp`) instead? That is a different permission",
131
+ "surface: the harness gates TOOLS there, and these Bash rules do not apply. Leave",
132
+ "`mcp__tenjin__tenjin_publish` and `mcp__tenjin__tenjin_wallet` gated, and treat",
133
+ "`mcp__tenjin__tenjin_candidate` as gated for its add/drop actions. `tenjin_buy` is the",
134
+ "same opt-in decision as the buy line above."
135
+ ];
136
+ function recommendedPermissions() {
137
+ return {
138
+ alwaysSafe: ALWAYS_SAFE_ALLOWLIST.map((e) => ({ ...e })),
139
+ optIn: OPT_IN_ALLOWLIST.map((e) => ({ ...e })),
140
+ neverAllowlisted: NEVER_ALLOWLISTED.map((e) => ({ ...e })),
141
+ caveats: { flags: [...FLAG_CAVEAT], mcp: [...MCP_CAVEAT] }
142
+ };
143
+ }
144
+ function renderPermissionsBlock() {
145
+ const lines = [
146
+ "Auto-mode permission allowlist (add these once, then agents stop being denied):"
147
+ ];
148
+ for (const e of ALWAYS_SAFE_ALLOWLIST) lines.push(` ${e.rule}`);
149
+ lines.push(" Free: no wallet, no signing, no payment. Not all read-only, though:");
150
+ lines.push(" `search` and `outcome` POST to the marketplace (a question, a report).");
151
+ lines.push("");
152
+ lines.push(...FLAG_CAVEAT.map((l) => ` ${l}`));
153
+ lines.push("");
154
+ lines.push("Opt in separately, only if you want unattended purchases:");
155
+ for (const e of OPT_IN_ALLOWLIST) {
156
+ lines.push(` ${e.rule}`);
157
+ lines.push(` ${e.note}`);
158
+ }
159
+ lines.push("");
160
+ lines.push("Never recommended (each one is a human decision):");
161
+ for (const e of NEVER_ALLOWLISTED) lines.push(` ${e.command} - ${e.reason}`);
162
+ lines.push("");
163
+ lines.push(...MCP_CAVEAT.map((l) => ` ${l}`));
164
+ lines.push("");
165
+ lines.push(
166
+ 'Claude Code: add the lines to the "permissions.allow" array in .claude/settings.json.'
167
+ );
168
+ return lines;
169
+ }
170
+
171
+ // src/commands/doctor.ts
172
+ var POCKET_MONEY_CEILING_ATOMIC = 20000000n;
173
+ var FIX_POINT_AT_TENJIN_API = "Point the configured base URL at a Tenjin API (expected an OpenAPI document): `tenjin config set baseUrl <url>`.";
174
+ var FIX_CHECK_NETWORK_AND_BASE_URL = "Check your network connection and the configured base URL (`tenjin config get baseUrl`).";
175
+ async function collectDoctorChecks(ctx, deps = {}) {
176
+ const env = deps.env ?? process.env;
177
+ const { config, check: configCheck } = await loadConfigForDoctor(ctx.dataDir);
178
+ const settings = resolveSettings({ config, flags: { baseUrl: ctx.flags.baseUrl }, env });
179
+ const baseUrl = settings.baseUrl.value;
180
+ const built = [
181
+ checkNode(),
182
+ configCheck,
183
+ await checkApiContract(baseUrl, ctx.flags.timeout, deps.fetchImpl),
184
+ await checkReadPath(baseUrl, ctx.flags.timeout, deps.fetchImpl),
185
+ await checkSearchContract(baseUrl, ctx.flags.timeout, deps.fetchImpl),
186
+ await checkSkills(
187
+ deps.homeDir ?? homedir(),
188
+ deps.which ?? ((bin) => onPath(bin, env)),
189
+ config.install?.harness ?? []
190
+ )
191
+ ];
192
+ for (const result of await checkWallet(ctx, deps, env, settings.rpcUrl.value)) {
193
+ built.push({ result });
194
+ }
195
+ const checks = built.map((b) => b.result);
196
+ const firstFail = built.find((b) => b.result.required && b.result.status === "fail");
197
+ if (firstFail === void 0) return { checks };
198
+ return { checks, failure: { code: firstFail.failCode ?? "INTERNAL", result: firstFail.result } };
199
+ }
200
+ async function runDoctor(ctx, deps = {}) {
201
+ const { checks, failure } = await collectDoctorChecks(ctx, deps);
202
+ if (failure !== void 0) {
203
+ const r = failure.result;
204
+ throw new CliError(failure.code, r.detail, {
205
+ ...r.fix !== void 0 ? { fix: r.fix } : {},
206
+ details: { checks, permissions: recommendedPermissions() }
207
+ });
208
+ }
209
+ return {
210
+ data: { status: "pass", checks, permissions: recommendedPermissions() },
211
+ humanLines: [...renderDoctorHuman(ctx.io, checks), "", ...renderPermissionsBlock()]
212
+ };
213
+ }
214
+ function checkNode() {
215
+ const version = process.versions.node;
216
+ const major = Number.parseInt(version.split(".")[0] ?? "0", 10);
217
+ if (major >= 22) {
218
+ return { result: { name: "node", status: "ok", required: true, detail: `Node ${version}` } };
219
+ }
220
+ return {
221
+ result: {
222
+ name: "node",
223
+ status: "fail",
224
+ required: true,
225
+ detail: `Node ${version} is unsupported (need >= 22)`,
226
+ fix: "Install Node 22 or newer"
227
+ },
228
+ failCode: "NODE_UNSUPPORTED"
229
+ };
230
+ }
231
+ async function loadConfigForDoctor(dataDir) {
232
+ try {
233
+ const config = await loadRawConfig(dataDir);
234
+ const detail = Object.keys(config).length === 0 ? "No config file; using defaults" : `Config at ${configPath(dataDir)} is valid`;
235
+ return { config, check: { result: { name: "config", status: "ok", required: true, detail } } };
236
+ } catch (err) {
237
+ if (err instanceof CliError && err.code === "CONFIG_INVALID") {
238
+ return {
239
+ config: {},
240
+ check: {
241
+ result: {
242
+ name: "config",
243
+ status: "fail",
244
+ required: true,
245
+ detail: err.message,
246
+ ...err.fix !== void 0 ? { fix: err.fix } : {}
247
+ },
248
+ failCode: "CONFIG_INVALID"
249
+ }
250
+ };
251
+ }
252
+ throw err;
253
+ }
254
+ }
255
+ async function checkApiContract(baseUrl, timeoutMs, fetchImpl) {
256
+ const url = `${trimSlash(baseUrl)}/openapi.json`;
257
+ const res = await fetchJson(url, {
258
+ timeoutMs,
259
+ fetchImpl,
260
+ headers: { "x-tenjin-client": CLIENT_HEADER }
261
+ });
262
+ if (!res.ok) {
263
+ const malformed = res.kind === "invalid-json";
264
+ return {
265
+ result: {
266
+ name: "api-contract",
267
+ status: "fail",
268
+ required: true,
269
+ detail: malformed ? `OpenAPI document at ${url} was not valid JSON` : `Could not reach the Tenjin API at ${url}: ${res.message}`,
270
+ fix: malformed ? FIX_POINT_AT_TENJIN_API : FIX_CHECK_NETWORK_AND_BASE_URL
271
+ },
272
+ failCode: malformed ? "CONTRACT_MISMATCH" : "API_UNREACHABLE"
273
+ };
274
+ }
275
+ const version = infoVersion(res.json);
276
+ if (version === void 0) {
277
+ return {
278
+ result: {
279
+ name: "api-contract",
280
+ status: "fail",
281
+ required: true,
282
+ detail: `OpenAPI document at ${url} is missing a string info.version`,
283
+ fix: FIX_POINT_AT_TENJIN_API
284
+ },
285
+ failCode: "CONTRACT_MISMATCH"
286
+ };
287
+ }
288
+ return {
289
+ result: {
290
+ name: "api-contract",
291
+ status: "ok",
292
+ required: true,
293
+ detail: `Tenjin API ${version} at ${baseUrl}`
294
+ }
295
+ };
296
+ }
297
+ async function checkSearchContract(baseUrl, timeoutMs, fetchImpl) {
298
+ const url = `${trimSlash(baseUrl)}/openapi.json`;
299
+ const res = await fetchJson(url, {
300
+ timeoutMs,
301
+ fetchImpl,
302
+ headers: { "x-tenjin-client": CLIENT_HEADER }
303
+ });
304
+ if (!res.ok) {
305
+ return {
306
+ result: {
307
+ name: "search-contract",
308
+ status: "warn",
309
+ required: false,
310
+ detail: `Could not confirm the search endpoint at ${url}`,
311
+ fix: "Check the configured base URL (`tenjin config get baseUrl`); search/buy need the A2 endpoints deployed."
312
+ }
313
+ };
314
+ }
315
+ const present = hasSearchPath(res.json);
316
+ return {
317
+ result: present ? {
318
+ name: "search-contract",
319
+ status: "ok",
320
+ required: false,
321
+ detail: "Search endpoint advertised"
322
+ } : {
323
+ name: "search-contract",
324
+ status: "warn",
325
+ required: false,
326
+ detail: "This deployment does not advertise POST /api/agent/search (A2 not deployed)",
327
+ fix: "search/buy need A2 deployed; point the configured base URL at a deploy that has it (`tenjin config set baseUrl <url>`)."
328
+ }
329
+ };
330
+ }
331
+ function hasSearchPath(json) {
332
+ if (!isRecord(json)) return false;
333
+ const paths = json.paths;
334
+ return isRecord(paths) && "/api/agent/search" in paths;
335
+ }
336
+ async function checkSkills(home, which, requested) {
337
+ const present = detectHarnesses(home, which);
338
+ const wiring = await readAllWiring(home);
339
+ const data = {
340
+ directories: wiring.map((w) => ({
341
+ ...w,
342
+ harnessPresent: harnessReads(home, w.dir, present),
343
+ requested: harnessRequested(home, w.dir, requested)
344
+ }))
345
+ };
346
+ const inPlay = wiring.filter((w) => anyTenjinSkill(w));
347
+ if (inPlay.length === 0) {
348
+ const targeted = requested.length > 0 ? wiring.filter((w) => harnessInPlay(home, w.dir, present, requested)) : [];
349
+ return {
350
+ result: {
351
+ name: "skills",
352
+ status: "warn",
353
+ required: false,
354
+ detail: `No Tenjin skills wired under ${home} (looked in .claude/skills and .agents/skills)`,
355
+ fix: targeted.length > 0 ? fixFor(home, targeted) : "tenjin install",
356
+ data
357
+ }
358
+ };
359
+ }
360
+ const broken = wiring.filter(
361
+ (w) => harnessInPlay(home, w.dir, present, requested) && !cliSkillsWired(w)
362
+ );
363
+ if (broken.length > 0) {
364
+ return {
365
+ result: {
366
+ name: "skills",
367
+ status: "warn",
368
+ required: false,
369
+ detail: `${broken.map(describeProblem).join("; ")}. Full state: ${describeWiring(inPlay)}`,
370
+ fix: fixFor(home, broken),
371
+ data
372
+ }
373
+ };
374
+ }
375
+ return {
376
+ result: {
377
+ name: "skills",
378
+ status: "ok",
379
+ required: false,
380
+ detail: `${CLI_SKILL_NAMES.join(" + ")} wired: ${describeWiring(inPlay)}`,
381
+ data
382
+ }
383
+ };
384
+ }
385
+ function describeProblem(w) {
386
+ const shadowed = shadowedCliSkills(w);
387
+ const missing = missingCliSkills(w);
388
+ const parts = [];
389
+ const unreadable = shadowed.filter((n) => reasonFor(w, n) === "unreadable");
390
+ const disabled = shadowed.filter((n) => reasonFor(w, n) !== "unreadable");
391
+ if (disabled.length > 0) {
392
+ parts.push(
393
+ `${disabled.join(", ")} installed but not model-invocable (disable-model-invocation: true)`
394
+ );
395
+ }
396
+ if (unreadable.length > 0) {
397
+ parts.push(
398
+ `${unreadable.join(", ")} installed but not model-invocable (unreadable or disable-model-invocation: true)`
399
+ );
400
+ }
401
+ if (missing.length === CLI_SKILL_NAMES.length) {
402
+ parts.push(
403
+ w.state === "hosted-only" ? `the hosted ${HOSTED_SKILL_NAME} skill is here but neither CLI skill is wired` : "neither CLI skill is wired"
404
+ );
405
+ } else if (missing.length > 0) parts.push(`${missing.join(", ")} missing`);
406
+ return `${w.dir}: ${parts.join(" and ")}`;
407
+ }
408
+ function reasonFor(w, name) {
409
+ return w.skills.find((s) => s.name === name)?.reason;
410
+ }
411
+ function hostedHere(w) {
412
+ return w.skills.find((s) => s.name === HOSTED_SKILL_NAME)?.present === true;
413
+ }
414
+ function fixFor(home, dirs) {
415
+ const flags = [...new Set(dirs.map((w) => harnessFlagFor(home, w.dir)))];
416
+ return `tenjin install ${flags.map((f) => `--harness ${f}`).join(" ")}`;
417
+ }
418
+ function describeWiring(wiring) {
419
+ return wiring.map((w) => {
420
+ const parts = w.skills.filter((s) => s.present).map(
421
+ (s) => s.modelInvocable === false ? `${s.name} [${s.reason ?? "shadowed"}]` : s.name
422
+ );
423
+ return `${w.dir} -> ${parts.join(", ")} (${posture(w)})`;
424
+ }).join("; ");
425
+ }
426
+ function posture(w) {
427
+ if (w.state !== "wired") return POSTURE[w.state];
428
+ return hostedHere(w) ? "CLI skills wired, take precedence over the hosted mirror" : "CLI skills wired";
429
+ }
430
+ var POSTURE = {
431
+ empty: "no Tenjin skills",
432
+ "hosted-only": "hosted skill only, no CLI skills here",
433
+ partial: "only one CLI skill",
434
+ // "at least one": a directory with one CLI skill shadowed and the other absent
435
+ // classifies as `shadowed` too, and "CLI skills present" would be false there.
436
+ shadowed: "at least one CLI skill present but not model-invocable",
437
+ wired: "CLI skills wired, take precedence over the hosted mirror"
438
+ };
439
+ async function checkReadPath(baseUrl, timeoutMs, fetchImpl) {
440
+ const url = `${trimSlash(baseUrl)}/api/articles?limit=1`;
441
+ const res = await fetchJson(url, {
442
+ timeoutMs,
443
+ fetchImpl,
444
+ headers: { "x-tenjin-client": CLIENT_HEADER }
445
+ });
446
+ if (!res.ok) {
447
+ return {
448
+ result: {
449
+ name: "read-path",
450
+ status: "fail",
451
+ required: true,
452
+ detail: `Read path ${url} failed: ${res.message}`,
453
+ fix: FIX_CHECK_NETWORK_AND_BASE_URL
454
+ },
455
+ failCode: "API_UNREACHABLE"
456
+ };
457
+ }
458
+ const items = isRecord(res.json) ? res.json.items : void 0;
459
+ if (!Array.isArray(items)) {
460
+ return {
461
+ result: {
462
+ name: "read-path",
463
+ status: "fail",
464
+ required: true,
465
+ detail: `Read path ${url} did not return an items array`,
466
+ fix: "Point the configured base URL at a Tenjin API: `tenjin config set baseUrl <url>`."
467
+ },
468
+ failCode: "API_UNREACHABLE"
469
+ };
470
+ }
471
+ return {
472
+ result: { name: "read-path", status: "ok", required: true, detail: `Read path OK at ${url}` }
473
+ };
474
+ }
475
+ async function checkWallet(ctx, deps, env, rpcUrl) {
476
+ const provider = deps.provider ?? await resolveLocalProviderOrNull(ctx, env);
477
+ if (provider === null) return [noWalletCheck()];
478
+ const { describeWallet } = await import("./wallet-B7KJS2R5.js");
479
+ let desc;
480
+ try {
481
+ desc = await describeWallet(provider);
482
+ } catch (err) {
483
+ if (err instanceof CliError && err.code === "WALLET_MISSING") return [noWalletCheck()];
484
+ return [walletWarn(err)];
485
+ }
486
+ const checks = [
487
+ {
488
+ name: "wallet",
489
+ status: "ok",
490
+ required: false,
491
+ detail: `Wallet ${desc.address} (${desc.credentialSource})`
492
+ }
493
+ ];
494
+ for (const warning of (await provider.diagnostics()).warnings) {
495
+ checks.push({ name: "wallet-custody", status: "warn", required: false, detail: warning });
496
+ }
497
+ checks.push(await checkBalance(desc.address, rpcUrl));
498
+ return checks;
499
+ }
500
+ async function resolveLocalProviderOrNull(ctx, env) {
501
+ const envKey = env.TENJIN_WALLET_KEY;
502
+ const envKeySet = typeof envKey === "string" && envKey.length > 0;
503
+ if (!envKeySet && !await walletFileExists(ctx.dataDir)) return null;
504
+ const { resolveWalletProvider } = await import("./wallet-B7KJS2R5.js");
505
+ return resolveWalletProvider(ctx);
506
+ }
507
+ function noWalletCheck() {
508
+ return {
509
+ name: "wallet",
510
+ status: "warn",
511
+ required: false,
512
+ detail: "No wallet; needed only for buy/publish",
513
+ fix: "tenjin wallet create"
514
+ };
515
+ }
516
+ function walletWarn(err) {
517
+ return {
518
+ name: "wallet",
519
+ status: "warn",
520
+ required: false,
521
+ detail: err instanceof Error ? err.message : String(err),
522
+ ...err instanceof CliError && err.fix !== void 0 ? { fix: err.fix } : {}
523
+ };
524
+ }
525
+ async function checkBalance(address, rpcUrl) {
526
+ try {
527
+ const { getUsdcBalance } = await import("./usdc-4VCDHFWX.js");
528
+ const balance = await getUsdcBalance(address, rpcUrl);
529
+ if (balance === 0n) {
530
+ return {
531
+ name: "balance",
532
+ status: "warn",
533
+ required: false,
534
+ detail: "Wallet USDC balance is 0",
535
+ fix: "Send USDC on Base. $5 covers ~50 typical resources."
536
+ };
537
+ }
538
+ const money = toMoney(balance.toString());
539
+ if (balance > POCKET_MONEY_CEILING_ATOMIC) {
540
+ return {
541
+ name: "balance",
542
+ status: "warn",
543
+ required: false,
544
+ detail: `Balance ${money.usd} USDC is above the ~$20 pocket-money ceiling`,
545
+ fix: "Keep only small change in the CLI wallet; sweep the excess to cold storage."
546
+ };
547
+ }
548
+ return {
549
+ name: "balance",
550
+ status: "ok",
551
+ required: false,
552
+ detail: `Balance ${money.usd} USDC (${money.atomic} atomic)`
553
+ };
554
+ } catch (err) {
555
+ return {
556
+ name: "balance",
557
+ status: "warn",
558
+ required: false,
559
+ detail: `Could not read balance: ${err instanceof Error ? err.message : String(err)}`,
560
+ fix: "Check rpcUrl or retry; a balance read failure never fails doctor."
561
+ };
562
+ }
563
+ }
564
+ function renderDoctorHuman(io, checks) {
565
+ const nameWidth = Math.max(...checks.map((c) => c.name.length));
566
+ const lines = [];
567
+ for (const c of checks) {
568
+ const icon = c.status === "ok" ? paint(io, "green", "\u2713") : c.status === "warn" ? paint(io, "yellow", "!") : paint(io, "red", "\u2717");
569
+ lines.push(
570
+ `${icon} ${c.name.padEnd(nameWidth)} ${paint(io, "dim", sanitizeForTerminal(c.detail))}`
571
+ );
572
+ if (c.status !== "ok" && c.fix !== void 0) {
573
+ lines.push(` ${paint(io, "dim", `fix: ${sanitizeForTerminal(c.fix)}`)}`);
574
+ }
575
+ }
576
+ return lines;
577
+ }
578
+ function paint(io, format, text) {
579
+ if (io.stdout instanceof Stream) return styleText(format, text, { stream: io.stdout });
580
+ return styleText(format, text);
581
+ }
582
+ function infoVersion(json) {
583
+ if (!isRecord(json)) return void 0;
584
+ const info = json.info;
585
+ if (!isRecord(info)) return void 0;
586
+ return typeof info.version === "string" ? info.version : void 0;
587
+ }
588
+ function isRecord(value) {
589
+ return typeof value === "object" && value !== null;
590
+ }
591
+
592
+ export {
593
+ recommendedPermissions,
594
+ renderPermissionsBlock,
595
+ collectDoctorChecks,
596
+ runDoctor,
597
+ renderDoctorHuman
598
+ };
599
+ //# sourceMappingURL=chunk-RTJLLPFA.js.map