Fix(mcp): list the whole directory before paging list_files
list_files stopped parsing at 500 entries, so a larger directory reported total=500 with hasMore=false and offsets past 500 returned nothing: the model was told a false limit and could not reach the tail. Parse the full TOKEN_FILE_LIST payload (100000 cap only to bound a pathological directory), page over it, and report truncated=true plus a summary note when the cap hits. Only an empty path now means list drives. Windows "." "/" "\" are normalized to empty in BuildListFiles, while Linux/macOS "/" is a real root directory and is listed; OnDriveList no longer keeps its own copy of the magic-path rule. The file-manager channel carries GBK both ways (Windows FindFirstFileA; common/FileManager.h runs gbkToUtf8 on incoming paths, utf8ToGbk on outgoing names). The old CP_UTF8 choice for LNX/MAC decoded GBK names wrongly and sent UTF-8 paths to a client that treats them as GBK. Paths now go out as GBK, or as raw UTF-8 when GBK cannot represent them (the client's iconv then passes the bytes through). Names decode GBK-first, UTF-8 on failure: UTF-8-first misreads ~18% of common hanzi whose GBK bytes are also valid UTF-8. Go's server gets the same contract: 100000 cap, truncated in structuredContent, and the cap check after a real record so an exact-cap listing with trailing padding is not called truncated. tools_minimal.json is regenerated; the Go truncation test and the design doc are updated. Debug server builds; check_platform_table, gen_go_tools --check and go test ./... pass. The Release instance was not rebuilt or restarted. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
42dd70fe20
commit
5e012019ba
6 files changed
+137
-40
No files matched your search
@@ -723,7 +723,10 @@ func TestListFilesTruncationNote(t *testing.T) {
|
||||
}
|
||||
sc := c.res.StructuredContent.(map[string]any)
|
||||
checkInt(t, sc, "total", fileListMaxEntries)
|
||||
if !strings.Contains(c.res.Content[0].Text, "只解析了前") {
|
||||
if v, ok := sc["truncated"].(bool); !ok || !v {
|
||||
t.Fatalf("structuredContent truncated = %#v, want true", sc["truncated"])
|
||||
}
|
||||
if !strings.Contains(c.res.Content[0].Text, "total 只是上限内的数量") {
|
||||
t.Fatalf("summary does not mention the cap: %q", c.res.Content[0].Text)
|
||||
}
|
||||
// The note must stay on its own line, before the table.
|
||||
@@ -743,3 +746,18 @@ func TestParseFileListEntryCap(t *testing.T) {
|
||||
t.Fatalf("parsed %d entries, truncated=%v", len(files), truncated)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseFileListAtCapIsNotTruncated(t *testing.T) {
|
||||
// Exactly cap entries followed by the client's zero padding: nothing was
|
||||
// dropped, so the summary must not claim truncation.
|
||||
var buf []byte
|
||||
for i := 0; i < fileListMaxEntries; i++ {
|
||||
buf = append(buf, 0, 'a', 0)
|
||||
buf = append(buf, make([]byte, 16)...)
|
||||
}
|
||||
buf = append(buf, 0, 0, 0)
|
||||
files, truncated := parseFileList(buf)
|
||||
if len(files) != fileListMaxEntries || truncated {
|
||||
t.Fatalf("parsed %d entries, truncated=%v", len(files), truncated)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user