Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): require conversation key, honor instructions, deep-link alerts, cap fail-closed
[._.]/ Adam Eivyb38a14eb90b5
diff --git a/client/src/pages/Tribe.jsx b/client/src/pages/Tribe.jsxindex e2c68bc8ad..cec99ffcc4 100644--- a/client/src/pages/Tribe.jsx+++ b/client/src/pages/Tribe.jsx@@ -587,6 +587,12 @@ function OutreachQueue() {const [busyKeys, setBusyKeys] = useState(() => new Set());const [drafts, setDrafts] = useState({});const [copiedKey, setCopiedKey] = useState(null);+ const [highlightKey, setHighlightKey] = useState(null);+ const rowRefs = useRef({});+ // A proactive alert deep-links here as ?outreach=<personId> — scroll to and+ // highlight that person's thread so clicking one of several alerts lands on it.+ const [searchParams] = useSearchParams();+ const outreachPersonId = searchParams.get('outreach');useEffect(() => {let cancelled = false;@@ -596,6 +602,17 @@ function OutreachQueue() {return () => { cancelled = true; };}, []);+ useEffect(() => {+ if (!outreachPersonId || !Array.isArray(threads)) return;+ const target = threads.find((t) => t.personId === outreachPersonId);+ if (!target) return;+ const el = rowRefs.current[target.conversationKey];+ if (el) el.scrollIntoView({ behavior: 'smooth', block: 'center' });+ setHighlightKey(target.conversationKey);+ const timer = setTimeout(() => setHighlightKey((prev) => (prev === target.conversationKey ? null : prev)), 2500);+ return () => clearTimeout(timer);+ }, [outreachPersonId, threads]);+const generate = async (thread) => {const key = thread.conversationKey;if (busyKeys.has(key) || drafts[key]) return; // already generating or done@@ -655,8 +672,13 @@ function OutreachQueue() {{threads.map((thread) => {const draft = drafts[thread.conversationKey];const busy = busyKeys.has(thread.conversationKey);+ const highlighted = highlightKey === thread.conversationKey;return (- <div key={thread.conversationKey} className="rounded border border-port-border bg-port-bg p-3">+ <div+ key={thread.conversationKey}+ ref={(el) => { rowRefs.current[thread.conversationKey] = el; }}+ className={`rounded border bg-port-bg p-3 transition-colors ${highlighted ? 'border-port-warning ring-1 ring-port-warning' : 'border-port-border'}`}+ ><div className="flex flex-wrap items-center gap-2 text-xs text-gray-500"><span className="font-medium text-white">{thread.personName}</span><span className="rounded border border-port-border px-1.5 py-0.5">{sourceLabel(thread.source)}</span>diff --git a/server/routes/tribe.js b/server/routes/tribe.jsindex 574691e047..d4f25bf194 100644--- a/server/routes/tribe.js+++ b/server/routes/tribe.js@@ -72,7 +72,12 @@ const outreachDraftSchema = z.object({lastInboundAt: z.string().datetime().nullable().optional(),instructions: z.string().max(2000).optional().default(''),useVoice: z.boolean().optional(),-});+}).refine(+ // Require a conversation key — without one, generateOutreachDraft would query+ // the whole timeline and draft a reply to an unrelated conversation.+ (d) => Boolean(d.threadId || d.chatGuid || d.conversationId || d.handle),+ { message: 'An outreach draft needs one of threadId, chatGuid, conversationId, or handle' },+);const listQuerySchema = z.object({search: z.string().max(200).optional(),diff --git a/server/routes/tribe.test.js b/server/routes/tribe.test.jsindex 4b712c101b..9a23b29cca 100644--- a/server/routes/tribe.test.js+++ b/server/routes/tribe.test.js@@ -303,7 +303,16 @@ describe('Tribe Routes', () => {it('rejects an outreach draft request with a non-UUID personId', async () => {const response = await request(app).post('/api/tribe/outreach/draft')- .send({ personId: 'not-a-uuid' });+ .send({ personId: 'not-a-uuid', chatGuid: 'chat-1' });++ expect(response.status).toBe(400);+ expect(tribeOutreach.generateOutreachDraft).not.toHaveBeenCalled();+ });++ it('rejects an outreach draft request with no conversation key', async () => {+ const response = await request(app)+ .post('/api/tribe/outreach/draft')+ .send({ personId: PERSON_ID }); // valid person, but no thread/chat/convo/handleexpect(response.status).toBe(400);expect(tribeOutreach.generateOutreachDraft).not.toHaveBeenCalled();diff --git a/server/services/proactiveAlerts.js b/server/services/proactiveAlerts.jsindex 97c6cdfb19..e900d4f295 100644--- a/server/services/proactiveAlerts.js+++ b/server/services/proactiveAlerts.js@@ -287,7 +287,9 @@ async function checkUnansweredTribeThreads() {severity: t.daysAgo >= 7 ? 'high' : 'medium',title: `Unanswered: ${t.personName}`,detail: `You never replied to ${snippet} (${ago(t.daysAgo)})`,- link: '/tribe?tab=care',+ // Deep-link to the specific outreach item (person) so clicking one of several+ // alerts scrolls to and highlights the right thread, not just the Care Queue.+ link: `/tribe?tab=care&outreach=${encodeURIComponent(t.personId)}`,metadata: {personId: t.personId,source: t.source,diff --git a/server/services/tribeOutreach.js b/server/services/tribeOutreach.jsindex 474df2dc05..cfea6691b1 100644--- a/server/services/tribeOutreach.js+++ b/server/services/tribeOutreach.js@@ -51,8 +51,10 @@ const TWO_WAY_SOURCES = new Set(['imessage', 'signal']);// Channel-appropriate reply prompt for chat outreach — generateReplyBody's default// template is email-toned ("Write a professional reply to this email"), which reads-// wrong for a text message. {{from}}/{{body}} are substituted by generateReplyBody.-const OUTREACH_CHAT_TEMPLATE = 'Write a brief, warm, casual reply to reconnect over a text message. Keep it short and personal — no email subject line, no formal salutation or sign-off.\n\nFrom: {{from}}\nTheir message:\n{{body}}';+// wrong for a text message. generateReplyBody substitutes {{from}}/{{body}} and+// resolves the {{#instructions}} conditional block, so any caller-supplied guidance+// actually reaches the model (the default template omits it and drops it silently).+const OUTREACH_CHAT_TEMPLATE = 'Write a brief, warm, casual reply to reconnect over a text message. Keep it short and personal — no email subject line, no formal salutation or sign-off.{{#instructions}}\n\nAdditional guidance: {{instructions}}{{/instructions}}\n\nFrom: {{from}}\nTheir message:\n{{body}}';// A conversation is keyed by the most specific stable identifier available:// chatGuid (iMessage), conversationId (Signal — its outbound turns carry no@@ -192,8 +194,18 @@ export async function findUnansweredTribeThreads({Promise.all([listEvents({ from, source: src, kind: 'message.received', limit: 2000 }),listEvents({ from, source: src, kind: 'message.sent', limit: 2000 }),- ]).then(([r, s]) => { received.push(...r); sent.push(...s); })- .catch(() => { /* partial read → drop this source to avoid false nudges */ })+ ]).then(([r, s]) => {+ // Fail CLOSED when either direction hits the 2000-row cap: the two queries+ // are capped independently, so a truncated `sent` result could omit an older+ // reply while its inbound survives in `received` — reporting an answered+ // thread as unanswered. Better no nudge for that (very heavy) source than a+ // false one. (received-cap is a false-negative only, but skip either to be safe.)+ if (r.length >= 2000 || s.length >= 2000) {+ console.warn(`🤝 Skipping ${src} outreach scan — timeline query hit the 2000-row cap (can't verify reply state)`);+ return;+ }+ received.push(...r); sent.push(...s);+ }).catch(() => { /* partial read → drop this source to avoid false nudges */ })));// Every outbound turn just needs to cancel the unanswered flag for its