FormatKnowledgeHits renders search results for the tool transcript: each passage cites its knowledge base, source path and position, with a bounded snippet, so the model can follow up with `get` on the exact document.
(query string, hits []KnowledgeHit)
| 229 | // passage cites its knowledge base, source path and position, with a bounded |
| 230 | // snippet, so the model can follow up with `get` on the exact document. |
| 231 | func FormatKnowledgeHits(query string, hits []KnowledgeHit) string { |
| 232 | if len(hits) == 0 { |
| 233 | return "No passages matched. Try different terms, or use toc to inspect what the knowledge base covers." |
| 234 | } |
| 235 | var b strings.Builder |
| 236 | fmt.Fprintf(&b, "%d passage(s) for %q (snippets — read full documents with get):\n\n", len(hits), query) |
| 237 | for i, h := range hits { |
| 238 | fmt.Fprintf(&b, "[%d] %s :: %s (lines %d-%d)\n", i+1, h.ContextName, h.Seg.FilePath, h.Seg.StartLine, h.Seg.EndLine) |
| 239 | b.WriteString("```\n") |
| 240 | b.WriteString(snippet(h.Seg.Content, searchSnippetChars)) |
| 241 | b.WriteString("\n```\n\n") |
| 242 | } |
| 243 | b.WriteString("Use {\"cmd\":\"get\",\"args\":{\"source\":\"<path before the #>\"}} to read a full document.") |
| 244 | return b.String() |
| 245 | } |
| 246 | |
| 247 | // snippet trims s to at most limit bytes, preferring a word boundary and |
| 248 | // always landing on a rune boundary, flagging the elision so the model knows |