From 6a93c606b9fb27fa44cc80d1fa057f2d1f7c0a23 Mon Sep 17 00:00:00 2001 From: Chaim Marcus Date: Sun, 17 May 2026 10:54:39 +0000 Subject: [PATCH] fix: pick first mapped CEO for weekly-feedback-analysis; align reason string - Replace companies[0] with first company that has a CEO_AGENT_IDS entry, so the job doesn't silently skip if the list order is non-deterministic - Change reason to "weekly-feedback-job" to match the CEO routing condition added in legal-ceo.md (was "weekly-feedback-analysis scheduled job") - decision-lessons.md is shared between companies so one CEO invocation suffices Co-Authored-By: Claude Sonnet 4.6 --- src/worker.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/worker.ts b/src/worker.ts index f2ddbf1..0e6590d 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -799,25 +799,31 @@ const plugin = definePlugin({ return; } + // Pick the first company with a known CEO mapping — decision-lessons.md is + // shared between companies, so a single CEO invocation is sufficient. const companies = await ctx.companies.list(); - const company = companies[0]; - if (!company) return; + const mapped = companies + .map((c) => ({ company: c, ceoId: CEO_AGENT_IDS[c.id] })) + .filter((x): x is { company: (typeof companies)[0]; ceoId: string } => + Boolean(x.ceoId), + ); - const ceoId = CEO_AGENT_IDS[company.id]; - if (!ceoId) { + if (mapped.length === 0) { ctx.logger.warn( - `weekly-feedback-analysis: no CEO agent for company ${company.id}`, + "weekly-feedback-analysis: no company has a mapped CEO agent — skipping", ); return; } + const { company, ceoId } = mapped[0]; + await ctx.agents.invoke(ceoId, company.id, { prompt: `ניתוח פידבק שבועי יו"ר (${data.entry_count} פריטים):\n\n${data.summary}\n\nהמשימה: עדכן את /home/chaim/legal-ai/docs/legal-decision-lessons.md עם הלקחים החדשים שעולים מהפידבק. הוסף רק לקחים חדשים שלא קיימים כבר. קבץ לפי נושא.`, - reason: "weekly-feedback-analysis scheduled job", + reason: "weekly-feedback-job", }); ctx.logger.info( - `weekly-feedback-analysis: invoked CEO ${ceoId} with ${data.entry_count} feedback entries`, + `weekly-feedback-analysis: invoked CEO ${ceoId} (company ${company.id}) with ${data.entry_count} feedback entries`, ); });