// orchestrator/file-ownership.ts — File ownership map generation (SPEC-079 AC-09)
// Generates ownership maps from task assignments, ensuring no conflicts.
/**
 * Generate a FileOwnershipMap from task assignments.
 * Maps each file path to the agent that owns it.
 * If multiple agents claim the same file, the first assignment wins
 * and conflicts are returned separately.
 */
export function generateFileOwnershipMap(assignments) {
    const map = {};
    const conflicts = [];
    for (const assignment of assignments) {
        for (const file of assignment.files) {
            const existing = map[file];
            if (existing !== undefined && existing !== assignment.agentId) {
                if (!conflicts.includes(file)) {
                    conflicts.push(file);
                }
            }
            else if (existing === undefined) {
                map[file] = assignment.agentId;
            }
        }
    }
    return { map, conflicts };
}
/**
 * Get the list of files owned by a specific agent.
 */
export function getAgentFiles(ownershipMap, agentId) {
    return Object.entries(ownershipMap)
        .filter(([, owner]) => owner === agentId)
        .map(([file]) => file);
}
/**
 * Check if an agent owns a specific file.
 */
export function agentOwnsFile(ownershipMap, agentId, file) {
    return ownershipMap[file] === agentId;
}
/**
 * Format ownership map as markdown for agent handoff context.
 * Uses relative paths (not absolute) for language-agnostic portability.
 */
export function formatOwnershipContext(ownershipMap, agentId) {
    const ownedFiles = getAgentFiles(ownershipMap, agentId);
    const otherFiles = Object.entries(ownershipMap)
        .filter(([, owner]) => owner !== agentId)
        .map(([file, owner]) => `  - ${file} (owned by ${owner})`);
    const lines = [
        '## File Ownership',
        '',
        '### Your files (read + write):',
        ...ownedFiles.map((f) => `  - ${f}`),
        '',
    ];
    if (otherFiles.length > 0) {
        lines.push('### Other files (read only):', ...otherFiles, '');
    }
    return lines.join('\n');
}
//# sourceMappingURL=file-ownership.js.map