129 lines
3.6 KiB
TypeScript
129 lines
3.6 KiB
TypeScript
/**
|
|
* Agent Forum v4 - Meta-State Bootstrap Tool
|
|
* Scaffolds and commits baseline JSON-LD requirements, task DAGs, and transitions.json
|
|
* directly to the orphan 'meta-state' branch via headless virtual commits.
|
|
*/
|
|
|
|
import { fromFileUrl, join } from "jsr:@std/path";
|
|
import { v7 } from "jsr:@std/uuid@1";
|
|
import { runCommand } from "./core/sys_exec.ts";
|
|
import { createVirtualCommit } from "./core/git_virtual_branch.ts";
|
|
|
|
export async function bootstrapMetaState(cwd?: string): Promise<string> {
|
|
console.log("-> Bootstrapping Agent Forum Meta-State...");
|
|
|
|
const repoRootCmd = await runCommand(
|
|
"git",
|
|
["rev-parse", "--show-toplevel"],
|
|
{ cwd },
|
|
);
|
|
const repoRoot = repoRootCmd.stdout.trim();
|
|
|
|
const filesToUpdate: Record<string, string> = {};
|
|
|
|
// 1. Generate JSON-LD Requirement Graph
|
|
const ontologyGraph = [
|
|
{
|
|
"@context": "https://schema.org",
|
|
"@type": "SoftwareApplication",
|
|
"name": "Auth-Yes Project",
|
|
"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",
|
|
},
|
|
];
|
|
filesToUpdate["ontologies/graph.jsonld"] = JSON.stringify(
|
|
ontologyGraph,
|
|
null,
|
|
2,
|
|
);
|
|
|
|
// 2. Initialize decentralized delta inboxes
|
|
const domains = ["docs", "telemetry"];
|
|
for (const domain of domains) {
|
|
const seedUuid = v7.generate();
|
|
const seedSql = `BEGIN TRANSACTION;
|
|
CREATE TABLE IF NOT EXISTS ${domain}_symbols (
|
|
id TEXT PRIMARY KEY,
|
|
filepath TEXT,
|
|
symbol_name TEXT,
|
|
signature TEXT,
|
|
content_hash TEXT,
|
|
is_deleted INTEGER DEFAULT 0,
|
|
last_updated TEXT
|
|
);
|
|
CREATE VIRTUAL TABLE IF NOT EXISTS vec_${domain} USING vec0(
|
|
embedding float[3]
|
|
);
|
|
COMMIT;
|
|
`;
|
|
filesToUpdate[`deltas/${domain}/${seedUuid}.sql`] = seedSql;
|
|
}
|
|
|
|
// 3. Generate Initial Task DAG
|
|
const initialTask = `id: TASK-001
|
|
title: Bootstrap Agent Forum Governance
|
|
status: Done
|
|
description: Automatically initialized meta-state architecture and baseline requirements.
|
|
blocked_by: []
|
|
`;
|
|
filesToUpdate["tasks/TASK-001.yaml"] = initialTask;
|
|
|
|
// 4. Copy transitions.json if present
|
|
try {
|
|
let transitionsContent = "";
|
|
const baseDir = import.meta.dirname ??
|
|
fromFileUrl(new URL(".", import.meta.url));
|
|
const candidatePaths = [
|
|
join(baseDir, "core", "transitions.json"),
|
|
join(repoRoot, ".forum", "src", "core", "transitions.json"),
|
|
join(repoRoot, "src", "core", "transitions.json"),
|
|
];
|
|
for (const p of candidatePaths) {
|
|
try {
|
|
transitionsContent = await Deno.readTextFile(p);
|
|
if (transitionsContent) break;
|
|
} catch {
|
|
// Try next candidate
|
|
}
|
|
}
|
|
if (transitionsContent) {
|
|
filesToUpdate["transitions.json"] = transitionsContent;
|
|
}
|
|
} catch {
|
|
// Safe fallback
|
|
}
|
|
|
|
// 5. Commit headless virtual commit directly to meta-state
|
|
const commitId = await createVirtualCommit({
|
|
targetBranch: "meta-state",
|
|
filesToUpdate,
|
|
message: "chore(meta-state): bootstrap initial ontologies and task DAGs",
|
|
cwd,
|
|
});
|
|
|
|
console.log(
|
|
`🎉 Meta-state successfully bootstrapped locally (Commit: ${
|
|
commitId.substring(0, 7)
|
|
})!`,
|
|
);
|
|
return commitId;
|
|
}
|
|
|
|
export async function main(_args: string[] = Deno.args) {
|
|
await bootstrapMetaState();
|
|
}
|