Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion rust/crates/agent-sessions/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,12 @@ pub struct SearchHit {
pub at_ms: Option<i64>,
/// The bytes of `path` the span covers.
pub range: ByteRange,
/// How many bytes of `path` the cache has read, where reading the file
/// from the hit on ends.
#[serde(rename = "readBytes")]
pub read_bytes: u64,
/// The cache's reading of `path`, which `agentSessions.page` takes back.
pub generation: i64,
}

/// How a failure while syncing one file affects the rest of the sync.
Expand Down Expand Up @@ -792,7 +798,8 @@ impl SessionStore {
/// A query without letters or digits finds nothing.
pub fn search(&self, query: &SearchQuery) -> Result<Vec<SearchHit>, CoreError> {
const SQL: &str = "
SELECT f.agent, f.path, s.session_id, s.at_ms, s.range_start, s.range_end
SELECT f.agent, f.path, s.session_id, s.at_ms, s.range_start, s.range_end,
f.cursor_offset, f.generation
FROM span_terms
JOIN spans s ON s.id = span_terms.rowid
JOIN files f ON f.id = s.file_id
Expand Down Expand Up @@ -828,6 +835,8 @@ impl SessionStore {
start: row.get(4)?,
end: row.get(5)?,
},
read_bytes: row.get(6)?,
generation: row.get(7)?,
})
},
)
Expand Down
20 changes: 15 additions & 5 deletions rust/crates/agent-sessions/src/tests/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,12 +689,13 @@ fn a_rebuild_with_other_chunks_gives_the_same_records() {
entries
};
assert_eq!(records(&incremental), records(&whole));
let hits = |store: &SessionStore, text: &str| {
let mut hits = search(store, text, &[]);
hits.iter_mut().for_each(|hit| hit.generation = 0);
hits
};
for text in ["migration", "数据库", "数据库迁移", "an"] {
assert_eq!(
search(&incremental, text, &[]),
search(&whole, text, &[]),
"{text}"
);
assert_eq!(hits(&incremental, text), hits(&whole, text), "{text}");
}
assert_eq!(search(&whole, "migration", &[]).len(), 2);
}
Expand Down Expand Up @@ -776,6 +777,15 @@ fn read_range_returns_the_bytes_until_the_file_changes() {
let hits = fixture.search("deploy");
assert_eq!(hits.len(), 1);
let hit = &hits[0];
let file_size = std::fs::metadata(&path).expect("stat the file").len();
assert_eq!(hit.read_bytes, file_size);
assert_eq!(
Some(hit.generation),
fixture
.store
.generation(AGENT, &hit.path)
.expect("read the generation")
);
let read = |store: &SessionStore, range: ByteRange| store.read_range(AGENT, &hit.path, range);
assert_eq!(
read(&fixture.store, hit.range)
Expand Down
6 changes: 4 additions & 2 deletions shared/plugins/contract/v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4215,8 +4215,10 @@ Lithe list, search and sum them without the CLI running:
- A listed session also gives `generation`, an opaque integer naming the
cache's reading of `path`. It stays the same while the file only grows and
changes when the file was replaced or truncated and read again from the
start; byte offsets taken under another generation do not apply. It was
added within `agents` 0; an older Core does not answer it.
start; byte offsets taken under another generation do not apply. A search
hit gives the `generation` and `readBytes` of its own file, which may be a
subagent file. Both were added within `agents` 0; an older Core does not
answer them.
- `sessionID`, `readBytes` and `end` were added within `agents` 0. A Core
that predates them refuses `sessionID` as an unknown field, answers neither
`readBytes` nor `end`, and may hand `read` a range that ends inside a line;
Expand Down
1 change: 1 addition & 0 deletions shared/plugins/reference/protocol-changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

| PR | 修改人 | API 编号 | 协议 / 能力 | 改动 |
| --- | --- | --- | --- | --- |
| [#241](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/241)(待合入) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-45 | `agents` 0 内的补充 | 宿主命令 `agentSessions.search` 的命中新增 `generation` 和 `readBytes`,都是命中所在文件(可能是子代理文件)的值,宿主据此从命中处用 `agentSessions.page` 分页读取该文件。旧 Core 不回答这两个字段。没有新增宿主方法、通知、错误码或能力版本。 |
| [#239](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/239)(待合入) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-45 | `agents` 0 / `litheFunctions` 0 内的补充 | 原生会话增加立即补充、FIFO 排队、停止后暂停队列和结构化问答。`agents.prompt` 增加可选 `mode`(默认 `send`,另有 `queue`、`steer`)和 `expectedTurn`;`didPrompt` 仅立即补充时增加 `mode: "steer"`、`input`。新增通知 `didAnswerQuestion`;`report` 新增 `interactionCapabilities`、`questionRequested`、`questionClosed`、`questionAnswered`、`inputResolved`,后者可带封闭的 SDK 失败分类 `code`,四语 SDK 把立即补充失败的唯一终态诊断交给 Core;回答由 SDK 确认交付。Core 新增宿主命令 `agents.updateQueue`、`agents.respondQuestion`;`cancel` 进入 stopping 并暂停队列,真实结束前不宣告停止;通过 `interactionState`、`promptDispatched`、`promptRetracted` 和 `interactionFailed` 投影结果。事件重放同时限制 8192 条 / 16 MiB,交互状态只保留每会话最新快照;`agents.waitEvents` 增加 `recoveries` 与可选 `acknowledge`,拒绝的补充在预留的 64 条 / 16 MiB 容量中保留,直到宿主恢复并显式确认。停止后的有效当前轮次问题被抑制,不阻塞同批结束事件。共享用例为 `agents/native-session.json` 及 `rust/fixtures/agents/turn-interaction-v1.json`。没有提升 API、能力、清单或函数协议版本;旧 Core 严格拒绝新字段和事件,首个支持的 Core revision 为 [`1f843f8ee3aac802cda17ad8df43b51e30862b0d`](https://github.com/Lithe-IDEA/Lithe-core-rust/commit/1f843f8ee3aac802cda17ad8df43b51e30862b0d)(本 PR,尚未合入);桌面端尚未发布。 |
| [#231](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/231)(待合入) | [@WhiteZeek](https://github.com/WhiteZeek) | API-45 | `agents` 0 | `agents/usage` 支持按小时汇总。默认按指定 UTC 偏移对齐整点,也可用 `hourAnchorMs` 对齐滚动窗口。 |
| [#240](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/240)(待合入) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-45 | `agents` 0 内的补充 | 会话来源 `read` 函数增加可选请求参数 `messageIDs`:只有 `true` 时才可在消息里返回可选 `id`(1–256 个可见 ASCII 字节,来源会话内稳定,同一消息的镜像相同);省略或为 `false` 时保留旧结果形状。同时增加可选请求参数 `toolCalls`:只有 `true` 时 `tool` 消息才可带实时 `toolCall` 的详情 `toolCallID`、`status`、`toolKind`、`title`、`locations`(同一调用和它的结果共用 `toolCallID`,宿主按实时方式合并,让历史轮次和实时显示一致)。Core 的新宿主命令 `agentSessions.page` 协商该参数并按整行双向分页,两个参数都由它发送,旧 `agentSessions.read` 和标题读取不协商,回答里出现这些详情字段(包括显式 `null`)时以 `agentSessions.invalidRead` 拒绝。`agentSessions.list` 的会话新增 `generation`:文件只增长时不变,被替换或截断后重新读取时换新值;`agentSessions.page` 必须带上同一次列表的 `generation`,不一致时回答 `changed`。四语 SDK 都使用已有普通 JSON 函数处理器,无类型或版本变化;旧插件可忽略参数。没有新增宿主方法、通知、错误码或能力版本。样例见 `fixtures/agents/record-read.json` 与 `rust/fixtures/agents/record-page-v1.json`;首次实现见 Core `15c0717`;宿主发布版本尚未产生。 |
Expand Down
Loading