Files
Sakurasan d5dac5a6fc feat: AutoZero 通用 Agent 框架(从 AutoGo 五阶段拆分完成)
llm(三协议 Provider)/ session(JSONL 持久化)/ tools(Registry、围栏、
builtin、computer)/ cdp(browser)/ skills / mcp / agent(循环、两级压缩、
编排、审批门控)+ 底座 jsonl/textx/execx/diag/scratch/spill/imagecache。

产品装配代码(config 桥接、schedule 工具、memory/plan/retro/prompt)
留在 AutoGo,宿主接入方式见 MIGRATION.md。
2026-10-26 00:54:46 +08:00

40 lines
1.3 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package jsonl 提供 JSONL 的**容忍读取**:坏行跳过、**不设行长上限**。
//
// 为什么不直接用 bufio.Scanner:它有 64KB(bufio.MaxScanTokenSize)的默认行长上限,
// 超限时 Scan() 直接停下、Err() 返回 "bufio.Scanner: token too long" —— 整个文件
// 于是读不出来。这不是理论风险:20260916 有个会话因为一条 assistant 消息带 204KB
// 的 reasoning,整份 763KB 的会话在 WebUI 里**直接消失**(列表按"读不出来就跳过"
// 处理),历史也打不开。
//
// 所以这里用 bufio.Reader.ReadBytes 按行读,只在内存里持有当前这一行。
package jsonl
import (
"bufio"
"bytes"
"io"
)
// Each 逐行调用 fn(只传非空行,已去掉行尾换行)。坏行由 fn 自行决定怎么处理,
// 本函数不做解析判断。
//
// 返回的 error 只表示**读取失败**(IO),不含内容问题——内容层面的跳过是 fn 的事。
// 读到 EOF 视为正常结束(最后一行没有换行符也算)。
func Each(r io.Reader, fn func(line []byte)) error {
br := bufio.NewReader(r)
for {
line, err := br.ReadBytes('\n')
if len(line) > 0 {
if trimmed := bytes.TrimRight(line, "\r\n"); len(trimmed) > 0 {
fn(trimmed)
}
}
if err != nil {
if err == io.EOF {
return nil
}
return err
}
}
}