Skip to main content

KoteGuard โ€“ run GitHub Copilot agents safely in isolated git worktrees

Project description

koteguard.com Python 3.12+ PyPI Version Platform MIT License CI

KoteGuard ๐Ÿ›ก๏ธ

Safe GitHub Copilot agent sandboxing for Android (Kotlin) and iOS (Swift) developers.

kote prep โ†’ isolated git worktree โ†’ agent works safely โ†’ kote cleanup --accept


KoteGuard runs Copilot agents in isolated git worktrees so they can never accidentally commit secrets, break your main branch, or touch real signing credentials. Every session is planned, gated, validated, and audited.

Why KoteGuard?

Problem Without KoteGuard With KoteGuard
Agent pushes to main ๐Ÿ’ฅ Happens --deny-tool='shell(git push)' blocks it
Agent reads your .jks / .p12 ๐Ÿ’ฅ Full access Replaced with stubs before session starts
No record of what the agent did ๐Ÿ˜ฌ Nothing Per-session audit.jsonl + validation-report.md
Agent goes off-script ๐Ÿ˜ฌ No way to know PLAN.md hard gate + change validation on cleanup
Context bloat across sessions ๐Ÿ˜ฌ Expensive --compact accumulates knowledge into WORKSPACE.md

Features

  • ๐Ÿ” Smart project analysis โ€” auto-detects Android/iOS, parses build.gradle + Info.plist, scans docs
  • ๐Ÿ“‹ Interactive planning wizard โ€” builds PLAN.md with a refine loop and a hard YES gate
  • ๐ŸŒฟ Isolated git worktrees โ€” agent works on a dedicated branch, never touches main
  • ๐Ÿ”’ Sensitive file stubs โ€” .jks, google-services.json, .p12 replaced with safe placeholders
  • ๐Ÿค– Copilot CLI ready โ€” generates the complete copilot --deny-tool=... command for you
  • ๐Ÿ“Š Session tracking โ€” rich status table with age, Android CLI status, skills loaded, context pressure
  • โœ… Auto-validation โ€” validates PLAN.md + changed files on kote cleanup --accept
  • ๐Ÿงฐ Android Skills โ€” bundled SKILL.md guides for Navigation 3, Compose, AGP 9, Edge-to-Edge
  • ๐Ÿง  Token hygiene โ€” --compact saves session knowledge back into WORKSPACE.md

Installation

pip install koteguard

Requires Python 3.12+

Or install from source:

git clone https://github.com/alisen/KoteGuard.git
cd KoteGuard
pip install -e ".[dev]"

Local install (no GitHub push needed โ€” for testing before publishing):

# Using pipx (recommended for CLI tools)
brew install pipx && pipx ensurepath
pipx install /path/to/KoteGuard

# Or with pip directly
pip install /path/to/KoteGuard

Quick Start

cd your-android-or-ios-project

# 1. Run the wizard โ€” it detects your project, plans, creates the worktree
kote prep

# 2. See what it created
kote status

# 3. Copy the ready-to-run Copilot CLI command
kote cli

# 4. Inside the worktree, make sure the agent committed its changes
#    KoteGuard diffs branch commits โ€” uncommitted changes will not be merged
#    cd /path/to/worktree && git add -A && git commit -m "agent: apply changes"

# 5. Back in your project root โ€” validate + merge back
cd your-android-or-ios-project   # same dir as step 1
kote cleanup --accept

# 6. Or throw it away
kote cleanup --discard

Android-first (with skills wizard)

kote prep --android-first
# โ†’ detects Compose/Navigation/AGP usage
# โ†’ shows checkbox to select which skill guides to inject
# โ†’ pre-populates PLAN.md with selected skills

How It Works

kote prep
  โ”‚
  โ”œโ”€โ”€ Phase 0: Scan project
  โ”‚     detect Android/iOS ยท parse build.gradle/Info.plist
  โ”‚     scan docs ยท detect Android CLI ยท suggest skills
  โ”‚
  โ”œโ”€โ”€ Phase 1: Interactive planning
  โ”‚     title ยท objectives ยท tasks ยท definition of done ยท risks
  โ”‚     โ”€โ”€โ”€โ”€ HARD GATE: type YES to proceed, refine to re-edit โ”€โ”€โ”€โ”€
  โ”‚
  โ””โ”€โ”€ Phase 2: Create worktree
        new git branch (kote/<session-id>-<slug>)
        writes: PLAN.md ยท TASK.md ยท AGENTS.md ยท WORKSPACE.md
                .github/copilot-instructions.md
                .github/instructions/security.instructions.md
        stubs:  google-services.json ยท *.jks ยท *.p12 ยท etc.
        logs:   sessions/<id>/context/ ยท logs/ ยท output/

kote cli
  โ””โ”€โ”€ prints: cd /worktree && COPILOT_CUSTOM_INSTRUCTIONS_DIRS=... copilot --deny-tool=...

[agent works here]

kote cleanup --accept
  โ”œโ”€โ”€ auto-validates PLAN.md + changed files
  โ”œโ”€โ”€ generates sessions/<id>/output/validation-report.md
  โ”œโ”€โ”€ merges branch back
  โ””โ”€โ”€ archives PLAN ยท TASK ยท diff ยท audit ยท report โ†’ .kote/history/

Command Reference

Command Description
kote prep Full wizard: analyse โ†’ plan โ†’ worktree โ†’ IDE
kote prep --android-first Wizard with Android skills selection
kote prep --agent-mode <mode> Override agent mode: copilot-cli | copilot-plugin | none
kote prep --dry-run Simulate without creating a worktree
kote ide [session] Launch Android Studio or Xcode for a session
kote cli [session] Print complete copilot command + open terminal
kote status Rich table: all sessions with age, skills, context pressure
kote cleanup --accept Run from the original project root. Validate โ†’ merge โ†’ archive history. Auto-picks most recent active session.
kote cleanup <session-id> --accept Target a specific session by ID (find IDs with kote status)
kote cleanup --discard Throw away changes, preserve audit trail
kote cleanup --accept --force Accept even when validation has errors or uncommitted changes are detected
kote cleanup --accept --compact Accept + save session summary to WORKSPACE.md
kote validate [plan.md] Validate PLAN.md against schema
kote validate -w WORKSPACE.md Also validate WORKSPACE.md
kote android skills List bundled skills + suggest for current project
kote android docs Android KB links + worktree status
kote version Print version

Tips & Gotchas

  • Run kote cleanup from the project root โ€” the same directory where you ran kote prep. Running it from a different directory causes git operations (diff, merge, branch deletion) to target the wrong repository.

  • The agent must commit its changes โ€” KoteGuard detects what changed by diffing branch commits against main. If the agent modifies files but never runs git commit, those changes do not exist as commits and will not be merged. KoteGuard will block cleanup with a clear error and recovery instructions when this is detected. Use --force to skip the block and proceed (the uncommitted changes will not be merged).

  • "No changed files detected" warning โ€” means the agent branch has no new commits relative to main. Check the worktree for uncommitted files before accepting. If the session was already committed and merged manually, this is expected.

  • Find session IDs โ€” run kote status to see all sessions, their IDs, age, and whether the worktree still exists.


Android Skills

KoteGuard bundles best-practice SKILL.md guides that get injected into the agent's context. The scanner auto-detects which ones are relevant based on your build.gradle.

Skill Triggered by Guide covers
navigation3 androidx.navigation dependency Type-safe NavHost, @Serializable routes, no string routes
edge-to-edge enableEdgeToEdge / API 35 target windowInsetsPadding, Scaffold insets, API 35 enforcement
agp9 AGP 9.x in libs.versions.toml JDK 21 requirement, namespace, declarative Kotlin DSL
compose-migration androidx.compose dependency State hoisting, collectAsStateWithLifecycle, LazyColumn keys
kote android skills   # see what's available + what's suggested
kote android docs     # Android developer documentation links

Spec-Driven Development

Every PLAN.md KoteGuard creates has a machine-readable YAML block at the top. This is the source of truth โ€” not just documentation.

---
spec_version: '1.0'
title: Implement login screen
tasks:
- id: t1
  description: Create LoginViewModel
  done: false
- id: t2
  description: Wire up UI
  done: false
definition_of_done:
- All tests pass
- Reviewed
---

# Implement login screen
...

The agent is instructed to update done: true for each task it completes, directly inside that YAML block. When you run kote cleanup --accept, KoteGuard:

  1. Parses the YAML โ€” reads exactly which tasks were marked done
  2. Validates semantically โ€” checks that changed files actually match each task's keywords (CamelCase-aware: NavGraph โ†’ searches for nav, graph in file paths)
  3. Warns if tasks are undone โ€” if files changed but all tasks are still done: false, it flags it
  4. Survives corruption โ€” if the agent breaks the YAML, a regex fallback recovers the plan silently

This is why PLAN.md is not just a text document โ€” it's a live spec the agent writes back to.


Security Model

KoteGuard is designed so that even a misbehaving agent can't cause lasting damage.

Layer Mechanism
Planning gate Must type YES (or refine) โ€” no accidental starts
Branch isolation Agent never touches main โ€” always a kote/<id> branch
Secret stubs google-services.json, .jks, .p12 etc. swapped for placeholders before the session
Deny-tool flags git push, git clone, git remote add/set-url are CLI-level blocked
Dual instructions Agent gets both a task brief and a security rules file
Validation on accept PLAN.md compliance + file change analysis before any merge
Audit trail Every event written to sessions/<id>/logs/audit.jsonl + global ~/.kote/audit.jsonl
History archival PLAN, TASK, diff, audit, report copied to .kote/history/ on every accept or discard

Generated Copilot CLI Command

kote cli prints this โ€” ready to paste:

cd /path/to/worktree && \
  COPILOT_CUSTOM_INSTRUCTIONS_DIRS=".github/instructions" \
  copilot \
    --deny-tool='shell(git push)' \
    --deny-tool='shell(git remote add)' \
    --deny-tool='shell(git remote set-url)' \
    --deny-tool='shell(git clone)'

Project Structure

src/koteguard/
โ”œโ”€โ”€ cli.py              # Typer CLI (kote + kote android subgroup)
โ”œโ”€โ”€ models.py           # Pydantic v2 models + Android v1.1 skill models
โ”œโ”€โ”€ config.py           # TOML config ยท session audit ยท worktree context check
โ”œโ”€โ”€ project_scanner.py  # Phase 0: file-signature detection + gradle parsing + doc analysis
โ”œโ”€โ”€ worktree.py         # Git worktree engine ยท session subdirs ยท history archival
โ”œโ”€โ”€ sensitive_files.py  # Sensitive file stub injection
โ”œโ”€โ”€ planning.py         # PLAN.md ยท WORKSPACE.md ยท Copilot instructions rendering
โ”œโ”€โ”€ launcher.py         # IDE launcher ยท build_copilot_cli_command()
โ”œโ”€โ”€ validation.py       # Plan/change/skills validation ยท report generation
โ””โ”€โ”€ templates.py        # Template file management

templates/
โ”œโ”€โ”€ PLAN.md                          # Includes Token & Context Rules section
โ”œโ”€โ”€ WORKSPACE.md                     # Includes Android Agent Stack section
โ”œโ”€โ”€ TASK.md
โ”œโ”€โ”€ instructions.md                  # Includes model selection guidance
โ”œโ”€โ”€ security.instructions.md         # applyTo: "**/*" ยท Android + iOS deny rules
โ”œโ”€โ”€ AGENTS.md
โ”œโ”€โ”€ config.toml
โ””โ”€โ”€ android-skills/
    โ”œโ”€โ”€ navigation3.skill.md
    โ”œโ”€โ”€ edge-to-edge.skill.md
    โ”œโ”€โ”€ agp9.skill.md
    โ””โ”€โ”€ compose-migration.skill.md

Requirements

  • Python 3.12+
  • Git 2.5+ (for worktree support)
  • GitHub Copilot CLI (copilot binary) for the terminal workflow
  • Android Studio or Xcode (optional, for IDE auto-launch)

Agent Modes

KoteGuard supports three ways to run the Copilot agent. Set the default in ~/.kote/config.toml or override per session with kote prep --agent-mode.

Mode How it runs kote cli output
copilot-cli (default) Terminal binary with --deny-tool security flags Full copy-pasteable command
copilot-plugin IDE chat panel (Android Studio, VS Code) Open IDE at worktree path
none Instructions injected only โ€” bring your own agent cd <worktree>

Set default in ~/.kote/config.toml:

agent_mode = "copilot-cli"   # copilot-cli | copilot-plugin | none
android_cli_enabled = true

Override per session:

kote prep --agent-mode copilot-plugin

Contributing

git clone https://github.com/alisen/KoteGuard.git
cd KoteGuard
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest

License

MIT ยฉ Alishen

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

koteguard-1.0.0a4.tar.gz (68.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

koteguard-1.0.0a4-py3-none-any.whl (54.7 kB view details)

Uploaded Python 3

File details

Details for the file koteguard-1.0.0a4.tar.gz.

File metadata

  • Download URL: koteguard-1.0.0a4.tar.gz
  • Upload date:
  • Size: 68.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for koteguard-1.0.0a4.tar.gz
Algorithm Hash digest
SHA256 cb2328c2309c1e3dedacf5c6c1814484a6443c03bbf25c97dcfcca88866be89f
MD5 df4793db353e4dff0bb10fc8665ba6f1
BLAKE2b-256 2213992bfbed02f14d667d5d79ab20a572876d515ab233563703ffdadfcad4b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for koteguard-1.0.0a4.tar.gz:

Publisher: release.yml on alisen/KoteGuard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file koteguard-1.0.0a4-py3-none-any.whl.

File metadata

  • Download URL: koteguard-1.0.0a4-py3-none-any.whl
  • Upload date:
  • Size: 54.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for koteguard-1.0.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 1fca7af75b22a2fbfae3ec6190a8694a199cba026dde83b8474e971e3b9fe1a2
MD5 1f3e04cf87ec9dac5bee58ec95cc0778
BLAKE2b-256 97faef1f16c3eea25cb7d4ca7c610711b5870510d4bfe00cee10bebe68120052

See more details on using hashes here.

Provenance

The following attestation bundles were made for koteguard-1.0.0a4-py3-none-any.whl:

Publisher: release.yml on alisen/KoteGuard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page