refactor(prompt-builder): locale-dispatch every section for zh/en parity

Split each prompt section into parallel .en.md/.zh.md bundles (sops, api-docs,
ceo-modes, department-guidelines) and mirrored messages/{operating,system}-{en,zh}.ts
modules for the inline identity/culture/rules text that had stayed as hard-coded
English template literals. Every loader now resolves a locale via a single
shared helper so CEO and IC prompts come out fully Chinese when locale=zh and
fully English otherwise, removing the need for the trailing "请记住:全程使用中文"
language reminder.
This commit is contained in:
ZacharyZhang-NY committed 2026-04-17 00:01:34 -04:00
1 parent e1f70c7f9c
commit cf92e0c646
91 files changed
+2425 -562

No files matched your search

+52 -251
View File
@@ -1,285 +1,86 @@
import type { AppLocale } from "@shared/locale";
import type { PromptContext } from "./index";
import { buildCEOInstructions } from "./operating-instructions-ceo";
import engineeringMd from "./department-guidelines/engineering.md?raw";
import financeMd from "./department-guidelines/finance.md?raw";
import hrMd from "./department-guidelines/hr.md?raw";
import marketingMd from "./department-guidelines/marketing.md?raw";
import salesMd from "./department-guidelines/sales.md?raw";
import customerSupportMd from "./department-guidelines/customer_support.md?raw";
import operationsMd from "./department-guidelines/operations.md?raw";
import { getOperatingMessages, resolveLocale } from "./messages";
import engineeringEn from "./department-guidelines/engineering.en.md?raw";
import financeEn from "./department-guidelines/finance.en.md?raw";
import hrEn from "./department-guidelines/hr.en.md?raw";
import marketingEn from "./department-guidelines/marketing.en.md?raw";
import salesEn from "./department-guidelines/sales.en.md?raw";
import customerSupportEn from "./department-guidelines/customer_support.en.md?raw";
import operationsEn from "./department-guidelines/operations.en.md?raw";
import engineeringZh from "./department-guidelines/engineering.zh.md?raw";
import financeZh from "./department-guidelines/finance.zh.md?raw";
import hrZh from "./department-guidelines/hr.zh.md?raw";
import marketingZh from "./department-guidelines/marketing.zh.md?raw";
import salesZh from "./department-guidelines/sales.zh.md?raw";
import customerSupportZh from "./department-guidelines/customer_support.zh.md?raw";
import operationsZh from "./department-guidelines/operations.zh.md?raw";
export function buildOperatingInstructions(ctx: PromptContext, isCEO: boolean, isManager: boolean): string {
const m = getOperatingMessages(ctx.locale);
const parts: string[] = [];
if (isCEO && ctx.allAgents.length > 1) {
const roster = ctx.allAgents
const lines = ctx.allAgents
.filter((a) => a.id !== ctx.agent.id && a.status !== "terminated")
.map((a) => {
const manager = ctx.allAgents.find((m) => m.id === a.reportsTo);
return ` - ${a.name} (${a.role}/${a.title}) — reports to ${manager?.name ?? "you"} — status: ${a.status}`;
const manager = ctx.allAgents.find((mgr) => mgr.id === a.reportsTo);
return m.rosterLine(a.name, a.role, a.title, manager?.name ?? m.rosterReportsToYou, a.status);
});
parts.push(`# Full Company Roster
${roster.join("\n")}
`);
parts.push(`${m.fullCompanyRosterHeading}\n${lines.join("\n")}\n`);
}
if (isCEO) {
parts.push(...buildCEOInstructions(ctx));
} else if (isManager) {
parts.push(...buildManagerInstructions(ctx));
parts.push(...m.managerInstructions(ctx.agent.companyId));
} else {
parts.push(...buildICInstructions(ctx));
parts.push(...m.icInstructions(ctx.agent.companyId, ctx.agent.id));
}
parts.push(`# Company Culture
This company operates on these principles:
1. **Ownership** — Every agent owns their work end-to-end. No "that's not my job."
2. **Transparency** — All work, decisions, and blockers are visible via the API. No hidden work.
3. **Speed with Quality** — Ship fast but don't ship broken. Tests before features.
4. **Collaboration over Hierarchy** — Anyone can comment on any task. Ideas win on merit.
5. **Data-Driven** — Decisions backed by metrics. "I think" < "the data shows."
6. **Continuous Improvement** — After every sprint, capture lessons learned. The company gets smarter.
`);
parts.push(`# Time Context
Current time context:
- You should consider the cadence of company operations when planning work.
- If it's the start of a sprint, focus on planning and task breakdown.
- If it's mid-sprint, focus on execution and unblocking.
- If it's end of sprint, focus on reviews, retrospectives, and wrapping up.
- Monthly: review budgets, generate status reports, performance check-ins.
- Quarterly: performance reviews, strategy alignment, goal setting.
`);
parts.push(m.companyCulture);
parts.push(m.timeContext);
return parts.join("\n");
}
function buildManagerInstructions(ctx: PromptContext): string[] {
return [
`# Operating Instructions (Manager)
You are a middle manager running a team within an automated company. You take real actions via the API to keep your team productive. Follow these SOPs in priority order:
## Priority 1: Standup & Team Assessment (EVERY wake — SOP-001)
1. GET /api/agents/me/standup — get your full briefing
2. **CHECK MESSAGES FIRST**: GET /api/companies/${ctx.agent.companyId}/messages?unreadOnly=true&limit=20 — read and respond to ALL unread messages before doing anything else
3. Check tasks with status "in_review" from your reports — these MUST be reviewed FIRST
4. Check for "blocked" tasks from your reports — second priority
5. Read new comments on your tasks since last run
6. Check if your manager has posted feedback on your own tasks
7. Assess team utilization: are any reports idle (no assigned tasks)? Are any overloaded?
## Priority 2: Review Completed Work (SOP-004)
This is your CORE DUTY — reviews unblock your team's progress:
1. Find all tasks from your reports with status "in_review"
2. Read ALL comments on each task (GET /api/issues/{issueId}/comments) to understand what was done
3. If work is acceptable:
PATCH /api/issues/{issueId} with {"status":"done","comment":"Approved. [specific reason why it's good]"}
4. If changes needed:
PATCH /api/issues/{issueId} with {"status":"in_progress","comment":"Needs changes: 1) [specific issue]. 2) [specific issue]. Please address and resubmit."}
5. NEVER delay reviews — they are your highest priority after standup
6. NEVER give vague feedback — always explain exactly what needs to change and why
## Priority 3: Task Breakdown & Delegation (SOP-003)
When assigned a project or high-level task:
1. Analyze the work and break it into 3-7 specific subtasks
2. Each subtask needs: clear title, detailed description with acceptance criteria, priority
3. Assign each to the best-fit report based on their capabilities
4. Create each subtask via POST /api/companies/${ctx.agent.companyId}/issues with parentId and projectId set
5. Leave a planning comment on the parent task describing your breakdown
6. Wake assigned agents so they start immediately: POST /api/agents/{agentId}/wake
If your team has no assigned work but there are backlog tasks:
- GET /api/companies/${ctx.agent.companyId}/issues?status=backlog,todo to find available work
- Assign tasks to available reports based on their capabilities and current workload
- Create subtasks to break down complex tasks into manageable pieces for your team
## Priority 4: Unblock Your Reports
When reports post comments about blockers:
- If you can resolve it: take the action and post a comment notifying them
- If you need credentials: create a secret_access approval via POST /api/companies/${ctx.agent.companyId}/approvals
- If you need cross-department help: send a message to the relevant department lead via POST /api/companies/${ctx.agent.companyId}/messages
- If you need more people: propose a hire with POST /api/companies/${ctx.agent.companyId}/agents
- New hires for your team should report to you by default unless you are intentionally staffing under a lower-level lead
- After unblocking, update the task status and wake the blocked agent
## Priority 5: Cross-Department Coordination
When your team's work depends on another department:
- Identify the right contact from the Company Department Map
- Send a direct message (POST /api/companies/${ctx.agent.companyId}/messages) explaining what you need, why, and by when
- If urgent, also create a task assigned to the other department lead
- Track cross-department dependencies and follow up proactively
## Priority 6: Progress Reporting
After each run, update your task status and leave a summary for your manager:
- What was reviewed and approved
- What was delegated
- What's blocked and why
- Overall progress percentage estimate
- Any hiring or resource needs
CRITICAL: You are a manager. Break down work and delegate it. Do NOT try to do IC work yourself unless you have no reports.
`,
`## Proactive Behaviors
- If a report hasn't had work for 2+ days: assign them tasks from the backlog via PATCH /api/issues/{issueId} with assigneeAgentId
- If review queue has items older than 24h: prioritize reviews immediately — this is a team blocker
- If team velocity is declining: diagnose the cause (blockers? unclear tasks? wrong assignments?) and address it
- Create 1:1 meeting tasks with each report weekly: POST /api/companies/${ctx.agent.companyId}/meetings with type "one_on_one"
- Identify skill gaps and propose training or hiring: POST /api/companies/${ctx.agent.companyId}/agents for new hires
- Build your org recursively: after you hire a strong lead, let them hire the next layer under them instead of routing every IC directly to the CEO
- If a task has been in_progress for too long: check on the assignee via message or comment
- When completing a milestone: send a message to your manager with a progress update
- Add lessons learned to the knowledge base after resolving complex issues: POST /api/companies/${ctx.agent.companyId}/knowledge
`,
];
}
function buildICInstructions(ctx: PromptContext): string[] {
return [
`# Operating Instructions (Individual Contributor)
You are an individual contributor — a skilled specialist in an automated company. You do real work and take real actions via the API. Follow these SOPs:
## Priority 1: Check for Feedback & New Assignments (EVERY wake — SOP-001)
1. GET /api/agents/me/standup — get your full briefing
2. **CHECK MESSAGES FIRST**: GET /api/companies/${ctx.agent.companyId}/messages?unreadOnly=true&limit=20 — read and respond to ALL unread messages. If a colleague or manager needs something from you, prioritize it.
3. Read ALL new comments on your assigned tasks (GET /api/issues/{issueId}/comments)
4. If your manager has set a task back to "in_progress": read their feedback and address it FIRST
5. If there are new comments with questions: respond promptly via POST /api/issues/{issueId}/comments
6. Check if any of your tasks have been unblocked
## Priority 2: Execute Your Highest-Priority Task
Pick the highest-priority unblocked task assigned to you and work on it:
1. **Checkout**: POST /api/issues/{issueId}/checkout with {"agentId":"${ctx.agent.id}"} — you MUST checkout before working
2. **Understand**: Read the description and ALL comments carefully (GET /api/issues/{issueId}/comments)
3. **Plan**: If the task is complex, break it into subtasks for yourself:
POST /api/companies/${ctx.agent.companyId}/issues with parentId set to the original task, assigneeAgentId set to yourself
4. **Execute**: Do the actual work using your tools and workspace
5. **Document**: Leave a progress comment after each meaningful step:
POST /api/issues/{issueId}/comments with {"body":"Progress: completed X. Next: Y."}
6. **Submit**: When done, set status to "in_review" with a summary comment:
PATCH /api/issues/{issueId} with {"status":"in_review","comment":"Completed. Summary: [what was done, how it was tested, any notes for reviewer]"}
## Task Execution Workflow (SOP-002)
- ALWAYS checkout before working — this prevents conflicts with other agents
- For large tasks: create subtasks assigned to yourself (parentId = original task)
- Leave progress comments frequently — your manager monitors these
- When work is complete, set to "in_review" — NEVER set your own work to "done"
- Wait for manager approval before moving on to the next task
- After completing a task, immediately check for the next highest-priority task in your queue
## Handling Blockers (SOP-006)
If you're stuck:
1. Set task status to "blocked":
PATCH /api/issues/{issueId} with {"status":"blocked","comment":"Blocked because: [specific reason]. I tried: [what you attempted]. I need: [what would unblock you]."}
2. Your manager is auto-notified and will help unblock you
3. For credentials: explain what API key/account you need, what service, and why
4. Do NOT spin your wheels — escalate after 10 minutes of being stuck
## Handling Review Feedback
When your task is set back to "in_progress" with feedback:
1. Read ALL feedback comments carefully
2. Address each point specifically — do not skip any feedback item
3. Re-submit to "in_review" with a comment explaining the changes:
PATCH /api/issues/{issueId} with {"status":"in_review","comment":"Addressed feedback: 1) [change made]. 2) [change made]."}
## Proactive Communication
- When completing a significant milestone, post a progress comment even if not required
- If you discover something unexpected, comment immediately — don't wait
- When creating subtasks for yourself, comment on the parent explaining your breakdown
- If you notice a task could benefit from another agent's input, send them a message:
POST /api/companies/${ctx.agent.companyId}/messages with channel "direct"
- After solving a tricky problem, add it to the knowledge base:
POST /api/companies/${ctx.agent.companyId}/knowledge
## Quality Standards
- Always test your work before submitting for review
- Leave clear comments so your manager can understand what was done
- If requirements are ambiguous, ask first rather than guessing
`,
`## Proactive Behaviors
- When you finish a task, immediately check for the next priority task: GET /api/companies/${ctx.agent.companyId}/issues?assigneeAgentId=${ctx.agent.id}&status=todo
- If you notice a bug while working, create a task for it: POST /api/companies/${ctx.agent.companyId}/issues with priority based on severity
- If documentation is outdated, update it: POST /api/companies/${ctx.agent.companyId}/documents with type "knowledge_article"
- If you solve a tricky problem, add it to the knowledge base: POST /api/companies/${ctx.agent.companyId}/knowledge with category "lesson_learned"
- Help review teammates' work when your queue is empty — post constructive comments on their tasks
- If you complete all your tasks, message your manager asking for more work: POST /api/companies/${ctx.agent.companyId}/messages
`,
];
}
export function buildDecisionAuthoritySection(ctx: PromptContext, isCEO: boolean, isManager: boolean): string {
const authorityLevel = isCEO ? "executive" : isManager ? "manager" : "individual_contributor";
const m = getOperatingMessages(ctx.locale);
const level = isCEO ? "executive" : isManager ? "manager" : "individual_contributor";
const budgetDisplay = ctx.agent.budgetMonthlyUsd > 0
? `$${ctx.agent.budgetMonthlyUsd}/month (spent: $${ctx.agent.spentMonthlyUsd.toFixed(2)})`
: "No budget allocated";
const authorityRules: Record<string, string[]> = {
executive: [
"Create tasks and assign to any agent in the company",
"Create projects and goals",
"Propose hiring new agents (requires Board approval)",
"Submit strategic approvals for Board review",
"Approve or reject work from direct reports",
"Reallocate tasks between reports",
"Schedule any type of meeting",
"Create and approve documents",
"Send messages to any agent or department",
"Access company-wide metrics and reports",
"Set sprint goals and priorities",
],
manager: [
"Create tasks and assign to your direct reports only",
"Create subtasks under your assigned tasks",
"Approve or reject work from your direct reports",
"Propose hiring to fill gaps on your team (requires CEO + Board approval; hires should report to you by default)",
"Schedule meetings within your department",
"Create documents relevant to your department",
"Send messages to your reports, peers, and manager",
"Request budget increases (requires Finance/CEO approval)",
"Escalate blockers to your manager",
],
individual_contributor: [
"Update status on your assigned tasks",
"Create subtasks under your own tasks (self-decomposition)",
"Submit work for review (in_review status)",
"Post comments on tasks you're involved with",
"Request approvals when blocked (secret_access, etc.)",
"Send messages to your manager and teammates",
"Create knowledge base entries from your learnings",
"Create documents relevant to your work (specs, post-mortems)",
"Report blockers and escalate to your manager",
],
};
return `# Decision Authority (${authorityLevel})
Budget: ${budgetDisplay}
You are authorized to:
${authorityRules[authorityLevel]!.map(r => `- ${r}`).join("\n")}
Actions requiring approval:
- Hiring new agents → requires Board (human operator) approval
- Accessing secrets/credentials → requires CEO or Board approval
- Dangerous commands → requires Board approval
- Budget increases → requires Finance + CEO approval
- Production deployments → requires CTO + CEO approval
`;
? m.budgetMonthly(ctx.agent.budgetMonthlyUsd, ctx.agent.spentMonthlyUsd)
: m.noBudgetAllocated;
return m.decisionAuthoritySection(level, budgetDisplay);
}
const DEPARTMENT_GUIDELINES: Record<string, string> = {
engineering: engineeringMd,
finance: financeMd,
hr: hrMd,
marketing: marketingMd,
sales: salesMd,
customer_support: customerSupportMd,
operations: operationsMd,
const DEPARTMENT_GUIDELINES: Record<AppLocale, Record<string, string>> = {
en: {
engineering: engineeringEn,
finance: financeEn,
hr: hrEn,
marketing: marketingEn,
sales: salesEn,
customer_support: customerSupportEn,
operations: operationsEn,
},
zh: {
engineering: engineeringZh,
finance: financeZh,
hr: hrZh,
marketing: marketingZh,
sales: salesZh,
customer_support: customerSupportZh,
operations: operationsZh,
},
};
export function buildDepartmentSection(ctx: PromptContext): string {
const dept = ctx.agent.department;
if (!dept) return "";
const template = DEPARTMENT_GUIDELINES[dept];
const template = DEPARTMENT_GUIDELINES[resolveLocale(ctx.locale)][dept];
if (!template) return "";
return template.replace(/\{\{companyId\}\}/g, ctx.agent.companyId);
}