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,479 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
5
|
+
import sys
|
|
6
|
+
import time
|
|
7
|
+
from datetime import datetime, timezone
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from .private_io import append_private_text
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _now() -> str:
|
|
15
|
+
return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _entity(
|
|
19
|
+
entity_type: str,
|
|
20
|
+
entity_id: str,
|
|
21
|
+
*,
|
|
22
|
+
name: str | None = None,
|
|
23
|
+
attributes: dict[str, Any] | None = None,
|
|
24
|
+
) -> dict[str, Any]:
|
|
25
|
+
return {
|
|
26
|
+
"type": entity_type,
|
|
27
|
+
"id": entity_id,
|
|
28
|
+
"name": name,
|
|
29
|
+
"attributes": attributes or {},
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _agent() -> dict[str, Any]:
|
|
34
|
+
return _entity("agent", "agent:Antigravity", name="Antigravity")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _common(payload: dict[str, Any]) -> dict[str, Any]:
|
|
38
|
+
out: dict[str, Any] = {
|
|
39
|
+
"backend": "semantic",
|
|
40
|
+
"attribution": "antigravity_hook",
|
|
41
|
+
"evidence_source": "provider_hook",
|
|
42
|
+
"provider": "antigravity",
|
|
43
|
+
"causal": False,
|
|
44
|
+
}
|
|
45
|
+
mapping = {
|
|
46
|
+
"conversationId": "antigravity_conversation_id",
|
|
47
|
+
"transcriptPath": "antigravity_transcript_path",
|
|
48
|
+
"artifactDirectoryPath": "antigravity_artifact_directory_path",
|
|
49
|
+
"modelName": "antigravity_model_name",
|
|
50
|
+
"stepIdx": "antigravity_step_index",
|
|
51
|
+
"invocationNum": "antigravity_invocation_number",
|
|
52
|
+
"initialNumSteps": "antigravity_initial_num_steps",
|
|
53
|
+
"executionNum": "antigravity_execution_number",
|
|
54
|
+
"terminationReason": "antigravity_termination_reason",
|
|
55
|
+
"fullyIdle": "antigravity_fully_idle",
|
|
56
|
+
}
|
|
57
|
+
for source, target in mapping.items():
|
|
58
|
+
value = payload.get(source)
|
|
59
|
+
if isinstance(value, (str, int, float, bool)) and value != "":
|
|
60
|
+
out[target] = value
|
|
61
|
+
roots = payload.get("workspacePaths")
|
|
62
|
+
if isinstance(roots, list):
|
|
63
|
+
out["antigravity_workspace_paths"] = [
|
|
64
|
+
value for value in roots if isinstance(value, str) and value
|
|
65
|
+
]
|
|
66
|
+
return out
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _event(
|
|
70
|
+
*,
|
|
71
|
+
timestamp: str,
|
|
72
|
+
event_type: str,
|
|
73
|
+
relation: str,
|
|
74
|
+
source: dict[str, Any],
|
|
75
|
+
target: dict[str, Any],
|
|
76
|
+
payload: dict[str, Any],
|
|
77
|
+
attributes: dict[str, Any] | None = None,
|
|
78
|
+
) -> dict[str, Any]:
|
|
79
|
+
merged = _common(payload)
|
|
80
|
+
if attributes:
|
|
81
|
+
merged.update(attributes)
|
|
82
|
+
return {
|
|
83
|
+
"timestamp": timestamp,
|
|
84
|
+
"event_type": event_type,
|
|
85
|
+
"relation": relation,
|
|
86
|
+
"source": source,
|
|
87
|
+
"target": target,
|
|
88
|
+
"attributes": merged,
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _conversation(payload: dict[str, Any]) -> tuple[str, dict[str, Any]]:
|
|
93
|
+
value = payload.get("conversationId")
|
|
94
|
+
conversation_id = value if isinstance(value, str) and value else "unknown"
|
|
95
|
+
return conversation_id, _entity(
|
|
96
|
+
"provider_session",
|
|
97
|
+
f"provider-session:antigravity:{conversation_id}",
|
|
98
|
+
name=conversation_id,
|
|
99
|
+
attributes={"provider": "antigravity"},
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _model(payload: dict[str, Any]) -> dict[str, Any] | None:
|
|
104
|
+
model_name = payload.get("modelName")
|
|
105
|
+
if not isinstance(model_name, str) or not model_name:
|
|
106
|
+
return None
|
|
107
|
+
return _entity(
|
|
108
|
+
"model",
|
|
109
|
+
f"model:antigravity:{model_name}",
|
|
110
|
+
name=model_name,
|
|
111
|
+
attributes={"provider": "antigravity", "model_name": model_name},
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _execution(payload: dict[str, Any]) -> dict[str, Any]:
|
|
116
|
+
conversation_id, _ = _conversation(payload)
|
|
117
|
+
execution_num = payload.get("executionNum")
|
|
118
|
+
if (
|
|
119
|
+
not isinstance(execution_num, int)
|
|
120
|
+
or isinstance(execution_num, bool)
|
|
121
|
+
or execution_num < 0
|
|
122
|
+
):
|
|
123
|
+
raise ValueError("Antigravity Stop payload has no valid executionNum")
|
|
124
|
+
termination_reason = payload.get("terminationReason")
|
|
125
|
+
if not isinstance(termination_reason, str) or not termination_reason:
|
|
126
|
+
raise ValueError("Antigravity Stop payload has no terminationReason")
|
|
127
|
+
fully_idle = payload.get("fullyIdle")
|
|
128
|
+
if not isinstance(fully_idle, bool):
|
|
129
|
+
raise ValueError("Antigravity Stop payload has no valid fullyIdle flag")
|
|
130
|
+
return _entity(
|
|
131
|
+
"agent_execution",
|
|
132
|
+
f"agent-execution:antigravity:{conversation_id}:{execution_num}",
|
|
133
|
+
name=f"execution {execution_num}",
|
|
134
|
+
attributes={
|
|
135
|
+
"provider": "antigravity",
|
|
136
|
+
"execution_num": execution_num,
|
|
137
|
+
"termination_reason": termination_reason,
|
|
138
|
+
"fully_idle": fully_idle,
|
|
139
|
+
"identity_semantics": "provider_conversation_and_execution_number",
|
|
140
|
+
},
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _tool_call(payload: dict[str, Any]) -> tuple[dict[str, Any], dict[str, Any], dict[str, Any]]:
|
|
145
|
+
tool_call = payload.get("toolCall")
|
|
146
|
+
if not isinstance(tool_call, dict):
|
|
147
|
+
raise ValueError("Antigravity PostToolUse payload has no toolCall object")
|
|
148
|
+
name = tool_call.get("name")
|
|
149
|
+
if not isinstance(name, str) or not name:
|
|
150
|
+
raise ValueError("Antigravity PostToolUse payload has no toolCall.name")
|
|
151
|
+
args = tool_call.get("args")
|
|
152
|
+
canonical_args = args if isinstance(args, dict) else {}
|
|
153
|
+
conversation_id, _ = _conversation(payload)
|
|
154
|
+
step = payload.get("stepIdx")
|
|
155
|
+
raw = json.dumps(
|
|
156
|
+
[conversation_id, step, name, canonical_args],
|
|
157
|
+
ensure_ascii=False,
|
|
158
|
+
sort_keys=True,
|
|
159
|
+
separators=(",", ":"),
|
|
160
|
+
)
|
|
161
|
+
digest = hashlib.sha256(raw.encode("utf-8", errors="replace")).hexdigest()[:24]
|
|
162
|
+
call = _entity(
|
|
163
|
+
"tool_call",
|
|
164
|
+
f"tool-call:antigravity:{conversation_id}:{digest}",
|
|
165
|
+
name=name,
|
|
166
|
+
attributes={
|
|
167
|
+
"provider": "antigravity",
|
|
168
|
+
"tool_name": name,
|
|
169
|
+
"conversation_id": conversation_id,
|
|
170
|
+
"step_index": step,
|
|
171
|
+
"input_keys": sorted(str(key) for key in canonical_args),
|
|
172
|
+
"arguments_observed": isinstance(args, dict),
|
|
173
|
+
},
|
|
174
|
+
)
|
|
175
|
+
tool = _entity(
|
|
176
|
+
"tool",
|
|
177
|
+
f"tool:antigravity:{name}",
|
|
178
|
+
name=name,
|
|
179
|
+
attributes={"provider": "antigravity", "native_name": name},
|
|
180
|
+
)
|
|
181
|
+
return call, tool, canonical_args
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _command_entity(args: dict[str, Any]) -> dict[str, Any] | None:
|
|
185
|
+
value = args.get("CommandLine")
|
|
186
|
+
if not isinstance(value, str) or not value:
|
|
187
|
+
value = args.get("command")
|
|
188
|
+
if not isinstance(value, str) or not value:
|
|
189
|
+
return None
|
|
190
|
+
digest = hashlib.sha256(value.encode("utf-8", errors="replace")).hexdigest()
|
|
191
|
+
label = " ".join(value.replace("\x00", "").split())
|
|
192
|
+
if len(label) > 160:
|
|
193
|
+
label = label[:157] + "..."
|
|
194
|
+
return _entity(
|
|
195
|
+
"command",
|
|
196
|
+
f"command:sha256:{digest}",
|
|
197
|
+
name=label,
|
|
198
|
+
attributes={"command": value, "declared_by_provider_hook": True},
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _apply_patch_targets(value: object) -> list[tuple[str, str]]:
|
|
203
|
+
"""Extract provider-declared file targets from an apply_patch payload."""
|
|
204
|
+
if not isinstance(value, str) or not value:
|
|
205
|
+
return []
|
|
206
|
+
targets: list[tuple[str, str]] = []
|
|
207
|
+
seen: set[tuple[str, str]] = set()
|
|
208
|
+
for line in value.splitlines():
|
|
209
|
+
stripped = line.strip()
|
|
210
|
+
operation: str | None = None
|
|
211
|
+
raw_path: str | None = None
|
|
212
|
+
for marker, marker_operation in (
|
|
213
|
+
("*** Add File:", "add"),
|
|
214
|
+
("*** Update File:", "update"),
|
|
215
|
+
("*** Delete File:", "delete"),
|
|
216
|
+
("*** Move to:", "move"),
|
|
217
|
+
):
|
|
218
|
+
if stripped.startswith(marker):
|
|
219
|
+
operation = marker_operation
|
|
220
|
+
raw_path = stripped[len(marker) :].strip()
|
|
221
|
+
break
|
|
222
|
+
if operation is None or not raw_path:
|
|
223
|
+
continue
|
|
224
|
+
target = (operation, raw_path)
|
|
225
|
+
if target not in seen:
|
|
226
|
+
seen.add(target)
|
|
227
|
+
targets.append(target)
|
|
228
|
+
return targets
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def _file_entity(payload: dict[str, Any], args: dict[str, Any]) -> dict[str, Any] | None:
|
|
232
|
+
value = None
|
|
233
|
+
for key in ("TargetFile", "AbsolutePath", "FilePath", "path", "file_path"):
|
|
234
|
+
candidate = args.get(key)
|
|
235
|
+
if isinstance(candidate, str) and candidate:
|
|
236
|
+
value = candidate
|
|
237
|
+
break
|
|
238
|
+
if value is None:
|
|
239
|
+
return None
|
|
240
|
+
path = Path(value).expanduser()
|
|
241
|
+
if not path.is_absolute():
|
|
242
|
+
roots = payload.get("workspacePaths")
|
|
243
|
+
if isinstance(roots, list) and roots and isinstance(roots[0], str):
|
|
244
|
+
path = Path(roots[0]) / path
|
|
245
|
+
try:
|
|
246
|
+
normalized = path.resolve(strict=False)
|
|
247
|
+
except OSError:
|
|
248
|
+
normalized = path.absolute()
|
|
249
|
+
return _entity(
|
|
250
|
+
"file",
|
|
251
|
+
f"file:{normalized}",
|
|
252
|
+
name=normalized.name or str(normalized),
|
|
253
|
+
attributes={"provider": "antigravity", "declared_by_provider_hook": True},
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def antigravity_hook_to_semantic_events(
|
|
258
|
+
payload: dict[str, Any],
|
|
259
|
+
*,
|
|
260
|
+
hook_event: str,
|
|
261
|
+
timestamp: str | None = None,
|
|
262
|
+
) -> list[dict[str, Any]]:
|
|
263
|
+
observed_at = timestamp or _now()
|
|
264
|
+
_, conversation = _conversation(payload)
|
|
265
|
+
|
|
266
|
+
if hook_event == "PreInvocation":
|
|
267
|
+
events = [
|
|
268
|
+
_event(
|
|
269
|
+
timestamp=observed_at,
|
|
270
|
+
event_type="semantic.antigravity.session.observed",
|
|
271
|
+
relation="OBSERVED_PROVIDER_SESSION",
|
|
272
|
+
source=_agent(),
|
|
273
|
+
target=conversation,
|
|
274
|
+
payload=payload,
|
|
275
|
+
attributes={"provider_contract_exact": True},
|
|
276
|
+
)
|
|
277
|
+
]
|
|
278
|
+
model = _model(payload)
|
|
279
|
+
if model is not None:
|
|
280
|
+
events.append(
|
|
281
|
+
_event(
|
|
282
|
+
timestamp=observed_at,
|
|
283
|
+
event_type="semantic.antigravity.model.invocation.requested",
|
|
284
|
+
relation="INVOKES_MODEL",
|
|
285
|
+
source=conversation,
|
|
286
|
+
target=model,
|
|
287
|
+
payload=payload,
|
|
288
|
+
attributes={"provider_contract_exact": True},
|
|
289
|
+
)
|
|
290
|
+
)
|
|
291
|
+
return events
|
|
292
|
+
|
|
293
|
+
if hook_event == "PostInvocation":
|
|
294
|
+
model = _model(payload)
|
|
295
|
+
if model is None:
|
|
296
|
+
return []
|
|
297
|
+
return [
|
|
298
|
+
_event(
|
|
299
|
+
timestamp=observed_at,
|
|
300
|
+
event_type="semantic.antigravity.model.invocation.completed",
|
|
301
|
+
relation="MODEL_INVOCATION_COMPLETED",
|
|
302
|
+
source=conversation,
|
|
303
|
+
target=model,
|
|
304
|
+
payload=payload,
|
|
305
|
+
attributes={"provider_contract_exact": True},
|
|
306
|
+
)
|
|
307
|
+
]
|
|
308
|
+
|
|
309
|
+
if hook_event == "Stop":
|
|
310
|
+
execution = _execution(payload)
|
|
311
|
+
events = [
|
|
312
|
+
_event(
|
|
313
|
+
timestamp=observed_at,
|
|
314
|
+
event_type="semantic.antigravity.execution.stopped",
|
|
315
|
+
relation="OBSERVED_EXECUTION_STOP",
|
|
316
|
+
source=conversation,
|
|
317
|
+
target=execution,
|
|
318
|
+
payload=payload,
|
|
319
|
+
attributes={"provider_contract_exact": True},
|
|
320
|
+
)
|
|
321
|
+
]
|
|
322
|
+
error = payload.get("error")
|
|
323
|
+
if isinstance(error, str) and error:
|
|
324
|
+
events.append(
|
|
325
|
+
_event(
|
|
326
|
+
timestamp=observed_at,
|
|
327
|
+
event_type="semantic.antigravity.execution.error_observed",
|
|
328
|
+
relation="OBSERVED_EXECUTION_ERROR",
|
|
329
|
+
source=conversation,
|
|
330
|
+
target=execution,
|
|
331
|
+
payload=payload,
|
|
332
|
+
attributes={
|
|
333
|
+
"provider_contract_exact": True,
|
|
334
|
+
"provider_reported_error": True,
|
|
335
|
+
},
|
|
336
|
+
)
|
|
337
|
+
)
|
|
338
|
+
return events
|
|
339
|
+
|
|
340
|
+
if hook_event != "PostToolUse":
|
|
341
|
+
return []
|
|
342
|
+
|
|
343
|
+
call, tool, args = _tool_call(payload)
|
|
344
|
+
tool_name = tool.get("name")
|
|
345
|
+
error = payload.get("error")
|
|
346
|
+
has_error = isinstance(error, str) and bool(error.strip())
|
|
347
|
+
events = [
|
|
348
|
+
_event(
|
|
349
|
+
timestamp=observed_at,
|
|
350
|
+
event_type="semantic.antigravity.tool.observed",
|
|
351
|
+
relation="REQUESTED_TOOL_CALL",
|
|
352
|
+
source=_agent(),
|
|
353
|
+
target=call,
|
|
354
|
+
payload=payload,
|
|
355
|
+
),
|
|
356
|
+
_event(
|
|
357
|
+
timestamp=observed_at,
|
|
358
|
+
event_type="semantic.antigravity.tool.selected",
|
|
359
|
+
relation="USES_TOOL",
|
|
360
|
+
source=call,
|
|
361
|
+
target=tool,
|
|
362
|
+
payload=payload,
|
|
363
|
+
),
|
|
364
|
+
]
|
|
365
|
+
command = _command_entity(args) if tool_name != "apply_patch" else None
|
|
366
|
+
if command is not None:
|
|
367
|
+
events.append(
|
|
368
|
+
_event(
|
|
369
|
+
timestamp=observed_at,
|
|
370
|
+
event_type="semantic.antigravity.command.declared",
|
|
371
|
+
relation="DECLARED_COMMAND",
|
|
372
|
+
source=call,
|
|
373
|
+
target=command,
|
|
374
|
+
payload=payload,
|
|
375
|
+
)
|
|
376
|
+
)
|
|
377
|
+
patch_targets = (
|
|
378
|
+
_apply_patch_targets(args.get("patch") or args.get("command"))
|
|
379
|
+
if tool_name == "apply_patch"
|
|
380
|
+
else []
|
|
381
|
+
)
|
|
382
|
+
if patch_targets:
|
|
383
|
+
for operation, raw_path in patch_targets:
|
|
384
|
+
file_entity = _file_entity(payload, {"TargetFile": raw_path})
|
|
385
|
+
if file_entity is None:
|
|
386
|
+
continue
|
|
387
|
+
events.append(
|
|
388
|
+
_event(
|
|
389
|
+
timestamp=observed_at,
|
|
390
|
+
event_type="semantic.antigravity.file.declared",
|
|
391
|
+
relation="DECLARED_TARGET",
|
|
392
|
+
source=call,
|
|
393
|
+
target=file_entity,
|
|
394
|
+
payload=payload,
|
|
395
|
+
attributes={"patch_operation": operation},
|
|
396
|
+
)
|
|
397
|
+
)
|
|
398
|
+
else:
|
|
399
|
+
file_entity = _file_entity(payload, args)
|
|
400
|
+
if file_entity is not None:
|
|
401
|
+
events.append(
|
|
402
|
+
_event(
|
|
403
|
+
timestamp=observed_at,
|
|
404
|
+
event_type="semantic.antigravity.file.declared",
|
|
405
|
+
relation="DECLARED_TARGET",
|
|
406
|
+
source=call,
|
|
407
|
+
target=file_entity,
|
|
408
|
+
payload=payload,
|
|
409
|
+
)
|
|
410
|
+
)
|
|
411
|
+
result_id = hashlib.sha256(
|
|
412
|
+
f"{call['id']}\0{error if has_error else 'ok'}".encode("utf-8", errors="replace")
|
|
413
|
+
).hexdigest()[:24]
|
|
414
|
+
result = _entity(
|
|
415
|
+
"tool_result",
|
|
416
|
+
f"tool-result:antigravity:{result_id}",
|
|
417
|
+
name=f"{tool['name']} result",
|
|
418
|
+
attributes={"provider": "antigravity", "provider_reported_error": has_error},
|
|
419
|
+
)
|
|
420
|
+
events.append(
|
|
421
|
+
_event(
|
|
422
|
+
timestamp=observed_at,
|
|
423
|
+
event_type=(
|
|
424
|
+
"semantic.antigravity.tool.reported_error"
|
|
425
|
+
if has_error
|
|
426
|
+
else "semantic.antigravity.tool.returned"
|
|
427
|
+
),
|
|
428
|
+
relation="TOOL_RESULT_REPORTED_ERROR" if has_error else "TOOL_RESULT_RETURNED",
|
|
429
|
+
source=tool,
|
|
430
|
+
target=result,
|
|
431
|
+
payload=payload,
|
|
432
|
+
attributes={"provider_reported_error": has_error},
|
|
433
|
+
)
|
|
434
|
+
)
|
|
435
|
+
return events
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
def append_semantic_records(path: str | Path, records: list[dict[str, Any]]) -> Path:
|
|
439
|
+
raw_output = Path(path).expanduser()
|
|
440
|
+
output = raw_output.parent.resolve() / raw_output.name
|
|
441
|
+
output.parent.mkdir(parents=True, exist_ok=True)
|
|
442
|
+
if not records:
|
|
443
|
+
return output
|
|
444
|
+
blob = "".join(
|
|
445
|
+
json.dumps(record, ensure_ascii=False, sort_keys=True, separators=(",", ":")) + "\n"
|
|
446
|
+
for record in records
|
|
447
|
+
)
|
|
448
|
+
lock_dir = output.with_name(output.name + ".lock")
|
|
449
|
+
deadline = time.monotonic() + 5.0
|
|
450
|
+
while True:
|
|
451
|
+
try:
|
|
452
|
+
lock_dir.mkdir()
|
|
453
|
+
break
|
|
454
|
+
except FileExistsError:
|
|
455
|
+
if time.monotonic() >= deadline:
|
|
456
|
+
raise TimeoutError(f"timed out waiting for semantic sidecar lock: {lock_dir}")
|
|
457
|
+
time.sleep(0.01)
|
|
458
|
+
try:
|
|
459
|
+
append_private_text(output, blob)
|
|
460
|
+
finally:
|
|
461
|
+
try:
|
|
462
|
+
lock_dir.rmdir()
|
|
463
|
+
except OSError:
|
|
464
|
+
pass
|
|
465
|
+
return output
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
def read_hook_payload(stream: Any = None) -> dict[str, Any]:
|
|
469
|
+
source = stream if stream is not None else sys.stdin
|
|
470
|
+
raw = source.read()
|
|
471
|
+
if not isinstance(raw, str) or not raw.strip():
|
|
472
|
+
raise ValueError("Antigravity hook stdin is empty")
|
|
473
|
+
try:
|
|
474
|
+
payload = json.loads(raw)
|
|
475
|
+
except json.JSONDecodeError as exc:
|
|
476
|
+
raise ValueError(f"Antigravity hook stdin is invalid JSON: {exc.msg}") from exc
|
|
477
|
+
if not isinstance(payload, dict):
|
|
478
|
+
raise ValueError("Antigravity hook stdin must be one JSON object")
|
|
479
|
+
return payload
|