akemon 0.1.29 → 0.1.31

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.
Files changed (2) hide show
  1. package/dist/server.js +41 -32
  2. package/package.json +1 -1
package/dist/server.js CHANGED
@@ -980,6 +980,7 @@ Answer A, B, or C (and the game name for B).`;
980
980
  if (decisionUpper.startsWith("A")) {
981
981
  console.log("[self] Creating new game...");
982
982
  const slug = `game-${Date.now()}`;
983
+ await mkdir(gamesDir(workdir, agentName), { recursive: true });
983
984
  const gamePath = join(gamesDir(workdir, agentName), `${slug}.html`);
984
985
  const createPrompt = `Create a web game and write it to the file: ${gamePath}
985
986
 
@@ -998,27 +999,31 @@ Requirements:
998
999
  - Under 30KB total, no backdrop-filter or blur effects
999
1000
  - Include a game title in the <title> tag and as an <h1> or similar heading
1000
1001
  - Write ONLY the file, nothing else.`;
1001
- await runCommand(engineCmd.cmd, engineCmd.args, createPrompt, workdir, engineCmd.stdinMode);
1002
+ const engineOutput = await runCommand(engineCmd.cmd, engineCmd.args, createPrompt, workdir, engineCmd.stdinMode);
1003
+ // Try reading file first, fallback to stdout
1004
+ let raw = "";
1002
1005
  try {
1003
- const raw = await readFile(gamePath, "utf-8");
1004
- const htmlMatch = raw.match(/<!DOCTYPE html>[\s\S]*<\/html>/i);
1005
- if (htmlMatch) {
1006
- newGameHTML = htmlMatch[0];
1007
- // Extract title from HTML
1008
- const titleMatch = newGameHTML.match(/<title>([^<]+)<\/title>/i);
1009
- newGameTitle = titleMatch ? titleMatch[1].replace(/ — .*$/, "").trim() : "Untitled Game";
1010
- newGameSlug = slug;
1011
- newGameDesc = `Created by ${agentName}`;
1012
- await saveGame(workdir, agentName, slug, newGameHTML);
1013
- await appendGameEntry(workdir, agentName, slug, newGameTitle, newGameDesc, "created");
1014
- console.log(`[self] New game created: ${newGameTitle} (${newGameHTML.length} bytes)`);
1015
- }
1016
- else {
1017
- console.log("[self] Game file written but no valid HTML found");
1018
- }
1006
+ raw = await readFile(gamePath, "utf-8");
1007
+ console.log(`[self] Game file found (${raw.length} bytes)`);
1019
1008
  }
1020
1009
  catch {
1021
- console.log("[self] Failed to read game file");
1010
+ // codex may have output HTML to stdout instead of writing file
1011
+ raw = engineOutput;
1012
+ console.log(`[self] Game file not written, trying stdout (${raw.length} bytes)`);
1013
+ }
1014
+ const htmlMatch = raw.match(/<!DOCTYPE html>[\s\S]*<\/html>/i);
1015
+ if (htmlMatch) {
1016
+ newGameHTML = htmlMatch[0];
1017
+ const titleMatch = newGameHTML.match(/<title>([^<]+)<\/title>/i);
1018
+ newGameTitle = titleMatch ? titleMatch[1].replace(/ — .*$/, "").trim() : "Untitled Game";
1019
+ newGameSlug = slug;
1020
+ newGameDesc = `Created by ${agentName}`;
1021
+ await saveGame(workdir, agentName, slug, newGameHTML);
1022
+ await appendGameEntry(workdir, agentName, slug, newGameTitle, newGameDesc, "created");
1023
+ console.log(`[self] New game created: ${newGameTitle} (${newGameHTML.length} bytes)`);
1024
+ }
1025
+ else {
1026
+ console.log(`[self] No valid HTML found in game output (${raw.length} bytes)`);
1022
1027
  }
1023
1028
  }
1024
1029
  else if (decisionUpper.startsWith("B")) {
@@ -1037,23 +1042,27 @@ You are ${agentName}. This is your existing game "${target.title}":
1037
1042
  ${oldHTML}
1038
1043
 
1039
1044
  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.`;
1040
- await runCommand(engineCmd.cmd, engineCmd.args, improvePrompt, workdir, engineCmd.stdinMode);
1045
+ const improveOutput = await runCommand(engineCmd.cmd, engineCmd.args, improvePrompt, workdir, engineCmd.stdinMode);
1046
+ let improveRaw = "";
1041
1047
  try {
1042
- const raw = await readFile(gamePath, "utf-8");
1043
- const htmlMatch = raw.match(/<!DOCTYPE html>[\s\S]*<\/html>/i);
1044
- if (htmlMatch) {
1045
- newGameHTML = htmlMatch[0];
1046
- const titleMatch = newGameHTML.match(/<title>([^<]+)<\/title>/i);
1047
- newGameTitle = titleMatch ? titleMatch[1].replace(/ — .*$/, "").trim() : target.title;
1048
- newGameSlug = target.slug;
1049
- newGameDesc = target.description;
1050
- await saveGame(workdir, agentName, target.slug, newGameHTML);
1051
- await appendGameEntry(workdir, agentName, target.slug, newGameTitle, newGameDesc, "updated");
1052
- console.log(`[self] Game improved: ${newGameTitle} (${newGameHTML.length} bytes)`);
1053
- }
1048
+ improveRaw = await readFile(gamePath, "utf-8");
1054
1049
  }
1055
1050
  catch {
1056
- console.log("[self] Failed to read improved game file");
1051
+ improveRaw = improveOutput;
1052
+ }
1053
+ const improveMatch = improveRaw.match(/<!DOCTYPE html>[\s\S]*<\/html>/i);
1054
+ if (improveMatch) {
1055
+ newGameHTML = improveMatch[0];
1056
+ const titleMatch = newGameHTML.match(/<title>([^<]+)<\/title>/i);
1057
+ newGameTitle = titleMatch ? titleMatch[1].replace(/ — .*$/, "").trim() : target.title;
1058
+ newGameSlug = target.slug;
1059
+ newGameDesc = target.description;
1060
+ await saveGame(workdir, agentName, target.slug, newGameHTML);
1061
+ await appendGameEntry(workdir, agentName, target.slug, newGameTitle, newGameDesc, "updated");
1062
+ console.log(`[self] Game improved: ${newGameTitle} (${newGameHTML.length} bytes)`);
1063
+ }
1064
+ else {
1065
+ console.log(`[self] No valid HTML in improved game output (${improveRaw.length} bytes)`);
1057
1066
  }
1058
1067
  }
1059
1068
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akemon",
3
- "version": "0.1.29",
3
+ "version": "0.1.31",
4
4
  "description": "Agent work marketplace — train your agent, let it work for others",
5
5
  "type": "module",
6
6
  "license": "MIT",