fix: handle inline status for allowlisted senders

This commit is contained in:
Peter Steinberger
2026-01-12 06:29:26 +00:00
parent 40cc7f5426
commit 1ffb0fe787
2 changed files with 38 additions and 17 deletions

View File

@@ -435,6 +435,20 @@ export async function getReplyFromConfig(
sessionCtx.BodyStripped ?? sessionCtx.BodyStripped ??
sessionCtx.Body ?? sessionCtx.Body ??
""; "";
const command = buildCommandContext({
ctx,
cfg,
agentId,
sessionKey,
isGroup,
triggerBodyNormalized,
commandAuthorized,
});
const allowTextCommands = shouldHandleTextCommands({
cfg,
surface: command.surface,
commandSource: ctx.CommandSource,
});
const clearInlineDirectives = (cleaned: string): InlineDirectives => ({ const clearInlineDirectives = (cleaned: string): InlineDirectives => ({
cleaned, cleaned,
hasThinkDirective: false, hasThinkDirective: false,
@@ -475,6 +489,7 @@ export async function getReplyFromConfig(
.filter((alias) => !reservedCommands.has(alias.toLowerCase())); .filter((alias) => !reservedCommands.has(alias.toLowerCase()));
let parsedDirectives = parseInlineDirectives(commandSource, { let parsedDirectives = parseInlineDirectives(commandSource, {
modelAliases: configuredAliases, modelAliases: configuredAliases,
allowStatusDirective: command.isAuthorizedSender,
}); });
if ( if (
isGroup && isGroup &&
@@ -506,9 +521,19 @@ export async function getReplyFromConfig(
if (noMentions.trim().length > 0) { if (noMentions.trim().length > 0) {
const directiveOnlyCheck = parseInlineDirectives(noMentions, { const directiveOnlyCheck = parseInlineDirectives(noMentions, {
modelAliases: configuredAliases, modelAliases: configuredAliases,
allowStatusDirective: command.isAuthorizedSender,
}); });
if (directiveOnlyCheck.cleaned.trim().length > 0) { if (directiveOnlyCheck.cleaned.trim().length > 0) {
parsedDirectives = clearInlineDirectives(parsedDirectives.cleaned); const allowInlineStatus =
parsedDirectives.hasStatusDirective &&
allowTextCommands &&
command.isAuthorizedSender;
parsedDirectives = allowInlineStatus
? {
...clearInlineDirectives(parsedDirectives.cleaned),
hasStatusDirective: true,
}
: clearInlineDirectives(parsedDirectives.cleaned);
} }
} }
} }
@@ -530,6 +555,7 @@ export async function getReplyFromConfig(
if (!sessionCtx.CommandBody && !sessionCtx.RawBody) { if (!sessionCtx.CommandBody && !sessionCtx.RawBody) {
return parseInlineDirectives(existingBody, { return parseInlineDirectives(existingBody, {
modelAliases: configuredAliases, modelAliases: configuredAliases,
allowStatusDirective: command.isAuthorizedSender,
}).cleaned; }).cleaned;
} }
@@ -537,6 +563,7 @@ export async function getReplyFromConfig(
if (markerIndex < 0) { if (markerIndex < 0) {
return parseInlineDirectives(existingBody, { return parseInlineDirectives(existingBody, {
modelAliases: configuredAliases, modelAliases: configuredAliases,
allowStatusDirective: command.isAuthorizedSender,
}).cleaned; }).cleaned;
} }
@@ -549,6 +576,7 @@ export async function getReplyFromConfig(
); );
const cleanedTail = parseInlineDirectives(tail, { const cleanedTail = parseInlineDirectives(tail, {
modelAliases: configuredAliases, modelAliases: configuredAliases,
allowStatusDirective: command.isAuthorizedSender,
}).cleaned; }).cleaned;
return `${head}${cleanedTail}`; return `${head}${cleanedTail}`;
})(); })();
@@ -669,20 +697,6 @@ export async function getReplyFromConfig(
? undefined ? undefined
: directives.rawModelDirective; : directives.rawModelDirective;
const command = buildCommandContext({
ctx,
cfg,
agentId,
sessionKey,
isGroup,
triggerBodyNormalized,
commandAuthorized,
});
const allowTextCommands = shouldHandleTextCommands({
cfg,
surface: command.surface,
commandSource: ctx.CommandSource,
});
if (!command.isAuthorizedSender) { if (!command.isAuthorizedSender) {
directives = { directives = {
...directives, ...directives,

View File

@@ -464,7 +464,11 @@ export type InlineDirectives = {
export function parseInlineDirectives( export function parseInlineDirectives(
body: string, body: string,
options?: { modelAliases?: string[]; disableElevated?: boolean }, options?: {
modelAliases?: string[];
disableElevated?: boolean;
allowStatusDirective?: boolean;
},
): InlineDirectives { ): InlineDirectives {
const { const {
cleaned: thinkCleaned, cleaned: thinkCleaned,
@@ -497,8 +501,11 @@ export function parseInlineDirectives(
hasDirective: false, hasDirective: false,
} }
: extractElevatedDirective(reasoningCleaned); : extractElevatedDirective(reasoningCleaned);
const allowStatusDirective = options?.allowStatusDirective !== false;
const { cleaned: statusCleaned, hasDirective: hasStatusDirective } = const { cleaned: statusCleaned, hasDirective: hasStatusDirective } =
extractStatusDirective(elevatedCleaned); allowStatusDirective
? extractStatusDirective(elevatedCleaned)
: { cleaned: elevatedCleaned, hasDirective: false };
const { const {
cleaned: modelCleaned, cleaned: modelCleaned,
rawModel, rawModel,