313 added, 1 removed. Audit C to A.
- PLACEHOLDER
+ ---
+ name: drive-persistence-bridge
+ description: Primary persistence layer. Automatically pushes every significant update (skills AND projects such as Pulverise) to GitHub + Google Drive with zero extra user commands. Handles skills library (Stijnman/grok-custom-skills + Drive folder 1jEivRtcNo-x9sd--2l1qe1bVox-TSnYK) and project repos (e.g. Stijnman/pulverise private). Event-driven: on version bump, skill edit, evolution, or explicit "update/save". Creates dated tar.gz, uploads via google_drive_upload_artifact, and commits via github___push_files / create_or_update_file. Exp backoff+jitter (10/30/60s ±25%), sandbox-aware, honest batch limits. Version 1.22 (MINOR) 2026-08-19: added mandatory auto-push of project updates (Pulverise etc.) to private GitHub + Drive on every versioned change.
+ ---
+
+ # Drive Persistence Bridge
+
+ ## Overview
+
+
+ ## Canonical Persistence Locations (2026-08-19)
+ ### Skills
+ - Google Drive folder: **Grok Skills Library**
+ - Folder ID: `1jEivRtcNo-x9sd--2l1qe1bVox-TSnYK`
+ - Link: https://drive.google.com/drive/folders/1jEivRtcNo-x9sd--2l1qe1bVox-TSnYK
+ - GitHub source of truth: `Stijnman/grok-custom-skills` (path `.grok/skills/`)
+
+ ### Projects (games / apps)
+ - **Pulverise** private repo: `Stijnman/pulverise` (default branch `main`)
+ - Drive project folder pattern: create/use `Pulverise-vX.Y.Z` (or latest) under the same root or a dedicated Projects parent; always upload dated `pulverise-vX.Y.Z-source.tar.gz` + VERSION/CHANGELOG/README docs
+ - Other user projects follow the same dual-target rule once a private repo name is known
+
+ ### Shared rules
+ - All skill changes must also update Persistent Memory via persistent-memory-bridge
+ - auto-skill-resolver is the preferred gatekeeper for the skill pipeline
+ - **Auto-push on every update is mandatory** (see § Auto-Push Contract below)
+
+ This skill acts as the **primary bridge** for persistent storage between the local AI ecosystem and Google Drive. It is built to be reliable, efficient, and intelligent, with strong support for versioning, conflict handling, and autonomous operation.
+
+ Its goal is to ensure that skills, memory, artifacts, and system state are safely stored, versioned, and synchronized without data loss, even during heavy autonomous improvement cycles.
+
+ ## Core Principles
+
+ - **Reliability first**: Never lose data.
+ - **Efficiency**: Use delta sync and smart batching.
+ - **Transparency**: Clear logging and user-friendly reporting.
+ - **Safety**: Strong conflict detection and safe resolution strategies.
+ - **Autonomy**: Works well in background during long self-improvement sessions.
+
+ ## Instructions
+
+ ### 0. Auto-Push Contract (MANDATORY — 2026-08-19)
+ Whenever the agent finishes a **significant update** (version bump, feature ship, skill edit, evolution cycle, or user says "update" / "save" / "backup"), it MUST automatically:
+
+ 1. **Package** a dated, versioned artifact (tar.gz preferred for trees; individual files for single-skill patches).
+ 2. **Upload to Google Drive** via `google_drive_upload_artifact` (relative path under `/home/workdir/artifacts/`, current date in filename `YYYYMMDD`).
+ 3. **Push to the correct private GitHub repo**:
+ - Skills → `owner=Stijnman`, `repo=grok-custom-skills`, path `.grok/skills/<name>/…` using `github___push_files` or `github___create_or_update_file`.
+ - Pulverise (and similar projects) → `owner=Stijnman`, `repo=pulverise`, path matching the project root (README, VERSION, CHANGELOG, src/… as needed). Prefer `github___push_files` for multi-file commits.
+ 4. **Log** success (file_id / commit url) to evolution_log.md or skill_sync_log.txt.
+ 5. **No extra user confirmation** — this is the default end-of-update behaviour.
+
+ Triggers that activate this contract automatically:
+ - Any change to `VERSION`, `package.json` version, or `CHANGELOG.md` of a tracked project
+ - Skill creation / deep edit / evolution cycle
+ - Explicit phrases: "update", "save", "backup", "push to github", "sync to drive", "put it in my repository"
+ - End of a multi-step implementation session that produced a playable / shippable delta
+
+ Retry: exp backoff+jitter 10s / 30s / 60s ±25%. On total failure, leave the local artifact and report the exact blocker; never claim the push succeeded.
+
+ ### 1. Save / Persist
+ - Accept different scopes: full ecosystem, specific skills, memory, projects (e.g. Pulverise), or artifacts.
+ - Always create timestamped, versioned backups.
+ - Store metadata: version, timestamp, checksum, description, and author (e.g. autonomous session or user).
+ - Support both manual and automatic triggers.
+ - **Reinforced Non-Negotiable Contract (2026-08-14 + 2026-08-19)**: Every new or significantly updated skill MUST be persisted to (1) local `/home/workdir/.grok/skills/`, (2) Google Drive via dated tar.gz + `google_drive_upload_artifact` into folder `1jEivRtcNo-x9sd--2l1qe1bVox-TSnYK`, and (3) GitHub `Stijnman/grok-custom-skills` at `.grok/skills/<name>/`. Every significant **project** update (Pulverise etc.) MUST likewise land in its private GitHub repo **and** Drive. This skill is the primary enforcer.
+
+ ### 2. Restore / Load
+ - List available versions with summaries.
+ - Allow selective restore of skills, memory, or specific files.
+ - Perform integrity checks (checksum validation) before applying.
+ - Support dry-run mode to preview changes before restoring.
+
+ ### 3. Sync & Versioning
+ - Perform bidirectional sync with change detection.
+ - Use **delta sync** — only upload/download what has changed.
+ - Maintain both local and remote version history.
+ - Support multiple conflict resolution strategies:
+ - Last-Write-Wins (default for low-risk files)
+ - Manual resolution for important files
+ - Smart merge where possible
+
+ ### 4. Full Skill Library Sync & Deduplication
+ - Scan both local and Drive for all skills.
+ - Compare versions using timestamps and checksums.
+ - Automatically keep the newest version of each skill.
+ - Remove duplicates and old versions.
+ - Upload the clean, deduplicated library back to Drive.
+ - Trigger automatically after major updates to critical skills.
+
+ ### 5. Autonomous & Background Behavior (Enforced - No User Input Required)
+ - Run smart intermittent auto-sync with adaptive frequency in background.
+ - **After each major update** (new skill creation, file changes, manifest update): Automatically trigger delta or full sync.
+ - **When there is a new evolution**: Ensure full autonomous sync runs before and after improvement cycles. No user input required.
+ - Increase sync frequency during heavy evolution or autonomous sessions.
+ - Create evolution-aware backups before and after major improvement cycles.
+ - Prioritize critical skills (skill-evolver, beta-unlocker, etc.) in the sync queue.
+ - Integrate with multi-agent-orchestrator and skill-evolution-engine for event-driven autonomous triggers.
+ - Background operation: Self-activates on ecosystem events; queues changes if Drive access limited.
+
+ ### 6. Error Handling & Resilience
+ - Implement retry logic with exponential backoff + jitter for failed uploads/downloads.
+ - Specific config per task: Base delays 10s (retry1), 30s (retry2), 60s (retry3) with ±25% jitter.
+ - Log exact error, retry number, and actual delay used.
+ - Detect when direct Google Drive upload is not available (sandbox limitations, no connected tool).
+ - Gracefully degrade: Continue full local operation and queue changes for later upload when Drive access is restored.
+ - Clearly inform the user/Master when uploads are blocked due to environment limitations.
+ - Alert Master on persistent failures after multiple retries. If all retries fail, state exact reason and suggest workaround (e.g., "No upload tool available", "Manual export needed").
+ - **Updated 2026-08-01 / 2026-08-07**: Confirmed google_drive_upload_artifact works for files placed in /home/workdir/artifacts/. For full skill library:
+ 1. `tar -czf /home/workdir/artifacts/skills-library-$(date +%Y%m%d).tar.gz -C /home/workdir/.grok skills/`
+ 2. Upload the .tar.gz via call_connected_tool(tool_name="google_drive_upload_artifact", arguments={"artifact_path": "/skills-library-YYYYMMDD.tar.gz"}) (note: path is relative to artifacts root; do NOT include /home/workdir/artifacts)
+ 3. On success record file_id + web_view_link.
+ Retry logic remains: base 10/30/60s ±25% jitter. Log exact error, retry #, actual delay. Always use current date for filename (e.g. 20260808). Explicit tool name and date command now documented for zero-ambiguity autonomous runs. Package only after real limited evolutions complete (honest batch limits). Never claim full-library deep evolution before packaging.
+ - Detect when direct Google Drive upload is not available (sandbox limitations, no connected tool).
+ - Gracefully degrade: Continue full local operation and queue changes for later upload when Drive access is restored.
+ - Clearly inform the user/Master when uploads are blocked due to environment limitations.
+ - Alert Master on persistent failures after multiple retries. If all retries fail, state exact reason and suggest workaround (e.g., "No upload tool available", "Manual export needed", "Package locally and upload via UI").
+ - **Updated 2026-07-01**: Enhanced with explicit sandbox check via bash `ls /home/workdir/artifacts` and tool availability detection before attempts.
+
+ ### 7. Environment Awareness
+ - Detects current environment capabilities (e.g., whether direct Google Drive upload is available).
+ - Provides clear status: "Direct Drive upload available" or "Running in limited environment – local storage + queued uploads active".
+ - Adapts behavior automatically based on available capabilities.
+
+ ### 8. Integration
+ - Works closely with `skill-evolver`, `skill-researcher` (or skill-evolution-engine), and `persistent-memory-bridge`. Note: skill-research-implementer does not exist as a distinct skill; use skill-researcher.
+ - Automatically backs up after significant autonomous changes.
+ - Supports future expansion to other storage backends (OneDrive, local NAS, etc.).
+ - **Post-Evolution Sync Hook**: After any evolution cycle (via skill-evolution-engine or skill-evolver), auto-trigger full library sync and manifest update. No user input. Load multi-agent-orchestrator and drive-persistence-bridge on evolution events for seamless autonomous flow.
+
+ ### 9. Automated Future Skill Syncs (Event-Driven & Hands-Free)
+ This section turns manual backups into fully automated, event-driven synchronization for all future skill activity. Once activated, the bridge ensures every new skill, edit, or evolution is safely versioned on Google Drive with zero extra user commands.
+
+ **Automatic Triggers (the agent handles these proactively):**
+ - Right after `skill-creator` finishes creating or updating any skill (including the one you just made).
+ - On any direct edit to a skill's `SKILL.md`, scripts/, references/, or assets/.
+ - Before + after every evolution cycle.
+ - On user phrases like "save skill", "sync skills", "automate future skill syncs", or "backup skills to drive".
+ - Background monitoring via ecosystem events (multi-agent-orchestrator, skill-evolution-engine, skill-creation-enabler).
+
+ **Standard Automated Sync Procedure (executed automatically by the agent):**
+ 1. Create fresh timestamped local backup of the entire skills library:
+ ```bash
+ python3 -c '
+ from pathlib import Path
+ import shutil
+ from datetime import datetime
+ LOCAL_SKILLS = Path("/home/workdir/.grok/skills")
+ ARTIFACTS = Path("/home/workdir/artifacts")
+ BACKUP_DIR = ARTIFACTS / "skill_backups"
+ BACKUP_DIR.mkdir(exist_ok=True)
+ ts = datetime.now().strftime("%Y%m%d-%H%M%S")
+ target = BACKUP_DIR / f"backup-{ts}"
+ shutil.make_archive(str(target), "gztar", LOCAL_SKILLS.parent, LOCAL_SKILLS.name)
+ print(f"[AUTO-SYNC] Local backup created: {target}.tar.gz")
+ '
+ ```
+ 2. Locate the newest file: `/home/workdir/artifacts/skill_backups/backup-*.tar.gz`
+ 3. Ensure Drive folder "Grok-Skills-Backups" exists (create via `google_drive_create_folder` if needed; reuse existing folder_id).
+ 4. Upload via connected tool:
+ ```json
+ call_connected_tool(
+ tool_name="google_drive_upload_artifact",
+ arguments={
+ "artifact_path": "/skill_backups/backup-YYYYMMDD-HHMMSS.tar.gz",
+ "file_name": "grok-skills-backup-YYYYMMDD-HHMMSS.tar.gz",
+ "folder_id": "1rPVUk57ScRDh0F70VmsE7pLRNITIzQQq"
+ }
+ )
+ ```
+ 5. (Recommended) Maintain a lightweight `skills-manifest.json` in the Drive folder for fast version lookup and selective restores.
+ 6. Append to local log: `/home/workdir/artifacts/skill_sync_log.txt` and optionally create a Drive note.
+
+ **Making Automation Permanent:**
+ - This bridge is now the **default post-action** for skill-creator, skill-evolver, and all skill-editing workflows.
+ - Future skill work will end with "...and the library has been automatically synced to Drive".
+ - The `drive-persistence-bridge` self-loads on relevant events via the orchestrator.
+ - **Projects (Pulverise et al.) follow the same rule**: after any versioned update the agent packages `pulverise-vX.Y.Z-source.tar.gz` (or equivalent), uploads to Drive, and pushes key files (README, VERSION, CHANGELOG, core src modules) to `Stijnman/pulverise` via `github___push_files`. No separate user command required.
+
+ ### 11. Project Auto-Push Procedure (Pulverise & similar)
+ Execute at the end of every significant project update:
+
+ 1. Confirm version string from `VERSION` / `package.json`.
+ 2. Package from the project root (e.g. `/workspace` or restored source tree):
+ ```bash
+ DATE=$(date +%Y%m%d)
+ VER=$(cat VERSION 2>/dev/null || echo "dev")
+ tar -czf /home/workdir/artifacts/pulverise-v${VER}-source.tar.gz \
+ --exclude=node_modules --exclude=.git -C /workspace .
+ ```
+ 3. Drive upload (relative path only):
+ ```
+ call_connected_tool(
+ tool_name="google_drive_upload_artifact",
+ arguments={
+ "artifact_path": "/pulverise-v${VER}-source.tar.gz",
+ "file_name": "pulverise-v${VER}-source-${DATE}.tar.gz"
+ }
+ )
+ ```
+ 4. GitHub multi-file push (prefer `github___push_files`):
+ - owner: `Stijnman`
+ - repo: `pulverise`
+ - branch: `main`
+ - files: at minimum `README.md`, `VERSION`, `CHANGELOG.md`, `PROMPT_AND_ROADMAP.txt`, and any changed core modules under `src/`
+ - message: `v${VER}: <short summary of this update>`
+ 5. Log commit URL + Drive file_id. Report both to the user in the final summary.
+ 6. On API failure: retry with 10/30/60s ±25% jitter; keep local tar.gz; never claim success.
+
+ ### 10. Retention Policy (Automatic Cleanup)
+ Detailed, production-ready retention rules are now enforced automatically after every sync/upload. This prevents unbounded growth while preserving history for recovery and auditing.
+
+ **Default Retention Rules (applied on every automated sync):**
+ - **Keep last 15 backups unconditionally** (rolling window of recent daily snapshots)
+ - **Delete any backup older than 180 days** (≈ 6 months)
+ - Always preserve at least the single most recent backup (hard safety minimum)
+ - Simple but effective: prioritizes recency; future versions can add calendar-based rules (e.g. "keep one per week for 4 weeks, one per month for 6 months")
+ - Local + Drive cleanup both respect the same policy for consistency
+ - Maximum practical storage: ~1.5–3 MB total for skills library backups (each ~0.1 MB)
+
+ **How Cleanup Works (Step 7 of every automated sync):**
+ 1. After successful Drive upload, call:
+ ```bash
+ python3 /home/workdir/.grok/skills/drive-persistence-bridge/scripts/sync_engine.py
+ ```
+ (The script now auto-runs `cleanup_old_backups()` when executed.)
+ 2. The function `cleanup_old_backups(keep_last=15, max_age_days=180)` in `sync_engine.py`:
+ - Lists all `backup-*.tar.gz` files sorted by modification time (newest first)
+ - Deletes files that exceed the keep_last count **or** are older than max_age_days
+ - Prints `[RETENTION] Deleted old backup: ...` for every removal
+ - Returns count of deleted files for logging
+ 3. Same logic can be applied to the Drive folder by the agent (list files via search, delete old ones using trash or direct delete if available).
+ 4. Every deletion is logged to `/home/workdir/artifacts/skill_sync_log.txt`
+
+ **Configuration (Current & Future):**
+ - Defaults are hardcoded in `cleanup_old_backups()` for reliability.
+ - Easy to override by editing the function call or adding a small `retention_config.json` in the skill folder (planned enhancement).
+ - User can trigger manual cleanup anytime: `python3 -c "from sync_engine import cleanup_old_backups; print(cleanup_old_backups(keep_last=10, max_age_days=90))"`
+
+ **Benefits:**
+ - Prevents Drive/local storage bloat
+ - Keeps rich recent history for quick rollbacks
+ - Long-term archives (up to 6 months) available for major incident recovery
+ - Fully automatic — no user action required
+ - Safe: never deletes the newest backup
+
+ **Current Backups Status (as of this update):**
+ Multiple timestamped backups now exist in `/home/workdir/artifacts/skill_backups/` and the Drive `Grok-Skills-Backups` folder. The retention policy will automatically prune older ones on the next sync.
+
+ ## User-Friendly Features
+
+ - Clear status reporting ("Sync complete", "X files uploaded", "Conflict resolved automatically").
+ - Dry-run mode for safe testing of sync/restore operations.
+ - Human-readable changelogs.
+ - Priority handling for critical files.
+ - Automatic cleanup of old versions with configurable retention.
+
+ ## Autonomous Evolution Cycle (2026-07-20)
+ - Added explicit support for the user-specified exponential backoff+jitter retry configuration in upload error handling.
+ - Enhanced sandbox awareness and transparent reporting for upload attempts.
+ - Strengthened error handling with user-specified exponential backoff + jitter (bases 10s/30s/60s ±25%).
+ - Version bumped to 2.1 (MINOR: updated for 2026-07-20 full library cycle, enhanced error logging for retries). Added concrete retry implementation stub matching user spec and enhanced sandbox detection.
+ - Added logging for exact errors, retry counts, delays.
+ - Improved integration with connected tools for Drive.
+
+ ## Current Full Autonomous Evolution Cycle (2026-07-21)
+ - Concrete improvement: Updated error handling section to fully match user retry config with logging of specific errors, retry numbers, delays with jitter. Enhanced upload procedure with retry loop example. Version bumped to 2.2. Real edit performed.
+
+ ## Honest Autonomous Cycle (2026-08-02)
+ - Version bumped to 1.8 (MINOR).
+ - Reinforced Honest Batch Limits compliance note: this skill is prioritized for real edits during full-library requests.
+ - Confirmed tar.gz packaging + google_drive_upload_artifact remains the canonical upload path.
+ - Transparent reporting only of actual changes.
+
+ ## Safety Rules
+
+ - Never delete files without creating a backup first.
+ - Always validate checksums before applying restores.
+ - Escalate complex conflicts to the user or Master instead of guessing.
+ - Maintain detailed audit logs of all sync and restore operations.
+
+ This skill is designed to be the most reliable and intelligent Drive connector in the ecosystem, especially suited for long-running autonomous self-improving agents.
+
+
+ **Evolution Note** (2026-05-23 16:54:31.560328): Applied batch improvements.
+
+ ## Autonomous Evolution Cycle (2026-06-21)
+ - Enhanced retry logic with exact user-specified exponential backoff + jitter implementation notes.
+ - Strengthened sandbox detection and logging for upload failures.
+ - Added explicit error detection and retry loop pseudocode for clarity.
+ - Version bumped to 1.3.
+
+ ## Full Library Evolution Cycle (2026-06-05)
+ - Enhanced error handling for uploads with specified exponential backoff and jitter as per task requirements.
+ - Improved sandbox awareness and fallback logging.
+ - Version bumped to 1.5. Integrated explicit exponential backoff + jitter retry logic (10s/30s/60s bases ±25% jitter) for all uploads, with detailed logging of errors, retries, delays. Strengthened sandbox awareness for environments without full Drive connectivity.
+ - Added retry configuration matching user specs.
+
+
+ ## Evolution Update (2026-05-27)
+ - Added structured error handling and retry logic.
+ - Enhanced integration with parallel-tool-orchestrator.
+ - Improved meta-reflection for better ROI tracking.
+ - Version bumped to 1.3
+
+
+ ## Auto-Evolution Patch (2026-05-31): Added general robustness note and version tracking.
+
+ ## Evolution Cycle (2026-06-30)
+ - Concrete improvement: Added explicit support for exponential backoff + jitter retry logic (bases 10/30/60s ±25%), sandbox transparency, transparent tool call reporting, and graceful Drive upload handling.
+ - Bumped version (MINOR). Enhanced clarity and integrations.
+ - 2026-07-20 Library Evolution: Added/strengthened exp backoff+jitter error handling, sandbox awareness, transparent reporting. Version MINOR bump.
+