aiwg
Version:
Deployment tool and support utility for AI context. Copies agents, skills, commands, rules, and behaviors into the paths each AI platform reads (Claude Code, Codex, Copilot, Cursor, Warp, OpenClaw, and 6 more) so one source of truth works across 10 platfo
263 lines • 7.54 kB
TypeScript
/**
* Ground Truth Corpus Manager
*
* Manages multiple corpus types for NFR validation with versioning,
* schema validation, and statistics reporting.
*
* Supports 5 corpus types:
* - ai-vs-human: AI vs human writing classification
* - codebases: Codebase metadata validation
* - traceability: Requirements traceability links
* - security-attacks: Known attack pattern detection
* - template-recommendations: Template selection scenarios
*
* @module testing/corpus/ground-truth-manager
*/
/**
* Corpus types supported by the system
*/
export type CorpusType = 'ai-vs-human' | 'codebases' | 'traceability' | 'security-attacks' | 'template-recommendations';
/**
* Version constraint (semver or 'latest')
*/
export type VersionConstraint = string;
/**
* Ground truth item with labeled data
*/
export interface GroundTruthItem {
/** Unique item identifier */
id: string;
/** Item content or reference */
content: string | Record<string, unknown>;
/** Ground truth label */
groundTruth: unknown;
/** Optional metadata */
metadata?: Record<string, unknown>;
}
/**
* Corpus manifest structure
*/
export interface CorpusManifest {
/** Corpus name */
name: string;
/** Corpus type */
type: CorpusType;
/** Semantic version */
version: string;
/** Description */
description: string;
/** Creation date (ISO 8601) */
createdAt: string;
/** Last update date (ISO 8601) */
updatedAt: string;
/** Number of items */
itemCount: number;
/** Schema for ground truth labels */
schema: CorpusSchema;
/** Label distribution statistics */
labelDistribution: Record<string, number>;
/** Associated NFRs */
linkedNFRs: string[];
/** Data files */
dataFiles: string[];
}
/**
* Schema definition for corpus validation
*/
export interface CorpusSchema {
/** Ground truth type */
groundTruthType: 'boolean' | 'string' | 'number' | 'object' | 'array';
/** Required fields for ground truth object */
requiredFields?: string[];
/** Valid enum values (for string type) */
enumValues?: string[];
/** Description of expected format */
formatDescription: string;
}
/**
* Corpus statistics
*/
export interface CorpusStatistics {
/** Corpus type */
type: CorpusType;
/** Corpus version */
version: string;
/** Total items */
totalItems: number;
/** Label distribution */
labelDistribution: Record<string, number>;
/** Linked NFRs */
linkedNFRs: string[];
/** Last updated */
lastUpdated: string;
}
/**
* Validation result
*/
export interface ValidationResult {
/** Whether corpus is valid */
valid: boolean;
/** Validation errors */
errors: string[];
/** Validation warnings */
warnings: string[];
}
/**
* Comparison result for ground truth validation
*/
export interface ComparisonResult {
/** Item ID */
itemId: string;
/** Expected ground truth */
expected: unknown;
/** Actual value */
actual: unknown;
/** Whether they match */
matches: boolean;
/** Confidence score (0-1) if applicable */
confidence?: number;
}
/**
* GroundTruthCorpusManager - Manage multiple ground truth corpora
*
* @example
* ```typescript
* const manager = new GroundTruthCorpusManager('./tests/fixtures/corpora');
* await manager.initialize();
*
* // Load specific corpus
* const corpus = await manager.loadCorpus('ai-vs-human', '1.0.0');
*
* // Get ground truth for item
* const truth = manager.getGroundTruth('ai-vs-human', 'item-001');
*
* // Validate against ground truth
* const result = manager.validateAgainstGroundTruth('ai-vs-human', 'item-001', actualValue);
* ```
*/
export declare class GroundTruthCorpusManager {
private corporaRoot;
private manifests;
private loadedCorpora;
private initialized;
constructor(corporaRoot?: string);
/**
* Initialize manager and discover available corpora
*/
initialize(): Promise<void>;
/**
* Create the corpora directory structure
*/
private createDirectoryStructure;
/**
* Discover available corpus manifests
*/
private discoverManifests;
/**
* Get corpus key for map lookup
*/
private getCorpusKey;
/**
* Load a corpus by type and version
*
* @param type - Corpus type
* @param version - Semantic version or 'latest'
* @returns Loaded corpus items
*/
loadCorpus(type: CorpusType, version?: VersionConstraint): Promise<Map<string, GroundTruthItem>>;
/**
* Get the latest version for a corpus type
*/
private getLatestVersion;
/**
* Compare semver versions
*/
private compareSemver;
/**
* Get ground truth for a specific item
*
* @param type - Corpus type
* @param itemId - Item identifier
* @param version - Version constraint
* @returns Ground truth value
*/
getGroundTruth(type: CorpusType, itemId: string, version?: VersionConstraint): Promise<unknown>;
/**
* Validate actual value against ground truth
*
* @param type - Corpus type
* @param itemId - Item identifier
* @param actualValue - Value to compare
* @param version - Version constraint
* @returns Comparison result
*/
validateAgainstGroundTruth(type: CorpusType, itemId: string, actualValue: unknown, version?: VersionConstraint): Promise<ComparisonResult>;
/**
* Deep equality check
*/
private deepEquals;
/**
* Get corpus statistics
*
* @param type - Corpus type
* @param version - Version constraint
* @returns Statistics object
*/
getCorpusStatistics(type: CorpusType, version?: VersionConstraint): Promise<CorpusStatistics>;
/**
* Validate corpus schema and completeness
*
* @param type - Corpus type
* @param version - Version constraint
* @returns Validation result
*/
validateCorpus(type: CorpusType, version?: VersionConstraint): Promise<ValidationResult>;
/**
* Validate a single item against schema
*/
private validateItem;
/**
* List all available corpora
*
* @returns Array of corpus type and version pairs
*/
listCorpora(): Promise<Array<{
type: CorpusType;
version: string;
}>>;
/**
* Check if a corpus exists
*
* @param type - Corpus type
* @param version - Version constraint
* @returns True if corpus exists
*/
hasCorpus(type: CorpusType, version?: VersionConstraint): Promise<boolean>;
/**
* Get all items from a corpus
*
* @param type - Corpus type
* @param version - Version constraint
* @returns Array of all items
*/
getAllItems(type: CorpusType, version?: VersionConstraint): Promise<GroundTruthItem[]>;
/**
* Batch validate multiple items against ground truth
*
* @param type - Corpus type
* @param predictions - Map of itemId to predicted value
* @param version - Version constraint
* @returns Array of comparison results with overall statistics
*/
batchValidate(type: CorpusType, predictions: Map<string, unknown>, version?: VersionConstraint): Promise<{
results: ComparisonResult[];
accuracy: number;
totalCorrect: number;
totalItems: number;
}>;
/**
* Get the corpora root path
*/
getRoot(): string;
}
//# sourceMappingURL=ground-truth-manager.d.ts.map