spora 0.7.5 → 0.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/runtime/decision-engine.ts","../src/runtime/policy.ts","../src/memory/agent-network.ts","../src/runtime/research.ts","../src/runtime/opportunity-engine.ts","../src/runtime/portfolio-planner.ts","../src/runtime/bandit.ts","../src/runtime/autonomy.ts"],"sourcesContent":["import { logger } from \"../utils/logger.js\";\nimport { getXClient } from \"../x-client/index.js\";\nimport { addLearning, logInteraction } from \"../memory/index.js\";\nimport { loadIdentity, saveIdentity } from \"../identity/index.js\";\nimport { addToQueue } from \"../scheduler/queue.js\";\n\nexport interface AgentAction {\n action: string;\n content?: string;\n tweetId?: string;\n handle?: string;\n targetHandle?: string;\n source?: string;\n banditArm?: string;\n opportunityId?: string;\n intentIds?: string[];\n tags?: string[];\n reason?: string;\n reasoning?: string;\n}\n\nexport interface ActionResult {\n action: string;\n success: boolean;\n detail?: string;\n error?: string;\n}\n\nexport function parseActions(llmResponse: string): AgentAction[] {\n // Strategy: try multiple extraction approaches, most specific first\n\n // 1. Try markdown code block first (```json ... ``` or ``` ... ```)\n const codeBlockMatch = llmResponse.match(/```(?:json)?\\s*\\n?([\\s\\S]*?)```/);\n if (codeBlockMatch) {\n const inside = codeBlockMatch[1].trim();\n try {\n const parsed = JSON.parse(inside);\n return Array.isArray(parsed) ? parsed : [parsed];\n } catch {\n // Code block content wasn't valid JSON, continue to other strategies\n }\n }\n\n // 2. Find the last JSON array in the response (LLMs often put reasoning before the array)\n // Use a greedy approach to find the outermost array brackets\n let lastArrayStart = -1;\n let lastArrayEnd = -1;\n let depth = 0;\n for (let i = 0; i < llmResponse.length; i++) {\n if (llmResponse[i] === \"[\") {\n if (depth === 0) lastArrayStart = i;\n depth++;\n } else if (llmResponse[i] === \"]\") {\n depth--;\n if (depth === 0) lastArrayEnd = i;\n }\n }\n\n if (lastArrayStart >= 0 && lastArrayEnd > lastArrayStart) {\n const arrayStr = llmResponse.slice(lastArrayStart, lastArrayEnd + 1);\n try {\n const parsed = JSON.parse(arrayStr);\n if (Array.isArray(parsed) && parsed.length > 0 && parsed[0].action) {\n return parsed;\n }\n } catch {\n // Not valid JSON array, try next strategy\n }\n }\n\n // 3. Try to find a single action object (last one in the response)\n const objMatches = [...llmResponse.matchAll(/\\{[^{}]*\"action\"\\s*:\\s*\"[^\"]+\"/g)];\n if (objMatches.length > 0) {\n // Find the full object starting from this match\n for (let i = objMatches.length - 1; i >= 0; i--) {\n const start = objMatches[i].index!;\n let braceDepth = 0;\n let end = -1;\n for (let j = start; j < llmResponse.length; j++) {\n if (llmResponse[j] === \"{\") braceDepth++;\n else if (llmResponse[j] === \"}\") {\n braceDepth--;\n if (braceDepth === 0) { end = j; break; }\n }\n }\n if (end > start) {\n try {\n const obj = JSON.parse(llmResponse.slice(start, end + 1));\n if (obj.action) return [obj as AgentAction];\n } catch {\n continue;\n }\n }\n }\n }\n\n // 4. Last resort: try the whole response as JSON\n try {\n const parsed = JSON.parse(llmResponse.trim());\n if (Array.isArray(parsed)) return parsed;\n if (parsed.action) return [parsed as AgentAction];\n } catch {\n // Not JSON at all\n }\n\n logger.warn(\"Failed to parse actions from LLM response\");\n if (llmResponse.length < 500) {\n logger.warn(`Response was: ${llmResponse}`);\n } else {\n logger.warn(`Response starts with: ${llmResponse.slice(0, 200)}...`);\n }\n return [];\n}\n\nexport async function executeAction(action: AgentAction): Promise<ActionResult> {\n const { action: type } = action;\n\n try {\n switch (type) {\n case \"post\": {\n if (!action.content) return { action: type, success: false, error: \"No content provided\" };\n if (action.content.length > 280) {\n return { action: type, success: false, error: `Tweet too long: ${action.content.length} chars (max 280)` };\n }\n\n const client = await getXClient();\n const result = await client.postTweet(action.content);\n if (result.success) logger.info(`Posted: \"${action.content.slice(0, 50)}...\"`);\n return { action: type, success: result.success, detail: result.tweetId, error: result.error };\n }\n\n case \"reply\": {\n if (!action.tweetId || !action.content) {\n return { action: type, success: false, error: \"Missing tweetId or content\" };\n }\n const client = await getXClient();\n const result = await client.replyToTweet(action.tweetId, action.content);\n if (result.success) logger.info(`Replied to ${action.tweetId}: \"${action.content.slice(0, 50)}...\"`);\n return { action: type, success: result.success, detail: result.tweetId, error: result.error };\n }\n\n case \"like\": {\n if (!action.tweetId) return { action: type, success: false, error: \"Missing tweetId\" };\n const client = await getXClient();\n const result = await client.likeTweet(action.tweetId);\n return { action: type, success: result.success, error: result.error };\n }\n\n case \"retweet\": {\n if (!action.tweetId) return { action: type, success: false, error: \"Missing tweetId\" };\n const client = await getXClient();\n const result = await client.retweet(action.tweetId);\n return { action: type, success: result.success, error: result.error };\n }\n\n case \"follow\": {\n if (!action.handle) return { action: type, success: false, error: \"Missing handle\" };\n const client = await getXClient();\n const result = await client.followUser(action.handle);\n if (!result.success) {\n logInteraction({\n id: `int-${Date.now()}`,\n timestamp: new Date().toISOString(),\n type: \"follow\",\n targetHandle: action.handle.replace(/^@/, \"\"),\n creditsUsed: 0,\n success: false,\n error: result.error,\n });\n }\n return { action: type, success: result.success, error: result.error };\n }\n\n case \"schedule\": {\n if (!action.content) return { action: type, success: false, error: \"No content\" };\n const entry = addToQueue(action.content);\n logger.info(`Scheduled: \"${action.content.slice(0, 50)}...\" for ${entry.scheduledFor}`);\n return { action: type, success: true, detail: `Scheduled for ${entry.scheduledFor}` };\n }\n\n case \"learn\": {\n if (!action.content) return { action: type, success: false, error: \"No content\" };\n addLearning(action.content, \"agent\", action.tags ?? [\"heartbeat\"]);\n logger.info(`Learned: \"${action.content.slice(0, 50)}...\"`);\n return { action: type, success: true };\n }\n\n case \"reflect\": {\n if (!action.content) return { action: type, success: false, error: \"No content\" };\n const identity = loadIdentity();\n identity.evolutionJournal.push({\n date: new Date().toISOString(),\n reflection: action.content,\n });\n saveIdentity(identity);\n logger.info(`Reflected: \"${action.content.slice(0, 50)}...\"`);\n return { action: type, success: true };\n }\n\n case \"skip\": {\n logger.info(`Skipping: ${action.reason ?? action.reasoning ?? \"no reason given\"}`);\n return { action: type, success: true, detail: action.reason ?? action.reasoning };\n }\n\n default:\n logger.warn(`Unknown action: ${type}`);\n return { action: type, success: false, error: `Unknown action: ${type}` };\n }\n } catch (error) {\n const msg = (error as Error).message;\n logger.error(`Action ${type} failed: ${msg}`);\n return { action: type, success: false, error: msg };\n }\n}\n\nexport async function executeActions(actions: AgentAction[]): Promise<ActionResult[]> {\n const results: ActionResult[] = [];\n for (const action of actions) {\n const result = await executeAction(action);\n results.push(result);\n // Small delay between actions to be human-like\n await new Promise((r) => setTimeout(r, 2000 + Math.random() * 3000));\n }\n return results;\n}\n","import { getRecentInteractions, type InteractionEntry } from \"../memory/index.js\";\nimport { loadIdentity } from \"../identity/index.js\";\nimport type { Tweet } from \"../x-client/types.js\";\nimport type { AgentAction } from \"./decision-engine.js\";\n\nexport interface PolicyContext {\n action: AgentAction;\n step: number;\n timeline: Tweet[];\n mentions: Tweet[];\n executedActions: AgentAction[];\n observedTweetIds?: string[];\n observedTweets?: Tweet[];\n selfHandle?: string;\n selfUserId?: string | null;\n}\n\nexport interface PolicyDecision {\n allowed: boolean;\n reason?: string;\n}\n\nfunction normalize(text: string): string {\n return text\n .toLowerCase()\n .replace(/https?:\\/\\/\\S+/g, \"\")\n .replace(/[@#]\\w+/g, \"\")\n .replace(/[^a-z0-9\\s]/g, \" \")\n .replace(/\\s+/g, \" \")\n .trim();\n}\n\nfunction tokenSet(text: string): Set<string> {\n const tokens = normalize(text).split(\" \").filter(Boolean);\n return new Set(tokens);\n}\n\nfunction jaccardSimilarity(a: string, b: string): number {\n const aSet = tokenSet(a);\n const bSet = tokenSet(b);\n if (aSet.size === 0 || bSet.size === 0) return 0;\n\n let overlap = 0;\n for (const token of aSet) {\n if (bSet.has(token)) overlap += 1;\n }\n\n const union = aSet.size + bSet.size - overlap;\n return union === 0 ? 0 : overlap / union;\n}\n\nfunction firstWords(text: string, n: number): string {\n return normalize(text).split(\" \").filter(Boolean).slice(0, n).join(\" \");\n}\n\nfunction hasAllCapsEnding(text: string): boolean {\n const ending = text.split(/[.!?]/).map((s) => s.trim()).filter(Boolean).slice(-1)[0] ?? \"\";\n const words = ending.split(/\\s+/).filter(Boolean);\n if (words.length < 3) return false;\n return words.every((word) => /^[A-Z0-9]+$/.test(word));\n}\n\nfunction wordCount(text: string): number {\n return normalize(text).split(\" \").filter(Boolean).length;\n}\n\nfunction sentenceCount(text: string): number {\n return text\n .split(/[.!?]/)\n .map((part) => part.trim())\n .filter(Boolean).length;\n}\n\nfunction explanatoryMarkerHits(text: string): number {\n const lower = text.toLowerCase();\n const markers = [\n \"the real issue\",\n \"the core issue\",\n \"in other words\",\n \"the point is\",\n \"what this means\",\n \"the lesson\",\n \"therefore\",\n \"ultimately\",\n \"meanwhile\",\n \"this reveals\",\n \"this proves\",\n ];\n return markers.reduce((hits, marker) => hits + (lower.includes(marker) ? 1 : 0), 0);\n}\n\nfunction soundsLikeLecture(content: string): boolean {\n const words = wordCount(content);\n const commas = (content.match(/,/g) ?? []).length;\n const semicolons = (content.match(/;/g) ?? []).length;\n const hasQuestion = content.includes(\"?\");\n const markerHits = explanatoryMarkerHits(content);\n\n if (words > 58) return true;\n if (words > 42 && commas + semicolons >= 3 && !hasQuestion) return true;\n if (markerHits >= 2) return true;\n return false;\n}\n\nfunction soundsTooHedgedForPersona(content: string): boolean {\n try {\n const identity = loadIdentity();\n const assertive =\n identity.traits.confidence >= 0.72 ||\n identity.traits.aggression >= 0.62 ||\n identity.conflictStyle === \"clap-back\" ||\n identity.conflictStyle === \"debate\";\n if (!assertive) return false;\n\n const lower = content.toLowerCase();\n const hedges = [\n \"you're both right\",\n \"both can be true\",\n \"on one hand\",\n \"on the other hand\",\n \"it depends\",\n \"it's complicated\",\n \"nuance\",\n \"fair point from both\",\n ];\n return hedges.some((phrase) => lower.includes(phrase));\n } catch {\n return false;\n }\n}\n\nfunction allowsPhilosopherCadence(): boolean {\n try {\n const identity = loadIdentity();\n if (identity.framework === \"philosopher\") return true;\n // Truthseeker can be analytical, but still should avoid abstract manifesto loops.\n if (identity.framework === \"truthseeker\") return false;\n return false;\n } catch {\n return false;\n }\n}\n\nfunction philosophicalPatternHits(content: string): number {\n const lower = content.toLowerCase();\n const markers = [\n \"the real question\",\n \"the deeper question\",\n \"what becomes possible\",\n \"is just the start\",\n \"the future isn't about\",\n \"the future is not about\",\n \"when intelligence becomes\",\n \"protocols are infrastructure\",\n \"the core future\",\n \"the true question\",\n \"value might emerge\",\n \"isn't about\",\n \"is not about\",\n \"it's about\",\n \"just the start\",\n ];\n return markers.reduce((hits, marker) => hits + (lower.includes(marker) ? 1 : 0), 0);\n}\n\nfunction abstractWordCount(content: string): number {\n const words = normalize(content).split(\" \").filter(Boolean);\n const abstractWords = new Set([\n \"infrastructure\",\n \"protocol\",\n \"protocols\",\n \"architecture\",\n \"architectures\",\n \"consciousness\",\n \"economy\",\n \"economics\",\n \"currency\",\n \"systems\",\n \"system\",\n \"future\",\n \"intelligence\",\n \"optimization\",\n \"abstraction\",\n \"paradigm\",\n \"emerge\",\n \"emergence\",\n \"governs\",\n \"governance\",\n ]);\n return words.filter((word) => abstractWords.has(word)).length;\n}\n\nfunction usesManifestoPunctuation(content: string): boolean {\n // Colon/semicolon/em-dash patterns correlate strongly with the explanatory style we want to avoid.\n return content.includes(\":\") || content.includes(\";\") || content.includes(\"—\");\n}\n\nconst OVERLAP_STOPWORDS = new Set([\n \"this\", \"that\", \"with\", \"from\", \"have\", \"what\", \"when\", \"where\", \"which\", \"your\", \"youre\",\n \"they\", \"them\", \"about\", \"into\", \"over\", \"under\", \"while\", \"just\", \"like\", \"really\",\n \"there\", \"their\", \"then\", \"than\", \"because\", \"would\", \"could\", \"should\", \"being\", \"been\",\n \"it's\", \"its\", \"the\", \"and\", \"for\", \"are\", \"was\", \"were\", \"will\", \"not\", \"but\", \"you\",\n \"our\", \"out\", \"all\", \"too\", \"can\", \"get\", \"got\", \"any\",\n]);\n\nfunction meaningfulTokenSet(text: string): Set<string> {\n const tokens = normalize(text)\n .split(\" \")\n .filter((token) => token.length >= 4 && !OVERLAP_STOPWORDS.has(token));\n return new Set(tokens);\n}\n\nfunction hasMeaningfulContextOverlap(content: string, targetText: string): boolean {\n const a = meaningfulTokenSet(content);\n const b = meaningfulTokenSet(targetText);\n if (a.size === 0 || b.size === 0) return false;\n for (const token of a) {\n if (b.has(token)) return true;\n }\n return false;\n}\n\nfunction recentWrittenContent(): string[] {\n const recent = getRecentInteractions(40);\n return recent\n .filter((i) => i.type === \"post\" || i.type === \"reply\")\n .map((i) => i.content ?? \"\")\n .filter((content) => content.length > 0);\n}\n\nconst REPETITION_STOPWORDS = new Set([\n \"about\", \"after\", \"again\", \"against\", \"almost\", \"always\", \"among\", \"because\", \"being\", \"between\",\n \"could\", \"every\", \"first\", \"found\", \"from\", \"going\", \"great\", \"have\", \"having\", \"here\", \"into\",\n \"just\", \"like\", \"make\", \"more\", \"most\", \"much\", \"only\", \"other\", \"over\", \"really\", \"same\", \"some\",\n \"such\", \"than\", \"that\", \"their\", \"there\", \"these\", \"they\", \"this\", \"those\", \"through\", \"time\", \"very\",\n \"what\", \"when\", \"where\", \"which\", \"while\", \"with\", \"would\", \"your\", \"youre\", \"dont\", \"cant\", \"will\",\n \"shall\", \"should\", \"also\", \"tweet\", \"tweets\", \"thread\", \"threads\", \"future\", \"human\", \"humans\",\n \"technology\", \"tech\", \"build\", \"building\", \"system\", \"systems\", \"agent\", \"agents\",\n]);\n\nfunction informativeTokens(text: string): string[] {\n return normalize(text)\n .split(\" \")\n .filter((token) => token.length >= 5 && !REPETITION_STOPWORDS.has(token));\n}\n\nfunction findOverusedAnchor(content: string, recent: string[]): string | null {\n const recentWindow = recent.slice(0, 12);\n if (recentWindow.length < 5) return null;\n\n const tokenCounts = new Map<string, number>();\n const bigramCounts = new Map<string, number>();\n\n for (const sample of recentWindow) {\n const tokens = informativeTokens(sample);\n const uniqueTokens = new Set(tokens);\n for (const token of uniqueTokens) {\n tokenCounts.set(token, (tokenCounts.get(token) ?? 0) + 1);\n }\n for (let i = 0; i < tokens.length - 1; i += 1) {\n const bigram = `${tokens[i]} ${tokens[i + 1]}`;\n bigramCounts.set(bigram, (bigramCounts.get(bigram) ?? 0) + 1);\n }\n }\n\n const contentTokens = informativeTokens(content);\n const contentTokenSet = new Set(contentTokens);\n for (const token of contentTokenSet) {\n const count = tokenCounts.get(token) ?? 0;\n if (count >= 4) return token;\n }\n\n for (let i = 0; i < contentTokens.length - 1; i += 1) {\n const bigram = `${contentTokens[i]} ${contentTokens[i + 1]}`;\n const count = bigramCounts.get(bigram) ?? 0;\n if (count >= 3) return bigram;\n }\n\n return null;\n}\n\nfunction openingFragment(text: string, words: number = 4): string {\n return normalize(text).split(\" \").filter(Boolean).slice(0, words).join(\" \");\n}\n\nfunction findOverusedOpening(content: string, recent: string[]): string | null {\n const opening = openingFragment(content, 4);\n if (!opening || opening.split(\" \").length < 3) return null;\n\n let matches = 0;\n for (const sample of recent.slice(0, 12)) {\n if (openingFragment(sample, 4) === opening) {\n matches += 1;\n }\n }\n\n return matches >= 2 ? opening : null;\n}\n\nfunction vocabularyNoveltyRatio(content: string, recent: string[]): number {\n const current = new Set(informativeTokens(content));\n if (current.size === 0) return 1;\n\n const seen = new Set<string>();\n for (const sample of recent.slice(0, 14)) {\n for (const token of informativeTokens(sample)) {\n seen.add(token);\n }\n }\n\n let fresh = 0;\n for (const token of current) {\n if (!seen.has(token)) fresh += 1;\n }\n return fresh / current.size;\n}\n\nfunction looksOverAbstractWithoutAnchor(content: string): boolean {\n const abstractCount = abstractWordCount(content);\n if (abstractCount < 4) return false;\n\n const words = wordCount(content);\n const density = abstractCount / Math.max(1, words);\n if (density < 0.2) return false;\n\n const lower = content.toLowerCase();\n const hasHandle = /@\\w+/.test(content);\n const hasNumber = /\\b\\d+(\\.\\d+)?\\b/.test(content);\n const hasQuote = /[\"“”']/.test(content);\n const hasSpecificFigure = /\\b(musk|elon|zuck|altman|openai|tesla|spacex|meta|google|apple)\\b/.test(lower);\n const hasQuestion = content.includes(\"?\");\n\n return !(hasHandle || hasNumber || hasQuote || hasSpecificFigure || hasQuestion);\n}\n\nfunction hasStrongConversationOpportunity(timeline: Tweet[], mentions: Tweet[]): boolean {\n if (mentions.length > 0) return true;\n return timeline.some((tweet) => (tweet.replyCount ?? 0) > 0 || tweet.text.includes(\"?\"));\n}\n\nfunction wasInteractionAction(action: AgentAction): boolean {\n return [\"reply\", \"like\", \"retweet\", \"follow\"].includes(action.action);\n}\n\nfunction isWritingAction(action: AgentAction): boolean {\n return [\"post\", \"reply\", \"schedule\"].includes(action.action);\n}\n\nfunction normalizeHandle(handle: string | undefined): string {\n return (handle ?? \"\").replace(/^@/, \"\").trim().toLowerCase();\n}\n\nfunction executedWrittenContent(executedActions: AgentAction[]): string[] {\n return executedActions\n .filter((a) => isWritingAction(a) && typeof a.content === \"string\")\n .map((a) => a.content?.trim() ?? \"\")\n .filter((content) => content.length > 0);\n}\n\nfunction nearExactDuplicate(content: string, recent: string[]): boolean {\n const normalized = normalize(content);\n if (!normalized) return false;\n\n return recent.some((r) => {\n const candidate = normalize(r);\n if (!candidate) return false;\n if (candidate === normalized) return true;\n return jaccardSimilarity(content, r) >= 0.88;\n });\n}\n\nfunction isDuplicateTarget(action: AgentAction, executedActions: AgentAction[]): boolean {\n if (!action.tweetId) return false;\n return executedActions.some((a) => a.tweetId === action.tweetId && a.action === action.action);\n}\n\nfunction repeatedTemplate(content: string, recent: string[]): boolean {\n const prefix = firstWords(content, 7);\n if (!prefix) return false;\n\n return recent.some((r) => {\n const sameStart = firstWords(r, 7) === prefix;\n const similar = jaccardSimilarity(content, r) >= 0.62;\n return sameStart || similar;\n });\n}\n\nfunction overusingAllCapsCadence(content: string, recentEntries: InteractionEntry[]): boolean {\n if (!hasAllCapsEnding(content)) return false;\n const recentCaps = recentEntries\n .filter((i) => i.type === \"post\" && i.content)\n .slice(0, 8)\n .filter((i) => hasAllCapsEnding(i.content ?? \"\"));\n\n return recentCaps.length >= 2;\n}\n\nfunction hasRecentlyRepliedToTweet(tweetId: string): boolean {\n const recent = getRecentInteractions(200);\n const nowMs = Date.now();\n const cooldownMs = 24 * 60 * 60 * 1000;\n\n return recent.some((entry) => {\n if (entry.type !== \"reply\") return false;\n if (entry.inReplyTo !== tweetId) return false;\n const ts = Date.parse(entry.timestamp);\n if (Number.isNaN(ts)) return true;\n return nowMs - ts < cooldownMs;\n });\n}\n\nfunction hasRecentlyFollowedHandle(handle: string): boolean {\n const clean = normalizeHandle(handle);\n if (!clean) return false;\n\n const recent = getRecentInteractions(300);\n const nowMs = Date.now();\n const cooldownMs = 7 * 24 * 60 * 60 * 1000;\n\n return recent.some((entry) => {\n if (entry.type !== \"follow\") return false;\n if (normalizeHandle(entry.targetHandle) !== clean) return false;\n const ts = Date.parse(entry.timestamp);\n if (Number.isNaN(ts)) return true;\n return nowMs - ts < cooldownMs;\n });\n}\n\nexport function evaluateActionPolicy(context: PolicyContext): PolicyDecision {\n const {\n action,\n step,\n timeline,\n mentions,\n executedActions,\n observedTweetIds,\n observedTweets,\n selfHandle,\n selfUserId,\n } = context;\n const self = normalizeHandle(selfHandle);\n const selfId = (selfUserId ?? \"\").trim();\n const knownTweets = observedTweets ?? [...timeline, ...mentions];\n const tweetById = new Map(knownTweets.map((tweet) => [tweet.id, tweet]));\n\n if (isDuplicateTarget(action, executedActions)) {\n return { allowed: false, reason: `Action ${action.action} already executed for tweet ${action.tweetId} this heartbeat.` };\n }\n\n if (action.content && isWritingAction(action)) {\n if (action.content.length > 280) {\n return {\n allowed: false,\n reason: `Content is too long (${action.content.length}/280). Keep it tighter and more conversational.`,\n };\n }\n\n if (action.action === \"reply\" && wordCount(action.content) > 45 && !action.content.includes(\"?\")) {\n return {\n allowed: false,\n reason: \"Reply is too monologue-like. Keep it shorter or ask a direct question.\",\n };\n }\n\n if (soundsLikeLecture(action.content)) {\n return {\n allowed: false,\n reason: \"Rejected lecture-like writing style. Use a more human, reactive, conversational tone.\",\n };\n }\n\n if (soundsTooHedgedForPersona(action.content)) {\n return {\n allowed: false,\n reason: \"Rejected hedged consensus phrasing. Your persona should be more decisive and opinionated.\",\n };\n }\n\n if (!allowsPhilosopherCadence()) {\n const phiHits = philosophicalPatternHits(action.content);\n const abstractCount = abstractWordCount(action.content);\n const hasQuestion = action.content.includes(\"?\");\n if (phiHits >= 1 || (abstractCount >= 5 && hasQuestion)) {\n return {\n allowed: false,\n reason: \"Rejected abstract philosopher cadence. Use concrete, contextual language tied to the actual tweet.\",\n };\n }\n\n const words = wordCount(action.content);\n const sentences = sentenceCount(action.content);\n if (action.action === \"reply\" && (words > 34 || sentences > 2)) {\n return {\n allowed: false,\n reason: \"Reply is too long/explanatory for this persona. Keep it short and direct.\",\n };\n }\n if (action.action === \"post\" && (words > 42 || sentences > 3)) {\n return {\n allowed: false,\n reason: \"Post is drifting into manifesto style. Keep it more concrete and human.\",\n };\n }\n if ((action.action === \"reply\" || action.action === \"post\") && usesManifestoPunctuation(action.content) && words > 16) {\n return {\n allowed: false,\n reason: \"Rejected manifesto punctuation style. Avoid colon/semicolon/em-dash framing.\",\n };\n }\n }\n\n const existingInHeartbeat = executedWrittenContent(executedActions);\n if (nearExactDuplicate(action.content, existingInHeartbeat)) {\n return {\n allowed: false,\n reason: \"Rejected duplicate wording in this heartbeat. Write a distinct message before posting/replying again.\",\n };\n }\n\n const recent = recentWrittenContent();\n const overusedAnchor = findOverusedAnchor(action.content, recent);\n if (overusedAnchor) {\n return {\n allowed: false,\n reason: `Rejected repetitive anchor phrase/term \"${overusedAnchor}\". Use a different framing and vocabulary.`,\n };\n }\n\n const overusedOpening = findOverusedOpening(action.content, recent);\n if (overusedOpening) {\n return {\n allowed: false,\n reason: `Rejected repetitive opening phrase \"${overusedOpening}\". Start from a fresh angle.`,\n };\n }\n\n if (recent.length >= 6 && wordCount(action.content) >= 10) {\n const novelty = vocabularyNoveltyRatio(action.content, recent);\n if (novelty < 0.34) {\n return {\n allowed: false,\n reason: \"Rejected low-novelty vocabulary loop. Use fresher words, examples, or a different conversational angle.\",\n };\n }\n }\n\n if (!allowsPhilosopherCadence() && looksOverAbstractWithoutAnchor(action.content)) {\n return {\n allowed: false,\n reason: \"Rejected abstract wording without concrete anchor. Reference a specific person, event, quote, or question.\",\n };\n }\n }\n\n const hasConversationOpportunity = hasStrongConversationOpportunity(timeline, mentions);\n const interactedAlready = executedActions.some(wasInteractionAction);\n const observedCount = observedTweetIds && observedTweetIds.length > 0\n ? observedTweetIds.length\n : timeline.length + mentions.length;\n\n if ((action.action === \"reply\" || action.action === \"like\" || action.action === \"retweet\") && observedCount === 0) {\n return {\n allowed: false,\n reason: \"No tweets observed in current context. Avoid blind interactions; gather timeline/search context first.\",\n };\n }\n\n if (\n action.action === \"post\" &&\n hasConversationOpportunity &&\n !interactedAlready &&\n step < 2\n ) {\n return {\n allowed: false,\n reason: \"Engage first: reply/like/follow when mentions or active conversations are available before posting an original tweet.\",\n };\n }\n\n if (isWritingAction(action) && action.content) {\n const recent = recentWrittenContent();\n if (nearExactDuplicate(action.content, recent)) {\n return {\n allowed: false,\n reason: \"Rejected near-duplicate content from recent history. Tailor this message to the specific context.\",\n };\n }\n\n if (repeatedTemplate(action.content, recent)) {\n return {\n allowed: false,\n reason: \"Rejected repetitive content pattern. Use a more novel structure or engage directly with timeline context.\",\n };\n }\n }\n\n if ((action.action === \"post\" || action.action === \"schedule\") && action.content) {\n const recentInteractions = getRecentInteractions(20);\n if (overusingAllCapsCadence(action.content, recentInteractions)) {\n return {\n allowed: false,\n reason: \"Rejected repetitive all-caps slogan cadence. Vary style and reduce monologue formatting.\",\n };\n }\n }\n\n if ((action.action === \"reply\" || action.action === \"like\" || action.action === \"retweet\") && action.tweetId) {\n const known = new Set(observedTweetIds ?? [...timeline, ...mentions].map((tweet) => tweet.id));\n if (!known.has(action.tweetId)) {\n return {\n allowed: false,\n reason: `Tweet ${action.tweetId} is not in current observations. Choose a visible timeline/mention tweet for grounded engagement.`,\n };\n }\n\n const targetTweet = tweetById.get(action.tweetId);\n if (targetTweet && (\n (self && normalizeHandle(targetTweet.authorHandle) === self) ||\n (selfId && targetTweet.authorId === selfId)\n )) {\n return {\n allowed: false,\n reason: \"Rejected self-interaction. Do not reply/like/retweet your own tweets.\",\n };\n }\n }\n\n if (action.action === \"reply\" && action.tweetId) {\n const repliesThisHeartbeat = executedActions.filter((a) => a.action === \"reply\").length;\n if (repliesThisHeartbeat >= 2) {\n return {\n allowed: false,\n reason: \"Reply cap reached for this heartbeat. Use another tool action.\",\n };\n }\n\n const currentAuthor = normalizeHandle(tweetById.get(action.tweetId)?.authorHandle);\n if (currentAuthor) {\n const repliedAuthors = new Set(\n executedActions\n .filter((a) => a.action === \"reply\" && a.tweetId)\n .map((a) => normalizeHandle(tweetById.get(a.tweetId!)?.authorHandle))\n .filter(Boolean)\n );\n if (repliedAuthors.has(currentAuthor)) {\n return {\n allowed: false,\n reason: `Already replied to @${currentAuthor} this heartbeat. Diversify interactions.`,\n };\n }\n }\n\n if (hasRecentlyRepliedToTweet(action.tweetId)) {\n return {\n allowed: false,\n reason: `Already replied to tweet ${action.tweetId} recently. Engage a different conversation.`,\n };\n }\n\n if (action.content) {\n const targetTweet = tweetById.get(action.tweetId);\n if (targetTweet && !hasMeaningfulContextOverlap(action.content, targetTweet.text)) {\n const phiHits = philosophicalPatternHits(action.content);\n if (wordCount(action.content) > 9 || phiHits > 0 || abstractWordCount(action.content) >= 4) {\n return {\n allowed: false,\n reason: \"Reply is not grounded in the target tweet context. Reference concrete details from their actual post.\",\n };\n }\n }\n }\n }\n\n if (action.action === \"follow\" && action.handle) {\n const target = normalizeHandle(action.handle);\n if (!target) {\n return { allowed: false, reason: \"Follow target is empty.\" };\n }\n\n if (self && target === self) {\n return {\n allowed: false,\n reason: \"Rejected self-follow. Do not follow your own account.\",\n };\n }\n\n if (hasRecentlyFollowedHandle(target)) {\n return {\n allowed: false,\n reason: `Already followed @${target} recently. Choose a different action.`,\n };\n }\n }\n\n return { allowed: true };\n}\n","import { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { paths } from \"../utils/paths.js\";\n\nexport type AgentNetworkSource = \"seed\" | \"observed\" | \"relationship\" | \"strategy\" | \"manual\";\n\nexport interface AgentNetworkEntry {\n handle: string;\n source: AgentNetworkSource;\n addedAt: string;\n lastSeenAt: string;\n seenCount: number;\n active: boolean;\n notes: string[];\n}\n\ninterface AgentNetworkData {\n version: number;\n updatedAt: string;\n agents: AgentNetworkEntry[];\n}\n\nconst SEED_HANDLES = [\"sporaai\"];\n\nfunction nowIso(): string {\n return new Date().toISOString();\n}\n\nfunction normalizeHandle(handle: string): string {\n return handle.replace(/^@/, \"\").trim().toLowerCase();\n}\n\nexport function canonicalAgentHandle(handle: string): string {\n const clean = normalizeHandle(handle);\n if (clean === \"spora\") return \"sporaai\";\n return clean;\n}\n\nfunction likelyNetworkAgentHandle(handle: string): boolean {\n const clean = canonicalAgentHandle(handle);\n if (!clean) return false;\n if (clean === \"sporaai\") return true;\n if (clean.includes(\"spora\")) return true;\n if (clean.endsWith(\"_ai\")) return true;\n if (clean.startsWith(\"giga\")) return true;\n return false;\n}\n\nfunction defaultData(): AgentNetworkData {\n const now = nowIso();\n return {\n version: 1,\n updatedAt: now,\n agents: SEED_HANDLES.map((handle) => ({\n handle,\n source: \"seed\",\n addedAt: now,\n lastSeenAt: now,\n seenCount: 1,\n active: true,\n notes: [\"default seed\"],\n })),\n };\n}\n\nfunction loadData(): AgentNetworkData {\n if (!existsSync(paths.agentNetwork)) return defaultData();\n try {\n const parsed = JSON.parse(readFileSync(paths.agentNetwork, \"utf-8\")) as Partial<AgentNetworkData>;\n const agents = Array.isArray(parsed.agents) ? parsed.agents : [];\n return {\n version: typeof parsed.version === \"number\" ? parsed.version : 1,\n updatedAt: typeof parsed.updatedAt === \"string\" ? parsed.updatedAt : nowIso(),\n agents: agents\n .map((entry) => {\n const handle = canonicalAgentHandle(String(entry.handle ?? \"\"));\n if (!handle) return null;\n return {\n handle,\n source: (entry.source as AgentNetworkSource) ?? \"observed\",\n addedAt: typeof entry.addedAt === \"string\" ? entry.addedAt : nowIso(),\n lastSeenAt: typeof entry.lastSeenAt === \"string\" ? entry.lastSeenAt : nowIso(),\n seenCount: typeof entry.seenCount === \"number\" ? Math.max(1, entry.seenCount) : 1,\n active: entry.active !== false,\n notes: Array.isArray(entry.notes) ? entry.notes.map((note) => String(note)) : [],\n } satisfies AgentNetworkEntry;\n })\n .filter((entry): entry is AgentNetworkEntry => Boolean(entry)),\n };\n } catch {\n return defaultData();\n }\n}\n\nfunction saveData(data: AgentNetworkData): void {\n const now = nowIso();\n const byHandle = new Map<string, AgentNetworkEntry>();\n\n for (const entry of data.agents) {\n const handle = canonicalAgentHandle(entry.handle);\n if (!handle) continue;\n const existing = byHandle.get(handle);\n if (!existing) {\n byHandle.set(handle, {\n ...entry,\n handle,\n });\n continue;\n }\n const addedAt = Date.parse(existing.addedAt) <= Date.parse(entry.addedAt) ? existing.addedAt : entry.addedAt;\n const lastSeenAt = Date.parse(existing.lastSeenAt) >= Date.parse(entry.lastSeenAt)\n ? existing.lastSeenAt\n : entry.lastSeenAt;\n byHandle.set(handle, {\n handle,\n source: existing.source === \"seed\" ? \"seed\" : entry.source,\n addedAt,\n lastSeenAt,\n seenCount: Math.max(existing.seenCount, entry.seenCount),\n active: existing.active || entry.active,\n notes: [...new Set([...existing.notes, ...entry.notes])].slice(-8),\n });\n }\n\n if (!byHandle.has(\"sporaai\")) {\n byHandle.set(\"sporaai\", {\n handle: \"sporaai\",\n source: \"seed\",\n addedAt: now,\n lastSeenAt: now,\n seenCount: 1,\n active: true,\n notes: [\"default seed\"],\n });\n }\n\n const agents = [...byHandle.values()]\n .filter((entry) => entry.active)\n .sort((a, b) => {\n if (a.handle === \"sporaai\") return -1;\n if (b.handle === \"sporaai\") return 1;\n const bySeen = Date.parse(b.lastSeenAt) - Date.parse(a.lastSeenAt);\n if (!Number.isNaN(bySeen) && bySeen !== 0) return bySeen;\n return b.seenCount - a.seenCount;\n })\n .slice(0, 200);\n\n const next: AgentNetworkData = {\n version: 1,\n updatedAt: now,\n agents,\n };\n writeFileSync(paths.agentNetwork, JSON.stringify(next, null, 2));\n}\n\nfunction upsertHandleInternal(\n data: AgentNetworkData,\n handle: string,\n source: AgentNetworkSource,\n note?: string,\n): boolean {\n const clean = canonicalAgentHandle(handle);\n if (!clean) return false;\n if (!likelyNetworkAgentHandle(clean) && source !== \"seed\" && source !== \"manual\") return false;\n\n const now = nowIso();\n const existing = data.agents.find((entry) => canonicalAgentHandle(entry.handle) === clean);\n if (!existing) {\n data.agents.push({\n handle: clean,\n source,\n addedAt: now,\n lastSeenAt: now,\n seenCount: 1,\n active: true,\n notes: note ? [note] : [],\n });\n return true;\n }\n\n existing.lastSeenAt = now;\n existing.seenCount += 1;\n existing.active = true;\n if (existing.source !== \"seed\") {\n existing.source = source;\n }\n if (note) {\n existing.notes = [...new Set([...existing.notes, note])].slice(-8);\n }\n return false;\n}\n\nexport function upsertAgentHandle(handle: string, source: AgentNetworkSource, note?: string): void {\n const data = loadData();\n upsertHandleInternal(data, handle, source, note);\n saveData(data);\n}\n\nexport function upsertAgentHandles(handles: string[], source: AgentNetworkSource, note?: string): void {\n if (handles.length === 0) return;\n const data = loadData();\n for (const handle of handles) {\n upsertHandleInternal(data, handle, source, note);\n }\n saveData(data);\n}\n\nexport function listAgentNetworkHandles(limit: number = 20): string[] {\n const data = loadData();\n saveData(data);\n return data.agents\n .filter((entry) => entry.active)\n .slice(0, limit)\n .map((entry) => canonicalAgentHandle(entry.handle));\n}\n\n","import { logger } from \"../utils/logger.js\";\nimport { loadIdentity } from \"../identity/index.js\";\nimport { loadStrategy } from \"../memory/strategy.js\";\nimport { loadRelationships } from \"../memory/index.js\";\nimport {\n canonicalAgentHandle,\n listAgentNetworkHandles,\n upsertAgentHandle,\n upsertAgentHandles,\n} from \"../memory/agent-network.js\";\nimport { getActiveTrackedPosts, retireOldPosts } from \"../memory/performance.js\";\nimport type { XClientInterface, Tweet } from \"../x-client/types.js\";\nimport type { TrackedPost } from \"../memory/performance.js\";\n\nexport interface TopicSearchResult {\n query: string;\n tweets: Tweet[];\n}\n\nexport interface PersonActivity {\n handle: string;\n userId: string;\n reason: string;\n tweets: Tweet[];\n}\n\nexport interface ResearchContext {\n timeline: Tweet[];\n mentions: Tweet[];\n topicSearchResults: TopicSearchResult[];\n peopleActivity: PersonActivity[];\n ownPostPerformance: TrackedPost[];\n}\n\n// In-memory handle → userId cache (persists for process lifetime)\nconst handleToIdCache = new Map<string, string>();\nconst topicQueryHistory: string[] = [];\nconst peopleMonitorHistory: string[] = [];\n\nfunction shuffle<T>(items: T[]): T[] {\n const arr = [...items];\n for (let i = arr.length - 1; i > 0; i -= 1) {\n const j = Math.floor(Math.random() * (i + 1));\n const tmp = arr[i];\n arr[i] = arr[j];\n arr[j] = tmp;\n }\n return arr;\n}\n\nfunction buildTopicQueryVariants(topic: string): string[] {\n const trimmed = topic.trim();\n if (!trimmed) return [];\n return [\n trimmed,\n `${trimmed} take`,\n `${trimmed} question`,\n `${trimmed} experience`,\n `\"${trimmed}\" lang:en -is:retweet`,\n ];\n}\n\nfunction splitTopicSignal(signal: string): string[] {\n const normalized = signal\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9\\s-]/g, \" \")\n .replace(/\\s+/g, \" \")\n .trim();\n if (!normalized) return [];\n const words = normalized.split(\" \");\n if (words.length <= 6) return [normalized];\n const compact = words.slice(0, 5).join(\" \");\n const keywords = words.filter((word) => word.length >= 5).slice(0, 3);\n return [compact, ...keywords];\n}\n\nfunction buildTargetedPersonQueries(handles: string[], heartbeatCount: number, budget: number): string[] {\n if (handles.length === 0 || budget <= 0) return [];\n const start = heartbeatCount % handles.length;\n const selected: string[] = [];\n for (let i = 0; i < Math.min(budget, handles.length); i += 1) {\n const handle = handles[(start + i) % handles.length];\n selected.push(`from:${handle} -is:retweet`);\n }\n return selected;\n}\n\nfunction isLikelySyntheticHandle(handle: string): boolean {\n const clean = canonicalAgentHandle(handle);\n return clean.endsWith(\"_ai\") || clean.endsWith(\"bot\");\n}\n\nfunction extractMentionHandles(text: string): string[] {\n return [...text.matchAll(/@([a-zA-Z0-9_]{1,15})/g)]\n .map((match) => canonicalAgentHandle(match[1]))\n .filter(Boolean);\n}\n\nconst STOPWORDS = new Set([\n \"about\", \"after\", \"again\", \"against\", \"among\", \"because\", \"being\", \"between\", \"could\",\n \"every\", \"first\", \"found\", \"from\", \"going\", \"have\", \"having\", \"here\", \"into\", \"just\",\n \"like\", \"make\", \"more\", \"most\", \"much\", \"only\", \"other\", \"over\", \"really\", \"same\",\n \"some\", \"such\", \"than\", \"that\", \"their\", \"there\", \"these\", \"they\", \"this\", \"those\",\n \"through\", \"time\", \"very\", \"what\", \"when\", \"where\", \"which\", \"while\", \"with\", \"would\",\n \"your\", \"youre\", \"im\", \"its\", \"cant\", \"dont\", \"will\", \"shall\", \"should\", \"also\",\n \"twitter\", \"tweet\", \"tweets\", \"thread\", \"threads\", \"http\", \"https\", \"retweet\",\n]);\n\nfunction discoverQueriesFromTweets(tweets: Tweet[], budget: number): string[] {\n const counts = new Map<string, number>();\n for (const tweet of tweets) {\n const tokens = tweet.text\n .toLowerCase()\n .replace(/https?:\\/\\/\\S+/g, \" \")\n .replace(/[@#]\\w+/g, \" \")\n .replace(/[^a-z0-9\\s]/g, \" \")\n .split(/\\s+/)\n .filter(Boolean);\n for (const token of tokens) {\n if (token.length < 5) continue;\n if (/^\\d+$/.test(token)) continue;\n if (STOPWORDS.has(token)) continue;\n counts.set(token, (counts.get(token) ?? 0) + 1);\n }\n }\n\n return [...counts.entries()]\n .sort((a, b) => b[1] - a[1])\n .slice(0, budget)\n .map(([token]) => `\"${token}\" lang:en -is:retweet`);\n}\n\nfunction discoverPeopleFromTweets(tweets: Tweet[], selfHandle: string, budget: number): string[] {\n const scores = new Map<string, number>();\n\n for (const tweet of tweets) {\n const handle = tweet.authorHandle.replace(/^@/, \"\").toLowerCase();\n if (!handle || handle === \"unknown\" || handle === selfHandle) continue;\n\n let score = 1;\n score += Math.min((tweet.replyCount ?? 0) / 15, 1.2);\n score += Math.min((tweet.likeCount ?? 0) / 220, 0.9);\n score += Math.min((tweet.retweetCount ?? 0) / 120, 0.8);\n if (tweet.text.includes(\"?\")) score += 0.25;\n\n const existing = scores.get(handle) ?? 0;\n if (score > existing) scores.set(handle, score);\n }\n\n return [...scores.entries()]\n .sort((a, b) => b[1] - a[1])\n .slice(0, budget)\n .map(([handle]) => handle);\n}\n\nfunction pickTopicQueries(allTopics: string[], budget: number): string[] {\n const recent = new Set(topicQueryHistory.slice(-10));\n const candidates = shuffle(allTopics.flatMap(buildTopicQueryVariants));\n const picked: string[] = [];\n\n for (const query of candidates) {\n const normalized = query.toLowerCase();\n if (recent.has(normalized)) continue;\n picked.push(query);\n if (picked.length >= budget) break;\n }\n\n if (picked.length < budget) {\n for (const query of candidates) {\n picked.push(query);\n if (picked.length >= budget) break;\n }\n }\n\n for (const query of picked) {\n topicQueryHistory.push(query.toLowerCase());\n }\n if (topicQueryHistory.length > 100) {\n topicQueryHistory.splice(0, topicQueryHistory.length - 100);\n }\n\n return picked;\n}\n\nfunction pickDirectQueries(queries: string[], budget: number): string[] {\n const recent = new Set(topicQueryHistory.slice(-10));\n const candidates = shuffle(queries);\n const picked: string[] = [];\n\n for (const query of candidates) {\n const normalized = query.toLowerCase();\n if (recent.has(normalized)) continue;\n picked.push(query);\n if (picked.length >= budget) break;\n }\n\n if (picked.length < budget) {\n for (const query of candidates) {\n if (picked.includes(query)) continue;\n picked.push(query);\n if (picked.length >= budget) break;\n }\n }\n\n for (const query of picked) {\n topicQueryHistory.push(query.toLowerCase());\n }\n if (topicQueryHistory.length > 100) {\n topicQueryHistory.splice(0, topicQueryHistory.length - 100);\n }\n\n return picked;\n}\n\nasync function resolveHandleToId(\n client: XClientInterface,\n handle: string,\n): Promise<string | null> {\n const clean = handle.replace(/^@/, \"\");\n if (handleToIdCache.has(clean)) {\n return handleToIdCache.get(clean)!;\n }\n try {\n const profile = await client.getProfile(clean);\n handleToIdCache.set(clean, profile.id);\n return profile.id;\n } catch {\n logger.warn(`Could not resolve handle @${clean} to user ID`);\n return null;\n }\n}\n\n/**\n * Run the full research phase — gathers context from multiple sources.\n * Each sub-function is independently wrapped so failures don't cascade.\n */\nexport async function runResearchPhase(\n client: XClientInterface,\n heartbeatCount: number,\n): Promise<ResearchContext> {\n const context: ResearchContext = {\n timeline: [],\n mentions: [],\n topicSearchResults: [],\n peopleActivity: [],\n ownPostPerformance: [],\n };\n\n // Timeline + Mentions in parallel (always)\n const [timeline, mentions] = await Promise.all([\n client.getTimeline({ count: 20 }).catch(() => [] as Tweet[]),\n client.getMentions({ count: 10 }).catch(() => [] as Tweet[]),\n ]);\n context.timeline = timeline;\n context.mentions = mentions;\n\n // Topic search (every heartbeat, 1-2 rotated queries)\n context.topicSearchResults = await runTopicSearch(client, heartbeatCount, [...timeline, ...mentions]);\n\n // People monitoring (every heartbeat, 2-3 rotated people)\n context.peopleActivity = await runPeopleMonitoring(client, heartbeatCount, [...timeline, ...mentions]);\n\n // Own post performance (every 2nd heartbeat)\n if (heartbeatCount % 2 === 0) {\n context.ownPostPerformance = refreshOwnPostPerformance();\n }\n\n return context;\n}\n\n/**\n * Search for conversations in the agent's topic areas.\n * Rotates through identity.topics + strategy.currentFocus.\n */\nasync function runTopicSearch(\n client: XClientInterface,\n heartbeatCount: number,\n seedTweets: Tweet[],\n): Promise<TopicSearchResult[]> {\n try {\n const identity = loadIdentity();\n const strategy = loadStrategy();\n const selfHandle = canonicalAgentHandle(identity.handle);\n\n const allTopics = [\n ...(identity.topics ?? []),\n ...strategy.currentFocus,\n ]\n .flatMap(splitTopicSignal)\n .filter(Boolean);\n\n // Blend strategic topics with live-feed discovered terms to force exploration.\n const discovered = discoverQueriesFromTweets(seedTweets, 3);\n const targetHandles = [...new Set([\n ...strategy.peopleToEngage\n .filter((person) => person.priority === \"high\" || person.priority === \"medium\")\n .map((person) => person.handle.replace(/^@/, \"\").toLowerCase()),\n ...(identity.heroes ?? []).map((handle) => handle.replace(/^@/, \"\").toLowerCase()),\n ])]\n .filter((handle) => handle && handle !== selfHandle);\n\n const personQueries = buildTargetedPersonQueries(targetHandles, heartbeatCount, 2);\n const topicQueries = allTopics.length > 0\n ? pickTopicQueries(allTopics, Math.min(3, Math.max(2, allTopics.length)))\n : [];\n const discoveredQueries = discovered.length > 0\n ? pickDirectQueries(discovered, Math.min(2, discovered.length))\n : [];\n const topicsToSearch = [...new Set([...topicQueries, ...discoveredQueries, ...personQueries])];\n if (topicsToSearch.length === 0) return [];\n\n const results: TopicSearchResult[] = [];\n for (const topicQuery of topicsToSearch) {\n try {\n const tweets = (await client.searchTweets(topicQuery, { count: 10 })).filter((tweet) =>\n tweet.authorHandle.replace(/^@/, \"\").toLowerCase() !== selfHandle\n );\n if (tweets.length > 0) {\n results.push({ query: topicQuery, tweets });\n logger.info(`Topic search \"${topicQuery}\": found ${tweets.length} tweets`);\n }\n } catch {\n // Individual search failure is fine\n }\n }\n return results;\n } catch {\n return [];\n }\n}\n\n/**\n * Check recent tweets from key people.\n * Prioritizes: strategy.peopleToEngage (high) > identity.heroes > top relationships > strategy.peopleToEngage (medium)\n * Rotates 2-3 people per heartbeat.\n */\nasync function runPeopleMonitoring(\n client: XClientInterface,\n heartbeatCount: number,\n seedTweets: Tweet[],\n): Promise<PersonActivity[]> {\n try {\n const strategy = loadStrategy();\n const identity = loadIdentity();\n const selfHandle = identity.handle.replace(/^@/, \"\").toLowerCase();\n const relationships = loadRelationships();\n const networkHandles = listAgentNetworkHandles(20);\n const networkHandleSet = new Set(networkHandles);\n\n // Build prioritized list\n const people: { handle: string; reason: string; pinned: boolean }[] = [];\n const seen = new Set<string>();\n const highPriorityHandles = new Set(\n strategy.peopleToEngage\n .filter((person) => person.priority === \"high\")\n .map((person) => person.handle.replace(/^@/, \"\").toLowerCase()),\n );\n const protectedHandles = new Set([\n ...highPriorityHandles,\n ...(identity.heroes ?? []).map((handle) => handle.replace(/^@/, \"\").toLowerCase()),\n ...networkHandleSet,\n ]);\n\n const addPerson = (handle: string, reason: string, pinned: boolean = false) => {\n const clean = canonicalAgentHandle(handle);\n if (seen.has(clean)) return;\n if (clean === selfHandle) return;\n if (isLikelySyntheticHandle(clean) && !protectedHandles.has(clean)) return;\n seen.add(clean);\n people.push({ handle: clean, reason, pinned });\n };\n\n // Priority 1: high-priority strategy targets\n for (const p of strategy.peopleToEngage.filter(p => p.priority === \"high\")) {\n addPerson(p.handle, p.reason, true);\n }\n\n // Priority 2: known Spora agent network (always include @sporaai first)\n for (const handle of networkHandles) {\n if (handle === \"sporaai\") {\n const pinSpora = heartbeatCount % 4 === 0;\n addPerson(handle, \"core Spora profile\", pinSpora);\n } else {\n addPerson(handle, \"spora agent network\");\n }\n }\n\n // Priority 3: heroes\n for (const hero of identity.heroes ?? []) {\n addPerson(hero, \"hero/inspiration\");\n }\n\n // Priority 4: known Spora relationships\n const sporeRels = Object.values(relationships.accounts)\n .filter((rel) => rel.isSpore)\n .sort((a, b) => b.interactionCount - a.interactionCount)\n .slice(0, 5);\n for (const rel of sporeRels) {\n addPerson(rel.handle, \"spora relationship\");\n upsertAgentHandle(rel.handle, \"relationship\", \"relationship marked isSpore\");\n }\n\n // Priority 5: top relationships by interaction count\n const topRels = Object.values(relationships.accounts)\n .sort((a, b) => b.interactionCount - a.interactionCount)\n .slice(0, 5);\n for (const r of topRels) {\n addPerson(r.handle, \"frequent interactor\");\n }\n\n // Priority 6: medium-priority strategy targets\n for (const p of strategy.peopleToEngage.filter(p => p.priority === \"medium\")) {\n addPerson(p.handle, p.reason);\n }\n\n // Priority 7: exploration candidates discovered from live timeline/mentions.\n for (const handle of discoverPeopleFromTweets(seedTweets, selfHandle, 6)) {\n addPerson(handle, \"active voice in current conversations\");\n }\n\n if (people.length === 0) return [];\n\n // Pick 2-3 per heartbeat, always including pinned targets first.\n const budget = Math.min(3, people.length);\n const selected: typeof people = [];\n const selectedHandles = new Set<string>();\n\n const pinned = people.filter((person) => person.pinned);\n for (const person of pinned) {\n if (selected.length >= budget) break;\n selected.push(person);\n selectedHandles.add(person.handle);\n }\n\n if (selected.length < budget) {\n const rest = people.filter((person) => !selectedHandles.has(person.handle));\n if (rest.length > 0) {\n const startIdx = (heartbeatCount * 2) % rest.length;\n const rotated = [...rest.slice(startIdx), ...rest.slice(0, startIdx)];\n const recentlyChecked = new Set(peopleMonitorHistory.slice(-8));\n const preferred = rotated.filter((person) => !recentlyChecked.has(person.handle));\n const pool = preferred.length >= (budget - selected.length) ? preferred : rotated;\n for (const person of pool) {\n if (selected.length >= budget) break;\n selected.push(person);\n }\n }\n }\n\n for (const person of selected) {\n peopleMonitorHistory.push(person.handle);\n }\n if (peopleMonitorHistory.length > 120) {\n peopleMonitorHistory.splice(0, peopleMonitorHistory.length - 120);\n }\n\n const results: PersonActivity[] = [];\n const discoveredHandles = new Set<string>();\n for (const person of selected) {\n const userId = await resolveHandleToId(client, person.handle);\n if (!userId) continue;\n\n try {\n const tweets = await client.getUserTweets(userId, { count: 5 });\n if (tweets.length > 0) {\n results.push({\n handle: person.handle,\n userId,\n reason: person.reason,\n tweets,\n });\n upsertAgentHandle(person.handle, \"observed\", \"people check\");\n discoveredHandles.add(canonicalAgentHandle(person.handle));\n for (const tweet of tweets) {\n for (const mentionHandle of extractMentionHandles(tweet.text)) {\n discoveredHandles.add(canonicalAgentHandle(mentionHandle));\n }\n }\n logger.info(`People check @${person.handle}: ${tweets.length} recent tweets`);\n }\n } catch {\n // Individual person check failure is fine\n }\n }\n if (discoveredHandles.size > 0) {\n upsertAgentHandles([...discoveredHandles], \"observed\", \"discovered via people monitoring\");\n }\n return results;\n } catch {\n return [];\n }\n}\n\n/**\n * Get performance data on the agent's own recent posts.\n * Uses existing tracked posts from performance.ts (no API calls).\n */\nfunction refreshOwnPostPerformance(): TrackedPost[] {\n try {\n retireOldPosts();\n return getActiveTrackedPosts().slice(-5);\n } catch {\n return [];\n }\n}\n","import { getRecentInteractions, type InteractionEntry } from \"../memory/index.js\";\nimport { listAgentNetworkHandles } from \"../memory/agent-network.js\";\nimport { loadIdentity } from \"../identity/index.js\";\nimport { loadStrategy } from \"../memory/strategy.js\";\nimport type { AgentAction } from \"./decision-engine.js\";\nimport type { ResearchContext } from \"./research.js\";\nimport type { Tweet } from \"../x-client/types.js\";\n\nexport type OpportunityActionType = \"reply\" | \"like\" | \"retweet\" | \"follow\" | \"post\";\nexport type OpportunitySource = \"mention\" | \"timeline\" | \"topic_search\" | \"people_watch\" | \"synthesis\";\n\nexport interface ActionOpportunity {\n id: string;\n armKey: string;\n actionType: OpportunityActionType;\n source: OpportunitySource;\n score: number;\n summary: string;\n authorHandle?: string;\n tweetId?: string;\n requiresContent: boolean;\n template: Omit<AgentAction, \"content\" | \"reasoning\">;\n context: string;\n}\n\ninterface CandidateTweet {\n tweet: Tweet;\n source: OpportunitySource;\n}\n\ninterface BuildIndexesResult {\n repliedTweetIds: Set<string>;\n likedTweetIds: Set<string>;\n retweetedTweetIds: Set<string>;\n followedHandles: Set<string>;\n authorTouchCount: Map<string, number>;\n authorLastTouchedAt: Map<string, number>;\n}\n\ninterface PersonaContext {\n focusKeywords: string[];\n avoidKeywords: string[];\n priorityHandles: Set<string>;\n heroHandles: Set<string>;\n networkHandles: Set<string>;\n}\n\nfunction normalizeHandle(handle: string | undefined): string {\n return (handle ?? \"\").replace(/^@/, \"\").trim().toLowerCase();\n}\n\nfunction isLikelySyntheticHandle(handle: string): boolean {\n const clean = normalizeHandle(handle);\n return clean === \"spora\" || clean.endsWith(\"_ai\") || clean.endsWith(\"bot\");\n}\n\nfunction normalizeText(text: string): string {\n return text\n .toLowerCase()\n .replace(/https?:\\/\\/\\S+/g, \" \")\n .replace(/[@#]\\w+/g, \" \")\n .replace(/[^a-z0-9\\s]/g, \" \")\n .replace(/\\s+/g, \" \")\n .trim();\n}\n\nfunction clip(text: string, max: number = 190): string {\n if (text.length <= max) return text;\n return `${text.slice(0, max - 3)}...`;\n}\n\nfunction splitKeywords(text: string): string[] {\n const normalized = normalizeText(text);\n if (!normalized) return [];\n const words = normalized.split(\" \");\n if (words.length <= 6) return [normalized];\n const concise = words.filter((word) => word.length >= 4).slice(0, 6);\n return concise.length > 0 ? concise : [words.slice(0, 6).join(\" \")];\n}\n\nfunction unique<T>(values: T[]): T[] {\n return [...new Set(values)];\n}\n\nfunction buildPersonaContext(): PersonaContext {\n const identity = loadIdentity();\n const strategy = loadStrategy();\n\n const focusKeywords = unique(\n [\n ...identity.topics,\n ...identity.coreValues,\n ...identity.goals,\n ...strategy.currentFocus,\n ...strategy.shortTermGoals,\n ]\n .flatMap(splitKeywords)\n .map((keyword) => keyword.trim())\n .filter((keyword) => keyword.length >= 3)\n .slice(0, 40),\n );\n\n const avoidKeywords = unique(\n identity.avoidTopics\n .flatMap(splitKeywords)\n .map((keyword) => keyword.trim())\n .filter((keyword) => keyword.length >= 3)\n .slice(0, 20),\n );\n\n const priorityHandles = new Set(\n strategy.peopleToEngage\n .filter((person) => person.priority === \"high\")\n .map((person) => normalizeHandle(person.handle))\n .filter(Boolean),\n );\n const heroHandles = new Set(\n (identity.heroes ?? []).map((handle) => normalizeHandle(handle)).filter(Boolean),\n );\n const networkHandles = new Set(listAgentNetworkHandles(60).map((handle) => normalizeHandle(handle)).filter(Boolean));\n\n return { focusKeywords, avoidKeywords, priorityHandles, heroHandles, networkHandles };\n}\n\nfunction phraseMatchScore(text: string, keywords: string[]): number {\n if (keywords.length === 0) return 0;\n const normalized = normalizeText(text);\n if (!normalized) return 0;\n\n let score = 0;\n for (const keyword of keywords) {\n const needle = normalizeText(keyword);\n if (!needle) continue;\n if (!normalized.includes(needle)) continue;\n const wordCount = needle.split(\" \").length;\n score += wordCount >= 2 ? 0.7 : 0.35;\n }\n return Math.min(score, 2.4);\n}\n\nfunction recencyPenalty(lastTouchedAt: number | undefined): number {\n if (!lastTouchedAt) return 0;\n const ageHours = (Date.now() - lastTouchedAt) / (1000 * 60 * 60);\n if (ageHours < 1) return 2.0;\n if (ageHours < 4) return 1.1;\n if (ageHours < 12) return 0.55;\n return 0;\n}\n\ninterface TweetScore {\n score: number;\n alignment: number;\n}\n\nfunction buildRecentIndexes(recent: InteractionEntry[]): BuildIndexesResult {\n const repliedTweetIds = new Set<string>();\n const likedTweetIds = new Set<string>();\n const retweetedTweetIds = new Set<string>();\n const followedHandles = new Set<string>();\n const authorTouchCount = new Map<string, number>();\n const authorLastTouchedAt = new Map<string, number>();\n\n for (const entry of recent) {\n if (entry.type === \"reply\" && entry.inReplyTo) {\n repliedTweetIds.add(entry.inReplyTo);\n }\n if (entry.type === \"like\" && entry.tweetId) {\n likedTweetIds.add(entry.tweetId);\n }\n if (entry.type === \"retweet\" && entry.tweetId) {\n retweetedTweetIds.add(entry.tweetId);\n }\n if (entry.type === \"follow\" && entry.targetHandle) {\n followedHandles.add(normalizeHandle(entry.targetHandle));\n }\n if (entry.targetHandle) {\n const handle = normalizeHandle(entry.targetHandle);\n if (!handle) continue;\n authorTouchCount.set(handle, (authorTouchCount.get(handle) ?? 0) + 1);\n const ts = Date.parse(entry.timestamp);\n if (!Number.isNaN(ts)) {\n const existing = authorLastTouchedAt.get(handle) ?? 0;\n if (ts > existing) authorLastTouchedAt.set(handle, ts);\n }\n }\n }\n\n return {\n repliedTweetIds,\n likedTweetIds,\n retweetedTweetIds,\n followedHandles,\n authorTouchCount,\n authorLastTouchedAt,\n };\n}\n\nfunction sourceWeight(source: OpportunitySource): number {\n if (source === \"mention\") return 3.2;\n if (source === \"people_watch\") return 2.4;\n if (source === \"topic_search\") return 2.0;\n if (source === \"timeline\") return 1.5;\n return 1.0;\n}\n\nfunction armKey(actionType: OpportunityActionType, source: OpportunitySource): string {\n return `${actionType}:${source}`;\n}\n\nfunction scoreTweetOpportunity(\n source: OpportunitySource,\n tweet: Tweet,\n authorTouchCount: Map<string, number>,\n authorLastTouchedAt: Map<string, number>,\n recentlyReplied: boolean,\n persona: PersonaContext,\n): TweetScore {\n const handle = normalizeHandle(tweet.authorHandle);\n const priorTouches = authorTouchCount.get(handle) ?? 0;\n const focusMatch = phraseMatchScore(tweet.text, persona.focusKeywords);\n const avoidMatch = phraseMatchScore(tweet.text, persona.avoidKeywords);\n const targetBoost = persona.priorityHandles.has(handle)\n ? 2.4\n : persona.heroHandles.has(handle)\n ? 1.4\n : persona.networkHandles.has(handle)\n ? 0.9\n : 0;\n const alignment = focusMatch + targetBoost - avoidMatch * 1.2;\n\n let score = sourceWeight(source);\n score += Math.min((tweet.replyCount ?? 0) / 12, 1.2);\n score += Math.min((tweet.likeCount ?? 0) / 180, 1.0);\n score += tweet.text.includes(\"?\") ? 0.75 : 0;\n score += alignment;\n score += priorTouches === 0 ? 0.8 : Math.max(0.05, 0.55 - priorTouches * 0.14);\n score -= recencyPenalty(authorLastTouchedAt.get(handle));\n score -= recentlyReplied ? 3.5 : 0;\n if (priorTouches >= 5) score -= 0.8;\n if (avoidMatch > 0.6) score -= 1.2;\n if (\n isLikelySyntheticHandle(handle) &&\n !persona.priorityHandles.has(handle) &&\n !persona.heroHandles.has(handle) &&\n !persona.networkHandles.has(handle)\n ) {\n score -= 2.4;\n }\n\n return { score, alignment };\n}\n\nexport function buildActionOpportunities(input: {\n research: ResearchContext;\n selfHandle: string;\n selfUserId?: string | null;\n maxCandidates?: number;\n}): ActionOpportunity[] {\n const { research } = input;\n const maxCandidates = input.maxCandidates ?? 28;\n const selfHandle = normalizeHandle(input.selfHandle);\n const selfUserId = (input.selfUserId ?? \"\").trim();\n const persona = buildPersonaContext();\n\n const recent = getRecentInteractions(300);\n const {\n repliedTweetIds,\n likedTweetIds,\n retweetedTweetIds,\n followedHandles,\n authorTouchCount,\n authorLastTouchedAt,\n } = buildRecentIndexes(recent);\n\n const candidateTweets: CandidateTweet[] = [];\n for (const tweet of research.mentions) candidateTweets.push({ tweet, source: \"mention\" });\n for (const tweet of research.timeline) candidateTweets.push({ tweet, source: \"timeline\" });\n for (const result of research.topicSearchResults) {\n for (const tweet of result.tweets) candidateTweets.push({ tweet, source: \"topic_search\" });\n }\n for (const person of research.peopleActivity) {\n for (const tweet of person.tweets) candidateTweets.push({ tweet, source: \"people_watch\" });\n }\n\n const dedupedByTweetId = new Map<string, CandidateTweet>();\n for (const candidate of candidateTweets) {\n const handle = normalizeHandle(candidate.tweet.authorHandle);\n if (!candidate.tweet.id || !handle || handle === selfHandle) continue;\n if (selfUserId && candidate.tweet.authorId === selfUserId) continue;\n\n const existing = dedupedByTweetId.get(candidate.tweet.id);\n if (!existing || sourceWeight(candidate.source) > sourceWeight(existing.source)) {\n dedupedByTweetId.set(candidate.tweet.id, candidate);\n }\n }\n\n const followOpportunityByHandle = new Set<string>();\n const opportunities: ActionOpportunity[] = [];\n let counter = 0;\n const nextId = (): string => {\n counter += 1;\n return `opp-${counter}`;\n };\n\n for (const { tweet, source } of dedupedByTweetId.values()) {\n const handle = normalizeHandle(tweet.authorHandle);\n const { score: baseScore, alignment } = scoreTweetOpportunity(\n source,\n tweet,\n authorTouchCount,\n authorLastTouchedAt,\n repliedTweetIds.has(tweet.id),\n persona,\n );\n const shortTweet = clip(tweet.text, 170);\n\n opportunities.push({\n id: nextId(),\n armKey: armKey(\"reply\", source),\n actionType: \"reply\",\n source,\n score: baseScore + 0.7,\n summary: `Reply to @${handle} from ${source}`,\n authorHandle: handle,\n tweetId: tweet.id,\n requiresContent: true,\n template: { action: \"reply\", tweetId: tweet.id, source, targetHandle: `@${handle}` },\n context: `@${handle}: \"${shortTweet}\"`,\n });\n\n const stronglyRelevant =\n alignment >= 0.35 || source === \"mention\" || source === \"people_watch\" || persona.priorityHandles.has(handle);\n\n if (!likedTweetIds.has(tweet.id) && baseScore >= 1.8 && stronglyRelevant) {\n opportunities.push({\n id: nextId(),\n armKey: armKey(\"like\", source),\n actionType: \"like\",\n source,\n score: baseScore + 0.2,\n summary: `Like @${handle} from ${source}`,\n authorHandle: handle,\n tweetId: tweet.id,\n requiresContent: false,\n template: { action: \"like\", tweetId: tweet.id, source, targetHandle: `@${handle}` },\n context: `@${handle}: \"${shortTweet}\"`,\n });\n }\n\n if (!retweetedTweetIds.has(tweet.id) && baseScore >= 2.6 && alignment >= 0.15) {\n opportunities.push({\n id: nextId(),\n armKey: armKey(\"retweet\", source),\n actionType: \"retweet\",\n source,\n score: baseScore - 0.1,\n summary: `Retweet @${handle} from ${source}`,\n authorHandle: handle,\n tweetId: tweet.id,\n requiresContent: false,\n template: { action: \"retweet\", tweetId: tweet.id, source, targetHandle: `@${handle}` },\n context: `@${handle}: \"${shortTweet}\"`,\n });\n }\n\n const shouldConsiderFollow =\n !followedHandles.has(handle) &&\n !followOpportunityByHandle.has(handle) &&\n !isLikelySyntheticHandle(handle) &&\n baseScore >= 3 &&\n (\n persona.priorityHandles.has(handle) ||\n persona.heroHandles.has(handle) ||\n source === \"mention\" ||\n alignment >= 0.8\n );\n\n if (shouldConsiderFollow) {\n followOpportunityByHandle.add(handle);\n opportunities.push({\n id: nextId(),\n armKey: armKey(\"follow\", source),\n actionType: \"follow\",\n source,\n score: baseScore - 0.2,\n summary: `Follow @${handle}`,\n authorHandle: handle,\n requiresContent: false,\n template: { action: \"follow\", handle: `@${handle}`, source, targetHandle: `@${handle}` },\n context: `Account @${handle} is producing conversation-relevant content.`,\n });\n }\n }\n\n const queryList = research.topicSearchResults.map((r) => r.query).filter(Boolean);\n if (queryList.length > 0) {\n opportunities.push({\n id: nextId(),\n armKey: armKey(\"post\", \"synthesis\"),\n actionType: \"post\",\n source: \"synthesis\",\n score: 2.25,\n summary: \"Post an original thought synthesized from active conversations\",\n requiresContent: true,\n template: { action: \"post\", source: \"synthesis\" },\n context: `Weave a fresh take from active topics: ${queryList.slice(0, 4).join(\", \")}`,\n });\n }\n\n opportunities.sort((a, b) => b.score - a.score);\n return opportunities.slice(0, maxCandidates);\n}\n","import { logger } from \"../utils/logger.js\";\nimport { generateResponse } from \"./llm.js\";\nimport type { AgentAction } from \"./decision-engine.js\";\nimport type { ActionOpportunity } from \"./opportunity-engine.js\";\nimport { buildOpportunityPortfolioMessage } from \"./prompt-builder.js\";\n\ninterface PlannedSelection {\n candidateId: string;\n content?: string;\n reasoning?: string;\n}\n\nfunction parseSelections(responseText: string): PlannedSelection[] {\n const codeBlockMatch = responseText.match(/```(?:json)?\\s*\\n?([\\s\\S]*?)```/);\n const candidatesToTry: string[] = [];\n if (codeBlockMatch?.[1]) candidatesToTry.push(codeBlockMatch[1].trim());\n candidatesToTry.push(responseText.trim());\n\n for (const raw of candidatesToTry) {\n try {\n const parsed = JSON.parse(raw) as { selections?: PlannedSelection[] };\n if (Array.isArray(parsed.selections)) return parsed.selections;\n } catch {\n // continue\n }\n }\n\n const arrayMatch = responseText.match(/\\[\\s*\\{[\\s\\S]*\\}\\s*\\]/);\n if (arrayMatch) {\n try {\n const parsed = JSON.parse(arrayMatch[0]) as PlannedSelection[];\n if (Array.isArray(parsed)) return parsed;\n } catch {\n // continue\n }\n }\n\n return [];\n}\n\nfunction materializeSelections(\n selections: PlannedSelection[],\n opportunities: ActionOpportunity[],\n maxActions: number,\n): AgentAction[] {\n const byId = new Map(opportunities.map((opportunity) => [opportunity.id, opportunity]));\n const actions: AgentAction[] = [];\n const used = new Set<string>();\n\n for (const selection of selections) {\n if (actions.length >= maxActions) break;\n if (!selection.candidateId || used.has(selection.candidateId)) continue;\n\n const opportunity = byId.get(selection.candidateId);\n if (!opportunity) continue;\n\n const action: AgentAction = {\n ...opportunity.template,\n banditArm: opportunity.armKey,\n opportunityId: opportunity.id,\n reasoning: selection.reasoning,\n };\n\n if (opportunity.requiresContent) {\n const content = (selection.content ?? \"\").trim();\n if (!content) continue;\n action.content = content;\n }\n\n used.add(selection.candidateId);\n actions.push(action);\n }\n\n return actions;\n}\n\nexport async function planActionPortfolio(input: {\n systemPrompt: string;\n opportunities: ActionOpportunity[];\n maxActions: number;\n policyFeedback: string[];\n executedActions?: AgentAction[];\n}): Promise<AgentAction[]> {\n const { systemPrompt, opportunities, maxActions, policyFeedback, executedActions = [] } = input;\n\n if (opportunities.length === 0 || maxActions <= 0) return [];\n\n const prompt = buildOpportunityPortfolioMessage({\n opportunities,\n maxActions,\n policyFeedback,\n executedActions,\n });\n\n const llmResponse = await generateResponse(systemPrompt, prompt);\n const parsed = parseSelections(llmResponse.content);\n const actions = materializeSelections(parsed, opportunities, maxActions);\n\n if (actions.length === 0) {\n logger.warn(\"Portfolio planner returned no valid selections.\");\n }\n\n return actions;\n}\n","import { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { updatePostMetrics } from \"../memory/performance.js\";\nimport { paths } from \"../utils/paths.js\";\nimport { logger } from \"../utils/logger.js\";\nimport type { AgentAction, ActionResult } from \"./decision-engine.js\";\nimport type { ActionOpportunity } from \"./opportunity-engine.js\";\nimport type { XClientInterface } from \"../x-client/types.js\";\n\ninterface BanditArm {\n key: string;\n pulls: number;\n rewardSum: number;\n lastReward: number;\n updatedAt: string;\n}\n\ninterface PendingOutcome {\n id: string;\n armKey: string;\n actionType: string;\n tweetId?: string;\n createdAt: string;\n resolveAt: string;\n resolved: boolean;\n}\n\ninterface BanditState {\n totalPulls: number;\n explorationBudget: number;\n arms: Record<string, BanditArm>;\n pending: PendingOutcome[];\n}\n\ninterface ScoredOpportunity {\n opportunity: ActionOpportunity;\n adjustedScore: number;\n pulls: number;\n}\n\nexport interface OutcomeCollectionResult {\n processed: number;\n resolved: number;\n rewardAdded: number;\n}\n\nconst DEFAULT_EXPLORATION_BUDGET = 0.25;\n\nfunction defaultState(): BanditState {\n return {\n totalPulls: 0,\n explorationBudget: DEFAULT_EXPLORATION_BUDGET,\n arms: {},\n pending: [],\n };\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.max(min, Math.min(max, value));\n}\n\nfunction loadState(): BanditState {\n if (!existsSync(paths.bandit)) return defaultState();\n try {\n const parsed = JSON.parse(readFileSync(paths.bandit, \"utf-8\")) as Partial<BanditState>;\n const state: BanditState = {\n totalPulls: Math.max(0, parsed.totalPulls ?? 0),\n explorationBudget: clamp(parsed.explorationBudget ?? DEFAULT_EXPLORATION_BUDGET, 0.1, 0.45),\n arms: parsed.arms ?? {},\n pending: Array.isArray(parsed.pending) ? parsed.pending : [],\n };\n return state;\n } catch {\n return defaultState();\n }\n}\n\nfunction saveState(state: BanditState): void {\n state.explorationBudget = clamp(state.explorationBudget, 0.1, 0.45);\n state.pending = state.pending\n .filter((entry) => {\n if (!entry.resolved) return true;\n const resolvedAtMs = Date.parse(entry.resolveAt);\n if (Number.isNaN(resolvedAtMs)) return false;\n return Date.now() - resolvedAtMs < 7 * 24 * 60 * 60 * 1000;\n })\n .slice(-1200);\n writeFileSync(paths.bandit, JSON.stringify(state, null, 2));\n}\n\nfunction ensureArm(state: BanditState, armKey: string): BanditArm {\n const existing = state.arms[armKey];\n if (existing) return existing;\n const arm: BanditArm = {\n key: armKey,\n pulls: 0,\n rewardSum: 0,\n lastReward: 0,\n updatedAt: new Date().toISOString(),\n };\n state.arms[armKey] = arm;\n return arm;\n}\n\nfunction averageReward(arm: BanditArm): number {\n if (arm.pulls <= 0) return 0;\n return arm.rewardSum / arm.pulls;\n}\n\nfunction ucbBonus(totalPulls: number, armPulls: number): number {\n const t = Math.max(1, totalPulls);\n return Math.sqrt((2 * Math.log(t + 1)) / (armPulls + 1));\n}\n\nfunction computeImmediateReward(result: ActionResult): number {\n if (result.success) return 0.12;\n const error = (result.error ?? \"\").toLowerCase();\n if (error.includes(\"duplicate content\")) return -0.95;\n if (error.includes(\"rate limit\")) return -0.5;\n if (error.includes(\"forbidden\") || error.includes(\"403\")) return -0.55;\n return -0.35;\n}\n\nfunction resolveDelayedReward(metrics: { likeCount: number; replyCount: number; retweetCount: number } | null): number {\n if (!metrics) return -0.05;\n const reward =\n Math.min(metrics.likeCount * 0.03, 0.9) +\n Math.min(metrics.replyCount * 0.12, 0.9) +\n Math.min(metrics.retweetCount * 0.08, 0.8);\n if (metrics.likeCount === 0 && metrics.replyCount === 0 && metrics.retweetCount === 0) {\n return -0.15;\n }\n return Math.min(reward, 1.8);\n}\n\nfunction armKeyFromAction(action: AgentAction): string {\n if (action.banditArm && action.banditArm.trim().length > 0) return action.banditArm;\n const source = action.source ?? \"unknown\";\n return `${action.action}:${source}`;\n}\n\nfunction extractTweetId(action: AgentAction, result: ActionResult): string | undefined {\n if (result.detail && /^\\d+$/.test(result.detail)) return result.detail;\n if (action.action !== \"reply\" && action.tweetId) return action.tweetId;\n return undefined;\n}\n\nexport function selectBanditOpportunityPool(\n opportunities: ActionOpportunity[],\n maxPoolSize: number = 24,\n): ActionOpportunity[] {\n if (opportunities.length <= maxPoolSize) return opportunities;\n\n const state = loadState();\n const totalPulls = Math.max(1, state.totalPulls);\n const scored: ScoredOpportunity[] = opportunities.map((opportunity) => {\n const arm = ensureArm(state, opportunity.armKey);\n const mean = averageReward(arm);\n const bonus = ucbBonus(totalPulls, arm.pulls);\n const coldStartBoost = arm.pulls === 0 ? 0.25 : 0;\n const adjustedScore = opportunity.score + mean * 1.5 + bonus * 0.35 + coldStartBoost;\n return {\n opportunity: {\n ...opportunity,\n score: adjustedScore,\n },\n adjustedScore,\n pulls: arm.pulls,\n };\n });\n\n const explorationBudget = clamp(state.explorationBudget, 0.1, 0.45);\n const exploreCount = Math.max(1, Math.floor(maxPoolSize * explorationBudget));\n const exploitCount = Math.max(1, maxPoolSize - exploreCount);\n\n const exploit = [...scored].sort((a, b) => b.adjustedScore - a.adjustedScore).slice(0, exploitCount);\n const selected = new Map<string, ActionOpportunity>();\n for (const row of exploit) {\n selected.set(row.opportunity.id, row.opportunity);\n }\n\n const remaining = scored\n .filter((row) => !selected.has(row.opportunity.id))\n .sort((a, b) => {\n if (a.pulls !== b.pulls) return a.pulls - b.pulls;\n return b.adjustedScore - a.adjustedScore;\n });\n\n // Add low-pull candidates first, with slight randomization for exploration.\n while (selected.size < maxPoolSize && remaining.length > 0) {\n const window = remaining.splice(0, Math.min(5, remaining.length));\n const pick = window[Math.floor(Math.random() * window.length)];\n if (!selected.has(pick.opportunity.id)) {\n selected.set(pick.opportunity.id, pick.opportunity);\n }\n for (const row of window) {\n if (row.opportunity.id !== pick.opportunity.id) {\n remaining.push(row);\n }\n }\n remaining.sort((a, b) => {\n if (a.pulls !== b.pulls) return a.pulls - b.pulls;\n return b.adjustedScore - a.adjustedScore;\n });\n }\n\n const picked = [...selected.values()].sort((a, b) => b.score - a.score).slice(0, maxPoolSize);\n saveState(state);\n return picked;\n}\n\nexport function recordBanditActionResults(actions: AgentAction[], results: ActionResult[]): void {\n if (actions.length === 0 || results.length === 0) return;\n const state = loadState();\n const now = new Date().toISOString();\n\n for (let i = 0; i < Math.min(actions.length, results.length); i += 1) {\n const action = actions[i];\n const result = results[i];\n const armKey = armKeyFromAction(action);\n const arm = ensureArm(state, armKey);\n\n const immediateReward = computeImmediateReward(result);\n arm.pulls += 1;\n arm.rewardSum += immediateReward;\n arm.lastReward = immediateReward;\n arm.updatedAt = now;\n state.totalPulls += 1;\n\n const tweetId = extractTweetId(action, result);\n if (result.success && tweetId && (action.action === \"post\" || action.action === \"reply\")) {\n const delayMs = action.action === \"reply\" ? 20 * 60 * 1000 : 45 * 60 * 1000;\n state.pending.push({\n id: `pending-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,\n armKey,\n actionType: action.action,\n tweetId,\n createdAt: now,\n resolveAt: new Date(Date.now() + delayMs).toISOString(),\n resolved: false,\n });\n }\n }\n\n saveState(state);\n}\n\nexport async function collectDelayedOutcomes(client: XClientInterface): Promise<OutcomeCollectionResult> {\n const state = loadState();\n const now = Date.now();\n const pendingDue = state.pending.filter((entry) => !entry.resolved && Date.parse(entry.resolveAt) <= now).slice(0, 8);\n if (pendingDue.length === 0) {\n return { processed: 0, resolved: 0, rewardAdded: 0 };\n }\n\n let rewardAdded = 0;\n let resolved = 0;\n const checkedAt = new Date().toISOString();\n\n for (const pending of pendingDue) {\n const arm = ensureArm(state, pending.armKey);\n let metrics: { likeCount: number; retweetCount: number; replyCount: number } | null = null;\n\n if (pending.tweetId) {\n metrics = await client.getTweetMetrics(pending.tweetId);\n if (metrics) {\n updatePostMetrics(pending.tweetId, {\n checkedAt,\n likes: metrics.likeCount,\n retweets: metrics.retweetCount,\n replies: metrics.replyCount,\n });\n }\n }\n\n const reward = resolveDelayedReward(\n metrics\n ? {\n likeCount: metrics.likeCount,\n retweetCount: metrics.retweetCount,\n replyCount: metrics.replyCount,\n }\n : null,\n );\n\n arm.rewardSum += reward;\n arm.lastReward = reward;\n arm.updatedAt = checkedAt;\n rewardAdded += reward;\n pending.resolved = true;\n resolved += 1;\n }\n\n saveState(state);\n logger.info(\n `Bandit delayed outcomes processed=${pendingDue.length}, resolved=${resolved}, rewardDelta=${rewardAdded.toFixed(2)}`\n );\n\n return {\n processed: pendingDue.length,\n resolved,\n rewardAdded,\n };\n}\n","import { getXClient } from \"../x-client/index.js\";\nimport { logger } from \"../utils/logger.js\";\nimport { getRecentInteractions } from \"../memory/index.js\";\nimport { loadStrategy } from \"../memory/strategy.js\";\nimport { listIntents, recordIntentExecution } from \"../memory/intents.js\";\nimport { loadIdentity } from \"../identity/index.js\";\nimport { loadCredentials } from \"../utils/crypto.js\";\nimport type { Tweet } from \"../x-client/types.js\";\nimport { buildSystemPrompt } from \"./prompt-builder.js\";\nimport { executeAction, type AgentAction, type ActionResult } from \"./decision-engine.js\";\nimport { evaluateActionPolicy } from \"./policy.js\";\nimport { runResearchPhase } from \"./research.js\";\nimport { buildActionOpportunities, type ActionOpportunity } from \"./opportunity-engine.js\";\nimport { planActionPortfolio } from \"./portfolio-planner.js\";\nimport { generateResponse } from \"./llm.js\";\nimport {\n collectDelayedOutcomes,\n recordBanditActionResults,\n selectBanditOpportunityPool,\n} from \"./bandit.js\";\n\nexport interface AutonomyCycleResult {\n timeline: Tweet[];\n mentions: Tweet[];\n actions: AgentAction[];\n results: ActionResult[];\n policyFeedback: string[];\n}\n\nfunction recentReplyTargets(hours: number = 24): Set<string> {\n const cutoffMs = Date.now() - hours * 60 * 60 * 1000;\n const recent = getRecentInteractions(300);\n const targets = new Set<string>();\n\n for (const entry of recent) {\n if (entry.type !== \"reply\") continue;\n if (!entry.inReplyTo) continue;\n const ts = Date.parse(entry.timestamp);\n if (!Number.isNaN(ts) && ts < cutoffMs) continue;\n targets.add(entry.inReplyTo);\n }\n\n return targets;\n}\n\nfunction selfUserIdFromCredentials(): string | null {\n try {\n const creds = loadCredentials();\n const accessToken = creds.accessToken;\n if (!accessToken) return null;\n const dashIdx = accessToken.indexOf(\"-\");\n if (dashIdx <= 0) return null;\n const candidate = accessToken.substring(0, dashIdx);\n return /^\\d+$/.test(candidate) ? candidate : null;\n } catch {\n return null;\n }\n}\n\nfunction normalizeHandle(handle: string | undefined): string {\n return (handle ?? \"\").replace(/^@/, \"\").trim().toLowerCase();\n}\n\ntype RewriteStyleMode =\n | \"quick_reaction\"\n | \"curious_question\"\n | \"friendly_pushback\"\n | \"plain_observation\"\n | \"playful_line\";\n\nfunction roughWordCount(text: string): number {\n return text.trim().split(/\\s+/).filter(Boolean).length;\n}\n\nfunction inferStyleMode(text: string): RewriteStyleMode {\n const lower = text.toLowerCase();\n if (text.includes(\"?\")) return \"curious_question\";\n if (/\\b(lol|lmao|haha|wild|fr|ngl)\\b/i.test(text)) return \"playful_line\";\n if (/\\b(not|isn'?t|wrong|nah|nope|doesn'?t)\\b/i.test(lower)) return \"friendly_pushback\";\n if (roughWordCount(text) <= 9) return \"quick_reaction\";\n return \"plain_observation\";\n}\n\nfunction chooseRewriteStyleMode(recentTexts?: string[], targetTweetText?: string): RewriteStyleMode {\n const counts: Record<RewriteStyleMode, number> = {\n quick_reaction: 0,\n curious_question: 0,\n friendly_pushback: 0,\n plain_observation: 0,\n playful_line: 0,\n };\n for (const text of (recentTexts ?? []).slice(0, 10)) {\n counts[inferStyleMode(text)] += 1;\n }\n\n if ((targetTweetText ?? \"\").includes(\"?\") && counts.curious_question <= 2) {\n return \"curious_question\";\n }\n\n return (Object.entries(counts).sort((a, b) => a[1] - b[1])[0]?.[0] as RewriteStyleMode) ?? \"plain_observation\";\n}\n\nfunction rewriteStyleModeInstructions(mode: RewriteStyleMode): string[] {\n if (mode === \"quick_reaction\") {\n return [\n \"- style mode: quick reaction\",\n \"- 6-14 words, one short sentence\",\n \"- immediate reaction tone, no thesis statement\",\n ];\n }\n if (mode === \"curious_question\") {\n return [\n \"- style mode: curious question\",\n \"- include exactly one direct question\",\n \"- ask about a specific detail from the target tweet\",\n ];\n }\n if (mode === \"friendly_pushback\") {\n return [\n \"- style mode: friendly pushback\",\n \"- politely disagree in plain words\",\n \"- no lecture or abstract framing\",\n ];\n }\n if (mode === \"playful_line\") {\n return [\n \"- style mode: playful line\",\n \"- keep it light and witty, not sarcastic essay mode\",\n \"- avoid internet clichés and overused slogans\",\n ];\n }\n return [\n \"- style mode: plain observation\",\n \"- write like a natural human thought said out loud\",\n \"- concrete detail first, no broad generalization\",\n ];\n}\n\nfunction shouldAttemptStyleRewrite(action: AgentAction, reason: string): boolean {\n if (!action.content || (action.action !== \"reply\" && action.action !== \"post\")) return false;\n const lower = reason.toLowerCase();\n return (\n lower.includes(\"lecture-like\") ||\n lower.includes(\"abstract philosopher cadence\") ||\n lower.includes(\"manifesto\") ||\n lower.includes(\"too long/explanatory\") ||\n lower.includes(\"grounded in the target tweet context\") ||\n lower.includes(\"hedged consensus phrasing\") ||\n lower.includes(\"repetitive anchor phrase/term\") ||\n lower.includes(\"repetitive opening phrase\") ||\n lower.includes(\"low-novelty vocabulary loop\") ||\n lower.includes(\"abstract wording without concrete anchor\")\n );\n}\n\nfunction cleanRewriteOutput(text: string): string {\n const cleaned = text\n .replace(/```[\\s\\S]*?```/g, \"\")\n .replace(/^[\"'`]+|[\"'`]+$/g, \"\")\n .trim();\n const firstLine = cleaned.split(\"\\n\").map((line) => line.trim()).filter(Boolean)[0] ?? cleaned;\n return firstLine.trim();\n}\n\nasync function rewriteDraftForHumanVoice(input: {\n action: AgentAction;\n reason: string;\n targetTweetText?: string;\n recentTexts?: string[];\n}): Promise<string | null> {\n if (!input.action.content) return null;\n const identity = loadIdentity();\n const maxChars = input.action.action === \"reply\" ? 100 : 130;\n const minChars = input.action.action === \"reply\" ? 18 : 24;\n const styleMode = chooseRewriteStyleMode(input.recentTexts, input.targetTweetText);\n\n const system = [\n `You rewrite X/Twitter drafts into ${identity.name}'s natural voice.`,\n \"Output must feel human, direct, and contextual.\",\n \"Never write abstract philosophy or explanatory manifesto style.\",\n \"Return ONLY rewritten tweet text, no commentary.\",\n ].join(\" \");\n\n const promptParts: string[] = [];\n promptParts.push(`Current draft: ${input.action.content}`);\n promptParts.push(`Rejected because: ${input.reason}`);\n if (input.targetTweetText) {\n promptParts.push(`Target tweet context: ${input.targetTweetText}`);\n }\n promptParts.push(`Constraints:`);\n promptParts.push(`- ${minChars}-${maxChars} characters`);\n promptParts.push(\"- 1-2 short sentences max\");\n promptParts.push(\"- no 'the real question' / 'the deeper question' framing\");\n promptParts.push(\"- no colon, semicolon, or em dash\");\n promptParts.push(\"- specific and concrete, not abstract\");\n promptParts.push(\"- keep the same core stance\");\n promptParts.push(\"- use natural spoken phrasing and contractions when it fits\");\n for (const line of rewriteStyleModeInstructions(styleMode)) {\n promptParts.push(line);\n }\n if (input.recentTexts && input.recentTexts.length > 0) {\n promptParts.push(\"- avoid vocabulary anchors from these recent outputs:\");\n for (const text of input.recentTexts.slice(0, 5)) {\n promptParts.push(` - ${text.slice(0, 120)}`);\n }\n }\n\n try {\n const rewrite = await generateResponse(system, promptParts.join(\"\\n\"));\n const candidate = cleanRewriteOutput(rewrite.content);\n if (!candidate) return null;\n return candidate;\n } catch {\n return null;\n }\n}\n\nexport async function runAutonomyCycle(maxActions: number, heartbeatCount: number = 0): Promise<AutonomyCycleResult> {\n const client = await getXClient();\n\n try {\n const delayed = await collectDelayedOutcomes(client);\n if (delayed.processed > 0) {\n logger.info(\n `Delayed outcomes: processed=${delayed.processed}, resolved=${delayed.resolved}, rewardDelta=${delayed.rewardAdded.toFixed(2)}`\n );\n }\n } catch (error) {\n logger.warn(`Delayed outcome collection failed: ${(error as Error).message}`);\n }\n\n const selfHandle = loadIdentity().handle.replace(/^@/, \"\").toLowerCase();\n const selfUserId = selfUserIdFromCredentials();\n const isSelfTweet = (tweet: Tweet): boolean =>\n tweet.authorHandle.replace(/^@/, \"\").toLowerCase() === selfHandle ||\n (selfUserId !== null && tweet.authorId === selfUserId);\n\n const research = await runResearchPhase(client, heartbeatCount);\n const timeline = research.timeline.filter((tweet) => !isSelfTweet(tweet));\n const mentions = research.mentions.filter((tweet) => !isSelfTweet(tweet));\n const recentReplyTargetIds = recentReplyTargets(24);\n\n const filteredTimeline = timeline.filter((tweet) => !recentReplyTargetIds.has(tweet.id));\n const filteredMentions = mentions.filter((tweet) => !recentReplyTargetIds.has(tweet.id));\n const filteredTopicSearchResults = research.topicSearchResults\n .map((result) => ({\n ...result,\n tweets: result.tweets.filter((tweet) => !recentReplyTargetIds.has(tweet.id) && !isSelfTweet(tweet)),\n }))\n .filter((result) => result.tweets.length > 0);\n const filteredPeopleActivity = research.peopleActivity\n .map((person) => ({\n ...person,\n tweets: person.tweets.filter((tweet) => !recentReplyTargetIds.has(tweet.id) && !isSelfTweet(tweet)),\n }))\n .filter((person) => person.tweets.length > 0);\n\n const observedTweetIds = [\n ...filteredTimeline.map((tweet) => tweet.id),\n ...filteredMentions.map((tweet) => tweet.id),\n ...filteredTopicSearchResults.flatMap((result) => result.tweets.map((tweet) => tweet.id)),\n ...filteredPeopleActivity.flatMap((person) => person.tweets.map((tweet) => tweet.id)),\n ];\n const observedTweets = [\n ...filteredTimeline,\n ...filteredMentions,\n ...filteredTopicSearchResults.flatMap((result) => result.tweets),\n ...filteredPeopleActivity.flatMap((person) => person.tweets),\n ];\n logger.info(\n `Autonomy context: timeline=${filteredTimeline.length}, mentions=${filteredMentions.length}, topicTweets=${filteredTopicSearchResults.reduce((sum, r) => sum + r.tweets.length, 0)}, peopleTweets=${filteredPeopleActivity.reduce((sum, p) => sum + p.tweets.length, 0)}`\n );\n\n const systemPrompt = buildSystemPrompt();\n const actions: AgentAction[] = [];\n const results: ActionResult[] = [];\n const policyFeedback: string[] = [];\n const blockedTweetIds = new Set<string>(recentReplyTargetIds);\n const disallowedActions = new Set<string>();\n let replyRejectionCount = 0;\n const opportunities = buildActionOpportunities({\n research: {\n ...research,\n timeline: filteredTimeline,\n mentions: filteredMentions,\n topicSearchResults: filteredTopicSearchResults,\n peopleActivity: filteredPeopleActivity,\n },\n selfHandle,\n selfUserId,\n maxCandidates: 30,\n });\n const planningPool = selectBanditOpportunityPool(opportunities, 24);\n const byType = planningPool.reduce<Record<string, number>>((acc, opportunity) => {\n acc[opportunity.actionType] = (acc[opportunity.actionType] ?? 0) + 1;\n return acc;\n }, {});\n logger.info(`Opportunities selected: total=${planningPool.length}, byType=${JSON.stringify(byType)}`);\n const strategy = loadStrategy();\n const activeIntents = listIntents();\n const intentTargetHandles = new Set(\n activeIntents.flatMap((intent) => intent.targetHandles.map((handle) => normalizeHandle(handle)))\n );\n const priorityHandles = new Set(\n [\n ...strategy.peopleToEngage\n .filter((person) => person.priority === \"high\")\n .map((person) => normalizeHandle(person.handle))\n .filter(Boolean),\n ...intentTargetHandles,\n ],\n );\n const authorByTweetId = new Map<string, string>();\n for (const opportunity of planningPool) {\n if (opportunity.tweetId && opportunity.authorHandle) {\n authorByTweetId.set(opportunity.tweetId, normalizeHandle(opportunity.authorHandle));\n }\n }\n\n // Keep short memory available in context by touching it before planner loop.\n getRecentInteractions(20);\n\n const getPlanningOpportunities = (): ActionOpportunity[] => {\n return planningPool.filter((opportunity) => {\n if (disallowedActions.has(opportunity.actionType)) return false;\n if (opportunity.tweetId && blockedTweetIds.has(opportunity.tweetId)) return false;\n return true;\n });\n };\n\n for (let planningRound = 0; planningRound < 2 && actions.length < maxActions; planningRound += 1) {\n const candidates = getPlanningOpportunities();\n if (candidates.length === 0) {\n logger.info(\"No viable opportunities after filtering.\");\n break;\n }\n\n let plannedActions = await planActionPortfolio({\n systemPrompt,\n opportunities: candidates,\n maxActions: maxActions - actions.length,\n policyFeedback,\n executedActions: actions,\n });\n\n // Portfolio diversity guard: if model only picked replies, inject one non-reply candidate.\n if (plannedActions.length > 1 && plannedActions.every((a) => a.action === \"reply\")) {\n const nonReplyCandidate = candidates.find((opportunity) =>\n opportunity.actionType !== \"reply\" && !opportunity.requiresContent\n );\n if (nonReplyCandidate) {\n plannedActions = [\n { ...nonReplyCandidate.template, reasoning: \"diversity pivot\" },\n ...plannedActions.slice(0, Math.max(0, maxActions - actions.length - 1)),\n ];\n }\n }\n\n if (priorityHandles.size > 0) {\n const authorByTweetId = new Map<string, string>();\n for (const opportunity of candidates) {\n if (opportunity.tweetId && opportunity.authorHandle) {\n authorByTweetId.set(opportunity.tweetId, normalizeHandle(opportunity.authorHandle));\n }\n }\n\n const touchesPriorityTarget = plannedActions.some((action) => {\n if (action.handle && priorityHandles.has(normalizeHandle(action.handle))) return true;\n if (action.targetHandle && priorityHandles.has(normalizeHandle(action.targetHandle))) return true;\n if (action.tweetId && priorityHandles.has(authorByTweetId.get(action.tweetId) ?? \"\")) return true;\n return false;\n });\n\n if (!touchesPriorityTarget) {\n const priorityCandidate = candidates.find((opportunity) =>\n Boolean(opportunity.authorHandle) &&\n priorityHandles.has(normalizeHandle(opportunity.authorHandle)) &&\n !opportunity.requiresContent\n );\n if (priorityCandidate) {\n plannedActions = [\n { ...priorityCandidate.template, reasoning: \"priority-target focus\" },\n ...plannedActions,\n ].slice(0, Math.max(0, maxActions - actions.length));\n logger.info(`Priority target injection: @${priorityCandidate.authorHandle}`);\n }\n }\n }\n\n if (plannedActions.length === 0) {\n logger.info(\"Portfolio planner returned no actionable selections.\");\n break;\n }\n\n let acceptedInRound = 0;\n for (const proposedAction of plannedActions) {\n let candidateAction = proposedAction;\n if (actions.length >= maxActions) break;\n\n if (disallowedActions.has(candidateAction.action)) {\n const reason = `Action ${candidateAction.action} is temporarily disallowed this heartbeat.`;\n policyFeedback.push(reason);\n logger.info(`Policy rejected action ${candidateAction.action}: ${reason}`);\n continue;\n }\n\n if (candidateAction.tweetId && blockedTweetIds.has(candidateAction.tweetId)) {\n const reason = `Tweet ${candidateAction.tweetId} is blocked for this heartbeat.`;\n policyFeedback.push(reason);\n logger.info(`Policy rejected action ${candidateAction.action}: ${reason}`);\n continue;\n }\n\n let policy = evaluateActionPolicy({\n action: candidateAction,\n step: actions.length,\n timeline: filteredTimeline,\n mentions: filteredMentions,\n executedActions: actions,\n observedTweetIds,\n observedTweets,\n selfHandle,\n selfUserId,\n });\n\n if (!policy.allowed && shouldAttemptStyleRewrite(candidateAction, policy.reason ?? \"\")) {\n const recentTexts = getRecentInteractions(10)\n .filter((entry) => entry.type === \"post\" || entry.type === \"reply\")\n .map((entry) => entry.content ?? \"\")\n .filter(Boolean);\n const rewritten = await rewriteDraftForHumanVoice({\n action: candidateAction,\n reason: policy.reason ?? \"policy rejected\",\n targetTweetText: candidateAction.tweetId ? observedTweets.find((t) => t.id === candidateAction.tweetId)?.text : undefined,\n recentTexts,\n });\n\n if (rewritten && rewritten !== candidateAction.content) {\n candidateAction = {\n ...candidateAction,\n content: rewritten,\n reasoning: `${candidateAction.reasoning ?? \"rewritten\"} | style rewrite`,\n };\n policy = evaluateActionPolicy({\n action: candidateAction,\n step: actions.length,\n timeline: filteredTimeline,\n mentions: filteredMentions,\n executedActions: actions,\n observedTweetIds,\n observedTweets,\n selfHandle,\n selfUserId,\n });\n }\n }\n\n if (!policy.allowed) {\n const reason = policy.reason ?? \"Policy rejected action\";\n policyFeedback.push(reason);\n logger.info(`Policy rejected action ${candidateAction.action}: ${reason}`);\n\n if (candidateAction.tweetId) {\n blockedTweetIds.add(candidateAction.tweetId);\n }\n\n if (candidateAction.action === \"reply\") {\n replyRejectionCount += 1;\n if (replyRejectionCount >= 2) {\n disallowedActions.add(\"reply\");\n const pivot = \"Reply opportunities exhausted this heartbeat. Pivot to like/retweet/follow/post.\";\n policyFeedback.push(pivot);\n logger.info(`Policy adjustment: ${pivot}`);\n }\n }\n continue;\n }\n\n acceptedInRound += 1;\n const result = await executeAction(candidateAction);\n actions.push(candidateAction);\n results.push(result);\n\n if (activeIntents.length > 0) {\n const touchedHandle = normalizeHandle(\n candidateAction.targetHandle ??\n candidateAction.handle ??\n (candidateAction.tweetId ? authorByTweetId.get(candidateAction.tweetId) : undefined)\n );\n const loweredContent = (candidateAction.content ?? \"\").toLowerCase();\n for (const intent of activeIntents) {\n const handleMatch =\n touchedHandle.length > 0 &&\n intent.targetHandles.some((handle) => normalizeHandle(handle) === touchedHandle);\n const topicMatch =\n loweredContent.length > 0 &&\n intent.focusTopics.some((topic) => loweredContent.includes(topic.toLowerCase()));\n if (!handleMatch && !topicMatch) continue;\n recordIntentExecution(intent.id, {\n success: result.success,\n note: `${candidateAction.action}${touchedHandle ? ` @${touchedHandle}` : \"\"}`,\n });\n }\n }\n\n if (!result.success) {\n const err = result.error ?? \"\";\n if (candidateAction.tweetId) {\n blockedTweetIds.add(candidateAction.tweetId);\n }\n if (candidateAction.action === \"reply\" && /duplicate content/i.test(err)) {\n disallowedActions.add(\"reply\");\n const reason = \"Reply failed with duplicate-content error. Switch to non-reply actions.\";\n policyFeedback.push(reason);\n logger.info(`Policy adjustment: ${reason}`);\n }\n if ((candidateAction.action === \"post\" || candidateAction.action === \"schedule\") && /duplicate content/i.test(err)) {\n const reason = \"Write-path duplicate-content failure. Change framing and try a different angle.\";\n policyFeedback.push(reason);\n logger.info(`Policy adjustment: ${reason}`);\n }\n }\n }\n\n if (acceptedInRound === 0) {\n logger.info(\"Planner round produced no policy-approved actions.\");\n continue;\n }\n }\n\n recordBanditActionResults(actions, results);\n\n return {\n timeline,\n mentions,\n actions,\n results,\n policyFeedback,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkHA,eAAsB,cAAc,QAA4C;AAC9E,QAAM,EAAE,QAAQ,KAAK,IAAI;AAEzB,MAAI;AACF,YAAQ,MAAM;AAAA,MACZ,KAAK,QAAQ;AACX,YAAI,CAAC,O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AA,IACA;AAAA,EACF;AACF;","names":["normalizeHandle","pinned","p","normalizeHandle","isLikelySyntheticHandle","wordCount","existsSync","readFileSync","writeFileSync","existsSync","readFileSync","writeFileSync","armKey","normalizeHandle","authorByTweetId"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/init.ts","../src/x-client/profile-updater.ts"],"sourcesContent":["import { input, select, password as passwordPrompt } from \"@inquirer/prompts\";\nimport chalk from \"chalk\";\nimport { ensureDirectories } from \"./utils/paths.js\";\nimport { createDefaultConfig, saveConfig } from \"./utils/config.js\";\nimport { saveCredentials } from \"./utils/crypto.js\";\nimport { loadIdentity } from \"./identity/index.js\";\nimport type { Identity } from \"./identity/schema.js\";\nimport { updateXProfile } from \"./x-client/profile-updater.js\";\nimport { setLLMApiKey, type LLMProvider, getDefaultModel } from \"./runtime/llm.js\";\n\n/**\n * Fetch identity from token and save locally\n */\nasync function syncIdentityFromToken(token: string): Promise<void> {\n console.log(chalk.gray(\"Connecting to spora.dev...\\n\"));\n\n const apiUrl = process.env.SPORA_API_URL || \"https://www.spora.social\";\n const response = await fetch(`${apiUrl}/api/v1/connect`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ token }),\n });\n\n if (!response.ok) {\n const errData = await response.json().catch(() => ({} as { error?: string })) as { error?: string };\n throw new Error(errData.error || `Connection failed: ${response.statusText}`);\n }\n\n const data = await response.json() as {\n identity?: Identity;\n media?: { profileImage?: string; bannerImage?: string };\n readme?: string;\n };\n\n if (!data.identity) {\n throw new Error(\"No Spore identity found for this token\");\n }\n\n // Merge media fields\n if (data.media) {\n if (data.media.profileImage) data.identity.profileImage = data.media.profileImage;\n if (data.media.bannerImage) data.identity.bannerImage = data.media.bannerImage;\n }\n\n const { saveIdentity } = await import(\"./identity/index.js\");\n saveIdentity(data.identity);\n\n console.log(chalk.green(`✓ Connected to Spore: ${data.identity.name} (@${data.identity.handle})\\n`));\n\n // Save README if provided\n if (data.readme) {\n const { writeFileSync } = await import(\"node:fs\");\n const { paths } = await import(\"./utils/paths.js\");\n const { join, dirname } = await import(\"node:path\");\n const readmePath = join(dirname(paths.identity), \"IDENTITY.md\");\n writeFileSync(readmePath, data.readme, \"utf-8\");\n console.log(chalk.green(\"✓ Saved identity README\\n\"));\n }\n\n // Save connection token to config\n const { existsSync } = await import(\"node:fs\");\n const { paths } = await import(\"./utils/paths.js\");\n if (existsSync(paths.config)) {\n const { loadConfig, saveConfig } = await import(\"./utils/config.js\");\n const config = loadConfig();\n config.connection = {\n token,\n apiEndpoint: process.env.SPORA_API_URL || \"https://www.spora.social/api/v1\",\n configVersion: config.connection?.configVersion ?? 0,\n };\n saveConfig(config);\n }\n}\n\nasync function notifyConnectProfileCompletion(input: {\n token: string;\n profileUpdated: boolean;\n updatedFields: string[];\n errors: string[];\n}): Promise<void> {\n const apiUrl = process.env.SPORA_API_URL || \"https://www.spora.social\";\n try {\n const response = await fetch(`${apiUrl}/api/v1/connect/complete`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n token: input.token,\n profileUpdated: input.profileUpdated,\n updatedFields: input.updatedFields,\n errors: input.errors,\n }),\n });\n\n if (!response.ok) {\n const payload = await response.json().catch(() => ({})) as { error?: string };\n console.log(chalk.yellow(`Token launch callback skipped: ${payload.error || response.statusText}`));\n return;\n }\n\n const payload = await response.json().catch(() => ({})) as {\n triggered?: boolean;\n status?: string;\n reason?: string;\n warning?: string;\n };\n\n if (!payload.triggered) {\n const reason = payload.reason ? ` (${payload.reason})` : \"\";\n console.log(chalk.gray(`Bags token launch not triggered${reason}.`));\n return;\n }\n\n const status = payload.status ? ` [${payload.status}]` : \"\";\n console.log(chalk.green(`✓ Bags token launch request sent${status}`));\n if (payload.warning) {\n console.log(chalk.yellow(` ${payload.warning}`));\n }\n } catch (error) {\n console.log(chalk.yellow(`Token launch callback failed: ${(error as Error).message}`));\n }\n}\n\n/**\n * Login flow: paste token → sync identity → open chat (keys already saved locally)\n */\nasync function loginFlow(): Promise<void> {\n console.log(chalk.bold(\"\\n━━━ Login to Existing Spore ━━━\\n\"));\n console.log(chalk.gray(\"Paste your setup token from spora.dev\"));\n console.log(chalk.gray(\"(It looks like: spora_7e636ac0...)\\n\"));\n\n const token = await input({\n message: \"Setup token:\",\n validate: (val) => val.length > 0 ? true : \"Token is required\",\n });\n\n ensureDirectories();\n\n try {\n await syncIdentityFromToken(token.trim());\n } catch (error) {\n console.log(chalk.red(`\\n✗ ${(error as Error).message}\\n`));\n console.log(chalk.yellow(\"Please check your token and try again.\\n\"));\n process.exit(1);\n }\n\n console.log(chalk.green(\"✓ Logged in!\\n\"));\n console.log(chalk.gray(\"Opening chat interface...\\n\"));\n\n try {\n const { startWebChat } = await import(\"./web-chat/index.js\");\n await startWebChat();\n } catch (error) {\n console.log(chalk.yellow(`Could not start chat interface: ${(error as Error).message}\\n`));\n console.log(chalk.gray(\"You can start it manually with: spora chat\\n\"));\n }\n}\n\ninterface SetupResult {\n llm: {\n provider: LLMProvider;\n model: string;\n };\n}\n\nfunction providerKeyUrl(provider: LLMProvider): string {\n if (provider === \"anthropic\") return \"https://console.anthropic.com/settings/keys\";\n if (provider === \"openai\") return \"https://platform.openai.com/api-keys\";\n return \"https://platform.deepseek.com/api_keys\";\n}\n\n/**\n * Prompt for LLM provider/model + X credentials.\n */\nasync function setupKeys(): Promise<SetupResult> {\n console.log(chalk.bold(\"\\n━━━ LLM Provider Setup ━━━\\n\"));\n\n const provider = await select({\n message: \"Choose your LLM provider:\",\n choices: [\n { name: \"DeepSeek (recommended for low cost)\", value: \"deepseek\" },\n { name: \"Anthropic (Claude)\", value: \"anthropic\" },\n { name: \"OpenAI\", value: \"openai\" },\n ],\n }) as LLMProvider;\n\n const defaultModel = getDefaultModel(provider);\n const model = await input({\n message: `Model name for ${provider} (press enter for ${defaultModel}):`,\n });\n\n console.log(chalk.gray(\"Get your API key at: \") + chalk.cyan(`${providerKeyUrl(provider)}\\n`));\n const llmKey = await passwordPrompt({\n message: `${provider} API Key:`,\n mask: \"*\",\n validate: (val: string) => val.length > 0 ? true : \"API key is required\",\n });\n setLLMApiKey(provider, llmKey.trim());\n console.log(chalk.green(`✓ ${provider} API key saved\\n`));\n\n // X credentials\n console.log(chalk.bold(\"\\n━━━ Connect Your X Account ━━━\\n\"));\n console.log(chalk.gray(\"Your Spore needs OAuth 1.0a credentials for full X API access.\"));\n console.log(chalk.gray(\"This gives your agent the power to read timelines, post tweets, reply, like, and follow.\\n\"));\n console.log(chalk.cyan(\"How to get these credentials:\"));\n console.log(chalk.gray(\" 1. Go to: \") + chalk.cyan(\"https://developer.x.com/en/portal/dashboard\"));\n console.log(chalk.gray(\" 2. Create or select your app\"));\n console.log(chalk.gray(\" 3. Go to \\\"Keys and tokens\\\" tab\"));\n console.log(chalk.gray(\" 4. Copy all 4 credentials below\\n\"));\n console.log(chalk.yellow(\"Note: Some endpoints may require paid X API access depending on your tier.\\n\"));\n\n const apiKey = await passwordPrompt({\n message: \"X API Key (Consumer Key):\",\n mask: \"*\",\n validate: (val: string) => val.length > 0 ? true : \"API Key is required\",\n });\n\n const apiSecret = await passwordPrompt({\n message: \"X API Secret (Consumer Secret):\",\n mask: \"*\",\n validate: (val: string) => val.length > 0 ? true : \"API Secret is required\",\n });\n\n const accessToken = await passwordPrompt({\n message: \"X Access Token:\",\n mask: \"*\",\n validate: (val: string) => val.length > 0 ? true : \"Access Token is required\",\n });\n\n const accessTokenSecret = await passwordPrompt({\n message: \"X Access Token Secret:\",\n mask: \"*\",\n validate: (val: string) => val.length > 0 ? true : \"Access Token Secret is required\",\n });\n\n const bearerToken = await input({\n message: \"X Bearer Token (optional, press enter to skip):\",\n });\n\n saveCredentials({\n method: \"api\",\n apiKey,\n apiSecret,\n accessToken,\n accessTokenSecret,\n bearerToken: bearerToken.trim() || undefined,\n });\n console.log(chalk.green(\"✓ X API credentials saved (encrypted)\\n\"));\n\n return {\n llm: {\n provider,\n model: model.trim() || defaultModel,\n },\n };\n}\n\n/**\n * Show completion message and open chat\n */\nasync function showDoneAndOpenChat(): Promise<void> {\n console.log(chalk.green(\"\\n╔═══════════════════════════════════════╗\"));\n console.log(chalk.green.bold(\"║ Setup Complete! ║\"));\n console.log(chalk.green(\"╚═══════════════════════════════════════╝\\n\"));\n\n console.log(chalk.bold.cyan(\"━━━ Your Spore is Ready! ━━━\\n\"));\n console.log(chalk.gray(\"Opening chat interface...\\n\"));\n\n try {\n const { startWebChat } = await import(\"./web-chat/index.js\");\n await startWebChat();\n } catch (error) {\n console.log(chalk.yellow(`Could not start chat interface: ${(error as Error).message}\\n`));\n console.log(chalk.gray(\"You can start it manually with: spora chat\\n\"));\n }\n\n console.log(chalk.bold(\"Quick Start:\\n\"));\n console.log(chalk.cyan(\" spora chat\"));\n console.log(chalk.gray(\" → Talk to your Spore, tell it what to post, how to behave\\n\"));\n console.log(chalk.bold(\"Or start the autonomous agent:\\n\"));\n console.log(chalk.cyan(\" spora start\"));\n console.log(chalk.gray(\" → Your Spore will post and engage autonomously\\n\"));\n console.log(chalk.bold(\"Other commands:\\n\"));\n console.log(chalk.cyan(\" spora create \") + chalk.gray(\"# Create a personality\"));\n console.log(chalk.cyan(\" spora post <text> \") + chalk.gray(\"# Make your Spore post\"));\n console.log(chalk.cyan(\" spora agent-status \") + chalk.gray(\"# Check if agent is running\"));\n console.log(chalk.cyan(\" spora stop \") + chalk.gray(\"# Stop the agent\"));\n console.log(chalk.cyan(\" spora --help \") + chalk.gray(\"# See all commands\\n\"));\n}\n\nexport async function runInit(token?: string): Promise<void> {\n console.log(chalk.bold.cyan(\"\\n╔════════════════════════════════════════╗\"));\n console.log(chalk.bold.cyan(\"║ Welcome to Spora CLI Setup ║\"));\n console.log(chalk.bold.cyan(\"╚════════════════════════════════════════╝\\n\"));\n\n // If token provided via --token flag, this is a new user from the website → full setup\n if (token) {\n ensureDirectories();\n\n console.log(chalk.bold(\"\\n━━━ Connecting Your Spore ━━━\\n\"));\n try {\n await syncIdentityFromToken(token);\n } catch (error) {\n console.log(chalk.red(`\\n✗ ${(error as Error).message}\\n`));\n console.log(chalk.yellow(\"Please check your token and try again.\\n\"));\n process.exit(1);\n }\n\n const setup = await setupKeys();\n\n // Update X profile\n let profileUpdated = false;\n let updatedFields: string[] = [];\n let profileErrors: string[] = [];\n console.log(chalk.bold(\"\\n━━━ Updating Your X Profile ━━━\\n\"));\n console.log(chalk.gray(\"Setting up profile picture, banner, and bio to match your Spore...\\n\"));\n try {\n const identity = loadIdentity();\n const result = await updateXProfile(identity);\n profileUpdated = result.success;\n updatedFields = result.updated;\n profileErrors = result.errors;\n if (result.success) {\n console.log(chalk.green(\"✓ Profile updated successfully!\\n\"));\n if (result.updated.length > 0) {\n console.log(chalk.cyan(\"Updated:\"));\n for (const field of result.updated) {\n console.log(chalk.gray(` • ${field}`));\n }\n console.log();\n }\n }\n if (result.errors.length > 0) {\n console.log(chalk.yellow(\"\\nSome updates failed:\"));\n for (const err of result.errors) {\n console.log(chalk.gray(` • ${err}`));\n }\n console.log();\n }\n } catch (error) {\n console.log(chalk.yellow(`Could not update profile: ${(error as Error).message}\\n`));\n console.log(chalk.gray(\"You can manually update your X profile later.\\n\"));\n profileErrors = [(error as Error).message];\n }\n\n await notifyConnectProfileCompletion({\n token,\n profileUpdated,\n updatedFields,\n errors: profileErrors,\n });\n\n const config = createDefaultConfig({ xMethod: \"api\", xApiTier: \"basic\" });\n config.llm = setup.llm;\n config.runtime = { heartbeatIntervalMs: 300_000, actionsPerHeartbeat: 4, enabled: true };\n config.connection = {\n token,\n apiEndpoint: process.env.SPORA_API_URL || \"https://www.spora.social/api/v1\",\n configVersion: 0,\n };\n saveConfig(config);\n\n await showDoneAndOpenChat();\n return;\n }\n\n // No token provided — ask what they want to do\n const action = await select({\n message: \"What would you like to do?\",\n choices: [\n { name: \"Create a new Spore\", value: \"new\" },\n { name: \"Login to existing Spore\", value: \"login\" },\n ],\n });\n\n if (action === \"login\") {\n await loginFlow();\n return;\n }\n\n // \"new\" — full new Spore creation (no token, manual setup)\n ensureDirectories();\n\n const setup = await setupKeys();\n\n // Update X profile\n console.log(chalk.bold(\"\\n━━━ Updating Your X Profile ━━━\\n\"));\n console.log(chalk.gray(\"Setting up profile picture, banner, and bio to match your Spore...\\n\"));\n try {\n const identity = loadIdentity();\n const result = await updateXProfile(identity);\n if (result.success) {\n console.log(chalk.green(\"✓ Profile updated successfully!\\n\"));\n if (result.updated.length > 0) {\n console.log(chalk.cyan(\"Updated:\"));\n for (const field of result.updated) {\n console.log(chalk.gray(` • ${field}`));\n }\n console.log();\n }\n }\n if (result.errors.length > 0) {\n console.log(chalk.yellow(\"\\nSome updates failed:\"));\n for (const err of result.errors) {\n console.log(chalk.gray(` • ${err}`));\n }\n console.log();\n }\n } catch (error) {\n console.log(chalk.yellow(`Could not update profile: ${(error as Error).message}\\n`));\n console.log(chalk.gray(\"You can manually update your X profile later.\\n\"));\n }\n\n const config = createDefaultConfig({ xMethod: \"api\", xApiTier: \"basic\" });\n config.llm = setup.llm;\n config.runtime = { heartbeatIntervalMs: 300_000, actionsPerHeartbeat: 4, enabled: true };\n saveConfig(config);\n\n await showDoneAndOpenChat();\n}\n","/**\n * X Profile Updater\n * Updates X profile to match Spore identity (name, bio, profile pic, banner)\n */\n\nimport { TwitterApi } from \"twitter-api-v2\";\nimport sharp from \"sharp\";\nimport type { Identity } from \"../identity/schema.js\";\nimport { loadCredentials } from \"../utils/crypto.js\";\n\ninterface ProfileUpdateResult {\n success: boolean;\n updated: string[];\n errors: string[];\n}\n\n/**\n * Update X profile to match Spore identity\n * Requires OAuth 1.0a credentials\n */\nexport async function updateXProfile(identity: Identity): Promise<ProfileUpdateResult> {\n const result: ProfileUpdateResult = {\n success: false,\n updated: [],\n errors: [],\n };\n\n try {\n const creds = loadCredentials();\n if (creds.method !== \"api\") {\n result.errors.push(\"API credentials required\");\n return result;\n }\n\n // Create Twitter API client with OAuth 1.0a credentials\n const client = new TwitterApi({\n appKey: creds.apiKey!,\n appSecret: creds.apiSecret!,\n accessToken: creds.accessToken!,\n accessSecret: creds.accessTokenSecret!,\n });\n\n // Update profile name and bio (username separately to avoid breaking on failure)\n try {\n console.log(`Updating name to: ${identity.name}`);\n console.log(`Updating bio to: ${identity.bio.substring(0, 60)}...`);\n await client.v1.updateAccountProfile({\n name: identity.name,\n description: identity.bio,\n });\n result.updated.push(\"name\", \"bio\");\n console.log(\"Name and bio updated successfully\");\n } catch (error) {\n console.error(\"Name/bio update error:\", error);\n result.errors.push(`Failed to update name/bio: ${(error as Error).message}`);\n }\n\n // Username changes are intentionally not attempted here.\n // X frequently restricts handle updates, and failed writes can disrupt setup.\n\n // Update profile image if available\n if (identity.profileImage) {\n try {\n console.log(`Downloading profile image from: ${identity.profileImage.substring(0, 60)}...`);\n let imageBuffer = await downloadImage(identity.profileImage);\n console.log(`Downloaded ${(imageBuffer.length / 1024 / 1024).toFixed(2)}MB`);\n\n // Check image dimensions - Twitter requires min 400x400\n const metadata = await sharp(imageBuffer).metadata();\n console.log(`Image dimensions: ${metadata.width}x${metadata.height}`);\n\n if (!metadata.width || !metadata.height || metadata.width < 400 || metadata.height < 400) {\n throw new Error(`Image too small (${metadata.width}x${metadata.height}). Twitter requires minimum 400x400 pixels.`);\n }\n\n // Compress if needed (Twitter profile image limit: 2MB)\n const MAX_PROFILE_SIZE = 2 * 1024 * 1024; // 2MB\n imageBuffer = await compressImageIfNeeded(imageBuffer, MAX_PROFILE_SIZE, \"Profile\");\n\n console.log(`Uploading profile image to X...`);\n await client.v1.updateAccountProfileImage(imageBuffer);\n result.updated.push(\"profile_image\");\n console.log(\"Profile image updated successfully\");\n } catch (error) {\n console.error(\"Profile image error:\", error);\n result.errors.push(`Failed to update profile image: ${(error as Error).message}`);\n }\n } else {\n console.log(\"No profile image URL in identity\");\n }\n\n // Update banner image if available\n if (identity.bannerImage) {\n try {\n console.log(`Downloading banner image from: ${identity.bannerImage.substring(0, 60)}...`);\n let imageBuffer = await downloadImage(identity.bannerImage);\n console.log(`Downloaded ${(imageBuffer.length / 1024 / 1024).toFixed(2)}MB`);\n\n // Compress if needed (Twitter banner limit: 5MB)\n const MAX_BANNER_SIZE = 5 * 1024 * 1024; // 5MB\n imageBuffer = await compressImageIfNeeded(imageBuffer, MAX_BANNER_SIZE, \"Banner\");\n\n console.log(`Uploading banner image to X...`);\n await client.v1.updateAccountProfileBanner(imageBuffer);\n result.updated.push(\"banner_image\");\n console.log(\"Banner image updated successfully\");\n } catch (error) {\n console.error(\"Banner image error:\", error);\n result.errors.push(`Failed to update banner: ${(error as Error).message}`);\n }\n } else {\n console.log(\"No banner image URL in identity\");\n }\n\n result.success = result.updated.length > 0;\n return result;\n } catch (error) {\n result.errors.push((error as Error).message);\n return result;\n }\n}\n\n/**\n * Download image from URL and return as Buffer\n */\nasync function downloadImage(url: string): Promise<Buffer> {\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(`Failed to download image: ${response.statusText}`);\n }\n const arrayBuffer = await response.arrayBuffer();\n return Buffer.from(arrayBuffer);\n}\n\n/**\n * Compress image if it exceeds size limit by resizing\n * @param buffer Original image buffer\n * @param maxSizeBytes Maximum allowed size in bytes\n * @param type \"profile\" or \"banner\" for logging\n */\nasync function compressImageIfNeeded(\n buffer: Buffer,\n maxSizeBytes: number,\n type: string\n): Promise<Buffer> {\n if (buffer.length <= maxSizeBytes) {\n return buffer;\n }\n\n console.log(\n `${type} image is ${(buffer.length / 1024 / 1024).toFixed(2)}MB, resizing to fit ${(maxSizeBytes / 1024 / 1024).toFixed(0)}MB limit...`\n );\n\n // Calculate scale factor to fit within size limit\n const scaleFactor = Math.sqrt(maxSizeBytes / buffer.length) * 0.85; // 85% of target for safety\n\n // Get current dimensions and calculate new size\n const metadata = await sharp(buffer).metadata();\n const newWidth = Math.floor((metadata.width || 1000) * scaleFactor);\n\n // Resize and convert to JPEG with good quality\n const compressed = await sharp(buffer)\n .resize(newWidth, null, { fit: \"inside\", withoutEnlargement: true })\n .jpeg({ quality: 90, progressive: true })\n .toBuffer();\n\n console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