import { StorageManager } from './storage.js';
import { BriefingSections, BriefingFollowup, BriefingFocus, CalendarSource, CalendarEvent, MemoryFile, BriefingActiveThread, BriefingResult, EntityFile, BriefingRecentEntity } from './types.js';
import './page-versioning.js';
import './consolidation-operator.js';
import './memory-projection-store-D3vBHS4J.js';
import 'better-sqlite3';

/**
 * Daily Context Briefing (Issue #370)
 *
 * Produces a focused "here is what matters right now" briefing by
 * cross-referencing active entities, recent facts, open commitments,
 * LLM-generated follow-ups, and an optional calendar source.
 *
 * The module exposes:
 *   - `parseBriefingWindow(token)` — CLI-friendly window parser.
 *   - `buildBriefing(options)` — core builder that returns markdown + JSON.
 *   - `FileCalendarSource` — stub CalendarSource implementation that reads
 *     a local ICS or JSON file.
 *
 * ALL OpenAI usage in this module goes through the Responses API. Chat
 * Completions is never used.
 */

/** Allowed values for the briefing format flag/field. */
declare const BRIEFING_FORMAT_ALLOWED: readonly ["markdown", "json"];
/**
 * Default model used for the Responses API follow-up generation call.
 * Mirrors the extraction engine default in config.ts — keep in sync.
 */
declare const BRIEFING_FOLLOWUP_DEFAULT_MODEL = "gpt-5.2";
type BriefingFormatValue = typeof BRIEFING_FORMAT_ALLOWED[number];
/**
 * Validate a user-supplied `--format` flag value.
 * Returns `null` when the value is valid (or `undefined`, meaning the flag
 * was not supplied and the caller should fall back to the configured default).
 * Returns an error message string when the value is explicitly invalid.
 */
declare function validateBriefingFormat(value: string | undefined): string | null;
/** Parsed briefing lookback window. */
interface ParsedBriefingWindow {
    /** Start of the window (inclusive). */
    from: Date;
    /** End of the window (exclusive). */
    to: Date;
    /** Human-readable label. */
    label: string;
}
/**
 * Parse a CLI-friendly window token into a concrete date range.
 *
 * Accepted forms (case-insensitive):
 *   - `yesterday` — the previous UTC calendar day.
 *   - `today`    — the current UTC calendar day so far.
 *   - `NNh`      — last N hours (e.g. `24h`, `48h`).
 *   - `NNd`      — last N calendar days (e.g. `3d`, `7d`).
 *   - `NNw`      — last N weeks (e.g. `1w`, `2w`).
 *
 * Returns `null` for invalid tokens so callers can surface a clean error.
 */
declare function parseBriefingWindow(token: string, now?: Date): ParsedBriefingWindow | null;
/**
 * Parse a CLI `--focus` string into a structured focus filter.
 *
 * Accepted forms:
 *   - `person:Jane Doe`
 *   - `project:remnic-core`
 *   - `topic:retrieval`
 *
 * If no prefix is supplied, falls back to `topic:<value>`.
 */
declare function parseBriefingFocus(token: string | undefined): BriefingFocus | null;
/**
 * Decide whether a memory/entity matches the given focus filter.
 * Purely deterministic — no LLM, case-insensitive substring match across
 * the most useful surfaces.
 *
 * For typed focus (`person:`, `project:`, `entity:`) we attribute via the
 * canonical-id path below to avoid the substring leak fixed in #682 PR 2/3
 * R-10 (`Alice-Test` substring-hitting `person-alice-test-a1`).
 *
 * For untyped (`topic`) focus there is no type to canonicalize against, so
 * we keep `entityRef` in the raw haystack — otherwise memories that link to
 * an entity only via `frontmatter.entityRef` (no body / tag mention) would
 * silently drop out of an untyped focus filter (codex P2 review on #695).
 */
declare function focusMatchesMemory(memory: MemoryFile, focus: BriefingFocus): boolean;
declare function focusMatchesEntity(entity: EntityFile, focus: BriefingFocus): boolean;
/**
 * Stub `CalendarSource` backed by a single local file. Supports:
 *   - JSON files containing an array of `CalendarEvent` records, OR a wrapper
 *     `{ events: CalendarEvent[] }` object.
 *   - Minimal ICS (`.ics`) files — extracts `VEVENT` blocks with `SUMMARY`,
 *     `DTSTART`, `DTEND`, `LOCATION`, `DESCRIPTION`, `UID`.
 *
 * Real calendar integrations (Google, iCloud, Microsoft) can plug into the
 * same `CalendarSource` interface later.
 */
declare class FileCalendarSource implements CalendarSource {
    private readonly filePath;
    constructor(filePath: string);
    eventsForDate(dateIso: string): Promise<CalendarEvent[]>;
}
/** @internal — exported for testing only. */
declare function parseIcsEvents(raw: string): CalendarEvent[];
/** @internal — exported for testing only. */
declare function eventFallsOnDate(event: CalendarEvent, dateIso: string): boolean;
/** Dependency-injection hook for LLM follow-up generation (used in tests). */
type BriefingFollowupGenerator = (prompt: {
    sections: BriefingSections;
    windowLabel: string;
    maxFollowups: number;
}) => Promise<BriefingFollowup[]>;
/** Options accepted by `buildBriefing`. */
interface BuildBriefingOptions {
    /** Workspace-scoped storage. Tests pass a temp dir. */
    storage: StorageManager;
    /** Parsed window. If omitted, a default 1-day window is used. */
    window?: ParsedBriefingWindow;
    /** Optional focus filter. */
    focus?: BriefingFocus | null;
    /** Optional namespace hint for logging. */
    namespace?: string;
    /** Calendar source. Section omitted entirely when undefined. */
    calendarSource?: CalendarSource;
    /** Maximum LLM follow-ups (0 to disable the section). */
    maxFollowups?: number;
    /** Whether the module is allowed to invoke the Responses API. */
    allowLlm?: boolean;
    /** OpenAI API key. If absent the follow-up section is gracefully omitted. */
    openaiApiKey?: string;
    /** OpenAI-compatible base URL (for Azure or proxied endpoints). */
    openaiBaseUrl?: string;
    /** Model id for the Responses call. */
    model?: string;
    /** Injected follow-up generator. Overrides real LLM call (tests). */
    followupGenerator?: BriefingFollowupGenerator;
    /** Injected "now" — makes tests deterministic. */
    now?: Date;
}
/**
 * Build the daily context briefing.
 *
 * Never throws on LLM failures — the suggested follow-ups section is simply
 * omitted and `followupsUnavailableReason` is set.
 */
declare function buildBriefing(options: BuildBriefingOptions): Promise<BriefingResult>;
/** @internal — exported for testing only. */
declare function filterMemoriesByWindow(memories: MemoryFile[], window: ParsedBriefingWindow): MemoryFile[];
/** @internal — exported for testing only. */
declare function buildActiveThreads(memories: MemoryFile[]): BriefingActiveThread[];
/** @internal — exported for testing only. */
declare function buildRecentEntities(entities: EntityFile[], window: ParsedBriefingWindow, focus: BriefingFocus | null): BriefingRecentEntity[];
interface RenderContext {
    sections: BriefingSections;
    windowLabel: string;
    focus: BriefingFocus | null;
    followupsUnavailableReason?: string;
    generatedAt: Date;
    namespace?: string;
}
declare function renderBriefingMarkdown(ctx: RenderContext): string;
/**
 * Resolve the directory where `--save` writes dated briefings.
 * Respects the following precedence:
 *   1. explicit `configOverride` argument
 *   2. `$REMNIC_HOME/briefings/`
 *   3. `$HOME/.remnic/briefings/`
 */
declare function resolveBriefingSaveDir(configOverride: string | null | undefined, env?: NodeJS.ProcessEnv): string;
/** Format the dated filename for a given briefing. */
declare function briefingFilename(date: Date, format?: "markdown" | "json"): string;

export { BRIEFING_FOLLOWUP_DEFAULT_MODEL, BRIEFING_FORMAT_ALLOWED, type BriefingFollowupGenerator, type BriefingFormatValue, type BuildBriefingOptions, FileCalendarSource, type ParsedBriefingWindow, briefingFilename, buildActiveThreads, buildBriefing, buildRecentEntities, eventFallsOnDate, filterMemoriesByWindow, focusMatchesEntity, focusMatchesMemory, parseBriefingFocus, parseBriefingWindow, parseIcsEvents, renderBriefingMarkdown, resolveBriefingSaveDir, validateBriefingFormat };
