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.
This commit is contained in:
ZacharyZhang-NY committed 2026-04-16 22:57:35 -04:00
1 parent ba6ba8360b
commit 2df921ca88
6 files changed
+89 -34

No files matched your search

+4 -16
View File
@@ -19,27 +19,15 @@ import {
buildDepartmentSection,
} from "./operating-instructions";
import type { PromptContext } from "./index";
const LEADERSHIP_KEYWORDS = [
"chief",
"cto",
"cmo",
"coo",
"cfo",
"vp",
"vice president",
"head",
"director",
"manager",
"lead",
];
import { roleMatchesLeadershipKeywords } from "../agent-role-helpers";
function isLeadershipRole(ctx: PromptContext): boolean {
// HR roles inherit leadership scope for manager-style prompts;
// other departments rely on role/title keyword tokenization.
if (ctx.agent.department === "hr") {
return true;
}
const text = `${ctx.agent.role} ${ctx.agent.title ?? ""}`.toLowerCase();
return LEADERSHIP_KEYWORDS.some((keyword) => text.includes(keyword));
return roleMatchesLeadershipKeywords(ctx.agent.role, ctx.agent.title ?? null);
}
function buildSkillManifest(