Support Scattermind question-only rank handoffs

This commit is contained in:
OpenClaw Bot
2026-05-27 16:27:12 +02:00
parent ca186f2a01
commit a225586296
3 changed files with 77 additions and 5 deletions
+44 -3
View File
@@ -825,18 +825,24 @@ function cleanContextText(value = '') {
}
function meaningfulTokens(text = '') {
const stop = new Set(['the', 'and', 'with', 'from', 'that', 'this', 'into', 'before', 'after', 'until', 'user', 'users', 'idea', 'ideas', 'build', 'order', 'works', 'first', 'avoid', 'without', 'more', 'full', 'proof', 'manual', 'value', 'layer', 'result', 'sense', 'copyable', 'source', 'traced', 'source-traced']);
const stop = new Set(['the', 'and', 'with', 'from', 'that', 'this', 'into', 'before', 'after', 'until', 'user', 'users', 'idea', 'ideas', 'build', 'order', 'works', 'first', 'avoid', 'without', 'more', 'full', 'proof', 'manual', 'value', 'layer', 'result', 'sense', 'copyable', 'source', 'traced', 'source-traced', 'evidence']);
return [...new Set(String(text).toLowerCase().match(/[a-z0-9][a-z0-9-]{3,}/g) || [])].filter(token => !stop.has(token)).slice(0, 8);
}
function isGuardrailAvoidanceMention(lowerText = '', token = '') {
if (!token) return false;
const escaped = token.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
return new RegExp(`\\b(without|avoid(?:ing)?|no|not|skip|defer|wait(?:ing)?|hold(?:ing)?|before adding|before building)\\b[^.!?]{0,60}\\b${escaped}\\b`, 'i').test(lowerText);
}
function nonGoalConflicts(optionText, decisionContext = {}) {
const lower = String(optionText || '').toLowerCase();
return (decisionContext.nonGoals || []).filter(nonGoal => {
const tokens = meaningfulTokens(nonGoal);
return tokens.length > 0 && tokens.some(token => {
if (lower.includes(token)) return true;
const singular = token.endsWith('ies') ? `${token.slice(0, -3)}y` : token.replace(/(?:es|s)$/, '');
return singular.length >= 4 && lower.includes(singular);
const forms = [token, singular].filter(form => form.length >= 4);
return forms.some(form => lower.includes(form) && !isGuardrailAvoidanceMention(lower, form));
});
});
}
@@ -1015,6 +1021,35 @@ function optionsFromActionThreads(items = [], sourceSection = 'concept-map.threa
}).filter(item => item.action);
}
function questionActionTitle(text = '') {
const cleaned = cleanText(text.replace(/\?+$/g, ''), 180);
if (!cleaned) return '';
if (/^(can|could|will|would|should|does|do|is|are|what|where|when|who|how|why)\b/i.test(cleaned)) return cleanText(`Answer: ${cleaned}`, 140);
return cleanText(cleaned, 140);
}
function optionsFromQuestionsToSitWith(items = [], sourceSection = 'concept-map.questionsToSitWith', sourceTitle = 'Question to sit with') {
if (!Array.isArray(items)) return [];
return items.slice(0, 8).map((item, index) => {
const raw = typeof item === 'string' || typeof item === 'number' ? String(item) : '';
const objectItem = objectFrom(item);
const question = cleanMultiline(raw || objectItem.question || objectItem.text || objectItem.content || objectItem.title || '', 420);
return {
id: `question-${index + 1}`,
action: questionActionTitle(question),
why: 'Scattermind left this as an open question; Ranker treats it as evidence to collect, not a build feature.',
evidence: question,
validationSteps: cleanTextList(objectItem.validationSteps || objectItem.validation_steps || objectItem.steps || objectItem.proofSteps || objectItem.proof_steps, 4, 180),
suggestedLane: 'validate-next',
rankerHints: { value: 6, effort: 2, confidence: 5, urgency: 5, risk: 3 },
sourceSection,
sourceItemId: `${sourceSection}#${index + 1}`,
sourceTitle: cleanText(objectItem.sourceTitle || objectItem.source_title || sourceTitle, 140),
sourceExcerpt: question,
};
}).filter(item => item.action && item.evidence);
}
function optionsFromBody(body = {}) {
const envelope = bridgeEnvelopeFrom(body);
const featureSet = featureSetFrom(body);
@@ -1121,6 +1156,12 @@ function optionsFromBody(body = {}) {
'Thread to hold'
);
if (actionThreadOptions.length >= 2) return normalizeCandidateGroup([{ items: actionThreadOptions, sourceSection: 'concept-map.threadsToHold' }]);
const questionOptions = optionsFromQuestionsToSitWith(
body.questions_to_sit_with || body.questionsToSitWith || body.openQuestions || body.open_questions || conceptMap.questions_to_sit_with || conceptMap.questionsToSitWith || conceptMap.openQuestions || conceptMap.open_questions,
conceptMap.questions_to_sit_with || conceptMap.questionsToSitWith || conceptMap.openQuestions || conceptMap.open_questions ? 'concept-map.questionsToSitWith' : 'questionsToSitWith',
'Question to sit with'
);
if (questionOptions.length >= 2) return normalizeCandidateGroup([{ items: questionOptions, sourceSection: 'concept-map.questionsToSitWith', defaultLane: 'validate-next' }]);
if (Array.isArray(body.options)) {
return normalizeOptionIds(body.options.slice(0, 24).map((item, index) => normalizeFeatureOption(item, index, 'option', 'options')).filter(item => item.title));
}