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,42 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
|
|
5
|
+
_CALLBACK_PATH = "execweave.litellm_callback.execweave_litellm_callback"
|
|
6
|
+
_CONFIG = f"""litellm_settings:
|
|
7
|
+
callbacks: {_CALLBACK_PATH}
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def callback_path() -> str:
|
|
12
|
+
return _CALLBACK_PATH
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def config_fragment() -> str:
|
|
16
|
+
return _CONFIG
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
20
|
+
parser = argparse.ArgumentParser(
|
|
21
|
+
prog="execweave-litellm-callback",
|
|
22
|
+
description=(
|
|
23
|
+
"Print the LiteLLM Proxy callback configuration for privacy-safe ExecWeave routing telemetry."
|
|
24
|
+
),
|
|
25
|
+
)
|
|
26
|
+
action = parser.add_mutually_exclusive_group(required=True)
|
|
27
|
+
action.add_argument("--print-config", action="store_true")
|
|
28
|
+
action.add_argument("--print-callback", action="store_true")
|
|
29
|
+
return parser
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def main(argv: list[str] | None = None) -> int:
|
|
33
|
+
args = build_parser().parse_args(argv)
|
|
34
|
+
if args.print_callback:
|
|
35
|
+
print(callback_path())
|
|
36
|
+
else:
|
|
37
|
+
print(config_fragment(), end="")
|
|
38
|
+
return 0
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
raise SystemExit(main())
|
execweave/live.py
ADDED
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
import shutil
|
|
6
|
+
from collections import deque
|
|
7
|
+
|
|
8
|
+
from . import live_core as _core
|
|
9
|
+
from .conversation_records import conversation_index_payload
|
|
10
|
+
from .dashboard_shell import DASHBOARD_HTML
|
|
11
|
+
from .content_store import _filesystem_path
|
|
12
|
+
from .graph import logical_event_key
|
|
13
|
+
from .investigation_index import InvestigationCache
|
|
14
|
+
from .viewer_limits import resolve_viewer_limits
|
|
15
|
+
from .viewer_flow_layout import layers_of
|
|
16
|
+
from .viewer_projection import (
|
|
17
|
+
internal_hook_process_ids_in_event,
|
|
18
|
+
project_viewer_graph,
|
|
19
|
+
render_graph_html as _projected_render_graph_html,
|
|
20
|
+
strip_internal_hook_execution_graph,
|
|
21
|
+
write_graph_html as _projected_write_graph_html,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
# Re-export the established live API while keeping its implementation in live_core.
|
|
25
|
+
for _export_name in dir(_core):
|
|
26
|
+
if not _export_name.startswith("__"):
|
|
27
|
+
globals()[_export_name] = getattr(_core, _export_name)
|
|
28
|
+
del _export_name
|
|
29
|
+
|
|
30
|
+
# Make names referenced below explicit for static analysis as well as runtime use.
|
|
31
|
+
Path = _core.Path
|
|
32
|
+
_JsonlTail = _core._JsonlTail
|
|
33
|
+
LIVE_DELTA_HISTORY = _core.LIVE_DELTA_HISTORY
|
|
34
|
+
LIVE_DELTA_HISTORY_BYTES = _core.LIVE_DELTA_HISTORY_BYTES
|
|
35
|
+
VIEWER_MAX_NODES = _core.VIEWER_MAX_NODES
|
|
36
|
+
VIEWER_MAX_EDGES = _core.VIEWER_MAX_EDGES
|
|
37
|
+
VIEWER_MAX_DOM_ELEMENTS = _core.VIEWER_MAX_DOM_ELEMENTS
|
|
38
|
+
_BASE_LIVE_HTML = _core._LIVE_HTML
|
|
39
|
+
_LIVE_HTML = DASHBOARD_HTML
|
|
40
|
+
render_graph_html = _projected_render_graph_html
|
|
41
|
+
write_graph_html = _projected_write_graph_html
|
|
42
|
+
|
|
43
|
+
LIVE_RAW_EVENT_HISTORY = 640
|
|
44
|
+
LIVE_RAW_EVENT_STREAM_HISTORY = LIVE_RAW_EVENT_HISTORY // 2
|
|
45
|
+
_BaseLiveState = _core._LiveState
|
|
46
|
+
_base_inject_live_auth = _core._inject_live_auth
|
|
47
|
+
_base_inject_final_theme = _core._inject_final_theme
|
|
48
|
+
_base_build_execution_graph = _core.build_execution_graph
|
|
49
|
+
_base_handler_factory = _core._handler_factory
|
|
50
|
+
_RUN_CONTENT_ROUTE_RE = re.compile(r"^/content/sha256/[0-9a-f]{64}\.(?:json|txt|bin)$")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _within_live_payload_budget(node_count: int, edge_count: int) -> bool:
|
|
54
|
+
estimated_dom = node_count * 4 + edge_count * 3
|
|
55
|
+
max_nodes, max_edges, max_dom_elements = resolve_viewer_limits(
|
|
56
|
+
defaults=(VIEWER_MAX_NODES, VIEWER_MAX_EDGES, VIEWER_MAX_DOM_ELEMENTS)
|
|
57
|
+
)
|
|
58
|
+
return (
|
|
59
|
+
node_count <= max_nodes
|
|
60
|
+
and edge_count <= max_edges
|
|
61
|
+
and estimated_dom <= max_dom_elements
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _inject_live_auth(html: str) -> str:
|
|
66
|
+
authenticated = _base_inject_live_auth(html)
|
|
67
|
+
# Shared offline dashboard components can optionally use an API-token global.
|
|
68
|
+
# The live browser intentionally never receives that token; same-origin cookies
|
|
69
|
+
# authenticate these fetches instead. Remove the dead header branch from the
|
|
70
|
+
# served page so no future code can accidentally revive URL-token propagation.
|
|
71
|
+
return authenticated.replace(
|
|
72
|
+
"const headers={};if(window.__execweaveToken)headers['X-ExecWeave-Token']=window.__execweaveToken;",
|
|
73
|
+
"const headers={};",
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _inject_final_theme(html: str) -> str:
|
|
78
|
+
"""Honor the dashboard's built-in theme owner without injecting legacy controls."""
|
|
79
|
+
return _base_inject_final_theme(html)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _build_execution_graph_without_internal_hooks(*args, **kwargs):
|
|
83
|
+
return strip_internal_hook_execution_graph(_base_build_execution_graph(*args, **kwargs))
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _handler_factory(state, token: str, pairing=None):
|
|
87
|
+
base_handler = _base_handler_factory(state, token, pairing)
|
|
88
|
+
run_root = state.event_path.parent.resolve()
|
|
89
|
+
run_root_fs = _filesystem_path(run_root)
|
|
90
|
+
|
|
91
|
+
class Handler(base_handler):
|
|
92
|
+
def _live_conversation_index(self, *, include_investigation: bool = False) -> dict[str, object] | None:
|
|
93
|
+
project = getattr(state, "conversation_index", None)
|
|
94
|
+
if project is None:
|
|
95
|
+
return None
|
|
96
|
+
try:
|
|
97
|
+
return project(run_root, include_investigation=True) if include_investigation else project(run_root)
|
|
98
|
+
except (OSError, RuntimeError, ValueError):
|
|
99
|
+
return None
|
|
100
|
+
|
|
101
|
+
def _send_run_file(self, target: Path, content_type: str) -> None:
|
|
102
|
+
try:
|
|
103
|
+
size = target.stat().st_size
|
|
104
|
+
handle = target.open("rb")
|
|
105
|
+
except OSError:
|
|
106
|
+
self._send(b"Not found", "text/plain; charset=utf-8", 404)
|
|
107
|
+
return
|
|
108
|
+
with handle:
|
|
109
|
+
try:
|
|
110
|
+
self.send_response(200)
|
|
111
|
+
self.send_header("Content-Type", content_type)
|
|
112
|
+
self.send_header("Content-Length", str(size))
|
|
113
|
+
self.send_header("Cache-Control", "no-store")
|
|
114
|
+
self.send_header("X-Content-Type-Options", "nosniff")
|
|
115
|
+
self.send_header("Referrer-Policy", "no-referrer")
|
|
116
|
+
self.end_headers()
|
|
117
|
+
shutil.copyfileobj(handle, self.wfile, length=1024 * 1024)
|
|
118
|
+
except (BrokenPipeError, ConnectionResetError, ConnectionAbortedError):
|
|
119
|
+
self.close_connection = True
|
|
120
|
+
|
|
121
|
+
def do_GET(self) -> None:
|
|
122
|
+
parsed = _core.urlsplit(self.path)
|
|
123
|
+
request_path = parsed.path
|
|
124
|
+
run_artifact = (
|
|
125
|
+
request_path in {"/conversations.md", "/conversations.json"}
|
|
126
|
+
or request_path.startswith("/content/")
|
|
127
|
+
)
|
|
128
|
+
if not run_artifact:
|
|
129
|
+
super().do_GET()
|
|
130
|
+
return
|
|
131
|
+
if not self._authorized(parsed):
|
|
132
|
+
self._send(b"Unauthorized", "text/plain; charset=utf-8", 401)
|
|
133
|
+
return
|
|
134
|
+
if request_path.startswith("/content/") and not _RUN_CONTENT_ROUTE_RE.fullmatch(
|
|
135
|
+
request_path
|
|
136
|
+
):
|
|
137
|
+
self._send(b"Not found", "text/plain; charset=utf-8", 404)
|
|
138
|
+
return
|
|
139
|
+
relative = request_path.lstrip("/")
|
|
140
|
+
target = (run_root_fs / relative).resolve(strict=False)
|
|
141
|
+
try:
|
|
142
|
+
target.relative_to(run_root_fs)
|
|
143
|
+
except ValueError:
|
|
144
|
+
self._send(b"Not found", "text/plain; charset=utf-8", 404)
|
|
145
|
+
return
|
|
146
|
+
if not target.is_file():
|
|
147
|
+
payload = (
|
|
148
|
+
self._live_conversation_index(include_investigation=_core.parse_qs(parsed.query).get("investigation") == ["1"])
|
|
149
|
+
if request_path == "/conversations.json"
|
|
150
|
+
else None
|
|
151
|
+
)
|
|
152
|
+
if payload is None:
|
|
153
|
+
self._send(b"Not found", "text/plain; charset=utf-8", 404)
|
|
154
|
+
return
|
|
155
|
+
self._send(
|
|
156
|
+
json.dumps(payload, ensure_ascii=False, sort_keys=True).encode("utf-8"),
|
|
157
|
+
"application/json; charset=utf-8",
|
|
158
|
+
)
|
|
159
|
+
return
|
|
160
|
+
if request_path.endswith(".json"):
|
|
161
|
+
content_type = "application/json; charset=utf-8"
|
|
162
|
+
elif request_path.endswith(".md"):
|
|
163
|
+
content_type = "text/markdown; charset=utf-8"
|
|
164
|
+
elif request_path.endswith(".txt"):
|
|
165
|
+
content_type = "text/plain; charset=utf-8"
|
|
166
|
+
else:
|
|
167
|
+
content_type = "application/octet-stream"
|
|
168
|
+
self._send_run_file(target, content_type)
|
|
169
|
+
|
|
170
|
+
return Handler
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class _LiveState(_BaseLiveState):
|
|
174
|
+
def __init__(
|
|
175
|
+
self,
|
|
176
|
+
session_id: str,
|
|
177
|
+
event_path: Path,
|
|
178
|
+
semantic_path: Path | None = None,
|
|
179
|
+
) -> None:
|
|
180
|
+
super().__init__(session_id, event_path, semantic_path)
|
|
181
|
+
self._raw_events: deque[dict[str, object]] = deque(
|
|
182
|
+
maxlen=LIVE_RAW_EVENT_STREAM_HISTORY
|
|
183
|
+
)
|
|
184
|
+
self._raw_semantic_events: deque[dict[str, object]] = deque(
|
|
185
|
+
maxlen=LIVE_RAW_EVENT_STREAM_HISTORY
|
|
186
|
+
)
|
|
187
|
+
self._pending_raw_events: list[dict[str, object]] = []
|
|
188
|
+
self._raw_semantic_entries: dict[str, dict[str, object]] = {}
|
|
189
|
+
self._raw_semantic_entry_keys: dict[int, str] = {}
|
|
190
|
+
self._internal_hook_process_ids: set[str] = set()
|
|
191
|
+
self._viewer_projection_ever_active = False
|
|
192
|
+
self._investigation_cache = InvestigationCache()
|
|
193
|
+
|
|
194
|
+
def _reset_incremental_state_locked(self) -> None:
|
|
195
|
+
super()._reset_incremental_state_locked()
|
|
196
|
+
self._raw_events.clear()
|
|
197
|
+
self._raw_semantic_events.clear()
|
|
198
|
+
self._pending_raw_events.clear()
|
|
199
|
+
self._raw_semantic_entries.clear()
|
|
200
|
+
self._raw_semantic_entry_keys.clear()
|
|
201
|
+
self._internal_hook_process_ids.clear()
|
|
202
|
+
self._investigation_cache = InvestigationCache()
|
|
203
|
+
|
|
204
|
+
def _append_raw_entry_locked(
|
|
205
|
+
self,
|
|
206
|
+
*,
|
|
207
|
+
line_number: int,
|
|
208
|
+
event: dict[str, object],
|
|
209
|
+
stream: str,
|
|
210
|
+
semantic_key: str | None = None,
|
|
211
|
+
) -> None:
|
|
212
|
+
if semantic_key is not None:
|
|
213
|
+
existing = self._raw_semantic_entries.get(semantic_key)
|
|
214
|
+
if existing is not None and id(existing) in self._raw_semantic_entry_keys:
|
|
215
|
+
existing["last_line"] = line_number
|
|
216
|
+
existing["evidence_event_count"] = int(
|
|
217
|
+
existing.get("evidence_event_count", 1) or 1
|
|
218
|
+
) + 1
|
|
219
|
+
timestamp = event.get("timestamp")
|
|
220
|
+
if isinstance(timestamp, str) and timestamp:
|
|
221
|
+
existing["last_observed"] = timestamp
|
|
222
|
+
return
|
|
223
|
+
|
|
224
|
+
bucket = self._raw_semantic_events if stream == "semantic.jsonl" else self._raw_events
|
|
225
|
+
if len(bucket) == bucket.maxlen and bucket:
|
|
226
|
+
evicted = bucket[0]
|
|
227
|
+
evicted_key = self._raw_semantic_entry_keys.pop(id(evicted), None)
|
|
228
|
+
if evicted_key is not None:
|
|
229
|
+
self._raw_semantic_entries.pop(evicted_key, None)
|
|
230
|
+
entry: dict[str, object] = {
|
|
231
|
+
"line": line_number,
|
|
232
|
+
"stream": stream,
|
|
233
|
+
"event": event,
|
|
234
|
+
"evidence_event_count": 1,
|
|
235
|
+
}
|
|
236
|
+
bucket.append(entry)
|
|
237
|
+
self._pending_raw_events.append(entry)
|
|
238
|
+
if semantic_key is not None:
|
|
239
|
+
self._raw_semantic_entries[semantic_key] = entry
|
|
240
|
+
self._raw_semantic_entry_keys[id(entry)] = semantic_key
|
|
241
|
+
|
|
242
|
+
@staticmethod
|
|
243
|
+
def _event_entity_id(event: dict[str, object], key: str) -> str | None:
|
|
244
|
+
entity = event.get(key)
|
|
245
|
+
if not isinstance(entity, dict):
|
|
246
|
+
return None
|
|
247
|
+
value = entity.get("id")
|
|
248
|
+
return value if isinstance(value, str) and value else None
|
|
249
|
+
|
|
250
|
+
def _raw_event_snapshot_locked(self) -> list[dict[str, object]]:
|
|
251
|
+
rows = [*self._raw_events, *self._raw_semantic_events]
|
|
252
|
+
rows.sort(
|
|
253
|
+
key=lambda entry: (
|
|
254
|
+
str((entry.get("event") or {}).get("timestamp") or "")
|
|
255
|
+
if isinstance(entry.get("event"), dict)
|
|
256
|
+
else "",
|
|
257
|
+
str(entry.get("stream") or ""),
|
|
258
|
+
int(entry.get("line", 0) or 0),
|
|
259
|
+
)
|
|
260
|
+
)
|
|
261
|
+
return rows[-LIVE_RAW_EVENT_HISTORY:]
|
|
262
|
+
|
|
263
|
+
def _event_uses_internal_hook_process_locked(self, event: dict[str, object]) -> bool:
|
|
264
|
+
direct_ids = internal_hook_process_ids_in_event(event)
|
|
265
|
+
if direct_ids:
|
|
266
|
+
self._internal_hook_process_ids.update(direct_ids)
|
|
267
|
+
source_id = self._event_entity_id(event, "source")
|
|
268
|
+
target_id = self._event_entity_id(event, "target")
|
|
269
|
+
target = event.get("target")
|
|
270
|
+
if (
|
|
271
|
+
event.get("relation") == "SPAWNED"
|
|
272
|
+
and isinstance(source_id, str)
|
|
273
|
+
and source_id in self._internal_hook_process_ids
|
|
274
|
+
and isinstance(target, dict)
|
|
275
|
+
and target.get("type") == "process"
|
|
276
|
+
and isinstance(target_id, str)
|
|
277
|
+
):
|
|
278
|
+
self._internal_hook_process_ids.add(target_id)
|
|
279
|
+
return bool(
|
|
280
|
+
direct_ids
|
|
281
|
+
or (isinstance(source_id, str) and source_id in self._internal_hook_process_ids)
|
|
282
|
+
or (isinstance(target_id, str) and target_id in self._internal_hook_process_ids)
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
def _read_tail_records_locked(
|
|
286
|
+
self,
|
|
287
|
+
tail: _JsonlTail,
|
|
288
|
+
) -> list[tuple[int, dict[str, object]]]:
|
|
289
|
+
records = super()._read_tail_records_locked(tail)
|
|
290
|
+
if tail is self._runtime_tail:
|
|
291
|
+
for line_number, event in records:
|
|
292
|
+
if self._event_uses_internal_hook_process_locked(event):
|
|
293
|
+
continue
|
|
294
|
+
self._append_raw_entry_locked(
|
|
295
|
+
line_number=line_number,
|
|
296
|
+
event=event,
|
|
297
|
+
stream="events.jsonl",
|
|
298
|
+
)
|
|
299
|
+
elif tail is self._semantic_tail:
|
|
300
|
+
for line_number, event in records:
|
|
301
|
+
self._append_raw_entry_locked(
|
|
302
|
+
line_number=line_number,
|
|
303
|
+
event=event,
|
|
304
|
+
stream="semantic.jsonl",
|
|
305
|
+
semantic_key=logical_event_key(event),
|
|
306
|
+
)
|
|
307
|
+
return records
|
|
308
|
+
|
|
309
|
+
def _apply_live_event_locked(
|
|
310
|
+
self,
|
|
311
|
+
event: dict[str, object],
|
|
312
|
+
*,
|
|
313
|
+
added_nodes: set[str],
|
|
314
|
+
updated_nodes: set[str],
|
|
315
|
+
added_edges: set[tuple[str, str, str]],
|
|
316
|
+
updated_edges: set[tuple[str, str, str]],
|
|
317
|
+
) -> bool:
|
|
318
|
+
if self._event_uses_internal_hook_process_locked(event):
|
|
319
|
+
return False
|
|
320
|
+
return super()._apply_live_event_locked(
|
|
321
|
+
event,
|
|
322
|
+
added_nodes=added_nodes,
|
|
323
|
+
updated_nodes=updated_nodes,
|
|
324
|
+
added_edges=added_edges,
|
|
325
|
+
updated_edges=updated_edges,
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
def _raw_graph_locked(self) -> dict[str, object]:
|
|
329
|
+
return (
|
|
330
|
+
dict(self._final_graph)
|
|
331
|
+
if self._finished and self._final_graph is not None
|
|
332
|
+
else self._accumulator.to_dict()
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
def _projected_graph_locked(self) -> dict[str, object]:
|
|
336
|
+
# The columns from the previous tick are a floor, not a cache: new evidence may
|
|
337
|
+
# push a node further right, but a node already on screen never travels back to
|
|
338
|
+
# the left while the operator is reading it.
|
|
339
|
+
previous = getattr(self, "_flow_layers", None)
|
|
340
|
+
projected = project_viewer_graph(self._raw_graph_locked(), previous)
|
|
341
|
+
self._flow_layers = layers_of(projected)
|
|
342
|
+
if isinstance(projected.get("viewer_projection"), dict):
|
|
343
|
+
self._viewer_projection_ever_active = True
|
|
344
|
+
return projected
|
|
345
|
+
|
|
346
|
+
@staticmethod
|
|
347
|
+
def _projected_counts(graph: dict[str, object]) -> dict[str, object]:
|
|
348
|
+
return {
|
|
349
|
+
"event_count": int(graph.get("event_count", 0) or 0),
|
|
350
|
+
"node_count": int(graph.get("node_count", 0) or 0),
|
|
351
|
+
"edge_count": int(graph.get("edge_count", 0) or 0),
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
def _projected_snapshot_locked(
|
|
355
|
+
self,
|
|
356
|
+
projected: dict[str, object] | None = None,
|
|
357
|
+
) -> dict[str, object]:
|
|
358
|
+
graph = projected if projected is not None else self._projected_graph_locked()
|
|
359
|
+
node_count = int(graph.get("node_count", 0) or 0)
|
|
360
|
+
edge_count = int(graph.get("edge_count", 0) or 0)
|
|
361
|
+
return (
|
|
362
|
+
graph
|
|
363
|
+
if _within_live_payload_budget(node_count, edge_count)
|
|
364
|
+
else _core._compact_live_graph(graph)
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
def _snapshot_from_accumulator_locked(self) -> dict[str, object]:
|
|
368
|
+
return self._projected_snapshot_locked()
|
|
369
|
+
|
|
370
|
+
def conversation_index(self, run_root: Path, *, include_investigation: bool = False) -> dict[str, object]:
|
|
371
|
+
"""Build conversation ownership from observed evidence, never viewer-only collapse."""
|
|
372
|
+
with self._lock:
|
|
373
|
+
graph = self._raw_graph_locked()
|
|
374
|
+
return conversation_index_payload(graph, run_root, investigation_cache=self._investigation_cache,
|
|
375
|
+
include_investigation=include_investigation)
|
|
376
|
+
|
|
377
|
+
def _refresh_incremental_locked(self) -> None:
|
|
378
|
+
before_sequence = self._update_sequence
|
|
379
|
+
super()._refresh_incremental_locked()
|
|
380
|
+
if self._pending_raw_events and self._update_sequence == before_sequence:
|
|
381
|
+
counts = self._counts_locked()
|
|
382
|
+
self._append_update_locked(
|
|
383
|
+
{
|
|
384
|
+
**counts,
|
|
385
|
+
"event_count_delta": 0,
|
|
386
|
+
"evidence_event_count_delta": {"os_runtime": 0, "specialized": 0},
|
|
387
|
+
"nodes_added": [],
|
|
388
|
+
"nodes_updated": [],
|
|
389
|
+
"edges_added": [],
|
|
390
|
+
"edges_updated": [],
|
|
391
|
+
}
|
|
392
|
+
)
|
|
393
|
+
|
|
394
|
+
def _append_update_locked(self, update: dict[str, object]) -> None:
|
|
395
|
+
_core.LIVE_DELTA_HISTORY = LIVE_DELTA_HISTORY
|
|
396
|
+
_core.LIVE_DELTA_HISTORY_BYTES = LIVE_DELTA_HISTORY_BYTES
|
|
397
|
+
update.setdefault("raw_events_added", list(self._pending_raw_events))
|
|
398
|
+
super()._append_update_locked(update)
|
|
399
|
+
self._pending_raw_events.clear()
|
|
400
|
+
|
|
401
|
+
def snapshot(self) -> dict[str, object]:
|
|
402
|
+
payload = super().snapshot()
|
|
403
|
+
with self._lock:
|
|
404
|
+
payload["raw_events"] = self._raw_event_snapshot_locked()
|
|
405
|
+
return payload
|
|
406
|
+
|
|
407
|
+
def live_update(self, after: int | None) -> dict[str, object]:
|
|
408
|
+
payload = super().live_update(after)
|
|
409
|
+
with self._lock:
|
|
410
|
+
projected = self._projected_graph_locked()
|
|
411
|
+
if self._viewer_projection_ever_active:
|
|
412
|
+
counts = self._projected_counts(projected)
|
|
413
|
+
if payload.get("kind") == "delta":
|
|
414
|
+
payload = {
|
|
415
|
+
"kind": "snapshot",
|
|
416
|
+
"sequence": self._update_sequence,
|
|
417
|
+
"graph": self._projected_snapshot_locked(projected),
|
|
418
|
+
**self._evidence_metadata_locked(),
|
|
419
|
+
"live_finished": self._finished,
|
|
420
|
+
}
|
|
421
|
+
elif payload.get("kind") == "noop":
|
|
422
|
+
payload.update(counts)
|
|
423
|
+
if payload.get("kind") == "snapshot":
|
|
424
|
+
payload["raw_events"] = self._raw_event_snapshot_locked()
|
|
425
|
+
# The canvas description rides along with every update that carries state.
|
|
426
|
+
# A delta names the entities that changed; this names what to draw, so a
|
|
427
|
+
# newly folded node does not appear on screen until the next full snapshot.
|
|
428
|
+
flow = projected.get("viewer_flow")
|
|
429
|
+
if isinstance(flow, dict) and payload.get("kind") in {"snapshot", "delta"}:
|
|
430
|
+
payload["viewer_flow"] = flow
|
|
431
|
+
return payload
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
# Keep the extracted core on the latest presentation projection without rewriting
|
|
435
|
+
# its large implementation. run_live() resolves these globals at call time.
|
|
436
|
+
_core.render_graph_html = _projected_render_graph_html
|
|
437
|
+
_core.write_graph_html = _projected_write_graph_html
|
|
438
|
+
_core._inject_live_auth = _inject_live_auth
|
|
439
|
+
_core._inject_final_theme = _inject_final_theme
|
|
440
|
+
_core.build_execution_graph = _build_execution_graph_without_internal_hooks
|
|
441
|
+
_core._LiveState = _LiveState
|
|
442
|
+
_core._handler_factory = _handler_factory
|
|
443
|
+
_core._LIVE_HTML = _LIVE_HTML
|
|
444
|
+
_AUTHENTICATED_LIVE_HTML = _inject_live_auth(_LIVE_HTML)
|
|
445
|
+
_core._AUTHENTICATED_LIVE_HTML = _AUTHENTICATED_LIVE_HTML
|