auth-yes/forum/experiments/merkle_diff_poc.ts
Tyler Gillispie 4df94c2a19
feat: add agent-forum data structures and experiments (#64)
- Updates `forum/DATA_STRUCTURES.md` with missing concepts: Protocol Buffers, TurboQuant, Git Merkle DAG Diffing, Dependency Graphing, and Declarative Frontmatter (UUIDv7).
- Expands `forum/experiments/lab.ts` with 5 new proofs-of-concept for the new data structures.
- Adds `protobuf_poc.ts`, `merkle_diff_poc.ts`, `vector_db_poc.ts`, `dependency_graph_poc.ts`, and `telemetry_poc.ts`.

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 19:15:51 -07:00

74 lines
2.1 KiB
TypeScript

import {
assertNotEquals,
} from "https://deno.land/std@0.224.0/testing/asserts.ts";
/**
* Proof of Concept: Git Merkle DAG Diffing
*
* This module demonstrates using Git's fundamental Merkle Tree structure
* (`git diff-tree` and `git ls-tree`) to perform zero-overhead, O(1) diffing
* to find exactly which file hashes changed without reading the file string content.
*/
async function runGitCmd(args: string[]): Promise<string> {
const cmd = new Deno.Command("git", {
args,
stdout: "piped",
stderr: "piped",
});
const output = await cmd.output();
const stdout = new TextDecoder().decode(output.stdout).trim();
const stderr = new TextDecoder().decode(output.stderr).trim();
if (!output.success) {
throw new Error(`Git command failed: git ${args.join(" ")}\n${stderr}`);
}
return stdout;
}
if (import.meta.main) {
console.log("Running Git Merkle DAG Diffing PoC tests...");
try {
// 1. Get the current HEAD commit hash
const headHash = await runGitCmd(["rev-parse", "HEAD"]);
console.log(`Current HEAD: ${headHash}`);
// 2. Get the tree hash of HEAD
const treeHash = await runGitCmd(["rev-parse", "HEAD^{tree}"]);
console.log(`Tree Hash of HEAD: ${treeHash}`);
// 3. Diff HEAD against HEAD~1 (if available) to see what changed purely by hash
try {
const diffTreeOutput = await runGitCmd([
"diff-tree",
"--no-commit-id",
"--name-only",
"-r",
"HEAD",
]);
console.log(
`\nChanged files in HEAD (O(1) diffing):\n${
diffTreeOutput || "(No changes or no parent)"
}`,
);
assertNotEquals(treeHash, "");
console.log(
"\n✅ Git Merkle DAG Diffing PoC successful: Read tree hashes without opening files.",
);
} catch (e: any) {
if (e.message.includes("ambiguous argument")) {
console.log(
"Skipping diff-tree as there might not be enough commits in this repo for a diff.",
);
} else {
throw e;
}
}
} catch (err) {
console.error("❌ Git Merkle DAG Diffing PoC failed:", err);
Deno.exit(1);
}
}