This commit implements the missing Proof of Concepts (PoCs) required by the `agent-forum-v4` architecture blueprint as identified in `CONCEPTS.md`.
Updates include:
- `execution_flywheel_poc.ts`: Implemented mock version (Gen 1) using in-memory state and physical version (Gen 2) utilizing actual file I/O tracking to prove state management bounds.
- `tool_sandbox_poc.ts`: Implemented mock version (Gen 1) yielding simulated telemetry and physical version (Gen 2) utilizing real production-grade tool invocations (Semgrep via CLI and Tree-sitter via WASM module).
- `git_hooks_poc.ts`: Implemented mock version (Gen 1) intercepting simulated events and physical version (Gen 2) configuring a physical Git temp directory executing native `.git/hooks/pre-commit` hooks.
- `BOUNDARIES.md`: Documented explicit technical boundaries in both `poc-g1` and `poc-g2` to enforce strict isolation vs production file-system operation.
- Fixed Deno Linting constraints across `poc-g2/` scripts.
- `CONCEPTS.md`: Status flags updated to ✅.
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>
102 lines
3.1 KiB
TypeScript
102 lines
3.1 KiB
TypeScript
import { Database } from "jsr:@db/sqlite";
|
|
import {
|
|
assert,
|
|
// assertEquals,
|
|
} from "https://deno.land/std@0.224.0/testing/asserts.ts";
|
|
|
|
/**
|
|
* Proof of Concept: Multi-Vec Isolation (Gen 2)
|
|
*
|
|
* Demonstrates the concept of preventing semantic bleed by using physically
|
|
* isolated SQLite vector databases instead of dumping all embeddings into a
|
|
* single database. We use actual SQLite databases for this in Gen 2.
|
|
*/
|
|
|
|
// User-defined function for similarity
|
|
function cosineSimilarity(vecA: number[], vecB: number[]): number {
|
|
let dotProduct = 0, normA = 0, normB = 0;
|
|
for (let i = 0; i < vecA.length; i++) {
|
|
dotProduct += vecA[i] * vecB[i];
|
|
normA += vecA[i] ** 2;
|
|
normB += vecB[i] ** 2;
|
|
}
|
|
if (normA === 0 || normB === 0) return 0;
|
|
return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
|
|
}
|
|
|
|
function initDb(name: string): Database {
|
|
// Use independent named files in /tmp so they aren't the same memory db
|
|
const db = new Database(`/tmp/${name}.db`);
|
|
db.function(
|
|
"vec_distance",
|
|
(a: string, b: string) => cosineSimilarity(JSON.parse(a), JSON.parse(b)),
|
|
);
|
|
db.exec(
|
|
"CREATE TABLE IF NOT EXISTS embeddings (id TEXT, text TEXT, vector TEXT)",
|
|
);
|
|
db.exec("DELETE FROM embeddings"); // clear from previous runs
|
|
return db;
|
|
}
|
|
|
|
if (import.meta.main) {
|
|
console.log("Running Multi-Vec Isolation PoC (Gen 2) tests...");
|
|
|
|
try {
|
|
const docsDb = initDb("docs_graph");
|
|
const telemetryDb = initDb("telemetry_graph");
|
|
|
|
const insertDocs = docsDb.prepare(
|
|
"INSERT INTO embeddings VALUES (?, ?, ?)",
|
|
);
|
|
insertDocs.run(
|
|
"docs-1",
|
|
"High performance server scaling",
|
|
JSON.stringify([0.9, 0.1, 0.2]),
|
|
);
|
|
insertDocs.finalize();
|
|
|
|
const insertTelemetry = telemetryDb.prepare(
|
|
"INSERT INTO embeddings VALUES (?, ?, ?)",
|
|
);
|
|
insertTelemetry.run(
|
|
"telemetry-1",
|
|
"Memory leak in main process",
|
|
JSON.stringify([0.1, 0.9, 0.2]),
|
|
);
|
|
insertTelemetry.finalize();
|
|
|
|
// The user asks about "Performance and scaling"
|
|
const queryVector = JSON.stringify([0.85, 0.15, 0.1]);
|
|
|
|
const docsResults = docsDb.prepare(
|
|
"SELECT id, vec_distance(vector, ?) as score FROM embeddings ORDER BY score DESC LIMIT 1",
|
|
).get(queryVector) as { id: string; score: number };
|
|
const telemetryResults = telemetryDb.prepare(
|
|
"SELECT id, vec_distance(vector, ?) as score FROM embeddings ORDER BY score DESC LIMIT 1",
|
|
).get(queryVector) as { id: string; score: number };
|
|
|
|
console.log("Docs graph match:", docsResults?.id, docsResults?.score);
|
|
console.log(
|
|
"Telemetry graph match:",
|
|
telemetryResults?.id,
|
|
telemetryResults?.score,
|
|
);
|
|
|
|
assert(docsResults.score > 0.9, "Should find a high match in docs");
|
|
assert(
|
|
telemetryResults.score < docsResults.score,
|
|
"Telemetry should be less relevant for this query",
|
|
);
|
|
|
|
docsDb.close();
|
|
telemetryDb.close();
|
|
|
|
console.log(
|
|
"✅ Multi-Vec Isolation PoC (Gen 2) successful: Isolated graphs prevented cross-contamination.",
|
|
);
|
|
} catch (err) {
|
|
console.error("❌ Multi-Vec Isolation PoC (Gen 2) failed:", err);
|
|
Deno.exit(1);
|
|
}
|
|
}
|