tenjin-cli 0.1.0-alpha.13 → 0.1.0-alpha.15

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 (182) hide show
  1. package/README.md +51 -3
  2. package/dist/buy-VIRNSYGN.js +47 -0
  3. package/dist/{chunk-OC3EIDCP.js → chunk-2MYQN7HM.js} +71 -26
  4. package/dist/chunk-2MYQN7HM.js.map +1 -0
  5. package/dist/{chunk-XXY77EZJ.js → chunk-2RF2GIJQ.js} +57 -226
  6. package/dist/chunk-2RF2GIJQ.js.map +1 -0
  7. package/dist/chunk-3GL2Z5QK.js +57 -0
  8. package/dist/chunk-3GL2Z5QK.js.map +1 -0
  9. package/dist/{chunk-OXUJ3FXU.js → chunk-4CQIDQOT.js} +41 -8
  10. package/dist/chunk-4CQIDQOT.js.map +1 -0
  11. package/dist/{chunk-YMUJZWHB.js → chunk-4KG27W2S.js} +10 -10
  12. package/dist/chunk-4KG27W2S.js.map +1 -0
  13. package/dist/{chunk-SPUORKD7.js → chunk-5QQTYWEU.js} +13 -13
  14. package/dist/chunk-5QQTYWEU.js.map +1 -0
  15. package/dist/chunk-65DTCCJ7.js +21 -0
  16. package/dist/chunk-65DTCCJ7.js.map +1 -0
  17. package/dist/{chunk-BRAVLUGI.js → chunk-A5DKHMUN.js} +28 -13
  18. package/dist/chunk-A5DKHMUN.js.map +1 -0
  19. package/dist/chunk-B63XPWQ4.js +246 -0
  20. package/dist/chunk-B63XPWQ4.js.map +1 -0
  21. package/dist/{chunk-47YKYDOF.js → chunk-CAR6FHK6.js} +5 -5
  22. package/dist/{chunk-JVBMPU5G.js → chunk-CPCX67TI.js} +22 -22
  23. package/dist/{chunk-TXVC46SA.js → chunk-CQBVCYI2.js} +40 -53
  24. package/dist/chunk-CQBVCYI2.js.map +1 -0
  25. package/dist/chunk-DBU5CXBV.js +4731 -0
  26. package/dist/chunk-DBU5CXBV.js.map +1 -0
  27. package/dist/chunk-DHJD77OW.js +81 -0
  28. package/dist/chunk-DHJD77OW.js.map +1 -0
  29. package/dist/{chunk-XGZ5EVMB.js → chunk-EDZSNPE5.js} +2 -2
  30. package/dist/{chunk-736DW4V3.js → chunk-EFWZPUTC.js} +2 -2
  31. package/dist/chunk-EPFL6CTE.js +448 -0
  32. package/dist/chunk-EPFL6CTE.js.map +1 -0
  33. package/dist/{chunk-3P3ES4XU.js → chunk-GHLVXVZD.js} +3 -5
  34. package/dist/{chunk-3P3ES4XU.js.map → chunk-GHLVXVZD.js.map} +1 -1
  35. package/dist/{chunk-UUARTUY2.js → chunk-H3SOOJ2I.js} +264 -33
  36. package/dist/chunk-H3SOOJ2I.js.map +1 -0
  37. package/dist/{chunk-OUJDDY5L.js → chunk-HPJGOLTN.js} +32 -32
  38. package/dist/chunk-HPJGOLTN.js.map +1 -0
  39. package/dist/{chunk-J6FUAIRR.js → chunk-HRGBS2PA.js} +4 -6
  40. package/dist/{chunk-J6FUAIRR.js.map → chunk-HRGBS2PA.js.map} +1 -1
  41. package/dist/{chunk-NKN4YC5C.js → chunk-ITUXPJIS.js} +55 -58
  42. package/dist/chunk-ITUXPJIS.js.map +1 -0
  43. package/dist/{chunk-CA3JV7FX.js → chunk-JBIKAAT3.js} +2 -2
  44. package/dist/{chunk-CA3JV7FX.js.map → chunk-JBIKAAT3.js.map} +1 -1
  45. package/dist/{chunk-6JKD46OJ.js → chunk-KAJZHIQ4.js} +13 -10
  46. package/dist/chunk-KAJZHIQ4.js.map +1 -0
  47. package/dist/{chunk-OWVVI4VQ.js → chunk-KINZ23CV.js} +107 -4535
  48. package/dist/chunk-KINZ23CV.js.map +1 -0
  49. package/dist/{chunk-WMFRCSNC.js → chunk-LRYV3SK7.js} +9 -7
  50. package/dist/{chunk-WMFRCSNC.js.map → chunk-LRYV3SK7.js.map} +1 -1
  51. package/dist/{chunk-T4UWMVKV.js → chunk-NIKXHWOL.js} +11 -13
  52. package/dist/{chunk-T4UWMVKV.js.map → chunk-NIKXHWOL.js.map} +1 -1
  53. package/dist/chunk-OKDRDT74.js +209 -0
  54. package/dist/chunk-OKDRDT74.js.map +1 -0
  55. package/dist/chunk-OKYSNAS3.js +2144 -0
  56. package/dist/chunk-OKYSNAS3.js.map +1 -0
  57. package/dist/{chunk-B676GPS2.js → chunk-OLWTRUTS.js} +7 -3
  58. package/dist/{chunk-B676GPS2.js.map → chunk-OLWTRUTS.js.map} +1 -1
  59. package/dist/{chunk-WU5CZPLD.js → chunk-QQ6ELLSA.js} +6 -8
  60. package/dist/{chunk-WU5CZPLD.js.map → chunk-QQ6ELLSA.js.map} +1 -1
  61. package/dist/{chunk-WVHPGQH5.js → chunk-QZ6ROAJU.js} +8 -4
  62. package/dist/chunk-QZ6ROAJU.js.map +1 -0
  63. package/dist/{chunk-L4XNT3UW.js → chunk-R7RSCBI7.js} +167 -52
  64. package/dist/chunk-R7RSCBI7.js.map +1 -0
  65. package/dist/{chunk-ELVDOTU7.js → chunk-U6VPKMGC.js} +128 -28
  66. package/dist/chunk-U6VPKMGC.js.map +1 -0
  67. package/dist/{chunk-FKSAUOJU.js → chunk-UO22YNY4.js} +1 -69
  68. package/dist/chunk-UO22YNY4.js.map +1 -0
  69. package/dist/{chunk-IAR25V2E.js → chunk-US456VUI.js} +6 -6
  70. package/dist/{chunk-IKAJSA7E.js → chunk-V44J2MXV.js} +80 -34
  71. package/dist/chunk-V44J2MXV.js.map +1 -0
  72. package/dist/{chunk-IFPKA32J.js → chunk-VJQKL3YH.js} +10 -7
  73. package/dist/{chunk-IFPKA32J.js.map → chunk-VJQKL3YH.js.map} +1 -1
  74. package/dist/{chunk-GCGMXA2O.js → chunk-VJSQSLBM.js} +52 -20
  75. package/dist/chunk-VJSQSLBM.js.map +1 -0
  76. package/dist/{chunk-IGHSLJUF.js → chunk-VYOJOX4Z.js} +9 -7
  77. package/dist/chunk-VYOJOX4Z.js.map +1 -0
  78. package/dist/chunk-WY2K35OL.js +269 -0
  79. package/dist/chunk-WY2K35OL.js.map +1 -0
  80. package/dist/{chunk-PAOVPSP6.js → chunk-ZFJJ3EXC.js} +53 -5
  81. package/dist/chunk-ZFJJ3EXC.js.map +1 -0
  82. package/dist/chunk-ZOBNS7CX.js +73 -0
  83. package/dist/chunk-ZOBNS7CX.js.map +1 -0
  84. package/dist/{cli-XK5JZWU6.js → cli-KKRKBU5T.js} +76 -47
  85. package/dist/{cli-XK5JZWU6.js.map → cli-KKRKBU5T.js.map} +1 -1
  86. package/dist/config-JMRUNYE6.js +37 -0
  87. package/dist/discover-B5HF6SHM.js +102 -0
  88. package/dist/discover-B5HF6SHM.js.map +1 -0
  89. package/dist/doctor-ZBG7X66D.js +32 -0
  90. package/dist/edit-PZJIILQE.js +40 -0
  91. package/dist/{fund-JF6A76YS.js → fund-EUDH5KPA.js} +19 -17
  92. package/dist/index.js +1 -1
  93. package/dist/inspect-QC6WEQPN.js +37 -0
  94. package/dist/{install-YQVM3SUW.js → install-GNK2W3PI.js} +286 -447
  95. package/dist/install-GNK2W3PI.js.map +1 -0
  96. package/dist/outcome-KSGWZHUS.js +24 -0
  97. package/dist/pay-BC4UICPA.js +361 -0
  98. package/dist/pay-BC4UICPA.js.map +1 -0
  99. package/dist/publish-LXWFDIKF.js +42 -0
  100. package/dist/{read-UF7QVQOU.js → read-JMNUQ56P.js} +22 -20
  101. package/dist/{read-UF7QVQOU.js.map → read-JMNUQ56P.js.map} +1 -1
  102. package/dist/{run-GDZWHNWZ.js → run-XYTQ5TWQ.js} +54 -45
  103. package/dist/{run-GDZWHNWZ.js.map → run-XYTQ5TWQ.js.map} +1 -1
  104. package/dist/search-TSQAB45E.js +25 -0
  105. package/dist/{send-SI254H3R.js → send-G746D7PQ.js} +14 -14
  106. package/dist/{session-GJZJEXLJ.js → session-JBKWMJ24.js} +18 -17
  107. package/dist/{session-GJZJEXLJ.js.map → session-JBKWMJ24.js.map} +1 -1
  108. package/dist/{skill-heal-BPFT22XS.js → skill-heal-WKD67SLJ.js} +17 -9
  109. package/dist/skill-heal-WKD67SLJ.js.map +1 -0
  110. package/dist/skill-placement-RIU4AMC2.js +20 -0
  111. package/dist/{uninstall-7ZZG6WQ5.js → uninstall-5E263VTS.js} +15 -9
  112. package/dist/uninstall-5E263VTS.js.map +1 -0
  113. package/dist/{update-FPSBITLB.js → update-R76LHOZW.js} +18 -16
  114. package/dist/update-R76LHOZW.js.map +1 -0
  115. package/dist/{wallet-NS7TYWNN.js → wallet-TQ7D5EQ7.js} +7 -7
  116. package/dist/{wallet-TZVD2M4I.js → wallet-ZAVXWLWP.js} +11 -11
  117. package/dist/wallet-ZAVXWLWP.js.map +1 -0
  118. package/docs/agent-permissions.md +117 -18
  119. package/docs/command-reference.md +102 -50
  120. package/docs/safety-model.md +9 -0
  121. package/package.json +1 -1
  122. package/skills/tenjin/SKILL.md +38 -29
  123. package/skills/tenjin-pay/SKILL.md +76 -0
  124. package/skills/tenjin-publish/SKILL.md +184 -205
  125. package/skills/tenjin-publish/references/maintain.md +39 -0
  126. package/skills/tenjin-search/SKILL.md +92 -280
  127. package/skills/tenjin-search/references/permissions.md +112 -0
  128. package/dist/buy-X4VPHFUA.js +0 -44
  129. package/dist/chunk-3NZCU6SD.js +0 -125
  130. package/dist/chunk-3NZCU6SD.js.map +0 -1
  131. package/dist/chunk-6JKD46OJ.js.map +0 -1
  132. package/dist/chunk-BRAVLUGI.js.map +0 -1
  133. package/dist/chunk-ELVDOTU7.js.map +0 -1
  134. package/dist/chunk-FKSAUOJU.js.map +0 -1
  135. package/dist/chunk-GCGMXA2O.js.map +0 -1
  136. package/dist/chunk-IGHSLJUF.js.map +0 -1
  137. package/dist/chunk-IKAJSA7E.js.map +0 -1
  138. package/dist/chunk-L4XNT3UW.js.map +0 -1
  139. package/dist/chunk-NKN4YC5C.js.map +0 -1
  140. package/dist/chunk-OC3EIDCP.js.map +0 -1
  141. package/dist/chunk-OE36HRWG.js +0 -939
  142. package/dist/chunk-OE36HRWG.js.map +0 -1
  143. package/dist/chunk-OUJDDY5L.js.map +0 -1
  144. package/dist/chunk-OWVVI4VQ.js.map +0 -1
  145. package/dist/chunk-OXUJ3FXU.js.map +0 -1
  146. package/dist/chunk-PAOVPSP6.js.map +0 -1
  147. package/dist/chunk-SPUORKD7.js.map +0 -1
  148. package/dist/chunk-TXVC46SA.js.map +0 -1
  149. package/dist/chunk-UUARTUY2.js.map +0 -1
  150. package/dist/chunk-WVHPGQH5.js.map +0 -1
  151. package/dist/chunk-XXY77EZJ.js.map +0 -1
  152. package/dist/chunk-YMUJZWHB.js.map +0 -1
  153. package/dist/chunk-ZQIQ55KK.js +0 -51
  154. package/dist/chunk-ZQIQ55KK.js.map +0 -1
  155. package/dist/config-CNK7MYUR.js +0 -26
  156. package/dist/doctor-R7N7FUX5.js +0 -27
  157. package/dist/edit-QSUEG7CL.js +0 -38
  158. package/dist/inspect-NFNAA4LA.js +0 -35
  159. package/dist/install-YQVM3SUW.js.map +0 -1
  160. package/dist/outcome-IUSYFJTN.js +0 -22
  161. package/dist/publish-O2I6IAEL.js +0 -40
  162. package/dist/search-JVOHEF3E.js +0 -23
  163. package/dist/skill-heal-BPFT22XS.js.map +0 -1
  164. package/dist/uninstall-7ZZG6WQ5.js.map +0 -1
  165. package/dist/update-FPSBITLB.js.map +0 -1
  166. /package/dist/{buy-X4VPHFUA.js.map → buy-VIRNSYGN.js.map} +0 -0
  167. /package/dist/{chunk-47YKYDOF.js.map → chunk-CAR6FHK6.js.map} +0 -0
  168. /package/dist/{chunk-JVBMPU5G.js.map → chunk-CPCX67TI.js.map} +0 -0
  169. /package/dist/{chunk-XGZ5EVMB.js.map → chunk-EDZSNPE5.js.map} +0 -0
  170. /package/dist/{chunk-736DW4V3.js.map → chunk-EFWZPUTC.js.map} +0 -0
  171. /package/dist/{chunk-IAR25V2E.js.map → chunk-US456VUI.js.map} +0 -0
  172. /package/dist/{config-CNK7MYUR.js.map → config-JMRUNYE6.js.map} +0 -0
  173. /package/dist/{doctor-R7N7FUX5.js.map → doctor-ZBG7X66D.js.map} +0 -0
  174. /package/dist/{edit-QSUEG7CL.js.map → edit-PZJIILQE.js.map} +0 -0
  175. /package/dist/{fund-JF6A76YS.js.map → fund-EUDH5KPA.js.map} +0 -0
  176. /package/dist/{inspect-NFNAA4LA.js.map → inspect-QC6WEQPN.js.map} +0 -0
  177. /package/dist/{outcome-IUSYFJTN.js.map → outcome-KSGWZHUS.js.map} +0 -0
  178. /package/dist/{publish-O2I6IAEL.js.map → publish-LXWFDIKF.js.map} +0 -0
  179. /package/dist/{search-JVOHEF3E.js.map → search-TSQAB45E.js.map} +0 -0
  180. /package/dist/{send-SI254H3R.js.map → send-G746D7PQ.js.map} +0 -0
  181. /package/dist/{wallet-NS7TYWNN.js.map → skill-placement-RIU4AMC2.js.map} +0 -0
  182. /package/dist/{wallet-TZVD2M4I.js.map → wallet-TQ7D5EQ7.js.map} +0 -0
@@ -1,29 +1,31 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
2
  import {
3
- assertOnBaseOrigin
4
- } from "./chunk-IFPKA32J.js";
3
+ readSessionId
4
+ } from "./chunk-65DTCCJ7.js";
5
5
  import {
6
- recordSearch
7
- } from "./chunk-BRAVLUGI.js";
6
+ assertOnBaseOrigin
7
+ } from "./chunk-VJQKL3YH.js";
8
8
  import {
9
9
  MAX_LIMIT,
10
10
  buildSearchRequest,
11
11
  postSearch
12
- } from "./chunk-NKN4YC5C.js";
12
+ } from "./chunk-ITUXPJIS.js";
13
13
  import {
14
14
  sanitizeForTerminal
15
- } from "./chunk-B676GPS2.js";
15
+ } from "./chunk-OLWTRUTS.js";
16
16
  import {
17
17
  resolveContextSettings
18
- } from "./chunk-IGHSLJUF.js";
18
+ } from "./chunk-VYOJOX4Z.js";
19
19
  import {
20
20
  formatUsdDisplay,
21
- isPaidPrice,
22
21
  parseUsdToAtomic
23
- } from "./chunk-736DW4V3.js";
22
+ } from "./chunk-EFWZPUTC.js";
23
+ import {
24
+ recordSearch
25
+ } from "./chunk-A5DKHMUN.js";
24
26
  import {
25
27
  CliError
26
- } from "./chunk-PAOVPSP6.js";
28
+ } from "./chunk-ZFJJ3EXC.js";
27
29
 
28
30
  // src/commands/search.ts
29
31
  async function runSearch(args, ctx, deps = {}) {
@@ -43,7 +45,7 @@ async function runSearch(args, ctx, deps = {}) {
43
45
  evalCohort: settings.evalCohort,
44
46
  ...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
45
47
  });
46
- const candidates = response.candidates ?? [];
48
+ const candidates = response.items;
47
49
  for (const c of candidates) {
48
50
  try {
49
51
  assertOnBaseOrigin(c.url, settings.baseUrl, "search candidate URL");
@@ -55,22 +57,12 @@ async function runSearch(args, ctx, deps = {}) {
55
57
  );
56
58
  }
57
59
  }
58
- for (const b of response.browse ?? []) {
59
- try {
60
- assertOnBaseOrigin(b.url, settings.baseUrl, "browse pointer URL");
61
- } catch (err) {
62
- throw new CliError(
63
- "CONTRACT_MISMATCH",
64
- `Browse pointer ${b.resourceId} points off the configured base URL.`,
65
- { cause: err }
66
- );
67
- }
68
- }
60
+ const decision = candidates.length > 0 ? "CANDIDATES" : "MISS";
69
61
  await recordSearch(ctx.dataDir, {
70
62
  searchId: response.searchId,
71
63
  at: (/* @__PURE__ */ new Date()).toISOString(),
72
- question: request.question,
73
- decision: response.decision,
64
+ question: request.query,
65
+ decision,
74
66
  // A deliberate search, as opposed to one the WebSearch hook rode along with.
75
67
  // The Stop hook nags on the two differently, so the tag has to be written
76
68
  // here rather than inferred later from anything.
@@ -84,46 +76,41 @@ async function runSearch(args, ctx, deps = {}) {
84
76
  title: c.title,
85
77
  price: c.price
86
78
  })),
87
- // The pointers stay unrecorded on purpose (see below); only how many of them
88
- // cost money, so `outcome` can tell a MISS that offered a payable browse tail
89
- // from one that offered nothing to buy. A zero-priced pointer does not count:
90
- // `read` delivers it for nothing, so there was no purchase to decline. Zero on
91
- // a CANDIDATES decision, where the contract carries no browse array and the
92
- // parser drops any that appears.
93
- paidBrowseCount: (response.browse ?? []).filter((b) => isPaidPrice(b.price) === true).length
79
+ // Always zero under search v3, and that is a fact about the result rather
80
+ // than a placeholder: the decision view draws no browse tail at all, so no
81
+ // pointer was offered and none of them cost money. `outcome` reads this to
82
+ // tell a search that offered nothing to buy from one that put a payable
83
+ // pointer in front of the agent, and under v3 the answer is always the
84
+ // former. The field stays on the store because entries written by older CLIs
85
+ // still carry a real count, and `undefined` there must keep reading as
86
+ // "unknown" rather than as zero.
87
+ paidBrowseCount: 0
94
88
  });
95
- if (response.decision === "MISS") {
96
- ctx.io.stderr.write(`${publishBackLine(response.searchId)}
97
- `);
98
- }
99
- const browse = response.browse ?? [];
100
- const browseHint = browse.length > 0 ? [
101
- `no match, ${browse.length} piece(s) you could browse: ${browse.map((b) => `${sanitizeForTerminal(b.title)} (${formatUsdDisplay(b.price)} USD)`).join("; ")}`
102
- ] : [];
89
+ const missHint = response.hint !== void 0 && response.hint.length > 0 ? [sanitizeForTerminal(response.hint)] : [];
103
90
  const truncatedHint = response.truncated === true ? [
104
91
  request.limit < MAX_LIMIT ? `some candidates were dropped for size; retry with --limit ${MAX_LIMIT} (the size ceiling grows with the number of candidates returned)` : `some candidates were dropped for size; at --limit ${MAX_LIMIT} the dropped tail cannot be recovered, so narrow the question`
105
92
  ] : [];
106
- const humanLines = response.decision === "MISS" ? [`MISS, no candidates (searchId ${response.searchId})`, ...browseHint, ...truncatedHint] : [
93
+ const humanLines = decision === "MISS" ? [
94
+ `MISS, no candidates (searchId ${response.searchId})`,
95
+ ...missHint,
96
+ ...truncatedHint,
97
+ publishBackLine(response.searchId)
98
+ ] : [
107
99
  `${candidates.length} candidate(s) (searchId ${response.searchId}):`,
108
- // Dollars for the same reason the browse hint uses them: this is the
109
- // human's cue to size the spend against gates they entered in decimal
110
- // USD. The machine `candidates` array in --json keeps atomic.
100
+ // Dollars, not atomic units: this is the human's cue to size the spend
101
+ // against gates they entered in decimal USD (`--max-price 0.10`, the
102
+ // `maxAutoSpend` config). `formatUsdDisplay` is the canonical human-copy
103
+ // form (always two decimals, so a dime reads "0.10" and not "0.1"); the
104
+ // machine `items` array in --json keeps the exact atomic string, per the
105
+ // money-units contract in the README.
111
106
  ...candidates.map(
112
107
  (c, i) => ` ${i + 1}. ${sanitizeForTerminal(c.title)}, ${formatUsdDisplay(c.price)} USD, ${sanitizeForTerminal(c.url)}`
113
108
  ),
114
109
  ...truncatedHint
115
110
  ];
116
- const data = response.decision === "MISS" ? { ...response, publishBack: publishBackHint(response.searchId) } : response;
111
+ const data = decision === "MISS" ? { ...response, publishBack: publishBackHint(response.searchId) } : response;
117
112
  return { data, humanLines };
118
113
  }
119
- function readSessionId(env) {
120
- return firstNonEmpty(env.TENJIN_SESSION_ID) ?? firstNonEmpty(env.CLAUDE_CODE_SESSION_ID);
121
- }
122
- function firstNonEmpty(raw) {
123
- if (typeof raw !== "string") return void 0;
124
- const trimmed = raw.trim();
125
- return trimmed.length > 0 ? trimmed : void 0;
126
- }
127
114
  function publishBackHint(searchId) {
128
115
  return {
129
116
  searchId,
@@ -172,4 +159,4 @@ function parseAppliesTo(pairs) {
172
159
  export {
173
160
  runSearch
174
161
  };
175
- //# sourceMappingURL=chunk-TXVC46SA.js.map
162
+ //# sourceMappingURL=chunk-CQBVCYI2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/search.ts"],"sourcesContent":["import { CliError } from '../lib/errors';\nimport { formatUsdDisplay, parseUsdToAtomic } from '../lib/money';\nimport { resolveContextSettings } from '../lib/settings';\nimport { buildSearchRequest, postSearch, MAX_LIMIT, type SearchInput } from '../lib/agent-api';\nimport { recordSearch } from '../lib/search-store';\nimport { readSessionId } from '../lib/session';\nimport { assertOnBaseOrigin } from '../lib/resource-ref';\nimport { sanitizeForTerminal } from '../lib/output';\nimport type { CommandContext, CommandResult } from '../context';\n\n/**\n * `tenjin search \"<question>\"`, one POST to /api/search with `view: \"decision\"`.\n * Prints the compact result (spec 10) and records the searchId + items locally so\n * `outcome --last` and `buy <resourceId>` can use them. No wallet, no signing:\n * search is anonymous.\n *\n * The machine envelope is the server's response verbatim plus exactly one\n * CLI-owned key, `publishBack`, and only on a miss. It carries no server data: it\n * is the local searchId and the two commands that close the loop, which is\n * information the CLI owns and the contract does not describe.\n *\n * Search is the breadth step: an item is a lean hit (identity, price, freshness,\n * why it matched), and the full answer card comes from `tenjin inspect`, which is\n * free. So an item line stays short on purpose.\n *\n * A MISS is no longer a `decision` the server sends, it is simply `matched: 0`\n * with an empty `items` (search v3). The CANDIDATES/MISS wording survives ONLY in\n * the local store, whose entries predate v3 and whose `decision` field `outcome`\n * still reads; it is derived here from whether anything matched, and never parsed\n * off the wire.\n *\n * The response's `searchId` is the outcome-reporting capability for\n * POST /api/searches/<searchId>/outcomes. tenjin#463 renamed the field (from\n * `lookupId`), tenjin#616 dropped the `/agent` prefix from the outcomes path, and\n * tenjin#137 retired the `/api/agent/search` alias; this client follows all three\n * end to end, so nothing on the wire or in the local store still speaks\n * `lookupId` or a prefixed spelling.\n */\n\nexport interface SearchArgs {\n question: string;\n /** Decimal USD at the edge (O1); converted to atomic for the wire. */\n maxPrice?: string;\n freshWithin?: string;\n limit?: string;\n /** Raw `k=v` / `k=v1,v2` pairs from repeated --applies-to. */\n appliesTo?: string[];\n}\n\nexport interface SearchDeps {\n fetchImpl?: typeof fetch;\n /** Environment seam (TENJIN_SESSION_ID); defaults to process.env. */\n env?: NodeJS.ProcessEnv;\n}\n\nexport async function runSearch(\n args: SearchArgs,\n ctx: CommandContext,\n deps: SearchDeps = {},\n): Promise<CommandResult> {\n const settings = await resolveContextSettings(ctx);\n const input: SearchInput = { question: args.question };\n if (args.maxPrice !== undefined) input.maxPrice = parseUsdToAtomic(args.maxPrice);\n if (args.freshWithin !== undefined) input.freshWithin = args.freshWithin;\n if (args.limit !== undefined) input.limit = parseLimit(args.limit);\n if (args.appliesTo !== undefined && args.appliesTo.length > 0) {\n input.appliesTo = parseAppliesTo(args.appliesTo);\n }\n\n const sessionId = readSessionId(deps.env ?? process.env);\n const request = buildSearchRequest(input);\n const response = await postSearch(request, {\n baseUrl: settings.baseUrl,\n timeoutMs: ctx.flags.timeout,\n evalCohort: settings.evalCohort,\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n });\n\n const candidates = response.items;\n // Ingest trust boundary: a candidate url that points off the configured origin\n // would later route a wallet-signed SIWX header and payment to that host via\n // `buy <resourceId>`. Refuse the whole response as a contract violation.\n // This deliberately diverges from the hook path (lib/hook-scripts.ts\n // askTenjin), which DROPS the one off-origin candidate and keeps the rest: a\n // hook hint is advisory and never pays, so one bad row should not blank the\n // hint, whereas a `search` result feeds `buy` and must fail closed as a whole.\n for (const c of candidates) {\n try {\n assertOnBaseOrigin(c.url, settings.baseUrl, 'search candidate URL');\n } catch (err) {\n throw new CliError(\n 'CONTRACT_MISMATCH',\n `Search candidate ${c.resourceId} points off the configured base URL.`,\n { cause: err },\n );\n }\n }\n // Derived, never read off the wire: v3 has no `decision` field. The store keeps\n // the two words because entries written by older CLIs and by the WebSearch hook\n // carry them and `outcome` branches on them, so a rename here would split the\n // ledger rather than clean it up.\n const decision = candidates.length > 0 ? 'CANDIDATES' : 'MISS';\n await recordSearch(ctx.dataDir, {\n searchId: response.searchId,\n at: new Date().toISOString(),\n question: request.query,\n decision,\n // A deliberate search, as opposed to one the WebSearch hook rode along with.\n // The Stop hook nags on the two differently, so the tag has to be written\n // here rather than inferred later from anything.\n source: 'cli',\n // Usually absent; see readSessionId. An unstamped entry is raised in every\n // session, which is the safe direction for a reminder.\n ...(sessionId !== undefined ? { sessionId } : {}),\n candidates: candidates.map((c) => ({\n resourceId: c.resourceId,\n url: c.url,\n title: c.title,\n price: c.price,\n })),\n // Always zero under search v3, and that is a fact about the result rather\n // than a placeholder: the decision view draws no browse tail at all, so no\n // pointer was offered and none of them cost money. `outcome` reads this to\n // tell a search that offered nothing to buy from one that put a payable\n // pointer in front of the agent, and under v3 the answer is always the\n // former. The field stays on the store because entries written by older CLIs\n // still carry a real count, and `undefined` there must keep reading as\n // \"unknown\" rather than as zero.\n paidBrowseCount: 0,\n });\n\n // A miss under search v3 carries no browse tail at all: the decision view\n // returns matches or nothing, and the catalog is browsed at GET /api/articles.\n // The server says exactly that in `hint`, and rendering the server's own\n // sentence rather than a local paraphrase is what keeps the two from drifting\n // when that pointer moves. It is server-authored text on its way to a terminal,\n // so it is sanitized like every other rendered string, and the parser has\n // already bounded its length.\n //\n // Absent-but-empty is treated as absent: `hint` is contractually present only\n // when nothing matched, so a server that omits it costs the reader one line\n // rather than an empty bullet.\n const missHint =\n response.hint !== undefined && response.hint.length > 0\n ? [sanitizeForTerminal(response.hint)]\n : [];\n\n // `truncated` means the server's size backstop dropped candidates, either a\n // trailing few the limit had room for or a single oversized one. The response\n // ceiling GROWS with the number of candidates returned (tenjin#501), so the\n // remedy is counter-intuitive and worth stating outright: a larger --limit\n // recovers the tail, a smaller one returns strictly fewer. Only at the maximum\n // is the tail unrecoverable and narrowing the question the answer.\n //\n // The CLI knows the limit it sent, so it names the next step instead of\n // restating the rule and leaving the reader to work out which half applies.\n // The flag stays in the machine envelope (--json) untouched, where it is\n // omitted rather than false when it did not fire.\n //\n // Rendering it on a MISS too is DEFENSIVE, not wire behavior: the server only\n // ever sets the flag alongside candidates it dropped. Handling both keeps the\n // flag from going unrendered if that ever changes.\n const truncatedHint =\n response.truncated === true\n ? [\n request.limit < MAX_LIMIT\n ? `some candidates were dropped for size; retry with --limit ${MAX_LIMIT} (the size ceiling grows with the number of candidates returned)`\n : `some candidates were dropped for size; at --limit ${MAX_LIMIT} the dropped tail cannot be recovered, so narrow the question`,\n ]\n : [];\n\n // The publish-back line rides humanLines like every other rendering, so `--json`\n // suppresses it the way that flag's own help promises. It used to go straight to\n // stderr, which no output mode gates: an agent asking for a machine envelope got\n // ~260 bytes of human prose alongside it.\n const humanLines =\n decision === 'MISS'\n ? [\n `MISS, no candidates (searchId ${response.searchId})`,\n ...missHint,\n ...truncatedHint,\n publishBackLine(response.searchId),\n ]\n : [\n `${candidates.length} candidate(s) (searchId ${response.searchId}):`,\n // Dollars, not atomic units: this is the human's cue to size the spend\n // against gates they entered in decimal USD (`--max-price 0.10`, the\n // `maxAutoSpend` config). `formatUsdDisplay` is the canonical human-copy\n // form (always two decimals, so a dime reads \"0.10\" and not \"0.1\"); the\n // machine `items` array in --json keeps the exact atomic string, per the\n // money-units contract in the README.\n ...candidates.map(\n (c, i) =>\n ` ${i + 1}. ${sanitizeForTerminal(c.title)}, ${formatUsdDisplay(c.price)} USD, ${sanitizeForTerminal(c.url)}`,\n ),\n ...truncatedHint,\n ];\n\n // The one CLI-owned field in this envelope. Everything else is the server's\n // response verbatim (spec 10), so the addition is namespaced under a key the\n // contract does not define and is present ONLY on a miss: a miss is the moment\n // the demand this searcher just expressed can still be met, and the searchId is\n // what ties the answer they are about to derive back to it. A result WITH\n // matches is the v3 envelope and nothing else.\n const data =\n decision === 'MISS'\n ? { ...response, publishBack: publishBackHint(response.searchId) }\n : response;\n\n return { data, humanLines };\n}\n\n/** The publish-back hint, as machine fields rather than prose to re-parse. */\nfunction publishBackHint(searchId: string): {\n searchId: string;\n reason: string;\n publish: string;\n decline: string;\n} {\n return {\n searchId,\n reason: 'Nothing on the marketplace answered this. If you solve it, publish it back.',\n // Both arms carry the searchId, because both are commands to run verbatim and\n // a publish without it leaves this very loop open (see publish's --search-id).\n // The second arm is DECLINE, not park: nothing is saved to come back to, and\n // reporting the outcome is what closes the loop so it never raises again.\n publish: `tenjin publish <file.md> --json --search-id ${searchId}`,\n decline: `tenjin outcome --search-id ${searchId} --status regenerated --json`,\n };\n}\n\n/** The same hint as one rendered line for a human. */\nfunction publishBackLine(searchId: string): string {\n return `Nobody has published this yet - if you solve it, publish it back (tenjin publish <file.md> --search-id ${searchId}); if you will not, close the loop: tenjin outcome --search-id ${searchId} --status regenerated`;\n}\n\nfunction parseLimit(raw: string): number {\n const n = Number(raw);\n if (!Number.isInteger(n)) {\n throw new CliError('USAGE', `Invalid --limit: ${JSON.stringify(raw)}`, {\n fix: 'Pass an integer between 1 and 10.',\n });\n }\n return n;\n}\n\n/** `products=Vercel` or `products=Vercel,Next` → { products: [\"Vercel\",\"Next\"] }. Repeated\n * keys merge their values. */\nfunction parseAppliesTo(pairs: string[]): Record<string, string[]> {\n const out: Record<string, string[]> = {};\n for (const pair of pairs) {\n const eq = pair.indexOf('=');\n if (eq <= 0) {\n throw new CliError('USAGE', `Invalid --applies-to: ${JSON.stringify(pair)}`, {\n fix: 'Use key=value, e.g. --applies-to products=Vercel.',\n });\n }\n const key = pair.slice(0, eq).trim();\n const values = pair\n .slice(eq + 1)\n .split(',')\n .map((v) => v.trim())\n .filter((v) => v.length > 0);\n if (values.length === 0) {\n throw new CliError('USAGE', `--applies-to ${JSON.stringify(key)} has no values`, {\n fix: 'Give each key at least one value, e.g. products=Vercel.',\n });\n }\n out[key] = [...(out[key] ?? []), ...values];\n }\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,eAAsB,UACpB,MACA,KACA,OAAmB,CAAC,GACI;AACxB,QAAM,WAAW,MAAM,uBAAuB,GAAG;AACjD,QAAM,QAAqB,EAAE,UAAU,KAAK,SAAS;AACrD,MAAI,KAAK,aAAa,OAAW,OAAM,WAAW,iBAAiB,KAAK,QAAQ;AAChF,MAAI,KAAK,gBAAgB,OAAW,OAAM,cAAc,KAAK;AAC7D,MAAI,KAAK,UAAU,OAAW,OAAM,QAAQ,WAAW,KAAK,KAAK;AACjE,MAAI,KAAK,cAAc,UAAa,KAAK,UAAU,SAAS,GAAG;AAC7D,UAAM,YAAY,eAAe,KAAK,SAAS;AAAA,EACjD;AAEA,QAAM,YAAY,cAAc,KAAK,OAAO,QAAQ,GAAG;AACvD,QAAM,UAAU,mBAAmB,KAAK;AACxC,QAAM,WAAW,MAAM,WAAW,SAAS;AAAA,IACzC,SAAS,SAAS;AAAA,IAClB,WAAW,IAAI,MAAM;AAAA,IACrB,YAAY,SAAS;AAA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