auth-yes/forum/poc-g2/code_intelligence_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

113 lines
3.3 KiB
TypeScript

import * as acorn from "npm:acorn";
import { assertEquals } from "https://deno.land/std@0.224.0/testing/asserts.ts";
/**
* Proof of Concept: Local Code Intelligence (Gen 2)
*
* Replaces the naive regex extraction in Gen 1 with actual AST parsing using
* acorn, proving that we can extract a true Semantic
* Code graph structure from code files.
*/
export interface ExportSymbol {
name: string;
type: "function" | "class" | "const";
signature: string;
}
export function extractExports(sourceCode: string): ExportSymbol[] {
// Strip TypeScript annotations using a regex just to let acorn parse it as JS
// In a real scenario we'd use a TS-capable parser like @typescript-eslint/typescript-estree or swc,
// but this proves the concept of AST walking vs regex scraping.
const jsCode = sourceCode
.replace(/:\s*Promise<[^>]+>/g, '')
.replace(/:\s*[a-zA-Z0-9_]+/g, '')
.replace(/<[^>]+>/g, '');
const ast = acorn.parse(jsCode, { ecmaVersion: 2022, sourceType: "module" }) as any;
const exports: ExportSymbol[] = [];
for (const node of ast.body) {
if (node.type === "ExportNamedDeclaration") {
if (node.declaration) {
if (node.declaration.type === "FunctionDeclaration") {
const name = node.declaration.id.name;
// Simple mock signature from JS AST
const params = node.declaration.params.map((p: any) => p.name).join(", ");
exports.push({
name,
type: "function",
signature: `(${params}) => any`,
});
} else if (node.declaration.type === "VariableDeclaration") {
for (const decl of node.declaration.declarations) {
exports.push({
name: decl.id.name,
type: "const",
signature: "const",
});
}
}
}
}
}
return exports;
}
if (import.meta.main) {
console.log("Running Local Code Intelligence PoC (Gen 2) tests...");
const mockSourceCode = `
import { stuff } from "somewhere";
/**
* Calculates a complex value.
*/
export async function calculateValue(input: number, mode: string): Promise<number> {
return input * 2;
}
// An internal helper
function internalHelper() {
return true;
}
export const MAX_RETRIES = 5;
export function doSomethingElse(): void {
console.log(MAX_RETRIES);
}
`;
try {
const extracted = extractExports(mockSourceCode);
assertEquals(extracted.length, 3);
const calcFunc = extracted.find((e) => e.name === "calculateValue");
assertEquals(calcFunc?.type, "function");
assertEquals(
calcFunc?.signature,
"(input, mode) => any",
);
const maxRetries = extracted.find((e) => e.name === "MAX_RETRIES");
assertEquals(maxRetries?.type, "const");
const doSomething = extracted.find((e) => e.name === "doSomethingElse");
assertEquals(doSomething?.type, "function");
assertEquals(doSomething?.signature, "() => any");
console.log(
"✅ Local Code Intelligence PoC (Gen 2) successful: Extracted structured context from raw source using AST Parser.",
);
console.log("\n--- Agent Context Payload ---");
console.log(JSON.stringify(extracted, null, 2));
console.log("-----------------------------\n");
} catch (err) {
console.error("❌ Local Code Intelligence PoC (Gen 2) failed:", err);
}
}