perf(auto-reply): avoid skill scans for inline directives

This commit is contained in:
Peter Steinberger
2026-02-15 19:18:20 +00:00
parent 38f430e133
commit 8fdde0429e
4 changed files with 219 additions and 62 deletions

View File

@@ -169,27 +169,34 @@ export async function resolveReplyDirectives(params: {
surface: command.surface,
commandSource: ctx.CommandSource,
});
const shouldResolveSkillCommands =
allowTextCommands && command.commandBodyNormalized.includes("/");
const skillCommands = shouldResolveSkillCommands
? listSkillCommandsForWorkspace({
workspaceDir,
cfg,
skillFilter,
})
: [];
const reservedCommands = new Set(
listChatCommands().flatMap((cmd) =>
cmd.textAliases.map((a) => a.replace(/^\//, "").toLowerCase()),
),
);
for (const command of skillCommands) {
reservedCommands.add(command.name.toLowerCase());
}
const configuredAliases = Object.values(cfg.agents?.defaults?.models ?? {})
const rawAliases = Object.values(cfg.agents?.defaults?.models ?? {})
.map((entry) => entry.alias?.trim())
.filter((alias): alias is string => Boolean(alias))
.filter((alias) => !reservedCommands.has(alias.toLowerCase()));
// Only load workspace skill commands when we actually need them to filter aliases.
// This avoids scanning skills for messages that only use inline directives like /think:/verbose:.
const skillCommands =
allowTextCommands && rawAliases.length > 0
? listSkillCommandsForWorkspace({
workspaceDir,
cfg,
skillFilter,
})
: [];
for (const command of skillCommands) {
reservedCommands.add(command.name.toLowerCase());
}
const configuredAliases = rawAliases.filter(
(alias) => !reservedCommands.has(alias.toLowerCase()),
);
const allowStatusDirective = allowTextCommands && command.isAuthorizedSender;
let parsedDirectives = parseInlineDirectives(commandText, {
modelAliases: configuredAliases,