Agent Light
安装指南
将指南地址发送给 Agent,让它按当前环境完成配置。首次使用步骤和灯光含义请查看使用说明。
本地设备连接适用于 macOS / Linux,提供 Claude Code、Codex CLI 和 Comate 的配置示例。其他 Agent 需另行适配。
查看本地安装指南全文(供 Agent 阅读)
# Agent Light Installation (for AI Agents)
This guide is for a USB-connected device on a local macOS or Linux machine.
It provides installation examples for Claude Code, Codex CLI and Comate.
For remote development, use the sibling `remote.md` on the website (source:
`docs/install_guide_for_agent_remote.md`). Windows setup is not covered here.
Use the target Agent explicitly named in the installation request, even if a
different Agent is carrying out the installation. If no target is named, confirm
the intended Agent with the user before editing its configuration. Merge Agent
Light hooks with existing hooks; preserve unrelated settings. If the Agent or installed
version does not support the listed events, report that limitation instead of
inventing a configuration. Comate's status handler requires Python 3.
## Step 1: Detect device
Run: ls /dev/cu.usbmodem* /dev/ttyACM* 2>/dev/null
If no output, ask user to check USB connection.
## Step 2: Create send script
Run these commands:
mkdir -p ~/.agent-light
cat > ~/.agent-light/send.sh << 'SCRIPT'
#!/bin/bash
STATE=${1:-I}
# 计算 session 槽位:slot 为 0-92 数字编号(便于日志阅读),再映射到可打印字符发送
# 字符映射:'!'(33)~'~'(126),跳过 '*'(42) → 93 个槽,降低多会话碰撞
if [ -n "$AGENT_LIGHT_SID" ]; then
SID=$AGENT_LIGHT_SID
SLOT=$AGENT_LIGHT_SID
else
SLOT=$(( PPID % 93 ))
code=$(( 33 + SLOT ))
[ "$code" -ge 42 ] && code=$(( code + 1 ))
SID=$(printf "\\$(printf '%03o' "$code")")
fi
# 日志记录(方便调试):slot 为数字编号,sid 为实际发送字符
LOG_FILE="/tmp/agent_light.log"
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S' 2>/dev/null)
echo "[$TIMESTAMP] slot=$SLOT sid=$SID state=$STATE" >> "$LOG_FILE"
# 发送到设备
if [[ "$OSTYPE" == "darwin"* ]]; then
PORT=$(ls /dev/cu.usbmodem* 2>/dev/null | head -1)
elif [[ "$OSTYPE" == "linux"* ]]; then
PORT=$(ls /dev/ttyACM* 2>/dev/null | head -1)
fi
[ -n "$PORT" ] && printf '%s%s' "$SID" "$STATE" > "$PORT"
SCRIPT
chmod +x ~/.agent-light/send.sh
## Step 3: Configure hooks for the target Agent
Configure only the target Agent selected above:
### If Claude Code:
Merge the following hooks into `~/.claude/settings.json`.
Light mapping:
- UserPromptSubmit → W (working)
- PreToolUse → W (working)
- PostToolUse → W (working)
- PostToolBatch → W (working)
- SubagentStart → W (working)
- PermissionRequest → P (waiting for approval)
- PermissionDenied → P (denied by auto mode, may retry)
- Notification (permission_prompt / idle_prompt / agent_needs_input) → P (waiting for user)
- StopFailure → E (turn ended on an API error — the only red trigger)
- Stop → I (idle)
- SessionStart → I (idle)
- SessionEnd → I (idle)
Agent Light hooks run synchronously with a short timeout so lifecycle state frames
remain ordered. Background hooks can overlap and let an older state overwrite a
newer one.
```json
{
"hooks": {
"UserPromptSubmit": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh W", "timeout": 3 }
]
}
],
"PreToolUse": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh W", "timeout": 3 }
]
}
],
"PostToolUse": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh W", "timeout": 3 }
]
}
],
"PostToolBatch": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh W", "timeout": 3 }
]
}
],
"SubagentStart": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh W", "timeout": 3 }
]
}
],
"PermissionRequest": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh P", "timeout": 3 }
]
}
],
"PermissionDenied": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh P", "timeout": 3 }
]
}
],
"Notification": [
{
"matcher": "permission_prompt|idle_prompt|agent_needs_input",
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh P", "timeout": 3 }
]
}
],
"StopFailure": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh E", "timeout": 3 }
]
}
],
"Stop": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh I", "timeout": 3 }
]
}
],
"SessionStart": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh I", "timeout": 3 }
]
}
],
"SessionEnd": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh I", "timeout": 3 }
]
}
]
}
}
```
### If Codex CLI:
Merge the following hooks into `~/.codex/hooks.json`.
Reference: [official Codex Hooks documentation](https://learn.chatgpt.com/docs/hooks).
Light mapping:
- UserPromptSubmit / PreToolUse / PostToolUse → W (working)
- PreCompact / PostCompact → W (working)
- SubagentStart / SubagentStop → W (parent turn is still working)
- SessionStart (source=compact) → W (continue working after compaction)
- PermissionRequest → P (waiting for approval)
- SessionStart (source=startup / resume / clear) → I (idle)
- Stop / SessionEnd → I (idle)
- No reliable terminal success or error event → do not emit S or E
Codex supports background hooks, but Agent Light deliberately uses synchronous
hooks with a short timeout. Status frames must preserve lifecycle order; background
hooks may finish out of order and allow an older I/P frame to overwrite a newer W.
```json
{
"hooks": {
"SessionStart": [
{
"matcher": "startup|resume|clear",
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh I", "timeout": 3 }
]
},
{
"matcher": "compact",
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh W", "timeout": 3 }
]
}
],
"UserPromptSubmit": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh W", "timeout": 3 }
]
}
],
"PreToolUse": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh W", "timeout": 3 }
]
}
],
"PostToolUse": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh W", "timeout": 3 }
]
}
],
"PreCompact": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh W", "timeout": 3 }
]
}
],
"PostCompact": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh W", "timeout": 3 }
]
}
],
"SubagentStart": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh W", "timeout": 3 }
]
}
],
"SubagentStop": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh W", "timeout": 3 }
]
}
],
"PermissionRequest": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh P", "timeout": 3 }
]
}
],
"Stop": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh I", "timeout": 3 }
]
}
],
"SessionEnd": [
{
"hooks": [
{ "type": "command", "command": "~/.agent-light/send.sh I", "timeout": 3 }
]
}
]
}
}
```
After installing the hooks, complete the trust review in Codex CLI. If `codex` is
not available in your terminal, install it with the official macOS/Linux installer:
```bash
curl -fsSL https://chatgpt.com/codex/install.sh | sh
```
Start Codex:
```bash
codex
```
When the hook review appears, select:
```text
2. Trust all and continue
```
If the review does not open automatically, run `/hooks` in Codex CLI. After the
hooks are trusted, restart the Codex session in VS Code.
### Other Agents:
Cursor, CodeBuddy and TRAE require a separate integration. Do not install an
empty or guessed hooks file using this guide. Explain the limitation and consult
the installed Agent's Hook documentation before adapting the configuration.
### If Comate:
Create `~/.agent-light/comate-stop.py` to map the Stop event's status. Confirm
`python3` is available first; if it is missing, report the prerequisite.
```bash
cat > ~/.agent-light/comate-stop.py << 'PYTHON'
import json
import subprocess
import sys
from pathlib import Path
try:
event = json.load(sys.stdin)
except (ValueError, TypeError):
event = {}
status = event.get("status") if isinstance(event, dict) else None
state = {"completed": "S", "error": "E", "cancelled": "I"}.get(status, "I")
subprocess.run([str(Path.home() / ".agent-light" / "send.sh"), state], check=False)
PYTHON
```
Working events send W. Only `Stop` with `status=error` sends E; ordinary tool
failures stay in the working flow. `Stop` with `status=completed` sends S,
`status=cancelled` sends I. Comate has no native waiting-for-approval event.
Merge into `~/.comate/hooks.json`:
```json
{
"hooks": {
"UserPromptSubmit": [
{
"hooks": [
{
"type": "command",
"command": "~/.agent-light/send.sh W",
"timeout": 5
}
]
}
],
"PreToolUse": [
{
"hooks": [
{
"type": "command",
"command": "~/.agent-light/send.sh W",
"timeout": 5
}
]
}
],
"PostToolUse": [
{
"hooks": [
{
"type": "command",
"command": "~/.agent-light/send.sh W",
"timeout": 5
}
]
}
],
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "python3 ~/.agent-light/comate-stop.py",
"timeout": 5
}
]
}
],
"SessionEnd": [
{
"hooks": [
{
"type": "command",
"command": "~/.agent-light/send.sh I",
"timeout": 5
}
]
}
]
}
}
```
Note: Comate does not have a direct equivalent for `PermissionRequest` or
`TaskCompleted` events. Success and terminal error are derived from `Stop.status`.
## Step 4: Verify installation
Run the following on the local machine:
```bash
AGENT_LIGHT_TEST_PORT=$(ls /dev/cu.usbmodem* /dev/ttyACM* 2>/dev/null | head -1)
if [ -n "$AGENT_LIGHT_TEST_PORT" ]; then
printf '*C' > "$AGENT_LIGHT_TEST_PORT"
else
echo 'Agent Light serial device not found'
fi
```
The device LEDs should flash in sequence (red → yellow → green) for 3 seconds.
This confirms serial communication only. Then submit a simple task in a fresh
Agent session: the green LED should breathe while the Agent works, and normally
turn off when the response ends (Comate may show solid green for 2 seconds first).
Do not report installation as verified until an actual Agent task drives the LED.
If serial testing works but Agent activity does not, check Hook loading, supported
events and any Agent-specific trust or restart step.
## Troubleshooting
- No device: check the USB-C connection and try a different data-capable port.
If using a cable or hub, verify data transmission is supported.
- Permission denied (Linux): inspect the serial device's owner/group and use the
system's serial-access group or device permission mechanism.
- Permission denied (macOS): allow accessory in System Settings > Privacy