UNPKG

@phren/cli

Version:

Knowledge layer for AI agents - CLI, MCP server, and data layer

38 lines (37 loc) • 1.98 kB
import { z } from "zod"; import { sessionId } from "./protocol.js"; export const CI_FAILURE_PATH = "/v1/ci/failures"; export const CI_FAILURE_SCOPE = "gitboy-ci"; export const CI_FAILURE_BODY_CAP = 64 * 1024; export const CI_REPORT_CAP = 24 * 1024; export const CI_LOG_LIMIT = 12000; export const CI_LINE_LIMIT = 200; export const ciDigest = z.string().regex(/^[a-f0-9]{64}$/); const eventId = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9_.:-]{0,199}$/); const line = (max) => z.string().min(1).max(max).refine(value => !/[\x00-\x1f\x7f]/.test(value)); const repository = /^[a-z\d]+(?:[.-][a-z\d]+)*(?:\/(?!\.{1,2}(?:\/|$))[\w.-]+){2,}$/i; const change = z.object({ repo: z.string().max(300).regex(repository), branch: line(250).optional(), commit: z.string().regex(/^(?:[a-fA-F0-9]{40}|[a-fA-F0-9]{64})$/).optional(), snapshotId: eventId.optional(), }); const oneChange = (value) => (value.commit === undefined) !== (value.snapshotId === undefined); export const ciSubmissionSchema = change.extend({ reporterId: ciDigest, attemptId: z.string().regex(/^[A-Za-z0-9][A-Za-z0-9_-]{0,99}$/), }).strict() .refine(oneChange, "Supply exactly one of commit or snapshotId."); const report = change.extend({ step: line(CI_LINE_LIMIT), failedTests: z.array(line(CI_LINE_LIMIT)).max(40), logTail: z.string().max(CI_LOG_LIMIT), sessionId: sessionId.optional(), eventId: eventId.optional(), // Already-settled records from the first contract remain readable. }).strict(); const fits = (value) => Buffer.byteLength(JSON.stringify(value)) <= CI_REPORT_CAP; export const ciFailureSchema = report.refine(oneChange).refine(fits); export const ciIntakeSchema = report.extend({ eventId, originToken: z.string().max(4096).regex(/^[A-Za-z0-9_-]+\.[a-f0-9]{64}$/), }).refine(oneChange, "Supply exactly one of commit or snapshotId.").refine(({ originToken: _, ...value }) => fits(value), "The encoded report excluding originToken must fit in 24 KiB.");