@umang-boss/claudemon 1.1.3 → 1.1.4
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/dist/src/server/tools/starter.js +50 -12
- package/package.json +1 -1
- package/src/server/tools/starter.ts +53 -12
|
@@ -30,19 +30,56 @@ function seededShuffle(array, seed) {
|
|
|
30
30
|
}
|
|
31
31
|
return result;
|
|
32
32
|
}
|
|
33
|
-
/**
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
const year = now.getFullYear();
|
|
37
|
-
const month = String(now.getMonth() + 1).padStart(2, "0");
|
|
38
|
-
const day = String(now.getDate()).padStart(2, "0");
|
|
39
|
-
return `${year}-${month}-${day}`;
|
|
33
|
+
/** Path to stored starter options */
|
|
34
|
+
function getStarterOptionsPath() {
|
|
35
|
+
return `${process.env["HOME"] ?? "~"}/.claudemon/starter-options.json`;
|
|
40
36
|
}
|
|
41
|
-
/**
|
|
42
|
-
function
|
|
43
|
-
const
|
|
37
|
+
/** Get or generate 3 random starters. Stored for 24 hours so user sees same 3. */
|
|
38
|
+
async function getStarters() {
|
|
39
|
+
const optionsPath = getStarterOptionsPath();
|
|
40
|
+
// Try to load previously generated options (valid for 24 hours)
|
|
41
|
+
try {
|
|
42
|
+
const { readFile, stat, access: fsAccess } = await import("node:fs/promises");
|
|
43
|
+
const { constants } = await import("node:fs");
|
|
44
|
+
await fsAccess(optionsPath, constants.F_OK);
|
|
45
|
+
const fileStat = await stat(optionsPath);
|
|
46
|
+
const ageMs = Date.now() - fileStat.mtimeMs;
|
|
47
|
+
const ONE_DAY = 24 * 60 * 60 * 1000;
|
|
48
|
+
if (ageMs < ONE_DAY) {
|
|
49
|
+
const text = await readFile(optionsPath, "utf-8");
|
|
50
|
+
const saved = JSON.parse(text);
|
|
51
|
+
if (Array.isArray(saved) && saved.length === 3) {
|
|
52
|
+
return saved;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// No saved options or expired — generate new ones
|
|
58
|
+
}
|
|
59
|
+
// Generate fresh random 3
|
|
60
|
+
const seed = hashString(`claudemon-${Date.now()}-${Math.random()}`);
|
|
44
61
|
const shuffled = seededShuffle(STARTER_POOL, seed);
|
|
45
|
-
|
|
62
|
+
const starters = [shuffled[0], shuffled[1], shuffled[2]];
|
|
63
|
+
// Save for consistency until they pick
|
|
64
|
+
try {
|
|
65
|
+
const { writeFile, mkdir } = await import("node:fs/promises");
|
|
66
|
+
await mkdir(`${process.env["HOME"] ?? "~"}/.claudemon`, { recursive: true });
|
|
67
|
+
await writeFile(optionsPath, JSON.stringify(starters), "utf-8");
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Non-critical — they'll just get new options next time
|
|
71
|
+
}
|
|
72
|
+
return starters;
|
|
73
|
+
}
|
|
74
|
+
/** Clear saved starter options (called after picking) */
|
|
75
|
+
async function clearStarterOptions() {
|
|
76
|
+
try {
|
|
77
|
+
const { unlink } = await import("node:fs/promises");
|
|
78
|
+
await unlink(getStarterOptionsPath());
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// Ignore
|
|
82
|
+
}
|
|
46
83
|
}
|
|
47
84
|
/** Generate a UUID v4. */
|
|
48
85
|
function generateUUID() {
|
|
@@ -65,7 +102,7 @@ export function registerStarterTool(server) {
|
|
|
65
102
|
isError: true,
|
|
66
103
|
};
|
|
67
104
|
}
|
|
68
|
-
const starterIds =
|
|
105
|
+
const starterIds = await getStarters();
|
|
69
106
|
// No choice provided — show the 3 options
|
|
70
107
|
if (params.choice === undefined) {
|
|
71
108
|
const lines = ["Welcome to Claudemon! Choose your coding companion:", ""];
|
|
@@ -118,6 +155,7 @@ export function registerStarterTool(server) {
|
|
|
118
155
|
const trainerName = "Trainer";
|
|
119
156
|
await stateManager.initializePlayer(trainerId, trainerName, starter);
|
|
120
157
|
await stateManager.writeStatus();
|
|
158
|
+
await clearStarterOptions();
|
|
121
159
|
const lines = [];
|
|
122
160
|
lines.push(`Congratulations! You chose **${species.name}**!`, "", ` Species: ${species.name} (#${String(species.id).padStart(3, "0")})`, ` Type: ${formatTypes(species.types)}`, ` Level: ${STARTER_LEVEL}`, ` Exp Group: ${species.expGroup}`, "", ` "${species.description}"`, "", `Your coding journey begins now. Write code, fix bugs, and watch ${species.name} grow!`, "", "Use buddy_show to see your Pokemon, or buddy_pet to bond with them.");
|
|
123
161
|
return {
|
package/package.json
CHANGED
|
@@ -36,20 +36,60 @@ function seededShuffle<T>(array: readonly T[], seed: number): T[] {
|
|
|
36
36
|
return result;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
/**
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
const year = now.getFullYear();
|
|
43
|
-
const month = String(now.getMonth() + 1).padStart(2, "0");
|
|
44
|
-
const day = String(now.getDate()).padStart(2, "0");
|
|
45
|
-
return `${year}-${month}-${day}`;
|
|
39
|
+
/** Path to stored starter options */
|
|
40
|
+
function getStarterOptionsPath(): string {
|
|
41
|
+
return `${process.env["HOME"] ?? "~"}/.claudemon/starter-options.json`;
|
|
46
42
|
}
|
|
47
43
|
|
|
48
|
-
/**
|
|
49
|
-
function
|
|
50
|
-
const
|
|
44
|
+
/** Get or generate 3 random starters. Stored for 24 hours so user sees same 3. */
|
|
45
|
+
async function getStarters(): Promise<number[]> {
|
|
46
|
+
const optionsPath = getStarterOptionsPath();
|
|
47
|
+
|
|
48
|
+
// Try to load previously generated options (valid for 24 hours)
|
|
49
|
+
try {
|
|
50
|
+
const { readFile, stat, access: fsAccess } = await import("node:fs/promises");
|
|
51
|
+
const { constants } = await import("node:fs");
|
|
52
|
+
await fsAccess(optionsPath, constants.F_OK);
|
|
53
|
+
const fileStat = await stat(optionsPath);
|
|
54
|
+
const ageMs = Date.now() - fileStat.mtimeMs;
|
|
55
|
+
const ONE_DAY = 24 * 60 * 60 * 1000;
|
|
56
|
+
|
|
57
|
+
if (ageMs < ONE_DAY) {
|
|
58
|
+
const text = await readFile(optionsPath, "utf-8");
|
|
59
|
+
const saved = JSON.parse(text) as number[];
|
|
60
|
+
if (Array.isArray(saved) && saved.length === 3) {
|
|
61
|
+
return saved;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
} catch {
|
|
65
|
+
// No saved options or expired — generate new ones
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Generate fresh random 3
|
|
69
|
+
const seed = hashString(`claudemon-${Date.now()}-${Math.random()}`);
|
|
51
70
|
const shuffled = seededShuffle(STARTER_POOL, seed);
|
|
52
|
-
|
|
71
|
+
const starters = [shuffled[0]!, shuffled[1]!, shuffled[2]!];
|
|
72
|
+
|
|
73
|
+
// Save for consistency until they pick
|
|
74
|
+
try {
|
|
75
|
+
const { writeFile, mkdir } = await import("node:fs/promises");
|
|
76
|
+
await mkdir(`${process.env["HOME"] ?? "~"}/.claudemon`, { recursive: true });
|
|
77
|
+
await writeFile(optionsPath, JSON.stringify(starters), "utf-8");
|
|
78
|
+
} catch {
|
|
79
|
+
// Non-critical — they'll just get new options next time
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return starters;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Clear saved starter options (called after picking) */
|
|
86
|
+
async function clearStarterOptions(): Promise<void> {
|
|
87
|
+
try {
|
|
88
|
+
const { unlink } = await import("node:fs/promises");
|
|
89
|
+
await unlink(getStarterOptionsPath());
|
|
90
|
+
} catch {
|
|
91
|
+
// Ignore
|
|
92
|
+
}
|
|
53
93
|
}
|
|
54
94
|
|
|
55
95
|
/** Generate a UUID v4. */
|
|
@@ -80,7 +120,7 @@ export function registerStarterTool(server: McpServer): void {
|
|
|
80
120
|
};
|
|
81
121
|
}
|
|
82
122
|
|
|
83
|
-
const starterIds =
|
|
123
|
+
const starterIds = await getStarters();
|
|
84
124
|
|
|
85
125
|
// No choice provided — show the 3 options
|
|
86
126
|
if (params.choice === undefined) {
|
|
@@ -149,6 +189,7 @@ export function registerStarterTool(server: McpServer): void {
|
|
|
149
189
|
const trainerName = "Trainer";
|
|
150
190
|
await stateManager.initializePlayer(trainerId, trainerName, starter);
|
|
151
191
|
await stateManager.writeStatus();
|
|
192
|
+
await clearStarterOptions();
|
|
152
193
|
|
|
153
194
|
const lines: string[] = [];
|
|
154
195
|
|