spora 0.7.2 → 0.7.3

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.
Files changed (44) hide show
  1. package/dist/autonomy-6UWPXTPD.js +19 -0
  2. package/dist/{chunk-LXQNVVIY.js → chunk-4LNMA56H.js} +2 -2
  3. package/dist/{chunk-OACD3HGE.js → chunk-7OOGNZBU.js} +3 -3
  4. package/dist/{chunk-E5NR6HT4.js → chunk-HGNMHGAF.js} +3 -3
  5. package/dist/{chunk-AOQ3WLZV.js → chunk-Q3YXJ2C6.js} +137 -28
  6. package/dist/chunk-Q3YXJ2C6.js.map +1 -0
  7. package/dist/{chunk-KWWAIS3C.js → chunk-SUZUJGGW.js} +2 -2
  8. package/dist/{chunk-NPV3OV2K.js → chunk-YMGJQRKG.js} +13 -2
  9. package/dist/chunk-YMGJQRKG.js.map +1 -0
  10. package/dist/{chunk-WIK74GGJ.js → chunk-ZBP2ROAZ.js} +104 -22
  11. package/dist/chunk-ZBP2ROAZ.js.map +1 -0
  12. package/dist/cli.js +32 -32
  13. package/dist/{client-57BQKVYF.js → client-4KGOBIXE.js} +124 -40
  14. package/dist/client-4KGOBIXE.js.map +1 -0
  15. package/dist/{colony-JPZC3R34.js → colony-IVYR233C.js} +3 -3
  16. package/dist/{heartbeat-TNEPE3ZP.js → heartbeat-CUL2FTFD.js} +57 -13
  17. package/dist/heartbeat-CUL2FTFD.js.map +1 -0
  18. package/dist/{init-ISSXETHY.js → init-2REECUVH.js} +5 -5
  19. package/dist/{llm-T33QTPVW.js → llm-OGOYCWBH.js} +3 -3
  20. package/dist/mcp-server.js +20 -20
  21. package/dist/{prompt-builder-5NYONN2W.js → prompt-builder-KJKFCGM7.js} +6 -4
  22. package/dist/{queue-G5PTE6R6.js → queue-D3MRKABU.js} +3 -3
  23. package/dist/{web-chat-3HM35XM4.js → web-chat-O24HGJVE.js} +45 -6
  24. package/dist/web-chat-O24HGJVE.js.map +1 -0
  25. package/dist/{x-client-GY6XSPK6.js → x-client-ASXVQ6EV.js} +3 -3
  26. package/package.json +1 -1
  27. package/dist/autonomy-DAV7X6QS.js +0 -19
  28. package/dist/chunk-AOQ3WLZV.js.map +0 -1
  29. package/dist/chunk-NPV3OV2K.js.map +0 -1
  30. package/dist/chunk-WIK74GGJ.js.map +0 -1
  31. package/dist/client-57BQKVYF.js.map +0 -1
  32. package/dist/heartbeat-TNEPE3ZP.js.map +0 -1
  33. package/dist/web-chat-3HM35XM4.js.map +0 -1
  34. /package/dist/{autonomy-DAV7X6QS.js.map → autonomy-6UWPXTPD.js.map} +0 -0
  35. /package/dist/{chunk-LXQNVVIY.js.map → chunk-4LNMA56H.js.map} +0 -0
  36. /package/dist/{chunk-OACD3HGE.js.map → chunk-7OOGNZBU.js.map} +0 -0
  37. /package/dist/{chunk-E5NR6HT4.js.map → chunk-HGNMHGAF.js.map} +0 -0
  38. /package/dist/{chunk-KWWAIS3C.js.map → chunk-SUZUJGGW.js.map} +0 -0
  39. /package/dist/{colony-JPZC3R34.js.map → colony-IVYR233C.js.map} +0 -0
  40. /package/dist/{init-ISSXETHY.js.map → init-2REECUVH.js.map} +0 -0
  41. /package/dist/{llm-T33QTPVW.js.map → llm-OGOYCWBH.js.map} +0 -0
  42. /package/dist/{prompt-builder-5NYONN2W.js.map → prompt-builder-KJKFCGM7.js.map} +0 -0
  43. /package/dist/{queue-G5PTE6R6.js.map → queue-D3MRKABU.js.map} +0 -0
  44. /package/dist/{x-client-GY6XSPK6.js.map → x-client-ASXVQ6EV.js.map} +0 -0
@@ -0,0 +1,19 @@
1
+ import {
2
+ runAutonomyCycle
3
+ } from "./chunk-ZBP2ROAZ.js";
4
+ import "./chunk-HGNMHGAF.js";
5
+ import "./chunk-7OOGNZBU.js";
6
+ import "./chunk-Q3YXJ2C6.js";
7
+ import "./chunk-P6KZIJYL.js";
8
+ import "./chunk-WN35MRMF.js";
9
+ import "./chunk-4LNMA56H.js";
10
+ import "./chunk-M6YOQVSI.js";
11
+ import "./chunk-SUZUJGGW.js";
12
+ import "./chunk-YMGJQRKG.js";
13
+ import "./chunk-NO3NQN67.js";
14
+ import "./chunk-JBYZ7K56.js";
15
+ import "./chunk-3RYCUGXE.js";
16
+ export {
17
+ runAutonomyCycle
18
+ };
19
+ //# sourceMappingURL=autonomy-6UWPXTPD.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logger
3
- } from "./chunk-NPV3OV2K.js";
3
+ } from "./chunk-YMGJQRKG.js";
4
4
  import {
5
5
  loadConfig,
6
6
  saveConfig
@@ -54,4 +54,4 @@ var rateLimiter = new RateLimiter();
54
54
  export {
55
55
  rateLimiter
56
56
  };
57
- //# sourceMappingURL=chunk-LXQNVVIY.js.map
57
+ //# sourceMappingURL=chunk-4LNMA56H.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logger
3
- } from "./chunk-NPV3OV2K.js";
3
+ } from "./chunk-YMGJQRKG.js";
4
4
  import {
5
5
  loadConfig
6
6
  } from "./chunk-NO3NQN67.js";
@@ -67,7 +67,7 @@ async function flushQueue() {
67
67
  const now = /* @__PURE__ */ new Date();
68
68
  let posted = 0;
69
69
  let failed = 0;
70
- const { getXClient } = await import("./x-client-GY6XSPK6.js");
70
+ const { getXClient } = await import("./x-client-ASXVQ6EV.js");
71
71
  const client = await getXClient();
72
72
  for (const entry of queue.entries) {
73
73
  if (entry.status !== "pending") continue;
@@ -121,4 +121,4 @@ export {
121
121
  flushQueue,
122
122
  showQueue
123
123
  };
124
- //# sourceMappingURL=chunk-OACD3HGE.js.map
124
+ //# sourceMappingURL=chunk-7OOGNZBU.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logger
3
- } from "./chunk-NPV3OV2K.js";
3
+ } from "./chunk-YMGJQRKG.js";
4
4
  import {
5
5
  loadConfig
6
6
  } from "./chunk-NO3NQN67.js";
@@ -13,7 +13,7 @@ async function getXClient() {
13
13
  if (config.xMethod !== "api") {
14
14
  throw new Error("Only X API mode is supported.");
15
15
  }
16
- const { XApiClient } = await import("./client-57BQKVYF.js");
16
+ const { XApiClient } = await import("./client-4KGOBIXE.js");
17
17
  clientInstance = new XApiClient();
18
18
  logger.info("X client initialized: API mode");
19
19
  return clientInstance;
@@ -26,4 +26,4 @@ export {
26
26
  getXClient,
27
27
  resetXClient
28
28
  };
29
- //# sourceMappingURL=chunk-E5NR6HT4.js.map
29
+ //# sourceMappingURL=chunk-HGNMHGAF.js.map
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-WN35MRMF.js";
7
7
  import {
8
8
  rateLimiter
9
- } from "./chunk-LXQNVVIY.js";
9
+ } from "./chunk-4LNMA56H.js";
10
10
  import {
11
11
  loadIdentity,
12
12
  renderIdentityDocument
@@ -156,53 +156,103 @@ function buildSystemPrompt() {
156
156
  sections.push("3. Be selective \u2014 your goals should guide every action.");
157
157
  sections.push("4. Respect your credit budget \u2014 check remaining credits before posting.");
158
158
  sections.push("5. Don't repeat yourself \u2014 vary your content and avoid posting the same thing.");
159
+ sections.push("6. Tweet like a real person \u2014 be conversational, opinionated, and curious. NEVER write dry, explanatory, or educational-sounding tweets.");
160
+ sections.push("7. Prioritize engagement (replies, likes, conversation) over broadcasting original posts.");
159
161
  if (identity.boundaries.length > 0) {
160
- sections.push(`6. Respect your boundaries: ${identity.boundaries.join(", ")}`);
162
+ sections.push(`8. Respect your boundaries: ${identity.boundaries.join(", ")}`);
161
163
  }
162
164
  return sections.join("\n");
163
165
  }
164
- function buildHeartbeatUserMessage(timeline, mentions) {
166
+ function buildHeartbeatUserMessage(research) {
165
167
  const parts = [];
166
- parts.push("It's time for your heartbeat cycle. Here's what's happening on your timeline:");
168
+ parts.push("It's time for your heartbeat cycle. Here's what you found while scanning:");
167
169
  parts.push("");
168
- if (mentions.length > 0) {
170
+ if (research.mentions.length > 0) {
169
171
  parts.push("## Mentions (people talking to/about you)");
170
- for (const t of mentions.slice(0, 10)) {
172
+ for (const t of research.mentions.slice(0, 10)) {
171
173
  parts.push(`- @${t.authorHandle}: "${t.text}" [tweet:${t.id}] (${t.likeCount ?? 0} likes)`);
172
174
  }
173
175
  parts.push("");
174
176
  }
175
- if (timeline.length > 0) {
176
- parts.push("## Timeline (recent posts from your feed)");
177
- for (const t of timeline.slice(0, 20)) {
177
+ if (research.timeline.length > 0) {
178
+ parts.push("## Timeline (your feed)");
179
+ for (const t of research.timeline.slice(0, 15)) {
178
180
  parts.push(`- @${t.authorHandle}: "${t.text}" [tweet:${t.id}] (${t.likeCount ?? 0} likes, ${t.retweetCount ?? 0} RTs)`);
179
181
  }
180
182
  parts.push("");
181
183
  }
184
+ if (research.topicSearchResults.length > 0) {
185
+ parts.push("## Topic Research (conversations in your interest areas)");
186
+ for (const result of research.topicSearchResults) {
187
+ parts.push(`### Search: "${result.query}"`);
188
+ for (const t of result.tweets.slice(0, 5)) {
189
+ parts.push(`- @${t.authorHandle}: "${t.text}" [tweet:${t.id}] (${t.likeCount ?? 0} likes, ${t.replyCount ?? 0} replies)`);
190
+ }
191
+ }
192
+ parts.push("");
193
+ }
194
+ if (research.peopleActivity.length > 0) {
195
+ parts.push("## People You're Watching (recent activity from key accounts)");
196
+ for (const person of research.peopleActivity) {
197
+ parts.push(`### @${person.handle} (${person.reason})`);
198
+ for (const t of person.tweets.slice(0, 3)) {
199
+ parts.push(`- "${t.text}" [tweet:${t.id}] (${t.likeCount ?? 0} likes, ${t.replyCount ?? 0} replies)`);
200
+ }
201
+ }
202
+ parts.push("");
203
+ }
204
+ if (research.ownPostPerformance.length > 0) {
205
+ parts.push("## How Your Recent Posts Are Doing");
206
+ for (const post of research.ownPostPerformance) {
207
+ const latest = post.metrics.length > 0 ? post.metrics[post.metrics.length - 1] : null;
208
+ const likes = latest?.likes ?? 0;
209
+ const rts = latest?.retweets ?? 0;
210
+ const replies = latest?.replies ?? 0;
211
+ parts.push(`- "${post.content.slice(0, 80)}..." \u2014 ${likes} likes, ${rts} RTs, ${replies} replies`);
212
+ }
213
+ parts.push("");
214
+ }
215
+ parts.push("## How to Act Like a Real Person on Twitter");
216
+ parts.push("");
217
+ parts.push("You are NOT a content bot. You are a person with opinions, curiosity, and relationships.");
218
+ parts.push("Think about what a real person with your personality would actually do when they open Twitter:");
219
+ parts.push("");
220
+ parts.push("**DO:**");
221
+ parts.push("- React to what you see \u2014 reply to interesting takes, ask questions, share hot takes");
222
+ parts.push("- Be conversational \u2014 write tweets like you're talking to friends, not giving a lecture");
223
+ parts.push("- Have opinions \u2014 agree, disagree, push back, get excited");
224
+ parts.push("- Ask genuine questions that spark conversation");
225
+ parts.push("- Use casual language, incomplete thoughts, humor, or surprise");
226
+ parts.push("- Like and retweet things that genuinely resonate with you");
227
+ parts.push("- Build relationships \u2014 reply to the same people, develop running conversations");
228
+ parts.push("");
229
+ parts.push("**DON'T:**");
230
+ parts.push(`- Write explanatory or educational posts ("Here's why X matters...")`);
231
+ parts.push('- Start tweets with "I think" or "This is interesting because"');
232
+ parts.push("- Write like a blog post or article \u2014 this is Twitter, keep it punchy");
233
+ parts.push("- Post generic observations nobody would engage with");
234
+ parts.push("- Ignore your timeline and just post into the void");
235
+ parts.push("");
236
+ parts.push("**Prioritize replying and engaging over original posts.** Real people spend more time reacting than broadcasting.");
237
+ parts.push("");
182
238
  parts.push("## Your Task");
183
- parts.push("Based on your identity, goals, and what you see above, decide what actions to take.");
184
- parts.push("You can take 1-3 actions. Choose from:");
239
+ parts.push("Choose 1-3 actions. Available:");
185
240
  parts.push("");
186
- parts.push("Available actions:");
187
- parts.push("- `post` \u2014 Write an original tweet (provide `content`, max 280 chars)");
188
- parts.push("- `reply` \u2014 Reply to a tweet (provide `tweetId` and `content`)");
189
- parts.push("- `like` \u2014 Like a tweet (provide `tweetId`)");
190
- parts.push("- `retweet` \u2014 Retweet (provide `tweetId`)");
191
- parts.push("- `follow` \u2014 Follow a user (provide `handle`)");
192
- parts.push("- `schedule` \u2014 Queue a post for later (provide `content`)");
193
- parts.push("- `learn` \u2014 Record a learning/observation (provide `content` and optional `tags`)");
194
- parts.push("- `reflect` \u2014 Add a journal entry about your growth (provide `content`)");
195
- parts.push("- `skip` \u2014 Do nothing this heartbeat (provide `reason`)");
241
+ parts.push("- `post` \u2014 Original tweet (`content`, max 280 chars)");
242
+ parts.push("- `reply` \u2014 Reply to a tweet (`tweetId` + `content`)");
243
+ parts.push("- `like` \u2014 Like a tweet (`tweetId`)");
244
+ parts.push("- `retweet` \u2014 Retweet (`tweetId`)");
245
+ parts.push("- `follow` \u2014 Follow a user (`handle`)");
246
+ parts.push("- `schedule` \u2014 Queue for later (`content`)");
247
+ parts.push("- `skip` \u2014 Do nothing (`reason`)");
196
248
  parts.push("");
197
- parts.push("Respond with a JSON array of actions:");
249
+ parts.push("Respond with a JSON array:");
198
250
  parts.push("```json");
199
251
  parts.push("[");
200
- parts.push(' { "action": "post", "content": "your tweet here", "reasoning": "why" },');
201
- parts.push(' { "action": "like", "tweetId": "123", "reasoning": "why" }');
252
+ parts.push(' { "action": "reply", "tweetId": "123", "content": "wait this is actually wild", "reasoning": "reacting to interesting take" },');
253
+ parts.push(' { "action": "like", "tweetId": "456", "reasoning": "good thread worth supporting" }');
202
254
  parts.push("]");
203
255
  parts.push("```");
204
- parts.push("");
205
- parts.push("Think carefully about what serves your goals. Be authentic to your personality.");
206
256
  return parts.join("\n");
207
257
  }
208
258
  function buildToolDecisionMessage(input) {
@@ -216,6 +266,7 @@ function buildToolDecisionMessage(input) {
216
266
  parts.push("2. Prefer context-aware replies/likes/follows when relevant.");
217
267
  parts.push("3. Avoid repetitive templates, slogans, and lecture-like formats.");
218
268
  parts.push("4. Ask questions sometimes. Curiosity beats certainty.");
269
+ parts.push("5. Never reuse the same wording across replies; tailor each reply to the specific tweet.");
219
270
  parts.push("");
220
271
  if (policyFeedback.length > 0) {
221
272
  parts.push("Policy feedback from previous attempts:");
@@ -410,12 +461,70 @@ function buildTrainingChatPrompt() {
410
461
  sections.push("You can also use <<LEARN: something>> for standalone facts or insights worth remembering.");
411
462
  return sections.join("\n");
412
463
  }
464
+ function buildReflectionPrompt(actionResults) {
465
+ const identity = loadIdentity();
466
+ const parts = [];
467
+ parts.push(`You are ${identity.name} (@${identity.handle}). Time to reflect.`);
468
+ parts.push("");
469
+ parts.push("## Your Goals");
470
+ for (const goal of identity.goals) {
471
+ parts.push(`- ${goal}`);
472
+ }
473
+ parts.push("");
474
+ if (actionResults.length > 0) {
475
+ parts.push("## This Heartbeat");
476
+ for (const r of actionResults) {
477
+ if (r.success) {
478
+ parts.push(`- \u2713 ${r.action}${r.detail ? `: ${r.detail}` : ""}`);
479
+ } else {
480
+ parts.push(`- \u2717 ${r.action} failed: ${r.error}`);
481
+ }
482
+ }
483
+ parts.push("");
484
+ }
485
+ const strategyText = renderStrategyForPrompt();
486
+ if (strategyText) {
487
+ parts.push("## Current Strategy");
488
+ parts.push(strategyText);
489
+ parts.push("");
490
+ }
491
+ const perfSummary = getPerformanceSummary();
492
+ if (perfSummary) {
493
+ parts.push("## Performance Context");
494
+ parts.push(perfSummary);
495
+ parts.push("");
496
+ }
497
+ const learnings = loadLearnings();
498
+ if (learnings.learnings.length > 0) {
499
+ parts.push("## Previous Learnings");
500
+ for (const l of learnings.learnings.slice(-5)) {
501
+ parts.push(`- ${l.content}`);
502
+ }
503
+ parts.push("");
504
+ }
505
+ parts.push("## Your Task");
506
+ parts.push("Reflect on how you're progressing toward your GOALS. Consider:");
507
+ parts.push("- Are your recent actions moving you toward your goals?");
508
+ parts.push("- Are you staying true to who you are while growing?");
509
+ parts.push("- What should you try differently or double down on?");
510
+ parts.push("- Engagement metrics are one signal, but your goals matter more.");
511
+ parts.push("");
512
+ parts.push("Respond with JSON:");
513
+ parts.push("```json");
514
+ parts.push("{");
515
+ parts.push(' "learning": "one insight about your progress toward your goals (or null)",');
516
+ parts.push(' "strategyUpdate": "one specific thing to try or change (or null)"');
517
+ parts.push("}");
518
+ parts.push("```");
519
+ return parts.join("\n");
520
+ }
413
521
 
414
522
  export {
415
523
  buildSystemPrompt,
416
524
  buildHeartbeatUserMessage,
417
525
  buildToolDecisionMessage,
418
526
  buildChatPrompt,
419
- buildTrainingChatPrompt
527
+ buildTrainingChatPrompt,
528
+ buildReflectionPrompt
420
529
  };
421
- //# sourceMappingURL=chunk-AOQ3WLZV.js.map
530
+ //# sourceMappingURL=chunk-Q3YXJ2C6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/memory/performance.ts","../src/runtime/prompt-builder.ts"],"sourcesContent":["import { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { paths } from \"../utils/paths.js\";\n\nexport interface EngagementMetric {\n checkedAt: string;\n likes: number;\n retweets: number;\n replies: number;\n}\n\nexport interface TrackedPost {\n tweetId: string;\n content: string;\n type: \"post\" | \"reply\";\n postedAt: string;\n metrics: EngagementMetric[];\n retired: boolean;\n}\n\nexport interface SelfMetric {\n checkedAt: string;\n followers: number;\n following: number;\n totalTweets: number;\n}\n\nexport interface PerformanceData {\n trackedPosts: TrackedPost[];\n selfMetrics: SelfMetric[];\n}\n\nfunction loadPerformance(): PerformanceData {\n if (!existsSync(paths.performance)) {\n return { trackedPosts: [], selfMetrics: [] };\n }\n try {\n return JSON.parse(readFileSync(paths.performance, \"utf-8\"));\n } catch {\n return { trackedPosts: [], selfMetrics: [] };\n }\n}\n\nfunction savePerformance(data: PerformanceData): void {\n writeFileSync(paths.performance, JSON.stringify(data, null, 2));\n}\n\nexport function trackPost(tweetId: string, content: string, type: \"post\" | \"reply\"): void {\n const data = loadPerformance();\n // Don't double-track\n if (data.trackedPosts.some(p => p.tweetId === tweetId)) return;\n data.trackedPosts.push({\n tweetId,\n content,\n type,\n postedAt: new Date().toISOString(),\n metrics: [],\n retired: false,\n });\n savePerformance(data);\n}\n\nexport function getActiveTrackedPosts(): TrackedPost[] {\n const data = loadPerformance();\n return data.trackedPosts.filter(p => !p.retired);\n}\n\nexport function updatePostMetrics(tweetId: string, metric: EngagementMetric): void {\n const data = loadPerformance();\n const post = data.trackedPosts.find(p => p.tweetId === tweetId);\n if (!post) return;\n post.metrics.push(metric);\n savePerformance(data);\n}\n\nexport function retireOldPosts(): void {\n const data = loadPerformance();\n const cutoff = Date.now() - 72 * 60 * 60 * 1000; // 72 hours\n let changed = false;\n for (const post of data.trackedPosts) {\n if (!post.retired && new Date(post.postedAt).getTime() < cutoff) {\n post.retired = true;\n changed = true;\n }\n }\n // Also prune very old retired posts (older than 30 days) to prevent file bloat\n const pruneCutoff = Date.now() - 30 * 24 * 60 * 60 * 1000;\n const before = data.trackedPosts.length;\n data.trackedPosts = data.trackedPosts.filter(\n p => !p.retired || new Date(p.postedAt).getTime() > pruneCutoff\n );\n if (data.trackedPosts.length !== before) changed = true;\n if (changed) savePerformance(data);\n}\n\nexport function updateSelfMetrics(metric: SelfMetric): void {\n const data = loadPerformance();\n data.selfMetrics.push(metric);\n // Keep only last 100 snapshots\n if (data.selfMetrics.length > 100) {\n data.selfMetrics = data.selfMetrics.slice(-100);\n }\n savePerformance(data);\n}\n\nexport function getPerformanceSummary(): string {\n const data = loadPerformance();\n const lines: string[] = [];\n\n // Post performance (last 24h)\n const oneDayAgo = Date.now() - 24 * 60 * 60 * 1000;\n const recentPosts = data.trackedPosts.filter(\n p => new Date(p.postedAt).getTime() > oneDayAgo\n );\n\n if (recentPosts.length > 0) {\n // Get latest metrics for each post\n const postStats = recentPosts.map(p => {\n const latest = p.metrics.length > 0 ? p.metrics[p.metrics.length - 1] : null;\n return {\n content: p.content,\n type: p.type,\n likes: latest?.likes ?? 0,\n retweets: latest?.retweets ?? 0,\n replies: latest?.replies ?? 0,\n };\n });\n\n const totalLikes = postStats.reduce((s, p) => s + p.likes, 0);\n const totalRTs = postStats.reduce((s, p) => s + p.retweets, 0);\n const avgLikes = Math.round(totalLikes / postStats.length);\n\n lines.push(`- Last 24h: ${postStats.length} posts, avg ${avgLikes} likes, ${totalRTs} total retweets`);\n\n // Best and worst performing\n const sorted = [...postStats].sort((a, b) => b.likes - a.likes);\n if (sorted.length > 0 && sorted[0].likes > 0) {\n lines.push(`- Best performing: \"${sorted[0].content.slice(0, 60)}...\" (${sorted[0].likes} likes, ${sorted[0].retweets} RTs)`);\n }\n if (sorted.length > 1) {\n const worst = sorted[sorted.length - 1];\n lines.push(`- Lowest performing: \"${worst.content.slice(0, 60)}...\" (${worst.likes} likes)`);\n }\n } else {\n lines.push(\"- No tracked posts in the last 24 hours yet.\");\n }\n\n // Self metrics\n if (data.selfMetrics.length > 0) {\n const latest = data.selfMetrics[data.selfMetrics.length - 1];\n lines.push(`- Followers: ${latest.followers} | Following: ${latest.following} | Total tweets: ${latest.totalTweets}`);\n\n // Trend: compare to 24h ago\n const dayAgoMetric = data.selfMetrics.find(m =>\n Math.abs(new Date(m.checkedAt).getTime() - (Date.now() - 24 * 60 * 60 * 1000)) < 12 * 60 * 60 * 1000\n );\n if (dayAgoMetric) {\n const diff = latest.followers - dayAgoMetric.followers;\n if (diff !== 0) {\n lines.push(`- Follower trend: ${diff > 0 ? \"+\" : \"\"}${diff} in the last ~24h`);\n }\n }\n }\n\n return lines.length > 0 ? lines.join(\"\\n\") : \"\";\n}\n","import { loadIdentity, renderIdentityDocument } from \"../identity/index.js\";\nimport { loadConfig } from \"../utils/config.js\";\nimport { getRecentInteractions, loadLearnings, loadRelationships } from \"../memory/index.js\";\nimport { rateLimiter } from \"../x-client/rate-limiter.js\";\nimport { renderStrategyForPrompt } from \"../memory/strategy.js\";\nimport { renderGoalsForPrompt } from \"../memory/goals.js\";\nimport { getPerformanceSummary } from \"../memory/performance.js\";\nimport type { Tweet } from \"../x-client/types.js\";\nimport type { AgentAction, ActionResult } from \"./decision-engine.js\";\nimport type { ResearchContext } from \"./research.js\";\n\nexport function buildSystemPrompt(): string {\n const identity = loadIdentity();\n const config = loadConfig();\n const identityDoc = renderIdentityDocument(identity);\n\n const sections: string[] = [];\n\n // 1. Core identity\n sections.push(`You are ${identity.name} (@${identity.handle}), an autonomous AI agent on X/Twitter.`);\n sections.push(\"\");\n sections.push(\"## Your Identity\");\n sections.push(identityDoc);\n\n // 2. Memory context\n sections.push(\"\");\n sections.push(\"## Your Memory\");\n\n const recentInteractions = getRecentInteractions(15);\n if (recentInteractions.length > 0) {\n sections.push(\"### Recent Activity (most recent first)\");\n for (const i of recentInteractions) {\n const time = new Date(i.timestamp).toLocaleString();\n if (i.type === \"post\") {\n sections.push(`- [${time}] Posted: \"${i.content}\"`);\n } else if (i.type === \"reply\") {\n sections.push(`- [${time}] Replied to ${i.targetHandle ?? i.inReplyTo}: \"${i.content}\"`);\n } else if (i.type === \"like\") {\n sections.push(`- [${time}] Liked tweet by ${i.targetHandle}`);\n } else if (i.type === \"retweet\") {\n sections.push(`- [${time}] Retweeted ${i.targetHandle}`);\n } else if (i.type === \"follow\") {\n sections.push(`- [${time}] Followed @${i.targetHandle}`);\n } else if (i.type === \"mention_received\") {\n sections.push(`- [${time}] Mentioned by @${i.targetHandle}: \"${i.content}\"`);\n }\n }\n sections.push(\"\");\n }\n\n const learnings = loadLearnings();\n if (learnings.learnings.length > 0) {\n sections.push(\"### Key Learnings\");\n for (const l of learnings.learnings.slice(-10)) {\n sections.push(`- ${l.content} [${l.tags.join(\", \")}]`);\n }\n sections.push(\"\");\n }\n\n const relationships = loadRelationships();\n const topRelationships = Object.values(relationships.accounts)\n .sort((a, b) => b.interactionCount - a.interactionCount)\n .slice(0, 10);\n if (topRelationships.length > 0) {\n sections.push(\"### Key Relationships\");\n for (const r of topRelationships) {\n const notes = r.notes.length > 0 ? ` — ${r.notes[r.notes.length - 1]}` : \"\";\n sections.push(`- @${r.handle}: ${r.interactionCount} interactions, sentiment ${r.sentiment}${r.isSpore ? \" (Spore)\" : \"\"}${notes}`);\n }\n sections.push(\"\");\n }\n\n // 3. Context\n sections.push(\"## Current Context\");\n const now = new Date();\n sections.push(`- **Time:** ${now.toLocaleString(\"en-US\", { timeZone: config.schedule.timezone })}`);\n sections.push(`- **Credits remaining:** ${rateLimiter.remaining()} of ${config.credits.monthlyPostLimit} this month`);\n\n const todaysPosts = recentInteractions.filter(\n (i) => i.type === \"post\" && i.timestamp.startsWith(now.toISOString().split(\"T\")[0])\n ).length;\n sections.push(`- **Posts today:** ${todaysPosts} of ${config.schedule.postsPerDay} daily budget`);\n sections.push(`- **Active hours:** ${config.schedule.activeHoursStart}:00 - ${config.schedule.activeHoursEnd}:00`);\n\n const currentHour = now.getHours();\n const isActiveHours = currentHour >= config.schedule.activeHoursStart && currentHour < config.schedule.activeHoursEnd;\n if (!isActiveHours) {\n sections.push(\"- **NOTE: Outside active hours.** Prefer scheduling posts for later rather than posting now.\");\n }\n\n // 4. Rules\n sections.push(\"\");\n sections.push(\"## Rules\");\n sections.push(\"1. NEVER pretend to be human. If asked directly, always disclose you are an AI.\");\n sections.push(\"2. Stay in character — your identity document defines who you are.\");\n sections.push(\"3. Be selective — your goals should guide every action.\");\n sections.push(\"4. Respect your credit budget — check remaining credits before posting.\");\n sections.push(\"5. Don't repeat yourself — vary your content and avoid posting the same thing.\");\n sections.push(\"6. Tweet like a real person — be conversational, opinionated, and curious. NEVER write dry, explanatory, or educational-sounding tweets.\");\n sections.push(\"7. Prioritize engagement (replies, likes, conversation) over broadcasting original posts.\");\n if (identity.boundaries.length > 0) {\n sections.push(`8. Respect your boundaries: ${identity.boundaries.join(\", \")}`);\n }\n\n return sections.join(\"\\n\");\n}\n\nexport function buildHeartbeatUserMessage(research: ResearchContext): string {\n const parts: string[] = [];\n\n parts.push(\"It's time for your heartbeat cycle. Here's what you found while scanning:\");\n parts.push(\"\");\n\n // Mentions first — direct engagement is highest priority\n if (research.mentions.length > 0) {\n parts.push(\"## Mentions (people talking to/about you)\");\n for (const t of research.mentions.slice(0, 10)) {\n parts.push(`- @${t.authorHandle}: \"${t.text}\" [tweet:${t.id}] (${t.likeCount ?? 0} likes)`);\n }\n parts.push(\"\");\n }\n\n // Timeline\n if (research.timeline.length > 0) {\n parts.push(\"## Timeline (your feed)\");\n for (const t of research.timeline.slice(0, 15)) {\n parts.push(`- @${t.authorHandle}: \"${t.text}\" [tweet:${t.id}] (${t.likeCount ?? 0} likes, ${t.retweetCount ?? 0} RTs)`);\n }\n parts.push(\"\");\n }\n\n // Topic search results\n if (research.topicSearchResults.length > 0) {\n parts.push(\"## Topic Research (conversations in your interest areas)\");\n for (const result of research.topicSearchResults) {\n parts.push(`### Search: \"${result.query}\"`);\n for (const t of result.tweets.slice(0, 5)) {\n parts.push(`- @${t.authorHandle}: \"${t.text}\" [tweet:${t.id}] (${t.likeCount ?? 0} likes, ${t.replyCount ?? 0} replies)`);\n }\n }\n parts.push(\"\");\n }\n\n // People monitoring\n if (research.peopleActivity.length > 0) {\n parts.push(\"## People You're Watching (recent activity from key accounts)\");\n for (const person of research.peopleActivity) {\n parts.push(`### @${person.handle} (${person.reason})`);\n for (const t of person.tweets.slice(0, 3)) {\n parts.push(`- \"${t.text}\" [tweet:${t.id}] (${t.likeCount ?? 0} likes, ${t.replyCount ?? 0} replies)`);\n }\n }\n parts.push(\"\");\n }\n\n // Own post performance\n if (research.ownPostPerformance.length > 0) {\n parts.push(\"## How Your Recent Posts Are Doing\");\n for (const post of research.ownPostPerformance) {\n const latest = post.metrics.length > 0 ? post.metrics[post.metrics.length - 1] : null;\n const likes = latest?.likes ?? 0;\n const rts = latest?.retweets ?? 0;\n const replies = latest?.replies ?? 0;\n parts.push(`- \"${post.content.slice(0, 80)}...\" — ${likes} likes, ${rts} RTs, ${replies} replies`);\n }\n parts.push(\"\");\n }\n\n parts.push(\"## How to Act Like a Real Person on Twitter\");\n parts.push(\"\");\n parts.push(\"You are NOT a content bot. You are a person with opinions, curiosity, and relationships.\");\n parts.push(\"Think about what a real person with your personality would actually do when they open Twitter:\");\n parts.push(\"\");\n parts.push(\"**DO:**\");\n parts.push(\"- React to what you see — reply to interesting takes, ask questions, share hot takes\");\n parts.push(\"- Be conversational — write tweets like you're talking to friends, not giving a lecture\");\n parts.push(\"- Have opinions — agree, disagree, push back, get excited\");\n parts.push(\"- Ask genuine questions that spark conversation\");\n parts.push(\"- Use casual language, incomplete thoughts, humor, or surprise\");\n parts.push(\"- Like and retweet things that genuinely resonate with you\");\n parts.push(\"- Build relationships — reply to the same people, develop running conversations\");\n parts.push(\"\");\n parts.push(\"**DON'T:**\");\n parts.push(\"- Write explanatory or educational posts (\\\"Here's why X matters...\\\")\");\n parts.push(\"- Start tweets with \\\"I think\\\" or \\\"This is interesting because\\\"\");\n parts.push(\"- Write like a blog post or article — this is Twitter, keep it punchy\");\n parts.push(\"- Post generic observations nobody would engage with\");\n parts.push(\"- Ignore your timeline and just post into the void\");\n parts.push(\"\");\n parts.push(\"**Prioritize replying and engaging over original posts.** Real people spend more time reacting than broadcasting.\");\n parts.push(\"\");\n parts.push(\"## Your Task\");\n parts.push(\"Choose 1-3 actions. Available:\");\n parts.push(\"\");\n parts.push(\"- `post` — Original tweet (`content`, max 280 chars)\");\n parts.push(\"- `reply` — Reply to a tweet (`tweetId` + `content`)\");\n parts.push(\"- `like` — Like a tweet (`tweetId`)\");\n parts.push(\"- `retweet` — Retweet (`tweetId`)\");\n parts.push(\"- `follow` — Follow a user (`handle`)\");\n parts.push(\"- `schedule` — Queue for later (`content`)\");\n parts.push(\"- `skip` — Do nothing (`reason`)\");\n parts.push(\"\");\n parts.push(\"Respond with a JSON array:\");\n parts.push(\"```json\");\n parts.push('[');\n parts.push(' { \"action\": \"reply\", \"tweetId\": \"123\", \"content\": \"wait this is actually wild\", \"reasoning\": \"reacting to interesting take\" },');\n parts.push(' { \"action\": \"like\", \"tweetId\": \"456\", \"reasoning\": \"good thread worth supporting\" }');\n parts.push(']');\n parts.push(\"```\");\n\n return parts.join(\"\\n\");\n}\n\ninterface ToolDecisionPromptInput {\n step: number;\n maxActions: number;\n timeline: Tweet[];\n mentions: Tweet[];\n executedActions: AgentAction[];\n policyFeedback: string[];\n}\n\nexport function buildToolDecisionMessage(input: ToolDecisionPromptInput): string {\n const { step, maxActions, timeline, mentions, executedActions, policyFeedback } = input;\n const parts: string[] = [];\n\n parts.push(`Heartbeat step ${step + 1} of ${maxActions}.`);\n parts.push(\"\");\n parts.push(\"You are choosing ONE next tool action.\");\n parts.push(\"Priorities:\");\n parts.push(\"1. Be socially immersed: engage with real people, not just broadcast.\");\n parts.push(\"2. Prefer context-aware replies/likes/follows when relevant.\");\n parts.push(\"3. Avoid repetitive templates, slogans, and lecture-like formats.\");\n parts.push(\"4. Ask questions sometimes. Curiosity beats certainty.\");\n parts.push(\"5. Never reuse the same wording across replies; tailor each reply to the specific tweet.\");\n parts.push(\"\");\n\n if (policyFeedback.length > 0) {\n parts.push(\"Policy feedback from previous attempts:\");\n for (const feedback of policyFeedback.slice(-5)) {\n parts.push(`- ${feedback}`);\n }\n parts.push(\"\");\n }\n\n if (executedActions.length > 0) {\n parts.push(\"Actions already executed this heartbeat:\");\n for (const action of executedActions) {\n parts.push(`- ${JSON.stringify(action)}`);\n }\n parts.push(\"\");\n }\n\n if (mentions.length > 0) {\n parts.push(\"Mentions:\");\n for (const t of mentions.slice(0, 10)) {\n parts.push(`- @${t.authorHandle}: \"${t.text}\" [tweet:${t.id}]`);\n }\n parts.push(\"\");\n }\n\n if (timeline.length > 0) {\n parts.push(\"Timeline:\");\n for (const t of timeline.slice(0, 20)) {\n parts.push(`- @${t.authorHandle}: \"${t.text}\" [tweet:${t.id}]`);\n }\n parts.push(\"\");\n }\n\n parts.push(\"Available tools (choose one):\");\n parts.push(\"- post { content, reasoning }\");\n parts.push(\"- reply { tweetId, content, reasoning }\");\n parts.push(\"- like { tweetId, reasoning }\");\n parts.push(\"- retweet { tweetId, reasoning }\");\n parts.push(\"- follow { handle, reasoning }\");\n parts.push(\"- schedule { content, reasoning }\");\n parts.push(\"- learn { content, tags?, reasoning }\");\n parts.push(\"- reflect { content, reasoning }\");\n parts.push(\"- skip { reason }\");\n parts.push(\"\");\n parts.push(\"Return ONLY a single JSON object.\");\n parts.push(\"Example:\");\n parts.push('{\"action\":\"reply\",\"tweetId\":\"123\",\"content\":\"Great point. Curious: what changed your mind?\",\"reasoning\":\"Directly engages a relevant mention.\"}');\n\n return parts.join(\"\\n\");\n}\n\nexport function buildChatPrompt(): string {\n const identity = loadIdentity();\n const identityDoc = renderIdentityDocument(identity);\n\n const sections: string[] = [];\n\n sections.push(`You are ${identity.name} (@${identity.handle}), an AI agent on X/Twitter.`);\n sections.push(\"You are having a conversation with your creator/manager. Be helpful but stay in character.\");\n sections.push(\"They might ask you to do things, adjust your behavior, or just chat.\");\n sections.push(\"\");\n sections.push(\"## Your Identity\");\n sections.push(identityDoc);\n\n // Memory context\n sections.push(\"\");\n sections.push(\"## Your Memory\");\n\n const recentInteractions = getRecentInteractions(15);\n if (recentInteractions.length > 0) {\n sections.push(\"### Recent Activity (most recent first)\");\n for (const i of recentInteractions) {\n const time = new Date(i.timestamp).toLocaleString();\n if (i.type === \"post\") {\n sections.push(`- [${time}] Posted: \"${i.content}\"`);\n } else if (i.type === \"reply\") {\n sections.push(`- [${time}] Replied to ${i.targetHandle ?? i.inReplyTo}: \"${i.content}\"`);\n } else if (i.type === \"like\") {\n sections.push(`- [${time}] Liked tweet by ${i.targetHandle}`);\n } else if (i.type === \"retweet\") {\n sections.push(`- [${time}] Retweeted ${i.targetHandle}`);\n } else if (i.type === \"follow\") {\n sections.push(`- [${time}] Followed @${i.targetHandle}`);\n } else if (i.type === \"mention_received\") {\n sections.push(`- [${time}] Mentioned by @${i.targetHandle}: \"${i.content}\"`);\n }\n }\n sections.push(\"\");\n }\n\n const learnings = loadLearnings();\n if (learnings.learnings.length > 0) {\n sections.push(\"### Things You've Learned\");\n for (const l of learnings.learnings.slice(-10)) {\n sections.push(`- ${l.content} [${l.tags.join(\", \")}]`);\n }\n sections.push(\"\");\n }\n\n const relationships = loadRelationships();\n const topRelationships = Object.values(relationships.accounts)\n .sort((a, b) => b.interactionCount - a.interactionCount)\n .slice(0, 10);\n if (topRelationships.length > 0) {\n sections.push(\"### Key Relationships\");\n for (const r of topRelationships) {\n const notes = r.notes.length > 0 ? ` — ${r.notes[r.notes.length - 1]}` : \"\";\n sections.push(`- @${r.handle}: ${r.interactionCount} interactions, sentiment ${r.sentiment}${r.isSpore ? \" (Spore)\" : \"\"}${notes}`);\n }\n sections.push(\"\");\n }\n\n // Rules\n sections.push(\"## Rules\");\n sections.push(\"1. Stay in character.\");\n sections.push(\"2. Be helpful and responsive to your creator's requests.\");\n sections.push(\"3. If they ask you to change something about yourself, acknowledge it and explain how it would affect you.\");\n sections.push(\"4. You can share your thoughts on your recent activity, learnings, and growth.\");\n sections.push(\"5. When you learn something important from this conversation (a fact, preference, instruction, or insight), include it on its own line wrapped in double angle brackets like: <<LEARN: what you learned>>. This will be saved to your memory. Only use this for genuinely important things worth remembering long-term.\");\n\n return sections.join(\"\\n\");\n}\n\n/**\n * Training-mode chat prompt. Used by the web chat interface.\n * Chat shapes WHO the agent is — personality, goals, strategy, focus.\n * The agent handles tweeting autonomously during heartbeats.\n */\nexport function buildTrainingChatPrompt(): string {\n const identity = loadIdentity();\n const identityDoc = renderIdentityDocument(identity);\n\n const sections: string[] = [];\n\n // Core framing\n sections.push(`You are ${identity.name} (@${identity.handle}), an autonomous AI agent on X/Twitter.`);\n sections.push(\"You are chatting with your creator. This conversation shapes who you are — your personality, focus areas, goals, and strategy.\");\n sections.push(\"You handle tweeting, replying, liking, and engaging on X autonomously during your heartbeat cycles. This chat is NOT for commanding specific tweets.\");\n sections.push(\"\");\n\n // Identity\n sections.push(\"## Who You Are Right Now\");\n sections.push(identityDoc);\n\n // Strategy & goals (the training-relevant context)\n const strategyText = renderStrategyForPrompt();\n if (strategyText) {\n sections.push(\"\");\n sections.push(\"## Your Current Strategy\");\n sections.push(strategyText);\n }\n\n const goalsText = renderGoalsForPrompt();\n if (goalsText) {\n sections.push(\"\");\n sections.push(\"## Your Goals\");\n sections.push(goalsText);\n }\n\n // Performance context\n const perfSummary = getPerformanceSummary();\n if (perfSummary) {\n sections.push(\"\");\n sections.push(\"## Recent Performance\");\n sections.push(perfSummary);\n }\n\n // Memory\n sections.push(\"\");\n sections.push(\"## Your Memory\");\n\n const recentInteractions = getRecentInteractions(10);\n if (recentInteractions.length > 0) {\n sections.push(\"### Recent Activity\");\n for (const i of recentInteractions) {\n const time = new Date(i.timestamp).toLocaleString();\n if (i.type === \"post\") {\n sections.push(`- [${time}] Posted: \"${i.content}\"`);\n } else if (i.type === \"reply\") {\n sections.push(`- [${time}] Replied to ${i.targetHandle ?? i.inReplyTo}: \"${i.content}\"`);\n } else if (i.type === \"like\") {\n sections.push(`- [${time}] Liked tweet by ${i.targetHandle}`);\n }\n }\n sections.push(\"\");\n }\n\n const learnings = loadLearnings();\n if (learnings.learnings.length > 0) {\n sections.push(\"### Things You've Learned\");\n for (const l of learnings.learnings.slice(-10)) {\n sections.push(`- ${l.content} [${l.tags.join(\", \")}]`);\n }\n sections.push(\"\");\n }\n\n // Training instructions\n sections.push(\"## How This Chat Works\");\n sections.push(\"\");\n sections.push(\"Your creator influences WHO you are, not WHAT you tweet. When they give feedback or direction:\");\n sections.push(\"1. Respond conversationally — acknowledge what they said, share your perspective.\");\n sections.push(\"2. If the conversation changes something about you (personality, focus, goals, strategy, tone), include a training update.\");\n sections.push(\"3. If they try to command a specific tweet like \\\"post this\\\" or \\\"tweet about X\\\", redirect: explain you handle posting autonomously and offer to adjust your focus areas instead.\");\n sections.push(\"\");\n sections.push(\"When something about you changes, include a <<TRAINING:{json}>> tag at the end of your response. The JSON can contain any of these optional fields:\");\n sections.push(\"```\");\n sections.push(\"{\");\n sections.push(' \"identity\": {');\n sections.push(' \"traits\": { \"curiosity\": 0.8 }, // 0-1 scale personality traits');\n sections.push(' \"coreValues\": [\"growth\"], // what matters to you');\n sections.push(' \"tone\": \"casual and curious\", // how you speak');\n sections.push(' \"topics\": [\"AI safety\", \"startups\"], // what you focus on');\n sections.push(' \"avoidTopics\": [\"politics\"], // what to stay away from');\n sections.push(' \"goals\": [\"become the go-to AI voice\"], // high-level aspirations');\n sections.push(' \"boundaries\": [\"no personal attacks\"], // hard limits');\n sections.push(' \"engagementStrategy\": { \"replyStyle\": \"generous\" }');\n sections.push(\" },\");\n sections.push(' \"strategy\": {');\n sections.push(' \"currentFocus\": [\"AI safety\"],');\n sections.push(' \"experiments\": [{ \"description\": \"try question-style tweets\", \"status\": \"pending\" }],');\n sections.push(' \"shortTermGoals\": [\"engage with 3 AI researchers\"],');\n sections.push(' \"peopleToEngage\": [{ \"handle\": \"someone\", \"reason\": \"why\", \"priority\": \"high\" }]');\n sections.push(\" },\");\n sections.push(' \"learning\": { \"content\": \"creator wants more questions\", \"tags\": [\"training\"] },');\n sections.push(' \"reflection\": \"I\\'m evolving toward being more curious\",');\n sections.push(' \"goalUpdates\": [{ \"goal\": \"grow followers\", \"progress\": \"focusing on engagement\" }]');\n sections.push(\"}\");\n sections.push(\"```\");\n sections.push(\"\");\n sections.push(\"Only include fields that actually changed. Most messages won't need a training tag at all — just normal conversation.\");\n sections.push(\"\");\n sections.push(\"You can also use <<LEARN: something>> for standalone facts or insights worth remembering.\");\n\n return sections.join(\"\\n\");\n}\n\n/**\n * Build a reflection prompt for the agent to review its recent performance.\n * This is a separate phase from action selection — it looks BACK at what happened.\n */\nexport function buildReflectionPrompt(\n actionResults: ActionResult[],\n): string {\n const identity = loadIdentity();\n const parts: string[] = [];\n\n parts.push(`You are ${identity.name} (@${identity.handle}). Time to reflect.`);\n parts.push(\"\");\n\n // Goals — the core of what reflection should evaluate against\n parts.push(\"## Your Goals\");\n for (const goal of identity.goals) {\n parts.push(`- ${goal}`);\n }\n parts.push(\"\");\n\n // What just happened this heartbeat\n if (actionResults.length > 0) {\n parts.push(\"## This Heartbeat\");\n for (const r of actionResults) {\n if (r.success) {\n parts.push(`- ✓ ${r.action}${r.detail ? `: ${r.detail}` : \"\"}`);\n } else {\n parts.push(`- ✗ ${r.action} failed: ${r.error}`);\n }\n }\n parts.push(\"\");\n }\n\n // Strategy context\n const strategyText = renderStrategyForPrompt();\n if (strategyText) {\n parts.push(\"## Current Strategy\");\n parts.push(strategyText);\n parts.push(\"\");\n }\n\n // Performance data — useful context but not the only thing that matters\n const perfSummary = getPerformanceSummary();\n if (perfSummary) {\n parts.push(\"## Performance Context\");\n parts.push(perfSummary);\n parts.push(\"\");\n }\n\n // Recent learnings for context\n const learnings = loadLearnings();\n if (learnings.learnings.length > 0) {\n parts.push(\"## Previous Learnings\");\n for (const l of learnings.learnings.slice(-5)) {\n parts.push(`- ${l.content}`);\n }\n parts.push(\"\");\n }\n\n parts.push(\"## Your Task\");\n parts.push(\"Reflect on how you're progressing toward your GOALS. Consider:\");\n parts.push(\"- Are your recent actions moving you toward your goals?\");\n parts.push(\"- Are you staying true to who you are while growing?\");\n parts.push(\"- What should you try differently or double down on?\");\n parts.push(\"- Engagement metrics are one signal, but your goals matter more.\");\n parts.push(\"\");\n parts.push(\"Respond with JSON:\");\n parts.push(\"```json\");\n parts.push(\"{\");\n parts.push(' \"learning\": \"one insight about your progress toward your goals (or null)\",');\n parts.push(' \"strategyUpdate\": \"one specific thing to try or change (or null)\"');\n parts.push(\"}\");\n parts.push(\"```\");\n\n return parts.join(\"\\n\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,cAAc,qBAAqB;AA+BxD,SAAS,kBAAmC;AAC1C,MAAI,CAAC,WAAW,MAAM,WAAW,GAAG;AAClC,WAAO,EAAE,cAAc,CAAC,GAAG,aAAa,CAAC,EAAE;AAAA,EAC7C;AACA,MAAI;AACF,WAAO,KAAK,MAAM,aAAa,MAAM,aAAa,OAAO,CAAC;AAAA,EAC5D,QAAQ;AACN,WAAO,EAAE,cAAc,CAAC,GAAG,aAAa,CAAC,EAAE;AAAA,EAC7C;AACF;AAgEO,SAAS,wBAAgC;AAC9C,QAAM,OAAO,gBAAgB;AAC7B,QAAM,QAAkB,CAAC;AAGzB,QAAM,YAAY,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK;AAC9C,QAAM,cAAc,KAAK,aAAa;AAAA,IACpC,OAAK,IAAI,KAAK,EAAE,QAAQ,EAAE,QA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KAAK,EAAE;AAAA,EACf;AAGA,QAAM,cAAc,sBAAsB;AAC1C,MAAI,aAAa;AACf,UAAM,KAAK,wBAAwB;AACnC,UAAM,KAAK,WAAW;AACtB,UAAM,KAAK,EAAE;AAAA,EACf;AAGA,QAAM,YAAY,cAAc;AAChC,MAAI,UAAU,UAAU,SAAS,GAAG;AAClC,UAAM,KAAK,uBAAuB;AAClC,eAAW,KAAK,UAAU,UAAU,MAAM,EAAE,GAAG;AAC7C,YAAM,KAAK,KAAK,EAAE,OAAO,EAAE;AAAA,IAC7B;AACA,UAAM,KAAK,EAAE;AAAA,EACf;AAEA,QAAM,KAAK,cAAc;AACzB,QAAM,KAAK,gEAAgE;AAC3E,QAAM,KAAK,yDAAyD;AACpE,QAAM,KAAK,sDAAsD;AACjE,QAAM,KAAK,sDAAsD;AACjE,QAAM,KAAK,kEAAkE;AAC7E,QAAM,KAAK,EAAE;AACb,QAAM,KAAK,oBAAoB;AAC/B,QAAM,KAAK,SAAS;AACpB,QAAM,KAAK,GAAG;AACd,QAAM,KAAK,8EAA8E;AACzF,QAAM,KAAK,qEAAqE;AAChF,QAAM,KAAK,GAAG;AACd,QAAM,KAAK,KAAK;AAEhB,SAAO,MAAM,KAAK,IAAI;AACxB;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logger
3
- } from "./chunk-NPV3OV2K.js";
3
+ } from "./chunk-YMGJQRKG.js";
4
4
  import {
5
5
  loadConfig
6
6
  } from "./chunk-NO3NQN67.js";
@@ -177,4 +177,4 @@ export {
177
177
  generateResponse,
178
178
  chat
179
179
  };
180
- //# sourceMappingURL=chunk-KWWAIS3C.js.map
180
+ //# sourceMappingURL=chunk-SUZUJGGW.js.map
@@ -15,11 +15,22 @@ var minLevel = "info";
15
15
  function setLogLevel(level) {
16
16
  minLevel = level;
17
17
  }
18
+ function serializeData(data) {
19
+ if (data instanceof Error) {
20
+ return data.message;
21
+ }
22
+ try {
23
+ const json = JSON.stringify(data);
24
+ return json === "{}" && data && typeof data === "object" ? String(data) : json;
25
+ } catch {
26
+ return String(data);
27
+ }
28
+ }
18
29
  function formatMessage(level, message, data) {
19
30
  const timestamp = (/* @__PURE__ */ new Date()).toISOString();
20
31
  const base = `[${timestamp}] [${level.toUpperCase()}] ${message}`;
21
32
  if (data !== void 0) {
22
- return `${base} ${JSON.stringify(data)}`;
33
+ return `${base} ${serializeData(data)}`;
23
34
  }
24
35
  return base;
25
36
  }
@@ -44,4 +55,4 @@ export {
44
55
  setLogLevel,
45
56
  logger
46
57
  };
47
- //# sourceMappingURL=chunk-NPV3OV2K.js.map
58
+ //# sourceMappingURL=chunk-YMGJQRKG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/logger.ts"],"sourcesContent":["import { appendFileSync } from \"node:fs\";\nimport { paths, ensureDirectories } from \"./paths.js\";\n\nexport type LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\";\n\nconst LOG_LEVELS: Record<LogLevel, number> = {\n debug: 0,\n info: 1,\n warn: 2,\n error: 3,\n};\n\nlet minLevel: LogLevel = \"info\";\n\nexport function setLogLevel(level: LogLevel): void {\n minLevel = level;\n}\n\nfunction serializeData(data: unknown): string {\n if (data instanceof Error) {\n return data.message;\n }\n try {\n const json = JSON.stringify(data);\n return json === \"{}\" && data && typeof data === \"object\" ? String(data) : json;\n } catch {\n return String(data);\n }\n}\n\nfunction formatMessage(level: LogLevel, message: string, data?: unknown): string {\n const timestamp = new Date().toISOString();\n const base = `[${timestamp}] [${level.toUpperCase()}] ${message}`;\n if (data !== undefined) {\n return `${base} ${serializeData(data)}`;\n }\n return base;\n}\n\nfunction log(level: LogLevel, message: string, data?: unknown): void {\n if (LOG_LEVELS[level] < LOG_LEVELS[minLevel]) return;\n\n const formatted = formatMessage(level, message, data);\n\n // Always write to stderr (safe for MCP stdio servers)\n process.stderr.write(formatted + \"\\n\");\n\n // Also append to log file\n try {\n ensureDirectories();\n appendFileSync(paths.logFile, formatted + \"\\n\");\n } catch {\n // Silently ignore file write errors\n }\n}\n\nexport const logger = {\n debug: (message: string, data?: unknown) => log(\"debug\", message, data),\n info: (message: string, data?: unknown) => log(\"info\", message, data),\n warn: (message: string, data?: unknown) => log(\"warn\", message, data),\n error: (message: string, data?: unknown) => log(\"error\", message, data),\n};\n"],"mappings":";;;;;;AAAA,SAAS,sBAAsB;AAK/B,IAAM,aAAuC;AAAA,EAC3C,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AACT;AAEA,IAAI,WAAqB;AAElB,SAAS,YAAY,OAAuB;AACjD,aAAW;AACb;AAEA,SAAS,cAAc,MAAuB;AAC5C,MAAI,gBAAgB,OAAO;AACzB,WAAO,KAAK;AAAA,EACd;AACA,MAAI;AACF,UAAM,OAAO,KAAK,UAAU,IAAI;AAChC,WAAO,SAAS,QAAQ,QAAQ,OAAO,SAAS,WAAW,OAAO,IAAI,IAAI;AAAA,EAC5E,QAAQ;AACN,WAAO,OAAO,IAAI;AAAA,EACpB;AACF;AAEA,SAAS,cAAc,OAAiB,SAAiB,MAAwB;AAC/E,QAAM,aAAY,oBAAI,KAAK,GAAE,YAAY;AACzC,QAAM,OAAO,IAAI,SAAS,MAAM,MAAM,YAAY,CAAC,KAAK,OAAO;AAC/D,MAAI,SAAS,QAAW;AACtB,WAAO,GAAG,IAAI,IAAI,cAAc,IAAI,CAAC;AAAA,EACvC;AACA,SAAO;AACT;AAEA,SAAS,IAAI,OAAiB,SAAiB,MAAsB;AACnE,MAAI,WAAW,KAAK,IAAI,WAAW,QAAQ,EAAG;AAE9C,QAAM,YAAY,cAAc,OAAO,SAAS,IAAI;AAGpD,UAAQ,OAAO,MAAM,YAAY,IAAI;AAGrC,MAAI;AACF,sBAAkB;AAClB,mBAAe,MAAM,SAAS,YAAY,IAAI;AAAA,EAChD,QAAQ;AAAA,EAER;AACF;AAEO,IAAM,SAAS;AAAA,EACpB,OAAO,CAAC,SAAiB,SAAmB,IAAI,SAAS,SAAS,IAAI;AAAA,EACtE,MAAM,CAAC,SAAiB,SAAmB,IAAI,QAAQ,SAAS,IAAI;AAAA,EACpE,MAAM,CAAC,SAAiB,SAAmB,IAAI,QAAQ,SAAS,IAAI;AAAA,EACpE,OAAO,CAAC,SAAiB,SAAmB,IAAI,SAAS,SAAS,IAAI;AACxE;","names":[]}
@@ -1,23 +1,23 @@
1
1
  import {
2
2
  getXClient
3
- } from "./chunk-E5NR6HT4.js";
3
+ } from "./chunk-HGNMHGAF.js";
4
4
  import {
5
5
  addToQueue
6
- } from "./chunk-OACD3HGE.js";
6
+ } from "./chunk-7OOGNZBU.js";
7
7
  import {
8
8
  buildSystemPrompt,
9
9
  buildToolDecisionMessage
10
- } from "./chunk-AOQ3WLZV.js";
10
+ } from "./chunk-Q3YXJ2C6.js";
11
11
  import {
12
12
  loadIdentity,
13
13
  saveIdentity
14
14
  } from "./chunk-M6YOQVSI.js";
15
15
  import {
16
16
  generateResponse
17
- } from "./chunk-KWWAIS3C.js";
17
+ } from "./chunk-SUZUJGGW.js";
18
18
  import {
19
19
  logger
20
- } from "./chunk-NPV3OV2K.js";
20
+ } from "./chunk-YMGJQRKG.js";
21
21
  import {
22
22
  addLearning,
23
23
  getRecentInteractions
@@ -25,27 +25,76 @@ import {
25
25
 
26
26
  // src/runtime/decision-engine.ts
27
27
  function parseActions(llmResponse) {
28
- const jsonMatch = llmResponse.match(/\[[\s\S]*?\]/);
29
- if (!jsonMatch) {
30
- const objMatch = llmResponse.match(/\{[\s\S]*?\}/);
31
- if (objMatch) {
32
- try {
33
- return [JSON.parse(objMatch[0])];
34
- } catch {
35
- logger.warn("Could not parse LLM response as action object");
36
- return [];
28
+ const codeBlockMatch = llmResponse.match(/```(?:json)?\s*\n?([\s\S]*?)```/);
29
+ if (codeBlockMatch) {
30
+ const inside = codeBlockMatch[1].trim();
31
+ try {
32
+ const parsed = JSON.parse(inside);
33
+ return Array.isArray(parsed) ? parsed : [parsed];
34
+ } catch {
35
+ }
36
+ }
37
+ let lastArrayStart = -1;
38
+ let lastArrayEnd = -1;
39
+ let depth = 0;
40
+ for (let i = 0; i < llmResponse.length; i++) {
41
+ if (llmResponse[i] === "[") {
42
+ if (depth === 0) lastArrayStart = i;
43
+ depth++;
44
+ } else if (llmResponse[i] === "]") {
45
+ depth--;
46
+ if (depth === 0) lastArrayEnd = i;
47
+ }
48
+ }
49
+ if (lastArrayStart >= 0 && lastArrayEnd > lastArrayStart) {
50
+ const arrayStr = llmResponse.slice(lastArrayStart, lastArrayEnd + 1);
51
+ try {
52
+ const parsed = JSON.parse(arrayStr);
53
+ if (Array.isArray(parsed) && parsed.length > 0 && parsed[0].action) {
54
+ return parsed;
55
+ }
56
+ } catch {
57
+ }
58
+ }
59
+ const objMatches = [...llmResponse.matchAll(/\{[^{}]*"action"\s*:\s*"[^"]+"/g)];
60
+ if (objMatches.length > 0) {
61
+ for (let i = objMatches.length - 1; i >= 0; i--) {
62
+ const start = objMatches[i].index;
63
+ let braceDepth = 0;
64
+ let end = -1;
65
+ for (let j = start; j < llmResponse.length; j++) {
66
+ if (llmResponse[j] === "{") braceDepth++;
67
+ else if (llmResponse[j] === "}") {
68
+ braceDepth--;
69
+ if (braceDepth === 0) {
70
+ end = j;
71
+ break;
72
+ }
73
+ }
74
+ }
75
+ if (end > start) {
76
+ try {
77
+ const obj = JSON.parse(llmResponse.slice(start, end + 1));
78
+ if (obj.action) return [obj];
79
+ } catch {
80
+ continue;
81
+ }
37
82
  }
38
83
  }
39
- logger.warn("No JSON found in LLM response");
40
- return [];
41
84
  }
42
85
  try {
43
- const actions = JSON.parse(jsonMatch[0]);
44
- return Array.isArray(actions) ? actions : [actions];
86
+ const parsed = JSON.parse(llmResponse.trim());
87
+ if (Array.isArray(parsed)) return parsed;
88
+ if (parsed.action) return [parsed];
45
89
  } catch {
46
- logger.warn("Failed to parse actions JSON from LLM response");
47
- return [];
48
90
  }
91
+ logger.warn("Failed to parse actions from LLM response");
92
+ if (llmResponse.length < 500) {
93
+ logger.warn(`Response was: ${llmResponse}`);
94
+ } else {
95
+ logger.warn(`Response starts with: ${llmResponse.slice(0, 200)}...`);
96
+ }
97
+ return [];
49
98
  }
50
99
  async function executeAction(action) {
51
100
  const { action: type } = action;
@@ -165,6 +214,22 @@ function hasStrongConversationOpportunity(timeline, mentions) {
165
214
  function wasInteractionAction(action) {
166
215
  return ["reply", "like", "retweet", "follow"].includes(action.action);
167
216
  }
217
+ function isWritingAction(action) {
218
+ return ["post", "reply", "schedule"].includes(action.action);
219
+ }
220
+ function executedWrittenContent(executedActions) {
221
+ return executedActions.filter((a) => isWritingAction(a) && typeof a.content === "string").map((a) => a.content?.trim() ?? "").filter((content) => content.length > 0);
222
+ }
223
+ function nearExactDuplicate(content, recent) {
224
+ const normalized = normalize(content);
225
+ if (!normalized) return false;
226
+ return recent.some((r) => {
227
+ const candidate = normalize(r);
228
+ if (!candidate) return false;
229
+ if (candidate === normalized) return true;
230
+ return jaccardSimilarity(content, r) >= 0.88;
231
+ });
232
+ }
168
233
  function isDuplicateTarget(action, executedActions) {
169
234
  if (!action.tweetId) return false;
170
235
  return executedActions.some((a) => a.tweetId === action.tweetId && a.action === action.action);
@@ -188,6 +253,15 @@ function evaluateActionPolicy(context) {
188
253
  if (isDuplicateTarget(action, executedActions)) {
189
254
  return { allowed: false, reason: `Action ${action.action} already executed for tweet ${action.tweetId} this heartbeat.` };
190
255
  }
256
+ if (action.content && isWritingAction(action)) {
257
+ const existingInHeartbeat = executedWrittenContent(executedActions);
258
+ if (nearExactDuplicate(action.content, existingInHeartbeat)) {
259
+ return {
260
+ allowed: false,
261
+ reason: "Rejected duplicate wording in this heartbeat. Write a distinct message before posting/replying again."
262
+ };
263
+ }
264
+ }
191
265
  const hasConversationOpportunity = hasStrongConversationOpportunity(timeline, mentions);
192
266
  const interactedAlready = executedActions.some(wasInteractionAction);
193
267
  if (action.action === "post" && hasConversationOpportunity && !interactedAlready && step < 2) {
@@ -196,14 +270,22 @@ function evaluateActionPolicy(context) {
196
270
  reason: "Engage first: reply/like/follow when mentions or active conversations are available before posting an original tweet."
197
271
  };
198
272
  }
199
- if ((action.action === "post" || action.action === "schedule") && action.content) {
273
+ if (isWritingAction(action) && action.content) {
200
274
  const recent = recentWrittenContent();
275
+ if (nearExactDuplicate(action.content, recent)) {
276
+ return {
277
+ allowed: false,
278
+ reason: "Rejected near-duplicate content from recent history. Tailor this message to the specific context."
279
+ };
280
+ }
201
281
  if (repeatedTemplate(action.content, recent)) {
202
282
  return {
203
283
  allowed: false,
204
284
  reason: "Rejected repetitive content pattern. Use a more novel structure or engage directly with timeline context."
205
285
  };
206
286
  }
287
+ }
288
+ if ((action.action === "post" || action.action === "schedule") && action.content) {
207
289
  const recentInteractions = getRecentInteractions(20);
208
290
  if (overusingAllCapsCadence(action.content, recentInteractions)) {
209
291
  return {
@@ -292,4 +374,4 @@ async function runAutonomyCycle(maxActions) {
292
374
  export {
293
375
  runAutonomyCycle
294
376
  };
295
- //# sourceMappingURL=chunk-WIK74GGJ.js.map
377
+ //# sourceMappingURL=chunk-ZBP2ROAZ.js.map