# Sol Cycle

> Run one Self-Optimization Loop queue item through audit, validation, auto-mode or approval, patch application, Cortex save, and manifest update. Use when Pafi asks for sol-cycle or one SOL optimization cycle. ANTI-PATTERN: Do not use for general prompt optimization; use opt.

- Skill: `cryptopafi/sol-cycle` (Agent Skill)
- Install (CLI): `npx skillmds@latest add cryptopafi/sol-cycle`
- Raw SKILL.md: https://api.skillmd.com/api/skills/cryptopafi/sol-cycle/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: cryptopafi (https://skillmd.com/u/cryptopafi)
- Updated: 2026-09-21
- Page: https://skillmd.com/skills/cryptopafi/sol-cycle

---


<!-- GENERATED by forgebuild portable-skill v0.1.1; runtime=codex; core_sha256=90386c812f539862300bceb0e97ba7b3f5c3a941a5ddc3160d95f0b4f59bd63d; target_sha256=b6707f18c0febbf525b73fe6945b182ab45221ccc64c12131f6150645e3faf49; do not hand edit -->

# /sol-cycle - Self-Optimization Loop Cycle

Runtime-neutral SOL cycle behavior: process one optimization queue item through audit, validation, approval or auto-mode, patch application, Cortex persistence, and manifest update. Runtime-specific model routing, local paths, approval tooling, and queue implementation details live in target wrappers.

## Runtime Adapter

# SOL Cycle Skill

## Purpose
Execute one full SOL improvement cycle:
1. Pop highest-priority item from queue.json (P77 weight: 50 + invocation_count/10; unaudited=100, changed=80)
2. Dispatch Opus subagent to audit the prompt (32k thinking budget)
3. Validate audit JSON with sol-validate-audit.py
4. Write audit to ~/.nexus/optimization/audits/<id>.json
5. Run sol-auto-mode.py to either auto-apply safe audits or route critical/unsafe audits to human approval
6. On apply: run sol-apply.py, sol-cortex-save.sh, and manifest updates
7. Update manifest and queue

## Idempotency
If ~/.nexus/optimization/audits/<safe_id>.json already exists and is valid, skip audit subagent and go directly to auto-mode unless a fresh audit is explicitly requested by deleting the audit file or regenerating it before Step 4. Use Step 4 flags only for gate behavior: --dry-run, --force-human, or --force-auto.

## Lock
Acquire flock on ~/.nexus/optimization/.sol.lock at start. Exit 1 if already locked.

## Execution Flow

### Resilience (required — do not skip)
At cycle start, before any queue mutation:
1. Import and enter SOLCycle context manager from `~/.nexus/optimization/lib/sol_resilience.py`
2. Call `cycle_ctx.heartbeat_start()` immediately after
3. Call `cycle_ctx.phase("phase_name")` at each phase transition
4. Call `cycle_ctx.success(score_before, score_after)` on successful completion
5. The context manager handles all interrupt traps, distress Telegram, and flock automatically

### Step 1 — Pop queue
```python
import json
q = json.load(open(QUEUE_PATH))
if not q: exit("SOL queue empty")
item = q[0]  # already sorted by priority
id_ = item["id"]
target = item["path"]
safe_id = id_.replace("/", "_")
audit_file = AUDITS_DIR / f"{safe_id}.json"
```

### Step 2 — Audit subagent brief (model: claude-opus-4-8, thinking: 32000)
```
You are a prompt engineering auditor for NexusOS SOL.

TARGET FILE CONTENTS: <read target file>

Audit against NexusOS PE patterns. Produce a single JSON object (no markdown):
{
  "id": "<safe_id>",
  "target_path": "<absolute path>",
  "score_before": <0-100>,
  "score_after": <0-100>,
  "dimensions": {
    "claritate": <0-20>, "completitudine": <0-20>, "corectitudine": <0-20>,
    "focalizare": <0-20>, "adecvare": <0-20>
  },
  "findings": [{"pattern": "P6", "present": true, "impact": "..."}],
  "patch_diff": "<unified diff or empty>",
  "counter_argument": "<justification if score delta > 25, else empty>",
  "reasoning": "<max 40 words>",
  "created_at": "<ISO timestamp>"
}

SCORE INFLATION GUARD: If score_after - score_before > 25, counter_argument MUST be non-empty.
DIMENSIONS: claritate=clarity, completitudine=completeness, corectitudine=correctness,
            focalizare=focus, adecvare=agent-fit
PATTERNS: check P6,P7,P8,P10,P15,P17,P18,P20,P21,P23,P24,P25,P26,P29,P33,P70,P74,P77,P79

PATCH FORMAT (HARD — sol-apply.py rejects non-conformant diffs):
The `patch_diff` field MUST be a GNU-patch-compatible unified diff:
  1. Start with `--- a/<relative-or-absolute-path>` then `+++ b/<same-path>` headers
  2. Each hunk MUST start with `@@ -<old_line>,<old_count> +<new_line>,<new_count> @@`
  3. Each hunk MUST include at least 3 lines of UNCHANGED context above AND below the change (or fewer only if the file is shorter)
  4. Context lines start with a single space ` `
  5. Removed lines start with `-`; added lines start with `+`
  6. NO leading/trailing markdown fences inside the JSON string — just the raw diff text
  7. If no change is recommended (score_after == score_before), leave `patch_diff` as an empty string `""`

Example valid hunk:
  --- a/SKILL.md
  +++ b/SKILL.md
  @@ -10,5 +10,7 @@
   line 10 unchanged
   line 11 unchanged
   line 12 unchanged
  +new line A
  +new line B
   line 13 unchanged
```

### Step 3 — Validate
```bash
python3 ~/.nexus/optimization/sol-validate-audit.py "$audit_file"
# Exit 1 on failure — keep item in queue
```

### Step 4 — Auto-mode gate (hybrid: auto-apply or human approval)

Dispatch through `sol-auto-mode.py`, which classifies the audit and either:
- **Auto-applies** (score_after ≥ 85, delta ≤ 15, non-critical target, validation passes) → applies patch, saves to Cortex, appends manifest entry, and sends a Telegram notification.
- **Falls back to human approval** → calls sol-approval-gate.py, which spawns the inbox watcher before sending the Telegram message with APPROVE/REJECT inline buttons. LIS owns Telegram polling and forwards `sol:*` callbacks into the SOL inbox.

All outcomes are terminal — the loop continues to Step 5 with exit 0.

```bash
python3 ~/.nexus/optimization/sol-auto-mode.py "$safe_id"
```

Exit 0 = terminal state reached (auto-applied OR approved+applied OR rejected).

**Override flags:**
- `--dry-run` → prints verdict + reason, no side effects.
- `--force-human` → skip classification, go straight to approval gate.
- `--force-auto` → bypass classification, auto-apply directly (debug only).
- No bare `--force` flag is defined for this cycle.

### Step 5 — Pop item from queue (after gate returns 0)

### Step 6 — After apply (triggered by sol-apply-from-telegram.py):
- Run: bash ~/.nexus/optimization/sol-cortex-save.sh "$safe_id"
- Update manifest: status=optimized, last_score=score_after, best_score=max(old,new), audit_count+=1, last_audit=today
- Preserve baseline_improvements_pre_sol field unchanged

