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,192 @@
1
+ """Measure routed SVG geometry, not node-center chords, for layout decisions."""
2
+
3
+ LAYOUT_GEOMETRY_SCRIPT = r"""
4
+ const execweaveGeometry=(function(){
5
+ const epsilon=1e-6;
6
+ function polyline(d){
7
+ const tokens=String(d).match(/[A-Za-z]|[-+]?(?:\d*\.\d+|\d+\.?\d*)(?:[eE][-+]?\d+)?/g)||[];
8
+ const points=[];let x=0,y=0,i=0,command='';
9
+ while(i<tokens.length){
10
+ if(/^[A-Za-z]$/.test(tokens[i]))command=tokens[i++];
11
+ if(command==='M'||command==='L'){x=Number(tokens[i++]);y=Number(tokens[i++])}
12
+ else if(command==='H')x=Number(tokens[i++]);
13
+ else if(command==='V')y=Number(tokens[i++]);
14
+ else return null;
15
+ if(!Number.isFinite(x)||!Number.isFinite(y))return null;
16
+ points.push({x,y});
17
+ }
18
+ return points;
19
+ }
20
+ const cache=new Map();
21
+ function sample(d){
22
+ if(cache.has(d))return cache.get(d);
23
+ const save=points=>{if(cache.size>=4096)cache.delete(cache.keys().next().value);cache.set(d,points);return points};
24
+ const exact=polyline(d);if(exact)return save(exact);
25
+ // The two intentional special families are measured from the same SVG path
26
+ // string the renderer uses. Browser arc-length sampling handles the cubic.
27
+ const path=document.createElementNS('http://www.w3.org/2000/svg','path');
28
+ path.setAttribute('d',d);const length=path.getTotalLength();
29
+ const count=Math.max(24,Math.min(192,Math.ceil(length/8))),out=[];
30
+ for(let i=0;i<=count;i++){const p=path.getPointAtLength(length*i/count);out.push({x:p.x,y:p.y})}
31
+ return save(out);
32
+ }
33
+ const side=(a,b,c)=>(b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
34
+ function crosses(a,b,c,d){
35
+ if(Math.max(a.x,b.x)<Math.min(c.x,d.x)||Math.max(c.x,d.x)<Math.min(a.x,b.x)||
36
+ Math.max(a.y,b.y)<Math.min(c.y,d.y)||Math.max(c.y,d.y)<Math.min(a.y,b.y))return false;
37
+ const p=side(a,b,c),q=side(a,b,d),r=side(c,d,a),s=side(c,d,b);
38
+ return ((p>epsilon&&q< -epsilon)||(p< -epsilon&&q>epsilon))&&
39
+ ((r>epsilon&&s< -epsilon)||(r< -epsilon&&s>epsilon));
40
+ }
41
+ function throughBox(a,b,box){
42
+ // Liang-Barsky clipping into the OPEN interior. Touching a boundary is not
43
+ // an edge passing through a node. End-node boxes are excluded by the caller.
44
+ let lo=0,hi=1;const dx=b.x-a.x,dy=b.y-a.y;
45
+ const left=box.x+epsilon,right=box.x+box.w-epsilon,top=box.y+epsilon,bottom=box.y+box.h-epsilon;
46
+ for(const [p,q] of [[-dx,a.x-left],[dx,right-a.x],[-dy,a.y-top],[dy,bottom-a.y]]){
47
+ if(Math.abs(p)<epsilon){if(q<0)return false;continue}
48
+ const t=q/p;if(p<0)lo=Math.max(lo,t);else hi=Math.min(hi,t);
49
+ if(lo>=hi)return false;
50
+ }
51
+ return lo<hi&&hi>0&&lo<1;
52
+ }
53
+ function avoidNodes(points,boxes){
54
+ const blocked=(a,b)=>boxes.some(box=>throughBox(a,b,box));
55
+ const inside=p=>boxes.some(b=>p.x>b.x&&p.x<b.x+b.w&&p.y>b.y&&p.y<b.y+b.h);
56
+ // A semantic constraint may move a box over a former Dagre bend. Keep all
57
+ // legal guides, replacing only obstructed bends with visibility detours.
58
+ const guides=points.filter((p,i)=>i===0||i===points.length-1||!inside(p));
59
+ const out=[guides[0]];let detours=0;
60
+ for(let part=1;part<guides.length;part++){
61
+ const a=out[out.length-1],b=guides[part];
62
+ if(!blocked(a,b)){out.push(b);continue}
63
+ let blockers=boxes.filter(box=>throughBox(a,b,box)),found=null;
64
+ for(let pass=0;pass<2&&!found;pass++){
65
+ const vertices=[a,b];
66
+ for(const box of blockers){
67
+ const l=box.x-2,r=box.x+box.w+2,t=box.y-2,d=box.y+box.h+2;
68
+ for(const p of [{x:l,y:t},{x:l,y:d},{x:r,y:t},{x:r,y:d}])if(!inside(p))vertices.push(p);
69
+ }
70
+ const dist=vertices.map(()=>Infinity),prev=vertices.map(()=>-1),used=new Set();dist[0]=0;
71
+ for(let i=0;i<vertices.length;i++){
72
+ let u=-1;for(let j=0;j<vertices.length;j++)if(!used.has(j)&&(u<0||dist[j]<dist[u]))u=j;
73
+ if(u<0||!Number.isFinite(dist[u]))break;
74
+ if(u===1)break;used.add(u);
75
+ for(let v=0;v<vertices.length;v++){
76
+ if(v===u||used.has(v)||blocked(vertices[u],vertices[v]))continue;
77
+ const next=dist[u]+Math.hypot(vertices[u].x-vertices[v].x,vertices[u].y-vertices[v].y);
78
+ if(next<dist[v]-1e-6){dist[v]=next;prev[v]=u}
79
+ }
80
+ }
81
+ if(Number.isFinite(dist[1])){
82
+ found=[];let at=1;while(at>0){found.push(vertices[at]);at=prev[at]}found.reverse();
83
+ }else blockers=boxes;
84
+ }
85
+ if(found){out.push(...found);detours++}else out.push(b);
86
+ }
87
+ return{points:out,detours,obstructedGuides:points.length-guides.length};
88
+ }
89
+
90
+ function avoidCrossings(points,boxes,segments,clearance=7){
91
+ const protectedSegments=(Array.isArray(segments)?segments:[]).filter(segment=>
92
+ segment?.a&&segment?.b&&Number.isFinite(segment.a.x)&&Number.isFinite(segment.a.y)&&
93
+ Number.isFinite(segment.b.x)&&Number.isFinite(segment.b.y)&&
94
+ Math.hypot(segment.b.x-segment.a.x,segment.b.y-segment.a.y)>epsilon
95
+ );
96
+ if(!Array.isArray(points)||points.length<2||!protectedSegments.length){
97
+ return{points:Array.isArray(points)?points:[],detours:0,crossingsAvoided:0};
98
+ }
99
+ const nodeBoxes=Array.isArray(boxes)?boxes:[];
100
+ const inside=p=>nodeBoxes.some(box=>p.x>box.x&&p.x<box.x+box.w&&p.y>box.y&&p.y<box.y+box.h);
101
+ const blocked=(a,b)=>nodeBoxes.some(box=>throughBox(a,b,box))||
102
+ protectedSegments.some(segment=>crosses(a,b,segment.a,segment.b));
103
+ const crossingCount=route=>{
104
+ let count=0;
105
+ for(let i=1;i<route.length;i++)for(const segment of protectedSegments)
106
+ if(crosses(route[i-1],route[i],segment.a,segment.b))count++;
107
+ return count;
108
+ };
109
+ const before=crossingCount(points);
110
+ if(!before)return{points,detours:0,crossingsAvoided:0};
111
+
112
+ const portals=[];
113
+ for(const segment of protectedSegments){
114
+ const dx=segment.b.x-segment.a.x,dy=segment.b.y-segment.a.y,length=Math.hypot(dx,dy);
115
+ if(length<=epsilon)continue;
116
+ const tx=dx/length,ty=dy/length,nx=-ty,ny=tx;
117
+ for(const endpoint of [segment.a,segment.b])for(const normal of [-1,1])for(const tangent of [-1,1]){
118
+ const p={
119
+ x:endpoint.x+normal*clearance*nx+tangent*clearance*tx,
120
+ y:endpoint.y+normal*clearance*ny+tangent*clearance*ty,
121
+ };
122
+ if(!inside(p))portals.push(p);
123
+ }
124
+ }
125
+
126
+ const solve=(a,b,includeBoxes)=>{
127
+ const vertices=[a,b,...portals];
128
+ if(includeBoxes){
129
+ for(const box of nodeBoxes){
130
+ const l=box.x-2,r=box.x+box.w+2,t=box.y-2,d=box.y+box.h+2;
131
+ for(const p of [{x:l,y:t},{x:l,y:d},{x:r,y:t},{x:r,y:d}])if(!inside(p))vertices.push(p);
132
+ }
133
+ }
134
+ const dist=vertices.map(()=>Infinity),prev=vertices.map(()=>-1),used=new Set();dist[0]=0;
135
+ for(let i=0;i<vertices.length;i++){
136
+ let u=-1;for(let j=0;j<vertices.length;j++)if(!used.has(j)&&(u<0||dist[j]<dist[u]))u=j;
137
+ if(u<0||!Number.isFinite(dist[u]))break;
138
+ if(u===1)break;used.add(u);
139
+ for(let v=0;v<vertices.length;v++){
140
+ if(v===u||used.has(v)||blocked(vertices[u],vertices[v]))continue;
141
+ const next=dist[u]+Math.hypot(vertices[u].x-vertices[v].x,vertices[u].y-vertices[v].y);
142
+ if(next<dist[v]-1e-6){dist[v]=next;prev[v]=u}
143
+ }
144
+ }
145
+ if(!Number.isFinite(dist[1]))return null;
146
+ const found=[];let at=1;
147
+ while(at>0){found.push(vertices[at]);at=prev[at]}
148
+ found.reverse();return found;
149
+ };
150
+
151
+ const out=[points[0]];let detours=0;
152
+ for(let part=1;part<points.length;part++){
153
+ const a=out[out.length-1],b=points[part];
154
+ const directCrosses=protectedSegments.some(segment=>crosses(a,b,segment.a,segment.b));
155
+ if(!directCrosses){out.push(b);continue}
156
+ const found=solve(a,b,false)||solve(a,b,true);
157
+ if(found){out.push(...found);detours++}else out.push(b);
158
+ }
159
+ const after=crossingCount(out);
160
+ if(after>=before)return{points,detours:0,crossingsAvoided:0};
161
+ return{points:out,detours,crossingsAvoided:before-after};
162
+ }
163
+
164
+ function measure(nodes,edges){
165
+ const routes=edges.map(e=>{const points=sample(e.d);return{...e,points,left:Math.min(...points.map(p=>p.x)),right:Math.max(...points.map(p=>p.x)),top:Math.min(...points.map(p=>p.y)),bottom:Math.max(...points.map(p=>p.y))}});
166
+ let crossings=0,overlaps=0,intersections=0;
167
+ for(let i=0;i<nodes.length;i++)for(let j=0;j<i;j++){
168
+ const a=nodes[i],b=nodes[j];
169
+ if(Math.min(a.x+a.w,b.x+b.w)-Math.max(a.x,b.x)>epsilon&&
170
+ Math.min(a.y+a.h,b.y+b.h)-Math.max(a.y,b.y)>epsilon)overlaps++;
171
+ }
172
+ for(let i=0;i<routes.length;i++){
173
+ const a=routes[i];
174
+ for(let j=0;j<i;j++){
175
+ const b=routes[j];if(a.right<b.left||b.right<a.left||a.bottom<b.top||b.bottom<a.top)continue;let hit=false;
176
+ for(let k=1;k<a.points.length&&!hit;k++)for(let l=1;l<b.points.length&&!hit;l++)
177
+ hit=crosses(a.points[k-1],a.points[k],b.points[l-1],b.points[l]);
178
+ if(hit)crossings++;
179
+ }
180
+ for(const node of nodes){
181
+ if(node.id===a.source||node.id===a.target||a.right<=node.x||a.left>=node.x+node.w||a.bottom<=node.y||a.top>=node.y+node.h)continue;
182
+ if(a.points.some((p,k)=>k>0&&throughBox(a.points[k-1],p,node)))intersections++;
183
+ }
184
+ }
185
+ const lengths=routes.map(e=>e.points.reduce((s,p,i)=>i?s+Math.hypot(p.x-e.points[i-1].x,p.y-e.points[i-1].y):s,0)).sort((a,b)=>a-b);
186
+ return{EDGE_CROSSINGS:crossings,NODE_OVERLAPS:overlaps,EDGE_NODE_INTERSECTIONS:intersections,
187
+ MAX_EDGE_LENGTH:lengths.at(-1)||0,P95_EDGE_LENGTH:lengths[Math.max(0,Math.ceil(lengths.length*.95)-1)]||0,
188
+ VISIBLE_NODE_COUNT:nodes.length,VISIBLE_EDGE_COUNT:edges.length};
189
+ }
190
+ return{polyline,sample,crosses,throughBox,measure,avoidNodes,avoidCrossings};
191
+ })();
192
+ """.strip()
@@ -0,0 +1,429 @@
1
+ from __future__ import annotations
2
+
3
+ _STARTUP_SEAM = "applyTheme(initialTheme());applyTransform();poll();"
4
+ _BAND_GAP_SEAM = "const EXECWEAVE_BAND_GAP=170;"
5
+ _PACKING_SEAM = """ const columns=Math.max(1,Math.ceil(Math.sqrt(compBoxes.length)));
6
+ const widest=compBoxes.reduce((width,box)=>Math.max(width,box.w),0);
7
+ const packingWidth=Math.max(spineWidth,columns*widest+(columns-1)*bandGap);"""
8
+ _PACKING_REPLACEMENT = """ const columns=Math.max(1,Math.ceil(Math.sqrt(compBoxes.length)));
9
+ const widest=compBoxes.reduce((width,box)=>Math.max(width,box.w),0);
10
+ const packingWidth=typeof execweaveLayoutV2PackingWidth==='function'
11
+ ?execweaveLayoutV2PackingWidth(compBoxes,spineWidth,bandGap)
12
+ :Math.max(spineWidth,columns*widest+(columns-1)*bandGap);"""
13
+ _SYNC_ORDER_SEAM = """ for(const [id,p] of positions){const s=topo.spec.get(id);if(s){s.x=p.x;s.y=p.y}}
14
+ if(typeof execweaveRecomputePorts==='function')execweaveRecomputePorts(topo);"""
15
+ _SYNC_ORDER_REPLACEMENT = """ for(const [id,p] of positions){const s=topo.spec.get(id);if(s){s.x=p.x;s.y=p.y}}
16
+ if(typeof execweaveLayoutV2SyncFinalOrder==='function')execweaveLayoutV2SyncFinalOrder(topo,positions);
17
+ if(typeof execweaveRecomputePorts==='function')execweaveRecomputePorts(topo);"""
18
+ _BUS_ROUTE_SEAM = """ function route(edge){
19
+ const topo=execweaveTopology,bundle=topo.bundleByEdge.get(edgeId(edge));
20
+ if(bundle&&bundle.size>1){"""
21
+ _BUS_ROUTE_REPLACEMENT = """ function route(edge){
22
+ const topo=execweaveTopology,bundle=topo.bundleByEdge.get(edgeId(edge));
23
+ if(bundle&&bundle.size>1&&typeof execweaveLayoutV2BusRoute==='function'){
24
+ const layoutV2Bus=execweaveLayoutV2BusRoute(edge);
25
+ if(layoutV2Bus)return layoutV2Bus;
26
+ }
27
+ if(bundle&&bundle.size>1){"""
28
+ _BUILD_TOPOLOGY_SEAM = """ const projectionBuildTopologyBase=execweaveBuildTopology;
29
+ execweaveBuildTopology=function(){
30
+ const topo=projectionBuildTopologyBase();
31
+ return optimize(projectionRetargetDagreRoutePoints(topo));
32
+ };"""
33
+ _BUILD_TOPOLOGY_REPLACEMENT = """ const projectionBuildTopologyBase=execweaveBuildTopology;
34
+ execweaveBuildTopology=function(){
35
+ const topo=projectionBuildTopologyBase();
36
+ const optimized=optimize(projectionRetargetDagreRoutePoints(topo));
37
+ return typeof execweaveLayoutV2FinalizeTopology==='function'
38
+ ?execweaveLayoutV2FinalizeTopology(optimized):optimized;
39
+ };"""
40
+ _INPUT_KEY_SEAM = """ const inputKey=JSON.stringify({nodes:[...topo.spec].map(([id,s])=>[id,s.x,s.y,topo.width.get(id),topo.height.get(id)]).sort(),
41
+ edges:[...edgeById.values()].map(e=>[edgeId(e),e.source,e.target,e.relation]).sort()});"""
42
+ _INPUT_KEY_REPLACEMENT = """ const layoutMode=(typeof window!=='undefined'&&window.__execweaveLayoutV2Mode)||'live';
43
+ const inputKey=JSON.stringify({mode:layoutMode,nodes:[...topo.spec].map(([id,s])=>[id,s.x,s.y,topo.width.get(id),topo.height.get(id)]).sort(),
44
+ edges:[...edgeById.values()].map(e=>[edgeId(e),e.source,e.target,e.relation]).sort()});"""
45
+ _BUDGET_SEAM = " const budget=Math.max(24,Math.min(512,Math.floor(24000/Math.max(1,edgeById.size))));"
46
+ _BUDGET_REPLACEMENT = """ const budget=layoutMode==='arrange'
47
+ ?Math.max(96,Math.min(1024,Math.floor(48000/Math.max(1,edgeById.size))))
48
+ :Math.max(24,Math.min(512,Math.floor(24000/Math.max(1,edgeById.size))));"""
49
+ _BETTER_SEAM = """ const crossingCeiling=best.EDGE_CROSSINGS;
50
+ const better=m=>m.NODE_OVERLAPS===0&&m.EDGE_CROSSINGS<=crossingCeiling&&
51
+ (m.EDGE_NODE_INTERSECTIONS<best.EDGE_NODE_INTERSECTIONS||
52
+ m.EDGE_NODE_INTERSECTIONS===best.EDGE_NODE_INTERSECTIONS&&m.EDGE_CROSSINGS<best.EDGE_CROSSINGS);"""
53
+ _BETTER_REPLACEMENT = """ const quality=m=>(m.NODE_DENSITY||0)-.10*(m.ASPECT_ERROR||0)-.04*Math.max(0,(m.P95_EDGE_STRETCH||1)-1);
54
+ const better=m=>{
55
+ if(m.NODE_OVERLAPS!==0||m.EDGE_NODE_INTERSECTIONS>best.EDGE_NODE_INTERSECTIONS)return false;
56
+ if(m.EDGE_CROSSINGS>best.EDGE_CROSSINGS)return false;
57
+ if(m.EDGE_NODE_INTERSECTIONS<best.EDGE_NODE_INTERSECTIONS||m.EDGE_CROSSINGS<best.EDGE_CROSSINGS)return true;
58
+ return quality(m)>quality(best)+1e-9;
59
+ };"""
60
+ _ROUNDS_SEAM = " for(let round=0;round<2&&evaluations<budget;round++){"
61
+ _ROUNDS_REPLACEMENT = " for(let round=0;round<(layoutMode==='arrange'?4:2)&&evaluations<budget;round++){"
62
+ _ARRANGE_SEAM = """function execweaveArrangePositions(){
63
+ execweaveTopology=execweaveBuildTopology();"""
64
+ _ARRANGE_REPLACEMENT = """function execweaveArrangePositions(){
65
+ const execweavePriorLayoutV2Mode=(typeof window!=='undefined'&&window.__execweaveLayoutV2Mode)||'live';
66
+ const execweaveNextLayoutV2Mode=(typeof nodeById!=='undefined'&&nodeById.size>96)?'live':'arrange';
67
+ if(typeof window!=='undefined')window.__execweaveLayoutV2Mode=execweaveNextLayoutV2Mode;
68
+ try{execweaveTopology=execweaveBuildTopology()}
69
+ finally{if(typeof window!=='undefined')window.__execweaveLayoutV2Mode=execweavePriorLayoutV2Mode}"""
70
+
71
+ LAYOUT_V2_SCRIPT = r"""
72
+ (function(){
73
+ window.__execweaveLayoutV2Mode=window.__execweaveLayoutV2Mode||'live';
74
+
75
+ function execweaveLayoutV2SyncFinalOrder(topo=execweaveTopology,placement=positions){
76
+ if(!topo?.spec||!(placement instanceof Map))return new Map();
77
+ const byLane=new Map();
78
+ for(const [id,p] of placement){
79
+ const spec=topo.spec.get(id);
80
+ if(!spec||!Number.isFinite(p?.y))continue;
81
+ const key=String(spec.lane||'other');
82
+ if(!byLane.has(key))byLane.set(key,[]);
83
+ byLane.get(key).push(id);
84
+ }
85
+ const finalOrder=new Map();
86
+ for(const ids of byLane.values()){
87
+ ids.sort((a,b)=>{
88
+ const ap=placement.get(a),bp=placement.get(b);
89
+ return (ap.y-bp.y)||(ap.x-bp.x)||String(a).localeCompare(String(b));
90
+ });
91
+ ids.forEach((id,index)=>{
92
+ const spec=topo.spec.get(id);
93
+ if(spec)spec.finalOrder=index;
94
+ finalOrder.set(id,index);
95
+ });
96
+ }
97
+ topo.finalOrder=finalOrder;
98
+ return finalOrder;
99
+ }
100
+ window.execweaveLayoutV2SyncFinalOrder=execweaveLayoutV2SyncFinalOrder;
101
+
102
+ function execweaveLayoutV2ViewportAspect(){
103
+ try{
104
+ const el=(typeof svg!=='undefined'&&svg)||document.getElementById('svg');
105
+ const box=el&&typeof el.getBoundingClientRect==='function'?el.getBoundingClientRect():null;
106
+ const value=box&&box.width>0&&box.height>0?box.width/box.height:16/9;
107
+ return Math.max(1.2,Math.min(2.4,value));
108
+ }catch(_){return 16/9}
109
+ }
110
+
111
+ function execweaveLayoutV2PackingWidth(boxes,spineWidth,gap){
112
+ if(!Array.isArray(boxes)||!boxes.length)return spineWidth;
113
+ const targetAspect=execweaveLayoutV2ViewportAspect();
114
+ const totalArea=boxes.reduce((sum,box)=>sum+Math.max(1,box.w+gap)*Math.max(1,box.h+gap),0);
115
+ const widest=boxes.reduce((width,box)=>Math.max(width,box.w),0);
116
+ const base=Math.max(spineWidth,widest,Math.sqrt(totalArea*targetAspect));
117
+ const widths=boxes.map(box=>box.w).sort((a,b)=>b-a);
118
+ const breakpoints=[];
119
+ let prefix=0;
120
+ for(let i=0;i<Math.min(widths.length,8);i++){
121
+ prefix+=widths[i];
122
+ breakpoints.push(prefix+i*gap);
123
+ }
124
+ const candidates=[spineWidth,widest,...breakpoints,...[.8,1,1.2,1.45].map(scale=>base*scale)]
125
+ .map(value=>Math.max(widest,value))
126
+ .sort((a,b)=>a-b)
127
+ .filter((value,index,list)=>index===0||Math.abs(value-list[index-1])>1);
128
+ let bestWidth=candidates[0],bestCost=Infinity;
129
+ for(const width of candidates){
130
+ let x=0,y=0,rowHeight=0,maxRight=0;
131
+ for(const box of boxes){
132
+ if(x>0&&x+box.w>width){x=0;y+=rowHeight+gap;rowHeight=0}
133
+ maxRight=Math.max(maxRight,x+box.w);
134
+ rowHeight=Math.max(rowHeight,box.h);
135
+ x+=box.w+gap;
136
+ }
137
+ const height=Math.max(1,y+rowHeight),usedWidth=Math.max(1,maxRight);
138
+ const area=usedWidth*height;
139
+ const aspectError=Math.abs(Math.log((usedWidth/height)/targetAspect));
140
+ const cost=area*(1+.35*aspectError);
141
+ if(cost<bestCost-1e-6||(Math.abs(cost-bestCost)<=1e-6&&width<bestWidth)){bestCost=cost;bestWidth=width}
142
+ }
143
+ return Math.max(spineWidth,bestWidth);
144
+ }
145
+ window.execweaveLayoutV2PackingWidth=execweaveLayoutV2PackingWidth;
146
+
147
+ function execweaveLayoutV2FinalizeTopology(topo){
148
+ if(!topo?.spec||typeof nodeById==='undefined'||typeof edgeById==='undefined'||typeof execweaveComponents!=='function')return topo;
149
+ const nodes=[...nodeById.values()].filter(node=>topo.spec.has(node.id));
150
+ const edges=[...edgeById.values()].filter(edge=>topo.spec.has(edge.source)&&topo.spec.has(edge.target));
151
+ const componentOf=execweaveComponents(nodes,edges);
152
+ if(!componentOf.size)return topo;
153
+ const sizes=new Map();
154
+ for(const value of componentOf.values())sizes.set(value,(sizes.get(value)||0)+1);
155
+ const roots=nodes.filter(typeof execweaveIsRoot==='function'?execweaveIsRoot:()=>false);
156
+ let primary=roots.length?componentOf.get(roots[0].id):undefined;
157
+ if(primary===undefined){
158
+ let best=-1;
159
+ for(const [value,size] of [...sizes.entries()].sort((a,b)=>a[0]-b[0]))if(size>best){best=size;primary=value}
160
+ }
161
+ const agentIds=new Set(nodes.filter(node=>node?.type==='agent').map(node=>node.id));
162
+ const spineComponents=new Set([...componentOf.entries()].filter(([id])=>agentIds.has(id)).map(([,value])=>value));
163
+ if(primary!==undefined)spineComponents.add(primary);
164
+ const secondary=[...sizes.keys()].filter(value=>!spineComponents.has(value)).sort((a,b)=>a-b);
165
+ topo.secondaryPackedIds=new Set();
166
+ if(!secondary.length){
167
+ const placement=new Map([...topo.spec].map(([id,spec])=>[id,{x:spec.x,y:spec.y}]));
168
+ execweaveLayoutV2SyncFinalOrder(topo,placement);
169
+ if(typeof execweaveRecomputePorts==='function')execweaveRecomputePorts(topo);
170
+ return topo;
171
+ }
172
+
173
+ let spineLeft=Infinity,spineRight=-Infinity,spineFloor=-Infinity;
174
+ for(const [id,value] of componentOf){
175
+ if(!spineComponents.has(value))continue;
176
+ const spec=topo.spec.get(id);if(!spec)continue;
177
+ const w=topo.width?.get(id)||execweaveWidthOf(id),h=topo.height?.get(id)||execweaveHeightOf(id);
178
+ spineLeft=Math.min(spineLeft,spec.x);spineRight=Math.max(spineRight,spec.x+w);spineFloor=Math.max(spineFloor,spec.y+h);
179
+ }
180
+ if(!Number.isFinite(spineLeft)){spineLeft=0;spineRight=600;spineFloor=100}
181
+ const gap=64,spineWidth=Math.max(600,spineRight-spineLeft),boxes=[];
182
+
183
+ for(const value of secondary){
184
+ const members=[...componentOf.entries()].filter(([,component])=>component===value).map(([id])=>id).sort();
185
+ // The global lane pass can give two nodes in one detached component hundreds
186
+ // of pixels of unrelated vertical separation. Compact each X column locally
187
+ // before packing components, while preserving the current within-column order.
188
+ const columns=new Map();
189
+ for(const id of members){
190
+ const spec=topo.spec.get(id);if(!spec)continue;
191
+ const key=Number(spec.x).toFixed(3);
192
+ if(!columns.has(key))columns.set(key,[]);
193
+ columns.get(key).push(id);
194
+ }
195
+ for(const ids of columns.values()){
196
+ ids.sort((a,b)=>(topo.spec.get(a).y-topo.spec.get(b).y)||String(a).localeCompare(String(b)));
197
+ let y=0;
198
+ for(const id of ids){
199
+ const spec=topo.spec.get(id),h=topo.height?.get(id)||execweaveHeightOf(id);
200
+ spec.y=y;y+=h+24;
201
+ }
202
+ }
203
+ let minX=Infinity,maxX=-Infinity,minY=Infinity,maxY=-Infinity;
204
+ for(const id of members){
205
+ const spec=topo.spec.get(id);if(!spec)continue;
206
+ const w=topo.width?.get(id)||execweaveWidthOf(id),h=topo.height?.get(id)||execweaveHeightOf(id);
207
+ minX=Math.min(minX,spec.x);maxX=Math.max(maxX,spec.x+w);minY=Math.min(minY,spec.y);maxY=Math.max(maxY,spec.y+h);
208
+ }
209
+ if(Number.isFinite(minX))boxes.push({value,members,minX,maxX,minY,maxY,w:maxX-minX,h:maxY-minY});
210
+ }
211
+
212
+ const packingWidth=execweaveLayoutV2PackingWidth(boxes,spineWidth,gap);
213
+ let cursorX=spineLeft,cursorY=spineFloor+gap,rowHeight=0;
214
+ for(const box of boxes){
215
+ if(cursorX>spineLeft&&cursorX+box.w>spineLeft+packingWidth){cursorX=spineLeft;cursorY+=rowHeight+gap;rowHeight=0}
216
+ const shiftX=cursorX-box.minX,shiftY=cursorY-box.minY;
217
+ for(const id of box.members){
218
+ const spec=topo.spec.get(id);if(spec){spec.x+=shiftX;spec.y+=shiftY;topo.secondaryPackedIds.add(id)}
219
+ }
220
+ cursorX+=box.w+gap;rowHeight=Math.max(rowHeight,box.h);
221
+ }
222
+ const placement=new Map([...topo.spec].map(([id,spec])=>[id,{x:spec.x,y:spec.y}]));
223
+ execweaveLayoutV2SyncFinalOrder(topo,placement);
224
+ if(typeof execweaveRecomputePorts==='function')execweaveRecomputePorts(topo);
225
+ return topo;
226
+ }
227
+ window.execweaveLayoutV2FinalizeTopology=execweaveLayoutV2FinalizeTopology;
228
+
229
+ function execweaveLayoutV2HubInversionRate(){
230
+ if(typeof edgeById==='undefined'||typeof positions==='undefined'||!execweaveTopology?.targetPort)return 0;
231
+ const incoming=new Map();
232
+ for(const edge of edgeById.values()){
233
+ if(!positions.has(edge.source)||!positions.has(edge.target))continue;
234
+ const target=typeof nodeById!=='undefined'?nodeById.get(edge.target):null;
235
+ const lane=target?String(execweaveTopology.spec.get(target.id)?.lane||''):'';
236
+ if(lane!=='tool'&&lane!=='model')continue;
237
+ if(!incoming.has(edge.target))incoming.set(edge.target,[]);
238
+ incoming.get(edge.target).push(edge);
239
+ }
240
+ let worst=0;
241
+ for(const edges of incoming.values()){
242
+ if(edges.length<3)continue;
243
+ const ordered=[...edges].sort((a,b)=>{
244
+ const ap=positions.get(a.source),bp=positions.get(b.source);
245
+ return (ap.y-bp.y)||(ap.x-bp.x)||edgeId(a).localeCompare(edgeId(b));
246
+ });
247
+ const slots=ordered.map(edge=>execweaveTopology.targetPort.get(edgeId(edge))?.index??0);
248
+ let inv=0;
249
+ for(let i=0;i<slots.length;i++)for(let j=0;j<i;j++)if(slots[j]>slots[i])inv++;
250
+ worst=Math.max(worst,inv/Math.max(1,slots.length*(slots.length-1)/2));
251
+ }
252
+ return worst;
253
+ }
254
+
255
+ function execweaveLayoutV2OrderMismatches(){
256
+ if(typeof positions==='undefined'||!execweaveTopology?.spec)return 0;
257
+ const byLane=new Map();
258
+ for(const [id,p] of positions){
259
+ const spec=execweaveTopology.spec.get(id);if(!spec)continue;
260
+ const lane=String(spec.lane||'other');
261
+ if(!byLane.has(lane))byLane.set(lane,[]);
262
+ byLane.get(lane).push([id,p,spec]);
263
+ }
264
+ let mismatches=0;
265
+ for(const rows of byLane.values()){
266
+ rows.sort((a,b)=>(a[1].y-b[1].y)||(a[1].x-b[1].x)||String(a[0]).localeCompare(String(b[0])));
267
+ rows.forEach((row,index)=>{if(Number(row[2].finalOrder)!==index)mismatches++});
268
+ }
269
+ return mismatches;
270
+ }
271
+
272
+ const layoutV2MeasureBase=execweaveGeometry.measure.bind(execweaveGeometry);
273
+ execweaveGeometry.measure=function(nodes,edges){
274
+ const metrics=layoutV2MeasureBase(nodes,edges);
275
+ if(!nodes.length)return{...metrics,CROSSINGS_PER_EDGE:0,CROSSING_SPAN_RATE:0,NONINCIDENT_EDGE_CROSSINGS:0,CROSSING_SPAN_PAIRS:0,NODE_DENSITY:0,ASPECT_ERROR:0,P95_EDGE_STRETCH:0,HUB_PORT_INVERSION_RATE:0,FINAL_ORDER_AUTHORITY_MISMATCHES:0};
276
+ const left=Math.min(...nodes.map(n=>n.x)),right=Math.max(...nodes.map(n=>n.x+n.w));
277
+ const top=Math.min(...nodes.map(n=>n.y)),bottom=Math.max(...nodes.map(n=>n.y+n.h));
278
+ const width=Math.max(1,right-left),height=Math.max(1,bottom-top);
279
+ const nodeArea=nodes.reduce((sum,n)=>sum+Math.max(0,n.w*n.h),0);
280
+ const density=nodeArea/(width*height);
281
+ const targetAspect=execweaveLayoutV2ViewportAspect();
282
+ const aspectError=Math.abs(Math.log((width/height)/targetAspect));
283
+ const routes=edges.map(edge=>{
284
+ const points=execweaveGeometry.sample(edge.d);
285
+ return{edge,points,left:Math.min(...points.map(p=>p.x)),right:Math.max(...points.map(p=>p.x)),
286
+ top:Math.min(...points.map(p=>p.y)),bottom:Math.max(...points.map(p=>p.y))};
287
+ });
288
+ let spanPairs=0,nonincidentCrossings=0;
289
+ for(let i=0;i<routes.length;i++)for(let j=0;j<i;j++){
290
+ const a=routes[i],b=routes[j],ae=a.edge,be=b.edge;
291
+ if(ae.source===be.source||ae.source===be.target||ae.target===be.source||ae.target===be.target)continue;
292
+ if(a.right<b.left||b.right<a.left||a.bottom<b.top||b.bottom<a.top)continue;
293
+ spanPairs++;
294
+ let hit=false;
295
+ for(let ai=1;ai<a.points.length&&!hit;ai++)for(let bi=1;bi<b.points.length&&!hit;bi++)
296
+ hit=execweaveGeometry.crosses(a.points[ai-1],a.points[ai],b.points[bi-1],b.points[bi]);
297
+ if(hit)nonincidentCrossings++;
298
+ }
299
+ const stretch=routes.map(({points})=>{
300
+ let length=0;
301
+ for(let i=1;i<points.length;i++)length+=Math.hypot(points[i].x-points[i-1].x,points[i].y-points[i-1].y);
302
+ const first=points[0],last=points[points.length-1];
303
+ const lower=Math.max(1,Math.hypot(last.x-first.x,last.y-first.y));
304
+ return length/lower;
305
+ }).sort((a,b)=>a-b);
306
+ return{...metrics,
307
+ CROSSINGS_PER_EDGE:metrics.EDGE_CROSSINGS/Math.max(1,edges.length),
308
+ CROSSING_SPAN_RATE:nonincidentCrossings/Math.max(1,spanPairs),
309
+ NONINCIDENT_EDGE_CROSSINGS:nonincidentCrossings,
310
+ CROSSING_SPAN_PAIRS:spanPairs,
311
+ NODE_DENSITY:density,
312
+ ASPECT_ERROR:aspectError,
313
+ P95_EDGE_STRETCH:stretch[Math.max(0,Math.ceil(stretch.length*.95)-1)]||0,
314
+ HUB_PORT_INVERSION_RATE:execweaveLayoutV2HubInversionRate(),
315
+ FINAL_ORDER_AUTHORITY_MISMATCHES:execweaveLayoutV2OrderMismatches(),
316
+ GRAPH_BBOX_WIDTH:width,GRAPH_BBOX_HEIGHT:height};
317
+ };
318
+
319
+ function execweaveLayoutV2BusRoute(edge){
320
+ if(typeof edgeById==='undefined'||typeof positions==='undefined'||!execweaveTopology?.bundleByEdge)return null;
321
+ if(typeof execweaveIsStopped==='function'&&execweaveIsStopped(edge))return null;
322
+ const bundle=execweaveTopology.bundleByEdge.get(edgeId(edge));
323
+ if(!bundle||bundle.size<2)return null;
324
+ const members=[...edgeById.values()].filter(candidate=>{
325
+ const other=execweaveTopology.bundleByEdge.get(edgeId(candidate));
326
+ return other&&other.size>1&&other.key===bundle.key&&positions.has(candidate.source)&&positions.has(candidate.target);
327
+ }).sort((a,b)=>edgeId(a).localeCompare(edgeId(b)));
328
+ if(members.length<2||new Set(members.map(member=>member.target)).size!==1)return null;
329
+ const topo=execweaveTopology;
330
+ const anchors=members.map(member=>{
331
+ const sp=positions.get(member.source),tp=positions.get(member.target);
332
+ const sw=topo.width?.get(member.source)||execweaveWidthOf(member.source);
333
+ const tw=topo.width?.get(member.target)||execweaveWidthOf(member.target);
334
+ const forward=tp.x+tw/2>=sp.x+sw/2;
335
+ const sx=forward?sp.x+sw:sp.x,tx=forward?tp.x:tp.x+tw;
336
+ const sy=execweavePortY(sp,topo.sourcePort.get(edgeId(member)),member.source);
337
+ const ty=execweavePortY(tp,topo.targetPort.get(edgeId(member)),member.target);
338
+ return{member,forward,sx,sy,tx,ty};
339
+ });
340
+ if(new Set(anchors.map(row=>row.forward)).size!==1)return null;
341
+ const lo=Math.max(...anchors.map(row=>Math.min(row.sx,row.tx)));
342
+ const hi=Math.min(...anchors.map(row=>Math.max(row.sx,row.tx)));
343
+ if(!(hi-lo>=24))return null;
344
+ const groups=new Map();
345
+ for(const candidate of edgeById.values()){
346
+ const group=topo.bundleByEdge.get(edgeId(candidate));
347
+ if(!group||group.size<2||groups.has(group.key)||!positions.has(candidate.target))continue;
348
+ groups.set(group.key,{key:group.key,target:candidate.target,y:positions.get(candidate.target).y});
349
+ }
350
+ const orderedGroups=[...groups.values()].sort((a,b)=>a.y-b.y||a.key.localeCompare(b.key));
351
+ const groupIndex=Math.max(0,orderedGroups.findIndex(group=>group.key===bundle.key));
352
+ const fraction=orderedGroups.length<=1?.55:.36+.32*groupIndex/Math.max(1,orderedGroups.length-1);
353
+ const ideal=lo+(hi-lo)*fraction;
354
+ const boxes=[...positions].filter(([id])=>nodeById.has(id)).map(([id,p])=>({id,x:p.x,y:p.y,w:execweaveWidthOf(id),h:execweaveHeightOf(id)}));
355
+ const candidateXs=[ideal,lo+(hi-lo)*.44,lo+(hi-lo)*.56,
356
+ ...boxes.flatMap(box=>[box.x-6,box.x+box.w+6])]
357
+ .filter(x=>x>=lo&&x<=hi)
358
+ .sort((a,b)=>Math.abs(a-ideal)-Math.abs(b-ideal)||a-b);
359
+ const clear=x=>anchors.every(row=>{
360
+ const ownBoxes=boxes.filter(box=>box.id!==row.member.source&&box.id!==row.member.target);
361
+ const p={x,y:row.sy},q={x,y:row.ty};
362
+ return !ownBoxes.some(box=>execweaveGeometry.throughBox({x:row.sx,y:row.sy},p,box)||
363
+ execweaveGeometry.throughBox(p,q,box)||execweaveGeometry.throughBox(q,{x:row.tx,y:row.ty},box));
364
+ });
365
+ const trunkX=candidateXs.find(clear);
366
+ if(!Number.isFinite(trunkX))return null;
367
+ const row=anchors.find(item=>edgeId(item.member)===edgeId(edge));
368
+ if(!row)return null;
369
+ return{d:`M ${row.sx} ${row.sy} H ${trunkX} V ${row.ty} H ${row.tx}`,
370
+ labelX:(trunkX+row.tx)/2,labelY:row.ty-8,kind:'bundle',
371
+ geometryKind:'shared-resource-bus',bundle};
372
+ }
373
+ window.execweaveLayoutV2BusRoute=execweaveLayoutV2BusRoute;
374
+
375
+ window.__execweaveLayoutV2={
376
+ syncFinalOrder:execweaveLayoutV2SyncFinalOrder,
377
+ finalizeTopology:execweaveLayoutV2FinalizeTopology,
378
+ packingWidth:execweaveLayoutV2PackingWidth,
379
+ hubInversionRate:execweaveLayoutV2HubInversionRate,
380
+ orderMismatches:execweaveLayoutV2OrderMismatches,
381
+ busRoute:execweaveLayoutV2BusRoute,
382
+ mode:()=>window.__execweaveLayoutV2Mode,
383
+ };
384
+ })();
385
+ """.strip()
386
+
387
+
388
+ def _replace_once(html: str, old: str, new: str, error: str) -> str:
389
+ if html.count(old) != 1:
390
+ raise RuntimeError(error)
391
+ return html.replace(old, new, 1)
392
+
393
+
394
+ def inject_layout_v2(html: str) -> str:
395
+ """Install Layout V2 authority, shared-resource routing and quality objectives."""
396
+
397
+ html = _replace_once(
398
+ html, _BAND_GAP_SEAM, "const EXECWEAVE_BAND_GAP=64;", "layout-v2 band-gap seam changed"
399
+ )
400
+ html = _replace_once(
401
+ html, _PACKING_SEAM, _PACKING_REPLACEMENT, "layout-v2 packing seam changed"
402
+ )
403
+ html = _replace_once(
404
+ html, _SYNC_ORDER_SEAM, _SYNC_ORDER_REPLACEMENT, "layout-v2 final-order seam changed"
405
+ )
406
+ html = _replace_once(
407
+ html, _BUS_ROUTE_SEAM, _BUS_ROUTE_REPLACEMENT, "layout-v2 bundle route seam changed"
408
+ )
409
+ html = _replace_once(
410
+ html, _BUILD_TOPOLOGY_SEAM, _BUILD_TOPOLOGY_REPLACEMENT, "layout-v2 topology-finalize seam changed"
411
+ )
412
+ html = _replace_once(
413
+ html, _INPUT_KEY_SEAM, _INPUT_KEY_REPLACEMENT, "layout-v2 cache-key seam changed"
414
+ )
415
+ html = _replace_once(
416
+ html, _BUDGET_SEAM, _BUDGET_REPLACEMENT, "layout-v2 optimization budget seam changed"
417
+ )
418
+ html = _replace_once(
419
+ html, _BETTER_SEAM, _BETTER_REPLACEMENT, "layout-v2 objective seam changed"
420
+ )
421
+ html = _replace_once(
422
+ html, _ROUNDS_SEAM, _ROUNDS_REPLACEMENT, "layout-v2 optimization round seam changed"
423
+ )
424
+ html = _replace_once(
425
+ html, _ARRANGE_SEAM, _ARRANGE_REPLACEMENT, "layout-v2 arrange-mode seam changed"
426
+ )
427
+ if html.count(_STARTUP_SEAM) != 1:
428
+ raise RuntimeError("layout-v2 startup seam changed")
429
+ return html.replace(_STARTUP_SEAM, LAYOUT_V2_SCRIPT + "\n" + _STARTUP_SEAM, 1)
@@ -0,0 +1,25 @@
1
+ from __future__ import annotations
2
+
3
+ _COMPONENT_SEAM = """ const nodes=[...nodeById.values()].filter(node=>topo.spec.has(node.id));
4
+ const edges=[...edgeById.values()].filter(edge=>topo.spec.has(edge.source)&&topo.spec.has(edge.target));
5
+ const componentOf=execweaveComponents(nodes,edges);"""
6
+ _COMPONENT_REPLACEMENT = """ const nodes=[...nodeById.values()].filter(node=>topo.spec.has(node.id));
7
+ const edges=[...edgeById.values()].filter(edge=>topo.spec.has(edge.source)&&topo.spec.has(edge.target));
8
+ // The orphan file summary is connected to the root by a viewer-only,
9
+ // non-causal OBSERVED_FILES bridge solely so the inspector can expose the
10
+ // collapsed evidence. That presentation bridge must not promote genuinely
11
+ // detached evidence into the execution spine for packing.
12
+ const detachedClusterIds=new Set(nodes.filter(node=>{
13
+ const attrs=node&&typeof node.attributes==='object'&&node.attributes?node.attributes:{};
14
+ return node.id==='viewer-cluster:orphan-files'||attrs.reason==='orphan_file_directory_nodes';
15
+ }).map(node=>node.id));
16
+ const layoutEdges=edges.filter(edge=>!detachedClusterIds.has(edge.source)&&!detachedClusterIds.has(edge.target));
17
+ const componentOf=execweaveComponents(nodes,layoutEdges);"""
18
+
19
+
20
+ def inject_layout_v2_detached_cluster_policy(html: str) -> str:
21
+ """Keep presentation-only orphan clusters out of execution-spine packing."""
22
+
23
+ if html.count(_COMPONENT_SEAM) != 1:
24
+ raise RuntimeError("layout-v2 detached-cluster component seam changed")
25
+ return html.replace(_COMPONENT_SEAM, _COMPONENT_REPLACEMENT, 1)