Intelligence

Artifacts

Browse the repository, read documents, and manage the governance folders. Source, runtime, and infrastructure are read-only.

Repository
README.md
CONSTITUTION_COMPLIANCE_AUDIT_V1.mdREADME.md
repositories/aaf-holdings/hq01/lib/content/overview.ts
2.2 KB
import path from "node:path";
import { cache } from "react";
import { CONTENT_ROOT } from "./config";
import { parseDoc, readText, relPath, walkFiles } from "./fs";
import { getAssignments } from "./assignments";
import { getExecutives } from "./executives";
import { getMissions } from "./missions";
import { getReports } from "./reports";
import { getWorkOrders } from "./work-orders";
import type { Status } from "./types";

export interface OverviewStats {
  missions: number;
  activeMissions: number;
  workOrders: number;
  openWorkOrders: number;
  assignments: number;
  executives: number;
  reports: number;
}

const OPEN_STATUSES: Status[] = ["Active", "In Progress", "Blocked", "Review", "Backlog"];

export const getOverviewStats = cache((): OverviewStats => {
  const missions = getMissions();
  const workOrders = getWorkOrders();
  return {
    missions: missions.length,
    activeMissions: missions.filter((m) => OPEN_STATUSES.includes(m.status)).length,
    workOrders: workOrders.length,
    openWorkOrders: workOrders.filter((w) => OPEN_STATUSES.includes(w.status)).length,
    assignments: getAssignments().length,
    executives: getExecutives().length,
    reports: getReports().length,
  };
});

export interface DocInfo {
  title: string;
  path: string;
  kind: "Constitution" | "Doctrine" | "Roadmap" | "Template";
}

function isGovernanceFile(p: string): boolean {
  const norm = p.split(path.sep).join("/");
  return /\/(constitutions?|doctrine|roadmaps?|templates?)\/.+\.md$/.test(norm);
}

function kindOf(p: string): DocInfo["kind"] {
  const norm = p.toLowerCase();
  if (norm.includes("/constitution")) return "Constitution";
  if (norm.includes("/doctrine")) return "Doctrine";
  if (norm.includes("/roadmap")) return "Roadmap";
  return "Template";
}

export const getGovernanceDocs = cache((): DocInfo[] => {
  const files = walkFiles(CONTENT_ROOT, isGovernanceFile);
  return files
    .map((f) => {
      const doc = parseDoc(readText(f));
      return {
        title: doc.title || path.basename(f, ".md"),
        path: relPath(f),
        kind: kindOf(f),
      };
    })
    .sort((a, b) => a.kind.localeCompare(b.kind) || a.title.localeCompare(b.title));
});

root · /srv/aaf