From e8085663bdbf012099a2389af4a1dc4a824c743d Mon Sep 17 00:00:00 2001 From: OpenClaw Bot Date: Tue, 26 May 2026 22:31:02 +0200 Subject: [PATCH] Honor Scattermind metric hints in ranking --- README.md | 11 +++++++++ scripts/check-rank-feedback.mjs | 29 ++++++++++++++++++++++- server.js | 42 +++++++++++++++++++++++++++++++-- 3 files changed, 79 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a1ac9ad..134439c 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,8 @@ Ranker's continuation job is narrow: `POST /api/rank-feedback` accepts a `prioritix-feature-set-v1`-style payload from Scattermind and returns ranked items plus `buildOrder.doFirst / validateNext / defer / park`. Keep this contract action-first; do not use it as a reason to add generic dashboard, auth, billing, or workspace layers before the bridge has proof. +Feature items may include optional 1–10 `rankerHints` (`value`, `effort`, `confidence`, `urgency`, `revenue`, `novelty`, `risk`). Ranker blends those explicit Scattermind hints with text heuristics; `effort` is inverted into feasibility. Hints improve the defended order, but `recommendedLane: "defer"` or `"park"` remains a safety rail so dashboard-swamp items do not get promoted by flashy wording. + Recommended payload shape: ```json @@ -69,6 +71,15 @@ Recommended payload shape: "userValue": "A tired builder sees the next move without opening a dashboard.", "evidenceNeeded": "Can 3 non-AI-native users understand the first recommended action?", "proofSteps": ["Show a static result screen to 3 people"], + "rankerHints": { + "value": 8, + "effort": 3, + "confidence": 7, + "urgency": 6, + "revenue": 4, + "novelty": 5, + "risk": 3 + }, "dependencies": [], "risk": "May become generic roadmap UI if the source context is lost.", "recommendedLane": "validate-next", diff --git a/scripts/check-rank-feedback.mjs b/scripts/check-rank-feedback.mjs index fa1c9fc..a234437 100644 --- a/scripts/check-rank-feedback.mjs +++ b/scripts/check-rank-feedback.mjs @@ -72,12 +72,39 @@ try { assert.equal(data.ranked.find(item => item.id === 'parked-bridge-dashboard').lane.source, 'hint'); assert.equal(data.ranked.find(item => item.id === 'bridge-contract').provenance.sourceSection, 'concept-map.nextMoves'); assert.match(data.ranked.find(item => item.id === 'bridge-contract').factors.evidenceNeeded, /Concept Map/); + assert.ok(data.ranked.find(item => item.id === 'bridge-contract').factors.metricHints.value === undefined); assert.equal(data.brief.source.artifactId, 'snapshot_123'); assert.match(data.brief.summary, /Source: Tiny shop idea clarity pass · snapshot_123/); assert.ok(data.brief.next48Hours.some(item => /Open the source artifact \(snapshot_123\)/i.test(item))); assert.ok(data.brief.next48Hours.some(item => /Evidence to collect/i.test(item))); assert.match(data.brief.summary, /nearest follow-up|strongest signal/i); - console.log(JSON.stringify({ ok: true, top: data.ranked[0].id, provenance: data.input.provenance, buildOrder: data.buildOrder }, null, 2)); + + const hintedResponse = await fetch(`${base}/api/rank-feedback`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + schema: 'prioritix-feature-set-v1', + sourceName: 'Scattermind', + artifactId: 'concept_map_metric_hints', + idea: 'A concept map produced possible next moves for an overwhelmed solo builder.', + context: 'Defend build order from explicit Scattermind scoring hints plus text; do not let flashy platform language win.', + mode: 'mvp', + featureSet: { + features: [ + { id: 'manual-concierge-proof', title: 'Manual concierge proof', description: 'Personally rank three real idea snapshots and turn each into a small build order preview.', rankerHints: { value: 9, effort: 2, confidence: 8, urgency: 8, risk: 2 }, evidenceNeeded: 'Will a tired user act on the first recommended move?', proofSteps: ['Run 3 manual previews'] }, + { id: 'ai-autopilot-roadmap', title: 'AI autopilot roadmap platform', description: 'Generate a full automated roadmap with dashboard, workspace, team voting, sync, and integrations.', rankerHints: { value: 5, effort: 9, confidence: 3, urgency: 3, risk: 9 } }, + { id: 'nice-export', title: 'Clean export of the build order', description: 'Turn the defended order into a shareable text brief.', scoring: { impact: 7, complexity: 3, certainty: 7, timing: 5, assumptionRisk: 3 }, recommendedLane: 'validate-next' }, + ], + }, + }), + }); + assert.equal(hintedResponse.status, 200); + const hinted = await hintedResponse.json(); + assert.equal(hinted.ranked[0].id, 'manual-concierge-proof', 'explicit low-effort/high-confidence Scattermind hints should defend the manual proof slice'); + assert.ok(hinted.ranked[0].factors.metricHints.value >= 9); + assert.ok(hinted.ranked.find(item => item.id === 'ai-autopilot-roadmap').metrics.risk > hinted.ranked[0].metrics.risk); + + console.log(JSON.stringify({ ok: true, top: data.ranked[0].id, hintedTop: hinted.ranked[0].id, provenance: data.input.provenance, buildOrder: data.buildOrder }, null, 2)); } finally { server.kill('SIGTERM'); } diff --git a/server.js b/server.js index 63bf9db..7ffe808 100644 --- a/server.js +++ b/server.js @@ -145,6 +145,33 @@ function cleanTextList(value, maxItems = 6, maxText = 180) { return list.map(item => cleanText(item, maxText)).filter(Boolean).slice(0, maxItems); } +function cleanMetricHints(item = {}) { + const raw = { + ...(item.factors && typeof item.factors === 'object' ? item.factors : {}), + ...(item.scoring && typeof item.scoring === 'object' ? item.scoring : {}), + ...(item.rankerHints && typeof item.rankerHints === 'object' ? item.rankerHints : {}), + }; + const aliases = { + value: ['value', 'impact', 'userImpact', 'userValueScore'], + effort: ['effort', 'buildEffort', 'complexity'], + confidence: ['confidence', 'certainty'], + urgency: ['urgency', 'timing'], + revenue: ['revenue', 'commercial', 'buyerSignal'], + novelty: ['novelty', 'differentiation', 'originality'], + risk: ['risk', 'assumptionRisk', 'scopeRisk'], + }; + return Object.fromEntries(Object.entries(aliases).map(([metric, keys]) => { + const found = keys.map(key => raw[key] ?? item[key]).find(value => value !== undefined && value !== null && value !== ''); + const parsed = Number.parseFloat(found); + return [metric, Number.isFinite(parsed) ? Math.min(10, Math.max(1, parsed)) : null]; + }).filter(([, value]) => value !== null)); +} + +function blendMetric(heuristic, explicit, weight = 0.58) { + if (!Number.isFinite(explicit)) return heuristic; + return Math.max(1, Math.min(10, heuristic * (1 - weight) + explicit * weight)); +} + function rowsFrom(result) { const rows = result?.rows || result?.documents; if (!Array.isArray(rows)) throw new Error('Appwrite returned an invalid table response'); @@ -397,7 +424,7 @@ function normalizeFeatureOption(item, index, fallbackId = 'feature') { id: cleanText(item?.id || item?.key || `${fallbackId}-${index + 1}`, 80) || `${fallbackId}-${index + 1}`, title, description: cleanText(descriptionParts.join(' '), 760), - factors: { userValue, evidenceNeeded, risk, proofSteps, dependencies, recommendedLane }, + factors: { userValue, evidenceNeeded, risk, proofSteps, dependencies, recommendedLane, metricHints: cleanMetricHints(item) }, provenance: { sourceId: cleanText(item?.sourceId || item?.sourceArtifactId || item?.id || '', 120), sourceSection, @@ -431,7 +458,7 @@ function scoreOption(option, mode, context = '') { const normalizedLaneHint = normalizeLaneHint(laneHint); const laneBoost = /do|first|now|build/.test(laneHint) ? 0.55 : /validate|test|proof/.test(laneHint) ? 0.25 : /defer|park|cut/.test(laneHint) ? -0.75 : 0; const lanePenalty = normalizedLaneHint === 'park' ? 18 : normalizedLaneHint === 'defer' ? 9 : 0; - const metrics = { + const heuristicMetrics = { value: Math.min(10, 4.8 + hits(text, wordSets.value) * 0.9 + coreLoopHits * 0.8 + bridgeHits * 0.75 + proofHits * 0.2 + hits(context, wordSets.value) * 0.15), feasibility: Math.max(1, Math.min(10, 8.2 - effortHits * 0.8 - riskHits * 0.35 - dependencyPenalty + Math.min(1.1, coreLoopHits * 0.28 + bridgeHits * 0.18 + proofHits * 0.12))), confidence: Math.max(1, Math.min(10, 5.8 + coreLoopHits * 0.35 + bridgeHits * 0.28 + proofHits * 0.32 + hits(text, ['manual', 'existing', 'already', 'simple', 'clear', 'known']) * 0.7 - hits(text, ['maybe', 'unknown', 'new market', 'all users']) * 0.9)), @@ -440,6 +467,17 @@ function scoreOption(option, mode, context = '') { novelty: Math.min(10, 4.1 + hits(text, wordSets.novelty) * 0.95), risk: Math.min(10, 2.5 + riskHits * 1.1 + Math.max(0, effortHits - 2) * 0.45 + swampHits * 0.2 + dependencyPenalty), }; + const hinted = factors.metricHints || {}; + const hintedFeasibility = Number.isFinite(hinted.effort) ? 11 - hinted.effort : undefined; + const metrics = { + value: blendMetric(heuristicMetrics.value, hinted.value), + feasibility: blendMetric(heuristicMetrics.feasibility, hintedFeasibility), + confidence: blendMetric(heuristicMetrics.confidence, hinted.confidence), + urgency: blendMetric(heuristicMetrics.urgency, hinted.urgency), + revenue: blendMetric(heuristicMetrics.revenue, hinted.revenue), + novelty: blendMetric(heuristicMetrics.novelty, hinted.novelty), + risk: blendMetric(heuristicMetrics.risk, hinted.risk), + }; const weights = mode.weights; const weighted = Object.entries(weights).reduce((sum, [key, weight]) => sum + metrics[key] * weight, 0); const possible = Object.entries(weights).reduce((sum, [_key, weight]) => sum + Math.abs(weight) * 10, 0);