execweave 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. execweave/__init__.py +3 -0
  2. execweave/__main__.py +5 -0
  3. execweave/_conversation_records_core.py +902 -0
  4. execweave/_dashboard_shell_base.py +148 -0
  5. execweave/_http_proxy_base.py +565 -0
  6. execweave/_http_proxy_bounded.py +560 -0
  7. execweave/_http_proxy_stage.py +509 -0
  8. execweave/acceptance_output.py +19 -0
  9. execweave/agent_bootstrap.py +395 -0
  10. execweave/agent_topology.py +313 -0
  11. execweave/agent_trace.py +1162 -0
  12. execweave/agy_preview_sanitize.py +102 -0
  13. execweave/analysis.py +427 -0
  14. execweave/anthropic.py +228 -0
  15. execweave/anthropic_cli.py +171 -0
  16. execweave/anthropic_full_fidelity.py +385 -0
  17. execweave/antigravity_adapter.py +112 -0
  18. execweave/antigravity_adapter_base.py +479 -0
  19. execweave/antigravity_full_fidelity.py +656 -0
  20. execweave/antigravity_full_fidelity_base.py +172 -0
  21. execweave/antigravity_full_fidelity_collaboration_base.py +451 -0
  22. execweave/antigravity_hook_cli.py +209 -0
  23. execweave/antigravity_record.py +96 -0
  24. execweave/antigravity_subagent_linkage.py +449 -0
  25. execweave/antigravity_trace_capability.py +39 -0
  26. execweave/auto_specialized.py +547 -0
  27. execweave/backends.py +102 -0
  28. execweave/benchmark.py +80 -0
  29. execweave/claude_adapter.py +517 -0
  30. execweave/claude_child_transcript.py +314 -0
  31. execweave/claude_delegation.py +136 -0
  32. execweave/claude_full_fidelity.py +396 -0
  33. execweave/claude_hook_cli.py +209 -0
  34. execweave/claude_hook_contract.py +943 -0
  35. execweave/claude_model_observer.py +353 -0
  36. execweave/claude_record.py +106 -0
  37. execweave/cli.py +629 -0
  38. execweave/codex_adapter.py +455 -0
  39. execweave/codex_conversation.py +621 -0
  40. execweave/codex_full_fidelity.py +287 -0
  41. execweave/codex_hook_cli.py +301 -0
  42. execweave/codex_hook_entry.py +207 -0
  43. execweave/codex_hook_lifecycle.py +363 -0
  44. execweave/codex_message_diagnostics.py +322 -0
  45. execweave/codex_message_transport_diagnostics.py +399 -0
  46. execweave/codex_record.py +199 -0
  47. execweave/codex_rollout_structures.py +402 -0
  48. execweave/codex_rollout_trace.py +56 -0
  49. execweave/codex_rollout_trace_base.py +1509 -0
  50. execweave/collector.py +768 -0
  51. execweave/command.py +157 -0
  52. execweave/command_privacy.py +20 -0
  53. execweave/content_evidence.py +101 -0
  54. execweave/content_integrity.py +289 -0
  55. execweave/content_store.py +273 -0
  56. execweave/controlled_checks.py +561 -0
  57. execweave/conversation_archive.py +338 -0
  58. execweave/conversation_message_identity.py +264 -0
  59. execweave/conversation_preview.py +66 -0
  60. execweave/conversation_preview_antigravity.py +32 -0
  61. execweave/conversation_preview_claude.py +31 -0
  62. execweave/conversation_preview_codex.py +107 -0
  63. execweave/conversation_preview_common.py +180 -0
  64. execweave/conversation_preview_generic.py +188 -0
  65. execweave/conversation_preview_lines.py +133 -0
  66. execweave/conversation_preview_transcript.py +121 -0
  67. execweave/conversation_records.py +349 -0
  68. execweave/conversation_records_antigravity.py +370 -0
  69. execweave/conversation_records_codex.py +83 -0
  70. execweave/conversation_records_common.py +17 -0
  71. execweave/conversation_records_ollama.py +39 -0
  72. execweave/correlation.py +818 -0
  73. execweave/cursor_adapter.py +349 -0
  74. execweave/cursor_delegation.py +87 -0
  75. execweave/cursor_delegation_base.py +220 -0
  76. execweave/cursor_full_fidelity.py +489 -0
  77. execweave/cursor_hook_cli.py +195 -0
  78. execweave/cursor_hook_contract.py +439 -0
  79. execweave/cursor_lifecycle.py +159 -0
  80. execweave/cursor_record.py +96 -0
  81. execweave/dashboard_shell.py +283 -0
  82. execweave/delivery_status.py +94 -0
  83. execweave/entry.py +98 -0
  84. execweave/evidence_availability.py +113 -0
  85. execweave/evidence_grade.py +166 -0
  86. execweave/fidelity.py +304 -0
  87. execweave/filesystem.py +327 -0
  88. execweave/finalization.py +92 -0
  89. execweave/focus.py +118 -0
  90. execweave/framework_adapters/__init__.py +34 -0
  91. execweave/framework_adapters/autogen.py +398 -0
  92. execweave/framework_adapters/base.py +580 -0
  93. execweave/framework_adapters/camel.py +270 -0
  94. execweave/framework_adapters/camel_channel.py +71 -0
  95. execweave/framework_adapters/metagpt.py +315 -0
  96. execweave/framework_adapters/metagpt_ollama_compat.py +54 -0
  97. execweave/framework_adapters/metagpt_recording.py +342 -0
  98. execweave/framework_adapters/registry.py +90 -0
  99. execweave/graph.py +590 -0
  100. execweave/graph_ops.py +472 -0
  101. execweave/hook_command.py +32 -0
  102. execweave/hook_delivery.py +32 -0
  103. execweave/hook_input.py +16 -0
  104. execweave/http_proxy.py +187 -0
  105. execweave/http_proxy_cli.py +84 -0
  106. execweave/inference_gateway.py +476 -0
  107. execweave/inference_gateway_cli.py +211 -0
  108. execweave/inference_gateway_full_fidelity.py +613 -0
  109. execweave/inference_identity.py +76 -0
  110. execweave/inference_identity_cli.py +60 -0
  111. execweave/integrity.py +235 -0
  112. execweave/integrity_cli.py +55 -0
  113. execweave/investigation_index.py +445 -0
  114. execweave/litellm_callback.py +211 -0
  115. execweave/litellm_callback_cli.py +42 -0
  116. execweave/live.py +445 -0
  117. execweave/live_core.py +972 -0
  118. execweave/live_view.py +109 -0
  119. execweave/live_view_extra_style.py +11 -0
  120. execweave/live_view_markup.py +29 -0
  121. execweave/live_view_process_layout.py +650 -0
  122. execweave/live_view_readability.py +502 -0
  123. execweave/live_view_script_a.py +59 -0
  124. execweave/live_view_script_b.py +97 -0
  125. execweave/live_view_script_c.py +59 -0
  126. execweave/live_view_script_d.py +40 -0
  127. execweave/live_view_style.py +34 -0
  128. execweave/model_runtime.py +560 -0
  129. execweave/model_runtime_cli.py +265 -0
  130. execweave/model_runtime_full_fidelity.py +519 -0
  131. execweave/observation.py +53 -0
  132. execweave/observation_demo.py +69 -0
  133. execweave/openai_agents.py +267 -0
  134. execweave/openai_agents_sdk.py +453 -0
  135. execweave/openai_compatible.py +239 -0
  136. execweave/openai_compatible_cli.py +189 -0
  137. execweave/openai_compatible_full_fidelity.py +438 -0
  138. execweave/opencode_adapter.py +325 -0
  139. execweave/opencode_event_contract.py +734 -0
  140. execweave/opencode_full_fidelity.py +198 -0
  141. execweave/opencode_hook_cli.py +119 -0
  142. execweave/opencode_plugin_cli.py +150 -0
  143. execweave/opencode_record.py +96 -0
  144. execweave/opencode_task_linkage.py +225 -0
  145. execweave/overhead_benchmark.py +440 -0
  146. execweave/privacy.py +84 -0
  147. execweave/private_io.py +465 -0
  148. execweave/provider_capability.py +578 -0
  149. execweave/provider_lifecycle.py +282 -0
  150. execweave/provider_record.py +290 -0
  151. execweave/reader_identity.py +13 -0
  152. execweave/redacted_archive.py +906 -0
  153. execweave/risk.py +106 -0
  154. execweave/rule_pack.py +359 -0
  155. execweave/rule_pack_cli.py +57 -0
  156. execweave/run_assessment.py +200 -0
  157. execweave/runtime_endpoint_availability.py +44 -0
  158. execweave/scalability_benchmark.py +195 -0
  159. execweave/schema.py +62 -0
  160. execweave/scope.py +85 -0
  161. execweave/semantic.py +453 -0
  162. execweave/session_summary.py +159 -0
  163. execweave/sink.py +71 -0
  164. execweave/strace_backend.py +927 -0
  165. execweave/stream_assembly.py +363 -0
  166. execweave/task_artifacts.py +192 -0
  167. execweave/task_validation.py +317 -0
  168. execweave/theme.py +40 -0
  169. execweave/top.py +599 -0
  170. execweave/top_cli.py +150 -0
  171. execweave/validate.py +196 -0
  172. execweave/vendor/dagre.min.js +815 -0
  173. execweave/view_cli.py +49 -0
  174. execweave/viewer.py +474 -0
  175. execweave/viewer_agent_panel.py +630 -0
  176. execweave/viewer_agent_panel_antigravity.py +31 -0
  177. execweave/viewer_agent_panel_claude.py +9 -0
  178. execweave/viewer_agent_panel_codex.py +50 -0
  179. execweave/viewer_agent_panel_cursor.py +9 -0
  180. execweave/viewer_agent_panel_default.py +79 -0
  181. execweave/viewer_agent_panel_ollama.py +20 -0
  182. execweave/viewer_agent_panel_opencode.py +9 -0
  183. execweave/viewer_agent_panel_registry.py +20 -0
  184. execweave/viewer_archive_verifier.py +178 -0
  185. execweave/viewer_background_files.py +86 -0
  186. execweave/viewer_content_browser.py +307 -0
  187. execweave/viewer_content_health.py +208 -0
  188. execweave/viewer_content_inspector.py +309 -0
  189. execweave/viewer_controlled_checks.py +258 -0
  190. execweave/viewer_conversation_sync.py +115 -0
  191. execweave/viewer_dashboard_clean.py +405 -0
  192. execweave/viewer_dashboard_focus.py +127 -0
  193. execweave/viewer_dashboard_hardening.py +264 -0
  194. execweave/viewer_dashboard_hardening_v2.py +62 -0
  195. execweave/viewer_dashboard_projection.py +261 -0
  196. execweave/viewer_delivery_status.py +155 -0
  197. execweave/viewer_edge_decross.py +117 -0
  198. execweave/viewer_execution_flow.py +611 -0
  199. execweave/viewer_execution_flow_provider_normalization.py +107 -0
  200. execweave/viewer_execution_flow_safety.py +349 -0
  201. execweave/viewer_external_endpoints.py +307 -0
  202. execweave/viewer_flow_canvas.py +1140 -0
  203. execweave/viewer_flow_layout.py +922 -0
  204. execweave/viewer_fold_state.py +31 -0
  205. execweave/viewer_framework_flow.py +68 -0
  206. execweave/viewer_framework_model_output.py +133 -0
  207. execweave/viewer_gif.py +278 -0
  208. execweave/viewer_history_browser.py +225 -0
  209. execweave/viewer_investigation.py +268 -0
  210. execweave/viewer_layout_geometry.py +192 -0
  211. execweave/viewer_layout_v2.py +429 -0
  212. execweave/viewer_layout_v2_detached.py +25 -0
  213. execweave/viewer_limits.py +93 -0
  214. execweave/viewer_live_layout.py +61 -0
  215. execweave/viewer_message_handoffs.py +114 -0
  216. execweave/viewer_projection.py +488 -0
  217. execweave/viewer_projection_base.py +522 -0
  218. execweave/viewer_projection_bridges.py +214 -0
  219. execweave/viewer_recorded_sources.py +146 -0
  220. execweave/viewer_run_assessment.py +274 -0
  221. execweave/viewer_run_guide.py +175 -0
  222. execweave/viewer_runtime_evidence.py +258 -0
  223. execweave/viewer_semantic_projection.py +641 -0
  224. execweave/viewer_session_flow.py +491 -0
  225. execweave/viewer_structure_share.py +132 -0
  226. execweave/viewer_task_validation.py +241 -0
  227. execweave/viewer_tool_mirror_identity.py +75 -0
  228. execweave/viewer_workflow_mode.py +127 -0
  229. execweave/workflow.py +183 -0
  230. execweave-1.0.0.dist-info/METADATA +462 -0
  231. execweave-1.0.0.dist-info/RECORD +234 -0
  232. execweave-1.0.0.dist-info/WHEEL +4 -0
  233. execweave-1.0.0.dist-info/entry_points.txt +30 -0
  234. execweave-1.0.0.dist-info/licenses/LICENSE +16 -0
@@ -0,0 +1,107 @@
1
+ from __future__ import annotations
2
+
3
+
4
+ _EXACT_SUBTASK_ACTION = """ const evidenceEdges=[...requests,...assignments,...childSessionEdges];
5
+ pushOccurrence(
6
+ 'assign_agent_task',owner,[target],assignmentSeed,[subtask.id],
7
+ evidenceEdges.map(edge=>edge.id).filter(Boolean)
8
+ );"""
9
+ _EXACT_SUBTASK_ACTION_NORMALIZED = """ const evidenceEdges=[...requests,...assignments,...childSessionEdges];
10
+ const matchingSpawn=occurrences.find(occurrence=>
11
+ occurrence.kind==='spawn_agent'&&occurrence.owner===owner&&occurrence.targets.has(target)
12
+ );
13
+ if(matchingSpawn){
14
+ if(!matchingSpawn.rawNodeIds.includes(subtask.id))matchingSpawn.rawNodeIds.push(subtask.id);
15
+ for(const edgeIdValue of evidenceEdges.map(edge=>edge.id).filter(Boolean)){
16
+ if(!matchingSpawn.rawEdgeIds.includes(edgeIdValue))matchingSpawn.rawEdgeIds.push(edgeIdValue);
17
+ }
18
+ }else{
19
+ pushOccurrence(
20
+ 'assign_agent_task',owner,[target],assignmentSeed,[subtask.id],
21
+ evidenceEdges.map(edge=>edge.id).filter(Boolean)
22
+ );
23
+ }"""
24
+
25
+ _ACTION_TARGET_END = """ for(const target of [...group.targets].sort()){
26
+ addedEdges.push({
27
+ id:`viewer:${id}--${targetRelation}-->${target}`,source:id,target,relation:targetRelation,
28
+ count:1,viewer_only:true,causal:false,inferred:false,
29
+ attributes:{viewer_only:true,projection:'execution_flow',evidence_node_ids:[...group.rawNodeIds],evidence_edge_ids:[...group.rawEdgeIds]}
30
+ });
31
+ }
32
+ for(const rawId of group.rawNodeIds)consumedRawNodes.add(rawId);"""
33
+ _ACTION_TARGET_WITH_PAYLOADS = """ for(const target of [...group.targets].sort()){
34
+ addedEdges.push({
35
+ id:`viewer:${id}--${targetRelation}-->${target}`,source:id,target,relation:targetRelation,
36
+ count:1,viewer_only:true,causal:false,inferred:false,
37
+ attributes:{viewer_only:true,projection:'execution_flow',evidence_node_ids:[...group.rawNodeIds],evidence_edge_ids:[...group.rawEdgeIds]}
38
+ });
39
+ }
40
+ // Retarget visible detail edges onto the replacement action, but never onto
41
+ // peers that other flow groups also consume (prevents dangling action ->
42
+ // consumed interaction anchors in Codex reduced-state replay).
43
+ const peerConsumedRawNodeIds=new Set();
44
+ for(const other of groups.values())for(const rawId of other.rawNodeIds)peerConsumedRawNodeIds.add(rawId);
45
+ const detailRelations=new Set([
46
+ 'HAS_SUBTASK_PROMPT','HAS_SUBTASK_DESCRIPTION','TARGETS_AGENT_PROFILE',
47
+ 'HAS_COMMAND','HAS_WORKING_DIRECTORY','USES_PROFILE','READS_FILE','WRITES_FILE',
48
+ 'HAS_FILE','OBSERVED_CONTENT','HAS_TOOL_INPUT','HAS_TOOL_OUTPUT'
49
+ ]);
50
+ for(const rawId of group.rawNodeIds){
51
+ for(const rawEdge of outgoing.get(rawId)||[]){
52
+ const payloadRelation=relation(rawEdge);
53
+ if(!detailRelations.has(payloadRelation))continue;
54
+ const detailTarget=rawEdge.target;
55
+ // Skip retargeting into another group's consumed anchors.
56
+ if(peerConsumedRawNodeIds.has(detailTarget)&&!group.rawNodeIds.has(detailTarget))continue;
57
+ if(!display.nodes.some(node=>node?.id===detailTarget)&&!rawById.has(detailTarget))continue;
58
+ // Do not paint observed_content back onto the canvas; content stays hidden
59
+ // and is exposed via viewer_content_references on the action instead.
60
+ const targetNode=rawById.get(detailTarget)||display.nodes.find(node=>node?.id===detailTarget);
61
+ if(targetNode?.type==='observed_content')continue;
62
+ if(targetNode?.type==='agent_interaction')continue;
63
+ addedEdges.push({
64
+ id:`viewer:${id}--${payloadRelation}-->${detailTarget}:evidence:${encodeURIComponent(rawEdge.id||rawId)}`,
65
+ source:id,target:detailTarget,relation:rawEdge.relation||payloadRelation,
66
+ count:Number.isFinite(rawEdge.count)?rawEdge.count:1,viewer_only:true,causal:false,inferred:false,
67
+ attributes:{viewer_only:true,projection:'execution_flow',evidence_node_ids:[rawId],evidence_edge_ids:[rawEdge.id].filter(Boolean)}
68
+ });
69
+ if(rawEdge.id)consumedRawEdges.add(rawEdge.id);
70
+ }
71
+ }
72
+ for(const rawId of group.rawNodeIds)consumedRawNodes.add(rawId);"""
73
+
74
+ _EDGE_FILTER = " if(consumedRawEdges.has(edge.id))return false;"
75
+ _EDGE_FILTER_NO_DANGLING = """ if(consumedRawEdges.has(edge.id))return false;
76
+ // Drop edges that still point at consumed presentation nodes, but never use
77
+ // this as a blanket cover for lost evidence — detail retargeting above must
78
+ // have preserved reachable payloads onto the replacement action first.
79
+ if(consumedRawNodes.has(edge.source)||consumedRawNodes.has(edge.target))return false;"""
80
+
81
+
82
+ def normalize_provider_execution_flow(html: str) -> str:
83
+ """Normalize equivalent exact delegation encodings without weakening evidence gates.
84
+
85
+ Cursor may report both a direct child-start lifecycle edge and an exact subtask
86
+ assignment for the same child. Those are two observations of one delegation, not two
87
+ orchestration actions. The exact subtask evidence is folded into the existing spawn
88
+ occurrence when both owner and child already match. Providers without a direct spawn
89
+ (for example the validated Antigravity assignment path) keep the assignment action.
90
+
91
+ Superseded task/tool-call nodes are presentation-only removals. Any provider-observed
92
+ task prompt/description remains reachable from the replacement orchestration action,
93
+ and no display edge is allowed to reference a consumed node. The raw graph is never
94
+ mutated by this normalizer.
95
+ """
96
+ seams = (
97
+ (_EXACT_SUBTASK_ACTION, _EXACT_SUBTASK_ACTION_NORMALIZED, "exact-subtask fold"),
98
+ (_ACTION_TARGET_END, _ACTION_TARGET_WITH_PAYLOADS, "delegation payload preservation"),
99
+ (_EDGE_FILTER, _EDGE_FILTER_NO_DANGLING, "consumed-node edge filter"),
100
+ )
101
+ for needle, replacement, label in seams:
102
+ if html.count(needle) != 1:
103
+ raise RuntimeError(f"execution-flow provider normalization seam changed: {label}")
104
+ html = html.replace(needle, replacement, 1)
105
+ from .viewer_session_flow import inject_session_flow
106
+
107
+ return inject_session_flow(html)
@@ -0,0 +1,349 @@
1
+ from __future__ import annotations
2
+
3
+
4
+ _DIRECT_ASSIGN = " ['ASSIGNED_AGENT_TASK','assign_agent_task'],\n"
5
+ _DIRECT_SUBTASK = " ['REQUESTED_SUBTASK','assign_agent_task'],\n"
6
+ _ASSIGN_TARGET = " ['assign_agent_task','ASSIGNED_AGENT_TASK'],"
7
+ _SAFE_ASSIGN_TARGET = " ['assign_agent_task','TARGETED_AGENT'],"
8
+ _ACTION_NAME = """ const actionName=value=>{
9
+ const text=String(value||'').trim().toLowerCase().replace(/[\\s-]+/g,'_');
10
+ return ACTION_ALIASES.get(text)||null;
11
+ };"""
12
+ _SAFE_ACTION_NAME = """ const actionName=value=>{
13
+ const raw=value&&typeof value==='object'&&typeof value.type==='string'?value.type:value;
14
+ const text=String(raw||'').trim().toLowerCase().replace(/[\\s-]+/g,'_');
15
+ return ACTION_ALIASES.get(text)||null;
16
+ };"""
17
+ _PROVIDER_HELPER = " const provider=node=>String(attrsOf(node).provider||'unknown').toLowerCase();"
18
+ _SAFE_PROVIDER_HELPER = """ const provider=node=>String(attrsOf(node).provider||'unknown').toLowerCase();
19
+ const providerObservedEdge=edge=>{
20
+ // Inferred / viewer-only edges must never authorize orchestration projection.
21
+ // Semantic provenance alone does not upgrade inferred evidence into observed truth.
22
+ if(!edge)return false;
23
+ const evidence=attrsOf(edge);
24
+ if(edge.inferred===true||evidence.inferred===true)return false;
25
+ if(edge.viewer_only===true||evidence.viewer_only===true)return false;
26
+ const eventTypes=Array.isArray(edge?.event_types)?edge.event_types:[];
27
+ const backends=Array.isArray(edge?.backends)?edge.backends:[];
28
+ const attributions=Array.isArray(edge?.attributions)?edge.attributions:[];
29
+ const lifecycle=Array.isArray(edge?.provider_lifecycle)?edge.provider_lifecycle:[];
30
+ return Boolean(
31
+ evidence.provider||evidence.evidence_source||evidence.attribution||
32
+ evidence.provider_event||evidence.provider_event_type||
33
+ lifecycle.length||attributions.length||
34
+ backends.some(value=>String(value).toLowerCase()==='semantic')||
35
+ eventTypes.some(value=>String(value).toLowerCase().startsWith('semantic.'))
36
+ );
37
+ };"""
38
+ _OWNER_FOR_NODE = """ const uniqueOwner=candidates=>{
39
+ const ids=[...new Set((candidates||[]).filter(Boolean))];
40
+ return ids.length===1?ids[0]:null;
41
+ };
42
+ const ownerForNode=node=>{
43
+ if(!node?.id)return null;
44
+ const direct=[];
45
+ for(const edge of incoming.get(node.id)||[])if(agents.has(edge.source))direct.push(edge.source);
46
+ const directOwner=uniqueOwner(direct);
47
+ if(directOwner)return directOwner;
48
+ if(direct.length)return null; // ambiguous direct owners
49
+ const viaTurn=[];
50
+ for(const edge of incoming.get(node.id)||[]){
51
+ const parent=rawById.get(edge.source);
52
+ if(parent?.type!=='agent_turn')continue;
53
+ for(const grand of incoming.get(parent.id)||[])if(agents.has(grand.source))viaTurn.push(grand.source);
54
+ }
55
+ const turnOwner=uniqueOwner(viaTurn);
56
+ if(turnOwner)return turnOwner;
57
+ if(viaTurn.length)return null;
58
+ const attrs=attrsOf(node);
59
+ const attrOwners=[];
60
+ for(const key of ['owner_agent_id','agent_id','source_agent_id','thread_id','agent_path']){
61
+ const found=resolveAgent(attrs[key]);if(found)attrOwners.push(found);
62
+ }
63
+ return uniqueOwner(attrOwners);
64
+ };"""
65
+ _SAFE_OWNER_FOR_NODE = """ const uniqueOwner=candidates=>{
66
+ const ids=[...new Set((candidates||[]).filter(Boolean))];
67
+ return ids.length===1?ids[0]:null;
68
+ };
69
+ const ownerForNode=node=>{
70
+ if(!node?.id)return null;
71
+ const candidates=new Set();
72
+ for(const edge of incoming.get(node.id)||[])if(agents.has(edge.source))candidates.add(edge.source);
73
+ for(const edge of incoming.get(node.id)||[]){
74
+ const parent=rawById.get(edge.source);
75
+ if(parent?.type!=='agent_turn')continue;
76
+ for(const grand of incoming.get(parent.id)||[])if(agents.has(grand.source))candidates.add(grand.source);
77
+ }
78
+ const attrs=attrsOf(node);
79
+ for(const key of ['owner_agent_id','agent_id','source_agent_id','thread_id','agent_path']){
80
+ const found=resolveAgent(attrs[key]);if(found)candidates.add(found);
81
+ }
82
+ return candidates.size===1?[...candidates][0]:null;
83
+ };"""
84
+ _MODEL_EDGE_LOOP = """ for(const edge of rawEdges){
85
+ if(!agents.has(edge?.source)||!models.has(edge?.target)||!MODEL_RELATIONS.has(relation(edge)))continue;
86
+ addModelEvent(edge.source,edge.target,edge);
87
+ }"""
88
+ _SAFE_MODEL_EDGE_LOOP = """ for(const edge of rawEdges){
89
+ if(!models.has(edge?.target)||!MODEL_RELATIONS.has(relation(edge))||!providerObservedEdge(edge))continue;
90
+ const owner=agentForAnchor(edge.source);
91
+ if(owner)addModelEvent(owner,edge.target,edge);
92
+ }"""
93
+ _MODEL_FILTER = " if(modelRelation(edge)&&agents.has(edge.source)&&contextIds.has(contextId(edge.source,edge.target)))return false;"
94
+ _SAFE_MODEL_FILTER = " if(modelRelation(edge)&&agents.has(edge.source)&&contextIds.has(contextId(edge.source,edge.target)))return false;"
95
+ _TOOL_RESOLVE = " if(relation(edge)!=='USES_TOOL')continue;"
96
+ _SAFE_TOOL_RESOLVE = " if(!['USES_TOOL','RESOLVED_TOOL'].includes(relation(edge)))continue;"
97
+ _TOOL_CONSUME = " const uses=(incoming.get(toolId)||[]).filter(edge=>['USES_TOOL','RESOLVED_TOOL'].includes(relation(edge)));"
98
+ _SAFE_TOOL_CONSUME = " const uses=(incoming.get(toolId)||[]).filter(edge=>['USES_TOOL','RESOLVED_TOOL'].includes(relation(edge)));"
99
+ _MODEL_ONLY_ACTIVATION = (
100
+ " if(!occurrences.length&&![...modelEventsByAgent.values()].some(list=>list.length))return display;"
101
+ )
102
+ _ACTION_ONLY_ACTIVATION = " if(!occurrences.length)return display;"
103
+ _TARGETED_ACTIVATION = """ const resolvedOccurrences=occurrences.filter(occurrence=>occurrence.targets.size>0);
104
+ if(!resolvedOccurrences.length)return display;"""
105
+ _WAIT_AWARE_ACTIVATION = """ const spawnEdges=rawEdges.filter(edge=>
106
+ providerObservedEdge(edge)&&['SPAWNED_AGENT','SPAWNED_SUBAGENT'].includes(relation(edge))&&
107
+ agents.has(agentForAnchor(edge.source))&&agents.has(agentForAnchor(edge.target))
108
+ );
109
+ const terminalEdges=rawEdges.filter(edge=>
110
+ providerObservedEdge(edge)&&['SUBAGENT_STOPPED','CLOSED_AGENT'].includes(relation(edge))
111
+ );
112
+ for(const occurrence of occurrences){
113
+ if(occurrence.kind!=='wait_agent'||occurrence.targets.size)continue;
114
+ const at=moment(occurrence.item);
115
+ for(const spawn of spawnEdges){
116
+ const owner=agentForAnchor(spawn.source),child=agentForAnchor(spawn.target);
117
+ if(owner!==occurrence.owner||!child||child===owner||!momentLE(moment(spawn),at))continue;
118
+ const ended=terminalEdges.some(edge=>{
119
+ const r=relation(edge),a=agentForAnchor(edge.source),b=agentForAnchor(edge.target);
120
+ const touches=r==='SUBAGENT_STOPPED'?a===child&&b===owner:a===owner&&b===child;
121
+ return touches&&momentLE(moment(edge),at);
122
+ });
123
+ if(!ended)occurrence.targets.add(child);
124
+ }
125
+ }
126
+ // Actions belong to the actor's model at the time of the action. A child's
127
+ // model never changes the model that issued a delegation, message, or wait.
128
+ const resolvedOccurrences=occurrences.filter(occurrence=>occurrence.targets.size>0);
129
+ if(!resolvedOccurrences.length)return display;
130
+ const flowKey=occurrence=>`${occurrence.owner}\\u0000${occurrence.kind}\\u0000${occurrence.modelId||''}`;
131
+ const resolvedKeys=new Set(resolvedOccurrences.map(flowKey));
132
+ // Once a group is justified by at least one resolved target, retain target-less
133
+ // provider call occurrences from that same owner/model/action group as evidence.
134
+ // This lets the projected action consume the original tool-call/tool definition
135
+ // instead of drawing a second visual spawn/send/wait node beside it.
136
+ const groupedOccurrences=occurrences.filter(occurrence=>
137
+ occurrence.targets.size>0||resolvedKeys.has(flowKey(occurrence))
138
+ );"""
139
+ _GROUP_BLOCK_START = """ const groups=new Map();
140
+ for(const occurrence of occurrences){"""
141
+ _EVIDENCE_GROUP_BLOCK_START = """ const groups=new Map();
142
+ for(const occurrence of groupedOccurrences){"""
143
+ _EAGER_CONTEXTS = """ for(const [owner,list] of modelEventsByAgent){
144
+ for(const modelId of new Set(list.map(item=>item.modelId)))ensureContext(owner,modelId);
145
+ }
146
+
147
+ """
148
+ _DIRECT_ACTION_LOOP = """ for(const edge of rawEdges){
149
+ const kind=DIRECT_ACTION_RELATIONS.get(relation(edge));
150
+ if(!kind)continue;
151
+ const owner=agentForAnchor(edge.source),target=agentForAnchor(edge.target);
152
+ if(owner&&target&&owner!==target)pushOccurrence(kind,owner,[target],edge,[],[edge.id].filter(Boolean));
153
+ }"""
154
+ _SAFE_DIRECT_ACTION_LOOP = """ for(const edge of rawEdges){
155
+ const kind=DIRECT_ACTION_RELATIONS.get(relation(edge));
156
+ if(!kind||!providerObservedEdge(edge))continue;
157
+ const owner=agentForAnchor(edge.source),target=agentForAnchor(edge.target);
158
+ if(owner&&target&&owner!==target)pushOccurrence(kind,owner,[target],edge,[],[edge.id].filter(Boolean));
159
+ }
160
+
161
+ // Some providers expose delegation as an exact two-edge chain rather than a
162
+ // direct parent -> child spawn edge: requester -> subtask -> assigned child.
163
+ // Project that chain only when both endpoints are unique and the provider has
164
+ // supplied exact child linkage. This admits real Antigravity/Cursor evidence
165
+ // while continuing to abstain on profile-only or otherwise ambiguous subtasks.
166
+ // The raw subtask and child-session edges remain embedded evidence; they are
167
+ // merely superseded on the main canvas by the single action path.
168
+ const exactAssignmentRelation=['ASSIGNED','AGENT','TASK'].join('_');
169
+ const exactDelegationEdge=edge=>edge?.identity_exact===true||attrsOf(edge).identity_exact===true;
170
+ const seenDelegationSubtasks=new Set();
171
+ for(const assignmentSeed of rawEdges){
172
+ if(relation(assignmentSeed)!==exactAssignmentRelation||!providerObservedEdge(assignmentSeed))continue;
173
+ const subtask=rawById.get(assignmentSeed.source);
174
+ if(subtask?.type!=='subtask'||seenDelegationSubtasks.has(subtask.id))continue;
175
+ seenDelegationSubtasks.add(subtask.id);
176
+ const assignments=(outgoing.get(subtask.id)||[]).filter(edge=>
177
+ relation(edge)===exactAssignmentRelation&&providerObservedEdge(edge)
178
+ );
179
+ const assignmentTargetList=assignments.map(edge=>agentForAnchor(edge.target));
180
+ // Unknown endpoints must fail closed: filter(Boolean) would invent uniqueness.
181
+ if(assignmentTargetList.some(value=>!value))continue;
182
+ const assignmentTargets=new Set(assignmentTargetList);
183
+ if(assignmentTargets.size!==1)continue;
184
+ const target=[...assignmentTargets][0];
185
+ const requests=(incoming.get(subtask.id)||[]).filter(edge=>
186
+ relation(edge)==='REQUESTED_SUBTASK'&&providerObservedEdge(edge)
187
+ );
188
+ const requestOwnerList=requests.map(edge=>agentForAnchor(edge.source));
189
+ if(requestOwnerList.some(value=>!value))continue;
190
+ const requestOwners=new Set(requestOwnerList);
191
+ if(requestOwners.size!==1)continue;
192
+ const owner=[...requestOwners][0];
193
+ if(!owner||!target||owner===target)continue;
194
+ // Explicit identity_exact=false on any request/assignment rejects the chain.
195
+ if([...requests,...assignments].some(edge=>edge?.identity_exact===false||attrsOf(edge).identity_exact===false))continue;
196
+ const subtaskExact=attrsOf(subtask).exact_child_agent_linkage===true;
197
+ if(!subtaskExact&&!(requests.length&&assignments.length&&requests.every(exactDelegationEdge)&&assignments.every(exactDelegationEdge)))continue;
198
+ const scopedProviders=[provider(agents.get(owner)),provider(agents.get(target)),provider(subtask)]
199
+ .filter(value=>value&&value!=='unknown');
200
+ if(new Set(scopedProviders).size>1)continue;
201
+ const childSessionEdges=rawEdges.filter(edge=>
202
+ relation(edge)==='HAS_CHILD_AGENT_SESSION'&&providerObservedEdge(edge)&&
203
+ agentForAnchor(edge.source)===owner&&agentForAnchor(edge.target)===target
204
+ );
205
+ const evidenceEdges=[...requests,...assignments,...childSessionEdges];
206
+ pushOccurrence(
207
+ 'assign_agent_task',owner,[target],assignmentSeed,[subtask.id],
208
+ evidenceEdges.map(edge=>edge.id).filter(Boolean)
209
+ );
210
+ }
211
+
212
+ // A provider can also expose the exact child directly from an owner-bound tool
213
+ // call. Keep the generic assignment relation disabled: only an exact materialized
214
+ // identity edge plus a unique call owner and real agent target can enter the flow.
215
+ for(const assignment of rawEdges){
216
+ if(relation(assignment)!==exactAssignmentRelation||!providerObservedEdge(assignment)||!exactDelegationEdge(assignment))continue;
217
+ const anchor=rawById.get(assignment.source);
218
+ if(anchor?.type!=='tool_call')continue;
219
+ const owner=agentForAnchor(anchor.id),target=agentForAnchor(assignment.target);
220
+ if(!owner||!target||owner===target)continue;
221
+ const scopedProviders=[provider(agents.get(owner)),provider(agents.get(target)),provider(anchor)]
222
+ .filter(value=>value&&value!=='unknown');
223
+ if(new Set(scopedProviders).size>1)continue;
224
+ const supportEdges=[
225
+ ...(incoming.get(anchor.id)||[]).filter(edge=>
226
+ relation(edge)==='REQUESTED_TOOL_CALL'&&providerObservedEdge(edge)&&agentForAnchor(edge.source)===owner
227
+ ),
228
+ ...(outgoing.get(anchor.id)||[]).filter(edge=>
229
+ ['USES_TOOL','RESOLVED_TOOL'].includes(relation(edge))&&providerObservedEdge(edge)
230
+ ),
231
+ assignment,
232
+ ];
233
+ pushOccurrence(
234
+ 'assign_agent_task',owner,[target],assignment,[anchor.id],
235
+ supportEdges.map(edge=>edge.id).filter(Boolean)
236
+ );
237
+ }"""
238
+ _HIERARCHY_PARENT_ONLY = " if(group.kind!=='spawn_agent')continue;"
239
+ _HIERARCHY_PARENT_SAFE = " if(!['spawn_agent','assign_agent_task'].includes(group.kind))continue;"
240
+ _HIERARCHY_RANK_ONLY = " if(group.kind!=='spawn_agent'||!agentRank.has(group.owner))continue;"
241
+ _HIERARCHY_RANK_SAFE = " if(!['spawn_agent','assign_agent_task'].includes(group.kind)||!agentRank.has(group.owner))continue;"
242
+ _FLOW_EARLY_RETURN = " if(ranked.length<2)return topo;"
243
+ _FLOW_SAFE_EARLY_RETURN = """ const finalizeFlowGeometry=()=>{
244
+ const previousTopology=execweaveTopology;
245
+ execweaveTopology=topo;
246
+ try{
247
+ // This is the final layout wrapper in the shared Dashboard. Re-run the
248
+ // hard no-overlap gate after execution-flow X columns (or even when no
249
+ // flow ranks exist), because a later presentation column move must never
250
+ // invalidate Layout V2's earlier geometry guarantees.
251
+ if(typeof execweaveSeparateOverlappingNodes==='function')execweaveSeparateOverlappingNodes({spec:topo.spec});
252
+ const placement=new Map([...topo.spec].map(([id,spec])=>[id,{x:spec.x,y:spec.y}]));
253
+ if(typeof execweaveLayoutV2SyncFinalOrder==='function')execweaveLayoutV2SyncFinalOrder(topo,placement);
254
+ if(typeof execweaveRecomputePorts==='function')execweaveRecomputePorts(topo);
255
+ }finally{execweaveTopology=previousTopology}
256
+ return topo;
257
+ };
258
+ if(ranked.length<2)return finalizeFlowGeometry();"""
259
+ _FLOW_END = """ if(typeof execweaveRecomputePorts==='function')execweaveRecomputePorts(topo);
260
+ return topo;
261
+ }
262
+ window.execweaveApplyExecutionFlowColumns=execweaveApplyExecutionFlowColumns;"""
263
+ _FLOW_SAFE_END = """ return finalizeFlowGeometry();
264
+ }
265
+ window.execweaveApplyExecutionFlowColumns=execweaveApplyExecutionFlowColumns;"""
266
+
267
+
268
+ def harden_execution_flow_projection(html: str) -> str:
269
+ """Fail closed on ambiguous or evidence-poor execution-flow projection.
270
+
271
+ A model context is shown only for orchestration that resolves to real target agents.
272
+ The actor's evidenced model context owns the action, independently of the target's
273
+ model. Explicit targets are preferred.
274
+ Target-less ``wait_agent`` calls may use the provider-evidenced active-child set:
275
+ children spawned before the wait and without stop/close evidence before that wait.
276
+ Exact requester -> subtask -> assigned-child chains and exact owner-bound tool-call
277
+ assignments are accepted when provider evidence proves a unique owner and child;
278
+ ambiguous/profile-only subtasks and non-exact assignments still fail closed.
279
+ Once an action group has real targets, target-less call evidence from the same
280
+ owner/model/action is folded into that single viewer action so the raw collaboration
281
+ tool is not rendered as a duplicate. Provider tool-call vocabularies ``USES_TOOL``
282
+ and ``RESOLVED_TOOL`` are equivalent call-to-tool support for this presentation-only
283
+ consumption step. Bare tool names never rewrite the main hierarchy. Final execution-
284
+ flow columns re-run the hard node-overlap gate and port/order synchronization.
285
+ """
286
+
287
+ for unsafe in (_DIRECT_ASSIGN, _DIRECT_SUBTASK):
288
+ if unsafe not in html:
289
+ raise RuntimeError("execution-flow assignment safety seam changed")
290
+ html = html.replace(unsafe, "", 1)
291
+ if _ASSIGN_TARGET not in html:
292
+ raise RuntimeError("execution-flow assignment target seam changed")
293
+ html = html.replace(_ASSIGN_TARGET, _SAFE_ASSIGN_TARGET, 1)
294
+
295
+ if _ACTION_NAME not in html:
296
+ raise RuntimeError("execution-flow tagged action-name seam changed")
297
+ html = html.replace(_ACTION_NAME, _SAFE_ACTION_NAME, 1)
298
+ if _PROVIDER_HELPER not in html:
299
+ raise RuntimeError("execution-flow provider evidence seam changed")
300
+ html = html.replace(_PROVIDER_HELPER, _SAFE_PROVIDER_HELPER, 1)
301
+ if _OWNER_FOR_NODE not in html:
302
+ raise RuntimeError("execution-flow owner uniqueness seam changed")
303
+ html = html.replace(_OWNER_FOR_NODE, _SAFE_OWNER_FOR_NODE, 1)
304
+ if _MODEL_EDGE_LOOP not in html:
305
+ raise RuntimeError("execution-flow model ownership seam changed")
306
+ html = html.replace(_MODEL_EDGE_LOOP, _SAFE_MODEL_EDGE_LOOP, 1)
307
+ if _MODEL_FILTER not in html:
308
+ raise RuntimeError("execution-flow contextified-model filter seam changed")
309
+ html = html.replace(_MODEL_FILTER, _SAFE_MODEL_FILTER, 1)
310
+
311
+ if _TOOL_RESOLVE not in html or _TOOL_CONSUME not in html:
312
+ raise RuntimeError("execution-flow tool-resolution seam changed")
313
+ html = html.replace(_TOOL_RESOLVE, _SAFE_TOOL_RESOLVE, 1)
314
+ html = html.replace(_TOOL_CONSUME, _SAFE_TOOL_CONSUME, 1)
315
+
316
+ if _MODEL_ONLY_ACTIVATION not in html:
317
+ raise RuntimeError("execution-flow activation seam changed")
318
+ html = html.replace(_MODEL_ONLY_ACTIVATION, _ACTION_ONLY_ACTIVATION, 1)
319
+ if _ACTION_ONLY_ACTIVATION not in html:
320
+ raise RuntimeError("execution-flow targeted activation seam changed")
321
+ html = html.replace(_ACTION_ONLY_ACTIVATION, _TARGETED_ACTIVATION, 1)
322
+ if _TARGETED_ACTIVATION not in html:
323
+ raise RuntimeError("execution-flow wait target seam changed")
324
+ html = html.replace(_TARGETED_ACTIVATION, _WAIT_AWARE_ACTIVATION, 1)
325
+
326
+ # Anchor the evidence-group replacement on ``const groups``. Matching the bare
327
+ # loop text is unsafe because the wait/model-resolution block intentionally has
328
+ # earlier ``for(const occurrence of occurrences)`` loops of its own.
329
+ if _GROUP_BLOCK_START not in html:
330
+ raise RuntimeError("execution-flow evidence grouping seam changed")
331
+ html = html.replace(_GROUP_BLOCK_START, _EVIDENCE_GROUP_BLOCK_START, 1)
332
+
333
+ if _EAGER_CONTEXTS not in html:
334
+ raise RuntimeError("execution-flow eager model-context seam changed")
335
+ html = html.replace(_EAGER_CONTEXTS, "", 1)
336
+
337
+ if _DIRECT_ACTION_LOOP not in html:
338
+ raise RuntimeError("execution-flow direct action evidence seam changed")
339
+ html = html.replace(_DIRECT_ACTION_LOOP, _SAFE_DIRECT_ACTION_LOOP, 1)
340
+
341
+ if html.count(_HIERARCHY_PARENT_ONLY) != 1 or html.count(_HIERARCHY_RANK_ONLY) != 1:
342
+ raise RuntimeError("execution-flow hierarchy action seam changed")
343
+ html = html.replace(_HIERARCHY_PARENT_ONLY, _HIERARCHY_PARENT_SAFE, 1)
344
+ html = html.replace(_HIERARCHY_RANK_ONLY, _HIERARCHY_RANK_SAFE, 1)
345
+
346
+ if html.count(_FLOW_EARLY_RETURN) != 1 or html.count(_FLOW_END) != 1:
347
+ raise RuntimeError("execution-flow final geometry seam changed")
348
+ html = html.replace(_FLOW_EARLY_RETURN, _FLOW_SAFE_EARLY_RETURN, 1)
349
+ return html.replace(_FLOW_END, _FLOW_SAFE_END, 1)