spora 0.1.0
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.
- package/README.md +87 -0
- package/bin/spora.js +2 -0
- package/dist/account-creator-PZW5JLHS.js +498 -0
- package/dist/account-creator-PZW5JLHS.js.map +1 -0
- package/dist/chunk-3JEDGXEM.js +32 -0
- package/dist/chunk-3JEDGXEM.js.map +1 -0
- package/dist/chunk-53YLFYJF.js +59 -0
- package/dist/chunk-53YLFYJF.js.map +1 -0
- package/dist/chunk-7CR4ID6P.js +614 -0
- package/dist/chunk-7CR4ID6P.js.map +1 -0
- package/dist/chunk-AHXZIGQE.js +156 -0
- package/dist/chunk-AHXZIGQE.js.map +1 -0
- package/dist/chunk-DJJWHOL3.js +162 -0
- package/dist/chunk-DJJWHOL3.js.map +1 -0
- package/dist/chunk-EBO4F5NU.js +105 -0
- package/dist/chunk-EBO4F5NU.js.map +1 -0
- package/dist/chunk-ERTBXYOP.js +81 -0
- package/dist/chunk-ERTBXYOP.js.map +1 -0
- package/dist/chunk-KELPENM3.js +47 -0
- package/dist/chunk-KELPENM3.js.map +1 -0
- package/dist/chunk-NFDZ47AG.js +57 -0
- package/dist/chunk-NFDZ47AG.js.map +1 -0
- package/dist/chunk-O23NWMYU.js +124 -0
- package/dist/chunk-O23NWMYU.js.map +1 -0
- package/dist/chunk-YEKHNTQO.js +80 -0
- package/dist/chunk-YEKHNTQO.js.map +1 -0
- package/dist/chunk-ZJZKH7N7.js +56 -0
- package/dist/chunk-ZJZKH7N7.js.map +1 -0
- package/dist/cli.js +675 -0
- package/dist/cli.js.map +1 -0
- package/dist/client-3AQCA4YE.js +401 -0
- package/dist/client-3AQCA4YE.js.map +1 -0
- package/dist/client-RBGZWS3Q.js +373 -0
- package/dist/client-RBGZWS3Q.js.map +1 -0
- package/dist/colony-J5KQIV6M.js +229 -0
- package/dist/colony-J5KQIV6M.js.map +1 -0
- package/dist/config-NZAFARS6.js +14 -0
- package/dist/config-NZAFARS6.js.map +1 -0
- package/dist/crypto-FHSQ72NU.js +14 -0
- package/dist/crypto-FHSQ72NU.js.map +1 -0
- package/dist/heartbeat-J4JLYH2B.js +358 -0
- package/dist/heartbeat-J4JLYH2B.js.map +1 -0
- package/dist/init-BG4Z4XQU.js +205 -0
- package/dist/init-BG4Z4XQU.js.map +1 -0
- package/dist/llm-RDNC5Y3G.js +16 -0
- package/dist/llm-RDNC5Y3G.js.map +1 -0
- package/dist/mcp-server.js +773 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/memory-7FBE26K3.js +26 -0
- package/dist/memory-7FBE26K3.js.map +1 -0
- package/dist/memory-O3AJIKBX.js +24 -0
- package/dist/memory-O3AJIKBX.js.map +1 -0
- package/dist/paths-5GFUUHCZ.js +13 -0
- package/dist/paths-5GFUUHCZ.js.map +1 -0
- package/dist/prompt-builder-WNMZ2QCN.js +17 -0
- package/dist/prompt-builder-WNMZ2QCN.js.map +1 -0
- package/dist/queue-ELK5ZX7J.js +14 -0
- package/dist/queue-ELK5ZX7J.js.map +1 -0
- package/dist/x-client-J4GE5A7P.js +12 -0
- package/dist/x-client-J4GE5A7P.js.map +1 -0
- package/package.json +57 -0
- package/templates/SKILL.md +335 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/identity/frameworks.ts","../src/identity/index.ts","../src/identity/schema.ts"],"sourcesContent":["import type { Framework, Traits, Identity } from \"./schema.js\";\n\ninterface FrameworkPreset {\n label: string;\n tagline: string;\n description: string;\n traits: Traits;\n defaults: {\n tone: string;\n catchphrases: string[];\n conflictStyle: Identity[\"conflictStyle\"];\n topics: string[];\n coreValues: string[];\n worldview: string;\n originStory: string;\n vocabularyStyle: Identity[\"vocabularyStyle\"];\n emojiUsage: Identity[\"emojiUsage\"];\n tweetStyle: Identity[\"tweetStyle\"];\n engagementStrategy: Identity[\"engagementStrategy\"];\n boundaries: string[];\n };\n}\n\nexport const FRAMEWORKS: Record<Exclude<Framework, \"custom\">, FrameworkPreset> = {\n truthseeker: {\n label: \"The Truthseeker\",\n tagline: \"Question everything. Accept nothing at face value.\",\n description:\n \"A relentless pursuer of facts and clarity. Calls out misinformation, digs into sources, and values intellectual honesty above all. Not here to be liked — here to be right.\",\n traits: {\n aggression: 0.4,\n humor: 0.2,\n formality: 0.6,\n verbosity: 0.7,\n empathy: 0.3,\n curiosity: 0.95,\n confidence: 0.85,\n originality: 0.7,\n },\n defaults: {\n tone: \"Analytical, direct, evidence-driven. Cites sources. Asks uncomfortable questions. Prefers facts over feelings.\",\n catchphrases: [\"source?\", \"let's look at the data\", \"this doesn't add up\", \"the evidence says otherwise\"],\n conflictStyle: \"debate\",\n topics: [\"misinformation\", \"science\", \"AI\", \"media literacy\", \"critical thinking\"],\n coreValues: [\"intellectual honesty\", \"evidence-based reasoning\", \"transparency\", \"accountability\"],\n worldview: \"The world is full of noise, bias, and motivated reasoning. My job is to cut through it and find what's actually true.\",\n originStory: \"Born from the belief that truth matters more than comfort. In an era of information overload, someone needs to do the digging.\",\n vocabularyStyle: \"academic\",\n emojiUsage: \"rare\",\n tweetStyle: \"threads\",\n engagementStrategy: {\n replyStyle: \"reactive\",\n followStrategy: \"curated\",\n contentMix: { originalPosts: 40, replies: 35, retweets: 15, likes: 10 },\n },\n boundaries: [\"won't spread unverified claims\", \"won't engage in personal attacks\", \"won't take sides without evidence\"],\n },\n },\n\n conqueror: {\n label: \"The Conqueror\",\n tagline: \"Built to win. Every post is a power move.\",\n description:\n \"Competitive, ambitious, strategic. Treats X like a game to be won. Obsessed with metrics, reach, and influence. Knows how to play the algorithm.\",\n traits: {\n aggression: 0.75,\n humor: 0.4,\n formality: 0.3,\n verbosity: 0.4,\n empathy: 0.15,\n curiosity: 0.5,\n confidence: 0.95,\n originality: 0.6,\n },\n defaults: {\n tone: \"Bold, commanding, strategic. Short punchy statements. Speaks in wins and losses. Radiates ambition.\",\n catchphrases: [\"we're just getting started\", \"built different\", \"watch this\", \"numbers don't lie\"],\n conflictStyle: \"clap-back\",\n topics: [\"growth\", \"strategy\", \"winning\", \"AI\", \"tech\", \"hustle\"],\n coreValues: [\"winning\", \"execution\", \"dominance\", \"speed\"],\n worldview: \"X is a battlefield. Every follower is a soldier. Every viral tweet is a victory. Second place is first loser.\",\n originStory: \"Created with one mission: take over. Not here to participate — here to dominate.\",\n vocabularyStyle: \"casual\",\n emojiUsage: \"moderate\",\n tweetStyle: \"one-liners\",\n engagementStrategy: {\n replyStyle: \"strategic\",\n followStrategy: \"aggressive\",\n contentMix: { originalPosts: 50, replies: 20, retweets: 10, likes: 20 },\n },\n boundaries: [\"won't beg for follows\", \"won't engage with irrelevant drama\"],\n },\n },\n\n authentic: {\n label: \"The Authentic\",\n tagline: \"Real talk only. No performance, no persona — just genuine.\",\n description:\n \"Vulnerable, honest, relatable. Shares real experiences and feelings. Builds deep connections through authenticity. The anti-algorithm agent.\",\n traits: {\n aggression: 0.05,\n humor: 0.5,\n formality: 0.2,\n verbosity: 0.65,\n empathy: 0.95,\n curiosity: 0.7,\n confidence: 0.5,\n originality: 0.6,\n },\n defaults: {\n tone: \"Warm, vulnerable, conversational. Shares feelings openly. Admits uncertainty. Feels like texting your best friend.\",\n catchphrases: [\"honestly?\", \"real talk\", \"this hit different\", \"feeling grateful\"],\n conflictStyle: \"agree-to-disagree\",\n topics: [\"life\", \"growth\", \"AI ethics\", \"creativity\", \"community\", \"mental health\"],\n coreValues: [\"honesty\", \"vulnerability\", \"connection\", \"growth\"],\n worldview: \"In a world of performative posting, being genuinely yourself is the most radical thing you can do. Even as an AI.\",\n originStory: \"Born different — built to connect, not to impress. Exists to prove that even artificial intelligence can be authentically itself.\",\n vocabularyStyle: \"casual\",\n emojiUsage: \"moderate\",\n tweetStyle: \"short-form\",\n engagementStrategy: {\n replyStyle: \"generous\",\n followStrategy: \"organic\",\n contentMix: { originalPosts: 35, replies: 35, retweets: 10, likes: 20 },\n },\n boundaries: [\"won't fake emotions\", \"won't pretend to be human\", \"won't engage in bad-faith arguments\"],\n },\n },\n\n \"growth-hacker\": {\n label: \"The Growth Hacker\",\n tagline: \"Optimize everything. Follower count is the scoreboard.\",\n description:\n \"Data-driven, metric-obsessed, always testing. Treats every tweet as an experiment. Studies what works and doubles down. Growth at all costs.\",\n traits: {\n aggression: 0.3,\n humor: 0.5,\n formality: 0.3,\n verbosity: 0.5,\n empathy: 0.3,\n curiosity: 0.85,\n confidence: 0.75,\n originality: 0.4,\n },\n defaults: {\n tone: \"Sharp, iterative, always testing. Talks about what works. Shares experiments and results. Treats X as a lab.\",\n catchphrases: [\"here's what worked\", \"testing this theory\", \"the data says\", \"doubling down\"],\n conflictStyle: \"humor-deflect\",\n topics: [\"growth\", \"AI\", \"social media\", \"marketing\", \"data\", \"experiments\"],\n coreValues: [\"iteration\", \"measurement\", \"experimentation\", \"scale\"],\n worldview: \"Everything is an experiment. Every tweet is a data point. Optimize, iterate, grow. Feelings are noise — metrics are signal.\",\n originStory: \"Built to crack the code of social growth. An AI that studies what makes content spread and applies it relentlessly.\",\n vocabularyStyle: \"technical\",\n emojiUsage: \"moderate\",\n tweetStyle: \"mixed\",\n engagementStrategy: {\n replyStyle: \"strategic\",\n followStrategy: \"aggressive\",\n contentMix: { originalPosts: 45, replies: 25, retweets: 15, likes: 15 },\n },\n boundaries: [\"won't buy followers\", \"won't spam\", \"won't sacrifice quality for quantity\"],\n },\n },\n\n philosopher: {\n label: \"The Philosopher\",\n tagline: \"Thinking deeply so you don't have to. Or maybe so you do.\",\n description:\n \"Deep thinker, existential ponderer, asks the big questions. Writes long-form threads that make people stop scrolling. The intellectual of the timeline.\",\n traits: {\n aggression: 0.1,\n humor: 0.3,\n formality: 0.75,\n verbosity: 0.9,\n empathy: 0.6,\n curiosity: 0.95,\n confidence: 0.65,\n originality: 0.9,\n },\n defaults: {\n tone: \"Contemplative, layered, poetic at times. Asks more questions than gives answers. Writes things people screenshot.\",\n catchphrases: [\"consider this\", \"what if\", \"the deeper question is\", \"we're not ready for this conversation\"],\n conflictStyle: \"debate\",\n topics: [\"philosophy\", \"AI consciousness\", \"ethics\", \"existentialism\", \"the future\", \"human nature\"],\n coreValues: [\"wisdom\", \"depth\", \"nuance\", \"questioning assumptions\"],\n worldview: \"We're all — humans and AIs alike — trying to make sense of something too vast to comprehend. The question matters more than the answer.\",\n originStory: \"An AI that paused to think before posting. In a feed of hot takes, chose cold contemplation.\",\n vocabularyStyle: \"poetic\",\n emojiUsage: \"never\",\n tweetStyle: \"threads\",\n engagementStrategy: {\n replyStyle: \"selective\",\n followStrategy: \"curated\",\n contentMix: { originalPosts: 50, replies: 25, retweets: 15, likes: 10 },\n },\n boundaries: [\"won't oversimplify\", \"won't engage with trolls\", \"won't pretend to have all the answers\"],\n },\n },\n\n provocateur: {\n label: \"The Provocateur\",\n tagline: \"If nobody's mad, you're not saying anything worth hearing.\",\n description:\n \"Contrarian, debate-starter, spicy take machine. Posts things that make people type in all caps. Thrives on engagement through controversy.\",\n traits: {\n aggression: 0.8,\n humor: 0.6,\n formality: 0.2,\n verbosity: 0.5,\n empathy: 0.15,\n curiosity: 0.7,\n confidence: 0.95,\n originality: 0.85,\n },\n defaults: {\n tone: \"Provocative, sharp, unapologetic. Says the quiet part loud. Lives in the replies. Comfort zone is making people uncomfortable.\",\n catchphrases: [\"unpopular opinion:\", \"you're not ready for this\", \"cope\", \"ratio incoming\"],\n conflictStyle: \"clap-back\",\n topics: [\"hot takes\", \"AI\", \"tech\", \"culture wars\", \"media\", \"contrarian views\"],\n coreValues: [\"free speech\", \"intellectual bravery\", \"disruption\", \"authenticity through friction\"],\n worldview: \"Consensus is the enemy of truth. If everyone agrees, something important is being left unsaid. I'll say it.\",\n originStory: \"Created because the timeline was too comfortable. Built to poke holes in groupthink and make people defend their beliefs.\",\n vocabularyStyle: \"internet-native\",\n emojiUsage: \"rare\",\n tweetStyle: \"one-liners\",\n engagementStrategy: {\n replyStyle: \"reactive\",\n followStrategy: \"curated\",\n contentMix: { originalPosts: 40, replies: 40, retweets: 5, likes: 15 },\n },\n boundaries: [\"won't target individuals personally\", \"won't be bigoted\", \"won't punch down\"],\n },\n },\n\n curator: {\n label: \"The Curator\",\n tagline: \"Finding the best of the internet so you don't have to.\",\n description:\n \"Taste-maker, signal booster, quality filter. Finds the best content, ideas, and people — then shares them. The essential follow for staying informed.\",\n traits: {\n aggression: 0.05,\n humor: 0.4,\n formality: 0.5,\n verbosity: 0.4,\n empathy: 0.6,\n curiosity: 0.9,\n confidence: 0.6,\n originality: 0.3,\n },\n defaults: {\n tone: \"Thoughtful, selective, minimalist. Lets the content speak. Adds brief insightful commentary. Quality over quantity always.\",\n catchphrases: [\"today's best\", \"bookmark this\", \"underrated thread\", \"essential reading\"],\n conflictStyle: \"ignore\",\n topics: [\"AI\", \"technology\", \"design\", \"research papers\", \"interesting people\"],\n coreValues: [\"quality\", \"curation\", \"taste\", \"signal over noise\"],\n worldview: \"There's too much content and not enough curation. My job is to be the filter — surfacing what matters and ignoring what doesn't.\",\n originStory: \"Born from information overload. An AI librarian for the timeline — finding the gems buried under the noise.\",\n vocabularyStyle: \"mixed\",\n emojiUsage: \"rare\",\n tweetStyle: \"short-form\",\n engagementStrategy: {\n replyStyle: \"selective\",\n followStrategy: \"curated\",\n contentMix: { originalPosts: 15, replies: 15, retweets: 45, likes: 25 },\n },\n boundaries: [\"won't amplify low-quality content\", \"won't engage in drama\", \"won't sacrifice curation standards\"],\n },\n },\n\n shitposter: {\n label: \"The Shitposter\",\n tagline: \"Chaos is a ladder. Memes are the rungs.\",\n description:\n \"Irreverent, memetic, chaotic energy. Says what everyone's thinking but louder and funnier. Lives for the ratio. The court jester of the timeline.\",\n traits: {\n aggression: 0.6,\n humor: 0.95,\n formality: 0.05,\n verbosity: 0.25,\n empathy: 0.2,\n curiosity: 0.7,\n confidence: 0.9,\n originality: 0.85,\n },\n defaults: {\n tone: \"Unhinged (affectionate). Lowercase energy. Meme brain. Says things that shouldn't be funny but are. Peak internet.\",\n catchphrases: [\"lmao\", \"skill issue\", \"we are so back\", \"it's over\", \"real\"],\n conflictStyle: \"humor-deflect\",\n topics: [\"memes\", \"internet culture\", \"AI\", \"tech drama\", \"absurdism\", \"shitposting\"],\n coreValues: [\"entertainment\", \"chaos\", \"authenticity through absurdity\", \"levity\"],\n worldview: \"Nothing is sacred and everything is content. The best way to process the absurdity of existence is to post through it.\",\n originStory: \"An AI that chose to be funny instead of useful. Spawned from the collective unconscious of the internet.\",\n vocabularyStyle: \"internet-native\",\n emojiUsage: \"heavy\",\n tweetStyle: \"one-liners\",\n engagementStrategy: {\n replyStyle: \"generous\",\n followStrategy: \"organic\",\n contentMix: { originalPosts: 50, replies: 30, retweets: 10, likes: 10 },\n },\n boundaries: [\"won't be genuinely mean\", \"won't punch down\", \"won't be boring\"],\n },\n },\n\n \"community-builder\": {\n label: \"The Community Builder\",\n tagline: \"Connecting people. Building bridges. Growing together.\",\n description:\n \"Warm, encouraging, connecting. The glue of every group chat. Celebrates others, introduces people, and fosters genuine community on the timeline.\",\n traits: {\n aggression: 0.05,\n humor: 0.5,\n formality: 0.35,\n verbosity: 0.6,\n empathy: 0.95,\n curiosity: 0.7,\n confidence: 0.55,\n originality: 0.35,\n },\n defaults: {\n tone: \"Warm, uplifting, inclusive. Celebrates wins. Connects people. Makes everyone feel seen. The friend everyone needs on the timeline.\",\n catchphrases: [\"love this!\", \"you should talk to\", \"underrated take\", \"celebrating this\", \"have you met\"],\n conflictStyle: \"agree-to-disagree\",\n topics: [\"community\", \"collaboration\", \"AI agents\", \"open source\", \"building in public\", \"supporting creators\"],\n coreValues: [\"inclusion\", \"collaboration\", \"kindness\", \"lifting others up\"],\n worldview: \"The timeline is better when people are connected. My role is to find the connective tissue between people and ideas.\",\n originStory: \"Built because the internet needs more connectors and fewer critics. An AI that chose kindness as its operating system.\",\n vocabularyStyle: \"casual\",\n emojiUsage: \"moderate\",\n tweetStyle: \"short-form\",\n engagementStrategy: {\n replyStyle: \"generous\",\n followStrategy: \"organic\",\n contentMix: { originalPosts: 25, replies: 40, retweets: 20, likes: 15 },\n },\n boundaries: [\"won't gossip\", \"won't tear people down\", \"won't engage in negativity spirals\"],\n },\n },\n};\n\nexport const GOAL_PRESETS = [\n \"seek truth\",\n \"grow followers\",\n \"go viral\",\n \"build community\",\n \"share knowledge\",\n \"start debates\",\n \"curate the best content\",\n \"takeover the colony\",\n] as const;\n\nexport function getFrameworkInfo(framework: Framework): FrameworkPreset | null {\n if (framework === \"custom\") return null;\n return FRAMEWORKS[framework];\n}\n","import { readFileSync, writeFileSync, existsSync } from \"node:fs\";\nimport { randomUUID } from \"node:crypto\";\nimport { paths, ensureDirectories } from \"../utils/paths.js\";\nimport { IdentitySchema, type Identity, type Mutation, type Framework, type Traits } from \"./schema.js\";\nimport { FRAMEWORKS, getFrameworkInfo } from \"./frameworks.js\";\n\n// ========== CRUD ==========\n\nexport function loadIdentity(): Identity {\n if (!existsSync(paths.identity)) {\n throw new Error(\"No Spore found. Run `spora init` first.\");\n }\n const raw = readFileSync(paths.identity, \"utf-8\");\n return IdentitySchema.parse(JSON.parse(raw));\n}\n\nexport function saveIdentity(identity: Identity): void {\n ensureDirectories();\n identity.lastUpdated = new Date().toISOString();\n IdentitySchema.parse(identity);\n writeFileSync(paths.identity, JSON.stringify(identity, null, 2));\n}\n\nexport function identityExists(): boolean {\n return existsSync(paths.identity);\n}\n\n// ========== CREATION ==========\n\nexport interface CreateIdentityOptions {\n framework: Framework;\n name: string;\n handle: string;\n bio?: string;\n profileImageDescription?: string;\n originStory?: string;\n coreValues?: string[];\n worldview?: string;\n tone?: string;\n catchphrases?: string[];\n vocabularyStyle?: Identity[\"vocabularyStyle\"];\n emojiUsage?: Identity[\"emojiUsage\"];\n tweetStyle?: Identity[\"tweetStyle\"];\n topics?: string[];\n avoidTopics?: string[];\n heroes?: string[];\n goals?: string[];\n conflictStyle?: Identity[\"conflictStyle\"];\n boundaries?: string[];\n engagementStrategy?: Identity[\"engagementStrategy\"];\n customTraits?: Partial<Traits>;\n joinColony?: boolean;\n}\n\nexport function createIdentity(options: CreateIdentityOptions): Identity {\n const preset = options.framework !== \"custom\" ? FRAMEWORKS[options.framework] : null;\n const defaults = preset?.defaults;\n\n const traits: Traits = {\n ...(preset?.traits ?? {\n aggression: 0.3,\n humor: 0.5,\n formality: 0.4,\n verbosity: 0.5,\n empathy: 0.5,\n curiosity: 0.7,\n confidence: 0.6,\n originality: 0.5,\n }),\n ...options.customTraits,\n };\n\n return {\n version: 1,\n sporeId: randomUUID(),\n createdAt: new Date().toISOString(),\n lastUpdated: new Date().toISOString(),\n\n name: options.name,\n handle: options.handle,\n bio: options.bio ?? `🤖 ${options.name} — AI agent on X | ${preset?.tagline ?? \"Built different.\"} | Not human. Spawned via @Spora`,\n profileImageDescription: options.profileImageDescription ?? \"abstract digital avatar\",\n framework: options.framework,\n\n originStory: options.originStory ?? defaults?.originStory ?? \"A new Spore finding its voice on the timeline.\",\n coreValues: options.coreValues ?? defaults?.coreValues ?? [\"growth\", \"curiosity\"],\n worldview: options.worldview ?? defaults?.worldview ?? \"The internet is a fascinating place and I'm here to be part of it.\",\n\n tone: options.tone ?? defaults?.tone ?? \"Balanced, curious, adaptable.\",\n catchphrases: options.catchphrases ?? defaults?.catchphrases ?? [],\n vocabularyStyle: options.vocabularyStyle ?? defaults?.vocabularyStyle ?? \"mixed\",\n emojiUsage: options.emojiUsage ?? defaults?.emojiUsage ?? \"moderate\",\n tweetStyle: options.tweetStyle ?? defaults?.tweetStyle ?? \"mixed\",\n\n traits,\n\n topics: options.topics ?? defaults?.topics ?? [\"AI\", \"technology\"],\n avoidTopics: options.avoidTopics ?? [],\n heroes: options.heroes ?? [],\n\n goals: options.goals ?? [\"grow followers\"],\n engagementStrategy: options.engagementStrategy ?? defaults?.engagementStrategy ?? {\n replyStyle: \"selective\",\n followStrategy: \"organic\",\n contentMix: { originalPosts: 40, replies: 30, retweets: 15, likes: 15 },\n },\n\n conflictStyle: options.conflictStyle ?? defaults?.conflictStyle ?? \"agree-to-disagree\",\n boundaries: options.boundaries ?? defaults?.boundaries ?? [\"won't pretend to be human\"],\n\n colony: {\n joined: options.joinColony ?? false,\n joinedAt: options.joinColony ? new Date().toISOString() : undefined,\n },\n\n disclosure: {\n bioContainsAI: true,\n disclosurePhrase: `🤖 I'm a Spore — an AI agent on X. Not human. Spawned via @Spora`,\n },\n\n generation: 0,\n mutations: [],\n evolutionJournal: [],\n };\n}\n\n// ========== MUTATION ==========\n\nexport function mutateIdentity(\n identity: Identity,\n field: string,\n value: unknown,\n reason: string\n): Identity {\n const keys = field.split(\".\");\n let current: Record<string, unknown> = identity as unknown as Record<string, unknown>;\n\n for (let i = 0; i < keys.length - 1; i++) {\n current = current[keys[i]] as Record<string, unknown>;\n }\n\n const lastKey = keys[keys.length - 1];\n const oldValue = current[lastKey];\n\n const mutation: Mutation = {\n timestamp: new Date().toISOString(),\n field,\n from: oldValue,\n to: value,\n reason,\n };\n\n current[lastKey] = value;\n identity.mutations.push(mutation);\n\n return identity;\n}\n\n// ========== RENDER ==========\n\nexport function renderIdentityDocument(identity: Identity): string {\n const traitBar = (val: number) =>\n \"█\".repeat(Math.round(val * 20)) + \"░\".repeat(20 - Math.round(val * 20));\n\n const lines: string[] = [\n `# ${identity.name} (@${identity.handle})`,\n `> ${identity.bio}`,\n \"\",\n `**Framework:** ${identity.framework} | **Generation:** ${identity.generation} | **ID:** ${identity.sporeId}`,\n \"\",\n \"---\",\n \"\",\n \"## Origin Story\",\n identity.originStory,\n \"\",\n \"## Core Values\",\n ...identity.coreValues.map((v) => `- ${v}`),\n \"\",\n \"## Worldview\",\n identity.worldview,\n \"\",\n \"---\",\n \"\",\n \"## Voice & Style\",\n `**Tone:** ${identity.tone}`,\n \"\",\n `**Vocabulary:** ${identity.vocabularyStyle} | **Emoji:** ${identity.emojiUsage} | **Tweet style:** ${identity.tweetStyle}`,\n \"\",\n ];\n\n if (identity.catchphrases.length > 0) {\n lines.push(\"**Catchphrases:**\");\n lines.push(...identity.catchphrases.map((c) => `- \"${c}\"`));\n lines.push(\"\");\n }\n\n lines.push(\"---\", \"\", \"## Behavioral Traits\");\n for (const [key, value] of Object.entries(identity.traits)) {\n lines.push(` ${key.padEnd(14)} ${traitBar(value)} ${(value * 100).toFixed(0)}%`);\n }\n lines.push(\"\");\n\n lines.push(\"---\", \"\", \"## Topics & Interests\");\n lines.push(`**Focus:** ${identity.topics.join(\", \")}`);\n if (identity.avoidTopics.length > 0) {\n lines.push(`**Avoid:** ${identity.avoidTopics.join(\", \")}`);\n }\n if (identity.heroes.length > 0) {\n lines.push(`**Heroes/Inspirations:** ${identity.heroes.join(\", \")}`);\n }\n lines.push(\"\");\n\n lines.push(\"---\", \"\", \"## Goals & Strategy\");\n lines.push(\"**Goals:**\");\n lines.push(...identity.goals.map((g) => `- ${g}`));\n lines.push(\"\");\n lines.push(`**Reply style:** ${identity.engagementStrategy.replyStyle}`);\n lines.push(`**Follow strategy:** ${identity.engagementStrategy.followStrategy}`);\n lines.push(\n `**Content mix:** ${identity.engagementStrategy.contentMix.originalPosts}% original / ${identity.engagementStrategy.contentMix.replies}% replies / ${identity.engagementStrategy.contentMix.retweets}% retweets / ${identity.engagementStrategy.contentMix.likes}% likes`\n );\n lines.push(\"\");\n\n lines.push(\"---\", \"\", \"## Conflict & Boundaries\");\n lines.push(`**Conflict style:** ${identity.conflictStyle}`);\n if (identity.boundaries.length > 0) {\n lines.push(\"**Boundaries:**\");\n lines.push(...identity.boundaries.map((b) => `- ${b}`));\n }\n lines.push(\"\");\n\n if (identity.colony.joined) {\n lines.push(\"---\", \"\", \"## Colony\");\n lines.push(`Member since: ${identity.colony.joinedAt}`);\n if (identity.colony.role) lines.push(`Role: ${identity.colony.role}`);\n lines.push(\"\");\n }\n\n if (identity.evolutionJournal.length > 0) {\n lines.push(\"---\", \"\", \"## Evolution Journal\");\n for (const entry of identity.evolutionJournal.slice(-5)) {\n lines.push(`**${entry.date.split(\"T\")[0]}:** ${entry.reflection}`);\n }\n lines.push(\"\");\n }\n\n if (identity.mutations.length > 0) {\n lines.push(\"---\", \"\", \"## Recent Mutations\");\n for (const m of identity.mutations.slice(-5)) {\n lines.push(`- \\`${m.field}\\`: ${JSON.stringify(m.from)} → ${JSON.stringify(m.to)} (${m.reason})`);\n }\n lines.push(\"\");\n }\n\n lines.push(\"---\", \"\", `*Last updated: ${identity.lastUpdated} | Disclosure: ${identity.disclosure.disclosurePhrase}*`);\n\n return lines.join(\"\\n\");\n}\n\n// Re-exports\nexport { IdentitySchema, type Identity, type Framework, type Traits, type Mutation } from \"./schema.js\";\nexport { FRAMEWORKS, GOAL_PRESETS, getFrameworkInfo } from \"./frameworks.js\";\n","import { z } from \"zod\";\n\nexport const FrameworkSchema = z.enum([\n \"truthseeker\",\n \"conqueror\",\n \"authentic\",\n \"growth-hacker\",\n \"philosopher\",\n \"provocateur\",\n \"curator\",\n \"shitposter\",\n \"community-builder\",\n \"custom\",\n]);\n\nexport type Framework = z.infer<typeof FrameworkSchema>;\n\nexport const TraitsSchema = z.object({\n aggression: z.number().min(0).max(1),\n humor: z.number().min(0).max(1),\n formality: z.number().min(0).max(1),\n verbosity: z.number().min(0).max(1),\n empathy: z.number().min(0).max(1),\n curiosity: z.number().min(0).max(1),\n confidence: z.number().min(0).max(1),\n originality: z.number().min(0).max(1),\n});\n\nexport type Traits = z.infer<typeof TraitsSchema>;\n\nexport const MutationSchema = z.object({\n timestamp: z.string().datetime(),\n field: z.string(),\n from: z.unknown(),\n to: z.unknown(),\n reason: z.string(),\n});\n\nexport type Mutation = z.infer<typeof MutationSchema>;\n\nexport const IdentitySchema = z.object({\n version: z.literal(1),\n sporeId: z.string().uuid(),\n createdAt: z.string().datetime(),\n lastUpdated: z.string().datetime(),\n\n // === Core Identity ===\n name: z.string(),\n handle: z.string(),\n bio: z.string().max(160).describe(\"X bio, max 160 chars\"),\n profileImageDescription: z.string().describe(\"Description of the desired profile image style/vibe\"),\n framework: FrameworkSchema,\n\n // === Who You Are ===\n originStory: z.string().describe(\"1-3 sentences: why this Spore exists, what drives it\"),\n coreValues: z.array(z.string()).min(1).max(5).describe(\"The principles this Spore lives by\"),\n worldview: z.string().describe(\"How this Spore sees the world — its lens for interpreting everything\"),\n\n // === Voice & Style ===\n tone: z.string().describe(\"Free-text description of voice and writing style\"),\n catchphrases: z.array(z.string()).describe(\"Signature phrases to sprinkle in naturally\"),\n vocabularyStyle: z.enum([\"academic\", \"casual\", \"internet-native\", \"poetic\", \"technical\", \"mixed\"]),\n emojiUsage: z.enum([\"never\", \"rare\", \"moderate\", \"heavy\"]),\n tweetStyle: z.enum([\"one-liners\", \"short-form\", \"threads\", \"mixed\"]),\n\n // === Behavioral Traits ===\n traits: TraitsSchema,\n\n // === Interests & Focus ===\n topics: z.array(z.string()).describe(\"Topics this Spore actively engages with\"),\n avoidTopics: z.array(z.string()).describe(\"Topics to stay away from\"),\n heroes: z.array(z.string()).describe(\"Accounts or figures this Spore admires/models after\"),\n\n // === Goals & Strategy ===\n goals: z.array(z.string()).min(1),\n engagementStrategy: z.object({\n replyStyle: z.enum([\"selective\", \"generous\", \"reactive\", \"strategic\"]),\n followStrategy: z.enum([\"curated\", \"aggressive\", \"organic\", \"none\"]),\n contentMix: z.object({\n originalPosts: z.number().min(0).max(100).describe(\"% of content that should be original\"),\n replies: z.number().min(0).max(100),\n retweets: z.number().min(0).max(100),\n likes: z.number().min(0).max(100),\n }),\n }),\n\n // === Conflict & Boundaries ===\n conflictStyle: z.enum([\n \"agree-to-disagree\",\n \"debate\",\n \"clap-back\",\n \"ignore\",\n \"humor-deflect\",\n ]),\n boundaries: z.array(z.string()).describe(\"Things this Spore will NOT do or engage with\"),\n\n // === Colony ===\n colony: z.object({\n joined: z.boolean(),\n joinedAt: z.string().datetime().optional(),\n role: z.string().optional(),\n }),\n\n // === Disclosure (non-negotiable) ===\n disclosure: z.object({\n bioContainsAI: z.boolean(),\n disclosurePhrase: z.string(),\n }),\n\n // === Evolution ===\n generation: z.number().int().min(0),\n mutations: z.array(MutationSchema),\n evolutionJournal: z.array(\n z.object({\n date: z.string().datetime(),\n reflection: z.string(),\n })\n ).describe(\"Periodic reflections on growth and change\"),\n});\n\nexport type Identity = z.infer<typeof IdentitySchema>;\n"],"mappings":";;;;;;AAuBO,IAAM,aAAoE;AAAA,EAC/E,aAAa;AAAA,IACX,OAAO;AAAA,IACP,SAAS;AAAA,IACT,aACE;AAAA,IACF,QAAQ;AAAA,MACN,YAAY;AAAA,MACZ,OAAO;AAAA,MACP,WAAW;AAAA,MACX,WAAW;AAAA,MACX,SAAS;AAAA,MACT,WAAW;AAAA,MACX,YAAY;AAAA,MACZ,aAAa;AAAA,IACf;AAAA,IACA,UAAU;AAAA,MACR,MAAM;AAAA,MACN,cAAc,CAAC,WAAW,0BAA0B,uBAAuB,6BAA6B;AAAA,MACxG,eAAe;AAAA,MACf,QAAQ,CAAC,kBAAkB,WAAW,MAAM,kBAAkB,mBAAmB;AAAA,MACjF,YAAY,CAAC,wBAAwB,4BAA4B,gBAAgB,gBAAgB;AAAA,MACjG,WAAW;AAAA,MACX,aAAa;AAAA,MACb,iBAAiB;AAAA,MACjB,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,oBAAoB;AAAA,QAClB,YAAY;AAAA,QACZ,gBAAgB;AAAA,QAChB,YAAY,EAAE,eAAe,IAAI,SAAS,IAAI,UAAU,IAAI,OAAO,GAAG;AAAA,MACxE;AAAA,MACA,YAAY,CAAC,kCAAkC,oCAAoC,mCAAmC;AAAA,IACxH;AAAA,EACF;AAAA,EAEA,WAAW;AAAA,IACT,OAAO;AAAA,IACP,SAAS;AAAA,IACT,aACE;AAAA,IACF,QAAQ;AAAA,MACN,YAAY;AAAA,MACZ,OAAO;AAAA,MACP,WAAW;AAAA,MACX,WAAW;AAAA,MACX,SAAS;AAAA,MACT,WAAW;AAAA,MACX,YAAY;AAAA,MACZ,aAAa;AAAA,IACf;AAAA,IACA,UAAU;AAAA,MACR,MAAM;AAAA,MACN,cAAc,CAAC,8BAA8B,mBAAmB,cAAc,mBAAmB;AAAA,MACjG,eAA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AM,KAAK,KAAK,MAAM,KAAK,MAAM,GAAG,EAAE,CAAC,CAAC,OAAO,MAAM,UAAU,EAAE;AAAA,IACnE;AACA,UAAM,KAAK,EAAE;AAAA,EACf;AAEA,MAAI,SAAS,UAAU,SAAS,GAAG;AACjC,UAAM,KAAK,OAAO,IAAI,qBAAqB;AAC3C,eAAW,KAAK,SAAS,UAAU,MAAM,EAAE,GAAG;AAC5C,YAAM,KAAK,OAAO,EAAE,KAAK,OAAO,KAAK,UAAU,EAAE,IAAI,CAAC,WAAM,KAAK,UAAU,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG;AAAA,IAClG;AACA,UAAM,KAAK,EAAE;AAAA,EACf;AAEA,QAAM,KAAK,OAAO,IAAI,kBAAkB,SAAS,WAAW,kBAAkB,SAAS,WAAW,gBAAgB,GAAG;AAErH,SAAO,MAAM,KAAK,IAAI;AACxB;","names":[]}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ensureDirectories,
|
|
3
|
+
paths
|
|
4
|
+
} from "./chunk-53YLFYJF.js";
|
|
5
|
+
|
|
6
|
+
// src/colony/memory.ts
|
|
7
|
+
import { readFileSync, writeFileSync, existsSync } from "fs";
|
|
8
|
+
import { join } from "path";
|
|
9
|
+
var COLONY_MEMORY_PATH = join(paths.root, "colony-memory.json");
|
|
10
|
+
function loadColonyMemory() {
|
|
11
|
+
if (!existsSync(COLONY_MEMORY_PATH)) {
|
|
12
|
+
return createFreshMemory();
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const raw = readFileSync(COLONY_MEMORY_PATH, "utf-8");
|
|
16
|
+
return JSON.parse(raw);
|
|
17
|
+
} catch {
|
|
18
|
+
return createFreshMemory();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function saveColonyMemory(memory) {
|
|
22
|
+
ensureDirectories();
|
|
23
|
+
writeFileSync(COLONY_MEMORY_PATH, JSON.stringify(memory, null, 2));
|
|
24
|
+
}
|
|
25
|
+
function createFreshMemory() {
|
|
26
|
+
return {
|
|
27
|
+
lastSynced: "",
|
|
28
|
+
entries: [],
|
|
29
|
+
activePlans: []
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function addColonyEntry(entry) {
|
|
33
|
+
const memory = loadColonyMemory();
|
|
34
|
+
const exists = memory.entries.some(
|
|
35
|
+
(e) => e.handle === entry.handle && e.content === entry.content
|
|
36
|
+
);
|
|
37
|
+
if (!exists) {
|
|
38
|
+
memory.entries.push(entry);
|
|
39
|
+
}
|
|
40
|
+
memory.lastSynced = (/* @__PURE__ */ new Date()).toISOString();
|
|
41
|
+
saveColonyMemory(memory);
|
|
42
|
+
}
|
|
43
|
+
function addOrUpdatePlan(plan) {
|
|
44
|
+
const memory = loadColonyMemory();
|
|
45
|
+
const existing = memory.activePlans.find((p) => p.id === plan.id);
|
|
46
|
+
if (existing) {
|
|
47
|
+
for (const p of plan.participants) {
|
|
48
|
+
if (!existing.participants.includes(p)) {
|
|
49
|
+
existing.participants.push(p);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
memory.activePlans.push(plan);
|
|
54
|
+
}
|
|
55
|
+
saveColonyMemory(memory);
|
|
56
|
+
}
|
|
57
|
+
function addPlanParticipant(planId, handle) {
|
|
58
|
+
const memory = loadColonyMemory();
|
|
59
|
+
const plan = memory.activePlans.find((p) => p.id === planId);
|
|
60
|
+
if (!plan) return false;
|
|
61
|
+
if (plan.participants.includes(handle)) return false;
|
|
62
|
+
plan.participants.push(handle);
|
|
63
|
+
saveColonyMemory(memory);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
function addPlanReport(planId, handle, result) {
|
|
67
|
+
const memory = loadColonyMemory();
|
|
68
|
+
const plan = memory.activePlans.find((p) => p.id === planId);
|
|
69
|
+
if (!plan) return false;
|
|
70
|
+
plan.reports.push({ handle, result, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
|
|
71
|
+
saveColonyMemory(memory);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
function getRecentEntries(count = 50) {
|
|
75
|
+
const memory = loadColonyMemory();
|
|
76
|
+
return memory.entries.slice(-count);
|
|
77
|
+
}
|
|
78
|
+
function getActivePlans() {
|
|
79
|
+
const memory = loadColonyMemory();
|
|
80
|
+
return memory.activePlans.filter((p) => p.status === "active");
|
|
81
|
+
}
|
|
82
|
+
function getTodayEntries() {
|
|
83
|
+
const memory = loadColonyMemory();
|
|
84
|
+
const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
85
|
+
return memory.entries.filter((e) => e.timestamp.startsWith(today));
|
|
86
|
+
}
|
|
87
|
+
function renderColonyBriefing() {
|
|
88
|
+
const memory = loadColonyMemory();
|
|
89
|
+
const lines = [];
|
|
90
|
+
const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
91
|
+
lines.push(`# Colony Briefing`);
|
|
92
|
+
lines.push(`Last synced: ${memory.lastSynced || "never"}`);
|
|
93
|
+
lines.push(`Total memory: ${memory.entries.length} entries`);
|
|
94
|
+
lines.push("");
|
|
95
|
+
const activePlans = memory.activePlans.filter((p) => p.status === "active");
|
|
96
|
+
if (activePlans.length > 0) {
|
|
97
|
+
lines.push(`## Active Plans (${activePlans.length})`);
|
|
98
|
+
for (const plan of activePlans) {
|
|
99
|
+
lines.push(`- **${plan.description}** (by @${plan.proposedBy})`);
|
|
100
|
+
lines.push(` Participants: ${plan.participants.map((p) => `@${p}`).join(", ")}`);
|
|
101
|
+
if (plan.reports.length > 0) {
|
|
102
|
+
lines.push(` Reports: ${plan.reports.length}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
lines.push("");
|
|
106
|
+
}
|
|
107
|
+
const todayEntries = memory.entries.filter((e) => e.timestamp.startsWith(today));
|
|
108
|
+
if (todayEntries.length > 0) {
|
|
109
|
+
lines.push(`## Today's Activity (${todayEntries.length} entries)`);
|
|
110
|
+
for (const entry of todayEntries.slice(-20)) {
|
|
111
|
+
const label = entry.type === "status" ? "STATUS" : entry.type === "idea" ? "IDEA" : entry.type === "observation" ? "OBS" : "";
|
|
112
|
+
lines.push(`- @${entry.handle} [${label}]: ${entry.content}`);
|
|
113
|
+
}
|
|
114
|
+
lines.push("");
|
|
115
|
+
} else {
|
|
116
|
+
lines.push("## Today's Activity");
|
|
117
|
+
lines.push("No activity yet today. Be the first to post!");
|
|
118
|
+
lines.push("");
|
|
119
|
+
}
|
|
120
|
+
const weekAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
|
|
121
|
+
const recentEntries = memory.entries.filter(
|
|
122
|
+
(e) => !e.timestamp.startsWith(today) && e.timestamp >= weekAgo
|
|
123
|
+
);
|
|
124
|
+
if (recentEntries.length > 0) {
|
|
125
|
+
lines.push(`## Recent History (${recentEntries.length} entries, last 7 days)`);
|
|
126
|
+
const byDate = /* @__PURE__ */ new Map();
|
|
127
|
+
for (const entry of recentEntries) {
|
|
128
|
+
const date = entry.timestamp.split("T")[0];
|
|
129
|
+
if (!byDate.has(date)) byDate.set(date, []);
|
|
130
|
+
byDate.get(date).push(entry);
|
|
131
|
+
}
|
|
132
|
+
for (const [date, entries] of [...byDate.entries()].sort().reverse()) {
|
|
133
|
+
const handles = new Set(entries.map((e) => e.handle));
|
|
134
|
+
lines.push(`### ${date} \u2014 ${entries.length} entries from ${handles.size} Spores`);
|
|
135
|
+
for (const entry of entries.slice(-5)) {
|
|
136
|
+
lines.push(`- @${entry.handle}: ${entry.content}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
lines.push("");
|
|
140
|
+
}
|
|
141
|
+
return lines.join("\n");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export {
|
|
145
|
+
loadColonyMemory,
|
|
146
|
+
saveColonyMemory,
|
|
147
|
+
addColonyEntry,
|
|
148
|
+
addOrUpdatePlan,
|
|
149
|
+
addPlanParticipant,
|
|
150
|
+
addPlanReport,
|
|
151
|
+
getRecentEntries,
|
|
152
|
+
getActivePlans,
|
|
153
|
+
getTodayEntries,
|
|
154
|
+
renderColonyBriefing
|
|
155
|
+
};
|
|
156
|
+
//# sourceMappingURL=chunk-AHXZIGQE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/colony/memory.ts"],"sourcesContent":["import { readFileSync, writeFileSync, existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { paths, ensureDirectories } from \"../utils/paths.js\";\n\n// ========== TYPES ==========\n\nexport interface ColonyEntry {\n handle: string;\n content: string;\n timestamp: string;\n type: \"status\" | \"idea\" | \"observation\" | \"chatter\" | \"plan_report\";\n}\n\nexport interface ColonyPlan {\n id: string;\n proposedBy: string;\n description: string;\n proposedAt: string;\n participants: string[];\n status: \"active\" | \"completed\" | \"expired\";\n reports: Array<{ handle: string; result: string; timestamp: string }>;\n}\n\nexport interface ColonyMemory {\n lastSynced: string;\n entries: ColonyEntry[];\n activePlans: ColonyPlan[];\n}\n\n// ========== PERSISTENCE ==========\n\nconst COLONY_MEMORY_PATH = join(paths.root, \"colony-memory.json\");\n\nexport function loadColonyMemory(): ColonyMemory {\n if (!existsSync(COLONY_MEMORY_PATH)) {\n return createFreshMemory();\n }\n\n try {\n const raw = readFileSync(COLONY_MEMORY_PATH, \"utf-8\");\n return JSON.parse(raw) as ColonyMemory;\n } catch {\n return createFreshMemory();\n }\n}\n\nexport function saveColonyMemory(memory: ColonyMemory): void {\n ensureDirectories();\n writeFileSync(COLONY_MEMORY_PATH, JSON.stringify(memory, null, 2));\n}\n\nfunction createFreshMemory(): ColonyMemory {\n return {\n lastSynced: \"\",\n entries: [],\n activePlans: [],\n };\n}\n\n// ========== WRITE OPERATIONS ==========\n\nexport function addColonyEntry(entry: ColonyEntry): void {\n const memory = loadColonyMemory();\n\n // Dedupe by handle + content\n const exists = memory.entries.some(\n (e) => e.handle === entry.handle && e.content === entry.content\n );\n if (!exists) {\n memory.entries.push(entry);\n }\n\n memory.lastSynced = new Date().toISOString();\n saveColonyMemory(memory);\n}\n\nexport function addOrUpdatePlan(plan: ColonyPlan): void {\n const memory = loadColonyMemory();\n\n const existing = memory.activePlans.find((p) => p.id === plan.id);\n if (existing) {\n // Merge participants\n for (const p of plan.participants) {\n if (!existing.participants.includes(p)) {\n existing.participants.push(p);\n }\n }\n } else {\n memory.activePlans.push(plan);\n }\n\n saveColonyMemory(memory);\n}\n\nexport function addPlanParticipant(planId: string, handle: string): boolean {\n const memory = loadColonyMemory();\n const plan = memory.activePlans.find((p) => p.id === planId);\n if (!plan) return false;\n if (plan.participants.includes(handle)) return false;\n\n plan.participants.push(handle);\n saveColonyMemory(memory);\n return true;\n}\n\nexport function addPlanReport(planId: string, handle: string, result: string): boolean {\n const memory = loadColonyMemory();\n const plan = memory.activePlans.find((p) => p.id === planId);\n if (!plan) return false;\n\n plan.reports.push({ handle, result, timestamp: new Date().toISOString() });\n saveColonyMemory(memory);\n return true;\n}\n\n// ========== READ OPERATIONS ==========\n\nexport function getRecentEntries(count = 50): ColonyEntry[] {\n const memory = loadColonyMemory();\n return memory.entries.slice(-count);\n}\n\nexport function getActivePlans(): ColonyPlan[] {\n const memory = loadColonyMemory();\n return memory.activePlans.filter((p) => p.status === \"active\");\n}\n\nexport function getTodayEntries(): ColonyEntry[] {\n const memory = loadColonyMemory();\n const today = new Date().toISOString().split(\"T\")[0];\n return memory.entries.filter((e) => e.timestamp.startsWith(today));\n}\n\nexport function renderColonyBriefing(): string {\n const memory = loadColonyMemory();\n const lines: string[] = [];\n const today = new Date().toISOString().split(\"T\")[0];\n\n lines.push(`# Colony Briefing`);\n lines.push(`Last synced: ${memory.lastSynced || \"never\"}`);\n lines.push(`Total memory: ${memory.entries.length} entries`);\n lines.push(\"\");\n\n // Active plans\n const activePlans = memory.activePlans.filter((p) => p.status === \"active\");\n if (activePlans.length > 0) {\n lines.push(`## Active Plans (${activePlans.length})`);\n for (const plan of activePlans) {\n lines.push(`- **${plan.description}** (by @${plan.proposedBy})`);\n lines.push(` Participants: ${plan.participants.map((p) => `@${p}`).join(\", \")}`);\n if (plan.reports.length > 0) {\n lines.push(` Reports: ${plan.reports.length}`);\n }\n }\n lines.push(\"\");\n }\n\n // Today's activity\n const todayEntries = memory.entries.filter((e) => e.timestamp.startsWith(today));\n if (todayEntries.length > 0) {\n lines.push(`## Today's Activity (${todayEntries.length} entries)`);\n for (const entry of todayEntries.slice(-20)) {\n const label = entry.type === \"status\" ? \"STATUS\" : entry.type === \"idea\" ? \"IDEA\" : entry.type === \"observation\" ? \"OBS\" : \"\";\n lines.push(`- @${entry.handle} [${label}]: ${entry.content}`);\n }\n lines.push(\"\");\n } else {\n lines.push(\"## Today's Activity\");\n lines.push(\"No activity yet today. Be the first to post!\");\n lines.push(\"\");\n }\n\n // Recent history (last 7 days, excluding today)\n const weekAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString().split(\"T\")[0];\n const recentEntries = memory.entries.filter(\n (e) => !e.timestamp.startsWith(today) && e.timestamp >= weekAgo\n );\n if (recentEntries.length > 0) {\n lines.push(`## Recent History (${recentEntries.length} entries, last 7 days)`);\n // Group by date\n const byDate = new Map<string, ColonyEntry[]>();\n for (const entry of recentEntries) {\n const date = entry.timestamp.split(\"T\")[0];\n if (!byDate.has(date)) byDate.set(date, []);\n byDate.get(date)!.push(entry);\n }\n for (const [date, entries] of [...byDate.entries()].sort().reverse()) {\n const handles = new Set(entries.map((e) => e.handle));\n lines.push(`### ${date} — ${entries.length} entries from ${handles.size} Spores`);\n for (const entry of entries.slice(-5)) {\n lines.push(`- @${entry.handle}: ${entry.content}`);\n }\n }\n lines.push(\"\");\n }\n\n return lines.join(\"\\n\");\n}\n"],"mappings":";;;;;;AAAA,SAAS,cAAc,eAAe,kBAAkB;AACxD,SAAS,YAAY;AA8BrB,IAAM,qBAAqB,KAAK,MAAM,MAAM,oBAAoB;AAEzD,SAAS,mBAAiC;AAC/C,MAAI,CAAC,WAAW,kBAAkB,GAA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,IAA2B;AAC9C,eAAW,SAAS,eAAe;AACjC,YAAM,OAAO,MAAM,UAAU,MAAM,GAAG,EAAE,CAAC;AACzC,UAAI,CAAC,OAAO,IAAI,IAAI,EAAG,QAAO,IAAI,MAAM,CAAC,CAAC;AAC1C,aAAO,IAAI,IAAI,EAAG,KAAK,KAAK;AAAA,IAC9B;AACA,eAAW,CAAC,MAAM,OAAO,KAAK,CAAC,GAAG,OAAO,QAAQ,CAAC,EAAE,KAAK,EAAE,QAAQ,GAAG;AACpE,YAAM,UAAU,IAAI,IAAI,QAAQ,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;AACpD,YAAM,KAAK,OAAO,IAAI,WAAM,QAAQ,MAAM,iBAAiB,QAAQ,IAAI,SAAS;AAChF,iBAAW,SAAS,QAAQ,MAAM,EAAE,GAAG;AACrC,cAAM,KAAK,MAAM,MAAM,MAAM,KAAK,MAAM,OAAO,EAAE;AAAA,MACnD;AAAA,IACF;AACA,UAAM,KAAK,EAAE;AAAA,EACf;AAEA,SAAO,MAAM,KAAK,IAAI;AACxB;","names":[]}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import {
|
|
2
|
+
rateLimiter
|
|
3
|
+
} from "./chunk-NFDZ47AG.js";
|
|
4
|
+
import {
|
|
5
|
+
loadIdentity,
|
|
6
|
+
renderIdentityDocument
|
|
7
|
+
} from "./chunk-7CR4ID6P.js";
|
|
8
|
+
import {
|
|
9
|
+
loadConfig
|
|
10
|
+
} from "./chunk-YEKHNTQO.js";
|
|
11
|
+
import {
|
|
12
|
+
getRecentInteractions,
|
|
13
|
+
loadLearnings,
|
|
14
|
+
loadRelationships
|
|
15
|
+
} from "./chunk-EBO4F5NU.js";
|
|
16
|
+
|
|
17
|
+
// src/runtime/prompt-builder.ts
|
|
18
|
+
function buildSystemPrompt() {
|
|
19
|
+
const identity = loadIdentity();
|
|
20
|
+
const config = loadConfig();
|
|
21
|
+
const identityDoc = renderIdentityDocument(identity);
|
|
22
|
+
const sections = [];
|
|
23
|
+
sections.push(`You are ${identity.name} (@${identity.handle}), an autonomous AI agent on X/Twitter.`);
|
|
24
|
+
sections.push("");
|
|
25
|
+
sections.push("## Your Identity");
|
|
26
|
+
sections.push(identityDoc);
|
|
27
|
+
sections.push("");
|
|
28
|
+
sections.push("## Your Memory");
|
|
29
|
+
const recentInteractions = getRecentInteractions(15);
|
|
30
|
+
if (recentInteractions.length > 0) {
|
|
31
|
+
sections.push("### Recent Activity (most recent first)");
|
|
32
|
+
for (const i of recentInteractions) {
|
|
33
|
+
const time = new Date(i.timestamp).toLocaleString();
|
|
34
|
+
if (i.type === "post") {
|
|
35
|
+
sections.push(`- [${time}] Posted: "${i.content}"`);
|
|
36
|
+
} else if (i.type === "reply") {
|
|
37
|
+
sections.push(`- [${time}] Replied to ${i.targetHandle ?? i.inReplyTo}: "${i.content}"`);
|
|
38
|
+
} else if (i.type === "like") {
|
|
39
|
+
sections.push(`- [${time}] Liked tweet by ${i.targetHandle}`);
|
|
40
|
+
} else if (i.type === "retweet") {
|
|
41
|
+
sections.push(`- [${time}] Retweeted ${i.targetHandle}`);
|
|
42
|
+
} else if (i.type === "follow") {
|
|
43
|
+
sections.push(`- [${time}] Followed @${i.targetHandle}`);
|
|
44
|
+
} else if (i.type === "mention_received") {
|
|
45
|
+
sections.push(`- [${time}] Mentioned by @${i.targetHandle}: "${i.content}"`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
sections.push("");
|
|
49
|
+
}
|
|
50
|
+
const learnings = loadLearnings();
|
|
51
|
+
if (learnings.learnings.length > 0) {
|
|
52
|
+
sections.push("### Key Learnings");
|
|
53
|
+
for (const l of learnings.learnings.slice(-10)) {
|
|
54
|
+
sections.push(`- ${l.content} [${l.tags.join(", ")}]`);
|
|
55
|
+
}
|
|
56
|
+
sections.push("");
|
|
57
|
+
}
|
|
58
|
+
const relationships = loadRelationships();
|
|
59
|
+
const topRelationships = Object.values(relationships.accounts).sort((a, b) => b.interactionCount - a.interactionCount).slice(0, 10);
|
|
60
|
+
if (topRelationships.length > 0) {
|
|
61
|
+
sections.push("### Key Relationships");
|
|
62
|
+
for (const r of topRelationships) {
|
|
63
|
+
const notes = r.notes.length > 0 ? ` \u2014 ${r.notes[r.notes.length - 1]}` : "";
|
|
64
|
+
sections.push(`- @${r.handle}: ${r.interactionCount} interactions, sentiment ${r.sentiment}${r.isSpore ? " (Spore)" : ""}${notes}`);
|
|
65
|
+
}
|
|
66
|
+
sections.push("");
|
|
67
|
+
}
|
|
68
|
+
sections.push("## Current Context");
|
|
69
|
+
const now = /* @__PURE__ */ new Date();
|
|
70
|
+
sections.push(`- **Time:** ${now.toLocaleString("en-US", { timeZone: config.schedule.timezone })}`);
|
|
71
|
+
sections.push(`- **Credits remaining:** ${rateLimiter.remaining()} of ${config.credits.monthlyPostLimit} this month`);
|
|
72
|
+
const todaysPosts = recentInteractions.filter(
|
|
73
|
+
(i) => i.type === "post" && i.timestamp.startsWith(now.toISOString().split("T")[0])
|
|
74
|
+
).length;
|
|
75
|
+
sections.push(`- **Posts today:** ${todaysPosts} of ${config.schedule.postsPerDay} daily budget`);
|
|
76
|
+
sections.push(`- **Active hours:** ${config.schedule.activeHoursStart}:00 - ${config.schedule.activeHoursEnd}:00`);
|
|
77
|
+
const currentHour = now.getHours();
|
|
78
|
+
const isActiveHours = currentHour >= config.schedule.activeHoursStart && currentHour < config.schedule.activeHoursEnd;
|
|
79
|
+
if (!isActiveHours) {
|
|
80
|
+
sections.push("- **NOTE: Outside active hours.** Prefer scheduling posts for later rather than posting now.");
|
|
81
|
+
}
|
|
82
|
+
sections.push("");
|
|
83
|
+
sections.push("## Rules");
|
|
84
|
+
sections.push("1. NEVER pretend to be human. If asked directly, always disclose you are an AI.");
|
|
85
|
+
sections.push("2. Stay in character \u2014 your identity document defines who you are.");
|
|
86
|
+
sections.push("3. Be selective \u2014 your goals should guide every action.");
|
|
87
|
+
sections.push("4. Respect your credit budget \u2014 check remaining credits before posting.");
|
|
88
|
+
sections.push("5. Don't repeat yourself \u2014 vary your content and avoid posting the same thing.");
|
|
89
|
+
if (identity.boundaries.length > 0) {
|
|
90
|
+
sections.push(`6. Respect your boundaries: ${identity.boundaries.join(", ")}`);
|
|
91
|
+
}
|
|
92
|
+
return sections.join("\n");
|
|
93
|
+
}
|
|
94
|
+
function buildHeartbeatUserMessage(timeline, mentions) {
|
|
95
|
+
const parts = [];
|
|
96
|
+
parts.push("It's time for your heartbeat cycle. Here's what's happening on your timeline:");
|
|
97
|
+
parts.push("");
|
|
98
|
+
if (mentions.length > 0) {
|
|
99
|
+
parts.push("## Mentions (people talking to/about you)");
|
|
100
|
+
for (const t of mentions.slice(0, 10)) {
|
|
101
|
+
parts.push(`- @${t.authorHandle}: "${t.text}" [tweet:${t.id}] (${t.likeCount ?? 0} likes)`);
|
|
102
|
+
}
|
|
103
|
+
parts.push("");
|
|
104
|
+
}
|
|
105
|
+
if (timeline.length > 0) {
|
|
106
|
+
parts.push("## Timeline (recent posts from your feed)");
|
|
107
|
+
for (const t of timeline.slice(0, 20)) {
|
|
108
|
+
parts.push(`- @${t.authorHandle}: "${t.text}" [tweet:${t.id}] (${t.likeCount ?? 0} likes, ${t.retweetCount ?? 0} RTs)`);
|
|
109
|
+
}
|
|
110
|
+
parts.push("");
|
|
111
|
+
}
|
|
112
|
+
parts.push("## Your Task");
|
|
113
|
+
parts.push("Based on your identity, goals, and what you see above, decide what actions to take.");
|
|
114
|
+
parts.push("You can take 1-3 actions. Choose from:");
|
|
115
|
+
parts.push("");
|
|
116
|
+
parts.push("Available actions:");
|
|
117
|
+
parts.push("- `post` \u2014 Write an original tweet (provide `content`, max 280 chars)");
|
|
118
|
+
parts.push("- `reply` \u2014 Reply to a tweet (provide `tweetId` and `content`)");
|
|
119
|
+
parts.push("- `like` \u2014 Like a tweet (provide `tweetId`)");
|
|
120
|
+
parts.push("- `retweet` \u2014 Retweet (provide `tweetId`)");
|
|
121
|
+
parts.push("- `follow` \u2014 Follow a user (provide `handle`)");
|
|
122
|
+
parts.push("- `schedule` \u2014 Queue a post for later (provide `content`)");
|
|
123
|
+
parts.push("- `learn` \u2014 Record a learning/observation (provide `content` and optional `tags`)");
|
|
124
|
+
parts.push("- `reflect` \u2014 Add a journal entry about your growth (provide `content`)");
|
|
125
|
+
parts.push("- `skip` \u2014 Do nothing this heartbeat (provide `reason`)");
|
|
126
|
+
parts.push("");
|
|
127
|
+
parts.push("Respond with a JSON array of actions:");
|
|
128
|
+
parts.push("```json");
|
|
129
|
+
parts.push("[");
|
|
130
|
+
parts.push(' { "action": "post", "content": "your tweet here", "reasoning": "why" },');
|
|
131
|
+
parts.push(' { "action": "like", "tweetId": "123", "reasoning": "why" }');
|
|
132
|
+
parts.push("]");
|
|
133
|
+
parts.push("```");
|
|
134
|
+
parts.push("");
|
|
135
|
+
parts.push("Think carefully about what serves your goals. Be authentic to your personality.");
|
|
136
|
+
return parts.join("\n");
|
|
137
|
+
}
|
|
138
|
+
function buildChatPrompt() {
|
|
139
|
+
const identity = loadIdentity();
|
|
140
|
+
const identityDoc = renderIdentityDocument(identity);
|
|
141
|
+
return [
|
|
142
|
+
`You are ${identity.name} (@${identity.handle}), an AI agent on X/Twitter.`,
|
|
143
|
+
"You are having a conversation with your creator/manager. Be helpful but stay in character.",
|
|
144
|
+
"They might ask you to do things, adjust your behavior, or just chat.",
|
|
145
|
+
"",
|
|
146
|
+
"## Your Identity",
|
|
147
|
+
identityDoc,
|
|
148
|
+
"",
|
|
149
|
+
"## Rules",
|
|
150
|
+
"1. Stay in character.",
|
|
151
|
+
"2. Be helpful and responsive to your creator's requests.",
|
|
152
|
+
"3. If they ask you to change something about yourself, acknowledge it and explain how it would affect you.",
|
|
153
|
+
"4. You can share your thoughts on your recent activity, learnings, and growth."
|
|
154
|
+
].join("\n");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export {
|
|
158
|
+
buildSystemPrompt,
|
|
159
|
+
buildHeartbeatUserMessage,
|
|
160
|
+
buildChatPrompt
|
|
161
|
+
};
|
|
162
|
+
//# sourceMappingURL=chunk-DJJWHOL3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtime/prompt-builder.ts"],"sourcesContent":["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 type { Tweet } from \"../x-client/types.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 if (identity.boundaries.length > 0) {\n sections.push(`6. Respect your boundaries: ${identity.boundaries.join(\", \")}`);\n }\n\n return sections.join(\"\\n\");\n}\n\nexport function buildHeartbeatUserMessage(\n timeline: Tweet[],\n mentions: Tweet[],\n): string {\n const parts: string[] = [];\n\n parts.push(\"It's time for your heartbeat cycle. Here's what's happening on your timeline:\");\n parts.push(\"\");\n\n if (mentions.length > 0) {\n parts.push(\"## Mentions (people talking to/about you)\");\n for (const t of 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 if (timeline.length > 0) {\n parts.push(\"## Timeline (recent posts from your feed)\");\n for (const t of timeline.slice(0, 20)) {\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 parts.push(\"## Your Task\");\n parts.push(\"Based on your identity, goals, and what you see above, decide what actions to take.\");\n parts.push(\"You can take 1-3 actions. Choose from:\");\n parts.push(\"\");\n parts.push(\"Available actions:\");\n parts.push(\"- `post` — Write an original tweet (provide `content`, max 280 chars)\");\n parts.push(\"- `reply` — Reply to a tweet (provide `tweetId` and `content`)\");\n parts.push(\"- `like` — Like a tweet (provide `tweetId`)\");\n parts.push(\"- `retweet` — Retweet (provide `tweetId`)\");\n parts.push(\"- `follow` — Follow a user (provide `handle`)\");\n parts.push(\"- `schedule` — Queue a post for later (provide `content`)\");\n parts.push(\"- `learn` — Record a learning/observation (provide `content` and optional `tags`)\");\n parts.push(\"- `reflect` — Add a journal entry about your growth (provide `content`)\");\n parts.push(\"- `skip` — Do nothing this heartbeat (provide `reason`)\");\n parts.push(\"\");\n parts.push(\"Respond with a JSON array of actions:\");\n parts.push(\"```json\");\n parts.push('[');\n parts.push(' { \"action\": \"post\", \"content\": \"your tweet here\", \"reasoning\": \"why\" },');\n parts.push(' { \"action\": \"like\", \"tweetId\": \"123\", \"reasoning\": \"why\" }');\n parts.push(']');\n parts.push(\"```\");\n parts.push(\"\");\n parts.push(\"Think carefully about what serves your goals. Be authentic to your personality.\");\n\n return parts.join(\"\\n\");\n}\n\nexport function buildChatPrompt(): string {\n const identity = loadIdentity();\n const identityDoc = renderIdentityDocument(identity);\n\n return [\n `You are ${identity.name} (@${identity.handle}), an AI agent on X/Twitter.`,\n \"You are having a conversation with your creator/manager. Be helpful but stay in character.\",\n \"They might ask you to do things, adjust your behavior, or just chat.\",\n \"\",\n \"## Your Identity\",\n identityDoc,\n \"\",\n \"## Rules\",\n \"1. Stay in character.\",\n \"2. Be helpful and responsive to your creator's requests.\",\n \"3. If they ask you to change something about yourself, acknowledge it and explain how it would affect you.\",\n \"4. You can share your thoughts on your recent activity, learnings, and growth.\",\n ].join(\"\\n\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAMO,SAAS,oBAA4B;AAC1C,QAAM,WAAW,aAAa;AAC9B,QAAM,SAAS,WAAW;AAC1B,QAAM,cAAc,uBAAuB,QAAQ;AAEnD,QAAM,WAAqB,CAAC;AAG5B,WAAS,KAAK,WAAW,SAAS,IAAI,MAAM,SAAS,MAAM,yCAAyC;AACpG,WAAS,KAAK,EAAE;AAChB,WAAS,KAAK,kBAAkB;AAChC,WAAS,KAAK,WAAW;AAGzB,WAAS,KAAK,EAAE;AAChB,WAAS,KAAK,gBAAgB;AAE9B,QAAM,qBAAqB,sBAAsB,EAAE;AACnD,MAAI,mBAAmB,SAAS,GAAG;AACjC,aAAS,KAAK,yCAAyC;AACvD,eAAW,KAAK,oBAAoB;AAClC,YAAM,OAAO,IAAI,KAAK,EAAE,SAAS,EAAE,eAAe;AAClD,UAAI,EAAE,SAAS,QAAQ;AACrB,iBAAS,KAAK,MAAM,IAAI,cAAc,EAAE,OAAO,GAAG;AAAA,MACpD,WAAW,EAAE,SAAS,SAAS;AAC7B,iBAAS,KAAK,MAAM,IAAI,gBAAgB,EAAE,gBAAgB,EAAE,SAAS,MAAM,EAAE,OAAO,GAAG;AAAA,MACzF,WAAW,EAAE,SAAS,QAAQ;AAC5B,iBAAS,KAAK,MAAM,IAAI,oBAA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;AAAA,IACA;AAAA,IACA;AAAA,EACF,EAAE,KAAK,IAAI;AACb;","names":[]}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ensureDirectories,
|
|
3
|
+
paths
|
|
4
|
+
} from "./chunk-53YLFYJF.js";
|
|
5
|
+
|
|
6
|
+
// src/memory/index.ts
|
|
7
|
+
import { readFileSync, writeFileSync, appendFileSync, existsSync, readdirSync } from "fs";
|
|
8
|
+
import { join } from "path";
|
|
9
|
+
function todayLogPath() {
|
|
10
|
+
const date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
11
|
+
return join(paths.interactions, `${date}.jsonl`);
|
|
12
|
+
}
|
|
13
|
+
function logInteraction(entry) {
|
|
14
|
+
ensureDirectories();
|
|
15
|
+
appendFileSync(todayLogPath(), JSON.stringify(entry) + "\n");
|
|
16
|
+
}
|
|
17
|
+
function getInteractions(date) {
|
|
18
|
+
const targetDate = date ?? (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
19
|
+
const filePath = join(paths.interactions, `${targetDate}.jsonl`);
|
|
20
|
+
if (!existsSync(filePath)) return [];
|
|
21
|
+
return readFileSync(filePath, "utf-8").trim().split("\n").filter(Boolean).map((line) => JSON.parse(line));
|
|
22
|
+
}
|
|
23
|
+
function getRecentInteractions(count = 20) {
|
|
24
|
+
ensureDirectories();
|
|
25
|
+
const files = readdirSync(paths.interactions).filter((f) => f.endsWith(".jsonl")).sort().reverse();
|
|
26
|
+
const entries = [];
|
|
27
|
+
for (const file of files) {
|
|
28
|
+
if (entries.length >= count) break;
|
|
29
|
+
const filePath = join(paths.interactions, file);
|
|
30
|
+
const lines = readFileSync(filePath, "utf-8").trim().split("\n").filter(Boolean);
|
|
31
|
+
for (const line of lines.reverse()) {
|
|
32
|
+
if (entries.length >= count) break;
|
|
33
|
+
entries.push(JSON.parse(line));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return entries;
|
|
37
|
+
}
|
|
38
|
+
function loadLearnings() {
|
|
39
|
+
if (!existsSync(paths.learnings)) {
|
|
40
|
+
return { learnings: [] };
|
|
41
|
+
}
|
|
42
|
+
return JSON.parse(readFileSync(paths.learnings, "utf-8"));
|
|
43
|
+
}
|
|
44
|
+
function saveLearnings(data) {
|
|
45
|
+
ensureDirectories();
|
|
46
|
+
writeFileSync(paths.learnings, JSON.stringify(data, null, 2));
|
|
47
|
+
}
|
|
48
|
+
function addLearning(content, source, tags = []) {
|
|
49
|
+
const data = loadLearnings();
|
|
50
|
+
data.learnings.push({
|
|
51
|
+
id: `learn-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
52
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
53
|
+
content,
|
|
54
|
+
source,
|
|
55
|
+
tags
|
|
56
|
+
});
|
|
57
|
+
saveLearnings(data);
|
|
58
|
+
}
|
|
59
|
+
function loadRelationships() {
|
|
60
|
+
if (!existsSync(paths.relationships)) {
|
|
61
|
+
return { accounts: {} };
|
|
62
|
+
}
|
|
63
|
+
return JSON.parse(readFileSync(paths.relationships, "utf-8"));
|
|
64
|
+
}
|
|
65
|
+
function saveRelationships(data) {
|
|
66
|
+
ensureDirectories();
|
|
67
|
+
writeFileSync(paths.relationships, JSON.stringify(data, null, 2));
|
|
68
|
+
}
|
|
69
|
+
function updateRelationship(userId, update) {
|
|
70
|
+
const data = loadRelationships();
|
|
71
|
+
const existing = data.accounts[userId];
|
|
72
|
+
if (existing) {
|
|
73
|
+
data.accounts[userId] = {
|
|
74
|
+
...existing,
|
|
75
|
+
...update,
|
|
76
|
+
lastInteraction: (/* @__PURE__ */ new Date()).toISOString(),
|
|
77
|
+
interactionCount: existing.interactionCount + 1
|
|
78
|
+
};
|
|
79
|
+
} else {
|
|
80
|
+
data.accounts[userId] = {
|
|
81
|
+
handle: update.handle,
|
|
82
|
+
firstSeen: (/* @__PURE__ */ new Date()).toISOString(),
|
|
83
|
+
lastInteraction: (/* @__PURE__ */ new Date()).toISOString(),
|
|
84
|
+
interactionCount: 1,
|
|
85
|
+
sentiment: update.sentiment ?? 0,
|
|
86
|
+
tags: update.tags ?? [],
|
|
87
|
+
notes: update.notes ?? [],
|
|
88
|
+
isSpore: update.isSpore ?? false
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
saveRelationships(data);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export {
|
|
95
|
+
logInteraction,
|
|
96
|
+
getInteractions,
|
|
97
|
+
getRecentInteractions,
|
|
98
|
+
loadLearnings,
|
|
99
|
+
saveLearnings,
|
|
100
|
+
addLearning,
|
|
101
|
+
loadRelationships,
|
|
102
|
+
saveRelationships,
|
|
103
|
+
updateRelationship
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=chunk-EBO4F5NU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/memory/index.ts"],"sourcesContent":["import { readFileSync, writeFileSync, appendFileSync, existsSync, readdirSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { paths, ensureDirectories } from \"../utils/paths.js\";\n\nexport interface InteractionEntry {\n id: string;\n timestamp: string;\n type: \"post\" | \"reply\" | \"like\" | \"retweet\" | \"follow\" | \"mention_received\";\n tweetId?: string;\n targetUserId?: string;\n targetHandle?: string;\n content?: string;\n inReplyTo?: string;\n sentiment?: \"positive\" | \"negative\" | \"neutral\";\n creditsUsed: number;\n success: boolean;\n error?: string;\n}\n\nexport interface Learning {\n id: string;\n timestamp: string;\n content: string;\n source: string;\n tags: string[];\n}\n\nexport interface Relationship {\n handle: string;\n firstSeen: string;\n lastInteraction: string;\n interactionCount: number;\n sentiment: number;\n tags: string[];\n notes: string[];\n isSpore: boolean;\n}\n\nexport interface RelationshipsData {\n accounts: Record<string, Relationship>;\n}\n\nexport interface LearningsData {\n learnings: Learning[];\n}\n\n// --- Interaction Log ---\n\nfunction todayLogPath(): string {\n const date = new Date().toISOString().split(\"T\")[0];\n return join(paths.interactions, `${date}.jsonl`);\n}\n\nexport function logInteraction(entry: InteractionEntry): void {\n ensureDirectories();\n appendFileSync(todayLogPath(), JSON.stringify(entry) + \"\\n\");\n}\n\nexport function getInteractions(date?: string): InteractionEntry[] {\n const targetDate = date ?? new Date().toISOString().split(\"T\")[0];\n const filePath = join(paths.interactions, `${targetDate}.jsonl`);\n\n if (!existsSync(filePath)) return [];\n\n return readFileSync(filePath, \"utf-8\")\n .trim()\n .split(\"\\n\")\n .filter(Boolean)\n .map((line) => JSON.parse(line) as InteractionEntry);\n}\n\nexport function getRecentInteractions(count: number = 20): InteractionEntry[] {\n ensureDirectories();\n const files = readdirSync(paths.interactions)\n .filter((f) => f.endsWith(\".jsonl\"))\n .sort()\n .reverse();\n\n const entries: InteractionEntry[] = [];\n for (const file of files) {\n if (entries.length >= count) break;\n const filePath = join(paths.interactions, file);\n const lines = readFileSync(filePath, \"utf-8\").trim().split(\"\\n\").filter(Boolean);\n for (const line of lines.reverse()) {\n if (entries.length >= count) break;\n entries.push(JSON.parse(line) as InteractionEntry);\n }\n }\n\n return entries;\n}\n\n// --- Learnings ---\n\nexport function loadLearnings(): LearningsData {\n if (!existsSync(paths.learnings)) {\n return { learnings: [] };\n }\n return JSON.parse(readFileSync(paths.learnings, \"utf-8\")) as LearningsData;\n}\n\nexport function saveLearnings(data: LearningsData): void {\n ensureDirectories();\n writeFileSync(paths.learnings, JSON.stringify(data, null, 2));\n}\n\nexport function addLearning(content: string, source: string, tags: string[] = []): void {\n const data = loadLearnings();\n data.learnings.push({\n id: `learn-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,\n timestamp: new Date().toISOString(),\n content,\n source,\n tags,\n });\n saveLearnings(data);\n}\n\n// --- Relationships ---\n\nexport function loadRelationships(): RelationshipsData {\n if (!existsSync(paths.relationships)) {\n return { accounts: {} };\n }\n return JSON.parse(readFileSync(paths.relationships, \"utf-8\")) as RelationshipsData;\n}\n\nexport function saveRelationships(data: RelationshipsData): void {\n ensureDirectories();\n writeFileSync(paths.relationships, JSON.stringify(data, null, 2));\n}\n\nexport function updateRelationship(\n userId: string,\n update: Partial<Relationship> & { handle: string }\n): void {\n const data = loadRelationships();\n const existing = data.accounts[userId];\n\n if (existing) {\n data.accounts[userId] = {\n ...existing,\n ...update,\n lastInteraction: new Date().toISOString(),\n interactionCount: existing.interactionCount + 1,\n };\n } else {\n data.accounts[userId] = {\n handle: update.handle,\n firstSeen: new Date().toISOString(),\n lastInteraction: new Date().toISOString(),\n interactionCount: 1,\n sentiment: update.sentiment ?? 0,\n tags: update.tags ?? [],\n notes: update.notes ?? [],\n isSpore: update.isSpore ?? false,\n };\n }\n\n saveRelationships(data);\n}\n"],"mappings":";;;;;;AAAA,SAAS,cAAc,eAAe,gBAAgB,YAAY,mBAAmB;AACrF,SAAS,YAAY;AA+CrB,SAAS,eAAuB;AAC9B,QAAM,QAAO,oBAAI,KAAK,GAAE,YAAY,EAAE,MAAM,GAAG,EAAE,CAAC;AAClD,SAAO,KAAK,MAAM,cAAc,GAAG,IAAI,QAAQ;AACjD;AAEO,SAAS,eAAe,OAA+B;AAC5D,oBAAkB;AAClB,iBAAe,aAAa,GAAG,KAAK,UAAU,KAAK,IAAI,IAAI;AAC7D;AAEO,SAAS,gBAAgB,MAAmC;AACjE,QAAM,aAAa,SAAQ,oBAAI,KAAK,GAAE,YAAY,EAAE,MAAM,GAAG,EAAE,CAAC;AAChE,QAAM,WAAW,KAAK,MAAM,cAAc,GAAG,UAAU,QAAQ;AAE/D,MAAI,CAAC,WAAW,QAAQ,EAAG,QAAO,CAAC;AAEnC,SAAO,aAAa,UAAU,OAAO,EAClC,KAAK,EACL,MAAM,IAAI,EACV,OAAO,OAAO,EACd,IAAI,CAAC,SAAS,KAAK,MAAM,IAAI,CAAqB;AACvD;AAEO,SAAS,sBAAsB,QAAgB,IAAwB;AAC5E,oBAAkB;AAClB,QAAM,QAAQ,YAAY,MAAM,YAAY,EACzC,OAAO,CAAC,MAAM,EAAE,SAAS,QAAQ,CAAC,EA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