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,489 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
5
|
+
from datetime import datetime, timezone
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from .content_evidence import content_observation_event, filter_transport_credentials
|
|
10
|
+
from .content_store import FullFidelityContentStore
|
|
11
|
+
from .agent_topology import EVIDENCE_SUBAGENT_LIFECYCLE_HOOK, subagent_topology
|
|
12
|
+
|
|
13
|
+
_CONTENT_FIELDS = frozenset(
|
|
14
|
+
{
|
|
15
|
+
"prompt",
|
|
16
|
+
"text",
|
|
17
|
+
"task",
|
|
18
|
+
"summary",
|
|
19
|
+
"description",
|
|
20
|
+
"agent_message",
|
|
21
|
+
"tool_input",
|
|
22
|
+
"tool_output",
|
|
23
|
+
"error_message",
|
|
24
|
+
"content",
|
|
25
|
+
"edits",
|
|
26
|
+
"command",
|
|
27
|
+
"output",
|
|
28
|
+
"result_json",
|
|
29
|
+
}
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _now() -> str:
|
|
34
|
+
return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _entity(kind: str, ident: str, name: str, **attrs: Any) -> dict[str, Any]:
|
|
38
|
+
return {"type": kind, "id": ident, "name": name, "attributes": attrs}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _agent() -> dict[str, Any]:
|
|
42
|
+
return _entity("agent", "agent:Cursor", "Cursor", provider="cursor")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _scope(payload: dict[str, Any]) -> str:
|
|
46
|
+
for key in ("conversation_id", "session_id", "generation_id"):
|
|
47
|
+
value = payload.get(key)
|
|
48
|
+
if isinstance(value, str) and value:
|
|
49
|
+
return value
|
|
50
|
+
return "unknown"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _provider_session(payload: dict[str, Any]) -> dict[str, Any]:
|
|
54
|
+
session_id = payload.get("session_id")
|
|
55
|
+
if not isinstance(session_id, str) or not session_id:
|
|
56
|
+
raise ValueError("Cursor session hook requires session_id")
|
|
57
|
+
return _entity(
|
|
58
|
+
"provider_session",
|
|
59
|
+
f"provider-session:cursor:{session_id}",
|
|
60
|
+
session_id,
|
|
61
|
+
provider="cursor",
|
|
62
|
+
session_id=session_id,
|
|
63
|
+
identity_semantics="provider_session_id",
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _tool_call(payload: dict[str, Any], hook: str) -> dict[str, Any]:
|
|
68
|
+
name = (
|
|
69
|
+
payload.get("tool_name")
|
|
70
|
+
if isinstance(payload.get("tool_name"), str)
|
|
71
|
+
else "unknown"
|
|
72
|
+
)
|
|
73
|
+
use_id = payload.get("tool_use_id")
|
|
74
|
+
if isinstance(use_id, str) and use_id:
|
|
75
|
+
return _entity(
|
|
76
|
+
"tool_call",
|
|
77
|
+
f"tool-call:cursor:{_scope(payload)}:{use_id}",
|
|
78
|
+
name,
|
|
79
|
+
provider="cursor",
|
|
80
|
+
tool_name=name,
|
|
81
|
+
tool_use_id=use_id,
|
|
82
|
+
identity_semantics="provider_tool_use_id",
|
|
83
|
+
)
|
|
84
|
+
raw = json.dumps(
|
|
85
|
+
[
|
|
86
|
+
hook,
|
|
87
|
+
_scope(payload),
|
|
88
|
+
name,
|
|
89
|
+
payload.get("generation_id"),
|
|
90
|
+
payload.get("tool_input"),
|
|
91
|
+
],
|
|
92
|
+
ensure_ascii=False,
|
|
93
|
+
sort_keys=True,
|
|
94
|
+
default=str,
|
|
95
|
+
)
|
|
96
|
+
digest = hashlib.sha256(raw.encode()).hexdigest()[:24]
|
|
97
|
+
return _entity(
|
|
98
|
+
"tool_call_observation",
|
|
99
|
+
f"tool-call-observation:cursor:{_scope(payload)}:{digest}",
|
|
100
|
+
name,
|
|
101
|
+
provider="cursor",
|
|
102
|
+
tool_name=name,
|
|
103
|
+
identity_semantics="provider_hook_observation_without_unique_tool_call_id",
|
|
104
|
+
direct_tool_call_linkage_asserted=False,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _file(payload: dict[str, Any]) -> dict[str, Any]:
|
|
109
|
+
raw = "unknown"
|
|
110
|
+
for key in ("file_path", "filePath", "path"):
|
|
111
|
+
candidate = payload.get(key)
|
|
112
|
+
if isinstance(candidate, str) and candidate:
|
|
113
|
+
raw = candidate
|
|
114
|
+
break
|
|
115
|
+
candidate = Path(raw).expanduser() if raw != "unknown" else Path(raw)
|
|
116
|
+
try:
|
|
117
|
+
normalized = str(candidate.resolve(strict=False)) if raw != "unknown" else raw
|
|
118
|
+
except OSError:
|
|
119
|
+
normalized = str(candidate.absolute())
|
|
120
|
+
return _entity(
|
|
121
|
+
"file",
|
|
122
|
+
f"file:{normalized}",
|
|
123
|
+
Path(normalized).name or normalized,
|
|
124
|
+
provider="cursor",
|
|
125
|
+
provider_path=raw,
|
|
126
|
+
declared_by_provider_hook=True,
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _subagent(payload: dict[str, Any], hook: str) -> dict[str, Any]:
|
|
131
|
+
sub_id = payload.get("subagent_id")
|
|
132
|
+
sub_type = (
|
|
133
|
+
payload.get("subagent_type")
|
|
134
|
+
if isinstance(payload.get("subagent_type"), str)
|
|
135
|
+
else "Cursor subagent"
|
|
136
|
+
)
|
|
137
|
+
if isinstance(sub_id, str) and sub_id:
|
|
138
|
+
return _entity(
|
|
139
|
+
"agent",
|
|
140
|
+
f"agent:cursor:{_scope(payload)}:subagent:{sub_id}",
|
|
141
|
+
sub_type,
|
|
142
|
+
provider="cursor",
|
|
143
|
+
subagent_id=sub_id,
|
|
144
|
+
identity_semantics="provider_subagent_id",
|
|
145
|
+
**subagent_topology(
|
|
146
|
+
evidence=EVIDENCE_SUBAGENT_LIFECYCLE_HOOK,
|
|
147
|
+
parent_scope_id=_scope(payload),
|
|
148
|
+
),
|
|
149
|
+
)
|
|
150
|
+
raw = json.dumps(
|
|
151
|
+
[
|
|
152
|
+
hook,
|
|
153
|
+
_scope(payload),
|
|
154
|
+
sub_type,
|
|
155
|
+
payload.get("task"),
|
|
156
|
+
payload.get("description"),
|
|
157
|
+
payload.get("status"),
|
|
158
|
+
],
|
|
159
|
+
ensure_ascii=False,
|
|
160
|
+
sort_keys=True,
|
|
161
|
+
default=str,
|
|
162
|
+
)
|
|
163
|
+
digest = hashlib.sha256(raw.encode()).hexdigest()[:24]
|
|
164
|
+
return _entity(
|
|
165
|
+
"subagent_observation",
|
|
166
|
+
f"subagent-observation:cursor:{_scope(payload)}:{digest}",
|
|
167
|
+
sub_type,
|
|
168
|
+
provider="cursor",
|
|
169
|
+
identity_semantics="provider_hook_observation_without_subagent_id",
|
|
170
|
+
direct_start_stop_linkage_asserted=False,
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _observe(
|
|
175
|
+
events: list[dict[str, Any]],
|
|
176
|
+
store: FullFidelityContentStore,
|
|
177
|
+
*,
|
|
178
|
+
value: Any,
|
|
179
|
+
kind: str,
|
|
180
|
+
timestamp: str,
|
|
181
|
+
source: dict[str, Any],
|
|
182
|
+
relation: str,
|
|
183
|
+
field: str,
|
|
184
|
+
hook: str,
|
|
185
|
+
**attrs: Any,
|
|
186
|
+
) -> None:
|
|
187
|
+
ref = (
|
|
188
|
+
store.put_text(value, content_kind=kind)
|
|
189
|
+
if isinstance(value, str)
|
|
190
|
+
else store.put_json(value, content_kind=kind)
|
|
191
|
+
)
|
|
192
|
+
events.append(
|
|
193
|
+
content_observation_event(
|
|
194
|
+
timestamp=timestamp,
|
|
195
|
+
provider="cursor",
|
|
196
|
+
source=source,
|
|
197
|
+
reference=ref,
|
|
198
|
+
relation=relation,
|
|
199
|
+
observed_field=field,
|
|
200
|
+
evidence_source="provider_hook",
|
|
201
|
+
attribution="cursor_hook",
|
|
202
|
+
attributes={"cursor_hook_event_name": hook, **attrs},
|
|
203
|
+
)
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def _metadata(
|
|
208
|
+
payload: dict[str, Any],
|
|
209
|
+
store: FullFidelityContentStore,
|
|
210
|
+
timestamp: str,
|
|
211
|
+
hook: str,
|
|
212
|
+
) -> dict[str, Any] | None:
|
|
213
|
+
raw = {
|
|
214
|
+
key: value
|
|
215
|
+
for key, value in payload.items()
|
|
216
|
+
if key not in _CONTENT_FIELDS
|
|
217
|
+
}
|
|
218
|
+
filtered, removed = filter_transport_credentials(raw)
|
|
219
|
+
if not filtered:
|
|
220
|
+
return None
|
|
221
|
+
ref = store.put_json(filtered, content_kind="cursor.provider_hook_metadata")
|
|
222
|
+
return content_observation_event(
|
|
223
|
+
timestamp=timestamp,
|
|
224
|
+
provider="cursor",
|
|
225
|
+
source=_agent(),
|
|
226
|
+
reference=ref,
|
|
227
|
+
relation="OBSERVED_PROVIDER_METADATA",
|
|
228
|
+
observed_field="hook_metadata",
|
|
229
|
+
evidence_source="provider_hook",
|
|
230
|
+
attribution="cursor_hook",
|
|
231
|
+
attributes={
|
|
232
|
+
"cursor_hook_event_name": hook,
|
|
233
|
+
"transport_credentials_excluded": removed,
|
|
234
|
+
},
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def cursor_hook_to_content_events(
|
|
239
|
+
payload: dict[str, Any],
|
|
240
|
+
*,
|
|
241
|
+
store: FullFidelityContentStore,
|
|
242
|
+
timestamp: str | None = None,
|
|
243
|
+
) -> list[dict[str, Any]]:
|
|
244
|
+
"""Persist complete values supplied by Cursor hooks; never read transcript_path."""
|
|
245
|
+
hook = payload.get("hook_event_name")
|
|
246
|
+
if not isinstance(hook, str) or not hook:
|
|
247
|
+
raise ValueError("Cursor hook payload requires hook_event_name")
|
|
248
|
+
ts = timestamp or _now()
|
|
249
|
+
events: list[dict[str, Any]] = []
|
|
250
|
+
metadata = _metadata(payload, store, ts, hook)
|
|
251
|
+
if metadata is not None:
|
|
252
|
+
events.append(metadata)
|
|
253
|
+
|
|
254
|
+
if hook == "beforeSubmitPrompt" and isinstance(payload.get("prompt"), str):
|
|
255
|
+
_observe(
|
|
256
|
+
events,
|
|
257
|
+
store,
|
|
258
|
+
value=payload["prompt"],
|
|
259
|
+
kind="cursor.prompt_submission_candidate",
|
|
260
|
+
timestamp=ts,
|
|
261
|
+
source=_agent(),
|
|
262
|
+
relation="OBSERVED_PROMPT_SUBMISSION_CANDIDATE",
|
|
263
|
+
field="prompt",
|
|
264
|
+
hook=hook,
|
|
265
|
+
backend_submission_asserted=False,
|
|
266
|
+
prompt_can_be_blocked_by_hook=True,
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
if hook == "sessionEnd" and isinstance(payload.get("error_message"), str):
|
|
270
|
+
_observe(
|
|
271
|
+
events,
|
|
272
|
+
store,
|
|
273
|
+
value=payload["error_message"],
|
|
274
|
+
kind="cursor.session_end_error",
|
|
275
|
+
timestamp=ts,
|
|
276
|
+
source=_provider_session(payload),
|
|
277
|
+
relation="OBSERVED_SESSION_END_ERROR",
|
|
278
|
+
field="error_message",
|
|
279
|
+
hook=hook,
|
|
280
|
+
provider_reported_session_error=True,
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
if hook in {"preToolUse", "postToolUse", "postToolUseFailure"}:
|
|
284
|
+
call = _tool_call(payload, hook)
|
|
285
|
+
if "tool_input" in payload:
|
|
286
|
+
_observe(
|
|
287
|
+
events,
|
|
288
|
+
store,
|
|
289
|
+
value=payload["tool_input"],
|
|
290
|
+
kind="cursor.tool_input",
|
|
291
|
+
timestamp=ts,
|
|
292
|
+
source=call,
|
|
293
|
+
relation="OBSERVED_TOOL_INPUT",
|
|
294
|
+
field="tool_input",
|
|
295
|
+
hook=hook,
|
|
296
|
+
)
|
|
297
|
+
if isinstance(payload.get("agent_message"), str):
|
|
298
|
+
_observe(
|
|
299
|
+
events,
|
|
300
|
+
store,
|
|
301
|
+
value=payload["agent_message"],
|
|
302
|
+
kind="cursor.agent_message",
|
|
303
|
+
timestamp=ts,
|
|
304
|
+
source=call,
|
|
305
|
+
relation="OBSERVED_AGENT_MESSAGE",
|
|
306
|
+
field="agent_message",
|
|
307
|
+
hook=hook,
|
|
308
|
+
)
|
|
309
|
+
if hook == "postToolUse" and "tool_output" in payload:
|
|
310
|
+
_observe(
|
|
311
|
+
events,
|
|
312
|
+
store,
|
|
313
|
+
value=payload["tool_output"],
|
|
314
|
+
kind="cursor.tool_output",
|
|
315
|
+
timestamp=ts,
|
|
316
|
+
source=call,
|
|
317
|
+
relation="RECEIVED_TOOL_OUTPUT",
|
|
318
|
+
field="tool_output",
|
|
319
|
+
hook=hook,
|
|
320
|
+
provider_value_is_json_stringified_result=True,
|
|
321
|
+
)
|
|
322
|
+
if (
|
|
323
|
+
hook == "postToolUseFailure"
|
|
324
|
+
and isinstance(payload.get("error_message"), str)
|
|
325
|
+
):
|
|
326
|
+
_observe(
|
|
327
|
+
events,
|
|
328
|
+
store,
|
|
329
|
+
value=payload["error_message"],
|
|
330
|
+
kind="cursor.tool_failure",
|
|
331
|
+
timestamp=ts,
|
|
332
|
+
source=call,
|
|
333
|
+
relation="RECEIVED_TOOL_ERROR",
|
|
334
|
+
field="error_message",
|
|
335
|
+
hook=hook,
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
if hook in {"beforeShellExecution", "afterShellExecution"}:
|
|
339
|
+
if isinstance(payload.get("command"), str):
|
|
340
|
+
relation = (
|
|
341
|
+
"OBSERVED_SHELL_COMMAND_BEFORE_EXECUTION"
|
|
342
|
+
if hook.startswith("before")
|
|
343
|
+
else "OBSERVED_SHELL_COMMAND_AFTER_EXECUTION"
|
|
344
|
+
)
|
|
345
|
+
_observe(
|
|
346
|
+
events,
|
|
347
|
+
store,
|
|
348
|
+
value=payload["command"],
|
|
349
|
+
kind="cursor.shell_command",
|
|
350
|
+
timestamp=ts,
|
|
351
|
+
source=_agent(),
|
|
352
|
+
relation=relation,
|
|
353
|
+
field="command",
|
|
354
|
+
hook=hook,
|
|
355
|
+
)
|
|
356
|
+
if hook == "afterShellExecution" and isinstance(payload.get("output"), str):
|
|
357
|
+
_observe(
|
|
358
|
+
events,
|
|
359
|
+
store,
|
|
360
|
+
value=payload["output"],
|
|
361
|
+
kind="cursor.shell_output",
|
|
362
|
+
timestamp=ts,
|
|
363
|
+
source=_agent(),
|
|
364
|
+
relation="RECEIVED_SHELL_OUTPUT",
|
|
365
|
+
field="output",
|
|
366
|
+
hook=hook,
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
if hook in {"beforeMCPExecution", "afterMCPExecution"}:
|
|
370
|
+
if isinstance(payload.get("command"), str):
|
|
371
|
+
_observe(
|
|
372
|
+
events,
|
|
373
|
+
store,
|
|
374
|
+
value=payload["command"],
|
|
375
|
+
kind="cursor.mcp_server_command",
|
|
376
|
+
timestamp=ts,
|
|
377
|
+
source=_agent(),
|
|
378
|
+
relation="OBSERVED_MCP_SERVER_COMMAND",
|
|
379
|
+
field="command",
|
|
380
|
+
hook=hook,
|
|
381
|
+
mcp_server_identity_asserted=False,
|
|
382
|
+
)
|
|
383
|
+
if "tool_input" in payload:
|
|
384
|
+
_observe(
|
|
385
|
+
events,
|
|
386
|
+
store,
|
|
387
|
+
value=payload["tool_input"],
|
|
388
|
+
kind="cursor.mcp_tool_input",
|
|
389
|
+
timestamp=ts,
|
|
390
|
+
source=_agent(),
|
|
391
|
+
relation="OBSERVED_MCP_TOOL_INPUT",
|
|
392
|
+
field="tool_input",
|
|
393
|
+
hook=hook,
|
|
394
|
+
)
|
|
395
|
+
if hook == "afterMCPExecution" and "result_json" in payload:
|
|
396
|
+
_observe(
|
|
397
|
+
events,
|
|
398
|
+
store,
|
|
399
|
+
value=payload["result_json"],
|
|
400
|
+
kind="cursor.mcp_tool_result",
|
|
401
|
+
timestamp=ts,
|
|
402
|
+
source=_agent(),
|
|
403
|
+
relation="RECEIVED_MCP_TOOL_RESULT",
|
|
404
|
+
field="result_json",
|
|
405
|
+
hook=hook,
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
if (
|
|
409
|
+
hook in {"beforeReadFile", "beforeTabFileRead"}
|
|
410
|
+
and isinstance(payload.get("content"), str)
|
|
411
|
+
):
|
|
412
|
+
_observe(
|
|
413
|
+
events,
|
|
414
|
+
store,
|
|
415
|
+
value=payload["content"],
|
|
416
|
+
kind="cursor.file_content_before_read",
|
|
417
|
+
timestamp=ts,
|
|
418
|
+
source=_file(payload),
|
|
419
|
+
relation="OBSERVED_FILE_CONTENT_BEFORE_READ",
|
|
420
|
+
field="content",
|
|
421
|
+
hook=hook,
|
|
422
|
+
read_completion_asserted=False,
|
|
423
|
+
)
|
|
424
|
+
if (
|
|
425
|
+
hook in {"afterFileEdit", "afterTabFileEdit"}
|
|
426
|
+
and isinstance(payload.get("edits"), list)
|
|
427
|
+
):
|
|
428
|
+
_observe(
|
|
429
|
+
events,
|
|
430
|
+
store,
|
|
431
|
+
value=payload["edits"],
|
|
432
|
+
kind="cursor.file_edits",
|
|
433
|
+
timestamp=ts,
|
|
434
|
+
source=_file(payload),
|
|
435
|
+
relation="OBSERVED_FILE_EDITS",
|
|
436
|
+
field="edits",
|
|
437
|
+
hook=hook,
|
|
438
|
+
complete_post_edit_file_snapshot_asserted=False,
|
|
439
|
+
)
|
|
440
|
+
|
|
441
|
+
if (
|
|
442
|
+
hook in {"afterAgentResponse", "afterAgentThought"}
|
|
443
|
+
and isinstance(payload.get("text"), str)
|
|
444
|
+
):
|
|
445
|
+
thought = hook == "afterAgentThought"
|
|
446
|
+
_observe(
|
|
447
|
+
events,
|
|
448
|
+
store,
|
|
449
|
+
value=payload["text"],
|
|
450
|
+
kind=(
|
|
451
|
+
"cursor.agent_thought"
|
|
452
|
+
if thought
|
|
453
|
+
else "cursor.assistant_response"
|
|
454
|
+
),
|
|
455
|
+
timestamp=ts,
|
|
456
|
+
source=_agent(),
|
|
457
|
+
relation=(
|
|
458
|
+
"OBSERVED_AGENT_THOUGHT"
|
|
459
|
+
if thought
|
|
460
|
+
else "PRODUCED_ASSISTANT_RESPONSE"
|
|
461
|
+
),
|
|
462
|
+
field="text",
|
|
463
|
+
hook=hook,
|
|
464
|
+
**({"provider_labels_as_thinking_text": True} if thought else {}),
|
|
465
|
+
)
|
|
466
|
+
|
|
467
|
+
if hook in {"subagentStart", "subagentStop"}:
|
|
468
|
+
sub = _subagent(payload, hook)
|
|
469
|
+
for field, relation in (
|
|
470
|
+
("task", "OBSERVED_SUBAGENT_TASK"),
|
|
471
|
+
("description", "OBSERVED_SUBAGENT_DESCRIPTION"),
|
|
472
|
+
("summary", "RECEIVED_SUBAGENT_SUMMARY"),
|
|
473
|
+
):
|
|
474
|
+
if (
|
|
475
|
+
isinstance(payload.get(field), str)
|
|
476
|
+
and (field == "task" or hook == "subagentStop")
|
|
477
|
+
):
|
|
478
|
+
_observe(
|
|
479
|
+
events,
|
|
480
|
+
store,
|
|
481
|
+
value=payload[field],
|
|
482
|
+
kind=f"cursor.subagent_{field}",
|
|
483
|
+
timestamp=ts,
|
|
484
|
+
source=sub,
|
|
485
|
+
relation=relation,
|
|
486
|
+
field=field,
|
|
487
|
+
hook=hook,
|
|
488
|
+
)
|
|
489
|
+
return events
|
|
@@ -0,0 +1,195 @@
|
|
|
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 cursor_agent_trace_events
|
|
12
|
+
from .content_store import FullFidelityContentStore
|
|
13
|
+
from .cursor_adapter import (
|
|
14
|
+
append_semantic_records,
|
|
15
|
+
cursor_hook_to_semantic_events,
|
|
16
|
+
read_hook_payload,
|
|
17
|
+
)
|
|
18
|
+
from .cursor_delegation import cursor_delegation_events
|
|
19
|
+
from .cursor_full_fidelity import cursor_hook_to_content_events
|
|
20
|
+
from .private_io import private_artifact_path
|
|
21
|
+
from .privacy import full_content_capture_enabled
|
|
22
|
+
from .cursor_hook_contract import (
|
|
23
|
+
OFFICIAL_CURSOR_HOOK_EVENTS,
|
|
24
|
+
cursor_official_hook_semantic_events,
|
|
25
|
+
cursor_workspace_scope,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _now() -> str:
|
|
30
|
+
return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def cursor_hook_config(command: str = "execweave-cursor-hook") -> dict[str, Any]:
|
|
34
|
+
hooks = {
|
|
35
|
+
name: [{"command": command}]
|
|
36
|
+
for name in sorted(OFFICIAL_CURSOR_HOOK_EVENTS)
|
|
37
|
+
}
|
|
38
|
+
if set(hooks) != set(OFFICIAL_CURSOR_HOOK_EVENTS):
|
|
39
|
+
raise RuntimeError("Cursor hook config drifted from the official event set")
|
|
40
|
+
return {"version": 1, "hooks": hooks}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _default_sidecar(payload: dict[str, Any]) -> Path:
|
|
44
|
+
hook = payload.get("hook_event_name")
|
|
45
|
+
if hook == "workspaceOpen":
|
|
46
|
+
workspace_scope, root = cursor_workspace_scope(payload)
|
|
47
|
+
return (
|
|
48
|
+
root
|
|
49
|
+
/ ".execweave"
|
|
50
|
+
/ "semantic"
|
|
51
|
+
/ "cursor"
|
|
52
|
+
/ f"workspace-{workspace_scope}.jsonl"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
cwd = payload.get("cwd")
|
|
56
|
+
if not isinstance(cwd, str) or not cwd:
|
|
57
|
+
roots = payload.get("workspace_roots")
|
|
58
|
+
if isinstance(roots, list) and roots and isinstance(roots[0], str):
|
|
59
|
+
cwd = roots[0]
|
|
60
|
+
if not isinstance(cwd, str) or not cwd:
|
|
61
|
+
raise ValueError(
|
|
62
|
+
"Cursor hook payload has no cwd/workspace root for sidecar placement"
|
|
63
|
+
)
|
|
64
|
+
scope = next(
|
|
65
|
+
(
|
|
66
|
+
payload[key]
|
|
67
|
+
for key in ("conversation_id", "session_id", "generation_id")
|
|
68
|
+
if isinstance(payload.get(key), str) and payload[key]
|
|
69
|
+
),
|
|
70
|
+
None,
|
|
71
|
+
)
|
|
72
|
+
if scope is None:
|
|
73
|
+
raise ValueError("Cursor hook payload has no conversation/session identifier")
|
|
74
|
+
safe_scope = "".join(
|
|
75
|
+
c if c.isalnum() or c in "-_." else "_" for c in scope
|
|
76
|
+
)
|
|
77
|
+
return (
|
|
78
|
+
Path(cwd)
|
|
79
|
+
/ ".execweave"
|
|
80
|
+
/ "semantic"
|
|
81
|
+
/ "cursor"
|
|
82
|
+
/ f"{safe_scope}.jsonl"
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
87
|
+
parser = argparse.ArgumentParser(
|
|
88
|
+
prog="execweave-cursor-hook",
|
|
89
|
+
description="Capture Cursor hook input as local ExecWeave semantic telemetry.",
|
|
90
|
+
)
|
|
91
|
+
parser.add_argument("--sidecar", type=Path, default=None)
|
|
92
|
+
parser.add_argument("--strict", action="store_true")
|
|
93
|
+
parser.add_argument("--auto", action="store_true", help=argparse.SUPPRESS)
|
|
94
|
+
parser.add_argument("--print-config", action="store_true")
|
|
95
|
+
parser.add_argument("--command", default="execweave-cursor-hook")
|
|
96
|
+
return parser
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _official_contract_records(
|
|
100
|
+
payload: dict[str, Any],
|
|
101
|
+
*,
|
|
102
|
+
timestamp: str,
|
|
103
|
+
strict: bool,
|
|
104
|
+
) -> list[dict[str, Any]]:
|
|
105
|
+
"""Project the official contract without discarding other hook evidence.
|
|
106
|
+
|
|
107
|
+
Historical or synthetic payloads can omit fields that the current Cursor
|
|
108
|
+
contract documents as required. In normal fail-open mode, skip only this
|
|
109
|
+
contract projection rather than dropping adapter/full-fidelity evidence.
|
|
110
|
+
Strict mode preserves validation behavior for diagnostics and tests.
|
|
111
|
+
"""
|
|
112
|
+
|
|
113
|
+
try:
|
|
114
|
+
return cursor_official_hook_semantic_events(
|
|
115
|
+
payload,
|
|
116
|
+
timestamp=timestamp,
|
|
117
|
+
)
|
|
118
|
+
except ValueError as exc:
|
|
119
|
+
if strict:
|
|
120
|
+
raise
|
|
121
|
+
print(
|
|
122
|
+
f"ExecWeave Cursor official hook contract warning: {exc}",
|
|
123
|
+
file=sys.stderr,
|
|
124
|
+
)
|
|
125
|
+
return []
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def main(argv: list[str] | None = None) -> int:
|
|
129
|
+
args = build_parser().parse_args(argv)
|
|
130
|
+
if args.print_config:
|
|
131
|
+
print(json.dumps(cursor_hook_config(args.command), indent=2, sort_keys=True))
|
|
132
|
+
return 0
|
|
133
|
+
if args.auto and not os.environ.get("EXECWEAVE_SEMANTIC_SIDECAR"):
|
|
134
|
+
print("{}")
|
|
135
|
+
return 0
|
|
136
|
+
try:
|
|
137
|
+
payload = read_hook_payload()
|
|
138
|
+
sidecar = args.sidecar
|
|
139
|
+
if sidecar is None:
|
|
140
|
+
configured = os.environ.get("EXECWEAVE_SEMANTIC_SIDECAR")
|
|
141
|
+
sidecar = Path(configured) if configured else _default_sidecar(payload)
|
|
142
|
+
sidecar = private_artifact_path(sidecar)
|
|
143
|
+
observed_at = _now()
|
|
144
|
+
store = FullFidelityContentStore(sidecar.parent)
|
|
145
|
+
|
|
146
|
+
summary_records = cursor_hook_to_semantic_events(
|
|
147
|
+
payload,
|
|
148
|
+
timestamp=observed_at,
|
|
149
|
+
)
|
|
150
|
+
append_semantic_records(sidecar, summary_records)
|
|
151
|
+
append_semantic_records(
|
|
152
|
+
sidecar,
|
|
153
|
+
_official_contract_records(
|
|
154
|
+
payload,
|
|
155
|
+
timestamp=observed_at,
|
|
156
|
+
strict=args.strict,
|
|
157
|
+
),
|
|
158
|
+
)
|
|
159
|
+
if not full_content_capture_enabled():
|
|
160
|
+
print("{}")
|
|
161
|
+
return 0
|
|
162
|
+
append_semantic_records(
|
|
163
|
+
sidecar,
|
|
164
|
+
cursor_hook_to_content_events(
|
|
165
|
+
payload,
|
|
166
|
+
store=store,
|
|
167
|
+
timestamp=observed_at,
|
|
168
|
+
),
|
|
169
|
+
)
|
|
170
|
+
append_semantic_records(
|
|
171
|
+
sidecar,
|
|
172
|
+
cursor_agent_trace_events(
|
|
173
|
+
payload,
|
|
174
|
+
store=store,
|
|
175
|
+
timestamp=observed_at,
|
|
176
|
+
),
|
|
177
|
+
)
|
|
178
|
+
append_semantic_records(
|
|
179
|
+
sidecar,
|
|
180
|
+
cursor_delegation_events(
|
|
181
|
+
payload,
|
|
182
|
+
store=store,
|
|
183
|
+
timestamp=observed_at,
|
|
184
|
+
),
|
|
185
|
+
)
|
|
186
|
+
except (OSError, RuntimeError, TimeoutError, TypeError, ValueError) as exc:
|
|
187
|
+
print(f"ExecWeave Cursor hook warning: {exc}", file=sys.stderr)
|
|
188
|
+
if args.strict:
|
|
189
|
+
return 1
|
|
190
|
+
print("{}")
|
|
191
|
+
return 0
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
if __name__ == "__main__":
|
|
195
|
+
raise SystemExit(main())
|