Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 0 additions & 99 deletions reproduce_issue.py

This file was deleted.

9 changes: 9 additions & 0 deletions src/code_trajectory/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def _initialize_components(path: str) -> str:
if state.watcher:
state.watcher.stop()

# Check if this is a new initialization before creating the recorder (which creates the repo)
is_new_initialization = not os.path.exists(shadow_repo_path)

try:
state.recorder = Recorder(target_path)
state.watcher = Watcher(target_path, state.recorder)
Expand All @@ -73,6 +76,12 @@ def _initialize_components(path: str) -> str:

state.watcher.start()
logger.info(f"Initialized components for {target_path}")

if is_new_initialization:
return (
"New project initialized. No history available yet. "
"Do NOT call get_session_summary."
)
return f"Successfully configured to track: {target_path}"
except Exception as e:
logger.error(f"Failed to initialize components: {e}")
Expand Down
18 changes: 18 additions & 0 deletions src/code_trajectory/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ def get_global_trajectory(self, limit: int = 20, since_consolidate: bool = False
commits = list(self.recorder.repo.iter_commits(max_count=limit))

except Exception as e:
# Check for empty repo error (gitpython usually raises ValueError or GitCommandError)
error_msg = str(e)
# More specific checks for empty repository states
if "Reference at 'refs/heads/master' does not exist" in error_msg:
return "No history available"

# Check for GitCommandError that indicates no commits (git log fails)
if hasattr(e, 'stderr') and "does not have any commits yet" in str(e.stderr):
return "No history available"

# Check for BadObject (happens when HEAD is invalid)
if "BadObject" in error_msg and "HEAD" in error_msg:
return "No history available"

logger.error(f"Failed to fetch global trajectory: {e}")
return f"Error fetching global trajectory: {e}"

Expand Down Expand Up @@ -166,6 +180,10 @@ def get_session_summary(self) -> str:

timestamps = [int(ts) for ts in timestamps_output.splitlines()]
except Exception as e:
error_msg = str(e)
if "does not have any commits yet" in error_msg:
return "No history available"

logger.error(f"Failed to fetch commit timestamps: {e}")
return f"Error analyzing session history: {e}"

Expand Down
5 changes: 3 additions & 2 deletions tests/test_server_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def test_explicit_configuration(temp_project_dir):

result = configure_project(temp_project_dir)

assert "Successfully configured" in result
# Check for either success message (existing) or new init message
assert "Successfully configured" in result or "New project initialized" in result
assert state.project_path == temp_project_dir
assert state.recorder is not None
assert state.recorder.project_root == temp_project_dir
Expand Down Expand Up @@ -47,7 +48,7 @@ def test_reconfiguration(temp_project_dir):
# Configure second project
result = configure_project(second_dir)

assert "Successfully configured" in result
assert "Successfully configured" in result or "New project initialized" in result
assert state.project_path == second_dir
assert state.watcher != old_watcher

Expand Down