MCPcopy
hub / github.com/Doorman11991/smallcode / validateAstCompiles

Function validateAstCompiles

src/compiled/cognition/validate.js:208–224  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

206 * If `typescript` isn't installed, returns ok:true with a 'skipped' note.
207 */
208async 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}
225async 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" });

Callers

nothing calls this directly

Calls 3

validateFileListFunction · 0.70
validateSingleFileFunction · 0.70
validateTypeScriptStringFunction · 0.70

Tested by

no test coverage detected