MCPcopy Create free account
hub / github.com/bhowiebkr/PyFlowGraph / CodeChangeCommand

Class CodeChangeCommand

src/commands/node/property_changes.py:82–126  ·  view source on GitHub ↗

Command for tracking code changes in nodes.

Source from the content-addressed store, hash-verified

80
81
82class CodeChangeCommand(CommandBase):
83 """Command for tracking code changes in nodes."""
84
85 def __init__(self, node_graph, node, old_code: str, new_code: str):
86 """
87 Initialize code change command.
88
89 Args:
90 node_graph: The NodeGraph instance
91 node: Node whose code is changing
92 old_code: Original code
93 new_code: New code
94 """
95 super().__init__(f"Change code in '{node.title}'")
96 self.node_graph = node_graph
97 self.node = node
98 self.old_code = old_code
99 self.new_code = new_code
100
101 def execute(self) -> bool:
102 """Apply the code change."""
103 try:
104 self.node.set_code(self.new_code)
105 self._mark_executed()
106 return True
107 except Exception as e:
108 print(f"Failed to change code: {e}")
109 return False
110
111 def undo(self) -> bool:
112 """Revert the code change."""
113 try:
114 self.node.set_code(self.old_code)
115 self._mark_undone()
116 return True
117 except Exception as e:
118 print(f"Failed to undo code change: {e}")
119 return False
120
121 def get_memory_usage(self) -> int:
122 """Estimate memory usage for code changes."""
123 base_size = 512
124 old_code_size = len(self.old_code) * 2
125 new_code_size = len(self.new_code) * 2
126 return base_size + old_code_size + new_code_size

Calls

no outgoing calls