Feature: Filter search_file results by size, mtime and slim fields
Add four optional arguments to search_file that narrow the match list after the client has returned it: min_size and max_size in bytes, modified_after in either YYYY-MM-DD or YYYY-MM-DD HH:MM:SS form, and name_only to keep just path and name per entry. The client still runs the same name-matched recursive search, so these filters cut the response size and the reasoning work on our side, not the scan time on the host -- the summary sentence says so and totalAll keeps the pre-filter count so a too-narrow condition is obvious. Invalid values (negative sizes, an inverted range, a malformed timestamp) are rejected with -32602 before any packet goes out. The timestamp validator only accepted the ten-character form because its shape loop never allowed the two colons, which rejected every nineteen-character value; the loop now whitelists them. Smoke tests cover the unchanged totalAll under a size filter, the slim name_only payload and a rejected timestamp, for 33 checks when the search path is supplied. Design notes are in section 11.4. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
929065e7be
commit
7c5bf3e73d
3 files changed
+127
-1
No files matched your search
@@ -636,3 +636,15 @@ token 只从 `-Token` / env 读取,不落仓库、不打印;无在线主机
|
||||
- `list_all_hosts` 摘要里的在线/离线拆分也按命中条目统计。
|
||||
- **离线主机没有 `clientType`**(历史记录里不存这个字段),所以带 `client_type` 条件时离线主机不会命中——按平台筛历史主机用 `os`。
|
||||
- 验证(Debug 实例):`client_type=exe` 命中 1 台(`EXE`/`os=Windows 11`),`client_type=lnx` 命中 0 台但 `totalAll` 仍为 1;`list_all_hosts` 带 `group=default` 命中 3161 台并正确拆分在线 1 / 离线 3160,`os=zzz` 命中 0 台;冒烟脚本 28/28 通过(新增过滤未命中、totalAll 不变 2 项断言)。
|
||||
|
||||
### 11.4 C4 `search_file` 结果侧过滤
|
||||
|
||||
`search_file` 的搜索条件(根目录 + 通配模式)由客户端执行,改不动;但把匹配项拿回服务端后可以再筛一遍,省掉 AI 端逐条比对。
|
||||
|
||||
- 新增四个可选入参,**都在服务端对已收集的匹配项做过滤**,不减少客户端侧搜索耗时:
|
||||
- `min_size` / `max_size`:字节数,整数,闭区间;负数或非数字返回 `-32602`;两者都给出且 `min_size > max_size` 返回 `-32602`。
|
||||
- `modified_after`:接受 `YYYY-MM-DD`(当天 00:00:00 之后)或 `YYYY-MM-DD HH:MM:SS`;格式不符返回 `-32602`。客户端返回的 `modified` 是定宽 `"YYYY-MM-DD HH:MM:SS"`,可直接字典序比较,所以两种写法都合法(`"2026-01-01" <= "2026-01-01 08:00:00"`)。
|
||||
- `name_only`:布尔,命中项只保留 `path` / `name` 两个字段,适合只要文件清单时省 token。
|
||||
- 过滤在分页之前:`total` 为命中条数、`totalAll` 为过滤前条数;摘要补一句「过滤前共 N 条(大小/修改时间/精简字段过滤在服务端进行,不减少客户端搜索耗时)」。
|
||||
- 过滤只看服务端已收到的条目,所以仍受 `max_results` / `timeout_ms` 截断:客户端没搜完时,过滤结果也是部分的(`truncated` / `finished` 字段照旧反映这一点)。
|
||||
- 验证(Debug 实例,根目录 `C:\Windows\Fonts`、`*.ttf`):基线 255 条;`min_size=1000000` → 39 条且 `totalAll=255`;`name_only=true` 每条只有 `path`/`name`;`modified_after=2026-01-01` → 165 条、`2026-06-03 00:00:00` → 130 条、`2027-01-01` → 0 条;`min_size=-5`、`min_size=10 & max_size=5`、`modified_after=2026/01/01`、`modified_after=2026-01-01 12:00` 均返回预期的 `-32602`。冒烟脚本 33/33 通过(新增 3 项:`min_size` 过滤后 `totalAll` 不变、`name_only` 精简字段、非法 `modified_after` 返回 `-32602`;后三项需带 `-SearchPath` 才执行)。
|
||||
Reference in new issue
Block a user