"use strict";
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2024-2026 Gracker (Chris)
// This file is part of SmartPerfetto. See LICENSE for details.
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * Strategy admin endpoints.
 *
 * Exposes a hot-reload endpoint so strategy auto-patches can take effect on
 * a running production backend without a restart. In dev mode strategies are
 * read on every access (DEV_MODE skip cache), so this endpoint is essentially
 * a no-op there — it still provides an explicit signal that future runs
 * should re-parse from disk.
 *
 * See docs/architecture/self-improving-design.md §11–12.
 */
const express_1 = __importDefault(require("express"));
const strategyLoader_1 = require("../agentv3/strategyLoader");
const metricsAggregator_1 = require("../agentv3/selfImprove/metricsAggregator");
const auth_1 = require("../middleware/auth");
const router = express_1.default.Router();
router.use(auth_1.authenticate);
/**
 * POST /api/admin/strategies/reload
 *
 * Drops the in-process strategy / template / phase-hints cache so the next
 * `analyze()` re-reads `.strategy.md` and `.template.md` from disk.
 *
 * Safe to call any time — already-running analyses snapshot their strategy
 * version at start and are not retroactively affected.
 */
router.post('/strategies/reload', (_req, res) => {
    try {
        (0, strategyLoader_1.invalidateStrategyCache)();
        res.json({ success: true, reloadedAt: new Date().toISOString() });
    }
    catch (err) {
        console.error('[StrategyAdmin] Reload failed:', err.message);
        res.status(500).json({ success: false, error: 'Failed to reload strategy cache' });
    }
});
/**
 * GET /api/admin/self-improve/metrics
 *
 * Read-only snapshot of every self-improving subsystem (pattern memory,
 * supersede markers, review outbox, skill notes, feedback). The dashboard
 * polls this and the trend regression suite snapshots it. Aggregation is
 * best-effort — a corrupt subsystem shows up in `warnings` rather than
 * taking the whole endpoint down.
 */
router.get('/self-improve/metrics', (_req, res) => {
    try {
        const metrics = (0, metricsAggregator_1.collectSelfImproveMetrics)();
        res.json(metrics);
    }
    catch (err) {
        console.error('[SelfImproveMetrics] Aggregation failed:', err.message);
        res.status(500).json({ success: false, error: 'Failed to aggregate metrics' });
    }
});
exports.default = router;
//# sourceMappingURL=strategyAdminRoutes.js.map