/**
 * WikiWorkItemBridgeService — materialises pending wiki work as claimable WIs.
 *
 * Replaces the wiki-bookkeep / wiki-reflect "shouldFire ≥ threshold" cron
 * model with the same V3 pool the rest of the system uses. Two source
 * streams feed the pool:
 *
 *   1. Pending `wiki-queue` items (one WI per vault that has ≥ 1 pending
 *      item; the agent drains the whole vault in that WI).
 *   2. Legacy `.crewly/knowledge/*` migration candidates per project (one
 *      WI per project root with > 0 proposed pages).
 *
 * Idle agents claim them through `TaskPoolService.claimFromPool` — no
 * extra cron decisions about who to ping. Failures route through the
 * standard task:failed / reconciler escalation paths (closing the loop
 * with the 2026-05-27 reconciler-escalation fix in
 * `reconciler-data-provider.ts:applyCorrection`).
 *
 * PR-1 routing (conservative): both kinds target the orchestrator
 * session. The wiki skills today live under `config/skills/orchestrator/`,
 * so ORC is the only role with a built-in handler. Broadening to TLs is
 * a follow-up once the skills are promoted to a shared path.
 *
 * Dedupe: at most one non-terminal WI per (kind, vaultPath/projectRoot).
 *
 * @module services/wiki/wiki-workitem-bridge.service
 */
import { TaskPoolService } from '../task-pool/task-pool.service.js';
import { WikiQueueService } from './wiki-queue.service.js';
import { WikiMigrateService } from './wiki-migrate.service.js';
import { WikiCleanupService } from './wiki-cleanup.service.js';
/** WorkItem.metadata.kind value identifying a wiki queue drain WI. */
export declare const META_KIND_WIKI_DRAIN: "wiki_queue_drain";
/** WorkItem.metadata.kind value identifying a wiki legacy migration WI. */
export declare const META_KIND_WIKI_MIGRATE: "wiki_legacy_migrate";
/** WorkItem.metadata.kind value identifying a wiki cleanup (low-quality removal) WI. */
export declare const META_KIND_WIKI_CLEANUP: "wiki_quality_cleanup";
export interface WikiWorkItemBridgeOptions {
    /** How often to scan vaults + projects (default 10 min). */
    intervalMs?: number;
    /** Target agent session for the created WIs (default `crewly-orc`). */
    targetAgent?: string;
    /**
     * Max new WIs to publish per tick (default 2). Throttles PTY flood —
     * see {@link DEFAULT_MAX_CREATES_PER_TICK}.
     */
    maxCreatesPerTick?: number;
    /**
     * Per-key cooldown (default 30 min) between successive create attempts
     * for the same vault path or project root. Survives pool deletes —
     * see {@link DEFAULT_COOLDOWN_MS}.
     */
    cooldownMs?: number;
    /** Time source override (test seam). Returns `Date.now()` by default. */
    now?: () => number;
    /**
     * Override the state file path (test seam). When omitted, the bridge
     * resolves `~/.crewly/wiki-bridge-state.json` via `getCrewlyHomePath()`.
     * Passing `null` disables persistence entirely — handy for unit tests
     * that don't want filesystem side effects.
     */
    statePath?: string | null;
    /** Vault discovery override (default: `discoverWikiVaults`). */
    discoverRoots?: () => Promise<string[]>;
    /** Project-root discovery override (default: cwd + projects.json entries). */
    discoverProjectRoots?: () => Promise<string[]>;
    /** Wiki queue service override (test seam). */
    queueService?: WikiQueueService;
    /** Wiki migrate service override (test seam). */
    migrateService?: WikiMigrateService;
    /** Wiki cleanup service override (test seam). */
    cleanupService?: WikiCleanupService;
    /** Task pool override (test seam). */
    taskPool?: TaskPoolService;
}
export interface WikiBridgeTickResult {
    scannedVaults: string[];
    createdForVault: string[];
    skippedInflightVaults: string[];
    scannedProjects: string[];
    createdForProject: string[];
    skippedInflightProjects: string[];
    /** Candidates that were eligible but deferred to the next tick because of {@link WikiWorkItemBridgeOptions.maxCreatesPerTick}. */
    deferredByThrottle: string[];
    /** Candidates skipped because their cooldown hasn't elapsed yet. */
    skippedByCooldown: string[];
    /** Vault paths for which a cleanup WI was created this tick. */
    createdCleanupForVault: string[];
}
/**
 * Periodic bridge: pending wiki queue items + migration candidates
 * become claimable WorkItems in the V3 pool.
 */
export declare class WikiWorkItemBridgeService {
    private static instance;
    private readonly logger;
    private readonly intervalMs;
    private readonly targetAgent;
    private readonly maxCreatesPerTick;
    private readonly cooldownMs;
    private readonly nowFn;
    private readonly discoverRoots;
    private readonly discoverProjectRoots;
    private readonly queue;
    private readonly migrate;
    private readonly cleanup;
    private readonly pool;
    private timer;
    private running;
    /** Per-key (kind + path) last-create timestamp. Survives pool deletes. */
    private readonly lastCreatedAt;
    /** Absolute path of the persisted state file (or `null` to disable). */
    private readonly statePath;
    /** True after `loadStateFromDisk` has either populated or no-op'd. */
    private stateLoaded;
    constructor(opts?: WikiWorkItemBridgeOptions);
    /**
     * Hydrate {@link lastCreatedAt} from disk. Idempotent — runs once per
     * service lifetime. Bad/missing/stale-version files reset to empty.
     */
    private loadStateFromDisk;
    /**
     * Persist {@link lastCreatedAt} to disk. Best-effort — write failures
     * are logged but never throw (the bridge is non-essential infrastructure).
     * Prunes expired entries before writing so the file stays small.
     */
    private saveStateToDisk;
    /**
     * True iff the key's cooldown is still active (i.e., we created a WI
     * for this key recently). Survives forced pool deletes so an
     * agent-driven cleanup can't trick the bridge into re-creating
     * immediately.
     */
    private isCoolingDown;
    private markCreated;
    static getInstance(): WikiWorkItemBridgeService | null;
    /** Wire / detach the production singleton. */
    static setInstance(next: WikiWorkItemBridgeService | null): void;
    /** Start the periodic scan. Idempotent. Fires an immediate tick. */
    start(): void;
    stop(): void;
    /** Single pass — exposed for tests and the initial boot-time fire. */
    tick(): Promise<WikiBridgeTickResult>;
    /**
     * Build the dedupe sets from the pool's current contents. A WI is
     * "in-flight" if its kind metadata matches and its status is not
     * terminal — i.e. it's still queued/claimed/running/etc.
     */
    private snapshotInflight;
    private createDrainWorkItem;
    private createCleanupWorkItem;
    private createMigrateWorkItem;
}
/**
 * Best-effort label for a vault path that surfaces in UI/list views.
 * Order matters: check global before the generic project tail.
 */
export declare function describeVaultScope(vaultPath: string): string;
/**
 * Default project-root discovery used by the production bridge. Mirrors
 * `discoverWikiVaults`'s project sources but returns roots, not vault paths.
 */
export declare function defaultProjectRoots(): Promise<string[]>;
//# sourceMappingURL=wiki-workitem-bridge.service.d.ts.map