( toolName: string, tokens: number, percent: number, )
| 96 | } |
| 97 | |
| 98 | function getLargeToolSuggestion( |
| 99 | toolName: string, |
| 100 | tokens: number, |
| 101 | percent: number, |
| 102 | ): ContextSuggestion | null { |
| 103 | const tokenStr = formatTokens(tokens) |
| 104 | |
| 105 | switch (toolName) { |
| 106 | case BASH_TOOL_NAME: |
| 107 | return { |
| 108 | severity: 'warning', |
| 109 | title: `Bash results using ${tokenStr} tokens (${percent.toFixed(0)}%)`, |
| 110 | detail: |
| 111 | 'Pipe output through head, tail, or grep to reduce result size. Avoid cat on large files \u2014 use Read with offset/limit instead.', |
| 112 | savingsTokens: Math.floor(tokens * 0.5), |
| 113 | } |
| 114 | case FILE_READ_TOOL_NAME: |
| 115 | return { |
| 116 | severity: 'info', |
| 117 | title: `Read results using ${tokenStr} tokens (${percent.toFixed(0)}%)`, |
| 118 | detail: |
| 119 | 'Use offset and limit parameters to read only the sections you need. Avoid re-reading entire files when you only need a few lines.', |
| 120 | savingsTokens: Math.floor(tokens * 0.3), |
| 121 | } |
| 122 | case GREP_TOOL_NAME: |
| 123 | return { |
| 124 | severity: 'info', |
| 125 | title: `Grep results using ${tokenStr} tokens (${percent.toFixed(0)}%)`, |
| 126 | detail: |
| 127 | 'Add more specific patterns or use the glob or type parameter to narrow file types. Consider Glob for file discovery instead of Grep.', |
| 128 | savingsTokens: Math.floor(tokens * 0.3), |
| 129 | } |
| 130 | case WEB_FETCH_TOOL_NAME: |
| 131 | return { |
| 132 | severity: 'info', |
| 133 | title: `WebFetch results using ${tokenStr} tokens (${percent.toFixed(0)}%)`, |
| 134 | detail: |
| 135 | 'Web page content can be very large. Consider extracting only the specific information needed.', |
| 136 | savingsTokens: Math.floor(tokens * 0.4), |
| 137 | } |
| 138 | default: |
| 139 | if (percent >= 20) { |
| 140 | return { |
| 141 | severity: 'info', |
| 142 | title: `${toolName} using ${tokenStr} tokens (${percent.toFixed(0)}%)`, |
| 143 | detail: `This tool is consuming a significant portion of context.`, |
| 144 | savingsTokens: Math.floor(tokens * 0.2), |
| 145 | } |
| 146 | } |
| 147 | return null |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | function checkReadResultBloat( |
| 152 | data: ContextData, |
no test coverage detected