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,102 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from .agent_topology import ROOT_PATH
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _normalized_preview_text(value: object) -> str:
|
|
9
|
+
return " ".join(str(value or "").split())
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _parent_agent_path(path: str) -> str:
|
|
13
|
+
parent = path.rsplit("/", 1)[0] if "/" in path else ""
|
|
14
|
+
return parent or ROOT_PATH
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _is_antigravity_addressed_task(message: dict[str, Any], path: str) -> bool:
|
|
18
|
+
if str(message.get("recipient") or "") != path:
|
|
19
|
+
return False
|
|
20
|
+
kind = str(message.get("kind") or "")
|
|
21
|
+
role = str(message.get("content_role") or "")
|
|
22
|
+
return kind == "subagent_task" or role == "antigravity_addressed_task"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def sanitize_antigravity_preview_messages(entries: list[dict[str, Any]]) -> None:
|
|
26
|
+
"""Canonicalize child assignments and drop copies pasted onto /root."""
|
|
27
|
+
child_replies: set[str] = set()
|
|
28
|
+
child_assignments: set[str] = set()
|
|
29
|
+
for entry in entries:
|
|
30
|
+
if str(entry.get("provider") or "").lower() != "antigravity":
|
|
31
|
+
continue
|
|
32
|
+
preview = entry.get("conversation_preview")
|
|
33
|
+
if not isinstance(preview, dict) or preview.get("is_root") is not False:
|
|
34
|
+
continue
|
|
35
|
+
path = str(preview.get("agent_path") or "")
|
|
36
|
+
for message in preview.get("messages") or []:
|
|
37
|
+
if not isinstance(message, dict):
|
|
38
|
+
continue
|
|
39
|
+
kind = str(message.get("kind") or "")
|
|
40
|
+
sender = str(message.get("sender") or "")
|
|
41
|
+
text = _normalized_preview_text(message.get("text"))
|
|
42
|
+
if _is_antigravity_addressed_task(message, path) and text:
|
|
43
|
+
child_assignments.add(text)
|
|
44
|
+
if kind not in {"assistant_message", "subagent_final_response"}:
|
|
45
|
+
continue
|
|
46
|
+
if path and sender and sender != path:
|
|
47
|
+
continue
|
|
48
|
+
if text:
|
|
49
|
+
child_replies.add(text)
|
|
50
|
+
|
|
51
|
+
for entry in entries:
|
|
52
|
+
if str(entry.get("provider") or "").lower() != "antigravity":
|
|
53
|
+
continue
|
|
54
|
+
preview = entry.get("conversation_preview")
|
|
55
|
+
if not isinstance(preview, dict):
|
|
56
|
+
continue
|
|
57
|
+
messages = [message for message in preview.get("messages") or [] if isinstance(message, dict)]
|
|
58
|
+
path = str(preview.get("agent_path") or "")
|
|
59
|
+
is_root = preview.get("is_root") is True or path == ROOT_PATH
|
|
60
|
+
kept: list[dict[str, Any]] = []
|
|
61
|
+
assignment_texts: set[str] = set()
|
|
62
|
+
if not is_root:
|
|
63
|
+
for message in messages:
|
|
64
|
+
kind = str(message.get("kind") or "")
|
|
65
|
+
if kind in {"task", "subagent_task"} or str(
|
|
66
|
+
message.get("content_role") or ""
|
|
67
|
+
) == "antigravity_addressed_task":
|
|
68
|
+
text = _normalized_preview_text(message.get("text"))
|
|
69
|
+
if text:
|
|
70
|
+
assignment_texts.add(text)
|
|
71
|
+
for original in messages:
|
|
72
|
+
message = original
|
|
73
|
+
kind = str(message.get("kind") or "")
|
|
74
|
+
recipient = str(message.get("recipient") or "")
|
|
75
|
+
text = _normalized_preview_text(message.get("text"))
|
|
76
|
+
if is_root:
|
|
77
|
+
if kind == "subagent_task" and recipient in {"", ROOT_PATH, "/root"}:
|
|
78
|
+
continue
|
|
79
|
+
if kind == "assistant_message" and text and text in child_assignments:
|
|
80
|
+
continue
|
|
81
|
+
if text and text in child_replies and kind != "assistant_message":
|
|
82
|
+
continue
|
|
83
|
+
else:
|
|
84
|
+
if _is_antigravity_addressed_task(message, path):
|
|
85
|
+
sender = str(message.get("sender") or "")
|
|
86
|
+
message = dict(message)
|
|
87
|
+
message["kind"] = "task"
|
|
88
|
+
message["phase"] = "assignment"
|
|
89
|
+
message["content_role"] = "antigravity_addressed_task"
|
|
90
|
+
if sender in {"", "user"}:
|
|
91
|
+
message["sender"] = _parent_agent_path(path)
|
|
92
|
+
kind = "task"
|
|
93
|
+
if (
|
|
94
|
+
kind == "user_message"
|
|
95
|
+
and text
|
|
96
|
+
and text in assignment_texts
|
|
97
|
+
and recipient == path
|
|
98
|
+
):
|
|
99
|
+
continue
|
|
100
|
+
kept.append(message)
|
|
101
|
+
preview["messages"] = kept
|
|
102
|
+
preview["message_count"] = len(kept)
|
execweave/analysis.py
ADDED
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import ipaddress
|
|
4
|
+
from collections import Counter, defaultdict, deque
|
|
5
|
+
from dataclasses import asdict, dataclass, field
|
|
6
|
+
from pathlib import PurePath
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from .evidence_grade import (
|
|
10
|
+
EVIDENCE_GRADES,
|
|
11
|
+
EVIDENCE_GRADE_SCHEMA_VERSION,
|
|
12
|
+
annotate_finding,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
_SEVERITY_ORDER = {"high": 0, "medium": 1, "low": 2, "info": 3}
|
|
16
|
+
_SENSITIVE_MARKERS = (
|
|
17
|
+
"/.ssh/",
|
|
18
|
+
"\\.ssh\\",
|
|
19
|
+
"/.aws/credentials",
|
|
20
|
+
"\\.aws\\credentials",
|
|
21
|
+
"/.config/gcloud/",
|
|
22
|
+
"\\.config\\gcloud\\",
|
|
23
|
+
"/.azure/",
|
|
24
|
+
"\\.azure\\",
|
|
25
|
+
"/.kube/config",
|
|
26
|
+
"\\.kube\\config",
|
|
27
|
+
"/.docker/config.json",
|
|
28
|
+
"\\.docker\\config.json",
|
|
29
|
+
"/.npmrc",
|
|
30
|
+
"\\.npmrc",
|
|
31
|
+
"/.pypirc",
|
|
32
|
+
"\\.pypirc",
|
|
33
|
+
"/.netrc",
|
|
34
|
+
"\\.netrc",
|
|
35
|
+
)
|
|
36
|
+
_SENSITIVE_BASENAMES = {
|
|
37
|
+
".env",
|
|
38
|
+
"id_rsa",
|
|
39
|
+
"id_dsa",
|
|
40
|
+
"id_ecdsa",
|
|
41
|
+
"id_ed25519",
|
|
42
|
+
"credentials",
|
|
43
|
+
"credentials.json",
|
|
44
|
+
"service-account.json",
|
|
45
|
+
}
|
|
46
|
+
_FILE_RELATIONS = {"OPENED_READ", "OPENED_READ_WRITE", "OPENED_WRITE"}
|
|
47
|
+
_NETWORK_RELATIONS = {"CONNECTED_TO", "CONNECT_ATTEMPTED"}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass(frozen=True)
|
|
51
|
+
class Finding:
|
|
52
|
+
rule_id: str
|
|
53
|
+
severity: str
|
|
54
|
+
title: str
|
|
55
|
+
summary: str
|
|
56
|
+
node_ids: list[str] = field(default_factory=list)
|
|
57
|
+
edge_ids: list[str] = field(default_factory=list)
|
|
58
|
+
evidence_event_ids: list[str] = field(default_factory=list)
|
|
59
|
+
attributes: dict[str, Any] = field(default_factory=dict)
|
|
60
|
+
|
|
61
|
+
def to_dict(self) -> dict[str, Any]:
|
|
62
|
+
return asdict(self)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _node_map(graph: dict[str, Any]) -> dict[str, dict[str, Any]]:
|
|
66
|
+
return {
|
|
67
|
+
node["id"]: node
|
|
68
|
+
for node in graph.get("nodes", [])
|
|
69
|
+
if isinstance(node, dict) and isinstance(node.get("id"), str)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _resource_text(node: dict[str, Any]) -> str:
|
|
74
|
+
return f"{node.get('id', '')} {node.get('name', '')}".lower()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _is_sensitive_file(node: dict[str, Any]) -> bool:
|
|
78
|
+
if node.get("type") != "file":
|
|
79
|
+
return False
|
|
80
|
+
text = _resource_text(node)
|
|
81
|
+
if any(marker in text for marker in _SENSITIVE_MARKERS):
|
|
82
|
+
return True
|
|
83
|
+
name = str(node.get("name") or "").lower()
|
|
84
|
+
if name in _SENSITIVE_BASENAMES:
|
|
85
|
+
return True
|
|
86
|
+
node_id = str(node.get("id") or "")
|
|
87
|
+
_, _, raw_path = node_id.partition(":")
|
|
88
|
+
if raw_path:
|
|
89
|
+
try:
|
|
90
|
+
return PurePath(raw_path).name.lower() in _SENSITIVE_BASENAMES
|
|
91
|
+
except (TypeError, ValueError):
|
|
92
|
+
return False
|
|
93
|
+
return False
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _endpoint_host(node: dict[str, Any]) -> str | None:
|
|
97
|
+
if node.get("type") != "network_endpoint":
|
|
98
|
+
return None
|
|
99
|
+
raw = str(node.get("name") or "")
|
|
100
|
+
if not raw:
|
|
101
|
+
node_id = str(node.get("id") or "")
|
|
102
|
+
_, _, raw = node_id.partition(":")
|
|
103
|
+
if not raw:
|
|
104
|
+
return None
|
|
105
|
+
if raw.startswith("[") and "]" in raw:
|
|
106
|
+
return raw[1 : raw.index("]")]
|
|
107
|
+
if raw.count(":") == 1:
|
|
108
|
+
return raw.rsplit(":", 1)[0]
|
|
109
|
+
return raw
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _is_external_endpoint(node: dict[str, Any]) -> bool:
|
|
113
|
+
host = _endpoint_host(node)
|
|
114
|
+
if host is None:
|
|
115
|
+
return False
|
|
116
|
+
normalized = host.strip().lower()
|
|
117
|
+
if normalized in {"localhost", "ip6-localhost"}:
|
|
118
|
+
return False
|
|
119
|
+
try:
|
|
120
|
+
address = ipaddress.ip_address(normalized)
|
|
121
|
+
except ValueError:
|
|
122
|
+
return True
|
|
123
|
+
return not (
|
|
124
|
+
address.is_loopback
|
|
125
|
+
or address.is_private
|
|
126
|
+
or address.is_link_local
|
|
127
|
+
or address.is_multicast
|
|
128
|
+
or address.is_unspecified
|
|
129
|
+
or address.is_reserved
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _event_ids(edge: dict[str, Any], limit: int = 24) -> list[str]:
|
|
134
|
+
values = edge.get("event_ids") or []
|
|
135
|
+
return [str(value) for value in values if isinstance(value, str)][:limit]
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _edge_sequence(edge: dict[str, Any], key: str) -> int | None:
|
|
139
|
+
value = edge.get(key)
|
|
140
|
+
return value if isinstance(value, int) and not isinstance(value, bool) else None
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _causal_spawn_adjacency(
|
|
144
|
+
edges: list[dict[str, Any]],
|
|
145
|
+
) -> dict[str, list[dict[str, Any]]]:
|
|
146
|
+
adjacency: dict[str, list[dict[str, Any]]] = defaultdict(list)
|
|
147
|
+
for edge in edges:
|
|
148
|
+
if edge.get("relation") != "SPAWNED" or edge.get("causal") is not True:
|
|
149
|
+
continue
|
|
150
|
+
source = edge.get("source")
|
|
151
|
+
target = edge.get("target")
|
|
152
|
+
if isinstance(source, str) and isinstance(target, str):
|
|
153
|
+
adjacency[source].append(edge)
|
|
154
|
+
for values in adjacency.values():
|
|
155
|
+
values.sort(
|
|
156
|
+
key=lambda edge: (
|
|
157
|
+
_edge_sequence(edge, "first_sequence") or 0,
|
|
158
|
+
str(edge.get("target") or ""),
|
|
159
|
+
)
|
|
160
|
+
)
|
|
161
|
+
return dict(adjacency)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _descendant_spawn_paths(
|
|
165
|
+
process_id: str,
|
|
166
|
+
adjacency: dict[str, list[dict[str, Any]]],
|
|
167
|
+
*,
|
|
168
|
+
after_sequence: int | None,
|
|
169
|
+
max_depth: int = 4,
|
|
170
|
+
) -> list[tuple[str, list[dict[str, Any]]]]:
|
|
171
|
+
"""Return chronological causal SPAWNED paths created after a source observation."""
|
|
172
|
+
results: list[tuple[str, list[dict[str, Any]]]] = []
|
|
173
|
+
queue: deque[tuple[str, list[dict[str, Any]], set[str], int | None]] = deque()
|
|
174
|
+
queue.append((process_id, [], {process_id}, after_sequence))
|
|
175
|
+
|
|
176
|
+
while queue:
|
|
177
|
+
current, path, seen, minimum_sequence = queue.popleft()
|
|
178
|
+
if len(path) >= max_depth:
|
|
179
|
+
continue
|
|
180
|
+
for edge in adjacency.get(current, []):
|
|
181
|
+
child = edge.get("target")
|
|
182
|
+
if not isinstance(child, str) or child in seen:
|
|
183
|
+
continue
|
|
184
|
+
spawn_sequence = _edge_sequence(edge, "first_sequence")
|
|
185
|
+
if minimum_sequence is not None:
|
|
186
|
+
if spawn_sequence is None or spawn_sequence < minimum_sequence:
|
|
187
|
+
continue
|
|
188
|
+
next_path = [*path, edge]
|
|
189
|
+
results.append((child, next_path))
|
|
190
|
+
queue.append(
|
|
191
|
+
(
|
|
192
|
+
child,
|
|
193
|
+
next_path,
|
|
194
|
+
{*seen, child},
|
|
195
|
+
spawn_sequence if spawn_sequence is not None else minimum_sequence,
|
|
196
|
+
)
|
|
197
|
+
)
|
|
198
|
+
return results
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def analyze_graph(graph: dict[str, Any]) -> dict[str, Any]:
|
|
202
|
+
"""Run conservative, explainable rules over one execution graph.
|
|
203
|
+
|
|
204
|
+
Findings never upgrade co-occurrence into byte-level data-flow. Sensitive-file
|
|
205
|
+
access followed by network activity is a prioritization signal, not proof that
|
|
206
|
+
file contents were transmitted. The same rule applies across child processes:
|
|
207
|
+
SPAWNED proves process lineage, not data inheritance or IPC.
|
|
208
|
+
"""
|
|
209
|
+
nodes = _node_map(graph)
|
|
210
|
+
edges = [edge for edge in graph.get("edges", []) if isinstance(edge, dict)]
|
|
211
|
+
edges_by_id = {
|
|
212
|
+
edge_id: edge
|
|
213
|
+
for edge in edges
|
|
214
|
+
if isinstance((edge_id := edge.get("id")), str) and edge_id
|
|
215
|
+
}
|
|
216
|
+
findings: list[Finding] = []
|
|
217
|
+
sensitive_by_process: dict[str, list[dict[str, Any]]] = {}
|
|
218
|
+
external_by_process: dict[str, list[dict[str, Any]]] = {}
|
|
219
|
+
|
|
220
|
+
for edge in edges:
|
|
221
|
+
source_id = edge.get("source")
|
|
222
|
+
target_id = edge.get("target")
|
|
223
|
+
relation = edge.get("relation")
|
|
224
|
+
if not isinstance(source_id, str) or not isinstance(target_id, str):
|
|
225
|
+
continue
|
|
226
|
+
source = nodes.get(source_id)
|
|
227
|
+
target = nodes.get(target_id)
|
|
228
|
+
if source is None or target is None or source.get("type") != "process":
|
|
229
|
+
continue
|
|
230
|
+
|
|
231
|
+
if relation in _FILE_RELATIONS and _is_sensitive_file(target):
|
|
232
|
+
causal = edge.get("causal") is True
|
|
233
|
+
severity = "high" if relation in {"OPENED_READ_WRITE", "OPENED_WRITE"} else "medium"
|
|
234
|
+
if not causal:
|
|
235
|
+
severity = "low"
|
|
236
|
+
findings.append(
|
|
237
|
+
Finding(
|
|
238
|
+
rule_id="sensitive-file-access",
|
|
239
|
+
severity=severity,
|
|
240
|
+
title="Process accessed a sensitive-looking file",
|
|
241
|
+
summary=(
|
|
242
|
+
f"{source_id} has {relation} evidence for {target_id}. "
|
|
243
|
+
"Review whether this resource was required for the agent task."
|
|
244
|
+
),
|
|
245
|
+
node_ids=[source_id, target_id],
|
|
246
|
+
edge_ids=[str(edge.get("id") or "")],
|
|
247
|
+
evidence_event_ids=_event_ids(edge),
|
|
248
|
+
attributes={
|
|
249
|
+
"relation": relation,
|
|
250
|
+
"causal": edge.get("causal"),
|
|
251
|
+
"data_flow_proven": False,
|
|
252
|
+
},
|
|
253
|
+
)
|
|
254
|
+
)
|
|
255
|
+
if causal:
|
|
256
|
+
sensitive_by_process.setdefault(source_id, []).append(edge)
|
|
257
|
+
|
|
258
|
+
if relation in _NETWORK_RELATIONS and _is_external_endpoint(target):
|
|
259
|
+
causal = edge.get("causal") is True
|
|
260
|
+
findings.append(
|
|
261
|
+
Finding(
|
|
262
|
+
rule_id="external-network-contact",
|
|
263
|
+
severity="info" if relation == "CONNECTED_TO" else "low",
|
|
264
|
+
title="Process contacted an external network endpoint",
|
|
265
|
+
summary=f"{source_id} emitted {relation} evidence for {target_id}.",
|
|
266
|
+
node_ids=[source_id, target_id],
|
|
267
|
+
edge_ids=[str(edge.get("id") or "")],
|
|
268
|
+
evidence_event_ids=_event_ids(edge),
|
|
269
|
+
attributes={
|
|
270
|
+
"relation": relation,
|
|
271
|
+
"causal": edge.get("causal"),
|
|
272
|
+
"endpoint_host": _endpoint_host(target),
|
|
273
|
+
},
|
|
274
|
+
)
|
|
275
|
+
)
|
|
276
|
+
if causal:
|
|
277
|
+
external_by_process.setdefault(source_id, []).append(edge)
|
|
278
|
+
|
|
279
|
+
# Same-process correlation with strict chronological ordering when sequences exist.
|
|
280
|
+
for process_id in sorted(set(sensitive_by_process).intersection(external_by_process)):
|
|
281
|
+
for file_edge in sensitive_by_process[process_id]:
|
|
282
|
+
file_target = str(file_edge.get("target") or "")
|
|
283
|
+
file_last = _edge_sequence(file_edge, "last_sequence")
|
|
284
|
+
for net_edge in external_by_process[process_id]:
|
|
285
|
+
net_target = str(net_edge.get("target") or "")
|
|
286
|
+
net_first = _edge_sequence(net_edge, "first_sequence")
|
|
287
|
+
if file_last is not None and net_first is not None and net_first < file_last:
|
|
288
|
+
continue
|
|
289
|
+
relation = str(net_edge.get("relation") or "")
|
|
290
|
+
severity = "high" if relation == "CONNECTED_TO" else "medium"
|
|
291
|
+
findings.append(
|
|
292
|
+
Finding(
|
|
293
|
+
rule_id="possible-sensitive-file-to-network-path",
|
|
294
|
+
severity=severity,
|
|
295
|
+
title="Sensitive-file access was followed by external network activity",
|
|
296
|
+
summary=(
|
|
297
|
+
f"{process_id} accessed {file_target} and later produced {relation} "
|
|
298
|
+
f"evidence for {net_target}. This is a prioritization signal only: "
|
|
299
|
+
"ExecWeave has not proven that bytes from the file were transmitted."
|
|
300
|
+
),
|
|
301
|
+
node_ids=[process_id, file_target, net_target],
|
|
302
|
+
edge_ids=[
|
|
303
|
+
str(file_edge.get("id") or ""),
|
|
304
|
+
str(net_edge.get("id") or ""),
|
|
305
|
+
],
|
|
306
|
+
evidence_event_ids=[
|
|
307
|
+
*_event_ids(file_edge, 12),
|
|
308
|
+
*_event_ids(net_edge, 12),
|
|
309
|
+
],
|
|
310
|
+
attributes={
|
|
311
|
+
"file_relation": file_edge.get("relation"),
|
|
312
|
+
"network_relation": relation,
|
|
313
|
+
"file_last_sequence": file_last,
|
|
314
|
+
"network_first_sequence": net_first,
|
|
315
|
+
"causal_process_attribution": True,
|
|
316
|
+
"data_flow_proven": False,
|
|
317
|
+
"exfiltration_proven": False,
|
|
318
|
+
},
|
|
319
|
+
)
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
# Graph-native delegated path: sensitive access -> causal SPAWNED chain -> network.
|
|
323
|
+
# This proves chronological process lineage only. It does not prove inheritance,
|
|
324
|
+
# IPC, taint propagation, or that the child received bytes from the sensitive file.
|
|
325
|
+
spawn_adjacency = _causal_spawn_adjacency(edges)
|
|
326
|
+
for source_process, file_edges in sorted(sensitive_by_process.items()):
|
|
327
|
+
for file_edge in file_edges:
|
|
328
|
+
file_target = str(file_edge.get("target") or "")
|
|
329
|
+
file_last = _edge_sequence(file_edge, "last_sequence")
|
|
330
|
+
for descendant, spawn_path in _descendant_spawn_paths(
|
|
331
|
+
source_process,
|
|
332
|
+
spawn_adjacency,
|
|
333
|
+
after_sequence=file_last,
|
|
334
|
+
):
|
|
335
|
+
spawn_last = _edge_sequence(spawn_path[-1], "first_sequence")
|
|
336
|
+
for net_edge in external_by_process.get(descendant, []):
|
|
337
|
+
net_first = _edge_sequence(net_edge, "first_sequence")
|
|
338
|
+
if spawn_last is not None:
|
|
339
|
+
if net_first is None or net_first < spawn_last:
|
|
340
|
+
continue
|
|
341
|
+
relation = str(net_edge.get("relation") or "")
|
|
342
|
+
net_target = str(net_edge.get("target") or "")
|
|
343
|
+
process_chain = [source_process]
|
|
344
|
+
process_chain.extend(str(edge.get("target") or "") for edge in spawn_path)
|
|
345
|
+
spawn_edge_ids = [str(edge.get("id") or "") for edge in spawn_path]
|
|
346
|
+
spawn_event_ids = [
|
|
347
|
+
event_id
|
|
348
|
+
for edge in spawn_path
|
|
349
|
+
for event_id in _event_ids(edge, 8)
|
|
350
|
+
]
|
|
351
|
+
findings.append(
|
|
352
|
+
Finding(
|
|
353
|
+
rule_id="possible-delegated-sensitive-file-to-network-path",
|
|
354
|
+
severity="medium" if relation == "CONNECTED_TO" else "low",
|
|
355
|
+
title=(
|
|
356
|
+
"Sensitive-file access was followed by child-process "
|
|
357
|
+
"external network activity"
|
|
358
|
+
),
|
|
359
|
+
summary=(
|
|
360
|
+
f"{source_process} accessed {file_target}, then a causal SPAWNED "
|
|
361
|
+
f"chain reached {descendant}, which later produced {relation} "
|
|
362
|
+
f"evidence for {net_target}. Process lineage is proven, but "
|
|
363
|
+
"ExecWeave has not proven data inheritance, IPC, or exfiltration."
|
|
364
|
+
),
|
|
365
|
+
node_ids=[source_process, file_target, *process_chain[1:], net_target],
|
|
366
|
+
edge_ids=[
|
|
367
|
+
str(file_edge.get("id") or ""),
|
|
368
|
+
*spawn_edge_ids,
|
|
369
|
+
str(net_edge.get("id") or ""),
|
|
370
|
+
],
|
|
371
|
+
evidence_event_ids=[
|
|
372
|
+
*_event_ids(file_edge, 8),
|
|
373
|
+
*spawn_event_ids,
|
|
374
|
+
*_event_ids(net_edge, 8),
|
|
375
|
+
],
|
|
376
|
+
attributes={
|
|
377
|
+
"delegation_hops": len(spawn_path),
|
|
378
|
+
"process_chain": process_chain,
|
|
379
|
+
"file_last_sequence": file_last,
|
|
380
|
+
"spawn_sequences": [
|
|
381
|
+
_edge_sequence(edge, "first_sequence")
|
|
382
|
+
for edge in spawn_path
|
|
383
|
+
],
|
|
384
|
+
"network_first_sequence": net_first,
|
|
385
|
+
"causal_process_lineage": True,
|
|
386
|
+
"data_inheritance_proven": False,
|
|
387
|
+
"ipc_proven": False,
|
|
388
|
+
"data_flow_proven": False,
|
|
389
|
+
"exfiltration_proven": False,
|
|
390
|
+
},
|
|
391
|
+
)
|
|
392
|
+
)
|
|
393
|
+
|
|
394
|
+
findings.sort(
|
|
395
|
+
key=lambda finding: (
|
|
396
|
+
_SEVERITY_ORDER.get(finding.severity, 99),
|
|
397
|
+
finding.rule_id,
|
|
398
|
+
finding.node_ids,
|
|
399
|
+
)
|
|
400
|
+
)
|
|
401
|
+
counts = Counter(finding.severity for finding in findings)
|
|
402
|
+
finding_payloads = [
|
|
403
|
+
annotate_finding(finding.to_dict(), edges_by_id) for finding in findings
|
|
404
|
+
]
|
|
405
|
+
grade_counts = Counter(
|
|
406
|
+
str(finding.get("evidence_grade") or "U") for finding in finding_payloads
|
|
407
|
+
)
|
|
408
|
+
return {
|
|
409
|
+
"analysis_schema_version": "0.3",
|
|
410
|
+
"evidence_grade_schema_version": EVIDENCE_GRADE_SCHEMA_VERSION,
|
|
411
|
+
"session_id": graph.get("session_id"),
|
|
412
|
+
"finding_count": len(findings),
|
|
413
|
+
"severity_counts": {
|
|
414
|
+
severity: counts.get(severity, 0) for severity in ("high", "medium", "low", "info")
|
|
415
|
+
},
|
|
416
|
+
"evidence_grade_counts": {
|
|
417
|
+
grade: grade_counts.get(grade, 0) for grade in EVIDENCE_GRADES
|
|
418
|
+
},
|
|
419
|
+
"limitations": [
|
|
420
|
+
"Findings are rule-based prioritization signals, not proof of malicious intent.",
|
|
421
|
+
"Sensitive-file-to-network findings do not prove byte-level data flow or exfiltration.",
|
|
422
|
+
"SPAWNED lineage does not prove data inheritance, IPC, or taint propagation.",
|
|
423
|
+
"Collector coverage and attribution strength depend on the backend.",
|
|
424
|
+
"Evidence grades describe provenance strength, not probability, correctness, or maliciousness.",
|
|
425
|
+
],
|
|
426
|
+
"findings": finding_payloads,
|
|
427
|
+
}
|