refactor(prompt): split stable prefix from volatile tail
This commit is contained in:
1 parent
227fd7faf2
commit
2cdf26f9fa
13 files changed
+242
-54
No files matched your search
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildSystemPrompt } from "../../../src/main/prompt-builder/index";
|
||||
import { buildSystemPrompt, buildTaskPrompt } from "../../../src/main/prompt-builder/index";
|
||||
import type { ApprovalRecord } from "../../../src/shared/types";
|
||||
import { installSharedSetup } from "./shared-setup";
|
||||
|
||||
@@ -22,14 +22,21 @@ describe("Step 2: CEO phased prompts", () => {
|
||||
pendingApprovals: [],
|
||||
});
|
||||
|
||||
const prompt = buildSystemPrompt(ctx);
|
||||
const stablePrompt = buildSystemPrompt(ctx);
|
||||
const prompt = buildTaskPrompt(ctx);
|
||||
|
||||
expect(stablePrompt).not.toContain("Team Building Phase");
|
||||
expect(stablePrompt).not.toContain("Awaiting Hire Approvals");
|
||||
expect(stablePrompt).not.toContain("Awaiting Org Strategy Approval");
|
||||
expect(prompt).toContain("Team Building Phase");
|
||||
expect(prompt).toContain("file 3–5 `hire_agent` tool calls");
|
||||
expect(prompt).toContain("Do this first — file the hires");
|
||||
expect(prompt).not.toContain("file_approval.strategy.before_hires");
|
||||
expect(prompt).not.toContain("file_approval.strategy.already_filed");
|
||||
expect(prompt).not.toContain("Awaiting Org Strategy Approval");
|
||||
expect(prompt).not.toContain("Standup & Situational Assessment");
|
||||
expect(prompt).not.toContain("Goal Decomposition");
|
||||
expect(prompt).not.toContain("Proactive Behaviors");
|
||||
});
|
||||
|
||||
it("Phase 0.5: shows awaiting hire approvals when pending_approval hires exist but no org approval", () => {
|
||||
@@ -45,12 +52,19 @@ describe("Step 2: CEO phased prompts", () => {
|
||||
pendingApprovals: [],
|
||||
});
|
||||
|
||||
const prompt = buildSystemPrompt(ctx);
|
||||
const stablePrompt = buildSystemPrompt(ctx);
|
||||
const prompt = buildTaskPrompt(ctx);
|
||||
|
||||
expect(stablePrompt).not.toContain("Team Building Phase");
|
||||
expect(stablePrompt).not.toContain("Awaiting Hire Approvals");
|
||||
expect(stablePrompt).not.toContain("Awaiting Org Strategy Approval");
|
||||
expect(prompt).toContain("Awaiting Hire Approvals");
|
||||
expect(prompt).toContain("call `file_approval` once");
|
||||
expect(prompt).toContain("file_approval.strategy.before_hires");
|
||||
expect(prompt).not.toContain("Team Building Phase");
|
||||
expect(prompt).not.toContain("Standup & Situational Assessment");
|
||||
expect(prompt).not.toContain("Goal Decomposition");
|
||||
expect(prompt).not.toContain("Proactive Behaviors");
|
||||
});
|
||||
|
||||
it("Phase 1: shows awaiting org approval when pending approve_ceo_strategy exists", () => {
|
||||
@@ -77,10 +91,17 @@ describe("Step 2: CEO phased prompts", () => {
|
||||
],
|
||||
});
|
||||
|
||||
const prompt = buildSystemPrompt(ctx);
|
||||
const stablePrompt = buildSystemPrompt(ctx);
|
||||
const prompt = buildTaskPrompt(ctx);
|
||||
|
||||
expect(stablePrompt).not.toContain("Team Building Phase");
|
||||
expect(stablePrompt).not.toContain("Awaiting Hire Approvals");
|
||||
expect(stablePrompt).not.toContain("Awaiting Org Strategy Approval");
|
||||
expect(prompt).toContain("Awaiting Org Strategy Approval");
|
||||
expect(prompt).not.toContain("Team Building Phase");
|
||||
expect(prompt).not.toContain("Standup & Situational Assessment");
|
||||
expect(prompt).not.toContain("Goal Decomposition");
|
||||
expect(prompt).not.toContain("Proactive Behaviors");
|
||||
});
|
||||
|
||||
it("Phase 2: shows normal executive instructions when active reports and no pending org approval", () => {
|
||||
@@ -95,11 +116,12 @@ describe("Step 2: CEO phased prompts", () => {
|
||||
pendingApprovals: [],
|
||||
});
|
||||
|
||||
const prompt = buildSystemPrompt(ctx);
|
||||
const prompt = buildTaskPrompt(ctx);
|
||||
expect(prompt).toContain("Executive / CEO");
|
||||
expect(prompt).toContain("Goal Decomposition");
|
||||
expect(prompt).toContain("Delegation");
|
||||
expect(prompt).toContain("Unblock & Coordinate");
|
||||
expect(prompt).toContain("Proactive Behaviors");
|
||||
expect(prompt).not.toContain("Team Building Phase");
|
||||
expect(prompt).not.toContain("Awaiting Org Approval");
|
||||
});
|
||||
@@ -130,7 +152,7 @@ describe("Step 2: CEO phased prompts", () => {
|
||||
],
|
||||
});
|
||||
|
||||
const prompt = buildSystemPrompt(ctx);
|
||||
const prompt = buildTaskPrompt(ctx);
|
||||
expect(prompt).toContain("Pending Approvals");
|
||||
expect(prompt).toContain("Need Twitter API keys");
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildSystemPrompt, buildTaskPrompt } from "../../../src/main/prompt-builder/index";
|
||||
import { buildTaskPrompt } from "../../../src/main/prompt-builder/index";
|
||||
import type { ApprovalRecord } from "../../../src/shared/types";
|
||||
import { installSharedSetup } from "./shared-setup";
|
||||
|
||||
@@ -23,7 +23,7 @@ describe("E2E: Full autonomous CEO cold start flow", () => {
|
||||
chainOfCommand: [],
|
||||
pendingApprovals: [],
|
||||
});
|
||||
const phase0Prompt = buildSystemPrompt(phase0Ctx);
|
||||
const phase0Prompt = buildTaskPrompt(phase0Ctx);
|
||||
expect(phase0Prompt).toContain("Team Building Phase");
|
||||
|
||||
// 2. CEO submits hire requests
|
||||
@@ -60,7 +60,7 @@ describe("E2E: Full autonomous CEO cold start flow", () => {
|
||||
updatedAt: new Date().toISOString(),
|
||||
} as ApprovalRecord],
|
||||
});
|
||||
const phase1Prompt = buildSystemPrompt(phase1Ctx);
|
||||
const phase1Prompt = buildTaskPrompt(phase1Ctx);
|
||||
expect(phase1Prompt).toContain("Awaiting Org Strategy Approval");
|
||||
|
||||
// 4. Board approves hires
|
||||
@@ -100,7 +100,7 @@ describe("E2E: Full autonomous CEO cold start flow", () => {
|
||||
chainOfCommand: [],
|
||||
pendingApprovals: [], // all approved now
|
||||
});
|
||||
const phase2Prompt = buildSystemPrompt(phase2Ctx);
|
||||
const phase2Prompt = buildTaskPrompt(phase2Ctx);
|
||||
expect(phase2Prompt).toContain("Executive / CEO");
|
||||
expect(phase2Prompt).toContain("Goal Decomposition");
|
||||
expect(phase2Prompt).toContain("Delegation");
|
||||
@@ -226,7 +226,7 @@ describe("Review Fix: CEO phase ordering edge case", () => {
|
||||
pendingApprovals: [], // org strategy already resolved
|
||||
});
|
||||
|
||||
const prompt = buildSystemPrompt(ctx);
|
||||
const prompt = buildTaskPrompt(ctx);
|
||||
// Should NOT get Phase 0 (team building) — hires are already submitted
|
||||
expect(prompt).not.toContain("Team Building Phase");
|
||||
// Should get the awaiting hire approvals phase
|
||||
@@ -245,7 +245,7 @@ describe("Review Fix: CEO phase ordering edge case", () => {
|
||||
pendingApprovals: [],
|
||||
});
|
||||
|
||||
const prompt = buildSystemPrompt(ctx);
|
||||
const prompt = buildTaskPrompt(ctx);
|
||||
expect(prompt).toContain("Executive / CEO");
|
||||
expect(prompt).not.toContain("Awaiting Hire Approvals");
|
||||
expect(prompt).not.toContain("Team Building Phase");
|
||||
@@ -277,7 +277,7 @@ describe("Review Fix: Org gate consistency (revision_requested)", () => {
|
||||
],
|
||||
});
|
||||
|
||||
const prompt = buildSystemPrompt(ctx);
|
||||
const prompt = buildTaskPrompt(ctx);
|
||||
expect(prompt).toContain("Awaiting Org Strategy Approval");
|
||||
expect(prompt).toContain("revision_requested");
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildSystemPrompt } from "../../../src/main/prompt-builder/index";
|
||||
import { buildSystemPrompt, buildTaskPrompt } from "../../../src/main/prompt-builder/index";
|
||||
import { installSharedSetup } from "./shared-setup";
|
||||
|
||||
const shared = installSharedSetup();
|
||||
@@ -19,7 +19,7 @@ describe("Step 1: CEO role detection", () => {
|
||||
chainOfCommand: [], // top-level
|
||||
});
|
||||
|
||||
const prompt = buildSystemPrompt(ctx);
|
||||
const prompt = buildTaskPrompt(ctx);
|
||||
|
||||
// CEO should NOT get IC instructions
|
||||
expect(prompt).not.toContain("Individual Contributor");
|
||||
|
||||
@@ -71,6 +71,54 @@ function buildCtx(overrides: Partial<PromptContext> = {}): PromptContext {
|
||||
};
|
||||
}
|
||||
|
||||
function buildTask(overrides: Partial<NonNullable<PromptContext["task"]>> = {}): NonNullable<PromptContext["task"]> {
|
||||
const now = new Date().toISOString();
|
||||
return {
|
||||
id: "task-1",
|
||||
companyId: "company-1",
|
||||
projectId: null,
|
||||
goalId: null,
|
||||
parentId: null,
|
||||
title: "Ship volatile task",
|
||||
description: "This task should live in the volatile prompt tail.",
|
||||
assigneeAgentId: "agent-1",
|
||||
workspaceId: null,
|
||||
status: "in_progress",
|
||||
priority: "high",
|
||||
activeRunId: null,
|
||||
costUsd: 0,
|
||||
taskType: null,
|
||||
requiresUserReview: false,
|
||||
requiresFilesystem: false,
|
||||
startedAt: null,
|
||||
completedAt: null,
|
||||
cancelledAt: null,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function buildApproval(overrides: Partial<PromptContext["pendingApprovals"][number]> = {}): PromptContext["pendingApprovals"][number] {
|
||||
const now = new Date().toISOString();
|
||||
return {
|
||||
id: "approval-1",
|
||||
companyId: "company-1",
|
||||
relatedTaskId: null,
|
||||
relatedAgentId: null,
|
||||
requestedByAgentId: "agent-1",
|
||||
type: "approve_ceo_strategy",
|
||||
payloadSummary: "Review the volatile org gate.",
|
||||
impactSummary: "Board decision required.",
|
||||
payloadJson: null,
|
||||
decisionNote: "",
|
||||
state: "pending",
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("buildSystemPrompt leadership classification", () => {
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
@@ -112,6 +160,84 @@ describe("buildSystemPrompt leadership classification", () => {
|
||||
expect(second).toBe(first);
|
||||
});
|
||||
|
||||
it("keeps run, locale, and task context out of the stable system prompt", () => {
|
||||
const ctx = buildCtx({
|
||||
runId: "run-volatile",
|
||||
locale: "zh",
|
||||
task: buildTask(),
|
||||
wakeReason: "assignment",
|
||||
});
|
||||
|
||||
const stablePrompt = buildSystemPrompt(ctx);
|
||||
const fullPrompt = buildTaskPrompt(ctx);
|
||||
|
||||
expect(stablePrompt).not.toContain("run-volatile");
|
||||
expect(stablePrompt).not.toContain("Ship volatile task");
|
||||
expect(stablePrompt).not.toContain("Respond to the user in Chinese.");
|
||||
expect(stablePrompt).not.toContain("{{runId}}");
|
||||
expect(stablePrompt).toContain("$AGENT_COMPANY_RUN_ID");
|
||||
expect(fullPrompt).toContain("Current Run ID: run-volatile");
|
||||
expect(fullPrompt).toContain("Ship volatile task");
|
||||
expect(fullPrompt).toContain("Respond to the user in Chinese.");
|
||||
});
|
||||
|
||||
it("keeps the stable prefix identical across volatile run changes", () => {
|
||||
const firstCtx = buildCtx({
|
||||
runId: "run-a",
|
||||
locale: "en",
|
||||
task: buildTask({ id: "task-a", title: "First volatile task" }),
|
||||
wakeReason: "timer",
|
||||
});
|
||||
const secondCtx = buildCtx({
|
||||
runId: "run-b",
|
||||
locale: "zh",
|
||||
task: buildTask({ id: "task-b", title: "Second volatile task" }),
|
||||
wakeReason: "assignment",
|
||||
});
|
||||
|
||||
const firstStable = buildSystemPrompt(firstCtx);
|
||||
const secondStable = buildSystemPrompt(secondCtx);
|
||||
const secondFull = buildTaskPrompt(secondCtx);
|
||||
|
||||
expect(secondStable).toBe(firstStable);
|
||||
expect(secondFull.slice(0, secondStable.length)).toBe(secondStable);
|
||||
expect(secondFull.slice(secondStable.length)).toContain("Second volatile task");
|
||||
});
|
||||
|
||||
it("keeps approval gates and workload counts out of the stable system prompt", () => {
|
||||
const baseAgent = buildCtx().agent;
|
||||
const report = {
|
||||
...baseAgent,
|
||||
id: "report-1",
|
||||
name: "Engineer",
|
||||
role: "Engineer",
|
||||
title: "Staff Engineer",
|
||||
reportsTo: baseAgent.id,
|
||||
};
|
||||
const stableBase = buildCtx({
|
||||
chainOfCommand: [],
|
||||
directReports: [report],
|
||||
allAgents: [baseAgent, report],
|
||||
allTasks: [buildTask({ id: "report-task", assigneeAgentId: report.id, status: "todo" })],
|
||||
pendingApprovals: [],
|
||||
});
|
||||
const volatileChanged = buildCtx({
|
||||
chainOfCommand: [],
|
||||
directReports: [report],
|
||||
allAgents: [baseAgent, report],
|
||||
allTasks: [buildTask({ id: "report-task", assigneeAgentId: report.id, status: "blocked" })],
|
||||
pendingApprovals: [buildApproval()],
|
||||
});
|
||||
|
||||
const stablePrompt = buildSystemPrompt(stableBase);
|
||||
const changedStablePrompt = buildSystemPrompt(volatileChanged);
|
||||
const changedFullPrompt = buildTaskPrompt(volatileChanged);
|
||||
|
||||
expect(changedStablePrompt).toBe(stablePrompt);
|
||||
expect(changedFullPrompt).toContain("Pending Approvals");
|
||||
expect(changedFullPrompt).toContain("1 blocked");
|
||||
});
|
||||
|
||||
it("keeps volatile task context after the cacheable system prefix", () => {
|
||||
const ctx = buildCtx({ wakeReason: "timer" });
|
||||
const systemPrompt = buildSystemPrompt(ctx);
|
||||
|
||||
Reference in new issue
Block a user