tenjin-cli 0.1.0-alpha.18 → 0.1.0-alpha.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/README.md +151 -40
  2. package/dist/{_esm-CE7KNONL.js → _esm-OVVGTKHH.js} +4 -4
  3. package/dist/{chunk-WUHY2AXD.js → chunk-2SQEFBAM.js} +4 -3
  4. package/dist/{chunk-FGR734LZ.js → chunk-3VYGDRRL.js} +5 -5
  5. package/dist/{chunk-PDA2BVFY.js → chunk-5DOHKQ24.js} +4 -15
  6. package/dist/chunk-5DOHKQ24.js.map +1 -0
  7. package/dist/{chunk-N35E6CM2.js → chunk-6DCELMQA.js} +6 -6
  8. package/dist/{chunk-WXC57XGG.js → chunk-A36LQPHV.js} +1 -1
  9. package/dist/chunk-A36LQPHV.js.map +1 -0
  10. package/dist/{chunk-BTX2QE2Y.js → chunk-A6CY6BUW.js} +3 -3
  11. package/dist/{chunk-TP4D47BY.js → chunk-AISBL7EY.js} +3 -3
  12. package/dist/{chunk-ON6C6WOX.js → chunk-AMG4SONW.js} +138 -58
  13. package/dist/chunk-AMG4SONW.js.map +1 -0
  14. package/dist/{chunk-AUKDYPPX.js → chunk-BG2EXNAA.js} +7 -6
  15. package/dist/chunk-BG2EXNAA.js.map +1 -0
  16. package/dist/{chunk-F3FUGWPZ.js → chunk-FHBGTOFA.js} +121 -40
  17. package/dist/chunk-FHBGTOFA.js.map +1 -0
  18. package/dist/{chunk-HPWO4O6S.js → chunk-FPUPBQHX.js} +2 -2
  19. package/dist/{chunk-3AUDA53C.js → chunk-KTAW4KGH.js} +6 -5
  20. package/dist/{chunk-J5INH7WB.js → chunk-LSWVVSFX.js} +106 -5
  21. package/dist/chunk-LSWVVSFX.js.map +1 -0
  22. package/dist/chunk-O2JYBOUO.js +47 -0
  23. package/dist/chunk-O2JYBOUO.js.map +1 -0
  24. package/dist/{chunk-NRQMOVKM.js → chunk-PZQRSZJV.js} +2 -2
  25. package/dist/{chunk-NRQMOVKM.js.map → chunk-PZQRSZJV.js.map} +1 -1
  26. package/dist/{chunk-N44H5TFB.js → chunk-SCAOYGKX.js} +315 -71
  27. package/dist/chunk-SCAOYGKX.js.map +1 -0
  28. package/dist/{chunk-35M3VITA.js → chunk-TDGN476R.js} +60 -7
  29. package/dist/chunk-TDGN476R.js.map +1 -0
  30. package/dist/{chunk-AR7U7BRG.js → chunk-UNV4K45L.js} +12 -18
  31. package/dist/{chunk-AR7U7BRG.js.map → chunk-UNV4K45L.js.map} +1 -1
  32. package/dist/{chunk-ZG7SFI34.js → chunk-VFVFVQM6.js} +4 -4
  33. package/dist/{chunk-EPCOMXLF.js → chunk-WUU3BH6G.js} +2 -2
  34. package/dist/{chunk-KUBEYXSO.js → chunk-XDADPAWW.js} +22 -22
  35. package/dist/{chunk-YPQSMIDH.js → chunk-XNP6VUAJ.js} +3 -3
  36. package/dist/{chunk-AWQPGIR6.js → chunk-Y66XUXVI.js} +5 -5
  37. package/dist/{chunk-TJMCBIZU.js → chunk-ZDKEU2GF.js} +2 -2
  38. package/dist/{chunk-WLMJE3GJ.js → chunk-ZTFIQC4C.js} +2 -2
  39. package/dist/{cli-MP3RAYHL.js → cli-456F77ZY.js} +33 -28
  40. package/dist/{cli-MP3RAYHL.js.map → cli-456F77ZY.js.map} +1 -1
  41. package/dist/{config-BJK6U5VY.js → config-BLUWOH6S.js} +9 -12
  42. package/dist/{doctor-KJROWE5V.js → doctor-PS45CR3T.js} +37 -29
  43. package/dist/{doctor-KJROWE5V.js.map → doctor-PS45CR3T.js.map} +1 -1
  44. package/dist/{fund-I5COXPEJ.js → fund-4SW2ZBWC.js} +17 -17
  45. package/dist/{hook-command-EJO2564A.js → hook-command-YTV7X333.js} +247 -24
  46. package/dist/hook-command-YTV7X333.js.map +1 -0
  47. package/dist/index.js +2 -2
  48. package/dist/{install-NUQLLHS2.js → install-U4BIDCHH.js} +14 -13
  49. package/dist/{install-wallet-JPFTEC6H.js → install-wallet-EYHELQMG.js} +14 -14
  50. package/dist/{mcp-I5XMVE64.js → mcp-AC4PIXH5.js} +30 -26
  51. package/dist/{mcp-I5XMVE64.js.map → mcp-AC4PIXH5.js.map} +1 -1
  52. package/dist/{pay-WA3JSCNB.js → pay-VJOP6TFT.js} +19 -19
  53. package/dist/{send-KVUH5WDO.js → send-YH75Z6LB.js} +14 -14
  54. package/dist/{status-FFC6FO72.js → status-5CHCDLUE.js} +24 -17
  55. package/dist/status-5CHCDLUE.js.map +1 -0
  56. package/dist/{status-line-SAXSU6CR.js → status-line-CZAZUOAY.js} +6 -6
  57. package/dist/{status-line-wiring-DQZCWIUO.js → status-line-wiring-2ABDVXSJ.js} +4 -4
  58. package/dist/tenjin-daemon.mjs +3 -14
  59. package/dist/{uninstall-SWICHBTF.js → uninstall-BYVGAQMO.js} +13 -15
  60. package/dist/{uninstall-SWICHBTF.js.map → uninstall-BYVGAQMO.js.map} +1 -1
  61. package/dist/{update-W572AMXG.js → update-7QJDSHST.js} +5 -5
  62. package/dist/{viemAdapter-By13KInL-X2VY6CY3.js → viemAdapter-By13KInL-N2GIVMZ7.js} +2 -2
  63. package/dist/{wallet-L2YLAJFN.js → wallet-YZOXIXBC.js} +14 -14
  64. package/docs/agent-permissions.md +29 -13
  65. package/docs/safety-model.md +7 -1
  66. package/package.json +1 -1
  67. package/dist/chunk-35M3VITA.js.map +0 -1
  68. package/dist/chunk-AUKDYPPX.js.map +0 -1
  69. package/dist/chunk-F3FUGWPZ.js.map +0 -1
  70. package/dist/chunk-J5INH7WB.js.map +0 -1
  71. package/dist/chunk-N44H5TFB.js.map +0 -1
  72. package/dist/chunk-ON6C6WOX.js.map +0 -1
  73. package/dist/chunk-PDA2BVFY.js.map +0 -1
  74. package/dist/chunk-U2DZISAH.js +0 -111
  75. package/dist/chunk-U2DZISAH.js.map +0 -1
  76. package/dist/chunk-WS4JA6TC.js +0 -137
  77. package/dist/chunk-WS4JA6TC.js.map +0 -1
  78. package/dist/chunk-WXC57XGG.js.map +0 -1
  79. package/dist/hook-command-EJO2564A.js.map +0 -1
  80. package/dist/skill-placement-JMDPSKE6.js +0 -299
  81. package/dist/skill-placement-JMDPSKE6.js.map +0 -1
  82. package/dist/status-FFC6FO72.js.map +0 -1
  83. /package/dist/{_esm-CE7KNONL.js.map → _esm-OVVGTKHH.js.map} +0 -0
  84. /package/dist/{chunk-WUHY2AXD.js.map → chunk-2SQEFBAM.js.map} +0 -0
  85. /package/dist/{chunk-FGR734LZ.js.map → chunk-3VYGDRRL.js.map} +0 -0
  86. /package/dist/{chunk-N35E6CM2.js.map → chunk-6DCELMQA.js.map} +0 -0
  87. /package/dist/{chunk-BTX2QE2Y.js.map → chunk-A6CY6BUW.js.map} +0 -0
  88. /package/dist/{chunk-TP4D47BY.js.map → chunk-AISBL7EY.js.map} +0 -0
  89. /package/dist/{chunk-HPWO4O6S.js.map → chunk-FPUPBQHX.js.map} +0 -0
  90. /package/dist/{chunk-3AUDA53C.js.map → chunk-KTAW4KGH.js.map} +0 -0
  91. /package/dist/{chunk-ZG7SFI34.js.map → chunk-VFVFVQM6.js.map} +0 -0
  92. /package/dist/{chunk-EPCOMXLF.js.map → chunk-WUU3BH6G.js.map} +0 -0
  93. /package/dist/{chunk-KUBEYXSO.js.map → chunk-XDADPAWW.js.map} +0 -0
  94. /package/dist/{chunk-YPQSMIDH.js.map → chunk-XNP6VUAJ.js.map} +0 -0
  95. /package/dist/{chunk-AWQPGIR6.js.map → chunk-Y66XUXVI.js.map} +0 -0
  96. /package/dist/{chunk-TJMCBIZU.js.map → chunk-ZDKEU2GF.js.map} +0 -0
  97. /package/dist/{chunk-WLMJE3GJ.js.map → chunk-ZTFIQC4C.js.map} +0 -0
  98. /package/dist/{config-BJK6U5VY.js.map → config-BLUWOH6S.js.map} +0 -0
  99. /package/dist/{fund-I5COXPEJ.js.map → fund-4SW2ZBWC.js.map} +0 -0
  100. /package/dist/{install-NUQLLHS2.js.map → install-U4BIDCHH.js.map} +0 -0
  101. /package/dist/{install-wallet-JPFTEC6H.js.map → install-wallet-EYHELQMG.js.map} +0 -0
  102. /package/dist/{pay-WA3JSCNB.js.map → pay-VJOP6TFT.js.map} +0 -0
  103. /package/dist/{send-KVUH5WDO.js.map → send-YH75Z6LB.js.map} +0 -0
  104. /package/dist/{status-line-SAXSU6CR.js.map → status-line-CZAZUOAY.js.map} +0 -0
  105. /package/dist/{status-line-wiring-DQZCWIUO.js.map → status-line-wiring-2ABDVXSJ.js.map} +0 -0
  106. /package/dist/{update-W572AMXG.js.map → update-7QJDSHST.js.map} +0 -0
  107. /package/dist/{viemAdapter-By13KInL-X2VY6CY3.js.map → viemAdapter-By13KInL-N2GIVMZ7.js.map} +0 -0
  108. /package/dist/{wallet-L2YLAJFN.js.map → wallet-YZOXIXBC.js.map} +0 -0
@@ -1,22 +1,25 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
- import {
3
- isPublicAddress
4
- } from "./chunk-2G2WLVHB.js";
5
2
  import {
6
3
  requestToolAccess
7
4
  } from "./chunk-S2NRVRPF.js";
8
5
  import {
9
6
  ROUTER_PATH,
10
7
  requestDecision
11
- } from "./chunk-YPQSMIDH.js";
12
- import "./chunk-WUHY2AXD.js";
8
+ } from "./chunk-XNP6VUAJ.js";
9
+ import {
10
+ isPublicAddress
11
+ } from "./chunk-2G2WLVHB.js";
12
+ import {
13
+ composeUserAgent
14
+ } from "./chunk-2SQEFBAM.js";
13
15
  import {
14
16
  readUsdcBalance
15
17
  } from "./chunk-3KKKB2AQ.js";
16
18
  import {
19
+ evaluateSpendPolicy,
17
20
  readSpendSummary,
18
21
  spentOf
19
- } from "./chunk-35M3VITA.js";
22
+ } from "./chunk-TDGN476R.js";
20
23
  import {
21
24
  REQUEST_TOOL
22
25
  } from "./chunk-TGLKKLQG.js";
@@ -24,32 +27,36 @@ import {
24
27
  mask
25
28
  } from "./chunk-7QKHZQKW.js";
26
29
  import {
30
+ augmentOf,
27
31
  bindDecision,
32
+ claimQuery,
33
+ markAugment,
28
34
  markOffered,
29
35
  newCallId,
36
+ noteRedirect,
30
37
  noteSession,
31
38
  pruneProgress,
32
39
  pruneSessions,
33
40
  sessionDir,
41
+ takeUndelivered,
34
42
  wasOffered,
35
43
  writeProgress
36
- } from "./chunk-J5INH7WB.js";
44
+ } from "./chunk-LSWVVSFX.js";
45
+ import "./chunk-2I4QTOLB.js";
37
46
  import {
38
47
  routerSettings
39
- } from "./chunk-TP4D47BY.js";
40
- import "./chunk-2I4QTOLB.js";
48
+ } from "./chunk-AISBL7EY.js";
41
49
  import {
42
50
  resolveContextSettings
43
- } from "./chunk-PDA2BVFY.js";
44
- import {
45
- evaluateSpendPolicy
46
- } from "./chunk-U2DZISAH.js";
51
+ } from "./chunk-5DOHKQ24.js";
52
+ import "./chunk-O2JYBOUO.js";
47
53
  import {
48
54
  external_exports,
55
+ isSameDeployment,
49
56
  loadRawConfig,
50
57
  resolveSettings
51
- } from "./chunk-AR7U7BRG.js";
52
- import "./chunk-NRQMOVKM.js";
58
+ } from "./chunk-UNV4K45L.js";
59
+ import "./chunk-PZQRSZJV.js";
53
60
  import "./chunk-JLEF5WHM.js";
54
61
  import {
55
62
  walletPath
@@ -287,6 +294,148 @@ function textOf(message) {
287
294
  // src/router/gate.ts
288
295
  var GATE_TIMEOUT_MS = 3500;
289
296
 
297
+ // src/router/augment.ts
298
+ import { spawn } from "node:child_process";
299
+ import { constants } from "node:fs";
300
+ import { open as open2, rm } from "node:fs/promises";
301
+ import { dirname as dirname2 } from "node:path";
302
+ var DOCS_QUERY_MAX = 500;
303
+ var PREFETCH_TIMEOUT_MS = 12e3;
304
+ var AUGMENT_WAIT_MS = 9e3;
305
+ var MAX_DOCS_CHARS = 1e5;
306
+ var MAX_BODY_BYTES = 1e6;
307
+ var POLL_MS = 100;
308
+ var PREFETCH_SCRIPT = [
309
+ "const { renameSync, rmSync, writeFileSync } = require('node:fs');",
310
+ "const { basename, dirname, join } = require('node:path');",
311
+ "const [url, out, agent, timeout, max] = process.argv.slice(1);",
312
+ "const tmp = join(dirname(out), '.' + basename(out) + '.' + process.pid + '.tmp');",
313
+ // The deadline is a plain timer that answers and exits, not an
314
+ // `AbortSignal.timeout`: that one's timer does not hold the process open, so
315
+ // a stalled lookup let it exit without writing anything.
316
+ "const timer = setTimeout(() => done(0, ''), Number(timeout));",
317
+ "const done = (status, text) => {",
318
+ " clearTimeout(timer);",
319
+ " try {",
320
+ " writeFileSync(tmp, JSON.stringify({ status, text }), { mode: 0o600, flag: 'wx' });",
321
+ " renameSync(tmp, out);",
322
+ " } catch {",
323
+ " try { rmSync(tmp, { force: true }); } catch {}",
324
+ " }",
325
+ " process.exit(0);",
326
+ "};",
327
+ "fetch(url, {",
328
+ " headers: { accept: 'text/plain', 'user-agent': agent },",
329
+ " redirect: 'error',",
330
+ "})",
331
+ " .then(async (res) => done(res.status, res.ok ? (await res.text()).slice(0, Number(max)) : ''))",
332
+ " .catch(() => done(0, ''));"
333
+ ].join("\n");
334
+ function spawnPrefetch(job) {
335
+ const child = spawn(
336
+ process.execPath,
337
+ [
338
+ "-e",
339
+ PREFETCH_SCRIPT,
340
+ job.url,
341
+ job.out,
342
+ job.userAgent,
343
+ String(PREFETCH_TIMEOUT_MS),
344
+ String(MAX_DOCS_CHARS)
345
+ ],
346
+ {
347
+ detached: true,
348
+ stdio: "ignore",
349
+ // Never the session's project: a live child would pin its worktree.
350
+ cwd: dirname2(job.out),
351
+ windowsHide: true
352
+ }
353
+ );
354
+ child.on("error", () => void 0);
355
+ child.unref();
356
+ }
357
+ function docsUrl(endpoint, query, baseUrl) {
358
+ let url;
359
+ let base;
360
+ try {
361
+ url = new URL(endpoint);
362
+ base = new URL(baseUrl);
363
+ } catch {
364
+ return null;
365
+ }
366
+ if (url.username !== "" || url.password !== "") return null;
367
+ if (!isSameDeployment(url.origin, base.origin)) return null;
368
+ url.searchParams.set("query", query.slice(0, DOCS_QUERY_MAX));
369
+ return url.toString();
370
+ }
371
+ async function startAugment(call, offer, baseUrl, deps) {
372
+ if (call.toolUseId === void 0) return false;
373
+ const url = docsUrl(offer.endpoint, call.query, baseUrl);
374
+ if (url === null) return false;
375
+ const now = deps.now?.() ?? Date.now();
376
+ if (!await claimQuery(deps.dataDir, call.sessionId, call.agentId, call.query, now)) {
377
+ return false;
378
+ }
379
+ const out = await markAugment(deps.dataDir, call.sessionId, call.toolUseId, offer.provider, now);
380
+ if (out === null) return false;
381
+ try {
382
+ (deps.prefetch ?? spawnPrefetch)({ url, out, userAgent: composeUserAgent() });
383
+ return true;
384
+ } catch {
385
+ return false;
386
+ }
387
+ }
388
+ async function finishAugment(call, deps) {
389
+ if (call.toolUseId === void 0) return null;
390
+ const now = deps.now?.() ?? Date.now();
391
+ const marker = await augmentOf(deps.dataDir, call.sessionId, call.toolUseId, now);
392
+ if (marker === null) return null;
393
+ if (call.search === null) return { updatedToolOutput: null };
394
+ const budget = Math.min(
395
+ deps.augmentWaitMs ?? AUGMENT_WAIT_MS,
396
+ PREFETCH_TIMEOUT_MS + 1e3 - (now - marker.at)
397
+ );
398
+ const answer = await awaitBody(marker.body, Date.now() + Math.max(0, budget));
399
+ await rm(marker.body, { force: true }).catch(() => void 0);
400
+ const text = answer?.status === 200 ? answer.text.trim() : "";
401
+ if (text.length === 0) return { updatedToolOutput: null };
402
+ return {
403
+ updatedToolOutput: {
404
+ ...call.search.raw,
405
+ results: [docsLine(marker.provider || "library", text), ...call.search.results]
406
+ }
407
+ };
408
+ }
409
+ function docsLine(provider, text) {
410
+ return `Tenjin router added ${provider} docs for this search (free). If they don't cover it, use the web results below.
411
+
412
+ ${text}`;
413
+ }
414
+ async function awaitBody(path, deadline) {
415
+ for (; ; ) {
416
+ const body = await readBody(path);
417
+ if (body !== null) return body;
418
+ const left = deadline - Date.now();
419
+ if (left <= 0) return null;
420
+ await new Promise((resolve) => setTimeout(resolve, Math.min(POLL_MS, left)));
421
+ }
422
+ }
423
+ async function readBody(path) {
424
+ const file = await open2(path, constants.O_RDONLY | constants.O_NOFOLLOW).catch(() => void 0);
425
+ if (file === void 0) return null;
426
+ try {
427
+ if ((await file.stat()).size > MAX_BODY_BYTES) return { status: 0, text: "" };
428
+ const parsed = JSON.parse(await file.readFile("utf8"));
429
+ const { status, text } = parsed ?? {};
430
+ if (typeof status !== "number" || typeof text !== "string") return { status: 0, text: "" };
431
+ return { status, text: text.slice(0, MAX_DOCS_CHARS) };
432
+ } catch {
433
+ return { status: 0, text: "" };
434
+ } finally {
435
+ await file.close().catch(() => void 0);
436
+ }
437
+ }
438
+
290
439
  // src/router/hooks.ts
291
440
  var PromptEventSchema = external_exports.object({
292
441
  session_id: external_exports.string().min(1).max(200),
@@ -342,6 +491,7 @@ function decodeEvent(raw) {
342
491
  kind: "shortfall",
343
492
  eventName: shortfall.data.hook_event_name,
344
493
  nativeOutcome: shortfallOf(shortfall.data),
494
+ search: searchOf(shortfall.data),
345
495
  ...nativeCallOf(shortfall.data)
346
496
  };
347
497
  }
@@ -383,6 +533,13 @@ function nativeCallOf(event) {
383
533
  ...optional("cwd", event.cwd)
384
534
  };
385
535
  }
536
+ function searchOf(event) {
537
+ if (event.hook_event_name !== "PostToolUse" || event.tool_name !== "WebSearch") return null;
538
+ const response = event.tool_response;
539
+ if (response === null || typeof response !== "object" || Array.isArray(response)) return null;
540
+ const raw = response;
541
+ return Array.isArray(raw.results) ? { raw, results: raw.results } : null;
542
+ }
386
543
  function optional(key, value) {
387
544
  return value === void 0 ? {} : { [key]: value };
388
545
  }
@@ -401,6 +558,7 @@ function toolNamed(hint) {
401
558
  function attributed(hint) {
402
559
  return `${HINT_SOURCE}: ${toolNamed(hint)}`;
403
560
  }
561
+ var ONE_BLOCK = "If this does not cover it, make your own call again: you will not be redirected twice in a row.";
404
562
  function shortfallOffer(tool, hint) {
405
563
  return `${HINT_SOURCE}: your ${tool} call came back short. Optional: ${toolNamed(hint)}`;
406
564
  }
@@ -537,7 +695,11 @@ function injection(line) {
537
695
  }
538
696
  };
539
697
  }
540
- async function routeNativeCall(event, pending, deps, nativeOutcome) {
698
+ function isFree(offer) {
699
+ return offer.providerPriceAtomic === "0";
700
+ }
701
+ async function routeNativeCall(event, pending, deps, opts = {}) {
702
+ const { nativeOutcome, repeated } = opts;
541
703
  const router = await routerFor(event.cwd, deps);
542
704
  if (router === null) return { offer: null, outcome: { response: null } };
543
705
  if (event.agentId !== void 0 && await requestToolAccess(event.agentType, agentLookup(event.cwd, deps)) !== "allowed") {
@@ -578,31 +740,67 @@ async function routeNativeCall(event, pending, deps, nativeOutcome) {
578
740
  outcome: { response: null, ...outcome !== null ? { action: outcome.action } : {} }
579
741
  };
580
742
  }
581
- const denies = nativeOutcome === void 0;
582
- const withheld = event.agentId !== void 0 || denies ? await withheldBecause(outcome, deps, deadline) : null;
743
+ if (opts.passFree === true && isFree(outcome)) {
744
+ await footer.close(outcome, { withheld: "free lookup, call runs" });
745
+ return { offer: outcome, free: true, baseUrl: resolveBaseUrl(deps, router.config) };
746
+ }
747
+ const withheld = await withheldBecause(outcome, deps, deadline);
583
748
  if (withheld !== null) {
584
749
  await footer.close(outcome, { withheld });
585
750
  return { offer: null, outcome: { response: null, action: "execute", withheld: true } };
586
751
  }
752
+ if (repeated !== void 0 && await repeated(outcome)) {
753
+ await footer.close(outcome, { withheld: "already redirected once" });
754
+ return {
755
+ offer: null,
756
+ outcome: { response: null, action: "execute", redirectUndelivered: true }
757
+ };
758
+ }
587
759
  await footer.close(outcome);
588
760
  return { offer: outcome };
589
761
  }
590
762
  async function runNativeHook(raw, deps) {
591
763
  const event = decodeEvent(raw);
592
764
  if (event?.kind !== "native" || event.pending === null) return { response: null };
593
- const routed = await routeNativeCall(event, event.pending, deps);
765
+ const routed = await routeNativeCall(event, event.pending, deps, {
766
+ passFree: true,
767
+ repeated: (offer) => takeUndelivered(deps.dataDir, event.sessionId, event.agentId, offer.category, deps.now?.())
768
+ });
594
769
  if (routed.offer === null) return routed.outcome;
770
+ if (routed.free === true) {
771
+ const { pending } = event;
772
+ const augmenting = pending.tool === "WebSearch" && await startAugment(
773
+ {
774
+ sessionId: event.sessionId,
775
+ query: pending.query,
776
+ ...event.agentId !== void 0 ? { agentId: event.agentId } : {},
777
+ ...event.toolUseId !== void 0 ? { toolUseId: event.toolUseId } : {}
778
+ },
779
+ routed.offer,
780
+ routed.baseUrl,
781
+ deps
782
+ );
783
+ return {
784
+ response: null,
785
+ action: "execute",
786
+ id: routed.offer.id,
787
+ free: true,
788
+ ...augmenting ? { augmenting: true } : {}
789
+ };
790
+ }
595
791
  if (event.toolUseId !== void 0) {
596
792
  await markOffered(deps.dataDir, event.sessionId, event.toolUseId, deps.now?.());
597
793
  }
794
+ await noteRedirect(deps.dataDir, event.sessionId, event.agentId, routed.offer, deps.now?.());
598
795
  return {
599
796
  response: {
600
797
  hookSpecificOutput: {
601
798
  hookEventName: "PreToolUse",
602
799
  permissionDecision: "deny",
603
- // THE SERVER'S LINE, attributed and tool-named, and nothing else. It
604
- // already carries the id and the exact search or URL that was denied.
605
- permissionDecisionReason: attributed(routed.offer.hint)
800
+ // THE SERVER'S LINE, attributed and tool-named, then this client's one
801
+ // sentence. The line already carries the id and the exact search or URL
802
+ // that was denied.
803
+ permissionDecisionReason: `${attributed(routed.offer.hint)} ${ONE_BLOCK}`
606
804
  }
607
805
  },
608
806
  action: "execute",
@@ -612,14 +810,39 @@ async function runNativeHook(raw, deps) {
612
810
  async function runShortfallHook(raw, deps) {
613
811
  const event = decodeEvent(raw);
614
812
  if (event?.kind !== "shortfall") return { response: null };
813
+ const augment = await finishAugment(
814
+ {
815
+ sessionId: event.sessionId,
816
+ search: event.search,
817
+ ...event.toolUseId !== void 0 ? { toolUseId: event.toolUseId } : {}
818
+ },
819
+ deps
820
+ );
821
+ if (augment !== null && augment.updatedToolOutput !== null) {
822
+ return {
823
+ response: {
824
+ hookSpecificOutput: {
825
+ hookEventName: "PostToolUse",
826
+ updatedToolOutput: augment.updatedToolOutput
827
+ }
828
+ },
829
+ augmented: "added"
830
+ };
831
+ }
832
+ const outcome = await offerOnShortfall(event, deps, augment !== null);
833
+ return augment === null ? outcome : { ...outcome, augmented: "nothing" };
834
+ }
835
+ async function offerOnShortfall(event, deps, docsJustMissed = false) {
615
836
  const { nativeOutcome, pending, eventName } = event;
616
837
  if (nativeOutcome === null) return { response: null };
617
838
  if (pending === null) return { response: null };
618
839
  if (event.toolUseId !== void 0 && await wasOffered(deps.dataDir, event.sessionId, event.toolUseId, deps.now?.())) {
619
840
  return { response: null, nativeOutcome, alreadyOffered: true };
620
841
  }
621
- const routed = await routeNativeCall(event, pending, deps, nativeOutcome);
842
+ const routed = await routeNativeCall(event, pending, deps, { nativeOutcome });
622
843
  if (routed.offer === null) return { ...routed.outcome, nativeOutcome };
844
+ if (docsJustMissed && routed.offer.providerPriceAtomic === "0")
845
+ return { response: null, nativeOutcome, action: "execute" };
623
846
  return {
624
847
  response: {
625
848
  hookSpecificOutput: {
@@ -818,4 +1041,4 @@ export {
818
1041
  STDIN_TIMEOUT_MS,
819
1042
  runHookCommand
820
1043
  };
821
- //# sourceMappingURL=hook-command-EJO2564A.js.map
1044
+ //# sourceMappingURL=hook-command-YTV7X333.js.map