execweave 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. execweave/__init__.py +3 -0
  2. execweave/__main__.py +5 -0
  3. execweave/_conversation_records_core.py +902 -0
  4. execweave/_dashboard_shell_base.py +148 -0
  5. execweave/_http_proxy_base.py +565 -0
  6. execweave/_http_proxy_bounded.py +560 -0
  7. execweave/_http_proxy_stage.py +509 -0
  8. execweave/acceptance_output.py +19 -0
  9. execweave/agent_bootstrap.py +395 -0
  10. execweave/agent_topology.py +313 -0
  11. execweave/agent_trace.py +1162 -0
  12. execweave/agy_preview_sanitize.py +102 -0
  13. execweave/analysis.py +427 -0
  14. execweave/anthropic.py +228 -0
  15. execweave/anthropic_cli.py +171 -0
  16. execweave/anthropic_full_fidelity.py +385 -0
  17. execweave/antigravity_adapter.py +112 -0
  18. execweave/antigravity_adapter_base.py +479 -0
  19. execweave/antigravity_full_fidelity.py +656 -0
  20. execweave/antigravity_full_fidelity_base.py +172 -0
  21. execweave/antigravity_full_fidelity_collaboration_base.py +451 -0
  22. execweave/antigravity_hook_cli.py +209 -0
  23. execweave/antigravity_record.py +96 -0
  24. execweave/antigravity_subagent_linkage.py +449 -0
  25. execweave/antigravity_trace_capability.py +39 -0
  26. execweave/auto_specialized.py +547 -0
  27. execweave/backends.py +102 -0
  28. execweave/benchmark.py +80 -0
  29. execweave/claude_adapter.py +517 -0
  30. execweave/claude_child_transcript.py +314 -0
  31. execweave/claude_delegation.py +136 -0
  32. execweave/claude_full_fidelity.py +396 -0
  33. execweave/claude_hook_cli.py +209 -0
  34. execweave/claude_hook_contract.py +943 -0
  35. execweave/claude_model_observer.py +353 -0
  36. execweave/claude_record.py +106 -0
  37. execweave/cli.py +629 -0
  38. execweave/codex_adapter.py +455 -0
  39. execweave/codex_conversation.py +621 -0
  40. execweave/codex_full_fidelity.py +287 -0
  41. execweave/codex_hook_cli.py +301 -0
  42. execweave/codex_hook_entry.py +207 -0
  43. execweave/codex_hook_lifecycle.py +363 -0
  44. execweave/codex_message_diagnostics.py +322 -0
  45. execweave/codex_message_transport_diagnostics.py +399 -0
  46. execweave/codex_record.py +199 -0
  47. execweave/codex_rollout_structures.py +402 -0
  48. execweave/codex_rollout_trace.py +56 -0
  49. execweave/codex_rollout_trace_base.py +1509 -0
  50. execweave/collector.py +768 -0
  51. execweave/command.py +157 -0
  52. execweave/command_privacy.py +20 -0
  53. execweave/content_evidence.py +101 -0
  54. execweave/content_integrity.py +289 -0
  55. execweave/content_store.py +273 -0
  56. execweave/controlled_checks.py +561 -0
  57. execweave/conversation_archive.py +338 -0
  58. execweave/conversation_message_identity.py +264 -0
  59. execweave/conversation_preview.py +66 -0
  60. execweave/conversation_preview_antigravity.py +32 -0
  61. execweave/conversation_preview_claude.py +31 -0
  62. execweave/conversation_preview_codex.py +107 -0
  63. execweave/conversation_preview_common.py +180 -0
  64. execweave/conversation_preview_generic.py +188 -0
  65. execweave/conversation_preview_lines.py +133 -0
  66. execweave/conversation_preview_transcript.py +121 -0
  67. execweave/conversation_records.py +349 -0
  68. execweave/conversation_records_antigravity.py +370 -0
  69. execweave/conversation_records_codex.py +83 -0
  70. execweave/conversation_records_common.py +17 -0
  71. execweave/conversation_records_ollama.py +39 -0
  72. execweave/correlation.py +818 -0
  73. execweave/cursor_adapter.py +349 -0
  74. execweave/cursor_delegation.py +87 -0
  75. execweave/cursor_delegation_base.py +220 -0
  76. execweave/cursor_full_fidelity.py +489 -0
  77. execweave/cursor_hook_cli.py +195 -0
  78. execweave/cursor_hook_contract.py +439 -0
  79. execweave/cursor_lifecycle.py +159 -0
  80. execweave/cursor_record.py +96 -0
  81. execweave/dashboard_shell.py +283 -0
  82. execweave/delivery_status.py +94 -0
  83. execweave/entry.py +98 -0
  84. execweave/evidence_availability.py +113 -0
  85. execweave/evidence_grade.py +166 -0
  86. execweave/fidelity.py +304 -0
  87. execweave/filesystem.py +327 -0
  88. execweave/finalization.py +92 -0
  89. execweave/focus.py +118 -0
  90. execweave/framework_adapters/__init__.py +34 -0
  91. execweave/framework_adapters/autogen.py +398 -0
  92. execweave/framework_adapters/base.py +580 -0
  93. execweave/framework_adapters/camel.py +270 -0
  94. execweave/framework_adapters/camel_channel.py +71 -0
  95. execweave/framework_adapters/metagpt.py +315 -0
  96. execweave/framework_adapters/metagpt_ollama_compat.py +54 -0
  97. execweave/framework_adapters/metagpt_recording.py +342 -0
  98. execweave/framework_adapters/registry.py +90 -0
  99. execweave/graph.py +590 -0
  100. execweave/graph_ops.py +472 -0
  101. execweave/hook_command.py +32 -0
  102. execweave/hook_delivery.py +32 -0
  103. execweave/hook_input.py +16 -0
  104. execweave/http_proxy.py +187 -0
  105. execweave/http_proxy_cli.py +84 -0
  106. execweave/inference_gateway.py +476 -0
  107. execweave/inference_gateway_cli.py +211 -0
  108. execweave/inference_gateway_full_fidelity.py +613 -0
  109. execweave/inference_identity.py +76 -0
  110. execweave/inference_identity_cli.py +60 -0
  111. execweave/integrity.py +235 -0
  112. execweave/integrity_cli.py +55 -0
  113. execweave/investigation_index.py +445 -0
  114. execweave/litellm_callback.py +211 -0
  115. execweave/litellm_callback_cli.py +42 -0
  116. execweave/live.py +445 -0
  117. execweave/live_core.py +972 -0
  118. execweave/live_view.py +109 -0
  119. execweave/live_view_extra_style.py +11 -0
  120. execweave/live_view_markup.py +29 -0
  121. execweave/live_view_process_layout.py +650 -0
  122. execweave/live_view_readability.py +502 -0
  123. execweave/live_view_script_a.py +59 -0
  124. execweave/live_view_script_b.py +97 -0
  125. execweave/live_view_script_c.py +59 -0
  126. execweave/live_view_script_d.py +40 -0
  127. execweave/live_view_style.py +34 -0
  128. execweave/model_runtime.py +560 -0
  129. execweave/model_runtime_cli.py +265 -0
  130. execweave/model_runtime_full_fidelity.py +519 -0
  131. execweave/observation.py +53 -0
  132. execweave/observation_demo.py +69 -0
  133. execweave/openai_agents.py +267 -0
  134. execweave/openai_agents_sdk.py +453 -0
  135. execweave/openai_compatible.py +239 -0
  136. execweave/openai_compatible_cli.py +189 -0
  137. execweave/openai_compatible_full_fidelity.py +438 -0
  138. execweave/opencode_adapter.py +325 -0
  139. execweave/opencode_event_contract.py +734 -0
  140. execweave/opencode_full_fidelity.py +198 -0
  141. execweave/opencode_hook_cli.py +119 -0
  142. execweave/opencode_plugin_cli.py +150 -0
  143. execweave/opencode_record.py +96 -0
  144. execweave/opencode_task_linkage.py +225 -0
  145. execweave/overhead_benchmark.py +440 -0
  146. execweave/privacy.py +84 -0
  147. execweave/private_io.py +465 -0
  148. execweave/provider_capability.py +578 -0
  149. execweave/provider_lifecycle.py +282 -0
  150. execweave/provider_record.py +290 -0
  151. execweave/reader_identity.py +13 -0
  152. execweave/redacted_archive.py +906 -0
  153. execweave/risk.py +106 -0
  154. execweave/rule_pack.py +359 -0
  155. execweave/rule_pack_cli.py +57 -0
  156. execweave/run_assessment.py +200 -0
  157. execweave/runtime_endpoint_availability.py +44 -0
  158. execweave/scalability_benchmark.py +195 -0
  159. execweave/schema.py +62 -0
  160. execweave/scope.py +85 -0
  161. execweave/semantic.py +453 -0
  162. execweave/session_summary.py +159 -0
  163. execweave/sink.py +71 -0
  164. execweave/strace_backend.py +927 -0
  165. execweave/stream_assembly.py +363 -0
  166. execweave/task_artifacts.py +192 -0
  167. execweave/task_validation.py +317 -0
  168. execweave/theme.py +40 -0
  169. execweave/top.py +599 -0
  170. execweave/top_cli.py +150 -0
  171. execweave/validate.py +196 -0
  172. execweave/vendor/dagre.min.js +815 -0
  173. execweave/view_cli.py +49 -0
  174. execweave/viewer.py +474 -0
  175. execweave/viewer_agent_panel.py +630 -0
  176. execweave/viewer_agent_panel_antigravity.py +31 -0
  177. execweave/viewer_agent_panel_claude.py +9 -0
  178. execweave/viewer_agent_panel_codex.py +50 -0
  179. execweave/viewer_agent_panel_cursor.py +9 -0
  180. execweave/viewer_agent_panel_default.py +79 -0
  181. execweave/viewer_agent_panel_ollama.py +20 -0
  182. execweave/viewer_agent_panel_opencode.py +9 -0
  183. execweave/viewer_agent_panel_registry.py +20 -0
  184. execweave/viewer_archive_verifier.py +178 -0
  185. execweave/viewer_background_files.py +86 -0
  186. execweave/viewer_content_browser.py +307 -0
  187. execweave/viewer_content_health.py +208 -0
  188. execweave/viewer_content_inspector.py +309 -0
  189. execweave/viewer_controlled_checks.py +258 -0
  190. execweave/viewer_conversation_sync.py +115 -0
  191. execweave/viewer_dashboard_clean.py +405 -0
  192. execweave/viewer_dashboard_focus.py +127 -0
  193. execweave/viewer_dashboard_hardening.py +264 -0
  194. execweave/viewer_dashboard_hardening_v2.py +62 -0
  195. execweave/viewer_dashboard_projection.py +261 -0
  196. execweave/viewer_delivery_status.py +155 -0
  197. execweave/viewer_edge_decross.py +117 -0
  198. execweave/viewer_execution_flow.py +611 -0
  199. execweave/viewer_execution_flow_provider_normalization.py +107 -0
  200. execweave/viewer_execution_flow_safety.py +349 -0
  201. execweave/viewer_external_endpoints.py +307 -0
  202. execweave/viewer_flow_canvas.py +1140 -0
  203. execweave/viewer_flow_layout.py +922 -0
  204. execweave/viewer_fold_state.py +31 -0
  205. execweave/viewer_framework_flow.py +68 -0
  206. execweave/viewer_framework_model_output.py +133 -0
  207. execweave/viewer_gif.py +278 -0
  208. execweave/viewer_history_browser.py +225 -0
  209. execweave/viewer_investigation.py +268 -0
  210. execweave/viewer_layout_geometry.py +192 -0
  211. execweave/viewer_layout_v2.py +429 -0
  212. execweave/viewer_layout_v2_detached.py +25 -0
  213. execweave/viewer_limits.py +93 -0
  214. execweave/viewer_live_layout.py +61 -0
  215. execweave/viewer_message_handoffs.py +114 -0
  216. execweave/viewer_projection.py +488 -0
  217. execweave/viewer_projection_base.py +522 -0
  218. execweave/viewer_projection_bridges.py +214 -0
  219. execweave/viewer_recorded_sources.py +146 -0
  220. execweave/viewer_run_assessment.py +274 -0
  221. execweave/viewer_run_guide.py +175 -0
  222. execweave/viewer_runtime_evidence.py +258 -0
  223. execweave/viewer_semantic_projection.py +641 -0
  224. execweave/viewer_session_flow.py +491 -0
  225. execweave/viewer_structure_share.py +132 -0
  226. execweave/viewer_task_validation.py +241 -0
  227. execweave/viewer_tool_mirror_identity.py +75 -0
  228. execweave/viewer_workflow_mode.py +127 -0
  229. execweave/workflow.py +183 -0
  230. execweave-1.0.0.dist-info/METADATA +462 -0
  231. execweave-1.0.0.dist-info/RECORD +234 -0
  232. execweave-1.0.0.dist-info/WHEEL +4 -0
  233. execweave-1.0.0.dist-info/entry_points.txt +30 -0
  234. execweave-1.0.0.dist-info/licenses/LICENSE +16 -0
@@ -0,0 +1,519 @@
1
+ from __future__ import annotations
2
+
3
+ import hashlib
4
+ import json
5
+ from dataclasses import replace
6
+ from datetime import datetime, timezone
7
+ from typing import Any
8
+
9
+ from .content_evidence import content_observation_event
10
+ from .content_store import ContentReference, FullFidelityContentStore
11
+ from .model_runtime import sanitize_endpoint
12
+
13
+ _RUNTIMES = frozenset({"ollama", "llamacpp", "vllm", "lmstudio"})
14
+ _REQUEST_CONFIG_KEYS = (
15
+ "stream",
16
+ "temperature",
17
+ "top_p",
18
+ "top_k",
19
+ "min_p",
20
+ "max_tokens",
21
+ "max_completion_tokens",
22
+ "num_predict",
23
+ "seed",
24
+ "stop",
25
+ "response_format",
26
+ "tool_choice",
27
+ "parallel_tool_calls",
28
+ "options",
29
+ "format",
30
+ "keep_alive",
31
+ "think",
32
+ "raw",
33
+ )
34
+
35
+
36
+ def _now() -> str:
37
+ return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
38
+
39
+
40
+ def _request_id(runtime: str, payload: dict[str, Any], explicit: str | None) -> str:
41
+ if isinstance(explicit, str) and explicit:
42
+ return explicit
43
+ native = payload.get("id")
44
+ if isinstance(native, str) and native:
45
+ return native
46
+ seed = {
47
+ "model": payload.get("model"),
48
+ "created_at": payload.get("created_at"),
49
+ "created": payload.get("created"),
50
+ "done_reason": payload.get("done_reason"),
51
+ "usage": payload.get("usage"),
52
+ }
53
+ raw = json.dumps(seed, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
54
+ return hashlib.sha256((runtime + "\0" + raw).encode("utf-8", errors="replace")).hexdigest()[:32]
55
+
56
+
57
+ def _request_entity(
58
+ runtime: str,
59
+ response: dict[str, Any],
60
+ *,
61
+ endpoint: str,
62
+ request_id: str | None,
63
+ ) -> dict[str, Any]:
64
+ native_id = _request_id(runtime, response, request_id)
65
+ return {
66
+ "type": "inference_request",
67
+ "id": f"inference-request:{runtime}:{native_id}",
68
+ "name": native_id,
69
+ "attributes": {"provider": runtime, "endpoint": sanitize_endpoint(endpoint)},
70
+ }
71
+
72
+
73
+ def _store(
74
+ store: FullFidelityContentStore,
75
+ value: Any,
76
+ *,
77
+ content_kind: str,
78
+ ) -> ContentReference:
79
+ if isinstance(value, str):
80
+ return store.put_text(value, content_kind=content_kind)
81
+ return store.put_json(value, content_kind=content_kind)
82
+
83
+
84
+ def _content_event(
85
+ *,
86
+ store: FullFidelityContentStore,
87
+ value: Any,
88
+ content_kind: str,
89
+ timestamp: str,
90
+ runtime: str,
91
+ source: dict[str, Any],
92
+ relation: str,
93
+ observed_field: str,
94
+ evidence_source: str,
95
+ attribution: str,
96
+ attributes: dict[str, Any],
97
+ ) -> dict[str, Any]:
98
+ return content_observation_event(
99
+ timestamp=timestamp,
100
+ provider=runtime,
101
+ source=source,
102
+ reference=_store(store, value, content_kind=content_kind),
103
+ relation=relation,
104
+ observed_field=observed_field,
105
+ evidence_source=evidence_source,
106
+ attribution=attribution,
107
+ event_type=f"model_runtime.{runtime}.content.observed",
108
+ attributes=attributes,
109
+ )
110
+
111
+
112
+ def _metadata_event(
113
+ *,
114
+ store: FullFidelityContentStore,
115
+ metadata: dict[str, Any],
116
+ timestamp: str,
117
+ runtime: str,
118
+ source: dict[str, Any],
119
+ evidence_source: str,
120
+ attribution: str,
121
+ attributes: dict[str, Any],
122
+ ) -> dict[str, Any]:
123
+ reference = store.put_json(metadata, content_kind=f"model_runtime.{runtime}.provider_metadata")
124
+ reference = replace(reference, complete_from_source=False)
125
+ return content_observation_event(
126
+ timestamp=timestamp,
127
+ provider=runtime,
128
+ source=source,
129
+ reference=reference,
130
+ relation="OBSERVED_PROVIDER_METADATA",
131
+ observed_field="integration_metadata_projection",
132
+ evidence_source=evidence_source,
133
+ attribution=attribution,
134
+ event_type=f"model_runtime.{runtime}.metadata.observed",
135
+ attributes={
136
+ **attributes,
137
+ "metadata_projection": True,
138
+ "metadata_complete_from_source": False,
139
+ },
140
+ )
141
+
142
+
143
+ def _tool_result_messages(messages: object) -> list[Any]:
144
+ if not isinstance(messages, list):
145
+ return []
146
+ return [
147
+ message
148
+ for message in messages
149
+ if isinstance(message, dict) and message.get("role") in {"tool", "function"}
150
+ ]
151
+
152
+
153
+ def _assistant_messages(response: object) -> list[Any]:
154
+ if not isinstance(response, dict):
155
+ return []
156
+ messages: list[Any] = []
157
+ native = response.get("message")
158
+ if isinstance(native, dict):
159
+ messages.append(native)
160
+ generated = response.get("response")
161
+ if isinstance(generated, str) and generated:
162
+ messages.append({"role": "assistant", "content": generated})
163
+ choices = response.get("choices")
164
+ if isinstance(choices, list):
165
+ for choice in choices:
166
+ if isinstance(choice, dict) and isinstance(choice.get("message"), dict):
167
+ messages.append(choice["message"])
168
+ output = response.get("output")
169
+ if isinstance(output, list):
170
+ for item in output:
171
+ if not isinstance(item, dict):
172
+ continue
173
+ if item.get("type") in {"message", "assistant_message"}:
174
+ messages.append(item)
175
+ return messages
176
+
177
+
178
+ def _response_tool_calls(response: object) -> list[Any]:
179
+ if not isinstance(response, dict):
180
+ return []
181
+ calls: list[Any] = []
182
+ direct = response.get("tool_calls")
183
+ if isinstance(direct, list):
184
+ calls.extend(direct)
185
+ for message in _assistant_messages(response):
186
+ if isinstance(message, dict):
187
+ nested = message.get("tool_calls")
188
+ if isinstance(nested, list):
189
+ calls.extend(nested)
190
+ output = response.get("output")
191
+ if isinstance(output, list):
192
+ for item in output:
193
+ if not isinstance(item, dict):
194
+ continue
195
+ if item.get("type") in {"function_call", "tool_call", "tool_use"}:
196
+ calls.append(item)
197
+ nested = item.get("tool_calls")
198
+ if isinstance(nested, list):
199
+ calls.extend(nested)
200
+ return calls
201
+
202
+
203
+ def _request_config(request: dict[str, Any]) -> dict[str, Any]:
204
+ config: dict[str, Any] = {}
205
+ for key in _REQUEST_CONFIG_KEYS:
206
+ if key in request:
207
+ config[key] = request[key]
208
+ return config
209
+
210
+
211
+ def runtime_response_to_content_events(
212
+ payload: dict[str, Any],
213
+ *,
214
+ store: FullFidelityContentStore,
215
+ runtime: str,
216
+ endpoint: str,
217
+ request_id: str | None = None,
218
+ timestamp: str | None = None,
219
+ ) -> list[dict[str, Any]]:
220
+ """Store the complete supplied final response without claiming request visibility."""
221
+ if runtime not in _RUNTIMES:
222
+ raise ValueError(f"unsupported model runtime: {runtime}")
223
+ observed_at = timestamp or _now()
224
+ safe_endpoint = sanitize_endpoint(endpoint)
225
+ request = _request_entity(runtime, payload, endpoint=safe_endpoint, request_id=request_id)
226
+ attrs = {
227
+ "observation_scope": "response_only",
228
+ "request_observed": False,
229
+ "caller_supplied_exchange": False,
230
+ "wire_interception_asserted": False,
231
+ "streaming_chunks_observed": False,
232
+ }
233
+ common = {
234
+ "store": store,
235
+ "timestamp": observed_at,
236
+ "runtime": runtime,
237
+ "source": request,
238
+ "evidence_source": "model_runtime_response",
239
+ "attribution": "model_runtime_api_response",
240
+ "attributes": attrs,
241
+ }
242
+ events = [
243
+ _content_event(
244
+ **common,
245
+ value=payload,
246
+ content_kind=f"model_runtime.{runtime}.response",
247
+ relation="OBSERVED_INFERENCE_RESPONSE",
248
+ observed_field="response",
249
+ )
250
+ ]
251
+ assistant_messages = _assistant_messages(payload)
252
+ if assistant_messages:
253
+ events.append(
254
+ _content_event(
255
+ **common,
256
+ value=assistant_messages,
257
+ content_kind=f"model_runtime.{runtime}.assistant_messages",
258
+ relation="OBSERVED_ASSISTANT_MESSAGES",
259
+ observed_field="response.assistant_messages",
260
+ )
261
+ )
262
+ tool_calls = _response_tool_calls(payload)
263
+ if tool_calls:
264
+ events.append(
265
+ _content_event(
266
+ **common,
267
+ value=tool_calls,
268
+ content_kind=f"model_runtime.{runtime}.assistant_tool_calls",
269
+ relation="OBSERVED_ASSISTANT_TOOL_CALLS",
270
+ observed_field="response.tool_calls",
271
+ )
272
+ )
273
+ metadata = {
274
+ "runtime": runtime,
275
+ "endpoint": safe_endpoint,
276
+ "request_id": request["name"],
277
+ "resolved_model": payload.get("model"),
278
+ }
279
+ events.append(
280
+ _metadata_event(
281
+ store=store,
282
+ metadata=metadata,
283
+ timestamp=observed_at,
284
+ runtime=runtime,
285
+ source=request,
286
+ evidence_source="model_runtime_response",
287
+ attribution="model_runtime_api_response",
288
+ attributes=attrs,
289
+ )
290
+ )
291
+ return events
292
+
293
+
294
+ def runtime_exchange_to_content_events(
295
+ exchange: dict[str, Any],
296
+ *,
297
+ store: FullFidelityContentStore,
298
+ runtime: str,
299
+ endpoint: str,
300
+ request_id: str | None = None,
301
+ timestamp: str | None = None,
302
+ ) -> list[dict[str, Any]]:
303
+ """Store caller-supplied request+response evidence; this is not transparent interception."""
304
+ if runtime not in _RUNTIMES:
305
+ raise ValueError(f"unsupported model runtime: {runtime}")
306
+ request_payload = exchange.get("request")
307
+ response_payload = exchange.get("response")
308
+ if not isinstance(request_payload, dict) or not isinstance(response_payload, dict):
309
+ raise ValueError("model runtime exchange requires JSON-object request and response fields")
310
+ observed_at = timestamp or _now()
311
+ safe_endpoint = sanitize_endpoint(endpoint)
312
+ request = _request_entity(
313
+ runtime, response_payload, endpoint=safe_endpoint, request_id=request_id
314
+ )
315
+ attrs = {
316
+ "observation_scope": "caller_supplied_exchange",
317
+ "request_observed": True,
318
+ "caller_supplied_exchange": True,
319
+ "wire_interception_asserted": False,
320
+ "streaming_chunks_observed": False,
321
+ }
322
+ common = {
323
+ "store": store,
324
+ "timestamp": observed_at,
325
+ "runtime": runtime,
326
+ "source": request,
327
+ "evidence_source": "caller_supplied_exchange",
328
+ "attribution": "execweave_model_runtime_cli",
329
+ "attributes": attrs,
330
+ }
331
+ events = [
332
+ _content_event(
333
+ **common,
334
+ value=request_payload,
335
+ content_kind=f"model_runtime.{runtime}.request",
336
+ relation="OBSERVED_INFERENCE_REQUEST",
337
+ observed_field="request",
338
+ )
339
+ ]
340
+ if "messages" in request_payload:
341
+ events.append(
342
+ _content_event(
343
+ **common,
344
+ value=request_payload["messages"],
345
+ content_kind=f"model_runtime.{runtime}.request_messages",
346
+ relation="OBSERVED_INFERENCE_REQUEST_MESSAGES",
347
+ observed_field="request.messages",
348
+ )
349
+ )
350
+ tool_results = _tool_result_messages(request_payload["messages"])
351
+ if tool_results:
352
+ events.append(
353
+ _content_event(
354
+ **common,
355
+ value=tool_results,
356
+ content_kind=f"model_runtime.{runtime}.tool_result_messages",
357
+ relation="OBSERVED_TOOL_RESULT_MESSAGES",
358
+ observed_field="request.messages[role=tool|function]",
359
+ )
360
+ )
361
+ if "prompt" in request_payload:
362
+ events.append(
363
+ _content_event(
364
+ **common,
365
+ value=request_payload["prompt"],
366
+ content_kind=f"model_runtime.{runtime}.request_prompt",
367
+ relation="OBSERVED_INFERENCE_REQUEST_PROMPT",
368
+ observed_field="request.prompt",
369
+ )
370
+ )
371
+ if "input" in request_payload:
372
+ events.append(
373
+ _content_event(
374
+ **common,
375
+ value=request_payload["input"],
376
+ content_kind=f"model_runtime.{runtime}.request_input",
377
+ relation="OBSERVED_INFERENCE_REQUEST_INPUT",
378
+ observed_field="request.input",
379
+ )
380
+ )
381
+ if "system" in request_payload:
382
+ events.append(
383
+ _content_event(
384
+ **common,
385
+ value=request_payload["system"],
386
+ content_kind=f"model_runtime.{runtime}.system_context",
387
+ relation="OBSERVED_SYSTEM_CONTEXT",
388
+ observed_field="request.system",
389
+ )
390
+ )
391
+ if "tools" in request_payload:
392
+ events.append(
393
+ _content_event(
394
+ **common,
395
+ value=request_payload["tools"],
396
+ content_kind=f"model_runtime.{runtime}.tool_definitions",
397
+ relation="OBSERVED_TOOL_DEFINITIONS",
398
+ observed_field="request.tools",
399
+ )
400
+ )
401
+ config = _request_config(request_payload)
402
+ if config:
403
+ events.append(
404
+ _content_event(
405
+ **common,
406
+ value=config,
407
+ content_kind=f"model_runtime.{runtime}.request_config",
408
+ relation="OBSERVED_INFERENCE_REQUEST_CONFIG",
409
+ observed_field="request.provider_facing_config",
410
+ )
411
+ )
412
+
413
+ for event in runtime_response_to_content_events(
414
+ response_payload,
415
+ store=store,
416
+ runtime=runtime,
417
+ endpoint=safe_endpoint,
418
+ request_id=request_id,
419
+ timestamp=observed_at,
420
+ ):
421
+ if event.get("relation") == "OBSERVED_PROVIDER_METADATA":
422
+ continue
423
+ event["attributes"].update(attrs)
424
+ event["attributes"]["evidence_source"] = "caller_supplied_exchange"
425
+ event["attributes"]["attribution"] = "execweave_model_runtime_cli"
426
+ events.append(event)
427
+
428
+ metadata = {
429
+ "runtime": runtime,
430
+ "endpoint": safe_endpoint,
431
+ "request_id": request["name"],
432
+ "requested_model": request_payload.get("model"),
433
+ "resolved_model": response_payload.get("model"),
434
+ }
435
+ events.append(
436
+ _metadata_event(
437
+ store=store,
438
+ metadata=metadata,
439
+ timestamp=observed_at,
440
+ runtime=runtime,
441
+ source=request,
442
+ evidence_source="caller_supplied_exchange",
443
+ attribution="execweave_model_runtime_cli",
444
+ attributes=attrs,
445
+ )
446
+ )
447
+ return events
448
+
449
+
450
+ def ollama_response_to_content_events(
451
+ payload: dict[str, Any],
452
+ *,
453
+ store: FullFidelityContentStore,
454
+ endpoint: str = "http://localhost:11434",
455
+ request_id: str | None = None,
456
+ timestamp: str | None = None,
457
+ ) -> list[dict[str, Any]]:
458
+ return runtime_response_to_content_events(
459
+ payload,
460
+ store=store,
461
+ runtime="ollama",
462
+ endpoint=endpoint,
463
+ request_id=request_id,
464
+ timestamp=timestamp,
465
+ )
466
+
467
+
468
+ def llamacpp_response_to_content_events(
469
+ payload: dict[str, Any],
470
+ *,
471
+ store: FullFidelityContentStore,
472
+ endpoint: str = "http://localhost:8080",
473
+ request_id: str | None = None,
474
+ timestamp: str | None = None,
475
+ ) -> list[dict[str, Any]]:
476
+ return runtime_response_to_content_events(
477
+ payload,
478
+ store=store,
479
+ runtime="llamacpp",
480
+ endpoint=endpoint,
481
+ request_id=request_id,
482
+ timestamp=timestamp,
483
+ )
484
+
485
+
486
+ def vllm_response_to_content_events(
487
+ payload: dict[str, Any],
488
+ *,
489
+ store: FullFidelityContentStore,
490
+ endpoint: str = "http://localhost:8000",
491
+ request_id: str | None = None,
492
+ timestamp: str | None = None,
493
+ ) -> list[dict[str, Any]]:
494
+ return runtime_response_to_content_events(
495
+ payload,
496
+ store=store,
497
+ runtime="vllm",
498
+ endpoint=endpoint,
499
+ request_id=request_id,
500
+ timestamp=timestamp,
501
+ )
502
+
503
+
504
+ def lmstudio_response_to_content_events(
505
+ payload: dict[str, Any],
506
+ *,
507
+ store: FullFidelityContentStore,
508
+ endpoint: str = "http://localhost:1234",
509
+ request_id: str | None = None,
510
+ timestamp: str | None = None,
511
+ ) -> list[dict[str, Any]]:
512
+ return runtime_response_to_content_events(
513
+ payload,
514
+ store=store,
515
+ runtime="lmstudio",
516
+ endpoint=endpoint,
517
+ request_id=request_id,
518
+ timestamp=timestamp,
519
+ )
@@ -0,0 +1,53 @@
1
+ """Conservative observation assessment, separate from process/task outcomes.
2
+
3
+ No inferred writer, nonempty sidecar, or zero exit code proves capture completeness.
4
+ These assessments describe declared evidence, not an adversary-resistant archive.
5
+ """
6
+ from __future__ import annotations
7
+
8
+ from typing import Any
9
+
10
+ SCHEMA_VERSION = "0.1"
11
+
12
+
13
+ def assess_observation(*, specialized: int, finished: bool, unknown_files: int, missing_snapshots: int,
14
+ short_lived_loss_possible: bool | None,
15
+ filesystem_enabled: bool | None,
16
+ warning_codes: set[str]) -> dict[str, Any]:
17
+ reasons = set(warning_codes)
18
+ if unknown_files:
19
+ reasons.add("unknown_file_writer")
20
+ if missing_snapshots:
21
+ reasons.add("file_snapshot_not_captured")
22
+ if short_lived_loss_possible is True:
23
+ reasons.add("short_lived_process_loss_possible")
24
+ elif short_lived_loss_possible is None:
25
+ reasons.add("process_coverage_unverified")
26
+ if filesystem_enabled is False:
27
+ reasons.add("filesystem_collection_disabled")
28
+ if finished and specialized == 0:
29
+ reasons.add("zero_specialized_evidence")
30
+ if not finished:
31
+ reasons.add("terminal_evidence_missing")
32
+ # Even a gap-free declared inventory does not establish end-to-end recall.
33
+ return {
34
+ "schema_version": SCHEMA_VERSION,
35
+ "state": "observation_incomplete" if reasons else "not_verified",
36
+ "reasons": sorted(reasons),
37
+ "specialized_evidence": specialized,
38
+ "unknown_owner_files": unknown_files,
39
+ "files_with_uncaptured_snapshots": missing_snapshots,
40
+ "short_lived_process_loss_possible": short_lived_loss_possible,
41
+ "missed_process_lower_bound": None,
42
+ "end_to_end_completeness_proven": False,
43
+ "scope": "declared_evidence",
44
+ }
45
+
46
+
47
+ def session_outcome(execution: dict[str, Any], observation: dict[str, Any]) -> dict[str, Any]:
48
+ result = dict(execution)
49
+ result["execution_state"] = execution.get("state", "unknown")
50
+ result["observation_state"] = observation["state"]
51
+ if execution.get("recorder_finished") is True and observation["state"] == "observation_incomplete":
52
+ result["state"] = "observation_incomplete"
53
+ return result
@@ -0,0 +1,69 @@
1
+ """A local negative observation example; no provider, credentials, or elevation.
2
+
3
+ Run from an installed wheel with ``python -m execweave.observation_demo``.
4
+ The task and its independent assertions pass, but observation remains incomplete.
5
+ """
6
+ from __future__ import annotations
7
+
8
+ import argparse
9
+ import json
10
+ import sys
11
+ from pathlib import Path
12
+
13
+ from .live import run_live
14
+
15
+ _WORKLOAD = '''from pathlib import Path
16
+ import subprocess, sys
17
+ source = "print(' '.join(str(n) for n in range(2, 30) if all(n % d for d in range(2, n))))\\n"
18
+ Path('primes.py').write_text(source, encoding='utf-8')
19
+ result = subprocess.run([sys.executable, 'primes.py'], capture_output=True, text=True, check=True)
20
+ Path('output.txt').write_text(result.stdout, encoding='utf-8')
21
+ '''
22
+ _EXPECTED = "2 3 5 7 11 13 17 19 23 29"
23
+
24
+
25
+ def run_example(root: Path) -> dict:
26
+ # The example may create its own directory, never reuse a user's prior run.
27
+ root = root.expanduser().absolute()
28
+ root.mkdir(parents=True, exist_ok=False)
29
+ result = run_live([sys.executable, "-c", _WORKLOAD], watch_root=root, output_dir=root,
30
+ open_browser=False, linger_seconds=0, collect_network=False)
31
+ output = root / "output.txt"
32
+ verified = result.return_code == 0 and output.is_file() and output.read_text().strip() == _EXPECTED
33
+ graph = json.loads(result.graph.read_text(encoding="utf-8"))
34
+ observation = graph["observation_assessment"]
35
+ final = json.loads((root / "finalization.json").read_text(encoding="utf-8"))
36
+ expected_failure = (observation["state"] == "observation_incomplete"
37
+ and {"unknown_file_writer", "file_snapshot_not_captured"}
38
+ <= set(observation["reasons"])
39
+ and final["observation_assessment"] == observation)
40
+ return {
41
+ "example": "successful_task_incomplete_observation", "uses_real_provider": False,
42
+ "ordinary_exit_only_trace": "success" if result.return_code == 0 else "failure",
43
+ "execution": {"return_code": result.return_code, "state": graph["session_outcome"]["execution_state"]},
44
+ "independent_example_task_verification": {"state": "passed" if verified else "failed",
45
+ "method": "exact_expected_primes_output", "expected": _EXPECTED,
46
+ "scope": "This example's assertion, not a general task verifier."},
47
+ "observation": observation,
48
+ "observation_acceptance": "FAIL" if observation["state"] == "observation_incomplete" else "NOT_VERIFIED",
49
+ "example_reproduced": verified and expected_failure,
50
+ "graph": str(result.graph), "viewer": str(result.viewer),
51
+ }
52
+
53
+
54
+ def main(argv: list[str] | None = None) -> int:
55
+ parser = argparse.ArgumentParser(description=__doc__)
56
+ parser.add_argument("--output-dir", type=Path, required=True, help="New directory; must not exist")
57
+ args = parser.parse_args(argv)
58
+ try:
59
+ report = run_example(args.output_dir)
60
+ except (OSError, ValueError) as exc:
61
+ print(json.dumps({"example_reproduced": False, "environment_error": type(exc).__name__}))
62
+ return 2
63
+ print(json.dumps(report, indent=2, sort_keys=True))
64
+ # Zero here says that the negative example reproduced; it is not observation PASS.
65
+ return 0 if report["example_reproduced"] else 1
66
+
67
+
68
+ if __name__ == "__main__":
69
+ raise SystemExit(main())