auth-yes/forum/poc-g2/dependency_graph_poc.ts
Tyler Gillispie e5855248e6
feat: Port all agent-forum-v4 Gen 1 PoCs to Gen 2 using real tooling (#68)
This commit ports the remaining Gen 1 proof-of-concept experiments from `forum/poc-g1` into `forum/poc-g2` while substituting naive mocks with real, production-ready mechanisms.

Key advancements include:
- `code_intelligence_poc.ts` and `cfg_poc.ts`: Swapped regex matching for actual Javascript AST traversal using `acorn`.
- `static_analysis_poc.ts`: Replaced mock payloads with real `deno lint --json` output executed via `Deno.Command`.
- `vector_db_poc.ts` and `multi_vec_poc.ts`: Replaced basic JS arrays with actual `jsr:@db/sqlite` instances utilizing User-Defined Functions (UDFs) to perform native vector cosine similarity queries in memory or on disk.
- `protobuf_poc.ts`: Implemented robust protobuf serialization/deserialization via `protobufjs`.
- Semantic/Governance PoCs (`constitution_poc.ts`, `ontology_poc.ts`, `state_machine_poc.ts`, `orphan_branch_poc.ts`, etc): Replaced string-mock I/O with absolute filesystem reads, real YAML parsing using `jsr:@std/yaml`, and isolated `Deno.Command` Git sandboxes.
- Updated `forum/poc-g2/lab.ts` to orchestrate and execute all 19 experiments, proving 100% test pass rate with Gen 2 tooling.

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 22:11:53 -07:00

96 lines
3.2 KiB
TypeScript

import { assertEquals } from "https://deno.land/std@0.224.0/testing/asserts.ts";
import * as path from "https://deno.land/std@0.224.0/path/mod.ts";
/**
* Proof of Concept: Dependency Graphing (Gen 2)
*
* Demonstrates extracting a real dependency graph from Deno Info instead of a hardcoded
* matrix, showing how an agent calculates blast radius from live code.
*/
async function getDenoDependencies(entryFile: string) {
const command = new Deno.Command("deno", {
args: ["info", "--json", entryFile],
stdout: "piped",
stderr: "piped",
});
const { stdout } = await command.output();
const outputStr = new TextDecoder().decode(stdout);
return JSON.parse(outputStr);
}
function calculateBlastRadius(info: any, targetFileUrl: string): string[] {
// Build a reverse-dependency map (who imports me?)
const reverseMap = new Map<string, string[]>();
if (info.modules) {
for (const mod of info.modules) {
const specifier = mod.specifier;
if (!reverseMap.has(specifier)) reverseMap.set(specifier, []);
if (mod.dependencies) {
for (const dep of mod.dependencies) {
const importedSpecifier = dep.code?.specifier;
if (importedSpecifier) {
if (!reverseMap.has(importedSpecifier)) reverseMap.set(importedSpecifier, []);
reverseMap.get(importedSpecifier)!.push(specifier);
}
}
}
}
}
const impacted = new Set<string>();
const queue = [targetFileUrl];
while (queue.length > 0) {
const current = queue.shift()!;
const dependants = reverseMap.get(current) || [];
for (const dep of dependants) {
if (!impacted.has(dep)) {
impacted.add(dep);
queue.push(dep);
}
}
}
return Array.from(impacted);
}
if (import.meta.main) {
console.log("Running Dependency Graphing PoC (Gen 2) tests...");
try {
const dir = await Deno.makeTempDir();
// Create a mock dependency tree: A imports B, B imports C
const fileC = path.join(dir, "C.ts");
const fileB = path.join(dir, "B.ts");
const fileA = path.join(dir, "A.ts");
await Deno.writeTextFile(fileC, "export const c = 1;");
await Deno.writeTextFile(fileB, "import { c } from './C.ts'; export const b = c + 1;");
await Deno.writeTextFile(fileA, "import { b } from './B.ts'; console.log(b);");
const info = await getDenoDependencies(fileA);
const targetUrl = path.toFileUrl(fileC).href;
const blastRadius = calculateBlastRadius(info, targetUrl);
console.log(`If ${fileC} changes, the blast radius impacts:`);
blastRadius.forEach(b => console.log(` - ${b}`));
// B imports C, A imports B. Both should be impacted.
assertEquals(blastRadius.length, 2);
assertEquals(blastRadius.some(b => b.includes("B.ts")), true);
assertEquals(blastRadius.some(b => b.includes("A.ts")), true);
console.log("✅ Dependency Graphing PoC (Gen 2) successful: Real Deno dependency graph analyzed.");
await Deno.remove(dir, { recursive: true });
} catch (err) {
console.error("❌ Dependency Graphing PoC (Gen 2) failed:", err);
Deno.exit(1);
}
}