Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
refactor(profile): implement progressive disclosure for profile loading
Jiang Bohan5cdc6974f70d
diff --git a/src/agent/system-prompt/builder.test.ts b/src/agent/system-prompt/builder.test.tsindex e9657a5ee5..09a2946783 100644--- a/src/agent/system-prompt/builder.test.ts+++ b/src/agent/system-prompt/builder.test.ts@@ -15,12 +15,13 @@ const TOOLS = ["read", "write", "edit", "glob", "exec", "memory_get", "memory_sedescribe("buildSystemPrompt", () => {// ── Full mode ─────────────────────────────────────────────────────────- it("full mode includes all profile sections", () => {+ it("full mode includes workspace section only (progressive disclosure)", () => {+ // Soul, user, memory are read on-demand by the agentconst result = buildSystemPrompt({ mode: "full", profile: PROFILE });- expect(result).toContain("# Soul");- expect(result).toContain("# User");+ expect(result).not.toContain("# Soul");+ expect(result).not.toContain("# User");expect(result).toContain("# Workspace");- expect(result).toContain("# Memory");+ expect(result).not.toContain("# Memory");});it("full mode includes safety constitution", () => {@@ -76,13 +77,17 @@ describe("buildSystemPrompt", () => {expect(result).toContain("os=darwin (arm64)");});- it("full mode includes profile directory", () => {+ it("full mode includes profile info in workspace section", () => {const result = buildSystemPrompt({mode: "full",profileDir: "/home/user/.super-multica/agent-profiles/test",+ profile: { workspace: "Workspace rules" },});- expect(result).toContain("## Profile Directory");+ expect(result).toContain("## Profile");expect(result).toContain("/home/user/.super-multica/agent-profiles/test");+ expect(result).toContain("soul.md");+ expect(result).toContain("user.md");+ expect(result).toContain("memory.md");});it("full mode excludes subagent section", () => {@@ -242,8 +247,13 @@ describe("buildSystemPromptWithReport", () => {it("report marks excluded sections correctly in minimal mode", () => {const { report } = buildSystemPromptWithReport({ mode: "minimal" });+ // Identity is now included in all modes (just a one-liner)const identity = report.sections.find((s) => s.name === "identity");- expect(identity?.included).toBe(false);+ expect(identity?.included).toBe(true);++ // User and memory are excluded (progressive disclosure)+ const user = report.sections.find((s) => s.name === "user");+ expect(user?.included).toBe(false);const safety = report.sections.find((s) => s.name === "safety");expect(safety?.included).toBe(true);diff --git a/src/agent/system-prompt/builder.ts b/src/agent/system-prompt/builder.tsindex b0f1f45f6f..619b05f89e 100644--- a/src/agent/system-prompt/builder.ts+++ b/src/agent/system-prompt/builder.ts@@ -56,7 +56,7 @@ export function buildSystemPromptWithReport(options: SystemPromptOptions): {const candidates: Array<{ name: string; lines: string[] }> = [{ name: "identity", lines: buildIdentitySection(profile, mode) },{ name: "user", lines: buildUserSection(profile, mode) },- { name: "workspace", lines: buildWorkspaceSection(profile, mode) },+ { name: "workspace", lines: buildWorkspaceSection(profile, mode, profileDir) },{ name: "memory", lines: buildMemoryFileSection(profile, mode) },{ name: "safety", lines: buildSafetySection(includeSafety) },{ name: "tooling", lines: buildToolingSummary(tools, mode) },diff --git a/src/agent/system-prompt/sections.test.ts b/src/agent/system-prompt/sections.test.tsindex f98ccabd77..cfd25f6fa1 100644--- a/src/agent/system-prompt/sections.test.ts+++ b/src/agent/system-prompt/sections.test.ts@@ -15,9 +15,15 @@ import {} from "./sections.js";describe("buildIdentitySection", () => {- it("returns soul content in full mode", () => {+ it("returns identity line in full mode (progressive disclosure)", () => {+ // Soul content is no longer injected - agent reads soul.md on demand+ const result = buildIdentitySection({ soul: "You are helpful.", config: { name: "Cleo" } }, "full");+ expect(result).toEqual(["You are Cleo, a Super Multica agent."]);+ });++ it("returns generic identity line in full mode without name", () => {const result = buildIdentitySection({ soul: "You are helpful." }, "full");- expect(result).toEqual(["You are helpful."]);+ expect(result).toEqual(["You are a Super Multica agent."]);});it("returns identity line with name in none mode", () => {@@ -30,47 +36,48 @@ describe("buildIdentitySection", () => {expect(result).toEqual(["You are a Super Multica agent."]);});- it("returns empty in minimal mode", () => {- const result = buildIdentitySection({ soul: "data" }, "minimal");- expect(result).toEqual([]);+ it("returns identity line in minimal mode", () => {+ const result = buildIdentitySection({ soul: "data", config: { name: "Cleo" } }, "minimal");+ expect(result).toEqual(["You are Cleo, a Super Multica agent."]);});});describe("buildUserSection", () => {- it("returns user content in full mode", () => {- const result = buildUserSection({ user: "Name: Bob" }, "full");- expect(result).toEqual(["Name: Bob"]);- });-- it("returns empty in minimal mode", () => {- const result = buildUserSection({ user: "data" }, "minimal");- expect(result).toEqual([]);- });-- it("returns empty when no user content", () => {- const result = buildUserSection({}, "full");- expect(result).toEqual([]);+ it("returns empty in all modes (progressive disclosure)", () => {+ // User content is no longer injected - agent reads user.md on demand+ expect(buildUserSection({ user: "Name: Bob" }, "full")).toEqual([]);+ expect(buildUserSection({ user: "data" }, "minimal")).toEqual([]);+ expect(buildUserSection({}, "full")).toEqual([]);});});describe("buildWorkspaceSection", () => {- it("returns workspace content in full mode", () => {+ it("returns workspace content with profile info in full mode", () => {+ const result = buildWorkspaceSection({ workspace: "Rules here" }, "full", "/path/to/profile");+ const text = result.join("\n");+ expect(text).toContain("## Profile");+ expect(text).toContain("/path/to/profile");+ expect(text).toContain("soul.md");+ expect(text).toContain("user.md");+ expect(text).toContain("memory.md");+ expect(text).toContain("Rules here");+ });++ it("returns workspace content without profile dir", () => {const result = buildWorkspaceSection({ workspace: "Rules here" }, "full");expect(result).toEqual(["Rules here"]);});it("returns empty in minimal mode", () => {expect(buildWorkspaceSection({ workspace: "data" }, "minimal")).toEqual([]);+ expect(buildWorkspaceSection({ workspace: "data" }, "minimal", "/path")).toEqual([]);});});describe("buildMemoryFileSection", () => {- it("returns memory content in full mode", () => {- const result = buildMemoryFileSection({ memory: "Key facts" }, "full");- expect(result).toEqual(["Key facts"]);- });-- it("returns empty in minimal mode", () => {+ it("returns empty in all modes (progressive disclosure)", () => {+ // Memory content is no longer injected - agent reads memory.md on demand+ expect(buildMemoryFileSection({ memory: "Key facts" }, "full")).toEqual([]);expect(buildMemoryFileSection({ memory: "data" }, "minimal")).toEqual([]);});});@@ -227,12 +234,9 @@ describe("buildRuntimeSection", () => {});describe("buildProfileDirSection", () => {- it("includes path in full mode", () => {- const result = buildProfileDirSection("/path/to/profile", "full");- expect(result.join("\n")).toContain("/path/to/profile");- });-- it("returns empty in minimal mode", () => {+ it("returns empty in all modes (merged into workspace section)", () => {+ // Profile directory info is now part of buildWorkspaceSection+ expect(buildProfileDirSection("/path/to/profile", "full")).toEqual([]);expect(buildProfileDirSection("/path", "minimal")).toEqual([]);});});diff --git a/src/agent/system-prompt/sections.ts b/src/agent/system-prompt/sections.tsindex af1569d41f..a0126d56f5 100644--- a/src/agent/system-prompt/sections.ts+++ b/src/agent/system-prompt/sections.ts@@ -47,59 +47,85 @@ const TOOL_ORDER = [// ─── Section builders ───────────────────────────────────────────────────────/**- * Identity section — soul.md in full mode, single line in none mode, nothing in minimal.+ * Identity section — brief identity line only.+ * Full profile content (soul.md) is loaded on-demand by the agent.*/export function buildIdentitySection(profile: ProfileContent | undefined,mode: SystemPromptMode,): string[] {- if (mode === "none") {- const name = profile?.config?.name;+ const name = profile?.config?.name;+ if (mode === "none" || mode === "minimal") {return name? [`You are ${name}, a Super Multica agent.`]: ["You are a Super Multica agent."];}- if (mode === "minimal") {- return [];- }- // full mode- if (profile?.soul) {- return [profile.soul];- }- return [];+ // full mode - just identity line, agent reads soul.md on demand+ return name+ ? [`You are ${name}, a Super Multica agent.`]+ : ["You are a Super Multica agent."];}/**- * User section — user.md content (full mode only).+ * User section — no longer injected into system prompt.+ * Agent reads user.md on demand from profile directory.*/export function buildUserSection(- profile: ProfileContent | undefined,- mode: SystemPromptMode,+ _profile: ProfileContent | undefined,+ _mode: SystemPromptMode,): string[] {- if (mode !== "full" || !profile?.user) return [];- return [profile.user];+ // Progressive disclosure: agent reads user.md on demand+ return [];}/**- * Workspace section — workspace.md content (full mode only).+ * Workspace section — workspace.md content with profile directory path.+ * This is the primary profile content injected into system prompt.+ * Other profile files (soul.md, user.md, memory.md) are read on demand.*/export function buildWorkspaceSection(profile: ProfileContent | undefined,mode: SystemPromptMode,+ profileDir?: string,): string[] {- if (mode !== "full" || !profile?.workspace) return [];- return [profile.workspace];+ if (mode !== "full") return [];++ const lines: string[] = [];++ // Add profile directory context first+ if (profileDir) {+ lines.push(+ "## Profile",+ "",+ `Your profile directory: \`${profileDir}\``,+ "",+ "Profile files:",+ "- `soul.md` — Your identity and values",+ "- `user.md` — Information about your user",+ "- `workspace.md` — Guidelines and conventions (below)",+ "- `memory.md` — Persistent knowledge",+ "",+ );+ }++ // Add workspace.md content+ if (profile?.workspace) {+ lines.push(profile.workspace);+ }++ return lines;}/**- * Memory section — memory.md content (full mode only).+ * Memory section — no longer injected into system prompt.+ * Agent reads memory.md on demand from profile directory.*/export function buildMemoryFileSection(- profile: ProfileContent | undefined,- mode: SystemPromptMode,+ _profile: ProfileContent | undefined,+ _mode: SystemPromptMode,): string[] {- if (mode !== "full" || !profile?.memory) return [];- return [profile.memory];+ // Progressive disclosure: agent reads memory.md on demand+ return [];}/**@@ -265,21 +291,15 @@ export function buildRuntimeSection(}/**- * Profile directory section — tells agent where its files live.- * Full mode only.+ * Profile directory section — now merged into buildWorkspaceSection.+ * Kept for backwards compatibility but returns empty.*/export function buildProfileDirSection(- profileDir: string | undefined,- mode: SystemPromptMode,+ _profileDir: string | undefined,+ _mode: SystemPromptMode,): string[] {- if (mode !== "full" || !profileDir) return [];- return [- "## Profile Directory",- "",- `Your profile files are located at: \`${profileDir}\``,- "",- "Use `edit` or `write` tools to update these files when needed.",- ];+ // Profile directory info is now part of workspace section+ return [];}/**