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,502 @@
1
+ from __future__ import annotations
2
+
3
+ LIVE_READABILITY_STYLE = r"""
4
+ #svg.execweave-crowded .label{opacity:0;transition:opacity .12s ease,fill .12s ease}
5
+ #svg.execweave-crowded .label.aggregate-label,
6
+ #svg.execweave-crowded .label.edge-hover,
7
+ #svg.execweave-crowded .label.context-visible,
8
+ #svg.execweave-crowded .label.selected{opacity:1}
9
+ .edge.context-dim{opacity:.055!important}
10
+ .edge.context-related:not(.dim){opacity:1;stroke-width:4.4}
11
+ .edge.edge-hover:not(.dim){opacity:1;stroke-width:4.4}
12
+ .edge.bundle-member:not(.context-dim){opacity:.52}
13
+ .edge.bundle-representative:not(.context-dim){opacity:.94;stroke-width:3.6}
14
+ .node.context-dim{opacity:.32}
15
+ .label.context-dim{opacity:0!important}
16
+ .label.context-visible{fill:var(--text)}
17
+ .label.aggregate-label{fill:var(--text);font-size:9px;font-weight:700}
18
+ .node{cursor:grab;touch-action:none}.node.dragging{cursor:grabbing}
19
+ .execweave-tool-occurrences{margin-top:12px;border-top:1px solid var(--border);padding-top:10px}.execweave-tool-occurrences>strong{display:block;margin-bottom:7px}.execweave-tool-occurrence{border:1px solid var(--border);border-radius:8px;background:var(--panel2);margin:6px 0}.execweave-tool-occurrence>summary{cursor:pointer;padding:7px 9px;color:var(--muted);font-size:11px}.execweave-tool-occurrence>pre{margin:0;padding:9px;border-top:1px solid var(--border);max-height:280px;overflow:auto;white-space:pre-wrap;overflow-wrap:anywhere;font:11px/1.45 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
20
+ """.strip()
21
+
22
+
23
+ LIVE_READABILITY_SCRIPT = r"""
24
+ const EXECWEAVE_NODE_W=160,EXECWEAVE_NODE_H=50,EXECWEAVE_ROW_GAP=104;
25
+ const EXECWEAVE_NODE_W_MAX=320,EXECWEAVE_LABEL_PAD=20;
26
+ // A second label line adds this much. Every vertical measurement below is written as a
27
+ // fraction of the node's own height, so a one-line node reproduces the numbers the fixed
28
+ // 50 produced: centre 25, the lifecycle anchor 39, and a port span of 30.
29
+ const EXECWEAVE_LINE_H=14;
30
+ const EXECWEAVE_LANES={runtime:0,root:1,agent:2,model:3,tool:4,file:5,endpoint:6,other:6};
31
+ const EXECWEAVE_LANE_ORDER=['runtime','root','agent','model','tool','file','endpoint'];
32
+ // The gap that follows each lane. These are the differences in the fixed table this
33
+ // replaced, so a graph whose labels all fit the minimum width lands on exactly the
34
+ // x positions it did before: 0, 270, 540, 820, 1100, 1380.
35
+ const EXECWEAVE_LANE_GAP={runtime:110,root:110,agent:120,model:120,tool:120,file:120,endpoint:120,other:120};
36
+ // A component with no path to the execution spine is packed below it rather than
37
+ // interleaved with it, so its rows never sit between two nodes that talk to each other.
38
+ const EXECWEAVE_BAND_GAP=170;
39
+ let execweaveTopology={spec:new Map(),bundleByEdge:new Map(),sourcePort:new Map(),targetPort:new Map(),routePoints:new Map(),width:new Map(),height:new Map(),laneX:{},crowded:false};
40
+ let execweaveRuler=null;
41
+ // Measure with a hidden text node carrying the label's own class, so the width comes
42
+ // from the font actually in use rather than a guess. Contexts without layout (a
43
+ // detached document, an export) report zero or throw; both fall back to an estimate.
44
+ function execweaveMeasure(text){
45
+ const value=String(text||'');
46
+ if(!value)return 0;
47
+ try{
48
+ if(!execweaveRuler){
49
+ execweaveRuler=document.createElementNS('http://www.w3.org/2000/svg','text');
50
+ execweaveRuler.classList.add('name-label');
51
+ execweaveRuler.setAttribute('visibility','hidden');
52
+ execweaveRuler.setAttribute('x','-9999');
53
+ execweaveRuler.setAttribute('y','-9999');
54
+ svg.appendChild(execweaveRuler);
55
+ }
56
+ execweaveRuler.textContent=value;
57
+ const measured=execweaveRuler.getComputedTextLength();
58
+ if(Number.isFinite(measured)&&measured>0)return measured;
59
+ }catch(_){}
60
+ return value.length*7.1;
61
+ }
62
+ function execweaveNodeLabel(node){return String(node?.name||node?.id||node?.type||'node')}
63
+ function execweaveNodeWidth(node){
64
+ const wanted=execweaveMeasure(execweaveNodeLabel(node))+EXECWEAVE_LABEL_PAD;
65
+ if(!Number.isFinite(wanted))return EXECWEAVE_NODE_W;
66
+ return Math.max(EXECWEAVE_NODE_W,Math.min(EXECWEAVE_NODE_W_MAX,Math.ceil(wanted)));
67
+ }
68
+ function execweaveWidthOf(id){const value=execweaveTopology.width.get(id);return Number.isFinite(value)?value:EXECWEAVE_NODE_W}
69
+ function execweaveHeightOf(id){const value=execweaveTopology.height.get(id);return Number.isFinite(value)?value:EXECWEAVE_NODE_H}
70
+ function execweaveCentreY(position,id){return position.y+execweaveHeightOf(id)/2}
71
+ // Break at the last separator that fits, so a path or a namespaced tool name splits
72
+ // where a reader would split it. A label with no separator breaks on the character.
73
+ function execweaveWrapLabel(text,width){
74
+ const value=String(text||''),room=width-EXECWEAVE_LABEL_PAD;
75
+ if(execweaveMeasure(value)<=room)return[value];
76
+ let cut=0;
77
+ for(let index=1;index<value.length;index++){
78
+ if(execweaveMeasure(value.slice(0,index))>room)break;
79
+ if(/[\/_\-. :]/.test(value[index-1]))cut=index;
80
+ }
81
+ if(!cut){
82
+ let low=0,high=value.length;
83
+ while(low<high){const mid=Math.ceil((low+high)/2);if(execweaveMeasure(value.slice(0,mid))<=room)low=mid;else high=mid-1}
84
+ cut=Math.max(1,low);
85
+ }
86
+ return[value.slice(0,cut),value.slice(cut)];
87
+ }
88
+ function execweaveLaneXOf(lane){const value=execweaveTopology.laneX[lane];return Number.isFinite(value)?value:0}
89
+ // A lane starts far enough right that the widest node in the lane before it cannot
90
+ // reach into it. With every label at the minimum width this reproduces the fixed
91
+ // table exactly; a wide label pushes every lane after it, and only those.
92
+ function execweaveLaneX(widthByLane,occupied){
93
+ const laneX={};let x=0;
94
+ for(const lane of EXECWEAVE_LANE_ORDER){
95
+ laneX[lane]=x;
96
+ // A lane holding nothing reserves nothing. Walking every lane unconditionally
97
+ // spent a column on each empty one, and an agent talking to a file paid for the
98
+ // empty model and tool lanes between them in edge length.
99
+ if(!occupied||occupied.has(lane))x+=Math.max(EXECWEAVE_NODE_W,widthByLane.get(lane)||EXECWEAVE_NODE_W)+EXECWEAVE_LANE_GAP[lane];
100
+ }
101
+ laneX.other=laneX.endpoint;
102
+ return laneX;
103
+ }
104
+ function execweaveAttrs(node){return node&&typeof node.attributes==='object'&&node.attributes?node.attributes:{}}
105
+ function execweaveAgentPath(node){const a=execweaveAttrs(node);return String(a.agent_path||a.child_agent_path||a.root_agent_path||node?.name||node?.id||'')}
106
+ function execweaveRelation(edge){return String(edge?.relation||'').toUpperCase()}
107
+ function execweaveIsSpawn(edge){const value=execweaveRelation(edge);return value==='SPAWNED_AGENT'||value.includes('SPAWNED_AGENT')||value.includes('SPAWN_AGENT')}
108
+ function execweaveIsStopped(edge){const value=execweaveRelation(edge);return value==='SUBAGENT_STOPPED'||value.includes('SUBAGENT_STOPPED')}
109
+ function execweaveIsRoot(node){const a=execweaveAttrs(node);if(node?.type!=='agent')return false;if(Object.prototype.hasOwnProperty.call(a,'viewer_root'))return a.viewer_root===true;return a.agent_role==='root'||a.root_agent_path==='/root'||a.agent_path==='/root'||execweaveAgentPath(node)==='/root'}
110
+ function execweaveLane(node){
111
+ const type=String(node?.type||'').toLowerCase();
112
+ if(type==='agent')return execweaveIsRoot(node)?'root':'agent';
113
+ if(type.includes('model')||type.includes('inference')||type.includes('llm'))return'model';
114
+ if(type.includes('tool'))return'tool';
115
+ if(type.includes('file')||type.includes('path'))return'file';
116
+ if(type.includes('network')||type.includes('endpoint')||type.includes('socket')||type.includes('host'))return'endpoint';
117
+ if(type.includes('process')||type.includes('session')||type.includes('runtime')||type.includes('shell'))return'runtime';
118
+ return'other';
119
+ }
120
+ function execweaveMoment(edge){
121
+ if(Number.isInteger(edge?.first_sequence))return`0:${String(edge.first_sequence).padStart(12,'0')}`;
122
+ if(edge?.first_seen)return`1:${edge.first_seen}`;
123
+ return`2:${edgeId(edge)}`;
124
+ }
125
+ function execweaveStableNodeSort(a,b){return String(a?.name||a?.id||'').localeCompare(String(b?.name||b?.id||''))||String(a?.id||'').localeCompare(String(b?.id||''))}
126
+ function execweaveBuildTopology(){
127
+ const nodes=[...nodeById.values()],edges=[...edgeById.values()],spawnFor=new Map();
128
+ for(const edge of edges){
129
+ if(!execweaveIsSpawn(edge))continue;
130
+ const source=nodeById.get(edge.source),target=nodeById.get(edge.target);
131
+ if(source?.type!=='agent'||target?.type!=='agent')continue;
132
+ const current=spawnFor.get(target.id);if(!current||execweaveMoment(edge)<execweaveMoment(current))spawnFor.set(target.id,edge);
133
+ }
134
+ const roots=nodes.filter(execweaveIsRoot).sort(execweaveStableNodeSort);
135
+ const children=nodes.filter(node=>node.type==='agent'&&!execweaveIsRoot(node)).sort((a,b)=>{
136
+ const ae=spawnFor.get(a.id),be=spawnFor.get(b.id),am=ae?execweaveMoment(ae):'9:',bm=be?execweaveMoment(be):'9:';
137
+ return am.localeCompare(bm)||execweaveAgentPath(a).localeCompare(execweaveAgentPath(b))||execweaveStableNodeSort(a,b);
138
+ });
139
+ const childOrder=new Map(children.map((node,index)=>[node.id,index]));
140
+ const rootY=children.length?100+((children.length-1)*EXECWEAVE_ROW_GAP)/2:100;
141
+ const byLane=new Map();for(const lane of Object.keys(EXECWEAVE_LANES))byLane.set(lane,[]);
142
+ for(const node of nodes)byLane.get(execweaveLane(node)).push(node);
143
+ const agentBarycenter=node=>{
144
+ const touching=edges.filter(edge=>edge.target===node.id&&childOrder.has(edge.source));
145
+ if(!touching.length)return Number.MAX_SAFE_INTEGER;
146
+ return touching.reduce((sum,edge)=>sum+(childOrder.get(edge.source)||0),0)/touching.length;
147
+ };
148
+ // Order an evidence lane by the average position of whoever points at it, so a
149
+ // target sits opposite its sources instead of wherever the alphabet put it. This is
150
+ // the crossing-reduction step the tool lane already had; the others sorted by name
151
+ // and ignored the graph entirely.
152
+ const sourceBarycentre=node=>{
153
+ const touching=edges.filter(edge=>edge.target===node.id&&childOrder.has(edge.source));
154
+ if(!touching.length)return Number.MAX_SAFE_INTEGER;
155
+ return touching.reduce((sum,edge)=>sum+(childOrder.get(edge.source)||0),0)/touching.length;
156
+ };
157
+ const rootNodeOrder=new Map(roots.map((node,index)=>[node.id,index]));
158
+ const rootEdges=edges.filter(edge=>rootNodeOrder.has(edge.source)).sort((a,b)=>execweaveMoment(a).localeCompare(execweaveMoment(b))||edgeId(a).localeCompare(edgeId(b)));
159
+ const rootEdgeOrder=new Map(rootEdges.map((edge,index)=>[edgeId(edge),index]));
160
+ const rootFallbackBarycenter=node=>{
161
+ const rootTouching=edges.filter(edge=>edge.target===node.id&&rootNodeOrder.has(edge.source));
162
+ if(!rootTouching.length)return Number.MAX_SAFE_INTEGER;
163
+ if(roots.length>1){
164
+ const primary=rootTouching.reduce((sum,edge)=>sum+(rootNodeOrder.get(edge.source)||0),0)/rootTouching.length;
165
+ const secondary=rootTouching.reduce((sum,edge)=>sum+(rootEdgeOrder.get(edgeId(edge))??0),0)/rootTouching.length;
166
+ return primary*10000+secondary;
167
+ }
168
+ return rootTouching.reduce((sum,edge)=>sum+(rootEdgeOrder.get(edgeId(edge))??0),0)/rootTouching.length;
169
+ };
170
+ const effectiveBarycentre=node=>{
171
+ const childTouching=edges.filter(edge=>edge.target===node.id&&childOrder.has(edge.source));
172
+ if(childTouching.length)return sourceBarycentre(node);
173
+ const rbc=rootFallbackBarycenter(node);
174
+ if(rbc!==Number.MAX_SAFE_INTEGER)return rbc;
175
+ return sourceBarycentre(node);
176
+ };
177
+ const effectiveAgentBarycenter=node=>{
178
+ const childTouching=edges.filter(edge=>edge.target===node.id&&childOrder.has(edge.source));
179
+ if(childTouching.length)return agentBarycenter(node);
180
+ const rbc=rootFallbackBarycenter(node);
181
+ if(rbc!==Number.MAX_SAFE_INTEGER)return rbc;
182
+ return agentBarycenter(node);
183
+ };
184
+ const byBarycentre=(a,b)=>{
185
+ const ab=effectiveBarycentre(a),bb=effectiveBarycentre(b);
186
+ return ab!==bb?ab-bb:execweaveStableNodeSort(a,b);
187
+ };
188
+ byLane.get('runtime').sort(execweaveStableNodeSort);
189
+ for(const lane of ['model','file','endpoint','other'])byLane.get(lane).sort(byBarycentre);
190
+ byLane.get('tool').sort((a,b)=>{
191
+ const ac=/spawn|send|wait|agent/i.test(String(a?.name||execweaveAttrs(a).tool_name||'')),bc=/spawn|send|wait|agent/i.test(String(b?.name||execweaveAttrs(b).tool_name||''));
192
+ if(ac!==bc)return ac?-1:1;
193
+ const ab=effectiveAgentBarycenter(a),bb=effectiveAgentBarycenter(b);if(ab!==bb)return ab-bb;
194
+ return execweaveStableNodeSort(a,b);
195
+ });
196
+ const width=new Map(),height=new Map(),widthByLane=new Map(),occupied=new Set();
197
+ for(const node of nodes){
198
+ const w=execweaveNodeWidth(node),lane=execweaveLane(node);
199
+ width.set(node.id,w);
200
+ height.set(node.id,EXECWEAVE_NODE_H+(execweaveWrapLabel(execweaveNodeLabel(node),w).length>1?EXECWEAVE_LINE_H:0));
201
+ widthByLane.set(lane,Math.max(widthByLane.get(lane)||EXECWEAVE_NODE_W,w));
202
+ occupied.add(lane==='other'?'endpoint':lane);
203
+ }
204
+ // `other` shares a column with `endpoint`, so it must not widen a lane of its own.
205
+ widthByLane.set('endpoint',Math.max(widthByLane.get('endpoint')||EXECWEAVE_NODE_W,widthByLane.get('other')||EXECWEAVE_NODE_W));
206
+ const laneX=execweaveLaneX(widthByLane,occupied);
207
+ const spec=new Map();
208
+ const put=(node,lane,order,y)=>spec.set(node.id,{lane,rank:EXECWEAVE_LANES[lane],order,x:laneX[lane],y});
209
+ roots.forEach((node,index)=>put(node,'root',index,rootY+index*EXECWEAVE_ROW_GAP));
210
+ children.forEach((node,index)=>put(node,'agent',index,100+index*EXECWEAVE_ROW_GAP));
211
+ byLane.get('runtime').forEach((node,index)=>put(node,'runtime',index,rootY+(index-Math.floor(byLane.get('runtime').length/2))*86));
212
+ byLane.get('model').forEach((node,index)=>put(node,'model',index,rootY+(index-Math.floor(byLane.get('model').length/2))*92));
213
+ const tools=byLane.get('tool'),collab=tools.filter(node=>/spawn|send|wait|agent/i.test(String(node?.name||execweaveAttrs(node).tool_name||''))),ordinary=tools.filter(node=>!collab.includes(node));
214
+ collab.forEach((node,index)=>put(node,'tool',index,-170+index*82));
215
+ ordinary.forEach((node,index)=>put(node,'tool',collab.length+index,80+index*130));
216
+ for(const lane of ['file','endpoint','other'])byLane.get(lane).forEach((node,index)=>put(node,lane,index,80+index*104));
217
+ for(const node of nodes)if(!spec.has(node.id))put(node,execweaveLane(node),0,100);
218
+
219
+ // The lifecycle offset spreads returns apart by their order within a lane, so it
220
+ // needs to know how many there are. A fixed modulus wrapped: with five subagents the
221
+ // first and the fifth were handed the same offset and their loops landed on top of
222
+ // each other.
223
+ const laneCount=new Map();
224
+ for(const value of spec.values())laneCount.set(value.lane,(laneCount.get(value.lane)||0)+1);
225
+ for(const value of spec.values())value.laneCount=laneCount.get(value.lane)||1;
226
+
227
+ // Push every component that cannot reach the spine below it. The spine is the
228
+ // component holding the first root; with no root at all it is the largest, which
229
+ // keeps a runtime-only graph from being demoted to its own band.
230
+ const componentOf=execweaveComponents(nodes,edges);
231
+ if(componentOf.size){
232
+ const sizes=new Map();
233
+ for(const value of componentOf.values())sizes.set(value,(sizes.get(value)||0)+1);
234
+ // An agent belongs to the spine whether or not the provider recorded an edge to
235
+ // it. Codex records subagents with no edge back to their root, so reading the
236
+ // graph alone demoted every subagent to the band meant for stray evidence.
237
+ const spineIds=new Set(nodes.filter(node=>node?.type==='agent').map(node=>node.id));
238
+ let primary=roots.length?componentOf.get(roots[0].id):undefined;
239
+ if(primary===undefined){
240
+ let best=-1;
241
+ for(const [value,size] of [...sizes.entries()].sort((a,b)=>a[0]-b[0]))if(size>best){best=size;primary=value}
242
+ }
243
+ const spineComponents=new Set([...componentOf.entries()].filter(entry=>spineIds.has(entry[0])).map(entry=>entry[1]));
244
+ if(primary!==undefined)spineComponents.add(primary);
245
+ const secondary=[...sizes.keys()].filter(value=>!spineComponents.has(value)).sort((a,b)=>a-b);
246
+ if(secondary.length){
247
+ let spineFloor=-Infinity,spineLeft=Infinity,spineRight=-Infinity;
248
+ for(const [id,value] of componentOf)if(spineComponents.has(value)){const s=spec.get(id);if(s){spineFloor=Math.max(spineFloor,s.y+(height.get(id)||EXECWEAVE_NODE_H));spineLeft=Math.min(spineLeft,s.x);spineRight=Math.max(spineRight,s.x+(width.get(id)||EXECWEAVE_NODE_W))}}
249
+ if(!Number.isFinite(spineFloor))spineFloor=0;
250
+ if(!Number.isFinite(spineLeft)){spineLeft=0;spineRight=800}
251
+ const spineWidth=Math.max(600,spineRight-spineLeft);
252
+ const compBoxes=secondary.map(value=>{
253
+ const members=[...componentOf.entries()].filter(entry=>entry[1]===value).map(entry=>entry[0]);
254
+ let minX=Infinity,maxX=-Infinity,minY=Infinity,maxY=-Infinity;
255
+ for(const id of members){const s=spec.get(id);if(s){minX=Math.min(minX,s.x);maxX=Math.max(maxX,s.x+(width.get(id)||EXECWEAVE_NODE_W));minY=Math.min(minY,s.y);maxY=Math.max(maxY,s.y+(height.get(id)||EXECWEAVE_NODE_H))}}
256
+ return{value,members,minX,maxX,minY,maxY,w:maxX-minX,h:maxY-minY};
257
+ }).filter(box=>Number.isFinite(box.minX));
258
+ let cursorX=spineLeft,cursorY=spineFloor+EXECWEAVE_BAND_GAP,rowHeight=0;
259
+ for(const box of compBoxes){
260
+ if(cursorX>spineLeft&&cursorX+box.w>spineLeft+spineWidth){cursorX=spineLeft;cursorY+=rowHeight+EXECWEAVE_BAND_GAP;rowHeight=0}
261
+ const shiftX=cursorX-box.minX,shiftY=cursorY-box.minY;
262
+ for(const id of box.members){const s=spec.get(id);if(s){s.x+=shiftX;s.y+=shiftY}}
263
+ cursorX+=box.w+EXECWEAVE_BAND_GAP;
264
+ rowHeight=Math.max(rowHeight,box.h);
265
+ }
266
+ }
267
+ }
268
+
269
+ const bundleGroups=new Map();
270
+ for(const edge of edges){
271
+ const source=nodeById.get(edge.source),target=nodeById.get(edge.target);
272
+ if(source?.type!=='agent'||!['tool','model'].includes(execweaveLane(target))||execweaveIsSpawn(edge)||execweaveIsStopped(edge))continue;
273
+ const key=`${edge.target}\u0000${String(edge.relation||'')}`;
274
+ if(!bundleGroups.has(key))bundleGroups.set(key,[]);bundleGroups.get(key).push(edge);
275
+ }
276
+ const bundleByEdge=new Map(),sourceEdges=new Map(),targetEdges=new Map();
277
+ const sortedGroups=[...bundleGroups.entries()].sort((a,b)=>{
278
+ const as=spec.get(a[1][0]?.target),bs=spec.get(b[1][0]?.target);
279
+ return (as?.y??0)-(bs?.y??0)||a[0].localeCompare(b[0]);
280
+ });
281
+ sortedGroups.forEach(([key,members],groupIndex)=>{
282
+ members.sort((a,b)=>(childOrder.get(a.source)??Number.MAX_SAFE_INTEGER)-(childOrder.get(b.source)??Number.MAX_SAFE_INTEGER)||edgeId(a).localeCompare(edgeId(b)));
283
+ members.forEach((edge,index)=>bundleByEdge.set(edgeId(edge),{key,size:members.length,index,representative:index===0,groupIndex}));
284
+ });
285
+ for(const edge of edges){
286
+ if(!sourceEdges.has(edge.source))sourceEdges.set(edge.source,[]);sourceEdges.get(edge.source).push(edge);
287
+ if(!targetEdges.has(edge.target))targetEdges.set(edge.target,[]);targetEdges.get(edge.target).push(edge);
288
+ }
289
+ const sourcePort=new Map(),targetPort=new Map();
290
+ for(const list of sourceEdges.values()){
291
+ list.sort((a,b)=>{const at=spec.get(a.target),bt=spec.get(b.target);return (at?.y??0)-(bt?.y??0)||(at?.rank??0)-(bt?.rank??0)||edgeId(a).localeCompare(edgeId(b))});
292
+ list.forEach((edge,index)=>sourcePort.set(edgeId(edge),{index,total:list.length}));
293
+ }
294
+ for(const list of targetEdges.values()){
295
+ list.sort((a,b)=>{const as=spec.get(a.source),bs=spec.get(b.source);return (as?.y??0)-(bs?.y??0)||(as?.rank??0)-(bs?.rank??0)||edgeId(a).localeCompare(edgeId(b))});
296
+ list.forEach((edge,index)=>targetPort.set(edgeId(edge),{index,total:list.length}));
297
+ }
298
+ return{spec,bundleByEdge,sourcePort,targetPort,routePoints:new Map(),width,height,laneX,crowded:edges.length>=16||nodes.length>=12,sourceBarycentre:effectiveBarycentre,agentBarycenter:effectiveAgentBarycenter,rootFallbackBarycenter};
299
+ }
300
+ function execweaveComponents(nodes,edges){
301
+ const adjacent=new Map();
302
+ for(const node of nodes)adjacent.set(node.id,[]);
303
+ for(const edge of edges){
304
+ if(!adjacent.has(edge.source)||!adjacent.has(edge.target))continue;
305
+ adjacent.get(edge.source).push(edge.target);adjacent.get(edge.target).push(edge.source);
306
+ }
307
+ const componentOf=new Map();let index=0;
308
+ for(const node of [...nodes].sort(execweaveStableNodeSort)){
309
+ if(componentOf.has(node.id))continue;
310
+ const queue=[node.id];componentOf.set(node.id,index);
311
+ while(queue.length){
312
+ const id=queue.pop();
313
+ for(const next of adjacent.get(id)||[])if(!componentOf.has(next)){componentOf.set(next,index);queue.push(next)}
314
+ }
315
+ index++;
316
+ }
317
+ return componentOf;
318
+ }
319
+ function execweavePortY(position,port,id){const h=execweaveHeightOf(id);if(!port||port.total<=1)return position.y+h/2;const span=h-20;return position.y+10+(span*port.index)/(port.total-1)}
320
+ function execweaveDesiredPosition(id){const value=execweaveTopology.spec.get(id);return value?{x:value.x,y:value.y}:{x:0,y:0}}
321
+ // 74 still clears the tallest node this can produce: 50 plus one wrapped line is 64.
322
+ // A third line would need this to grow with the nodes it compares.
323
+ function execweaveCollision(position,next,id){for(const [other,p] of next){if(other===id)continue;if(Math.abs(p.x-position.x)<2&&Math.abs(p.y-position.y)<74)return true}return false}
324
+ function execweavePlaceStable(id,desired,next){let candidate={...desired};while(execweaveCollision(candidate,next,id))candidate.y+=EXECWEAVE_ROW_GAP;return candidate}
325
+ fullLayout=function(){
326
+ const prior=positions;execweaveTopology=execweaveBuildTopology();const next=new Map();
327
+ for(const id of nodeById.keys()){
328
+ const desired=execweaveDesiredPosition(id),old=prior.get(id);
329
+ next.set(id,old?{x:old.x,y:old.y}:execweavePlaceStable(id,desired,next,id));
330
+ }
331
+ positions=next;layerRows=new Map();
332
+ for(const [id,p] of positions){const spec=execweaveTopology.spec.get(id);if(spec)layerRows.set(spec.rank,Math.max(layerRows.get(spec.rank)||0,spec.order+1));if(!Number.isFinite(p.x)||!Number.isFinite(p.y))positions.set(id,execweaveDesiredPosition(id))}
333
+ svg.classList.toggle('execweave-crowded',execweaveTopology.crowded);
334
+ };
335
+ reservePosition=function(depth){const row=layerRows.get(depth)||0;layerRows.set(depth,row+1);const lane=EXECWEAVE_LANE_ORDER[Number(depth)||0];return{x:lane?execweaveLaneXOf(lane):(Number(depth)||0)*270,y:100+row*EXECWEAVE_ROW_GAP}};
336
+ nodeDepth=function(id){return execweaveTopology.spec.get(id)?.rank??null};
337
+ placeAddedNodes=function(ids){
338
+ execweaveTopology=execweaveBuildTopology();
339
+ for(const id of ids||[]){if(!nodeById.has(id)||positions.has(id))continue;positions.set(id,execweavePlaceStable(id,execweaveDesiredPosition(id),positions,id))}
340
+ svg.classList.toggle('execweave-crowded',execweaveTopology.crowded);
341
+ };
342
+ function execweaveRoute(edge){
343
+ const id=edgeId(edge),sp=positions.get(edge.source)||{x:0,y:0},tp=positions.get(edge.target)||{x:0,y:0},sourceSpec=execweaveTopology.spec.get(edge.source)||{},targetSpec=execweaveTopology.spec.get(edge.target)||{},bundle=execweaveTopology.bundleByEdge.get(id),sourcePort=execweaveTopology.sourcePort.get(id),targetPort=execweaveTopology.targetPort.get(id);
344
+ if(bundle&&bundle.size>1){
345
+ const sx=sp.x+execweaveWidthOf(edge.source),sy=execweavePortY(sp,sourcePort,edge.source),tx=tp.x,ty=execweavePortY(tp,targetPort,edge.target),trunkX=Math.max(sx+54,tx-82-(bundle.groupIndex%6)*24);
346
+ return{d:`M ${sx} ${sy} H ${trunkX} V ${ty} H ${tx}`,labelX:(trunkX+tx)/2,labelY:ty-8,kind:'bundle',bundle};
347
+ }
348
+ if(execweaveIsStopped(edge)){
349
+ const sx=sp.x,sy=sp.y+execweaveHeightOf(edge.source)*0.78,tx=tp.x+execweaveWidthOf(edge.target),ty=tp.y+execweaveHeightOf(edge.target)*0.78,offset=62+((sourceSpec.order||0)%Math.max(1,sourceSpec.laneCount||4))*11;
350
+ return{d:`M ${sx} ${sy} C ${sx-offset} ${sy+offset}, ${tx+offset} ${ty+offset}, ${tx} ${ty}`,labelX:(sx+tx)/2,labelY:Math.max(sy,ty)+offset*.66,kind:'lifecycle-return',bundle:null};
351
+ }
352
+ // One family for every ordinary execution edge. Spawning a subagent is ordinary
353
+ // flow, but it routed on its own bend constant and anchored its target at the node's
354
+ // centre instead of a port, so an agent's spawn and its tool call left the same node
355
+ // on different geometry. The kind is still reported, because the difference is worth
356
+ // styling and worth asserting; the geometry is not.
357
+ const forward=(targetSpec.rank??0)>=(sourceSpec.rank??0);
358
+ const sx=forward?sp.x+execweaveWidthOf(edge.source):sp.x,tx=forward?tp.x:tp.x+execweaveWidthOf(edge.target),sy=execweavePortY(sp,sourcePort,edge.source),ty=execweavePortY(tp,targetPort,edge.target),distance=Math.abs(tx-sx),bend=Math.max(44,distance*.42),sign=forward?1:-1;
359
+ return{d:`M ${sx} ${sy} C ${sx+sign*bend} ${sy}, ${tx-sign*bend} ${ty}, ${tx} ${ty}`,labelX:(sx+tx)/2,labelY:(sy+ty)/2-8,kind:execweaveIsSpawn(edge)?'spawn':(forward?'forward':'reverse'),bundle:null};
360
+ }
361
+ anchor=function(id,right){const p=positions.get(id)||{x:0,y:0};return{x:p.x+(right?execweaveWidthOf(id):0),y:execweaveCentreY(p,id)}};
362
+ curve=function(edge){return execweaveRoute(edge).d};
363
+ // The base renderer draws every node 160 wide and truncates its label at 28 characters,
364
+ // so a label that now has room would still be cut. Both are re-applied here from the
365
+ // width the topology computed for this node.
366
+ function execweaveFitLabel(text,width){
367
+ const value=String(text||'');
368
+ if(execweaveMeasure(value)+EXECWEAVE_LABEL_PAD<=width)return value;
369
+ let low=0,high=value.length;
370
+ while(low<high){
371
+ const mid=Math.ceil((low+high)/2);
372
+ if(execweaveMeasure(value.slice(0,mid)+'\u2026')+EXECWEAVE_LABEL_PAD<=width)low=mid;else high=mid-1;
373
+ }
374
+ return low>0?value.slice(0,low)+'\u2026':value.slice(0,1);
375
+ }
376
+ const execweaveBaseUpdateNodeElement=updateNodeElement;
377
+ updateNodeElement=function(node){
378
+ execweaveBaseUpdateNodeElement(node);const group=nodeElements.get(node.id);if(!group)return;
379
+ const width=execweaveWidthOf(node.id);
380
+ const height=execweaveHeightOf(node.id);
381
+ const rect=group.querySelector('rect');if(rect){rect.setAttribute('width',width);rect.setAttribute('height',height)}
382
+ const label=group.querySelector('.name-label');
383
+ if(label){
384
+ const full=execweaveNodeLabel(node);
385
+ const lines=execweaveWrapLabel(full,width);
386
+ label.textContent='';
387
+ if(lines.length>1){
388
+ label.setAttribute('y',32);
389
+ const first=document.createElementNS('http://www.w3.org/2000/svg','tspan');
390
+ first.setAttribute('x',10);first.setAttribute('y',32);first.textContent=lines[0];
391
+ const second=document.createElementNS('http://www.w3.org/2000/svg','tspan');
392
+ second.setAttribute('x',10);second.setAttribute('y',32+EXECWEAVE_LINE_H);
393
+ second.textContent=execweaveFitLabel(lines[1],width);
394
+ label.appendChild(first);label.appendChild(second);
395
+ }else{
396
+ label.setAttribute('y',34);
397
+ label.textContent=execweaveFitLabel(full,width);
398
+ }
399
+ group.dataset.labelLines=String(lines.length);
400
+ group.dataset.fullLabel=full;
401
+ let title=group.querySelector('title');
402
+ if(!title){title=document.createElementNS('http://www.w3.org/2000/svg','title');group.appendChild(title)}
403
+ title.textContent=full;
404
+ }
405
+ group.dataset.nodeWidth=String(width);group.dataset.nodeHeight=String(height);
406
+ const spec=execweaveTopology.spec.get(node.id);if(!spec)return;
407
+ group.dataset.layoutLane=spec.lane;group.dataset.layoutRank=String(spec.rank);group.dataset.layoutOrder=String(spec.order);
408
+ };
409
+ const execweaveBaseUpdateEdgeElement=updateEdgeElement;
410
+ updateEdgeElement=function(edge){
411
+ execweaveBaseUpdateEdgeElement(edge);const id=edgeId(edge),els=edgeElements.get(id);if(!els)return;const route=execweaveRoute(edge),bundle=route.bundle;
412
+ els.visible.setAttribute('d',route.d);els.hit.setAttribute('d',route.d);els.visible.dataset.routeKind=route.kind;els.hit.dataset.routeKind=route.kind;
413
+ els.visible.dataset.bundleKey=bundle?.key||'';els.visible.dataset.bundleSize=String(bundle?.size||1);els.visible.dataset.layoutConstraint=execweaveIsStopped(edge)?'ignored-for-rank':'ranked';
414
+ els.label.setAttribute('x',route.labelX);els.label.setAttribute('y',route.labelY);els.label.dataset.fullRelation=String(edge.relation||'');
415
+ const aggregate=!!bundle&&bundle.size>1&&bundle.representative;
416
+ els.visible.classList.toggle('bundle-member',!!bundle&&bundle.size>1);els.visible.classList.toggle('bundle-representative',aggregate);els.label.classList.toggle('aggregate-label',aggregate);
417
+ els.label.textContent=aggregate?`${edge.relation} ×${bundle.size}`:(edge.count>1?`${edge.relation} ×${edge.count}`:edge.relation);
418
+ if(execweaveTopology.crowded&&!aggregate)els.label.setAttribute('aria-hidden','true');else els.label.removeAttribute('aria-hidden');
419
+ };
420
+ const execweaveBaseCreateEdgeElement=createEdgeElement;
421
+ createEdgeElement=function(edge){
422
+ const id=edgeId(edge),exists=edgeElements.has(id);execweaveBaseCreateEdgeElement(edge);const els=edgeElements.get(id);if(!els||exists||els.hit.dataset.readabilityBound==='1')return;
423
+ els.hit.dataset.readabilityBound='1';els.hit.setAttribute('aria-label',`${edge.relation||'edge'}: ${entityLabel(edge.source)} → ${entityLabel(edge.target)}`);
424
+ els.hit.addEventListener('mouseenter',()=>{els.visible.classList.add('edge-hover');els.label.classList.add('edge-hover')});
425
+ els.hit.addEventListener('mouseleave',()=>{els.visible.classList.remove('edge-hover');els.label.classList.remove('edge-hover')});
426
+ };
427
+ function execweaveClearContextFocus(){
428
+ for(const els of edgeElements.values()){els.visible.classList.remove('context-dim','context-related');els.label.classList.remove('context-dim','context-visible')}
429
+ for(const group of nodeElements.values())group.classList.remove('context-dim');
430
+ }
431
+ function execweaveFocusNodeEdges(id){
432
+ const neighborIds=new Set([id]);
433
+ for(const [edgeIdValue,edge] of edgeById){const related=edge.source===id||edge.target===id,els=edgeElements.get(edgeIdValue);if(!els)continue;els.visible.classList.toggle('context-related',related);els.visible.classList.toggle('context-dim',!related);els.label.classList.toggle('context-visible',related);els.label.classList.toggle('context-dim',!related);if(related){neighborIds.add(edge.source);neighborIds.add(edge.target)}}
434
+ for(const [nodeIdValue,group] of nodeElements)group.classList.toggle('context-dim',!neighborIds.has(nodeIdValue));
435
+ }
436
+ function execweaveFocusOneEdge(id){
437
+ for(const [edgeIdValue,els] of edgeElements){const related=edgeIdValue===id;els.visible.classList.toggle('context-related',related);els.visible.classList.toggle('context-dim',!related);els.label.classList.toggle('context-visible',related);els.label.classList.toggle('context-dim',!related)}
438
+ }
439
+ const execweaveBaseClearSelection=clearSelection;
440
+ clearSelection=function(){execweaveBaseClearSelection();execweaveClearContextFocus()};
441
+ const execweaveBaseSelectNode=selectNode;
442
+ selectNode=function(id,options={}){
443
+ execweaveBaseSelectNode(id,options);
444
+ if(nodeById.has(id))execweaveFocusNodeEdges(id);
445
+ };
446
+ const execweaveBaseSelectEdge=selectEdge;
447
+ selectEdge=function(id,options={}){
448
+ execweaveBaseSelectEdge(id,options);
449
+ if(edgeById.has(id))execweaveFocusOneEdge(id);
450
+ };
451
+
452
+ // Manual placement and automatic arrangement are complementary. Polling preserves a
453
+ // reader's manual position, while Arrange deliberately throws manual positions away
454
+ // and recomputes the existing topology-aware lane layout.
455
+ let execweaveNodeDrag=null;
456
+ function execweaveGraphPoint(event){const rect=svg.getBoundingClientRect();return{x:(event.clientX-rect.left-transform.x)/transform.scale,y:(event.clientY-rect.top-transform.y)/transform.scale}}
457
+ function execweaveRefreshIncidentEdges(id){const edgeIds=new Set([...(incomingByNode.get(id)||[]),...(outgoingByNode.get(id)||[])]);for(const edgeIdValue of edgeIds){const edge=edgeById.get(edgeIdValue);if(edge)updateEdgeElement(edge)}}
458
+ const execweaveBaseCreateNodeElement=createNodeElement;
459
+ createNodeElement=function(node){
460
+ const existed=nodeElements.has(node.id);execweaveBaseCreateNodeElement(node);const group=nodeElements.get(node.id);
461
+ if(!group||existed||group.dataset.execweaveDragBound==='1')return;
462
+ group.dataset.execweaveDragBound='1';
463
+ group.addEventListener('click',event=>{if(group.dataset.execweaveSuppressClick==='1'){delete group.dataset.execweaveSuppressClick;event.preventDefault();event.stopImmediatePropagation()}},true);
464
+ group.addEventListener('pointerdown',event=>{
465
+ if(event.button!==0)return;const current=positions.get(node.id);if(!current)return;
466
+ event.stopPropagation();userTookCamera();stopAnimation();const point=execweaveGraphPoint(event);
467
+ execweaveNodeDrag={id:node.id,pointerId:event.pointerId,dx:point.x-current.x,dy:point.y-current.y,startX:event.clientX,startY:event.clientY,moved:false};
468
+ group.classList.add('dragging');try{group.setPointerCapture(event.pointerId)}catch(_){}
469
+ });
470
+ group.addEventListener('pointermove',event=>{
471
+ const drag=execweaveNodeDrag;if(!drag||drag.id!==node.id||drag.pointerId!==event.pointerId)return;
472
+ if(Math.abs(event.clientX-drag.startX)>3||Math.abs(event.clientY-drag.startY)>3)drag.moved=true;
473
+ const point=execweaveGraphPoint(event),next={x:point.x-drag.dx,y:point.y-drag.dy};positions.set(node.id,next);group.setAttribute('transform',`translate(${next.x} ${next.y})`);execweaveRefreshIncidentEdges(node.id);updateJumpLatest();
474
+ });
475
+ const finish=event=>{
476
+ const drag=execweaveNodeDrag;if(!drag||drag.id!==node.id||drag.pointerId!==event.pointerId)return;
477
+ if(drag.moved){group.dataset.execweaveSuppressClick='1';setTimeout(()=>{if(group.dataset.execweaveSuppressClick==='1')delete group.dataset.execweaveSuppressClick},250)}
478
+ execweaveNodeDrag=null;group.classList.remove('dragging');try{group.releasePointerCapture(event.pointerId)}catch(_){}
479
+ };
480
+ group.addEventListener('pointerup',finish);group.addEventListener('pointercancel',finish);
481
+ };
482
+ function execweaveArrangeGraph(){
483
+ execweaveTopology=execweaveBuildTopology();const next=new Map();
484
+ const ordered=[...nodeById.keys()].sort((a,b)=>{const av=execweaveTopology.spec.get(a)||{},bv=execweaveTopology.spec.get(b)||{};return Number(av.rank||0)-Number(bv.rank||0)||Number(av.order||0)-Number(bv.order||0)||String(a).localeCompare(String(b))});
485
+ for(const id of ordered)next.set(id,execweavePlaceStable(id,execweaveDesiredPosition(id),next,id));
486
+ positions=next;layerRows=new Map();
487
+ for(const [id,p] of positions){const spec=execweaveTopology.spec.get(id);if(spec)layerRows.set(spec.rank,Math.max(layerRows.get(spec.rank)||0,spec.order+1));const group=nodeElements.get(id);if(group)group.setAttribute('transform',`translate(${p.x} ${p.y})`);const node=nodeById.get(id);if(node)updateNodeElement(node)}
488
+ for(const edge of edgeById.values())updateEdgeElement(edge);
489
+ svg.classList.toggle('execweave-crowded',execweaveTopology.crowded);applySearch();updateJumpLatest();return new Map(positions);
490
+ }
491
+ window.__execweaveArrangeGraph=execweaveArrangeGraph;
492
+ const execweaveArrangeButton=document.getElementById('arrange');if(execweaveArrangeButton)execweaveArrangeButton.onclick=()=>execweaveArrangeGraph();
493
+ function execweaveToolOccurrenceSection(node){
494
+ const occurrences=Array.isArray(execweaveAttrs(node).viewer_tool_call_occurrences)?execweaveAttrs(node).viewer_tool_call_occurrences:[];if(!occurrences.length)return null;
495
+ const section=document.createElement('section');section.className='execweave-tool-occurrences';const title=document.createElement('strong');title.textContent=`Invocations · ${occurrences.length} call${occurrences.length===1?'':'s'}`;section.appendChild(title);
496
+ occurrences.forEach((occurrence,index)=>{const fold=document.createElement('details');fold.className='execweave-tool-occurrence';const summary=document.createElement('summary');const when=prettyTime(occurrence.first_seen||occurrence.last_seen),owner=entityLabel(occurrence.owner_id);summary.textContent=`${when} · ${owner} · call ${index+1}`;const pre=document.createElement('pre');pre.textContent=JSON.stringify({first_seen:occurrence.first_seen,last_seen:occurrence.last_seen,first_sequence:occurrence.first_sequence,last_sequence:occurrence.last_sequence,input:occurrence.input,output:occurrence.output,call_ids:occurrence.call_ids,content_references:occurrence.content_references},null,2);fold.append(summary,pre);section.appendChild(fold)});
497
+ return section;
498
+ }
499
+ const execweaveBaseShow=show;
500
+ show=function(value,kind='Selection'){execweaveBaseShow(value,kind);if(kind==='Node'&&value?.type==='tool'){const section=execweaveToolOccurrenceSection(value);if(section){const raw=details.querySelector('.raw-toggle');if(raw)details.insertBefore(section,raw);else details.appendChild(section)}}};
501
+
502
+ """.strip()
@@ -0,0 +1,59 @@
1
+ from __future__ import annotations
2
+
3
+ LIVE_SCRIPT_A = r"""(()=>{
4
+ const MAX_NODES=1500,MAX_EDGES=4000,MAX_DOM_ELEMENTS=5000,MAX_ACTIVITY=240,THEME_KEY='execweave-theme',VIEWER_LIMITS=window.__execweaveViewerLimits||{};
5
+ const ACTIVE_MAX_NODES=Number(VIEWER_LIMITS.max_nodes)||MAX_NODES,ACTIVE_MAX_EDGES=Number(VIEWER_LIMITS.max_edges)||MAX_EDGES,ACTIVE_MAX_DOM_ELEMENTS=Number(VIEWER_LIMITS.max_dom_elements)||MAX_DOM_ELEMENTS;
6
+ const svg=document.getElementById('svg'),viewport=document.getElementById('viewport'),edgeLayer=document.getElementById('edges'),labelLayer=document.getElementById('labels'),nodeLayer=document.getElementById('nodes'),details=document.getElementById('details'),detailsEmpty=document.getElementById('details-empty'),search=document.getElementById('search'),stats=document.getElementById('stats'),evidence=document.getElementById('evidence'),status=document.getElementById('status'),statusLabel=document.getElementById('status-label'),protective=document.getElementById('protective'),protectiveSummary=document.getElementById('protective-summary'),themeToggle=document.getElementById('theme-toggle'),cameraLabel=document.getElementById('camera-label'),jumpLatest=document.getElementById('jump-latest'),currentTitle=document.getElementById('current-title'),currentSub=document.getElementById('current-sub'),currentKv=document.getElementById('current-kv'),activityRows=document.getElementById('activity-rows'),activityCount=document.getElementById('activity-count'),activityList=document.getElementById('activity-list');
7
+ let graph={nodes:[],edges:[]},nodeById=new Map(),edgeById=new Map(),positions=new Map(),incomingByNode=new Map(),outgoingByNode=new Map(),layerRows=new Map(),nodeElements=new Map(),edgeElements=new Map(),transform={x:35,y:35,scale:1},pan=null,liveSequence=-1,hasFitted=false,protectedMode=false,cameraMode='manual',latestNodeId=null,latestEdgeId=null,selectedNodeId=null,selectedEdgeId=null,activities=[],activityFilter='all',cameraTimer=null,animationFrame=null,activitySerial=0;
8
+ function applyTheme(theme,persist=false){const next=theme==='light'?'light':'dark';document.documentElement.dataset.theme=next;const light=next==='light';themeToggle.textContent=light?'Dark':'Light';themeToggle.setAttribute('aria-label',light?'Switch to dark theme':'Switch to light theme');themeToggle.title=light?'Switch to dark theme':'Switch to light theme';if(persist){try{localStorage.setItem(THEME_KEY,next)}catch(_){}}}
9
+ function initialTheme(){try{return localStorage.getItem(THEME_KEY)==='light'?'light':'dark'}catch(_){return'dark'}}
10
+ function edgeId(e){return e.id||`${e.source}:${e.relation}:${e.target}`}
11
+ function shortText(value,max=32){const text=String(value??'');return text.length>max?text.slice(0,max-1)+'…':text}
12
+ function short(node){return shortText(node?.name||node?.id||node?.type||'node',28)}
13
+ function nodeColor(type){const value=String(type||'').toLowerCase();if(value.includes('session')||value.includes('agent'))return'var(--node-agent)';if(value.includes('process')||value.includes('shell'))return'var(--node-process)';if(value.includes('file')||value.includes('path'))return'var(--node-file)';if(value.includes('network')||value.includes('socket')||value.includes('endpoint')||value.includes('host'))return'var(--node-network)';if(value.includes('tool'))return'var(--node-tool)';if(value.includes('model')||value.includes('inference')||value.includes('llm'))return'var(--node-model)';return'var(--node-other)'}
14
+ function nodeCategory(node){const value=String(node?.type||'').toLowerCase();if(value.includes('process')||value.includes('shell'))return'process';if(value.includes('file')||value.includes('path'))return'file';if(value.includes('network')||value.includes('socket')||value.includes('endpoint')||value.includes('host'))return'network';if(value.includes('tool'))return'tool';if(value.includes('model')||value.includes('inference')||value.includes('llm'))return'model';return'other'}
15
+ function graphCounts(data){const nodes=Number(data.node_count)||((data.nodes||[]).length),edges=Number(data.edge_count)||((data.edges||[]).length);return{nodes,edges,estimated:nodes*4+edges*3}}
16
+ function withinRenderBudget(data){const counts=graphCounts(data);return counts.nodes<=ACTIVE_MAX_NODES&&counts.edges<=ACTIVE_MAX_EDGES&&counts.estimated<=ACTIVE_MAX_DOM_ELEMENTS}
17
+ function updateStats(data){stats.innerHTML=`<strong>${Number(data.node_count)||0}</strong> nodes · <strong>${Number(data.edge_count)||0}</strong> edges · <strong>${Number(data.event_count)||0}</strong> events`;stats.title=stats.textContent}
18
+ function updateEvidence(data){
19
+ const raw=window.__execweaveCore?.getGraph?.()||window.__execweaveStaticGraph||{},counts=data.live_evidence_counts||data.evidence_counts||raw.evidence_counts||{};
20
+ const count=value=>typeof value==='number'&&Number.isInteger(value)&&value>=0?String(value):'—';
21
+ const provisional=!!data.live_specialized_provisional,specialized=count(counts.specialized);
22
+ const specializedMarkup=`specialized ${specialized}`.replace(specialized,`<strong>${specialized}</strong>`);
23
+ evidence.innerHTML=`OS <strong>${count(counts.os_runtime)}</strong> · ${specializedMarkup}${provisional?' · provisional':''}`;
24
+ evidence.classList.toggle('provisional',provisional);evidence.title='Observed event counts. — means unavailable, not zero.';
25
+ const outcome=data.session_outcome||raw.session_outcome||{},labels={observation_incomplete:'OBSERVATION INCOMPLETE',succeeded:'PROCESS EXITED 0',failed:'FAILED',interrupted:'INTERRUPTED',collector_failed:'COLLECTOR FAILED',unknown:'UNKNOWN'};
26
+ let badge=document.getElementById('workload-outcome');if(!badge){badge=document.createElement('span');badge.id='workload-outcome';badge.className='metric-pill';evidence.after(badge)}
27
+ const finished=outcome.recorder_finished||data.live_finished||window.__execweaveStaticMode;
28
+ const state=finished?labels[outcome.state]||'UNKNOWN':'',exit=Number.isInteger(outcome.return_code)?' · exit '+outcome.return_code:'';
29
+ badge.replaceChildren();if(state){const label=document.createElement('span'),value=document.createElement('strong');label.className='workload-label';label.textContent='Workload: ';value.textContent=state;badge.append(label,value,exit)}
30
+ const workload=state?`Workload: ${state}${exit}`:'';badge.hidden=!workload;
31
+ badge.dataset.state=outcome.state||'unknown';badge.title=`${workload?workload+'. ':''}Workload result is separate from recorder FINISHED status.`;
32
+ }
33
+ function setStatus(label,kind=''){statusLabel.textContent=label;status.className=kind}
34
+ function enterProtectiveMode(data){const counts=graphCounts(data);edgeLayer.replaceChildren();labelLayer.replaceChildren();nodeLayer.replaceChildren();positions=new Map();nodeElements=new Map();edgeElements=new Map();svg.style.display='none';protective.hidden=false;protectiveSummary.textContent=`${counts.nodes} nodes · ${counts.edges} edges · about ${counts.estimated} SVG elements exceeds the live safety budget.`;setStatus('PROTECTED','reconnecting');protectedMode=true}
35
+ function leaveProtectiveMode(){protective.hidden=true;svg.style.display='block';protectedMode=false}
36
+ function registerEdgeAdjacency(e){const id=edgeId(e);if(!incomingByNode.has(e.target))incomingByNode.set(e.target,new Set());if(!outgoingByNode.has(e.source))outgoingByNode.set(e.source,new Set());incomingByNode.get(e.target).add(id);outgoingByNode.get(e.source).add(id)}
37
+ function rebuildAdjacency(){incomingByNode=new Map();outgoingByNode=new Map();for(const e of edgeById.values())registerEdgeAdjacency(e)}
38
+ function fullLayout(){positions=new Map();const ids=[...nodeById.keys()],incomingCount=new Map(ids.map(id=>[id,0])),outgoing=new Map(ids.map(id=>[id,[]]));for(const e of edgeById.values()){if(!nodeById.has(e.source)||!nodeById.has(e.target))continue;incomingCount.set(e.target,(incomingCount.get(e.target)||0)+1);outgoing.get(e.source).push(e.target)}let roots=ids.filter(id=>(incomingCount.get(id)||0)===0);if(!roots.length&&ids.length)roots=[ids[0]];const depth=new Map(),queue=roots.map(id=>[id,0]);for(let i=0;i<queue.length;i++){const [id,d]=queue[i];if(depth.has(id))continue;depth.set(id,d);for(const next of outgoing.get(id)||[])queue.push([next,d+1])}let maxDepth=0;depth.forEach(value=>{if(value>maxDepth)maxDepth=value});for(const id of ids)if(!depth.has(id))depth.set(id,maxDepth+1);const layers=new Map();for(const id of ids){const d=depth.get(id);if(!layers.has(d))layers.set(d,[]);layers.get(d).push(id)}layerRows=new Map();for(const [d,list] of layers){list.sort((a,b)=>String(nodeById.get(a)?.type).localeCompare(String(nodeById.get(b)?.type))||a.localeCompare(b));list.forEach((id,i)=>positions.set(id,{x:d*235,y:i*76}));layerRows.set(d,list.length)}}
39
+ function reservePosition(depth){const row=layerRows.get(depth)||0;layerRows.set(depth,row+1);return{x:depth*235,y:row*76}}
40
+ function nodeDepth(id){const p=positions.get(id);return p?Math.max(0,Math.round(p.x/235)):null}
41
+ function placeAddedNodes(ids){const pending=new Set(ids.filter(id=>nodeById.has(id)&&!positions.has(id)));while(pending.size){let progress=false;for(const id of [...pending]){const incoming=[...(incomingByNode.get(id)||[])].map(edgeIdValue=>edgeById.get(edgeIdValue)).filter(Boolean);const parentDepths=incoming.map(e=>nodeDepth(e.source)).filter(d=>d!==null);if(parentDepths.length){positions.set(id,reservePosition(Math.max(...parentDepths)+1));pending.delete(id);progress=true;continue}const outgoing=[...(outgoingByNode.get(id)||[])].map(edgeIdValue=>edgeById.get(edgeIdValue)).filter(Boolean);const targetDepths=outgoing.map(e=>nodeDepth(e.target)).filter(d=>d!==null);if(targetDepths.length){positions.set(id,reservePosition(Math.max(0,Math.min(...targetDepths)-1)));pending.delete(id);progress=true}}if(progress)continue;const id=pending.values().next().value;positions.set(id,reservePosition(0));pending.delete(id)}}
42
+ function anchor(id,right){const p=positions.get(id)||{x:0,y:0};return{x:p.x+(right?160:0),y:p.y+25}}
43
+ function curve(e){const a=anchor(e.source,true),b=anchor(e.target,false),distance=Math.abs(b.x-a.x),bend=Math.max(38,distance*.42);const p0={x:a.x,y:a.y},p1={x:a.x+bend,y:a.y},p2={x:b.x-bend,y:b.y},p3={x:b.x,y:b.y};let d=`M ${a.x} ${a.y}`;for(let i=1;i<8;i++){const t=i/8,u=1-t,x=u*u*u*p0.x+3*u*u*t*p1.x+3*u*t*t*p2.x+t*t*t*p3.x,y=u*u*u*p0.y+3*u*u*t*p1.y+3*u*t*t*p2.y+t*t*t*p3.y;d+=` L ${+x.toFixed(1)} ${+y.toFixed(1)}`}return d+` L ${b.x} ${b.y}`}
44
+ function currentEdge(id,fallback){return edgeById.get(id)||fallback}
45
+ function currentNode(id,fallback){return nodeById.get(id)||fallback}
46
+ function evidenceLabel(value){if(value?.inferred===true)return'Inferred';if(value?.causal===true)return'Direct / causal';if(value?.causal===false)return'Observed / non-causal';return'Observed'}
47
+ function evidenceClass(value){return value?.inferred===true?'inferred':value?.causal===true?'direct':''}
48
+ function prettyTime(value){if(!value)return'—';const date=new Date(value);if(Number.isNaN(date.getTime()))return shortText(value,18);return date.toLocaleTimeString([],{hour:'2-digit',minute:'2-digit',second:'2-digit',fractionalSecondDigits:3})}
49
+ function entityLabel(id){const node=nodeById.get(id);return node?.name||node?.id||id||'unknown'}
50
+ function renderKv(target,entries){target.replaceChildren();for(const [key,value] of entries){if(value===null||value===undefined||value==='')continue;const dt=document.createElement('dt');dt.textContent=key;const dd=document.createElement('dd');if(key==='Evidence'){const badge=document.createElement('span');badge.className='badge '+evidenceClass(value.raw||{});badge.textContent=value.label||String(value);dd.appendChild(badge)}else dd.textContent=String(value);target.append(dt,dd)}}
51
+ function show(value,kind='Selection'){detailsEmpty.hidden=true;details.innerHTML='';const title=document.createElement('div');title.className='current-title';title.textContent=kind==='Node'?(value.name||value.id||'Node'):kind==='Edge'?(value.relation||value.id||'Edge'):kind;const sub=document.createElement('div');sub.className='current-sub';sub.textContent=kind==='Node'?(value.type||'unknown'):kind==='Edge'?`${entityLabel(value.source)} → ${entityLabel(value.target)}`:'';const dl=document.createElement('dl');dl.className='kv';const entries=kind==='Node'?[['Type',value.type],['Events',value.event_count],['First seen',prettyTime(value.first_seen)],['Last seen',prettyTime(value.last_seen)]]:[['Count',value.count],['Last seen',prettyTime(value.last_seen)],['Sequence',value.last_sequence],['Evidence',{label:evidenceLabel(value),raw:value}]];renderKv(dl,entries);const raw=document.createElement('details');raw.className='raw-toggle';const summary=document.createElement('summary');summary.textContent='Raw metadata';const pre=document.createElement('pre');pre.textContent=JSON.stringify(value,null,2);raw.append(summary,pre);details.append(title,sub,dl,raw)}
52
+ function clearSelection(){if(selectedNodeId&&nodeElements.has(selectedNodeId))nodeElements.get(selectedNodeId).classList.remove('selected');if(selectedEdgeId&&edgeElements.has(selectedEdgeId)){const els=edgeElements.get(selectedEdgeId);els.visible.classList.remove('selected');els.label.classList.remove('selected')}selectedNodeId=null;selectedEdgeId=null;document.querySelectorAll('.activity-row.selected').forEach(row=>row.classList.remove('selected'))}
53
+ function selectNode(id,{syncLog=true}={}){const node=nodeById.get(id);if(!node)return;clearSelection();selectedNodeId=id;nodeElements.get(id)?.classList.add('selected');show(node,'Node');window.__execweaveFocusConversationAgent?.(node);if(syncLog){const activity=[...activities].reverse().find(item=>item.nodeId===id);if(activity)selectActivityRow(activity.id,false)}}
54
+ function selectEdge(id,{syncLog=true}={}){const edge=edgeById.get(id);if(!edge)return;clearSelection();window.__execweaveClearConversationFocus?.();selectedEdgeId=id;const els=edgeElements.get(id);if(els){els.visible.classList.add('selected');els.label.classList.add('selected')}show(edge,'Edge');if(syncLog){const activity=[...activities].reverse().find(item=>item.edgeId===id);if(activity)selectActivityRow(activity.id,false)}}
55
+ function createNodeElement(n){if(nodeElements.has(n.id))return updateNodeElement(n);const p=positions.get(n.id);if(!p)return;const group=document.createElementNS('http://www.w3.org/2000/svg','g');group.classList.add('node');group.dataset.id=n.id;group.setAttribute('transform',`translate(${p.x} ${p.y})`);const rect=document.createElementNS('http://www.w3.org/2000/svg','rect');rect.setAttribute('width',160);rect.setAttribute('height',50);group.appendChild(rect);const type=document.createElementNS('http://www.w3.org/2000/svg','text');type.setAttribute('x',10);type.setAttribute('y',15);type.classList.add('type');group.appendChild(type);const label=document.createElementNS('http://www.w3.org/2000/svg','text');label.setAttribute('x',10);label.setAttribute('y',34);label.classList.add('name-label');group.appendChild(label);group.onclick=ev=>{ev.stopPropagation();selectNode(n.id)};nodeLayer.appendChild(group);nodeElements.set(n.id,group);updateNodeElement(n)}
56
+ function updateNodeElement(n){const group=nodeElements.get(n.id);if(!group)return;const cat=nodeCategory(n);group.dataset.search=`${n.id} ${n.name||''} ${n.type||''}`.toLowerCase();group.dataset.category=cat;group.classList.toggle('category-'+cat,true);const rect=group.querySelector('rect');if(rect)rect.setAttribute('fill',nodeColor(n.type));const type=group.querySelector('.type');if(type)type.textContent=n.type||'unknown';const label=group.querySelector('.name-label');if(label)label.textContent=short(n);group.classList.toggle('latest',n.id===latestNodeId);group.classList.toggle('selected',n.id===selectedNodeId)}
57
+ function createEdgeElement(e){const id=edgeId(e);if(edgeElements.has(id))return updateEdgeElement(e);if(!positions.has(e.source)||!positions.has(e.target))return;const visible=document.createElementNS('http://www.w3.org/2000/svg','path');visible.classList.add('edge');visible.dataset.edgeId=id;edgeLayer.appendChild(visible);const hit=document.createElementNS('http://www.w3.org/2000/svg','path');hit.classList.add('edge-hit');hit.dataset.edgeId=id;hit.onclick=ev=>{ev.stopPropagation();selectEdge(id)};edgeLayer.appendChild(hit);const label=document.createElementNS('http://www.w3.org/2000/svg','text');label.setAttribute('text-anchor','middle');label.classList.add('label');label.dataset.edgeId=id;labelLayer.appendChild(label);edgeElements.set(id,{visible,hit,label});updateEdgeElement(e)}
58
+ function updateEdgeElement(e){const id=edgeId(e),els=edgeElements.get(id);if(!els)return;const d=curve(e);els.visible.setAttribute('d',d);els.hit.setAttribute('d',d);els.visible.classList.toggle('causal',e.causal===true);els.visible.classList.toggle('noncausal',e.causal===false);els.visible.classList.toggle('inferred',e.inferred===true);els.visible.classList.toggle('latest-edge',id===latestEdgeId);els.visible.classList.toggle('selected',id===selectedEdgeId);els.label.classList.toggle('selected',id===selectedEdgeId);els.visible.dataset.source=e.source;els.visible.dataset.target=e.target;els.visible.dataset.relation=String(e.relation||'').toLowerCase();const a=anchor(e.source,true),b=anchor(e.target,false);els.label.setAttribute('x',(a.x+b.x)/2);els.label.setAttribute('y',(a.y+b.y)/2-6);els.label.textContent=e.count>1?`${e.relation} ×${e.count}`:e.relation}
59
+ """