Update history_tree.py
This commit is contained in:
@@ -7,7 +7,6 @@ class HistoryTree:
|
|||||||
self.branches = raw_data.get("branches", {"main": None})
|
self.branches = raw_data.get("branches", {"main": None})
|
||||||
self.head_id = raw_data.get("head_id", None)
|
self.head_id = raw_data.get("head_id", None)
|
||||||
|
|
||||||
# Migration for legacy list-based history
|
|
||||||
if "prompt_history" in raw_data and isinstance(raw_data["prompt_history"], list) and not self.nodes:
|
if "prompt_history" in raw_data and isinstance(raw_data["prompt_history"], list) and not self.nodes:
|
||||||
self._migrate_legacy(raw_data["prompt_history"])
|
self._migrate_legacy(raw_data["prompt_history"])
|
||||||
|
|
||||||
@@ -26,14 +25,12 @@ class HistoryTree:
|
|||||||
def commit(self, data, note="Snapshot"):
|
def commit(self, data, note="Snapshot"):
|
||||||
new_id = str(uuid.uuid4())[:8]
|
new_id = str(uuid.uuid4())[:8]
|
||||||
|
|
||||||
# Logic: Are we at the tip of a branch?
|
|
||||||
active_branch = None
|
active_branch = None
|
||||||
for b_name, tip_id in self.branches.items():
|
for b_name, tip_id in self.branches.items():
|
||||||
if tip_id == self.head_id:
|
if tip_id == self.head_id:
|
||||||
active_branch = b_name
|
active_branch = b_name
|
||||||
break
|
break
|
||||||
|
|
||||||
# If not at a tip, we must FORK a new branch
|
|
||||||
if not active_branch:
|
if not active_branch:
|
||||||
base_name = "branch"
|
base_name = "branch"
|
||||||
count = 1
|
count = 1
|
||||||
@@ -58,34 +55,39 @@ class HistoryTree:
|
|||||||
return {"nodes": self.nodes, "branches": self.branches, "head_id": self.head_id}
|
return {"nodes": self.nodes, "branches": self.branches, "head_id": self.head_id}
|
||||||
|
|
||||||
def generate_horizontal_graph(self):
|
def generate_horizontal_graph(self):
|
||||||
"""Generates a Fusion 360-style Horizontal Graph."""
|
"""Generates a Compact Fusion 360-style Horizontal Graph."""
|
||||||
dot = [
|
dot = [
|
||||||
'digraph History {',
|
'digraph History {',
|
||||||
' rankdir=LR;', # Left-to-Right layout
|
' rankdir=LR;',
|
||||||
' node [shape=rect, style="filled,rounded", fontname="Arial", margin=0.2];',
|
' bgcolor="transparent";',
|
||||||
' edge [color="#888888", arrowsize=0.8];'
|
# COMPACT STYLING
|
||||||
|
' nodesep=0.3;',
|
||||||
|
' ranksep=0.4;',
|
||||||
|
' node [shape=rect, style="filled,rounded", fontname="Arial", fontsize=10, height=0.4, margin="0.1,0.05"];',
|
||||||
|
' edge [color="#888888", arrowsize=0.6, penwidth=1.0];'
|
||||||
]
|
]
|
||||||
|
|
||||||
# Sort by time for linear flow
|
|
||||||
sorted_nodes = sorted(self.nodes.values(), key=lambda x: x["timestamp"])
|
sorted_nodes = sorted(self.nodes.values(), key=lambda x: x["timestamp"])
|
||||||
|
|
||||||
for n in sorted_nodes:
|
for n in sorted_nodes:
|
||||||
nid = n["id"]
|
nid = n["id"]
|
||||||
note = n.get('note', 'Step')
|
# TRUNCATE LABEL to keep box small
|
||||||
label = f"{note}\\nid: {nid}"
|
full_note = n.get('note', 'Step')
|
||||||
|
short_note = (full_note[:15] + '..') if len(full_note) > 15 else full_note
|
||||||
|
|
||||||
|
label = f"{short_note}\\n<{nid[:4]}>"
|
||||||
|
|
||||||
# Styling
|
# Styling
|
||||||
color = "#e0e0e0" # Default Grey
|
color = "#e0e0e0"
|
||||||
penwidth = "1"
|
penwidth = "1"
|
||||||
|
|
||||||
# Active Node (HEAD) - Yellow
|
|
||||||
if nid == self.head_id:
|
if nid == self.head_id:
|
||||||
color = "#ffeba0"
|
color = "#ffeba0" # Active Yellow
|
||||||
penwidth = "3"
|
penwidth = "2"
|
||||||
|
|
||||||
# Branch Tips - Green
|
|
||||||
if nid in self.branches.values():
|
if nid in self.branches.values():
|
||||||
color = "#d0f0c0"
|
# Branch tips get slightly darker border
|
||||||
|
if color == "#e0e0e0": color = "#d0f0c0"
|
||||||
|
|
||||||
dot.append(f' "{nid}" [label="{label}", fillcolor="{color}", penwidth="{penwidth}"];')
|
dot.append(f' "{nid}" [label="{label}", fillcolor="{color}", penwidth="{penwidth}"];')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user