/** * KnowledgeWriter — validated writes to the YAML sources plus index sync. * * Same-id adds merge instead of duplicating (KG Req 4.4): union tags, keep * the higher confidence, prefer the incoming description, bump lastVerified. * Descriptions and metadata are screened for common secret patterns with a * warning — never store credentials in the graph (NFR N6). * * Requirements: KG 4.1–4.6, 12.1, 12.5 * * @module */ import type { Entity, Relationship } from './types.js'; import type { SeedInput } from './seed.js'; import type { YamlSourceStore } from './yaml-source.js'; import type { KnowledgeIndex } from './index/knowledge-index.js'; export interface WriteResult { entity: Entity; merged: boolean; warnings: string[]; } export interface ImportResult { added: number; updated: number; errors: string[]; warnings: string[]; } /** What `importDiscovered` did; `unchanged` entities were not written at all. */ export interface DiscoveryImportResult extends ImportResult { unchanged: number; } /** Resolve the author for a write: AIDLC_AUTHOR → git user.name → "unknown" (KG Req 12.1). */ export declare function resolveAuthor(cwd?: string): string; export declare class KnowledgeWriter { private readonly source; private readonly index; constructor(source: YamlSourceStore, index: KnowledgeIndex); /** * Add an entity; if the id already exists, merge fields (KG Req 4.4). * Fills defaults: confidence 0.9, author resolution, lastVerified now. */ addEntity(input: Partial & { id: string; type: string; name: string; }): WriteResult; /** * Throw if `input` would be rejected by `addEntity`, writing nothing. Lets a * batch be validated whole before any of it is written * (knowledge-add-corrupts-tags/AC-6). */ checkEntity(input: Partial & { id: string; type: string; name: string; }): void; /** Create a relationship between two existing entities (KG Req 4.2). */ addRelationship(input: { from: string; to: string; type: string; metadata?: Record; }): Relationship; /** Update fields on an existing entity (KG Req 4.3). */ updateEntity(id: string, updates: Partial>): WriteResult; /** Bulk import entities then relationships; per-item errors don't abort (KG Req 4.6). */ importBatch(entities: Array & { id: string; type: string; name: string; }>, relationships: Array<{ from: string; to: string; type: string; metadata?: Record; }>): ImportResult; /** * Import what `aidlc discover` inferred without overwriting what people wrote * (discover-clobbers-knowledge, design §3). Unlike `importBatch`, an existing * entity keeps its name, source, author, confidence, tags and any description * that is not a discovery placeholder; a generated module with no id match * writes into the one module sharing its name or source; and nothing is * rewritten whose facts did not change. */ importDiscovered(entities: SeedInput['entities'], relationships: SeedInput['relationships']): DiscoveryImportResult; /** Same id first (AC-7); then, for modules only, a unique name or source match (AC-5, AC-8, AC-9). */ private resolveDiscoveryTarget; private validateEntity; private screenForSecrets; } /** Parse comma-separated tags — the one meaning of a tags string, for `--tags` and YAML alike. */ export declare function parseTags(value: string | undefined): string[]; /** Merge an incoming entity into an existing one (KG Req 4.4). */ export declare function mergeEntities(existing: Entity, incoming: Entity): Entity; /** * Merge what discovery inferred into an existing entity, or `null` when nothing * would change (discover-clobbers-knowledge/AC-1–AC-4, AC-10). Only a description * that is empty or still a discovery placeholder is replaced, and only metadata * keys whose values differ are written. An absent `metadata` stays absent. */ export declare function mergeDiscovered(existing: Entity, incoming: Entity): Entity | null; //# sourceMappingURL=writer.d.ts.map