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,313 @@
|
|
|
1
|
+
"""Evidence-scoped agent topology: who is root, who is a child, and how we know.
|
|
2
|
+
|
|
3
|
+
ExecWeave must never present an agent hierarchy it did not observe. Absence from a
|
|
4
|
+
list of known provider display names is not evidence that an agent is a child, so
|
|
5
|
+
this module inverts the rule: **an agent is root unless positive provider evidence
|
|
6
|
+
establishes a parent.**
|
|
7
|
+
|
|
8
|
+
Two questions are kept separate because they have different answers:
|
|
9
|
+
|
|
10
|
+
``topology_state``
|
|
11
|
+
How the parent/child relationship itself was established.
|
|
12
|
+
|
|
13
|
+
``agent_path_source``
|
|
14
|
+
Whether the ``/root/...`` path string was published by the provider or is an
|
|
15
|
+
ExecWeave canonical rendering of a relationship the provider expressed some
|
|
16
|
+
other way. A provider can report ``parentSessionId``/``sessionId`` without ever
|
|
17
|
+
emitting a path; the relationship is then provider-reported while the path is
|
|
18
|
+
derived, and the two must not be conflated.
|
|
19
|
+
|
|
20
|
+
Producers declare topology on the agent node with :func:`root_topology` or
|
|
21
|
+
:func:`subagent_topology`. Consumers read it back with :func:`resolve_agent_topology`,
|
|
22
|
+
which defaults to root and never infers a child from an unfamiliar identifier.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
from dataclasses import dataclass
|
|
28
|
+
from typing import Any
|
|
29
|
+
|
|
30
|
+
# How the parent/child relationship was established.
|
|
31
|
+
TOPOLOGY_OBSERVED = "observed"
|
|
32
|
+
"""The provider published the agent path/topology directly."""
|
|
33
|
+
|
|
34
|
+
TOPOLOGY_PROVIDER_REPORTED = "provider_reported"
|
|
35
|
+
"""The provider reported the relationship (parent id ↔ child id) but not a path."""
|
|
36
|
+
|
|
37
|
+
TOPOLOGY_DERIVED = "derived"
|
|
38
|
+
"""ExecWeave rendered this position; the provider expressed no hierarchy."""
|
|
39
|
+
|
|
40
|
+
TOPOLOGY_UNRESOLVED = "unresolved"
|
|
41
|
+
"""Evidence names an agent but does not establish reliable identity or parentage."""
|
|
42
|
+
|
|
43
|
+
TOPOLOGY_STATES = (
|
|
44
|
+
TOPOLOGY_OBSERVED,
|
|
45
|
+
TOPOLOGY_PROVIDER_REPORTED,
|
|
46
|
+
TOPOLOGY_DERIVED,
|
|
47
|
+
TOPOLOGY_UNRESOLVED,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
# Where the agent path string itself came from.
|
|
51
|
+
PATH_PROVIDER_DECLARED = "provider_declared"
|
|
52
|
+
PATH_EXECWEAVE_DERIVED = "execweave_derived"
|
|
53
|
+
PATH_LEGACY_UNKNOWN = "legacy_unknown"
|
|
54
|
+
"""An artifact written before topology provenance existed. Never upgraded."""
|
|
55
|
+
|
|
56
|
+
# How much conversational evidence a materialized thread actually rests on. A thread
|
|
57
|
+
# assembled only from a parent's routing records must never read as a full transcript.
|
|
58
|
+
COMPLETENESS_PROVIDER_TRANSCRIPT = "provider_transcript"
|
|
59
|
+
"""The agent's own provider transcript was archived and parsed."""
|
|
60
|
+
|
|
61
|
+
COMPLETENESS_ROUTING_ONLY = "routing_only"
|
|
62
|
+
"""Only cross-agent routing records survive; the agent's own transcript was not captured."""
|
|
63
|
+
|
|
64
|
+
COMPLETENESS_UNAVAILABLE = "unavailable"
|
|
65
|
+
"""The agent is known, but no conversational evidence is available for it."""
|
|
66
|
+
|
|
67
|
+
CONVERSATION_COMPLETENESS = (
|
|
68
|
+
COMPLETENESS_PROVIDER_TRANSCRIPT,
|
|
69
|
+
COMPLETENESS_ROUTING_ONLY,
|
|
70
|
+
COMPLETENESS_UNAVAILABLE,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
_COMPLETENESS_RANK = {
|
|
74
|
+
COMPLETENESS_UNAVAILABLE: 0,
|
|
75
|
+
COMPLETENESS_ROUTING_ONLY: 1,
|
|
76
|
+
COMPLETENESS_PROVIDER_TRANSCRIPT: 2,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def strongest_completeness(values: list[str]) -> str:
|
|
81
|
+
"""Merging threads from several sources keeps the strongest evidence they carry."""
|
|
82
|
+
known = [value for value in values if value in _COMPLETENESS_RANK]
|
|
83
|
+
if not known:
|
|
84
|
+
return COMPLETENESS_UNAVAILABLE
|
|
85
|
+
return max(known, key=lambda value: _COMPLETENESS_RANK[value])
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
# Where a conversation thread's identifier came from. A provider-native thread id is
|
|
89
|
+
# authoritative; a synthesized one is ExecWeave's label for the same execution, and the
|
|
90
|
+
# two must be reconcilable rather than producing two conversations for one agent.
|
|
91
|
+
THREAD_ID_PROVIDER_NATIVE = "provider_native"
|
|
92
|
+
THREAD_ID_EXECWEAVE_DERIVED = "execweave_derived"
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
AGENT_ROLE_ROOT = "root"
|
|
96
|
+
AGENT_ROLE_SUBAGENT = "subagent"
|
|
97
|
+
|
|
98
|
+
ROOT_PATH = "/root"
|
|
99
|
+
|
|
100
|
+
# Node attribute keys. Root and child declarations are deliberately namespaced apart.
|
|
101
|
+
#
|
|
102
|
+
# Graph nodes merge first-write-wins, and event order is not guaranteed: a session's
|
|
103
|
+
# completion evidence can be observed before the task metadata that names its parent.
|
|
104
|
+
# If both declarations wrote the same keys, whichever arrived first would decide the
|
|
105
|
+
# topology. Keeping them disjoint makes a positive child declaration authoritative
|
|
106
|
+
# regardless of arrival order, while absence of one still means root.
|
|
107
|
+
ATTR_ROLE = "agent_role"
|
|
108
|
+
|
|
109
|
+
ATTR_ROOT_PATH = "root_agent_path"
|
|
110
|
+
ATTR_ROOT_PATH_SOURCE = "root_agent_path_source"
|
|
111
|
+
ATTR_ROOT_EVIDENCE = "root_topology_evidence"
|
|
112
|
+
|
|
113
|
+
ATTR_PARENT_PATH = "parent_agent_path"
|
|
114
|
+
ATTR_PARENT_SCOPE = "parent_scope_id"
|
|
115
|
+
ATTR_PARENT_EVIDENCE = "parent_relation_source"
|
|
116
|
+
ATTR_CHILD_PATH = "child_agent_path"
|
|
117
|
+
|
|
118
|
+
# Pre-provenance artifacts wrote a bare path with no source. Read, never upgraded.
|
|
119
|
+
ATTR_LEGACY_PATH = "agent_path"
|
|
120
|
+
|
|
121
|
+
# Evidence vocabulary. Each value names the provider fact that established the
|
|
122
|
+
# relationship, so a reader can audit the claim back to its source.
|
|
123
|
+
EVIDENCE_PROVIDER_SESSION_ROOT = "provider_session_root"
|
|
124
|
+
EVIDENCE_SUBAGENT_LIFECYCLE_HOOK = "provider_subagent_lifecycle_hook"
|
|
125
|
+
EVIDENCE_ROLLOUT_SESSION_META = "provider_rollout_session_meta"
|
|
126
|
+
EVIDENCE_PARENT_SESSION_ID = "provider_parent_session_id"
|
|
127
|
+
EVIDENCE_VALIDATED_CHILD_TRANSCRIPT = "provider_validated_child_transcript"
|
|
128
|
+
EVIDENCE_CROSS_AGENT_ROUTING = "provider_cross_agent_routing_record"
|
|
129
|
+
EVIDENCE_NO_PARENT_EVIDENCE = "no_parent_evidence_observed"
|
|
130
|
+
EVIDENCE_LEGACY_ARTIFACT = "legacy_artifact_without_provenance"
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _text(value: object) -> str | None:
|
|
134
|
+
return value.strip() if isinstance(value, str) and value.strip() else None
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def root_topology(
|
|
138
|
+
*,
|
|
139
|
+
evidence: str = EVIDENCE_PROVIDER_SESSION_ROOT,
|
|
140
|
+
agent_path: str | None = None,
|
|
141
|
+
provider_declared_path: bool = False,
|
|
142
|
+
) -> dict[str, Any]:
|
|
143
|
+
"""Declare an agent node as the root of what was observed.
|
|
144
|
+
|
|
145
|
+
``/root`` is ExecWeave's canonical name for the top of a run. Unless the provider
|
|
146
|
+
literally published that path, ``root_agent_path_source`` stays
|
|
147
|
+
``execweave_derived`` even though the root position itself is provider-reported.
|
|
148
|
+
|
|
149
|
+
This never blocks a later subagent declaration: the keys are disjoint, so evidence
|
|
150
|
+
of a parent always wins over the absence of one.
|
|
151
|
+
"""
|
|
152
|
+
return {
|
|
153
|
+
ATTR_ROLE: AGENT_ROLE_ROOT,
|
|
154
|
+
ATTR_ROOT_PATH: _text(agent_path) or ROOT_PATH,
|
|
155
|
+
ATTR_ROOT_PATH_SOURCE: (
|
|
156
|
+
PATH_PROVIDER_DECLARED if provider_declared_path else PATH_EXECWEAVE_DERIVED
|
|
157
|
+
),
|
|
158
|
+
ATTR_ROOT_EVIDENCE: evidence,
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def subagent_topology(
|
|
163
|
+
*,
|
|
164
|
+
evidence: str,
|
|
165
|
+
parent_scope_id: str | None = None,
|
|
166
|
+
agent_path: str | None = None,
|
|
167
|
+
parent_agent_path: str | None = None,
|
|
168
|
+
) -> dict[str, Any]:
|
|
169
|
+
"""Declare an agent node as a child, naming the evidence that establishes it.
|
|
170
|
+
|
|
171
|
+
Call this only where the provider positively identified the agent as a subagent —
|
|
172
|
+
a subagent lifecycle hook, a rollout naming its parent thread, an explicit parent
|
|
173
|
+
session id. Never call it because an identifier looked unfamiliar.
|
|
174
|
+
|
|
175
|
+
Keys written here are absent from :func:`root_topology`, so this declaration is
|
|
176
|
+
authoritative however the events interleave. Only what this evidence actually
|
|
177
|
+
established is published; a path the provider never sent is simply omitted rather
|
|
178
|
+
than reserved as ``None``, which the first-write-wins merge would treat as final.
|
|
179
|
+
"""
|
|
180
|
+
declared: dict[str, Any] = {
|
|
181
|
+
ATTR_ROLE: AGENT_ROLE_SUBAGENT,
|
|
182
|
+
ATTR_PARENT_PATH: _text(parent_agent_path) or ROOT_PATH,
|
|
183
|
+
ATTR_PARENT_EVIDENCE: evidence,
|
|
184
|
+
}
|
|
185
|
+
path = _text(agent_path)
|
|
186
|
+
if path:
|
|
187
|
+
declared[ATTR_CHILD_PATH] = path
|
|
188
|
+
scope = _text(parent_scope_id)
|
|
189
|
+
if scope:
|
|
190
|
+
declared[ATTR_PARENT_SCOPE] = scope
|
|
191
|
+
return declared
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
@dataclass(frozen=True)
|
|
195
|
+
class AgentTopology:
|
|
196
|
+
"""One agent's position in the run, with the provenance of every claim."""
|
|
197
|
+
|
|
198
|
+
agent_path: str
|
|
199
|
+
agent_path_source: str
|
|
200
|
+
topology_state: str
|
|
201
|
+
topology_evidence: str | None
|
|
202
|
+
parent_agent_path: str | None
|
|
203
|
+
parent_relation_source: str | None
|
|
204
|
+
provider_native_id: str | None
|
|
205
|
+
is_root: bool
|
|
206
|
+
|
|
207
|
+
def to_dict(self) -> dict[str, Any]:
|
|
208
|
+
return {
|
|
209
|
+
"agent_path": self.agent_path,
|
|
210
|
+
"agent_path_source": self.agent_path_source,
|
|
211
|
+
"topology_state": self.topology_state,
|
|
212
|
+
"topology_evidence": self.topology_evidence,
|
|
213
|
+
"parent_agent_path": self.parent_agent_path,
|
|
214
|
+
"parent_relation_source": self.parent_relation_source,
|
|
215
|
+
"provider_native_id": self.provider_native_id,
|
|
216
|
+
"is_root": self.is_root,
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def _native_id(attributes: dict[str, Any], source: dict[str, Any]) -> str | None:
|
|
221
|
+
for key in ("agent_id", "subagent_id", "conversation_id", "thread_id", "session_id"):
|
|
222
|
+
value = _text(attributes.get(key))
|
|
223
|
+
if value:
|
|
224
|
+
return value
|
|
225
|
+
return _text(source.get("id"))
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def _derived_child_path(native_id: str | None, parent_path: str) -> str:
|
|
229
|
+
"""Render a canonical path for a child whose provider exposed no path of its own."""
|
|
230
|
+
leaf = (native_id or "agent").replace("/", "-")
|
|
231
|
+
base = parent_path.rstrip("/") or ROOT_PATH
|
|
232
|
+
return f"{base}/{leaf}"
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def resolve_agent_topology(source: dict[str, Any] | None) -> AgentTopology:
|
|
236
|
+
"""Read an agent node's topology, defaulting to root without parent evidence.
|
|
237
|
+
|
|
238
|
+
The one rule that matters: this never returns a child unless the node carries a
|
|
239
|
+
positive subagent declaration, or a legacy artifact already recorded a child path.
|
|
240
|
+
An unfamiliar id, a bare session id, a nickname, or a source type of ``agent`` are
|
|
241
|
+
all insufficient on their own.
|
|
242
|
+
"""
|
|
243
|
+
source = source if isinstance(source, dict) else {}
|
|
244
|
+
attributes = source.get("attributes")
|
|
245
|
+
attributes = attributes if isinstance(attributes, dict) else {}
|
|
246
|
+
native_id = _native_id(attributes, source)
|
|
247
|
+
|
|
248
|
+
parent_path = _text(attributes.get(ATTR_PARENT_PATH))
|
|
249
|
+
if parent_path:
|
|
250
|
+
child_path = _text(attributes.get(ATTR_CHILD_PATH))
|
|
251
|
+
evidence = _text(attributes.get(ATTR_PARENT_EVIDENCE))
|
|
252
|
+
return AgentTopology(
|
|
253
|
+
agent_path=child_path or _derived_child_path(native_id, parent_path),
|
|
254
|
+
agent_path_source=(
|
|
255
|
+
PATH_PROVIDER_DECLARED if child_path else PATH_EXECWEAVE_DERIVED
|
|
256
|
+
),
|
|
257
|
+
topology_state=(
|
|
258
|
+
TOPOLOGY_OBSERVED if child_path else TOPOLOGY_PROVIDER_REPORTED
|
|
259
|
+
),
|
|
260
|
+
topology_evidence=evidence,
|
|
261
|
+
parent_agent_path=parent_path,
|
|
262
|
+
parent_relation_source=evidence,
|
|
263
|
+
provider_native_id=native_id,
|
|
264
|
+
is_root=False,
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
legacy_path = _text(attributes.get(ATTR_LEGACY_PATH))
|
|
268
|
+
if legacy_path and legacy_path != ROOT_PATH:
|
|
269
|
+
# A pre-provenance artifact. Preserve what it recorded, but never upgrade an
|
|
270
|
+
# unlabelled path into a provider-observed claim.
|
|
271
|
+
return AgentTopology(
|
|
272
|
+
agent_path=legacy_path,
|
|
273
|
+
agent_path_source=PATH_LEGACY_UNKNOWN,
|
|
274
|
+
topology_state=TOPOLOGY_UNRESOLVED,
|
|
275
|
+
topology_evidence=EVIDENCE_LEGACY_ARTIFACT,
|
|
276
|
+
parent_agent_path=ROOT_PATH,
|
|
277
|
+
parent_relation_source=EVIDENCE_LEGACY_ARTIFACT,
|
|
278
|
+
provider_native_id=native_id,
|
|
279
|
+
is_root=False,
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
root_path = _text(attributes.get(ATTR_ROOT_PATH))
|
|
283
|
+
if root_path:
|
|
284
|
+
return AgentTopology(
|
|
285
|
+
agent_path=root_path,
|
|
286
|
+
agent_path_source=(
|
|
287
|
+
_text(attributes.get(ATTR_ROOT_PATH_SOURCE)) or PATH_EXECWEAVE_DERIVED
|
|
288
|
+
),
|
|
289
|
+
topology_state=(
|
|
290
|
+
TOPOLOGY_OBSERVED
|
|
291
|
+
if attributes.get(ATTR_ROOT_PATH_SOURCE) == PATH_PROVIDER_DECLARED
|
|
292
|
+
else TOPOLOGY_PROVIDER_REPORTED
|
|
293
|
+
),
|
|
294
|
+
topology_evidence=(
|
|
295
|
+
_text(attributes.get(ATTR_ROOT_EVIDENCE)) or EVIDENCE_PROVIDER_SESSION_ROOT
|
|
296
|
+
),
|
|
297
|
+
parent_agent_path=None,
|
|
298
|
+
parent_relation_source=None,
|
|
299
|
+
provider_native_id=native_id,
|
|
300
|
+
is_root=True,
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
# No positive child evidence anywhere: this agent is the root of what we observed.
|
|
304
|
+
return AgentTopology(
|
|
305
|
+
agent_path=ROOT_PATH,
|
|
306
|
+
agent_path_source=PATH_EXECWEAVE_DERIVED,
|
|
307
|
+
topology_state=TOPOLOGY_DERIVED,
|
|
308
|
+
topology_evidence=EVIDENCE_NO_PARENT_EVIDENCE,
|
|
309
|
+
parent_agent_path=None,
|
|
310
|
+
parent_relation_source=None,
|
|
311
|
+
provider_native_id=native_id,
|
|
312
|
+
is_root=True,
|
|
313
|
+
)
|