tenjin-cli 0.1.0-alpha.14 → 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 (176) hide show
  1. package/README.md +18 -3
  2. package/dist/{buy-2JBYPHAI.js → buy-VIRNSYGN.js} +24 -23
  3. package/dist/{chunk-QWBUKIP2.js → chunk-2MYQN7HM.js} +66 -27
  4. package/dist/chunk-2MYQN7HM.js.map +1 -0
  5. package/dist/{chunk-DAZAXFSF.js → chunk-2RF2GIJQ.js} +57 -226
  6. package/dist/chunk-2RF2GIJQ.js.map +1 -0
  7. package/dist/{chunk-VEAERJVJ.js → chunk-3GL2Z5QK.js} +23 -9
  8. package/dist/chunk-3GL2Z5QK.js.map +1 -0
  9. package/dist/{chunk-IUQZ4Z7M.js → chunk-4CQIDQOT.js} +6 -1
  10. package/dist/chunk-4CQIDQOT.js.map +1 -0
  11. package/dist/{chunk-IXZJ3JOO.js → chunk-4KG27W2S.js} +10 -10
  12. package/dist/chunk-4KG27W2S.js.map +1 -0
  13. package/dist/{chunk-54AJIO3E.js → chunk-5QQTYWEU.js} +4 -3
  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-7NADDA2V.js → chunk-A5DKHMUN.js} +20 -8
  18. package/dist/chunk-A5DKHMUN.js.map +1 -0
  19. package/dist/{chunk-WYLMJQVH.js → chunk-B63XPWQ4.js} +24 -18
  20. package/dist/chunk-B63XPWQ4.js.map +1 -0
  21. package/dist/{chunk-L6G35FU5.js → chunk-CAR6FHK6.js} +5 -5
  22. package/dist/{chunk-7GJQ5RGA.js → chunk-CPCX67TI.js} +20 -22
  23. package/dist/{chunk-7GJQ5RGA.js.map → chunk-CPCX67TI.js.map} +1 -1
  24. package/dist/{chunk-XVPQGCH4.js → chunk-CQBVCYI2.js} +36 -50
  25. package/dist/chunk-CQBVCYI2.js.map +1 -0
  26. package/dist/chunk-DBU5CXBV.js +4731 -0
  27. package/dist/chunk-DBU5CXBV.js.map +1 -0
  28. package/dist/chunk-DHJD77OW.js +81 -0
  29. package/dist/chunk-DHJD77OW.js.map +1 -0
  30. package/dist/{chunk-XGZ5EVMB.js → chunk-EDZSNPE5.js} +2 -2
  31. package/dist/{chunk-736DW4V3.js → chunk-EFWZPUTC.js} +2 -2
  32. package/dist/chunk-EPFL6CTE.js +448 -0
  33. package/dist/chunk-EPFL6CTE.js.map +1 -0
  34. package/dist/{chunk-3P3ES4XU.js → chunk-GHLVXVZD.js} +3 -5
  35. package/dist/{chunk-3P3ES4XU.js.map → chunk-GHLVXVZD.js.map} +1 -1
  36. package/dist/{chunk-4UHNXY6B.js → chunk-H3SOOJ2I.js} +88 -294
  37. package/dist/chunk-H3SOOJ2I.js.map +1 -0
  38. package/dist/{chunk-MJSXP4LW.js → chunk-HPJGOLTN.js} +6 -8
  39. package/dist/{chunk-MJSXP4LW.js.map → chunk-HPJGOLTN.js.map} +1 -1
  40. package/dist/{chunk-J6FUAIRR.js → chunk-HRGBS2PA.js} +4 -6
  41. package/dist/{chunk-J6FUAIRR.js.map → chunk-HRGBS2PA.js.map} +1 -1
  42. package/dist/{chunk-FDUD3W5V.js → chunk-ITUXPJIS.js} +55 -58
  43. package/dist/chunk-ITUXPJIS.js.map +1 -0
  44. package/dist/{chunk-ETKZWJ4B.js → chunk-JBIKAAT3.js} +2 -2
  45. package/dist/{chunk-ETKZWJ4B.js.map → chunk-JBIKAAT3.js.map} +1 -1
  46. package/dist/{chunk-3ZW7HPY5.js → chunk-KAJZHIQ4.js} +13 -10
  47. package/dist/chunk-KAJZHIQ4.js.map +1 -0
  48. package/dist/{chunk-OWVVI4VQ.js → chunk-KINZ23CV.js} +107 -4535
  49. package/dist/chunk-KINZ23CV.js.map +1 -0
  50. package/dist/{chunk-PCX2JQ2J.js → chunk-LRYV3SK7.js} +9 -7
  51. package/dist/{chunk-PCX2JQ2J.js.map → chunk-LRYV3SK7.js.map} +1 -1
  52. package/dist/{chunk-ACBEHJAH.js → chunk-NIKXHWOL.js} +11 -13
  53. package/dist/{chunk-ACBEHJAH.js.map → chunk-NIKXHWOL.js.map} +1 -1
  54. package/dist/chunk-OKDRDT74.js +209 -0
  55. package/dist/chunk-OKDRDT74.js.map +1 -0
  56. package/dist/chunk-OKYSNAS3.js +2144 -0
  57. package/dist/chunk-OKYSNAS3.js.map +1 -0
  58. package/dist/{chunk-B676GPS2.js → chunk-OLWTRUTS.js} +7 -3
  59. package/dist/{chunk-B676GPS2.js.map → chunk-OLWTRUTS.js.map} +1 -1
  60. package/dist/{chunk-WU5CZPLD.js → chunk-QQ6ELLSA.js} +6 -8
  61. package/dist/{chunk-WU5CZPLD.js.map → chunk-QQ6ELLSA.js.map} +1 -1
  62. package/dist/{chunk-NAAMHWSI.js → chunk-QZ6ROAJU.js} +5 -4
  63. package/dist/chunk-QZ6ROAJU.js.map +1 -0
  64. package/dist/{chunk-GEHL43VE.js → chunk-R7RSCBI7.js} +130 -47
  65. package/dist/chunk-R7RSCBI7.js.map +1 -0
  66. package/dist/{chunk-LSWP7MU2.js → chunk-U6VPKMGC.js} +127 -27
  67. package/dist/chunk-U6VPKMGC.js.map +1 -0
  68. package/dist/{chunk-W4VW5XYB.js → chunk-US456VUI.js} +6 -6
  69. package/dist/{chunk-O75FOHXS.js → chunk-V44J2MXV.js} +64 -36
  70. package/dist/chunk-V44J2MXV.js.map +1 -0
  71. package/dist/{chunk-4Y53PDH6.js → chunk-VJQKL3YH.js} +10 -7
  72. package/dist/{chunk-4Y53PDH6.js.map → chunk-VJQKL3YH.js.map} +1 -1
  73. package/dist/{chunk-VRPLZERE.js → chunk-VJSQSLBM.js} +47 -26
  74. package/dist/chunk-VJSQSLBM.js.map +1 -0
  75. package/dist/{chunk-PKW3H26Z.js → chunk-VYOJOX4Z.js} +9 -7
  76. package/dist/chunk-VYOJOX4Z.js.map +1 -0
  77. package/dist/chunk-WY2K35OL.js +269 -0
  78. package/dist/chunk-WY2K35OL.js.map +1 -0
  79. package/dist/{chunk-PAOVPSP6.js → chunk-ZFJJ3EXC.js} +53 -5
  80. package/dist/chunk-ZFJJ3EXC.js.map +1 -0
  81. package/dist/{cli-U2BEUA55.js → cli-KKRKBU5T.js} +71 -40
  82. package/dist/{cli-U2BEUA55.js.map → cli-KKRKBU5T.js.map} +1 -1
  83. package/dist/config-JMRUNYE6.js +37 -0
  84. package/dist/discover-B5HF6SHM.js +102 -0
  85. package/dist/discover-B5HF6SHM.js.map +1 -0
  86. package/dist/doctor-ZBG7X66D.js +32 -0
  87. package/dist/edit-PZJIILQE.js +40 -0
  88. package/dist/{fund-Y5IAHZ5D.js → fund-EUDH5KPA.js} +19 -19
  89. package/dist/index.js +1 -1
  90. package/dist/{inspect-NFQ6SQQQ.js → inspect-QC6WEQPN.js} +20 -20
  91. package/dist/{install-DXX7PVUP.js → install-GNK2W3PI.js} +196 -78
  92. package/dist/install-GNK2W3PI.js.map +1 -0
  93. package/dist/outcome-KSGWZHUS.js +24 -0
  94. package/dist/pay-BC4UICPA.js +361 -0
  95. package/dist/pay-BC4UICPA.js.map +1 -0
  96. package/dist/publish-LXWFDIKF.js +42 -0
  97. package/dist/{read-W7QVRBVD.js → read-JMNUQ56P.js} +21 -21
  98. package/dist/{run-CJWPGMIQ.js → run-XYTQ5TWQ.js} +52 -45
  99. package/dist/{run-CJWPGMIQ.js.map → run-XYTQ5TWQ.js.map} +1 -1
  100. package/dist/search-TSQAB45E.js +25 -0
  101. package/dist/{send-C5EOKXOU.js → send-G746D7PQ.js} +14 -15
  102. package/dist/{send-C5EOKXOU.js.map → send-G746D7PQ.js.map} +1 -1
  103. package/dist/{session-OBCUUIFX.js → session-JBKWMJ24.js} +17 -17
  104. package/dist/{skill-heal-D6EPLPS6.js → skill-heal-WKD67SLJ.js} +17 -9
  105. package/dist/skill-heal-WKD67SLJ.js.map +1 -0
  106. package/dist/skill-placement-RIU4AMC2.js +20 -0
  107. package/dist/{uninstall-OWJNJ5LI.js → uninstall-5E263VTS.js} +12 -12
  108. package/dist/uninstall-5E263VTS.js.map +1 -0
  109. package/dist/{update-24Y2CQTT.js → update-R76LHOZW.js} +7 -8
  110. package/dist/{update-24Y2CQTT.js.map → update-R76LHOZW.js.map} +1 -1
  111. package/dist/{wallet-SLRIYJ2U.js → wallet-TQ7D5EQ7.js} +7 -8
  112. package/dist/{wallet-OFXDIIGP.js → wallet-ZAVXWLWP.js} +11 -12
  113. package/dist/wallet-ZAVXWLWP.js.map +1 -0
  114. package/docs/agent-permissions.md +17 -2
  115. package/docs/command-reference.md +84 -42
  116. package/docs/safety-model.md +9 -0
  117. package/package.json +1 -1
  118. package/skills/tenjin/SKILL.md +38 -29
  119. package/skills/tenjin-pay/SKILL.md +76 -0
  120. package/skills/tenjin-publish/SKILL.md +10 -7
  121. package/skills/tenjin-search/SKILL.md +18 -13
  122. package/skills/tenjin-search/references/permissions.md +9 -3
  123. package/dist/chunk-3ZW7HPY5.js.map +0 -1
  124. package/dist/chunk-4UHNXY6B.js.map +0 -1
  125. package/dist/chunk-54AJIO3E.js.map +0 -1
  126. package/dist/chunk-7NADDA2V.js.map +0 -1
  127. package/dist/chunk-DAZAXFSF.js.map +0 -1
  128. package/dist/chunk-DTCXO7HS.js +0 -791
  129. package/dist/chunk-DTCXO7HS.js.map +0 -1
  130. package/dist/chunk-FDUD3W5V.js.map +0 -1
  131. package/dist/chunk-GEHL43VE.js.map +0 -1
  132. package/dist/chunk-IU2HVT3Y.js +0 -313
  133. package/dist/chunk-IU2HVT3Y.js.map +0 -1
  134. package/dist/chunk-IUQZ4Z7M.js.map +0 -1
  135. package/dist/chunk-IXZJ3JOO.js.map +0 -1
  136. package/dist/chunk-LSWP7MU2.js.map +0 -1
  137. package/dist/chunk-NAAMHWSI.js.map +0 -1
  138. package/dist/chunk-O75FOHXS.js.map +0 -1
  139. package/dist/chunk-OWVVI4VQ.js.map +0 -1
  140. package/dist/chunk-PAOVPSP6.js.map +0 -1
  141. package/dist/chunk-PKW3H26Z.js.map +0 -1
  142. package/dist/chunk-PQZVDCCA.js +0 -125
  143. package/dist/chunk-PQZVDCCA.js.map +0 -1
  144. package/dist/chunk-QWBUKIP2.js.map +0 -1
  145. package/dist/chunk-VEAERJVJ.js.map +0 -1
  146. package/dist/chunk-VRPLZERE.js.map +0 -1
  147. package/dist/chunk-WYLMJQVH.js.map +0 -1
  148. package/dist/chunk-XVPQGCH4.js.map +0 -1
  149. package/dist/chunk-ZQIQ55KK.js +0 -51
  150. package/dist/chunk-ZQIQ55KK.js.map +0 -1
  151. package/dist/config-CNUIX23Q.js +0 -32
  152. package/dist/doctor-QJJXRWTO.js +0 -31
  153. package/dist/edit-HJ44P44P.js +0 -40
  154. package/dist/install-DXX7PVUP.js.map +0 -1
  155. package/dist/outcome-ANV4QIED.js +0 -24
  156. package/dist/publish-PCBTCXCZ.js +0 -42
  157. package/dist/search-JGAVKTYJ.js +0 -25
  158. package/dist/skill-heal-D6EPLPS6.js.map +0 -1
  159. package/dist/uninstall-OWJNJ5LI.js.map +0 -1
  160. /package/dist/{buy-2JBYPHAI.js.map → buy-VIRNSYGN.js.map} +0 -0
  161. /package/dist/{chunk-L6G35FU5.js.map → chunk-CAR6FHK6.js.map} +0 -0
  162. /package/dist/{chunk-XGZ5EVMB.js.map → chunk-EDZSNPE5.js.map} +0 -0
  163. /package/dist/{chunk-736DW4V3.js.map → chunk-EFWZPUTC.js.map} +0 -0
  164. /package/dist/{chunk-W4VW5XYB.js.map → chunk-US456VUI.js.map} +0 -0
  165. /package/dist/{config-CNUIX23Q.js.map → config-JMRUNYE6.js.map} +0 -0
  166. /package/dist/{doctor-QJJXRWTO.js.map → doctor-ZBG7X66D.js.map} +0 -0
  167. /package/dist/{edit-HJ44P44P.js.map → edit-PZJIILQE.js.map} +0 -0
  168. /package/dist/{fund-Y5IAHZ5D.js.map → fund-EUDH5KPA.js.map} +0 -0
  169. /package/dist/{inspect-NFQ6SQQQ.js.map → inspect-QC6WEQPN.js.map} +0 -0
  170. /package/dist/{outcome-ANV4QIED.js.map → outcome-KSGWZHUS.js.map} +0 -0
  171. /package/dist/{publish-PCBTCXCZ.js.map → publish-LXWFDIKF.js.map} +0 -0
  172. /package/dist/{read-W7QVRBVD.js.map → read-JMNUQ56P.js.map} +0 -0
  173. /package/dist/{search-JGAVKTYJ.js.map → search-TSQAB45E.js.map} +0 -0
  174. /package/dist/{session-OBCUUIFX.js.map → session-JBKWMJ24.js.map} +0 -0
  175. /package/dist/{wallet-OFXDIIGP.js.map → skill-placement-RIU4AMC2.js.map} +0 -0
  176. /package/dist/{wallet-SLRIYJ2U.js.map → wallet-TQ7D5EQ7.js.map} +0 -0
@@ -1,14 +1,13 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
2
  import {
3
- configPath
4
- } from "./chunk-ZQIQ55KK.js";
5
- import {
6
- HARNESS_TARGETS
7
- } from "./chunk-QWBUKIP2.js";
3
+ HARNESS_TARGETS,
4
+ PRODUCTION_ORIGIN
5
+ } from "./chunk-2MYQN7HM.js";
8
6
  import {
9
7
  CliError,
8
+ configPath,
10
9
  external_exports
11
- } from "./chunk-PAOVPSP6.js";
10
+ } from "./chunk-ZFJJ3EXC.js";
12
11
 
13
12
  // src/lib/config.ts
14
13
  import { readFile } from "fs/promises";
@@ -25,9 +24,19 @@ var PublishConfigSchema = external_exports.object({
25
24
  mode: PublishModeSchema,
26
25
  defaultPrice: atomicString
27
26
  });
28
- var SearchHookModeSchema = external_exports.enum(["auto", "remind", "off"]);
29
- function parseSearchHookModeFlag(value, flagName) {
30
- const parsed = SearchHookModeSchema.safeParse(value);
27
+ var WebSearchModeSchema = external_exports.enum(["auto", "remind", "off"]);
28
+ var AgentDispatchModeSchema = external_exports.enum(["auto", "remind", "off"]);
29
+ var SearchHookModeSchema = WebSearchModeSchema;
30
+ var DispatchHookModeSchema = external_exports.enum(["inherit", "auto", "remind", "off"]);
31
+ function parseAgentDispatchHookModeFlag(value, flagName) {
32
+ const parsed = AgentDispatchModeSchema.safeParse(value);
33
+ if (parsed.success) return parsed.data;
34
+ throw new CliError("USAGE", `Invalid ${flagName} ${JSON.stringify(value)}`, {
35
+ fix: 'Use "auto", "remind", or "off".'
36
+ });
37
+ }
38
+ function parseWebSearchHookModeFlag(value, flagName) {
39
+ const parsed = WebSearchModeSchema.safeParse(value);
31
40
  if (parsed.success) return parsed.data;
32
41
  throw new CliError("USAGE", `Invalid ${flagName} ${JSON.stringify(value)}`, {
33
42
  fix: 'Use "auto", "remind", or "off".'
@@ -41,9 +50,23 @@ function parseStopNagFlag(value, flagName) {
41
50
  fix: 'Use "on", "deliberate-only", or "off".'
42
51
  });
43
52
  }
53
+ var SessionPrimerModeSchema = external_exports.enum(["on", "off"]);
54
+ function parseSessionPrimerFlag(value, flagName) {
55
+ const parsed = SessionPrimerModeSchema.safeParse(value);
56
+ if (parsed.success) return parsed.data;
57
+ throw new CliError("USAGE", `Invalid ${flagName} ${JSON.stringify(value)}`, {
58
+ fix: 'Use "on" or "off".'
59
+ });
60
+ }
44
61
  var HooksConfigSchema = external_exports.object({
45
- searchMode: SearchHookModeSchema,
46
- stopNag: StopNagModeSchema
62
+ webSearch: WebSearchModeSchema,
63
+ agentDispatch: AgentDispatchModeSchema,
64
+ stopNag: StopNagModeSchema,
65
+ sessionPrimer: SessionPrimerModeSchema
66
+ });
67
+ var LegacyHooksFields = external_exports.object({
68
+ searchMode: SearchHookModeSchema.optional(),
69
+ dispatchMode: DispatchHookModeSchema.optional()
47
70
  });
48
71
  var UpdateModeSchema = external_exports.enum(["nudge", "off"]);
49
72
  var UpdateConfigSchema = external_exports.object({
@@ -82,6 +105,17 @@ var ConfigSchema = external_exports.object({
82
105
  * 90 days. Off by default; no query text is retained server-side without it.
83
106
  */
84
107
  evalCohort: external_exports.boolean(),
108
+ /**
109
+ * The Bazaar pay lane opt-in: when true, `tenjin pay` may pay a NON-Tenjin
110
+ * x402 endpoint, provided a configured registry lists that exact resource and
111
+ * the live 402 matches the listed deal. Off by default; `install` asks once.
112
+ * The lane's teaching is the OPTIONAL tenjin-pay skill, present on disk
113
+ * exactly while this is on (lib/skill-placement).
114
+ */
115
+ bazaarPay: external_exports.boolean(),
116
+ /** x402 discovery registries (facilitator base URLs) `discover` queries and
117
+ * the Bazaar pay lane verifies against. */
118
+ bazaarRegistries: external_exports.array(external_exports.url()),
85
119
  publish: PublishConfigSchema,
86
120
  install: InstallConfigSchema,
87
121
  hooks: HooksConfigSchema,
@@ -90,10 +124,15 @@ var ConfigSchema = external_exports.object({
90
124
  var RawConfigSchema = ConfigSchema.partial().extend({
91
125
  publish: PublishConfigSchema.partial().passthrough().optional(),
92
126
  install: InstallConfigSchema.partial().passthrough().optional(),
93
- hooks: HooksConfigSchema.partial().passthrough().optional(),
127
+ hooks: HooksConfigSchema.partial().merge(LegacyHooksFields).passthrough().optional(),
94
128
  update: UpdateConfigSchema.partial().passthrough().optional()
95
129
  }).passthrough();
96
130
  var SEND_MAX_UNSET = "unset";
131
+ var DEFAULT_BAZAAR_REGISTRIES = [
132
+ "https://api.cdp.coinbase.com/platform/v2/x402",
133
+ "https://facilitator.ultravioletadao.xyz",
134
+ "https://facilitator.payai.network"
135
+ ];
97
136
  var CONFIG_DEFAULTS = {
98
137
  maxAutoSpend: "0",
99
138
  sessionBudget: "0",
@@ -106,15 +145,18 @@ var CONFIG_DEFAULTS = {
106
145
  // leak fails closed instead of silently running uncapped.
107
146
  sendMaxAmount: "0",
108
147
  allowlistCreators: [],
109
- baseUrl: "https://tenjin.blog",
148
+ baseUrl: PRODUCTION_ORIGIN,
110
149
  rpcUrl: "https://mainnet.base.org",
111
150
  evalCohort: false,
151
+ bazaarPay: false,
152
+ bazaarRegistries: DEFAULT_BAZAAR_REGISTRIES,
112
153
  publish: { mode: "review", defaultPrice: "100000" },
113
154
  install: { harness: [] },
114
155
  // `auto` is the default because the hook exists to be useful without being
115
156
  // asked for; the disclosure and the undo ride the install output, and `off`
116
- // leaves the installed script inert without touching settings.json.
117
- hooks: { searchMode: "auto", stopNag: "on" },
157
+ // leaves the installed script inert without touching settings.json. Both hooks
158
+ // are `auto` by default and disjoint — no `inherit`.
159
+ hooks: { webSearch: "auto", agentDispatch: "auto", stopNag: "on", sessionPrimer: "on" },
118
160
  update: { mode: "nudge" }
119
161
  };
120
162
  var NESTED_CONFIG_KEYS = /* @__PURE__ */ new Set(["publish", "install", "hooks", "update"]);
@@ -122,7 +164,13 @@ var CONFIG_KEYS = Object.keys(CONFIG_DEFAULTS).filter(
122
164
  (key) => !NESTED_CONFIG_KEYS.has(key)
123
165
  );
124
166
  var PUBLISH_CONFIG_KEYS = ["publish.mode", "publish.defaultPrice"];
125
- var HOOKS_CONFIG_KEYS = ["hooks.searchMode", "hooks.stopNag"];
167
+ var HOOKS_CONFIG_KEYS = [
168
+ "hooks.webSearch",
169
+ "hooks.agentDispatch",
170
+ "hooks.stopNag",
171
+ "hooks.sessionPrimer"
172
+ ];
173
+ var LEGACY_HOOKS_CONFIG_KEYS = ["hooks.searchMode", "hooks.dispatchMode"];
126
174
  var UPDATE_CONFIG_KEYS = ["update.mode"];
127
175
  async function loadRawConfig(dir) {
128
176
  const path = configPath(dir);
@@ -156,6 +204,22 @@ async function loadRawConfig(dir) {
156
204
  }
157
205
  async function loadConfig(dir) {
158
206
  const raw = await loadRawConfig(dir);
207
+ const rawHooks = raw.hooks;
208
+ const resolvedWebSearch = rawHooks?.webSearch ?? rawHooks?.searchMode ?? CONFIG_DEFAULTS.hooks.webSearch;
209
+ let resolvedAgentDispatch;
210
+ if (rawHooks?.agentDispatch !== void 0) {
211
+ resolvedAgentDispatch = rawHooks.agentDispatch;
212
+ } else if (rawHooks?.dispatchMode !== void 0 && rawHooks.dispatchMode !== "inherit") {
213
+ resolvedAgentDispatch = rawHooks.dispatchMode;
214
+ } else if (rawHooks?.dispatchMode === "inherit") {
215
+ resolvedAgentDispatch = resolvedWebSearch;
216
+ } else if (rawHooks?.dispatchMode === void 0 && rawHooks?.searchMode !== void 0) {
217
+ resolvedAgentDispatch = resolvedWebSearch;
218
+ } else if (rawHooks?.dispatchMode === void 0 && rawHooks?.webSearch !== void 0 && rawHooks?.agentDispatch === void 0) {
219
+ resolvedAgentDispatch = CONFIG_DEFAULTS.hooks.agentDispatch;
220
+ } else {
221
+ resolvedAgentDispatch = CONFIG_DEFAULTS.hooks.agentDispatch;
222
+ }
159
223
  return {
160
224
  ...CONFIG_DEFAULTS,
161
225
  ...raw,
@@ -165,14 +229,18 @@ async function loadConfig(dir) {
165
229
  },
166
230
  install: { harness: raw.install?.harness ?? CONFIG_DEFAULTS.install.harness },
167
231
  hooks: {
168
- searchMode: raw.hooks?.searchMode ?? CONFIG_DEFAULTS.hooks.searchMode,
169
- stopNag: raw.hooks?.stopNag ?? CONFIG_DEFAULTS.hooks.stopNag
232
+ webSearch: resolvedWebSearch,
233
+ agentDispatch: resolvedAgentDispatch,
234
+ stopNag: rawHooks?.stopNag ?? CONFIG_DEFAULTS.hooks.stopNag,
235
+ sessionPrimer: rawHooks?.sessionPrimer ?? CONFIG_DEFAULTS.hooks.sessionPrimer
170
236
  },
171
237
  update: { mode: raw.update?.mode ?? CONFIG_DEFAULTS.update.mode }
172
238
  };
173
239
  }
174
240
  function resolveSettings(input) {
175
241
  const { config, flags, env, project } = input;
242
+ const webSearch = resolveHooksWebSearch(config);
243
+ const agentDispatch = resolveHooksAgentDispatch(config);
176
244
  return {
177
245
  maxAutoSpend: fileOrDefault("maxAutoSpend", config),
178
246
  sessionBudget: fileOrDefault("sessionBudget", config),
@@ -182,10 +250,16 @@ function resolveSettings(input) {
182
250
  baseUrl: resolveBaseUrl(config, flags, env),
183
251
  rpcUrl: fileOrDefault("rpcUrl", config),
184
252
  evalCohort: fileOrDefault("evalCohort", config),
253
+ bazaarPay: fileOrDefault("bazaarPay", config),
254
+ bazaarRegistries: fileOrDefault("bazaarRegistries", config),
185
255
  publishMode: resolvePublishMode({ config, project, env }),
186
256
  publishDefaultPrice: resolvePublishDefaultPrice({ config, project }),
187
- hooksSearchMode: resolveHooksSearchMode(config),
257
+ hooksWebSearch: webSearch,
258
+ hooksAgentDispatch: agentDispatch,
259
+ hooksSearchMode: webSearch,
260
+ hooksDispatchMode: agentDispatch,
188
261
  hooksStopNag: resolveHooksStopNag(config),
262
+ hooksSessionPrimer: resolveHooksSessionPrimer(config),
189
263
  updateMode: resolveUpdateMode(config)
190
264
  };
191
265
  }
@@ -194,16 +268,39 @@ function resolveUpdateMode(config) {
194
268
  if (fromFile !== void 0) return { value: fromFile, source: "file" };
195
269
  return { value: CONFIG_DEFAULTS.update.mode, source: "default" };
196
270
  }
271
+ function resolveHooksWebSearch(config) {
272
+ const hooks = config.hooks;
273
+ if (hooks?.webSearch !== void 0) return { value: hooks.webSearch, source: "file" };
274
+ if (hooks?.searchMode !== void 0) return { value: hooks.searchMode, source: "file" };
275
+ return { value: CONFIG_DEFAULTS.hooks.webSearch, source: "default" };
276
+ }
277
+ function resolveHooksAgentDispatch(config) {
278
+ const hooks = config.hooks;
279
+ if (hooks?.agentDispatch !== void 0) return { value: hooks.agentDispatch, source: "file" };
280
+ const legacy = hooks?.dispatchMode;
281
+ if (legacy !== void 0 && legacy !== "inherit") {
282
+ return { value: legacy, source: "file" };
283
+ }
284
+ if (legacy === "inherit") {
285
+ const webSearch = hooks?.webSearch ?? hooks?.searchMode ?? CONFIG_DEFAULTS.hooks.webSearch;
286
+ return { value: webSearch, source: "file" };
287
+ }
288
+ if (hooks?.searchMode !== void 0 && hooks?.dispatchMode === void 0 && hooks?.agentDispatch === void 0) {
289
+ const webSearch = hooks.webSearch ?? hooks.searchMode ?? CONFIG_DEFAULTS.hooks.webSearch;
290
+ return { value: webSearch, source: "file" };
291
+ }
292
+ return { value: CONFIG_DEFAULTS.hooks.agentDispatch, source: "default" };
293
+ }
294
+ function resolveHooksSessionPrimer(config) {
295
+ const fromFile = config.hooks?.sessionPrimer;
296
+ if (fromFile !== void 0) return { value: fromFile, source: "file" };
297
+ return { value: CONFIG_DEFAULTS.hooks.sessionPrimer, source: "default" };
298
+ }
197
299
  function resolveHooksStopNag(config) {
198
300
  const fromFile = config.hooks?.stopNag;
199
301
  if (fromFile !== void 0) return { value: fromFile, source: "file" };
200
302
  return { value: CONFIG_DEFAULTS.hooks.stopNag, source: "default" };
201
303
  }
202
- function resolveHooksSearchMode(config) {
203
- const fromFile = config.hooks?.searchMode;
204
- if (fromFile !== void 0) return { value: fromFile, source: "file" };
205
- return { value: CONFIG_DEFAULTS.hooks.searchMode, source: "default" };
206
- }
207
304
  var FULL_AUTO_DOWNGRADE_WARNING = 'Ignoring publish.mode "full-auto" from a committed .tenjin.json (cloning a repo must not enable auto-publish); using "auto". Add .tenjin.json to .gitignore to opt in.';
208
305
  function coercePublishMode(raw) {
209
306
  if (raw === void 0 || raw.length === 0) return void 0;
@@ -270,9 +367,11 @@ function isNotFound(err) {
270
367
  export {
271
368
  PublishModeSchema,
272
369
  parsePublishModeFlag,
273
- SearchHookModeSchema,
274
- parseSearchHookModeFlag,
370
+ WebSearchModeSchema,
371
+ parseAgentDispatchHookModeFlag,
372
+ parseWebSearchHookModeFlag,
275
373
  parseStopNagFlag,
374
+ parseSessionPrimerFlag,
276
375
  parseUpdateModeFlag,
277
376
  RawConfigSchema,
278
377
  SEND_MAX_UNSET,
@@ -280,6 +379,7 @@ export {
280
379
  CONFIG_KEYS,
281
380
  PUBLISH_CONFIG_KEYS,
282
381
  HOOKS_CONFIG_KEYS,
382
+ LEGACY_HOOKS_CONFIG_KEYS,
283
383
  UPDATE_CONFIG_KEYS,
284
384
  loadRawConfig,
285
385
  loadConfig,
@@ -287,4 +387,4 @@ export {
287
387
  resolvePublishMode,
288
388
  resolvePublishDefaultPrice
289
389
  };
290
- //# sourceMappingURL=chunk-LSWP7MU2.js.map
390
+ //# sourceMappingURL=chunk-U6VPKMGC.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/config.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { z } from 'zod';\nimport { CliError } from './errors';\nimport { PRODUCTION_ORIGIN } from './production-origin';\nimport { configPath } from './paths';\nimport { HARNESS_TARGETS } from './skill-wiring';\nimport { writeFileAtomic } from './atomic-json';\n\n/** A non-negative integer string in USDC atomic units (6-decimal base). */\nconst atomicString = z.string().regex(/^\\d+$/, 'expected an atomic USDC integer string');\n\n/** The publish consent mode (B3, D38). `full-auto` is loosening-gated, below. */\nexport const PublishModeSchema = z.enum(['review', 'auto', 'full-auto']);\nexport type PublishMode = z.infer<typeof PublishModeSchema>;\n\n/**\n * Validate a publish-mode value at a command edge (`--mode`, `--publish-mode`):\n * an unrecognized value is USAGE (exit 2), never silently dropped. `flagName` is\n * woven into the message so the failing flag is named.\n */\nexport function parsePublishModeFlag(value: string, flagName: string): PublishMode {\n const parsed = PublishModeSchema.safeParse(value);\n if (parsed.success) return parsed.data;\n throw new CliError('USAGE', `Invalid ${flagName} ${JSON.stringify(value)}`, {\n fix: 'Use \"review\", \"auto\", or \"full-auto\".',\n });\n}\n\n/**\n * The publish block (B3): `mode` governs the confirm cascade a `publish` runs,\n * `defaultPrice` is the atomic USDC price a card is published at when no\n * per-publish price is given. Stored atomic like the spend keys.\n */\nconst PublishConfigSchema = z.object({\n mode: PublishModeSchema,\n defaultPrice: atomicString,\n});\n\n/**\n * What the harness WebSearch hook does when the agent is about to search the web\n * (see lib/hook-scripts.ts). `auto` asks Tenjin first and mentions a tested\n * answer when one exists, `remind` says the marketplace is there without sending\n * the query anywhere, `off` leaves the installed hook inert.\n */\nexport const WebSearchModeSchema = z.enum(['auto', 'remind', 'off']);\nexport type WebSearchMode = z.infer<typeof WebSearchModeSchema>;\n\n/**\n * What the subagent-dispatch hook does, on its own switch. Disjoint from\n * `hooks.webSearch`: both default `auto`, no `inherit`. The split exists because\n * a dispatch prompt is the most sensitive payload any hook sees: a fleet can keep\n * `webSearch auto` and still run dispatch as `remind` (a local nudge, nothing\n * sent) or `off`.\n */\nexport const AgentDispatchModeSchema = z.enum(['auto', 'remind', 'off']);\nexport type AgentDispatchMode = z.infer<typeof AgentDispatchModeSchema>;\n\n// Backward compat aliases — old keys still parse, new code uses the WebSearch/AgentDispatch names.\nexport const SearchHookModeSchema = WebSearchModeSchema;\nexport type SearchHookMode = WebSearchMode;\n/** Legacy: accepted on read for old config files that stored `inherit`. */\nexport const DispatchHookModeSchema = z.enum(['inherit', 'auto', 'remind', 'off']);\nexport type DispatchHookMode = z.infer<typeof DispatchHookModeSchema>;\n\n/** Validate a dispatch-hook mode at a command edge for the new disjoint key. */\nexport function parseAgentDispatchHookModeFlag(value: string, flagName: string): AgentDispatchMode {\n const parsed = AgentDispatchModeSchema.safeParse(value);\n if (parsed.success) return parsed.data;\n throw new CliError('USAGE', `Invalid ${flagName} ${JSON.stringify(value)}`, {\n fix: 'Use \"auto\", \"remind\", or \"off\".',\n });\n}\n\n/** Validate a web-search hook mode at a command edge. */\nexport function parseWebSearchHookModeFlag(value: string, flagName: string): WebSearchMode {\n const parsed = WebSearchModeSchema.safeParse(value);\n if (parsed.success) return parsed.data;\n throw new CliError('USAGE', `Invalid ${flagName} ${JSON.stringify(value)}`, {\n fix: 'Use \"auto\", \"remind\", or \"off\".',\n });\n}\n\n/** @deprecated use parseAgentDispatchHookModeFlag — kept for `hooks.dispatchMode` alias */\nexport function parseDispatchHookModeFlag(value: string, flagName: string): DispatchHookMode {\n const parsed = DispatchHookModeSchema.safeParse(value);\n if (parsed.success) return parsed.data;\n throw new CliError('USAGE', `Invalid ${flagName} ${JSON.stringify(value)}`, {\n fix: 'Use \"inherit\", \"auto\", \"remind\", or \"off\".',\n });\n}\n\n/**\n * @deprecated use parseWebSearchHookModeFlag — kept for `hooks.searchMode` alias\n */\nexport function parseSearchHookModeFlag(value: string, flagName: string): SearchHookMode {\n return parseWebSearchHookModeFlag(value, flagName);\n}\n\n/**\n * Which open loops the Stop hook may raise at the end of a turn.\n *\n * `deliberate-only` is the middle setting the two-value toggle was missing. The\n * hook has two arms, and they are not equally welcome: a deliberate `tenjin\n * search` MISS is a question the agent chose to ask, while the batched\n * ride-along web searches are a firehose in a research session. With only `on`\n * and `off`, silencing the noisy arm meant silencing both, and nothing ever\n * prompts turning them back on (tenjin-agent #162). This keeps the high-signal\n * arm and drops the batch.\n */\nexport const StopNagModeSchema = z.enum(['on', 'deliberate-only', 'off']);\nexport type StopNagMode = z.infer<typeof StopNagModeSchema>;\n\nexport function parseStopNagFlag(value: string, flagName: string): StopNagMode {\n const parsed = StopNagModeSchema.safeParse(value);\n if (parsed.success) return parsed.data;\n throw new CliError('USAGE', `Invalid ${flagName} ${JSON.stringify(value)}`, {\n fix: 'Use \"on\", \"deliberate-only\", or \"off\".',\n });\n}\n\n/** Whether the SessionStart hook prints its primer. Two values and no middle\n * one: one paragraph either belongs at the top of a session or does not. */\nexport const SessionPrimerModeSchema = z.enum(['on', 'off']);\nexport type SessionPrimerMode = z.infer<typeof SessionPrimerModeSchema>;\n\nexport function parseSessionPrimerFlag(value: string, flagName: string): SessionPrimerMode {\n const parsed = SessionPrimerModeSchema.safeParse(value);\n if (parsed.success) return parsed.data;\n throw new CliError('USAGE', `Invalid ${flagName} ${JSON.stringify(value)}`, {\n fix: 'Use \"on\" or \"off\".',\n });\n}\n\n/**\n * The harness-hook block. EVERY key is read by the installed scripts at run\n * time, which is what makes them runtime toggles rather than install-time\n * choices: `tenjin config set hooks.webSearch off`, `hooks.agentDispatch off`,\n * `hooks.stopNag off` or `hooks.sessionPrimer off` silences a hook immediately,\n * with no re-install and nothing to unwire. The scripts stay registered and\n * no-op, which is also what lets turning one back on be a single `config set`.\n */\nconst HooksConfigSchema = z.object({\n webSearch: WebSearchModeSchema,\n agentDispatch: AgentDispatchModeSchema,\n stopNag: StopNagModeSchema,\n sessionPrimer: SessionPrimerModeSchema,\n});\n\n/**\n * Legacy hook fields kept for one release so an old config.json still parses.\n * `searchMode` maps to `webSearch`; `dispatchMode` (including `inherit`) maps\n * to `agentDispatch` per the migration in loadConfig / resolve* below.\n */\nconst LegacyHooksFields = z.object({\n searchMode: SearchHookModeSchema.optional(),\n dispatchMode: DispatchHookModeSchema.optional(),\n});\n\n/**\n * What the daily update check is allowed to do about a newer version.\n *\n * `nudge` reports it — one dim line for a human at a terminal, and an\n * `updateAvailable` field on the JSON envelope for everyone else, which is how\n * an agent learns to run `tenjin update` itself. `off` reports neither and stops\n * asking npm entirely.\n *\n * There is deliberately no mode that installs on its own. Replacing the binary\n * under a running agent has no safe moment in a CLI that starts a fresh process\n * per invocation: \"next start\" IS \"mid-session\". Reporting is the part that was\n * missing, so reporting is what this key controls.\n */\nexport const UpdateModeSchema = z.enum(['nudge', 'off']);\nexport type UpdateMode = z.infer<typeof UpdateModeSchema>;\n\nconst UpdateConfigSchema = z.object({\n mode: UpdateModeSchema,\n});\n\nexport function parseUpdateModeFlag(value: string, flagName: string): UpdateMode {\n const parsed = UpdateModeSchema.safeParse(value);\n if (parsed.success) return parsed.data;\n throw new CliError('USAGE', `Invalid ${flagName} ${JSON.stringify(value)}`, {\n fix: 'Use \"nudge\" or \"off\".',\n });\n}\n\n/**\n * What `install` recorded about its OWN targets. `harness` is the explicit\n * `--harness` set of the last install that passed the flag, and it exists so\n * `doctor` keeps judging a directory the user named by hand: detection cannot see a\n * harness this CLI does not probe for, and without the record such a directory is a\n * target for one run and invisible to every later check. Written by `install`, not a\n * `config set` key.\n */\nconst InstallConfigSchema = z.object({\n harness: z.array(z.enum(HARNESS_TARGETS)),\n});\n\n/**\n * The persisted config shape. Spend keys are stored atomic (accepted as decimal\n * USD at the command edge, see lib/money); `confirm` is the stored form\n * \"always\" | \"above:<atomic>\". These are client-enforced guardrails, not a\n * security boundary — any process that runs the CLI can also edit this file.\n */\nexport const ConfigSchema = z.object({\n maxAutoSpend: atomicString,\n sessionBudget: atomicString,\n confirm: z.union([z.literal('always'), z.string().regex(/^above:\\d+$/)]),\n /**\n * Hard per-send cap for `tenjin send`, NOT satisfiable by --yes or a prompt\n * (the spend-policy posture): an atomic amount caps each send, \"0\" disables\n * the verb entirely, and \"none\" = explicitly uncapped (send exists to drain\n * the wallet, but uncapped is an opt-in, never a default). The key has NO\n * usable default: absent from config.json, `tenjin send` refuses until it is\n * set (see resolveSendMaxAmount). Client-enforced like every spend key (see\n * the note above).\n */\n sendMaxAmount: z.union([z.literal('none'), atomicString]),\n allowlistCreators: z.array(z.string()),\n baseUrl: z.url(),\n rpcUrl: z.url(),\n /**\n * Evaluation-cohort opt-in (spec 09 §3): when true, search sends\n * X-Tenjin-Eval-Cohort: 1 and the server stores the generalized question for\n * 90 days. Off by default; no query text is retained server-side without it.\n */\n evalCohort: z.boolean(),\n /**\n * The Bazaar pay lane opt-in: when true, `tenjin pay` may pay a NON-Tenjin\n * x402 endpoint, provided a configured registry lists that exact resource and\n * the live 402 matches the listed deal. Off by default; `install` asks once.\n * The lane's teaching is the OPTIONAL tenjin-pay skill, present on disk\n * exactly while this is on (lib/skill-placement).\n */\n bazaarPay: z.boolean(),\n /** x402 discovery registries (facilitator base URLs) `discover` queries and\n * the Bazaar pay lane verifies against. */\n bazaarRegistries: z.array(z.url()),\n publish: PublishConfigSchema,\n install: InstallConfigSchema,\n hooks: HooksConfigSchema,\n update: UpdateConfigSchema,\n});\nexport type Config = z.infer<typeof ConfigSchema>;\n\n/**\n * Values as they may appear in config.json — every known key optional; absent =\n * default. `.passthrough()` PRESERVES unknown keys through load + persist: without\n * it an older binary's `config set` would strip (and re-serialize away) any newer\n * block a later CLI wrote, e.g. B3's `publish.*`. Known keys are still validated;\n * unknown keys ride along untouched.\n */\nexport const RawConfigSchema = ConfigSchema.partial()\n // The publish block is itself partial + passthrough: `config set publish.mode`\n // writes only the one subkey, and a subkey a newer CLI adds (e.g. publish.*\n // beyond mode/defaultPrice) survives an older binary's set, same reason the\n // outer object passes unknown keys through.\n .extend({\n publish: PublishConfigSchema.partial().passthrough().optional(),\n install: InstallConfigSchema.partial().passthrough().optional(),\n hooks: HooksConfigSchema.partial().merge(LegacyHooksFields).passthrough().optional(),\n update: UpdateConfigSchema.partial().passthrough().optional(),\n })\n .passthrough();\nexport type PartialConfig = z.infer<typeof RawConfigSchema>;\n\n/**\n * The resolved-view sentinel for an absent sendMaxAmount. Never a persistable\n * value (ConfigSchema rejects it, and `config set` has no way to produce it);\n * while the resolved value is this sentinel, `tenjin send` refuses —\n * require-set-before-first-send.\n */\nexport const SEND_MAX_UNSET = 'unset';\n\n/**\n * Registries verified keyless (CDP/UV on 2026-08-14, PayAI on 2026-08-18): all\n * answer GET /discovery/resources with no credential in the Bazaar envelope\n * the sweep parses. CDP's Bazaar is settlement-derived (it indexes what its\n * facilitator settles, Tenjin's endpoints included); UltraVioleta is the\n * registry Tenjin also announces to; PayAI's facilitator is settlement-derived\n * like CDP's (26k+ listings at verification). PayAI has no /discovery/search\n * and ignores payTo filters, the same shapes UV and CDP already exhibit, which\n * the query sweep's per-registry errors and the stored-sweep evidence cover.\n */\nexport const DEFAULT_BAZAAR_REGISTRIES = [\n 'https://api.cdp.coinbase.com/platform/v2/x402',\n 'https://facilitator.ultravioletadao.xyz',\n 'https://facilitator.payai.network',\n];\n\nexport const CONFIG_DEFAULTS: Config = {\n maxAutoSpend: '0',\n sessionBudget: '0',\n confirm: 'always',\n // A type placeholder only, never honored: Config requires every key (and\n // CONFIG_KEYS derives from these). resolveSendMaxAmount never reads it — an\n // absent key resolves to SEND_MAX_UNSET and `tenjin send` refuses until the\n // cap is set. '0' (send disabled) rather than 'none' (uncapped) so that if a\n // future caller ever DOES read the cap through loadConfig/fileOrDefault, the\n // leak fails closed instead of silently running uncapped.\n sendMaxAmount: '0',\n allowlistCreators: [],\n baseUrl: PRODUCTION_ORIGIN,\n rpcUrl: 'https://mainnet.base.org',\n evalCohort: false,\n bazaarPay: false,\n bazaarRegistries: DEFAULT_BAZAAR_REGISTRIES,\n publish: { mode: 'review', defaultPrice: '100000' },\n install: { harness: [] },\n // `auto` is the default because the hook exists to be useful without being\n // asked for; the disclosure and the undo ride the install output, and `off`\n // leaves the installed script inert without touching settings.json. Both hooks\n // are `auto` by default and disjoint — no `inherit`.\n hooks: { webSearch: 'auto', agentDispatch: 'auto', stopNag: 'on', sessionPrimer: 'on' },\n update: { mode: 'nudge' },\n};\n\n/**\n * Scalar keys `config get/set/list` render one line each. The nested blocks are\n * excluded: `publish` and `hooks` are addressed by their dotted keys (see\n * PUBLISH_CONFIG_KEYS / HOOKS_CONFIG_KEYS), and `install` is a record `install`\n * writes about itself rather than a setting to hand-edit, so none is ever a bare\n * scalar.\n */\nexport type ScalarConfigKey = Exclude<keyof Config, 'publish' | 'install' | 'hooks' | 'update'>;\nconst NESTED_CONFIG_KEYS: ReadonlySet<string> = new Set(['publish', 'install', 'hooks', 'update']);\nexport const CONFIG_KEYS = (Object.keys(CONFIG_DEFAULTS) as Array<keyof Config>).filter(\n (key): key is ScalarConfigKey => !NESTED_CONFIG_KEYS.has(key),\n);\n\n/** The dotted keys `config get/set` accept for the nested publish block. */\nexport const PUBLISH_CONFIG_KEYS = ['publish.mode', 'publish.defaultPrice'] as const;\nexport type PublishConfigKey = (typeof PUBLISH_CONFIG_KEYS)[number];\n\n/** The dotted keys `config get/set` accept for the nested hooks block. */\nexport const HOOKS_CONFIG_KEYS = [\n 'hooks.webSearch',\n 'hooks.agentDispatch',\n 'hooks.stopNag',\n 'hooks.sessionPrimer',\n] as const;\nexport type HooksConfigKey = (typeof HOOKS_CONFIG_KEYS)[number];\n\n/** Legacy aliases still accepted on `config set/get` for one release. */\nexport const LEGACY_HOOKS_CONFIG_KEYS = ['hooks.searchMode', 'hooks.dispatchMode'] as const;\nexport type LegacyHooksConfigKey = (typeof LEGACY_HOOKS_CONFIG_KEYS)[number];\n\n/** The dotted key `config get/set` accepts for the nested update block. */\nexport const UPDATE_CONFIG_KEYS = ['update.mode'] as const;\nexport type UpdateConfigKey = (typeof UPDATE_CONFIG_KEYS)[number];\n\n/**\n * Read and validate config.json WITHOUT applying defaults, so provenance can\n * distinguish \"present in file\" from \"absent\". Missing file is fine (returns\n * {}); malformed JSON or a failed schema is CONFIG_INVALID with a fix.\n */\nexport async function loadRawConfig(dir: string): Promise<PartialConfig> {\n const path = configPath(dir);\n let raw: string;\n try {\n raw = await readFile(path, 'utf8');\n } catch (err) {\n if (isNotFound(err)) return {};\n throw new CliError('CONFIG_INVALID', `Could not read config at ${path}`, {\n fix: `Check file permissions on ${path}.`,\n cause: err,\n });\n }\n let json: unknown;\n try {\n json = JSON.parse(raw);\n } catch (err) {\n throw new CliError('CONFIG_INVALID', `Config at ${path} is not valid JSON`, {\n fix: `Fix the JSON syntax in ${path}, or delete it to restore defaults.`,\n cause: err,\n });\n }\n const parsed = RawConfigSchema.safeParse(json);\n if (!parsed.success) {\n throw new CliError('CONFIG_INVALID', `Config at ${path} is invalid`, {\n fix: `Correct the reported keys in ${path}, or delete it to restore defaults.`,\n details: parsed.error.issues,\n });\n }\n return parsed.data;\n}\n\n/** File values merged over defaults — the effective persisted config. The nested\n * publish block is merged per-subkey so a file that sets only publish.mode keeps\n * the default defaultPrice (a shallow spread would drop it). */\nexport async function loadConfig(dir: string): Promise<Config> {\n const raw = await loadRawConfig(dir);\n const rawHooks = raw.hooks as\n | {\n webSearch?: WebSearchMode;\n agentDispatch?: AgentDispatchMode;\n searchMode?: WebSearchMode;\n dispatchMode?: DispatchHookMode;\n stopNag?: StopNagMode;\n sessionPrimer?: SessionPrimerMode;\n }\n | undefined;\n // Backward compat: new webSearch wins, else legacy searchMode, else default.\n const resolvedWebSearch =\n rawHooks?.webSearch ?? rawHooks?.searchMode ?? CONFIG_DEFAULTS.hooks.webSearch;\n // Migration for agentDispatch: new key wins; else legacy dispatchMode (if not inherit) wins;\n // else if legacy is inherit or missing but webSearch resolved, copy webSearch; else default.\n // Since dispatch never shipped to npm (only searchMode did), the elaborate branch is only\n // for the unreleased `inherit` branch; the important legacy is searchMode -> webSearch.\n let resolvedAgentDispatch: AgentDispatchMode;\n if (rawHooks?.agentDispatch !== undefined) {\n resolvedAgentDispatch = rawHooks.agentDispatch;\n } else if (rawHooks?.dispatchMode !== undefined && rawHooks.dispatchMode !== 'inherit') {\n resolvedAgentDispatch = rawHooks.dispatchMode as AgentDispatchMode;\n } else if (rawHooks?.dispatchMode === 'inherit') {\n resolvedAgentDispatch = resolvedWebSearch;\n } else if (rawHooks?.dispatchMode === undefined && rawHooks?.searchMode !== undefined) {\n // Old file had only searchMode (dispatch inherited): preserve previous behavior for one release.\n resolvedAgentDispatch = resolvedWebSearch;\n } else if (\n rawHooks?.dispatchMode === undefined &&\n rawHooks?.webSearch !== undefined &&\n rawHooks?.agentDispatch === undefined\n ) {\n // New file with only webSearch set after the rename — keep disjoint: do NOT copy.\n resolvedAgentDispatch = CONFIG_DEFAULTS.hooks.agentDispatch;\n } else {\n resolvedAgentDispatch = CONFIG_DEFAULTS.hooks.agentDispatch;\n }\n // If the file had neither new nor legacy hooks at all, loadSettings' file-or-default\n // semantics would say `default` rather than `file` — but loadConfig's job is to produce\n // the effective Config object, so defaults are correct here regardless. The provenance\n // question lives in resolve* below.\n return {\n ...CONFIG_DEFAULTS,\n ...raw,\n publish: {\n mode: raw.publish?.mode ?? CONFIG_DEFAULTS.publish.mode,\n defaultPrice: raw.publish?.defaultPrice ?? CONFIG_DEFAULTS.publish.defaultPrice,\n },\n install: { harness: raw.install?.harness ?? CONFIG_DEFAULTS.install.harness },\n hooks: {\n webSearch: resolvedWebSearch,\n agentDispatch: resolvedAgentDispatch,\n stopNag: rawHooks?.stopNag ?? CONFIG_DEFAULTS.hooks.stopNag,\n sessionPrimer: rawHooks?.sessionPrimer ?? CONFIG_DEFAULTS.hooks.sessionPrimer,\n },\n update: { mode: raw.update?.mode ?? CONFIG_DEFAULTS.update.mode },\n };\n}\n\nexport type Provenance = 'default' | 'file' | 'project' | 'env' | 'flag';\n\nexport interface ResolvedSetting<T> {\n value: T;\n source: Provenance;\n}\n\n/**\n * The per-project `.tenjin.json` layer (B3, D38): publish overrides discovered by\n * walking up from cwd, plus whether that file is gitignored. `gitignored` gates\n * `full-auto` — a committed file requesting it is downgraded (loosening gate).\n */\nexport interface ProjectPublishLayer {\n publish?: { mode?: PublishMode; defaultPrice?: string };\n gitignored: boolean;\n}\n\n/** publish.mode resolution: value, source, and the downgrade warning (if any). */\nexport interface PublishModeResolution {\n value: PublishMode;\n source: Provenance;\n /** Set when a committed `.tenjin.json`'s `full-auto` was downgraded to `auto`. */\n downgradedWarning?: string;\n}\n\n/** Effective value + where it came from, per key. What `config` (bare) renders. */\nexport interface EffectiveSettings {\n maxAutoSpend: ResolvedSetting<string>;\n sessionBudget: ResolvedSetting<string>;\n confirm: ResolvedSetting<string>;\n sendMaxAmount: ResolvedSetting<string>;\n allowlistCreators: ResolvedSetting<string[]>;\n baseUrl: ResolvedSetting<string>;\n rpcUrl: ResolvedSetting<string>;\n evalCohort: ResolvedSetting<boolean>;\n bazaarPay: ResolvedSetting<boolean>;\n bazaarRegistries: ResolvedSetting<string[]>;\n publishMode: PublishModeResolution;\n publishDefaultPrice: ResolvedSetting<string>;\n hooksWebSearch: ResolvedSetting<WebSearchMode>;\n hooksAgentDispatch: ResolvedSetting<AgentDispatchMode>;\n hooksStopNag: ResolvedSetting<StopNagMode>;\n hooksSessionPrimer: ResolvedSetting<SessionPrimerMode>;\n updateMode: ResolvedSetting<UpdateMode>;\n /** @deprecated use hooksWebSearch — kept for backward compat */\n hooksSearchMode: ResolvedSetting<WebSearchMode>;\n /** @deprecated use hooksAgentDispatch — kept for backward compat (never `inherit`) */\n hooksDispatchMode: ResolvedSetting<AgentDispatchMode>;\n}\n\n/** CLI flags that participate in settings precedence (`--base-url`). */\nexport interface SettingsFlags {\n baseUrl?: string;\n}\n\nexport interface ResolveSettingsInput {\n /** Raw file values (present keys only) — from loadRawConfig, not loadConfig. */\n config: PartialConfig;\n flags: SettingsFlags;\n env: NodeJS.ProcessEnv;\n /** The nearest `.tenjin.json` layer, when one was found (see publish-settings). */\n project?: ProjectPublishLayer;\n}\n\n/**\n * Apply precedence flag > env > file > default per key, returning each effective\n * value with its source. In B1 only baseUrl has flag/env overrides\n * (`--base-url`, TENJIN_BASE_URL); the rest resolve file-or-default. B3 adds the\n * publish keys, which additionally fold in the per-project `.tenjin.json` layer.\n */\nexport function resolveSettings(input: ResolveSettingsInput): EffectiveSettings {\n const { config, flags, env, project } = input;\n const webSearch = resolveHooksWebSearch(config);\n const agentDispatch = resolveHooksAgentDispatch(config);\n return {\n maxAutoSpend: fileOrDefault('maxAutoSpend', config),\n sessionBudget: fileOrDefault('sessionBudget', config),\n confirm: fileOrDefault('confirm', config),\n sendMaxAmount: resolveSendMaxAmount(config),\n allowlistCreators: fileOrDefault('allowlistCreators', config),\n baseUrl: resolveBaseUrl(config, flags, env),\n rpcUrl: fileOrDefault('rpcUrl', config),\n evalCohort: fileOrDefault('evalCohort', config),\n bazaarPay: fileOrDefault('bazaarPay', config),\n bazaarRegistries: fileOrDefault('bazaarRegistries', config),\n publishMode: resolvePublishMode({ config, project, env }),\n publishDefaultPrice: resolvePublishDefaultPrice({ config, project }),\n hooksWebSearch: webSearch,\n hooksAgentDispatch: agentDispatch,\n hooksSearchMode: webSearch,\n hooksDispatchMode: agentDispatch,\n hooksStopNag: resolveHooksStopNag(config),\n hooksSessionPrimer: resolveHooksSessionPrimer(config),\n updateMode: resolveUpdateMode(config),\n };\n}\n\n/** update.mode: file or default, no env or flag. Every surface that reports a\n * newer version reads this one resolved value, so they cannot disagree. */\nfunction resolveUpdateMode(config: PartialConfig): ResolvedSetting<UpdateMode> {\n const fromFile = config.update?.mode;\n if (fromFile !== undefined) return { value: fromFile, source: 'file' };\n return { value: CONFIG_DEFAULTS.update.mode, source: 'default' };\n}\n\n/** hooks.webSearch: file or default. Legacy `hooks.searchMode` counts as `file`. */\nexport function resolveHooksWebSearch(config: PartialConfig): ResolvedSetting<WebSearchMode> {\n const hooks = config.hooks as\n { webSearch?: WebSearchMode; searchMode?: WebSearchMode } | undefined;\n if (hooks?.webSearch !== undefined) return { value: hooks.webSearch, source: 'file' };\n if (hooks?.searchMode !== undefined) return { value: hooks.searchMode, source: 'file' };\n return { value: CONFIG_DEFAULTS.hooks.webSearch, source: 'default' };\n}\n\n/** @deprecated use resolveHooksWebSearch */\nexport function resolveHooksSearchMode(config: PartialConfig): ResolvedSetting<WebSearchMode> {\n return resolveHooksWebSearch(config);\n}\n\n/** hooks.agentDispatch: file or default, disjoint from webSearch. Legacy `dispatchMode` (including `inherit`) honoured on read. */\nexport function resolveHooksAgentDispatch(\n config: PartialConfig,\n): ResolvedSetting<AgentDispatchMode> {\n const hooks = config.hooks as\n | {\n agentDispatch?: AgentDispatchMode;\n dispatchMode?: DispatchHookMode;\n webSearch?: WebSearchMode;\n searchMode?: WebSearchMode;\n }\n | undefined;\n if (hooks?.agentDispatch !== undefined) return { value: hooks.agentDispatch, source: 'file' };\n const legacy = hooks?.dispatchMode;\n if (legacy !== undefined && legacy !== 'inherit') {\n return { value: legacy as AgentDispatchMode, source: 'file' };\n }\n if (legacy === 'inherit') {\n const webSearch = hooks?.webSearch ?? hooks?.searchMode ?? CONFIG_DEFAULTS.hooks.webSearch;\n return { value: webSearch as AgentDispatchMode, source: 'file' };\n }\n // File had only legacy searchMode (dispatch inherited implicitly) — preserve prior behaviour for one release.\n if (\n hooks?.searchMode !== undefined &&\n hooks?.dispatchMode === undefined &&\n hooks?.agentDispatch === undefined\n ) {\n const webSearch = hooks.webSearch ?? hooks.searchMode ?? CONFIG_DEFAULTS.hooks.webSearch;\n return { value: webSearch as AgentDispatchMode, source: 'file' };\n }\n return { value: CONFIG_DEFAULTS.hooks.agentDispatch, source: 'default' };\n}\n\n/** @deprecated use resolveHooksAgentDispatch — `inherit` never surfaces; value is already resolved */\nexport function resolveHooksDispatchMode(\n config: PartialConfig,\n): ResolvedSetting<AgentDispatchMode> {\n return resolveHooksAgentDispatch(config);\n}\n\n/** hooks.sessionPrimer: file or default, same shape as hooks.webSearch. */\nfunction resolveHooksSessionPrimer(config: PartialConfig): ResolvedSetting<SessionPrimerMode> {\n const fromFile = (config.hooks as { sessionPrimer?: SessionPrimerMode } | undefined)\n ?.sessionPrimer;\n if (fromFile !== undefined) return { value: fromFile, source: 'file' };\n return { value: CONFIG_DEFAULTS.hooks.sessionPrimer, source: 'default' };\n}\n\n/** hooks.stopNag: file or default, same shape as hooks.webSearch. */\nfunction resolveHooksStopNag(config: PartialConfig): ResolvedSetting<StopNagMode> {\n const fromFile = (config.hooks as { stopNag?: StopNagMode } | undefined)?.stopNag;\n if (fromFile !== undefined) return { value: fromFile, source: 'file' };\n return { value: CONFIG_DEFAULTS.hooks.stopNag, source: 'default' };\n}\n\n/**\n * The loosening gate (D38): a committed (not-gitignored) `.tenjin.json` requesting\n * `full-auto` is downgraded to `auto`, never silently honored — cloning a repo\n * must not enable auto-publish. `full-auto` from global config / env / flag (all\n * inherently local, not cloned) is always honored.\n */\nconst FULL_AUTO_DOWNGRADE_WARNING =\n 'Ignoring publish.mode \"full-auto\" from a committed .tenjin.json (cloning a repo must not enable auto-publish); using \"auto\". Add .tenjin.json to .gitignore to opt in.';\n\nfunction coercePublishMode(raw: string | undefined): PublishMode | undefined {\n if (raw === undefined || raw.length === 0) return undefined;\n const parsed = PublishModeSchema.safeParse(raw);\n return parsed.success ? parsed.data : undefined;\n}\n\n/**\n * Resolve publish.mode through global file < project `.tenjin.json` < env\n * (TENJIN_PUBLISH_MODE) < flag (`--mode`). Total: an invalid env/flag value is\n * ignored (validation lives at the command edge, like baseUrl). The project\n * layer's `full-auto` is gated on that file being gitignored.\n */\nexport function resolvePublishMode(input: {\n config: PartialConfig;\n project?: ProjectPublishLayer;\n env: NodeJS.ProcessEnv;\n flag?: string;\n}): PublishModeResolution {\n const { config, project, env, flag } = input;\n let winner: PublishModeResolution = { value: CONFIG_DEFAULTS.publish.mode, source: 'default' };\n\n const fromFile = config.publish?.mode;\n if (fromFile !== undefined) winner = { value: fromFile, source: 'file' };\n\n if (project !== undefined && project.publish?.mode !== undefined) {\n const fromProject = project.publish.mode;\n if (fromProject === 'full-auto' && !project.gitignored) {\n winner = { value: 'auto', source: 'project', downgradedWarning: FULL_AUTO_DOWNGRADE_WARNING };\n } else {\n winner = { value: fromProject, source: 'project' };\n }\n }\n\n const fromEnv = coercePublishMode(env.TENJIN_PUBLISH_MODE);\n if (fromEnv !== undefined) winner = { value: fromEnv, source: 'env' };\n\n const fromFlag = coercePublishMode(flag);\n if (fromFlag !== undefined) winner = { value: fromFlag, source: 'flag' };\n\n return winner;\n}\n\n/** Resolve publish.defaultPrice (atomic) through global file < project < default. */\nexport function resolvePublishDefaultPrice(input: {\n config: PartialConfig;\n project?: ProjectPublishLayer;\n}): ResolvedSetting<string> {\n const { config, project } = input;\n let result: ResolvedSetting<string> = {\n value: CONFIG_DEFAULTS.publish.defaultPrice,\n source: 'default',\n };\n if (config.publish?.defaultPrice !== undefined) {\n result = { value: config.publish.defaultPrice, source: 'file' };\n }\n if (project?.publish?.defaultPrice !== undefined) {\n result = { value: project.publish.defaultPrice, source: 'project' };\n }\n return result;\n}\n\n/** Persist a full, validated config via the atomic writer (0700 dir, 0644 file). */\nexport async function writeConfig(dir: string, config: Config): Promise<void> {\n const validated = ConfigSchema.parse(config);\n await writeFileAtomic(configPath(dir), `${JSON.stringify(validated, null, 2)}\\n`, {\n mode: 0o644,\n dirMode: 0o700,\n });\n}\n\n/**\n * sendMaxAmount deliberately bypasses fileOrDefault: it has no usable default\n * (the operator's require-set-before-first-send posture). Absent from\n * config.json it resolves to the SEND_MAX_UNSET sentinel with source 'default',\n * which `tenjin send` refuses outright — the cap must be set to an amount, \"0\"\n * (disable), or an explicit \"none\" (uncapped opt-in) before the first send.\n */\nfunction resolveSendMaxAmount(config: PartialConfig): ResolvedSetting<string> {\n if (config.sendMaxAmount !== undefined) return { value: config.sendMaxAmount, source: 'file' };\n return { value: SEND_MAX_UNSET, source: 'default' };\n}\n\nfunction fileOrDefault<K extends keyof Config>(\n key: K,\n config: PartialConfig,\n): ResolvedSetting<Config[K]> {\n const fromFile = config[key];\n // PartialConfig[K] is Config[K] | undefined; narrowing an indexed access of a\n // type parameter doesn't refine K, so assert the excluded-undefined type.\n if (fromFile !== undefined) return { value: fromFile as Config[K], source: 'file' };\n return { value: CONFIG_DEFAULTS[key], source: 'default' };\n}\n\nfunction resolveBaseUrl(\n config: PartialConfig,\n flags: SettingsFlags,\n env: NodeJS.ProcessEnv,\n): ResolvedSetting<string> {\n if (flags.baseUrl !== undefined && flags.baseUrl.length > 0) {\n return { value: flags.baseUrl, source: 'flag' };\n }\n const fromEnv = env.TENJIN_BASE_URL;\n if (fromEnv !== undefined && fromEnv.length > 0) {\n return { value: fromEnv, source: 'env' };\n }\n if (config.baseUrl !== undefined) return { value: config.baseUrl, source: 'file' };\n return { value: CONFIG_DEFAULTS.baseUrl, source: 'default' };\n}\n\nfunction isNotFound(err: unknown): boolean {\n return (\n typeof err === 'object' &&\n err !== null &&\n 'code' in err &&\n (err as { code?: unknown }).code === 'ENOENT'\n );\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,gBAAgB;AASzB,IAAM,eAAe,iBAAE,OAAO,EAAE,MAAM,SAAS,wCAAwC;AAGhF,IAAM,oBAAoB,iBAAE,KAAK,CAAC,UAAU,QAAQ,WAAW,CAAC;AAQhE,SAAS,qBAAqB,OAAe,UAA+B;AACjF,QAAM,SAAS,kBAAkB,UAAU,KAAK;AAChD,MAAI,OAAO,QAAS,QAAO,OAAO;AAClC,QAAM,IAAI,SAAS,SAAS,WAAW,QAAQ,IAAI,KAAK,UAAU,KAAK,CAAC,IAAI;AAAA,IAC1E,KAAK;AAAA,EACP,CAAC;AACH;AAOA,IAAM,sBAAsB,iBAAE,OAAO;AAAA,EACnC,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;AAQM,IAAM,sBAAsB,iBAAE,KAAK,CAAC,QAAQ,UAAU,KAAK,CAAC;AAU5D,IAAM,0BAA0B,iBAAE,KAAK,CAAC,QAAQ,UAAU,KAAK,CAAC;AAIhE,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AAO,OAAO,SAAS,QAAQ,OAAO;AACjF,SAAO,EAAE,OAAO,gBAAgB,SAAS,QAAQ,UAAU;AAC7D;AAEA,SAAS,WAAW,KAAuB;AACzC,SACE,OAAO,QAAQ,YACf,QAAQ,QACR,UAAU,OACT,IAA2B,SAAS;AAEzC;","names":[]}
@@ -1,22 +1,22 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
2
  import {
3
3
  fetchRead
4
- } from "./chunk-PCX2JQ2J.js";
4
+ } from "./chunk-LRYV3SK7.js";
5
5
  import {
6
6
  headingOutline
7
7
  } from "./chunk-SGK2B724.js";
8
8
  import {
9
9
  resolveResourceRef
10
- } from "./chunk-4Y53PDH6.js";
10
+ } from "./chunk-VJQKL3YH.js";
11
11
  import {
12
12
  sanitizeForTerminal
13
- } from "./chunk-B676GPS2.js";
13
+ } from "./chunk-OLWTRUTS.js";
14
14
  import {
15
15
  resolveContextSettings
16
- } from "./chunk-PKW3H26Z.js";
16
+ } from "./chunk-VYOJOX4Z.js";
17
17
  import {
18
18
  toMoney
19
- } from "./chunk-736DW4V3.js";
19
+ } from "./chunk-EFWZPUTC.js";
20
20
 
21
21
  // src/commands/inspect.ts
22
22
  async function runInspect(args, ctx, deps = {}) {
@@ -146,4 +146,4 @@ function freshness(card) {
146
146
  export {
147
147
  runInspect
148
148
  };
149
- //# sourceMappingURL=chunk-W4VW5XYB.js.map
149
+ //# sourceMappingURL=chunk-US456VUI.js.map
@@ -2,7 +2,6 @@ import { createRequire as __tenjinCreateRequire } from 'node:module'; const requ
2
2
  import {
3
3
  EXCERPT_MAX_LENGTH,
4
4
  PUBLISH_STATUSES,
5
- SEARCH_ID_WIRE_RE,
6
5
  dedupeFindings,
7
6
  deriveCard,
8
7
  deriveProjectMarkers,
@@ -10,6 +9,7 @@ import {
10
9
  localCardEligibility,
11
10
  missingSentences,
12
11
  needsConfirmation,
12
+ normalizeSearchIds,
13
13
  parseAppliesToFlags,
14
14
  parseFrontmatter,
15
15
  publicFinding,
@@ -17,39 +17,39 @@ import {
17
17
  resolveWriteAuth,
18
18
  scan,
19
19
  writeModeNotices
20
- } from "./chunk-VRPLZERE.js";
20
+ } from "./chunk-VJSQSLBM.js";
21
21
  import {
22
22
  headingOutline
23
23
  } from "./chunk-SGK2B724.js";
24
- import {
25
- loadSearches,
26
- markSearchResolved
27
- } from "./chunk-7NADDA2V.js";
28
24
  import {
29
25
  describeWallet,
30
26
  resolveWalletProvider
31
- } from "./chunk-7GJQ5RGA.js";
27
+ } from "./chunk-CPCX67TI.js";
32
28
  import {
33
29
  trimSlash
34
- } from "./chunk-XGZ5EVMB.js";
30
+ } from "./chunk-EDZSNPE5.js";
35
31
  import {
36
32
  sanitizeForTerminal,
37
33
  sanitizeWireText
38
- } from "./chunk-B676GPS2.js";
34
+ } from "./chunk-OLWTRUTS.js";
39
35
  import {
40
36
  resolveContextSettings,
41
37
  resolvePublishSettings
42
- } from "./chunk-PKW3H26Z.js";
38
+ } from "./chunk-VYOJOX4Z.js";
43
39
  import {
44
40
  parseUsdToAtomic,
45
41
  toMoney
46
- } from "./chunk-736DW4V3.js";
42
+ } from "./chunk-EFWZPUTC.js";
47
43
  import {
48
44
  parsePublishModeFlag
49
- } from "./chunk-LSWP7MU2.js";
45
+ } from "./chunk-U6VPKMGC.js";
46
+ import {
47
+ loadSearches,
48
+ markSearchResolved
49
+ } from "./chunk-A5DKHMUN.js";
50
50
  import {
51
51
  CliError
52
- } from "./chunk-PAOVPSP6.js";
52
+ } from "./chunk-ZFJJ3EXC.js";
53
53
 
54
54
  // src/commands/publish.ts
55
55
  import { readFile } from "fs/promises";
@@ -58,17 +58,19 @@ async function runPublish(args, ctx, deps = {}) {
58
58
  const env = deps.env ?? process.env;
59
59
  const cwd = deps.cwd ?? process.cwd();
60
60
  if (args.mode !== void 0) parsePublishModeFlag(args.mode, "--mode");
61
- validateSearchId(args);
61
+ const searchIds = normalizeSearchIds(args.searchId, deps.searchIdLabel ?? "--search-id");
62
62
  const raw = await readSource(args);
63
- const storedSearch = args.searchId !== void 0 ? (await loadSearches(ctx.dataDir)).find((s) => s.searchId === args.searchId) ?? null : null;
63
+ const stored = await loadNamedSearches(ctx, searchIds);
64
64
  const { frontmatter, body } = parseFrontmatter(raw);
65
65
  const status = resolveStatus(args, frontmatter);
66
+ if (status !== "draft") warnUnrecorded(ctx, searchIds, stored);
66
67
  const title = resolveTitle(frontmatter, body);
67
68
  const tags = resolveTags(frontmatter);
68
69
  const excerpt = resolveExcerpt(args, frontmatter);
69
70
  const handle = expectString(frontmatter, "handle");
70
71
  const cardFlags = cardFlagsFrom(args);
71
- const wanted = storedSearch?.question;
72
+ const prefillFrom = searchIds.find((id) => stored.get(id)?.question !== void 0);
73
+ const wanted = prefillFrom === void 0 ? void 0 : stored.get(prefillFrom)?.question;
72
74
  const prefillQuestion = wanted === void 0 ? void 0 : cardQuestion(wanted);
73
75
  const roomForPrefill = cardFlags.question === void 0 && frontmatter.questionsAnswered === void 0;
74
76
  if (prefillQuestion !== void 0 && roomForPrefill) cardFlags.question = [prefillQuestion];
@@ -155,7 +157,7 @@ async function runPublish(args, ctx, deps = {}) {
155
157
  // demand either. Sending it on a draft put one demand signal on two posts —
156
158
  // no command promotes a draft, so reaching a public piece means a second
157
159
  // publish carrying the same id — with one of them possibly never shipping.
158
- ...args.searchId !== void 0 && status !== "draft" ? { searchId: args.searchId } : {}
160
+ ...searchIds.length > 0 && status !== "draft" ? { searchId: searchIds } : {}
159
161
  };
160
162
  const result = await publishPost(input, auth, {
161
163
  baseUrl: runtime.baseUrl,
@@ -163,19 +165,35 @@ async function runPublish(args, ctx, deps = {}) {
163
165
  ...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
164
166
  });
165
167
  const parksPrivately = status === "draft";
166
- let searchInfo;
167
- if (args.searchId !== void 0) {
168
- searchInfo = await closeNamedSearch(ctx, args.searchId, storedSearch, parksPrivately, prefill);
168
+ const searches = [];
169
+ for (const id of searchIds) {
170
+ searches.push(
171
+ await closeNamedSearch(
172
+ ctx,
173
+ id,
174
+ stored.get(id) ?? null,
175
+ parksPrivately,
176
+ id === prefillFrom ? prefill : "none"
177
+ )
178
+ );
169
179
  }
170
- return receipt(result, runtime.baseUrl, searchInfo);
180
+ return receipt(result, runtime.baseUrl, searches);
171
181
  }
172
- function validateSearchId(args) {
173
- if (args.searchId === void 0) return;
174
- if (!SEARCH_ID_WIRE_RE.test(args.searchId)) {
175
- throw new CliError("USAGE", `Invalid --search-id: ${JSON.stringify(args.searchId)}.`, {
176
- fix: "Pass the searchId from a prior `tenjin search` (a uuid)."
177
- });
178
- }
182
+ function warnUnrecorded(ctx, searchIds, stored) {
183
+ const unrecorded = searchIds.filter((id) => !stored.has(id));
184
+ if (unrecorded.length === 0) return;
185
+ ctx.io.stderr.write(
186
+ `Not in this machine's search store: ${unrecorded.join(", ")}. The server accepts or refuses the named searches as one batch, so if it has no record of one either, this publish is refused after it is signed. Drop that id to publish without it.
187
+ `
188
+ );
189
+ }
190
+ async function loadNamedSearches(ctx, searchIds) {
191
+ if (searchIds.length === 0) return /* @__PURE__ */ new Map();
192
+ const searches = await loadSearches(ctx.dataDir);
193
+ const wanted = new Set(searchIds);
194
+ return new Map(
195
+ searches.filter((s) => wanted.has(s.searchId.toLowerCase())).map((s) => [s.searchId.toLowerCase(), s])
196
+ );
179
197
  }
180
198
  async function closeNamedSearch(ctx, searchId, stored, parksPrivately, prefill) {
181
199
  const open = (reason) => {
@@ -187,7 +205,7 @@ async function closeNamedSearch(ctx, searchId, stored, parksPrivately, prefill)
187
205
  if (stored === null) {
188
206
  return open(`Published, but search ${searchId} is not in the local store.`);
189
207
  }
190
- const outcome = await markSearchResolved(ctx.dataDir, searchId, "publish", void 0, {
208
+ const outcome = await markSearchResolved(ctx.dataDir, stored.searchId, "publish", void 0, {
191
209
  relink: true
192
210
  });
193
211
  if (outcome === "failed") {
@@ -216,7 +234,7 @@ async function readSource(args) {
216
234
  }
217
235
  return readMarkdown(args.file);
218
236
  }
219
- function receipt(result, baseUrl, searchInfo) {
237
+ function receipt(result, baseUrl, searches) {
220
238
  const price = toMoney(result.priceAtomic);
221
239
  const missing = missingSentences(result.cacheEligibleMissing).map(sanitizeForTerminal);
222
240
  const cacheEligible = result.cacheEligible ?? false;
@@ -224,10 +242,8 @@ function receipt(result, baseUrl, searchInfo) {
224
242
  const title = sanitizeForTerminal(result.title);
225
243
  const human = [
226
244
  `Published ${title} (${sanitizeForTerminal(result.status)}) for ${price.usd} USD \u2192 ${sanitizeForTerminal(result.url)}`,
227
- cacheEligible ? "Answer card is search-eligible." : missing.length > 0 ? `Answer card not search-eligible yet: ${missing.join(" ")}` : "Published as a browse-only document (no answer card).",
228
- ...searchInfo?.closed === true ? [
229
- searchInfo.relinked === true ? `Re-linked search ${searchInfo.id} to this piece; it had been closed without one.` : searchInfo.alreadyAnswered === true ? `Search ${searchInfo.id} was already answered by an earlier publish.` : `Closed the loop on search ${searchInfo.id}.`
230
- ] : [],
245
+ cacheEligible ? "Answer card is search-eligible." : missing.length > 0 ? `Answer card incomplete, ranks below every complete card in agent search. To fix: ${missing.join(" ")}` : "Published without an answer card: ranks below every carded piece in agent search.",
246
+ ...searches.filter((s) => s.closed).map(closeLine),
231
247
  ...result.warnings.map((w) => `warning: ${sanitizeForTerminal(w)}`)
232
248
  ];
233
249
  return {
@@ -239,12 +255,24 @@ function receipt(result, baseUrl, searchInfo) {
239
255
  cacheEligible,
240
256
  missing,
241
257
  deskUrl,
242
- ...searchInfo !== void 0 ? { search: searchInfo } : {},
258
+ // `search` repeats a lone result for callers that already read it; a
259
+ // batch has no single one to repeat.
260
+ ...searches.length === 1 ? { search: searches[0] } : {},
261
+ ...searches.length > 0 ? { searches } : {},
243
262
  ...result.warnings.length > 0 ? { warnings: result.warnings } : {}
244
263
  },
245
264
  humanLines: human
246
265
  };
247
266
  }
267
+ function closeLine(search) {
268
+ if (search.relinked === true) {
269
+ return `Re-linked search ${search.id} to this piece; it had been closed without one.`;
270
+ }
271
+ if (search.alreadyAnswered === true) {
272
+ return `Search ${search.id} was already answered by an earlier publish.`;
273
+ }
274
+ return `Closed the loop on search ${search.id}.`;
275
+ }
248
276
  async function readMarkdown(file) {
249
277
  try {
250
278
  return await readFile(file, "utf8");
@@ -369,4 +397,4 @@ function confirmMessage(warnCount, priceUsd) {
369
397
  export {
370
398
  runPublish
371
399
  };
372
- //# sourceMappingURL=chunk-O75FOHXS.js.map
400
+ //# sourceMappingURL=chunk-V44J2MXV.js.map