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>
65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import protobuf from "npm:protobufjs";
|
|
import { assertEquals } from "https://deno.land/std@0.224.0/testing/asserts.ts";
|
|
|
|
/**
|
|
* Proof of Concept: Protocol Buffers (Gen 2)
|
|
*
|
|
* Demonstrates serializing and deserializing agent state using actual
|
|
* protobufjs instead of a JSON stringifier mock, showing high-performance
|
|
* I/O for vector math and state passing.
|
|
*/
|
|
|
|
const protoDefinition = `
|
|
syntax = "proto3";
|
|
|
|
message AgentState {
|
|
string agentId = 1;
|
|
string status = 2;
|
|
int32 memoryUsage = 3;
|
|
}
|
|
`;
|
|
|
|
if (import.meta.main) {
|
|
console.log("Running Protocol Buffers PoC (Gen 2) tests...");
|
|
|
|
try {
|
|
const root = protobuf.parse(protoDefinition).root;
|
|
const AgentState = root.lookupType("AgentState");
|
|
|
|
const payload = {
|
|
agentId: "adversary-01",
|
|
status: "active",
|
|
memoryUsage: 1024,
|
|
};
|
|
|
|
const errMsg = AgentState.verify(payload);
|
|
if (errMsg) throw Error(errMsg);
|
|
|
|
const message = AgentState.create(payload);
|
|
const buffer = AgentState.encode(message).finish();
|
|
|
|
console.log(`Original Data:`, payload);
|
|
console.log(`Serialized Size: ${buffer.length} bytes (binary)`);
|
|
|
|
const decodedMessage = AgentState.decode(buffer);
|
|
const deserialized = AgentState.toObject(decodedMessage, {
|
|
longs: String,
|
|
enums: String,
|
|
bytes: String,
|
|
});
|
|
|
|
console.log("Deserialized Data:", deserialized);
|
|
|
|
assertEquals(deserialized.agentId, payload.agentId);
|
|
assertEquals(deserialized.status, payload.status);
|
|
assertEquals(deserialized.memoryUsage, payload.memoryUsage);
|
|
|
|
console.log(
|
|
"✅ Protocol Buffers PoC (Gen 2) successful: Real protobuf serialization/deserialization worked.",
|
|
);
|
|
} catch (err) {
|
|
console.error("❌ Protocol Buffers PoC (Gen 2) failed:", err);
|
|
Deno.exit(1);
|
|
}
|
|
}
|