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>
67 lines
2.0 KiB
TypeScript
67 lines
2.0 KiB
TypeScript
import { assertEquals } from "https://deno.land/std@0.224.0/testing/asserts.ts";
|
|
|
|
/**
|
|
* Proof of Concept: Static Analysis Payloads (Gen 2)
|
|
*
|
|
* Simulates a real CI/CD integration where we spawn Deno.Command to run a local
|
|
* static analysis tool (like deno lint), capture its JSON output, and feed it
|
|
* as structured data for the Adversary agent.
|
|
*/
|
|
|
|
async function runStaticAnalysis(code: string): Promise<any> {
|
|
// Write the temp code to a file
|
|
const tempFile = await Deno.makeTempFile({ suffix: ".ts" });
|
|
await Deno.writeTextFile(tempFile, code);
|
|
|
|
// We use deno lint as our real "static analysis tool" for this PoC
|
|
const command = new Deno.Command("deno", {
|
|
args: ["lint", "--json", tempFile],
|
|
stdout: "piped",
|
|
stderr: "piped",
|
|
});
|
|
|
|
const { stdout } = await command.output();
|
|
const outputStr = new TextDecoder().decode(stdout);
|
|
|
|
// Cleanup
|
|
await Deno.remove(tempFile);
|
|
|
|
try {
|
|
return JSON.parse(outputStr);
|
|
} catch (e) {
|
|
return { diagnostics: [] }; // Empty if no output or parse error
|
|
}
|
|
}
|
|
|
|
if (import.meta.main) {
|
|
console.log("Running Static Analysis Payloads PoC (Gen 2) tests...");
|
|
|
|
// We write some intentionally bad code that triggers deno lint
|
|
const badCode = `
|
|
const unusedVar = 42;
|
|
function anyFunc(a: any) {
|
|
return a == null;
|
|
}
|
|
`;
|
|
|
|
try {
|
|
const analysisReport = await runStaticAnalysis(badCode) as any;
|
|
|
|
console.log("Agent received real structured static analysis report:");
|
|
console.log(`Found ${analysisReport.diagnostics.length} lint issues.`);
|
|
|
|
// We expect deno lint to catch 'no-unused-vars'
|
|
assertEquals(analysisReport.diagnostics.length > 0, true);
|
|
|
|
const hasUnusedVar = analysisReport.diagnostics.some((e: any) => e.code === "no-unused-vars");
|
|
assertEquals(hasUnusedVar, true);
|
|
|
|
console.log(
|
|
"✅ Static Analysis Payloads PoC (Gen 2) successful: Spawned real tool (deno lint) and parsed JSON payload.",
|
|
);
|
|
} catch (err) {
|
|
console.error("❌ Static Analysis Payloads PoC (Gen 2) failed:", err);
|
|
Deno.exit(1);
|
|
}
|
|
}
|