/**
 * Claude Code AgentObserver — adapts the existing ClaudeCodeWatcher to the
 * normalized cross-agent interface and registers it in the integration
 * registry.
 *
 * The watcher itself is unchanged (it's well-tested); this is a thin
 * normalization layer: ClaudeSessionInfo → AgentSession. Activity (Tier 2)
 * is attached when the watcher provides it.
 */
import { ClaudeCodeWatcher } from "./watcher.js";
import { registerIntegration } from "../registry.js";
function toAgentSession(info) {
    return {
        agent: "claude-code",
        sessionId: info.sessionId,
        project: info.projectLabel,
        cwd: info.cwd,
        state: info.state,
        stateReason: info.stateReason,
        lastMtime: info.lastMtime,
        activity: info.activity,
    };
}
export class ClaudeCodeObserver {
    agent = "claude-code";
    watcher;
    constructor(cfg) {
        // Tier 2: compute structural activity when visibility is "activity" or
        // "intent". At "metadata"/"off" we stay metadata-only (cheaper, and the
        // privacy-minimal default).
        const computeActivity = cfg.visibility === "activity" || cfg.visibility === "intent";
        this.watcher = new ClaudeCodeWatcher({
            log: (m) => console.error(m),
            computeActivity,
        });
    }
    async start(emit) {
        // The watcher's "update" payload is a lightweight ClaudeSessionUpdate
        // (no lastMtime/activity), so we re-derive the full session from the
        // current snapshot by sessionId. listActive() includes the just-updated
        // session (its mtime is current), so the lookup succeeds.
        this.watcher.on("update", (payload) => {
            const info = this.watcher
                .listActive()
                .find((s) => s.sessionId === payload.sessionId);
            if (info)
                emit(toAgentSession(info));
        });
        await this.watcher.start();
    }
    list() {
        return this.watcher.listActive().map(toAgentSession);
    }
    async stop() {
        this.watcher.stop();
    }
}
registerIntegration("claude-code", (cfg) => new ClaudeCodeObserver(cfg));
//# sourceMappingURL=observer.js.map