auth-yes/forum/poc-g2/frontmatter_poc.ts
Tyler Gillispie 8f61cbdc49
feat(forum): add Generation 2 agent forum PoCs with production tools (#67)
- Renamed `forum/experiments` to `forum/poc-g1` to designate generation 1.
- Created `forum/poc-g2` and a new `lab.ts` runner.
- Non-destructively migrated `dag_engine_poc.ts`, `git_storage_poc.ts`, `merkle_diff_poc.ts`, and `frontmatter_poc.ts` to `poc-g2`.
- Upgraded migrated PoCs to utilize actual production-ready tools (e.g. `std/yaml` parsing and isolated `Deno.Command` Git repos) per blueprint constraints.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: mrteye <1945243+mrteye@users.noreply.github.com>
2026-08-28 21:10:21 -07:00

89 lines
2.5 KiB
TypeScript

import { assertEquals } from "https://deno.land/std@0.224.0/testing/asserts.ts";
import { parse as yamlParse } from "https://deno.land/std@0.224.0/yaml/mod.ts";
/**
* Generation 2 Proof of Concept: Declarative Frontmatter (YAML UUIDs)
*
* This module demonstrates extracting strict UUIDv7 identifiers from
* Markdown YAML frontmatter using production-ready YAML parsing,
* ensuring precise artifact identification.
*/
// A helper to test if a string matches UUIDv7 structure
// (8-4-4-4-12, where the 13th hex char is '7')
function isUUIDv7(uuid: string): boolean {
const uuidV7Regex =
/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
return uuidV7Regex.test(uuid);
}
export function extractArtifactId(markdownContent: string): string {
// Extract YAML block strictly
const match = markdownContent.match(/^---\n([\s\S]*?)\n---/);
if (!match || !match[1]) {
throw new Error("No YAML frontmatter found");
}
// Parse YAML block with std/yaml
const metadata = yamlParse(match[1]) as Record<string, unknown>;
const id = metadata["Artifact-ID"];
if (!id || typeof id !== "string") {
throw new Error("Missing or invalid Artifact-ID in frontmatter");
}
if (!isUUIDv7(id)) {
throw new Error(`Artifact-ID ${id} is not a valid UUIDv7`);
}
return id;
}
if (import.meta.main) {
console.log("Running Gen 2 Declarative Frontmatter PoC tests...");
// Mock UUIDv7: 018fa031-6e3e-7a2e-8c4d-91b5a6c7d8e9
const validMarkdown = `---
Artifact-ID: 018fa031-6e3e-7a2e-8c4d-91b5a6c7d8e9
Title: Authentication Architecture
Status: Draft
---
# Authentication Architecture
This document details the auth system...
`;
const invalidMarkdown = `---
Artifact-ID: task-123
Title: Legacy Task
---
# Legacy System
`;
try {
const id = extractArtifactId(validMarkdown);
assertEquals(id, "018fa031-6e3e-7a2e-8c4d-91b5a6c7d8e9");
console.log(
"✅ Gen 2 Frontmatter PoC successful: Correctly extracted UUIDv7 using std/yaml.",
);
// Test rejection of non-UUIDv7
let failedAsExpected = false;
try {
extractArtifactId(invalidMarkdown);
} catch (e: any) {
if (e.message.includes("not a valid UUIDv7")) {
failedAsExpected = true;
}
}
assertEquals(failedAsExpected, true, "Should have rejected invalid UUID");
console.log("✅ Gen 2 Frontmatter PoC successful: Successfully rejected non-UUIDv7 artifact.");
} catch (err) {
console.error("❌ Gen 2 Frontmatter PoC failed:", err);
Deno.exit(1);
}
}