-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_backup_file.py
More file actions
executable file
·121 lines (100 loc) · 4.4 KB
/
get_backup_file.py
File metadata and controls
executable file
·121 lines (100 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python3
"""
get-backup-file command for Antigravity CLI.
Accesses resolved.N versions of artifacts.
Usage:
python get_backup_file.py --artifacttype <type> --primarytask <index_or_guid> --version <N>
Requirements:
- artifacttype: one of 'task', 'implementation_plan', 'walkthrough', 'other'
- primarytask: either a 1-based index or GUID
- version: integer version number N
The command:
1. Validates artifact type
2. Resolves primarytask to GUID using task_parser.py
3. Constructs path: ~/.gemini/antigravity/brain/<GUID>/<artifact_name>.md.resolved.<N>
4. Reads and outputs file content
5. Returns error if version file doesn't exist
6. Returns error if task doesn't exist
Uses only standard library imports and imports from task_parser.py
"""
import os
import sys
import argparse
from pathlib import Path
# Import local modules
from task_parser import parse_task_md, get_task_summary
# Constants
BRAIN_ROOT = Path.home() / ".gemini" / "antigravity" / "brain"
ANTIGRAVITY_DIR = Path.home() / ".gemini" / "antigravity" / "brain"
def get_artifact_name(artifact_type: str) -> str:
"""
Get the artifact filename based on artifact type.
Args:
artifact_type: One of 'task', 'implementation_plan', 'walkthrough', 'other'
Returns:
Artifact filename (without extension)
"""
artifact_map = {
'task': 'task',
'implementation_plan': 'implementation_plan',
'walkthrough': 'walkthrough',
'other': 'other'
}
if artifact_type not in artifact_map:
raise ValueError(f"Invalid artifact type: {artifact_type}")
return artifact_map[artifact_type]
def main():
parser = argparse.ArgumentParser(description='Access resolved.N versions of artifacts')
parser.add_argument('--artifacttype', required=True,
choices=['task', 'implementation_plan', 'walkthrough', 'other'],
help='Type of artifact: task, implementation_plan, walkthrough, or other')
parser.add_argument('--primarytask', required=True,
help='1-based index or GUID of the primary task')
parser.add_argument('--version', required=True, type=int,
help='Version number N')
args = parser.parse_args()
# 1. Validate artifact type (already done by argparse choices)
artifact_type = args.artifacttype
# 2. Resolve primarytask to GUID
try:
# Resolve primarytask using the same logic as in update_task.py
if args.primarytask.isdigit():
index = int(args.primarytask)
tasks = sorted([d.name for d in ANTIGRAVITY_DIR.iterdir() if d.is_dir()])
if index < 1 or index > len(tasks):
print(f"Error: Index {index} is out of bounds. Available tasks: 1-{len(tasks)}", file=sys.stderr)
sys.exit(1)
guid = tasks[index - 1]
else:
# Validate GUID format
import re
uuid_pattern = r'^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'
if not re.match(uuid_pattern, args.primarytask.lower()):
print(f"Error: Invalid GUID format '{args.primarytask}'. Expected UUID format (e.g., 123e4567-e89b-12d3-a456-426614174000)", file=sys.stderr)
sys.exit(1)
guid = args.primarytask
# Validate that the task directory exists
task_path = ANTIGRAVITY_DIR / guid
if not task_path.exists() or not task_path.is_dir():
print(f"Error: Task not found: {guid}", file=sys.stderr)
sys.exit(1)
except ValueError as e:
print(f"Error: Task not found: {args.primarytask}", file=sys.stderr)
sys.exit(1)
# 3. Construct path to versioned file
artifact_name = get_artifact_name(artifact_type)
versioned_filename = f"{artifact_name}.md.resolved.{args.version}"
versioned_path = BRAIN_ROOT / guid / versioned_filename
# 4. Read and output content of versioned file
if not versioned_path.exists():
print(f"Error: Version {args.version} not found for {artifact_name}", file=sys.stderr)
sys.exit(1)
try:
with open(versioned_path, 'r', encoding='utf-8') as f:
content = f.read()
print(content, end='') # Print without extra newline
except Exception as e:
print(f"Error reading versioned file: {e}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()