code-with-codex
npx skills add https://github.com/chaorenex1/coding-workflow --skill code-with-codex
Agent 安装分布
Skill 文档
Code with Codex
Use memex-cli to leverage Codex for code generation with memory and resume support.
Mandatory Execution Protocol
â ï¸ CRITICAL: Claude MUST complete ALL applicable steps below BEFORE invoking memex-cli. Skipping any step is a protocol violation.
Step 1: Complexity Assessment (ALL Levels)
Required for: L1-L5
Use decision tree to determine complexity level:
Start
ââ Single file, <100 lines? â L1
ââ Reusable functions, no external deps? â L2
ââ Production module with tests?
â ââ Standard CRUD/API? â L3
â ââ Complex algorithm? â L4
ââ Multi-module/microservice? â L5
Output: Determined level (L1-L5) with reasoning.
Step 2: Task Decomposition (L3+ MANDATORY)
Required for: L3, L4, L5
Claude MUST decompose the task into subtasks:
- Identify all components/modules/files to be created
- Split into independent subtasks (each <300 lines output)
- Assign unique task IDs
- Establish dependency relationships
Skip condition: Only if task is truly atomic (single file, single responsibility)
Step 3: Dependency Analysis (L2+ MANDATORY)
Required for: L2, L3, L4, L5
Claude MUST analyze dependencies:
- File dependencies: Which files import/require others?
- Task dependencies: Which tasks must complete before others?
- Build DAG: Create directed acyclic graph of execution order
Output: Dependency graph showing parallel groups.
Step 4: Execution Plan Report (ALL Levels)
Required for: L1-L5
Claude MUST report to user before execution:
## ð Execution Plan Report
### Complexity Assessment
- **Level**: L[X] ([level name])
- **Model**: [selected model]
- **Reasoning**: [why this level]
### Task Decomposition (L3+)
| ID | Description | Est. Lines | Dependencies |
|----|-------------|------------|--------------|
| task-1 | [desc] | ~100 | - |
| task-2 | [desc] | ~150 | task-1 |
### Dependency Graph (L2+)
Phase 1 (Parallel): [task-1] [task-2] â â Phase 2 (Sequential): [task-3 depends on 1,2]
### Execution Summary
- **Total subtasks**: N
- **Parallel groups**: M
- **Estimated phases**: P
Step 5: Workdir Resolution (AUTO)
Required for: ALL tasks
Claude MUST resolve workdir to project root:
git rev-parse --show-toplevel
Rule: workdir = Git é¡¹ç®æ ¹ç®å½ï¼ç»å¯¹è·¯å¾ï¼
Output: Report resolved workdir in Execution Plan.
Pre-Execution Checklist
Before invoking memex-cli, Claude MUST confirm:
- â Complexity level determined (L1-L5)
- â Model selected based on level
- â (L2+) Dependencies analyzed
- â (L3+) Task decomposed into subtasks
- â Workdir resolved (via git root)
- â Execution plan reported to user
â VIOLATION: Directly passing L3/L4/L5 task to Codex without decomposition is a protocol violation. Always decompose first.
Execution Strategy
| Level | Model | files-mode | Dependency Analysis | Task Decomposition | Execution |
|---|---|---|---|---|---|
| L1 | gpt-5.1-codex-mini |
ref | â | â | Serial |
| L2 | gpt-5.1-codex-max |
ref | â | â | Parallel |
| L3 | gpt-5.2-codex |
ref | â | â | Parallel |
| L4 | gpt-5.2 |
ref | â | â | Parallel |
| L5 | gpt-5.2 |
ref | â | â | Parallel |
Automated Capabilities
| Capability | Description | Active Level |
|---|---|---|
| Auto Model Selection | Automatically select optimal model based on complexity | L1-L5 |
| Auto Grading | Evaluate task complexity via Decision Tree | L1-L5 |
| Dependency Analysis | Analyze task/file dependencies, build DAG | L2+ |
| Task Decomposition | Auto-split large tasks into subtasks | L3+ |
| Parallel Execution | Execute independent subtasks in parallel | L2+ |
Dependency Analysis Guide (L2+)
System automatically analyzes dependencies between tasks/files and builds execution DAG.
How It Works
Input: Multiple related tasks
â
âââââââââââââââââââââââââââââââ
â 1. Parse task descriptions â
â 2. Identify file references â
â 3. Detect implicit deps â
â 4. Build dependency graph â
âââââââââââââââââââââââââââââââ
â
Output: Execution DAG with parallel groups
Dependency Detection Rules
| Type | Detection Method | Example |
|---|---|---|
| Explicit | dependencies field |
dependencies: task-1, task-2 |
| File-based | OutputâInput file match | Task A outputs config.py â Task B imports it |
| Import-based | Module import analysis | from utils import helper â depends on utils |
| Sequential | Keyword detection | “based on”, “after”, “using result of” |
L2 Example: Parallel Validators with Dependencies
memex-cli run --backend codex --stdin <<'EOF'
---TASK---
id: email-validator
backend: codex
model: gpt-5.1-codex-max
workdir: ./utils
---CONTENT---
ç¼åé®ç®±éªè¯å½æ° (validators/email.py)
---END---
---TASK---
id: phone-validator
backend: codex
model: gpt-5.1-codex-max
workdir: ./utils
---CONTENT---
ç¼åææºå·éªè¯å½æ° (validators/phone.py)
---END---
---TASK---
id: validator-index
backend: codex
model: gpt-5.1-codex-max
workdir: ./utils
dependencies: email-validator, phone-validator
---CONTENT---
å建 validators/__init__.pyï¼å¯¼åºææéªè¯å½æ°
---END---
EOF
Execution Flow:
âââââââââââââââââââ âââââââââââââââââââ
â email-validator â â phone-validator â â Parallel (no deps)
ââââââââââ¬âââââââââ ââââââââââ¬âââââââââ
â â
ââââââââââââ¬ââââââââââ
â
âââââââââââââââââââ
â validator-index â â Sequential (depends on both)
âââââââââââââââââââ
Task Decomposition Guide (L3+)
System automatically decomposes large tasks into manageable subtasks.
How It Works
Input: Complex task description
â
âââââââââââââââââââââââââââââââ
â 1. Analyze task scope â
â 2. Identify components â
â 3. Generate subtask list â
â 4. Establish dependencies â
â 5. Assign to parallel groupsâ
âââââââââââââââââââââââââââââââ
â
Output: DAG of subtasks
Decomposition Triggers
| Trigger | Detection | Action |
|---|---|---|
| Multi-file | “create X files”, file list | Split by file |
| Multi-component | “module with A, B, C” | Split by component |
| Layered | “model, service, controller” | Split by layer |
| Test + Impl | “implement and test” | Split impl â test |
L3 Example: HTTP Client with Auto-Decomposition
Input Task:
memex-cli run --backend codex --stdin <<'EOF'
---TASK---
id: http-client-module
backend: codex
model: gpt-5.2-codex
workdir: ./lib
timeout: 5400
---CONTENT---
åå»ºå®æ´ç HTTP 客æ·ç«¯æ¨¡åï¼
1. æ ¸å¿å®¢æ·ç«¯ç±» (http_client.py)
2. éè¯çç¥ (retry.py)
3. æ¦æªå¨ç³»ç» (interceptors.py)
4. åå
æµè¯ (test_http_client.py)
---END---
EOF
Auto-Decomposed Execution:
Phase 1 (Parallel - No deps):
ââââââââââââââââ ââââââââââââââââ ââââââââââââââââââââ
â http_client â â retry â â interceptors â
â .py â â .py â â .py â
ââââââââ¬ââââââââ ââââââââ¬ââââââââ ââââââââââ¬ââââââââââ
â â â
âââââââââââââââââââ¼ââââââââââââââââââââ
â
Phase 2 (Sequential - Depends on all above):
âââââââââââââââââââââââ
â test_http_client.py â
âââââââââââââââââââââââ
L4/L5 Example: Microservice with Full Decomposition
Input Task:
memex-cli run --backend codex --stdin <<'EOF'
---TASK---
id: auth-service
backend: codex
model: gpt-5.2
workdir: ./services/auth
timeout: 9000
---CONTENT---
è®¾è®¡ç¨æ·è®¤è¯å¾®æå¡ï¼
- æ°æ®æ¨¡å (models/)
- ä¸å¡é»è¾ (services/)
- API ç«¯ç¹ (api/)
- æ°æ®åºè¿ç§» (migrations/)
- 宿´æµè¯å¥ä»¶ (tests/)
---END---
EOF
Auto-Decomposed Execution:
Phase 1: Foundation (Parallel)
ââââââââââââ ââââââââââââ
â models/ â â schemas/ â
â user.py â â auth.py â
ââââââ¬ââââââ ââââââ¬ââââââ
â â
ââââââââ¬âââââââ
â
Phase 2: Business Logic (Parallel, depends on Phase 1)
âââââââââââââââ âââââââââââââââ âââââââââââââââ
â services/ â â services/ â â services/ â
â auth.py â â token.py â â password.py â
ââââââââ¬âââââââ ââââââââ¬âââââââ ââââââââ¬âââââââ
â â â
ââââââââââââââââââ¼âââââââââââââââââ
â
Phase 3: API Layer (Sequential, depends on Phase 2)
âââââââââââââââââââââââââââââââââââ
â api/routes.py, api/middleware.pyâ
ââââââââââââââââââ¬âââââââââââââââââ
â
Phase 4: Database & Tests (Parallel, depends on Phase 3)
âââââââââââââââ âââââââââââââââ
â migrations/ â â tests/ â
âââââââââââââââ âââââââââââââââ
Model Selection Guide
| Model | Best For | Complexity |
|---|---|---|
| gpt-5.1-codex-mini | Simple scripts, quick fixes | â |
| gpt-5.1-codex-max | Utilities, production modules | ââ-âââ |
| gpt-5.2-codex | Code review, refactoring, testing | âââ |
| gpt-5.2 | Complex algorithms, architecture | ââââ-âââââ |
Auto selection rules:
- Model is automatically selected based on task complexity level
- Manual override available via
modelfield when needed - System optimizes for cost-efficiency while maintaining quality
Complexity Levels Overview
Level 1: Simple Scripts (â)
Quick utilities, single-file scripts (20-100 lines). Use gpt-5.1-codex-mini.
Examples: Batch file rename, CSV processing, disk monitoring
Quick example:
memex-cli run --backend codex --stdin <<'EOF'
---TASK---
id: batch-rename
backend: codex
model: gpt-5.1-codex-mini
workdir: /path/to/scripts
---CONTENT---
Pythonèæ¬ï¼æ¹ééå½åæä»¶ï¼æ·»å æ¥æåç¼
---END---
EOF
â Detailed examples: examples/level1-simple-scripts.md
Level 2: Utility Functions (ââ)
Reusable functions, data transformations (100-300 lines). Use gpt-5.1-codex-max.
Examples: Data validators, format converters, simple unit tests
Quick example:
memex-cli run --backend codex --stdin <<'EOF'
---TASK---
id: validators
backend: codex
model: gpt-5.1-codex-max
workdir: /path/to/utils
---CONTENT---
ç¼åé®ç®±ãææºå·ã身份è¯å·éªè¯å½æ°
---END---
EOF
â Detailed examples: examples/level2-utilities.md
Level 3: Complete Modules (âââ)
Production-ready modules with error handling, logging, tests (300-800 lines). Use gpt-5.2-codex.
Examples: HTTP clients, database helpers, API wrappers
Special tasks at Level 3:
- Code Review: Analyze code for security/performance issues
- Refactoring: Apply design patterns, improve testability
- Unit Testing: Comprehensive test coverage (>80%)
Quick example:
memex-cli run --backend codex --stdin <<'EOF'
---TASK---
id: http-client
backend: codex
model: gpt-5.2-codex
workdir: /path/to/lib
timeout: 5400
---CONTENT---
Python HTTP客æ·ç«¯ï¼æ¯æéè¯ãè¶
æ¶ãæ¦æªå¨
---END---
EOF
Code review example:
memex-cli run --backend codex --stdin <<'EOF'
---TASK---
id: review
backend: codex
model: gpt-5.2-codex
files: ./src/auth.py
files-mode: ref
workdir: /path/to/project
---CONTENT---
审æ¥ä»£ç ï¼å®å
¨éæ£ãæ§è½ç¶é¢ãæ¹è¿å»ºè®®
---END---
EOF
â Detailed examples: examples/level3-modules.md
Level 4: Complex Algorithms (ââââ)
Advanced data structures, optimized algorithms (500-1500 lines). Use gpt-5.2 with extended timeout.
Examples: Skip lists, pathfinding (Dijkstra, A*), expression parsers
Quick example:
memex-cli run --backend codex --stdin <<'EOF'
---TASK---
id: skiplist
backend: codex
model: gpt-5.2
workdir: /path/to/algorithms
timeout: 7200
---CONTENT---
å®ç°è·³è¡¨ï¼æ¯ææå
¥ãå é¤ãæç´¢ï¼O(log n)å¤æåº¦
---END---
EOF
â Detailed examples: examples/level4-algorithms.md
Level 5: System Design & Architecture (âââââ)
Multi-module projects, microservices, complete applications (2000+ lines). Use gpt-5.2 with 300-600s timeout.
Examples: Authentication microservices, event-driven systems, full-stack apps
Quick example:
memex-cli run --backend codex --stdin <<'EOF'
---TASK---
id: auth-service
backend: codex
model: gpt-5.2
workdir: /path/to/services/auth
timeout: 9000
---CONTENT---
è®¾è®¡ç¨æ·è®¤è¯å¾®æå¡ï¼JWTãOAuth2ãRBACæé模å
---END---
EOF
â Detailed examples: examples/level5-architecture.md
Basic Usage
Single Task
memex-cli run --backend codex --stdin <<'EOF'
---TASK---
id: task-id
backend: codex
workdir: /working/directory
model: gpt-5.2-codex
---CONTENT---
[Your task description]
---END---
EOF
Required Fields
| Field | Description | Example |
|---|---|---|
id |
Unique task identifier | impl-auth, test-validators |
backend |
Always codex for code generation |
codex |
workdir |
Working directory path | ./src, /home/user/project |
Optional Fields
| Field | Default | Description |
|---|---|---|
model |
gpt-5.2-codex | Model selection (see complexity guide) |
timeout |
1800 | Max execution time (seconds, 30min base, +30min per level) |
dependencies |
– | Comma-separated task IDs |
files |
– | Source files to reference |
files-mode |
ref | ref (path only) – unified across all levels |
retry |
0 | Retry count on failure |
Quick Reference
Complexity Decision Tree
Start
ââ Single file, <100 lines? â Level 1 (codex-mini)
ââ Reusable functions, no external deps? â Level 2 (codex)
ââ Production module with tests?
â ââ Standard CRUD/API? â Level 3 (gpt-5.1-codex-max)
â ââ Complex algorithm? â Level 4 (gpt-5.2)
ââ Multi-module/microservice? â Level 5 (gpt-5.2)
Task Type Classification
| Task Type | Level | Model | Example Link |
|---|---|---|---|
| Batch rename script | 1 | codex-mini | Level 1 |
| Email validator | 2 | gpt-5.1-codex-max | Level 2 |
| HTTP client with retry | 3 | gpt-5.2-codex | Level 3 |
| Code review | 3 | gpt-5.2-codex | Level 3 |
| Refactoring | 3-4 | gpt-5.2-codex / gpt-5.2 | Level 3 |
| Unit testing | 2-3 | gpt-5.1-codex-max / gpt-5.2-codex | Level 3 |
| Skip list algorithm | 4 | gpt-5.2 | Level 4 |
| Auth microservice | 5 | gpt-5.2 | Level 5 |
Additional Resources
Progressive Disclosure Documentation
-
HOW_TO_USE.md – Complete usage guide
- When to use this skill
- Relationship with memex-cli
- Model selection tips
- Workflow references
-
references/complexity-guide.md – Detailed complexity selection
- In-depth explanation of 5 levels
- Model performance comparison
- Decision tree and classification
- Best practices by task type
-
examples/ – Runnable code examples
- level1-simple-scripts.md – Quick utilities
- level2-utilities.md – Reusable functions
- level3-modules.md – Production modules, code review, refactoring
- level4-algorithms.md – Complex algorithms
- level5-architecture.md – System design
Advanced Workflows
For multi-task workflows, parallel execution, and resume functionality, refer to memex-cli skill:
- Multi-task DAG workflows: memex-cli/references/advanced-usage.md
- Parallel execution patterns: memex-cli/examples/parallel-tasks.md
- Resume interrupted runs: memex-cli/examples/resume-workflow.md
Tips
-
Match model to task complexity
- Start with lightweight models for simple tasks
- Upgrade to powerful models only when needed
- Save costs by not over-provisioning
-
Use files for context
- Code review:
files: ./src/auth.py(files-mode defaults toref) - Refactoring: Reference source files for analysis
- Unit testing: Reference module to test
- Code review:
-
Break down large tasks
- Split Level 5 projects into parallel Level 3-4 subtasks
- Use DAG workflows for dependencies
- See memex-cli advanced usage
-
Include context in prompts
- Specify language, framework, coding standards
- Mention target Python/Node.js version
- Include expected output format
-
Leverage examples
- Browse examples/ directory for similar tasks
- Copy and customize example commands
- Follow established patterns
SKILL Reference
- skills/memex-cli/SKILL.md – Memex CLI full documentation
- HOW_TO_USE.md – Detailed usage guide for this skill