- Created `CONCEPTS.md` to track coverage of blueprint structures - Added 5 new PoCs: CFG, Constitution, Frontmatter, Mutation, and Orphan Branch - Registered all 15 experiments in `lab.ts` runner - Ensured zero-dependency Deno execution for tests 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>
100 lines
2.7 KiB
TypeScript
100 lines
2.7 KiB
TypeScript
import {
|
|
assert,
|
|
assertEquals,
|
|
} from "https://deno.land/std@0.224.0/testing/asserts.ts";
|
|
|
|
/**
|
|
* Proof of Concept: The Constitution (AGENTS.md)
|
|
*
|
|
* Demonstrates a mechanism to parse an AGENTS.md rule file and use it to
|
|
* programmatically restrict an agent's proposed actions (e.g. stack validation).
|
|
*/
|
|
|
|
const mockAgentsMd = `
|
|
# System Constitution
|
|
|
|
## Allowed Tech Stack
|
|
- Deno
|
|
- TypeScript
|
|
- Vue.js
|
|
- Tailwind CSS
|
|
- PostgreSQL
|
|
|
|
## Denied Libraries
|
|
- React
|
|
- Express
|
|
- MongoDB
|
|
`;
|
|
|
|
function extractAllowedStack(markdown: string): string[] {
|
|
const allowedSection = markdown.match(
|
|
/## Allowed Tech Stack\n([\s\S]*?)(?=##|$)/,
|
|
);
|
|
if (!allowedSection) return [];
|
|
|
|
return allowedSection[1]
|
|
.split("\n")
|
|
.map((line) => line.replace(/^- /, "").trim())
|
|
.filter((line) => line.length > 0);
|
|
}
|
|
|
|
function extractDeniedStack(markdown: string): string[] {
|
|
const deniedSection = markdown.match(
|
|
/## Denied Libraries\n([\s\S]*?)(?=##|$)/,
|
|
);
|
|
if (!deniedSection) return [];
|
|
|
|
return deniedSection[1]
|
|
.split("\n")
|
|
.map((line) => line.replace(/^- /, "").trim())
|
|
.filter((line) => line.length > 0);
|
|
}
|
|
|
|
function evaluateAgentProposal(
|
|
proposal: string[],
|
|
allowed: string[],
|
|
denied: string[],
|
|
): { valid: boolean; violations: string[] } {
|
|
const violations = [];
|
|
|
|
for (const tech of proposal) {
|
|
if (denied.includes(tech)) {
|
|
violations.push(`${tech} is explicitly forbidden.`);
|
|
} else if (!allowed.includes(tech)) {
|
|
violations.push(`${tech} is not in the approved tech stack.`);
|
|
}
|
|
}
|
|
|
|
return { valid: violations.length === 0, violations };
|
|
}
|
|
|
|
if (import.meta.main) {
|
|
console.log("Running The Constitution PoC tests...");
|
|
|
|
try {
|
|
const allowed = extractAllowedStack(mockAgentsMd);
|
|
const denied = extractDeniedStack(mockAgentsMd);
|
|
|
|
// Scenario 1: Agent proposes an allowed stack update
|
|
const safeProposal = ["Deno", "TypeScript"];
|
|
const safeResult = evaluateAgentProposal(safeProposal, allowed, denied);
|
|
assert(safeResult.valid, "Expected safe proposal to be valid");
|
|
console.log("✅ Safe proposal accepted.");
|
|
|
|
// Scenario 2: Agent hallucinates a React/Mongo app
|
|
const unsafeProposal = ["Deno", "React", "MongoDB"];
|
|
const unsafeResult = evaluateAgentProposal(unsafeProposal, allowed, denied);
|
|
assert(!unsafeResult.valid, "Expected unsafe proposal to be invalid");
|
|
assertEquals(unsafeResult.violations.length, 2);
|
|
console.log(
|
|
"✅ Unsafe proposal correctly rejected based on AGENTS.md rules:",
|
|
);
|
|
unsafeResult.violations.forEach((v) => console.log(` - ${v}`));
|
|
|
|
console.log("✅ The Constitution PoC successful.");
|
|
} catch (err) {
|
|
console.error("❌ The Constitution PoC failed:", err);
|
|
Deno.exit(1);
|
|
}
|
|
}
|