correction-memory

TotalClaw 作者 totalclaw v1.1.0

使代理更正持久且可重用。当您覆盖、拒绝或更正代理的输出时,此技能会记录更正并自动将其注入到相同代理类型的未来生成中。解决“代理在各个会话中不断犯同样的错误”的问题。将 Correction-Tracker lib + Injection hook 安装到 Agent-Context-Loader 中。可以独立工作,也可以与意图工程技能一起工作。

安装 / 下载方式

TotalClaw CLI推荐
totalclaw skills install shop:totalclaw:totalclaw~donovanpankratz-del-correction-memory
cURL直接下载,无需登录
curl -fsSL https://skills.taituai.com/api/skills/totalclaw%3Atotalclaw~donovanpankratz-del-correction-memory/file -o donovanpankratz-del-correction-memory.md
# Correction Memory

## The Problem

When you correct an agent, that correction evaporates after the session. Next time you spawn the same agent type, it makes the same mistake. There's no memory of what you've already taught it.

## What This Skill Installs

- **`lib/correction-tracker.js`** — logs corrections per agent type to `memory/corrections/[AgentType].jsonl`
- **Hook into `agent-context-loader.js`** — correction preamble prepended to spawns automatically (if intent-engineering is also installed)

## Installation

### Step 1 — Install correction-tracker

```bash
cp references/correction-tracker-template.js $OPENCLAW_WORKSPACE/lib/correction-tracker.js
```

Verify it runs:

```bash
node $OPENCLAW_WORKSPACE/lib/correction-tracker.js
```

### Step 2 — Wire agent-context-loader (if using intent-engineering)

If `lib/agent-context-loader.js` is installed (from intent-engineering skill), correction injection is **automatic** — no wiring needed. The loader checks for `correction-tracker.js` at startup and loads it if present.

If you are NOT using intent-engineering, add this to your spawn logic manually:

```javascript
const { buildCorrectionPreamble } = require('./lib/correction-tracker');

const agentType   = 'CoderAgent'; // or whatever agent you're spawning
const corrections = buildCorrectionPreamble(agentType, workspaceRoot);
const fullTask    = corrections ? corrections + '\n\n---\n\n' + originalTask : originalTask;
```

## Logging Corrections

### Programmatic

```javascript
const { logCorrection } = require('./lib/correction-tracker');

logCorrection(
  'CoderAgent',                                    // agent type
  'Used ESM import instead of require()',          // what was wrong
  'Always use require() for Node.js stdlib modules', // correct behavior
  workspaceRoot,
  { session_channel: 'discord' }                  // optional metadata
);
```

### Via main agent (natural language)

Just tell the main agent:

> "Note that [AgentType]: [what it did wrong] — [correct behavior]"

The main agent will log it programmatically.

## How Corrections Are Replayed

On every subagent spawn, `agent-context-loader` detects the agent type from the task description and prepends:

```
## Corrections from Previous Sessions

The following corrections were logged for CoderAgent. Apply these behaviors:

1. **[2026-03-01] Issue:** Used ESM import instead of require()
   **Correction:** Always use require() for Node.js stdlib modules
```

Only corrections from the **last 30 days** are injected. Older corrections expire automatically — stale rules don't accumulate.

## Viewing Corrections

```bash
# All corrections for an agent type
cat $OPENCLAW_WORKSPACE/memory/corrections/CoderAgent.jsonl | jq .

# List all agent types with corrections
ls $OPENCLAW_WORKSPACE/memory/corrections/

# Count corrections per agent
for f in $OPENCLAW_WORKSPACE/memory/corrections/*.jsonl; do
  echo "$(basename $f .jsonl): $(wc -l < $f) corrections"
done
```

## Agent Type Detection

The loader auto-detects agent type from the task description. Default rules:

| Task keywords | Agent type |
|---|---|
| `code`, `coder`, `impl`, `debug` | `CoderAgent` |
| `writ`, `author`, `novel`, `chapter` | `AuthorAgent` |
| `world`, `build` | `WorldbuilderAgent` |
| (anything else) | `general` |

To add custom agent types, edit `detectAgentType()` in `agent-context-loader.js`.

## References

- `references/correction-tracker-template.js` — Full implementation of correction-tracker.js

---

## 中文说明

# Correction Memory

## 问题所在

当你纠正一个代理时,该纠正会在会话结束后蒸发。下一次你生成相同类型的代理时,它又会犯同样的错误。它对你已经教过的内容没有任何记忆。

## 此技能安装的内容

- **`lib/correction-tracker.js`** —— 按代理类型将纠正记录到 `memory/corrections/[AgentType].jsonl`
- **挂接到 `agent-context-loader.js`** —— 纠正前言会自动添加到生成内容前(如果同时安装了 intent-engineering)

## 安装

### 第 1 步 —— 安装 correction-tracker

```bash
cp references/correction-tracker-template.js $OPENCLAW_WORKSPACE/lib/correction-tracker.js
```

验证其运行:

```bash
node $OPENCLAW_WORKSPACE/lib/correction-tracker.js
```

### 第 2 步 —— 接入 agent-context-loader(如果使用 intent-engineering)

如果已安装 `lib/agent-context-loader.js`(来自 intent-engineering 技能),纠正注入是**自动的** —— 无需接线。loader 会在启动时检查 `correction-tracker.js`,并在存在时加载它。

如果你**没有**使用 intent-engineering,请手动将以下内容添加到你的生成逻辑中:

```javascript
const { buildCorrectionPreamble } = require('./lib/correction-tracker');

const agentType   = 'CoderAgent'; // or whatever agent you're spawning
const corrections = buildCorrectionPreamble(agentType, workspaceRoot);
const fullTask    = corrections ? corrections + '\n\n---\n\n' + originalTask : originalTask;
```

## 记录纠正

### 编程方式

```javascript
const { logCorrection } = require('./lib/correction-tracker');

logCorrection(
  'CoderAgent',                                    // agent type
  'Used ESM import instead of require()',          // what was wrong
  'Always use require() for Node.js stdlib modules', // correct behavior
  workspaceRoot,
  { session_channel: 'discord' }                  // optional metadata
);
```

### 通过主代理(自然语言)

只需告诉主代理:

> "Note that [AgentType]: [what it did wrong] — [correct behavior]"

主代理会以编程方式记录它。

## 纠正如何被重放

在每次生成子代理时,`agent-context-loader` 会从任务描述中检测代理类型,并在前面添加:

```
## Corrections from Previous Sessions

The following corrections were logged for CoderAgent. Apply these behaviors:

1. **[2026-03-01] Issue:** Used ESM import instead of require()
   **Correction:** Always use require() for Node.js stdlib modules
```

只有**最近 30 天**内的纠正才会被注入。较旧的纠正会自动过期 —— 陈旧规则不会累积。

## 查看纠正

```bash
# All corrections for an agent type
cat $OPENCLAW_WORKSPACE/memory/corrections/CoderAgent.jsonl | jq .

# List all agent types with corrections
ls $OPENCLAW_WORKSPACE/memory/corrections/

# Count corrections per agent
for f in $OPENCLAW_WORKSPACE/memory/corrections/*.jsonl; do
  echo "$(basename $f .jsonl): $(wc -l < $f) corrections"
done
```

## 代理类型检测

loader 会从任务描述中自动检测代理类型。默认规则:

| 任务关键词 | 代理类型 |
|---|---|
| `code`, `coder`, `impl`, `debug` | `CoderAgent` |
| `writ`, `author`, `novel`, `chapter` | `AuthorAgent` |
| `world`, `build` | `WorldbuilderAgent` |
| (其他任何内容) | `general` |

要添加自定义代理类型,请编辑 `agent-context-loader.js` 中的 `detectAgentType()`。

## 参考

- `references/correction-tracker-template.js` —— correction-tracker.js 的完整实现