a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
65 lines
1.9 KiB
Go
65 lines
1.9 KiB
Go
package mcp
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/zzet/gortex/internal/excludes"
|
|
)
|
|
|
|
// omission builds one machine-readable omission note for a tool
|
|
// response envelope. kind is a stable token — compressed, truncated,
|
|
// binary, vendored, or generated — and detail is a short human
|
|
// explanation. The note tells the model that code is intentionally
|
|
// absent or reshaped, so it does not hallucinate about what it cannot
|
|
// see in the payload.
|
|
func omission(kind, detail string) map[string]any {
|
|
return map[string]any{"kind": kind, "detail": detail}
|
|
}
|
|
|
|
// pathOmissions returns the vendored / generated notes that can be
|
|
// inferred from a file path alone. Both may apply; the result is nil
|
|
// when neither does.
|
|
func pathOmissions(path string) []map[string]any {
|
|
var notes []map[string]any
|
|
if excludes.IsVendored(path) {
|
|
notes = append(notes, omission("vendored",
|
|
"file lives under a vendored dependency or build-output directory — not first-party code"))
|
|
}
|
|
if excludes.IsGenerated(path) {
|
|
notes = append(notes, omission("generated",
|
|
"file name matches a code-generation convention — edits here are overwritten by the generator"))
|
|
}
|
|
return notes
|
|
}
|
|
|
|
// looksBinary reports whether content is non-text. A NUL byte in the
|
|
// sampled head is the signal git and most editors use.
|
|
func looksBinary(content []byte) bool {
|
|
n := len(content)
|
|
if n > 8192 {
|
|
n = 8192
|
|
}
|
|
for i := 0; i < n; i++ {
|
|
if content[i] == 0 {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// omissionKindsCSV joins the kind tokens of a note list for a GCX
|
|
// header, where the space-splitting header tokeniser rules out the
|
|
// prose detail. Returns "" for an empty list.
|
|
func omissionKindsCSV(notes []map[string]any) string {
|
|
if len(notes) == 0 {
|
|
return ""
|
|
}
|
|
kinds := make([]string, 0, len(notes))
|
|
for _, n := range notes {
|
|
if k, ok := n["kind"].(string); ok {
|
|
kinds = append(kinds, k)
|
|
}
|
|
}
|
|
return strings.Join(kinds, ",")
|
|
}
|