auth-yes/forum/poc-g1/merkle_diff_poc.ts
Tyler Gillispie 8f61cbdc49
feat(forum): add Generation 2 agent forum PoCs with production tools (#67)
- Renamed `forum/experiments` to `forum/poc-g1` to designate generation 1.
- Created `forum/poc-g2` and a new `lab.ts` runner.
- Non-destructively migrated `dag_engine_poc.ts`, `git_storage_poc.ts`, `merkle_diff_poc.ts`, and `frontmatter_poc.ts` to `poc-g2`.
- Upgraded migrated PoCs to utilize actual production-ready tools (e.g. `std/yaml` parsing and isolated `Deno.Command` Git repos) per blueprint constraints.

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 21:10:21 -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);
}
}