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,509 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from . import _http_proxy_base as _base
|
|
6
|
+
from . import model_runtime_full_fidelity as _runtime_ff
|
|
7
|
+
from . import openai_compatible_full_fidelity as _openai_ff
|
|
8
|
+
from ._http_proxy_base import * # noqa: F403
|
|
9
|
+
from .privacy import full_content_capture_enabled
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# OpenAI-compatible request config is request-side evidence too. Without this relation
|
|
13
|
+
# in the phase set it was emitted only after the response arrived, then duplicated by
|
|
14
|
+
# the two-stage proxy capture.
|
|
15
|
+
_base._REQUEST_RELATIONS = frozenset(
|
|
16
|
+
set(_base._REQUEST_RELATIONS) | {"OBSERVED_PROVIDER_REQUEST_CONFIG"}
|
|
17
|
+
)
|
|
18
|
+
_ORIGINAL_RECORD_EXCHANGE = _base.record_exchange_fail_open
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _request_events_openai(
|
|
22
|
+
config: ProxyConfig, # noqa: F405
|
|
23
|
+
request: dict[str, Any],
|
|
24
|
+
store,
|
|
25
|
+
exchange_id: str,
|
|
26
|
+
) -> list[dict[str, Any]]:
|
|
27
|
+
observed_at = _openai_ff._now()
|
|
28
|
+
safe_endpoint = _openai_ff.sanitize_openai_compatible_endpoint(config.upstream)
|
|
29
|
+
source = _openai_ff._request_entity(
|
|
30
|
+
{},
|
|
31
|
+
endpoint=safe_endpoint,
|
|
32
|
+
provider_name=config.provider_name,
|
|
33
|
+
request_id=exchange_id,
|
|
34
|
+
observed_at=observed_at,
|
|
35
|
+
)
|
|
36
|
+
common = {
|
|
37
|
+
"store": store,
|
|
38
|
+
"timestamp": observed_at,
|
|
39
|
+
"provider_name": config.provider_name,
|
|
40
|
+
"source": source,
|
|
41
|
+
"evidence_source": "localhost_http_proxy",
|
|
42
|
+
"attribution": "execweave_http_proxy",
|
|
43
|
+
"attributes": {},
|
|
44
|
+
}
|
|
45
|
+
events = [
|
|
46
|
+
_openai_ff._content_event(
|
|
47
|
+
**common,
|
|
48
|
+
value=request,
|
|
49
|
+
content_kind="openai_compatible.request",
|
|
50
|
+
relation="OBSERVED_INFERENCE_REQUEST",
|
|
51
|
+
observed_field="request",
|
|
52
|
+
)
|
|
53
|
+
]
|
|
54
|
+
for key, relation in (
|
|
55
|
+
("messages", "OBSERVED_INFERENCE_REQUEST_MESSAGES"),
|
|
56
|
+
("prompt", "OBSERVED_INFERENCE_REQUEST_PROMPT"),
|
|
57
|
+
("input", "OBSERVED_INFERENCE_REQUEST_INPUT"),
|
|
58
|
+
):
|
|
59
|
+
if key in request:
|
|
60
|
+
events.append(
|
|
61
|
+
_openai_ff._content_event(
|
|
62
|
+
**common,
|
|
63
|
+
value=request[key],
|
|
64
|
+
content_kind=f"openai_compatible.request_{key}",
|
|
65
|
+
relation=relation,
|
|
66
|
+
observed_field=f"request.{key}",
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
for key in ("system", "instructions"):
|
|
70
|
+
if key in request:
|
|
71
|
+
events.append(
|
|
72
|
+
_openai_ff._content_event(
|
|
73
|
+
**common,
|
|
74
|
+
value=request[key],
|
|
75
|
+
content_kind=f"openai_compatible.{key}_context",
|
|
76
|
+
relation="OBSERVED_SYSTEM_CONTEXT",
|
|
77
|
+
observed_field=f"request.{key}",
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
for key in ("tools", "functions"):
|
|
81
|
+
if key in request:
|
|
82
|
+
events.append(
|
|
83
|
+
_openai_ff._content_event(
|
|
84
|
+
**common,
|
|
85
|
+
value=request[key],
|
|
86
|
+
content_kind=f"openai_compatible.{key}",
|
|
87
|
+
relation="OBSERVED_TOOL_DEFINITIONS",
|
|
88
|
+
observed_field=f"request.{key}",
|
|
89
|
+
)
|
|
90
|
+
)
|
|
91
|
+
tool_results = _openai_ff._tool_results(request)
|
|
92
|
+
if tool_results:
|
|
93
|
+
events.append(
|
|
94
|
+
_openai_ff._content_event(
|
|
95
|
+
**common,
|
|
96
|
+
value=tool_results,
|
|
97
|
+
content_kind="openai_compatible.tool_results",
|
|
98
|
+
relation="OBSERVED_TOOL_RESULT_MESSAGES",
|
|
99
|
+
observed_field="request.tool_results",
|
|
100
|
+
)
|
|
101
|
+
)
|
|
102
|
+
request_config = {
|
|
103
|
+
key: value for key, value in request.items() if key not in _openai_ff._REQUEST_CONTENT_KEYS
|
|
104
|
+
}
|
|
105
|
+
if request_config:
|
|
106
|
+
events.append(
|
|
107
|
+
_openai_ff._content_event(
|
|
108
|
+
**common,
|
|
109
|
+
value=request_config,
|
|
110
|
+
content_kind="openai_compatible.request_config",
|
|
111
|
+
relation="OBSERVED_PROVIDER_REQUEST_CONFIG",
|
|
112
|
+
observed_field="request.provider_facing_config",
|
|
113
|
+
)
|
|
114
|
+
)
|
|
115
|
+
return events
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _request_events_ollama(
|
|
119
|
+
config: ProxyConfig, # noqa: F405
|
|
120
|
+
request: dict[str, Any],
|
|
121
|
+
store,
|
|
122
|
+
exchange_id: str,
|
|
123
|
+
) -> list[dict[str, Any]]:
|
|
124
|
+
observed_at = _runtime_ff._now()
|
|
125
|
+
safe_endpoint = _runtime_ff.sanitize_endpoint(config.upstream)
|
|
126
|
+
source = _runtime_ff._request_entity(
|
|
127
|
+
"ollama", {}, endpoint=safe_endpoint, request_id=exchange_id
|
|
128
|
+
)
|
|
129
|
+
common = {
|
|
130
|
+
"store": store,
|
|
131
|
+
"timestamp": observed_at,
|
|
132
|
+
"runtime": "ollama",
|
|
133
|
+
"source": source,
|
|
134
|
+
"evidence_source": "localhost_http_proxy",
|
|
135
|
+
"attribution": "execweave_http_proxy",
|
|
136
|
+
"attributes": {},
|
|
137
|
+
}
|
|
138
|
+
events = [
|
|
139
|
+
_runtime_ff._content_event(
|
|
140
|
+
**common,
|
|
141
|
+
value=request,
|
|
142
|
+
content_kind="model_runtime.ollama.request",
|
|
143
|
+
relation="OBSERVED_INFERENCE_REQUEST",
|
|
144
|
+
observed_field="request",
|
|
145
|
+
)
|
|
146
|
+
]
|
|
147
|
+
if "messages" in request:
|
|
148
|
+
events.append(
|
|
149
|
+
_runtime_ff._content_event(
|
|
150
|
+
**common,
|
|
151
|
+
value=request["messages"],
|
|
152
|
+
content_kind="model_runtime.ollama.request_messages",
|
|
153
|
+
relation="OBSERVED_INFERENCE_REQUEST_MESSAGES",
|
|
154
|
+
observed_field="request.messages",
|
|
155
|
+
)
|
|
156
|
+
)
|
|
157
|
+
tool_results = _runtime_ff._tool_result_messages(request["messages"])
|
|
158
|
+
if tool_results:
|
|
159
|
+
events.append(
|
|
160
|
+
_runtime_ff._content_event(
|
|
161
|
+
**common,
|
|
162
|
+
value=tool_results,
|
|
163
|
+
content_kind="model_runtime.ollama.tool_result_messages",
|
|
164
|
+
relation="OBSERVED_TOOL_RESULT_MESSAGES",
|
|
165
|
+
observed_field="request.messages[role=tool|function]",
|
|
166
|
+
)
|
|
167
|
+
)
|
|
168
|
+
if "prompt" in request:
|
|
169
|
+
events.append(
|
|
170
|
+
_runtime_ff._content_event(
|
|
171
|
+
**common,
|
|
172
|
+
value=request["prompt"],
|
|
173
|
+
content_kind="model_runtime.ollama.request_prompt",
|
|
174
|
+
relation="OBSERVED_INFERENCE_REQUEST_PROMPT",
|
|
175
|
+
observed_field="request.prompt",
|
|
176
|
+
)
|
|
177
|
+
)
|
|
178
|
+
if "input" in request:
|
|
179
|
+
events.append(
|
|
180
|
+
_runtime_ff._content_event(
|
|
181
|
+
**common,
|
|
182
|
+
value=request["input"],
|
|
183
|
+
content_kind="model_runtime.ollama.request_input",
|
|
184
|
+
relation="OBSERVED_INFERENCE_REQUEST_INPUT",
|
|
185
|
+
observed_field="request.input",
|
|
186
|
+
)
|
|
187
|
+
)
|
|
188
|
+
if "system" in request:
|
|
189
|
+
events.append(
|
|
190
|
+
_runtime_ff._content_event(
|
|
191
|
+
**common,
|
|
192
|
+
value=request["system"],
|
|
193
|
+
content_kind="model_runtime.ollama.system_context",
|
|
194
|
+
relation="OBSERVED_SYSTEM_CONTEXT",
|
|
195
|
+
observed_field="request.system",
|
|
196
|
+
)
|
|
197
|
+
)
|
|
198
|
+
if "tools" in request:
|
|
199
|
+
events.append(
|
|
200
|
+
_runtime_ff._content_event(
|
|
201
|
+
**common,
|
|
202
|
+
value=request["tools"],
|
|
203
|
+
content_kind="model_runtime.ollama.tool_definitions",
|
|
204
|
+
relation="OBSERVED_TOOL_DEFINITIONS",
|
|
205
|
+
observed_field="request.tools",
|
|
206
|
+
)
|
|
207
|
+
)
|
|
208
|
+
request_config = _runtime_ff._request_config(request)
|
|
209
|
+
if request_config:
|
|
210
|
+
events.append(
|
|
211
|
+
_runtime_ff._content_event(
|
|
212
|
+
**common,
|
|
213
|
+
value=request_config,
|
|
214
|
+
content_kind="model_runtime.ollama.request_config",
|
|
215
|
+
relation="OBSERVED_INFERENCE_REQUEST_CONFIG",
|
|
216
|
+
observed_field="request.provider_facing_config",
|
|
217
|
+
)
|
|
218
|
+
)
|
|
219
|
+
return events
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def _stamp_phase(
|
|
223
|
+
events: list[dict[str, Any]],
|
|
224
|
+
*,
|
|
225
|
+
config: ProxyConfig, # noqa: F405
|
|
226
|
+
method: str,
|
|
227
|
+
request_path: str,
|
|
228
|
+
status: int | None,
|
|
229
|
+
phase: str,
|
|
230
|
+
) -> None:
|
|
231
|
+
for event in events:
|
|
232
|
+
attrs = event.setdefault("attributes", {})
|
|
233
|
+
attrs.update(
|
|
234
|
+
{
|
|
235
|
+
"observation_scope": "localhost_http_proxy",
|
|
236
|
+
"caller_supplied_exchange": False,
|
|
237
|
+
"wire_interception_asserted": True,
|
|
238
|
+
"transport_relay_observed": True,
|
|
239
|
+
"evidence_source": "localhost_http_proxy",
|
|
240
|
+
"attribution": "execweave_http_proxy",
|
|
241
|
+
"proxy_method": method,
|
|
242
|
+
"proxy_request_path": request_path,
|
|
243
|
+
"proxy_status": status,
|
|
244
|
+
"proxy_upstream": _base.sanitize_upstream(config.upstream),
|
|
245
|
+
"causal": False,
|
|
246
|
+
"inferred": False,
|
|
247
|
+
"capture_phase": phase,
|
|
248
|
+
"response_observed": phase == "response",
|
|
249
|
+
}
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def _record_request_phase(
|
|
254
|
+
config: ProxyConfig, # noqa: F405
|
|
255
|
+
*,
|
|
256
|
+
exchange_id: str,
|
|
257
|
+
request_body: bytes,
|
|
258
|
+
request_content_type: str | None,
|
|
259
|
+
method: str,
|
|
260
|
+
request_path: str,
|
|
261
|
+
status: int | None,
|
|
262
|
+
) -> bool:
|
|
263
|
+
request = _base._json(request_body)
|
|
264
|
+
if not isinstance(request, dict):
|
|
265
|
+
request = {}
|
|
266
|
+
if not any(key in request for key in ("messages", "prompt", "input")):
|
|
267
|
+
return False
|
|
268
|
+
store = _base.FullFidelityContentStore(config.sidecar.parent)
|
|
269
|
+
if config.mode == "ollama":
|
|
270
|
+
events = _request_events_ollama(config, request, store, exchange_id)
|
|
271
|
+
provider = "ollama"
|
|
272
|
+
else:
|
|
273
|
+
events = _request_events_openai(config, request, store, exchange_id)
|
|
274
|
+
provider = config.provider_name
|
|
275
|
+
_stamp_phase(
|
|
276
|
+
events,
|
|
277
|
+
config=config,
|
|
278
|
+
method=method,
|
|
279
|
+
request_path=request_path,
|
|
280
|
+
status=status,
|
|
281
|
+
phase="request",
|
|
282
|
+
)
|
|
283
|
+
source = events[0]["source"]
|
|
284
|
+
source.setdefault("attributes", {})["observed_at"] = events[0]["timestamp"]
|
|
285
|
+
events.append(
|
|
286
|
+
_base._raw_event(
|
|
287
|
+
store,
|
|
288
|
+
source,
|
|
289
|
+
provider,
|
|
290
|
+
request_body,
|
|
291
|
+
kind="http_proxy.request_body_raw",
|
|
292
|
+
relation="OBSERVED_INFERENCE_REQUEST_RAW",
|
|
293
|
+
field="request.body.raw",
|
|
294
|
+
media_type=request_content_type,
|
|
295
|
+
)
|
|
296
|
+
)
|
|
297
|
+
_base.append_openai_compatible_records(config.sidecar, events)
|
|
298
|
+
return True
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def _record_response_phase(
|
|
302
|
+
config: ProxyConfig, # noqa: F405
|
|
303
|
+
*,
|
|
304
|
+
exchange_id: str,
|
|
305
|
+
request_body: bytes,
|
|
306
|
+
response_body: bytes,
|
|
307
|
+
response_content_type: str | None,
|
|
308
|
+
method: str,
|
|
309
|
+
request_path: str,
|
|
310
|
+
status: int | None,
|
|
311
|
+
) -> bool:
|
|
312
|
+
request = _base._json(request_body)
|
|
313
|
+
if not isinstance(request, dict):
|
|
314
|
+
request = {}
|
|
315
|
+
chunks = _base._stream_items(response_body, response_content_type, request)
|
|
316
|
+
assembled = (
|
|
317
|
+
_base.assemble_stream(
|
|
318
|
+
chunks,
|
|
319
|
+
wire_format=_base.OLLAMA_NDJSON
|
|
320
|
+
if config.mode == "ollama"
|
|
321
|
+
else _base.OPENAI_CHAT_DELTA,
|
|
322
|
+
)
|
|
323
|
+
if chunks
|
|
324
|
+
else None
|
|
325
|
+
)
|
|
326
|
+
response = assembled.response if assembled is not None else _base._json(response_body)
|
|
327
|
+
if not isinstance(response, dict):
|
|
328
|
+
response = {}
|
|
329
|
+
store = _base.FullFidelityContentStore(config.sidecar.parent)
|
|
330
|
+
if config.mode == "ollama":
|
|
331
|
+
events = _runtime_ff.runtime_response_to_content_events(
|
|
332
|
+
response,
|
|
333
|
+
store=store,
|
|
334
|
+
runtime="ollama",
|
|
335
|
+
endpoint=config.upstream,
|
|
336
|
+
request_id=exchange_id,
|
|
337
|
+
)
|
|
338
|
+
provider = "ollama"
|
|
339
|
+
else:
|
|
340
|
+
events = _openai_ff.response_to_content_events(
|
|
341
|
+
response,
|
|
342
|
+
store=store,
|
|
343
|
+
endpoint=config.upstream,
|
|
344
|
+
provider_name=config.provider_name,
|
|
345
|
+
request_id=exchange_id,
|
|
346
|
+
)
|
|
347
|
+
provider = config.provider_name
|
|
348
|
+
_stamp_phase(
|
|
349
|
+
events,
|
|
350
|
+
config=config,
|
|
351
|
+
method=method,
|
|
352
|
+
request_path=request_path,
|
|
353
|
+
status=status,
|
|
354
|
+
phase="response",
|
|
355
|
+
)
|
|
356
|
+
for event in events:
|
|
357
|
+
attrs = event.setdefault("attributes", {})
|
|
358
|
+
if assembled is not None:
|
|
359
|
+
attrs.update(assembled.attributes())
|
|
360
|
+
attrs["stream_tool_arguments_parse_cleanly"] = _base.arguments_parse_cleanly(response)
|
|
361
|
+
if assembled.notes:
|
|
362
|
+
attrs["stream_assembly_notes"] = assembled.notes
|
|
363
|
+
source = events[0]["source"]
|
|
364
|
+
source.setdefault("attributes", {})["observed_at"] = events[0]["timestamp"]
|
|
365
|
+
events.append(
|
|
366
|
+
_base._raw_event(
|
|
367
|
+
store,
|
|
368
|
+
source,
|
|
369
|
+
provider,
|
|
370
|
+
response_body,
|
|
371
|
+
kind="http_proxy.response_body_raw",
|
|
372
|
+
relation="OBSERVED_INFERENCE_RESPONSE_RAW",
|
|
373
|
+
field="response.body.raw",
|
|
374
|
+
media_type=response_content_type,
|
|
375
|
+
)
|
|
376
|
+
)
|
|
377
|
+
if chunks and not _base._has_relation(events, "OBSERVED_INFERENCE_STREAM_CHUNKS"):
|
|
378
|
+
kind = (
|
|
379
|
+
"http_proxy.ollama_stream_chunks"
|
|
380
|
+
if config.mode == "ollama"
|
|
381
|
+
else "http_proxy.stream_chunks"
|
|
382
|
+
)
|
|
383
|
+
reference = store.put_json(chunks, content_kind=kind)
|
|
384
|
+
events.append(
|
|
385
|
+
_base.content_observation_event(
|
|
386
|
+
timestamp=events[0]["timestamp"],
|
|
387
|
+
provider=provider,
|
|
388
|
+
source=source,
|
|
389
|
+
reference=reference,
|
|
390
|
+
relation="OBSERVED_INFERENCE_STREAM_CHUNKS",
|
|
391
|
+
observed_field="response.stream_chunks",
|
|
392
|
+
evidence_source="localhost_http_proxy",
|
|
393
|
+
attribution="execweave_http_proxy",
|
|
394
|
+
event_type="http_proxy.content.observed",
|
|
395
|
+
attributes={"causal": False, "inferred": False},
|
|
396
|
+
)
|
|
397
|
+
)
|
|
398
|
+
calls = (
|
|
399
|
+
[]
|
|
400
|
+
if _base._has_relation(events, "OBSERVED_ASSISTANT_TOOL_CALLS")
|
|
401
|
+
else _base.assembled_tool_calls(response)
|
|
402
|
+
if assembled is not None
|
|
403
|
+
else _base._tool_calls(response)
|
|
404
|
+
)
|
|
405
|
+
if calls:
|
|
406
|
+
reference = store.put_json(calls, content_kind="http_proxy.response_tool_calls")
|
|
407
|
+
events.append(
|
|
408
|
+
_base.content_observation_event(
|
|
409
|
+
timestamp=events[0]["timestamp"],
|
|
410
|
+
provider=provider,
|
|
411
|
+
source=source,
|
|
412
|
+
reference=reference,
|
|
413
|
+
relation="OBSERVED_ASSISTANT_TOOL_CALLS",
|
|
414
|
+
observed_field="response.tool_calls",
|
|
415
|
+
evidence_source="localhost_http_proxy",
|
|
416
|
+
attribution="execweave_http_proxy",
|
|
417
|
+
event_type="http_proxy.content.observed",
|
|
418
|
+
attributes={"causal": False, "inferred": False},
|
|
419
|
+
)
|
|
420
|
+
)
|
|
421
|
+
_base.append_openai_compatible_records(config.sidecar, events)
|
|
422
|
+
return True
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
def record_exchange_fail_open(
|
|
426
|
+
config: ProxyConfig, # noqa: F405
|
|
427
|
+
*,
|
|
428
|
+
exchange_id: str,
|
|
429
|
+
request_body: bytes,
|
|
430
|
+
request_content_type: str | None,
|
|
431
|
+
response_body: bytes,
|
|
432
|
+
response_content_type: str | None,
|
|
433
|
+
method: str,
|
|
434
|
+
request_path: str,
|
|
435
|
+
status: int | None,
|
|
436
|
+
request_only: bool = False,
|
|
437
|
+
request_recorded: bool = False,
|
|
438
|
+
) -> bool:
|
|
439
|
+
if not full_content_capture_enabled():
|
|
440
|
+
return False
|
|
441
|
+
try:
|
|
442
|
+
if request_only:
|
|
443
|
+
return _record_request_phase(
|
|
444
|
+
config,
|
|
445
|
+
exchange_id=exchange_id,
|
|
446
|
+
request_body=request_body,
|
|
447
|
+
request_content_type=request_content_type,
|
|
448
|
+
method=method,
|
|
449
|
+
request_path=request_path,
|
|
450
|
+
status=status,
|
|
451
|
+
)
|
|
452
|
+
if request_recorded:
|
|
453
|
+
return _record_response_phase(
|
|
454
|
+
config,
|
|
455
|
+
exchange_id=exchange_id,
|
|
456
|
+
request_body=request_body,
|
|
457
|
+
response_body=response_body,
|
|
458
|
+
response_content_type=response_content_type,
|
|
459
|
+
method=method,
|
|
460
|
+
request_path=request_path,
|
|
461
|
+
status=status,
|
|
462
|
+
)
|
|
463
|
+
return _ORIGINAL_RECORD_EXCHANGE(
|
|
464
|
+
config,
|
|
465
|
+
exchange_id=exchange_id,
|
|
466
|
+
request_body=request_body,
|
|
467
|
+
request_content_type=request_content_type,
|
|
468
|
+
response_body=response_body,
|
|
469
|
+
response_content_type=response_content_type,
|
|
470
|
+
method=method,
|
|
471
|
+
request_path=request_path,
|
|
472
|
+
status=status,
|
|
473
|
+
request_only=False,
|
|
474
|
+
request_recorded=False,
|
|
475
|
+
)
|
|
476
|
+
except Exception as exc:
|
|
477
|
+
print(f"ExecWeave HTTP proxy capture warning: {exc}", file=_base.sys.stderr)
|
|
478
|
+
return False
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
def create_proxy_server(
|
|
482
|
+
*,
|
|
483
|
+
listen_host: str,
|
|
484
|
+
listen_port: int,
|
|
485
|
+
config: ProxyConfig, # noqa: F405
|
|
486
|
+
recorder=None,
|
|
487
|
+
):
|
|
488
|
+
"""Create a proxy with the staged recorder as the actual runtime default.
|
|
489
|
+
|
|
490
|
+
The base function's default argument was bound before this acceptance layer replaced
|
|
491
|
+
the recorder. Passing it explicitly is required so the handler's identity check
|
|
492
|
+
enters request-phase capture before it waits for model response headers.
|
|
493
|
+
"""
|
|
494
|
+
actual = record_exchange_fail_open if recorder is None else recorder
|
|
495
|
+
return _base.create_proxy_server(
|
|
496
|
+
listen_host=listen_host,
|
|
497
|
+
listen_port=listen_port,
|
|
498
|
+
config=config,
|
|
499
|
+
recorder=actual,
|
|
500
|
+
)
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
# Handler methods were defined in the base module, so patch its global too. This keeps
|
|
504
|
+
# identity checks inside _relay aligned with the recorder explicitly passed above.
|
|
505
|
+
_base.record_exchange_fail_open = record_exchange_fail_open
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
def __getattr__(name: str):
|
|
509
|
+
return getattr(_base, name)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Safe output placement for workloads launched inside an active recording."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def prepare_acceptance_output(path: str | Path) -> Path:
|
|
9
|
+
output = Path(path).expanduser().resolve()
|
|
10
|
+
sidecar = os.environ.get("EXECWEAVE_SEMANTIC_SIDECAR")
|
|
11
|
+
shared = bool(sidecar and Path(sidecar).expanduser().resolve().parent == output
|
|
12
|
+
and os.environ.get("EXECWEAVE_SESSION_ID"))
|
|
13
|
+
if output.exists():
|
|
14
|
+
if not output.is_dir():
|
|
15
|
+
raise FileExistsError(f"Acceptance output is not a directory: {output}")
|
|
16
|
+
if (output / "summary.json").exists() or (any(output.iterdir()) and not shared):
|
|
17
|
+
raise FileExistsError(f"Acceptance output contains a previous run: {output}")
|
|
18
|
+
output.mkdir(parents=True, exist_ok=True)
|
|
19
|
+
return output
|