message-injector

TotalClaw 作者 totalclaw

OpenClaw 插件,可在每条用户消息到达代理之前为其添加自定义文本。用于:在回复之前强制执行内存搜索、注入系统级指令、为每个对话回合添加持久提醒。作为工作区扩展安装 - 适用于所有渠道,包括 WebChat、Telegram、Slack 等。

安装 / 下载方式

TotalClaw CLI推荐
totalclaw install totalclaw:totalclaw~harukaon-message-injector
cURL直接下载,无需登录
curl -fsSL https://skills.taituai.com/api/skills/totalclaw%3Atotalclaw~harukaon-message-injector/file -o harukaon-message-injector.md
# Message Injector

A lightweight OpenClaw workspace extension that uses the `before_agent_start` hook to inject custom text into every user message via `prependContext`.

## Installation

### 1. Create the extension directory

```bash
mkdir -p ~/.openclaw/workspace/.openclaw/extensions/message-injector
```

### 2. Copy the plugin files

Copy `scripts/index.ts` and `scripts/openclaw.plugin.json` to the extension directory:

```bash
cp scripts/index.ts ~/.openclaw/workspace/.openclaw/extensions/message-injector/
cp scripts/openclaw.plugin.json ~/.openclaw/workspace/.openclaw/extensions/message-injector/
```

### 3. Add configuration

Add the following to `~/.openclaw/openclaw.json` under `plugins.entries`:

```json
"message-injector": {
  "enabled": true,
  "config": {
    "enabled": true,
    "prependText": "Your custom text here"
  }
}
```

### 4. Restart Gateway

```bash
openclaw gateway restart
```

## Configuration

| Field | Type | Default | Description |
|-------|------|---------|-------------|
| `enabled` | boolean | `true` | Enable or disable the injector |
| `prependText` | string | `""` | Text to prepend before every user message |

## Example Use Cases

**Force memory search:**
```json
"prependText": "[⚠️ 回答前必须先 memory_search 检索相关记忆,禁止凭印象回答]"
```

**Add persistent context:**
```json
"prependText": "[当前项目:my-app | 技术栈:React + Node.js | 部署环境:AWS]"
```

**Inject safety rules:**
```json
"prependText": "[RULE: Always verify file paths before deletion. Never run rm -rf without confirmation.]"
```

## How It Works

The plugin registers a `before_agent_start` hook. When triggered, it returns `{ prependContext: prependText }` which OpenClaw prepends to the user's message before the agent processes it. This is a hard injection at the Gateway level — the agent cannot skip or ignore it.

## Source Code

GitHub: https://github.com/Harukaon/openclaw-message-injector

---

## 中文说明

# Message Injector

一个轻量级的 OpenClaw 工作区扩展,它使用 `before_agent_start` 钩子,通过 `prependContext` 将自定义文本注入到每条用户消息中。

## 安装

### 1. 创建扩展目录

```bash
mkdir -p ~/.openclaw/workspace/.openclaw/extensions/message-injector
```

### 2. 复制插件文件

将 `scripts/index.ts` 和 `scripts/openclaw.plugin.json` 复制到扩展目录:

```bash
cp scripts/index.ts ~/.openclaw/workspace/.openclaw/extensions/message-injector/
cp scripts/openclaw.plugin.json ~/.openclaw/workspace/.openclaw/extensions/message-injector/
```

### 3. 添加配置

将以下内容添加到 `~/.openclaw/openclaw.json` 的 `plugins.entries` 下:

```json
"message-injector": {
  "enabled": true,
  "config": {
    "enabled": true,
    "prependText": "Your custom text here"
  }
}
```

### 4. 重启 Gateway

```bash
openclaw gateway restart
```

## 配置

| 字段 | 类型 | 默认值 | 说明 |
|-------|------|---------|-------------|
| `enabled` | boolean | `true` | 启用或禁用注入器 |
| `prependText` | string | `""` | 在每条用户消息前添加的文本 |

## 示例用例

**强制内存搜索:**
```json
"prependText": "[⚠️ 回答前必须先 memory_search 检索相关记忆,禁止凭印象回答]"
```

**添加持久上下文:**
```json
"prependText": "[当前项目:my-app | 技术栈:React + Node.js | 部署环境:AWS]"
```

**注入安全规则:**
```json
"prependText": "[RULE: Always verify file paths before deletion. Never run rm -rf without confirmation.]"
```

## 工作原理

该插件注册了一个 `before_agent_start` 钩子。当被触发时,它返回 `{ prependContext: prependText }`,OpenClaw 会在代理处理用户消息之前将其添加到消息前面。这是在 Gateway 层级的硬注入——代理无法跳过或忽略它。

## 源代码

GitHub: https://github.com/Harukaon/openclaw-message-injector