import { defineHandler } from '@kb-labs/sdk';
import { SessionManager } from '@kb-labs/agent-core';
import { ChangeStore, toSummary } from '@kb-labs/agent-history';

// src/rest/handlers/list-file-changes-handler.ts
var list_file_changes_handler_default = defineHandler({
  async execute(ctx, input) {
    const params = input.params;
    const sessionId = params?.sessionId;
    if (!sessionId) {
      throw new Error("Session ID is required");
    }
    const query = input.query;
    const runId = query?.runId;
    const sessionManager = new SessionManager(ctx.cwd);
    const session = await sessionManager.loadSession(sessionId);
    if (!session) {
      throw new Error(`Session not found: ${sessionId}`);
    }
    const workingDir = session.workingDir || ctx.cwd;
    const store = new ChangeStore(workingDir);
    const changes = runId ? await store.listRun(sessionId, runId) : await store.listSession(sessionId);
    return {
      changes: changes.map(toSummary),
      total: changes.length,
      sessionId,
      runId
    };
  }
});

export { list_file_changes_handler_default as default };
//# sourceMappingURL=list-file-changes-handler.js.map
//# sourceMappingURL=list-file-changes-handler.js.map