{"version":3,"file":"tool-serializer.d.ts","sourceRoot":"","sources":["../../src/cache/tool-serializer.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,UAAU;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAwBD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,MAAM,CAQhE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,MAAM,CAE1D","sourcesContent":["// T-004: Deterministic alphabetically-sorted tool schema serializer.\n// T-006: Per-tool description edits isolate to tools-layer hash; strip paths/timestamps.\nimport { createHash } from \"node:crypto\";\n\nexport interface ToolSchema {\n\tname: string;\n\tdescription?: string;\n\tparameters?: unknown;\n}\n\nconst ISO_TIMESTAMP_RE = /\\b\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:?\\d{2})?\\b/g;\nconst ABSOLUTE_PATH_RE = /(?:\\/(?:Users|home|tmp|var|opt)\\/[^\\s\"'`]+)/g;\n\nfunction scrub(text: string): string {\n\treturn text.replace(ISO_TIMESTAMP_RE, \"<ts>\").replace(ABSOLUTE_PATH_RE, \"<path>\");\n}\n\nfunction sortKeysDeep(value: unknown): unknown {\n\tif (value === null || typeof value !== \"object\") {\n\t\treturn typeof value === \"string\" ? scrub(value) : value;\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn value.map(sortKeysDeep);\n\t}\n\tconst obj = value as Record<string, unknown>;\n\tconst sorted: Record<string, unknown> = {};\n\tfor (const key of Object.keys(obj).sort()) {\n\t\tsorted[key] = sortKeysDeep(obj[key]);\n\t}\n\treturn sorted;\n}\n\nexport function serializeToolSchemas(tools: ToolSchema[]): string {\n\tconst sorted = [...tools].sort((a, b) => a.name.localeCompare(b.name));\n\tconst normalized = sorted.map((tool) => ({\n\t\tdescription: tool.description ? scrub(tool.description) : \"\",\n\t\tname: tool.name,\n\t\tparameters: sortKeysDeep(tool.parameters ?? {}),\n\t}));\n\treturn JSON.stringify(normalized);\n}\n\nexport function toolSchemaHash(tools: ToolSchema[]): string {\n\treturn createHash(\"sha256\").update(serializeToolSchemas(tools)).digest(\"hex\");\n}\n"]}