MCPcopy Create free account
hub / github.com/diillson/chatcli / buildFetchOutput

Function buildFetchOutput

cli/plugins/builtin_webfetch.go:251–290  ·  view source on GitHub ↗

buildFetchOutput assembles the final string returned to the agent: applies the auto-save preview cap and max_length truncation, then prepends a pointer to the on-disk copy when one was written.

(parsed fetchArgs, filtered, fullContent, savedPath string, autoSaved bool)

Source from the content-addressed store, hash-verified

249// applies the auto-save preview cap and max_length truncation, then
250// prepends a pointer to the on-disk copy when one was written.
251func buildFetchOutput(parsed fetchArgs, filtered, fullContent, savedPath string, autoSaved bool) string {
252 output := filtered
253
254 // When we auto-saved to disk, ship only a compact preview back — full
255 // body is on disk and the model has been told where. Keeping the inline
256 // preview small is THE point of auto-save: otherwise we pay twice
257 // (inline bytes + disk) for the same content.
258 if autoSaved {
259 previewSize := parsed.MaxLength / 4
260 if previewSize < 2000 {
261 previewSize = 2000
262 }
263 if len(output) > previewSize {
264 output = output[:previewSize] + "\n...(auto-truncated — full body saved to disk)"
265 }
266 }
267 truncated := false
268 if len(output) > parsed.MaxLength {
269 output = output[:parsed.MaxLength] + "\n...(truncated)"
270 truncated = true
271 }
272
273 if savedPath == "" {
274 return output
275 }
276
277 var prefix string
278 switch {
279 case autoSaved:
280 prefix = fmt.Sprintf("[auto-saved: response was %d bytes — too large to inline. Full body is at %s. Preview below; use read_file with start/end or rerun with filter/from_line/to_line for specific ranges.]\n\n",
281 len(fullContent), savedPath)
282 case truncated:
283 prefix = fmt.Sprintf("[response truncated inline at %d chars; full response saved to %s — %d bytes. Use read_file with start/end to examine specific ranges.]\n\n",
284 parsed.MaxLength, savedPath, len(fullContent))
285 default:
286 prefix = fmt.Sprintf("[full response saved to %s — %d bytes. Use read_file with start/end to examine specific ranges.]\n\n",
287 savedPath, len(fullContent))
288 }
289 return prefix + output
290}
291
292// parseFetchArgs accepts either a single JSON arg or positional --flag args.
293func parseFetchArgs(args []string) (fetchArgs, error) {

Callers 2

TestBuildFetchOutputFunction · 0.85
ExecuteWithStreamMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestBuildFetchOutputFunction · 0.68