Files
Orchestrator/dhive/Jury-Voting/server/conflict.ts
ankn a5f8fb49ab Migrate all repos into monorepo context folders
Bahn: aisupport, Analyse-O2C-C2S, awesome-bahn-mcp-servers, beam-mcp,
      Confluence_Bot, db-planet-mcp-server, O2C-Harness, project-audit,
      Projekt-KIQ-HP, teamlandkarte-mcp
Dhive: Jury-Voting
Privat: CV, NoteGraph (NOTE: NoteGraph needs complete redo after consolidation)
Shared: AI-Orchestrator, OrgMyLife, power_skills_and_more
Shared/references: symphony (read-only)

Bahn repos remain available as independent remotes - this monorepo
pulls them in via subtree, the originals are untouched.
2026-06-30 20:39:52 +02:00

48 lines
1.1 KiB
TypeScript

import { Score } from '../shared/types.js';
export interface ConflictResult {
accept: boolean;
reason?: string;
}
/**
* Determine whether an incoming score should be accepted over an existing one.
* Uses last-write-wins strategy based on updatedAt timestamps.
*
* - If no existing score → accept
* - If incoming.updatedAt > existing.updatedAt → accept (last-write-wins)
* - If incoming.updatedAt <= existing.updatedAt → reject
*/
export function shouldAcceptScore(
incoming: Score,
existing: Score | undefined
): ConflictResult {
if (!existing) {
return { accept: true };
}
if (incoming.updatedAt > existing.updatedAt) {
return { accept: true };
}
return { accept: false, reason: 'Newer score already exists' };
}
/**
* Resolve a score conflict with optional force override.
*
* - If force is true → always accept
* - Otherwise delegate to shouldAcceptScore (last-write-wins)
*/
export function resolveConflict(
incoming: Score,
existing: Score | undefined,
force?: boolean
): ConflictResult {
if (force) {
return { accept: true };
}
return shouldAcceptScore(incoming, existing);
}