MCPcopy Create free account
hub / github.com/Ishabdullah/Codey-v2 / create_checkpoint

Function create_checkpoint

core/checkpoint.py:69–130  ·  view source on GitHub ↗

Create a checkpoint before self-modification. Args: reason: Reason for checkpoint (e.g., "Adding new feature") files_modified: List of files that will be modified Returns: Checkpoint ID (timestamp)

(reason: str, files_modified: List[str] = None)

Source from the content-addressed store, hash-verified

67
68
69def create_checkpoint(reason: str, files_modified: List[str] = None) -> str:
70 """
71 Create a checkpoint before self-modification.
72
73 Args:
74 reason: Reason for checkpoint (e.g., "Adding new feature")
75 files_modified: List of files that will be modified
76
77 Returns:
78 Checkpoint ID (timestamp)
79 """
80 checkpoint_id = str(int(time.time()))
81 backup_dir = CHECKPOINT_DIR / checkpoint_id
82 backup_dir.mkdir(parents=True, exist_ok=True)
83
84 info(f"Checkpoint: creating '{checkpoint_id}' - {reason}")
85
86 # Backup core files
87 backed_up = []
88
89 # Backup all Python files in core directories
90 for pattern in CORE_PATTERNS:
91 base_path = CODE_DIR / pattern.split('/')[0]
92 if base_path.exists():
93 for py_file in base_path.rglob("*.py"):
94 try:
95 rel_path = py_file.relative_to(CODE_DIR)
96 dest = backup_dir / rel_path
97 dest.parent.mkdir(parents=True, exist_ok=True)
98 shutil.copy2(py_file, dest)
99 backed_up.append(str(rel_path))
100 except Exception as e:
101 warning(f"Checkpoint: could not backup {py_file}: {e}")
102
103 # Also backup specific important files
104 important_files = [
105 CODE_DIR / "main.py",
106 CODE_DIR / "codey",
107 CODE_DIR / "codey2",
108 ]
109 for f in important_files:
110 if f.exists():
111 try:
112 dest = backup_dir / f.name
113 shutil.copy2(f, dest)
114 backed_up.append(f.name)
115 except Exception as e:
116 warning(f"Checkpoint: could not backup {f}: {e}")
117
118 # Create git commit
119 git_hash = _create_git_commit(reason)
120
121 # Record in database
122 state = get_state_store()
123 state.execute("""
124 INSERT INTO checkpoints (id, created_at, reason, files_modified, git_commit_hash)
125 VALUES (?, ?, ?, ?, ?)
126 """, (checkpoint_id, int(time.time()), reason, json.dumps(files_modified or []), git_hash))

Callers 1

_require_checkpointMethod · 0.90

Calls 8

infoFunction · 0.90
warningFunction · 0.90
get_state_storeFunction · 0.90
successFunction · 0.90
_create_git_commitFunction · 0.85
existsMethod · 0.80
appendMethod · 0.80
executeMethod · 0.80

Tested by

no test coverage detected