function createEmptyState() {
    return {
        task: '',
        plan: [],
        files: new Map(),
        decisions: [],
        failures: [],
        discoveries: [],
        environment: [],
        toolResults: [],
        userRequirements: [],
        assistantNotes: [],
    };
}
export class WorkingStateManager {
    state;
    config;
    constructor(config) {
        this.config = config;
        this.state = createEmptyState();
    }
    setTask(task) {
        this.state.task = task.slice(0, this.config.maxCharsPerTask);
    }
    setPlan(plan) {
        this.state.plan = plan;
    }
    trackFile(path, action) {
        const existing = this.state.files.get(path);
        if (existing) {
            existing.actions.push(action);
        }
        else {
            this.state.files.set(path, { path, actions: [action] });
        }
    }
    addDecision(decision) {
        this.pushWithEviction(this.state.decisions, decision, this.config.maxListSize);
    }
    addFailure(failure) {
        this.pushWithEviction(this.state.failures, failure, this.config.maxListSize);
    }
    addDiscovery(discovery) {
        this.pushWithEviction(this.state.discoveries, discovery, this.config.maxListSize);
    }
    addEnvironment(env) {
        this.pushWithEviction(this.state.environment, env, this.config.maxListSize);
    }
    addToolResult(result) {
        this.state.toolResults.push(result);
        while (this.state.toolResults.length > this.config.maxToolResults) {
            this.state.toolResults.shift();
        }
    }
    addUserRequirement(requirement) {
        const truncated = requirement.slice(0, this.config.maxCharsPerRequirement);
        this.pushWithEviction(this.state.userRequirements, truncated, this.config.maxListSize);
    }
    addAssistantNote(note) {
        const truncated = note.slice(0, this.config.maxCharsPerNote);
        this.pushWithEviction(this.state.assistantNotes, truncated, this.config.maxListSize);
    }
    slotCount() {
        let count = 0;
        if (this.state.task)
            count++;
        count += this.state.plan.length;
        count += this.state.files.size;
        count += this.state.decisions.length;
        count += this.state.failures.length;
        count += this.state.discoveries.length;
        count += this.state.environment.length;
        count += this.state.toolResults.length;
        count += this.state.userRequirements.length;
        count += this.state.assistantNotes.length;
        return count;
    }
    getState() {
        return this.state;
    }
    reset() {
        this.state = createEmptyState();
    }
    pushWithEviction(list, item, max) {
        list.push(item);
        while (list.length > max) {
            list.shift();
        }
    }
}
//# sourceMappingURL=manager.js.map