mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-17 12:11:20 +00:00
perf: optimize directive test imports
This commit is contained in:
@@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import type { SessionBindingRecord } from "../../infra/outbound/session-binding-service.js";
|
||||
import type { HandleCommandsParams } from "./commands-types.js";
|
||||
import { parseInlineDirectives } from "./directive-handling.js";
|
||||
import { parseInlineDirectives } from "./directive-handling.parse.js";
|
||||
|
||||
const THREAD_CHANNEL = "thread-chat";
|
||||
const ROOM_CHANNEL = "room-chat";
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { OpenClawConfig } from "../../config/config.js";
|
||||
import type { MsgContext } from "../templating.js";
|
||||
import { buildCommandContext } from "./commands-context.js";
|
||||
import type { HandleCommandsParams } from "./commands-types.js";
|
||||
import { parseInlineDirectives } from "./directive-handling.js";
|
||||
import { parseInlineDirectives } from "./directive-handling.parse.js";
|
||||
|
||||
export function buildCommandTestParams(
|
||||
commandBody: string,
|
||||
|
||||
30
src/auto-reply/reply/directive-handling.directive-only.ts
Normal file
30
src/auto-reply/reply/directive-handling.directive-only.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import type { MsgContext } from "../templating.js";
|
||||
import type { InlineDirectives } from "./directive-handling.parse.js";
|
||||
import { stripMentions, stripStructuralPrefixes } from "./mentions.js";
|
||||
|
||||
export function isDirectiveOnly(params: {
|
||||
directives: InlineDirectives;
|
||||
cleanedBody: string;
|
||||
ctx: MsgContext;
|
||||
cfg: OpenClawConfig;
|
||||
agentId?: string;
|
||||
isGroup: boolean;
|
||||
}): boolean {
|
||||
const { directives, cleanedBody, ctx, cfg, agentId, isGroup } = params;
|
||||
if (
|
||||
!directives.hasThinkDirective &&
|
||||
!directives.hasVerboseDirective &&
|
||||
!directives.hasFastDirective &&
|
||||
!directives.hasReasoningDirective &&
|
||||
!directives.hasElevatedDirective &&
|
||||
!directives.hasExecDirective &&
|
||||
!directives.hasModelDirective &&
|
||||
!directives.hasQueueDirective
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
const stripped = stripStructuralPrefixes(cleanedBody ?? "");
|
||||
const noMentions = isGroup ? stripMentions(stripped, ctx, cfg, agentId) : stripped;
|
||||
return noMentions.length === 0;
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { ReplyPayload } from "../types.js";
|
||||
import { isDirectiveOnly } from "./directive-handling.directive-only.js";
|
||||
import { handleDirectiveOnly } from "./directive-handling.impl.js";
|
||||
import { resolveCurrentDirectiveLevels } from "./directive-handling.levels.js";
|
||||
import type { ApplyInlineDirectivesFastLaneParams } from "./directive-handling.params.js";
|
||||
import { isDirectiveOnly } from "./directive-handling.parse.js";
|
||||
|
||||
export async function applyInlineDirectivesFastLane(
|
||||
params: ApplyInlineDirectivesFastLaneParams,
|
||||
|
||||
@@ -30,11 +30,11 @@ import type { OpenClawConfig } from "../../config/config.js";
|
||||
import type { SessionEntry } from "../../config/sessions.js";
|
||||
import type { ElevatedLevel } from "../thinking.js";
|
||||
import { handleDirectiveOnly } from "./directive-handling.impl.js";
|
||||
import { parseInlineDirectives } from "./directive-handling.js";
|
||||
import {
|
||||
maybeHandleModelDirectiveInfo,
|
||||
resolveModelSelectionFromDirective,
|
||||
} from "./directive-handling.model.js";
|
||||
import { parseInlineDirectives } from "./directive-handling.parse.js";
|
||||
import { persistInlineDirectives } from "./directive-handling.persist.js";
|
||||
|
||||
const liveModelSwitchMocks = vi.hoisted(() => ({
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import type { ExecAsk, ExecSecurity, ExecTarget } from "../../infra/exec-approvals.js";
|
||||
import { extractModelDirective } from "../model.js";
|
||||
import type { MsgContext } from "../templating.js";
|
||||
import type { ElevatedLevel, ReasoningLevel, ThinkLevel, VerboseLevel } from "./directives.js";
|
||||
import {
|
||||
extractElevatedDirective,
|
||||
@@ -12,7 +10,6 @@ import {
|
||||
extractThinkDirective,
|
||||
extractVerboseDirective,
|
||||
} from "./directives.js";
|
||||
import { stripMentions, stripStructuralPrefixes } from "./mentions.js";
|
||||
import { extractQueueDirective } from "./queue/directive.js";
|
||||
import type { QueueDropPolicy, QueueMode } from "./queue/types.js";
|
||||
|
||||
@@ -201,29 +198,3 @@ export function parseInlineDirectives(
|
||||
hasQueueOptions,
|
||||
};
|
||||
}
|
||||
|
||||
export function isDirectiveOnly(params: {
|
||||
directives: InlineDirectives;
|
||||
cleanedBody: string;
|
||||
ctx: MsgContext;
|
||||
cfg: OpenClawConfig;
|
||||
agentId?: string;
|
||||
isGroup: boolean;
|
||||
}): boolean {
|
||||
const { directives, cleanedBody, ctx, cfg, agentId, isGroup } = params;
|
||||
if (
|
||||
!directives.hasThinkDirective &&
|
||||
!directives.hasVerboseDirective &&
|
||||
!directives.hasFastDirective &&
|
||||
!directives.hasReasoningDirective &&
|
||||
!directives.hasElevatedDirective &&
|
||||
!directives.hasExecDirective &&
|
||||
!directives.hasModelDirective &&
|
||||
!directives.hasQueueDirective
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
const stripped = stripStructuralPrefixes(cleanedBody ?? "");
|
||||
const noMentions = isGroup ? stripMentions(stripped, ctx, cfg, agentId) : stripped;
|
||||
return noMentions.length === 0;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
export { applyInlineDirectivesFastLane } from "./directive-handling.fast-lane.js";
|
||||
export * from "./directive-handling.impl.js";
|
||||
export type { InlineDirectives } from "./directive-handling.parse.js";
|
||||
export { isDirectiveOnly, parseInlineDirectives } from "./directive-handling.parse.js";
|
||||
export { isDirectiveOnly } from "./directive-handling.directive-only.js";
|
||||
export { parseInlineDirectives } from "./directive-handling.parse.js";
|
||||
export { persistInlineDirectives } from "./directive-handling.persist.js";
|
||||
export { resolveDefaultModel } from "./directive-handling.defaults.js";
|
||||
export { formatDirectiveAck } from "./directive-handling.shared.js";
|
||||
|
||||
@@ -5,8 +5,9 @@ import type { MsgContext } from "../templating.js";
|
||||
import type { ElevatedLevel } from "../thinking.js";
|
||||
import type { ReplyPayload } from "../types.js";
|
||||
import type { CommandContext } from "./commands-types.js";
|
||||
import { isDirectiveOnly } from "./directive-handling.directive-only.js";
|
||||
import type { ApplyInlineDirectivesFastLaneParams } from "./directive-handling.params.js";
|
||||
import { isDirectiveOnly, type InlineDirectives } from "./directive-handling.parse.js";
|
||||
import type { InlineDirectives } from "./directive-handling.parse.js";
|
||||
import { clearInlineDirectives } from "./get-reply-directives-utils.js";
|
||||
import type { createModelSelectionState } from "./model-selection.js";
|
||||
import type { TypingController } from "./typing.js";
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { ModelAliasIndex } from "../../agents/model-selection.js";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import type { SessionEntry } from "../../config/sessions.js";
|
||||
import { parseInlineDirectives } from "./directive-handling.parse.js";
|
||||
import { persistInlineDirectives } from "./directive-handling.persist.js";
|
||||
import { type ReplyExecOverrides, resolveReplyExecOverrides } from "./get-reply-exec-overrides.js";
|
||||
|
||||
const AGENT_EXEC_DEFAULTS = {
|
||||
@@ -21,33 +18,6 @@ function createSessionEntry(overrides?: Partial<SessionEntry>): SessionEntry {
|
||||
};
|
||||
}
|
||||
|
||||
async function persistExecDirective(params: {
|
||||
sessionEntry: SessionEntry;
|
||||
sessionStore: Record<string, SessionEntry>;
|
||||
body: string;
|
||||
}) {
|
||||
await persistInlineDirectives({
|
||||
directives: parseInlineDirectives(params.body),
|
||||
cfg: { commands: { text: true } } as OpenClawConfig,
|
||||
agentDir: "/tmp/agent",
|
||||
sessionEntry: params.sessionEntry,
|
||||
sessionStore: params.sessionStore,
|
||||
sessionKey: "agent:main:main",
|
||||
elevatedEnabled: false,
|
||||
elevatedAllowed: false,
|
||||
defaultProvider: "anthropic",
|
||||
defaultModel: "claude-opus-4-6",
|
||||
aliasIndex: { byAlias: new Map(), byKey: new Map() } satisfies ModelAliasIndex,
|
||||
allowedModelKeys: new Set(),
|
||||
provider: "anthropic",
|
||||
model: "claude-opus-4-6",
|
||||
initialModelLabel: "anthropic/claude-opus-4-6",
|
||||
formatModelSwitchEvent: (label) => label,
|
||||
agentCfg: undefined,
|
||||
surface: "whatsapp",
|
||||
});
|
||||
}
|
||||
|
||||
describe("reply exec overrides", () => {
|
||||
it("uses per-agent exec defaults when session and message are unset", () => {
|
||||
expect(
|
||||
@@ -90,19 +60,11 @@ describe("reply exec overrides", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("resolves the latest persisted exec directive for later turns", async () => {
|
||||
const sessionEntry = createSessionEntry();
|
||||
const sessionStore = { "agent:main:main": sessionEntry };
|
||||
|
||||
await persistExecDirective({
|
||||
sessionEntry,
|
||||
sessionStore,
|
||||
body: "/exec host=gateway security=deny ask=off",
|
||||
});
|
||||
await persistExecDirective({
|
||||
sessionEntry,
|
||||
sessionStore,
|
||||
body: "/exec host=gateway security=full ask=always",
|
||||
it("uses persisted session exec fields for later turns", () => {
|
||||
const sessionEntry = createSessionEntry({
|
||||
execHost: "gateway",
|
||||
execSecurity: "full",
|
||||
execAsk: "always",
|
||||
});
|
||||
|
||||
expect(
|
||||
|
||||
@@ -27,8 +27,8 @@ import {
|
||||
} from "./abort-cutoff.js";
|
||||
import { getAbortMemory, isAbortRequestText } from "./abort-primitives.js";
|
||||
import type { buildStatusReply, handleCommands } from "./commands.runtime.js";
|
||||
import { isDirectiveOnly } from "./directive-handling.directive-only.js";
|
||||
import type { InlineDirectives } from "./directive-handling.parse.js";
|
||||
import { isDirectiveOnly } from "./directive-handling.parse.js";
|
||||
import { extractExplicitGroupId } from "./group-id.js";
|
||||
import { stripMentions, stripStructuralPrefixes } from "./mentions.js";
|
||||
import type { createModelSelectionState } from "./model-selection.js";
|
||||
|
||||
Reference in New Issue
Block a user