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.
- execweave/__init__.py +3 -0
- execweave/__main__.py +5 -0
- execweave/_conversation_records_core.py +902 -0
- execweave/_dashboard_shell_base.py +148 -0
- execweave/_http_proxy_base.py +565 -0
- execweave/_http_proxy_bounded.py +560 -0
- execweave/_http_proxy_stage.py +509 -0
- execweave/acceptance_output.py +19 -0
- execweave/agent_bootstrap.py +395 -0
- execweave/agent_topology.py +313 -0
- execweave/agent_trace.py +1162 -0
- execweave/agy_preview_sanitize.py +102 -0
- execweave/analysis.py +427 -0
- execweave/anthropic.py +228 -0
- execweave/anthropic_cli.py +171 -0
- execweave/anthropic_full_fidelity.py +385 -0
- execweave/antigravity_adapter.py +112 -0
- execweave/antigravity_adapter_base.py +479 -0
- execweave/antigravity_full_fidelity.py +656 -0
- execweave/antigravity_full_fidelity_base.py +172 -0
- execweave/antigravity_full_fidelity_collaboration_base.py +451 -0
- execweave/antigravity_hook_cli.py +209 -0
- execweave/antigravity_record.py +96 -0
- execweave/antigravity_subagent_linkage.py +449 -0
- execweave/antigravity_trace_capability.py +39 -0
- execweave/auto_specialized.py +547 -0
- execweave/backends.py +102 -0
- execweave/benchmark.py +80 -0
- execweave/claude_adapter.py +517 -0
- execweave/claude_child_transcript.py +314 -0
- execweave/claude_delegation.py +136 -0
- execweave/claude_full_fidelity.py +396 -0
- execweave/claude_hook_cli.py +209 -0
- execweave/claude_hook_contract.py +943 -0
- execweave/claude_model_observer.py +353 -0
- execweave/claude_record.py +106 -0
- execweave/cli.py +629 -0
- execweave/codex_adapter.py +455 -0
- execweave/codex_conversation.py +621 -0
- execweave/codex_full_fidelity.py +287 -0
- execweave/codex_hook_cli.py +301 -0
- execweave/codex_hook_entry.py +207 -0
- execweave/codex_hook_lifecycle.py +363 -0
- execweave/codex_message_diagnostics.py +322 -0
- execweave/codex_message_transport_diagnostics.py +399 -0
- execweave/codex_record.py +199 -0
- execweave/codex_rollout_structures.py +402 -0
- execweave/codex_rollout_trace.py +56 -0
- execweave/codex_rollout_trace_base.py +1509 -0
- execweave/collector.py +768 -0
- execweave/command.py +157 -0
- execweave/command_privacy.py +20 -0
- execweave/content_evidence.py +101 -0
- execweave/content_integrity.py +289 -0
- execweave/content_store.py +273 -0
- execweave/controlled_checks.py +561 -0
- execweave/conversation_archive.py +338 -0
- execweave/conversation_message_identity.py +264 -0
- execweave/conversation_preview.py +66 -0
- execweave/conversation_preview_antigravity.py +32 -0
- execweave/conversation_preview_claude.py +31 -0
- execweave/conversation_preview_codex.py +107 -0
- execweave/conversation_preview_common.py +180 -0
- execweave/conversation_preview_generic.py +188 -0
- execweave/conversation_preview_lines.py +133 -0
- execweave/conversation_preview_transcript.py +121 -0
- execweave/conversation_records.py +349 -0
- execweave/conversation_records_antigravity.py +370 -0
- execweave/conversation_records_codex.py +83 -0
- execweave/conversation_records_common.py +17 -0
- execweave/conversation_records_ollama.py +39 -0
- execweave/correlation.py +818 -0
- execweave/cursor_adapter.py +349 -0
- execweave/cursor_delegation.py +87 -0
- execweave/cursor_delegation_base.py +220 -0
- execweave/cursor_full_fidelity.py +489 -0
- execweave/cursor_hook_cli.py +195 -0
- execweave/cursor_hook_contract.py +439 -0
- execweave/cursor_lifecycle.py +159 -0
- execweave/cursor_record.py +96 -0
- execweave/dashboard_shell.py +283 -0
- execweave/delivery_status.py +94 -0
- execweave/entry.py +98 -0
- execweave/evidence_availability.py +113 -0
- execweave/evidence_grade.py +166 -0
- execweave/fidelity.py +304 -0
- execweave/filesystem.py +327 -0
- execweave/finalization.py +92 -0
- execweave/focus.py +118 -0
- execweave/framework_adapters/__init__.py +34 -0
- execweave/framework_adapters/autogen.py +398 -0
- execweave/framework_adapters/base.py +580 -0
- execweave/framework_adapters/camel.py +270 -0
- execweave/framework_adapters/camel_channel.py +71 -0
- execweave/framework_adapters/metagpt.py +315 -0
- execweave/framework_adapters/metagpt_ollama_compat.py +54 -0
- execweave/framework_adapters/metagpt_recording.py +342 -0
- execweave/framework_adapters/registry.py +90 -0
- execweave/graph.py +590 -0
- execweave/graph_ops.py +472 -0
- execweave/hook_command.py +32 -0
- execweave/hook_delivery.py +32 -0
- execweave/hook_input.py +16 -0
- execweave/http_proxy.py +187 -0
- execweave/http_proxy_cli.py +84 -0
- execweave/inference_gateway.py +476 -0
- execweave/inference_gateway_cli.py +211 -0
- execweave/inference_gateway_full_fidelity.py +613 -0
- execweave/inference_identity.py +76 -0
- execweave/inference_identity_cli.py +60 -0
- execweave/integrity.py +235 -0
- execweave/integrity_cli.py +55 -0
- execweave/investigation_index.py +445 -0
- execweave/litellm_callback.py +211 -0
- execweave/litellm_callback_cli.py +42 -0
- execweave/live.py +445 -0
- execweave/live_core.py +972 -0
- execweave/live_view.py +109 -0
- execweave/live_view_extra_style.py +11 -0
- execweave/live_view_markup.py +29 -0
- execweave/live_view_process_layout.py +650 -0
- execweave/live_view_readability.py +502 -0
- execweave/live_view_script_a.py +59 -0
- execweave/live_view_script_b.py +97 -0
- execweave/live_view_script_c.py +59 -0
- execweave/live_view_script_d.py +40 -0
- execweave/live_view_style.py +34 -0
- execweave/model_runtime.py +560 -0
- execweave/model_runtime_cli.py +265 -0
- execweave/model_runtime_full_fidelity.py +519 -0
- execweave/observation.py +53 -0
- execweave/observation_demo.py +69 -0
- execweave/openai_agents.py +267 -0
- execweave/openai_agents_sdk.py +453 -0
- execweave/openai_compatible.py +239 -0
- execweave/openai_compatible_cli.py +189 -0
- execweave/openai_compatible_full_fidelity.py +438 -0
- execweave/opencode_adapter.py +325 -0
- execweave/opencode_event_contract.py +734 -0
- execweave/opencode_full_fidelity.py +198 -0
- execweave/opencode_hook_cli.py +119 -0
- execweave/opencode_plugin_cli.py +150 -0
- execweave/opencode_record.py +96 -0
- execweave/opencode_task_linkage.py +225 -0
- execweave/overhead_benchmark.py +440 -0
- execweave/privacy.py +84 -0
- execweave/private_io.py +465 -0
- execweave/provider_capability.py +578 -0
- execweave/provider_lifecycle.py +282 -0
- execweave/provider_record.py +290 -0
- execweave/reader_identity.py +13 -0
- execweave/redacted_archive.py +906 -0
- execweave/risk.py +106 -0
- execweave/rule_pack.py +359 -0
- execweave/rule_pack_cli.py +57 -0
- execweave/run_assessment.py +200 -0
- execweave/runtime_endpoint_availability.py +44 -0
- execweave/scalability_benchmark.py +195 -0
- execweave/schema.py +62 -0
- execweave/scope.py +85 -0
- execweave/semantic.py +453 -0
- execweave/session_summary.py +159 -0
- execweave/sink.py +71 -0
- execweave/strace_backend.py +927 -0
- execweave/stream_assembly.py +363 -0
- execweave/task_artifacts.py +192 -0
- execweave/task_validation.py +317 -0
- execweave/theme.py +40 -0
- execweave/top.py +599 -0
- execweave/top_cli.py +150 -0
- execweave/validate.py +196 -0
- execweave/vendor/dagre.min.js +815 -0
- execweave/view_cli.py +49 -0
- execweave/viewer.py +474 -0
- execweave/viewer_agent_panel.py +630 -0
- execweave/viewer_agent_panel_antigravity.py +31 -0
- execweave/viewer_agent_panel_claude.py +9 -0
- execweave/viewer_agent_panel_codex.py +50 -0
- execweave/viewer_agent_panel_cursor.py +9 -0
- execweave/viewer_agent_panel_default.py +79 -0
- execweave/viewer_agent_panel_ollama.py +20 -0
- execweave/viewer_agent_panel_opencode.py +9 -0
- execweave/viewer_agent_panel_registry.py +20 -0
- execweave/viewer_archive_verifier.py +178 -0
- execweave/viewer_background_files.py +86 -0
- execweave/viewer_content_browser.py +307 -0
- execweave/viewer_content_health.py +208 -0
- execweave/viewer_content_inspector.py +309 -0
- execweave/viewer_controlled_checks.py +258 -0
- execweave/viewer_conversation_sync.py +115 -0
- execweave/viewer_dashboard_clean.py +405 -0
- execweave/viewer_dashboard_focus.py +127 -0
- execweave/viewer_dashboard_hardening.py +264 -0
- execweave/viewer_dashboard_hardening_v2.py +62 -0
- execweave/viewer_dashboard_projection.py +261 -0
- execweave/viewer_delivery_status.py +155 -0
- execweave/viewer_edge_decross.py +117 -0
- execweave/viewer_execution_flow.py +611 -0
- execweave/viewer_execution_flow_provider_normalization.py +107 -0
- execweave/viewer_execution_flow_safety.py +349 -0
- execweave/viewer_external_endpoints.py +307 -0
- execweave/viewer_flow_canvas.py +1140 -0
- execweave/viewer_flow_layout.py +922 -0
- execweave/viewer_fold_state.py +31 -0
- execweave/viewer_framework_flow.py +68 -0
- execweave/viewer_framework_model_output.py +133 -0
- execweave/viewer_gif.py +278 -0
- execweave/viewer_history_browser.py +225 -0
- execweave/viewer_investigation.py +268 -0
- execweave/viewer_layout_geometry.py +192 -0
- execweave/viewer_layout_v2.py +429 -0
- execweave/viewer_layout_v2_detached.py +25 -0
- execweave/viewer_limits.py +93 -0
- execweave/viewer_live_layout.py +61 -0
- execweave/viewer_message_handoffs.py +114 -0
- execweave/viewer_projection.py +488 -0
- execweave/viewer_projection_base.py +522 -0
- execweave/viewer_projection_bridges.py +214 -0
- execweave/viewer_recorded_sources.py +146 -0
- execweave/viewer_run_assessment.py +274 -0
- execweave/viewer_run_guide.py +175 -0
- execweave/viewer_runtime_evidence.py +258 -0
- execweave/viewer_semantic_projection.py +641 -0
- execweave/viewer_session_flow.py +491 -0
- execweave/viewer_structure_share.py +132 -0
- execweave/viewer_task_validation.py +241 -0
- execweave/viewer_tool_mirror_identity.py +75 -0
- execweave/viewer_workflow_mode.py +127 -0
- execweave/workflow.py +183 -0
- execweave-1.0.0.dist-info/METADATA +462 -0
- execweave-1.0.0.dist-info/RECORD +234 -0
- execweave-1.0.0.dist-info/WHEEL +4 -0
- execweave-1.0.0.dist-info/entry_points.txt +30 -0
- execweave-1.0.0.dist-info/licenses/LICENSE +16 -0
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import datetime, timezone
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from .content_evidence import content_observation_event, filter_transport_credentials
|
|
7
|
+
from .content_store import ContentReference, FullFidelityContentStore
|
|
8
|
+
from .agent_topology import EVIDENCE_SUBAGENT_LIFECYCLE_HOOK, subagent_topology
|
|
9
|
+
|
|
10
|
+
_CONTENT_FIELDS = frozenset(
|
|
11
|
+
{
|
|
12
|
+
"prompt",
|
|
13
|
+
"delta",
|
|
14
|
+
"tool_input",
|
|
15
|
+
"tool_response",
|
|
16
|
+
"tool_calls",
|
|
17
|
+
"error",
|
|
18
|
+
"error_details",
|
|
19
|
+
"last_assistant_message",
|
|
20
|
+
}
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _now() -> str:
|
|
25
|
+
return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _entity(
|
|
29
|
+
entity_type: str,
|
|
30
|
+
entity_id: str,
|
|
31
|
+
*,
|
|
32
|
+
name: str | None = None,
|
|
33
|
+
attributes: dict[str, Any] | None = None,
|
|
34
|
+
) -> dict[str, Any]:
|
|
35
|
+
return {
|
|
36
|
+
"type": entity_type,
|
|
37
|
+
"id": entity_id,
|
|
38
|
+
"name": name,
|
|
39
|
+
"attributes": attributes or {},
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _main_agent() -> dict[str, Any]:
|
|
44
|
+
return _entity("agent", "agent:Claude Code", name="Claude Code")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _subagent(payload: dict[str, Any]) -> dict[str, Any]:
|
|
48
|
+
session_id = payload.get("session_id")
|
|
49
|
+
agent_id = payload.get("agent_id")
|
|
50
|
+
session = session_id if isinstance(session_id, str) and session_id else "unknown"
|
|
51
|
+
agent = agent_id if isinstance(agent_id, str) and agent_id else "unknown"
|
|
52
|
+
agent_type = payload.get("agent_type")
|
|
53
|
+
name = agent_type if isinstance(agent_type, str) and agent_type else "Claude subagent"
|
|
54
|
+
return _entity(
|
|
55
|
+
"agent",
|
|
56
|
+
f"agent:claude:{session}:subagent:{agent}",
|
|
57
|
+
name=name,
|
|
58
|
+
attributes={
|
|
59
|
+
"provider": "claude",
|
|
60
|
+
"agent_id": agent,
|
|
61
|
+
"agent_type": name,
|
|
62
|
+
**subagent_topology(
|
|
63
|
+
evidence=EVIDENCE_SUBAGENT_LIFECYCLE_HOOK,
|
|
64
|
+
parent_scope_id=session,
|
|
65
|
+
),
|
|
66
|
+
},
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _tool_call(payload: dict[str, Any], *, tool_use_id: object = None, tool_name: object = None) -> dict[str, Any]:
|
|
71
|
+
session_id = payload.get("session_id")
|
|
72
|
+
resolved_use_id = tool_use_id if tool_use_id is not None else payload.get("tool_use_id")
|
|
73
|
+
resolved_name = tool_name if tool_name is not None else payload.get("tool_name")
|
|
74
|
+
session = session_id if isinstance(session_id, str) and session_id else "unknown"
|
|
75
|
+
use_id = resolved_use_id if isinstance(resolved_use_id, str) and resolved_use_id else "unknown"
|
|
76
|
+
name = resolved_name if isinstance(resolved_name, str) and resolved_name else "unknown"
|
|
77
|
+
return _entity(
|
|
78
|
+
"tool_call",
|
|
79
|
+
f"tool-call:claude:{session}:{use_id}",
|
|
80
|
+
name=name,
|
|
81
|
+
attributes={"provider": "claude", "tool_name": name, "tool_use_id": use_id},
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _store_value(
|
|
86
|
+
store: FullFidelityContentStore,
|
|
87
|
+
value: Any,
|
|
88
|
+
*,
|
|
89
|
+
content_kind: str,
|
|
90
|
+
) -> ContentReference:
|
|
91
|
+
if isinstance(value, str):
|
|
92
|
+
return store.put_text(value, content_kind=content_kind)
|
|
93
|
+
return store.put_json(value, content_kind=content_kind)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _content_event(
|
|
97
|
+
*,
|
|
98
|
+
store: FullFidelityContentStore,
|
|
99
|
+
value: Any,
|
|
100
|
+
content_kind: str,
|
|
101
|
+
timestamp: str,
|
|
102
|
+
source: dict[str, Any],
|
|
103
|
+
relation: str,
|
|
104
|
+
observed_field: str,
|
|
105
|
+
hook_event: str,
|
|
106
|
+
attributes: dict[str, Any] | None = None,
|
|
107
|
+
) -> dict[str, Any]:
|
|
108
|
+
reference = _store_value(store, value, content_kind=content_kind)
|
|
109
|
+
merged = {"claude_hook_event_name": hook_event}
|
|
110
|
+
if attributes:
|
|
111
|
+
merged.update(attributes)
|
|
112
|
+
return content_observation_event(
|
|
113
|
+
timestamp=timestamp,
|
|
114
|
+
provider="claude",
|
|
115
|
+
source=source,
|
|
116
|
+
reference=reference,
|
|
117
|
+
relation=relation,
|
|
118
|
+
observed_field=observed_field,
|
|
119
|
+
evidence_source="provider_hook",
|
|
120
|
+
attribution="claude_hook",
|
|
121
|
+
attributes=merged,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _metadata_event(
|
|
126
|
+
payload: dict[str, Any],
|
|
127
|
+
*,
|
|
128
|
+
store: FullFidelityContentStore,
|
|
129
|
+
timestamp: str,
|
|
130
|
+
hook_event: str,
|
|
131
|
+
) -> dict[str, Any] | None:
|
|
132
|
+
metadata = {key: value for key, value in payload.items() if key not in _CONTENT_FIELDS}
|
|
133
|
+
filtered, removed = filter_transport_credentials(metadata)
|
|
134
|
+
if not filtered:
|
|
135
|
+
return None
|
|
136
|
+
reference = store.put_json(filtered, content_kind="claude.provider_hook_metadata")
|
|
137
|
+
return content_observation_event(
|
|
138
|
+
timestamp=timestamp,
|
|
139
|
+
provider="claude",
|
|
140
|
+
source=_main_agent(),
|
|
141
|
+
reference=reference,
|
|
142
|
+
relation="OBSERVED_PROVIDER_METADATA",
|
|
143
|
+
observed_field="hook_metadata",
|
|
144
|
+
evidence_source="provider_hook",
|
|
145
|
+
attribution="claude_hook",
|
|
146
|
+
attributes={
|
|
147
|
+
"claude_hook_event_name": hook_event,
|
|
148
|
+
"transport_credentials_excluded": removed,
|
|
149
|
+
},
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _tool_content_events(
|
|
154
|
+
payload: dict[str, Any],
|
|
155
|
+
*,
|
|
156
|
+
store: FullFidelityContentStore,
|
|
157
|
+
timestamp: str,
|
|
158
|
+
hook_event: str,
|
|
159
|
+
) -> list[dict[str, Any]]:
|
|
160
|
+
call = _tool_call(payload)
|
|
161
|
+
events: list[dict[str, Any]] = []
|
|
162
|
+
if "tool_input" in payload:
|
|
163
|
+
events.append(
|
|
164
|
+
_content_event(
|
|
165
|
+
store=store,
|
|
166
|
+
value=payload["tool_input"],
|
|
167
|
+
content_kind="claude.tool_input",
|
|
168
|
+
timestamp=timestamp,
|
|
169
|
+
source=call,
|
|
170
|
+
relation="HAS_TOOL_INPUT",
|
|
171
|
+
observed_field="tool_input",
|
|
172
|
+
hook_event=hook_event,
|
|
173
|
+
)
|
|
174
|
+
)
|
|
175
|
+
if hook_event == "PostToolUse" and "tool_response" in payload:
|
|
176
|
+
events.append(
|
|
177
|
+
_content_event(
|
|
178
|
+
store=store,
|
|
179
|
+
value=payload["tool_response"],
|
|
180
|
+
content_kind="claude.tool_response_structured",
|
|
181
|
+
timestamp=timestamp,
|
|
182
|
+
source=call,
|
|
183
|
+
relation="HAS_TOOL_OUTPUT",
|
|
184
|
+
observed_field="tool_response",
|
|
185
|
+
hook_event=hook_event,
|
|
186
|
+
attributes={"model_visible_serialization": False},
|
|
187
|
+
)
|
|
188
|
+
)
|
|
189
|
+
if hook_event == "PostToolUseFailure" and isinstance(payload.get("error"), str):
|
|
190
|
+
events.append(
|
|
191
|
+
_content_event(
|
|
192
|
+
store=store,
|
|
193
|
+
value=payload["error"],
|
|
194
|
+
content_kind="claude.tool_error",
|
|
195
|
+
timestamp=timestamp,
|
|
196
|
+
source=call,
|
|
197
|
+
relation="HAS_TOOL_ERROR",
|
|
198
|
+
observed_field="error",
|
|
199
|
+
hook_event=hook_event,
|
|
200
|
+
)
|
|
201
|
+
)
|
|
202
|
+
return events
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def _batch_events(
|
|
206
|
+
payload: dict[str, Any],
|
|
207
|
+
*,
|
|
208
|
+
store: FullFidelityContentStore,
|
|
209
|
+
timestamp: str,
|
|
210
|
+
) -> list[dict[str, Any]]:
|
|
211
|
+
tool_calls = payload.get("tool_calls")
|
|
212
|
+
if not isinstance(tool_calls, list):
|
|
213
|
+
return []
|
|
214
|
+
events = [
|
|
215
|
+
_content_event(
|
|
216
|
+
store=store,
|
|
217
|
+
value=tool_calls,
|
|
218
|
+
content_kind="claude.tool_batch",
|
|
219
|
+
timestamp=timestamp,
|
|
220
|
+
source=_main_agent(),
|
|
221
|
+
relation="OBSERVED_TOOL_BATCH",
|
|
222
|
+
observed_field="tool_calls",
|
|
223
|
+
hook_event="PostToolBatch",
|
|
224
|
+
)
|
|
225
|
+
]
|
|
226
|
+
for index, item in enumerate(tool_calls):
|
|
227
|
+
if not isinstance(item, dict):
|
|
228
|
+
continue
|
|
229
|
+
call = _tool_call(
|
|
230
|
+
payload,
|
|
231
|
+
tool_use_id=item.get("tool_use_id"),
|
|
232
|
+
tool_name=item.get("tool_name"),
|
|
233
|
+
)
|
|
234
|
+
common = {"tool_batch_index": index}
|
|
235
|
+
if "tool_input" in item:
|
|
236
|
+
events.append(
|
|
237
|
+
_content_event(
|
|
238
|
+
store=store,
|
|
239
|
+
value=item["tool_input"],
|
|
240
|
+
content_kind="claude.tool_input",
|
|
241
|
+
timestamp=timestamp,
|
|
242
|
+
source=call,
|
|
243
|
+
relation="HAS_TOOL_INPUT",
|
|
244
|
+
observed_field="tool_calls[].tool_input",
|
|
245
|
+
hook_event="PostToolBatch",
|
|
246
|
+
attributes=common,
|
|
247
|
+
)
|
|
248
|
+
)
|
|
249
|
+
if "tool_response" in item:
|
|
250
|
+
events.append(
|
|
251
|
+
_content_event(
|
|
252
|
+
store=store,
|
|
253
|
+
value=item["tool_response"],
|
|
254
|
+
content_kind="claude.tool_result_model_visible",
|
|
255
|
+
timestamp=timestamp,
|
|
256
|
+
source=call,
|
|
257
|
+
relation="MODEL_RECEIVED_TOOL_RESULT",
|
|
258
|
+
observed_field="tool_calls[].tool_response",
|
|
259
|
+
hook_event="PostToolBatch",
|
|
260
|
+
attributes={**common, "model_visible_serialization": True},
|
|
261
|
+
)
|
|
262
|
+
)
|
|
263
|
+
return events
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def claude_hook_to_content_events(
|
|
267
|
+
payload: dict[str, Any],
|
|
268
|
+
*,
|
|
269
|
+
store: FullFidelityContentStore,
|
|
270
|
+
timestamp: str | None = None,
|
|
271
|
+
) -> list[dict[str, Any]]:
|
|
272
|
+
"""Persist complete values exposed by documented Claude Code hooks.
|
|
273
|
+
|
|
274
|
+
This records what the provider hook exposes. It does not claim access to hidden
|
|
275
|
+
prompts, internal reasoning, or provider-side stages that are absent from the hook.
|
|
276
|
+
"""
|
|
277
|
+
|
|
278
|
+
hook_event = payload.get("hook_event_name")
|
|
279
|
+
if not isinstance(hook_event, str) or not hook_event:
|
|
280
|
+
raise ValueError("Claude hook payload requires hook_event_name")
|
|
281
|
+
observed_at = timestamp or _now()
|
|
282
|
+
events: list[dict[str, Any]] = []
|
|
283
|
+
|
|
284
|
+
metadata_event = _metadata_event(
|
|
285
|
+
payload,
|
|
286
|
+
store=store,
|
|
287
|
+
timestamp=observed_at,
|
|
288
|
+
hook_event=hook_event,
|
|
289
|
+
)
|
|
290
|
+
if metadata_event is not None:
|
|
291
|
+
events.append(metadata_event)
|
|
292
|
+
|
|
293
|
+
if hook_event == "UserPromptSubmit" and isinstance(payload.get("prompt"), str):
|
|
294
|
+
events.append(
|
|
295
|
+
_content_event(
|
|
296
|
+
store=store,
|
|
297
|
+
value=payload["prompt"],
|
|
298
|
+
content_kind="claude.user_prompt",
|
|
299
|
+
timestamp=observed_at,
|
|
300
|
+
source=_main_agent(),
|
|
301
|
+
relation="RECEIVED_USER_PROMPT",
|
|
302
|
+
observed_field="prompt",
|
|
303
|
+
hook_event=hook_event,
|
|
304
|
+
)
|
|
305
|
+
)
|
|
306
|
+
elif hook_event == "MessageDisplay" and isinstance(payload.get("delta"), str):
|
|
307
|
+
display_attrs = {
|
|
308
|
+
key: payload[key]
|
|
309
|
+
for key in ("turn_id", "message_id", "index", "final")
|
|
310
|
+
if key in payload
|
|
311
|
+
}
|
|
312
|
+
events.append(
|
|
313
|
+
_content_event(
|
|
314
|
+
store=store,
|
|
315
|
+
value=payload["delta"],
|
|
316
|
+
content_kind="claude.assistant_display_delta",
|
|
317
|
+
timestamp=observed_at,
|
|
318
|
+
source=_main_agent(),
|
|
319
|
+
relation="DISPLAYED_ASSISTANT_TEXT",
|
|
320
|
+
observed_field="delta",
|
|
321
|
+
hook_event=hook_event,
|
|
322
|
+
attributes=display_attrs,
|
|
323
|
+
)
|
|
324
|
+
)
|
|
325
|
+
elif hook_event in {"PreToolUse", "PostToolUse", "PostToolUseFailure"}:
|
|
326
|
+
events.extend(
|
|
327
|
+
_tool_content_events(
|
|
328
|
+
payload,
|
|
329
|
+
store=store,
|
|
330
|
+
timestamp=observed_at,
|
|
331
|
+
hook_event=hook_event,
|
|
332
|
+
)
|
|
333
|
+
)
|
|
334
|
+
elif hook_event == "PostToolBatch":
|
|
335
|
+
events.extend(_batch_events(payload, store=store, timestamp=observed_at))
|
|
336
|
+
elif hook_event in {"Stop", "SubagentStop"} and isinstance(
|
|
337
|
+
payload.get("last_assistant_message"), str
|
|
338
|
+
):
|
|
339
|
+
source = _subagent(payload) if hook_event == "SubagentStop" else _main_agent()
|
|
340
|
+
events.append(
|
|
341
|
+
_content_event(
|
|
342
|
+
store=store,
|
|
343
|
+
value=payload["last_assistant_message"],
|
|
344
|
+
content_kind=(
|
|
345
|
+
"claude.subagent_final_response"
|
|
346
|
+
if hook_event == "SubagentStop"
|
|
347
|
+
else "claude.assistant_final_response"
|
|
348
|
+
),
|
|
349
|
+
timestamp=observed_at,
|
|
350
|
+
source=source,
|
|
351
|
+
relation="PRODUCED_ASSISTANT_RESPONSE",
|
|
352
|
+
observed_field="last_assistant_message",
|
|
353
|
+
hook_event=hook_event,
|
|
354
|
+
)
|
|
355
|
+
)
|
|
356
|
+
elif hook_event == "StopFailure":
|
|
357
|
+
if isinstance(payload.get("error"), str):
|
|
358
|
+
events.append(
|
|
359
|
+
_content_event(
|
|
360
|
+
store=store,
|
|
361
|
+
value=payload["error"],
|
|
362
|
+
content_kind="claude.stop_failure_type",
|
|
363
|
+
timestamp=observed_at,
|
|
364
|
+
source=_main_agent(),
|
|
365
|
+
relation="HAS_STOP_FAILURE",
|
|
366
|
+
observed_field="error",
|
|
367
|
+
hook_event=hook_event,
|
|
368
|
+
)
|
|
369
|
+
)
|
|
370
|
+
if isinstance(payload.get("error_details"), str):
|
|
371
|
+
events.append(
|
|
372
|
+
_content_event(
|
|
373
|
+
store=store,
|
|
374
|
+
value=payload["error_details"],
|
|
375
|
+
content_kind="claude.stop_failure_details",
|
|
376
|
+
timestamp=observed_at,
|
|
377
|
+
source=_main_agent(),
|
|
378
|
+
relation="HAS_STOP_FAILURE_DETAILS",
|
|
379
|
+
observed_field="error_details",
|
|
380
|
+
hook_event=hook_event,
|
|
381
|
+
)
|
|
382
|
+
)
|
|
383
|
+
if isinstance(payload.get("last_assistant_message"), str):
|
|
384
|
+
events.append(
|
|
385
|
+
_content_event(
|
|
386
|
+
store=store,
|
|
387
|
+
value=payload["last_assistant_message"],
|
|
388
|
+
content_kind="claude.stop_failure_message",
|
|
389
|
+
timestamp=observed_at,
|
|
390
|
+
source=_main_agent(),
|
|
391
|
+
relation="DISPLAYED_STOP_FAILURE",
|
|
392
|
+
observed_field="last_assistant_message",
|
|
393
|
+
hook_event=hook_event,
|
|
394
|
+
)
|
|
395
|
+
)
|
|
396
|
+
return events
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
from datetime import datetime, timezone
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from .agent_trace import provider_agent_trace_visibility_event
|
|
12
|
+
from .claude_adapter import append_semantic_records, claude_hook_to_semantic_events, read_hook_payload
|
|
13
|
+
from .claude_delegation import claude_delegation_events
|
|
14
|
+
from .claude_child_transcript import claude_child_transcript_semantic_events
|
|
15
|
+
from .claude_hook_contract import (
|
|
16
|
+
PASSIVE_CLAUDE_HOOK_EVENTS,
|
|
17
|
+
claude_official_full_fidelity_events,
|
|
18
|
+
claude_official_hook_semantic_events,
|
|
19
|
+
)
|
|
20
|
+
from .claude_model_observer import append_claude_transcript_model_events
|
|
21
|
+
from .content_store import FullFidelityContentStore
|
|
22
|
+
from .conversation_archive import claude_conversation_archive_events
|
|
23
|
+
from .private_io import private_artifact_path
|
|
24
|
+
from .privacy import full_content_capture_enabled
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _hook_handler(command: str) -> dict[str, str]:
|
|
28
|
+
return {"type": "command", "command": command}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _now() -> str:
|
|
32
|
+
return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
_MATCH_ALL_EVENTS = frozenset(
|
|
36
|
+
{
|
|
37
|
+
"PreToolUse",
|
|
38
|
+
"PermissionRequest",
|
|
39
|
+
"PostToolUse",
|
|
40
|
+
"PostToolUseFailure",
|
|
41
|
+
"PermissionDenied",
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def claude_hook_config(command: str = "execweave-claude-hook") -> dict[str, Any]:
|
|
47
|
+
"""Return a passive Claude Code observer config grounded in the official hook contract.
|
|
48
|
+
|
|
49
|
+
WorktreeCreate is intentionally excluded because configuring it replaces Claude
|
|
50
|
+
Code's default worktree creation. FileChanged is excluded because its matcher
|
|
51
|
+
defines the literal file watch list and therefore cannot be enabled generically.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
handler = _hook_handler(command)
|
|
55
|
+
tool_group = {"matcher": "*", "hooks": [handler]}
|
|
56
|
+
plain_group = {"hooks": [handler]}
|
|
57
|
+
hooks: dict[str, Any] = {}
|
|
58
|
+
for event in sorted(PASSIVE_CLAUDE_HOOK_EVENTS):
|
|
59
|
+
hooks[event] = [tool_group if event in _MATCH_ALL_EVENTS else plain_group]
|
|
60
|
+
if set(hooks) != set(PASSIVE_CLAUDE_HOOK_EVENTS):
|
|
61
|
+
raise RuntimeError("Claude hook config drifted from the passive official event set")
|
|
62
|
+
return {"hooks": hooks}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _default_sidecar(payload: dict[str, Any]) -> Path:
|
|
66
|
+
cwd = payload.get("cwd")
|
|
67
|
+
session_id = payload.get("session_id")
|
|
68
|
+
if not isinstance(cwd, str) or not cwd:
|
|
69
|
+
raise ValueError("Claude hook payload has no cwd for automatic sidecar placement")
|
|
70
|
+
if not isinstance(session_id, str) or not session_id:
|
|
71
|
+
raise ValueError("Claude hook payload has no session_id for automatic sidecar placement")
|
|
72
|
+
safe_session = "".join(
|
|
73
|
+
character if character.isalnum() or character in {"-", "_", "."} else "_"
|
|
74
|
+
for character in session_id
|
|
75
|
+
)
|
|
76
|
+
return Path(cwd) / ".execweave" / "semantic" / "claude" / f"{safe_session}.jsonl"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _restore_official_hook_event_name(
|
|
80
|
+
records: list[dict[str, Any]],
|
|
81
|
+
payload: dict[str, Any],
|
|
82
|
+
) -> None:
|
|
83
|
+
"""Keep persisted official content evidence tied to the exact hook event that emitted it."""
|
|
84
|
+
|
|
85
|
+
hook_event = payload.get("hook_event_name")
|
|
86
|
+
if not isinstance(hook_event, str) or not hook_event:
|
|
87
|
+
return
|
|
88
|
+
for record in records:
|
|
89
|
+
attributes = record.get("attributes")
|
|
90
|
+
if not isinstance(attributes, dict):
|
|
91
|
+
continue
|
|
92
|
+
if attributes.get("attribution") != "claude_official_hook_contract":
|
|
93
|
+
continue
|
|
94
|
+
if attributes.get("claude_hook_event_name") in (None, ""):
|
|
95
|
+
attributes["claude_hook_event_name"] = hook_event
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
99
|
+
parser = argparse.ArgumentParser(
|
|
100
|
+
prog="execweave-claude-hook",
|
|
101
|
+
description="Capture Claude Code hook input as local ExecWeave semantic telemetry.",
|
|
102
|
+
)
|
|
103
|
+
parser.add_argument(
|
|
104
|
+
"--sidecar",
|
|
105
|
+
type=Path,
|
|
106
|
+
default=None,
|
|
107
|
+
help=(
|
|
108
|
+
"Semantic JSONL output path. Defaults to EXECWEAVE_SEMANTIC_SIDECAR, then "
|
|
109
|
+
"<cwd>/.execweave/semantic/claude/<Claude-session-id>.jsonl."
|
|
110
|
+
),
|
|
111
|
+
)
|
|
112
|
+
parser.add_argument(
|
|
113
|
+
"--strict",
|
|
114
|
+
action="store_true",
|
|
115
|
+
help="Return non-zero on telemetry errors. Default is fail-open so tracing cannot block Claude.",
|
|
116
|
+
)
|
|
117
|
+
parser.add_argument("--auto", action="store_true", help=argparse.SUPPRESS)
|
|
118
|
+
parser.add_argument(
|
|
119
|
+
"--print-config",
|
|
120
|
+
action="store_true",
|
|
121
|
+
help="Print a passive Claude Code settings fragment grounded in the official hook contract.",
|
|
122
|
+
)
|
|
123
|
+
parser.add_argument(
|
|
124
|
+
"--command",
|
|
125
|
+
default="execweave-claude-hook",
|
|
126
|
+
help="Hook command embedded by --print-config (default: execweave-claude-hook).",
|
|
127
|
+
)
|
|
128
|
+
return parser
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def main(argv: list[str] | None = None) -> int:
|
|
132
|
+
parser = build_parser()
|
|
133
|
+
args = parser.parse_args(argv)
|
|
134
|
+
if args.print_config:
|
|
135
|
+
print(json.dumps(claude_hook_config(args.command), indent=2, sort_keys=True))
|
|
136
|
+
return 0
|
|
137
|
+
if args.auto and not os.environ.get("EXECWEAVE_SEMANTIC_SIDECAR"):
|
|
138
|
+
return 0
|
|
139
|
+
|
|
140
|
+
try:
|
|
141
|
+
payload = read_hook_payload()
|
|
142
|
+
sidecar = args.sidecar
|
|
143
|
+
if sidecar is None:
|
|
144
|
+
configured = os.environ.get("EXECWEAVE_SEMANTIC_SIDECAR")
|
|
145
|
+
sidecar = Path(configured) if configured else _default_sidecar(payload)
|
|
146
|
+
sidecar = private_artifact_path(sidecar)
|
|
147
|
+
observed_at = _now()
|
|
148
|
+
records = claude_hook_to_semantic_events(payload, timestamp=observed_at)
|
|
149
|
+
records.extend(
|
|
150
|
+
claude_official_hook_semantic_events(
|
|
151
|
+
payload,
|
|
152
|
+
timestamp=observed_at,
|
|
153
|
+
)
|
|
154
|
+
)
|
|
155
|
+
if payload.get("hook_event_name") == "SessionStart":
|
|
156
|
+
records.append(
|
|
157
|
+
provider_agent_trace_visibility_event(
|
|
158
|
+
"claude",
|
|
159
|
+
timestamp=observed_at,
|
|
160
|
+
attribution="claude_hook",
|
|
161
|
+
evidence_source="provider_hook",
|
|
162
|
+
)
|
|
163
|
+
)
|
|
164
|
+
if not full_content_capture_enabled():
|
|
165
|
+
append_semantic_records(sidecar, records)
|
|
166
|
+
return 0
|
|
167
|
+
content_store = FullFidelityContentStore(sidecar.parent)
|
|
168
|
+
content_records = claude_official_full_fidelity_events(
|
|
169
|
+
payload,
|
|
170
|
+
store=content_store,
|
|
171
|
+
timestamp=observed_at,
|
|
172
|
+
)
|
|
173
|
+
_restore_official_hook_event_name(content_records, payload)
|
|
174
|
+
content_records.extend(
|
|
175
|
+
claude_conversation_archive_events(
|
|
176
|
+
payload,
|
|
177
|
+
store=content_store,
|
|
178
|
+
timestamp=observed_at,
|
|
179
|
+
)
|
|
180
|
+
)
|
|
181
|
+
records.extend(content_records)
|
|
182
|
+
records.extend(
|
|
183
|
+
claude_delegation_events(
|
|
184
|
+
payload,
|
|
185
|
+
content_events=content_records,
|
|
186
|
+
timestamp=observed_at,
|
|
187
|
+
)
|
|
188
|
+
)
|
|
189
|
+
records.extend(
|
|
190
|
+
claude_child_transcript_semantic_events(
|
|
191
|
+
payload,
|
|
192
|
+
timestamp=observed_at,
|
|
193
|
+
sidecar=sidecar,
|
|
194
|
+
)
|
|
195
|
+
)
|
|
196
|
+
append_semantic_records(sidecar, records)
|
|
197
|
+
append_claude_transcript_model_events(
|
|
198
|
+
payload,
|
|
199
|
+
sidecar=sidecar,
|
|
200
|
+
timestamp=observed_at,
|
|
201
|
+
)
|
|
202
|
+
except (OSError, RuntimeError, TimeoutError, TypeError, ValueError) as exc:
|
|
203
|
+
print(f"ExecWeave Claude hook warning: {exc}", file=sys.stderr)
|
|
204
|
+
return 1 if args.strict else 0
|
|
205
|
+
return 0
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
if __name__ == "__main__":
|
|
209
|
+
raise SystemExit(main())
|