Intelligence
Artifacts
Browse the repository, read documents, and manage the governance folders. Source, runtime, and infrastructure are read-only.
Repository
repositories/aaf-holdings/hq01/lib/content/executives.ts
2.0 KB
import path from "node:path";
import yaml from "js-yaml";
import { cache } from "react";
import { CONTENT_ROOT } from "./config";
import { readText, relPath, walkFiles } from "./fs";
import type { Executive } from "./types";
interface RawExec {
name?: string;
role?: string;
mission?: string;
authority?: string[];
current_objectives?: string[];
currentObjectives?: string[];
known_constraints?: string[];
knownConstraints?: string[];
recent_lessons?: string[];
recentLessons?: string[];
}
function isExecFile(p: string): boolean {
const norm = p.split(path.sep).join("/");
return (
/\/hermes\/executives\/[^/]+\.ya?ml$/.test(norm) ||
/\/executives\/[^/]+\.ya?ml$/.test(norm)
);
}
function toExecutive(filePath: string): Executive | null {
let data: RawExec;
try {
data = (yaml.load(readText(filePath)) as RawExec) ?? {};
} catch {
return null;
}
if (!data || (!data.name && !data.role)) return null;
const id = path.basename(filePath).replace(/\.ya?ml$/, "");
return {
id,
name: data.name ?? id,
role: data.role ?? "Executive",
mission: data.mission ?? "",
authority: data.authority ?? [],
currentObjectives: data.current_objectives ?? data.currentObjectives ?? [],
knownConstraints: data.known_constraints ?? data.knownConstraints ?? [],
recentLessons: data.recent_lessons ?? data.recentLessons ?? [],
sourcePath: relPath(filePath),
};
}
export const getExecutives = cache((): Executive[] => {
const files = walkFiles(CONTENT_ROOT, isExecFile);
const execs = files
.map(toExecutive)
.filter((e): e is Executive => Boolean(e));
// De-duplicate by id (a profile may exist in more than one root).
const byId = new Map<string, Executive>();
for (const e of execs) {
if (!byId.has(e.id)) byId.set(e.id, e);
}
return [...byId.values()].sort((a, b) => a.name.localeCompare(b.name));
});
export const getExecutive = cache((id: string): Executive | undefined => {
return getExecutives().find((e) => e.id === id);
});
root · /srv/aaf