Fix OpenClaw review issues

This commit is contained in:
YeonGyu-Kim
2026-03-16 22:28:54 +09:00
parent b79df5e018
commit c644930753
14 changed files with 412 additions and 194 deletions
+28 -20
View File
@@ -9,7 +9,9 @@ import { getCurrentTmuxSession, captureTmuxPane } from "./tmux"
import { startReplyListener, stopReplyListener } from "./reply-listener"
import type { OpenClawConfig, OpenClawContext, OpenClawPayload, WakeResult } from "./types"
const DEBUG = process.env.OMX_OPENCLAW_DEBUG === "1"
const DEBUG =
process.env.OMO_OPENCLAW_DEBUG === "1"
|| process.env.OMX_OPENCLAW_DEBUG === "1"
function buildWhitelistedContext(context: OpenClawContext): OpenClawContext {
const result: OpenClawContext = {}
@@ -18,7 +20,7 @@ function buildWhitelistedContext(context: OpenClawContext): OpenClawContext {
if (context.tmuxSession !== undefined) result.tmuxSession = context.tmuxSession
if (context.prompt !== undefined) result.prompt = context.prompt
if (context.contextSummary !== undefined) result.contextSummary = context.contextSummary
if (context.reason !== undefined) result.reason = context.reason
if (context.reasoning !== undefined) result.reasoning = context.reasoning
if (context.question !== undefined) result.question = context.question
if (context.tmuxTail !== undefined) result.tmuxTail = context.tmuxTail
if (context.replyChannel !== undefined) result.replyChannel = context.replyChannel
@@ -34,27 +36,27 @@ export async function wakeOpenClaw(
): Promise<WakeResult | null> {
try {
if (!config.enabled) return null
const resolved = resolveGateway(config, event)
if (!resolved) return null
const { gatewayName, gateway, instruction } = resolved
const now = new Date().toISOString()
const replyChannel = context.replyChannel ?? process.env.OPENCLAW_REPLY_CHANNEL
const replyTarget = context.replyTarget ?? process.env.OPENCLAW_REPLY_TARGET
const replyThread = context.replyThread ?? process.env.OPENCLAW_REPLY_THREAD
const enrichedContext: OpenClawContext = {
...context,
...(replyChannel !== undefined && { replyChannel }),
...(replyTarget !== undefined && { replyTarget }),
...(replyThread !== undefined && { replyThread }),
}
const tmuxSession = enrichedContext.tmuxSession ?? getCurrentTmuxSession() ?? undefined
let tmuxTail = enrichedContext.tmuxTail
if (!tmuxTail && (event === "stop" || event === "session-end") && process.env.TMUX) {
try {
@@ -62,11 +64,16 @@ export async function wakeOpenClaw(
if (paneId) {
tmuxTail = (await captureTmuxPane(paneId, 15)) ?? undefined
}
} catch {
// Ignore
} catch (error) {
if (DEBUG) {
console.error(
"[openclaw] failed to capture tmux tail:",
error instanceof Error ? error.message : error,
)
}
}
}
const variables: Record<string, string | undefined> = {
sessionId: enrichedContext.sessionId,
projectPath: enrichedContext.projectPath,
@@ -74,7 +81,7 @@ export async function wakeOpenClaw(
tmuxSession,
prompt: enrichedContext.prompt,
contextSummary: enrichedContext.contextSummary,
reason: enrichedContext.reason,
reasoning: enrichedContext.reasoning,
question: enrichedContext.question,
tmuxTail,
event,
@@ -83,12 +90,12 @@ export async function wakeOpenClaw(
replyTarget,
replyThread,
}
const interpolatedInstruction = interpolateInstruction(instruction, variables)
variables.instruction = interpolatedInstruction
let result: WakeResult
if (gateway.type === "command") {
result = await wakeCommandGateway(gatewayName, gateway, variables)
} else {
@@ -107,14 +114,14 @@ export async function wakeOpenClaw(
...(replyThread !== undefined && { threadId: replyThread }),
context: buildWhitelistedContext(enrichedContext),
}
result = await wakeGateway(gatewayName, gateway, payload)
}
if (DEBUG) {
console.error(`[openclaw] wake ${event} -> ${gatewayName}: ${result.success ? "ok" : result.error}`)
}
return result
} catch (error) {
if (DEBUG) {
@@ -125,7 +132,8 @@ export async function wakeOpenClaw(
}
export async function initializeOpenClaw(config: OpenClawConfig): Promise<void> {
if (config.enabled && (config.discordBotToken || config.telegramBotToken)) {
const replyListener = config.replyListener
if (config.enabled && (replyListener?.discordBotToken || replyListener?.telegramBotToken)) {
await startReplyListener(config)
}
}