prizmkit 1.1.192 → 1.1.193
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundled/VERSION.json +3 -3
- package/bundled/dev-pipeline/README.md +23 -34
- package/bundled/dev-pipeline/assets/feature-list-example.json +0 -1
- package/bundled/dev-pipeline/assets/skill-subagent-integration.md +3 -0
- package/bundled/dev-pipeline/prizmkit_runtime/config.py +24 -2
- package/bundled/dev-pipeline/prizmkit_runtime/daemon.py +2 -0
- package/bundled/dev-pipeline/prizmkit_runtime/gitops.py +89 -40
- package/bundled/dev-pipeline/prizmkit_runtime/heartbeat.py +9 -1
- package/bundled/dev-pipeline/prizmkit_runtime/interoperability.py +0 -22
- package/bundled/dev-pipeline/prizmkit_runtime/platform_detection.py +11 -7
- package/bundled/dev-pipeline/prizmkit_runtime/processes.py +26 -20
- package/bundled/dev-pipeline/prizmkit_runtime/reset.py +37 -4
- package/bundled/dev-pipeline/prizmkit_runtime/reset_preserve.py +20 -41
- package/bundled/dev-pipeline/prizmkit_runtime/runner_bookkeeping.py +74 -36
- package/bundled/dev-pipeline/prizmkit_runtime/runner_models.py +0 -66
- package/bundled/dev-pipeline/prizmkit_runtime/runners.py +271 -52
- package/bundled/dev-pipeline/prizmkit_runtime/runtime_commit.py +51 -13
- package/bundled/dev-pipeline/prizmkit_runtime/sessions.py +43 -15
- package/bundled/dev-pipeline/prizmkit_runtime/stream_progress.py +27 -24
- package/bundled/dev-pipeline/prizmkit_runtime/task_checkout.py +0 -1
- package/bundled/dev-pipeline/scripts/check-session-status.py +13 -1
- package/bundled/dev-pipeline/scripts/continuation.py +2 -3
- package/bundled/dev-pipeline/scripts/detect-stuck.py +19 -5
- package/bundled/dev-pipeline/scripts/generate-bootstrap-prompt.py +6 -14
- package/bundled/dev-pipeline/scripts/generate-bugfix-prompt.py +13 -8
- package/bundled/dev-pipeline/scripts/init-change-artifact.py +17 -2
- package/bundled/dev-pipeline/scripts/prompt_framework.py +39 -21
- package/bundled/dev-pipeline/scripts/update-checkpoint.py +27 -0
- package/bundled/dev-pipeline/templates/bootstrap-tier3.md +1 -1
- package/bundled/dev-pipeline/templates/bugfix-bootstrap-prompt.md +6 -6
- package/bundled/dev-pipeline/templates/sections/bugfix-phase-test.md +1 -1
- package/bundled/dev-pipeline/templates/sections/phase-prizmkit-test.md +1 -1
- package/bundled/skills/_metadata.json +1 -1
- package/package.json +1 -1
- package/bundled/dev-pipeline/tests/_helpers.py +0 -418
- package/bundled/dev-pipeline/tests/conftest.py +0 -73
- package/bundled/dev-pipeline/tests/live_ai_cli_log_smoke.py +0 -208
- package/bundled/dev-pipeline/tests/test_auto_skip.py +0 -1806
- package/bundled/dev-pipeline/tests/test_checkpoint_state.py +0 -1439
- package/bundled/dev-pipeline/tests/test_daemon_and_scripts.py +0 -257
- package/bundled/dev-pipeline/tests/test_e2e_pipeline_run.py +0 -500
- package/bundled/dev-pipeline/tests/test_generate_bootstrap_prompt.py +0 -1654
- package/bundled/dev-pipeline/tests/test_generate_bugfix_prompt.py +0 -629
- package/bundled/dev-pipeline/tests/test_python_runner_parity.py +0 -2973
- package/bundled/dev-pipeline/tests/test_recovery_workflow.py +0 -321
- package/bundled/dev-pipeline/tests/test_repository_bootstrap.py +0 -251
- package/bundled/dev-pipeline/tests/test_reset_modes.py +0 -1196
- package/bundled/dev-pipeline/tests/test_reset_preserve.py +0 -872
- package/bundled/dev-pipeline/tests/test_runner_bookkeeping.py +0 -766
- package/bundled/dev-pipeline/tests/test_runner_lifecycle.py +0 -1257
- package/bundled/dev-pipeline/tests/test_runtime_commit.py +0 -1113
- package/bundled/dev-pipeline/tests/test_runtime_helper.py +0 -380
- package/bundled/dev-pipeline/tests/test_session_launch.py +0 -1101
- package/bundled/dev-pipeline/tests/test_stream_progress.py +0 -585
- package/bundled/dev-pipeline/tests/test_unified_cli.py +0 -3625
- package/bundled/dev-pipeline/tests/test_utils.py +0 -170
|
@@ -1,585 +0,0 @@
|
|
|
1
|
-
"""Focused tests for stream-json and progress parsing helpers."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
import json
|
|
6
|
-
import sys
|
|
7
|
-
|
|
8
|
-
import pytest
|
|
9
|
-
|
|
10
|
-
from _helpers import PIPELINE_ROOT, load_progress_parser_module as _load_progress_parser_module
|
|
11
|
-
|
|
12
|
-
sys.path.insert(0, str(PIPELINE_ROOT))
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def test_progress_parser_adds_required_metadata(tmp_path):
|
|
16
|
-
import importlib.util
|
|
17
|
-
|
|
18
|
-
parser_path = PIPELINE_ROOT / "scripts" / "parse-stream-progress.py"
|
|
19
|
-
spec = importlib.util.spec_from_file_location("parse_stream_progress", parser_path)
|
|
20
|
-
module = importlib.util.module_from_spec(spec)
|
|
21
|
-
assert spec.loader is not None
|
|
22
|
-
spec.loader.exec_module(module)
|
|
23
|
-
|
|
24
|
-
tracker = module.ProgressTracker()
|
|
25
|
-
tracker.process_event({"type": "system", "subtype": "init", "session_id": "claude-session", "cwd": str(tmp_path)})
|
|
26
|
-
tracker.process_event({"type": "assistant", "message": {"content": [{"type": "text", "text": "working"}]}})
|
|
27
|
-
tracker.process_event({"type": "result", "subtype": "success", "stop_reason": "end_turn", "usage": {"input_tokens": 1}, "result": "done"})
|
|
28
|
-
tracker.process_event({"type": "error", "error": {"message": "permission denied by user"}})
|
|
29
|
-
data = tracker.to_dict()
|
|
30
|
-
|
|
31
|
-
assert data["event_type_counts"]["system"] == 1
|
|
32
|
-
assert data["event_type_counts"]["assistant"] == 1
|
|
33
|
-
assert data["claude_session_id"] == "claude-session"
|
|
34
|
-
assert data["result_subtype"] == "success"
|
|
35
|
-
assert data["stop_reason"] == "end_turn"
|
|
36
|
-
assert data["has_usage"] is True
|
|
37
|
-
assert data["permission_denial_count"] == 1
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def test_progress_parser_normalizes_pi_json_events():
|
|
42
|
-
module = _load_progress_parser_module()
|
|
43
|
-
tracker = module.ProgressTracker()
|
|
44
|
-
tracker.process_event({"type": "session", "version": 3, "id": "pi-session", "cwd": "/tmp/project"})
|
|
45
|
-
tracker.process_event({"type": "agent_start"})
|
|
46
|
-
tracker.process_event({"type": "turn_start"})
|
|
47
|
-
tracker.process_event({
|
|
48
|
-
"type": "message_update",
|
|
49
|
-
"assistantMessageEvent": {"type": "text_delta", "delta": "Running prizmkit-implement"},
|
|
50
|
-
})
|
|
51
|
-
tracker.process_event({"type": "tool_execution_start", "toolName": "edit", "args": {"path": "src/a.js"}})
|
|
52
|
-
tracker.process_event({"type": "tool_execution_end", "toolName": "edit", "result": {"ok": True}, "isError": False})
|
|
53
|
-
tracker.process_event({"type": "compaction_start", "reason": "threshold"})
|
|
54
|
-
tracker.process_event({"type": "compaction_end", "reason": "threshold", "aborted": False, "willRetry": False})
|
|
55
|
-
tracker.process_event({"type": "agent_end", "messages": []})
|
|
56
|
-
data = tracker.to_dict()
|
|
57
|
-
assert data["event_format"] == "pi-json"
|
|
58
|
-
assert data["message_count"] == 1
|
|
59
|
-
assert data["total_tool_calls"] == 1
|
|
60
|
-
assert {item["name"]: item["count"] for item in data["tool_calls"]}["edit"] == 1
|
|
61
|
-
assert data["current_phase"] == "implement"
|
|
62
|
-
assert data["is_active"] is False
|
|
63
|
-
assert data["result_subtype"] == "success"
|
|
64
|
-
assert data["terminal_success_at"]
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
def test_progress_parser_does_not_mark_failed_pi_agent_end_as_success():
|
|
68
|
-
module = _load_progress_parser_module()
|
|
69
|
-
tracker = module.ProgressTracker()
|
|
70
|
-
tracker.process_event({"type": "session", "version": 3, "id": "pi-session", "cwd": "/tmp/project"})
|
|
71
|
-
tracker.process_event({"type": "agent_start"})
|
|
72
|
-
tracker.process_event({
|
|
73
|
-
"type": "message_end",
|
|
74
|
-
"message": {
|
|
75
|
-
"role": "assistant",
|
|
76
|
-
"content": [],
|
|
77
|
-
"stopReason": "error",
|
|
78
|
-
"errorMessage": "provider request failed",
|
|
79
|
-
},
|
|
80
|
-
})
|
|
81
|
-
tracker.process_event({"type": "agent_end", "messages": []})
|
|
82
|
-
|
|
83
|
-
data = tracker.to_dict()
|
|
84
|
-
|
|
85
|
-
assert data["event_format"] == "pi-json"
|
|
86
|
-
assert data["is_active"] is False
|
|
87
|
-
assert data["result_subtype"] == "error"
|
|
88
|
-
assert data["stop_reason"] == "error"
|
|
89
|
-
assert data["last_result_is_error"] is True
|
|
90
|
-
assert data["terminal_success_at"] == ""
|
|
91
|
-
assert "provider request failed" in data["errors"]
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
def test_progress_parser_keeps_pi_length_as_nonfatal_diagnostic_metadata():
|
|
95
|
-
module = _load_progress_parser_module()
|
|
96
|
-
tracker = module.ProgressTracker()
|
|
97
|
-
tracker.process_event({"type": "session", "version": 3, "id": "pi-session", "cwd": "/tmp/project"})
|
|
98
|
-
tracker.process_event({"type": "agent_start"})
|
|
99
|
-
message = {
|
|
100
|
-
"role": "assistant",
|
|
101
|
-
"content": [{"type": "thinking", "thinking": "Planning the next test"}],
|
|
102
|
-
"stopReason": "length",
|
|
103
|
-
}
|
|
104
|
-
tracker.process_event({"type": "message_end", "message": message})
|
|
105
|
-
tracker.process_event({"type": "agent_end", "willRetry": False, "messages": [message]})
|
|
106
|
-
|
|
107
|
-
data = tracker.to_dict()
|
|
108
|
-
|
|
109
|
-
assert data["result_subtype"] == "success"
|
|
110
|
-
assert data["stop_reason"] == "length"
|
|
111
|
-
assert data["last_result_is_error"] is False
|
|
112
|
-
assert data["api_error_code"] == ""
|
|
113
|
-
assert data["fatal_error_code"] == ""
|
|
114
|
-
assert data["terminal_success_at"]
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
@pytest.mark.parametrize("role", ("assistant", "toolResult"))
|
|
118
|
-
def test_progress_parser_does_not_promote_pi_diagnostic_content_to_fatal_error(role):
|
|
119
|
-
module = _load_progress_parser_module()
|
|
120
|
-
tracker = module.ProgressTracker()
|
|
121
|
-
tracker.process_event({"type": "session", "version": 3, "id": "pi-session", "cwd": "/tmp/project"})
|
|
122
|
-
tracker.process_event({"type": "agent_start"})
|
|
123
|
-
tracker.process_event({
|
|
124
|
-
"type": "message_end",
|
|
125
|
-
"message": {
|
|
126
|
-
"role": role,
|
|
127
|
-
"content": [{
|
|
128
|
-
"type": "text",
|
|
129
|
-
"text": 'continuation_reason = "context_overflow"\nerror = _error_text(result)',
|
|
130
|
-
}],
|
|
131
|
-
"stopReason": "toolUse",
|
|
132
|
-
},
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
data = tracker.to_dict()
|
|
136
|
-
|
|
137
|
-
assert data["api_error_code"] == ""
|
|
138
|
-
assert data["fatal_error_code"] == ""
|
|
139
|
-
assert data["last_result_is_error"] is False
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
def test_progress_parser_recovers_from_retrying_pi_attempt_before_final_success():
|
|
143
|
-
module = _load_progress_parser_module()
|
|
144
|
-
tracker = module.ProgressTracker()
|
|
145
|
-
tracker.process_event({"type": "session", "version": 3, "id": "pi-session", "cwd": "/tmp/project"})
|
|
146
|
-
tracker.process_event({"type": "agent_start"})
|
|
147
|
-
tracker.process_event({
|
|
148
|
-
"type": "message_end",
|
|
149
|
-
"message": {
|
|
150
|
-
"role": "assistant",
|
|
151
|
-
"content": [],
|
|
152
|
-
"stopReason": "error",
|
|
153
|
-
"errorMessage": "Error Code internal_server_error: unexpected EOF",
|
|
154
|
-
},
|
|
155
|
-
})
|
|
156
|
-
tracker.process_event({"type": "agent_end", "willRetry": True, "messages": []})
|
|
157
|
-
tracker.process_event({
|
|
158
|
-
"type": "auto_retry_start",
|
|
159
|
-
"attempt": 1,
|
|
160
|
-
"delayMs": 2000,
|
|
161
|
-
"errorMessage": "Error Code internal_server_error: unexpected EOF",
|
|
162
|
-
})
|
|
163
|
-
tracker.process_event({"type": "agent_start"})
|
|
164
|
-
tracker.process_event({"type": "auto_retry_end", "attempt": 1})
|
|
165
|
-
tracker.process_event({
|
|
166
|
-
"type": "message_end",
|
|
167
|
-
"message": {
|
|
168
|
-
"role": "assistant",
|
|
169
|
-
"content": [{"type": "text", "text": "WORKFLOW_COMPLETED"}],
|
|
170
|
-
"stopReason": "stop",
|
|
171
|
-
},
|
|
172
|
-
})
|
|
173
|
-
tracker.process_event({
|
|
174
|
-
"type": "agent_end",
|
|
175
|
-
"willRetry": False,
|
|
176
|
-
"messages": [{
|
|
177
|
-
"role": "assistant",
|
|
178
|
-
"content": [{"type": "text", "text": "WORKFLOW_COMPLETED"}],
|
|
179
|
-
"stopReason": "stop",
|
|
180
|
-
}],
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
data = tracker.to_dict()
|
|
184
|
-
|
|
185
|
-
assert data["result_subtype"] == "success"
|
|
186
|
-
assert data["last_result_is_error"] is False
|
|
187
|
-
assert data["stop_reason"] == "stop"
|
|
188
|
-
assert data["fatal_error_code"] == ""
|
|
189
|
-
assert data["terminal_success_at"]
|
|
190
|
-
assert any("unexpected EOF" in str(error) for error in data["errors"])
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
def test_progress_parser_keeps_final_error_after_internal_retry_exhausts():
|
|
194
|
-
module = _load_progress_parser_module()
|
|
195
|
-
tracker = module.ProgressTracker()
|
|
196
|
-
tracker.process_event({"type": "session", "id": "pi-session"})
|
|
197
|
-
tracker.process_event({"type": "agent_start"})
|
|
198
|
-
tracker.process_event({
|
|
199
|
-
"type": "message_end",
|
|
200
|
-
"message": {"role": "assistant", "content": [], "stopReason": "error", "errorMessage": "temporary error"},
|
|
201
|
-
})
|
|
202
|
-
tracker.process_event({"type": "agent_end", "willRetry": True, "messages": []})
|
|
203
|
-
tracker.process_event({"type": "auto_retry_start", "attempt": 1, "errorMessage": "temporary error"})
|
|
204
|
-
tracker.process_event({"type": "agent_start"})
|
|
205
|
-
tracker.process_event({
|
|
206
|
-
"type": "message_end",
|
|
207
|
-
"message": {"role": "assistant", "content": [], "stopReason": "error", "errorMessage": "final error"},
|
|
208
|
-
})
|
|
209
|
-
tracker.process_event({
|
|
210
|
-
"type": "agent_end",
|
|
211
|
-
"willRetry": False,
|
|
212
|
-
"messages": [{"role": "assistant", "content": [], "stopReason": "error", "errorMessage": "final error"}],
|
|
213
|
-
})
|
|
214
|
-
|
|
215
|
-
data = tracker.to_dict()
|
|
216
|
-
|
|
217
|
-
assert data["result_subtype"] == "error"
|
|
218
|
-
assert data["last_result_is_error"] is True
|
|
219
|
-
assert data["stop_reason"] == "error"
|
|
220
|
-
assert data["terminal_success_at"] == ""
|
|
221
|
-
assert "final error" in data["terminal_result_text"]
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
def test_progress_parser_clears_retrying_fatal_marker_on_new_pi_attempt():
|
|
225
|
-
module = _load_progress_parser_module()
|
|
226
|
-
tracker = module.ProgressTracker()
|
|
227
|
-
tracker.process_event({"type": "session", "id": "pi-session"})
|
|
228
|
-
tracker.process_event({"type": "agent_start"})
|
|
229
|
-
tracker.process_event({
|
|
230
|
-
"type": "message_end",
|
|
231
|
-
"message": {
|
|
232
|
-
"role": "assistant",
|
|
233
|
-
"content": [],
|
|
234
|
-
"stopReason": "error",
|
|
235
|
-
"errorMessage": "API Error: Your input exceeds the context window",
|
|
236
|
-
},
|
|
237
|
-
})
|
|
238
|
-
tracker.process_event({"type": "agent_end", "willRetry": True, "messages": []})
|
|
239
|
-
failed_attempt = tracker.to_dict()
|
|
240
|
-
|
|
241
|
-
tracker.process_event({"type": "agent_start"})
|
|
242
|
-
next_attempt = tracker.to_dict()
|
|
243
|
-
|
|
244
|
-
assert failed_attempt["fatal_error_code"] == "context_overflow"
|
|
245
|
-
assert failed_attempt["last_result_is_error"] is True
|
|
246
|
-
assert next_attempt["fatal_error_code"] == ""
|
|
247
|
-
assert next_attempt["result_subtype"] == ""
|
|
248
|
-
assert next_attempt["last_result_is_error"] is False
|
|
249
|
-
assert any("context window" in str(error) for error in next_attempt["errors"])
|
|
250
|
-
assert next_attempt["is_active"] is True
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
def test_semantic_log_normalizer_compacts_pi_cumulative_stream():
|
|
254
|
-
module = _load_progress_parser_module()
|
|
255
|
-
normalizer = module.SemanticLogNormalizer()
|
|
256
|
-
events = [
|
|
257
|
-
{"type": "session", "id": "session-1"},
|
|
258
|
-
{"type": "message_start", "message": {"role": "user"}},
|
|
259
|
-
{"type": "message_end", "message": {"role": "user", "content": [{"type": "text", "text": "SECRET PROMPT"}]}},
|
|
260
|
-
{"type": "turn_start"},
|
|
261
|
-
{"type": "message_update", "assistantMessageEvent": {"type": "thinking_start", "contentIndex": 0}},
|
|
262
|
-
{"type": "message_update", "assistantMessageEvent": {"type": "thinking_delta", "contentIndex": 0, "delta": "Inspecting"}},
|
|
263
|
-
{"type": "message_update", "assistantMessageEvent": {"type": "thinking_delta", "contentIndex": 0, "delta": " state"}},
|
|
264
|
-
{"type": "message_update", "assistantMessageEvent": {"type": "thinking_end", "contentIndex": 0, "content": "Inspecting state"}},
|
|
265
|
-
{"type": "tool_execution_start", "toolCallId": "call-1", "toolName": "bash", "args": {"command": "printf ABC"}},
|
|
266
|
-
{"type": "tool_execution_update", "toolCallId": "call-1", "toolName": "bash", "partialResult": {"content": [{"type": "text", "text": "A"}]}},
|
|
267
|
-
{"type": "tool_execution_update", "toolCallId": "call-1", "toolName": "bash", "partialResult": {"content": [{"type": "text", "text": "AB"}]}},
|
|
268
|
-
{"type": "tool_execution_update", "toolCallId": "call-1", "toolName": "bash", "partialResult": {"content": [{"type": "text", "text": "ABC"}]}},
|
|
269
|
-
{"type": "tool_execution_end", "toolCallId": "call-1", "toolName": "bash", "result": {"content": [{"type": "text", "text": "ABC"}]}, "isError": False},
|
|
270
|
-
{"type": "message_start", "message": {"role": "toolResult"}},
|
|
271
|
-
{"type": "message_end", "message": {"role": "toolResult", "toolCallId": "call-1", "toolName": "bash", "content": [{"type": "text", "text": "ABC"}]}},
|
|
272
|
-
{"type": "message_update", "assistantMessageEvent": {"type": "text_start", "contentIndex": 1}},
|
|
273
|
-
{"type": "message_update", "assistantMessageEvent": {"type": "text_delta", "contentIndex": 1, "delta": "Done"}},
|
|
274
|
-
{"type": "message_update", "assistantMessageEvent": {"type": "text_end", "contentIndex": 1, "content": "Done"}},
|
|
275
|
-
{"type": "message_end", "message": {"role": "assistant", "content": [{"type": "text", "text": "Done"}], "stopReason": "stop"}},
|
|
276
|
-
{"type": "turn_end", "message": {"role": "assistant", "content": [{"type": "text", "text": "Done"}], "stopReason": "stop"}},
|
|
277
|
-
{"type": "agent_end", "willRetry": False, "messages": [{"role": "assistant", "content": [{"type": "text", "text": "Done"}], "stopReason": "stop"}]},
|
|
278
|
-
{"type": "agent_settled"},
|
|
279
|
-
]
|
|
280
|
-
|
|
281
|
-
rendered = "".join(normalizer.process_event(event) for event in events) + normalizer.finish()
|
|
282
|
-
|
|
283
|
-
assert rendered.count("[THINK]") == 1
|
|
284
|
-
assert "[THINK] Inspecting state\n" in rendered
|
|
285
|
-
assert rendered.count("[ACTION]") == 1
|
|
286
|
-
assert "bash" in rendered and "printf ABC" in rendered
|
|
287
|
-
assert rendered.count("[OBSERVATION]") == 1
|
|
288
|
-
assert "[OBSERVATION] ABC\n" in rendered
|
|
289
|
-
assert rendered.count("[FINAL]") == 1
|
|
290
|
-
assert "[FINAL] Done\n" in rendered
|
|
291
|
-
assert rendered.count("[SESSION_END]") == 1
|
|
292
|
-
assert "message_update" not in rendered
|
|
293
|
-
assert "SECRET PROMPT" not in rendered
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
def test_semantic_log_normalizer_ignores_user_prompt_but_keeps_nested_tool_results():
|
|
297
|
-
module = _load_progress_parser_module()
|
|
298
|
-
normalizer = module.SemanticLogNormalizer()
|
|
299
|
-
rendered = normalizer.process_event({
|
|
300
|
-
"type": "user",
|
|
301
|
-
"message": {
|
|
302
|
-
"content": [
|
|
303
|
-
{"type": "text", "text": "SECRET PROMPT"},
|
|
304
|
-
{"type": "tool_result", "tool_use_id": "tool-1", "content": "tool output"},
|
|
305
|
-
]
|
|
306
|
-
},
|
|
307
|
-
})
|
|
308
|
-
rendered += normalizer.finish()
|
|
309
|
-
|
|
310
|
-
assert "SECRET PROMPT" not in rendered
|
|
311
|
-
assert "[OBSERVATION] tool output" in rendered
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
def test_semantic_log_normalizer_preserves_repeated_plain_and_tool_output_records():
|
|
315
|
-
module = _load_progress_parser_module()
|
|
316
|
-
normalizer = module.SemanticLogNormalizer()
|
|
317
|
-
rendered = normalizer.process_text("same\n")
|
|
318
|
-
rendered += normalizer.process_text("same\n")
|
|
319
|
-
rendered += normalizer.process_event({"type": "function_call_result", "id": "one", "output": "same result"})
|
|
320
|
-
rendered += normalizer.process_event({"type": "function_call_result", "id": "two", "output": "same result"})
|
|
321
|
-
rendered += normalizer.finish()
|
|
322
|
-
|
|
323
|
-
assert rendered.count("[OUTPUT] same") == 2
|
|
324
|
-
assert rendered.count("[OBSERVATION] same result") == 2
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
def test_semantic_log_normalizer_emits_terminal_metadata_once():
|
|
328
|
-
module = _load_progress_parser_module()
|
|
329
|
-
normalizer = module.SemanticLogNormalizer()
|
|
330
|
-
rendered = normalizer.process_event({"type": "turn.completed"})
|
|
331
|
-
rendered += normalizer.process_event({"type": "result", "subtype": "success", "result": "Done"})
|
|
332
|
-
rendered += normalizer.finish()
|
|
333
|
-
|
|
334
|
-
assert rendered.count("[SESSION_END]") == 1
|
|
335
|
-
assert "[FINAL] Done" in rendered
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
def test_semantic_log_normalizer_does_not_promote_pi_length_to_context_overflow():
|
|
339
|
-
module = _load_progress_parser_module()
|
|
340
|
-
normalizer = module.SemanticLogNormalizer()
|
|
341
|
-
rendered = normalizer.process_event({
|
|
342
|
-
"type": "agent_end",
|
|
343
|
-
"willRetry": False,
|
|
344
|
-
"messages": [{"role": "assistant", "content": [], "stopReason": "length"}],
|
|
345
|
-
})
|
|
346
|
-
rendered += normalizer.finish()
|
|
347
|
-
|
|
348
|
-
assert rendered.count("[SESSION_END]") == 1
|
|
349
|
-
assert "status=success stop_reason=length" in rendered
|
|
350
|
-
assert "status=context_overflow" not in rendered
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
def test_semantic_log_normalizer_preserves_identical_text_from_distinct_turns():
|
|
354
|
-
module = _load_progress_parser_module()
|
|
355
|
-
normalizer = module.SemanticLogNormalizer()
|
|
356
|
-
events = [
|
|
357
|
-
{"type": "turn_start"},
|
|
358
|
-
{"type": "message_end", "message": {"role": "assistant", "content": [{"type": "text", "text": "Done"}], "stopReason": "stop"}},
|
|
359
|
-
{"type": "turn_start"},
|
|
360
|
-
{"type": "message_end", "message": {"role": "assistant", "content": [{"type": "text", "text": "Done"}], "stopReason": "stop"}},
|
|
361
|
-
]
|
|
362
|
-
|
|
363
|
-
rendered = "".join(normalizer.process_event(event) for event in events) + normalizer.finish()
|
|
364
|
-
|
|
365
|
-
assert rendered.count("[FINAL] Done") == 2
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
def test_semantic_log_normalizer_size_tracks_unique_cumulative_content():
|
|
369
|
-
module = _load_progress_parser_module()
|
|
370
|
-
normalizer = module.SemanticLogNormalizer()
|
|
371
|
-
chunks = []
|
|
372
|
-
payload = ""
|
|
373
|
-
chunks.append(normalizer.process_event({"type": "tool_execution_start", "toolCallId": "call-1", "toolName": "read", "args": {"path": "sample"}}))
|
|
374
|
-
for index in range(1, 501):
|
|
375
|
-
payload += chr(64 + ((index - 1) % 26) + 1)
|
|
376
|
-
chunks.append(normalizer.process_event({
|
|
377
|
-
"type": "tool_execution_update",
|
|
378
|
-
"toolCallId": "call-1",
|
|
379
|
-
"toolName": "read",
|
|
380
|
-
"partialResult": {"content": [{"type": "text", "text": payload}]},
|
|
381
|
-
}))
|
|
382
|
-
assert sum(len(value) for value in normalizer._snapshots.values()) == len(payload)
|
|
383
|
-
assert not any(stream_id.startswith("tool:call-1:output") for stream_id in normalizer._stream_buffers)
|
|
384
|
-
chunks.append(normalizer.process_event({
|
|
385
|
-
"type": "tool_execution_end",
|
|
386
|
-
"toolCallId": "call-1",
|
|
387
|
-
"toolName": "read",
|
|
388
|
-
"result": {"content": [{"type": "text", "text": payload}]},
|
|
389
|
-
"isError": False,
|
|
390
|
-
}))
|
|
391
|
-
rendered = "".join(chunks) + normalizer.finish()
|
|
392
|
-
|
|
393
|
-
assert rendered.count(payload) == 1
|
|
394
|
-
assert len(rendered.encode("utf-8")) <= len(payload.encode("utf-8")) + 256
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
@pytest.mark.parametrize(
|
|
398
|
-
("events", "expected_labels"),
|
|
399
|
-
[
|
|
400
|
-
(
|
|
401
|
-
[
|
|
402
|
-
{"type": "assistant", "message": {"content": [{"type": "text", "text": "Answer"}, {"type": "tool_use", "id": "tool-1", "name": "Read", "input": {"path": "a"}}]}},
|
|
403
|
-
{"type": "user", "message": {"content": [{"type": "tool_result", "tool_use_id": "tool-1", "content": "result"}]}},
|
|
404
|
-
{"type": "result", "subtype": "success", "stop_reason": "end_turn", "result": "Answer"},
|
|
405
|
-
],
|
|
406
|
-
{"[FINAL]", "[ACTION]", "[OBSERVATION]", "[SESSION_END]"},
|
|
407
|
-
),
|
|
408
|
-
(
|
|
409
|
-
[
|
|
410
|
-
{"type": "message", "sessionId": "cb-1", "role": "assistant", "content": [{"type": "text", "text": "Answer"}]},
|
|
411
|
-
{"type": "function_call", "sessionId": "cb-1", "id": "call-1", "name": "read", "arguments": "{\"path\":\"a\"}"},
|
|
412
|
-
{"type": "function_call_result", "sessionId": "cb-1", "id": "call-1", "output": "result"},
|
|
413
|
-
{"type": "result", "subtype": "success", "result": "Answer"},
|
|
414
|
-
],
|
|
415
|
-
{"[FINAL]", "[ACTION]", "[OBSERVATION]", "[SESSION_END]"},
|
|
416
|
-
),
|
|
417
|
-
(
|
|
418
|
-
[
|
|
419
|
-
{"type": "turn.started"},
|
|
420
|
-
{"type": "item.completed", "item": {"id": "reason-1", "type": "reasoning", "text": "Think"}},
|
|
421
|
-
{"type": "item.started", "item": {"id": "cmd-1", "type": "command_execution", "command": "printf result"}},
|
|
422
|
-
{"type": "item.completed", "item": {"id": "cmd-1", "type": "command_execution", "command": "printf result", "aggregated_output": "result", "status": "completed"}},
|
|
423
|
-
{"type": "item.completed", "item": {"id": "answer-1", "type": "agent_message", "text": "Answer"}},
|
|
424
|
-
{"type": "turn.completed", "usage": {"input_tokens": 1}},
|
|
425
|
-
],
|
|
426
|
-
{"[THINK]", "[FINAL]", "[ACTION]", "[OBSERVATION]", "[SESSION_END]"},
|
|
427
|
-
),
|
|
428
|
-
],
|
|
429
|
-
)
|
|
430
|
-
def test_semantic_log_normalizer_has_cross_format_contract(events, expected_labels):
|
|
431
|
-
module = _load_progress_parser_module()
|
|
432
|
-
normalizer = module.SemanticLogNormalizer()
|
|
433
|
-
|
|
434
|
-
rendered = "".join(normalizer.process_event(event) for event in events) + normalizer.finish()
|
|
435
|
-
|
|
436
|
-
for label in expected_labels:
|
|
437
|
-
assert label in rendered
|
|
438
|
-
assert not any(json.dumps(event, ensure_ascii=False) in rendered for event in events)
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
def test_progress_parser_normalizes_claude_subagents_without_double_counting(tmp_path):
|
|
442
|
-
module = _load_progress_parser_module()
|
|
443
|
-
tracker = module.ProgressTracker()
|
|
444
|
-
|
|
445
|
-
tracker.process_event({"type": "system", "subtype": "init", "session_id": "claude-session", "cwd": str(tmp_path)})
|
|
446
|
-
tracker.process_event({
|
|
447
|
-
"type": "assistant",
|
|
448
|
-
"message": {"content": [{
|
|
449
|
-
"type": "tool_use",
|
|
450
|
-
"id": "tool-1",
|
|
451
|
-
"name": "Agent",
|
|
452
|
-
"input": {"description": "review code", "prompt": "check", "subagent_type": "reviewer"},
|
|
453
|
-
}]},
|
|
454
|
-
})
|
|
455
|
-
tracker.process_event({
|
|
456
|
-
"type": "system",
|
|
457
|
-
"subtype": "task_started",
|
|
458
|
-
"task_id": "task-1",
|
|
459
|
-
"tool_use_id": "tool-1",
|
|
460
|
-
"task_type": "in_process_teammate",
|
|
461
|
-
"subagent_type": "reviewer",
|
|
462
|
-
"description": "review code",
|
|
463
|
-
})
|
|
464
|
-
tracker.process_event({"type": "assistant", "parent_tool_use_id": "tool-1", "message": {"content": [{"type": "text", "text": "child activity"}]}})
|
|
465
|
-
tracker.process_event({"type": "system", "subtype": "task_started", "task_id": "bash-1", "task_type": "local_bash", "description": "ls"})
|
|
466
|
-
tracker.process_event({"type": "system", "subtype": "task_notification", "task_id": "task-1", "tool_use_id": "tool-1", "status": "completed", "summary": "done"})
|
|
467
|
-
|
|
468
|
-
data = tracker.to_dict()
|
|
469
|
-
|
|
470
|
-
statistics = data["subagent_statistics"]
|
|
471
|
-
assert statistics["source"] == "session_log"
|
|
472
|
-
assert statistics["spawned"] == 1
|
|
473
|
-
assert statistics["active"] == 0
|
|
474
|
-
assert statistics["states"] == [{"status": "completed", "count": 1}]
|
|
475
|
-
assert "task-1" in statistics["observed_ids"]
|
|
476
|
-
assert "tool-1" in statistics["parent_activity_ids"]
|
|
477
|
-
assert all("bash" not in record["id"] for record in data["subagent_statistics"]["records"])
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
def test_progress_parser_normalizes_codebuddy_agent_tools_with_deduplication():
|
|
481
|
-
module = _load_progress_parser_module()
|
|
482
|
-
tracker = module.ProgressTracker()
|
|
483
|
-
args = {"prompt": "inspect", "description": "inspect", "subagent_type": "Explore"}
|
|
484
|
-
|
|
485
|
-
tracker.process_event({
|
|
486
|
-
"type": "message",
|
|
487
|
-
"sessionId": "cb-session",
|
|
488
|
-
"cwd": "/tmp/project",
|
|
489
|
-
"role": "assistant",
|
|
490
|
-
"content": [{"type": "tool_use", "id": "call-1", "name": "Agent", "input": args}],
|
|
491
|
-
})
|
|
492
|
-
tracker.process_event({
|
|
493
|
-
"type": "function_call",
|
|
494
|
-
"sessionId": "cb-session",
|
|
495
|
-
"cwd": "/tmp/project",
|
|
496
|
-
"id": "call-1",
|
|
497
|
-
"name": "Agent",
|
|
498
|
-
"arguments": json.dumps(args),
|
|
499
|
-
})
|
|
500
|
-
tracker.process_event({
|
|
501
|
-
"type": "function_call",
|
|
502
|
-
"sessionId": "cb-session",
|
|
503
|
-
"cwd": "/tmp/project",
|
|
504
|
-
"id": "task-call",
|
|
505
|
-
"name": "TaskCreate",
|
|
506
|
-
"arguments": json.dumps({"description": "background", "subject": "status"}),
|
|
507
|
-
})
|
|
508
|
-
|
|
509
|
-
data = tracker.to_dict()
|
|
510
|
-
|
|
511
|
-
assert data["cb_session_id"] == "cb-session"
|
|
512
|
-
statistics = data["subagent_statistics"]
|
|
513
|
-
assert statistics["providers"] == ["codebuddy"]
|
|
514
|
-
assert statistics["spawned"] == 1
|
|
515
|
-
assert statistics["active"] == 1
|
|
516
|
-
assert {item["status"] for item in statistics["states"]} == {"running"}
|
|
517
|
-
assert len(statistics["records"]) == 1
|
|
518
|
-
assert data["subagent_statistics"]["records"][0]["metadata"]["tool"] == "Agent"
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
def test_progress_parser_normalizes_codex_collab_metadata_with_missing_fields():
|
|
522
|
-
module = _load_progress_parser_module()
|
|
523
|
-
tracker = module.ProgressTracker()
|
|
524
|
-
|
|
525
|
-
tracker.process_event({"type": "thread.started", "thread_id": "parent"})
|
|
526
|
-
tracker.process_event({
|
|
527
|
-
"type": "item.started",
|
|
528
|
-
"item": {
|
|
529
|
-
"type": "collab_tool_call",
|
|
530
|
-
"tool": "delegate",
|
|
531
|
-
"receiver_thread_ids": ["thread-a", "thread-b"],
|
|
532
|
-
"agents_states": {
|
|
533
|
-
"thread-a": {"status": "running", "message": "working"},
|
|
534
|
-
"thread-b": {"status": "completed", "message": "done"},
|
|
535
|
-
},
|
|
536
|
-
},
|
|
537
|
-
})
|
|
538
|
-
tracker.process_event({"type": "item.completed", "item": {"type": "collab_tool_call", "tool": "delegate"}})
|
|
539
|
-
tracker.process_event({"type": "turn.completed", "usage": {"input_tokens": 1}})
|
|
540
|
-
|
|
541
|
-
data = tracker.to_dict()
|
|
542
|
-
|
|
543
|
-
assert data["event_format"] == "codex-json"
|
|
544
|
-
assert data["result_subtype"] == "success"
|
|
545
|
-
assert data["stop_reason"] == "completed"
|
|
546
|
-
assert data["is_active"] is False
|
|
547
|
-
assert data["child_thread_ids"] == ["thread-a", "thread-b"]
|
|
548
|
-
statistics = data["subagent_statistics"]
|
|
549
|
-
assert statistics["spawned"] == 2
|
|
550
|
-
assert statistics["active"] == 1
|
|
551
|
-
assert {state["status"]: state["count"] for state in statistics["states"]} == {"running": 1, "completed": 1}
|
|
552
|
-
assert statistics["child_activity_source"] == "filesystem_liveness_only"
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
def test_progress_parser_keeps_child_files_liveness_only(tmp_path, monkeypatch):
|
|
556
|
-
module = _load_progress_parser_module()
|
|
557
|
-
claude_home = tmp_path / "claude"
|
|
558
|
-
project_key = str(tmp_path).replace("\\", "-").replace("/", "-").replace(":", "")
|
|
559
|
-
subagents_dir = claude_home / "projects" / project_key / "parent-session" / "subagents"
|
|
560
|
-
subagents_dir.mkdir(parents=True)
|
|
561
|
-
child_log = subagents_dir / "agent-child.jsonl"
|
|
562
|
-
child_log.write_text("child activity", encoding="utf-8")
|
|
563
|
-
monkeypatch.setenv("CLAUDE_HOME", str(claude_home))
|
|
564
|
-
|
|
565
|
-
tracker = module.ProgressTracker()
|
|
566
|
-
tracker.process_event({"type": "system", "subtype": "init", "session_id": "parent-session", "cwd": str(tmp_path)})
|
|
567
|
-
tracker.process_event({
|
|
568
|
-
"type": "system",
|
|
569
|
-
"subtype": "task_started",
|
|
570
|
-
"task_id": "task-1",
|
|
571
|
-
"tool_use_id": "tool-1",
|
|
572
|
-
"task_type": "in_process_teammate",
|
|
573
|
-
"description": "agent",
|
|
574
|
-
})
|
|
575
|
-
first = tracker.to_dict()
|
|
576
|
-
child_log.write_text("child activity grew", encoding="utf-8")
|
|
577
|
-
tracker.refresh_child_session_activity(force=True)
|
|
578
|
-
second = tracker.to_dict()
|
|
579
|
-
|
|
580
|
-
assert first["subagent_statistics"]["spawned"] == 1
|
|
581
|
-
assert second["subagent_statistics"]["spawned"] == 1
|
|
582
|
-
assert second["child_total_bytes"] > first["child_total_bytes"]
|
|
583
|
-
assert second["child_session_files"]
|
|
584
|
-
assert second["child_activity_source"] == "filesystem_liveness_only"
|
|
585
|
-
assert second["subagent_statistics"]["source"] == "session_log"
|