Skip to content

Open-source SEO, GEO, and marketing skills for AI agents.

feat(files): surface PROJECT.md in the agent Files tab

Yuting Zhong6c9fb0e491cf
diff --git a/src/app/(app)/[project]/agents/[agent]/files/page.tsx b/src/app/(app)/[project]/agents/[agent]/files/page.tsx
index f01346b5..eac1504c 100644
--- a/src/app/(app)/[project]/agents/[agent]/files/page.tsx
+++ b/src/app/(app)/[project]/agents/[agent]/files/page.tsx
@@ -1,13 +1,47 @@
+import { promises as fs } from "node:fs";
+import { join } from "node:path";
import Link from "next/link";
import { notFound } from "next/navigation";
import { FileText, FileX } from "lucide-react";
import { Badge } from "@/components/ui/badge";
import { getProject } from "@/server/db/projects";
-import { resolveAgentBySlug } from "@/server/agent-meta";
+import { resolveAgentBySlug, workspaceDirFor } from "@/server/agent-meta";
import { listAgentFiles, getAgentFile } from "@/server/openclaw/gateway-rpc";
import { cn } from "@/lib/utils";
import { projectHref } from "@/lib/project-href";
+const PROJECT_FILE_NAME = "PROJECT.md";
+
+type AugmentedFile = Awaited<ReturnType<typeof listAgentFiles>>["files"][number];
+
+/**
+ * Augment OpenClaw's hardcoded workspace-file list with PROJECT.md when it
+ * exists on disk. PROJECT.md is the canonical project-context file written
+ * by the CMO via set_project_brief and synced into every agent's workspace
+ * by writeIdentityFile — it lives in the same directory as IDENTITY.md but
+ * isn't in OpenClaw's enumeration list, so we have to add it ourselves.
+ */
+async function readWorkspaceProjectFile(
+ agentId: string,
+): Promise<AugmentedFile | null> {
+ const workspace = workspaceDirFor(agentId);
+ const path = join(workspace, PROJECT_FILE_NAME);
+ try {
+ const stat = await fs.stat(path);
+ if (!stat.isFile()) return null;
+ return {
+ name: PROJECT_FILE_NAME,
+ path,
+ missing: false,
+ size: stat.size,
+ updatedAtMs: stat.mtimeMs,
+ };
+ } catch (err) {
+ if ((err as NodeJS.ErrnoException).code === "ENOENT") return null;
+ throw err;
+ }
+}
+
type Params = { agent: string; project: string };
type Search = { file?: string };
@@ -29,7 +63,7 @@ export default async function AgentFilesPage({
const agentFullId = resolved.agent_id;
let error: string | null = null;
- let files: Awaited<ReturnType<typeof listAgentFiles>>["files"] = [];
+ let files: AugmentedFile[] = [];
let workspace = "";
try {
const list = await listAgentFiles(agentFullId);
@@ -39,6 +73,27 @@ export default async function AgentFilesPage({
error = err instanceof Error ? err.message : String(err);
}
+ // Splice PROJECT.md in if it exists on disk. We surface it right after
+ // IDENTITY.md when both are present so the "what this agent knows about
+ // the company" file sits next to the role identity it pairs with.
+ try {
+ const projectEntry = await readWorkspaceProjectFile(agentFullId);
+ if (projectEntry) {
+ const identityIdx = files.findIndex((f) => f.name === "IDENTITY.md");
+ if (identityIdx >= 0) {
+ files = [
+ ...files.slice(0, identityIdx + 1),
+ projectEntry,
+ ...files.slice(identityIdx + 1),
+ ];
+ } else {
+ files = [projectEntry, ...files];
+ }
+ }
+ } catch (err) {
+ console.warn("[files] could not read PROJECT.md:", err);
+ }
+
// Pick which file to show: explicit search param wins, else first present
// file, else first overall (which may be missing).
const selectedName =
@@ -56,10 +111,19 @@ export default async function AgentFilesPage({
selectedMissing = entry?.missing ?? true;
if (!selectedMissing) {
try {
- const got = await getAgentFile(agentFullId, selectedName);
- selectedContent = got.file.content;
- selectedSize = got.file.size;
- selectedUpdatedAtMs = got.file.updatedAtMs;
+ if (selectedName === PROJECT_FILE_NAME) {
+ // PROJECT.md isn't in OpenClaw's enumeration; read from disk
+ // directly using the path we resolved during list-augmentation.
+ const content = await fs.readFile(entry!.path, "utf8");
+ selectedContent = content;
+ selectedSize = entry!.size;
+ selectedUpdatedAtMs = entry!.updatedAtMs;
+ } else {
+ const got = await getAgentFile(agentFullId, selectedName);
+ selectedContent = got.file.content;
+ selectedSize = got.file.size;
+ selectedUpdatedAtMs = got.file.updatedAtMs;
+ }
} catch (err) {
selectedError = err instanceof Error ? err.message : String(err);
}