execweave 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- execweave/__init__.py +3 -0
- execweave/__main__.py +5 -0
- execweave/_conversation_records_core.py +902 -0
- execweave/_dashboard_shell_base.py +148 -0
- execweave/_http_proxy_base.py +565 -0
- execweave/_http_proxy_bounded.py +560 -0
- execweave/_http_proxy_stage.py +509 -0
- execweave/acceptance_output.py +19 -0
- execweave/agent_bootstrap.py +395 -0
- execweave/agent_topology.py +313 -0
- execweave/agent_trace.py +1162 -0
- execweave/agy_preview_sanitize.py +102 -0
- execweave/analysis.py +427 -0
- execweave/anthropic.py +228 -0
- execweave/anthropic_cli.py +171 -0
- execweave/anthropic_full_fidelity.py +385 -0
- execweave/antigravity_adapter.py +112 -0
- execweave/antigravity_adapter_base.py +479 -0
- execweave/antigravity_full_fidelity.py +656 -0
- execweave/antigravity_full_fidelity_base.py +172 -0
- execweave/antigravity_full_fidelity_collaboration_base.py +451 -0
- execweave/antigravity_hook_cli.py +209 -0
- execweave/antigravity_record.py +96 -0
- execweave/antigravity_subagent_linkage.py +449 -0
- execweave/antigravity_trace_capability.py +39 -0
- execweave/auto_specialized.py +547 -0
- execweave/backends.py +102 -0
- execweave/benchmark.py +80 -0
- execweave/claude_adapter.py +517 -0
- execweave/claude_child_transcript.py +314 -0
- execweave/claude_delegation.py +136 -0
- execweave/claude_full_fidelity.py +396 -0
- execweave/claude_hook_cli.py +209 -0
- execweave/claude_hook_contract.py +943 -0
- execweave/claude_model_observer.py +353 -0
- execweave/claude_record.py +106 -0
- execweave/cli.py +629 -0
- execweave/codex_adapter.py +455 -0
- execweave/codex_conversation.py +621 -0
- execweave/codex_full_fidelity.py +287 -0
- execweave/codex_hook_cli.py +301 -0
- execweave/codex_hook_entry.py +207 -0
- execweave/codex_hook_lifecycle.py +363 -0
- execweave/codex_message_diagnostics.py +322 -0
- execweave/codex_message_transport_diagnostics.py +399 -0
- execweave/codex_record.py +199 -0
- execweave/codex_rollout_structures.py +402 -0
- execweave/codex_rollout_trace.py +56 -0
- execweave/codex_rollout_trace_base.py +1509 -0
- execweave/collector.py +768 -0
- execweave/command.py +157 -0
- execweave/command_privacy.py +20 -0
- execweave/content_evidence.py +101 -0
- execweave/content_integrity.py +289 -0
- execweave/content_store.py +273 -0
- execweave/controlled_checks.py +561 -0
- execweave/conversation_archive.py +338 -0
- execweave/conversation_message_identity.py +264 -0
- execweave/conversation_preview.py +66 -0
- execweave/conversation_preview_antigravity.py +32 -0
- execweave/conversation_preview_claude.py +31 -0
- execweave/conversation_preview_codex.py +107 -0
- execweave/conversation_preview_common.py +180 -0
- execweave/conversation_preview_generic.py +188 -0
- execweave/conversation_preview_lines.py +133 -0
- execweave/conversation_preview_transcript.py +121 -0
- execweave/conversation_records.py +349 -0
- execweave/conversation_records_antigravity.py +370 -0
- execweave/conversation_records_codex.py +83 -0
- execweave/conversation_records_common.py +17 -0
- execweave/conversation_records_ollama.py +39 -0
- execweave/correlation.py +818 -0
- execweave/cursor_adapter.py +349 -0
- execweave/cursor_delegation.py +87 -0
- execweave/cursor_delegation_base.py +220 -0
- execweave/cursor_full_fidelity.py +489 -0
- execweave/cursor_hook_cli.py +195 -0
- execweave/cursor_hook_contract.py +439 -0
- execweave/cursor_lifecycle.py +159 -0
- execweave/cursor_record.py +96 -0
- execweave/dashboard_shell.py +283 -0
- execweave/delivery_status.py +94 -0
- execweave/entry.py +98 -0
- execweave/evidence_availability.py +113 -0
- execweave/evidence_grade.py +166 -0
- execweave/fidelity.py +304 -0
- execweave/filesystem.py +327 -0
- execweave/finalization.py +92 -0
- execweave/focus.py +118 -0
- execweave/framework_adapters/__init__.py +34 -0
- execweave/framework_adapters/autogen.py +398 -0
- execweave/framework_adapters/base.py +580 -0
- execweave/framework_adapters/camel.py +270 -0
- execweave/framework_adapters/camel_channel.py +71 -0
- execweave/framework_adapters/metagpt.py +315 -0
- execweave/framework_adapters/metagpt_ollama_compat.py +54 -0
- execweave/framework_adapters/metagpt_recording.py +342 -0
- execweave/framework_adapters/registry.py +90 -0
- execweave/graph.py +590 -0
- execweave/graph_ops.py +472 -0
- execweave/hook_command.py +32 -0
- execweave/hook_delivery.py +32 -0
- execweave/hook_input.py +16 -0
- execweave/http_proxy.py +187 -0
- execweave/http_proxy_cli.py +84 -0
- execweave/inference_gateway.py +476 -0
- execweave/inference_gateway_cli.py +211 -0
- execweave/inference_gateway_full_fidelity.py +613 -0
- execweave/inference_identity.py +76 -0
- execweave/inference_identity_cli.py +60 -0
- execweave/integrity.py +235 -0
- execweave/integrity_cli.py +55 -0
- execweave/investigation_index.py +445 -0
- execweave/litellm_callback.py +211 -0
- execweave/litellm_callback_cli.py +42 -0
- execweave/live.py +445 -0
- execweave/live_core.py +972 -0
- execweave/live_view.py +109 -0
- execweave/live_view_extra_style.py +11 -0
- execweave/live_view_markup.py +29 -0
- execweave/live_view_process_layout.py +650 -0
- execweave/live_view_readability.py +502 -0
- execweave/live_view_script_a.py +59 -0
- execweave/live_view_script_b.py +97 -0
- execweave/live_view_script_c.py +59 -0
- execweave/live_view_script_d.py +40 -0
- execweave/live_view_style.py +34 -0
- execweave/model_runtime.py +560 -0
- execweave/model_runtime_cli.py +265 -0
- execweave/model_runtime_full_fidelity.py +519 -0
- execweave/observation.py +53 -0
- execweave/observation_demo.py +69 -0
- execweave/openai_agents.py +267 -0
- execweave/openai_agents_sdk.py +453 -0
- execweave/openai_compatible.py +239 -0
- execweave/openai_compatible_cli.py +189 -0
- execweave/openai_compatible_full_fidelity.py +438 -0
- execweave/opencode_adapter.py +325 -0
- execweave/opencode_event_contract.py +734 -0
- execweave/opencode_full_fidelity.py +198 -0
- execweave/opencode_hook_cli.py +119 -0
- execweave/opencode_plugin_cli.py +150 -0
- execweave/opencode_record.py +96 -0
- execweave/opencode_task_linkage.py +225 -0
- execweave/overhead_benchmark.py +440 -0
- execweave/privacy.py +84 -0
- execweave/private_io.py +465 -0
- execweave/provider_capability.py +578 -0
- execweave/provider_lifecycle.py +282 -0
- execweave/provider_record.py +290 -0
- execweave/reader_identity.py +13 -0
- execweave/redacted_archive.py +906 -0
- execweave/risk.py +106 -0
- execweave/rule_pack.py +359 -0
- execweave/rule_pack_cli.py +57 -0
- execweave/run_assessment.py +200 -0
- execweave/runtime_endpoint_availability.py +44 -0
- execweave/scalability_benchmark.py +195 -0
- execweave/schema.py +62 -0
- execweave/scope.py +85 -0
- execweave/semantic.py +453 -0
- execweave/session_summary.py +159 -0
- execweave/sink.py +71 -0
- execweave/strace_backend.py +927 -0
- execweave/stream_assembly.py +363 -0
- execweave/task_artifacts.py +192 -0
- execweave/task_validation.py +317 -0
- execweave/theme.py +40 -0
- execweave/top.py +599 -0
- execweave/top_cli.py +150 -0
- execweave/validate.py +196 -0
- execweave/vendor/dagre.min.js +815 -0
- execweave/view_cli.py +49 -0
- execweave/viewer.py +474 -0
- execweave/viewer_agent_panel.py +630 -0
- execweave/viewer_agent_panel_antigravity.py +31 -0
- execweave/viewer_agent_panel_claude.py +9 -0
- execweave/viewer_agent_panel_codex.py +50 -0
- execweave/viewer_agent_panel_cursor.py +9 -0
- execweave/viewer_agent_panel_default.py +79 -0
- execweave/viewer_agent_panel_ollama.py +20 -0
- execweave/viewer_agent_panel_opencode.py +9 -0
- execweave/viewer_agent_panel_registry.py +20 -0
- execweave/viewer_archive_verifier.py +178 -0
- execweave/viewer_background_files.py +86 -0
- execweave/viewer_content_browser.py +307 -0
- execweave/viewer_content_health.py +208 -0
- execweave/viewer_content_inspector.py +309 -0
- execweave/viewer_controlled_checks.py +258 -0
- execweave/viewer_conversation_sync.py +115 -0
- execweave/viewer_dashboard_clean.py +405 -0
- execweave/viewer_dashboard_focus.py +127 -0
- execweave/viewer_dashboard_hardening.py +264 -0
- execweave/viewer_dashboard_hardening_v2.py +62 -0
- execweave/viewer_dashboard_projection.py +261 -0
- execweave/viewer_delivery_status.py +155 -0
- execweave/viewer_edge_decross.py +117 -0
- execweave/viewer_execution_flow.py +611 -0
- execweave/viewer_execution_flow_provider_normalization.py +107 -0
- execweave/viewer_execution_flow_safety.py +349 -0
- execweave/viewer_external_endpoints.py +307 -0
- execweave/viewer_flow_canvas.py +1140 -0
- execweave/viewer_flow_layout.py +922 -0
- execweave/viewer_fold_state.py +31 -0
- execweave/viewer_framework_flow.py +68 -0
- execweave/viewer_framework_model_output.py +133 -0
- execweave/viewer_gif.py +278 -0
- execweave/viewer_history_browser.py +225 -0
- execweave/viewer_investigation.py +268 -0
- execweave/viewer_layout_geometry.py +192 -0
- execweave/viewer_layout_v2.py +429 -0
- execweave/viewer_layout_v2_detached.py +25 -0
- execweave/viewer_limits.py +93 -0
- execweave/viewer_live_layout.py +61 -0
- execweave/viewer_message_handoffs.py +114 -0
- execweave/viewer_projection.py +488 -0
- execweave/viewer_projection_base.py +522 -0
- execweave/viewer_projection_bridges.py +214 -0
- execweave/viewer_recorded_sources.py +146 -0
- execweave/viewer_run_assessment.py +274 -0
- execweave/viewer_run_guide.py +175 -0
- execweave/viewer_runtime_evidence.py +258 -0
- execweave/viewer_semantic_projection.py +641 -0
- execweave/viewer_session_flow.py +491 -0
- execweave/viewer_structure_share.py +132 -0
- execweave/viewer_task_validation.py +241 -0
- execweave/viewer_tool_mirror_identity.py +75 -0
- execweave/viewer_workflow_mode.py +127 -0
- execweave/workflow.py +183 -0
- execweave-1.0.0.dist-info/METADATA +462 -0
- execweave-1.0.0.dist-info/RECORD +234 -0
- execweave-1.0.0.dist-info/WHEEL +4 -0
- execweave-1.0.0.dist-info/entry_points.txt +30 -0
- execweave-1.0.0.dist-info/licenses/LICENSE +16 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
# Antigravity-only child rounds. Tasks come from invoke/send_message projection
|
|
4
|
+
# (kind=task / subagent_task / assignment), not Codex user_message.
|
|
5
|
+
# Child-addressed kind==='user_message' is not an opener; duplicate assignment
|
|
6
|
+
# copies from the parent transcript stay kind=task.
|
|
7
|
+
|
|
8
|
+
ANTIGRAVITY_CHILD_ROUNDS_JS = r"""
|
|
9
|
+
function execweaveAntigravityChildRounds(messages,path){
|
|
10
|
+
const parent=path.includes('/')?(path.slice(0,path.lastIndexOf('/'))||'/root'):'/root';
|
|
11
|
+
const isTask=message=>{
|
|
12
|
+
const sender=String(message?.sender||'');
|
|
13
|
+
const kind=String(message?.kind||'');
|
|
14
|
+
const phase=String(message?.phase||'');
|
|
15
|
+
const role=String(message?.content_role||'');
|
|
16
|
+
return isObserved(message)&&!isInjected(message)&&String(message?.recipient||'')===path&&sender!==path&&(!sender||sender==='user'||sender===parent||sender.startsWith('antigravity:'))&&(role==='antigravity_addressed_task'||kind==='subagent_task'||kind==='send_message'||(/task|assign/i.test(kind)&&kind!=='user_message')||phase==='assignment');
|
|
17
|
+
};
|
|
18
|
+
const openers=messages.filter(isTask);
|
|
19
|
+
return windows(messages,openers).map(window=>{
|
|
20
|
+
const inside=window.messages;
|
|
21
|
+
const thoughts=inside.filter(message=>isObserved(message)&&!isInjected(message)&&own(message,path)&&(/reason|think|commentary/i.test(`${message?.kind||''} ${message?.phase||''}`))&&String(message?.phase||'')!=='planner_response');
|
|
22
|
+
let responses=inside.filter(message=>isObserved(message)&&!isInjected(message)&&own(message,path)&&(String(message?.phase||'')==='planner_response'||String(message?.phase||'')==='final_answer'||/subagent_final_response|final[_ -]?response/i.test(String(message?.kind||''))));
|
|
23
|
+
if(!responses.length)responses=inside.filter(message=>isObserved(message)&&!isInjected(message)&&own(message,path)&&!thoughts.includes(message)&&String(message?.recipient||'')!==path&&!/task|assign|send_message/i.test(String(message?.kind||'')));
|
|
24
|
+
return{
|
|
25
|
+
key:messageKey(window.opener),
|
|
26
|
+
start:stampOf(window.opener),
|
|
27
|
+
cards:[['Task',displayText(window.opener)],['Thinking',uniqueTexts(thoughts).join('\n\n')],['Response',displayText(responses.at(-1))]],
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
""".strip()
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from .viewer_agent_panel_default import DEFAULT_CHILD_ROUNDS_JS
|
|
4
|
+
|
|
5
|
+
CLAUDE_CHILD_ROUNDS_JS = r"""
|
|
6
|
+
function execweaveClaudeChildRounds(messages,path){return execweaveDefaultChildRounds(messages,path)}
|
|
7
|
+
""".strip()
|
|
8
|
+
|
|
9
|
+
assert DEFAULT_CHILD_ROUNDS_JS
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
# Codex-only child Task/Thinking/Response. Do not copy this into default or other
|
|
4
|
+
# providers. Assignments are often kind=user_message from parent path to child path.
|
|
5
|
+
# A first spawn often emits task (assignment) and new_task for the same job; that
|
|
6
|
+
# pair is one round. A later new_task after a child response starts another round.
|
|
7
|
+
|
|
8
|
+
CODEX_CHILD_ROUNDS_JS = r"""
|
|
9
|
+
function execweaveCodexChildRounds(messages,path){
|
|
10
|
+
const parent=path.includes('/')?(path.slice(0,path.lastIndexOf('/'))||'/root'):'/root';
|
|
11
|
+
const childMessages=messages.filter(message=>{
|
|
12
|
+
const sender=String(message?.sender||'');
|
|
13
|
+
const recipient=String(message?.recipient||'');
|
|
14
|
+
return !(sender==='user'&&recipient==='/root');
|
|
15
|
+
});
|
|
16
|
+
const isTaskCandidate=message=>{
|
|
17
|
+
const sender=String(message?.sender||'');
|
|
18
|
+
const kind=String(message?.kind||'');
|
|
19
|
+
const phase=String(message?.phase||'');
|
|
20
|
+
const recipient=String(message?.recipient||'');
|
|
21
|
+
if(sender==='user'&&recipient==='/root')return false;
|
|
22
|
+
return isObserved(message)&&!isInjected(message)&&recipient===path&&sender!==path&&(!sender||sender==='user'||sender===parent)&&(kind==='user_message'||kind==='new_task'||/task|assign/i.test(kind)||phase==='assignment');
|
|
23
|
+
};
|
|
24
|
+
const isChildResponse=message=>isObserved(message)&&!isInjected(message)&&own(message,path)&&(String(message?.phase||'')==='final_answer'||/subagent_final_response|final[_ -]?response/i.test(String(message?.kind||'')));
|
|
25
|
+
const isTask=(message,index,list)=>{
|
|
26
|
+
if(!isTaskCandidate(message))return false;
|
|
27
|
+
if(String(message?.kind||'')!=='new_task')return true;
|
|
28
|
+
for(let cursor=index-1;cursor>=0;cursor--){
|
|
29
|
+
const previous=list[cursor];
|
|
30
|
+
if(isChildResponse(previous))return true;
|
|
31
|
+
if(isTaskCandidate(previous))return false;
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
};
|
|
35
|
+
const openers=childMessages.filter(isTask);
|
|
36
|
+
return windows(childMessages,openers).map(window=>{
|
|
37
|
+
const inside=window.messages;
|
|
38
|
+
const thoughts=inside.filter(message=>isObserved(message)&&!isInjected(message)&&own(message,path)&&(/reason|think|commentary/i.test(`${message?.kind||''} ${message?.phase||''}`)));
|
|
39
|
+
let responses=inside.filter(message=>isChildResponse(message));
|
|
40
|
+
if(!responses.length)responses=inside.filter(message=>isObserved(message)&&!isInjected(message)&&own(message,path)&&!thoughts.includes(message)&&String(message?.recipient||'')!==path&&!/task|assign|user_message|new_task/i.test(String(message?.kind||'')));
|
|
41
|
+
const taskText=displayText(window.opener);
|
|
42
|
+
return{
|
|
43
|
+
key:messageKey(window.opener),
|
|
44
|
+
start:stampOf(window.opener),
|
|
45
|
+
label:taskText?summarise(taskText):'Task',
|
|
46
|
+
cards:[['Task',taskText],['Thinking',uniqueTexts(thoughts).join('\n\n')],['Response',displayText(responses.at(-1))]],
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
""".strip()
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from .viewer_agent_panel_default import DEFAULT_CHILD_ROUNDS_JS
|
|
4
|
+
|
|
5
|
+
CURSOR_CHILD_ROUNDS_JS = r"""
|
|
6
|
+
function execweaveCursorChildRounds(messages,path){return execweaveDefaultChildRounds(messages,path)}
|
|
7
|
+
""".strip()
|
|
8
|
+
|
|
9
|
+
assert DEFAULT_CHILD_ROUNDS_JS
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
# Shared child Task/Thinking/Response selection. Framework terminal notes are
|
|
4
|
+
# additive; provider modules continue to share the existing assignment rules.
|
|
5
|
+
|
|
6
|
+
DEFAULT_CHILD_ROUNDS_JS = r"""
|
|
7
|
+
function execweaveFrameworkTerminalCards(cards,inside,path,response){
|
|
8
|
+
// Interpret the recorded text, not framework completion or task correctness.
|
|
9
|
+
// Restrict the additive excerpt to one exact framework source; do not reuse
|
|
10
|
+
// the inspector's legacy name/path fallback as ownership evidence.
|
|
11
|
+
const node=typeof selectedNode==='undefined'?null:selectedNode;
|
|
12
|
+
if(node?.type!=='agent'||attrs(node).conversation_scope!=='framework_agent'||
|
|
13
|
+
!['autogen','camel','metagpt'].includes(String(attrs(node).framework||attrs(node).provider||'').toLowerCase()))return cards;
|
|
14
|
+
const raw=typeof rawGraph==='function'?rawGraph():{};
|
|
15
|
+
if((Array.isArray(raw.nodes)?raw.nodes:[]).filter(n=>n?.id===node.id).length!==1)return cards;
|
|
16
|
+
const exact=(Array.isArray(entries)?entries:[]).filter(e=>e?.source_id===node.id&&e.conversation_preview);
|
|
17
|
+
if(!exact.length||exact.some(e=>e.conversation_preview.agent_path!==path))return cards;
|
|
18
|
+
const nativeIds=new Set(exact.map(e=>e.conversation_preview.provider_native_id).filter(Boolean));
|
|
19
|
+
if(nativeIds.size>1)return cards;
|
|
20
|
+
const kinds=new Set(['agent_message','agent_result','subagent_final_response']);
|
|
21
|
+
// Reuse the inspector's ownership predicate only after requiring an explicit
|
|
22
|
+
// string sender. Its legacy missing-sender fallback is not annotation evidence.
|
|
23
|
+
const hasExactSender=m=>typeof m?.sender==='string'&&m.sender.length>0&&own(m,path);
|
|
24
|
+
const outgoing=m=>hasExactSender(m)&&m.recipient!==path&&kinds.has(m.kind)&&
|
|
25
|
+
!['request','received','assignment','candidate'].includes(m.phase)&&
|
|
26
|
+
!isEncrypted(m)&&!isInjected(m)&&isObserved(m);
|
|
27
|
+
const marker=m=>m?.text_truncated!==true&&['TERMINATE','<CAMEL_TASK_DONE>'].includes(messageText(m));
|
|
28
|
+
// The selected Response may be a normalized model response rather than a
|
|
29
|
+
// routed message (the default SDK shape in the original CAMEL/AutoGen runs).
|
|
30
|
+
// Annotating its displayed text does not establish that it was sent. Keep
|
|
31
|
+
// outgoing() unchanged for the earlier-message excerpt below.
|
|
32
|
+
const modelResponseText=response?.kind==='assistant_message'&&response.phase==='response'&&
|
|
33
|
+
hasExactSender(response)&&(response.recipient==null||response.recipient==='')&&
|
|
34
|
+
!isEncrypted(response)&&!isInjected(response)&&isObserved(response);
|
|
35
|
+
if((!outgoing(response)&&!modelResponseText)||!marker(response))return cards;
|
|
36
|
+
const at=inside.indexOf(response);if(at<0)return cards;
|
|
37
|
+
// Generic assistant records can be replayed model-request context. Without
|
|
38
|
+
// per-record provenance they are not substituted for an outgoing message.
|
|
39
|
+
const earlier=inside.slice(0,at).filter(m=>outgoing(m)&&
|
|
40
|
+
!['TERMINATE','<CAMEL_TASK_DONE>'].includes(messageText(m))).at(-1);
|
|
41
|
+
const extra=[];
|
|
42
|
+
if(earlier)extra.push(['Earlier observed message',displayText(earlier)]);
|
|
43
|
+
extra.push(['Response interpretation',
|
|
44
|
+
'Termination-marker text match only; not a verified task result. The reported response is preserved below. '+
|
|
45
|
+
(earlier?'The earlier outgoing-message preview is not a replacement final answer. ':'No earlier eligible outgoing message is present in this displayed window. ')+
|
|
46
|
+
'Use Browse observed history for timing, other records and preview limits.']);
|
|
47
|
+
const responseIndex=cards.findIndex(c=>c[0]==='Response');
|
|
48
|
+
return responseIndex<0?cards:[...cards.slice(0,responseIndex),...extra,...cards.slice(responseIndex)];
|
|
49
|
+
}
|
|
50
|
+
function execweaveDefaultChildRounds(messages,path){
|
|
51
|
+
const parent=path.includes('/')?(path.slice(0,path.lastIndexOf('/'))||'/root'):'/root';
|
|
52
|
+
const isTask=message=>{const sender=String(message?.sender||'');return isObserved(message)&&!isInjected(message)&&String(message?.recipient||'')===path&&sender!==path&&(/task|assign/i.test(String(message?.kind||''))||String(message?.phase||'')==='assignment')&&(!sender||sender==='user'||sender===parent)};
|
|
53
|
+
// One spawn is recorded twice — in the parent's rollout and in the child's own — and
|
|
54
|
+
// the provider may add its own framing beside it. Those are one assignment, not
|
|
55
|
+
// several rounds, so openers are grouped by the root round they belong to.
|
|
56
|
+
const runs=runRounds();
|
|
57
|
+
const groups=[];
|
|
58
|
+
for(const opener of messages.filter(isTask)){
|
|
59
|
+
const owner=roundOf(stampOf(opener),runs);
|
|
60
|
+
const key=owner?String(owner.start||''):'';
|
|
61
|
+
const last=groups[groups.length-1];
|
|
62
|
+
if(last&&last.key===key)last.openers.push(opener);
|
|
63
|
+
else groups.push({key,openers:[opener]});
|
|
64
|
+
}
|
|
65
|
+
const openers=groups.map(group=>group.openers[0]);
|
|
66
|
+
return windows(messages,openers).map((window,index)=>{
|
|
67
|
+
const inside=window.messages;
|
|
68
|
+
const spoken=groups[index]?.openers.find(opener=>!!messageText(opener));
|
|
69
|
+
const thoughts=inside.filter(message=>isObserved(message)&&!isInjected(message)&&own(message,path)&&(/reason|think|commentary/i.test(`${message?.kind||''} ${message?.phase||''}`)));
|
|
70
|
+
let responses=inside.filter(message=>isObserved(message)&&!isInjected(message)&&own(message,path)&&(String(message?.phase||'')==='final_answer'||/final[_ -]?response|agent_result|result/i.test(String(message?.kind||''))));
|
|
71
|
+
if(!responses.length)responses=inside.filter(message=>isObserved(message)&&!isInjected(message)&&own(message,path)&&!thoughts.includes(message)&&String(message?.recipient||'')!==path&&!/task|assign/i.test(String(message?.kind||'')));
|
|
72
|
+
return{
|
|
73
|
+
key:messageKey(window.opener),
|
|
74
|
+
start:stampOf(window.opener),
|
|
75
|
+
cards:execweaveFrameworkTerminalCards([['Task',displayText(spoken||window.opener)],['Thinking',uniqueTexts(thoughts).join('\n\n')],['Response',displayText(responses.at(-1))]],inside,path,responses.at(-1)),
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
""".strip()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
# Ollama has no observed subagent Task contract. Records already reduce a
|
|
4
|
+
# cumulative request to the current user + assistant turn. The panel must not
|
|
5
|
+
# invent Task/Thinking folds.
|
|
6
|
+
|
|
7
|
+
OLLAMA_CHILD_ROUNDS_JS = r"""
|
|
8
|
+
function execweaveOllamaChildRounds(messages,path){
|
|
9
|
+
const prompts=messages.filter(message=>isObserved(message)&&!isInjected(message)&&(String(message?.kind||'')==='user_message'||String(message?.sender||'')==='user')&&(!message?.recipient||String(message.recipient)===path));
|
|
10
|
+
return windows(messages,prompts).map(window=>{
|
|
11
|
+
const inside=window.messages;
|
|
12
|
+
const finals=inside.filter(message=>isObserved(message)&&!isInjected(message)&&own(message,path)&&(String(message?.content_role||'')==='ollama_response_surface'||String(message?.kind||'').startsWith('assistant')));
|
|
13
|
+
return{
|
|
14
|
+
key:messageKey(window.opener),
|
|
15
|
+
start:stampOf(window.opener),
|
|
16
|
+
cards:[['Prompt',displayText(window.opener)],['Final response',displayText(finals.at(-1))]],
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
""".strip()
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from .viewer_agent_panel_default import DEFAULT_CHILD_ROUNDS_JS
|
|
4
|
+
|
|
5
|
+
OPENCODE_CHILD_ROUNDS_JS = r"""
|
|
6
|
+
function execweaveOpencodeChildRounds(messages,path){return execweaveDefaultChildRounds(messages,path)}
|
|
7
|
+
""".strip()
|
|
8
|
+
|
|
9
|
+
assert DEFAULT_CHILD_ROUNDS_JS
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
# Phase 1 isolation map. Each provider panel currently forwards to default.
|
|
4
|
+
|
|
5
|
+
PANEL_PROVIDERS = (
|
|
6
|
+
"codex",
|
|
7
|
+
"claude",
|
|
8
|
+
"antigravity",
|
|
9
|
+
"cursor",
|
|
10
|
+
"opencode",
|
|
11
|
+
"ollama",
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
SHARED_LAYOUT_MODULES = (
|
|
15
|
+
"viewer_projection",
|
|
16
|
+
"viewer_projection_base",
|
|
17
|
+
"live_view_readability",
|
|
18
|
+
"live_view_process_layout",
|
|
19
|
+
"viewer_external_endpoints",
|
|
20
|
+
)
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"""User-selected offline archive verification; no fetch, execution, or path discovery."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
ARCHIVE_VERIFIER_JS = r"""
|
|
5
|
+
(()=>{
|
|
6
|
+
'use strict';
|
|
7
|
+
if(globalThis.__execweaveArchiveVerifier)return;
|
|
8
|
+
const PRIMARY=['graph.json','conversations.json','viewer.html'];
|
|
9
|
+
const LINEAGE='lineage.json',DERIVATIVE='execweave.redacted-archive.v1',LINEAGE_FORMAT='execweave.redacted-lineage.v1';
|
|
10
|
+
const PATH=/^content\/sha256\/([0-9a-f]{64})\.(?:txt|json|bin)$/;
|
|
11
|
+
const HASH=/^[0-9a-f]{64}$/;
|
|
12
|
+
const DEFAULTS={fileBytes:64*1024*1024,totalBytes:256*1024*1024,manifestBytes:16*1024*1024,files:100000,references:100000,jsonTokens:2000000};
|
|
13
|
+
const object=v=>v!==null&&typeof v==='object'&&!Array.isArray(v);
|
|
14
|
+
const integer=v=>Number.isSafeInteger(v)&&v>=0;
|
|
15
|
+
function fail(code,location=''){throw Object.assign(new Error(code),{code,location})}
|
|
16
|
+
function check(signal){if(signal?.aborted)fail('cancelled')}
|
|
17
|
+
function abortable(promise,signal){
|
|
18
|
+
if(!signal)return promise;check(signal);
|
|
19
|
+
return new Promise((resolve,reject)=>{
|
|
20
|
+
const abort=()=>reject(Object.assign(new Error('cancelled'),{code:'cancelled'}));
|
|
21
|
+
signal.addEventListener('abort',abort,{once:true});
|
|
22
|
+
Promise.resolve(promise).then(value=>{signal.removeEventListener('abort',abort);resolve(value)},
|
|
23
|
+
error=>{signal.removeEventListener('abort',abort);reject(error)});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function strictJSON(text,maxTokens=DEFAULTS.jsonTokens){
|
|
27
|
+
// JSON.parse accepts duplicate keys. Detect decoded-key collisions first, so
|
|
28
|
+
// a receipt/index cannot mean something different to the Python verifier.
|
|
29
|
+
let pos=0,tokens=0;
|
|
30
|
+
const number=/-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/y;
|
|
31
|
+
const space=()=>{while(pos<text.length&&' \t\r\n'.includes(text[pos]))pos++};
|
|
32
|
+
function string(key=false){
|
|
33
|
+
const start=pos;if(text[pos++]!=='"')fail('invalid_json');
|
|
34
|
+
while(pos<text.length){const c=text[pos++];if(c==='"')return key?JSON.parse(text.slice(start,pos)):null;if(c==='\\')pos++}
|
|
35
|
+
fail('invalid_json');
|
|
36
|
+
}
|
|
37
|
+
function value(depth){
|
|
38
|
+
if(depth>128||++tokens>maxTokens)fail('verification_limit');space();
|
|
39
|
+
const c=text[pos];
|
|
40
|
+
if(c==='"'){string();return}
|
|
41
|
+
if(c==='{'||c==='['){
|
|
42
|
+
pos++;space();const end=c==='{'?'}':']',keys=new Set();
|
|
43
|
+
if(text[pos]===end){pos++;return}
|
|
44
|
+
while(true){
|
|
45
|
+
space();
|
|
46
|
+
if(c==='{'){const key=string(true);if(keys.has(key))fail('duplicate_json_key');keys.add(key);space();if(text[pos++]!==':')fail('invalid_json')}
|
|
47
|
+
value(depth+1);space();const delimiter=text[pos++];if(delimiter===end)return;if(delimiter!==',')fail('invalid_json');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
for(const literal of ['true','false','null'])if(text.startsWith(literal,pos)){pos+=literal.length;return}
|
|
51
|
+
number.lastIndex=pos;const match=number.exec(text);if(!match)fail('invalid_json');pos=number.lastIndex;
|
|
52
|
+
}
|
|
53
|
+
try{value(0);space();if(pos!==text.length)fail('invalid_json');return JSON.parse(text)}
|
|
54
|
+
catch(error){if(error.code)throw error;fail('invalid_json')}
|
|
55
|
+
}
|
|
56
|
+
function filesFromSelection(selection){
|
|
57
|
+
const files=new Map(),roots=new Set();let inspected=0;
|
|
58
|
+
for(const file of selection){
|
|
59
|
+
if(++inspected>DEFAULTS.files)fail('verification_limit');
|
|
60
|
+
const relative=file.webkitRelativePath;
|
|
61
|
+
if(typeof relative!=='string'||!relative.includes('/'))fail('invalid_folder');
|
|
62
|
+
const parts=relative.split('/');roots.add(parts.shift());
|
|
63
|
+
if(roots.size!==1||parts.some(p=>!p||p==='.'||p==='..'))fail('invalid_folder');
|
|
64
|
+
const path=parts.join('/');
|
|
65
|
+
if(path!=='finalization.json'&&path!==LINEAGE&&!PRIMARY.includes(path)&&!PATH.test(path))continue;
|
|
66
|
+
if(files.has(path))fail('duplicate_file',path);files.set(path,file);
|
|
67
|
+
}
|
|
68
|
+
return files;
|
|
69
|
+
}
|
|
70
|
+
function fingerprint(value){
|
|
71
|
+
return object(value)&&typeof value.sha256==='string'&&HASH.test(value.sha256)&&integer(value.size_bytes);
|
|
72
|
+
}
|
|
73
|
+
async function verifyArchive(files,scope,{signal,onProgress,limits={}}={}){
|
|
74
|
+
const budget={};for(const [key,value] of Object.entries(DEFAULTS))budget[key]=integer(limits[key])?Math.min(value,limits[key]):value;
|
|
75
|
+
if(!(files instanceof Map)||files.size>budget.files)fail('invalid_folder');
|
|
76
|
+
if(!object(scope)||typeof scope.session_id!=='string'||!scope.session_id)fail('scope_unavailable');
|
|
77
|
+
check(signal);let totalBytes=0,checkedFiles=0;
|
|
78
|
+
async function read(path,expected,asJSON=false,limit=budget.fileBytes){
|
|
79
|
+
check(signal);
|
|
80
|
+
if(path!=='finalization.json'&&path!==LINEAGE&&!PRIMARY.includes(path)&&!PATH.test(path))fail('invalid_reference',path);
|
|
81
|
+
const file=files.get(path);if(!file)fail('missing_file',path);
|
|
82
|
+
if(!integer(file.size)||file.size>limit||totalBytes+file.size>budget.totalBytes)fail('verification_limit',path);
|
|
83
|
+
if(expected&&!fingerprint(expected))fail('invalid_receipt',path);
|
|
84
|
+
if(expected&&file.size!==expected.size_bytes)fail('size_mismatch',path);
|
|
85
|
+
const bytes=await abortable(file.arrayBuffer(),signal);check(signal);
|
|
86
|
+
if(bytes.byteLength!==file.size)fail('changed_during_read',path);
|
|
87
|
+
totalBytes+=bytes.byteLength;
|
|
88
|
+
if(expected){
|
|
89
|
+
if(!globalThis.crypto?.subtle)fail('crypto_unavailable');
|
|
90
|
+
const hash=await abortable(globalThis.crypto.subtle.digest('SHA-256',bytes),signal);check(signal);
|
|
91
|
+
const actual=Array.from(new Uint8Array(hash),x=>x.toString(16).padStart(2,'0')).join('');
|
|
92
|
+
if(actual!==expected.sha256)fail('hash_mismatch',path);
|
|
93
|
+
}
|
|
94
|
+
checkedFiles++;onProgress?.({checked_files:checkedFiles,checked_bytes:totalBytes});
|
|
95
|
+
if(!asJSON)return;
|
|
96
|
+
let text;try{text=new TextDecoder('utf-8',{fatal:true,ignoreBOM:true}).decode(bytes)}catch(_){fail('invalid_json',path)}
|
|
97
|
+
return strictJSON(text,budget.jsonTokens);
|
|
98
|
+
}
|
|
99
|
+
const report=await read('finalization.json',null,true,budget.manifestBytes);
|
|
100
|
+
if(!object(report)||report.schema_version!=='0.2'||!object(report.artifacts))fail('unsupported_receipt');
|
|
101
|
+
for(const name of PRIMARY)if(!fingerprint(report.artifacts[name])||report.artifacts[name].size_bytes===0)fail('invalid_receipt',name);
|
|
102
|
+
const graph=await read('graph.json',report.artifacts['graph.json'],true);
|
|
103
|
+
if(!object(graph)||!Array.isArray(graph.nodes))fail('invalid_index','graph.json');
|
|
104
|
+
if(graph.session_id!==scope.session_id||(graph.source_path||null)!==(scope.source_path||null))fail('run_mismatch');
|
|
105
|
+
const conversations=await read('conversations.json',report.artifacts['conversations.json'],true);
|
|
106
|
+
if(!object(conversations)||!Array.isArray(conversations.entries))fail('invalid_index','conversations.json');
|
|
107
|
+
if(typeof conversations.session_id==='string'&&conversations.session_id&&conversations.session_id!==graph.session_id)fail('run_mismatch');
|
|
108
|
+
await read('viewer.html',report.artifacts['viewer.html']);
|
|
109
|
+
const refs=new Map();let referenceCount=0,records=0;
|
|
110
|
+
function register(ref,location){
|
|
111
|
+
if(++referenceCount>budget.references)fail('verification_limit',location);
|
|
112
|
+
if(!object(ref)||typeof ref.path!=='string')fail('invalid_reference',location);
|
|
113
|
+
const match=PATH.exec(ref.path);
|
|
114
|
+
if(!match||match[0]!==ref.path||ref.sha256!==match[1]||('size_bytes' in ref&&!integer(ref.size_bytes)))fail('invalid_reference',location);
|
|
115
|
+
const previous=refs.get(ref.path);
|
|
116
|
+
if(previous?.size_bytes!==undefined&&ref.size_bytes!==undefined&&previous.size_bytes!==ref.size_bytes)fail('conflicting_reference',location);
|
|
117
|
+
refs.set(ref.path,{sha256:ref.sha256,size_bytes:ref.size_bytes??previous?.size_bytes});
|
|
118
|
+
}
|
|
119
|
+
function nodes(items,location){
|
|
120
|
+
if(!Array.isArray(items))fail('invalid_index',location);
|
|
121
|
+
for(let i=0;i<items.length;i++){
|
|
122
|
+
if(++records>budget.files)fail('verification_limit',location);
|
|
123
|
+
if(!object(items[i]))fail('invalid_index',location);
|
|
124
|
+
if(items[i].type==='observed_content')register(items[i].attributes,location+'/'+i);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
nodes(graph.nodes,'graph.json/nodes');
|
|
128
|
+
if(graph.expansion!==undefined){
|
|
129
|
+
if(!object(graph.expansion)||!object(graph.expansion.clusters??{}))fail('invalid_index','graph.json/expansion');
|
|
130
|
+
for(const cluster of Object.values(graph.expansion.clusters||{})){
|
|
131
|
+
if(++records>budget.files)fail('verification_limit');
|
|
132
|
+
nodes(cluster?.nodes,'graph.json/expansion/nodes');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
for(let i=0;i<conversations.entries.length;i++)register(conversations.entries[i],'conversations.json/entries/'+i);
|
|
136
|
+
for(const [path,ref] of refs){
|
|
137
|
+
const file=files.get(path);if(!file)fail('missing_file',path);
|
|
138
|
+
// Legacy references can omit size, but their hash must still be checked.
|
|
139
|
+
await read(path,{sha256:ref.sha256,size_bytes:ref.size_bytes??file.size});
|
|
140
|
+
}
|
|
141
|
+
let derivation=null;
|
|
142
|
+
if(report.derivation!==undefined){
|
|
143
|
+
const d=report.derivation;
|
|
144
|
+
if(!object(d)||Object.keys(d).sort().join(',')!=='format,lineage,policy_sha256,source_finalization_sha256'||
|
|
145
|
+
d.format!==DERIVATIVE||!fingerprint(d.lineage)||typeof d.policy_sha256!=='string'||!HASH.test(d.policy_sha256)||
|
|
146
|
+
typeof d.source_finalization_sha256!=='string'||!HASH.test(d.source_finalization_sha256))fail('invalid_lineage','finalization.json');
|
|
147
|
+
const lineage=await read(LINEAGE,d.lineage,true,budget.manifestBytes);
|
|
148
|
+
if(!object(lineage)||lineage.format!==LINEAGE_FORMAT||!object(lineage.policy)||lineage.policy.sha256!==d.policy_sha256||
|
|
149
|
+
!object(lineage.source)||!object(lineage.derived)||!Array.isArray(lineage.mappings)||!Array.isArray(lineage.limitations))fail('invalid_lineage',LINEAGE);
|
|
150
|
+
if(lineage.mappings.length>budget.references)fail('verification_limit',LINEAGE);
|
|
151
|
+
if(lineage.derived.session_id!==graph.session_id||!object(lineage.derived.artifacts))fail('invalid_lineage',LINEAGE);
|
|
152
|
+
for(const name of PRIMARY)if(JSON.stringify(lineage.derived.artifacts[name])!==JSON.stringify(report.artifacts[name]))fail('lineage_mismatch',name);
|
|
153
|
+
const marker=graph.redacted_derivative;
|
|
154
|
+
if(!object(marker)||marker.format!==DERIVATIVE||marker.policy_sha256!==d.policy_sha256||marker.lineage_file!==LINEAGE)fail('invalid_lineage','graph.json');
|
|
155
|
+
const mapped=new Set();
|
|
156
|
+
for(const row of lineage.mappings){
|
|
157
|
+
if(!object(row)||!object(row.source)||!object(row.derived)||!Array.isArray(row.actions)||typeof row.changed!=='boolean'||
|
|
158
|
+
typeof row.source.path!=='string'||typeof row.derived.path!=='string'||!fingerprint({sha256:row.source.sha256,size_bytes:row.source.size_bytes})||
|
|
159
|
+
!fingerprint({sha256:row.derived.sha256,size_bytes:row.derived.size_bytes}))fail('invalid_lineage',LINEAGE);
|
|
160
|
+
const dm=PATH.exec(row.derived.path),sm=PATH.exec(row.source.path);
|
|
161
|
+
if(!dm||dm[0]!==row.derived.path||dm[1]!==row.derived.sha256||!sm||sm[0]!==row.source.path||sm[1]!==row.source.sha256)fail('invalid_lineage',LINEAGE);
|
|
162
|
+
const current=refs.get(row.derived.path);
|
|
163
|
+
if(!current||current.sha256!==row.derived.sha256||(current.size_bytes!==undefined&¤t.size_bytes!==row.derived.size_bytes))fail('lineage_mismatch',row.derived.path);
|
|
164
|
+
mapped.add(row.derived.path);
|
|
165
|
+
}
|
|
166
|
+
if(mapped.size!==refs.size||[...refs.keys()].some(path=>!mapped.has(path))||lineage.derived.content_file_count!==mapped.size)fail('lineage_mismatch',LINEAGE);
|
|
167
|
+
derivation={state:'verified_now',format:d.format,policy_sha256:d.policy_sha256,source_finalization_sha256:d.source_finalization_sha256,
|
|
168
|
+
mapping_count:lineage.mappings.length,source_state:'declared_not_rechecked'};
|
|
169
|
+
}
|
|
170
|
+
check(signal);
|
|
171
|
+
return {state:'verified_now',reference_count:referenceCount,verified_file_count:refs.size,
|
|
172
|
+
primary_file_count:3,checked_bytes:totalBytes,checked_at:new Date().toISOString(),derivation,
|
|
173
|
+
recorded_state:['recording','exporting','complete','incomplete','failed'].includes(report.state)?report.state:'unknown',
|
|
174
|
+
scope:'declared_graph_and_conversation_content',session_id:graph.session_id,source_path:graph.source_path||null};
|
|
175
|
+
}
|
|
176
|
+
globalThis.__execweaveArchiveVerifier={verifyArchive,filesFromSelection,strictJSON};
|
|
177
|
+
})();
|
|
178
|
+
""".strip()
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""Collapse known Python cache files without deleting or inventing evidence."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from collections import defaultdict
|
|
5
|
+
from copy import deepcopy
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
CACHE_FILES_NODE_ID = "viewer-cluster:python-cache-files"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def file_path(node: dict[str, Any]) -> str:
|
|
12
|
+
attributes = node.get("attributes")
|
|
13
|
+
attributes = attributes if isinstance(attributes, dict) else {}
|
|
14
|
+
value = attributes.get("path")
|
|
15
|
+
if isinstance(value, str) and value:
|
|
16
|
+
return value
|
|
17
|
+
node_id = str(node.get("id") or "")
|
|
18
|
+
if node_id.startswith(("file:", "directory:")):
|
|
19
|
+
return node_id.split(":", 1)[1]
|
|
20
|
+
return str(node.get("name") or "")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def is_python_cache(node: dict[str, Any]) -> bool:
|
|
24
|
+
if node.get("type") not in {"file", "directory"}:
|
|
25
|
+
return False
|
|
26
|
+
path = file_path(node).replace("\\", "/")
|
|
27
|
+
parts = path.lower().split("/")
|
|
28
|
+
return "__pycache__" in parts or parts[-1].endswith((".pyc", ".pyo"))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def collapse_python_cache_files(
|
|
32
|
+
nodes: list[dict[str, Any]], edges: list[dict[str, Any]], root_id: str | None,
|
|
33
|
+
) -> tuple[list[dict[str, Any]], list[dict[str, Any]], dict[str, Any] | None]:
|
|
34
|
+
members = [node for node in nodes if is_python_cache(node) and isinstance(node.get("id"), str)]
|
|
35
|
+
if len(members) < 3:
|
|
36
|
+
return nodes, edges, None
|
|
37
|
+
ids = {node["id"] for node in members}
|
|
38
|
+
incident = [edge for edge in edges if edge.get("source") in ids or edge.get("target") in ids]
|
|
39
|
+
entries = [{
|
|
40
|
+
"id": n["id"], "type": n.get("type"), "path": file_path(n),
|
|
41
|
+
"first_seen": n.get("first_seen"), "last_seen": n.get("last_seen"),
|
|
42
|
+
"event_count": n.get("event_count", 0),
|
|
43
|
+
} for n in sorted(members, key=lambda item: str(item.get("name") or item["id"]))]
|
|
44
|
+
cluster = {
|
|
45
|
+
"id": CACHE_FILES_NODE_ID, "type": "file_cluster", "name": f"Python cache · {len(members)} files",
|
|
46
|
+
"attributes": {"viewer_only": True, "collapsed": True, "expandable": True,
|
|
47
|
+
"reason": "python_cache_paths", "member_count": len(members), "entries": entries},
|
|
48
|
+
"first_seen": min((n["first_seen"] for n in members if n.get("first_seen")), default=None),
|
|
49
|
+
"last_seen": max((n["last_seen"] for n in members if n.get("last_seen")), default=None),
|
|
50
|
+
"event_count": sum(int(n.get("event_count") or 0) for n in members),
|
|
51
|
+
}
|
|
52
|
+
grouped: dict[tuple[str, str, str], list[dict[str, Any]]] = defaultdict(list)
|
|
53
|
+
out_edges = []
|
|
54
|
+
for edge in edges:
|
|
55
|
+
source, target = edge.get("source"), edge.get("target")
|
|
56
|
+
if source not in ids and target not in ids:
|
|
57
|
+
out_edges.append(deepcopy(edge))
|
|
58
|
+
continue
|
|
59
|
+
source = CACHE_FILES_NODE_ID if source in ids else source
|
|
60
|
+
target = CACHE_FILES_NODE_ID if target in ids else target
|
|
61
|
+
if source != target:
|
|
62
|
+
grouped[(source, str(edge.get("relation") or ""), target)].append(edge)
|
|
63
|
+
for (source, relation, target), observations in grouped.items():
|
|
64
|
+
value = deepcopy(observations[0])
|
|
65
|
+
value.update({
|
|
66
|
+
"id": f"viewer:{source}--{relation}-->{target}", "source": source, "target": target,
|
|
67
|
+
"viewer_only": True, "count": sum(int(e.get("count") or 0) for e in observations),
|
|
68
|
+
"event_ids": list(dict.fromkeys(i for e in observations for i in (e.get("event_ids") or []))),
|
|
69
|
+
"viewer_occurrences": deepcopy(observations),
|
|
70
|
+
"first_seen": min((e["first_seen"] for e in observations if e.get("first_seen")), default=None),
|
|
71
|
+
"last_seen": max((e["last_seen"] for e in observations if e.get("last_seen")), default=None),
|
|
72
|
+
})
|
|
73
|
+
# A display aggregate must not promote a mixed evidence set to certainty.
|
|
74
|
+
for field in ("causal", "inferred", "identity_exact"):
|
|
75
|
+
values = {e.get(field) for e in observations}
|
|
76
|
+
value[field] = next(iter(values)) if len(values) == 1 else None
|
|
77
|
+
out_edges.append(value)
|
|
78
|
+
display_edge = None
|
|
79
|
+
if not grouped and root_id:
|
|
80
|
+
display_edge = f"viewer:{root_id}--OBSERVED_FILES-->{CACHE_FILES_NODE_ID}"
|
|
81
|
+
out_edges.append({"id": display_edge, "source": root_id, "target": CACHE_FILES_NODE_ID,
|
|
82
|
+
"relation": "OBSERVED_FILES", "viewer_only": True,
|
|
83
|
+
"causal": False, "inferred": False, "count": len(members)})
|
|
84
|
+
expansion = {"cluster_node_id": CACHE_FILES_NODE_ID, "cluster_edge_id": display_edge,
|
|
85
|
+
"nodes": deepcopy(members), "edges": deepcopy(incident), "viewer_only": True}
|
|
86
|
+
return [deepcopy(n) for n in nodes if n.get("id") not in ids] + [cluster], out_edges, expansion
|