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/executives/memos.ts
1.4 KB
import fs from "node:fs";
import path from "node:path";
import { MEMOS_DIR } from "./config";
import type { Memo } from "./types";
/**
* Executive memos — the foundation for cross-executive communication. Executives
* communicate through structured memos, never ad-hoc chat. This pass establishes
* the schema and storage only; full memo workflows are intentionally deferred.
*/
function stamp(): string {
return new Date().toISOString().replace(/[:.]/g, "-");
}
/** Persist a memo and return the saved record (with createdAt filled). */
export function createMemo(
input: Omit<Memo, "createdAt"> & { createdAt?: string },
): Memo {
const memo: Memo = { ...input, createdAt: input.createdAt ?? new Date().toISOString() };
fs.mkdirSync(MEMOS_DIR, { recursive: true });
const name = `${stamp()}-${memo.fromExecutiveId}-to-${memo.toExecutiveId}.json`;
const file = path.join(MEMOS_DIR, name);
fs.writeFileSync(file, JSON.stringify(memo, null, 2) + "\n", "utf8");
return memo;
}
export function listMemos(): Memo[] {
let names: string[];
try {
names = fs.readdirSync(MEMOS_DIR);
} catch {
return [];
}
const out: Memo[] = [];
for (const name of names) {
if (!name.endsWith(".json")) continue;
try {
out.push(JSON.parse(fs.readFileSync(path.join(MEMOS_DIR, name), "utf8")) as Memo);
} catch {
/* skip */
}
}
return out.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
}
root · /srv/aaf