Skip to content

Commit 942fb0a

Browse files
fix(jsonl): address parser-split review follow-ups
1 parent ddefa46 commit 942fb0a

4 files changed

Lines changed: 22 additions & 14 deletions

File tree

tests/test_jsonl_parser.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,16 @@ def test_plan_result(self):
234234
r = _parse_tool_result({"plan": [], "filePath": "/plan.md"})
235235
assert r["result_type"] == "plan"
236236

237+
def test_plan_with_content_not_classified_as_file_write(self):
238+
"""plan is registered before file_write in _TOOL_RESULT_DISPATCH."""
239+
r = _parse_tool_result({
240+
"plan": [],
241+
"filePath": "/plan.md",
242+
"content": "plan body",
243+
})
244+
assert r["result_type"] == "plan"
245+
assert r["file_path"] == "/plan.md"
246+
237247
def test_unknown_fallback(self):
238248
r = _parse_tool_result({"unexpected": True})
239249
assert r["result_type"] == "unknown"

utils/jsonl_parser.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
normalize_content as _normalize_content,
1616
strip_system_tags as _strip_system_tags,
1717
)
18-
from utils.session_peek import quick_session_info
1918
from utils.tool_dispatch import _TOOL_RESULT_DISPATCH, _parse_tool_result
2019
from utils.validation import validate_session_dict
2120

@@ -38,6 +37,14 @@
3837
]
3938

4039

40+
def __getattr__(name: str) -> Any:
41+
if name == "quick_session_info":
42+
from utils.session_peek import quick_session_info
43+
44+
return quick_session_info
45+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
46+
47+
4148
def parse_session(filepath: str) -> SessionDict:
4249
"""Main entry point. Reads every line from a .jsonl file and builds up
4350
a session dict with messages, metadata (tokens, models, tool counts),

utils/session_peek.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ def quick_session_info(filepath: str) -> QuickSessionInfoDict:
1515
without fully parsing all messages. Much faster than parse_session() for
1616
large files.
1717
18-
Strategy: read the first ~50 lines for the title, then seek to the end of
19-
the file and read the last chunk to find the last timestamp."""
18+
Strategy: files over 10 KiB cap the head scan at 80 lines for title, then
19+
tail-read for last_timestamp; smaller files are scanned fully in pass 1."""
2020
title = None
2121
first_ts = None
2222
last_ts = None

utils/tool_dispatch.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -229,20 +229,11 @@ def _tool_result_build_user_input(tr: dict[str, Any], base: dict[str, Any]) -> d
229229
return result
230230

231231

232-
# Dispatch registry: **first matching predicate wins** (same as legacy if/elif).
233-
# Order is load-bearing — do not sort alphabetically or “more specific first”
234-
# without replaying tests and real session fixtures.
235-
#
236-
# Notably ``task_message`` is intentionally broad (``task_id`` or ``message``)
237-
# and sits before ``task_retrieval`` / ``task_completed`` / ``task_async`` so
238-
# payloads that include overlapping keys still match the legacy branch order.
239-
#
240-
# To add a shape: append ``(pred, build)`` here, or insert only after verifying
241-
# predicates above would not steal intended matches.
232+
# Registry order is load-bearing (see module docstring).
233+
# ``plan`` before ``file_write``: plan blobs may carry ``filePath`` + ``content``.
242234
_TOOL_RESULT_DISPATCH = (
243235
(_tool_result_pred_bash, _tool_result_build_bash),
244236
(_tool_result_pred_file_edit, _tool_result_build_file_edit),
245-
# plan before file_write: plan blobs may also carry filePath + content
246237
(_tool_result_pred_plan, _tool_result_build_plan),
247238
(_tool_result_pred_file_write, _tool_result_build_file_write),
248239
(_tool_result_pred_glob, _tool_result_build_glob),

0 commit comments

Comments
 (0)