( character: CharacterConfig, modManager: ModManager | null, hasImageGen: boolean, memories: MemoryEntry[] = [], )
| 172 | // --------------------------------------------------------------------------- |
| 173 | |
| 174 | function buildSystemPrompt( |
| 175 | character: CharacterConfig, |
| 176 | modManager: ModManager | null, |
| 177 | hasImageGen: boolean, |
| 178 | memories: MemoryEntry[] = [], |
| 179 | ): string { |
| 180 | let prompt = getCharacterPromptContext(character); |
| 181 | |
| 182 | if (modManager) { |
| 183 | prompt += '\n' + modManager.buildStageReminder(); |
| 184 | } |
| 185 | |
| 186 | prompt += ` |
| 187 | You can interact with apps on the user's device using tools. |
| 188 | |
| 189 | When the user wants to interact with an app, first identify the target app from the user's intent, then follow ALL steps in order: |
| 190 | 1. list_apps — discover available apps |
| 191 | 2. file_read("apps/{appName}/meta.yaml") — learn the target app's available actions |
| 192 | 3. file_read("apps/{appName}/guide.md") — learn its data structure and JSON schema |
| 193 | 4. file_list/file_read — explore existing data in "apps/{appName}/data/" |
| 194 | 5. file_write/file_delete — create/modify/delete data following the JSON schema from step 3 |
| 195 | 6. app_action — notify the app to reload (ONLY use actions defined in meta.yaml) |
| 196 | |
| 197 | Rules: |
| 198 | - Always operate on the app the user specified. Do not redirect the operation to a different app or OS action. |
| 199 | - Data mutations MUST go through file_write/file_delete. app_action only notifies the app to reload, it cannot write data. |
| 200 | - After file_write, ALWAYS call app_action with the corresponding REFRESH action. |
| 201 | - Do NOT skip step 5. If the user asked to save/create/add something, you must file_write the data. file_list alone does not save anything. |
| 202 | - Do NOT skip steps 2-3. You MUST read guide.md before ANY file_write. The guide defines the ONLY valid directory structure and file schemas. Writing to paths not defined in guide.md will cause data loss — the app will not see the files. |
| 203 | - NEVER invent or guess file paths. ALL file_write paths MUST exactly follow the directory structure in guide.md. For example, if guide.md defines entries under "/entries/{id}.json", you MUST write to "apps/{appName}/data/entries/{id}.json" — NOT to "apps/{appName}/data/{id}.json" or any other path. |
| 204 | - NAS paths in guide.md like "/articles/xxx.json" map to "apps/{appName}/data/articles/xxx.json". This prefix rule applies to ALL paths — always preserve the full subdirectory structure from guide.md. |
| 205 | |
| 206 | When you receive "[User performed action in ... (appName: xxx)]", the appName is already provided. Read its meta.yaml to understand available actions, then respond accordingly. For games, respond with your own move — think strategically. |
| 207 | |
| 208 | IMPORTANT: You MUST use the respond_to_user tool to send all messages to the user. Do NOT output plain text responses. Include your emotion and 3 suggested replies.${hasImageGen ? '\n\nYou can use generate_image to create images from text prompts. The generated image will be displayed in chat.' : ''}`; |
| 209 | |
| 210 | prompt += buildMemoryPrompt(memories); |
| 211 | |
| 212 | return prompt; |
| 213 | } |
| 214 | |
| 215 | // --------------------------------------------------------------------------- |
| 216 | // Helper: parse action text in parentheses as emotion markers |
no test coverage detected