fix(observer): v12 — skip prompt-only code text + enrichment validation (v0.5.44) #task-619
- extractContextFromNearby: PROMPT_ONLY_RE skips code elements containing only terminal prompts (e.g. '\\gravity_control >') - Multi-codeEl traversal: tries all code elements at each depth, picks longest non-prompt text - http-bridge enrichment: validates extracted command is not just a prompt fragment before enriching - Fixes: cmd='\\gravity_control >' (prompt-only) no longer sent to Discord as the command text
This commit is contained in:
@@ -256,7 +256,7 @@ function _handlePending(req: any, res: any, ctx: HttpBridgeContext) {
|
||||
try {
|
||||
const data = JSON.parse(body);
|
||||
|
||||
// ── v11: Command enrichment FIRST — extract actual command from description ──
|
||||
// ── v12: Command enrichment FIRST — extract actual command from description ──
|
||||
// Must run before filters so "Always run" with useful description isn't filtered out
|
||||
const rawCmd = (data.command || '').trim();
|
||||
const rawDesc = (data.description || '').trim();
|
||||
@@ -271,9 +271,18 @@ function _handlePending(req: any, res: any, ctx: HttpBridgeContext) {
|
||||
if (promptMatch && promptMatch[1].trim().length > 3) {
|
||||
extracted = promptMatch[1].trim();
|
||||
}
|
||||
enrichedCmd = extracted.substring(0, 200);
|
||||
enrichedDesc = `[${rawCmd}] ${rawDesc}`;
|
||||
ctx.logToFile(`[HTTP] command enriched: "${rawCmd}" → "${enrichedCmd.substring(0, 60)}"`);
|
||||
// v12: Validate extracted text is not just a prompt fragment
|
||||
// Skip enrichment if extracted is the same as rawDesc (no > found) or looks like a bare prompt
|
||||
const PROMPT_ONLY_RE = /^[\s\\\/]*[\w_.-]+\s*[>»$#]\s*$/;
|
||||
const isPromptOnly = PROMPT_ONLY_RE.test(extracted) || extracted === rawDesc;
|
||||
if (!isPromptOnly && extracted.length > 3) {
|
||||
enrichedCmd = extracted.substring(0, 200);
|
||||
enrichedDesc = `[${rawCmd}] ${rawDesc}`;
|
||||
ctx.logToFile(`[HTTP] command enriched: "${rawCmd}" → "${enrichedCmd.substring(0, 60)}"`);
|
||||
} else {
|
||||
// Keep original button text as command, but use desc as-is
|
||||
ctx.logToFile(`[HTTP] enrichment skipped (prompt-only): "${rawCmd}" desc="${rawDesc.substring(0, 60)}"`);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Server-side false positive filter (uses enriched cmd) ──
|
||||
|
||||
Reference in New Issue
Block a user