execweave 1.0.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 (234) hide show
  1. execweave/__init__.py +3 -0
  2. execweave/__main__.py +5 -0
  3. execweave/_conversation_records_core.py +902 -0
  4. execweave/_dashboard_shell_base.py +148 -0
  5. execweave/_http_proxy_base.py +565 -0
  6. execweave/_http_proxy_bounded.py +560 -0
  7. execweave/_http_proxy_stage.py +509 -0
  8. execweave/acceptance_output.py +19 -0
  9. execweave/agent_bootstrap.py +395 -0
  10. execweave/agent_topology.py +313 -0
  11. execweave/agent_trace.py +1162 -0
  12. execweave/agy_preview_sanitize.py +102 -0
  13. execweave/analysis.py +427 -0
  14. execweave/anthropic.py +228 -0
  15. execweave/anthropic_cli.py +171 -0
  16. execweave/anthropic_full_fidelity.py +385 -0
  17. execweave/antigravity_adapter.py +112 -0
  18. execweave/antigravity_adapter_base.py +479 -0
  19. execweave/antigravity_full_fidelity.py +656 -0
  20. execweave/antigravity_full_fidelity_base.py +172 -0
  21. execweave/antigravity_full_fidelity_collaboration_base.py +451 -0
  22. execweave/antigravity_hook_cli.py +209 -0
  23. execweave/antigravity_record.py +96 -0
  24. execweave/antigravity_subagent_linkage.py +449 -0
  25. execweave/antigravity_trace_capability.py +39 -0
  26. execweave/auto_specialized.py +547 -0
  27. execweave/backends.py +102 -0
  28. execweave/benchmark.py +80 -0
  29. execweave/claude_adapter.py +517 -0
  30. execweave/claude_child_transcript.py +314 -0
  31. execweave/claude_delegation.py +136 -0
  32. execweave/claude_full_fidelity.py +396 -0
  33. execweave/claude_hook_cli.py +209 -0
  34. execweave/claude_hook_contract.py +943 -0
  35. execweave/claude_model_observer.py +353 -0
  36. execweave/claude_record.py +106 -0
  37. execweave/cli.py +629 -0
  38. execweave/codex_adapter.py +455 -0
  39. execweave/codex_conversation.py +621 -0
  40. execweave/codex_full_fidelity.py +287 -0
  41. execweave/codex_hook_cli.py +301 -0
  42. execweave/codex_hook_entry.py +207 -0
  43. execweave/codex_hook_lifecycle.py +363 -0
  44. execweave/codex_message_diagnostics.py +322 -0
  45. execweave/codex_message_transport_diagnostics.py +399 -0
  46. execweave/codex_record.py +199 -0
  47. execweave/codex_rollout_structures.py +402 -0
  48. execweave/codex_rollout_trace.py +56 -0
  49. execweave/codex_rollout_trace_base.py +1509 -0
  50. execweave/collector.py +768 -0
  51. execweave/command.py +157 -0
  52. execweave/command_privacy.py +20 -0
  53. execweave/content_evidence.py +101 -0
  54. execweave/content_integrity.py +289 -0
  55. execweave/content_store.py +273 -0
  56. execweave/controlled_checks.py +561 -0
  57. execweave/conversation_archive.py +338 -0
  58. execweave/conversation_message_identity.py +264 -0
  59. execweave/conversation_preview.py +66 -0
  60. execweave/conversation_preview_antigravity.py +32 -0
  61. execweave/conversation_preview_claude.py +31 -0
  62. execweave/conversation_preview_codex.py +107 -0
  63. execweave/conversation_preview_common.py +180 -0
  64. execweave/conversation_preview_generic.py +188 -0
  65. execweave/conversation_preview_lines.py +133 -0
  66. execweave/conversation_preview_transcript.py +121 -0
  67. execweave/conversation_records.py +349 -0
  68. execweave/conversation_records_antigravity.py +370 -0
  69. execweave/conversation_records_codex.py +83 -0
  70. execweave/conversation_records_common.py +17 -0
  71. execweave/conversation_records_ollama.py +39 -0
  72. execweave/correlation.py +818 -0
  73. execweave/cursor_adapter.py +349 -0
  74. execweave/cursor_delegation.py +87 -0
  75. execweave/cursor_delegation_base.py +220 -0
  76. execweave/cursor_full_fidelity.py +489 -0
  77. execweave/cursor_hook_cli.py +195 -0
  78. execweave/cursor_hook_contract.py +439 -0
  79. execweave/cursor_lifecycle.py +159 -0
  80. execweave/cursor_record.py +96 -0
  81. execweave/dashboard_shell.py +283 -0
  82. execweave/delivery_status.py +94 -0
  83. execweave/entry.py +98 -0
  84. execweave/evidence_availability.py +113 -0
  85. execweave/evidence_grade.py +166 -0
  86. execweave/fidelity.py +304 -0
  87. execweave/filesystem.py +327 -0
  88. execweave/finalization.py +92 -0
  89. execweave/focus.py +118 -0
  90. execweave/framework_adapters/__init__.py +34 -0
  91. execweave/framework_adapters/autogen.py +398 -0
  92. execweave/framework_adapters/base.py +580 -0
  93. execweave/framework_adapters/camel.py +270 -0
  94. execweave/framework_adapters/camel_channel.py +71 -0
  95. execweave/framework_adapters/metagpt.py +315 -0
  96. execweave/framework_adapters/metagpt_ollama_compat.py +54 -0
  97. execweave/framework_adapters/metagpt_recording.py +342 -0
  98. execweave/framework_adapters/registry.py +90 -0
  99. execweave/graph.py +590 -0
  100. execweave/graph_ops.py +472 -0
  101. execweave/hook_command.py +32 -0
  102. execweave/hook_delivery.py +32 -0
  103. execweave/hook_input.py +16 -0
  104. execweave/http_proxy.py +187 -0
  105. execweave/http_proxy_cli.py +84 -0
  106. execweave/inference_gateway.py +476 -0
  107. execweave/inference_gateway_cli.py +211 -0
  108. execweave/inference_gateway_full_fidelity.py +613 -0
  109. execweave/inference_identity.py +76 -0
  110. execweave/inference_identity_cli.py +60 -0
  111. execweave/integrity.py +235 -0
  112. execweave/integrity_cli.py +55 -0
  113. execweave/investigation_index.py +445 -0
  114. execweave/litellm_callback.py +211 -0
  115. execweave/litellm_callback_cli.py +42 -0
  116. execweave/live.py +445 -0
  117. execweave/live_core.py +972 -0
  118. execweave/live_view.py +109 -0
  119. execweave/live_view_extra_style.py +11 -0
  120. execweave/live_view_markup.py +29 -0
  121. execweave/live_view_process_layout.py +650 -0
  122. execweave/live_view_readability.py +502 -0
  123. execweave/live_view_script_a.py +59 -0
  124. execweave/live_view_script_b.py +97 -0
  125. execweave/live_view_script_c.py +59 -0
  126. execweave/live_view_script_d.py +40 -0
  127. execweave/live_view_style.py +34 -0
  128. execweave/model_runtime.py +560 -0
  129. execweave/model_runtime_cli.py +265 -0
  130. execweave/model_runtime_full_fidelity.py +519 -0
  131. execweave/observation.py +53 -0
  132. execweave/observation_demo.py +69 -0
  133. execweave/openai_agents.py +267 -0
  134. execweave/openai_agents_sdk.py +453 -0
  135. execweave/openai_compatible.py +239 -0
  136. execweave/openai_compatible_cli.py +189 -0
  137. execweave/openai_compatible_full_fidelity.py +438 -0
  138. execweave/opencode_adapter.py +325 -0
  139. execweave/opencode_event_contract.py +734 -0
  140. execweave/opencode_full_fidelity.py +198 -0
  141. execweave/opencode_hook_cli.py +119 -0
  142. execweave/opencode_plugin_cli.py +150 -0
  143. execweave/opencode_record.py +96 -0
  144. execweave/opencode_task_linkage.py +225 -0
  145. execweave/overhead_benchmark.py +440 -0
  146. execweave/privacy.py +84 -0
  147. execweave/private_io.py +465 -0
  148. execweave/provider_capability.py +578 -0
  149. execweave/provider_lifecycle.py +282 -0
  150. execweave/provider_record.py +290 -0
  151. execweave/reader_identity.py +13 -0
  152. execweave/redacted_archive.py +906 -0
  153. execweave/risk.py +106 -0
  154. execweave/rule_pack.py +359 -0
  155. execweave/rule_pack_cli.py +57 -0
  156. execweave/run_assessment.py +200 -0
  157. execweave/runtime_endpoint_availability.py +44 -0
  158. execweave/scalability_benchmark.py +195 -0
  159. execweave/schema.py +62 -0
  160. execweave/scope.py +85 -0
  161. execweave/semantic.py +453 -0
  162. execweave/session_summary.py +159 -0
  163. execweave/sink.py +71 -0
  164. execweave/strace_backend.py +927 -0
  165. execweave/stream_assembly.py +363 -0
  166. execweave/task_artifacts.py +192 -0
  167. execweave/task_validation.py +317 -0
  168. execweave/theme.py +40 -0
  169. execweave/top.py +599 -0
  170. execweave/top_cli.py +150 -0
  171. execweave/validate.py +196 -0
  172. execweave/vendor/dagre.min.js +815 -0
  173. execweave/view_cli.py +49 -0
  174. execweave/viewer.py +474 -0
  175. execweave/viewer_agent_panel.py +630 -0
  176. execweave/viewer_agent_panel_antigravity.py +31 -0
  177. execweave/viewer_agent_panel_claude.py +9 -0
  178. execweave/viewer_agent_panel_codex.py +50 -0
  179. execweave/viewer_agent_panel_cursor.py +9 -0
  180. execweave/viewer_agent_panel_default.py +79 -0
  181. execweave/viewer_agent_panel_ollama.py +20 -0
  182. execweave/viewer_agent_panel_opencode.py +9 -0
  183. execweave/viewer_agent_panel_registry.py +20 -0
  184. execweave/viewer_archive_verifier.py +178 -0
  185. execweave/viewer_background_files.py +86 -0
  186. execweave/viewer_content_browser.py +307 -0
  187. execweave/viewer_content_health.py +208 -0
  188. execweave/viewer_content_inspector.py +309 -0
  189. execweave/viewer_controlled_checks.py +258 -0
  190. execweave/viewer_conversation_sync.py +115 -0
  191. execweave/viewer_dashboard_clean.py +405 -0
  192. execweave/viewer_dashboard_focus.py +127 -0
  193. execweave/viewer_dashboard_hardening.py +264 -0
  194. execweave/viewer_dashboard_hardening_v2.py +62 -0
  195. execweave/viewer_dashboard_projection.py +261 -0
  196. execweave/viewer_delivery_status.py +155 -0
  197. execweave/viewer_edge_decross.py +117 -0
  198. execweave/viewer_execution_flow.py +611 -0
  199. execweave/viewer_execution_flow_provider_normalization.py +107 -0
  200. execweave/viewer_execution_flow_safety.py +349 -0
  201. execweave/viewer_external_endpoints.py +307 -0
  202. execweave/viewer_flow_canvas.py +1140 -0
  203. execweave/viewer_flow_layout.py +922 -0
  204. execweave/viewer_fold_state.py +31 -0
  205. execweave/viewer_framework_flow.py +68 -0
  206. execweave/viewer_framework_model_output.py +133 -0
  207. execweave/viewer_gif.py +278 -0
  208. execweave/viewer_history_browser.py +225 -0
  209. execweave/viewer_investigation.py +268 -0
  210. execweave/viewer_layout_geometry.py +192 -0
  211. execweave/viewer_layout_v2.py +429 -0
  212. execweave/viewer_layout_v2_detached.py +25 -0
  213. execweave/viewer_limits.py +93 -0
  214. execweave/viewer_live_layout.py +61 -0
  215. execweave/viewer_message_handoffs.py +114 -0
  216. execweave/viewer_projection.py +488 -0
  217. execweave/viewer_projection_base.py +522 -0
  218. execweave/viewer_projection_bridges.py +214 -0
  219. execweave/viewer_recorded_sources.py +146 -0
  220. execweave/viewer_run_assessment.py +274 -0
  221. execweave/viewer_run_guide.py +175 -0
  222. execweave/viewer_runtime_evidence.py +258 -0
  223. execweave/viewer_semantic_projection.py +641 -0
  224. execweave/viewer_session_flow.py +491 -0
  225. execweave/viewer_structure_share.py +132 -0
  226. execweave/viewer_task_validation.py +241 -0
  227. execweave/viewer_tool_mirror_identity.py +75 -0
  228. execweave/viewer_workflow_mode.py +127 -0
  229. execweave/workflow.py +183 -0
  230. execweave-1.0.0.dist-info/METADATA +462 -0
  231. execweave-1.0.0.dist-info/RECORD +234 -0
  232. execweave-1.0.0.dist-info/WHEEL +4 -0
  233. execweave-1.0.0.dist-info/entry_points.txt +30 -0
  234. execweave-1.0.0.dist-info/licenses/LICENSE +16 -0
@@ -0,0 +1,943 @@
1
+ from __future__ import annotations
2
+
3
+ import hashlib
4
+ import json
5
+ from datetime import datetime, timezone
6
+ from typing import Any
7
+
8
+ from .claude_full_fidelity import claude_hook_to_content_events as _legacy_content_events
9
+ from .content_evidence import content_observation_event
10
+ from .content_store import ContentReference, FullFidelityContentStore
11
+ from .agent_topology import EVIDENCE_SUBAGENT_LIFECYCLE_HOOK, subagent_topology
12
+
13
+ CLAUDE_HOOKS_REFERENCE = "https://code.claude.com/docs/en/hooks"
14
+
15
+ OFFICIAL_CLAUDE_HOOK_EVENTS = frozenset(
16
+ {
17
+ "SessionStart",
18
+ "Setup",
19
+ "InstructionsLoaded",
20
+ "UserPromptSubmit",
21
+ "UserPromptExpansion",
22
+ "MessageDisplay",
23
+ "PreToolUse",
24
+ "PermissionRequest",
25
+ "PostToolUse",
26
+ "PostToolUseFailure",
27
+ "PostToolBatch",
28
+ "PermissionDenied",
29
+ "Notification",
30
+ "SubagentStart",
31
+ "SubagentStop",
32
+ "TaskCreated",
33
+ "TaskCompleted",
34
+ "Stop",
35
+ "StopFailure",
36
+ "TeammateIdle",
37
+ "ConfigChange",
38
+ "CwdChanged",
39
+ "DirectoryAdded",
40
+ "FileChanged",
41
+ "WorktreeCreate",
42
+ "WorktreeRemove",
43
+ "PreCompact",
44
+ "PostCompact",
45
+ "Elicitation",
46
+ "ElicitationResult",
47
+ "SessionEnd",
48
+ }
49
+ )
50
+
51
+ # Configuring WorktreeCreate replaces Claude Code's default worktree creation.
52
+ # FileChanged's matcher also defines the literal watch list. Neither is safe to
53
+ # enable as an unconditional passive observer.
54
+ UNSAFE_DEFAULT_CLAUDE_HOOK_EVENTS = frozenset({"WorktreeCreate", "FileChanged"})
55
+ PASSIVE_CLAUDE_HOOK_EVENTS = OFFICIAL_CLAUDE_HOOK_EVENTS - UNSAFE_DEFAULT_CLAUDE_HOOK_EVENTS
56
+
57
+ _ALREADY_PROJECTED_ELSEWHERE = frozenset(
58
+ {
59
+ "UserPromptSubmit",
60
+ "MessageDisplay",
61
+ "PreToolUse",
62
+ "PostToolUse",
63
+ "PostToolUseFailure",
64
+ "PostToolBatch",
65
+ "SubagentStart",
66
+ "SubagentStop",
67
+ }
68
+ )
69
+
70
+ _EXTRA_CONTENT_FIELDS: dict[str, frozenset[str]] = {
71
+ "UserPromptExpansion": frozenset({"prompt", "command_args"}),
72
+ "PermissionRequest": frozenset({"tool_input"}),
73
+ "PermissionDenied": frozenset({"tool_input", "reason"}),
74
+ "Notification": frozenset({"message", "title"}),
75
+ "TaskCreated": frozenset({"task_subject", "task_description"}),
76
+ "TaskCompleted": frozenset({"task_subject", "task_description"}),
77
+ "Stop": frozenset({"background_tasks", "session_crons"}),
78
+ "PreCompact": frozenset({"custom_instructions"}),
79
+ "PostCompact": frozenset({"compact_summary"}),
80
+ "Elicitation": frozenset({"message", "requested_schema", "url"}),
81
+ "ElicitationResult": frozenset({"content"}),
82
+ }
83
+
84
+
85
+ def _now() -> str:
86
+ return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
87
+
88
+
89
+ def _entity(
90
+ entity_type: str,
91
+ entity_id: str,
92
+ *,
93
+ name: str | None = None,
94
+ attributes: dict[str, Any] | None = None,
95
+ ) -> dict[str, Any]:
96
+ return {
97
+ "type": entity_type,
98
+ "id": entity_id,
99
+ "name": name,
100
+ "attributes": attributes or {},
101
+ }
102
+
103
+
104
+ def _main_agent() -> dict[str, Any]:
105
+ return _entity("agent", "agent:Claude Code", name="Claude Code")
106
+
107
+
108
+ def _actor(payload: dict[str, Any]) -> dict[str, Any]:
109
+ agent_id = payload.get("agent_id")
110
+ if not isinstance(agent_id, str) or not agent_id:
111
+ return _main_agent()
112
+ session_id = payload.get("session_id")
113
+ session = session_id if isinstance(session_id, str) and session_id else "unknown"
114
+ agent_type = payload.get("agent_type")
115
+ name = agent_type if isinstance(agent_type, str) and agent_type else "Claude subagent"
116
+ return _entity(
117
+ "agent",
118
+ f"agent:claude:{session}:subagent:{agent_id}",
119
+ name=name,
120
+ attributes={
121
+ "provider": "claude",
122
+ "session_id": session,
123
+ "agent_id": agent_id,
124
+ "agent_type": name,
125
+ "identity_source": "provider_exposed_agent_id",
126
+ **subagent_topology(
127
+ evidence=EVIDENCE_SUBAGENT_LIFECYCLE_HOOK,
128
+ parent_scope_id=session,
129
+ ),
130
+ },
131
+ )
132
+
133
+
134
+ def _session(payload: dict[str, Any]) -> dict[str, Any]:
135
+ session_id = payload.get("session_id")
136
+ if not isinstance(session_id, str) or not session_id:
137
+ raise ValueError("Claude official hook payload requires session_id")
138
+ return _entity(
139
+ "provider_session",
140
+ f"provider-session:claude:{session_id}",
141
+ name=session_id,
142
+ attributes={"provider": "claude", "session_id": session_id},
143
+ )
144
+
145
+
146
+ def _event(
147
+ *,
148
+ timestamp: str,
149
+ event_type: str,
150
+ relation: str,
151
+ source: dict[str, Any],
152
+ target: dict[str, Any],
153
+ attributes: dict[str, Any] | None = None,
154
+ ) -> dict[str, Any]:
155
+ merged: dict[str, Any] = {
156
+ "backend": "semantic",
157
+ "provider": "claude",
158
+ "evidence_source": "provider_hook",
159
+ "attribution": "claude_official_hook_contract",
160
+ "causal": False,
161
+ "inferred": False,
162
+ "official_hook_contract": True,
163
+ "official_hook_reference": CLAUDE_HOOKS_REFERENCE,
164
+ }
165
+ if attributes:
166
+ merged.update(attributes)
167
+ return {
168
+ "timestamp": timestamp,
169
+ "event_type": event_type,
170
+ "relation": relation,
171
+ "source": source,
172
+ "target": target,
173
+ "attributes": merged,
174
+ }
175
+
176
+
177
+ def _common(payload: dict[str, Any]) -> dict[str, Any]:
178
+ attrs: dict[str, Any] = {"claude_hook_event_name": payload.get("hook_event_name")}
179
+ for key in ("session_id", "cwd", "permission_mode", "agent_id", "agent_type"):
180
+ value = payload.get(key)
181
+ if isinstance(value, (str, int, float, bool)) and value != "":
182
+ attrs[f"claude_{key}"] = value
183
+ return attrs
184
+
185
+
186
+ def _observation_id(payload: dict[str, Any], *, timestamp: str, phase: str) -> str:
187
+ stable = {
188
+ "session_id": payload.get("session_id"),
189
+ "hook_event_name": payload.get("hook_event_name"),
190
+ "agent_id": payload.get("agent_id"),
191
+ "task_id": payload.get("task_id"),
192
+ "elicitation_id": payload.get("elicitation_id"),
193
+ "tool_use_id": payload.get("tool_use_id"),
194
+ "phase": phase,
195
+ "timestamp": timestamp,
196
+ }
197
+ raw = json.dumps(stable, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
198
+ return hashlib.sha256(raw.encode("utf-8")).hexdigest()[:24]
199
+
200
+
201
+ def _observation(
202
+ payload: dict[str, Any],
203
+ *,
204
+ timestamp: str,
205
+ phase: str,
206
+ entity_type: str,
207
+ name: str,
208
+ attributes: dict[str, Any] | None = None,
209
+ ) -> dict[str, Any]:
210
+ ident = _observation_id(payload, timestamp=timestamp, phase=phase)
211
+ merged = {"provider": "claude", "observation_phase": phase}
212
+ if attributes:
213
+ merged.update(attributes)
214
+ return _entity(
215
+ entity_type,
216
+ f"{entity_type}:claude:{ident}",
217
+ name=name,
218
+ attributes=merged,
219
+ )
220
+
221
+
222
+ def _file(path: str, *, instruction: bool = False) -> dict[str, Any]:
223
+ return _entity(
224
+ "file",
225
+ f"file:{path}",
226
+ name=path.rsplit("/", 1)[-1] or path,
227
+ attributes={
228
+ "provider": "claude",
229
+ "absolute_path_from_provider": True,
230
+ "instruction_file": instruction,
231
+ },
232
+ )
233
+
234
+
235
+ def _directory(path: str, *, kind: str = "directory") -> dict[str, Any]:
236
+ return _entity(
237
+ kind,
238
+ f"{kind}:claude:{path}",
239
+ name=path,
240
+ attributes={"provider": "claude", "absolute_path_from_provider": True},
241
+ )
242
+
243
+
244
+ def _tool_call(payload: dict[str, Any]) -> dict[str, Any]:
245
+ session_id = payload.get("session_id")
246
+ session = session_id if isinstance(session_id, str) and session_id else "unknown"
247
+ tool_use_id = payload.get("tool_use_id")
248
+ use_id = tool_use_id if isinstance(tool_use_id, str) and tool_use_id else "unknown"
249
+ tool_name = payload.get("tool_name")
250
+ name = tool_name if isinstance(tool_name, str) and tool_name else "unknown"
251
+ return _entity(
252
+ "tool_call",
253
+ f"tool-call:claude:{session}:{use_id}",
254
+ name=name,
255
+ attributes={"provider": "claude", "tool_use_id": use_id, "tool_name": name},
256
+ )
257
+
258
+
259
+ def _task(payload: dict[str, Any]) -> dict[str, Any]:
260
+ session_id = payload.get("session_id")
261
+ session = session_id if isinstance(session_id, str) and session_id else "unknown"
262
+ task_id = payload.get("task_id")
263
+ if not isinstance(task_id, str) or not task_id:
264
+ raise ValueError(f"{payload.get('hook_event_name')} requires task_id")
265
+ subject = payload.get("task_subject")
266
+ name = subject if isinstance(subject, str) and subject else task_id
267
+ attrs: dict[str, Any] = {"provider": "claude", "session_id": session, "task_id": task_id}
268
+ teammate = payload.get("teammate_name")
269
+ if isinstance(teammate, str) and teammate:
270
+ attrs["teammate_name"] = teammate
271
+ attrs["teammate_name_is_stable_agent_identity"] = False
272
+ team_name = payload.get("team_name")
273
+ if isinstance(team_name, str) and team_name:
274
+ attrs["team_name"] = team_name
275
+ attrs["team_name_deprecated_by_provider"] = True
276
+ return _entity("agent_task", f"agent-task:claude:{session}:{task_id}", name=name, attributes=attrs)
277
+
278
+
279
+ def _mcp_server(payload: dict[str, Any]) -> dict[str, Any]:
280
+ name = payload.get("mcp_server_name")
281
+ if not isinstance(name, str) or not name:
282
+ raise ValueError(f"{payload.get('hook_event_name')} requires mcp_server_name")
283
+ return _entity(
284
+ "mcp_server",
285
+ f"mcp-server:claude:{name}",
286
+ name=name,
287
+ attributes={"provider": "claude", "server_name": name},
288
+ )
289
+
290
+
291
+ def _elicitation(payload: dict[str, Any], *, timestamp: str) -> dict[str, Any]:
292
+ server = payload.get("mcp_server_name")
293
+ if not isinstance(server, str) or not server:
294
+ raise ValueError(f"{payload.get('hook_event_name')} requires mcp_server_name")
295
+ elicitation_id = payload.get("elicitation_id")
296
+ if isinstance(elicitation_id, str) and elicitation_id:
297
+ ident = elicitation_id
298
+ identity = "provider_exposed_elicitation_id"
299
+ else:
300
+ ident = _observation_id(payload, timestamp=timestamp, phase="elicitation")
301
+ identity = "hook_observation_without_elicitation_id"
302
+ attrs: dict[str, Any] = {
303
+ "provider": "claude",
304
+ "mcp_server_name": server,
305
+ "identity_semantics": identity,
306
+ }
307
+ mode = payload.get("mode")
308
+ if isinstance(mode, str) and mode:
309
+ attrs["mode"] = mode
310
+ return _entity(
311
+ "mcp_elicitation",
312
+ f"mcp-elicitation:claude:{server}:{ident}",
313
+ name=f"{server} elicitation",
314
+ attributes=attrs,
315
+ )
316
+
317
+
318
+ def claude_official_hook_semantic_events(
319
+ payload: dict[str, Any],
320
+ *,
321
+ timestamp: str | None = None,
322
+ ) -> list[dict[str, Any]]:
323
+ """Project only semantics explicitly exposed by the current Claude Code hook contract."""
324
+
325
+ hook_event = payload.get("hook_event_name")
326
+ if not isinstance(hook_event, str) or not hook_event:
327
+ raise ValueError("Claude hook payload requires hook_event_name")
328
+ if hook_event not in OFFICIAL_CLAUDE_HOOK_EVENTS or hook_event in _ALREADY_PROJECTED_ELSEWHERE:
329
+ return []
330
+
331
+ observed_at = timestamp or _now()
332
+ actor = _actor(payload)
333
+ common = _common(payload)
334
+
335
+ if hook_event == "SessionStart":
336
+ source = payload.get("source")
337
+ if isinstance(source, str) and source:
338
+ common["claude_session_source"] = source
339
+ return [
340
+ _event(
341
+ timestamp=observed_at,
342
+ event_type="semantic.claude.session.started",
343
+ relation="STARTED_PROVIDER_SESSION",
344
+ source=actor,
345
+ target=_session(payload),
346
+ attributes=common,
347
+ )
348
+ ]
349
+
350
+ if hook_event == "SessionEnd":
351
+ reason = payload.get("reason")
352
+ if isinstance(reason, str) and reason:
353
+ common["claude_session_end_reason"] = reason
354
+ return [
355
+ _event(
356
+ timestamp=observed_at,
357
+ event_type="semantic.claude.session.ended",
358
+ relation="OBSERVED_PROVIDER_SESSION_END",
359
+ source=actor,
360
+ target=_session(payload),
361
+ attributes=common,
362
+ )
363
+ ]
364
+
365
+ if hook_event == "Setup":
366
+ trigger = payload.get("trigger")
367
+ if isinstance(trigger, str) and trigger:
368
+ common["setup_trigger"] = trigger
369
+ target = _observation(
370
+ payload,
371
+ timestamp=observed_at,
372
+ phase="setup",
373
+ entity_type="provider_setup",
374
+ name=f"Claude setup {trigger or 'unknown'}",
375
+ )
376
+ return [
377
+ _event(
378
+ timestamp=observed_at,
379
+ event_type="semantic.claude.setup.observed",
380
+ relation="OBSERVED_PROVIDER_SETUP",
381
+ source=actor,
382
+ target=target,
383
+ attributes=common,
384
+ )
385
+ ]
386
+
387
+ if hook_event == "InstructionsLoaded":
388
+ path = payload.get("file_path")
389
+ if not isinstance(path, str) or not path:
390
+ raise ValueError("InstructionsLoaded requires file_path")
391
+ for key in ("memory_type", "load_reason", "trigger_file_path", "parent_file_path"):
392
+ value = payload.get(key)
393
+ if value is not None:
394
+ common[key] = value
395
+ globs = payload.get("globs")
396
+ if isinstance(globs, list):
397
+ common["globs"] = globs
398
+ return [
399
+ _event(
400
+ timestamp=observed_at,
401
+ event_type="semantic.claude.instructions.loaded",
402
+ relation="LOADED_INSTRUCTION_FILE",
403
+ source=actor,
404
+ target=_file(path, instruction=True),
405
+ attributes=common,
406
+ )
407
+ ]
408
+
409
+ if hook_event == "UserPromptExpansion":
410
+ for key in ("expansion_type", "command_name", "command_source"):
411
+ value = payload.get(key)
412
+ if isinstance(value, str) and value:
413
+ common[key] = value
414
+ common["prompt_stored_separately"] = isinstance(payload.get("prompt"), str)
415
+ common["command_args_stored_separately"] = isinstance(payload.get("command_args"), str)
416
+ target = _observation(
417
+ payload,
418
+ timestamp=observed_at,
419
+ phase="prompt_expansion",
420
+ entity_type="prompt_expansion",
421
+ name=str(payload.get("command_name") or "Claude prompt expansion"),
422
+ )
423
+ return [
424
+ _event(
425
+ timestamp=observed_at,
426
+ event_type="semantic.claude.prompt.expansion",
427
+ relation="OBSERVED_PROMPT_EXPANSION",
428
+ source=actor,
429
+ target=target,
430
+ attributes=common,
431
+ )
432
+ ]
433
+
434
+ if hook_event == "PermissionRequest":
435
+ tool_name = payload.get("tool_name")
436
+ if not isinstance(tool_name, str) or not tool_name:
437
+ raise ValueError("PermissionRequest requires tool_name")
438
+ tool_input = payload.get("tool_input")
439
+ common["tool_name"] = tool_name
440
+ if isinstance(tool_input, dict):
441
+ common["tool_input_keys"] = sorted(str(key) for key in tool_input)
442
+ target = _observation(
443
+ payload,
444
+ timestamp=observed_at,
445
+ phase="permission_request",
446
+ entity_type="permission_request",
447
+ name=f"{tool_name} permission request",
448
+ attributes={"identity_semantics": "provider_hook_observation_without_tool_use_id"},
449
+ )
450
+ return [
451
+ _event(
452
+ timestamp=observed_at,
453
+ event_type="semantic.claude.permission.requested",
454
+ relation="OBSERVED_PERMISSION_REQUEST",
455
+ source=actor,
456
+ target=target,
457
+ attributes=common,
458
+ )
459
+ ]
460
+
461
+ if hook_event == "PermissionDenied":
462
+ tool_use_id = payload.get("tool_use_id")
463
+ if not isinstance(tool_use_id, str) or not tool_use_id:
464
+ raise ValueError("PermissionDenied requires tool_use_id")
465
+ common["permission_denial_reason_stored_separately"] = isinstance(payload.get("reason"), str)
466
+ return [
467
+ _event(
468
+ timestamp=observed_at,
469
+ event_type="semantic.claude.permission.denied",
470
+ relation="PERMISSION_DENIED_TOOL_CALL",
471
+ source=actor,
472
+ target=_tool_call(payload),
473
+ attributes=common,
474
+ )
475
+ ]
476
+
477
+ if hook_event == "Notification":
478
+ notification_type = payload.get("notification_type")
479
+ if isinstance(notification_type, str) and notification_type:
480
+ common["notification_type"] = notification_type
481
+ common["message_stored_separately"] = isinstance(payload.get("message"), str)
482
+ common["title_stored_separately"] = isinstance(payload.get("title"), str)
483
+ target = _observation(
484
+ payload,
485
+ timestamp=observed_at,
486
+ phase="notification",
487
+ entity_type="provider_notification",
488
+ name=str(notification_type or "Claude notification"),
489
+ )
490
+ return [
491
+ _event(
492
+ timestamp=observed_at,
493
+ event_type="semantic.claude.notification.observed",
494
+ relation="OBSERVED_NOTIFICATION",
495
+ source=actor,
496
+ target=target,
497
+ attributes=common,
498
+ )
499
+ ]
500
+
501
+ if hook_event in {"TaskCreated", "TaskCompleted"}:
502
+ relation = "CREATED_AGENT_TASK" if hook_event == "TaskCreated" else "COMPLETED_AGENT_TASK"
503
+ stage = "created" if hook_event == "TaskCreated" else "completed"
504
+ common["task_subject_stored_separately"] = isinstance(payload.get("task_subject"), str)
505
+ common["task_description_stored_separately"] = isinstance(payload.get("task_description"), str)
506
+ return [
507
+ _event(
508
+ timestamp=observed_at,
509
+ event_type=f"semantic.claude.task.{stage}",
510
+ relation=relation,
511
+ source=actor,
512
+ target=_task(payload),
513
+ attributes=common,
514
+ )
515
+ ]
516
+
517
+ if hook_event == "Stop":
518
+ common["stop_hook_active"] = bool(payload.get("stop_hook_active", False))
519
+ background_tasks = payload.get("background_tasks")
520
+ session_crons = payload.get("session_crons")
521
+ if isinstance(background_tasks, list):
522
+ common["background_task_count"] = len(background_tasks)
523
+ if isinstance(session_crons, list):
524
+ common["session_cron_count"] = len(session_crons)
525
+ common["last_assistant_message_stored_separately"] = isinstance(
526
+ payload.get("last_assistant_message"), str
527
+ )
528
+ target = _observation(
529
+ payload,
530
+ timestamp=observed_at,
531
+ phase="stop",
532
+ entity_type="agent_turn_stop",
533
+ name="Claude turn stop",
534
+ attributes={
535
+ "completion_semantics": (
536
+ "provider_stop_hook_fired_after_response; hook_can_request_continuation"
537
+ )
538
+ },
539
+ )
540
+ return [
541
+ _event(
542
+ timestamp=observed_at,
543
+ event_type="semantic.claude.turn.stop_observed",
544
+ relation="OBSERVED_TURN_STOP",
545
+ source=actor,
546
+ target=target,
547
+ attributes=common,
548
+ )
549
+ ]
550
+
551
+ if hook_event == "StopFailure":
552
+ error = payload.get("error")
553
+ if isinstance(error, str) and error:
554
+ common["error_type"] = error
555
+ common["error_details_stored_separately"] = isinstance(payload.get("error_details"), str)
556
+ common["rendered_error_stored_separately"] = isinstance(
557
+ payload.get("last_assistant_message"), str
558
+ )
559
+ target = _observation(
560
+ payload,
561
+ timestamp=observed_at,
562
+ phase="stop_failure",
563
+ entity_type="agent_turn_failure",
564
+ name=f"Claude stop failure {error or 'unknown'}",
565
+ attributes={"last_assistant_message_semantics": "rendered_api_error_not_conversational_output"},
566
+ )
567
+ return [
568
+ _event(
569
+ timestamp=observed_at,
570
+ event_type="semantic.claude.turn.failed",
571
+ relation="OBSERVED_TURN_FAILURE",
572
+ source=actor,
573
+ target=target,
574
+ attributes=common,
575
+ )
576
+ ]
577
+
578
+ if hook_event == "TeammateIdle":
579
+ teammate = payload.get("teammate_name")
580
+ if not isinstance(teammate, str) or not teammate:
581
+ raise ValueError("TeammateIdle requires teammate_name")
582
+ target = _observation(
583
+ payload,
584
+ timestamp=observed_at,
585
+ phase="teammate_idle",
586
+ entity_type="teammate_state",
587
+ name=teammate,
588
+ attributes={
589
+ "teammate_name": teammate,
590
+ "teammate_name_is_stable_agent_identity": False,
591
+ "team_name": payload.get("team_name"),
592
+ "team_name_deprecated_by_provider": True,
593
+ },
594
+ )
595
+ return [
596
+ _event(
597
+ timestamp=observed_at,
598
+ event_type="semantic.claude.teammate.idle",
599
+ relation="OBSERVED_TEAMMATE_IDLE",
600
+ source=actor,
601
+ target=target,
602
+ attributes=common,
603
+ )
604
+ ]
605
+
606
+ if hook_event == "ConfigChange":
607
+ source_name = payload.get("source")
608
+ if not isinstance(source_name, str) or not source_name:
609
+ raise ValueError("ConfigChange requires source")
610
+ file_path = payload.get("file_path")
611
+ target = _entity(
612
+ "configuration",
613
+ f"configuration:claude:{source_name}:{file_path or 'unspecified'}",
614
+ name=source_name,
615
+ attributes={
616
+ "provider": "claude",
617
+ "source": source_name,
618
+ "file_path": file_path,
619
+ },
620
+ )
621
+ return [
622
+ _event(
623
+ timestamp=observed_at,
624
+ event_type="semantic.claude.config.changed",
625
+ relation="OBSERVED_CONFIG_CHANGE",
626
+ source=actor,
627
+ target=target,
628
+ attributes=common,
629
+ )
630
+ ]
631
+
632
+ if hook_event == "CwdChanged":
633
+ old_cwd = payload.get("old_cwd")
634
+ new_cwd = payload.get("new_cwd")
635
+ if not isinstance(new_cwd, str) or not new_cwd:
636
+ raise ValueError("CwdChanged requires new_cwd")
637
+ if isinstance(old_cwd, str) and old_cwd:
638
+ common["old_cwd"] = old_cwd
639
+ return [
640
+ _event(
641
+ timestamp=observed_at,
642
+ event_type="semantic.claude.cwd.changed",
643
+ relation="CHANGED_WORKING_DIRECTORY",
644
+ source=actor,
645
+ target=_directory(new_cwd),
646
+ attributes=common,
647
+ )
648
+ ]
649
+
650
+ if hook_event == "DirectoryAdded":
651
+ directory = payload.get("directory")
652
+ if not isinstance(directory, str) or not directory:
653
+ raise ValueError("DirectoryAdded requires directory")
654
+ source_name = payload.get("source")
655
+ if isinstance(source_name, str) and source_name:
656
+ common["directory_add_source"] = source_name
657
+ return [
658
+ _event(
659
+ timestamp=observed_at,
660
+ event_type="semantic.claude.directory.added",
661
+ relation="ADDED_WORKING_DIRECTORY",
662
+ source=actor,
663
+ target=_directory(directory),
664
+ attributes=common,
665
+ )
666
+ ]
667
+
668
+ if hook_event == "FileChanged":
669
+ path = payload.get("file_path")
670
+ if not isinstance(path, str) or not path:
671
+ raise ValueError("FileChanged requires file_path")
672
+ change = payload.get("event")
673
+ if isinstance(change, str) and change:
674
+ common["file_change_event"] = change
675
+ common["default_execweave_hook_enabled"] = False
676
+ return [
677
+ _event(
678
+ timestamp=observed_at,
679
+ event_type="semantic.claude.file.changed",
680
+ relation="OBSERVED_FILE_CHANGE",
681
+ source=actor,
682
+ target=_file(path),
683
+ attributes=common,
684
+ )
685
+ ]
686
+
687
+ if hook_event == "WorktreeCreate":
688
+ # ExecWeave intentionally does not default-enable this event because a
689
+ # configured hook replaces Claude Code's built-in worktree creation.
690
+ return []
691
+
692
+ if hook_event == "WorktreeRemove":
693
+ path = payload.get("worktree_path")
694
+ if not isinstance(path, str) or not path:
695
+ raise ValueError("WorktreeRemove requires worktree_path")
696
+ return [
697
+ _event(
698
+ timestamp=observed_at,
699
+ event_type="semantic.claude.worktree.removed",
700
+ relation="REMOVED_WORKTREE",
701
+ source=actor,
702
+ target=_directory(path, kind="worktree"),
703
+ attributes=common,
704
+ )
705
+ ]
706
+
707
+ if hook_event in {"PreCompact", "PostCompact"}:
708
+ phase = "pre" if hook_event == "PreCompact" else "post"
709
+ trigger = payload.get("trigger")
710
+ if trigger not in {"manual", "auto"}:
711
+ raise ValueError(f"{hook_event} requires trigger manual or auto")
712
+ target = _observation(
713
+ payload,
714
+ timestamp=observed_at,
715
+ phase=f"compaction_{phase}",
716
+ entity_type="context_compaction",
717
+ name=f"Claude compaction {phase}",
718
+ attributes={
719
+ "trigger": trigger,
720
+ "pairing_semantics": "no_pre_post_pairing_asserted_without_provider_compaction_id",
721
+ },
722
+ )
723
+ common.update(
724
+ {
725
+ "compaction_trigger": trigger,
726
+ "compaction_phase": phase,
727
+ "pre_post_pairing_asserted": False,
728
+ }
729
+ )
730
+ if hook_event == "PostCompact":
731
+ common["compact_summary_stored_separately"] = isinstance(
732
+ payload.get("compact_summary"), str
733
+ )
734
+ else:
735
+ common["custom_instructions_stored_separately"] = isinstance(
736
+ payload.get("custom_instructions"), str
737
+ )
738
+ return [
739
+ _event(
740
+ timestamp=observed_at,
741
+ event_type=f"semantic.claude.compaction.{phase}",
742
+ relation="OBSERVED_PRE_COMPACTION" if phase == "pre" else "COMPACTED_CONTEXT",
743
+ source=actor,
744
+ target=target,
745
+ attributes=common,
746
+ )
747
+ ]
748
+
749
+ if hook_event == "Elicitation":
750
+ server = _mcp_server(payload)
751
+ elicitation = _elicitation(payload, timestamp=observed_at)
752
+ common["message_stored_separately"] = isinstance(payload.get("message"), str)
753
+ common["requested_schema_stored_separately"] = isinstance(
754
+ payload.get("requested_schema"), dict
755
+ )
756
+ common["url_stored_separately"] = isinstance(payload.get("url"), str)
757
+ return [
758
+ _event(
759
+ timestamp=observed_at,
760
+ event_type="semantic.claude.mcp.elicitation",
761
+ relation="OBSERVED_MCP_ELICITATION",
762
+ source=server,
763
+ target=elicitation,
764
+ attributes=common,
765
+ )
766
+ ]
767
+
768
+ if hook_event == "ElicitationResult":
769
+ server = _mcp_server(payload)
770
+ elicitation = _elicitation(payload, timestamp=observed_at)
771
+ action = payload.get("action")
772
+ if isinstance(action, str) and action:
773
+ common["elicitation_action"] = action
774
+ common["content_stored_separately"] = "content" in payload
775
+ return [
776
+ _event(
777
+ timestamp=observed_at,
778
+ event_type="semantic.claude.mcp.elicitation_result",
779
+ relation="OBSERVED_MCP_ELICITATION_RESULT",
780
+ source=elicitation,
781
+ target=server,
782
+ attributes=common,
783
+ )
784
+ ]
785
+
786
+ return []
787
+
788
+
789
+ def _store_value(
790
+ store: FullFidelityContentStore,
791
+ value: Any,
792
+ *,
793
+ content_kind: str,
794
+ ) -> ContentReference:
795
+ if isinstance(value, str):
796
+ return store.put_text(value, content_kind=content_kind)
797
+ return store.put_json(value, content_kind=content_kind)
798
+
799
+
800
+ def _content_event(
801
+ *,
802
+ store: FullFidelityContentStore,
803
+ value: Any,
804
+ content_kind: str,
805
+ timestamp: str,
806
+ source: dict[str, Any],
807
+ relation: str,
808
+ observed_field: str,
809
+ ) -> dict[str, Any]:
810
+ reference = _store_value(store, value, content_kind=content_kind)
811
+ return content_observation_event(
812
+ timestamp=timestamp,
813
+ provider="claude",
814
+ source=source,
815
+ reference=reference,
816
+ relation=relation,
817
+ observed_field=observed_field,
818
+ evidence_source="provider_hook",
819
+ attribution="claude_official_hook_contract",
820
+ attributes={
821
+ "claude_hook_event_name": source.get("attributes", {}).get("hook_event_name"),
822
+ "official_hook_contract": True,
823
+ "official_hook_reference": CLAUDE_HOOKS_REFERENCE,
824
+ },
825
+ )
826
+
827
+
828
+ def _content_source(payload: dict[str, Any], *, timestamp: str) -> dict[str, Any]:
829
+ hook_event = payload.get("hook_event_name")
830
+ if hook_event in {"TaskCreated", "TaskCompleted"}:
831
+ return _task(payload)
832
+ if hook_event in {"Elicitation", "ElicitationResult"}:
833
+ return _elicitation(payload, timestamp=timestamp)
834
+ return _actor(payload)
835
+
836
+
837
+ def _extra_content_events(
838
+ payload: dict[str, Any],
839
+ *,
840
+ store: FullFidelityContentStore,
841
+ timestamp: str,
842
+ ) -> list[dict[str, Any]]:
843
+ hook_event = payload.get("hook_event_name")
844
+ if not isinstance(hook_event, str):
845
+ return []
846
+ source = _content_source(payload, timestamp=timestamp)
847
+ specs: dict[str, tuple[str, str]] = {}
848
+
849
+ if hook_event == "UserPromptExpansion":
850
+ specs = {
851
+ "prompt": ("claude.prompt_expansion.original_prompt", "OBSERVED_EXPANSION_PROMPT"),
852
+ "command_args": ("claude.prompt_expansion.command_args", "OBSERVED_EXPANSION_ARGUMENTS"),
853
+ }
854
+ elif hook_event == "PermissionRequest":
855
+ specs = {"tool_input": ("claude.permission.tool_input", "OBSERVED_PERMISSION_TOOL_INPUT")}
856
+ elif hook_event == "PermissionDenied":
857
+ specs = {
858
+ "tool_input": ("claude.permission_denied.tool_input", "OBSERVED_DENIED_TOOL_INPUT"),
859
+ "reason": ("claude.permission_denied.reason", "OBSERVED_PERMISSION_DENIAL_REASON"),
860
+ }
861
+ elif hook_event == "Notification":
862
+ specs = {
863
+ "message": ("claude.notification.message", "OBSERVED_NOTIFICATION_MESSAGE"),
864
+ "title": ("claude.notification.title", "OBSERVED_NOTIFICATION_TITLE"),
865
+ }
866
+ elif hook_event in {"TaskCreated", "TaskCompleted"}:
867
+ specs = {
868
+ "task_subject": ("claude.task.subject", "HAS_TASK_SUBJECT"),
869
+ "task_description": ("claude.task.description", "HAS_TASK_DESCRIPTION"),
870
+ }
871
+ elif hook_event == "Stop":
872
+ specs = {
873
+ "background_tasks": ("claude.stop.background_tasks", "OBSERVED_BACKGROUND_TASKS"),
874
+ "session_crons": ("claude.stop.session_crons", "OBSERVED_SESSION_CRONS"),
875
+ }
876
+ elif hook_event == "PreCompact":
877
+ specs = {
878
+ "custom_instructions": (
879
+ "claude.compaction.custom_instructions",
880
+ "OBSERVED_COMPACTION_INSTRUCTIONS",
881
+ )
882
+ }
883
+ elif hook_event == "PostCompact":
884
+ specs = {
885
+ "compact_summary": ("claude.compaction.summary", "OBSERVED_COMPACTION_SUMMARY")
886
+ }
887
+ elif hook_event == "Elicitation":
888
+ specs = {
889
+ "message": ("claude.elicitation.message", "OBSERVED_ELICITATION_MESSAGE"),
890
+ "requested_schema": ("claude.elicitation.requested_schema", "OBSERVED_ELICITATION_SCHEMA"),
891
+ "url": ("claude.elicitation.url", "OBSERVED_ELICITATION_URL"),
892
+ }
893
+ elif hook_event == "ElicitationResult":
894
+ specs = {"content": ("claude.elicitation.result_content", "OBSERVED_ELICITATION_CONTENT")}
895
+
896
+ events: list[dict[str, Any]] = []
897
+ for field, (content_kind, relation) in specs.items():
898
+ if field not in payload or payload[field] is None:
899
+ continue
900
+ events.append(
901
+ _content_event(
902
+ store=store,
903
+ value=payload[field],
904
+ content_kind=content_kind,
905
+ timestamp=timestamp,
906
+ source=source,
907
+ relation=relation,
908
+ observed_field=field,
909
+ )
910
+ )
911
+ return events
912
+
913
+
914
+ def claude_official_full_fidelity_events(
915
+ payload: dict[str, Any],
916
+ *,
917
+ store: FullFidelityContentStore,
918
+ timestamp: str | None = None,
919
+ ) -> list[dict[str, Any]]:
920
+ """Preserve official Claude hook payloads without duplicating large content in metadata."""
921
+
922
+ hook_event = payload.get("hook_event_name")
923
+ if not isinstance(hook_event, str) or not hook_event:
924
+ raise ValueError("Claude hook payload requires hook_event_name")
925
+ observed_at = timestamp or _now()
926
+
927
+ legacy_payload = dict(payload)
928
+ for field in _EXTRA_CONTENT_FIELDS.get(hook_event, frozenset()):
929
+ legacy_payload.pop(field, None)
930
+
931
+ events = _legacy_content_events(
932
+ legacy_payload,
933
+ store=store,
934
+ timestamp=observed_at,
935
+ )
936
+ events.extend(
937
+ _extra_content_events(
938
+ payload,
939
+ store=store,
940
+ timestamp=observed_at,
941
+ )
942
+ )
943
+ return events