@tyvm/knowhow 0.0.145 → 0.0.146

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 (139) hide show
  1. package/package.json +1 -1
  2. package/src/chat/CliChatService.ts +16 -0
  3. package/src/chat/modules/AgentModule.ts +30 -23
  4. package/src/chat/modules/SessionsModule.ts +7 -5
  5. package/src/chat/types.ts +3 -2
  6. package/src/clients/anthropic.ts +24 -0
  7. package/src/clients/fireworks.ts +3 -0
  8. package/src/clients/gemini.ts +8 -0
  9. package/src/clients/openai.ts +7 -4
  10. package/src/clients/types.ts +30 -7
  11. package/src/clients/xai.ts +23 -4
  12. package/src/commands/agent.ts +10 -1
  13. package/src/commands/services.ts +49 -3
  14. package/src/plugins/plugins.ts +16 -0
  15. package/src/processors/TokenCompressor.ts +40 -8
  16. package/src/processors/ToolResponseCache.ts +17 -8
  17. package/src/processors/tools/boundedToolResponse.ts +49 -0
  18. package/src/processors/tools/grepToolResponse.ts +164 -38
  19. package/src/processors/tools/index.ts +2 -0
  20. package/src/processors/tools/jqToolResponse.ts +40 -10
  21. package/src/processors/tools/listStoredToolResponses.ts +51 -10
  22. package/src/processors/tools/tailToolResponse.ts +85 -17
  23. package/src/services/LazyToolsService.ts +7 -0
  24. package/src/services/Mcp.ts +9 -2
  25. package/src/services/RuntimeReloadService.ts +31 -0
  26. package/src/services/Tools.ts +11 -0
  27. package/src/services/TracingService.ts +116 -0
  28. package/src/services/index.ts +8 -0
  29. package/src/services/modules/index.ts +45 -2
  30. package/src/services/modules/types.ts +8 -0
  31. package/src/util/Trace.ts +236 -0
  32. package/tests/clients/fireworks.test.ts +65 -0
  33. package/tests/clients/reasoningEffort.test.ts +79 -0
  34. package/tests/compressor/toolResponseCache.test.ts +2 -1
  35. package/tests/manual/clients/completions.test.ts +27 -10
  36. package/tests/processors/TokenCompressor.test.ts +17 -3
  37. package/tests/processors/tools/boundedRetrievalTools.test.ts +68 -0
  38. package/tests/processors/tools/grepToolResponse.test.ts +88 -1
  39. package/tests/unit/plugins/pluginLoading.test.ts +31 -0
  40. package/tests/unit/services/RuntimeReloadService.test.ts +29 -0
  41. package/ts_build/package.json +1 -1
  42. package/ts_build/src/chat/CliChatService.js +15 -0
  43. package/ts_build/src/chat/CliChatService.js.map +1 -1
  44. package/ts_build/src/chat/modules/AgentModule.js +13 -19
  45. package/ts_build/src/chat/modules/AgentModule.js.map +1 -1
  46. package/ts_build/src/chat/modules/SessionsModule.js +1 -6
  47. package/ts_build/src/chat/modules/SessionsModule.js.map +1 -1
  48. package/ts_build/src/chat/types.d.ts +3 -2
  49. package/ts_build/src/clients/anthropic.d.ts +1 -0
  50. package/ts_build/src/clients/anthropic.js +12 -0
  51. package/ts_build/src/clients/anthropic.js.map +1 -1
  52. package/ts_build/src/clients/fireworks.js +1 -0
  53. package/ts_build/src/clients/fireworks.js.map +1 -1
  54. package/ts_build/src/clients/gemini.js +8 -0
  55. package/ts_build/src/clients/gemini.js.map +1 -1
  56. package/ts_build/src/clients/openai.js +4 -2
  57. package/ts_build/src/clients/openai.js.map +1 -1
  58. package/ts_build/src/clients/types.d.ts +4 -1
  59. package/ts_build/src/clients/types.js +14 -0
  60. package/ts_build/src/clients/types.js.map +1 -1
  61. package/ts_build/src/clients/xai.d.ts +1 -0
  62. package/ts_build/src/clients/xai.js +23 -4
  63. package/ts_build/src/clients/xai.js.map +1 -1
  64. package/ts_build/src/commands/agent.js +6 -1
  65. package/ts_build/src/commands/agent.js.map +1 -1
  66. package/ts_build/src/commands/services.d.ts +2 -0
  67. package/ts_build/src/commands/services.js +45 -3
  68. package/ts_build/src/commands/services.js.map +1 -1
  69. package/ts_build/src/plugins/plugins.d.ts +1 -0
  70. package/ts_build/src/plugins/plugins.js +14 -0
  71. package/ts_build/src/plugins/plugins.js.map +1 -1
  72. package/ts_build/src/processors/TokenCompressor.js +15 -6
  73. package/ts_build/src/processors/TokenCompressor.js.map +1 -1
  74. package/ts_build/src/processors/ToolResponseCache.d.ts +3 -3
  75. package/ts_build/src/processors/ToolResponseCache.js +8 -8
  76. package/ts_build/src/processors/ToolResponseCache.js.map +1 -1
  77. package/ts_build/src/processors/tools/boundedToolResponse.d.ts +7 -0
  78. package/ts_build/src/processors/tools/boundedToolResponse.js +27 -0
  79. package/ts_build/src/processors/tools/boundedToolResponse.js.map +1 -0
  80. package/ts_build/src/processors/tools/grepToolResponse.d.ts +4 -0
  81. package/ts_build/src/processors/tools/grepToolResponse.js +101 -25
  82. package/ts_build/src/processors/tools/grepToolResponse.js.map +1 -1
  83. package/ts_build/src/processors/tools/index.d.ts +2 -2
  84. package/ts_build/src/processors/tools/index.js.map +1 -1
  85. package/ts_build/src/processors/tools/jqToolResponse.d.ts +5 -1
  86. package/ts_build/src/processors/tools/jqToolResponse.js +26 -9
  87. package/ts_build/src/processors/tools/jqToolResponse.js.map +1 -1
  88. package/ts_build/src/processors/tools/listStoredToolResponses.d.ts +7 -1
  89. package/ts_build/src/processors/tools/listStoredToolResponses.js +39 -9
  90. package/ts_build/src/processors/tools/listStoredToolResponses.js.map +1 -1
  91. package/ts_build/src/processors/tools/tailToolResponse.d.ts +5 -0
  92. package/ts_build/src/processors/tools/tailToolResponse.js +56 -13
  93. package/ts_build/src/processors/tools/tailToolResponse.js.map +1 -1
  94. package/ts_build/src/services/LazyToolsService.d.ts +1 -0
  95. package/ts_build/src/services/LazyToolsService.js +5 -0
  96. package/ts_build/src/services/LazyToolsService.js.map +1 -1
  97. package/ts_build/src/services/Mcp.js +8 -2
  98. package/ts_build/src/services/Mcp.js.map +1 -1
  99. package/ts_build/src/services/RuntimeReloadService.d.ts +12 -0
  100. package/ts_build/src/services/RuntimeReloadService.js +26 -0
  101. package/ts_build/src/services/RuntimeReloadService.js.map +1 -0
  102. package/ts_build/src/services/Tools.d.ts +1 -0
  103. package/ts_build/src/services/Tools.js +5 -0
  104. package/ts_build/src/services/Tools.js.map +1 -1
  105. package/ts_build/src/services/TracingService.d.ts +16 -0
  106. package/ts_build/src/services/TracingService.js +35 -0
  107. package/ts_build/src/services/TracingService.js.map +1 -0
  108. package/ts_build/src/services/index.d.ts +6 -0
  109. package/ts_build/src/services/index.js +7 -1
  110. package/ts_build/src/services/index.js.map +1 -1
  111. package/ts_build/src/services/modules/index.d.ts +5 -0
  112. package/ts_build/src/services/modules/index.js +28 -2
  113. package/ts_build/src/services/modules/index.js.map +1 -1
  114. package/ts_build/src/services/modules/types.d.ts +3 -0
  115. package/ts_build/src/util/Trace.d.ts +13 -0
  116. package/ts_build/src/util/Trace.js +107 -0
  117. package/ts_build/src/util/Trace.js.map +1 -0
  118. package/ts_build/tests/clients/fireworks.test.d.ts +1 -0
  119. package/ts_build/tests/clients/fireworks.test.js +65 -0
  120. package/ts_build/tests/clients/fireworks.test.js.map +1 -0
  121. package/ts_build/tests/clients/reasoningEffort.test.d.ts +1 -0
  122. package/ts_build/tests/clients/reasoningEffort.test.js +68 -0
  123. package/ts_build/tests/clients/reasoningEffort.test.js.map +1 -0
  124. package/ts_build/tests/compressor/toolResponseCache.test.js +1 -1
  125. package/ts_build/tests/compressor/toolResponseCache.test.js.map +1 -1
  126. package/ts_build/tests/manual/clients/completions.test.js +19 -6
  127. package/ts_build/tests/manual/clients/completions.test.js.map +1 -1
  128. package/ts_build/tests/processors/TokenCompressor.test.js +11 -2
  129. package/ts_build/tests/processors/TokenCompressor.test.js.map +1 -1
  130. package/ts_build/tests/processors/tools/boundedRetrievalTools.test.d.ts +1 -0
  131. package/ts_build/tests/processors/tools/boundedRetrievalTools.test.js +57 -0
  132. package/ts_build/tests/processors/tools/boundedRetrievalTools.test.js.map +1 -0
  133. package/ts_build/tests/processors/tools/grepToolResponse.test.js +37 -0
  134. package/ts_build/tests/processors/tools/grepToolResponse.test.js.map +1 -1
  135. package/ts_build/tests/unit/plugins/pluginLoading.test.js +59 -0
  136. package/ts_build/tests/unit/plugins/pluginLoading.test.js.map +1 -1
  137. package/ts_build/tests/unit/services/RuntimeReloadService.test.d.ts +1 -0
  138. package/ts_build/tests/unit/services/RuntimeReloadService.test.js +26 -0
  139. package/ts_build/tests/unit/services/RuntimeReloadService.test.js.map +1 -0
@@ -2,6 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.grepToolResponseDefinition = void 0;
4
4
  exports.executeGrep = executeGrep;
5
+ const DEFAULT_MAX_RESULTS = 100;
6
+ const MAX_RESULTS = 1000;
7
+ const DEFAULT_MAX_CHARACTERS = 20_000;
8
+ const MAX_CHARACTERS = 50_000;
9
+ const DEFAULT_MAX_LINE_CHARACTERS = 4_000;
10
+ const MAX_LINE_CHARACTERS = 10_000;
11
+ const FOOTER_RESERVE = 700;
12
+ function boundedInteger(value, fallback, min, max) {
13
+ return Math.min(max, Math.max(min, Number.isFinite(value) ? Math.floor(value) : fallback));
14
+ }
5
15
  async function executeGrep(data, toolCallId, pattern, availableIds, options, toolNameMap) {
6
16
  if (!data) {
7
17
  const idList = availableIds
@@ -10,48 +20,104 @@ async function executeGrep(data, toolCallId, pattern, availableIds, options, too
10
20
  return name ? `${id} (${name})` : id;
11
21
  })
12
22
  .join("\n - ");
13
- return `Error: No tool response found for toolCallId "${toolCallId}". Call listStoredToolResponses to see all available responses with their tool names.\n\nAvailable toolCallIds:\n - ${idList || "(none)"}`;
23
+ const maxCharacters = boundedInteger(options?.maxCharacters, DEFAULT_MAX_CHARACTERS, 1000, MAX_CHARACTERS);
24
+ return `Error: No tool response found for toolCallId "${toolCallId}". Call listStoredToolResponses to see all available responses with their tool names.\n\nAvailable toolCallIds:\n - ${idList || "(none)"}`.slice(0, maxCharacters);
14
25
  }
15
26
  try {
16
27
  const lines = data.split("\n");
17
28
  const matchedResults = [];
18
- const ignoreCase = options?.ignoreCase || false;
19
- const invertMatch = options?.invertMatch || false;
20
- const contextBefore = options?.contextBefore || 0;
21
- const contextAfter = options?.contextAfter || 0;
22
- const maxResults = options?.maxResults || 1000;
23
- const flags = ignoreCase ? "i" : "";
24
- const regex = new RegExp(pattern, flags);
25
- for (let i = 0; i < lines.length && matchedResults.length < maxResults; i++) {
26
- const line = lines[i];
27
- const matches = regex.test(line);
28
- const shouldInclude = invertMatch ? !matches : matches;
29
- if (shouldInclude) {
30
- const startIdx = Math.max(0, i - contextBefore);
31
- const endIdx = Math.min(lines.length - 1, i + contextAfter);
29
+ const ignoreCase = options?.ignoreCase ?? false;
30
+ const invertMatch = options?.invertMatch ?? false;
31
+ const contextBefore = boundedInteger(options?.contextBefore, 0, 0, 1000);
32
+ const contextAfter = boundedInteger(options?.contextAfter, 0, 0, 1000);
33
+ const maxResults = boundedInteger(options?.maxResults, DEFAULT_MAX_RESULTS, 1, MAX_RESULTS);
34
+ const resultOffset = boundedInteger(options?.resultOffset, 0, 0, Number.MAX_SAFE_INTEGER);
35
+ const maxCharacters = boundedInteger(options?.maxCharacters, DEFAULT_MAX_CHARACTERS, 1000, MAX_CHARACTERS);
36
+ const lineCharacterOffset = boundedInteger(options?.lineCharacterOffset, 0, 0, Number.MAX_SAFE_INTEGER);
37
+ const maxLineCharacters = boundedInteger(options?.maxLineCharacters, DEFAULT_MAX_LINE_CHARACTERS, 100, MAX_LINE_CHARACTERS);
38
+ const contentBudget = Math.max(1, maxCharacters - FOOTER_RESERVE);
39
+ const regex = new RegExp(pattern, ignoreCase ? "i" : "");
40
+ let totalMatches = 0;
41
+ let outputCharacters = 0;
42
+ let outputTruncated = false;
43
+ const pagedLineNumbers = new Set();
44
+ for (let i = 0; i < lines.length; i++) {
45
+ const matches = regex.test(lines[i]);
46
+ if (invertMatch ? matches : !matches)
47
+ continue;
48
+ const resultIndex = totalMatches++;
49
+ const startIdx = Math.max(0, i - contextBefore);
50
+ const endIdx = Math.min(lines.length - 1, i + contextAfter);
51
+ if (resultIndex >= resultOffset &&
52
+ matchedResults.length < maxResults &&
53
+ !outputTruncated) {
32
54
  const contextLines = [];
33
55
  for (let j = startIdx; j <= endIdx; j++) {
56
+ const sourceLine = lines[j];
57
+ const visibleLine = sourceLine.slice(lineCharacterOffset, lineCharacterOffset + maxLineCharacters);
34
58
  const prefix = j === i ? "> " : " ";
35
- contextLines.push(`${prefix}${j + 1}: ${lines[j]}`);
59
+ let rendered = `${prefix}${j + 1}: ${visibleLine}`;
60
+ if (lineCharacterOffset >= sourceLine.length && sourceLine.length > 0) {
61
+ rendered += ` [no characters at offset ${lineCharacterOffset}; line length=${sourceLine.length}]`;
62
+ }
63
+ else if (lineCharacterOffset + maxLineCharacters < sourceLine.length) {
64
+ pagedLineNumbers.add(j + 1);
65
+ rendered += `\n [line ${j + 1} truncated; characters ${lineCharacterOffset}-${lineCharacterOffset + visibleLine.length - 1} of ${sourceLine.length}]`;
66
+ }
67
+ contextLines.push(rendered);
68
+ }
69
+ const separatorLength = matchedResults.length > 0 ? 5 : 0;
70
+ const result = contextLines.join("\n");
71
+ const remaining = contentBudget - outputCharacters - separatorLength;
72
+ if (result.length > remaining) {
73
+ if (matchedResults.length === 0 && remaining > 80) {
74
+ matchedResults.push(`${result.slice(0, remaining - 48)}\n[result page truncated by maxCharacters]`);
75
+ outputCharacters = contentBudget;
76
+ }
77
+ outputTruncated = true;
78
+ }
79
+ else {
80
+ matchedResults.push(result);
81
+ outputCharacters += separatorLength + result.length;
36
82
  }
37
- matchedResults.push(contextLines.join("\n"));
38
- i += contextAfter;
39
83
  }
84
+ i += contextAfter;
85
+ }
86
+ if (totalMatches === 0) {
87
+ const preview = pattern.length > 200 ? `${pattern.slice(0, 200)}…` : pattern;
88
+ return `No matches found for pattern "${preview}" in toolCallId "${toolCallId}"`.slice(0, maxCharacters);
89
+ }
90
+ const consumedResults = matchedResults.length;
91
+ const nextResultOffset = resultOffset + consumedResults;
92
+ const hasMoreResults = nextResultOffset < totalMatches;
93
+ const range = consumedResults
94
+ ? `${resultOffset + 1}-${nextResultOffset}`
95
+ : `none (offset ${resultOffset} is past the final result)`;
96
+ const footerLines = [
97
+ "",
98
+ `[grep page: results ${range} of ${totalMatches}; ${consumedResults} returned; maxCharacters=${maxCharacters}]`,
99
+ ];
100
+ if (pagedLineNumbers.size > 0) {
101
+ footerLines.push(`[Long source line(s) ${Array.from(pagedLineNumbers).join(", ")} were sliced. Repeat with options.lineCharacterOffset=${lineCharacterOffset + maxLineCharacters} to read their next characters.]`);
102
+ }
103
+ if (hasMoreResults) {
104
+ footerLines.push(`[More matches available. Repeat with options.resultOffset=${nextResultOffset}.]`);
40
105
  }
41
- if (matchedResults.length === 0) {
42
- return `No matches found for pattern "${pattern}" in toolCallId "${toolCallId}"`;
106
+ else {
107
+ footerLines.push("[End of matches.]");
43
108
  }
44
- return matchedResults.join("\n---\n");
109
+ return (matchedResults.join("\n---\n") + footerLines.join("\n")).slice(0, maxCharacters);
45
110
  }
46
111
  catch (error) {
47
- return `Grep Error: ${error.message}`;
112
+ const message = error instanceof Error ? error.message : String(error);
113
+ return `Grep Error: ${message.slice(0, 500)}`;
48
114
  }
49
115
  }
50
116
  exports.grepToolResponseDefinition = {
51
117
  type: "function",
52
118
  function: {
53
119
  name: "grepToolResponse",
54
- description: "Search through a stored tool response using grep-like pattern matching. Useful when a tool response is too large and you need to find specific lines or content without re-running the tool. Returns matching lines with optional context.",
120
+ description: "Search a stored tool response using a regular expression. Results and individual source lines are bounded and paginated. Follow the returned resultOffset or lineCharacterOffset instruction to retrieve more.",
55
121
  parameters: {
56
122
  type: "object",
57
123
  positional: true,
@@ -66,8 +132,18 @@ exports.grepToolResponseDefinition = {
66
132
  },
67
133
  options: {
68
134
  type: "object",
69
- description: "Optional grep settings: ignoreCase (boolean), invertMatch (boolean), contextBefore (number), contextAfter (number), maxResults (number, default: 1000)",
70
- properties: {},
135
+ description: "Optional grep, output-bound, and pagination settings.",
136
+ properties: {
137
+ ignoreCase: { type: "boolean", description: "Case-insensitive matching." },
138
+ invertMatch: { type: "boolean", description: "Return non-matching lines." },
139
+ contextBefore: { type: "number", description: "Context lines before a match (maximum 1000)." },
140
+ contextAfter: { type: "number", description: "Context lines after a match (maximum 1000)." },
141
+ maxResults: { type: "number", description: "Matches per page (default 100, maximum 1000)." },
142
+ resultOffset: { type: "number", description: "Zero-based match offset for the next result page." },
143
+ maxCharacters: { type: "number", description: "Response size (default 20000, hard maximum 50000)." },
144
+ lineCharacterOffset: { type: "number", description: "Character offset within every source line, for paging very long lines." },
145
+ maxLineCharacters: { type: "number", description: "Characters shown per source line (default 4000, maximum 10000)." },
146
+ },
71
147
  },
72
148
  },
73
149
  required: ["toolCallId", "pattern"],
@@ -1 +1 @@
1
- {"version":3,"file":"grepToolResponse.js","sourceRoot":"","sources":["../../../../src/processors/tools/grepToolResponse.ts"],"names":[],"mappings":";;;AAaA,kCA6DC;AA7DM,KAAK,UAAU,WAAW,CAC/B,IAAY,EACZ,UAAkB,EAClB,OAAe,EACf,YAAsB,EACtB,OAAqB,EACrB,WAA8C;IAE9C,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,MAAM,GAAG,YAAY;aACxB,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;YACV,MAAM,IAAI,GAAG,WAAW,EAAE,CAAC,EAAE,CAAC,CAAC;YAC/B,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACvC,CAAC,CAAC;aACD,IAAI,CAAC,QAAQ,CAAC,CAAC;QAClB,OAAO,iDAAiD,UAAU,wHAAwH,MAAM,IAAI,QAAQ,EAAE,CAAC;IACjN,CAAC;IAED,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/B,MAAM,cAAc,GAAa,EAAE,CAAC;QACpC,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,KAAK,CAAC;QAChD,MAAM,WAAW,GAAG,OAAO,EAAE,WAAW,IAAI,KAAK,CAAC;QAClD,MAAM,aAAa,GAAG,OAAO,EAAE,aAAa,IAAI,CAAC,CAAC;QAClD,MAAM,YAAY,GAAG,OAAO,EAAE,YAAY,IAA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C,IAAI,CAAC,CAAC,CAAC;gBAG7C,CAAC,IAAI,YAAY,CAAC;YACpB,CAAC;QACH,CAAC;QAED,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAChC,OAAO,iCAAiC,OAAO,oBAAoB,UAAU,GAAG,CAAC;QACnF,CAAC;QAED,OAAO,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,OAAO,eAAe,KAAK,CAAC,OAAO,EAAE,CAAC;IACxC,CAAC;AACH,CAAC;AAEY,QAAA,0BAA0B,GAAS;IAC9C,IAAI,EAAE,UAAU;IAChB,QAAQ,EAAE;QACR,IAAI,EAAE,kBAAkB;QACxB,WAAW,EACT,4OAA4O;QAC9O,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE;gBACV,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,4CAA4C;iBAC1D;gBACD,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,+DAA+D;iBAC7E;gBACD,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,wJAAwJ;oBACrK,UAAU,EAAE,EAAE;iBACf;aACF;YACD,QAAQ,EAAE,CAAC,YAAY,EAAE,SAAS,CAAC;SACpC;KACF;CACF,CAAC"}
1
+ {"version":3,"file":"grepToolResponse.js","sourceRoot":"","sources":["../../../../src/processors/tools/grepToolResponse.ts"],"names":[],"mappings":";;;AAmCA,kCA2JC;AAhLD,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAChC,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,MAAM,sBAAsB,GAAG,MAAM,CAAC;AACtC,MAAM,cAAc,GAAG,MAAM,CAAC;AAC9B,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAC1C,MAAM,mBAAmB,GAAG,MA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AE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,iEAAiE,EAAE;qBACtH;iBACF;aACF;YACD,QAAQ,EAAE,CAAC,YAAY,EAAE,SAAS,CAAC;SACpC;KACF;CACF,CAAC"}
@@ -1,4 +1,4 @@
1
- export { jqToolResponseDefinition, executeJqQuery, } from "./jqToolResponse";
1
+ export { jqToolResponseDefinition, executeJqQuery, JqOptions, } from "./jqToolResponse";
2
2
  export { grepToolResponseDefinition, executeGrep, GrepOptions, } from "./grepToolResponse";
3
3
  export { tailToolResponseDefinition, executeTail, TailOptions, } from "./tailToolResponse";
4
- export { listStoredToolResponsesDefinition, executeListStoredToolResponses, } from "./listStoredToolResponses";
4
+ export { listStoredToolResponsesDefinition, executeListStoredToolResponses, ListStoredToolResponsesOptions, } from "./listStoredToolResponses";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/processors/tools/index.ts"],"names":[],"mappings":";;;AAAA,mDAG0B;AAFxB,0HAAA,wBAAwB,OAAA;AACxB,gHAAA,cAAc,OAAA;AAGhB,uDAI4B;AAH1B,8HAAA,0BAA0B,OAAA;AAC1B,+GAAA,WAAW,OAAA;AAIb,uDAI4B;AAH1B,8HAAA,0BAA0B,OAAA;AAC1B,+GAAA,WAAW,OAAA;AAIb,qEAGmC;AAFjC,4IAAA,iCAAiC,OAAA;AACjC,yIAAA,8BAA8B,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/processors/tools/index.ts"],"names":[],"mappings":";;;AAAA,mDAI0B;AAHxB,0HAAA,wBAAwB,OAAA;AACxB,gHAAA,cAAc,OAAA;AAIhB,uDAI4B;AAH1B,8HAAA,0BAA0B,OAAA;AAC1B,+GAAA,WAAW,OAAA;AAIb,uDAI4B;AAH1B,8HAAA,0BAA0B,OAAA;AAC1B,+GAAA,WAAW,OAAA;AAIb,qEAImC;AAHjC,4IAAA,iCAAiC,OAAA;AACjC,yIAAA,8BAA8B,OAAA"}
@@ -1,5 +1,9 @@
1
1
  import { Tool } from "../../clients";
2
+ export interface JqOptions {
3
+ characterOffset?: number;
4
+ maxCharacters?: number;
5
+ }
2
6
  export declare function executeJqQuery(data: string, toolCallId: string, jqQuery: string, availableIds: string[], toolNameMap?: {
3
7
  [toolCallId: string]: string;
4
- }): Promise<string>;
8
+ }, options?: JqOptions): Promise<string>;
5
9
  export declare const jqToolResponseDefinition: Tool;
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.jqToolResponseDefinition = void 0;
37
37
  exports.executeJqQuery = executeJqQuery;
38
38
  const jq = __importStar(require("node-jq"));
39
+ const boundedToolResponse_1 = require("./boundedToolResponse");
39
40
  function tryParseJson(content) {
40
41
  try {
41
42
  return JSON.parse(content);
@@ -64,7 +65,7 @@ function parseNestedJsonStrings(obj) {
64
65
  }
65
66
  return obj;
66
67
  }
67
- async function executeJqQuery(data, toolCallId, jqQuery, availableIds, toolNameMap) {
68
+ async function executeJqQuery(data, toolCallId, jqQuery, availableIds, toolNameMap, options) {
68
69
  if (!data) {
69
70
  const idList = availableIds
70
71
  .map((id) => {
@@ -72,27 +73,29 @@ async function executeJqQuery(data, toolCallId, jqQuery, availableIds, toolNameM
72
73
  return name ? `${id} (${name})` : id;
73
74
  })
74
75
  .join("\n - ");
75
- return `Error: No tool response found for toolCallId "${toolCallId}". Call listStoredToolResponses to see all available responses with their tool names.\n\nAvailable toolCallIds:\n - ${idList || "(none)"}`;
76
+ return (0, boundedToolResponse_1.paginateToolResponse)(`Error: No tool response found for toolCallId "${toolCallId}". Call listStoredToolResponses to see all available responses with their tool names.\n\nAvailable toolCallIds:\n - ${idList || "(none)"}`, options, "available toolCallId list");
76
77
  }
77
78
  try {
78
79
  const jsonData = tryParseJson(data);
79
80
  if (!jsonData) {
80
- return `Error: Tool response data is not valid JSON for toolCallId "${toolCallId}"`;
81
+ return (0, boundedToolResponse_1.paginateToolResponse)(`Error: Tool response data is not valid JSON for toolCallId "${toolCallId}"`, options, "jq input error");
81
82
  }
82
83
  const parsedData = parseNestedJsonStrings(jsonData);
83
84
  const result = await jq.run(jqQuery, parsedData, { input: "json" });
85
+ let rendered;
84
86
  if (typeof result === "string") {
85
- return result;
87
+ rendered = result;
86
88
  }
87
89
  else if (typeof result === "number" || typeof result === "boolean") {
88
- return String(result);
90
+ rendered = String(result);
89
91
  }
90
92
  else if (result === null) {
91
- return "null";
93
+ rendered = "null";
92
94
  }
93
95
  else {
94
- return JSON.stringify(result);
96
+ rendered = JSON.stringify(result);
95
97
  }
98
+ return (0, boundedToolResponse_1.paginateToolResponse)(rendered, options, "jq result");
96
99
  }
97
100
  catch (error) {
98
101
  let errorMessage = `JQ Query Error: ${error.message}`;
@@ -103,14 +106,14 @@ async function executeJqQuery(data, toolCallId, jqQuery, availableIds, toolNameM
103
106
  else {
104
107
  errorMessage += `\nData structure preview:\n${JSON.stringify(jsonObj, null, 2).substring(0, 500)}...`;
105
108
  }
106
- return errorMessage;
109
+ return (0, boundedToolResponse_1.paginateToolResponse)(errorMessage, options, "jq error");
107
110
  }
108
111
  }
109
112
  exports.jqToolResponseDefinition = {
110
113
  type: "function",
111
114
  function: {
112
115
  name: "jqToolResponse",
113
- description: "Execute a JQ query on a stored tool response to extract specific data. Use this when you need to extract specific information from any tool response that has been stored. This is the preferred way to search or filter compressed JSON tool responses — it parses the data automatically without requiring repeated expandTokens calls. IMPORTANT: You do NOT know the toolCallId at the time you call a tool — you must call listStoredToolResponses first to discover the correct toolCallId. The listStoredToolResponses output shows each response's tool name so you can identify which response belongs to which call. How to determine the correct JQ query: (1) For mcp_* tool responses (external MCP tools like mcp_1_*): the response is stored as a raw JSON object — use '.' to access the root directly, e.g. '.children | map(.name)' or '.state'. Do NOT use .content[0].text | fromjson for these. (2) For compressed MCP tool responses (._mcp_format === true): use '._data' e.g. '._data.children | map(.name)'. (3) For standard built-in tool responses: data may be nested under '.content[0].text | fromjson'. Use jqToolResponse instead of expandTokens whenever the stored data is JSON.",
116
+ description: "Execute a JQ query on a stored tool response. Output is bounded to 20,000 characters by default; use options.characterOffset to page through a large result. Prefer a selective JQ query over paging a broad query. Call listStoredToolResponses first to discover the toolCallId. MCP responses are generally rooted at '.' (or '._data' when _mcp_format is true); standard built-in responses may be nested under '.content[0].text | fromjson'.",
114
117
  parameters: {
115
118
  type: "object",
116
119
  positional: true,
@@ -123,6 +126,20 @@ exports.jqToolResponseDefinition = {
123
126
  type: "string",
124
127
  description: "The JQ query to execute on the tool response data. For mcp_* tool responses (raw JSON object): '.children | map({id: .id, name: .name})' (extract fields from children array), '.children | map(select(.state == \"PENDING\")) | length' (count pending children), '.name' (get a top-level field). For compressed responses (._mcp_format true): '._data.children | map(.name)' or '._data | map(select(.state == \"PENDING\")) | length'. For standard built-in tool responses: '.content[0].text | fromjson | map(.title)' (extract titles from standard MCP array), '.content[0].text | fromjson | map(select(.createdAt > \"2025-01-01\"))' (filter by date).",
125
128
  },
129
+ options: {
130
+ type: "object",
131
+ description: "Optional output pagination settings.",
132
+ properties: {
133
+ characterOffset: {
134
+ type: "number",
135
+ description: "Zero-based character offset into the rendered JQ result.",
136
+ },
137
+ maxCharacters: {
138
+ type: "number",
139
+ description: "Response size (default 20000, hard maximum 50000).",
140
+ },
141
+ },
142
+ },
126
143
  },
127
144
  required: ["toolCallId", "jqQuery"],
128
145
  },
@@ -1 +1 @@
1
- {"version":3,"file":"jqToolResponse.js","sourceRoot":"","sources":["../../../../src/processors/tools/jqToolResponse.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,wCA2DC;AAtGD,4CAA8B;AAK9B,SAAS,YAAY,CAAC,OAAe;IACnC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAKD,SAAS,sBAAsB,CAAC,GAAQ;IACtC,IAA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S;IAC5C,IAAI,EAAE,UAAU;IAChB,QAAQ,EAAE;QACR,IAAI,EAAE,gBAAgB;QACtB,WAAW,EACT,upCAAupC;QACzpC,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE;gBACV,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,4CAA4C;iBAC1D;gBACD,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,ooBAAooB;iBACvoB;aACF;YACD,QAAQ,EAAE,CAAC,YAAY,EAAE,SAAS,CAAC;SACpC;KACF;CACF,CAAC"}
1
+ {"version":3,"file":"jqToolResponse.js","sourceRoot":"","sources":["../../../../src/processors/tools/jqToolResponse.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,wCAqEC;AAtHD,4CAA8B;AAC9B,+DAA6D;AAU7D,SAAS,YAAY,CAAC,OAAe;IACnC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAKD,SAAS,sBAAsB,CAAC,GAAQ;IACtC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,IAAI,GAAG,IAAI,OAAO,G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ACV,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE;gBACV,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,4CAA4C;iBAC1D;gBACD,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,ooBAAooB;iBACvoB;gBACD,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,sCAAsC;oBACnD,UAAU,EAAE;wBACV,eAAe,EAAE;4BACf,IAAI,EAAE,QAAQ;4BACd,WAAW,EAAE,0DAA0D;yBACxE;wBACD,aAAa,EAAE;4BACb,IAAI,EAAE,QAAQ;4BACd,WAAW,EAAE,oDAAoD;yBAClE;qBACF;iBACF;aACF;YACD,QAAQ,EAAE,CAAC,YAAY,EAAE,SAAS,CAAC;SACpC;KACF;CACF,CAAC"}
@@ -1,4 +1,10 @@
1
1
  import { Tool } from "../../clients";
2
+ export interface ListStoredToolResponsesOptions {
3
+ resultOffset?: number;
4
+ maxResults?: number;
5
+ characterOffset?: number;
6
+ maxCharacters?: number;
7
+ }
2
8
  export interface ToolResponseInfo {
3
9
  toolCallId: string;
4
10
  toolName: string;
@@ -17,5 +23,5 @@ export declare function executeListStoredToolResponses(storage: {
17
23
  };
18
24
  }, toolNameMap: {
19
25
  [toolCallId: string]: string;
20
- }): Promise<string>;
26
+ }, options?: ListStoredToolResponsesOptions): Promise<string>;
21
27
  export declare const listStoredToolResponsesDefinition: Tool;
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.listStoredToolResponsesDefinition = void 0;
4
4
  exports.executeListStoredToolResponses = executeListStoredToolResponses;
5
- async function executeListStoredToolResponses(storage, metadataStorage, toolNameMap) {
5
+ const boundedToolResponse_1 = require("./boundedToolResponse");
6
+ async function executeListStoredToolResponses(storage, metadataStorage, toolNameMap, options) {
6
7
  const toolCallIds = Object.keys(storage);
7
8
  if (toolCallIds.length === 0) {
8
9
  return "No tool responses have been stored yet.";
@@ -21,30 +22,59 @@ async function executeListStoredToolResponses(storage, metadataStorage, toolName
21
22
  };
22
23
  });
23
24
  responses.sort((a, b) => b.storedAt - a.storedAt);
24
- const output = responses
25
+ const resultOffset = (0, boundedToolResponse_1.boundedInteger)(options?.resultOffset, 0, 0, responses.length);
26
+ const maxResults = (0, boundedToolResponse_1.boundedInteger)(options?.maxResults, 100, 1, 1000);
27
+ const page = responses.slice(resultOffset, resultOffset + maxResults);
28
+ const output = page
25
29
  .map((resp) => {
26
30
  const date = new Date(resp.storedAt).toISOString();
27
31
  return `
28
- Tool Call ID: ${resp.toolCallId}
29
- Tool Name: ${resp.toolName}
32
+ Tool Call ID: ${resp.toolCallId.slice(0, 500)}
33
+ Tool Name: ${resp.toolName.slice(0, 500)}
30
34
  Size: ${resp.size} characters
31
35
  Stored At: ${date}
32
36
  Preview: ${resp.preview}
33
37
  ---`;
34
38
  })
35
39
  .join("\n");
36
- return `Found ${responses.length} stored tool response(s):\n${output}`;
40
+ const nextOffset = resultOffset + page.length;
41
+ const footer = nextOffset < responses.length
42
+ ? `\n[More stored responses available. Repeat with options.resultOffset=${nextOffset}.]`
43
+ : "\n[End of stored responses.]";
44
+ return (0, boundedToolResponse_1.paginateToolResponse)(`Found ${responses.length} stored tool response(s); showing ${resultOffset + 1}-${nextOffset}:\n${output}${footer}`, options, "stored-response list");
37
45
  }
38
46
  exports.listStoredToolResponsesDefinition = {
39
47
  type: "function",
40
48
  function: {
41
49
  name: "listStoredToolResponses",
42
- description: "List all stored tool responses with metadata including tool call ID, tool name, size, timestamp, and a preview of the content. ALWAYS call this before using jqToolResponse, grepToolResponse, or tailToolResponse — you need the toolCallId from this list to query a specific response. The tool name shown here corresponds to the tool that produced the response (e.g. 'mcp_1_knowhow-web_GetOrgUserTask'), making it easy to identify which response you want.",
50
+ description: "List a bounded page of stored tool responses with IDs, tool names, sizes, timestamps, and previews. Call this before jqToolResponse, grepToolResponse, or tailToolResponse to discover a toolCallId.",
43
51
  parameters: {
44
52
  type: "object",
45
- positional: false,
46
- properties: {},
47
- required: [],
53
+ positional: true,
54
+ properties: {
55
+ options: {
56
+ type: "object",
57
+ description: "Optional result and output pagination settings.",
58
+ properties: {
59
+ resultOffset: {
60
+ type: "number",
61
+ description: "Zero-based response offset (default 0).",
62
+ },
63
+ maxResults: {
64
+ type: "number",
65
+ description: "Responses per page (default 100, maximum 1000).",
66
+ },
67
+ characterOffset: {
68
+ type: "number",
69
+ description: "Character offset within the rendered page.",
70
+ },
71
+ maxCharacters: {
72
+ type: "number",
73
+ description: "Response size (default 20000, hard maximum 50000).",
74
+ },
75
+ },
76
+ },
77
+ },
48
78
  },
49
79
  },
50
80
  };
@@ -1 +1 @@
1
- {"version":3,"file":"listStoredToolResponses.js","sourceRoot":"","sources":["../../../../src/processors/tools/listStoredToolResponses.ts"],"names":[],"mappings":";;;AAaA,wEAsDC;AAtDM,KAAK,UAAU,8BAA8B,CAClD,OAAyC,EACzC,eAOC,EACD,WAA6C;IAE7C,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAEzC,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,yCAAyC,CAAC;IACnD,CAAC;IAED,MAAM,SAAS,GAAuB,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;QACnE,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;QACjC,MAAM,QAAQ,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC;QAC7C,MAAM,QAAQ,GAAG,WAAW,CAAC,UAAU,CAAC,IAAI,SAAS,CAAC;QAGtD,MAAM,OAAO,GACX,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;QAE5D,OAAO;YACL,UAAU;YACV,QAAQ;YACR,IAAI,EAAE,QAAQ,EAAE,cAAc,IAAI,IAAI,CAAC,MAAM;YAC7C,QAAQ,EAAE,QAAQ,EAAE,QAAQ,IAAI,CAAC;YACjC,OAAO;SACR,CAAC;IACJ,CAAC,CAAC,CAAC;IAGH,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;IAGlD,MAAM,MAAM,GAAG,SAAS;SACrB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACZ,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;QACnD,OAAO;gBACG,IAAI,CAAC,UAAU;aAClB,IAAI,CAAC,QAAQ;QAClB,IAAI,CAAC,IAAI;aACJ,IAAI;WACN,IAAI,CAAC,OAAO;IACnB,CAAC;IACD,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,OAAO,SAAS,SAAS,CAAC,MAAM,8BAA8B,MAAM,EAAE,CAAC;AACzE,CAAC;AAEY,QAAA,iCAAiC,GAAS;IACrD,IAAI,EAAE,UAAU;IAChB,QAAQ,EAAE;QACR,IAAI,EAAE,yBAAyB;QAC/B,WAAW,EACT,scAAsc;QACxc,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,KAAK;YACjB,UAAU,EAAE,EAAE;YACd,QAAQ,EAAE,EAAE;SACb;KACF;CACF,CAAC"}
1
+ {"version":3,"file":"listStoredToolResponses.js","sourceRoot":"","sources":["../../../../src/processors/tools/listStoredToolResponses.ts"],"names":[],"mappings":";;;AAqBA,wEAiEC;AArFD,+DAA6E;AAoBtE,KAAK,UAAU,8BAA8B,CAClD,OAAyC,EACzC,eAOC,EACD,WAA6C,EAC7C,OAAwC;IAExC,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI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Q;4BACd,WAAW,EAAE,4CAA4C;yBAC1D;wBACD,aAAa,EAAE;4BACb,IAAI,EAAE,QAAQ;4BACd,WAAW,EAAE,oDAAoD;yBAClE;qBACF;iBACF;aACF;SACF;KACF;CACF,CAAC"}
@@ -1,6 +1,11 @@
1
1
  import { Tool } from "../../clients";
2
2
  export interface TailOptions {
3
3
  lines?: number;
4
+ endLine?: number;
5
+ lineCharacterOffset?: number;
6
+ maxLineCharacters?: number;
7
+ characterOffset?: number;
8
+ maxCharacters?: number;
4
9
  }
5
10
  export declare function executeTail(data: string, toolCallId: string, availableIds: string[], options?: TailOptions, toolNameMap?: {
6
11
  [toolCallId: string]: string;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tailToolResponseDefinition = void 0;
4
4
  exports.executeTail = executeTail;
5
+ const boundedToolResponse_1 = require("./boundedToolResponse");
5
6
  async function executeTail(data, toolCallId, availableIds, options, toolNameMap) {
6
7
  if (data === null || data === undefined) {
7
8
  const idList = availableIds
@@ -10,46 +11,88 @@ async function executeTail(data, toolCallId, availableIds, options, toolNameMap)
10
11
  return name ? `${id} (${name})` : id;
11
12
  })
12
13
  .join("\n - ");
13
- return `Error: No tool response found for toolCallId "${toolCallId}". Call listStoredToolResponses to see all available responses with their tool names.\n\nAvailable toolCallIds:\n - ${idList || "(none)"}`;
14
+ return (0, boundedToolResponse_1.paginateToolResponse)(`Error: No tool response found for toolCallId "${toolCallId}". Call listStoredToolResponses to see all available responses with their tool names.\n\nAvailable toolCallIds:\n - ${idList || "(none)"}`, {
15
+ characterOffset: options?.characterOffset,
16
+ maxCharacters: options?.maxCharacters,
17
+ }, "available toolCallId list");
14
18
  }
15
19
  try {
16
20
  const lines = data.split("\n");
17
- const numLines = options?.lines ?? 10;
21
+ const numLines = (0, boundedToolResponse_1.boundedInteger)(options?.lines, 10, 0, 1000);
18
22
  if (numLines <= 0) {
19
23
  return "";
20
24
  }
21
- const startIdx = Math.max(0, lines.length - numLines);
22
- const tailLines = lines.slice(startIdx);
23
- const formatted = tailLines.map((line, idx) => {
24
- const lineNum = startIdx + idx + 1;
25
- return `${lineNum}: ${line}`;
25
+ const endLine = (0, boundedToolResponse_1.boundedInteger)(options?.endLine, lines.length, 1, lines.length);
26
+ const startIdx = Math.max(0, endLine - numLines);
27
+ const lineCharacterOffset = (0, boundedToolResponse_1.boundedInteger)(options?.lineCharacterOffset, 0, 0, Number.MAX_SAFE_INTEGER);
28
+ const maxLineCharacters = (0, boundedToolResponse_1.boundedInteger)(options?.maxLineCharacters, 4000, 100, 10_000);
29
+ const longLines = [];
30
+ const formatted = lines.slice(startIdx, endLine).map((line, idx) => {
31
+ const lineNumber = startIdx + idx + 1;
32
+ const visible = line.slice(lineCharacterOffset, lineCharacterOffset + maxLineCharacters);
33
+ if (lineCharacterOffset + maxLineCharacters < line.length) {
34
+ longLines.push(lineNumber);
35
+ }
36
+ return `${lineNumber}: ${visible}`;
26
37
  });
27
- return formatted.join("\n");
38
+ const notes = [];
39
+ if (typeof options?.endLine === "number" && startIdx > 0) {
40
+ notes.push(`[Earlier lines available: repeat with options.endLine=${startIdx}.]`);
41
+ }
42
+ if (longLines.length > 0)
43
+ notes.push(`[Long lines ${longLines.join(", ")} were sliced; repeat with options.lineCharacterOffset=${lineCharacterOffset + maxLineCharacters}.]`);
44
+ const rendered = formatted.join("\n") +
45
+ (notes.length > 0 ? `\n\n${notes.join("\n")}` : "");
46
+ return (0, boundedToolResponse_1.paginateToolResponse)(rendered, {
47
+ characterOffset: options?.characterOffset,
48
+ maxCharacters: options?.maxCharacters,
49
+ }, "tail result");
28
50
  }
29
51
  catch (error) {
30
- return `Tail Error: ${error.message}`;
52
+ const message = error instanceof Error ? error.message : String(error);
53
+ return `Tail Error: ${message.slice(0, 500)}`;
31
54
  }
32
55
  }
33
56
  exports.tailToolResponseDefinition = {
34
57
  type: "function",
35
58
  function: {
36
59
  name: "tailToolResponse",
37
- description: "Get the last n lines from a stored tool response. Similar to the Unix 'tail' command, useful when a tool response is too large and you only need to see the end. Returns the last n lines with line numbers.",
60
+ description: "Get a bounded page of lines from the end of a stored tool response. Use endLine to page backward and lineCharacterOffset to page through unusually long lines.",
38
61
  parameters: {
39
62
  type: "object",
40
63
  positional: true,
41
64
  properties: {
42
65
  toolCallId: {
43
66
  type: "string",
44
- description: "The toolCallId of the stored tool response",
67
+ description: "The toolCallId of the stored tool response.",
45
68
  },
46
69
  options: {
47
70
  type: "object",
48
- description: "Optional tail settings: lines (number, default: 10) - number of lines to return from the end",
71
+ description: "Optional tail and pagination settings.",
49
72
  properties: {
50
73
  lines: {
51
74
  type: "number",
52
- description: "Number of lines to return from the end (default: 10)",
75
+ description: "Lines per page (default 10, maximum 1000).",
76
+ },
77
+ endLine: {
78
+ type: "number",
79
+ description: "1-based inclusive line at which the page ends; use the returned value to page backward.",
80
+ },
81
+ lineCharacterOffset: {
82
+ type: "number",
83
+ description: "Character offset within each source line.",
84
+ },
85
+ maxLineCharacters: {
86
+ type: "number",
87
+ description: "Characters shown per line (default 4000, maximum 10000).",
88
+ },
89
+ characterOffset: {
90
+ type: "number",
91
+ description: "Character offset within the rendered tail page.",
92
+ },
93
+ maxCharacters: {
94
+ type: "number",
95
+ description: "Response size (default 20000, hard maximum 50000).",
53
96
  },
54
97
  },
55
98
  },
@@ -1 +1 @@
1
- {"version":3,"file":"tailToolResponse.js","sourceRoot":"","sources":["../../../../src/processors/tools/tailToolResponse.ts"],"names":[],"mappings":";;;AASA,kCAwCC;AAxCM,KAAK,UAAU,WAAW,CAC/B,IAAY,EACZ,UAAkB,EAClB,YAAsB,EACtB,OAAqB,EACrB,WAA8C;IAE9C,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACxC,MAAM,MAAM,GAAG,YAAY;aACxB,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;YACV,MAAM,IAAI,GAAG,WAAW,EAAE,CAAC,EAAE,CAAC,CAAC;YAC/B,OAA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V,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,4CAA4C;iBAC1D;gBACD,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,8FAA8F;oBAC3G,UAAU,EAAE;wBACV,KAAK,EAAE;4BACL,IAAI,EAAE,QAAQ;4BACd,WAAW,EAAE,sDAAsD;yBACpE;qBACF;iBACF;aACF;YACD,QAAQ,EAAE,CAAC,YAAY,CAAC;SACzB;KACF;CACF,CAAC"}
1
+ {"version":3,"file":"tailToolResponse.js","sourceRoot":"","sources":["../../../../src/processors/tools/tailToolResponse.ts"],"names":[],"mappings":";;;AAeA,kCAgFC;AA9FD,+DAA6E;AActE,KAAK,UAAU,WAAW,CAC/B,IAAY,EACZ,UAAkB,EAClB,YAAsB,EACtB,OAAqB,EACrB,WAA8C;IAE9C,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACxC,MAAM,MAAM,GAAG,YAAY;aACxB,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;YACV,MAAM,IAAI,GAAG,WAAW,EAAE,CAAC,EAAE,CAAC,CAAC;YAC/B,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACvC,CAAC,CAAC;aACD,IAAI,CAAC,QAAQ,CAAC,CAAC;QAClB,OAAO,IAAA,0CAAoB,EACzB,iDAAiD,UAAU,wHAAwH,MAAM,IAAI,QAAQ,EAAE,EACvM;YACE,eAAe,EAAE,OAAO,EAAE,eAAe;YACzC,aAAa,EAAE,OAAO,EAAE,aAAa;SACtC,EACD,2BAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/B,MAAM,QAAQ,GAAG,IAAA,oCAAc,EAAC,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,E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E;4BACL,IAAI,EAAE,QAAQ;4BACd,WAAW,EAAE,4CAA4C;yBAC1D;wBACD,OAAO,EAAE;4BACP,IAAI,EAAE,QAAQ;4BACd,WAAW,EACT,yFAAyF;yBAC5F;wBACD,mBAAmB,EAAE;4BACnB,IAAI,EAAE,QAAQ;4BACd,WAAW,EAAE,2CAA2C;yBACzD;wBACD,iBAAiB,EAAE;4BACjB,IAAI,EAAE,QAAQ;4BACd,WAAW,EACT,0DAA0D;yBAC7D;wBACD,eAAe,EAAE;4BACf,IAAI,EAAE,QAAQ;4BACd,WAAW,EAAE,iDAAiD;yBAC/D;wBACD,aAAa,EAAE;4BACb,IAAI,EAAE,QAAQ;4BACd,WAAW,EAAE,oDAAoD;yBAClE;qBACF;iBACF;aACF;YACD,QAAQ,EAAE,CAAC,YAAY,CAAC;SACzB;KACF;CACF,CAAC"}
@@ -10,6 +10,7 @@ export declare class LazyToolsService extends ToolsService {
10
10
  addTools(tools: Tool[]): void;
11
11
  addTool(tool: Tool): void;
12
12
  getTools(): Tool[];
13
+ resetTools(): void;
13
14
  enableTools(patterns: string[]): {
14
15
  enabled: number;
15
16
  total: number;
@@ -39,6 +39,11 @@ class LazyToolsService extends Tools_1.ToolsService {
39
39
  getTools() {
40
40
  return this.tools;
41
41
  }
42
+ resetTools() {
43
+ this.allTools = [];
44
+ super.resetTools();
45
+ this.registerLazyTools();
46
+ }
42
47
  enableTools(patterns) {
43
48
  for (const pattern of patterns) {
44
49
  if (!this.enabledPatterns.includes(pattern)) {