* Best-effort syntactic + semantic validation of TypeScript code returned * by the model. Loads the user's installed `typescript` module on demand, * runs `createSourceFile` for parse diagnostics, then `createProgram` with * an in-memory compiler host for both syntactic and semantic diagnostics.
(value)
| 206 | * If `typescript` isn't installed, returns ok:true with a 'skipped' note. |
| 207 | */ |
| 208 | async function validateAstCompiles(value) { |
| 209 | // Phase 14: File / list<File> dispatch. Single File: validate its |
| 210 | // .content. List of Files: validate each, prefix issues by path, OR |
| 211 | // together (one bad file fails the whole list). |
| 212 | if (Array.isArray(value)) { |
| 213 | return validateFileList(value); |
| 214 | } |
| 215 | if (value && typeof value === "object" && "path" in value && "content" in value) { |
| 216 | const f = value; |
| 217 | return validateSingleFile(f); |
| 218 | } |
| 219 | if (typeof value !== "string" || value.trim().length === 0) { |
| 220 | (0, metrics_1.counter)("cognition.validate.failed", { mode: "ast_compiles", kind: "empty" }); |
| 221 | return { ok: false, issues: ["output must be a non-empty TypeScript string"] }; |
| 222 | } |
| 223 | return validateTypeScriptString(value); |
| 224 | } |
| 225 | async function validateSingleFile(f) { |
| 226 | if (typeof f.content !== "string" || f.content.trim().length === 0) { |
| 227 | (0, metrics_1.counter)("cognition.validate.failed", { mode: "ast_compiles", kind: "empty_file" }); |
nothing calls this directly
no test coverage detected