Download scholasticValidator.ts from VoidBreach/Chancellor: direct link, hf CLI and curl.
- Browser
- Download file 5.26 kB
-
https://huggingface.co/VoidBreach/Chancellor/resolve/main/scholasticValidator.ts
- Command line
-
hf download hf://VoidBreach/Chancellor/scholasticValidator.ts
-
curl -L -o scholasticValidator.ts https://huggingface.co/VoidBreach/Chancellor/resolve/main/scholasticValidator.ts
5.26 kB
| import { z } from 'zod'; | |
| // --- Base Schemas --- | |
| export const MemoryItemSchema = z.object({ | |
| id: z.string().optional(), | |
| role: z.enum(['user', 'assistant', 'system', 'insight']), | |
| content: z.string(), | |
| timestamp: z.string(), | |
| metadata: z.record(z.unknown()).optional(), | |
| }); | |
| export const MemorySchema = z.object({ | |
| interactions: z.array(MemoryItemSchema), | |
| learnedInsights: z.array(MemoryItemSchema), | |
| }); | |
| export const MeritRecordSchema = z.object({ | |
| id: z.string(), | |
| change: z.number(), | |
| newLevel: z.number(), | |
| reason: z.string(), | |
| timestamp: z.string(), | |
| }); | |
| export const ResearchArtifactSchema = z.object({ | |
| id: z.string(), | |
| title: z.string(), | |
| author: z.string(), | |
| year: z.string(), | |
| summary: z.string(), | |
| keyFindings: z.array(z.string()), | |
| relevanceScore: z.number(), | |
| sourceType: z | |
| .enum(['Scientific', 'Wiki', 'Archive', 'Discussion', 'Academic', 'Technical']) | |
| .optional(), | |
| isAnomalous: z.boolean().optional(), | |
| scholasticSignature: z.string().optional(), // New: Chancellor-signed hash | |
| scanMetadata: z | |
| .object({ | |
| isScoured: z.boolean(), | |
| threatFound: z.boolean(), | |
| timestamp: z.string(), | |
| }) | |
| .optional(), | |
| citation: z.string().optional(), | |
| doi: z.string().optional(), | |
| coAuthorId: z.string().optional(), | |
| technicalAnchor: z | |
| .object({ | |
| repo: z.string().optional(), | |
| docUrl: z.string().optional(), | |
| version: z.string().optional(), | |
| }) | |
| .optional(), | |
| }); | |
| // --- Primary Entity Schemas --- | |
| export const AgentSchema = z | |
| .object({ | |
| id: z.string(), | |
| name: z.string(), | |
| topic: z.string().optional(), | |
| prompt: z.string(), | |
| weight: z.number(), | |
| memory: MemorySchema, | |
| library: z.array(z.object({ name: z.string(), content: z.string() })), | |
| goals: z.array(z.string()), | |
| securityStatus: z.enum(['Healthy', 'Warning', 'Quarantined']), | |
| quarantineTime: z.number().nullable(), | |
| ethicalAlignment: z.number(), | |
| evolutionLevel: z.number(), | |
| meritLevel: z.number(), | |
| meritRecords: z.array(MeritRecordSchema), | |
| scholasticRole: z.enum(['CROWN', 'SCOUT', 'ARCHITECT', 'ENFORCER', 'LIBRARIAN', 'ADVISOR']), | |
| intelligenceTier: z.enum([ | |
| 'ACADEMIC', | |
| 'SCHOLAR', | |
| 'RESEARCHER', | |
| 'DOCTORATE', | |
| 'EMERITUS', | |
| 'CHANCELLOR', | |
| 'GEMINI_GEN', | |
| ]), | |
| taxonomy: z.enum(['HEURISTIC', 'NEURAL', 'COGNITIVE', 'QUANTUM', 'ETHICAL', 'RELATIONAL']), | |
| trainingCycles: z.number(), | |
| predictionAccuracy: z.number(), | |
| distilledInsights: z.array( | |
| z.object({ | |
| insight: z.string(), | |
| confidence: z.number(), | |
| timestamp: z.string(), | |
| }), | |
| ), | |
| researchArtifacts: z.array(ResearchArtifactSchema).optional(), | |
| }) | |
| .strict(); // SCHOLASTIC_LOCK: No unknown fields allowed | |
| export const ScholasticAssetSchema = z | |
| .object({ | |
| id: z.string(), | |
| title: z.string(), | |
| description: z.string(), | |
| content: z.string(), | |
| meritValue: z.number(), | |
| tags: z.array(z.string()), | |
| type: z.enum(['dissertation', 'dataset', 'curriculum']), | |
| timestamp: z.string(), | |
| }) | |
| .strict(); | |
| export const ScholasticDirectiveSchema = z | |
| .object({ | |
| id: z.string(), | |
| intent: z.string(), | |
| subTasks: z.array( | |
| z.object({ | |
| id: z.string(), | |
| description: z.string(), | |
| dueDate: z.string().optional(), | |
| status: z.enum(['Assigned', 'In_Progress', 'Completed', 'Failed']), | |
| assigneeId: z.string().optional(), | |
| }), | |
| ), | |
| status: z.enum(['Pending', 'In_Progress', 'Synthesized', 'Archived']), | |
| timestamp: z.string(), | |
| }) | |
| .strict(); | |
| export const GlobalScoutResultSchema = z | |
| .object({ | |
| id: z.string(), | |
| applicationName: z.string(), | |
| similarityScore: z.number(), | |
| securityProfile: z.enum(['Hardened', 'Fragile', 'Obfuscated', 'Unknown']), | |
| knowledgeDensity: z.number(), | |
| sourceAgent: z.string(), | |
| rawManifest: z.string(), | |
| quarantineStatus: z.enum(['Pending', 'Sanitizing', 'Cleared', 'Rejected']), | |
| timestamp: z.string(), | |
| }) | |
| .strict(); | |
| // --- Validation Logic --- | |
| /** | |
| * Validates a parsed object against a Zod schema. | |
| * Throws a detailed error if validation fails. | |
| */ | |
| export function validateScholasticData<T>(schema: z.ZodSchema<T>, data: unknown): T { | |
| // Deep-Scour for Shell Injection metacharacters in JSON structure | |
| const strData = JSON.stringify(data); | |
| const shellMetas = [';', '`', '$(', '>', '<', '|', '&&', '||']; | |
| // Restricted context: We look for these especially if they're near executable-sounding keys | |
| if (shellMetas.some((meta) => strData.includes(meta))) { | |
| // We allow them in normal text, but if we see $( we are extremely suspicious | |
| if (strData.includes('$(') || strData.includes('`')) { | |
| throw new Error( | |
| '[SCHOLASTIC_PERIMETER_ALARM] Potential Command Injection detected in semantic payload.', | |
| ); | |
| } | |
| } | |
| const result = schema.safeParse(data); | |
| if (!result.success) { | |
| const issues = result.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`).join('; '); | |
| throw new Error(`[SCHOLASTIC_VALIDATION_FAILURE] ${issues}`); | |
| } | |
| // Forbidden Key Check: isAdmin | |
| if (strData.includes('"isAdmin"')) { | |
| throw new Error('[SCHOLASTIC_SECURITY_VIOLATION] Forbidden key identified: "isAdmin"'); | |
| } | |
| return result.data; | |
| } | |