auth-yes/forum/poc-g2/git_hooks_poc.ts
Tyler Gillispie 555c5eb384
feat(forum): add missing Gen 1 & Gen 2 PoCs with strict constraint enforcement (#69)
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>
2026-08-29 00:28:19 -07:00

117 lines
3.7 KiB
TypeScript

/**
* Automated Git Hooks PoC (Gen 2 - Production Tooling)
*
* This script proves that we can hook into Git's native events to automatically
* generate code intelligence graphs. It creates a temporary Git repository,
* writes a real bash script to `.git/hooks/pre-commit`, and triggers a commit.
*/
import {
join,
} from "https://deno.land/std@0.224.0/path/mod.ts";
async function runCommand(cmd: string[], cwd: string): Promise<string> {
const command = new Deno.Command(cmd[0], {
args: cmd.slice(1),
cwd,
stdout: "piped",
stderr: "piped",
});
const { code, stdout, stderr } = await command.output();
const decoder = new TextDecoder();
if (code !== 0) {
throw new Error(
`Command ${cmd.join(" ")} failed: ${decoder.decode(stderr)}`,
);
}
return decoder.decode(stdout);
}
async function runGitHooksPoc() {
console.log("Starting Automated Git Hooks PoC (Gen 2)\n");
// Setup temporary directory
const tempDir = await Deno.makeTempDir({
prefix: "agent-forum-githook-poc-",
});
console.log(`[Git] Created temporary workspace: ${tempDir}`);
try {
// Init git
await runCommand(["git", "init"], tempDir);
// Write a mock pre-commit hook that simulates generating a SCIP index
const hookPath = join(tempDir, ".git", "hooks", "pre-commit");
const hookScript = `#!/bin/bash
echo "[Hook] Pre-commit hook triggered by Git natively!"
echo "[Hook] Extracting modified files..."
git diff --cached --name-only
echo "[Hook] Generating 'scip.graph' (Simulated via touch)..."
touch scip.graph
echo "[Hook] Execution complete. Proceeding with commit."
`;
await Deno.writeTextFile(hookPath, hookScript);
// Make the hook executable (chmod +x)
const chmodCmd = new Deno.Command("chmod", { args: ["+x", hookPath] });
await chmodCmd.output();
console.log("[Git] pre-commit hook installed and made executable.");
// Create a dummy file to commit
const testFile = join(tempDir, "target.js");
await Deno.writeTextFile(testFile, "console.log('Hello World');");
console.log("[Git] Staging files...");
await runCommand(["git", "add", "target.js"], tempDir);
console.log("[Git] Committing files to trigger hook...\n");
console.log("[Git] Configuring local git user...");
await runCommand(["git", "config", "user.name", "Test User"], tempDir);
await runCommand(["git", "config", "user.email", "test@test.com"], tempDir);
// We run the commit command and pipe the output so we can see the hook execute
const commitCmd = new Deno.Command("git", {
args: ["commit", "-m", "Initial commit"],
cwd: tempDir,
stdout: "piped",
stderr: "piped",
});
const { code: _code, stdout, stderr } = await commitCmd.output();
const decoder = new TextDecoder();
const output = decoder.decode(stdout);
console.log(output);
if (output.includes("Pre-commit hook triggered by Git natively!")) {
console.log(
"✅ Git pre-commit hook successfully intercepted commit and executed.",
);
// Verify the hook actually created the simulated artifact
const stat = await Deno.stat(join(tempDir, "scip.graph"));
if (stat.isFile) {
console.log(
"✅ Artifact 'scip.graph' successfully generated by the hook.",
);
}
} else {
console.error("❌ Hook did not appear to trigger.");
console.error(decoder.decode(stderr));
throw new Error("Hook execution failed.");
}
} finally {
// Cleanup
console.log(`\n[Git] Cleaning up temporary workspace: ${tempDir}`);
await Deno.remove(tempDir, { recursive: true });
console.log("Gen 2 Git Hooks execution completed successfully.");
}
}
if (import.meta.main) {
runGitHooksPoc().catch(console.error);
}