Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
!.agents/**
!.github
!.github/**
!claude/.claude-plugin
!claude/.claude-plugin/**
.tts
.reflection
.opencode/
Expand All @@ -28,9 +30,18 @@ test/mocks/
evals/results/
evals/evals/

# Raw CC stop datasets (contain real user session data — never commit)
evals/datasets/cc-stop-candidates-raw.jsonl
evals/datasets/cc-stop-candidates-filtered.jsonl
evals/datasets/cc-stop-classified.jsonl
# Allow committing the redacted gold set only
!evals/datasets/cc-stop-labeled-gold-redacted.jsonl

# E2E eval reports
.eval/
.eval-tmp/

# Working notes
plan.md
# Added by code-review-graph
.code-review-graph/
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
## @reflection-3.ts - push opencode agent to reflect on the task, useful for continuous interrupted runs
<img width="1472" height="972" alt="image" src="https://github.com/user-attachments/assets/40f3a752-4b84-4151-93f4-2614330ac653" />

## @claude/ - Claude Code reflection plugin (experimental)
Port of the reflection idea to Claude Code as a `Stop` hook. Classifies the last assistant turn into one of six categories (complete, working, waiting_for_user_legitimate, tool_available_punt, summary_drift_stop, genuinely_stuck) with Claude Haiku 4.5, and re-prompts the agent when it punted to the user, drifted into "summary + next step + stop", or halted mid-thought. Honors `stop_hook_active` loop guard and caps at 3 inject cycles per session. Install with `claude --plugin-dir ./claude` for dev or via the marketplace once published. See [`claude/README.md`](claude/README.md). Baseline classifier accuracy and dataset are tracked in [`evals/datasets/README.md`](evals/datasets/README.md) and follow-up [#138](https://github.com/dzianisv/opencode-plugins/issues/138).

## @telegram.ts - integrates with Telegram over [t.me/OpencodeMgrBot](@OpenCodeMgrBot) bot
<img width="1019" height="734" alt="image" src="https://github.com/user-attachments/assets/6f120c14-dba5-431b-a458-0f51f360f561" />
@tts.ts - uses coqui TTS to read the opencode agent response. Useful to run a few agents on macOS and be notified when one finishes a task.
Expand Down
13 changes: 13 additions & 0 deletions claude/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "reflection-cc",
"version": "0.1.0",
"description": "Re-prompts Claude Code when it stops prematurely due to failure modes like summary-drift-stop or tool-available-punt",
"author": "dzianisv",
"license": "MIT",
"hooks": {
"stop": {
"command": "${CLAUDE_PLUGIN_ROOT}/bin/reflect.mjs",
"timeout": 30000
}
}
}
80 changes: 80 additions & 0 deletions claude/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# reflection-cc

Re-prompts Claude Code when it stops prematurely due to failure modes like summary-drift-stop or tool-available-punt. This plugin intercepts the Stop hook, analyzes the session transcript using Claude Haiku, classifies the failure reason, and decides whether to re-prompt with recovery instructions or accept the stop.

## Install

**Recommended (works today, CC v2.x):** add the Stop hook directly to `~/.claude/settings.json`:

```json
{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "/absolute/path/to/opencode-plugins/claude/bin/reflect.mjs",
"timeout": 30
}
]
}
]
}
}
```

The plugin manifest under `.claude-plugin/` is included for future marketplace publication, but in CC v2.1.150 `--plugin-dir` and the `enabledPlugins` config path do NOT activate `Stop` hooks for headless `-p` sessions. The settings-based install above is the authoritative path until that gap closes.

**One-session try:** `claude --settings '<json above>'` ... or write the JSON to a file and pass `--settings ./reflect-settings.json`.

## Failure Categories

The classifier maps each Stop into one of these categories (only the first three trigger an inject):

| Category | Inject? | Description |
|----------|---------|-------------|
| `summary_drift_stop` | **yes** | Agent wrote a plan with a "next step" then stopped before doing it |
| `tool_available_punt` | **yes** | Agent asked the user about something an available tool could resolve |
| `genuinely_stuck` | **yes** | Agent halted mid-thought, no question, no plan |
| `complete` | no | Task finished |
| `working` | no | Mid-action narration (rare at Stop) |
| `waiting_for_user_legitimate` | no | Agent legitimately needs user input |

## How it works

1. **Stop Hook**: Claude Code invokes the Stop hook when the agent terminates
2. **Transcript Analysis**: Haiku classifies the session transcript into failure categories
3. **Verdict**: Judge decides to re-prompt with recovery instructions or accept the stop
4. **Session Guards**: Loop prevention via attempt counter (max 3 cycles per session)

## Testing

`node claude/test/e2e-cc.mjs` runs 4 real E2E scenarios:

- `explicit_wait_negative` — user asked "wait" → plugin must not inject.
- `complete_negative` — trivial Q&A → plugin must not inject.
- `attempt_cap_respected` — multi-file task → cap honored.
- `direct_pipe_summary_drift` — synthetic drift transcript piped to `reflect.mjs` → verifies the inject pathway end-to-end including schema-correct stdout.

Real `claude -p` headless sessions + real Anthropic API. No stubs. Costs roughly $0.05–0.20 per scenario via Haiku 4.5 over your Max-subscription OAuth. Out of CI (auth + cost). Run before any change to the hook payload format.

## Configuration

Environment variables:
- `REFLECTION_CC_DEBUG=1` — Enable debug output
- `REFLECTION_CC_MODEL` — Model for classification (default: `haiku-4-5`)
- `REFLECTION_CC_MAX_ATTEMPTS=3` — Max re-prompt cycles per session

## Disk Artifacts

Plugin stores local transcripts and verdicts:
- `.reflection/verdict_<sid>.json` — Haiku verdict + recovery instructions
- `.reflection/<sid>_<ts>.json` — Full transcript snapshot
- `.reflection/<sid>_attempts.json` — Attempt counter for session

**Privacy**: Transcripts stored locally only; never sent externally except to Haiku during classification.

## Status

Experimental. Baseline accuracy numbers pending PR evaluation.
Loading
Loading