Skip to content

Commit e8c3e10

Browse files
committed
Merge pull request #49 from Kirchberg/codex/codex-skill-first-upstream
Make Codex integration skill-first
2 parents 1b2652c + d31e9d9 commit e8c3e10

8 files changed

Lines changed: 112 additions & 68 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ harvest session transcripts → mine recurring tasks → replay offline
8080
| Platform | Folder | Install |
8181
|---|---|---|
8282
| **Claude Code** | [`plugins/claude-code`](plugins/claude-code) | `/plugin marketplace add ./plugins/claude-code``/skillopt-sleep` |
83-
| **Codex** | [`plugins/codex`](plugins/codex) | `bash plugins/codex/install.sh``/skillopt-sleep` |
83+
| **Codex** | [`plugins/codex`](plugins/codex) | `bash plugins/codex/install.sh``skillopt-sleep` skill |
8484
| **Copilot** | [`plugins/copilot`](plugins/copilot) | register `plugins/copilot/mcp_server.py` as an MCP server |
8585

8686
**Validated on real models.** On the public

docs/sleep/PR_DRAFT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Synthesizes SkillOpt (validation-gated bounded text edits), Claude Dreams
1515
Shipped as plugins for **three agents**, one engine + three thin shells:
1616

1717
- **Claude Code**`.claude-plugin` + `/sleep` command + skill + hooks
18-
- **Codex**`~/.codex/prompts/sleep.md` + `~/.agents/skills` + `install.sh`
18+
- **Codex**user-level `skillopt-sleep` skill + shared runner + `install.sh`
1919
- **Copilot** — a stdlib-only MCP server exposing `sleep_*` tools
2020

2121
## Design notes

docs/sleep/plugin_load_test.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ from scratch for this test. Two forms were used:
2323
| Shell | What was run | Result |
2424
|---|---|---|
2525
| **Claude Code** (`scripts/sleep.sh`) | `harvest`, full `run`, `adopt` | harvest found 2 sessions → 2 tasks; `run` staged a proposal; `adopt` honored the safety contract (no live change when nothing was accepted) |
26-
| **Codex** (`install.sh` + shared runner) | `install.sh` into a temp HOME | placed `~/.codex/prompts/sleep.md` and `~/.agents/skills/skillopt-sleep/SKILL.md` correctly |
26+
| **Codex** (`install.sh` + shared runner) | `install.sh` into a temp HOME | placed the user-level `~/.agents/skills/skillopt-sleep/SKILL.md` skill correctly and moved any legacy custom prompt aside instead of installing one |
2727
| **Copilot** (`mcp_server.py`) | `initialize``tools/list``tools/call sleep_harvest` | 5 tools listed; `sleep_harvest` returned real engine output (2 sessions → 2 tasks) |
2828

2929
### Genuine improvement (real model, fresh persona)
@@ -71,6 +71,6 @@ Shell checks:
7171
# Copilot MCP server
7272
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' \
7373
| SKILLOPT_SLEEP_REPO="$(pwd)" python3 plugins/copilot/mcp_server.py
74-
# Codex installer (into a throwaway HOME)
74+
# Codex skill installer (into a throwaway HOME)
7575
HOME=$(mktemp -d) bash plugins/codex/install.sh
7676
```

plugins/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ sleep** idea (short-term experience → long-term competence).
2020
2121
---
2222

23+
| Platform | Folder | Mechanism | Status |
24+
|---|---|---|---|
25+
| **Claude Code** | [`claude-code/`](claude-code) | `.claude-plugin` + `/skillopt-sleep` command + skill + hooks | full, installable |
26+
| **Codex** | [`codex/`](codex) | user-level `skillopt-sleep` skill + shared runner | full |
27+
| **Copilot** | [`copilot/`](copilot) | MCP server (`sleep_*` tools) + `copilot-instructions` | full (MCP) |
28+
2329
## Install (pick your agent)
2430

2531
| Platform | Install | Then |

plugins/codex/README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,35 @@ as the Claude Code plugin (`skillopt_sleep`), wrapped for Codex.
1414
## What Codex supports (and what we use)
1515

1616
Codex (`@openai/codex`) extends via **`AGENTS.md`** instructions, **skills** at
17-
`~/.agents/skills/<name>/SKILL.md`, and **custom prompts** at
18-
`~/.codex/prompts/<name>.md` (invoked as `/<name>`). This integration ships all
19-
three, plus a shared runner.
17+
`~/.agents/skills/<name>/SKILL.md`, and plugins that can distribute skills.
18+
Custom prompts are deprecated in Codex, so this integration is skill-first: the
19+
installed `skillopt-sleep` skill contains the launch commands and operating
20+
rules. The shared runner remains a plain shell entrypoint that the skill calls.
2021

2122
## Install
2223

2324
```bash
2425
git clone <repo-url> SkillOpt-Sleep
2526
cd SkillOpt-Sleep
26-
bash plugins/codex/install.sh # installs the /skillopt-sleep prompt + skill
27+
bash plugins/codex/install.sh # installs the skill
2728
export SKILLOPT_SLEEP_REPO="$(pwd)" # so the runner is found from anywhere
2829
```
2930

31+
If a previous install created `~/.codex/prompts/sleep.md`, the installer moves
32+
that deprecated prompt aside with a `.skillopt-legacy*.bak` suffix.
33+
3034
Requires Python ≥ 3.10 and the `codex` CLI on PATH.
3135

3236
## Use
3337

38+
Mention `$skillopt-sleep` where Codex supports explicit skill mentions, or ask
39+
Codex in natural language:
40+
3441
```text
35-
/skillopt-sleep status # what's happened
36-
/skillopt-sleep dry-run # safe preview, stages nothing
37-
/skillopt-sleep run # full cycle, stages a reviewed proposal (no live edits)
38-
/skillopt-sleep adopt # apply the staged proposal (with backup)
42+
Use the skillopt-sleep skill to run status for this project.
43+
Use the skillopt-sleep skill to run a dry-run for this project.
44+
Use the skillopt-sleep skill to run the full cycle for this project with the Codex backend.
45+
Use the skillopt-sleep skill to adopt the latest staged proposal.
3946
```
4047

4148
Or call the engine directly:
@@ -53,7 +60,7 @@ identically — see [`../../docs/sleep/CONTROLLABLE_DREAMING.md`](../../docs/sle
5360

5461
- Codex's `exec` runs shell, so the real-tool-loop replay (e.g. the
5562
`tool_called: search` benchmark seed) works natively.
56-
- Codex's standalone *plugin-package manifest* format is not yet a stable public
57-
spec; this integration uses the documented `AGENTS.md` + skills + prompts
58-
mechanisms, which are stable. If/when a `codex plugin` package format ships,
59-
we'll add a one-file manifest.
63+
- This integration no longer installs a `.codex/prompts` slash command. Skills
64+
are the reusable Codex workflow surface; mention `skillopt-sleep` explicitly
65+
or ask for a sleep/dream/offline self-improvement run and Codex can load the
66+
skill.

plugins/codex/install.sh

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
#!/usr/bin/env bash
2-
# Install the SkillOpt-Sleep Codex integration into the user's ~/.codex and
3-
# ~/.agents directories. Idempotent; prints what it does.
2+
# Install the SkillOpt-Sleep Codex integration as a user-level Codex skill.
3+
# Idempotent; prints what it does.
44
set -euo pipefail
55

66
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
77
CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
88
AGENTS_SKILLS="${HOME}/.agents/skills"
9+
LEGACY_PROMPT="$CODEX_HOME/prompts/sleep.md"
910

1011
echo "[install] repo: $REPO_ROOT"
1112

12-
# 1) custom /skillopt-sleep prompt
13-
mkdir -p "$CODEX_HOME/prompts"
14-
cp "$REPO_ROOT/plugins/codex/prompts/skillopt-sleep.md" "$CODEX_HOME/prompts/skillopt-sleep.md"
15-
echo "[install] /skillopt-sleep prompt -> $CODEX_HOME/prompts/skillopt-sleep.md"
16-
17-
# 2) user-level skill
13+
# 1) user-level skill
1814
mkdir -p "$AGENTS_SKILLS/skillopt-sleep"
1915
cp "$REPO_ROOT/plugins/codex/skills/skillopt-sleep/SKILL.md" "$AGENTS_SKILLS/skillopt-sleep/SKILL.md"
2016
echo "[install] skill -> $AGENTS_SKILLS/skillopt-sleep/SKILL.md"
2117

18+
# 2) retire the old custom prompt entrypoint from previous installs
19+
if [ -f "$LEGACY_PROMPT" ]; then
20+
backup="${LEGACY_PROMPT}.skillopt-legacy.bak"
21+
if [ -e "$backup" ]; then
22+
backup="${LEGACY_PROMPT}.skillopt-legacy.$(date +%Y%m%d%H%M%S).bak"
23+
fi
24+
mv "$LEGACY_PROMPT" "$backup"
25+
echo "[install] legacy prompt -> $backup"
26+
fi
27+
2228
# 3) record the repo location so the runner is found from anywhere
2329
echo "[install] add to your shell profile:"
2430
echo " export SKILLOPT_SLEEP_REPO=\"$REPO_ROOT\""
@@ -29,8 +35,10 @@ cat <<EOF
2935
[install] Optional — add this to ~/.codex/AGENTS.md so Codex always knows the tool:
3036
3137
## SkillOpt-Sleep
32-
An offline self-improvement cycle is available. To run it:
33-
\`bash "$REPO_ROOT/plugins/run-sleep.sh" status\`. Use \`/skillopt-sleep\` for the guided flow.
38+
Use the skillopt-sleep skill when I ask to run a sleep/dream/offline
39+
self-improvement cycle. The runner is:
40+
\`bash "$REPO_ROOT/plugins/run-sleep.sh" status --project "\$(pwd)"\`.
3441
35-
Done. Try: /skillopt-sleep status
42+
Done. Try asking Codex:
43+
Use the skillopt-sleep skill to run status for this project.
3644
EOF

plugins/codex/prompts/skillopt-sleep.md

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,93 @@
11
---
22
name: skillopt-sleep
3-
description: Nightly offline self-evolution for a Codex agent. Reviews past sessions, replays recurring tasks, and consolidates validated memory + skills behind a held-out gate. Use when the user wants Codex to learn from past usage, run a "sleep"/"dream" cycle, or schedule offline self-optimization.
3+
description: "Use when the user wants Codex to self-improve from past usage, asks about a nightly/offline 'sleep' or 'dream' cycle, wants Codex to review past sessions, learn preferences, consolidate memory/skills, run dry-run/run/adopt/status for SkillOpt-Sleep, or schedule offline self-optimization. Drives the skillopt_sleep engine: harvest past sessions -> mine recurring tasks -> replay offline -> consolidate validated memory + skills behind a held-out gate."
44
---
55

6-
# SkillOpt-Sleep (Codex skill)
6+
# SkillOpt-Sleep: offline self-evolution for a local Codex agent
77

8-
This skill drives the `skillopt_sleep` engine — an offline "sleep cycle" that
9-
makes a Codex agent better at the user's recurring work without retraining.
8+
SkillOpt-Sleep gives the user's Codex agent a sleep cycle. While the user is
9+
offline or on demand, it reviews past local sessions, re-runs recurring tasks
10+
on the user's own budget, and consolidates what it learns into memory and
11+
skills. It keeps only changes that pass a held-out validation gate, and live
12+
files change only after the user explicitly adopts a staged proposal. There is
13+
no model-weight training.
1014

1115
## When to use
1216

13-
Trigger when the user wants to: review past sessions, learn their preferences,
14-
consolidate feedback into long-term memory/skills, run a nightly/offline
15-
self-improvement cycle, or adopt a staged proposal.
17+
Trigger when the user wants any of:
1618

17-
## How to run it
19+
- Codex to learn from past sessions or get better the more they use it;
20+
- a nightly/scheduled or on-demand sleep/dream/offline self-improvement run;
21+
- to review past sessions and distill recurring tasks;
22+
- to consolidate feedback into memory or managed skills;
23+
- to run `status`, `harvest`, `dry-run`, `run`, or `adopt` for SkillOpt-Sleep.
24+
25+
## The cycle
26+
27+
1. **Harvest** - read local session transcripts according to the engine
28+
configuration and normalize them into session digests.
29+
2. **Mine** - turn digests into recurring `TaskRecord`s with outcomes and
30+
checkable references where possible.
31+
3. **Replay** - re-run mined tasks offline under the current skill and memory.
32+
4. **Consolidate** - reflect on failures and propose bounded edits.
33+
5. **Gate** - accept edits only when the held-out validation score improves.
34+
6. **Stage** - write the proposal under
35+
`<project>/.skillopt-sleep/staging/<date>/`; nothing live changes.
36+
7. **Adopt** - only after explicit user approval, copy staged files over live
37+
files with backups.
38+
39+
## How to drive it
1840

1941
Invoke the bundled runner via shell (Codex `exec` has shell access). The runner
20-
finds the engine and a Python 3.10 automatically:
42+
finds the engine and a Python >= 3.10 automatically.
2143

2244
```bash
2345
# point at the repo if it isn't auto-detected from CWD:
2446
export SKILLOPT_SLEEP_REPO=/path/to/SkillOpt-Sleep
25-
bash "$SKILLOPT_SLEEP_REPO/plugins/run-sleep.sh" <action> --project "$(pwd)"
47+
48+
bash "$SKILLOPT_SLEEP_REPO/plugins/run-sleep.sh" status --project "$(pwd)"
49+
bash "$SKILLOPT_SLEEP_REPO/plugins/run-sleep.sh" harvest --project "$(pwd)"
50+
bash "$SKILLOPT_SLEEP_REPO/plugins/run-sleep.sh" dry-run --project "$(pwd)" --backend mock
51+
bash "$SKILLOPT_SLEEP_REPO/plugins/run-sleep.sh" run --project "$(pwd)" --backend codex
52+
bash "$SKILLOPT_SLEEP_REPO/plugins/run-sleep.sh" adopt --project "$(pwd)"
2653
```
2754

28-
`<action>``status | dry-run | run | adopt | harvest`. Use `--backend codex`
29-
for real improvement on the user's own Codex budget (default `mock` = no spend).
55+
Actions are `status`, `harvest`, `dry-run`, `run`, and `adopt`.
56+
57+
- Default backend is `mock`, which is deterministic and spends no API budget.
58+
- `--backend codex` uses the user's Codex budget for real improvement.
59+
- Keep `dry-run --backend mock` as the first smoke check unless the user
60+
explicitly asked for a real optimization run.
3061

3162
## Steps
3263

3364
1. Run the requested action; capture stdout.
34-
2. For `run`/`dry-run`: read the staged `report.md` it prints and show the user
35-
the held-out baseline → candidate score and the exact proposed edits.
36-
3. `run` only **stages** a proposal under `<project>/.skillopt-sleep/staging/`;
37-
nothing live changes until `adopt`. Offer `/skillopt-sleep adopt`.
38-
4. Never hand-edit the user's `AGENTS.md` / skills yourself — only `adopt` does,
39-
and it backs up first.
65+
2. For `dry-run` and `run`, report the held-out baseline -> candidate score,
66+
gate action, task count, session count, and exact proposed edits.
67+
3. If a staging directory is printed, read `report.md` before summarizing.
68+
4. `run` only stages a proposal; nothing live changes until `adopt`.
69+
5. Offer adoption only after the user has reviewed the staged proposal.
70+
6. Never hand-edit the user's `AGENTS.md`, memory, or skills as a substitute
71+
for `adopt`; adoption is the safety boundary and writes backups first.
72+
73+
## Hard rules
74+
75+
- Harvest is read-only. Do not edit archived sessions or raw transcripts.
76+
- Keep raw secrets, credentials, private user data, and unsanitized transcript
77+
contents out of messages, logs, generated artifacts, and commits.
78+
- Show validation evidence before recommending adoption.
79+
- Treat generated edits as proposals, not as source of truth.
80+
- Do not rely on deprecated custom prompts or `/sleep` slash commands for this
81+
Codex integration. This skill is the entrypoint.
4082

4183
## Validate
4284

4385
```bash
86+
python -m skillopt_sleep dry-run --project "$(pwd)" --backend mock --json
4487
python -m skillopt_sleep.experiments.run_gbrain --backend codex \
4588
--seeds brief-writer --data-root /path/to/gbrain-evals/eval/data/skillopt-v1 \
4689
--nights 2 --limit-replay 3 --limit-holdout 3
4790
```
48-
A deficient skill goes 0.00 → 1.00 on a held-out set; the optimizer's edits are
49-
gated on real-task performance.
91+
92+
A deficient skill goes 0.00 -> 1.00 on a held-out set; the optimizer's edits
93+
are gated on real-task performance.

0 commit comments

Comments
 (0)