gemini-chat-sync 0.1.0__tar.gz

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.
@@ -0,0 +1,12 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.pyo
4
+ .venv/
5
+ dist/
6
+ build/
7
+ *.egg-info/
8
+ .pytest_cache/
9
+ .ruff_cache/
10
+ .sync.lock
11
+ *.tmp
12
+ .DS_Store
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 David Kracht
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,85 @@
1
+ Metadata-Version: 2.5
2
+ Name: gemini-chat-sync
3
+ Version: 0.1.0
4
+ Summary: Incremental backup, overview indexing, and bidirectional sync for Google Gemini Web chats (CLI + Agent Skill)
5
+ Project-URL: Homepage, https://github.com/david-kracht/gemini-chat-sync
6
+ Project-URL: Repository, https://github.com/david-kracht/gemini-chat-sync
7
+ Project-URL: Issues, https://github.com/david-kracht/gemini-chat-sync/issues
8
+ Author-email: David Kracht <david.kracht@mail.de>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: agent-skill,backup,browser-use,cdp,gemini,markdown,sync
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Requires-Python: >=3.11
22
+ Requires-Dist: browser-use>=1.0.0
23
+ Description-Content-Type: text/markdown
24
+
25
+ # gemini-chat-sync
26
+
27
+ Dual-use incremental backup, overview indexing, and bidirectional sync tool for **Google Gemini Web** (`gemini.google.com`) — packaged as a `uv` Python CLI with a built-in multi-framework **Agent Skill** installer (modeled after `browser-use`).
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ # Install globally as a uv tool (brings browser-use along automatically)
33
+ uv tool install gemini-chat-sync
34
+
35
+ # Install the Agent Skill into all detected agent frameworks
36
+ # (~/.agents, Antigravity, Claude Code, Codex, Copilot, Cursor, Gemini CLI, OpenCode, OpenClaw)
37
+ gemini-chat-sync skill install
38
+ ```
39
+
40
+ Install into a specific framework or project directory:
41
+
42
+ ```bash
43
+ gemini-chat-sync skill install --target antigravity
44
+ gemini-chat-sync skill install --target claude
45
+ gemini-chat-sync skill install --path ./.agents/skills/gemini-chat-sync
46
+ ```
47
+
48
+ ## CLI Quickstart
49
+
50
+ ```bash
51
+ # 1. Preflight check (browser-use binary, CDP connectivity, backup directory)
52
+ gemini-chat-sync --out-dir ~/gemini-backup --doctor
53
+
54
+ # 2. Fast sidebar overview (indexes all chats into sessions.md without opening them)
55
+ gemini-chat-sync --out-dir ~/gemini-backup --mode overview
56
+
57
+ # 3. Selectively export specific chats (Markdown, KaTeX, Canvas .md/.txt/.html, attachments)
58
+ gemini-chat-sync --out-dir ~/gemini-backup --mode full --cid <cid1>,<cid2>
59
+
60
+ # 4. Incremental backward-delta sync across all live chats
61
+ gemini-chat-sync --out-dir ~/gemini-backup --mode sync
62
+
63
+ # 5. Preview / apply deletions marked `Löschen: [x]` (or `Delete: [x]`) in sessions.md
64
+ gemini-chat-sync --out-dir ~/gemini-backup --dry-run
65
+ gemini-chat-sync --out-dir ~/gemini-backup --apply-deletes
66
+ ```
67
+
68
+ ## Features
69
+
70
+ - **Fine-grained modes:** `overview` (sidebar-only index), `sync` (backward-delta with bottom-peek hash + Canvas fingerprint), `full`, `--cid` filtering, `--no-canvas`, `--no-attachments`, `--rebuild-only`, `--dry-run`, `--doctor`.
71
+ - **Clean Artifact Export:**
72
+ - `chat.md` with KaTeX math (`$...$` / `$$...$$`) and inline links to Canvas & attachment files.
73
+ - Latest Canvas documents (`.md`, `.txt`) and unmodified pre-execution HTML/WebGL demos (`.html` via *Export → Download code*).
74
+ - Uploaded text/code files and generated/embedded images under `attachments/`.
75
+ - **Safe Bidirectional Deletion:** Marks in `sessions.md` are previewed by default; `--apply-deletes` deletes in Gemini Web while keeping local archives (`deleted_in_web: true`) unless `--purge-local` is passed.
76
+ - **Robustness:** Hard single-tab navigation (`CDP Page.navigate`) prevents Angular SPA cross-chat DOM bleed; automatic sidebar expansion; atomic writes (`.tmp` → `os.replace`); `.sync.lock`; 1× retry with `failed` reporting.
77
+
78
+ ## Development
79
+
80
+ ```bash
81
+ uv sync
82
+ uv run pytest
83
+ uv run ruff check && uv run ruff format --check
84
+ uv build
85
+ ```
@@ -0,0 +1,61 @@
1
+ # gemini-chat-sync
2
+
3
+ Dual-use incremental backup, overview indexing, and bidirectional sync tool for **Google Gemini Web** (`gemini.google.com`) — packaged as a `uv` Python CLI with a built-in multi-framework **Agent Skill** installer (modeled after `browser-use`).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ # Install globally as a uv tool (brings browser-use along automatically)
9
+ uv tool install gemini-chat-sync
10
+
11
+ # Install the Agent Skill into all detected agent frameworks
12
+ # (~/.agents, Antigravity, Claude Code, Codex, Copilot, Cursor, Gemini CLI, OpenCode, OpenClaw)
13
+ gemini-chat-sync skill install
14
+ ```
15
+
16
+ Install into a specific framework or project directory:
17
+
18
+ ```bash
19
+ gemini-chat-sync skill install --target antigravity
20
+ gemini-chat-sync skill install --target claude
21
+ gemini-chat-sync skill install --path ./.agents/skills/gemini-chat-sync
22
+ ```
23
+
24
+ ## CLI Quickstart
25
+
26
+ ```bash
27
+ # 1. Preflight check (browser-use binary, CDP connectivity, backup directory)
28
+ gemini-chat-sync --out-dir ~/gemini-backup --doctor
29
+
30
+ # 2. Fast sidebar overview (indexes all chats into sessions.md without opening them)
31
+ gemini-chat-sync --out-dir ~/gemini-backup --mode overview
32
+
33
+ # 3. Selectively export specific chats (Markdown, KaTeX, Canvas .md/.txt/.html, attachments)
34
+ gemini-chat-sync --out-dir ~/gemini-backup --mode full --cid <cid1>,<cid2>
35
+
36
+ # 4. Incremental backward-delta sync across all live chats
37
+ gemini-chat-sync --out-dir ~/gemini-backup --mode sync
38
+
39
+ # 5. Preview / apply deletions marked `Löschen: [x]` (or `Delete: [x]`) in sessions.md
40
+ gemini-chat-sync --out-dir ~/gemini-backup --dry-run
41
+ gemini-chat-sync --out-dir ~/gemini-backup --apply-deletes
42
+ ```
43
+
44
+ ## Features
45
+
46
+ - **Fine-grained modes:** `overview` (sidebar-only index), `sync` (backward-delta with bottom-peek hash + Canvas fingerprint), `full`, `--cid` filtering, `--no-canvas`, `--no-attachments`, `--rebuild-only`, `--dry-run`, `--doctor`.
47
+ - **Clean Artifact Export:**
48
+ - `chat.md` with KaTeX math (`$...$` / `$$...$$`) and inline links to Canvas & attachment files.
49
+ - Latest Canvas documents (`.md`, `.txt`) and unmodified pre-execution HTML/WebGL demos (`.html` via *Export → Download code*).
50
+ - Uploaded text/code files and generated/embedded images under `attachments/`.
51
+ - **Safe Bidirectional Deletion:** Marks in `sessions.md` are previewed by default; `--apply-deletes` deletes in Gemini Web while keeping local archives (`deleted_in_web: true`) unless `--purge-local` is passed.
52
+ - **Robustness:** Hard single-tab navigation (`CDP Page.navigate`) prevents Angular SPA cross-chat DOM bleed; automatic sidebar expansion; atomic writes (`.tmp` → `os.replace`); `.sync.lock`; 1× retry with `failed` reporting.
53
+
54
+ ## Development
55
+
56
+ ```bash
57
+ uv sync
58
+ uv run pytest
59
+ uv run ruff check && uv run ruff format --check
60
+ uv build
61
+ ```
@@ -0,0 +1,70 @@
1
+ [project]
2
+ name = "gemini-chat-sync"
3
+ version = "0.1.0"
4
+ description = "Incremental backup, overview indexing, and bidirectional sync for Google Gemini Web chats (CLI + Agent Skill)"
5
+ authors = [{ name = "David Kracht", email = "david.kracht@mail.de" }]
6
+ license = "MIT"
7
+ readme = "README.md"
8
+ requires-python = ">=3.11"
9
+ keywords = ["gemini", "backup", "sync", "browser-use", "cdp", "agent-skill", "markdown"]
10
+ classifiers = [
11
+ "Development Status :: 4 - Beta",
12
+ "Intended Audience :: Developers",
13
+ "License :: OSI Approved :: MIT License",
14
+ "Operating System :: OS Independent",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.11",
17
+ "Programming Language :: Python :: 3.12",
18
+ "Programming Language :: Python :: 3.13",
19
+ "Programming Language :: Python :: 3.14",
20
+ ]
21
+ dependencies = [
22
+ "browser-use>=1.0.0",
23
+ ]
24
+
25
+ [project.urls]
26
+ Homepage = "https://github.com/david-kracht/gemini-chat-sync"
27
+ Repository = "https://github.com/david-kracht/gemini-chat-sync"
28
+ Issues = "https://github.com/david-kracht/gemini-chat-sync/issues"
29
+
30
+ [project.scripts]
31
+ gemini-chat-sync = "gemini_chat_sync.cli:main"
32
+
33
+ [dependency-groups]
34
+ dev = [
35
+ "pytest>=8.3.0",
36
+ "ruff>=0.9.0",
37
+ ]
38
+
39
+ [build-system]
40
+ requires = ["hatchling>=1.25.0"]
41
+ build-backend = "hatchling.build"
42
+
43
+ [tool.hatch.build.targets.wheel]
44
+ packages = ["src/gemini_chat_sync"]
45
+
46
+ [tool.hatch.build.targets.sdist]
47
+ include = [
48
+ "src/gemini_chat_sync/**/*.py",
49
+ "src/gemini_chat_sync/skills/**/*.md",
50
+ "tests/**/*.py",
51
+ "README.md",
52
+ "LICENSE",
53
+ "pyproject.toml",
54
+ ]
55
+
56
+ [tool.ruff]
57
+ line-length = 130
58
+ target-version = "py311"
59
+
60
+ [tool.ruff.lint]
61
+ select = ["E", "F", "I", "UP", "B"]
62
+ ignore = ["E101", "E501"]
63
+
64
+ [tool.ruff.format]
65
+ quote-style = "single"
66
+ indent-style = "tab"
67
+ line-ending = "lf"
68
+
69
+ [tool.pytest.ini_options]
70
+ testpaths = ["tests"]
@@ -0,0 +1,12 @@
1
+ """Dual-use incremental backup and sync for Google Gemini Web chats."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from importlib.metadata import PackageNotFoundError, version
6
+
7
+ try:
8
+ __version__ = version('gemini-chat-sync')
9
+ except PackageNotFoundError:
10
+ __version__ = '0.0.0-dev'
11
+
12
+ __all__ = ['__version__']
@@ -0,0 +1,182 @@
1
+ """Dual-use CLI for gemini-chat-sync (sync/export + multi-agent skill installer)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import fcntl
7
+ import json
8
+ import os
9
+ import shutil
10
+ import subprocess
11
+ import sys
12
+ import urllib.request
13
+ from pathlib import Path
14
+
15
+ from gemini_chat_sync import __version__
16
+ from gemini_chat_sync.sessions import parse_marked_deletions, rebuild_sessions
17
+
18
+ PROXY_VARS = ('http_proxy', 'https_proxy', 'HTTP_PROXY', 'HTTPS_PROXY', 'all_proxy', 'ALL_PROXY')
19
+
20
+
21
+ def find_browser_use_binary() -> str | None:
22
+ """Prefer browser-use installed alongside this Python/uv tool, then fall back to PATH."""
23
+ sibling = Path(sys.executable).resolve().parent / ('browser-use.exe' if os.name == 'nt' else 'browser-use')
24
+ if sibling.is_file() and os.access(sibling, os.X_OK):
25
+ return str(sibling)
26
+ return shutil.which('browser-use')
27
+
28
+
29
+ def clean_env(cdp_url: str | None, daemon: str | None) -> dict[str, str]:
30
+ env = {k: v for k, v in os.environ.items() if k not in PROXY_VARS}
31
+ if cdp_url:
32
+ env['BU_CDP_URL'] = cdp_url
33
+ if daemon:
34
+ env['BU_NAME'] = daemon
35
+ return env
36
+
37
+
38
+ def check_cdp_reachable(cdp_url: str) -> tuple[bool, str]:
39
+ url = cdp_url.rstrip('/') + '/json/version'
40
+ opener = urllib.request.build_opener(urllib.request.ProxyHandler({}))
41
+ try:
42
+ with opener.open(url, timeout=3.0) as resp:
43
+ data = json.loads(resp.read().decode('utf-8'))
44
+ return True, f"{data.get('Browser', 'Chrome')} ({url})"
45
+ except Exception as e:
46
+ return False, f'{url}: {e}'
47
+
48
+
49
+ def run_doctor(out_dir: Path, cdp_url: str | None, daemon: str | None) -> int:
50
+ ok = True
51
+ bu_bin = find_browser_use_binary()
52
+ print(f"[{'OK' if bu_bin else 'FAIL'}] browser-use binary: {bu_bin or 'not found in PATH or tool venv'}")
53
+ if not bu_bin:
54
+ ok = False
55
+
56
+ if cdp_url:
57
+ cdp_ok, detail = check_cdp_reachable(cdp_url)
58
+ print(f"[{'OK' if cdp_ok else 'FAIL'}] CDP endpoint: {detail}")
59
+ if not cdp_ok:
60
+ ok = False
61
+ else:
62
+ print('[INFO] CDP endpoint: local default Chrome (no --cdp-url / BU_CDP_URL set)')
63
+
64
+ print(f"[INFO] Daemon name (BU_NAME): {daemon or '(default)'}")
65
+ print(f"[{'OK' if out_dir.exists() else 'WARN'}] Output directory: {out_dir}")
66
+
67
+ marked = parse_marked_deletions(out_dir / 'sessions.md')
68
+ print(f'[INFO] Marked for deletion in sessions.md: {len(marked)} {marked if marked else ""}'.strip())
69
+ return 0 if ok else 1
70
+
71
+
72
+ def parse_cids(raw_cids: list[str] | None) -> list[str]:
73
+ if not raw_cids:
74
+ return []
75
+ out: list[str] = []
76
+ for item in raw_cids:
77
+ for part in item.split(','):
78
+ p = part.strip()
79
+ if p and p not in out:
80
+ out.append(p)
81
+ return out
82
+
83
+
84
+ def _build_sync_parser() -> argparse.ArgumentParser:
85
+ default_out = Path(os.environ.get('GEMINI_SYNC_DIR') or Path.cwd())
86
+ parser = argparse.ArgumentParser(
87
+ prog='gemini-chat-sync',
88
+ description='Incremental backup, overview indexing, and bidirectional sync for Google Gemini Web chats. Run `gemini-chat-sync skill install` to install the Agent Skill.',
89
+ )
90
+ parser.add_argument('--version', action='version', version=f'%(prog)s {__version__}')
91
+ parser.add_argument(
92
+ '--out-dir',
93
+ type=Path,
94
+ default=default_out,
95
+ help='Backup root directory (default: $GEMINI_SYNC_DIR or current working directory)',
96
+ )
97
+ parser.add_argument(
98
+ '--mode',
99
+ choices=['overview', 'sync', 'full'],
100
+ default='sync',
101
+ help='overview=sidebar index only, sync=backward-delta (default), full=full re-export',
102
+ )
103
+ parser.add_argument('--cid', action='append', help='Target specific chat ID(s); repeatable or comma-separated')
104
+ parser.add_argument('--no-canvas', action='store_true', help='Skip exporting Canvas documents and HTML demos')
105
+ parser.add_argument('--no-attachments', action='store_true', help='Skip exporting attachments and images')
106
+ parser.add_argument('--dry-run', action='store_true', help='Inspect changes and marked deletions without writing or deleting')
107
+ parser.add_argument('--apply-deletes', action='store_true', help='Execute deletions for chats marked `Löschen: [x]` in sessions.md')
108
+ parser.add_argument('--purge-local', action='store_true', help='With --apply-deletes: also remove local chat folder instead of archiving')
109
+ parser.add_argument('--rebuild-only', action='store_true', help='Only rebuild sessions.md from local metadata (no browser)')
110
+ parser.add_argument('--doctor', action='store_true', help='Run preflight checks (browser-use, CDP endpoint, out-dir)')
111
+ parser.add_argument('--cdp-url', default=os.environ.get('BU_CDP_URL'), help='Remote CDP URL (e.g. http://127.0.0.1:9223 for WSL2)')
112
+ parser.add_argument('--daemon', default=os.environ.get('BU_NAME'), help='browser-use daemon name (e.g. win-dev)')
113
+ return parser
114
+
115
+
116
+ def main(argv: list[str] | None = None) -> int:
117
+ args_list = list(sys.argv[1:] if argv is None else argv)
118
+
119
+ # Delegate `gemini-chat-sync skill ...` just like `browser-use skill ...`
120
+ if args_list and args_list[0] == 'skill':
121
+ from gemini_chat_sync.skills.install import handle
122
+
123
+ return handle(args_list[1:])
124
+
125
+ parser = _build_sync_parser()
126
+ args = parser.parse_args(args_list)
127
+ out_dir = args.out_dir.resolve()
128
+
129
+ if args.doctor:
130
+ return run_doctor(out_dir, args.cdp_url, args.daemon)
131
+
132
+ if args.rebuild_only:
133
+ stats = rebuild_sessions(out_dir)
134
+ print(json.dumps({'rebuilt': stats}, ensure_ascii=False, indent=2))
135
+ return 0
136
+
137
+ bu_bin = find_browser_use_binary()
138
+ if not bu_bin:
139
+ print('ERROR: `browser-use` not found. Install via `uv tool install gemini-chat-sync` or `uv tool install browser-use`.', file=sys.stderr)
140
+ return 1
141
+
142
+ if args.cdp_url:
143
+ cdp_ok, detail = check_cdp_reachable(args.cdp_url)
144
+ if not cdp_ok:
145
+ print(f'ERROR: CDP endpoint unreachable ({detail}). Start Chrome with remote debugging first.', file=sys.stderr)
146
+ return 1
147
+
148
+ out_dir.mkdir(parents=True, exist_ok=True)
149
+ lock_path = out_dir / '.sync.lock'
150
+ with lock_path.open('w', encoding='utf-8') as lock_f:
151
+ try:
152
+ fcntl.flock(lock_f.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
153
+ except BlockingIOError:
154
+ print(f'ERROR: Another sync is already running (lock held: {lock_path}).', file=sys.stderr)
155
+ return 1
156
+
157
+ marked_deletes = parse_marked_deletions(out_dir / 'sessions.md')
158
+ pkg_src_dir = Path(__file__).resolve().parent.parent
159
+ cfg = {
160
+ 'out_dir': str(out_dir),
161
+ 'mode': args.mode,
162
+ 'cids': parse_cids(args.cid),
163
+ 'export_canvas': not args.no_canvas,
164
+ 'export_attachments': not args.no_attachments,
165
+ 'dry_run': args.dry_run,
166
+ 'apply_deletes': args.apply_deletes,
167
+ 'purge_local': args.purge_local,
168
+ 'marked_deletes': marked_deletes,
169
+ 'pkg_src_dir': str(pkg_src_dir),
170
+ }
171
+
172
+ env = clean_env(args.cdp_url, args.daemon)
173
+ env['GEMINI_SYNC_CONFIG_JSON'] = json.dumps(cfg, ensure_ascii=False)
174
+
175
+ engine_path = Path(__file__).resolve().parent / 'engine.py'
176
+ with engine_path.open('rb') as script_fh:
177
+ proc = subprocess.run([bu_bin], stdin=script_fh, env=env)
178
+ return proc.returncode
179
+
180
+
181
+ if __name__ == '__main__':
182
+ raise SystemExit(main())