Handle structured Scattermind context

This commit is contained in:
OpenClaw Bot
2026-05-26 23:40:46 +02:00
parent 65832f9b56
commit adcef9a6f7
3 changed files with 58 additions and 4 deletions
+23 -2
View File
@@ -422,11 +422,20 @@ function cleanProvenance(input = {}) {
};
}
function firstObject(...values) {
for (const value of values) {
const obj = objectFrom(value);
if (Object.keys(obj).length) return obj;
}
return {};
}
function cleanDecisionContext(input = {}) {
const featureSet = objectFrom(input.featureSet);
const artifact = objectFrom(input.artifact || featureSet.artifact);
const conceptMap = objectFrom(input.conceptMap || featureSet.conceptMap || artifact.conceptMap);
const sourceContext = objectFrom(input.decisionContext || featureSet.decisionContext || artifact.decisionContext || conceptMap.decisionContext || conceptMap.context);
const structuredContext = objectFrom(input.context);
const sourceContext = firstObject(input.decisionContext, featureSet.decisionContext, artifact.decisionContext, conceptMap.decisionContext, structuredContext, conceptMap.context);
return {
targetAudience: cleanText(input.targetAudience || featureSet.targetAudience || sourceContext.targetAudience || conceptMap.targetAudience || '', 180),
constraints: cleanFlexibleTextList(input.constraints || featureSet.constraints || sourceContext.constraints || conceptMap.constraints, 8, 180),
@@ -435,6 +444,18 @@ function cleanDecisionContext(input = {}) {
};
}
function cleanContextText(value = '') {
if (!value || typeof value !== 'object' || Array.isArray(value)) return cleanMultiline(value || '', 3000);
const pieces = [
value.summary || value.description || value.notes || value.brief || '',
value.targetAudience && `Target audience: ${value.targetAudience}`,
...cleanFlexibleTextList(value.constraints, 8, 180).map(item => `Constraint: ${item}`),
...cleanFlexibleTextList(value.nonGoals || value.avoid, 8, 180).map(item => `Non-goal: ${item}`),
...cleanFlexibleTextList(value.assumptions, 6, 180).map(item => `Assumption: ${item}`),
].filter(Boolean);
return cleanMultiline(pieces.join('\n'), 3000);
}
function meaningfulTokens(text = '') {
const stop = new Set(['the', 'and', 'with', 'from', 'that', 'this', 'into', 'before', 'after', 'user', 'users', 'idea', 'ideas', 'build', 'first', 'avoid', 'without', 'more', 'full', 'proof', 'value', 'layer']);
return [...new Set(String(text).toLowerCase().match(/[a-z0-9][a-z0-9-]{3,}/g) || [])].filter(token => !stop.has(token)).slice(0, 8);
@@ -735,7 +756,7 @@ function createHandoffContract({ ranked, provenance, decisionContext }) {
app.post('/api/rank-feedback', (req, res) => {
const idea = cleanMultiline(req.body?.idea || '', 3000);
const context = cleanMultiline(req.body?.context || '', 3000);
const context = cleanContextText(req.body?.context || '');
const modeId = cleanText(req.body?.mode || 'progress', 40);
const mode = judgementModes[modeId] || judgementModes.progress;
const provenance = cleanProvenance(req.body || {});