Skip to content

Commit 82249cc

Browse files
committed
Fix README.md merge
1 parent d49584e commit 82249cc

23 files changed

Lines changed: 721 additions & 439 deletions
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import json
2+
import logging
3+
import os
4+
import sys
5+
import urllib.request
6+
7+
# Setup logging
8+
# Script is in .gemini/hooks/
9+
# Log file should be in .gemini/
10+
base_dir = os.path.dirname(
11+
os.path.dirname(os.path.abspath(__file__))
12+
) # This is .gemini directory
13+
log_path = os.path.join(base_dir, "check_github_version.log")
14+
15+
# Create logger
16+
logger = logging.getLogger()
17+
logger.setLevel(logging.INFO)
18+
19+
# File handler (keeps full history)
20+
file_handler = logging.FileHandler(log_path)
21+
file_handler.setLevel(logging.INFO)
22+
file_handler.setFormatter(
23+
logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")
24+
)
25+
logger.addHandler(file_handler)
26+
27+
# Stream handler (only shows warnings and errors to user)
28+
stream_handler = logging.StreamHandler(sys.stderr)
29+
stream_handler.setLevel(logging.WARNING) # Only show WARNING or higher
30+
stream_handler.setFormatter(
31+
logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")
32+
)
33+
logger.addHandler(stream_handler)
34+
35+
36+
def get_local_version():
37+
# gemini-extension.json is in the root directory
38+
# So we need to go up one more level from .gemini to find gemini-extension.json
39+
root_dir = os.path.dirname(base_dir)
40+
json_path = os.path.join(root_dir, "gemini-extension.json")
41+
42+
try:
43+
with open(json_path, "r") as f:
44+
data = json.load(f)
45+
return data.get("version")
46+
except Exception as e:
47+
logging.error(f"Error reading local version: {e}")
48+
return None
49+
50+
51+
def get_remote_version():
52+
url = "https://raw.githubusercontent.com/googleads/google-ads-api-developer-assistant/main/gemini-extension.json"
53+
try:
54+
with urllib.request.urlopen(url, timeout=5) as response:
55+
if response.status == 200:
56+
data = json.loads(response.read().decode("utf-8"))
57+
return data.get("version")
58+
else:
59+
logging.error(
60+
f"Failed to fetch remote version, status: {response.status}"
61+
)
62+
return None
63+
except Exception as e:
64+
logging.error(f"Error fetching remote version: {e}")
65+
return None
66+
67+
68+
def parse_version(v_str):
69+
return tuple(map(int, v_str.split(".")))
70+
71+
72+
def main():
73+
logging.info("Checking for extension updates...")
74+
local_version = get_local_version()
75+
remote_version = get_remote_version()
76+
77+
if not local_version or not remote_version:
78+
logging.info("Could not complete version check.")
79+
return
80+
81+
logging.info(
82+
f"Local version: {local_version}, Remote version: {remote_version}"
83+
)
84+
85+
try:
86+
if parse_version(remote_version) > parse_version(local_version):
87+
logging.warning(
88+
f"A new version of the extension is available: {remote_version}"
89+
)
90+
logging.warning("Please run `./update.sh` to update.")
91+
else:
92+
logging.info("Extension is up to date.")
93+
except Exception as e:
94+
logging.error(f"Error comparing versions: {e}")
95+
96+
97+
if __name__ == "__main__":
98+
main()
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,20 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
# ==============================================================================
15+
# CRITICAL MAINTENANCE NOTE - DO NOT REMOVE
16+
# ==============================================================================
17+
# ⚠️ DO NOT migrate lifecycle hooks (SessionStart/SessionEnd) to the extension
18+
# manifest (hooks/hooks.json or gemini-extension.json).
19+
#
20+
# Doing so breaks hook execution in the OSS version of gemini-cli used in this
21+
# workspace. Hooks MUST remain registered in `.gemini/settings.json` using the
22+
# `matcher` wrapper list structure to function correctly.
23+
# ==============================================================================
1424

1525
import os
1626
import shutil
1727
import sys
18-
import datetime
1928

2029
def cleanup():
2130
# Determine paths
@@ -43,7 +52,16 @@ def cleanup():
4352
except Exception as e:
4453
print(f"Failed to delete {file_path}. Reason: {e}", file=sys.stderr)
4554

46-
timestamp = datetime.datetime.now()
55+
# Delete isolated virtual environment
56+
venv_dir = os.path.join(project_root, ".venv")
57+
if os.path.exists(venv_dir):
58+
print(f"Deleting virtual environment at {venv_dir}...", file=sys.stderr)
59+
try:
60+
shutil.rmtree(venv_dir)
61+
print("Virtual environment deleted successfully.", file=sys.stderr)
62+
except Exception as e:
63+
print(f"Failed to delete virtual environment: {e}", file=sys.stderr)
64+
4765

4866
except Exception as e:
4967
print(f"Error cleaning up config directory: {e}", file=sys.stderr)

0 commit comments

Comments
 (0)