// Discovery + extraction types for the Local Knowledge Connector (Epic #189, Issue #194).
// The discovery layer is the bridge between a `KnowledgeSource` and a `KnowledgeStore`:
// it walks files in scope via the workspace `WorkspaceFs` port, hands each file to the
// parser registry, and persists the document/page/section/parsed-unit/diagnostic rows.
// Chunks and vectors are NOT written here — those are #195 (chunking) and #196 (indexing).
//
// `DiscoveryError.code` is a closed string union so downstream UI surfaces and the eventual
// audit ledger entries can branch on stable identifiers rather than free-form messages.
export const DEFAULT_DISCOVERY_OPTIONS = {
    maxDepth: 12,
    maxFiles: 5_000,
};
// Branded helper so callers (extract.ts) don't need to repeat the cast. The returned id is
// deterministic in `(capsuleId, sourceId, relativePath)` so a re-walk of the same scope
// targets the SAME `documents` row — that's the lineage anchor for incremental updates.
//
// The `#` character is encoded as `%23` before embedding so that a file literally named
// `a#u0.md` cannot produce an id that collides with a parsed_unit suffix (`#u0`) or a
// diagnostic suffix (`#d0`) derived from a different document.
export function documentIdFor(input) {
    const encodedPath = input.relativePath.replace(/#/g, "%23");
    return `doc:${String(input.capsuleId)}:${String(input.sourceId)}:${encodedPath}`;
}
