Metadata-Version: 2.4
Name: github-sync-agent
Version: 0.2.0
Summary: Sync all your local projects to GitHub automatically
License: MIT
Project-URL: Homepage, https://github.com/yuvalavni/Agents
Project-URL: Repository, https://github.com/yuvalavni/Agents
Project-URL: Bug Tracker, https://github.com/yuvalavni/Agents/issues
Keywords: github,git,sync,backup,automation,cli,api
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Environment :: Console
Classifier: Topic :: Software Development :: Version Control :: Git
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: pyyaml>=6.0
Requires-Dist: click>=8.0
Provides-Extra: api
Requires-Dist: fastapi>=0.100; extra == "api"
Requires-Dist: uvicorn>=0.23; extra == "api"

# GitHub Sync Agent

Automatically syncs every local project directory to its own GitHub repository.

For each project it will:
1. `git init` if not already a repo
2. Create the GitHub repo if it doesn't exist yet
3. Ensure the remote uses SSH
4. Stage + commit any uncommitted changes
5. Push to `origin`

Runs daily via a systemd user timer, and on-demand via CLI.

---

## Installation

```bash
pip install github-sync-agent
```

## First-time setup

```bash
github-sync init
```

The wizard will:
- Check `git` and `gh` are installed
- Authenticate with GitHub (`gh auth login`)
- Ask which folder to scan for projects
- Set up your SSH key automatically
- **Verify SSH works** (auto-fixes port 443 and ssh-agent if needed)
- Write a config file to `~/.config/github-sync/config.yaml`

Setup will **not** complete until `ssh -T git@github.com` succeeds.

---

## Usage

```bash
# Sync all projects
github-sync sync

# Sync a single project
github-sync sync --project my-project

# Preview without making changes
github-sync sync --dry-run

# Show status of all projects
github-sync status
```

---

## HTTP API

Install API dependencies:

```bash
pip install 'github-sync-agent[api]'
```

Start the server:

```bash
github-sync serve
# → http://127.0.0.1:8741
```

### Endpoints

| Method | Path | Description |
|--------|------|-------------|
| `GET` | `/health` | Health check (no auth) |
| `GET` | `/status` | Sync status for all projects |
| `POST` | `/sync` | Sync all projects |
| `POST` | `/sync/{project}` | Sync one project |

Optional body for POST: `{"dry_run": false}`

### Examples

```bash
curl http://127.0.0.1:8741/health
curl http://127.0.0.1:8741/status
curl -X POST http://127.0.0.1:8741/sync
curl -X POST http://127.0.0.1:8741/sync/Agents
```

### API authentication (optional)

Add to `config.yaml`:

```yaml
api_key: "your-secret-key"
```

Then pass the key on every request (except `/health`):

```bash
curl -H "Authorization: Bearer your-secret-key" http://127.0.0.1:8741/status
```

### Run as a systemd service

```bash
cp systemd/github-sync-api.service ~/.config/systemd/user/
systemctl --user enable --now github-sync-api.service
```

---

## Configuration (`~/.config/github-sync/config.yaml`)

Generated by `github-sync init`. You can edit it at any time.

| Key | Default | Description |
|-----|---------|-------------|
| `github_user` | _(detected from gh auth)_ | Your GitHub username |
| `projects_root` | `~/projects` | Scans all subdirectories here |
| `schedule_time` | `02:00` | Daily run time |
| `default_visibility` | `private` | `private` or `public` for new repos |
| `auto_commit_message` | `chore: auto-sync` | Commit message for auto-commits |
| `exclude` | `[]` | Directory names to skip |
| `log_file` | `~/.local/share/github-sync/github-sync.log` | Log file path |
| `log_level` | `INFO` | `DEBUG` / `INFO` / `WARNING` / `ERROR` |
| `api_host` | `127.0.0.1` | API bind address |
| `api_port` | `8741` | API port |
| `api_key` | _(empty)_ | Optional Bearer token for API auth |

### Excluding a project

```yaml
exclude:
  - SomeProjectToSkip
```

---

## Requirements

- Python 3.10+
- `git` installed
- `gh` (GitHub CLI) installed — [installation guide](https://cli.github.com)

---

## License

MIT
