You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Guidelines for AI agents working on this codebase.
Project Overview
An OpenCode plugin that adds configurable personality and mood systems to AI assistants. Supports multiple personalities per config file with per-personality mood state tracking. The plugin injects the active personality traits into the system prompt and manages a mood state machine that drifts over time.
Code Style
TypeScript: Strict mode enabled with noUncheckedIndexedAccess and exactOptionalPropertyTypes
Formatting: Use Prettier defaults (no config file needed)
Imports: Use .js extensions for local imports (ESM)
Types: Prefer explicit types for function parameters and return values
Null handling: Use ! only when value is guaranteed; prefer guards
Comments: Avoid inline comments; use JSDoc for public APIs only
Mood drift algorithm - uses seeded random for testing
src/prompt.ts
Builds personality section for system prompt
src/index.ts
Plugin hooks registration, main entry point
Plugin Hooks Used
Hook
Purpose
experimental.chat.system.transform
Inject active personality into system prompt
event
Drift mood after assistant responses
command.execute.before
Handle /mood and /personality commands
Testing Workflow
Run npm run typecheck to verify types
Run npm run lint to check code style
Run npm run build to verify build
Test in OpenCode by updating opencode.json to point to src/index.ts
Making Changes
Adding a New Personality Field
Add field to PersonalityDefinition in src/types.ts
Add default value in mergeWithDefaults() in src/config.ts
Use the field in src/prompt.ts or other consumers
Update savePersonality tool args in src/tools/savePersonality.ts
Update README config reference
Adding a New Mood Field
Add type to MoodDefinition or MoodConfig in src/types.ts
Add default value in DEFAULT_MOODS or DEFAULT_MOOD_CONFIG in src/config.ts
Use the field in src/mood.ts or src/prompt.ts
Update README config reference
Adding a New Command
Create handler in src/commands/
Import and wire up in src/index.tscommand.execute.before hook
Register in opencode.json command definitions
Document in README
Adding a New Tool
Create tool in src/tools/ using tool() from @opencode-ai/plugin
Import and add to tool: object in src/index.ts
Document in README Tools section
Adding a New Hook
Add implementation in src/index.ts return object
Follow existing patterns for hook signatures
Document behavior in README if user-facing
Release Process
Update version in package.json
Update CHANGELOG.md
Commit: git commit -m "chore: release vX.Y.Z"
Tag: git tag vX.Y.Z
Push: git push && git push --tags
GitHub Actions handles npm publish
Common Patterns
Config Loading
constconfigResult=loadConfigWithPrecedence(directory)if(configResult.config===null){// No config - return minimal hooks or no-opreturn{}}constconfig=configResult.config// PersonalityDefinition (active)constfile=configResult.file!// PersonalityFile (full store)constactiveKey=file.active// Key of active personality
Multi-Personality Operations
import{listPersonalities,addPersonality,removePersonality,switchActivePersonality}from"./config.js"constnames=listPersonalities(file)constupdated=addPersonality(file,"NewBot",definition)constswitched=switchActivePersonality(file,"NewBot")constreduced=removePersonality(file,"OldBot")// null if last personality removed