From 7151f0d37893c3ce215a370fdb97a2b57c7d17b5 Mon Sep 17 00:00:00 2001 From: OpenClaw Bot Date: Tue, 26 May 2026 23:30:35 +0200 Subject: [PATCH] Merge partial Scattermind rank imports --- README.md | 2 +- scripts/check-rank-feedback.mjs | 35 +++++++++++++++++++++++++++++++++ server.js | 23 ++++++++-------------- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index c53aecc..f2f2b3a 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Ranker's continuation job is narrow: `Snapshot / Concept Map → candidate feature/action set → Rank-ready build order` -`POST /api/rank-feedback` accepts a `prioritix-feature-set-v1`-style payload from Scattermind and returns ranked items plus `buildOrder.doFirst / validateNext / defer / park`. It accepts candidate arrays as `features`, `actions`, `nextMoves`, or `candidates` either at the top level or under `featureSet`, and it can consume a nested Concept Map directly, so Scattermind can hand off `conceptMap.nextActions / nextMoves` without renaming them into fake software features. Sectioned Concept Maps may also include `validateNext`, `deferred`, and `parkingLot`; Ranker combines those sections into one build-order pass while preserving `sourceSection` and treating deferred/parked sections as lane hints. Empty wrapper arrays are ignored rather than allowed to shadow a real nested Concept Map action set, which keeps partially-normalized Scattermind exports rankable. It also returns a `brief` with source, next-48-hour actions, carried-forward assumptions/constraints/non-goals, and `whatWouldChangeRanking` checks, plus a `handoff` object (`rank-feedback-result-v1`) with source provenance, item trace rows, and contract warnings for missing artifact IDs, source sections, original prompt provenance, or evidence on active items. 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. +`POST /api/rank-feedback` accepts a `prioritix-feature-set-v1`-style payload from Scattermind and returns ranked items plus `buildOrder.doFirst / validateNext / defer / park`. It accepts candidate arrays as `features`, `actions`, `nextMoves`, or `candidates` either at the top level or under `featureSet`, and it can consume a nested Concept Map directly, so Scattermind can hand off `conceptMap.nextActions / nextMoves` without renaming them into fake software features. Sectioned Concept Maps may also include `validateNext`, `deferred`, and `parkingLot`; Ranker combines those sections into one build-order pass while preserving `sourceSection` and treating deferred/parked sections as lane hints. Empty wrapper arrays are ignored rather than allowed to shadow a real nested Concept Map action set, and non-empty normalized wrappers are merged with Concept Map validation/deferred/parking sections rather than dropping that context. That keeps partially-normalized Scattermind exports rankable without losing the source lane contract. It also returns a `brief` with source, next-48-hour actions, carried-forward assumptions/constraints/non-goals, and `whatWouldChangeRanking` checks, plus a `handoff` object (`rank-feedback-result-v1`) with source provenance, item trace rows, and contract warnings for missing artifact IDs, source sections, original prompt provenance, or evidence on active items. 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. Candidate 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. For clean bridge handoff, Scattermind should send `sourceSection` and `evidenceNeeded` on each active next move. Scattermind can also send `targetAudience`, `constraints`, `assumptions`, and `nonGoals` / `avoid` at the top level, in `featureSet`, or inside `conceptMap.context`; Ranker returns that decision context in `input.decisionContext` and `handoff.decisionContext`, and penalizes candidates that conflict with source non-goals (for example saved workspaces/auth/billing before the continuation proof). If Scattermind sends duplicate candidate IDs, Ranker keeps the first ID, suffixes later duplicates (`preview-2`), and reports the normalization in `handoff.warnings` / `handoff.itemTrace` so downstream build-order references remain addressable. diff --git a/scripts/check-rank-feedback.mjs b/scripts/check-rank-feedback.mjs index 9a0495b..67d4777 100644 --- a/scripts/check-rank-feedback.mjs +++ b/scripts/check-rank-feedback.mjs @@ -271,6 +271,41 @@ try { assert.deepEqual(nonGoal.handoff.itemTrace.find(item => item.id === 'workspace-autopilot').nonGoalConflicts, workspace.metrics.nonGoalConflicts); assert.ok(!nonGoal.buildOrder.doFirst.includes('workspace-autopilot')); + const mixedWrapperResponse = await fetch(`${base}/api/rank-feedback`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + sourceName: 'Scattermind', + artifactId: 'concept_map_mixed_wrappers', + originalPrompt: 'The bridge export contains a normalized feature list plus Concept Map validation and parking sections.', + idea: 'Ranker should not lose sectioned Concept Map context when a partial feature wrapper is also present.', + mode: 'mvp', + featureSet: { + features: [ + { id: 'manual-bridge-proof', title: 'Manual bridge proof', description: 'Turn one Concept Map into a defended build-order preview.', evidenceNeeded: 'Can one tired user act on the preview?', recommendedLane: 'do-first', rankerHints: { value: 9, effort: 2, confidence: 8, urgency: 8, risk: 2 } }, + ], + }, + conceptMap: { + validateNext: [ + { id: 'copyable-brief-test', action: 'Copyable brief test', why: 'Check whether the decision brief remains useful outside Ranker.', evidence: 'Can the user paste it into notes and still know the next move?' }, + ], + parkingLot: [ + { id: 'account-dashboard', action: 'Account dashboard', why: 'Saved workspaces, auth, billing, and team sync.', evidence: 'No bridge proof yet' }, + ], + }, + }), + }); + assert.equal(mixedWrapperResponse.status, 200); + const mixedWrapper = await mixedWrapperResponse.json(); + assert.equal(mixedWrapper.input.optionCount, 3); + assert.equal(mixedWrapper.ranked[0].id, 'manual-bridge-proof'); + assert.equal(mixedWrapper.handoff.itemTrace.find(item => item.id === 'manual-bridge-proof').sourceSection, 'feature-set.features'); + assert.equal(mixedWrapper.ranked.find(item => item.id === 'copyable-brief-test').lane.id, 'test'); + assert.equal(mixedWrapper.handoff.itemTrace.find(item => item.id === 'copyable-brief-test').sourceSection, 'concept-map.validateNext'); + assert.equal(mixedWrapper.ranked.find(item => item.id === 'account-dashboard').lane.id, 'park'); + assert.equal(mixedWrapper.handoff.itemTrace.find(item => item.id === 'account-dashboard').sourceSection, 'concept-map.parkingLot'); + assert.deepEqual(mixedWrapper.handoff.warnings, []); + const duplicateIdResponse = await fetch(`${base}/api/rank-feedback`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, diff --git a/server.js b/server.js index baca4b7..4d69cf0 100644 --- a/server.js +++ b/server.js @@ -496,12 +496,8 @@ function normalizeOptionIds(options = []) { }); } -function candidateArrayFrom(...entries) { - return entries.find(entry => Array.isArray(entry?.items) && entry.items.length > 0) || null; -} - -function candidateGroupFrom(...groups) { - return groups.find(group => group.some(entry => Array.isArray(entry?.items) && entry.items.length > 0)) || null; +function compactCandidateGroup(group = []) { + return group.filter(entry => Array.isArray(entry?.items) && entry.items.length > 0); } function normalizeCandidateGroup(group = []) { @@ -515,7 +511,7 @@ function normalizeCandidateGroup(group = []) { function optionsFromBody(body = {}) { const featureSet = objectFrom(body.featureSet); const conceptMap = objectFrom(body.conceptMap || featureSet.conceptMap); - const rawCandidates = candidateArrayFrom( + const directCandidateGroup = compactCandidateGroup([ { items: body.features, sourceSection: 'features' }, { items: featureSet.features, sourceSection: 'feature-set.features' }, { items: body.actions, sourceSection: 'actions' }, @@ -523,13 +519,9 @@ function optionsFromBody(body = {}) { { items: body.nextMoves, sourceSection: 'nextMoves' }, { items: featureSet.nextMoves, sourceSection: 'feature-set.nextMoves' }, { items: body.candidates, sourceSection: 'candidates' }, - { items: featureSet.candidates, sourceSection: 'feature-set.candidates' } - ); - if (rawCandidates) { - const fallbackId = rawCandidates.sourceSection.toLowerCase().includes('action') ? 'action' : 'feature'; - return normalizeOptionIds(rawCandidates.items.slice(0, 24).map((item, index) => normalizeFeatureOption(item, index, fallbackId, rawCandidates.sourceSection)).filter(item => item.title)); - } - const conceptMapCandidates = candidateGroupFrom([ + { items: featureSet.candidates, sourceSection: 'feature-set.candidates' }, + ]); + const conceptMapCandidateGroup = compactCandidateGroup([ { items: conceptMap.nextActions, sourceSection: 'concept-map.nextActions' }, { items: conceptMap.nextMoves, sourceSection: 'concept-map.nextMoves' }, { items: conceptMap.features, sourceSection: 'concept-map.features' }, @@ -538,7 +530,8 @@ function optionsFromBody(body = {}) { { items: conceptMap.deferred || conceptMap.defer || conceptMap.later, sourceSection: 'concept-map.deferred', defaultLane: 'defer' }, { items: conceptMap.parkingLot || conceptMap.park || conceptMap.parked, sourceSection: 'concept-map.parkingLot', defaultLane: 'park' }, ]); - if (conceptMapCandidates) return normalizeCandidateGroup(conceptMapCandidates); + const groupedCandidates = [...directCandidateGroup, ...conceptMapCandidateGroup]; + if (groupedCandidates.length) return normalizeCandidateGroup(groupedCandidates); if (Array.isArray(body.options)) { return normalizeOptionIds(body.options.slice(0, 24).map((item, index) => normalizeFeatureOption(item, index, 'option', 'options')).filter(item => item.title)); }