Artifact
The artifact module handles scanning, parsing, naming, integrity verification, and lockfile management for grekt artifacts.
Scanner
scanArtifact
function scanArtifact(fs: FileSystem, artifactDir: string): ArtifactInfo | nullScans a directory and returns structured information about the artifact it contains. Returns null if the directory is not a valid artifact.
The returned ArtifactInfo includes the manifest, all discovered components organized by category, and any invalid files found.
generateComponents
function generateComponents(info: ArtifactInfo): ComponentsAuto-generates the components section from scanned files. Used during publish/pack to populate the manifest.
Frontmatter
parseFrontmatter
function parseFrontmatter(content: string): FrontmatterParseResultParses YAML frontmatter from markdown artifact files:
type FrontmatterParseResult =
| { success: true; parsed: ParsedArtifact }
| { success: false; reason: InvalidFileReason }The frontmatter must contain grk-type, grk-name, and grk-description fields.
Naming
Utilities for artifact ID parsing and safe filename generation.
parseName
function parseName(name: string): {
scope: string | null
baseName: string
artifactId: string
}Parses an artifact name into its components. Handles both scoped (@org/name) and unscoped (name) formats.
isScoped
function isScoped(name: string): booleanChecks if a name uses the @scope/name format.
getSafeFilename
function getSafeFilename(artifactId: string, filepath: string): stringGenerates a filesystem-safe filename from an artifact ID and component path. For example, getSafeFilename("@grekt/analyzer", "analyze.md") returns "grekt-analyzer_analyze.md".
toSafeName
function toSafeName(artifactId: string): stringConverts an artifact ID to a safe directory name. toSafeName("@grekt/analyzer") returns "grekt-analyzer".
buildArtifactId
function buildArtifactId(scope: string, name: string): stringBuilds a full artifact ID from scope and name.
getArtifactIdFromManifest
function getArtifactIdFromManifest(manifest: ArtifactManifest): stringExtracts the artifact ID from a manifest object.
Integrity
SHA256-based integrity verification for artifacts.
hashDirectory
function hashDirectory(
fs: FileSystem,
dir: string
): Record<string, string>Returns a map of relative file paths to their SHA256 hashes.
calculateIntegrity
function calculateIntegrity(fileHashes: Record<string, string>): stringCalculates a single integrity hash from a map of file hashes. The file hashes are sorted before hashing to ensure determinism.
verifyIntegrity
function verifyIntegrity(
fs: FileSystem,
artifactDir: string,
expectedFiles: Record<string, string>
): IntegrityResultVerifies that an artifact directory matches expected hashes:
interface IntegrityResult {
valid: boolean
missingFiles: string[]
modifiedFiles: string[]
extraFiles: string[]
}getDirectorySize
function getDirectorySize(fs: FileSystem, dir: string): numberCalculates the total size in bytes of all files in a directory.
Lockfile
getLockfile
function getLockfile(fs: FileSystem, lockfilePath: string): ParseResult<Lockfile>Reads and parses a lockfile. Returns a ParseResult with friendly error messages if parsing fails.
saveLockfile
function saveLockfile(fs: FileSystem, lockfilePath: string, data: Lockfile): voidWrites a lockfile to disk.
createEmptyLockfile
function createEmptyLockfile(): LockfileCreates a new empty lockfile with version: 1.
lockfileExists
function lockfileExists(fs: FileSystem, lockfilePath: string): booleanChecks if a lockfile exists at the given path.