agent-usage-tracker 0.1.0__py3-none-any.whl

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.
Files changed (113) hide show
  1. agent_usage_tracker/__init__.py +8 -0
  2. agent_usage_tracker/backup.py +225 -0
  3. agent_usage_tracker/cli.py +479 -0
  4. agent_usage_tracker/collectors/__init__.py +115 -0
  5. agent_usage_tracker/collectors/_util.py +310 -0
  6. agent_usage_tracker/collectors/activity_common.py +294 -0
  7. agent_usage_tracker/collectors/activitywatch.py +394 -0
  8. agent_usage_tracker/collectors/claude_code.py +484 -0
  9. agent_usage_tracker/collectors/claude_code_activity.py +317 -0
  10. agent_usage_tracker/collectors/codex.py +612 -0
  11. agent_usage_tracker/collectors/commits.py +154 -0
  12. agent_usage_tracker/collectors/cursor.py +193 -0
  13. agent_usage_tracker/collectors/cursor_api.py +247 -0
  14. agent_usage_tracker/collectors/cursor_cli.py +592 -0
  15. agent_usage_tracker/collectors/cursor_sdk.py +95 -0
  16. agent_usage_tracker/collectors/generic_sdk.py +100 -0
  17. agent_usage_tracker/collectors/pi.py +397 -0
  18. agent_usage_tracker/collectors/session_digest.py +379 -0
  19. agent_usage_tracker/collectors/t3.py +490 -0
  20. agent_usage_tracker/config.py +392 -0
  21. agent_usage_tracker/coverage.py +615 -0
  22. agent_usage_tracker/coverage_catalog.json +588 -0
  23. agent_usage_tracker/cursor_run.py +62 -0
  24. agent_usage_tracker/diagnostics.py +74 -0
  25. agent_usage_tracker/episode_store.py +78 -0
  26. agent_usage_tracker/event.py +132 -0
  27. agent_usage_tracker/git_day_cache.py +128 -0
  28. agent_usage_tracker/git_days.py +499 -0
  29. agent_usage_tracker/git_safe.py +58 -0
  30. agent_usage_tracker/harness_inventory.py +208 -0
  31. agent_usage_tracker/history_steers.py +88 -0
  32. agent_usage_tracker/improve/__init__.py +1 -0
  33. agent_usage_tracker/improve/case_view.py +112 -0
  34. agent_usage_tracker/improve/cli.py +138 -0
  35. agent_usage_tracker/improve/desktop.py +347 -0
  36. agent_usage_tracker/improve/evidence.py +322 -0
  37. agent_usage_tracker/improve/judge.py +671 -0
  38. agent_usage_tracker/improve/proposals.py +72 -0
  39. agent_usage_tracker/improve/rubric.py +360 -0
  40. agent_usage_tracker/improve/rubrics/avoidable_recovery.md +20 -0
  41. agent_usage_tracker/improve/rubrics/code_quality.md +22 -0
  42. agent_usage_tracker/improve/rubrics/completion_supported.md +20 -0
  43. agent_usage_tracker/improve/rubrics/redundant_tests.md +21 -0
  44. agent_usage_tracker/improve/rubrics/verbosity.md +21 -0
  45. agent_usage_tracker/improve/runtime.py +117 -0
  46. agent_usage_tracker/improve/schedule.py +291 -0
  47. agent_usage_tracker/improve/search_check.py +563 -0
  48. agent_usage_tracker/improve/store.py +244 -0
  49. agent_usage_tracker/improve/studies.py +285 -0
  50. agent_usage_tracker/improve/study_cli.py +46 -0
  51. agent_usage_tracker/improve/study_decision.py +121 -0
  52. agent_usage_tracker/improve/study_followup.py +174 -0
  53. agent_usage_tracker/improve/t3.py +269 -0
  54. agent_usage_tracker/improve/trial.py +318 -0
  55. agent_usage_tracker/improve/validation.py +148 -0
  56. agent_usage_tracker/inspector.py +350 -0
  57. agent_usage_tracker/label/__init__.py +22 -0
  58. agent_usage_tracker/label/backends.py +742 -0
  59. agent_usage_tracker/label/bakeoff.py +661 -0
  60. agent_usage_tracker/label/baseline.py +173 -0
  61. agent_usage_tracker/label/clef.py +258 -0
  62. agent_usage_tracker/label/context.py +382 -0
  63. agent_usage_tracker/label/core.py +355 -0
  64. agent_usage_tracker/label/covered_run.py +92 -0
  65. agent_usage_tracker/label/evalset.py +154 -0
  66. agent_usage_tracker/label/gold.py +209 -0
  67. agent_usage_tracker/label/local.py +326 -0
  68. agent_usage_tracker/label/local_parallel.py +232 -0
  69. agent_usage_tracker/label/merge.py +57 -0
  70. agent_usage_tracker/label/outcome_coverage.py +57 -0
  71. agent_usage_tracker/label/replay.py +194 -0
  72. agent_usage_tracker/label/run.py +339 -0
  73. agent_usage_tracker/label/tasks.py +579 -0
  74. agent_usage_tracker/label/teach.py +145 -0
  75. agent_usage_tracker/local_page.py +128 -0
  76. agent_usage_tracker/manual_time.py +69 -0
  77. agent_usage_tracker/net.py +23 -0
  78. agent_usage_tracker/observation_cli.py +65 -0
  79. agent_usage_tracker/observation_report.py +116 -0
  80. agent_usage_tracker/observation_server.py +110 -0
  81. agent_usage_tracker/observations.py +365 -0
  82. agent_usage_tracker/outcome_git.py +383 -0
  83. agent_usage_tracker/outcomes.py +464 -0
  84. agent_usage_tracker/pricing.py +248 -0
  85. agent_usage_tracker/push.py +530 -0
  86. agent_usage_tracker/redact.py +45 -0
  87. agent_usage_tracker/repo_keys.py +165 -0
  88. agent_usage_tracker/review.py +252 -0
  89. agent_usage_tracker/scan.py +472 -0
  90. agent_usage_tracker/scheduled.py +164 -0
  91. agent_usage_tracker/sdk.py +79 -0
  92. agent_usage_tracker/sink.py +82 -0
  93. agent_usage_tracker/sink_stack/README.md +71 -0
  94. agent_usage_tracker/sink_stack/apply.sh +63 -0
  95. agent_usage_tracker/sink_stack/compose.yaml +94 -0
  96. agent_usage_tracker/sink_stack/env.example +20 -0
  97. agent_usage_tracker/sink_stack/grafana/dashboards/agents-effort.json +634 -0
  98. agent_usage_tracker/sink_stack/grafana/dashboards/agents-usage.json +1279 -0
  99. agent_usage_tracker/sink_stack/grafana/provisioning/dashboards/aut.yaml +9 -0
  100. agent_usage_tracker/sink_stack/grafana/provisioning/datasources/agents.yaml +16 -0
  101. agent_usage_tracker/sink_stack/sql/01_schema.sql +1186 -0
  102. agent_usage_tracker/sink_stack/sql/02_price.sql +60 -0
  103. agent_usage_tracker/sink_stack/sql/03_effort.sql +1180 -0
  104. agent_usage_tracker/sink_stack/sql/04_grants.sql +149 -0
  105. agent_usage_tracker/sink_stack/sql/refresh.sql +66 -0
  106. agent_usage_tracker/sources.py +180 -0
  107. agent_usage_tracker/state.py +191 -0
  108. agent_usage_tracker/telemetry.py +165 -0
  109. agent_usage_tracker-0.1.0.dist-info/METADATA +366 -0
  110. agent_usage_tracker-0.1.0.dist-info/RECORD +113 -0
  111. agent_usage_tracker-0.1.0.dist-info/WHEEL +4 -0
  112. agent_usage_tracker-0.1.0.dist-info/entry_points.txt +3 -0
  113. agent_usage_tracker-0.1.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,317 @@
1
+ """Claude Code activity rows (agents.activity_event): how a person steers, what a turn did.
2
+
3
+ Called record by record from the claude_code collector. attrs carry counts, flags, short enums,
4
+ ids and hashes only, never prompt text, tool output, paths, titles or commit messages. It has its
5
+ own module only because of its size: this per-record machine is the same shape as the _Activity
6
+ classes in codex.py, pi.py and cursor_cli.py, which live next to their collectors.
7
+
8
+ The turn aggregates and the retry and runaway rules live in activity_common (from AgentsView,
9
+ github.com/kenn-io/agentsview, MIT licence, (c) its authors).
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from collections import Counter
15
+ from typing import Any, TypedDict
16
+ from urllib.parse import urlparse
17
+
18
+ from ..event import ActivityKind, ActivityEvent, EventSession, RunOrigin, make_event_id
19
+ from ..repo_keys import RepoKeys
20
+ from .activity_common import (IDLE_S, Link, TurnAgg, add_call, best_effort, blank_tool_tally, ms_between,
21
+ pop_pending, record_commits, text_of, text_sha256, tool_key,
22
+ turn_attrs)
23
+ from .commits import commit_call, commit_dir, commit_shas
24
+ from ._util import MS_PER_S, dict_or_empty, str_or_none
25
+
26
+ _INTERRUPT = "[Request interrupted"
27
+ _REJECTED = "The user doesn't want to proceed"
28
+
29
+
30
+ class ActivityState(TypedDict, total=False):
31
+ """What rides in the file's watermark entry; a key with nothing to carry is left out."""
32
+ intr: bool # the last user-side record was an interrupt
33
+ agg: TurnAgg
34
+ pend: dict[str, list[Any]] # commit tool_use_id -> pop_pending's list
35
+ seen: list[str] # tool block ids of the open turn only
36
+ queued: list[str] # hashes of queued prompts not consumed yet
37
+ link: dict[str, Any]
38
+ wt: list[Any] # [repo_key, branch_key] of the worktree the session is in
39
+ lo: dict[str, Any] # the open link turn: last record's uid, ts, session and origin
40
+
41
+
42
+ class Activity:
43
+ """Per-file, per-chunk extractor over `carried`, state from the private copy of the file's
44
+ watermark entry. state() is what must ride in that entry."""
45
+
46
+ def __init__(self, agent: str, path: str, subagent: bool, carried: ActivityState | None,
47
+ keys: RepoKeys) -> None:
48
+ s: ActivityState = carried if isinstance(carried, dict) else {}
49
+ self.agent, self.path, self.subagent, self.keys = agent, path, subagent, keys
50
+ self.events: list[ActivityEvent] = []
51
+ self.errors: Counter[str] = Counter() # records whose extraction raised (skipped)
52
+ self.intr = bool(s.get("intr")) # the last user-side record was an interrupt
53
+ self.after_intr = False
54
+ # Turn aggregates and unanswered commit calls are carried across scans in the watermark,
55
+ # so a turn split by a scan boundary still gets one complete row.
56
+ self.agg: TurnAgg = s.get("agg") or blank_tool_tally()
57
+ self.pend: dict[str, Any] = s.get("pend") or {}
58
+ # Tool block ids already counted. Within a chunk the set spans turns (Claude Code re-logs
59
+ # history after a turn ends). Across scans only the open turn's ids are carried, and
60
+ # turn_duration clears them, so old turns do not accumulate in the watermark.
61
+ # shortcut: subagent files carry none (they never close a turn, so the ids would never be
62
+ # dropped); a subagent block re-logged across a scan boundary can count twice.
63
+ carried_ids = [i for i in (s.get("seen") or []) if isinstance(i, str)]
64
+ self.seen: dict[str, None] = dict.fromkeys(carried_ids)
65
+ self.open_ids: list[str] = carried_ids
66
+ self.queued: set[str] = set(s.get("queued") or ())
67
+ self.link = Link(keys, s.get("link") or {})
68
+ self.wt: list[Any] | None = s.get("wt")
69
+ self.lo: dict[str, Any] | None = s.get("lo")
70
+ self._at3: tuple[Any, ...] | None = None # the (cwd, gitBranch) last placed in this turn
71
+
72
+ def state(self) -> ActivityState:
73
+ s: ActivityState = {}
74
+ if self.intr:
75
+ s["intr"] = True
76
+ # A subagent file never gets a turn_duration, so its aggregates would never be used.
77
+ if not self.subagent and (self.agg["calls"] or self.agg["errors"] or self.agg["hooks"]):
78
+ s["agg"] = self.agg
79
+ if self.pend:
80
+ s["pend"] = self.pend
81
+ if self.open_ids and not self.subagent:
82
+ s["seen"] = self.open_ids
83
+ if self.queued:
84
+ s["queued"] = sorted(self.queued)
85
+ if self.link.s:
86
+ s["link"] = self.link.s
87
+ if self.wt:
88
+ s["wt"] = self.wt
89
+ if self.lo:
90
+ s["lo"] = self.lo
91
+ return s
92
+
93
+ def _emit(self, kind: ActivityKind, o: dict[str, Any], seed: object, sess: EventSession, attrs: dict[str, Any]) -> None:
94
+ self.events.append(ActivityEvent(
95
+ event_id=make_event_id(self.agent, kind, seed), ts=str_or_none(o.get("timestamp")),
96
+ agent=self.agent, kind=kind, session_id=sess.session_id, turn_id=sess.turn_id,
97
+ attrs=attrs))
98
+
99
+ def _uid(self, o: dict[str, Any]) -> str:
100
+ return o.get("uuid") or f"{self.path}:{o.get('timestamp')}"
101
+
102
+ def finish(self) -> None:
103
+ """The file is complete (read to its end and idle for IDLE_S): close its open link turn.
104
+ A subagent or scripted file never gets a turn_duration to close it."""
105
+ best_effort(self.errors, self._close_open_link)
106
+
107
+ def _close_open_link(self) -> None:
108
+ if self.lo:
109
+ lo = self.lo
110
+ self._close_link(lo["uid"], lo["ts"], lo["sid"], lo["turn"], lo["origin"])
111
+
112
+ def _close_link(self, seed: str, ts: str | None, sid: str, turn: str | None,
113
+ origin: RunOrigin) -> None:
114
+ if self.wt:
115
+ self.link.s.setdefault("at", {}).setdefault("1", self.wt)
116
+ self.events.append(ActivityEvent(
117
+ event_id=make_event_id(self.agent, "link", seed), ts=ts, agent=self.agent,
118
+ kind="link", session_id=sid, turn_id=turn, attrs=self.link.attrs(origin)))
119
+ self.link.reset()
120
+ self.lo, self._at3 = None, None
121
+
122
+ def record(self, o: dict[str, Any], sess: EventSession) -> None:
123
+ typ = o.get("type")
124
+ self._close_link_after_gap(o)
125
+ if typ in ("queue-operation", "attachment"):
126
+ self._note_queued(o)
127
+ elif typ == "pr-link":
128
+ self._pr(o, sess)
129
+ elif typ == "worktree-state":
130
+ self._worktree(o)
131
+ elif typ in ("ai-title", "custom-title"):
132
+ self.link.note_tickets(o.get("aiTitle") or o.get("customTitle"))
133
+ elif typ == "system":
134
+ self._system(o, sess)
135
+ elif typ in ("assistant", "user"):
136
+ self._note_link_turn(o, sess)
137
+ m = o.get("message")
138
+ content = m.get("content") if isinstance(m, dict) else None
139
+ blocks = [b for b in content if isinstance(b, dict)] if isinstance(content, list) else []
140
+ if typ == "assistant":
141
+ self._assistant(o, blocks, sess)
142
+ else:
143
+ self._user(o, content, blocks, sess)
144
+
145
+ def _close_link_after_gap(self, o: dict[str, Any]) -> None:
146
+ # A record IDLE_S or more after the open link turn's last one: that turn closed there,
147
+ # as a live scan that saw the file idle in between closed it, so any split of scans and
148
+ # one full read cut the same place. shortcut: assumes a record reaches the file within
149
+ # IDLE_S of its timestamp (a synced log that lags longer can split differently); upgrade
150
+ # if synced files show split-vs-full drift.
151
+ gap = ms_between(self.lo["ts"], o.get("timestamp")) if self.lo else None
152
+ if gap is not None and gap >= IDLE_S * MS_PER_S:
153
+ self.finish()
154
+
155
+ def _note_link_turn(self, o: dict[str, Any], sess: EventSession) -> None:
156
+ self.lo = {"uid": self._uid(o), "ts": str_or_none(o.get("timestamp")), "sid": sess.session_id,
157
+ "turn": sess.turn_id, "origin": sess.run_origin}
158
+ at3 = (o.get("cwd"), o.get("gitBranch"))
159
+ if at3 != self._at3:
160
+ self._at3 = at3
161
+ self.link.place(3, self.keys.of_cwd(at3[0]), at3[1])
162
+
163
+ def _note_queued(self, o: dict[str, Any]) -> None:
164
+ if o.get("type") == "queue-operation":
165
+ if o.get("operation") == "enqueue" and isinstance(o.get("content"), str):
166
+ self.queued.add(text_sha256(o["content"]))
167
+ return
168
+ a = o.get("attachment")
169
+ if isinstance(a, dict) and a.get("type") == "queued_command":
170
+ self.queued.add(text_sha256(text_of(a.get("prompt"))))
171
+
172
+ def _worktree(self, o: dict[str, Any]) -> None:
173
+ ws = o.get("worktreeSession")
174
+ if isinstance(ws, dict):
175
+ rk = self.keys.of_cwd(ws.get("originalCwd")) \
176
+ or self.keys.of_cwd(ws.get("worktreePath"))
177
+ self.wt = self.link.source(rk, ws.get("worktreeBranch"))
178
+ else: # the session left its worktree
179
+ self.wt = None
180
+
181
+ def _system(self, o: dict[str, Any], sess: EventSession) -> None:
182
+ if o.get("subtype") == "turn_duration":
183
+ self._turn(o, sess)
184
+ elif o.get("subtype") == "compact_boundary":
185
+ meta = o.get("compactMetadata")
186
+ trig = meta.get("trigger") if isinstance(meta, dict) else None
187
+ self._emit("compaction", o, self._uid(o), sess,
188
+ {"trigger": trig} if isinstance(trig, str) else {})
189
+
190
+ def _assistant(self, o: dict[str, Any], blocks: list[dict[str, Any]], sess: EventSession) -> None:
191
+ for b in blocks:
192
+ if b.get("type") == "tool_use":
193
+ self._tool_use(o, b, sess)
194
+ elif b.get("type") == "text":
195
+ # shortcut: a re-logged text block is read again (its SHAs and PRs are the
196
+ # session's own, so only the next turn's lists grow); dedup by uuid if that skews
197
+ # the link lists
198
+ self.link.note_text(b.get("text"))
199
+
200
+ def _user(self, o: dict[str, Any], content: object, blocks: list[dict[str, Any]], sess: EventSession) -> None:
201
+ self.link.note_text(text_of(content))
202
+ for b in blocks:
203
+ if b.get("type") == "tool_result":
204
+ self._tool_result(o, b, sess)
205
+ if o.get("isMeta"):
206
+ return
207
+ is_intr = text_of(content).lstrip().startswith(_INTERRUPT)
208
+ self.after_intr, self.intr = self.intr, is_intr
209
+ # A subagent's copy of the interrupt is the same keypress the parent already logged.
210
+ if is_intr and not (self.subagent or o.get("isSidechain")):
211
+ self._emit("interrupt", o, self._uid(o), sess,
212
+ {"during_tool": "for tool use" in text_of(content)})
213
+
214
+ def steer(self, o: dict[str, Any], uid: str, text: str, sess: EventSession) -> ActivityEvent | None:
215
+ """The steer row for a prompt the collector counted as human (None if it raised). Call after
216
+ record(o)."""
217
+ return best_effort(self.errors, self._steer, o, uid, text, sess)
218
+
219
+ def _steer(self, o: dict[str, Any], uid: str, text: str, sess: EventSession) -> ActivityEvent:
220
+ s, ps = text.lstrip(), o.get("promptSource")
221
+ prompt_hash = text_sha256(text)
222
+ queued = ps == "queued" or (ps is None and prompt_hash in self.queued)
223
+ if queued:
224
+ self.queued.discard(prompt_hash)
225
+ if s.startswith("<bash-input>"):
226
+ via = "bash_input"
227
+ elif s.startswith("<skill>"):
228
+ via = "skill"
229
+ elif s.startswith(("<command-name>", "<command-message>")):
230
+ via = "slash_command"
231
+ elif ps == "suggestion_accepted":
232
+ via = "suggestion_accepted"
233
+ # promptSource says so on newer files; older ones only show the earlier enqueue.
234
+ elif queued:
235
+ via = "queued"
236
+ else:
237
+ via = "typed"
238
+ return ActivityEvent(
239
+ event_id=make_event_id(self.agent, "steer", uid), ts=str_or_none(o.get("timestamp")),
240
+ agent=self.agent, kind="steer", session_id=sess.session_id, turn_id=sess.turn_id,
241
+ attrs={"via": via, "words": len(text.split()), "chars": len(text),
242
+ "after_interrupt": self.after_intr})
243
+
244
+ def _tool_use(self, o: dict[str, Any], b: dict[str, Any], sess: EventSession) -> None:
245
+ tid, name = b.get("id"), b.get("name")
246
+ if not isinstance(tid, str) or not isinstance(name, str) or "u" + tid in self.seen:
247
+ return # a re-logged block counts once
248
+ self.seen["u" + tid] = None
249
+ self.open_ids.append("u" + tid)
250
+ inp = dict_or_empty(b.get("input"))
251
+ add_call(self.agg, name, inp)
252
+ if name == "Skill" and isinstance(inp.get("skill"), str):
253
+ self._emit("invoke", o, tid, sess, {"skill": tool_key(inp["skill"])})
254
+ cmd = inp.get("command")
255
+ if name == "Bash" and isinstance(cmd, str) and (call := commit_call(cmd)):
256
+ self.pend[tid] = [*call, commit_dir(cmd)]
257
+
258
+ def _tool_result(self, o: dict[str, Any], b: dict[str, Any], sess: EventSession) -> None:
259
+ tid = b.get("tool_use_id")
260
+ if not isinstance(tid, str) or "r" + tid in self.seen:
261
+ return
262
+ self.seen["r" + tid] = None
263
+ self.open_ids.append("r" + tid)
264
+ err = b.get("is_error") is True
265
+ text = text_of(b.get("content")).lstrip()
266
+ self.link.note_text(text)
267
+ if err:
268
+ self.agg["errors"] += 1
269
+ if text.startswith(_REJECTED):
270
+ self._emit("rejection", o, tid, sess, {})
271
+ elif text.startswith("PreToolUse:") and "hook error" in text[:200]:
272
+ self.agg["hooks"] += 1 # a hook denied it, not the user
273
+ if tid in self.pend:
274
+ amend, before, target = pop_pending(self.pend, tid)
275
+ self._commits(o, tid, text, sess, target, amend=amend, before=before, err=err)
276
+
277
+ def _commits(self, o: dict[str, Any], tid: str, text: str, sess: EventSession, target: object, *,
278
+ amend: bool, before: bool, err: bool) -> None:
279
+ tr = o.get("toolUseResult")
280
+ g = tr.get("gitOperation") if isinstance(tr, dict) else None
281
+ c = g.get("commit") if isinstance(g, dict) else None
282
+ sha = c.get("sha") if isinstance(c, dict) and isinstance(c.get("sha"), str) else None
283
+ found = commit_shas(text, err, before, sha)
284
+ for sha, attrs in record_commits(self.link, o.get("cwd"), target, text, found, amend=amend,
285
+ fallback=self.wt[0] if self.wt else None):
286
+ self._emit("commit", o, f"{tid}|{sha}", sess, attrs)
287
+
288
+ def _pr(self, o: dict[str, Any], sess: EventSession) -> None:
289
+ num, url, repo = o.get("prNumber"), o.get("prUrl"), o.get("prRepository")
290
+ if not isinstance(num, int) or isinstance(num, bool):
291
+ return
292
+ try:
293
+ host = (urlparse(url).hostname or "") if isinstance(url, str) else ""
294
+ except ValueError: # a malformed URL ("https://[x/...")
295
+ host = ""
296
+ kind = "github" if "github" in host else "bitbucket" if "bitbucket" in host else "other"
297
+ key = self.keys.of(f"{host}/{repo.strip('/')}".lower()) \
298
+ if host and isinstance(repo, str) else None
299
+ self.link.note_pr(host, repo, num)
300
+ # One row per pr-link record (its ts never depends on how much of the file a scan read);
301
+ # distinct PRs are counted in SQL. Real pr-link records carry no uuid, so the fallback seed
302
+ # is session + number + the record's own ts: a re-logged copy maps to the same row.
303
+ seed = o.get("uuid") or f"{sess.session_id}|{num}|{o.get('timestamp')}"
304
+ self._emit("pr", o, seed, sess, {"number": num, "host": kind, "repo_key": key})
305
+
306
+ def _turn(self, o: dict[str, Any], sess: EventSession) -> None:
307
+ self._emit("turn", o, self._uid(o), sess, {
308
+ "duration_ms": o.get("durationMs") if isinstance(o.get("durationMs"), int) else None,
309
+ "message_count": o.get("messageCount") if isinstance(o.get("messageCount"), int)
310
+ else None,
311
+ "hook_blocks": self.agg["hooks"], **turn_attrs(self.agg),
312
+ })
313
+ self.agg = blank_tool_tally()
314
+ self.pend.clear() # a commit call still unanswered at turn end never will be
315
+ self.open_ids = []
316
+ self._close_link(self._uid(o), o.get("timestamp"), sess.session_id, sess.turn_id,
317
+ sess.run_origin)