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,31 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+ from typing import Any
5
+
6
+ from .conversation_preview_common import (
7
+ _agent_identity,
8
+ _line_transcript_messages,
9
+ finish_transcript_preview,
10
+ )
11
+
12
+
13
+ def conversation_preview(
14
+ path: str | Path,
15
+ *,
16
+ content_kind: str,
17
+ provider: str,
18
+ source: dict[str, Any] | None,
19
+ timestamp: object = None,
20
+ ordinal: object = None,
21
+ ) -> dict[str, Any] | None:
22
+ del content_kind
23
+ source_path = Path(path).expanduser().resolve(strict=False)
24
+ identity = _agent_identity(provider, source)
25
+ messages = _line_transcript_messages(
26
+ source_path,
27
+ timestamp=timestamp,
28
+ ordinal=ordinal,
29
+ agent_path=str(identity["agent_path"]),
30
+ )
31
+ return finish_transcript_preview(identity, messages, preserve_history=False)
@@ -0,0 +1,107 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+ from typing import Any
5
+
6
+ from .agent_topology import (
7
+ COMPLETENESS_PROVIDER_TRANSCRIPT,
8
+ COMPLETENESS_ROUTING_ONLY,
9
+ EVIDENCE_CROSS_AGENT_ROUTING,
10
+ PATH_EXECWEAVE_DERIVED,
11
+ PATH_PROVIDER_DECLARED,
12
+ ROOT_PATH,
13
+ THREAD_ID_PROVIDER_NATIVE,
14
+ TOPOLOGY_OBSERVED,
15
+ TOPOLOGY_PROVIDER_REPORTED,
16
+ )
17
+ from .codex_conversation import codex_rollout_previews
18
+ from .conversation_preview_common import _agent_identity, _provider_label
19
+
20
+
21
+ def _codex_preview(
22
+ preview: dict[str, Any],
23
+ identity: dict[str, Any],
24
+ provider: str,
25
+ ) -> dict[str, Any]:
26
+ """Wrap one agent-local Codex thread in the shared dashboard conversation schema.
27
+
28
+ Codex is the one provider that publishes agent paths itself, on rollout
29
+ ``session_meta`` and on ``SubAgentActivity``. Those paths are marked
30
+ provider-declared; a thread carried only by the parent's routing records is marked
31
+ routing-only so it cannot be read as the child's own transcript.
32
+ """
33
+ agent_path = preview.get("agent_path")
34
+ routing_only = preview.get("evidence_scope") == EVIDENCE_CROSS_AGENT_ROUTING
35
+ result = {
36
+ **identity,
37
+ **preview,
38
+ "provider_label": _provider_label(provider),
39
+ "agent_label": preview.get("agent_nickname") or identity["agent_label"],
40
+ }
41
+ if preview.get("thread_id_source") is None and preview.get("thread_id"):
42
+ result["thread_id_source"] = THREAD_ID_PROVIDER_NATIVE
43
+
44
+ thread_id = result.get("thread_id")
45
+ if (
46
+ result.get("thread_id_source") == THREAD_ID_PROVIDER_NATIVE
47
+ and isinstance(thread_id, str)
48
+ and thread_id
49
+ ):
50
+ result["provider_native_id"] = thread_id
51
+ elif routing_only:
52
+ agent_id = preview.get("agent_id")
53
+ result["provider_native_id"] = (
54
+ agent_id if isinstance(agent_id, str) and agent_id else None
55
+ )
56
+
57
+ if isinstance(agent_path, str) and agent_path:
58
+ is_root = agent_path == ROOT_PATH
59
+ result["agent_path"] = agent_path
60
+ result["is_root"] = is_root
61
+ incoming_source = preview.get("agent_path_source")
62
+ if incoming_source in {PATH_EXECWEAVE_DERIVED, PATH_PROVIDER_DECLARED}:
63
+ result["agent_path_source"] = incoming_source
64
+ else:
65
+ result["agent_path_source"] = (
66
+ PATH_EXECWEAVE_DERIVED if is_root else PATH_PROVIDER_DECLARED
67
+ )
68
+ result["topology_state"] = (
69
+ TOPOLOGY_OBSERVED
70
+ if result["agent_path_source"] == PATH_PROVIDER_DECLARED and not is_root
71
+ else TOPOLOGY_PROVIDER_REPORTED
72
+ )
73
+ result["parent_agent_path"] = None if is_root else ROOT_PATH
74
+ result["parent_relation_source"] = (
75
+ None if is_root else preview.get("evidence_scope") or identity.get("topology_evidence")
76
+ )
77
+ if not is_root:
78
+ result["agent_label"] = (
79
+ preview.get("agent_nickname") or agent_path.rsplit("/", 1)[-1] or agent_path
80
+ )
81
+ result["conversation_completeness"] = (
82
+ COMPLETENESS_ROUTING_ONLY if routing_only else COMPLETENESS_PROVIDER_TRANSCRIPT
83
+ )
84
+ result["message_count"] = len(result.get("messages") or [])
85
+ return result
86
+
87
+
88
+ def conversation_preview(
89
+ path: str | Path,
90
+ *,
91
+ content_kind: str,
92
+ provider: str,
93
+ source: dict[str, Any] | None,
94
+ timestamp: object = None,
95
+ ordinal: object = None,
96
+ ) -> dict[str, Any] | None:
97
+ del content_kind, timestamp, ordinal
98
+ source_path = Path(path).expanduser().resolve(strict=False)
99
+ previews = codex_rollout_previews(source_path, preserve_history=True)
100
+ if not previews:
101
+ return None
102
+ identity = _agent_identity(provider, source)
103
+ result = _codex_preview(previews[0], identity, provider)
104
+ derived = [_codex_preview(preview, identity, provider) for preview in previews[1:]]
105
+ if derived:
106
+ result["derived_agent_previews"] = derived
107
+ return result
@@ -0,0 +1,180 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+ from typing import Any
5
+
6
+ from .agent_topology import (
7
+ THREAD_ID_EXECWEAVE_DERIVED,
8
+ THREAD_ID_PROVIDER_NATIVE,
9
+ PATH_PROVIDER_DECLARED,
10
+ TOPOLOGY_OBSERVED,
11
+ resolve_agent_topology,
12
+ )
13
+ from .conversation_preview_generic import ( # noqa: F401
14
+ _generic_content_messages,
15
+ _response_messages,
16
+ _routed_agent_message,
17
+ finish_transcript_preview,
18
+ )
19
+ from .conversation_preview_lines import ( # noqa: F401
20
+ _line_transcript_messages,
21
+ _structured_messages,
22
+ )
23
+ from .conversation_preview_transcript import ( # noqa: F401
24
+ _ANTIGRAVITY_USER_REQUEST_RE,
25
+ _ASSISTANT_FINAL_KINDS,
26
+ _ASSISTANT_RESPONSE_KINDS,
27
+ _SUBAGENT_SUMMARY_KINDS,
28
+ _SUBAGENT_TASK_KINDS,
29
+ _USER_KINDS,
30
+ _antigravity_inbound_message_text,
31
+ _antigravity_send_message_text,
32
+ _antigravity_user_text,
33
+ _text_parts,
34
+ )
35
+
36
+ _MAX_PREVIEW_MESSAGES = 80
37
+ _MAX_PREVIEW_TEXT_CHARS = 6000
38
+
39
+ _PROVIDER_LABELS = {
40
+ "claude": "Claude Code",
41
+ "codex": "OpenAI Codex",
42
+ "cursor": "Cursor",
43
+ "opencode": "OpenCode",
44
+ "antigravity": "Antigravity",
45
+ "anthropic": "Anthropic",
46
+ "openrouter": "OpenRouter",
47
+ "litellm": "LiteLLM",
48
+ "ollama": "Ollama",
49
+ "llamacpp": "llama.cpp",
50
+ "vllm": "vLLM",
51
+ "lmstudio": "LM Studio",
52
+ "openai-compatible": "OpenAI-compatible",
53
+ "openai_compatible": "OpenAI-compatible",
54
+ }
55
+
56
+
57
+ def _trim_text(value: str) -> str:
58
+ value = value.strip()
59
+ if len(value) <= _MAX_PREVIEW_TEXT_CHARS:
60
+ return value
61
+ return value[: _MAX_PREVIEW_TEXT_CHARS - 1] + "…"
62
+
63
+
64
+ def _read_value(path: Path) -> Any:
65
+ try:
66
+ text = path.read_text(encoding="utf-8")
67
+ except (OSError, UnicodeError):
68
+ return None
69
+ if path.suffix.lower() == ".json":
70
+ import json
71
+
72
+ try:
73
+ return json.loads(text)
74
+ except json.JSONDecodeError:
75
+ return text
76
+ return text
77
+
78
+
79
+ def _provider_label(provider: str) -> str:
80
+ normalized = provider.strip().lower()
81
+ return _PROVIDER_LABELS.get(normalized, provider or "Provider")
82
+
83
+
84
+ def _source_attributes(source: dict[str, Any] | None) -> dict[str, Any]:
85
+ if not isinstance(source, dict):
86
+ return {}
87
+ attrs = source.get("attributes")
88
+ return attrs if isinstance(attrs, dict) else {}
89
+
90
+
91
+ def _agent_identity(provider: str, source: dict[str, Any] | None) -> dict[str, Any]:
92
+ source = source if isinstance(source, dict) else {}
93
+ attrs = _source_attributes(source)
94
+ source_id = source.get("id")
95
+ source_name = source.get("name")
96
+ source_id_text = source_id if isinstance(source_id, str) else ""
97
+ provider_label = _provider_label(provider)
98
+ provider_key = provider.lower() or "provider"
99
+ if attrs.get("conversation_scope") == "framework_agent":
100
+ native_id = str(attrs.get("conversation_agent_id") or source_id_text or "agent")
101
+ agent_path = attrs.get("conversation_agent_path")
102
+ if not isinstance(agent_path, str) or not agent_path.strip():
103
+ agent_path = f"/{provider_key}/{native_id}"
104
+ label = source_name or attrs.get("conversation_agent_name") or native_id
105
+ return {
106
+ "thread_id": f"{provider_key}:agent:{native_id}",
107
+ "thread_id_source": THREAD_ID_PROVIDER_NATIVE,
108
+ "parent_thread_id": None,
109
+ "agent_label": str(label),
110
+ "provider_label": provider_label,
111
+ "agent_nickname": None,
112
+ "agent_path": agent_path,
113
+ "agent_path_source": PATH_PROVIDER_DECLARED,
114
+ "topology_state": TOPOLOGY_OBSERVED,
115
+ "topology_evidence": "framework_agent_boundary",
116
+ "parent_agent_path": None,
117
+ "parent_relation_source": None,
118
+ "provider_native_id": native_id,
119
+ "is_root": False,
120
+ }
121
+ topology = resolve_agent_topology(source)
122
+ agent_path = topology.agent_path
123
+ is_root = topology.is_root
124
+ native_label = (
125
+ attrs.get("agent_nickname")
126
+ or attrs.get("agent_type")
127
+ or attrs.get("subagent_type")
128
+ or attrs.get("native_agent_name")
129
+ or source_name
130
+ )
131
+ if is_root:
132
+ agent_label = provider_label
133
+ elif isinstance(native_label, str) and native_label.strip():
134
+ agent_label = native_label.strip()
135
+ else:
136
+ agent_label = agent_path.rsplit("/", 1)[-1] or "Agent"
137
+ if is_root:
138
+ thread_id = f"{provider_key}:root"
139
+ parent_thread_id = None
140
+ else:
141
+ thread_id = f"{provider_key}:{source_id_text or agent_path}"
142
+ parent_thread_id = f"{provider_key}:root"
143
+ return {
144
+ "thread_id": thread_id,
145
+ "thread_id_source": THREAD_ID_EXECWEAVE_DERIVED,
146
+ "parent_thread_id": parent_thread_id,
147
+ "agent_label": agent_label,
148
+ "provider_label": provider_label,
149
+ "agent_nickname": (
150
+ attrs.get("agent_nickname")
151
+ if isinstance(attrs.get("agent_nickname"), str)
152
+ else None
153
+ ),
154
+ **topology.to_dict(),
155
+ }
156
+
157
+
158
+ def _message(
159
+ *,
160
+ timestamp: object,
161
+ ordinal: object,
162
+ kind: str,
163
+ sender: str | None,
164
+ recipient: str | None,
165
+ text: str | None,
166
+ phase: str | None = None,
167
+ task_name: str | None = None,
168
+ content_state: str = "plaintext",
169
+ ) -> dict[str, Any]:
170
+ return {
171
+ "timestamp": timestamp if isinstance(timestamp, str) else None,
172
+ "ordinal": ordinal if isinstance(ordinal, int) and not isinstance(ordinal, bool) else None,
173
+ "kind": kind,
174
+ "sender": sender,
175
+ "recipient": recipient,
176
+ "text": _trim_text(text) if isinstance(text, str) and text.strip() else None,
177
+ "content_state": content_state,
178
+ "phase": phase,
179
+ "task_name": task_name,
180
+ }
@@ -0,0 +1,188 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+ from typing import Any
5
+
6
+ from .agent_topology import COMPLETENESS_PROVIDER_TRANSCRIPT
7
+ from .conversation_preview_lines import _structured_messages
8
+ from .conversation_preview_transcript import (
9
+ _ASSISTANT_FINAL_KINDS,
10
+ _ASSISTANT_RESPONSE_KINDS,
11
+ _MAX_PREVIEW_MESSAGES,
12
+ _SUBAGENT_SUMMARY_KINDS,
13
+ _SUBAGENT_TASK_KINDS,
14
+ _USER_KINDS,
15
+ _message,
16
+ _text_parts,
17
+ )
18
+
19
+
20
+ def _response_messages(
21
+ value: object,
22
+ *,
23
+ timestamp: object,
24
+ ordinal: object,
25
+ agent_path: str,
26
+ ) -> list[dict[str, Any]]:
27
+ if isinstance(value, dict):
28
+ direct = value.get("message")
29
+ if isinstance(direct, dict):
30
+ messages = _structured_messages(direct, timestamp=timestamp, ordinal=ordinal, agent_path=agent_path)
31
+ if messages:
32
+ return messages
33
+ choices = value.get("choices")
34
+ if isinstance(choices, list):
35
+ nested = [choice.get("message") for choice in choices if isinstance(choice, dict) and isinstance(choice.get("message"), dict)]
36
+ messages = _structured_messages(nested, timestamp=timestamp, ordinal=ordinal, agent_path=agent_path)
37
+ if messages:
38
+ return messages
39
+ output = value.get("output")
40
+ if isinstance(output, list):
41
+ messages = _structured_messages(output, timestamp=timestamp, ordinal=ordinal, agent_path=agent_path)
42
+ if messages:
43
+ return messages
44
+ text = _text_parts(value.get("content"))
45
+ if text:
46
+ return [_message(timestamp=timestamp, ordinal=ordinal, kind="assistant_message", sender=agent_path, recipient=None, text=text, phase="response")]
47
+ text = _text_parts(value)
48
+ if text:
49
+ return [_message(timestamp=timestamp, ordinal=ordinal, kind="assistant_message", sender=agent_path, recipient=None, text=text, phase="response")]
50
+ return []
51
+
52
+
53
+ def _routed_agent_message(
54
+ value: object,
55
+ *,
56
+ timestamp: object,
57
+ ordinal: object,
58
+ agent_path: str,
59
+ ) -> list[dict[str, Any]]:
60
+ if not isinstance(value, dict):
61
+ return []
62
+ text = _text_parts(value.get("text") or value.get("content") or value.get("message"))
63
+ if not text:
64
+ return []
65
+ sender = value.get("sender")
66
+ recipient = value.get("recipient")
67
+ if recipient is None and isinstance(value.get("recipients"), list):
68
+ recipient = ", ".join(
69
+ str(item).strip()
70
+ for item in value["recipients"]
71
+ if str(item).strip()
72
+ ) or None
73
+ kind = value.get("kind")
74
+ phase = value.get("phase")
75
+ task_name = value.get("task_name")
76
+ content_state = value.get("content_state")
77
+ message = _message(
78
+ timestamp=timestamp,
79
+ ordinal=ordinal,
80
+ kind=kind if isinstance(kind, str) and kind else "agent_message",
81
+ sender=sender if isinstance(sender, str) and sender else agent_path,
82
+ recipient=recipient if isinstance(recipient, str) and recipient else None,
83
+ text=text,
84
+ phase=phase if isinstance(phase, str) and phase else None,
85
+ task_name=task_name if isinstance(task_name, str) and task_name else None,
86
+ content_state=content_state if isinstance(content_state, str) and content_state else "plaintext",
87
+ )
88
+ if isinstance(value.get("message_id"), str):
89
+ message["message_id"] = value["message_id"]
90
+ return [message]
91
+
92
+
93
+ def _generic_content_messages(
94
+ value: object,
95
+ *,
96
+ content_kind: str,
97
+ timestamp: object,
98
+ ordinal: object,
99
+ identity: dict[str, Any],
100
+ ) -> list[dict[str, Any]]:
101
+ kind = content_kind.lower()
102
+ agent_path = str(identity["agent_path"])
103
+ if "assistant_content_blocks" in kind or "response_object" in kind or "standard_logging_response" in kind or kind == "inference_gateway.openrouter.response":
104
+ return _response_messages(value, timestamp=timestamp, ordinal=ordinal, agent_path=agent_path)
105
+ if "request_messages" in kind or "assistant_messages" in kind or "request_input" in kind or "inference_message" in kind or "user_message_parts" in kind:
106
+ structured = _structured_messages(value, timestamp=timestamp, ordinal=ordinal, agent_path=agent_path)
107
+ if structured:
108
+ return structured
109
+ if "agent_message" in kind:
110
+ routed = _routed_agent_message(value, timestamp=timestamp, ordinal=ordinal, agent_path=agent_path)
111
+ if routed:
112
+ return routed
113
+ if "model_request" in kind or "model_response" in kind or "model_failure" in kind:
114
+ if "model_response" in kind:
115
+ response = _response_messages(value, timestamp=timestamp, ordinal=ordinal, agent_path=agent_path)
116
+ if response:
117
+ return response
118
+ structured = _structured_messages(value, timestamp=timestamp, ordinal=ordinal, agent_path=agent_path)
119
+ if structured:
120
+ return structured
121
+ text = _text_parts(value)
122
+ if text:
123
+ if "model_request" in kind:
124
+ return [_message(timestamp=timestamp, ordinal=ordinal, kind="model_request", sender="context", recipient=agent_path, text=text, phase="request")]
125
+ return [_message(timestamp=timestamp, ordinal=ordinal, kind="assistant_message", sender=agent_path, recipient=None, text=text, phase="response")]
126
+ text = _text_parts(value)
127
+ if not text:
128
+ return []
129
+ if any(token in kind for token in _USER_KINDS):
130
+ return [_message(timestamp=timestamp, ordinal=ordinal, kind=("user_prompt_candidate" if "prompt_submission_candidate" in kind else "user_message"), sender="user", recipient=agent_path, text=text)]
131
+ if "agent_response_candidate" in kind:
132
+ return [_message(timestamp=timestamp, ordinal=ordinal, kind="assistant_response_candidate", sender=agent_path, recipient=None, text=text, phase="candidate")]
133
+ if any(token in kind for token in _ASSISTANT_FINAL_KINDS):
134
+ child = not bool(identity.get("is_root"))
135
+ return [_message(timestamp=timestamp, ordinal=ordinal, kind="subagent_final_response" if child else "assistant_message", sender=agent_path, recipient="/root" if child else None, text=text, phase="final_answer")]
136
+ if any(token in kind for token in _ASSISTANT_RESPONSE_KINDS):
137
+ return [_message(timestamp=timestamp, ordinal=ordinal, kind="assistant_message", sender=agent_path, recipient=None, text=text, phase="response")]
138
+ if "agent_message" in kind:
139
+ return [_message(timestamp=timestamp, ordinal=ordinal, kind="agent_message", sender=agent_path, recipient=None, text=text)]
140
+ if any(token in kind for token in _SUBAGENT_TASK_KINDS):
141
+ return [_message(timestamp=timestamp, ordinal=ordinal, kind="task", sender="/root", recipient=agent_path, text=text)]
142
+ if any(token in kind for token in _SUBAGENT_SUMMARY_KINDS):
143
+ return [_message(timestamp=timestamp, ordinal=ordinal, kind="assistant_summary", sender=agent_path, recipient="/root", text=text)]
144
+ return []
145
+
146
+
147
+ def finish_transcript_preview(
148
+ identity: dict[str, Any],
149
+ messages: list[dict[str, Any]],
150
+ *,
151
+ preserve_history: bool = False,
152
+ ) -> dict[str, Any] | None:
153
+ if not messages:
154
+ return None
155
+ truncated = not preserve_history and len(messages) > _MAX_PREVIEW_MESSAGES
156
+ if truncated:
157
+ messages = messages[:10] + messages[-(_MAX_PREVIEW_MESSAGES - 10) :]
158
+ return {
159
+ **identity,
160
+ "conversation_completeness": COMPLETENESS_PROVIDER_TRANSCRIPT,
161
+ "message_count": len(messages),
162
+ "messages_truncated": truncated,
163
+ "messages": messages,
164
+ }
165
+
166
+
167
+ def conversation_preview(
168
+ path: str | Path,
169
+ *,
170
+ content_kind: str,
171
+ provider: str,
172
+ source: dict[str, Any] | None,
173
+ timestamp: object = None,
174
+ ordinal: object = None,
175
+ ) -> dict[str, Any] | None:
176
+ from .conversation_preview_common import _agent_identity, _read_value
177
+
178
+ source_path = Path(path).expanduser().resolve(strict=False)
179
+ identity = _agent_identity(provider, source)
180
+ value = _read_value(source_path)
181
+ messages = _generic_content_messages(
182
+ value,
183
+ content_kind=content_kind,
184
+ timestamp=timestamp,
185
+ ordinal=ordinal,
186
+ identity=identity,
187
+ )
188
+ return finish_transcript_preview(identity, messages, preserve_history=False)
@@ -0,0 +1,133 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ from pathlib import Path
5
+ from typing import Any
6
+
7
+ from .conversation_preview_transcript import (
8
+ _antigravity_inbound_message_text,
9
+ _antigravity_send_message_text,
10
+ _antigravity_user_text,
11
+ _message,
12
+ _text_parts,
13
+ )
14
+
15
+
16
+ def _structured_messages(
17
+ value: object,
18
+ *,
19
+ timestamp: object,
20
+ ordinal: object,
21
+ agent_path: str,
22
+ ) -> list[dict[str, Any]]:
23
+ candidates: list[dict[str, Any]] = []
24
+ if isinstance(value, dict):
25
+ if isinstance(value.get("message"), dict):
26
+ candidates.append(value["message"])
27
+ if isinstance(value.get("messages"), list):
28
+ for item in value["messages"]:
29
+ if isinstance(item, dict):
30
+ if isinstance(item.get("message"), dict):
31
+ candidates.append(item["message"])
32
+ elif any(key in item for key in ("role", "content", "text")):
33
+ candidates.append(item)
34
+ elif any(key in value for key in ("role", "content", "text")):
35
+ candidates.append(value)
36
+ elif isinstance(value, list):
37
+ for item in value:
38
+ if isinstance(item, dict):
39
+ if isinstance(item.get("message"), dict):
40
+ candidates.append(item["message"])
41
+ elif any(key in item for key in ("role", "content", "text")):
42
+ candidates.append(item)
43
+ messages: list[dict[str, Any]] = []
44
+ for item in candidates:
45
+ role = str(item.get("role") or "").lower()
46
+ if role in {"system", "developer", "tool", "function"}:
47
+ continue
48
+ text = _text_parts(item.get("content")) or _text_parts(item.get("text"))
49
+ if not text:
50
+ continue
51
+ sender = item.get("source") or item.get("sender")
52
+ recipient = item.get("recipient") or item.get("target")
53
+ if recipient is None and isinstance(item.get("recipients"), list):
54
+ recipient = ", ".join(
55
+ str(value).strip()
56
+ for value in item["recipients"]
57
+ if str(value).strip()
58
+ ) or None
59
+ sender = sender.strip() if isinstance(sender, str) and sender.strip() else None
60
+ recipient = recipient.strip() if isinstance(recipient, str) and recipient.strip() else None
61
+ if role in {"user", "human"}:
62
+ messages.append(_message(timestamp=timestamp, ordinal=ordinal, kind="user_message", sender=sender or "user", recipient=recipient or agent_path, text=text))
63
+ elif role in {"assistant", "model", "agent"}:
64
+ messages.append(_message(timestamp=timestamp, ordinal=ordinal, kind="assistant_message", sender=sender or agent_path, recipient=recipient, text=text, phase="response"))
65
+ return messages
66
+
67
+
68
+ def _line_transcript_messages(
69
+ path: Path,
70
+ *,
71
+ timestamp: object,
72
+ ordinal: object,
73
+ agent_path: str,
74
+ antigravity: bool = False,
75
+ ) -> list[dict[str, Any]]:
76
+ messages: list[dict[str, Any]] = []
77
+ try:
78
+ lines = path.read_text(encoding="utf-8").splitlines()
79
+ except (OSError, UnicodeError):
80
+ return []
81
+ for index, line in enumerate(lines):
82
+ if not line.strip():
83
+ continue
84
+ try:
85
+ record = json.loads(line)
86
+ except json.JSONDecodeError:
87
+ continue
88
+ if not isinstance(record, dict):
89
+ continue
90
+ if antigravity:
91
+ role = str(record.get("source") or "").strip().lower()
92
+ record_type = str(record.get("type") or "").strip().lower()
93
+ text = _text_parts(record.get("content") or record.get("text"))
94
+ record_timestamp = record.get("created_at") or record.get("timestamp") or timestamp
95
+ step_index = record.get("step_index")
96
+ record_ordinal = step_index if isinstance(step_index, int) and not isinstance(step_index, bool) else (ordinal if isinstance(ordinal, int) else 0) + index
97
+ if role in {"user_explicit", "user", "human"} and record_type in {"user_input", "user_message", ""}:
98
+ if text:
99
+ messages.append(_message(timestamp=record_timestamp, ordinal=record_ordinal, kind="user_message", sender="user", recipient=agent_path, text=_antigravity_user_text(text)))
100
+ continue
101
+ if role in {"model", "assistant"} and record_type == "planner_response":
102
+ outbound = _antigravity_send_message_text(record)
103
+ if outbound:
104
+ messages.append(_message(timestamp=record_timestamp, ordinal=record_ordinal, kind="assistant_message", sender=agent_path, recipient=None, text=outbound, phase="planner_response"))
105
+ continue
106
+ if text:
107
+ messages.append(_message(timestamp=record_timestamp, ordinal=record_ordinal, kind="assistant_message", sender=agent_path, recipient=None, text=text, phase="planner_response"))
108
+ continue
109
+ if role == "system" and record_type == "system_message":
110
+ inbound = _antigravity_inbound_message_text(text)
111
+ if inbound and agent_path != "/root":
112
+ messages.append(_message(timestamp=record_timestamp, ordinal=record_ordinal, kind="subagent_task", sender="user", recipient=agent_path, text=inbound, phase="assignment"))
113
+ continue
114
+ continue
115
+ record_timestamp = record.get("timestamp") or timestamp
116
+ record_ordinal = record.get("ordinal")
117
+ if not isinstance(record_ordinal, int):
118
+ record_ordinal = (ordinal if isinstance(ordinal, int) else 0) + index
119
+ record_type = str(record.get("type") or "").lower()
120
+ payload = record.get("message")
121
+ if isinstance(payload, dict):
122
+ role = str(payload.get("role") or record_type).lower()
123
+ text = _text_parts(payload.get("content"))
124
+ else:
125
+ role = record_type
126
+ text = _text_parts(record.get("content") or record.get("text"))
127
+ if not text:
128
+ continue
129
+ if role in {"user", "human"}:
130
+ messages.append(_message(timestamp=record_timestamp, ordinal=record_ordinal, kind="user_message", sender="user", recipient=agent_path, text=text))
131
+ elif role in {"assistant", "model"}:
132
+ messages.append(_message(timestamp=record_timestamp, ordinal=record_ordinal, kind="assistant_message", sender=agent_path, recipient=None, text=text, phase="response"))
133
+ return messages