aline-ai 0.1.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.
- aline_ai-0.1.0.dist-info/METADATA +35 -0
- aline_ai-0.1.0.dist-info/RECORD +23 -0
- aline_ai-0.1.0.dist-info/WHEEL +5 -0
- aline_ai-0.1.0.dist-info/entry_points.txt +5 -0
- aline_ai-0.1.0.dist-info/licenses/LICENSE +21 -0
- aline_ai-0.1.0.dist-info/top_level.txt +1 -0
- realign/__init__.py +3 -0
- realign/claude_detector.py +99 -0
- realign/cli.py +36 -0
- realign/codex_detector.py +131 -0
- realign/commands/__init__.py +1 -0
- realign/commands/auto_commit.py +231 -0
- realign/commands/commit.py +197 -0
- realign/commands/config.py +154 -0
- realign/commands/init.py +308 -0
- realign/commands/search.py +423 -0
- realign/commands/show.py +429 -0
- realign/config.py +155 -0
- realign/hooks.py +914 -0
- realign/logging_config.py +172 -0
- realign/mcp_server.py +441 -0
- realign/mcp_watcher.py +319 -0
- realign/redactor.py +247 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aline-ai
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Shared AI memory; everyone knows everything in teams
|
|
5
|
+
Author: Sharemind
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/human-re/aline
|
|
8
|
+
Project-URL: Repository, https://github.com/human-re/aline
|
|
9
|
+
Project-URL: Documentation, https://github.com/human-re/aline#readme
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/human-re/aline/issues
|
|
11
|
+
Keywords: ai,agent,chat,history,mcp,claude,session-tracking,context-preservation
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: typer>=0.9.0
|
|
23
|
+
Requires-Dist: pyyaml>=6.0
|
|
24
|
+
Requires-Dist: rich>=13.0.0
|
|
25
|
+
Requires-Dist: mcp>=1.0.0
|
|
26
|
+
Requires-Dist: anthropic>=0.18.0
|
|
27
|
+
Requires-Dist: openai>=1.0.0
|
|
28
|
+
Requires-Dist: detect-secrets>=1.4.0
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
33
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: bump-my-version>=0.26.0; extra == "dev"
|
|
35
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
aline_ai-0.1.0.dist-info/licenses/LICENSE,sha256=H8wTqV5IF1oHw_HbBtS1PSDU8G_q81yblEIL_JfV8Vo,1077
|
|
2
|
+
realign/__init__.py,sha256=yt4R6O6rr0ImHHhNF1YOZbJxsINC7-45rDxl0OXK7ig,68
|
|
3
|
+
realign/claude_detector.py,sha256=NLxI0zJWcqNxNha9jAy9AslTMwHKakCc9yPGdkrbiFE,3028
|
|
4
|
+
realign/cli.py,sha256=bkwS329jMDEkrUEihXRN2DDyeTKE6HbAysoDxxskZ8g,941
|
|
5
|
+
realign/codex_detector.py,sha256=RI3JbZgebrhoqpRfTBMfclYCAISN7hZAHVW3bgftJpU,4428
|
|
6
|
+
realign/config.py,sha256=jarinbr0mA6e5DmgY19b_VpMnxk6SOYTwyvB9luq0ww,7207
|
|
7
|
+
realign/hooks.py,sha256=qhAeuln_62OgTq0vboZcUAuP2apOrNn58vSZqKwNmWQ,36456
|
|
8
|
+
realign/logging_config.py,sha256=KvkKktF-bkUu031y9vgUoHpsbnOw7ud25jhpzliNZwA,4929
|
|
9
|
+
realign/mcp_server.py,sha256=NaT1c7dCNfOvmBPkBMpWI63wqmJQ3wQP2MiMqNUmFIQ,15346
|
|
10
|
+
realign/mcp_watcher.py,sha256=AN5skK8qoVkXLCABkAsEcWC7lx2zJi24lwJQSXn2Ixk,13143
|
|
11
|
+
realign/redactor.py,sha256=uZvLKKGrRGJm-qM8S4XJyJK6i0CSSby_wbKiay7VGJw,8148
|
|
12
|
+
realign/commands/__init__.py,sha256=GG6IMw6fUBQAXGJDFJvOOQgv6pkiRSfMh8z3AYXTyRM,31
|
|
13
|
+
realign/commands/auto_commit.py,sha256=_DOw7nt9q3tD_Y3qDL9IFKAUG1hM4qH_xZ-9nyBc2Bc,7451
|
|
14
|
+
realign/commands/commit.py,sha256=_A2znDOLldtlkB4RfAc-otLa0soOYv5SSQgtKq7Qbk4,6580
|
|
15
|
+
realign/commands/config.py,sha256=oarvn6UuGT8svd2h5_8M_ueV5QWOCUOn8SYoa4XYjs8,6500
|
|
16
|
+
realign/commands/init.py,sha256=EpSzh2Dd2EmEQ_wo3vAsg6Uq7_YOlQWIpzIkZa_2y0A,11863
|
|
17
|
+
realign/commands/search.py,sha256=0CZaXll99wtd01MRiZk5NAblxgogc4RUAzMyJunvckE,18044
|
|
18
|
+
realign/commands/show.py,sha256=P1waa94-AKJr9XjagkE40OHMXzE6IwC74DpeDKqwsqw,16693
|
|
19
|
+
aline_ai-0.1.0.dist-info/METADATA,sha256=ZVUw6gLA1LJr34rmE7uVtdylss85X6PgGwBHRU17mGY,1398
|
|
20
|
+
aline_ai-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
21
|
+
aline_ai-0.1.0.dist-info/entry_points.txt,sha256=h-NocHDzSueXfsepHTIdRPNQzhNZQPAztJfldd-mQTE,202
|
|
22
|
+
aline_ai-0.1.0.dist-info/top_level.txt,sha256=yIL3s2xv9nf1GwD5n71Aq_JEIV4AfzCIDNKBzewuRm4,8
|
|
23
|
+
aline_ai-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ReAlign Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
realign
|
realign/__init__.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""Utility functions for detecting and integrating with Claude Code."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def get_claude_project_name(project_path: Path) -> str:
|
|
9
|
+
"""
|
|
10
|
+
Convert a project path to Claude Code's project directory name format.
|
|
11
|
+
|
|
12
|
+
Claude Code transforms project paths by replacing '/' with '-' (excluding root '/').
|
|
13
|
+
For example: /Users/alice/Projects/MyApp -> -Users-alice-Projects-MyApp
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
project_path: The absolute path to the project
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
The transformed project name used by Claude Code
|
|
20
|
+
"""
|
|
21
|
+
# Convert to absolute path and normalize
|
|
22
|
+
abs_path = project_path.resolve()
|
|
23
|
+
|
|
24
|
+
# Convert path to string and replace separators
|
|
25
|
+
# Remove leading '/' and replace all '/' and '_' with '-'
|
|
26
|
+
# Claude Code replaces both slashes and underscores with dashes
|
|
27
|
+
path_str = str(abs_path)
|
|
28
|
+
if path_str.startswith('/'):
|
|
29
|
+
path_str = path_str[1:]
|
|
30
|
+
|
|
31
|
+
return '-' + path_str.replace('/', '-').replace('_', '-')
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def find_claude_sessions_dir(project_path: Path) -> Optional[Path]:
|
|
35
|
+
"""
|
|
36
|
+
Find the Claude Code sessions directory for a given project path.
|
|
37
|
+
|
|
38
|
+
Claude Code stores project sessions in:
|
|
39
|
+
~/.claude/projects/{project_name}/
|
|
40
|
+
|
|
41
|
+
where project_name is the project path with '/' replaced by '-'.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
project_path: The absolute path to the project
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
Path to the Claude sessions directory if it exists, None otherwise
|
|
48
|
+
"""
|
|
49
|
+
# Get Claude base directory
|
|
50
|
+
claude_base = Path.home() / ".claude" / "projects"
|
|
51
|
+
|
|
52
|
+
if not claude_base.exists():
|
|
53
|
+
return None
|
|
54
|
+
|
|
55
|
+
# Get the project name in Claude's format
|
|
56
|
+
project_name = get_claude_project_name(project_path)
|
|
57
|
+
|
|
58
|
+
# Check if the project directory exists
|
|
59
|
+
claude_project_dir = claude_base / project_name
|
|
60
|
+
|
|
61
|
+
if claude_project_dir.exists() and claude_project_dir.is_dir():
|
|
62
|
+
return claude_project_dir
|
|
63
|
+
|
|
64
|
+
return None
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def auto_detect_sessions_path(project_path: Path, fallback_path: Optional[str] = None) -> Path:
|
|
68
|
+
"""
|
|
69
|
+
Auto-detect the best sessions path to use.
|
|
70
|
+
|
|
71
|
+
Priority:
|
|
72
|
+
1. REALIGN_LOCAL_HISTORY_PATH environment variable
|
|
73
|
+
2. Claude Code sessions directory (if exists)
|
|
74
|
+
3. fallback_path parameter (if provided)
|
|
75
|
+
4. Default: ~/.local/share/realign/histories
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
project_path: The absolute path to the project
|
|
79
|
+
fallback_path: Optional fallback path if auto-detection fails
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
Path to use for session history
|
|
83
|
+
"""
|
|
84
|
+
# Check environment variable first (highest priority)
|
|
85
|
+
env_path = os.getenv("REALIGN_LOCAL_HISTORY_PATH")
|
|
86
|
+
if env_path:
|
|
87
|
+
return Path(os.path.expanduser(env_path))
|
|
88
|
+
|
|
89
|
+
# Try to find Claude sessions directory
|
|
90
|
+
claude_dir = find_claude_sessions_dir(project_path)
|
|
91
|
+
if claude_dir:
|
|
92
|
+
return claude_dir
|
|
93
|
+
|
|
94
|
+
# Use fallback if provided
|
|
95
|
+
if fallback_path:
|
|
96
|
+
return Path(os.path.expanduser(fallback_path))
|
|
97
|
+
|
|
98
|
+
# Default path
|
|
99
|
+
return Path.home() / ".local" / "share" / "realign" / "histories"
|
realign/cli.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""ReAlign CLI - Main command-line interface."""
|
|
3
|
+
|
|
4
|
+
import typer
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Optional
|
|
7
|
+
from rich.console import Console
|
|
8
|
+
from rich.syntax import Syntax
|
|
9
|
+
|
|
10
|
+
from .commands import init, search, show, config, commit, auto_commit
|
|
11
|
+
|
|
12
|
+
app = typer.Typer(
|
|
13
|
+
name="realign",
|
|
14
|
+
help="Track and version AI agent chat sessions with git commits",
|
|
15
|
+
add_completion=False,
|
|
16
|
+
)
|
|
17
|
+
console = Console()
|
|
18
|
+
|
|
19
|
+
# Register commands
|
|
20
|
+
app.command(name="init")(init.init_command)
|
|
21
|
+
app.command(name="search")(search.search_command)
|
|
22
|
+
app.command(name="show")(show.show_command)
|
|
23
|
+
app.command(name="config")(config.config_command)
|
|
24
|
+
app.command(name="commit")(commit.commit_command)
|
|
25
|
+
app.command(name="auto-commit")(auto_commit.auto_commit_command)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@app.command()
|
|
29
|
+
def version():
|
|
30
|
+
"""Show ReAlign version."""
|
|
31
|
+
from . import __version__
|
|
32
|
+
console.print(f"ReAlign version {__version__}")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
if __name__ == "__main__":
|
|
36
|
+
app()
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Utility functions for detecting and integrating with Codex."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
from datetime import datetime, timedelta
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Optional, List
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def find_codex_sessions_for_project(
|
|
11
|
+
project_path: Path,
|
|
12
|
+
days_back: int = 7
|
|
13
|
+
) -> List[Path]:
|
|
14
|
+
"""
|
|
15
|
+
Find Codex sessions for a given project path.
|
|
16
|
+
|
|
17
|
+
Codex stores sessions in ~/.codex/sessions/{YYYY}/{MM}/{DD}/
|
|
18
|
+
with all projects mixed together. We need to search by date
|
|
19
|
+
and filter by the 'cwd' field in session metadata.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
project_path: The absolute path to the project
|
|
23
|
+
days_back: Number of days to look back (default: 7)
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
List of session file paths that match the project, sorted by timestamp (newest first)
|
|
27
|
+
"""
|
|
28
|
+
codex_sessions_base = Path.home() / ".codex" / "sessions"
|
|
29
|
+
|
|
30
|
+
if not codex_sessions_base.exists():
|
|
31
|
+
return []
|
|
32
|
+
|
|
33
|
+
# Normalize project path for comparison
|
|
34
|
+
abs_project_path = str(project_path.resolve())
|
|
35
|
+
|
|
36
|
+
matching_sessions = []
|
|
37
|
+
|
|
38
|
+
# Search through recent days
|
|
39
|
+
for days_ago in range(days_back + 1):
|
|
40
|
+
target_date = datetime.now() - timedelta(days=days_ago)
|
|
41
|
+
date_path = codex_sessions_base / str(target_date.year) / f"{target_date.month:02d}" / f"{target_date.day:02d}"
|
|
42
|
+
|
|
43
|
+
if not date_path.exists():
|
|
44
|
+
continue
|
|
45
|
+
|
|
46
|
+
# Check all session files in this date directory
|
|
47
|
+
for session_file in date_path.glob("rollout-*.jsonl"):
|
|
48
|
+
try:
|
|
49
|
+
# Read first line to get session metadata
|
|
50
|
+
with open(session_file, 'r', encoding='utf-8') as f:
|
|
51
|
+
first_line = f.readline()
|
|
52
|
+
if first_line:
|
|
53
|
+
data = json.loads(first_line)
|
|
54
|
+
if data.get('type') == 'session_meta':
|
|
55
|
+
session_cwd = data.get('payload', {}).get('cwd', '')
|
|
56
|
+
# Match the project path
|
|
57
|
+
if session_cwd == abs_project_path:
|
|
58
|
+
matching_sessions.append(session_file)
|
|
59
|
+
except (json.JSONDecodeError, IOError):
|
|
60
|
+
# Skip malformed or unreadable files
|
|
61
|
+
continue
|
|
62
|
+
|
|
63
|
+
# Sort by modification time, newest first
|
|
64
|
+
matching_sessions.sort(key=lambda p: p.stat().st_mtime, reverse=True)
|
|
65
|
+
|
|
66
|
+
return matching_sessions
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def get_latest_codex_session(project_path: Path, days_back: int = 7) -> Optional[Path]:
|
|
70
|
+
"""
|
|
71
|
+
Get the most recent Codex session for a given project.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
project_path: The absolute path to the project
|
|
75
|
+
days_back: Number of days to look back (default: 7)
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
Path to the most recent session file, or None if not found
|
|
79
|
+
"""
|
|
80
|
+
sessions = find_codex_sessions_for_project(project_path, days_back)
|
|
81
|
+
return sessions[0] if sessions else None
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def get_codex_sessions_dir() -> Optional[Path]:
|
|
85
|
+
"""
|
|
86
|
+
Get the Codex sessions base directory if it exists.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
Path to ~/.codex/sessions if it exists, None otherwise
|
|
90
|
+
"""
|
|
91
|
+
codex_sessions = Path.home() / ".codex" / "sessions"
|
|
92
|
+
return codex_sessions if codex_sessions.exists() else None
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def auto_detect_codex_sessions(
|
|
96
|
+
project_path: Path,
|
|
97
|
+
fallback_path: Optional[str] = None,
|
|
98
|
+
days_back: int = 7
|
|
99
|
+
) -> Optional[Path]:
|
|
100
|
+
"""
|
|
101
|
+
Auto-detect the most recent Codex session for a project.
|
|
102
|
+
|
|
103
|
+
Priority:
|
|
104
|
+
1. REALIGN_LOCAL_HISTORY_PATH environment variable (disables auto-detection)
|
|
105
|
+
2. Most recent Codex session matching project path
|
|
106
|
+
3. fallback_path parameter (if provided)
|
|
107
|
+
4. Default: None (let caller decide fallback)
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
project_path: The absolute path to the project
|
|
111
|
+
fallback_path: Optional fallback path if auto-detection fails
|
|
112
|
+
days_back: Number of days to look back for sessions (default: 7)
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
Path to use for session history, or None if not found
|
|
116
|
+
"""
|
|
117
|
+
# Check environment variable first (highest priority, disables auto-detection)
|
|
118
|
+
env_path = os.getenv("REALIGN_LOCAL_HISTORY_PATH")
|
|
119
|
+
if env_path:
|
|
120
|
+
return Path(os.path.expanduser(env_path))
|
|
121
|
+
|
|
122
|
+
# Try to find the latest Codex session for this project
|
|
123
|
+
latest_session = get_latest_codex_session(project_path, days_back)
|
|
124
|
+
if latest_session:
|
|
125
|
+
return latest_session
|
|
126
|
+
|
|
127
|
+
# Use fallback if provided
|
|
128
|
+
if fallback_path:
|
|
129
|
+
return Path(os.path.expanduser(fallback_path))
|
|
130
|
+
|
|
131
|
+
return None
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""ReAlign commands module."""
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"""ReAlign auto-commit command - Automatically commit after each chat round."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import subprocess
|
|
5
|
+
import time
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Optional, Set
|
|
8
|
+
import typer
|
|
9
|
+
from rich.console import Console
|
|
10
|
+
from rich.live import Live
|
|
11
|
+
from rich.panel import Panel
|
|
12
|
+
from rich.text import Text
|
|
13
|
+
|
|
14
|
+
from ..config import ReAlignConfig
|
|
15
|
+
from ..hooks import find_all_active_sessions
|
|
16
|
+
from ..commands.init import init_command
|
|
17
|
+
from ..commands.commit import commit_command as manual_commit
|
|
18
|
+
|
|
19
|
+
console = Console()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def is_realign_initialized() -> bool:
|
|
23
|
+
"""Check if ReAlign is initialized in the current repository."""
|
|
24
|
+
try:
|
|
25
|
+
result = subprocess.run(
|
|
26
|
+
["git", "rev-parse", "--show-toplevel"],
|
|
27
|
+
capture_output=True,
|
|
28
|
+
text=True,
|
|
29
|
+
check=True,
|
|
30
|
+
)
|
|
31
|
+
repo_root = Path(result.stdout.strip())
|
|
32
|
+
|
|
33
|
+
# Check if .realign directory exists
|
|
34
|
+
realign_dir = repo_root / ".realign"
|
|
35
|
+
if not realign_dir.exists():
|
|
36
|
+
return False
|
|
37
|
+
|
|
38
|
+
# Check if hooks are installed
|
|
39
|
+
result = subprocess.run(
|
|
40
|
+
["git", "config", "core.hooksPath"],
|
|
41
|
+
capture_output=True,
|
|
42
|
+
text=True,
|
|
43
|
+
)
|
|
44
|
+
hooks_path = result.stdout.strip()
|
|
45
|
+
|
|
46
|
+
return ".realign/hooks" in hooks_path
|
|
47
|
+
except subprocess.CalledProcessError:
|
|
48
|
+
return False
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def auto_initialize():
|
|
52
|
+
"""Automatically initialize ReAlign if not already initialized."""
|
|
53
|
+
if not is_realign_initialized():
|
|
54
|
+
console.print("[yellow]⚙️ ReAlign not initialized. Initializing...[/yellow]")
|
|
55
|
+
try:
|
|
56
|
+
# Call init command with auto-yes
|
|
57
|
+
result = subprocess.run(
|
|
58
|
+
["realign", "init", "--yes"],
|
|
59
|
+
capture_output=True,
|
|
60
|
+
text=True,
|
|
61
|
+
)
|
|
62
|
+
if result.returncode == 0:
|
|
63
|
+
console.print("[green]✓[/green] ReAlign initialized successfully")
|
|
64
|
+
return True
|
|
65
|
+
else:
|
|
66
|
+
console.print(f"[red]✗[/red] Failed to initialize ReAlign:\n{result.stderr}")
|
|
67
|
+
return False
|
|
68
|
+
except Exception as e:
|
|
69
|
+
console.print(f"[red]✗[/red] Error initializing ReAlign: {e}")
|
|
70
|
+
return False
|
|
71
|
+
return True
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def get_session_mtimes(repo_root: Path) -> dict:
|
|
75
|
+
"""Get modification times for all active session files."""
|
|
76
|
+
config = ReAlignConfig.load()
|
|
77
|
+
session_files = find_all_active_sessions(config, repo_root)
|
|
78
|
+
|
|
79
|
+
mtimes = {}
|
|
80
|
+
for session_file in session_files:
|
|
81
|
+
if session_file.exists():
|
|
82
|
+
mtimes[str(session_file)] = session_file.stat().st_mtime
|
|
83
|
+
|
|
84
|
+
return mtimes
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def generate_commit_message() -> str:
|
|
88
|
+
"""Generate an automatic commit message."""
|
|
89
|
+
from datetime import datetime
|
|
90
|
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
91
|
+
return f"chore: Auto-commit chat session ({timestamp})"
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def auto_commit_once(repo_root: Path, message: Optional[str] = None, silent: bool = False) -> bool:
|
|
95
|
+
"""
|
|
96
|
+
Perform a single auto-commit.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
repo_root: Path to the repository root
|
|
100
|
+
message: Custom commit message (auto-generated if not provided)
|
|
101
|
+
silent: If True, suppress console output (for watcher mode)
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
True if commit was successful, False otherwise
|
|
105
|
+
"""
|
|
106
|
+
commit_message = message or generate_commit_message()
|
|
107
|
+
|
|
108
|
+
try:
|
|
109
|
+
# Stage all changes including sessions
|
|
110
|
+
subprocess.run(
|
|
111
|
+
["git", "add", "-A"],
|
|
112
|
+
cwd=repo_root,
|
|
113
|
+
check=True,
|
|
114
|
+
capture_output=True,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
# Run realign commit
|
|
118
|
+
result = subprocess.run(
|
|
119
|
+
["realign", "commit", "-m", commit_message],
|
|
120
|
+
cwd=repo_root,
|
|
121
|
+
capture_output=True,
|
|
122
|
+
text=True,
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
if result.returncode == 0:
|
|
126
|
+
if not silent:
|
|
127
|
+
console.print(f"[green]✓[/green] Auto-committed: {commit_message}")
|
|
128
|
+
return True
|
|
129
|
+
else:
|
|
130
|
+
# Check if it's just "no changes" error
|
|
131
|
+
if "No changes detected" in result.stdout or "No changes detected" in result.stderr:
|
|
132
|
+
if not silent:
|
|
133
|
+
console.print("[dim]No changes to commit[/dim]")
|
|
134
|
+
return True
|
|
135
|
+
else:
|
|
136
|
+
if not silent:
|
|
137
|
+
console.print(f"[red]✗[/red] Commit failed:\n{result.stderr}")
|
|
138
|
+
return False
|
|
139
|
+
except subprocess.CalledProcessError as e:
|
|
140
|
+
if not silent:
|
|
141
|
+
console.print(f"[red]✗[/red] Error during commit: {e}")
|
|
142
|
+
return False
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def auto_commit_command(
|
|
146
|
+
watch: bool = typer.Option(
|
|
147
|
+
False,
|
|
148
|
+
"--watch",
|
|
149
|
+
"-w",
|
|
150
|
+
help="Watch for changes and auto-commit continuously"
|
|
151
|
+
),
|
|
152
|
+
interval: int = typer.Option(
|
|
153
|
+
5,
|
|
154
|
+
"--interval",
|
|
155
|
+
"-i",
|
|
156
|
+
help="Check interval in seconds (default: 5)"
|
|
157
|
+
),
|
|
158
|
+
message: Optional[str] = typer.Option(
|
|
159
|
+
None,
|
|
160
|
+
"--message",
|
|
161
|
+
"-m",
|
|
162
|
+
help="Custom commit message (auto-generated if not provided)"
|
|
163
|
+
),
|
|
164
|
+
):
|
|
165
|
+
"""
|
|
166
|
+
Automatically commit after each chat round.
|
|
167
|
+
|
|
168
|
+
By default, performs a single commit. Use --watch to continuously monitor
|
|
169
|
+
and commit changes as they happen.
|
|
170
|
+
"""
|
|
171
|
+
# Check if in git repository
|
|
172
|
+
try:
|
|
173
|
+
result = subprocess.run(
|
|
174
|
+
["git", "rev-parse", "--show-toplevel"],
|
|
175
|
+
check=True,
|
|
176
|
+
capture_output=True,
|
|
177
|
+
text=True,
|
|
178
|
+
)
|
|
179
|
+
repo_root = Path(result.stdout.strip())
|
|
180
|
+
except subprocess.CalledProcessError:
|
|
181
|
+
console.print("[red]Error: Not in a git repository[/red]")
|
|
182
|
+
raise typer.Exit(1)
|
|
183
|
+
|
|
184
|
+
# Auto-initialize if needed
|
|
185
|
+
if not auto_initialize():
|
|
186
|
+
console.print("[red]Failed to initialize ReAlign[/red]")
|
|
187
|
+
raise typer.Exit(1)
|
|
188
|
+
|
|
189
|
+
if not watch:
|
|
190
|
+
# Single commit mode
|
|
191
|
+
console.print("[cyan]🔄 Performing auto-commit...[/cyan]")
|
|
192
|
+
success = auto_commit_once(repo_root, message)
|
|
193
|
+
if success:
|
|
194
|
+
console.print("[green]✓[/green] Done")
|
|
195
|
+
else:
|
|
196
|
+
raise typer.Exit(1)
|
|
197
|
+
return
|
|
198
|
+
|
|
199
|
+
# Watch mode
|
|
200
|
+
console.print("[cyan]👁️ Watching for session changes...[/cyan]")
|
|
201
|
+
console.print(f"[dim] Check interval: {interval} seconds[/dim]")
|
|
202
|
+
console.print("[dim] Press Ctrl+C to stop[/dim]\n")
|
|
203
|
+
|
|
204
|
+
# Track last known modification times
|
|
205
|
+
last_mtimes = get_session_mtimes(repo_root)
|
|
206
|
+
commit_count = 0
|
|
207
|
+
|
|
208
|
+
try:
|
|
209
|
+
while True:
|
|
210
|
+
time.sleep(interval)
|
|
211
|
+
|
|
212
|
+
# Check for changes
|
|
213
|
+
current_mtimes = get_session_mtimes(repo_root)
|
|
214
|
+
|
|
215
|
+
# Detect if any session file was modified
|
|
216
|
+
has_changes = False
|
|
217
|
+
for session_path, mtime in current_mtimes.items():
|
|
218
|
+
if session_path not in last_mtimes or last_mtimes[session_path] < mtime:
|
|
219
|
+
has_changes = True
|
|
220
|
+
console.print(f"[yellow]📝 Session change detected: {Path(session_path).name}[/yellow]")
|
|
221
|
+
break
|
|
222
|
+
|
|
223
|
+
if has_changes:
|
|
224
|
+
console.print("[cyan]🔄 Auto-committing...[/cyan]")
|
|
225
|
+
if auto_commit_once(repo_root, message):
|
|
226
|
+
commit_count += 1
|
|
227
|
+
console.print(f"[green]✓[/green] Total commits: {commit_count}\n")
|
|
228
|
+
last_mtimes = current_mtimes
|
|
229
|
+
|
|
230
|
+
except KeyboardInterrupt:
|
|
231
|
+
console.print(f"\n[cyan]👋 Stopped watching. Total commits: {commit_count}[/cyan]")
|