refactor(llm): flatten tool results and validate native V4 sessions

Represent tool results as tool-role messages and migrate released wrappers
without losing outer own JSON fields, call identity, error state, or writer
field order. Refuse nested or wrapper-only information that has no lossless
current representation before successor publication.

Validate current event relationships directly instead of projecting V4 data
back into V3. Keep lifecycle, PTC, title/command, compaction, system-field and
retired-syntax checks on catalog restoration and ordinary JSONL opens. The
Worker JSON equality helper must inspect own keys so it cannot admit PTC
arguments that Node rejects.

Keep the source role change, required native admission and consumer fixture
updates in one complete review layer. Explain shared-type changes in the
persistence record and the native reader rationale in its existing note.
Use checked branded fixture identities and discriminant narrowing instead
of unknown double casts; fixture values and assertions remain intact.

This recomposes the original tool-role work by _Kerman with the independently
validated migration and admission repairs by Tianyi Cui. Frozen generations
and snapshot input version selection are retained.

Co-authored-by: Tianyi Cui <[email protected]>
This commit is contained in:
_KermanandTianyi Cui authored and Tianyi Cui committed 2026-09-18 19:05:32 +08:00
1 parent c6e62ff971
commit f4a32dbd0a
257 files changed
+34289 -26825

No files matched your search

+9 -5
View File
@@ -590,6 +590,9 @@ def test_committed_python_native_goldens_compare_current_output_without_rewritin
directory = SMOKE[f"{scenario}_SNAPSHOT_DIRECTORY"]
filenames = SMOKE[f"{scenario}_SNAPSHOT_FILENAMES"]
before = {path.name: path.read_bytes() for path in directory.iterdir() if path.is_file()}
selected = SMOKE["selected_snapshot_session_files"](directory)
first = next(iter(selected.values()))
source_version = SMOKE["session_header_version"](before[first.name].decode("utf-8"), first.name)
def current_writer(value: object) -> object:
if isinstance(value, list):
@@ -598,18 +601,19 @@ def test_committed_python_native_goldens_compare_current_output_without_rewritin
return value
result = {key: current_writer(item) for key, item in value.items()}
if result.get("type") == "session":
assert result["version"] == 3
assert result["version"] == source_version
result["version"] = SESSION_FORMAT_VERSION
if result.get("type") == "session-log-deepseek/delivery-accepted":
assert result["data"]["sessionFormatVersion"] == 3
assert result["data"]["sessionFormatVersion"] == source_version
result["data"]["sessionFormatVersion"] = SESSION_FORMAT_VERSION
return result
fresh = {}
for name in filenames:
content = before[name].decode("utf-8")
if name.endswith(".jsonl"):
parsed = SMOKE["parse_snapshot_session_filename"](name)
parsed = SMOKE["parse_snapshot_session_filename"](name)
source_name = selected[parsed[0]].name if parsed is not None else name
content = before[source_name].decode("utf-8")
if parsed is not None:
fresh[SMOKE["snapshot_session_filename"](parsed[0], SESSION_FORMAT_VERSION)] = SMOKE["render_jsonl"]([
current_writer(json.loads(line)) for line in content.splitlines() if line
])