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,200 @@
|
|
|
1
|
+
"""Conservative run assessment from declared graph metadata, without file I/O.
|
|
2
|
+
|
|
3
|
+
Process exit, native task reports, and content availability are different facts.
|
|
4
|
+
A task-completed event is not an independent test result. A well-formed content
|
|
5
|
+
reference is not proof that its bytes exist or that capture was exhaustive.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import re
|
|
10
|
+
|
|
11
|
+
from .task_validation import assessment_subjects
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
SCHEMA_VERSION = "0.1"
|
|
15
|
+
MAX_RECORDS = 100_000
|
|
16
|
+
_REFERENCE = re.compile(r"content/sha256/([0-9a-f]{64})\.(?:txt|json|bin)")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _object(value: Any) -> dict[str, Any]:
|
|
20
|
+
return value if isinstance(value, dict) else {}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _text(value: Any) -> str | None:
|
|
24
|
+
return value if isinstance(value, str) and value else None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _native(record: dict[str, Any]) -> bool:
|
|
28
|
+
attributes = _object(record.get("attributes"))
|
|
29
|
+
return not any(
|
|
30
|
+
scope.get(flag) is not None and scope.get(flag) is not False
|
|
31
|
+
for scope in (record, attributes)
|
|
32
|
+
for flag in ("inferred", "viewer_only")
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _execution(graph: dict[str, Any]) -> dict[str, Any]:
|
|
37
|
+
outcome = _object(graph.get("session_outcome"))
|
|
38
|
+
code = outcome.get("return_code")
|
|
39
|
+
code = code if type(code) is int else None
|
|
40
|
+
event_id = _text(outcome.get("event_id"))
|
|
41
|
+
result = {
|
|
42
|
+
"state": "unknown", "reason": "no_terminal_evidence", "return_code": code,
|
|
43
|
+
"event_id": event_id, "timestamp": _text(outcome.get("timestamp")),
|
|
44
|
+
"task_success_implied": False, "failure_domain": None,
|
|
45
|
+
}
|
|
46
|
+
if outcome.get("recorder_finished") is not True or event_id is None:
|
|
47
|
+
return result
|
|
48
|
+
if any(key in outcome and type(outcome[key]) is not bool
|
|
49
|
+
for key in ("collector_failed", "interrupted")):
|
|
50
|
+
result["reason"] = "invalid_terminal_metadata"
|
|
51
|
+
return result
|
|
52
|
+
state = (
|
|
53
|
+
"collector_failed" if outcome.get("collector_failed") is True else
|
|
54
|
+
"interrupted" if outcome.get("interrupted") is True else
|
|
55
|
+
"succeeded" if code == 0 else "failed" if code is not None else "unknown"
|
|
56
|
+
)
|
|
57
|
+
declared = outcome.get("execution_state", outcome.get("state"))
|
|
58
|
+
if declared not in (None, state):
|
|
59
|
+
result["reason"] = "conflicting_terminal_metadata"
|
|
60
|
+
return result
|
|
61
|
+
failure_domain = (
|
|
62
|
+
"environment" if state == "collector_failed" else
|
|
63
|
+
"operator" if state == "interrupted" else
|
|
64
|
+
"task" if state == "failed" else None
|
|
65
|
+
)
|
|
66
|
+
result.update(
|
|
67
|
+
state=state,
|
|
68
|
+
reason="recorded_terminal_event" if state != "unknown" else "terminal_exit_unavailable",
|
|
69
|
+
failure_domain=failure_domain,
|
|
70
|
+
)
|
|
71
|
+
return result
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def build_run_assessment(graph: dict[str, Any], *, max_records: int = MAX_RECORDS) -> dict[str, Any]:
|
|
75
|
+
"""Read only graph nodes/edges and named expansion containers.
|
|
76
|
+
|
|
77
|
+
The inspection budget bounds work and provenance lists. Exhaustion or a
|
|
78
|
+
compact/projected input is reported, not converted into a complete inventory.
|
|
79
|
+
Provider bodies and arbitrary nested dictionaries are never interpreted.
|
|
80
|
+
"""
|
|
81
|
+
if type(max_records) is not int or max_records < 0:
|
|
82
|
+
raise ValueError("max_records must be a nonnegative integer")
|
|
83
|
+
graph = _object(graph)
|
|
84
|
+
remaining = max_records
|
|
85
|
+
nodes: dict[str, dict[str, Any]] = {}
|
|
86
|
+
ambiguous: set[str] = set()
|
|
87
|
+
edges: list[dict[str, Any]] = []
|
|
88
|
+
limited = False
|
|
89
|
+
invalid = 0
|
|
90
|
+
|
|
91
|
+
def collect(container: dict[str, Any]) -> None:
|
|
92
|
+
nonlocal remaining, limited, invalid
|
|
93
|
+
for key in ("nodes", "edges"):
|
|
94
|
+
items = container.get(key)
|
|
95
|
+
if not isinstance(items, list):
|
|
96
|
+
invalid += 1
|
|
97
|
+
continue
|
|
98
|
+
for item in items:
|
|
99
|
+
if remaining == 0:
|
|
100
|
+
limited = True
|
|
101
|
+
return
|
|
102
|
+
remaining -= 1
|
|
103
|
+
if not isinstance(item, dict):
|
|
104
|
+
invalid += 1
|
|
105
|
+
continue
|
|
106
|
+
if key == "edges":
|
|
107
|
+
edges.append(item)
|
|
108
|
+
continue
|
|
109
|
+
node_id = _text(item.get("id"))
|
|
110
|
+
if node_id is None:
|
|
111
|
+
invalid += 1
|
|
112
|
+
continue
|
|
113
|
+
if node_id in nodes and nodes[node_id] != item:
|
|
114
|
+
ambiguous.add(node_id)
|
|
115
|
+
else:
|
|
116
|
+
nodes[node_id] = item
|
|
117
|
+
|
|
118
|
+
collect(graph)
|
|
119
|
+
expansion = _object(graph.get("expansion")).get("clusters", {})
|
|
120
|
+
if isinstance(expansion, dict):
|
|
121
|
+
for cluster in expansion.values():
|
|
122
|
+
if remaining == 0:
|
|
123
|
+
limited = True
|
|
124
|
+
break
|
|
125
|
+
remaining -= 1
|
|
126
|
+
if isinstance(cluster, dict):
|
|
127
|
+
collect(cluster)
|
|
128
|
+
else:
|
|
129
|
+
invalid += 1
|
|
130
|
+
else:
|
|
131
|
+
invalid += 1
|
|
132
|
+
for node_id in ambiguous:
|
|
133
|
+
nodes.pop(node_id, None)
|
|
134
|
+
task_ids = {key for key, node in nodes.items() if node.get("type") == "task" and _native(node)}
|
|
135
|
+
completed: set[str] = set()
|
|
136
|
+
failed: set[str] = set()
|
|
137
|
+
reports: list[dict[str, Any]] = []
|
|
138
|
+
for edge in edges:
|
|
139
|
+
if not _native(edge) or _text(edge.get("relation")) not in {"TASK_COMPLETED", "TASK_FAILED"}:
|
|
140
|
+
continue
|
|
141
|
+
target = edge.get("target")
|
|
142
|
+
source = nodes.get(edge.get("source")) if isinstance(edge.get("source"), str) else None
|
|
143
|
+
if not isinstance(target, str) or target not in task_ids or not source:
|
|
144
|
+
continue
|
|
145
|
+
if source.get("type") not in ("agent", "task") or not _native(source):
|
|
146
|
+
continue
|
|
147
|
+
(completed if edge["relation"] == "TASK_COMPLETED" else failed).add(target)
|
|
148
|
+
if len(reports) < 20:
|
|
149
|
+
reports.append({"task_id": target, "edge_id": _text(edge.get("id")),
|
|
150
|
+
"relation": edge["relation"], "source_id": edge.get("source")})
|
|
151
|
+
|
|
152
|
+
counts = {key: 0 for key in ("declared", "valid_references", "invalid_references",
|
|
153
|
+
"source_partial", "source_completeness_unknown", "opaque", "redacted")}
|
|
154
|
+
files: set[str] = set()
|
|
155
|
+
for node in nodes.values():
|
|
156
|
+
if node.get("type") != "observed_content" or not _native(node):
|
|
157
|
+
continue
|
|
158
|
+
a = _object(node.get("attributes"))
|
|
159
|
+
counts["declared"] += 1
|
|
160
|
+
path, digest = a.get("path"), a.get("sha256")
|
|
161
|
+
match = _REFERENCE.fullmatch(path) if isinstance(path, str) else None
|
|
162
|
+
size_ok = "size_bytes" not in a or (type(a["size_bytes"]) is int and a["size_bytes"] >= 0)
|
|
163
|
+
valid = match is not None and match[1] == digest and size_ok
|
|
164
|
+
counts["valid_references" if valid else "invalid_references"] += 1
|
|
165
|
+
if valid:
|
|
166
|
+
files.add(path)
|
|
167
|
+
if a.get("complete_from_source") is False:
|
|
168
|
+
counts["source_partial"] += 1
|
|
169
|
+
elif a.get("complete_from_source") is not True:
|
|
170
|
+
counts["source_completeness_unknown"] += 1
|
|
171
|
+
representation = _text(a.get("representation"))
|
|
172
|
+
if representation in {"opaque_encrypted", "opaque_signed", "encrypted"}:
|
|
173
|
+
counts["opaque"] += 1
|
|
174
|
+
if representation == "redacted" or a.get("redacted") is True:
|
|
175
|
+
counts["redacted"] += 1
|
|
176
|
+
|
|
177
|
+
projected = bool(graph.get("live_payload_compact") or graph.get("viewer_projection"))
|
|
178
|
+
scope = "partial" if limited or invalid or ambiguous or projected else "declared_graph"
|
|
179
|
+
return {
|
|
180
|
+
"schema_version": SCHEMA_VERSION,
|
|
181
|
+
"run_id": _text(graph.get("run_id")),
|
|
182
|
+
"session_id": _text(graph.get("session_id")),
|
|
183
|
+
"source_path": _text(graph.get("source_path")),
|
|
184
|
+
"scope": "published_graph_metadata",
|
|
185
|
+
"inspection": {"state": scope, "limit_reached": limited,
|
|
186
|
+
"inspected_records": max_records - remaining,
|
|
187
|
+
"invalid_records": invalid, "ambiguous_node_ids": len(ambiguous)},
|
|
188
|
+
"execution": _execution(graph),
|
|
189
|
+
"observation": _object(graph.get("observation_assessment")) or {
|
|
190
|
+
"state": "not_verified", "reasons": ["legacy_observation_assessment_missing"],
|
|
191
|
+
"end_to_end_completeness_proven": False,
|
|
192
|
+
},
|
|
193
|
+
"task_validation": {**assessment_subjects(list(nodes.values())), "state": "unverified", "reason": "no_independent_validation_contract",
|
|
194
|
+
"declared_tasks": len(task_ids), "reported_completed": len(completed),
|
|
195
|
+
"reported_failed": len(failed), "both_reported": len(completed & failed),
|
|
196
|
+
"reports": reports},
|
|
197
|
+
"content": {**counts, "unique_declared_files": len(files), "bytes_verified": None,
|
|
198
|
+
"state": "declared_gaps" if counts["invalid_references"] or counts["source_partial"]
|
|
199
|
+
else "not_verified", "archive_state": "not_checked_in_this_view"},
|
|
200
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Conservative Winsock fallback for a timed-out pre-launch loopback connect."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import ipaddress
|
|
5
|
+
import socket
|
|
6
|
+
import sys
|
|
7
|
+
from contextlib import ExitStack
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def windows_exclusive_endpoint_available(host: str, port: int) -> bool:
|
|
11
|
+
"""Require exclusive binds, not a timeout, as evidence of unused addresses.
|
|
12
|
+
|
|
13
|
+
A short Windows connect can time out before an unused port reports refusal.
|
|
14
|
+
SO_EXCLUSIVEADDRUSE prevents taking over an existing bind. Every resolved
|
|
15
|
+
loopback address must be exclusively bindable at the same instant; sockets
|
|
16
|
+
are closed before the real relay/child starts. No listener is created and no
|
|
17
|
+
SO_REUSEADDR is enabled. This proves availability only at the launch boundary,
|
|
18
|
+
not ownership of an unrelated service started later.
|
|
19
|
+
"""
|
|
20
|
+
exclusive = getattr(socket, 'SO_EXCLUSIVEADDRUSE', None)
|
|
21
|
+
if sys.platform != 'win32' or exclusive is None or not 0 < port <= 65535:
|
|
22
|
+
return False
|
|
23
|
+
try:
|
|
24
|
+
addresses = socket.getaddrinfo(host, port, type=socket.SOCK_STREAM,
|
|
25
|
+
proto=socket.IPPROTO_TCP)
|
|
26
|
+
seen = set()
|
|
27
|
+
with ExitStack() as stack:
|
|
28
|
+
for family, kind, protocol, _, address in addresses:
|
|
29
|
+
if family not in (socket.AF_INET, socket.AF_INET6):
|
|
30
|
+
return False
|
|
31
|
+
if not ipaddress.ip_address(address[0]).is_loopback:
|
|
32
|
+
return False
|
|
33
|
+
key = (family, address)
|
|
34
|
+
if key in seen:
|
|
35
|
+
continue
|
|
36
|
+
seen.add(key)
|
|
37
|
+
reservation = stack.enter_context(socket.socket(family, kind, protocol))
|
|
38
|
+
reservation.setsockopt(socket.SOL_SOCKET, exclusive, 1)
|
|
39
|
+
if family == socket.AF_INET6:
|
|
40
|
+
reservation.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
|
|
41
|
+
reservation.bind(address)
|
|
42
|
+
return bool(seen)
|
|
43
|
+
except (OSError, ValueError):
|
|
44
|
+
return False
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import platform
|
|
7
|
+
import sys
|
|
8
|
+
import time
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
import psutil
|
|
12
|
+
|
|
13
|
+
from . import __version__
|
|
14
|
+
from .graph import GraphAccumulator
|
|
15
|
+
|
|
16
|
+
BENCHMARK_SCHEMA_VERSION = "0.1"
|
|
17
|
+
DEFAULT_SIZES = (10_000, 100_000, 1_000_000)
|
|
18
|
+
DEFAULT_RESOURCES = 10_000
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _synthetic_event(index: int, resource_count: int) -> dict[str, object]:
|
|
22
|
+
resource = index % resource_count
|
|
23
|
+
target_id = f"file:/synthetic/resource-{resource}.txt"
|
|
24
|
+
return {
|
|
25
|
+
"schema_version": "0.2",
|
|
26
|
+
"session_id": "scalability-benchmark",
|
|
27
|
+
"event_id": f"event-{index}",
|
|
28
|
+
"sequence": index + 1,
|
|
29
|
+
"timestamp": "2026-01-01T00:00:00Z",
|
|
30
|
+
"event_type": "filesystem.modified",
|
|
31
|
+
"relation": "OBSERVED_FILE_CHANGE",
|
|
32
|
+
"source": {
|
|
33
|
+
"id": "session:scalability-benchmark",
|
|
34
|
+
"type": "session",
|
|
35
|
+
"name": "scalability-benchmark",
|
|
36
|
+
},
|
|
37
|
+
"target": {
|
|
38
|
+
"id": target_id,
|
|
39
|
+
"type": "file",
|
|
40
|
+
"name": f"resource-{resource}.txt",
|
|
41
|
+
},
|
|
42
|
+
"attributes": {
|
|
43
|
+
"backend": "portable",
|
|
44
|
+
"attribution": "session_observation",
|
|
45
|
+
"causal": False,
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def benchmark_point(event_count: int, *, resource_count: int) -> dict[str, object]:
|
|
51
|
+
if event_count <= 0:
|
|
52
|
+
raise ValueError("event_count must be > 0")
|
|
53
|
+
if resource_count <= 0:
|
|
54
|
+
raise ValueError("resource_count must be > 0")
|
|
55
|
+
|
|
56
|
+
process = psutil.Process(os.getpid())
|
|
57
|
+
rss_before = process.memory_info().rss
|
|
58
|
+
accumulator = GraphAccumulator(
|
|
59
|
+
session_id="scalability-benchmark",
|
|
60
|
+
source_path=Path("<synthetic>"),
|
|
61
|
+
retain_event_ids=False,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
started = time.perf_counter()
|
|
65
|
+
for index in range(event_count):
|
|
66
|
+
accumulator.apply(_synthetic_event(index, resource_count))
|
|
67
|
+
elapsed = time.perf_counter() - started
|
|
68
|
+
rss_after_apply = process.memory_info().rss
|
|
69
|
+
|
|
70
|
+
snapshot_started = time.perf_counter()
|
|
71
|
+
snapshot = accumulator.to_dict()
|
|
72
|
+
snapshot_seconds = time.perf_counter() - snapshot_started
|
|
73
|
+
encoded = json.dumps(snapshot, ensure_ascii=False, separators=(",", ":")).encode("utf-8")
|
|
74
|
+
rss_after_snapshot = process.memory_info().rss
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
"event_count": event_count,
|
|
78
|
+
"resource_count": resource_count,
|
|
79
|
+
"node_count": accumulator.node_count,
|
|
80
|
+
"edge_count": accumulator.edge_count,
|
|
81
|
+
"apply_seconds": elapsed,
|
|
82
|
+
"events_per_second": event_count / elapsed if elapsed else 0.0,
|
|
83
|
+
"snapshot_seconds": snapshot_seconds,
|
|
84
|
+
"snapshot_bytes": len(encoded),
|
|
85
|
+
"rss_before_bytes": rss_before,
|
|
86
|
+
"rss_after_apply_bytes": rss_after_apply,
|
|
87
|
+
"rss_after_snapshot_bytes": rss_after_snapshot,
|
|
88
|
+
"rss_apply_delta_bytes": max(0, rss_after_apply - rss_before),
|
|
89
|
+
"rss_snapshot_delta_bytes": max(0, rss_after_snapshot - rss_after_apply),
|
|
90
|
+
"retained_event_ids": sum(len(edge.event_ids) for edge in accumulator.edges.values()),
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def run_scalability_benchmark(
|
|
95
|
+
*,
|
|
96
|
+
sizes: tuple[int, ...] = DEFAULT_SIZES,
|
|
97
|
+
resource_count: int = DEFAULT_RESOURCES,
|
|
98
|
+
) -> dict[str, object]:
|
|
99
|
+
if not sizes:
|
|
100
|
+
raise ValueError("at least one size is required")
|
|
101
|
+
normalized = tuple(int(size) for size in sizes)
|
|
102
|
+
if any(size <= 0 for size in normalized):
|
|
103
|
+
raise ValueError("all benchmark sizes must be > 0")
|
|
104
|
+
return {
|
|
105
|
+
"benchmark_schema_version": BENCHMARK_SCHEMA_VERSION,
|
|
106
|
+
"execweave_version": __version__,
|
|
107
|
+
"python_version": platform.python_version(),
|
|
108
|
+
"platform": platform.platform(),
|
|
109
|
+
"resource_count": resource_count,
|
|
110
|
+
"points": [
|
|
111
|
+
benchmark_point(size, resource_count=resource_count)
|
|
112
|
+
for size in normalized
|
|
113
|
+
],
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _format_bytes(value: int) -> str:
|
|
118
|
+
if value >= 1024 * 1024:
|
|
119
|
+
return f"{value / (1024 * 1024):.1f} MiB"
|
|
120
|
+
return f"{value / 1024:.1f} KiB"
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def format_scalability(result: dict[str, object]) -> str:
|
|
124
|
+
lines = [
|
|
125
|
+
f"ExecWeave {result['execweave_version']} scalability benchmark",
|
|
126
|
+
"events apply(s) events/s nodes edges RSS delta snapshot",
|
|
127
|
+
]
|
|
128
|
+
for point in result["points"]:
|
|
129
|
+
assert isinstance(point, dict)
|
|
130
|
+
lines.append(
|
|
131
|
+
f"{int(point['event_count']):>10,} "
|
|
132
|
+
f"{float(point['apply_seconds']):>8.3f} "
|
|
133
|
+
f"{float(point['events_per_second']):>9,.0f} "
|
|
134
|
+
f"{int(point['node_count']):>8,} "
|
|
135
|
+
f"{int(point['edge_count']):>7,} "
|
|
136
|
+
f"{_format_bytes(int(point['rss_apply_delta_bytes'])):>10} "
|
|
137
|
+
f"{_format_bytes(int(point['snapshot_bytes'])):>10}"
|
|
138
|
+
)
|
|
139
|
+
return "\n".join(lines)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _parse_sizes(raw: str) -> tuple[int, ...]:
|
|
143
|
+
try:
|
|
144
|
+
values = tuple(int(part.strip()) for part in raw.split(",") if part.strip())
|
|
145
|
+
except ValueError as exc:
|
|
146
|
+
raise argparse.ArgumentTypeError("sizes must be comma-separated integers") from exc
|
|
147
|
+
if not values or any(value <= 0 for value in values):
|
|
148
|
+
raise argparse.ArgumentTypeError("sizes must contain positive integers")
|
|
149
|
+
return values
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
153
|
+
parser = argparse.ArgumentParser(
|
|
154
|
+
prog="execweave-scalability",
|
|
155
|
+
description="Measure incremental GraphAccumulator scaling without retaining raw event IDs.",
|
|
156
|
+
)
|
|
157
|
+
parser.add_argument(
|
|
158
|
+
"--sizes",
|
|
159
|
+
type=_parse_sizes,
|
|
160
|
+
default=DEFAULT_SIZES,
|
|
161
|
+
help="Comma-separated event counts (default: 10000,100000,1000000)",
|
|
162
|
+
)
|
|
163
|
+
parser.add_argument(
|
|
164
|
+
"--resources",
|
|
165
|
+
type=int,
|
|
166
|
+
default=DEFAULT_RESOURCES,
|
|
167
|
+
help="Unique synthetic file resources (default: 10000)",
|
|
168
|
+
)
|
|
169
|
+
parser.add_argument("--output-json", type=Path, default=None)
|
|
170
|
+
return parser
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def main(argv: list[str] | None = None) -> int:
|
|
174
|
+
args = build_parser().parse_args(argv)
|
|
175
|
+
try:
|
|
176
|
+
result = run_scalability_benchmark(
|
|
177
|
+
sizes=tuple(args.sizes),
|
|
178
|
+
resource_count=args.resources,
|
|
179
|
+
)
|
|
180
|
+
except ValueError as exc:
|
|
181
|
+
raise SystemExit(str(exc)) from exc
|
|
182
|
+
print(format_scalability(result))
|
|
183
|
+
if args.output_json is not None:
|
|
184
|
+
output = args.output_json.expanduser().resolve()
|
|
185
|
+
output.parent.mkdir(parents=True, exist_ok=True)
|
|
186
|
+
output.write_text(
|
|
187
|
+
json.dumps(result, ensure_ascii=False, indent=2, sort_keys=True) + "\n",
|
|
188
|
+
encoding="utf-8",
|
|
189
|
+
)
|
|
190
|
+
print(f"JSON: {output}", file=sys.stderr)
|
|
191
|
+
return 0
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
if __name__ == "__main__":
|
|
195
|
+
raise SystemExit(main())
|
execweave/schema.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import asdict, dataclass, field
|
|
4
|
+
from datetime import datetime, timezone
|
|
5
|
+
from typing import Any
|
|
6
|
+
from uuid import uuid4
|
|
7
|
+
|
|
8
|
+
SCHEMA_VERSION = "0.2"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True)
|
|
12
|
+
class Entity:
|
|
13
|
+
"""A graph entity referenced by a runtime event."""
|
|
14
|
+
|
|
15
|
+
type: str
|
|
16
|
+
id: str
|
|
17
|
+
name: str | None = None
|
|
18
|
+
attributes: dict[str, Any] = field(default_factory=dict)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass(frozen=True)
|
|
22
|
+
class RuntimeEvent:
|
|
23
|
+
"""One graph-ready observation represented as source -> relation -> target."""
|
|
24
|
+
|
|
25
|
+
schema_version: str
|
|
26
|
+
event_id: str
|
|
27
|
+
session_id: str
|
|
28
|
+
timestamp: str
|
|
29
|
+
event_type: str
|
|
30
|
+
relation: str
|
|
31
|
+
source: Entity | None
|
|
32
|
+
target: Entity | None
|
|
33
|
+
sequence: int | None = None
|
|
34
|
+
attributes: dict[str, Any] = field(default_factory=dict)
|
|
35
|
+
|
|
36
|
+
@classmethod
|
|
37
|
+
def create(
|
|
38
|
+
cls,
|
|
39
|
+
*,
|
|
40
|
+
session_id: str,
|
|
41
|
+
event_type: str,
|
|
42
|
+
relation: str,
|
|
43
|
+
source: Entity | None = None,
|
|
44
|
+
target: Entity | None = None,
|
|
45
|
+
attributes: dict[str, Any] | None = None,
|
|
46
|
+
timestamp: str | None = None,
|
|
47
|
+
) -> "RuntimeEvent":
|
|
48
|
+
return cls(
|
|
49
|
+
schema_version=SCHEMA_VERSION,
|
|
50
|
+
event_id=str(uuid4()),
|
|
51
|
+
session_id=session_id,
|
|
52
|
+
timestamp=timestamp
|
|
53
|
+
or datetime.now(timezone.utc).isoformat().replace("+00:00", "Z"),
|
|
54
|
+
event_type=event_type,
|
|
55
|
+
relation=relation,
|
|
56
|
+
source=source,
|
|
57
|
+
target=target,
|
|
58
|
+
attributes=attributes or {},
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
def to_dict(self) -> dict[str, Any]:
|
|
62
|
+
return asdict(self)
|
execweave/scope.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import warnings
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass(frozen=True)
|
|
9
|
+
class CollectionScopeDecision:
|
|
10
|
+
watch_root: Path
|
|
11
|
+
collect_filesystem: bool
|
|
12
|
+
broad_scope: bool
|
|
13
|
+
reason: str | None = None
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _safe_resolve(path: Path) -> Path:
|
|
17
|
+
return path.expanduser().resolve()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def broad_filesystem_roots() -> set[Path]:
|
|
21
|
+
"""Return platform-local roots that are unsafe for implicit recursive watching.
|
|
22
|
+
|
|
23
|
+
The set intentionally stays small and structural: filesystem root, the user's
|
|
24
|
+
home directory, and the parent that contains user homes. ExecWeave does not
|
|
25
|
+
maintain a broad path-ignore list here because a security/observability tool
|
|
26
|
+
must not silently hide project activity merely for performance.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
home = _safe_resolve(Path.home())
|
|
30
|
+
roots = {home}
|
|
31
|
+
|
|
32
|
+
anchor = Path(home.anchor) if home.anchor else None
|
|
33
|
+
if anchor is not None:
|
|
34
|
+
try:
|
|
35
|
+
roots.add(_safe_resolve(anchor))
|
|
36
|
+
except OSError:
|
|
37
|
+
pass
|
|
38
|
+
|
|
39
|
+
parent = home.parent
|
|
40
|
+
if parent != home:
|
|
41
|
+
try:
|
|
42
|
+
roots.add(_safe_resolve(parent))
|
|
43
|
+
except OSError:
|
|
44
|
+
pass
|
|
45
|
+
|
|
46
|
+
return roots
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def protect_filesystem_scope(
|
|
50
|
+
watch_root: str | Path,
|
|
51
|
+
*,
|
|
52
|
+
collect_filesystem: bool,
|
|
53
|
+
allow_broad_scope: bool = False,
|
|
54
|
+
warn: bool = True,
|
|
55
|
+
) -> CollectionScopeDecision:
|
|
56
|
+
"""Disable recursive filesystem observation for dangerously broad roots.
|
|
57
|
+
|
|
58
|
+
Process/network collection is unaffected. This is a resource-safety guard,
|
|
59
|
+
not an evidence reinterpretation: if filesystem collection is suppressed the
|
|
60
|
+
caller is told explicitly. Advanced programmatic callers may opt in with
|
|
61
|
+
``allow_broad_scope=True`` after making that scope choice deliberately.
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
root = _safe_resolve(Path(watch_root))
|
|
65
|
+
broad = root in broad_filesystem_roots()
|
|
66
|
+
if not collect_filesystem or not broad or allow_broad_scope:
|
|
67
|
+
return CollectionScopeDecision(
|
|
68
|
+
watch_root=root,
|
|
69
|
+
collect_filesystem=collect_filesystem,
|
|
70
|
+
broad_scope=broad,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
reason = (
|
|
74
|
+
"ExecWeave disabled recursive filesystem observation because the watch root "
|
|
75
|
+
f"is unusually broad: {root}. Process and network collection remain enabled. "
|
|
76
|
+
"Run from a project directory or pass a narrower --watch-root to collect files."
|
|
77
|
+
)
|
|
78
|
+
if warn:
|
|
79
|
+
warnings.warn(reason, RuntimeWarning, stacklevel=2)
|
|
80
|
+
return CollectionScopeDecision(
|
|
81
|
+
watch_root=root,
|
|
82
|
+
collect_filesystem=False,
|
|
83
|
+
broad_scope=True,
|
|
84
|
+
reason=reason,
|
|
85
|
+
)
|