@probelabs/probe 0.6.0-rc227 → 0.6.0-rc228

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@probelabs/probe",
3
- "version": "0.6.0-rc227",
3
+ "version": "0.6.0-rc228",
4
4
  "description": "Node.js wrapper for the probe code search tool",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -5,6 +5,8 @@ import { randomUUID } from 'crypto';
5
5
 
6
6
  const DEFAULT_MAX_OUTPUT_TOKENS = 20000;
7
7
  const CHARS_PER_TOKEN = 4; // Conservative approximation
8
+ const TAIL_TOKENS = 1000; // Number of tokens to show from the end of truncated output
9
+ const MIN_LIMIT_FOR_TAIL = 2000; // Minimum token limit to use head+tail split
8
10
 
9
11
  /**
10
12
  * Validate and normalize a token limit value.
@@ -61,10 +63,6 @@ export async function truncateIfNeeded(content, tokenCounter, sessionId, maxToke
61
63
  return { truncated: false, content };
62
64
  }
63
65
 
64
- // Truncate to approximately maxTokens worth of characters
65
- const maxChars = limit * CHARS_PER_TOKEN;
66
- const truncatedContent = content.substring(0, maxChars);
67
-
68
66
  // Try to write full output to temp file
69
67
  let tempFilePath = null;
70
68
  let fileError = null;
@@ -79,22 +77,37 @@ export async function truncateIfNeeded(content, tokenCounter, sessionId, maxToke
79
77
  tempFilePath = null;
80
78
  }
81
79
 
80
+ // Build truncated content with head + tail for better context
81
+ let truncatedBody;
82
+ const useTail = limit >= MIN_LIMIT_FOR_TAIL;
83
+
84
+ if (useTail) {
85
+ const headTokens = limit - TAIL_TOKENS;
86
+ const headChars = headTokens * CHARS_PER_TOKEN;
87
+ const tailChars = TAIL_TOKENS * CHARS_PER_TOKEN;
88
+ const headContent = content.substring(0, headChars);
89
+ const tailContent = content.substring(content.length - tailChars);
90
+ const omittedTokens = tokenCount - headTokens - TAIL_TOKENS;
91
+ truncatedBody = `${headContent}\n\n... ${omittedTokens} tokens omitted ...\n\n${tailContent}`;
92
+ } else {
93
+ const maxChars = limit * CHARS_PER_TOKEN;
94
+ truncatedBody = content.substring(0, maxChars);
95
+ }
96
+
82
97
  let message;
83
98
  if (tempFilePath) {
84
99
  message = `Output exceeded maximum size (${tokenCount} tokens, limit: ${limit}).
85
100
  Full output saved to: ${tempFilePath}
86
101
 
87
- --- Truncated Output (first ${limit} tokens approx) ---
88
- ${truncatedContent}
89
- ...
102
+ --- Truncated Output ---
103
+ ${truncatedBody}
90
104
  --- End of Truncated Output ---`;
91
105
  } else {
92
106
  message = `Output exceeded maximum size (${tokenCount} tokens, limit: ${limit}).
93
107
  Warning: Could not save full output to file (${fileError}).
94
108
 
95
- --- Truncated Output (first ${limit} tokens approx) ---
96
- ${truncatedContent}
97
- ...
109
+ --- Truncated Output ---
110
+ ${truncatedBody}
98
111
  --- End of Truncated Output ---`;
99
112
  }
100
113