feat(v2): T10 rollup + prefix cache 前缀稳定性(--cache-reuse 对齐)

This commit is contained in:
tzt
2026-08-30 21:16:02 +08:00
parent c874382130
commit ff7e1bc8de
3 changed files with 90 additions and 1 deletions
+17
View File
@@ -501,6 +501,23 @@ class Workspace:
data = json.load(f)
return cls(data)
def prefix_signature(self) -> str:
"""返回稳定前缀的签名(T10 prefix cache)。
交流文本的"恒定位于前部"的部分(version + request_id + query + meta + brief
应不随 progress/issues/decisions 追加而变化,从而使 llama-server 的
--cache-reuse 能命中该前缀、降低 prefill 开销。用紧凑 JSON 的哈希度量稳定性。
"""
stable = {
"version": self._data.get("version"),
"request_id": self._data.get("request_id"),
"query": self._data.get("query"),
"brief": self._data.get("brief"),
}
import hashlib
s = json.dumps(stable, ensure_ascii=False, sort_keys=True)
return hashlib.sha256(s.encode("utf-8")).hexdigest()[:16]
def to_dict(self) -> Dict[str, Any]:
return self.data