/** * BootstrapService — Phase 4 repo bootstrap (G6). * * Scans a project root for high-signal context (recent git history, README, * docs, package manifests, top-central files from the existing PageRank ETL) * and turns them into seed memories (types pattern/code/decision) via the * Phase-1 llm-client. Stored through the existing MemoryRepository so they * are searchable by the existing recall/FTS path. * * Contract (spec.md R1–R6, NF1–NF2): * - Idempotent: a seed memory tagged `bootstrap:` is the marker; * a second run without `force` is a no-op. * - Silent degradation: when the LLM is off / `{ok:false}` / throws, falls * back to rule-based minimal seeds derived from README + git log. When * even those signals are empty, skips seeding with a logged reason. * NEVER throws. * - Migration-free: seed memories are rows in the existing memories table. * * Test-isolation (mirrors Phase-3 ObservationConsolidationJob): the ctor * accepts injectable `memoryRepo`, `llm` (LlmSurface), `isBootstrapped`, * `symbolGraph`, and `gitRunner` seams. Defaults resolve lazily at run time * so the closed-MemoryRepository-singleton landmine (memory-crud.test.ts) * does not poison bootstrap tests. */ import { z } from "zod"; import type { InsertMemoryInput } from "../../data/memory/memory-repository.js"; import type { LlmSurface } from "../memory/consolidator.js"; export type SeedType = "pattern" | "code" | "decision"; export interface BootstrapSeed { summary: string; type: SeedType; level: 0 | 1 | 2; importance: number; rationale?: string; } export interface BootstrapSignals { gitLog: string[]; readme?: string; docs: Array<{ path: string; snippet: string; }>; manifests: Array<{ kind: string; name?: string; description?: string; deps?: string[]; }>; centralFiles: Array<{ filePath: string; score: number; }>; } export type BootstrapSource = "llm" | "rule-based" | "none"; export interface BootstrapResult { bootstrapped: boolean; reason?: string; skipped?: boolean; source: BootstrapSource; bootstrapId?: string; seedMemoryIds: string[]; signalCount: number; memoryCount: number; } export interface BootstrapOptions { projectPath?: string; force?: boolean; } /** * Injectable memory-repository seam. The default implementation resolves * getMemoryRepository() lazily inside each method (test-isolation). */ export interface MemoryRepoSeam { insert(input: InsertMemoryInput): void | Promise; /** Whether any non-deleted memory tagged `bootstrap:` exists. */ hasBootstrapMarker(projectId: string): boolean; } /** Centrality source — narrowed SymbolGraphService surface. */ export interface CentralitySource { getTopCentralFiles(projectId: string, limit?: number): Promise>; } /** Git runner — narrowed surface so tests inject a fake (no subprocess). */ export interface GitRunner { (cwd: string, args: string[]): Promise<{ ok: boolean; stdout: string; stderr?: string; }>; } export interface BootstrapDeps { llm?: LlmSurface; memoryRepo?: MemoryRepoSeam; isBootstrapped?: (projectId: string) => boolean; symbolGraph?: CentralitySource; gitRunner?: GitRunner; } /** * zod schema for the LLM object call. A bounded list of seed memories. * Exported for tests + consumers that want the same contract. */ export declare const SeedMemoriesSchema: z.ZodObject<{ memories: z.ZodArray; level: z.ZodUnion, z.ZodLiteral<1>, z.ZodLiteral<2>]>; importance: z.ZodNumber; rationale: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>; export type SeedMemories = z.infer; export declare class BootstrapService { private readonly llm; private readonly memoryRepo; private readonly isBootstrappedFn; private readonly symbolGraph; private readonly gitRunner; constructor(deps?: BootstrapDeps); /** * Run a bootstrap pass for `projectId`. Idempotent unless `force`. Never * throws (R5 silent degradation). */ bootstrap(projectId: string, opts?: BootstrapOptions): Promise; } /** * Gather repo signals. Every step is best-effort; a failing step yields its * empty default. Never throws. */ export declare function scanSignals(_projectId: string, projectRoot: string, caps: { gitLogLimit: number; centralityLimit: number; }, symbolGraph: CentralitySource, gitRunner: GitRunner): Promise; export declare function summarizeWithLlm(signals: BootstrapSignals, surface: LlmSurface, maxSeedMemories: number): Promise<{ ok: true; seeds: BootstrapSeed[]; } | { ok: false; reason: string; }>; /** * Derive minimal seeds from the cheapest signals without an LLM call. * Capped at 3 seeds. Empty when no usable signal exists. */ export declare function ruleBasedSeed(signals: BootstrapSignals): BootstrapSeed[]; export declare function storeSeeds(memoryRepo: MemoryRepoSeam, projectId: string, bootstrapId: string, seeds: BootstrapSeed[], signals: BootstrapSignals): Promise; export declare function countSignals(s: BootstrapSignals): number; export declare function getBootstrapService(): BootstrapService; export declare function resetBootstrapService(): void; export declare const bootstrapService: BootstrapService; //# sourceMappingURL=bootstrap-service.d.ts.map