import { o as RankedLesson, A as AddLessonInput, a as AddLessonOptions, b as AddLessonResult, j as LessonsQuery } from './init-B0aI-g8W.js'; export { c as AddLessonTriggers, D as DEFAULT_RECALL_LIMIT, X as DEFAULT_RECALL_MAX_TOKENS, I as ImportLegacyOptions, d as ImportLegacyReport, Y as LESSONS_LOCK_FILENAME, L as LESSONS_PROCEDURAL_RULE, e as Lesson, f as LessonStatus, g as LessonsGraph, Z as LessonsGraphExistsError, h as LessonsGraphSchema, i as LessonsPaths, M as MatchedLesson, k as MergeLessonsOptions, l as MergeLessonsResult, m as MutateOptions, R as RankOptions, n as RankReason, S as ScaffoldLessonsResult, p as StripMarkersOptions, q as StripMarkersReport, T as Topic, r as Trigger, s as TriggerKind, U as UnknownTopicError, V as ValidationFinding, t as ValidationLevel, u as ValidationReport, v as acquireLessonsLock, w as addLesson, x as graphFilePath, y as importLegacyLessons, _ as lessonsLockPath, z as lessonsPaths, B as loadLessonsGraph, C as mergeLessons, E as mutateLessonsGraph, F as parseGraph, G as queryLessons, H as rankLessons, J as scaffoldLessons, K as serializeGraph, N as stripLegacyMarkers, O as stripMarkersInGraph, P as toRelPath, Q as tryLoadLessonsGraph, W as validateLessonsGraph } from './init-B0aI-g8W.js'; import 'zod'; /** * Migration-aware application APIs for the lessons subsystem. * * The WRITE path migrates automatically: `mutateLessonsGraph` (and everything * built on it — `addLesson`, `mergeLessons`, deprecate, strip-markers) runs the * legacy→JSON migration before mutating, so even a first raw write can never * create an empty `lessons.json` over an unmigrated `index.yaml`. (The migrator * and scaffolding use the internal `mutateLessonsGraphLocked` to avoid * recursing.) * * The low-level READ primitives (`tryLoadLessonsGraph`, `loadLessonsGraph`, * `queryLessons`) do NOT migrate — a first read through them on a legacy project * would see no graph. `recallLessons` closes that: it migrates first, then * loads + ranks. `captureLesson` is the symmetric capture entry point. Prefer * these application APIs; reach for the read primitives only post-migration. */ interface RecallOptions { /** Max ranked lessons to return. Defaults to {@link DEFAULT_RECALL_LIMIT}. */ readonly limit?: number; /** * Cumulative rule-token budget. Defaults to {@link DEFAULT_RECALL_MAX_TOKENS}; * pass `null` to disable the budget (return up to `limit` results). */ readonly maxTokens?: number | null; /** * Session correlator for recall dedup. Defaults to `AGENTSMESH_SESSION_ID`; * when set, lessons already delivered this session are suppressed. */ readonly sessionId?: string; /** Force dedup off even when a session correlator is present. */ readonly noDedup?: boolean; } interface RecallResult { /** Relevance-ranked, capped lessons (compact metadata lives on each entry). */ readonly lessons: RankedLesson[]; /** How many active lessons matched the query before the caps were applied. */ readonly totalMatches: number; /** * True when the canonical graph existed but could not be read (corrupt JSON / * schema drift). Recall degrades to empty instead of throwing; callers surface * this so a corrupt graph is a visible warning, not silent zero recall. */ readonly corrupt?: boolean; /** * Set to the on-disk schema version when the graph is newer than this build * understands. Recall degrades to empty (like `corrupt`) but callers surface * an upgrade hint rather than a "corrupt" warning. */ readonly newerVersion?: number; /** * Count of matched lessons suppressed because they were already delivered * earlier in this session (dedup). 0 when dedup is off or nothing repeated. */ readonly suppressed: number; } /** * Recall primitive for applications: migrate if needed, then return the active * lessons matching `query`, relevance-ranked and capped by limit + token budget. */ declare function recallLessons(projectRoot: string, query: LessonsQuery, options?: RecallOptions): Promise; /** * Capture primitive for applications: migrate if needed, then add the lesson * through the transactional write path. Idempotent on repeat (same rule+topic). * * Both CLI `lessons add` and MCP `lessons_add` route through here, so capture * telemetry is recorded once at this single entry point (mirroring how every * recall records through `recallLessons`). Every rejection — a dead trigger, an * unknown topic, a write-barrier failure — is recorded as a BLOCKED capture * before being rethrown, so `stats` never undercounts blocks. */ declare function captureLesson(projectRoot: string, input: AddLessonInput, options?: AddLessonOptions): Promise; /** * One-shot legacy→JSON migration on first access. Shared by the CLI dispatcher * AND the MCP handlers so that an MCP-only agent (query/add) does not strand a * legacy store: if it added first it would create `lessons.json`, which then * permanently blocks the absent-graph auto-migration. Returns true if it * migrated. No-op when a graph already exists or no legacy index is present. */ declare function maybeAutoMigrateLessons(projectRoot: string): Promise; /** * Safety gate for `command_pattern` triggers. * * Recall is mandatory (it runs before every edit/command) and matches * author-supplied patterns against the command string. A backtracking `RegExp` * can be driven super-linear by a crafted pattern — `(a+)+`, `(a|aa)+`, `a+a+`, * or even `a+b` (quadratic on a long non-matching input) — so one lesson could * hang recall. Local inspection of quantifier shape CANNOT prove a backtracking * regex linear, so we do not try: command patterns are matched by an in-repo * non-backtracking engine ({@link compileLinearMatcher}), which is provably * linear in the input length for any pattern it can compile. * * A pattern is "safe" iff the linear engine can compile it. Patterns it cannot * evaluate (invalid syntax, backreferences, lookarounds) are rejected at capture * (UNSAFE_TRIGGER_PATTERN) and skipped at read time — fail closed. */ /** True when `pattern` can be matched by the linear engine (no ReDoS risk). */ declare function isSafeRegexPattern(pattern: string): boolean; export { AddLessonInput, AddLessonOptions, AddLessonResult, LessonsQuery, RankedLesson, type RecallOptions, type RecallResult, captureLesson, isSafeRegexPattern, maybeAutoMigrateLessons, recallLessons };