import { parse as parseYaml } from 'yaml'; import { type ManifestForCapabilityCheck, checkCapabilityVersions } from './capability-versions'; import { checkContractVersion } from './contract-version'; import { checkGitHygiene } from './git-hygiene'; import { checkManifestSchema, readManifestYaml } from './manifest-schema'; import type { Check, RunChecksOptions } from './types'; import { checkTypeScriptBuild } from './typescript-build'; import { checkWorkspaceDeps, defaultFetchNpmMetadata } from './workspace-deps'; export type { Check, CheckCategory, CheckStatus, NpmMetadata, RunChecksOptions } from './types'; export { checkCapabilityVersions, validateCapabilityVersions, type ManifestForCapabilityCheck, } from './capability-versions'; export { checkContractVersion } from './contract-version'; export { checkGitHygiene, checkModuleStale, type StalenessIssue } from './git-hygiene'; export { checkManifestSchema } from './manifest-schema'; export { checkTypeScriptBuild } from './typescript-build'; export { checkWorkspaceDeps, defaultFetchNpmMetadata } from './workspace-deps'; interface RawManifest extends ManifestForCapabilityCheck { celilo_contract?: string; version_source?: { kind?: string }; } /** * Runs every checker against the module at `modulePath` and returns the * combined `Check[]` in a stable, human-friendly order: * * 1. manifest_schema — bedrock; if this fails, downstream checks * may not even have a parseable manifest * 2. contract_version — top-of-file claim; semantically the framing * for everything else * 3. capability — manifest's claimed capability versions * 4. workspace_dep — npm-fed; the only network-dependent check * 5. git_hygiene — publish-readiness gates (stale-version drift, * dirty-tree); same shape `module publish` * enforces, surfaced here so a clean check * really does mean a clean publish * 6. typescript_build — slowest, most likely to spew errors * * Each checker returns its own Check[]; the orchestrator does no * filtering or reshaping. CLI presentation is layered on top. */ export async function runChecks( modulePath: string, options: RunChecksOptions = {}, ): Promise { const fetcher = options.fetchNpmMetadata ?? defaultFetchNpmMetadata; const checks: Check[] = []; const schemaCheck = await checkManifestSchema(modulePath); checks.push(schemaCheck); let manifest: RawManifest | null = null; try { const yaml = await readManifestYaml(modulePath); manifest = parseYaml(yaml) as RawManifest; } catch { // Couldn't even read the YAML — manifest_schema check above already // reports the failure. Skip the rest of the manifest-derived checks. } if (manifest) { checks.push(checkContractVersion(manifest)); checks.push(...checkCapabilityVersions(manifest)); } checks.push(...(await checkWorkspaceDeps(modulePath, fetcher))); checks.push(...checkGitHygiene(modulePath, manifest?.version_source?.kind)); checks.push(await checkTypeScriptBuild(modulePath, { noBuild: options.noBuild })); return checks; }