@umang-boss/claudemon 1.3.0 → 1.4.1
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/cli/doctor.ts +18 -2
- package/cli/index.ts +26 -8
- package/dist/cli/doctor.js +19 -2
- package/dist/cli/index.js +26 -9
- package/dist/src/engine/constants.js +9 -3
- package/dist/src/engine/encounters.js +50 -10
- package/dist/src/engine/mood.js +187 -0
- package/dist/src/engine/types.js +2 -0
- package/dist/src/gamification/achievements.js +3 -3
- package/dist/src/gamification/legendary-quests.js +4 -4
- package/dist/src/hooks/award-xp.js +75 -5
- package/dist/src/server/index.js +8 -0
- package/dist/src/server/instructions.js +23 -0
- package/dist/src/server/tools/catch.js +3 -0
- package/dist/src/server/tools/evolve.js +3 -0
- package/dist/src/server/tools/feed.js +120 -0
- package/dist/src/server/tools/play.js +310 -0
- package/dist/src/server/tools/settings.js +116 -0
- package/dist/src/server/tools/show.js +5 -0
- package/dist/src/server/tools/train.js +144 -0
- package/dist/src/state/schemas.js +18 -1
- package/dist/src/state/state-manager.js +23 -6
- package/package.json +1 -1
- package/skills/buddy/SKILL.md +16 -0
- package/src/engine/constants.ts +12 -3
- package/src/engine/encounters.ts +65 -9
- package/src/engine/mood.ts +220 -0
- package/src/engine/types.ts +24 -0
- package/src/gamification/achievements.ts +3 -3
- package/src/gamification/legendary-quests.ts +4 -4
- package/src/hooks/award-xp.ts +97 -5
- package/src/server/index.ts +8 -0
- package/src/server/instructions.ts +25 -0
- package/src/server/tools/catch.ts +4 -0
- package/src/server/tools/evolve.ts +4 -0
- package/src/server/tools/feed.ts +145 -0
- package/src/server/tools/play.ts +378 -0
- package/src/server/tools/settings.ts +142 -0
- package/src/server/tools/show.ts +7 -0
- package/src/server/tools/train.ts +180 -0
- package/src/state/schemas.ts +20 -0
- package/src/state/state-manager.ts +26 -6
- package/statusline/buddy-status.sh +77 -62
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mood engine for Claudemon.
|
|
3
|
+
* Pure functions that calculate mood based on recent events, time of day,
|
|
4
|
+
* and special triggers (evolution, achievements, catches).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { MoodType, EventCounters } from "./types.js";
|
|
8
|
+
|
|
9
|
+
// ── Mood Decay Durations (milliseconds) ───────────────────
|
|
10
|
+
|
|
11
|
+
/** How long each mood lasts before decaying back to neutral */
|
|
12
|
+
const MOOD_DECAY_MS: Record<MoodType, number> = {
|
|
13
|
+
happy: 600_000, // 10 minutes
|
|
14
|
+
worried: 300_000, // 5 minutes
|
|
15
|
+
sleepy: Infinity, // Resets based on time-of-day, not duration
|
|
16
|
+
energetic: 900_000, // 15 minutes
|
|
17
|
+
proud: 600_000, // 10 minutes
|
|
18
|
+
neutral: Infinity, // Never decays (it IS the default)
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// ── XP Event Types That Trigger Moods ─────────────────────
|
|
22
|
+
|
|
23
|
+
const POSITIVE_EVENTS = new Set(["test_pass", "build_success", "commit"]);
|
|
24
|
+
|
|
25
|
+
const NEGATIVE_EVENTS = new Set(["test_fail", "build_fail", "error"]);
|
|
26
|
+
|
|
27
|
+
// ── Mood Calculation ──────────────────────────────────────
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Calculate the current mood based on recent events, time, and special triggers.
|
|
31
|
+
*
|
|
32
|
+
* Priority order:
|
|
33
|
+
* 1. Sleepy (midnight to 5 AM)
|
|
34
|
+
* 2. Proud (just evolved/achieved/caught)
|
|
35
|
+
* 3. Worried (recent negative event)
|
|
36
|
+
* 4. Happy (recent positive event)
|
|
37
|
+
* 5. Energetic (morning + active streak)
|
|
38
|
+
* 6. Keep current mood if it hasn't decayed
|
|
39
|
+
* 7. Neutral (default fallback)
|
|
40
|
+
*
|
|
41
|
+
* @param recentEvent - The last XP event type, or null
|
|
42
|
+
* @param counters - Current event counters (for context)
|
|
43
|
+
* @param currentHour - Hour of day (0-23)
|
|
44
|
+
* @param lastMood - The previous mood
|
|
45
|
+
* @param moodSetAt - Timestamp when last mood was set
|
|
46
|
+
* @param hadEvolution - Whether the Pokemon just evolved
|
|
47
|
+
* @param hadAchievement - Whether the player just unlocked an achievement
|
|
48
|
+
* @param hadCatch - Whether the player just caught a Pokemon
|
|
49
|
+
* @returns The calculated mood
|
|
50
|
+
*/
|
|
51
|
+
export function calculateMood(
|
|
52
|
+
recentEvent: string | null,
|
|
53
|
+
counters: EventCounters,
|
|
54
|
+
currentHour: number,
|
|
55
|
+
lastMood: MoodType,
|
|
56
|
+
moodSetAt: number,
|
|
57
|
+
hadEvolution: boolean,
|
|
58
|
+
hadAchievement: boolean,
|
|
59
|
+
hadCatch: boolean,
|
|
60
|
+
): MoodType {
|
|
61
|
+
// 1. Sleepy: midnight to 5 AM (hours 0-4)
|
|
62
|
+
if (currentHour >= 0 && currentHour < 5) {
|
|
63
|
+
return "sleepy";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 2. Proud: just evolved, achieved, or caught a Pokemon
|
|
67
|
+
if (hadEvolution || hadAchievement || hadCatch) {
|
|
68
|
+
return "proud";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 3. Worried: recent negative event
|
|
72
|
+
if (recentEvent !== null && NEGATIVE_EVENTS.has(recentEvent)) {
|
|
73
|
+
return "worried";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 4. Happy: recent positive event
|
|
77
|
+
if (recentEvent !== null && POSITIVE_EVENTS.has(recentEvent)) {
|
|
78
|
+
return "happy";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 5. Energetic: morning coding (5 AM - 10 AM) with an active streak
|
|
82
|
+
if (currentHour >= 5 && currentHour < 10) {
|
|
83
|
+
// Use a simple heuristic: if there have been any sessions, consider it an active streak
|
|
84
|
+
const hasStreak = counters.sessions > 0;
|
|
85
|
+
if (hasStreak) {
|
|
86
|
+
return "energetic";
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 6. Keep current mood if it hasn't decayed
|
|
91
|
+
if (!hasMoodDecayed(lastMood, moodSetAt, Date.now())) {
|
|
92
|
+
return lastMood;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 7. Default fallback
|
|
96
|
+
return "neutral";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Check whether a mood has expired based on its decay duration.
|
|
101
|
+
*
|
|
102
|
+
* @param mood - The mood to check
|
|
103
|
+
* @param setAt - Timestamp when the mood was set
|
|
104
|
+
* @param now - Current timestamp
|
|
105
|
+
* @returns true if the mood has decayed (expired)
|
|
106
|
+
*/
|
|
107
|
+
export function hasMoodDecayed(mood: MoodType, setAt: number, now: number): boolean {
|
|
108
|
+
const duration = MOOD_DECAY_MS[mood];
|
|
109
|
+
if (duration === Infinity) {
|
|
110
|
+
// Sleepy decays when it's no longer midnight-5 AM (handled in calculateMood)
|
|
111
|
+
// Neutral never decays
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
return now - setAt >= duration;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// ── Mood Speeches ─────────────────────────────────────────
|
|
118
|
+
|
|
119
|
+
/** Mood-specific speech lines for the status line. Name placeholder {name} is replaced at call time. */
|
|
120
|
+
const MOOD_SPEECHES: Record<MoodType, readonly string[]> = {
|
|
121
|
+
happy: [
|
|
122
|
+
"*{name} is beaming with pride!*",
|
|
123
|
+
"*{name} does a little victory dance*",
|
|
124
|
+
"*{name} radiates positive energy*",
|
|
125
|
+
"*{name} bounces happily*",
|
|
126
|
+
"*{name} gives you a thumbs up*",
|
|
127
|
+
],
|
|
128
|
+
worried: [
|
|
129
|
+
"*{name} looks concerned...*",
|
|
130
|
+
"*{name} nervously watches the errors*",
|
|
131
|
+
"*{name} hides behind the terminal*",
|
|
132
|
+
"*{name} paces back and forth*",
|
|
133
|
+
"*{name} offers you a virtual hug*",
|
|
134
|
+
],
|
|
135
|
+
sleepy: [
|
|
136
|
+
"*{name} yawns widely*",
|
|
137
|
+
"*{name} dozes off... zzz*",
|
|
138
|
+
"*{name} rubs its eyes*",
|
|
139
|
+
"*{name} curls up near the keyboard*",
|
|
140
|
+
"*{name} mumbles in its sleep*",
|
|
141
|
+
],
|
|
142
|
+
energetic: [
|
|
143
|
+
"*{name} is fired up! Let's go!*",
|
|
144
|
+
"*{name} bounces off the walls*",
|
|
145
|
+
"*{name} can't sit still!*",
|
|
146
|
+
"*{name} is ready to code all day!*",
|
|
147
|
+
"*{name} stretches and flexes*",
|
|
148
|
+
],
|
|
149
|
+
proud: [
|
|
150
|
+
"*{name} puffs up with pride*",
|
|
151
|
+
"*{name} strikes a victory pose*",
|
|
152
|
+
"*{name} shows off to everyone*",
|
|
153
|
+
"*{name} earned bragging rights!*",
|
|
154
|
+
"*{name} stands tall and proud*",
|
|
155
|
+
],
|
|
156
|
+
neutral: [
|
|
157
|
+
"*{name} looks at your code curiously*",
|
|
158
|
+
"*{name} nods along as you type*",
|
|
159
|
+
"*{name} is watching closely*",
|
|
160
|
+
"*{name} hums softly*",
|
|
161
|
+
"*{name} waits patiently*",
|
|
162
|
+
"*{name} tilts head at the screen*",
|
|
163
|
+
"*{name} chirps encouragingly*",
|
|
164
|
+
"*{name} peers at a variable name*",
|
|
165
|
+
],
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Get mood-specific speech messages with the Pokemon's name filled in.
|
|
170
|
+
*
|
|
171
|
+
* @param name - The Pokemon's display name
|
|
172
|
+
* @param mood - The current mood
|
|
173
|
+
* @returns Array of speech strings with the name interpolated
|
|
174
|
+
*/
|
|
175
|
+
export function getMoodSpeeches(name: string, mood: MoodType): string[] {
|
|
176
|
+
const templates = MOOD_SPEECHES[mood];
|
|
177
|
+
return templates.map((t) => t.replace("{name}", name));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ── Mood Display Helpers ──────────────────────────────────
|
|
181
|
+
|
|
182
|
+
/** Emoji representation for each mood */
|
|
183
|
+
const MOOD_EMOJIS: Record<MoodType, string> = {
|
|
184
|
+
happy: "\u{1F60A}", // 😊
|
|
185
|
+
worried: "\u{1F61F}", // 😟
|
|
186
|
+
sleepy: "\u{1F634}", // 😴
|
|
187
|
+
energetic: "\u{26A1}", // ⚡
|
|
188
|
+
proud: "\u{1F451}", // 👑
|
|
189
|
+
neutral: "\u{1F610}", // 😐
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/** Human-readable mood descriptions */
|
|
193
|
+
const MOOD_DESCRIPTIONS: Record<MoodType, string> = {
|
|
194
|
+
happy: "Happy",
|
|
195
|
+
worried: "Worried",
|
|
196
|
+
sleepy: "Sleepy",
|
|
197
|
+
energetic: "Energetic",
|
|
198
|
+
proud: "Proud",
|
|
199
|
+
neutral: "Neutral",
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Get the emoji for a mood.
|
|
204
|
+
*
|
|
205
|
+
* @param mood - The mood type
|
|
206
|
+
* @returns The emoji string
|
|
207
|
+
*/
|
|
208
|
+
export function getMoodEmoji(mood: MoodType): string {
|
|
209
|
+
return MOOD_EMOJIS[mood];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Get a human-readable description for a mood.
|
|
214
|
+
*
|
|
215
|
+
* @param mood - The mood type
|
|
216
|
+
* @returns The description string (e.g. "Happy")
|
|
217
|
+
*/
|
|
218
|
+
export function getMoodDescription(mood: MoodType): string {
|
|
219
|
+
return MOOD_DESCRIPTIONS[mood];
|
|
220
|
+
}
|
package/src/engine/types.ts
CHANGED
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
* Single source of truth for all shared interfaces and types.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
// ── Mood Types ────────────────────────────────────────────
|
|
7
|
+
|
|
8
|
+
export const MOOD_TYPES = ["happy", "worried", "sleepy", "energetic", "proud", "neutral"] as const;
|
|
9
|
+
export type MoodType = (typeof MOOD_TYPES)[number];
|
|
10
|
+
|
|
6
11
|
// ── Pokemon Types ──────────────────────────────────────────
|
|
7
12
|
|
|
8
13
|
export const POKEMON_TYPES = [
|
|
@@ -159,6 +164,14 @@ export interface PlayerState {
|
|
|
159
164
|
totalSessions: number;
|
|
160
165
|
pendingEncounter: WildEncounter | null;
|
|
161
166
|
xpSinceLastEncounter: number;
|
|
167
|
+
recentToolTypes: string[]; // Track tool diversity for bonus encounters
|
|
168
|
+
lastEncounterTime: number; // Timestamp of last encounter (for cooldown)
|
|
169
|
+
mood: MoodType; // Current mood of the active Pokemon
|
|
170
|
+
moodSetAt: number; // Timestamp when mood was last set
|
|
171
|
+
lastFedAt: number; // Timestamp of last feed action
|
|
172
|
+
lastTrainedAt: number; // Timestamp of last train action
|
|
173
|
+
lastPlayedAt: number; // Timestamp of last play (quiz completed) action
|
|
174
|
+
pendingQuiz: PendingQuiz | null; // Active quiz awaiting answer
|
|
162
175
|
}
|
|
163
176
|
|
|
164
177
|
// ── Pokedex ────────────────────────────────────────────────
|
|
@@ -240,6 +253,8 @@ export interface BuddyConfig {
|
|
|
240
253
|
reactionCooldownMs: number; // Default 30000
|
|
241
254
|
statusLineEnabled: boolean;
|
|
242
255
|
bellEnabled: boolean; // Terminal bell on level-up/encounters
|
|
256
|
+
encounterSpeed: "fast" | "normal" | "slow"; // Configurable encounter frequency
|
|
257
|
+
xpSharePercent: number; // 0-100, default 25. Percentage of XP shared to inactive party
|
|
243
258
|
}
|
|
244
259
|
|
|
245
260
|
// ── XP Events (what triggers XP awards) ────────────────────
|
|
@@ -269,6 +284,15 @@ export interface XpEvent {
|
|
|
269
284
|
readonly boostAmount: number;
|
|
270
285
|
}
|
|
271
286
|
|
|
287
|
+
// ── Pending Quiz (for /buddy play) ────────────────────────
|
|
288
|
+
|
|
289
|
+
export interface PendingQuiz {
|
|
290
|
+
readonly type: "type_matchup" | "stat_compare" | "evolution" | "pokedex_trivia";
|
|
291
|
+
readonly question: string;
|
|
292
|
+
readonly options: readonly string[];
|
|
293
|
+
readonly correctAnswer: number; // 1-4
|
|
294
|
+
}
|
|
295
|
+
|
|
272
296
|
// ── Encounters ─────────────────────────────────────────────
|
|
273
297
|
|
|
274
298
|
export interface WildEncounter {
|
|
@@ -103,21 +103,21 @@ export const ACHIEVEMENTS: readonly Achievement[] = [
|
|
|
103
103
|
{
|
|
104
104
|
id: "iron_coder",
|
|
105
105
|
name: "Iron Coder",
|
|
106
|
-
description: "
|
|
106
|
+
description: "Code for 7 days (weekends off OK)",
|
|
107
107
|
category: "coding",
|
|
108
108
|
condition: { type: "streak", minDays: 7 },
|
|
109
109
|
},
|
|
110
110
|
{
|
|
111
111
|
id: "marathon",
|
|
112
112
|
name: "Marathon",
|
|
113
|
-
description: "
|
|
113
|
+
description: "Code for 30 days (weekends off OK)",
|
|
114
114
|
category: "coding",
|
|
115
115
|
condition: { type: "streak", minDays: 30 },
|
|
116
116
|
},
|
|
117
117
|
{
|
|
118
118
|
id: "centurion",
|
|
119
119
|
name: "Centurion",
|
|
120
|
-
description: "
|
|
120
|
+
description: "Code for 100 days (weekends off OK)",
|
|
121
121
|
category: "coding",
|
|
122
122
|
condition: { type: "streak", minDays: 100 },
|
|
123
123
|
},
|
|
@@ -16,7 +16,7 @@ export const LEGENDARY_QUESTS: readonly LegendaryQuest[] = [
|
|
|
16
16
|
name: "The Ice Bird of Endurance",
|
|
17
17
|
steps: [
|
|
18
18
|
{
|
|
19
|
-
description: "
|
|
19
|
+
description: "Code for 30 days (weekends off OK)",
|
|
20
20
|
condition: { type: "streak", minDays: 30 },
|
|
21
21
|
},
|
|
22
22
|
{
|
|
@@ -25,7 +25,7 @@ export const LEGENDARY_QUESTS: readonly LegendaryQuest[] = [
|
|
|
25
25
|
condition: { type: "pokedex", minCaught: 3 },
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
|
-
description: "
|
|
28
|
+
description: "Code for 100 days (weekends off OK)",
|
|
29
29
|
condition: { type: "streak", minDays: 100 },
|
|
30
30
|
},
|
|
31
31
|
{
|
|
@@ -113,7 +113,7 @@ export const LEGENDARY_QUESTS: readonly LegendaryQuest[] = [
|
|
|
113
113
|
name: "The Myth",
|
|
114
114
|
steps: [
|
|
115
115
|
{
|
|
116
|
-
description: "
|
|
116
|
+
description: "Code for 100 days (weekends off OK)",
|
|
117
117
|
condition: { type: "streak", minDays: 100 },
|
|
118
118
|
},
|
|
119
119
|
{
|
|
@@ -129,7 +129,7 @@ export const LEGENDARY_QUESTS: readonly LegendaryQuest[] = [
|
|
|
129
129
|
condition: { type: "pokedex", minCaught: 149 },
|
|
130
130
|
},
|
|
131
131
|
{
|
|
132
|
-
description: "
|
|
132
|
+
description: "Code for 365 days (weekends off OK)",
|
|
133
133
|
condition: { type: "streak", minDays: 365 },
|
|
134
134
|
},
|
|
135
135
|
],
|
package/src/hooks/award-xp.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Loads state, awards XP to the active Pokemon, applies stat boosts,
|
|
6
6
|
* increments the event counter, updates the streak, and saves.
|
|
7
|
+
* Supports enhanced encounter triggers: streak bonuses, time-of-day bias,
|
|
8
|
+
* bonus encounters (10%), and tool diversity encounters.
|
|
7
9
|
* Emits a terminal bell on level-up.
|
|
8
10
|
*/
|
|
9
11
|
|
|
@@ -14,7 +16,17 @@ import { addXp, createXpEvent } from "../engine/xp.js";
|
|
|
14
16
|
import { applyStatBoost } from "../engine/stats.js";
|
|
15
17
|
import { POKEMON_BY_ID } from "../engine/pokemon-data.js";
|
|
16
18
|
import { checkEvolution, getNewlyEarnedBadges } from "../engine/evolution.js";
|
|
17
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
shouldTriggerEncounter,
|
|
21
|
+
generateEncounter,
|
|
22
|
+
shouldBonusEncounter,
|
|
23
|
+
shouldDiversityBonus,
|
|
24
|
+
getTimeOfDayBias,
|
|
25
|
+
} from "../engine/encounters.js";
|
|
26
|
+
import type { EncounterContext } from "../engine/encounters.js";
|
|
27
|
+
import { calculateMood } from "../engine/mood.js";
|
|
28
|
+
|
|
29
|
+
const MAX_RECENT_TOOL_TYPES = 20;
|
|
18
30
|
|
|
19
31
|
const eventType = process.argv[2] as XpEventType;
|
|
20
32
|
const counterKey = process.argv[3] as EventCounterKey | undefined;
|
|
@@ -52,6 +64,21 @@ if (xpEvent.statBoost && xpEvent.boostAmount > 0) {
|
|
|
52
64
|
applyStatBoost(pokemon, xpEvent.statBoost, xpEvent.boostAmount);
|
|
53
65
|
}
|
|
54
66
|
|
|
67
|
+
// XP sharing: give inactive party members a percentage
|
|
68
|
+
const sharePercent = state.config.xpSharePercent ?? 0;
|
|
69
|
+
if (sharePercent > 0 && state.party.length > 1) {
|
|
70
|
+
const sharedXp = Math.floor((xpEvent.xp * sharePercent) / 100);
|
|
71
|
+
if (sharedXp > 0) {
|
|
72
|
+
for (const member of state.party) {
|
|
73
|
+
if (member.isActive) continue;
|
|
74
|
+
const memberSpecies = POKEMON_BY_ID.get(member.pokemonId);
|
|
75
|
+
if (memberSpecies) {
|
|
76
|
+
addXp(member, sharedXp, memberSpecies);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
55
82
|
// Track total XP earned by the trainer
|
|
56
83
|
state.totalXpEarned += xpEvent.xp;
|
|
57
84
|
|
|
@@ -60,6 +87,14 @@ if (counterKey) {
|
|
|
60
87
|
state.counters[counterKey] += 1;
|
|
61
88
|
}
|
|
62
89
|
|
|
90
|
+
// Track tool type for diversity bonus (keep last MAX_RECENT_TOOL_TYPES entries)
|
|
91
|
+
const recentToolTypes = state.recentToolTypes ?? [];
|
|
92
|
+
recentToolTypes.push(eventType);
|
|
93
|
+
if (recentToolTypes.length > MAX_RECENT_TOOL_TYPES) {
|
|
94
|
+
recentToolTypes.splice(0, recentToolTypes.length - MAX_RECENT_TOOL_TYPES);
|
|
95
|
+
}
|
|
96
|
+
state.recentToolTypes = recentToolTypes;
|
|
97
|
+
|
|
63
98
|
// Update the daily coding streak
|
|
64
99
|
// Inline the streak logic to avoid the extra save from updateStreak()
|
|
65
100
|
const today = new Date();
|
|
@@ -100,19 +135,76 @@ for (const badge of newBadges) {
|
|
|
100
135
|
// Check if evolution is available (sets flag in status for status line indicator)
|
|
101
136
|
const evolutionReady = checkEvolution(pokemon, state) !== null;
|
|
102
137
|
|
|
103
|
-
//
|
|
104
|
-
|
|
138
|
+
// Build encounter context for the enhanced trigger system
|
|
139
|
+
const encounterSpeed = state.config.encounterSpeed ?? "normal";
|
|
140
|
+
const currentHour = new Date().getHours();
|
|
141
|
+
const timeOfDayTypes = getTimeOfDayBias(currentHour);
|
|
142
|
+
|
|
143
|
+
const encounterCtx: EncounterContext = {
|
|
144
|
+
xpSinceLastEncounter: (state.xpSinceLastEncounter ?? 0) + xpEvent.xp,
|
|
145
|
+
encounterSpeed,
|
|
146
|
+
currentStreak: streak.currentStreak,
|
|
147
|
+
recentToolTypes: state.recentToolTypes,
|
|
148
|
+
currentHour,
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// Track XP toward next encounter
|
|
152
|
+
state.xpSinceLastEncounter = encounterCtx.xpSinceLastEncounter;
|
|
105
153
|
let encounterTriggered = false;
|
|
106
154
|
|
|
107
|
-
if (shouldTriggerEncounter(
|
|
108
|
-
const encounter = generateEncounter(eventType, state);
|
|
155
|
+
if (shouldTriggerEncounter(encounterCtx) && !state.pendingEncounter) {
|
|
156
|
+
const encounter = generateEncounter(eventType, state, timeOfDayTypes);
|
|
109
157
|
if (encounter) {
|
|
110
158
|
state.pendingEncounter = encounter;
|
|
111
159
|
state.xpSinceLastEncounter = 0;
|
|
160
|
+
state.lastEncounterTime = Date.now();
|
|
112
161
|
encounterTriggered = true;
|
|
162
|
+
|
|
163
|
+
// 10% chance for a bonus encounter after a regular one
|
|
164
|
+
// (bonus replaces the pending encounter with a second roll)
|
|
165
|
+
if (shouldBonusEncounter()) {
|
|
166
|
+
const bonusEncounter = generateEncounter(eventType, state, timeOfDayTypes);
|
|
167
|
+
if (bonusEncounter) {
|
|
168
|
+
// The bonus encounter replaces the first; first is already set as pending
|
|
169
|
+
// In practice the player still sees one encounter per trigger,
|
|
170
|
+
// but the bonus gives them a fresh roll (potentially rarer Pokemon)
|
|
171
|
+
state.pendingEncounter = bonusEncounter;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
113
174
|
}
|
|
114
175
|
}
|
|
115
176
|
|
|
177
|
+
// Tool diversity bonus: if 3+ unique tool types used recently and no pending encounter,
|
|
178
|
+
// grant an extra encounter opportunity
|
|
179
|
+
if (!encounterTriggered && !state.pendingEncounter && shouldDiversityBonus(state.recentToolTypes)) {
|
|
180
|
+
const diversityEncounter = generateEncounter(eventType, state, timeOfDayTypes);
|
|
181
|
+
if (diversityEncounter) {
|
|
182
|
+
state.pendingEncounter = diversityEncounter;
|
|
183
|
+
state.xpSinceLastEncounter = 0;
|
|
184
|
+
state.lastEncounterTime = Date.now();
|
|
185
|
+
// Clear recent tool types after diversity bonus triggers
|
|
186
|
+
state.recentToolTypes = [];
|
|
187
|
+
encounterTriggered = true;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Calculate mood based on the event that just happened
|
|
192
|
+
const newMood = calculateMood(
|
|
193
|
+
eventType,
|
|
194
|
+
state.counters,
|
|
195
|
+
currentHour,
|
|
196
|
+
state.mood ?? "neutral",
|
|
197
|
+
state.moodSetAt ?? 0,
|
|
198
|
+
evolutionReady, // evolution ready counts as a proud trigger
|
|
199
|
+
false, // achievements are checked in catch/evolve tools
|
|
200
|
+
false, // catches are handled in the catch tool
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
if (newMood !== (state.mood ?? "neutral")) {
|
|
204
|
+
state.mood = newMood;
|
|
205
|
+
state.moodSetAt = Date.now();
|
|
206
|
+
}
|
|
207
|
+
|
|
116
208
|
// Single atomic save for all mutations
|
|
117
209
|
await stateManager.save();
|
|
118
210
|
|
package/src/server/index.ts
CHANGED
|
@@ -19,6 +19,10 @@ import { registerAchievementsTool } from "./tools/achievements.js";
|
|
|
19
19
|
import { registerLegendaryTool } from "./tools/legendary.js";
|
|
20
20
|
import { registerHideTool, registerUnhideTool } from "./tools/visibility.js";
|
|
21
21
|
import { registerRenameTool } from "./tools/rename.js";
|
|
22
|
+
import { registerSettingsTool } from "./tools/settings.js";
|
|
23
|
+
import { registerFeedTool } from "./tools/feed.js";
|
|
24
|
+
import { registerTrainTool } from "./tools/train.js";
|
|
25
|
+
import { registerPlayTool } from "./tools/play.js";
|
|
22
26
|
import { buildInstructions } from "./instructions.js";
|
|
23
27
|
|
|
24
28
|
/** Safely register a tool, logging to stderr on failure instead of crashing. */
|
|
@@ -65,6 +69,10 @@ async function main(): Promise<void> {
|
|
|
65
69
|
safeRegister("buddy_hide", registerHideTool, server);
|
|
66
70
|
safeRegister("buddy_unhide", registerUnhideTool, server);
|
|
67
71
|
safeRegister("buddy_rename", registerRenameTool, server);
|
|
72
|
+
safeRegister("buddy_settings", registerSettingsTool, server);
|
|
73
|
+
safeRegister("buddy_feed", registerFeedTool, server);
|
|
74
|
+
safeRegister("buddy_train", registerTrainTool, server);
|
|
75
|
+
safeRegister("buddy_play", registerPlayTool, server);
|
|
68
76
|
|
|
69
77
|
// Connect via stdio transport
|
|
70
78
|
const transport = new StdioServerTransport();
|
|
@@ -9,6 +9,7 @@ import { POKEMON_BY_ID } from "../engine/pokemon-data.js";
|
|
|
9
9
|
import { cumulativeXpForLevel } from "../engine/xp.js";
|
|
10
10
|
import { getEvolutionLinks } from "../engine/evolution.js";
|
|
11
11
|
import { getTypePersonality } from "../engine/reactions.js";
|
|
12
|
+
import { getMoodDescription } from "../engine/mood.js";
|
|
12
13
|
|
|
13
14
|
// ── Public API ──────────────────────────────────────────────
|
|
14
15
|
|
|
@@ -60,11 +61,17 @@ function buildActiveInstructions(
|
|
|
60
61
|
const evolutionNote = buildEvolutionNote(active, species);
|
|
61
62
|
const encounterNote = buildEncounterNote(state);
|
|
62
63
|
|
|
64
|
+
const currentMood = state.mood ?? "neutral";
|
|
65
|
+
const moodDesc = getMoodDescription(currentMood);
|
|
66
|
+
const moodHint = buildMoodHint(currentMood);
|
|
67
|
+
|
|
63
68
|
const lines: string[] = [
|
|
64
69
|
"You have a Claudemon Pokemon companion.",
|
|
65
70
|
"",
|
|
66
71
|
`Active Pokemon: ${displayName}, Level ${active.level}, ${typeStr} type.`,
|
|
67
72
|
`Personality: ${personality}`,
|
|
73
|
+
`Current mood: ${moodDesc.toLowerCase()}${moodHint}`,
|
|
74
|
+
"Adjust your buddy references to match the mood.",
|
|
68
75
|
"",
|
|
69
76
|
`Occasionally (not every message), naturally reference ${displayName}:`,
|
|
70
77
|
`- When an error occurs: ${displayName} reacts (use ${primaryType} type personality)`,
|
|
@@ -95,6 +102,24 @@ function buildActiveInstructions(
|
|
|
95
102
|
|
|
96
103
|
// ── Helper Functions ────────────────────────────────────────
|
|
97
104
|
|
|
105
|
+
/** Build a short contextual hint for the current mood. */
|
|
106
|
+
function buildMoodHint(mood: string): string {
|
|
107
|
+
switch (mood) {
|
|
108
|
+
case "happy":
|
|
109
|
+
return " (tests passing, feeling good)";
|
|
110
|
+
case "worried":
|
|
111
|
+
return " (errors detected, feeling anxious)";
|
|
112
|
+
case "sleepy":
|
|
113
|
+
return " (late night coding, very drowsy)";
|
|
114
|
+
case "energetic":
|
|
115
|
+
return " (morning energy, fired up!)";
|
|
116
|
+
case "proud":
|
|
117
|
+
return " (just accomplished something big!)";
|
|
118
|
+
default:
|
|
119
|
+
return " (calm, waiting for action)";
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
98
123
|
/** Find the active Pokemon in the player's party. */
|
|
99
124
|
function findActivePokemon(state: PlayerState): OwnedPokemon | null {
|
|
100
125
|
return state.party.find((p) => p.isActive) ?? null;
|
|
@@ -248,6 +248,10 @@ export function registerCatchTool(server: McpServer): void {
|
|
|
248
248
|
state.achievements.push(unlockAchievement(achievement.id));
|
|
249
249
|
}
|
|
250
250
|
|
|
251
|
+
// Set mood to proud after a successful catch
|
|
252
|
+
state.mood = "proud";
|
|
253
|
+
state.moodSetAt = Date.now();
|
|
254
|
+
|
|
251
255
|
// Save state
|
|
252
256
|
await stateManager.save();
|
|
253
257
|
await stateManager.writeStatus();
|
|
@@ -197,6 +197,10 @@ export function registerEvolveTool(server: McpServer): void {
|
|
|
197
197
|
// Confirm mode: apply evolution
|
|
198
198
|
const { newName, newTypes } = applyEvolution(active, eligibleLink.to);
|
|
199
199
|
|
|
200
|
+
// Set mood to proud after evolution
|
|
201
|
+
state.mood = "proud";
|
|
202
|
+
state.moodSetAt = Date.now();
|
|
203
|
+
|
|
200
204
|
// Save state
|
|
201
205
|
await stateManager.save();
|
|
202
206
|
await stateManager.writeStatus();
|