fix: unblock control commands during active runs
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
listChatCommandsForConfig,
|
||||
normalizeCommandBody,
|
||||
} from "./commands-registry.js";
|
||||
import { isAbortTrigger } from "./reply/abort.js";
|
||||
|
||||
export function hasControlCommand(
|
||||
text?: string,
|
||||
@@ -31,3 +32,16 @@ export function hasControlCommand(
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isControlCommandMessage(
|
||||
text?: string,
|
||||
cfg?: ClawdbotConfig,
|
||||
options?: CommandNormalizeOptions,
|
||||
): boolean {
|
||||
if (!text) return false;
|
||||
const trimmed = text.trim();
|
||||
if (!trimmed) return false;
|
||||
if (hasControlCommand(trimmed, cfg, options)) return true;
|
||||
const normalized = normalizeCommandBody(trimmed, options).trim().toLowerCase();
|
||||
return isAbortTrigger(normalized);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { ClawdbotConfig } from "../../config/config.js";
|
||||
import { isAbortTrigger } from "./abort.js";
|
||||
import { isAbortTrigger, tryFastAbortFromMessage } from "./abort.js";
|
||||
import { initSessionState } from "./session.js";
|
||||
|
||||
describe("abort detection", () => {
|
||||
@@ -35,8 +35,30 @@ describe("abort detection", () => {
|
||||
expect(isAbortTrigger("abort")).toBe(true);
|
||||
expect(isAbortTrigger("wait")).toBe(true);
|
||||
expect(isAbortTrigger("exit")).toBe(true);
|
||||
expect(isAbortTrigger("interrupt")).toBe(true);
|
||||
expect(isAbortTrigger("hello")).toBe(false);
|
||||
// /stop is NOT matched by isAbortTrigger - it's handled separately
|
||||
expect(isAbortTrigger("/stop")).toBe(false);
|
||||
});
|
||||
|
||||
it("fast-aborts even when text commands are disabled", async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-abort-"));
|
||||
const storePath = path.join(root, "sessions.json");
|
||||
const cfg = { session: { store: storePath }, commands: { text: false } } as ClawdbotConfig;
|
||||
|
||||
const result = await tryFastAbortFromMessage({
|
||||
ctx: {
|
||||
CommandBody: "/stop",
|
||||
RawBody: "/stop",
|
||||
SessionKey: "telegram:123",
|
||||
Provider: "telegram",
|
||||
Surface: "telegram",
|
||||
From: "telegram:123",
|
||||
To: "telegram:123",
|
||||
},
|
||||
cfg,
|
||||
});
|
||||
|
||||
expect(result.handled).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,11 +9,11 @@ import {
|
||||
} from "../../config/sessions.js";
|
||||
import { parseAgentSessionKey } from "../../routing/session-key.js";
|
||||
import { resolveCommandAuthorization } from "../command-auth.js";
|
||||
import { normalizeCommandBody, shouldHandleTextCommands } from "../commands-registry.js";
|
||||
import { normalizeCommandBody } from "../commands-registry.js";
|
||||
import type { MsgContext } from "../templating.js";
|
||||
import { stripMentions, stripStructuralPrefixes } from "./mentions.js";
|
||||
|
||||
const ABORT_TRIGGERS = new Set(["stop", "esc", "abort", "wait", "exit"]);
|
||||
const ABORT_TRIGGERS = new Set(["stop", "esc", "abort", "wait", "exit", "interrupt"]);
|
||||
const ABORT_MEMORY = new Map<string, boolean>();
|
||||
|
||||
export function isAbortTrigger(text?: string): boolean {
|
||||
@@ -57,14 +57,6 @@ export async function tryFastAbortFromMessage(params: {
|
||||
cfg: ClawdbotConfig;
|
||||
}): Promise<{ handled: boolean; aborted: boolean }> {
|
||||
const { ctx, cfg } = params;
|
||||
const surface = (ctx.Surface ?? ctx.Provider ?? "").trim().toLowerCase();
|
||||
const allowTextCommands = shouldHandleTextCommands({
|
||||
cfg,
|
||||
surface,
|
||||
commandSource: ctx.CommandSource,
|
||||
});
|
||||
if (!allowTextCommands) return { handled: false, aborted: false };
|
||||
|
||||
const commandAuthorized = ctx.CommandAuthorized ?? true;
|
||||
const auth = resolveCommandAuthorization({
|
||||
ctx,
|
||||
|
||||
Reference in New Issue
Block a user