{"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../../src/core/search/trace.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAO9C,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI,CActE","sourcesContent":["/**\n * Search trace sink (docs/hybrid-retrieval-design.md, Decision 5).\n *\n * Full per-call diagnostics — resolved mode, per-retriever latency/hits,\n * fused ranks, raw scores — go to a jsonl sidecar in the embsearch store dir,\n * never into model context or session files. Best-effort by design: a failed\n * trace write must never fail a search.\n */\n\nimport { appendFileSync, mkdirSync, renameSync, statSync } from \"fs\";\nimport { join } from \"path\";\nimport { getEmbsearchStoreDir } from \"../embsearch/index-meta.js\";\nimport type { SearchTrace } from \"./types.js\";\n\nconst TRACE_FILE = \"search-trace.jsonl\";\n/** One rotation (`.1` suffix) once the live file passes this size, so traces\n *  stay bounded without a GC pass. */\nconst TRACE_ROTATE_BYTES = 5 * 1024 * 1024;\n\nexport function getSearchTracePath(cwd: string): string {\n\treturn join(getEmbsearchStoreDir(cwd), TRACE_FILE);\n}\n\nexport function writeSearchTrace(cwd: string, trace: SearchTrace): void {\n\ttry {\n\t\tconst dir = getEmbsearchStoreDir(cwd);\n\t\tmkdirSync(dir, { recursive: true });\n\t\tconst file = join(dir, TRACE_FILE);\n\t\ttry {\n\t\t\tif (statSync(file).size >= TRACE_ROTATE_BYTES) renameSync(file, `${file}.1`);\n\t\t} catch {\n\t\t\t// Missing file — nothing to rotate.\n\t\t}\n\t\tappendFileSync(file, `${JSON.stringify(trace)}\\n`);\n\t} catch {\n\t\t// Diagnostics only — never surface trace failures to the caller.\n\t}\n}\n"]}