Skip to content

**Suggestion:** Improve the prompt-detection regex to robustly detect questions: check trailing '?' first and use a start-anchored interrogative-word check (with word boundary) to avoid accidental matches. [possible issue] #1

@Loopshape

Description

@Loopshape

Suggestion: Improve the prompt-detection regex to robustly detect questions: check trailing '?' first and use a start-anchored interrogative-word check (with word boundary) to avoid accidental matches. [possible issue]

Severity Level: Minor ⚠️

function isHumanPrompt(text) {
    const t = (text || '').trim();
    if (!t) return false;
    // If it ends with a question mark it's a human question
    if (t.endsWith('?')) return true;
    // Otherwise detect common interrogative words at the start of the prompt (English + some German)
    return /^\s*(who|what|how|when|where|why|which|whom|whose|wer|was|wie|wann|wo|warum)\b/i.test(t);
Why it matters? ⭐

The current regex can produce false positives and is brittle: the alternation mixes an unanchored literal-question check with start-anchored words without word boundaries, and it doesn't handle empty input gracefully. The proposed replacement first handles empty strings, explicitly checks for a trailing '?', and then uses a start-anchored, word-boundary regex for interrogatives — this directly fixes a likely misclassification bug and is safe to apply.

Prompt for AI Agent 🤖
<code>This is a comment left during a code review.

**Path:** nexus.html
**Line:** 268:270
**Comment:**
	*Possible Issue: Improve the prompt-detection regex to robustly detect questions: check trailing '?' first and use a start-anchored interrogative-word check (with word boundary) to avoid accidental matches.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.

Originally posted by @CodeAnt-AI in Loopshape/_NIX-SYSOP-AI-AGENT-by-Aris-Arjuna-Noorsanto#4 (comment)

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentationenhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions