# Codex Deep

> Conducts first-principles technical research, mathematical derivations, algorithm design, and cross-domain invention for complex engineering challenges. Generates timestamped research specifications and mathematical models inside codex-drive/specs/.

- Skill: `wwwroot/codex-deep` (Agent Skill)
- Install (CLI): `npx skillmds@latest add wwwroot/codex-deep`
- Raw SKILL.md: https://api.skillmd.com/api/skills/wwwroot/codex-deep/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Research & Search
- Author: wwwroot (https://skillmd.com/u/wwwroot)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/wwwroot/codex-deep

---


# Codex Deep — First-Principles Research & Invention Skill

> The deep research and invention engine of AI Codex. Explores theoretical foundations, derives mathematical proofs, invents novel algorithms, and solves problems where no conventional solution exists.

---

## Overview

`codex-deep` is designed for engineering challenges that require stepping outside standard libraries and patterns. It approaches problems from first principles — stripping away conventional assumptions, analyzing theoretical physics/math/computational limits, designing bespoke data structures or algorithms, and producing rigorous research artifacts in `codex-drive/specs/`.

---

## When to Trigger

- User runs `/codex-deep` (e.g., `/codex-deep invent lock-free ring buffer for GPU-CPU shared memory`, `/codex-deep mathematical modeling of token bucket rate limiter`, `/codex-deep design spatial partitioning grid for 1M entities`)
- When confronting hard computational limits (latency, throughput, cache contention, mathematical optimization)
- Designing custom algorithms, protocols, compression codecs, or memory layouts

---

## Execution Workflow

```
 ┌────────────────────────────────────────────────────────┐
 │ 1. STRIP TO FIRST PRINCIPLES & FUNDAMENTAL INVARIANTS  │
 │    Define the problem in terms of physics, math & CLR. │
 └──────────────────────────┬─────────────────────────────┘
                            │
                            ▼
 ┌────────────────────────────────────────────────────────┐
 │ 2. THEORETICAL DERIVATION & MATHEMATICAL PROOF         │
 │    Formulate formulas, state invariants, complexity.   │
 └──────────────────────────┬─────────────────────────────┘
                            │
                            ▼
 ┌────────────────────────────────────────────────────────┐
 │ 3. ALGORITHM & DATA STRUCTURE SYNTHESIS                │
 │    Design pseudo-code, memory layout, and access paths.│
 └──────────────────────────┬─────────────────────────────┘
                            │
                            ▼
 ┌────────────────────────────────────────────────────────┐
 │ 4. GENERATE TIMESTAMPED RESEARCH SPEC IN CODEX-DRIVE   │
 │    Write codex-drive/specs/YYYY-MM-DD-<slug>.research.md│
 └──────────────────────────┬─────────────────────────────┘
                            │
                            ▼
 ┌────────────────────────────────────────────────────────┐
 │ 5. TRANSITION TO PROTOTYPING & BENCHMARKS              │
 │    Recommend verification harness via /codex-test.     │
 └────────────────────────────────────────────────────────┘
```

---

## Research Spec File Specification (`codex-drive/specs/`)

All research documents generated by `codex-deep` MUST be Markdown (`.md`) files with exact date-time metadata.

### Filename Format:
`codex-drive/specs/YYYY-MM-DD-<slug>.research.md`

### Standard Research Document Template:

```markdown
# [Topic / Invention Name] Technical Research & Proof

> **Created At**: YYYY-MM-DD HH:MM:SS (Local Time)
> **Active Codex Edition**: [`skills/codex/<edition>/`](file:///...)
> **Status**: THEORETICAL_DRAFT | VALIDATED | BENCHMARKED
> **Domain**: [e.g., Lock-Free Concurrency / High-Performance Computing / Algorithmic Geometry]

---

## 1. Problem Statement & First-Principles Framing
- **Surface Problem**: [What is conventionally stated]
- **Fundamental Root Problem**: [Physical / mathematical constraint: memory bus bandwidth, CPU cache line false sharing, $O(N^2)$ algorithmic wall]
- **Conventional Assumptions Rejected**: [Why existing off-the-shelf solutions fail]

## 2. Mathematical Modeling & Theoretical Limits
- **Formulation**:
  $$\text{Throughput}(N) = \frac{C \cdot \text{CacheLineSize}}{\text{AtomicContentionTime}(N) + \text{MemoryLatency}}$$
- **Complexity Guarantees**:
  - Time Complexity: Best Case $O(1)$, Worst Case $O(1)$ amortized
  - Space Complexity: $O(K)$ fixed contiguous buffer (Zero Heap Allocations)

## 3. Algorithm & Memory Layout Synthesis

```
  Cache Line 0 (64 Bytes)             Cache Line 1 (64 Bytes)
┌───────────────────────────────────┬───────────────────────────────────┐
│ Head Pointer (Atomic u64, 8B)     │ Tail Pointer (Atomic u64, 8B)     │
│ Cache Padding (56B)               │ Cache Padding (56B)               │
└───────────────────────────────────┴───────────────────────────────────┘
```

### Pseudo-Code / Reference Logic:
```rust
// Core algorithmic state without false sharing
pub struct LockFreeRingBuffer<T, const CAPACITY: usize> {
    head: CachePadded<AtomicU64>,
    tail: CachePadded<AtomicU64>,
    slots: [UnsafeCell<Slot<T>>; CAPACITY],
}
```

## 4. Invariant Analysis & Safety Proofs
- **Invariant 1**: Head index never exceeds Tail index plus Buffer Capacity.
- **Invariant 2**: Atomic memory ordering (Acquire/Release) ensures data visibility before index update.
- **Deadlock Freedom**: Zero locking primitives; progress is guaranteed by compare-and-swap (CAS) loops.

## 5. Potential Failure Modes & Mitigation
- **ABA Problem**: Solved via 64-bit monotonic sequence tags.
- **Cache Contention**: Solved via explicit hardware cache-line padding (64/128 bytes).

## 6. Prototyping & Benchmarking Strategy
- Recommendation to execute microbenchmarks and stress tests via `/codex-test`.
```

---

## Response Protocol

When `codex-deep` finishes:
1. Provide a direct link to `[View Research Spec](file:///.../codex-drive/specs/YYYY-MM-DD-<slug>.research.md)`.
2. Summarize the theoretical breakthrough, algorithmic guarantees, or mathematical proofs.
3. Suggest next steps: `/codex-plans` for integration, or `/codex-test` for microbenchmarking.

