Files
AgentCompany/src/main/agent-role-helpers.ts
T
ZacharyZhang-NY 2df921ca88 refactor(agents): share leadership role detector, use word-boundary match
P2-23: 'lead' in system-prompt.ts matched 'cleaner' / 'leaderboard' via
substring .includes(). Hoist LEADERSHIP_ROLE_KEYWORDS into a shared
agent-role-helpers.ts module; tokenize input on non-alphanum to require
whole-word match.

P3-54: Same keyword list was duplicated in automation-skills with drift
(missing 'ceo', different members). Both sites now call through the
shared helper.
2026-04-16 22:57:35 -04:00

34 lines
863 B
TypeScript

/**
* Role-classification helpers used across prompt construction and skill
* auto-assignment. Keeping a single keyword list here prevents drift
* between system-prompt.ts and automation-skills.ts.
*
* Matching uses word-boundary tokenization instead of substring search,
* so "lead" does not match "cleaner" or "leaderboard".
*/
export const LEADERSHIP_ROLE_KEYWORDS = [
"chief",
"cto",
"cmo",
"coo",
"cfo",
"ceo",
"vp",
"vice",
"president",
"head",
"director",
"manager",
"lead",
] as const;
function tokenize(text: string): string[] {
return text.toLowerCase().match(/[a-z0-9]+/g) ?? [];
}
export function roleMatchesLeadershipKeywords(role: string, title?: string | null): boolean {
const tokens = new Set(tokenize(`${role} ${title ?? ""}`));
return LEADERSHIP_ROLE_KEYWORDS.some((keyword) => tokens.has(keyword));
}