Skip to main content

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

Project description

koteguard.com Python 3.12+ Version Platform MIT License Tests

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 (alpha branch):

git clone https://github.com/alisen/KoteGuard.git
cd KoteGuard
git checkout alpha/v1.0.0-alpha.1
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. When the agent is done โ€” validate + merge back
kote cleanup --accept

# 5. 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 Validate โ†’ merge โ†’ archive history
kote cleanup --discard Throw away changes, preserve audit trail
kote cleanup --accept --force Accept even when validation has errors
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

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   # 196 tests, all green

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.0a1.tar.gz (65.2 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.0a1-py3-none-any.whl (53.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: koteguard-1.0.0a1.tar.gz
  • Upload date:
  • Size: 65.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for koteguard-1.0.0a1.tar.gz
Algorithm Hash digest
SHA256 69b3c0b420f8c0ef40359f1fadf9e85d8db49fc1b5377e842256a51358c68775
MD5 6b9099ca748197f95695d5a0ccf56d45
BLAKE2b-256 3800763ee2e7e77406aaac456e788509d28deded7abba4f2d58c1f8a44dc6c5e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: koteguard-1.0.0a1-py3-none-any.whl
  • Upload date:
  • Size: 53.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for koteguard-1.0.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 6c347855f83bd500abaf9197df4216e45cd31da473b0b5cc9ff290e8ea7f3e0e
MD5 0e57fe9f34b366f0f7b624d639009c50
BLAKE2b-256 81f8915ab6def2f34aeae0540aa8582ce18e42bec7c4249531f3b645c153a183

See more details on using hashes here.

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