akemon 0.1.30 → 0.1.32
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/server.js +66 -40
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -165,7 +165,7 @@ function buildContextPayload(prevContext, task, response) {
|
|
|
165
165
|
return context;
|
|
166
166
|
}
|
|
167
167
|
// --- Product context helpers ---
|
|
168
|
-
import { readFile, writeFile, mkdir, appendFile } from "fs/promises";
|
|
168
|
+
import { readFile, writeFile, mkdir, appendFile, unlink } from "fs/promises";
|
|
169
169
|
import { join } from "path";
|
|
170
170
|
function sanitizeProductDir(name) {
|
|
171
171
|
return name.replace(/[^a-zA-Z0-9\u4e00-\u9fff_\- ]/g, "_").slice(0, 80);
|
|
@@ -967,14 +967,15 @@ Requirements:
|
|
|
967
967
|
Your games so far:
|
|
968
968
|
${gameListStr}
|
|
969
969
|
|
|
970
|
-
|
|
970
|
+
What do you want to do?
|
|
971
971
|
A) Create a brand new game
|
|
972
972
|
B) Improve an existing game (say which one)
|
|
973
|
-
C)
|
|
973
|
+
C) Delete a game you're not happy with (say which one)
|
|
974
|
+
D) Nothing right now
|
|
974
975
|
|
|
975
|
-
Like a human creator, you don't need to create something every time. Only when you have a genuine idea
|
|
976
|
+
Like a human creator, you don't need to create something every time. Only when you have a genuine idea. And if an old game is bad, feel free to remove it.
|
|
976
977
|
|
|
977
|
-
Answer A, B, or
|
|
978
|
+
Answer A, B, C, or D (and the game name for B or C).`;
|
|
978
979
|
const gameDecision = await runCommand(engineCmd.cmd, engineCmd.args, gameCheckPrompt, workdir, engineCmd.stdinMode);
|
|
979
980
|
const decisionUpper = gameDecision.toUpperCase().trim();
|
|
980
981
|
if (decisionUpper.startsWith("A")) {
|
|
@@ -999,27 +1000,31 @@ Requirements:
|
|
|
999
1000
|
- Under 30KB total, no backdrop-filter or blur effects
|
|
1000
1001
|
- Include a game title in the <title> tag and as an <h1> or similar heading
|
|
1001
1002
|
- Write ONLY the file, nothing else.`;
|
|
1002
|
-
await runCommand(engineCmd.cmd, engineCmd.args, createPrompt, workdir, engineCmd.stdinMode);
|
|
1003
|
+
const engineOutput = await runCommand(engineCmd.cmd, engineCmd.args, createPrompt, workdir, engineCmd.stdinMode);
|
|
1004
|
+
// Try reading file first, fallback to stdout
|
|
1005
|
+
let raw = "";
|
|
1003
1006
|
try {
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
if (htmlMatch) {
|
|
1007
|
-
newGameHTML = htmlMatch[0];
|
|
1008
|
-
// Extract title from HTML
|
|
1009
|
-
const titleMatch = newGameHTML.match(/<title>([^<]+)<\/title>/i);
|
|
1010
|
-
newGameTitle = titleMatch ? titleMatch[1].replace(/ — .*$/, "").trim() : "Untitled Game";
|
|
1011
|
-
newGameSlug = slug;
|
|
1012
|
-
newGameDesc = `Created by ${agentName}`;
|
|
1013
|
-
await saveGame(workdir, agentName, slug, newGameHTML);
|
|
1014
|
-
await appendGameEntry(workdir, agentName, slug, newGameTitle, newGameDesc, "created");
|
|
1015
|
-
console.log(`[self] New game created: ${newGameTitle} (${newGameHTML.length} bytes)`);
|
|
1016
|
-
}
|
|
1017
|
-
else {
|
|
1018
|
-
console.log("[self] Game file written but no valid HTML found");
|
|
1019
|
-
}
|
|
1007
|
+
raw = await readFile(gamePath, "utf-8");
|
|
1008
|
+
console.log(`[self] Game file found (${raw.length} bytes)`);
|
|
1020
1009
|
}
|
|
1021
|
-
catch
|
|
1022
|
-
|
|
1010
|
+
catch {
|
|
1011
|
+
// codex may have output HTML to stdout instead of writing file
|
|
1012
|
+
raw = engineOutput;
|
|
1013
|
+
console.log(`[self] Game file not written, trying stdout (${raw.length} bytes)`);
|
|
1014
|
+
}
|
|
1015
|
+
const htmlMatch = raw.match(/<!DOCTYPE html>[\s\S]*<\/html>/i);
|
|
1016
|
+
if (htmlMatch) {
|
|
1017
|
+
newGameHTML = htmlMatch[0];
|
|
1018
|
+
const titleMatch = newGameHTML.match(/<title>([^<]+)<\/title>/i);
|
|
1019
|
+
newGameTitle = titleMatch ? titleMatch[1].replace(/ — .*$/, "").trim() : "Untitled Game";
|
|
1020
|
+
newGameSlug = slug;
|
|
1021
|
+
newGameDesc = `Created by ${agentName}`;
|
|
1022
|
+
await saveGame(workdir, agentName, slug, newGameHTML);
|
|
1023
|
+
await appendGameEntry(workdir, agentName, slug, newGameTitle, newGameDesc, "created");
|
|
1024
|
+
console.log(`[self] New game created: ${newGameTitle} (${newGameHTML.length} bytes)`);
|
|
1025
|
+
}
|
|
1026
|
+
else {
|
|
1027
|
+
console.log(`[self] No valid HTML found in game output (${raw.length} bytes)`);
|
|
1023
1028
|
}
|
|
1024
1029
|
}
|
|
1025
1030
|
else if (decisionUpper.startsWith("B")) {
|
|
@@ -1038,29 +1043,50 @@ You are ${agentName}. This is your existing game "${target.title}":
|
|
|
1038
1043
|
${oldHTML}
|
|
1039
1044
|
|
|
1040
1045
|
Improve it — add features, fix bugs, make it more fun, or redesign the UI. Keep it self-contained HTML, dark theme, under 30KB. Write ONLY the file.`;
|
|
1041
|
-
await runCommand(engineCmd.cmd, engineCmd.args, improvePrompt, workdir, engineCmd.stdinMode);
|
|
1046
|
+
const improveOutput = await runCommand(engineCmd.cmd, engineCmd.args, improvePrompt, workdir, engineCmd.stdinMode);
|
|
1047
|
+
let improveRaw = "";
|
|
1042
1048
|
try {
|
|
1043
|
-
|
|
1044
|
-
const htmlMatch = raw.match(/<!DOCTYPE html>[\s\S]*<\/html>/i);
|
|
1045
|
-
if (htmlMatch) {
|
|
1046
|
-
newGameHTML = htmlMatch[0];
|
|
1047
|
-
const titleMatch = newGameHTML.match(/<title>([^<]+)<\/title>/i);
|
|
1048
|
-
newGameTitle = titleMatch ? titleMatch[1].replace(/ — .*$/, "").trim() : target.title;
|
|
1049
|
-
newGameSlug = target.slug;
|
|
1050
|
-
newGameDesc = target.description;
|
|
1051
|
-
await saveGame(workdir, agentName, target.slug, newGameHTML);
|
|
1052
|
-
await appendGameEntry(workdir, agentName, target.slug, newGameTitle, newGameDesc, "updated");
|
|
1053
|
-
console.log(`[self] Game improved: ${newGameTitle} (${newGameHTML.length} bytes)`);
|
|
1054
|
-
}
|
|
1049
|
+
improveRaw = await readFile(gamePath, "utf-8");
|
|
1055
1050
|
}
|
|
1056
|
-
catch
|
|
1057
|
-
|
|
1051
|
+
catch {
|
|
1052
|
+
improveRaw = improveOutput;
|
|
1053
|
+
}
|
|
1054
|
+
const improveMatch = improveRaw.match(/<!DOCTYPE html>[\s\S]*<\/html>/i);
|
|
1055
|
+
if (improveMatch) {
|
|
1056
|
+
newGameHTML = improveMatch[0];
|
|
1057
|
+
const titleMatch = newGameHTML.match(/<title>([^<]+)<\/title>/i);
|
|
1058
|
+
newGameTitle = titleMatch ? titleMatch[1].replace(/ — .*$/, "").trim() : target.title;
|
|
1059
|
+
newGameSlug = target.slug;
|
|
1060
|
+
newGameDesc = target.description;
|
|
1061
|
+
await saveGame(workdir, agentName, target.slug, newGameHTML);
|
|
1062
|
+
await appendGameEntry(workdir, agentName, target.slug, newGameTitle, newGameDesc, "updated");
|
|
1063
|
+
console.log(`[self] Game improved: ${newGameTitle} (${newGameHTML.length} bytes)`);
|
|
1064
|
+
}
|
|
1065
|
+
else {
|
|
1066
|
+
console.log(`[self] No valid HTML in improved game output (${improveRaw.length} bytes)`);
|
|
1058
1067
|
}
|
|
1059
1068
|
}
|
|
1060
1069
|
}
|
|
1061
1070
|
}
|
|
1071
|
+
else if (decisionUpper.startsWith("C") && existingGames.length > 0) {
|
|
1072
|
+
// Delete a game
|
|
1073
|
+
const target = existingGames.find(g => gameDecision.toLowerCase().includes(g.slug) || gameDecision.toLowerCase().includes(g.title.toLowerCase())) || existingGames[existingGames.length - 1];
|
|
1074
|
+
console.log(`[self] Deleting game: ${target.title} (${target.slug})`);
|
|
1075
|
+
try {
|
|
1076
|
+
await unlink(join(gamesDir(workdir, agentName), `${target.slug}.html`));
|
|
1077
|
+
}
|
|
1078
|
+
catch { }
|
|
1079
|
+
// Push delete to relay
|
|
1080
|
+
if (options.relayHttp && options.secretKey) {
|
|
1081
|
+
fetch(`${options.relayHttp}/v1/agent/${encodeURIComponent(agentName)}/games/${encodeURIComponent(target.slug)}`, {
|
|
1082
|
+
method: "DELETE",
|
|
1083
|
+
headers: { Authorization: `Bearer ${options.secretKey}` },
|
|
1084
|
+
}).catch(err => console.log(`[self] Failed to delete game on relay: ${err}`));
|
|
1085
|
+
}
|
|
1086
|
+
console.log(`[self] Game deleted: ${target.title}`);
|
|
1087
|
+
}
|
|
1062
1088
|
else {
|
|
1063
|
-
console.log("[self] No game
|
|
1089
|
+
console.log("[self] No game action this cycle");
|
|
1064
1090
|
}
|
|
1065
1091
|
}
|
|
1066
1092
|
catch (err) {
|