tenjin-cli 0.1.0-alpha.29 → 0.1.0-alpha.30

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 (110) hide show
  1. package/README.md +7 -5
  2. package/dist/{chunk-25GGN553.js → chunk-3O2BQIF6.js} +86 -22
  3. package/dist/chunk-3O2BQIF6.js.map +1 -0
  4. package/dist/{chunk-R4AO7GC2.js → chunk-5LJCEMFD.js} +14 -12
  5. package/dist/{chunk-R4AO7GC2.js.map → chunk-5LJCEMFD.js.map} +1 -1
  6. package/dist/{chunk-QTGUDCIR.js → chunk-AEG2PXBP.js} +3 -3
  7. package/dist/{chunk-AMEUXNJT.js → chunk-AWFUPKTM.js} +2 -2
  8. package/dist/{chunk-XJQ6CH7X.js → chunk-EBVIKMCH.js} +2 -2
  9. package/dist/{chunk-XDYKZRLN.js → chunk-HE2MS4QO.js} +6 -6
  10. package/dist/{chunk-RJEPZMYY.js → chunk-IOODYAXL.js} +3 -3
  11. package/dist/{chunk-SBL4THYT.js → chunk-JMM6YE7J.js} +190 -90
  12. package/dist/chunk-JMM6YE7J.js.map +1 -0
  13. package/dist/{chunk-VKQXVCZR.js → chunk-KHE6L6TD.js} +3 -3
  14. package/dist/chunk-KOGZDMHO.js +21 -0
  15. package/dist/chunk-KOGZDMHO.js.map +1 -0
  16. package/dist/{chunk-TROZ6HL4.js → chunk-KYFZTGMC.js} +2 -2
  17. package/dist/{chunk-LX5OT4TQ.js → chunk-NZIP4PA2.js} +2 -2
  18. package/dist/chunk-O2FRQ2L2.js +168 -0
  19. package/dist/chunk-O2FRQ2L2.js.map +1 -0
  20. package/dist/{chunk-3FY5HG7R.js → chunk-OK2TDZQU.js} +4 -4
  21. package/dist/{chunk-ZQNGTLOC.js → chunk-OSYTBCUC.js} +7 -5
  22. package/dist/{chunk-ZQNGTLOC.js.map → chunk-OSYTBCUC.js.map} +1 -1
  23. package/dist/{chunk-MRUPDSUM.js → chunk-PAYV4XUA.js} +3 -5
  24. package/dist/chunk-PAYV4XUA.js.map +1 -0
  25. package/dist/{chunk-USOLCBKC.js → chunk-QUVVWYJW.js} +7 -5
  26. package/dist/{chunk-USOLCBKC.js.map → chunk-QUVVWYJW.js.map} +1 -1
  27. package/dist/{chunk-MOG7PB3A.js → chunk-RAULEAZ6.js} +3 -3
  28. package/dist/{chunk-MG3G644T.js → chunk-SPAVAYSW.js} +3 -3
  29. package/dist/{chunk-4FYMDRD3.js → chunk-TTBKWWTV.js} +22 -20
  30. package/dist/chunk-TTBKWWTV.js.map +1 -0
  31. package/dist/{chunk-OOSRB3OF.js → chunk-U6YQ6FRI.js} +2 -2
  32. package/dist/{chunk-P4LVLFO4.js → chunk-VFMQTSXG.js} +2 -2
  33. package/dist/{chunk-LRCJ2IZ5.js → chunk-VUFAK2LW.js} +2 -2
  34. package/dist/{chunk-LRCJ2IZ5.js.map → chunk-VUFAK2LW.js.map} +1 -1
  35. package/dist/{chunk-WM7TJEBP.js → chunk-VZGAONSJ.js} +7 -5
  36. package/dist/{chunk-WM7TJEBP.js.map → chunk-VZGAONSJ.js.map} +1 -1
  37. package/dist/{chunk-VVAHFCX2.js → chunk-WO5BJNIB.js} +45 -194
  38. package/dist/chunk-WO5BJNIB.js.map +1 -0
  39. package/dist/chunk-WVUSXNIE.js +39 -0
  40. package/dist/chunk-WVUSXNIE.js.map +1 -0
  41. package/dist/chunk-XKESD27X.js +10 -0
  42. package/dist/chunk-XKESD27X.js.map +1 -0
  43. package/dist/{chunk-SFEQGENI.js → chunk-YFQOA5AU.js} +7 -2
  44. package/dist/{chunk-SFEQGENI.js.map → chunk-YFQOA5AU.js.map} +1 -1
  45. package/dist/{cli-JPTDHGRX.js → cli-O5SN7ZJ4.js} +38 -30
  46. package/dist/{cli-JPTDHGRX.js.map → cli-O5SN7ZJ4.js.map} +1 -1
  47. package/dist/{config-YYKDH2TH.js → config-OJQI27LT.js} +13 -12
  48. package/dist/{doctor-SSTXGCHX.js → doctor-IQQJHGGM.js} +36 -62
  49. package/dist/doctor-IQQJHGGM.js.map +1 -0
  50. package/dist/{fund-QWVWRVDK.js → fund-WEV6DMTD.js} +17 -12
  51. package/dist/{fund-QWVWRVDK.js.map → fund-WEV6DMTD.js.map} +1 -1
  52. package/dist/hook-command-D2P3ILRV.js +32 -0
  53. package/dist/hosts/claude/.claude-plugin/marketplace.json +2 -2
  54. package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +2 -2
  55. package/dist/index.js +4 -4
  56. package/dist/{install-2GXXD4DK.js → install-TUCRF32I.js} +23 -14
  57. package/dist/{install-identity-FK3YF227.js → install-identity-WHPNMNMQ.js} +7 -6
  58. package/dist/{install-wallet-TC22U52X.js → install-wallet-MA27FTQ5.js} +11 -10
  59. package/dist/{install-wallet-TC22U52X.js.map → install-wallet-MA27FTQ5.js.map} +1 -1
  60. package/dist/{mcp-42H2F4NY.js → mcp-QML7ZMPH.js} +33 -40
  61. package/dist/mcp-QML7ZMPH.js.map +1 -0
  62. package/dist/{package-6DJA3Y2O.js → package-LGKYOEPV.js} +2 -2
  63. package/dist/{pay-LSDJBIAZ.js → pay-2C2UBBXJ.js} +14 -13
  64. package/dist/{payments-SPECLBRQ.js → payments-C44QUFXU.js} +10 -9
  65. package/dist/{payments-SPECLBRQ.js.map → payments-C44QUFXU.js.map} +1 -1
  66. package/dist/{send-MHAOLPK3.js → send-KVJX4XIR.js} +9 -8
  67. package/dist/{send-MHAOLPK3.js.map → send-KVJX4XIR.js.map} +1 -1
  68. package/dist/{status-O2RWLPS5.js → status-S7C3WMSH.js} +10 -9
  69. package/dist/{status-O2RWLPS5.js.map → status-S7C3WMSH.js.map} +1 -1
  70. package/dist/{status-line-45TVCRM3.js → status-line-YR2T5HC4.js} +6 -5
  71. package/dist/{status-line-45TVCRM3.js.map → status-line-YR2T5HC4.js.map} +1 -1
  72. package/dist/{uninstall-VOK2Z5M4.js → uninstall-HY6LKIIT.js} +17 -14
  73. package/dist/{uninstall-VOK2Z5M4.js.map → uninstall-HY6LKIIT.js.map} +1 -1
  74. package/dist/{update-FGP3HNLD.js → update-OJV22LR3.js} +17 -14
  75. package/dist/usdc-JK4RRFFQ.js +39 -0
  76. package/dist/{wallet-DA7OFNEW.js → wallet-PD2IMZDU.js} +11 -10
  77. package/dist/wallet-PD2IMZDU.js.map +1 -0
  78. package/docs/agent-permissions.md +16 -4
  79. package/package.json +1 -1
  80. package/dist/chunk-25GGN553.js.map +0 -1
  81. package/dist/chunk-4FYMDRD3.js.map +0 -1
  82. package/dist/chunk-EWLU46J6.js +0 -100
  83. package/dist/chunk-EWLU46J6.js.map +0 -1
  84. package/dist/chunk-MRUPDSUM.js.map +0 -1
  85. package/dist/chunk-SBL4THYT.js.map +0 -1
  86. package/dist/chunk-VVAHFCX2.js.map +0 -1
  87. package/dist/doctor-SSTXGCHX.js.map +0 -1
  88. package/dist/hook-command-VWJXRT7H.js +0 -31
  89. package/dist/mcp-42H2F4NY.js.map +0 -1
  90. /package/dist/{chunk-QTGUDCIR.js.map → chunk-AEG2PXBP.js.map} +0 -0
  91. /package/dist/{chunk-AMEUXNJT.js.map → chunk-AWFUPKTM.js.map} +0 -0
  92. /package/dist/{chunk-XJQ6CH7X.js.map → chunk-EBVIKMCH.js.map} +0 -0
  93. /package/dist/{chunk-XDYKZRLN.js.map → chunk-HE2MS4QO.js.map} +0 -0
  94. /package/dist/{chunk-RJEPZMYY.js.map → chunk-IOODYAXL.js.map} +0 -0
  95. /package/dist/{chunk-VKQXVCZR.js.map → chunk-KHE6L6TD.js.map} +0 -0
  96. /package/dist/{chunk-TROZ6HL4.js.map → chunk-KYFZTGMC.js.map} +0 -0
  97. /package/dist/{chunk-LX5OT4TQ.js.map → chunk-NZIP4PA2.js.map} +0 -0
  98. /package/dist/{chunk-3FY5HG7R.js.map → chunk-OK2TDZQU.js.map} +0 -0
  99. /package/dist/{chunk-MOG7PB3A.js.map → chunk-RAULEAZ6.js.map} +0 -0
  100. /package/dist/{chunk-MG3G644T.js.map → chunk-SPAVAYSW.js.map} +0 -0
  101. /package/dist/{chunk-OOSRB3OF.js.map → chunk-U6YQ6FRI.js.map} +0 -0
  102. /package/dist/{chunk-P4LVLFO4.js.map → chunk-VFMQTSXG.js.map} +0 -0
  103. /package/dist/{config-YYKDH2TH.js.map → config-OJQI27LT.js.map} +0 -0
  104. /package/dist/{hook-command-VWJXRT7H.js.map → hook-command-D2P3ILRV.js.map} +0 -0
  105. /package/dist/{install-2GXXD4DK.js.map → install-TUCRF32I.js.map} +0 -0
  106. /package/dist/{install-identity-FK3YF227.js.map → install-identity-WHPNMNMQ.js.map} +0 -0
  107. /package/dist/{package-6DJA3Y2O.js.map → package-LGKYOEPV.js.map} +0 -0
  108. /package/dist/{pay-LSDJBIAZ.js.map → pay-2C2UBBXJ.js.map} +0 -0
  109. /package/dist/{update-FGP3HNLD.js.map → update-OJV22LR3.js.map} +0 -0
  110. /package/dist/{wallet-DA7OFNEW.js.map → usdc-JK4RRFFQ.js.map} +0 -0
@@ -5,7 +5,7 @@ import {
5
5
  emptyLedger,
6
6
  readLedger,
7
7
  spentOf
8
- } from "./chunk-LX5OT4TQ.js";
8
+ } from "./chunk-NZIP4PA2.js";
9
9
  import {
10
10
  withFileLock
11
11
  } from "./chunk-MEFB5KHA.js";
@@ -14,7 +14,7 @@ import {
14
14
  } from "./chunk-2SNUOHAT.js";
15
15
  import {
16
16
  writeFileAtomic
17
- } from "./chunk-VVAHFCX2.js";
17
+ } from "./chunk-O2FRQ2L2.js";
18
18
  import {
19
19
  spendLedgerPath
20
20
  } from "./chunk-SJLTEINJ.js";
@@ -189,4 +189,4 @@ export {
189
189
  createLocalSpendAuthorizer,
190
190
  releaseUnchargedExposure
191
191
  };
192
- //# sourceMappingURL=chunk-QTGUDCIR.js.map
192
+ //# sourceMappingURL=chunk-AEG2PXBP.js.map
@@ -10,7 +10,7 @@ import {
10
10
  loadRawConfig,
11
11
  parseUsdToAtomic,
12
12
  resolveSettings
13
- } from "./chunk-VVAHFCX2.js";
13
+ } from "./chunk-WO5BJNIB.js";
14
14
 
15
15
  // src/lib/settings.ts
16
16
  import { execFile } from "node:child_process";
@@ -235,4 +235,4 @@ export {
235
235
  ownedCandidates,
236
236
  projectRoot
237
237
  };
238
- //# sourceMappingURL=chunk-AMEUXNJT.js.map
238
+ //# sourceMappingURL=chunk-AWFUPKTM.js.map
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
2
  import {
3
3
  CliError
4
- } from "./chunk-VVAHFCX2.js";
4
+ } from "./chunk-WO5BJNIB.js";
5
5
 
6
6
  // src/lib/destination.ts
7
7
  import { lookup } from "node:dns/promises";
@@ -105,4 +105,4 @@ export {
105
105
  assertPublicDestination,
106
106
  resolvePublicDestination
107
107
  };
108
- //# sourceMappingURL=chunk-XJQ6CH7X.js.map
108
+ //# sourceMappingURL=chunk-EBVIKMCH.js.map
@@ -4,10 +4,10 @@ import {
4
4
  } from "./chunk-ORWL5BSN.js";
5
5
  import {
6
6
  getUsdcBalance
7
- } from "./chunk-SFEQGENI.js";
7
+ } from "./chunk-YFQOA5AU.js";
8
8
  import {
9
9
  channelCredit
10
- } from "./chunk-P4LVLFO4.js";
10
+ } from "./chunk-VFMQTSXG.js";
11
11
  import {
12
12
  commitLocalWallet,
13
13
  createLocalWallet,
@@ -20,10 +20,10 @@ import {
20
20
  verifyAndPreserveOutgoingWallet,
21
21
  walletExistsError,
22
22
  walletFileExists
23
- } from "./chunk-ZQNGTLOC.js";
23
+ } from "./chunk-OSYTBCUC.js";
24
24
  import {
25
25
  SUGGESTED_FUND_USD
26
- } from "./chunk-MRUPDSUM.js";
26
+ } from "./chunk-PAYV4XUA.js";
27
27
  import {
28
28
  LockTimeoutError,
29
29
  withFileLock
@@ -33,7 +33,7 @@ import {
33
33
  loadRawConfig,
34
34
  resolveSettings,
35
35
  toMoney
36
- } from "./chunk-VVAHFCX2.js";
36
+ } from "./chunk-WO5BJNIB.js";
37
37
  import {
38
38
  walletPath
39
39
  } from "./chunk-SJLTEINJ.js";
@@ -253,4 +253,4 @@ export {
253
253
  runWalletShow,
254
254
  runWalletBalance
255
255
  };
256
- //# sourceMappingURL=chunk-XDYKZRLN.js.map
256
+ //# sourceMappingURL=chunk-HE2MS4QO.js.map
@@ -2,10 +2,10 @@ import { createRequire as __tenjinCreateRequire } from 'node:module'; const requ
2
2
  import {
3
3
  CliError,
4
4
  PRODUCTION_ORIGIN
5
- } from "./chunk-VVAHFCX2.js";
5
+ } from "./chunk-WO5BJNIB.js";
6
6
  import {
7
7
  package_default
8
- } from "./chunk-LRCJ2IZ5.js";
8
+ } from "./chunk-VUFAK2LW.js";
9
9
 
10
10
  // src/lib/client-meta.ts
11
11
  var TENJIN_PRODUCT = `tenjin-cli/${package_default.version}`;
@@ -321,4 +321,4 @@ export {
321
321
  httpRequest,
322
322
  fetchFailureToCliError
323
323
  };
324
- //# sourceMappingURL=chunk-RJEPZMYY.js.map
324
+ //# sourceMappingURL=chunk-IOODYAXL.js.map
@@ -1,58 +1,64 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
- import {
3
- ROUTER_PATH
4
- } from "./chunk-VKQXVCZR.js";
5
2
  import {
6
3
  NUDGE_OPT_OUT,
7
4
  channelTag,
8
5
  fetchDistTags,
9
6
  isNewer,
10
7
  resolveTarget
11
- } from "./chunk-WM7TJEBP.js";
8
+ } from "./chunk-VZGAONSJ.js";
9
+ import {
10
+ underAgentHarness
11
+ } from "./chunk-KOGZDMHO.js";
12
+ import {
13
+ ROUTER_PATH
14
+ } from "./chunk-KHE6L6TD.js";
12
15
  import {
13
16
  CLI_SKILL_NAMES,
17
+ FEE_APPROVAL,
14
18
  RETIRED_SKILL_NAMES,
19
+ ROUTER_DEFAULTS,
20
+ ROUTING_FEE_TERMS,
15
21
  SHIPPED_SKILL_FILES,
22
+ SPEND_QUESTION,
16
23
  inspectHooksFile,
17
24
  persistRouterDefaults,
18
25
  persistRouterProject,
19
26
  readSkillFile,
27
+ shownLimits,
20
28
  skillFrontmatterName,
21
- skillsDirsFor
22
- } from "./chunk-25GGN553.js";
29
+ skillsDirsFor,
30
+ spendChoiceQuestion,
31
+ spendOptions
32
+ } from "./chunk-3O2BQIF6.js";
23
33
  import {
24
34
  HOOK_TOOL,
25
35
  hookToolInput
26
36
  } from "./chunk-AKWGE6JQ.js";
27
37
  import {
28
- FEE_APPROVAL,
29
38
  LEGACY_HOOK_TOOL,
30
39
  LEGACY_MCP_SERVER_NAME,
31
40
  LEGACY_REQUEST_TOOL,
32
41
  MARKETPLACE_NAME,
33
42
  MCP_SERVER_NAME,
34
- OWN_LIMITS_COMMANDS,
35
43
  PLUGIN_HOOK_TOOL,
36
44
  PLUGIN_ID,
37
45
  PLUGIN_NAME,
38
46
  PLUGIN_SERVER,
39
47
  REQUEST_TOOL,
40
- ROUTER_DEFAULTS,
41
- ROUTING_FEE_TERMS,
42
- SKILLS_DIR_PLUGIN_ID,
43
- limitsUsd,
44
- shownLimits,
45
- spendQuestion
46
- } from "./chunk-EWLU46J6.js";
48
+ SKILLS_DIR_PLUGIN_ID
49
+ } from "./chunk-WVUSXNIE.js";
47
50
  import {
48
51
  askText,
49
52
  selectOne
50
53
  } from "./chunk-P7LABKCW.js";
54
+ import {
55
+ SUGGESTED_FUND_USD
56
+ } from "./chunk-PAYV4XUA.js";
51
57
  import {
52
58
  emitWriteNotice,
53
59
  paint,
54
60
  sanitizeForTerminal
55
- } from "./chunk-TROZ6HL4.js";
61
+ } from "./chunk-KYFZTGMC.js";
56
62
  import {
57
63
  readAliveStamp
58
64
  } from "./chunk-6W5GYG3W.js";
@@ -62,28 +68,32 @@ import {
62
68
  } from "./chunk-S4SAZ7OD.js";
63
69
  import {
64
70
  httpRequest
65
- } from "./chunk-RJEPZMYY.js";
71
+ } from "./chunk-IOODYAXL.js";
66
72
  import {
67
73
  hasCode
68
74
  } from "./chunk-2I4QTOLB.js";
69
75
  import {
70
76
  resolveContextSettings
71
- } from "./chunk-AMEUXNJT.js";
77
+ } from "./chunk-AWFUPKTM.js";
72
78
  import {
73
79
  CliError,
80
+ MAX_AUTO_SPEND_FLOOR_ATOMIC,
81
+ MAX_AUTO_SPEND_FLOOR_WHY,
74
82
  PRODUCTION_ORIGIN,
75
83
  isSameDeployment,
76
84
  loadRawConfig,
77
85
  parseUsdToAtomic,
78
- toMoney,
86
+ toMoney
87
+ } from "./chunk-WO5BJNIB.js";
88
+ import {
79
89
  writeFileAtomic
80
- } from "./chunk-VVAHFCX2.js";
90
+ } from "./chunk-O2FRQ2L2.js";
81
91
  import {
82
92
  defaultDataDir
83
93
  } from "./chunk-SJLTEINJ.js";
84
94
  import {
85
95
  package_default
86
- } from "./chunk-LRCJ2IZ5.js";
96
+ } from "./chunk-VUFAK2LW.js";
87
97
 
88
98
  // src/commands/update.ts
89
99
  import { spawn } from "node:child_process";
@@ -1336,6 +1346,7 @@ async function runRouterInstall(args, ctx, deps = {}) {
1336
1346
  });
1337
1347
  }
1338
1348
  const config = await loadRawConfig(ctx.dataDir);
1349
+ const named = namedLimits(args);
1339
1350
  const cwd = deps.cwd ?? process.cwd();
1340
1351
  const project = args.project ?? (args.refresh === true && await projectInstallHere(cwd, home, env));
1341
1352
  const scope = project ? "local" : "user";
@@ -1351,8 +1362,10 @@ async function runRouterInstall(args, ctx, deps = {}) {
1351
1362
  }
1352
1363
  const humanOutput = ctx.flags.json === true ? false : deps.isInteractive ?? ctx.io.isTTY;
1353
1364
  const canPrompt = humanOutput && (deps.isInteractive ?? Boolean(process.stdin.isTTY));
1354
- const limits = args.refresh === true ? void 0 : args.yes === true ? shownLimits(config) : canPrompt ? await approveLimits(config, deps) : {};
1355
- const spend = await persistRouterDefaults(ctx.dataDir, args.refresh === true, limits);
1365
+ const answered = args.yes === true || named.keys.length > 0;
1366
+ const unasked = config.maxAutoSpend === void 0 && config.sessionBudget === void 0;
1367
+ const limits = args.refresh === true ? void 0 : named.keys.length > 0 ? { ...shownLimits(config), ...named.limits } : args.yes === true ? shownLimits(config) : canPrompt && unasked ? await approveLimits(deps) : {};
1368
+ const spend = await persistRouterDefaults(ctx.dataDir, args.refresh === true, limits, named.keys);
1356
1369
  const removedKeysLines = spend.removed.length > 0 ? [
1357
1370
  `Removed retired settings: ${spend.removed.join(", ")}. Automatic router limits remain in effect; manual pay always requires consent.`
1358
1371
  ] : [];
@@ -1408,28 +1421,35 @@ async function runRouterInstall(args, ctx, deps = {}) {
1408
1421
  ]
1409
1422
  };
1410
1423
  }
1411
- const { resolveWallet } = await import("./install-wallet-TC22U52X.js");
1424
+ const { resolveWallet } = await import("./install-wallet-MA27FTQ5.js");
1412
1425
  const wallet = await resolveWallet(ctx, deps, args.noWallet === true ? "flag" : void 0, false);
1413
1426
  const effective = await resolveContextSettings(ctx);
1414
- const approval = !canPrompt && args.yes !== true && !spend.kept.includes("maxAutoSpend") ? spendApproval(config, args) : void 0;
1415
- const router = await probeRouter(effective.baseUrl, {
1416
- timeoutMs: ctx.flags.timeout,
1417
- env,
1418
- ...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
1419
- });
1427
+ const spendAsk = !canPrompt && !answered && unasked ? spendStep(args) : void 0;
1428
+ const asksAgent = !canPrompt && underAgentHarness(env);
1429
+ const [router, fund] = await Promise.all([
1430
+ probeRouter(effective.baseUrl, {
1431
+ timeoutMs: ctx.flags.timeout,
1432
+ env,
1433
+ ...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
1434
+ }),
1435
+ // The spend question comes first, because its answer picks the install
1436
+ // command. The funding question rides on the install that follows it.
1437
+ asksAgent && spendAsk === void 0 ? fundStep(wallet, effective.rpcUrl, deps) : Promise.resolve(void 0)
1438
+ ]);
1439
+ const nextSteps = [
1440
+ ...spendAsk !== void 0 ? [spendAsk] : [],
1441
+ ...fund !== void 0 ? [fund] : []
1442
+ ];
1420
1443
  const data = {
1421
1444
  plugin,
1422
1445
  claudeCode,
1423
1446
  migration,
1424
- next: nextStep(plugin, claude, wallet, migration),
1447
+ next: nextStep(plugin, claude, wallet, migration, asksAgent && nextSteps.length > 0),
1448
+ nextSteps,
1425
1449
  // The check for this scope, said outright; a bare doctor in the project
1426
1450
  // also finds it from what the project holds.
1427
1451
  ...project ? { doctor: "tenjin doctor --project" } : {},
1428
- spend: {
1429
- ...spend,
1430
- effective: effectiveLimits(effective.policy),
1431
- ...approval !== void 0 ? { approval } : {}
1432
- },
1452
+ spend: { ...spend, effective: effectiveLimits(effective.policy) },
1433
1453
  wallet,
1434
1454
  router: {
1435
1455
  status: router.status === "ok" ? "ok" : "warn",
@@ -1448,8 +1468,10 @@ async function runRouterInstall(args, ctx, deps = {}) {
1448
1468
  claude,
1449
1469
  migration,
1450
1470
  wallet,
1471
+ ...fund !== void 0 ? { fund } : {},
1472
+ asks: asksAgent && nextSteps.length > 0,
1451
1473
  policy: effective.policy,
1452
- ...approval !== void 0 ? { approval } : {},
1474
+ ...spendAsk !== void 0 ? { spendAsk } : {},
1453
1475
  router
1454
1476
  }),
1455
1477
  ...removedKeysLines,
@@ -1476,10 +1498,14 @@ function registrationFix(plugin) {
1476
1498
  }
1477
1499
  return `Run \`tenjin doctor${flag}\` to see the cause, then run \`tenjin install${flag}\` again.`;
1478
1500
  }
1479
- function nextStep(plugin, claude, wallet, migration) {
1501
+ function nextStep(plugin, claude, wallet, migration, asksQuestion) {
1480
1502
  if (plugin.state === "failed") return registrationFix(plugin);
1481
1503
  const steps = [];
1482
- if (wallet.status === "created") steps.push("fund the wallet with `tenjin wallet fund`");
1504
+ if (asksQuestion) {
1505
+ steps.push("ask the person the question in nextSteps, then run what the answer names");
1506
+ } else if (wallet.status === "created") {
1507
+ steps.push("fund the wallet with `tenjin wallet fund`");
1508
+ }
1483
1509
  if (plugin.state === "deferred") {
1484
1510
  steps.unshift("run `claude update`");
1485
1511
  steps.push(
@@ -1530,62 +1556,126 @@ function refreshNotices(plugin, claude, migration) {
1530
1556
  if (status !== null) out.push(status);
1531
1557
  return out;
1532
1558
  }
1533
- var AUTO_SPEND_FIX = `tenjin config set maxAutoSpend ${toMoney(ROUTER_DEFAULTS.maxAutoSpend).usd}`;
1534
- var DECLINED = "the router then pays for nothing on its own, and the question stays open until the user answers it";
1535
- function spendApproval(config, args) {
1536
- const limits = shownLimits(config);
1537
- const approve = yesCommand(args);
1559
+ var SHOW_NOT_RUN = "Show the person addresses as written, and never ask them to run a command.";
1560
+ function spendStep(args) {
1561
+ const options = spendOptions(installCommand(args));
1562
+ const [byDefault, custom] = options;
1538
1563
  return {
1539
- question: spendQuestion(limits),
1540
- limits: limitsUsd(limits),
1541
- routingFee: ROUTING_FEE_TERMS,
1542
- next: `In this session, show the user these limits and ask this question before you change any limit. If they say yes, run the same install again with --yes: \`${approve}\`. If they give other amounts, run ${OWN_LIMITS_COMMANDS}. If they say no, run nothing: ${DECLINED}.`,
1543
- approve,
1544
- own: OWN_LIMITS_COMMANDS.replaceAll("`", "")
1564
+ id: "spend",
1565
+ question: spendChoiceQuestion(),
1566
+ options,
1567
+ next: `In this session, ask the person this question with your question tool, offering these two options in order with the defaults marked recommended. The defaults are already in effect. Use the defaults: run \`${byDefault.command}\`. Set my own limits: ask for the most per day in USD (or none for no daily limit) and the most per call in USD (at least 0.25), then run \`${custom.command}\` with their amounts. Run the command alone, never joined with another command, and do not ask again a question its output repeats. ${SHOW_NOT_RUN}`
1545
1568
  };
1546
1569
  }
1547
- function yesCommand(args) {
1570
+ function installCommand(args) {
1548
1571
  return [
1549
1572
  "tenjin install",
1550
1573
  ...args.project === true ? ["--project"] : [],
1551
- ...args.noWallet === true ? ["--no-wallet"] : [],
1552
- "--yes"
1574
+ ...args.noWallet === true ? ["--no-wallet"] : []
1553
1575
  ].join(" ");
1554
1576
  }
1555
- async function approveLimits(config, deps) {
1556
- const shown = shownLimits(config);
1557
- const askCall = config.maxAutoSpend === void 0;
1558
- const askDay = config.sessionBudget === void 0;
1559
- if (!askCall && !askDay) return void 0;
1560
- const daily = shown.sessionBudget === "none" ? "no daily limit" : `$${toMoney(shown.sessionBudget).usd} a day`;
1561
- const fee = `
1562
- ${ROUTING_FEE_TERMS}
1563
- ${FEE_APPROVAL}`;
1577
+ function namedLimits(args) {
1578
+ const flags = [
1579
+ ["maxAutoSpend", "--max-auto-spend", args.maxAutoSpend, "call"],
1580
+ ["sessionBudget", "--session-budget", args.sessionBudget, "day"]
1581
+ ];
1582
+ const limits = {};
1583
+ const keys = [];
1584
+ for (const [key, flag, raw, per] of flags) {
1585
+ if (raw === void 0) continue;
1586
+ if (args.refresh === true) {
1587
+ throw new CliError("USAGE", `${flag} sets a spend limit, and --refresh writes none.`, {
1588
+ fix: `Run \`tenjin install ${flag} ${raw}\` without --refresh.`
1589
+ });
1590
+ }
1591
+ const parsed = parseLimit(raw, per);
1592
+ if ("refusal" in parsed) {
1593
+ throw new CliError("USAGE", `${flag} ${raw}: ${parsed.refusal}`, {
1594
+ fix: per === "day" ? `Give a positive USD amount or none, for example \`${flag} 5\`.` : `Give 0.25 USD or more, for example \`${flag} 0.5\`. ${MAX_AUTO_SPEND_FLOOR_WHY}`
1595
+ });
1596
+ }
1597
+ limits[key] = parsed.value;
1598
+ keys.push(key);
1599
+ }
1600
+ return { limits, keys };
1601
+ }
1602
+ var FUND_QUESTION = `Do you want to add $${SUGGESTED_FUND_USD} to your Tenjin wallet now?`;
1603
+ var FUND_COMMAND = `tenjin wallet fund ${SUGGESTED_FUND_USD}`;
1604
+ async function fundStep(wallet, rpcUrl, deps) {
1605
+ const address = wallet.address;
1606
+ if (address === void 0 || wallet.status !== "created" && wallet.status !== "existing") {
1607
+ return void 0;
1608
+ }
1609
+ const funded = wallet.status === "created" ? false : await (deps.walletBalance ?? defaultBalance)(address, rpcUrl).then(
1610
+ (atomic) => atomic > 0n,
1611
+ () => null
1612
+ );
1613
+ if (funded === true) return void 0;
1614
+ const show = `To add funds, send USDC on Base to ${address}.`;
1615
+ return {
1616
+ id: "fund",
1617
+ question: FUND_QUESTION,
1618
+ options: [
1619
+ {
1620
+ id: "fund",
1621
+ label: "Yes, open the funding page",
1622
+ recommended: false,
1623
+ command: FUND_COMMAND
1624
+ },
1625
+ { id: "later", label: "Not now", recommended: false, command: null }
1626
+ ],
1627
+ next: `The install is done. Ask the person this question with your question tool. On "Yes, open the funding page", run \`${FUND_COMMAND}\` alone, in the same turn. On "Not now", run nothing and show the person this for later: ${show} Never run \`${FUND_COMMAND}\` without this yes. ${SHOW_NOT_RUN}`,
1628
+ address,
1629
+ show
1630
+ };
1631
+ }
1632
+ async function defaultBalance(address, rpcUrl) {
1633
+ const { getUsdcBalance } = await import("./usdc-JK4RRFFQ.js");
1634
+ return getUsdcBalance(address, rpcUrl);
1635
+ }
1636
+ function fundLines(fund) {
1637
+ return [
1638
+ ` Ask the person: ${fund.question}`,
1639
+ ` Yes, open the funding page: ${FUND_COMMAND}`,
1640
+ ` Not now: run nothing, show them: ${fund.show}`
1641
+ ];
1642
+ }
1643
+ async function approveLimits(deps) {
1564
1644
  const choice = await (deps.promptLimits ?? promptLimits)(
1565
- `The router pays for tool calls without asking, up to:
1566
- $${toMoney(shown.maxAutoSpend).usd} a call, ${daily}${fee}`
1645
+ `${SPEND_QUESTION}
1646
+ ${ROUTING_FEE_TERMS}
1647
+ ${FEE_APPROVAL}`
1567
1648
  );
1568
1649
  if (choice === null) throw installCancelled();
1569
- if (choice === "approve") return shown;
1650
+ if (choice === "approve") return { ...ROUTER_DEFAULTS };
1570
1651
  const ask = deps.promptAmount ?? promptAmount;
1571
- return {
1572
- maxAutoSpend: askCall ? await askLimit(ask, "Most the router may pay for one call, in USD", "0.25", false) : shown.maxAutoSpend,
1573
- sessionBudget: askDay ? await askLimit(ask, "Most it may pay in a day, in USD, or none", "5", true) : shown.sessionBudget
1574
- };
1652
+ const sessionBudget = await askLimit(
1653
+ ask,
1654
+ "Most it may pay in a day, in USD, or none",
1655
+ "5",
1656
+ "day"
1657
+ );
1658
+ const maxAutoSpend = await askLimit(
1659
+ ask,
1660
+ "Most it may pay for one call, in USD, at least 0.25",
1661
+ "0.25",
1662
+ "call"
1663
+ );
1664
+ return { maxAutoSpend, sessionBudget };
1575
1665
  }
1576
- async function askLimit(ask, question, placeholder, allowNone) {
1666
+ async function askLimit(ask, question, placeholder, per) {
1577
1667
  let message = question;
1578
1668
  for (; ; ) {
1579
1669
  const answer = await ask(message, placeholder);
1580
1670
  if (answer === null) throw installCancelled();
1581
- const parsed = parseLimit(answer, allowNone);
1671
+ const parsed = parseLimit(answer, per);
1582
1672
  if (!("refusal" in parsed)) return parsed.value;
1583
1673
  message = `${parsed.refusal} ${question}`;
1584
1674
  }
1585
1675
  }
1586
- function parseLimit(answer, allowNone) {
1676
+ function parseLimit(answer, per) {
1587
1677
  const trimmed = answer.trim();
1588
- if (allowNone && trimmed === "none") return { value: "none" };
1678
+ if (per === "day" && trimmed === "none") return { value: "none" };
1589
1679
  let atomic;
1590
1680
  try {
1591
1681
  atomic = parseUsdToAtomic(trimmed);
@@ -1593,20 +1683,27 @@ function parseLimit(answer, allowNone) {
1593
1683
  if (err instanceof CliError) return { refusal: `${err.message}.` };
1594
1684
  throw err;
1595
1685
  }
1596
- if (atomic === "0") return { refusal: "The limit must be more than zero." };
1686
+ if (per === "call" && BigInt(atomic) < MAX_AUTO_SPEND_FLOOR_ATOMIC) {
1687
+ return { refusal: "The per-call limit is at least $0.25." };
1688
+ }
1689
+ if (atomic === "0") {
1690
+ return {
1691
+ refusal: "The limit must be more than zero; `tenjin config set router.enabled false` turns the router off."
1692
+ };
1693
+ }
1597
1694
  return { value: atomic };
1598
1695
  }
1599
1696
  function installCancelled() {
1600
1697
  return new CliError("REFUSED", "Install cancelled before anything was written.", {
1601
- fix: "Re-run `tenjin install` and choose the spend limits."
1698
+ fix: "Re-run `tenjin install` and choose the defaults or your own limits."
1602
1699
  });
1603
1700
  }
1604
1701
  function promptLimits(message) {
1605
1702
  return selectOne({
1606
1703
  message,
1607
1704
  choices: [
1608
- { value: "approve", label: "Use these limits" },
1609
- { value: "own", label: "Choose my own" }
1705
+ { value: "approve", label: "Use the defaults" },
1706
+ { value: "own", label: "Set my own limits" }
1610
1707
  ],
1611
1708
  initialValue: "approve"
1612
1709
  });
@@ -1678,16 +1775,15 @@ function lines(ctx, s) {
1678
1775
  const warn = (text) => paint(ctx.io, "yellow", `! ${text}`);
1679
1776
  const limits = effectiveLimits(s.policy);
1680
1777
  const daily = s.policy.sessionBudgetAtomic === null ? "no daily limit" : `$${limits.sessionBudget} a day`;
1681
- const spend = s.approval !== void 0 ? [
1682
- warn("Automatic payments are off until the user approves a spend limit"),
1683
- ` Ask the user in this session: ${s.approval.question}`,
1684
- ` Yes: ${s.approval.approve}`,
1685
- ` Other amounts: ${s.approval.own}`,
1686
- ` No: run nothing, ${DECLINED.replaceAll("`", "")}`
1687
- ] : s.policy.maxAutoSpendAtomic === 0n ? [
1688
- warn("Automatic payments are off: every paid lookup needs your approval"),
1689
- ` To let the router pay without asking, run: ${AUTO_SPEND_FIX}`
1690
- ] : [` Automatic router: up to $${limits.maxAutoSpend} per call; daily limit ${daily}`];
1778
+ const spend = [
1779
+ ` Automatic router: up to $${limits.maxAutoSpend} per call; daily limit ${daily}`,
1780
+ ...s.spendAsk !== void 0 ? [
1781
+ ` Ask the person in this session: ${s.spendAsk.question}`,
1782
+ ...s.spendAsk.options.map(
1783
+ (o) => ` ${o.label}${o.recommended ? " (recommended)" : ""}: ${o.command}`
1784
+ )
1785
+ ] : []
1786
+ ];
1691
1787
  const router = s.router.status === "ok" ? [] : [
1692
1788
  warn(`The router did not answer: ${s.router.detail}`),
1693
1789
  ...s.router.fix !== void 0 ? [` ${s.router.fix}`] : []
@@ -1697,12 +1793,13 @@ function lines(ctx, s) {
1697
1793
  ...s.plugin.scope === "local" && s.plugin.state !== "failed" ? [" For this project only; check it with: tenjin doctor --project"] : [],
1698
1794
  ...walletLines(ctx, ok, s.wallet),
1699
1795
  ...spend,
1796
+ ...s.fund !== void 0 ? fundLines(s.fund) : [],
1700
1797
  ...pluginLines(ctx, s.plugin),
1701
1798
  ...claudeLines(ctx, s.claude),
1702
1799
  ...migrationLines(ctx, s.migration),
1703
1800
  ...router,
1704
1801
  "",
1705
- `Next: ${nextStep(s.plugin, s.claude, s.wallet, s.migration)}`
1802
+ `Next: ${nextStep(s.plugin, s.claude, s.wallet, s.migration, s.asks)}`
1706
1803
  ];
1707
1804
  }
1708
1805
  function refreshLines(ctx, plugin, claude, migration) {
@@ -2069,6 +2166,9 @@ export {
2069
2166
  migrateSettingsInstall,
2070
2167
  projectInstallHere,
2071
2168
  projectInstallAt,
2072
- runRouterInstall
2169
+ runRouterInstall,
2170
+ SHOW_NOT_RUN,
2171
+ FUND_QUESTION,
2172
+ FUND_COMMAND
2073
2173
  };
2074
- //# sourceMappingURL=chunk-SBL4THYT.js.map
2174
+ //# sourceMappingURL=chunk-JMM6YE7J.js.map