diff --git a/README.md b/README.md index 1692f90..c53aecc 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 `conceptMap.nextActions / nextMoves` artifact directly, so Scattermind can hand off Concept Map next actions without renaming them into fake software features. 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, 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. 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 338fc79..9a0495b 100644 --- a/scripts/check-rank-feedback.mjs +++ b/scripts/check-rank-feedback.mjs @@ -171,6 +171,42 @@ try { assert.equal(nestedConcept.ranked.find(item => item.id === 'lesson-library').lane.id, 'park'); assert.deepEqual(nestedConcept.handoff.warnings, []); + const sectionedConceptResponse = await fetch(`${base}/api/rank-feedback`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + sourceName: 'Scattermind', + artifactId: 'concept_map_sectioned_lanes', + originalPrompt: 'The Concept Map separates next actions, validation ideas, deferred items, and a parking lot.', + idea: 'Ranker should combine a sectioned Concept Map into one defended build order without losing lane provenance.', + mode: 'mvp', + conceptMap: { + nextActions: [ + { id: 'one-source-preview', action: 'One-source build-order preview', why: 'Turn the Concept Map into a defended first move.', evidence: 'Can one tired user say what to do next?', rankerHints: { value: 9, effort: 2, confidence: 8, urgency: 8, risk: 2 } }, + ], + validateNext: [ + { id: 'copyable-handoff', action: 'Copyable handoff brief', why: 'Let the user paste the build order into notes.', evidence: 'Does the copied brief preserve the action and reason?' }, + ], + deferred: [ + { id: 'visual-polish-pass', action: 'Visual polish pass', why: 'Improve the result screen after the bridge proves useful.', evidence: 'Do users understand the rough brief first?' }, + ], + parkingLot: [ + { id: 'saved-team-workspace', action: 'Saved team workspace', why: 'Accounts, auth dashboard, collaboration, and sync for every idea.', evidence: 'No proof yet' }, + ], + }, + }), + }); + assert.equal(sectionedConceptResponse.status, 200); + const sectionedConcept = await sectionedConceptResponse.json(); + assert.equal(sectionedConcept.input.optionCount, 4); + assert.equal(sectionedConcept.ranked[0].id, 'one-source-preview'); + assert.equal(sectionedConcept.ranked.find(item => item.id === 'copyable-handoff').lane.id, 'test', 'validateNext sections should default into Validate next'); + assert.equal(sectionedConcept.ranked.find(item => item.id === 'copyable-handoff').lane.source, 'hint'); + assert.equal(sectionedConcept.ranked.find(item => item.id === 'visual-polish-pass').lane.id, 'defer', 'deferred sections should not enter the active proof slice'); + assert.equal(sectionedConcept.ranked.find(item => item.id === 'saved-team-workspace').lane.id, 'park', 'parking lot sections should stay parked'); + assert.equal(sectionedConcept.handoff.itemTrace.find(item => item.id === 'saved-team-workspace').sourceSection, 'concept-map.parkingLot'); + assert.deepEqual(sectionedConcept.handoff.warnings, []); + const emptyWrapperResponse = await fetch(`${base}/api/rank-feedback`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, diff --git a/server.js b/server.js index 1d1622b..baca4b7 100644 --- a/server.js +++ b/server.js @@ -448,7 +448,7 @@ function nonGoalConflicts(optionText, decisionContext = {}) { }); } -function normalizeFeatureOption(item, index, fallbackId = 'feature', defaultSourceSection = '') { +function normalizeFeatureOption(item, index, fallbackId = 'feature', defaultSourceSection = '', defaultRecommendedLane = '') { const title = cleanText(item?.title || item?.name || item?.action || '', 140); const proofSteps = cleanTextList(item?.proofSteps || item?.proof || item?.validationSteps, 5, 180); const dependencies = cleanTextList(item?.dependencies || item?.blockedBy, 5, 120); @@ -456,7 +456,7 @@ function normalizeFeatureOption(item, index, fallbackId = 'feature', defaultSour const userValue = cleanText(item?.userValue || item?.value || item?.outcome || item?.why, 260); const risk = cleanText(item?.risk || item?.assumption || item?.unknown || '', 220); const sourceSection = cleanText(item?.sourceSection || item?.section || item?.lane || item?.origin || defaultSourceSection, 80); - const recommendedLane = cleanText(item?.recommendedLane || item?.laneHint || item?.suggestedLane || '', 40).toLowerCase(); + const recommendedLane = cleanText(item?.recommendedLane || item?.laneHint || item?.suggestedLane || defaultRecommendedLane || '', 40).toLowerCase(); const descriptionParts = [ item?.description || item?.brief || '', userValue && `User value: ${userValue}`, @@ -500,6 +500,18 @@ 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 normalizeCandidateGroup(group = []) { + const options = group.flatMap(entry => { + const fallbackId = entry.sourceSection.toLowerCase().includes('action') ? 'action' : 'feature'; + return (entry.items || []).slice(0, 24).map((item, index) => normalizeFeatureOption(item, index, fallbackId, entry.sourceSection, entry.defaultLane)); + }).filter(item => item.title).slice(0, 24); + return normalizeOptionIds(options); +} + function optionsFromBody(body = {}) { const featureSet = objectFrom(body.featureSet); const conceptMap = objectFrom(body.conceptMap || featureSet.conceptMap); @@ -511,16 +523,22 @@ 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' }, - { items: conceptMap.nextActions, sourceSection: 'concept-map.nextActions' }, - { items: conceptMap.nextMoves, sourceSection: 'concept-map.nextMoves' }, - { items: conceptMap.features, sourceSection: 'concept-map.features' }, - { items: conceptMap.candidates, sourceSection: 'concept-map.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: conceptMap.nextActions, sourceSection: 'concept-map.nextActions' }, + { items: conceptMap.nextMoves, sourceSection: 'concept-map.nextMoves' }, + { items: conceptMap.features, sourceSection: 'concept-map.features' }, + { items: conceptMap.candidates, sourceSection: 'concept-map.candidates' }, + { items: conceptMap.validateNext || conceptMap.validate || conceptMap.validation, sourceSection: 'concept-map.validateNext', defaultLane: 'validate-next' }, + { 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); if (Array.isArray(body.options)) { return normalizeOptionIds(body.options.slice(0, 24).map((item, index) => normalizeFeatureOption(item, index, 'option', 'options')).filter(item => item.title)); }