refactor(cli,mcp,openclaw): remove AI slop from code comments
This commit is contained in:
@@ -89,11 +89,9 @@ export function resolveGateway(
|
||||
return null
|
||||
}
|
||||
|
||||
// Validate based on gateway type
|
||||
if (gateway.type === "command") {
|
||||
if (!gateway.command) return null
|
||||
} else {
|
||||
// HTTP gateway
|
||||
if (!gateway.url) return null
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,6 @@ export async function wakeCommandGateway(
|
||||
try {
|
||||
const timeout = resolveCommandTimeoutMs(gatewayConfig.timeout)
|
||||
|
||||
// Interpolate variables with shell escaping
|
||||
const interpolated = gatewayConfig.command.replace(/\{\{(\w+)\}\}/g, (_match, key) => {
|
||||
const value = variables[key]
|
||||
if (value === undefined) return _match
|
||||
|
||||
@@ -82,7 +82,6 @@ function writeSecureFile(filePath: string, content: string): void {
|
||||
try {
|
||||
chmodSync(filePath, SECURE_FILE_MODE)
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +97,6 @@ function rotateLogIfNeeded(logPath: string): void {
|
||||
renameSync(logPath, backupPath)
|
||||
}
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +108,6 @@ function log(message: string): void {
|
||||
const logLine = `[${timestamp}] ${message}\n`
|
||||
appendFileSync(LOG_FILE_PATH, logLine, { mode: SECURE_FILE_MODE })
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,6 +127,31 @@ interface DaemonState {
|
||||
lastError?: string
|
||||
}
|
||||
|
||||
interface TelegramMessage {
|
||||
message_id?: number
|
||||
chat?: { id?: number | string }
|
||||
text?: string
|
||||
reply_to_message?: { message_id?: number }
|
||||
}
|
||||
|
||||
interface TelegramUpdate {
|
||||
update_id?: number
|
||||
message?: TelegramMessage
|
||||
}
|
||||
|
||||
interface TelegramUpdatesResponse {
|
||||
result?: TelegramUpdate[]
|
||||
}
|
||||
|
||||
function parseTelegramUpdatesResponse(body: unknown): TelegramUpdate[] {
|
||||
if (typeof body !== "object" || body === null) {
|
||||
return []
|
||||
}
|
||||
|
||||
const result = (body as TelegramUpdatesResponse).result
|
||||
return Array.isArray(result) ? result : []
|
||||
}
|
||||
|
||||
function readDaemonState(): DaemonState | null {
|
||||
try {
|
||||
if (!existsSync(STATE_FILE_PATH)) return null
|
||||
@@ -195,7 +217,6 @@ export async function isReplyListenerProcess(pid: number): Promise<boolean> {
|
||||
const cmdline = readFileSync(`/proc/${pid}/cmdline`, "utf-8")
|
||||
return cmdline.includes(DAEMON_IDENTITY_MARKER)
|
||||
}
|
||||
// macOS
|
||||
const proc = spawn(["ps", "-p", String(pid), "-o", "args="], {
|
||||
stdout: "pipe",
|
||||
stderr: "ignore",
|
||||
@@ -222,7 +243,6 @@ export async function isDaemonRunning(): Promise<boolean> {
|
||||
return true
|
||||
}
|
||||
|
||||
// Input Sanitization
|
||||
export function sanitizeReplyInput(text: string): string {
|
||||
return text
|
||||
.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, "")
|
||||
@@ -387,7 +407,6 @@ async function pollDiscord(
|
||||
},
|
||||
)
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
} else {
|
||||
state.errors++
|
||||
@@ -427,52 +446,52 @@ async function pollTelegram(
|
||||
return
|
||||
}
|
||||
|
||||
const body = await response.json() as any
|
||||
const updates = body.result || []
|
||||
const body = await response.json()
|
||||
const updates = parseTelegramUpdatesResponse(body)
|
||||
|
||||
for (const update of updates) {
|
||||
const msg = update.message
|
||||
if (!msg) {
|
||||
state.telegramLastUpdateId = update.update_id
|
||||
state.telegramLastUpdateId = update.update_id ?? state.telegramLastUpdateId
|
||||
writeDaemonState(state)
|
||||
continue
|
||||
}
|
||||
|
||||
if (!msg.reply_to_message?.message_id) {
|
||||
state.telegramLastUpdateId = update.update_id
|
||||
if (msg.reply_to_message?.message_id === undefined) {
|
||||
state.telegramLastUpdateId = update.update_id ?? state.telegramLastUpdateId
|
||||
writeDaemonState(state)
|
||||
continue
|
||||
}
|
||||
|
||||
if (String(msg.chat.id) !== replyListener.telegramChatId) {
|
||||
state.telegramLastUpdateId = update.update_id
|
||||
if (String(msg.chat?.id) !== replyListener.telegramChatId) {
|
||||
state.telegramLastUpdateId = update.update_id ?? state.telegramLastUpdateId
|
||||
writeDaemonState(state)
|
||||
continue
|
||||
}
|
||||
|
||||
const mapping = lookupByMessageId("telegram", String(msg.reply_to_message.message_id))
|
||||
if (!mapping) {
|
||||
state.telegramLastUpdateId = update.update_id
|
||||
state.telegramLastUpdateId = update.update_id ?? state.telegramLastUpdateId
|
||||
writeDaemonState(state)
|
||||
continue
|
||||
}
|
||||
|
||||
const text = msg.text || ""
|
||||
if (!text) {
|
||||
state.telegramLastUpdateId = update.update_id
|
||||
state.telegramLastUpdateId = update.update_id ?? state.telegramLastUpdateId
|
||||
writeDaemonState(state)
|
||||
continue
|
||||
}
|
||||
|
||||
if (!rateLimiter.canProceed()) {
|
||||
log(`WARN: Rate limit exceeded, dropping Telegram message ${msg.message_id}`)
|
||||
state.telegramLastUpdateId = update.update_id
|
||||
state.telegramLastUpdateId = update.update_id ?? state.telegramLastUpdateId
|
||||
writeDaemonState(state)
|
||||
state.errors++
|
||||
continue
|
||||
}
|
||||
|
||||
state.telegramLastUpdateId = update.update_id
|
||||
state.telegramLastUpdateId = update.update_id ?? state.telegramLastUpdateId
|
||||
writeDaemonState(state)
|
||||
|
||||
const success = await injectReply(mapping.tmuxPaneId, text, "telegram", config)
|
||||
@@ -604,9 +623,6 @@ export async function startReplyListener(config: OpenClawConfig): Promise<{ succ
|
||||
const normalizedConfig = normalizeReplyListenerConfig(config)
|
||||
const replyListener = normalizedConfig.replyListener
|
||||
if (!replyListener?.discordBotToken && !replyListener?.telegramBotToken) {
|
||||
// Only warn if no platforms enabled, but user might just want outbound
|
||||
// Actually, instructions say: "Fire-and-forget for outbound, daemon process for inbound"
|
||||
// So if no inbound config, we shouldn't start daemon.
|
||||
return {
|
||||
success: false,
|
||||
message: "No enabled reply listener platforms configured (missing bot tokens/channels)",
|
||||
|
||||
@@ -44,7 +44,6 @@ function ensureRegistryDir(): void {
|
||||
}
|
||||
|
||||
function sleepMs(ms: number): void {
|
||||
// Use Atomics.wait for synchronous sleep
|
||||
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms)
|
||||
}
|
||||
|
||||
@@ -79,7 +78,6 @@ function readLockSnapshot(): LockSnapshot | null {
|
||||
typeof parsed.token === "string" && parsed.token.length > 0 ? parsed.token : null
|
||||
return { raw, pid, token }
|
||||
} catch {
|
||||
// Legacy format or plain PID
|
||||
const [pidStr] = trimmed.split(":")
|
||||
const parsedPid = Number.parseInt(pidStr ?? "", 10)
|
||||
return {
|
||||
@@ -132,12 +130,10 @@ function acquireRegistryLock(): LockHandle | null {
|
||||
try {
|
||||
closeSync(fd)
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
try {
|
||||
unlinkSync(REGISTRY_LOCK_PATH)
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
throw writeError
|
||||
}
|
||||
@@ -164,7 +160,6 @@ function acquireRegistryLock(): LockHandle | null {
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Ignore errors
|
||||
}
|
||||
sleepMs(LOCK_RETRY_MS)
|
||||
}
|
||||
@@ -188,8 +183,7 @@ function releaseRegistryLock(lock: LockHandle): void {
|
||||
try {
|
||||
closeSync(lock.fd)
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
const snapshot = readLockSnapshot()
|
||||
if (!snapshot || snapshot.token !== lock.token) return
|
||||
removeLockIfUnchanged(snapshot)
|
||||
@@ -298,7 +292,6 @@ export function removeSession(sessionId: string): void {
|
||||
rewriteRegistryUnsafe(filtered)
|
||||
},
|
||||
() => {
|
||||
// Best-effort
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -312,7 +305,6 @@ export function removeMessagesByPane(paneId: string): void {
|
||||
rewriteRegistryUnsafe(filtered)
|
||||
},
|
||||
() => {
|
||||
// Best-effort
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -334,7 +326,6 @@ export function pruneStale(): void {
|
||||
rewriteRegistryUnsafe(filtered)
|
||||
},
|
||||
() => {
|
||||
// Best-effort
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4,8 +4,7 @@ export function getCurrentTmuxSession(): string | null {
|
||||
const env = process.env.TMUX
|
||||
if (!env) return null
|
||||
const match = env.match(/(\d+)$/)
|
||||
return match ? `session-${match[1]}` : null // Wait, TMUX env is /tmp/tmux-501/default,1234,0
|
||||
// Reference tmux.js gets session name via `tmux display-message -p '#S'`
|
||||
return match ? `session-${match[1]}` : null
|
||||
}
|
||||
|
||||
export async function getTmuxSessionName(): Promise<string | null> {
|
||||
@@ -17,7 +16,6 @@ export async function getTmuxSessionName(): Promise<string | null> {
|
||||
const outputPromise = new Response(proc.stdout).text()
|
||||
await proc.exited
|
||||
const output = await outputPromise
|
||||
// Await proc.exited ensures exitCode is set; avoid race condition
|
||||
if (proc.exitCode !== 0) return null
|
||||
return output.trim() || null
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user