diff --git a/.forum/src/bootstrap_meta.ts b/.forum/src/bootstrap_meta.ts new file mode 100644 index 0000000..fc3b52b --- /dev/null +++ b/.forum/src/bootstrap_meta.ts @@ -0,0 +1,122 @@ +/** + * Agent Forum v4 - Meta-State Bootstrap Tool + * Automatically scaffolds the orphan 'meta-state' branch with initial + * JSON-LD requirements, task DAGs, and transition rules. + */ + +import { ensureDir } from "https://deno.land/std@0.224.0/fs/ensure_dir.ts"; +import { join } from "https://deno.land/std@0.224.0/path/mod.ts"; + +async function runCmd(args: string[], cwd?: string): Promise { + const cmd = new Deno.Command("git", { + args, + cwd, + stdout: "piped", + stderr: "piped", + }); + const { code, stdout, stderr } = await cmd.output(); + if (code !== 0) { + const errText = new TextDecoder().decode(stderr); + throw new Error(`Git command failed: git ${args.join(" ")}\n${errText}`); + } + return new TextDecoder().decode(stdout).trim(); +} + +async function main() { + console.log("-> Bootstrapping Agent Forum Meta-State..."); + + const tmpDir = await Deno.makeTempDir({ prefix: "meta_state_" }); + + try { + // 1. Initialize or check out meta-state orphan branch in a temp dir + console.log(" Initializing meta-state orphan workspace..."); + try { + await runCmd(["symbolic-ref", "HEAD"], tmpDir); + } catch { + // Not a git repo yet in tmpDir, clone/init local linkage + const repoRoot = await runCmd(["rev-parse", "--show-toplevel"]); + await runCmd(["clone", repoRoot, tmpDir]); + await runCmd(["checkout", "--orphan", "meta-state"], tmpDir); + await runCmd(["rm", "-rf", "."], tmpDir); // Clean slate for orphan branch + } + + // 2. Ensure directories exist + await ensureDir(join(tmpDir, "ontologies")); + await ensureDir(join(tmpDir, "tasks")); + await ensureDir(join(tmpDir, "vectors")); + + // 3. Auto-generate JSON-LD Requirement Graph based on repo inspection + console.log(" Generating JSON-LD ontology graph..."); + let projectName = "Auth-Yes Project"; + try { + const pkgRaw = await Deno.readTextFile("package.json"); + const pkg = JSON.parse(pkgRaw); + if (pkg.name) projectName = pkg.name; + } catch { + // Default fallback + } + + const ontologyGraph = [ + { + "@context": "https://schema.org", + "@type": "SoftwareApplication", + "name": projectName, + "description": "Auto-bootstrapped application architecture for Agent Forum governance." + }, + { + "@type": "Requirement", + "id": "REQ-001", + "description": "Ensure zero-trust authentication and rate-limiting patterns are enforced on all API routes.", + "status": "Approved" + }, + { + "@type": "Requirement", + "id": "REQ-002", + "description": "Maintain strict code-to-documentation parity using SCIP index extraction.", + "status": "Approved" + } + ]; + + await Deno.writeTextFile( + join(tmpDir, "ontologies", "ontology.graph"), + JSON.stringify(ontologyGraph, null, 2) + ); + + // 4. Auto-generate Initial Task DAG + console.log(" Generating initial task backlog DAG..."); + const initialTask = `id: TASK-001 +title: Bootstrap Agent Forum Governance +status: Done +description: Automatically initialized meta-state architecture and baseline requirements. +blocked_by: [] +`; + + await Deno.writeTextFile( + join(tmpDir, "tasks", "TASK-001.yaml"), + initialTask + ); + + // 5. Commit and push/update meta-state branch + console.log(" Committing meta-state structures..."); + await runCmd(["add", "."], tmpDir); + + // Check if there are changes to commit + const status = await runCmd(["status", "--porcelain"], tmpDir); + if (status) { + await runCmd(["commit", "-m", "chore(meta-state): bootstrap initial ontologies and task DAGs"], tmpDir); + // Push meta-state to local/remote + await runCmd(["push", "origin", "meta-state:meta-state"], tmpDir).catch(() => { + console.warn("⚠️ Could not push meta-state to remote (offline or remote not set). Local branch updated."); + }); + } + + console.log("🎉 Meta-state successfully bootstrapped!"); + + } finally { + await Deno.remove(tmpDir, { recursive: true }).catch(() => {}); + } +} + +if (import.meta.main) { + await main(); +} diff --git a/.forum/src/hooks/pre-push b/.forum/src/hooks/pre-push new file mode 100755 index 0000000..b32aae0 --- /dev/null +++ b/.forum/src/hooks/pre-push @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Agent Forum v4 - Pre-Push Synchronization Hook +# Automatically syncs the 'meta-state' orphan branch and all agent git notes +# whenever any branch is pushed to a remote. + +remote="$1" +url="$2" + +echo "-> Agent Forum: Syncing meta-state and Git Notes to remote '${remote}'..." + +# 1. Push the meta-state branch if it exists locally +if git rev-parse --verify meta-state >/dev/null 2>&1; then + git push "$remote" meta-state:meta-state --quiet || echo "⚠️ Warning: Failed to push meta-state branch." +fi + +# 2. Push all agent Git Notes across all namespaces +git push "$remote" 'refs/notes/*' --quiet || echo "⚠️ Warning: Failed to push Git Notes." + +echo "-> Agent Forum: State synchronization complete." +exit 0 diff --git a/deno.lock b/deno.lock index 973bd22..36fc468 100644 --- a/deno.lock +++ b/deno.lock @@ -741,6 +741,8 @@ "https://deno.land/std@0.224.0/front_matter/_formats.ts": "9a8ac1524f93b3ae093bd66864a49fc0088037920c6d60863da136d10f92e04d", "https://deno.land/std@0.224.0/front_matter/create_extractor.ts": "642e6e55cd07864b7c8068f88d271290d5d0a13d979ad335e10a7f52046b1f80", "https://deno.land/std@0.224.0/front_matter/yaml.ts": "103b8338bec480c6b7a7e245cf6bda72682eb78ed2231c799a4526d52cb6888a", + "https://deno.land/std@0.224.0/fs/_get_file_info_type.ts": "da7bec18a7661dba360a1db475b826b18977582ce6fc9b25f3d4ee0403fe8cbd", + "https://deno.land/std@0.224.0/fs/ensure_dir.ts": "51a6279016c65d2985f8803c848e2888e206d1b510686a509fa7cc34ce59d29f", "https://deno.land/std@0.224.0/fs/exists.ts": "3d38cb7dcbca3cf313be343a7b8af18a87bddb4b5ca1bd2314be12d06533b50f", "https://deno.land/std@0.224.0/internal/diff.ts": "6234a4b493ebe65dc67a18a0eb97ef683626a1166a1906232ce186ae9f65f4e6", "https://deno.land/std@0.224.0/internal/format.ts": "0a98ee226fd3d43450245b1844b47003419d34d210fa989900861c79820d21c2",