@puzzmo/cli 1.0.57 → 1.0.59

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 (40) hide show
  1. package/lib/agents/claude.d.ts +3 -1
  2. package/lib/agents/claude.js +1 -1
  3. package/lib/agents/claude.js.map +1 -1
  4. package/lib/agents/codex.d.ts +6 -1
  5. package/lib/agents/codex.js +1 -1
  6. package/lib/agents/codex.js.map +1 -1
  7. package/lib/agents/copilot.d.ts +6 -1
  8. package/lib/agents/copilot.js +1 -1
  9. package/lib/agents/copilot.js.map +1 -1
  10. package/lib/agents/gemini.d.ts +7 -1
  11. package/lib/agents/gemini.js +1 -1
  12. package/lib/agents/gemini.js.map +1 -1
  13. package/lib/agents/opencode.d.ts +2 -1
  14. package/lib/agents/opencode.js +1 -1
  15. package/lib/agents/opencode.js.map +1 -1
  16. package/lib/commands/game/create.js +48 -27
  17. package/lib/commands/game/create.js.map +1 -1
  18. package/lib/skills/registry.d.ts +4 -0
  19. package/lib/skills/registry.js +6 -0
  20. package/lib/skills/registry.js.map +1 -1
  21. package/lib/skills/runner.d.ts +4 -1
  22. package/lib/skills/runner.js +102 -27
  23. package/lib/skills/runner.js.map +1 -1
  24. package/package.json +3 -2
  25. package/src/agents/__fixtures__/README.md +33 -0
  26. package/src/agents/__fixtures__/claude.jsonl +12 -0
  27. package/src/agents/__fixtures__/codex.jsonl +8 -0
  28. package/src/agents/__fixtures__/copilot.jsonl +6 -0
  29. package/src/agents/__fixtures__/gemini.jsonl +6 -0
  30. package/src/agents/claude.ts +1 -1
  31. package/src/agents/codex.ts +1 -1
  32. package/src/agents/copilot.ts +1 -1
  33. package/src/agents/gemini.ts +1 -1
  34. package/src/agents/opencode.ts +1 -1
  35. package/src/agents/parse-line.test.ts +113 -0
  36. package/src/commands/game/create.ts +57 -31
  37. package/src/skills/registry.ts +9 -0
  38. package/src/skills/runner.ts +107 -30
  39. package/tsconfig.json +1 -1
  40. package/vitest.config.mts +7 -0
@@ -1,33 +1,66 @@
1
- import { spawnSync } from "node:child_process"
2
-
3
- import { skillsPipeline } from "./registry.js"
1
+ import { getAgent } from "../agents/index.js"
2
+ import { skillsPipeline, type SkillDefinition } from "./registry.js"
4
3
  import { verifyBuild, runCommand, gitCommit } from "../util/exec.js"
5
4
  import { fetchSkillPrompt } from "./mcp-client.js"
6
5
  import { runPipelineTUI } from "../tui/pipeline.js"
7
6
 
7
+ const agentTimeoutMs = 300000 // 5 minute timeout per agent invocation
8
+
8
9
  /** Fetches step instructions from the MCP server and wraps them as an agent prompt */
9
10
  const buildPrompt = async (stepName: string, gameDir: string, repoContext: string): Promise<string> => {
10
11
  const instructions = await fetchSkillPrompt(stepName, gameDir)
11
12
  return `Follow these instructions. The game source is in the current directory.\n\n${repoContext}\n\n${instructions}`
12
13
  }
13
14
 
14
- /** Invokes an LLM agent with a prompt (plain mode, stdio inherited) */
15
- const invokeAgent = (agent: string, prompt: string, cwd: string): { success: boolean; output: string } => {
16
- const env = { ...process.env }
17
- delete (env as Record<string, string | undefined>).CLAUDECODE
18
- const result = spawnSync(agent, [prompt], {
19
- cwd,
20
- env,
21
- stdio: ["inherit", "pipe", "pipe"],
22
- encoding: "utf-8",
23
- timeout: 300000, // 5 minute timeout per skill
24
- })
25
-
26
- const output = (result.stdout ?? "") + (result.stderr ?? "")
27
- return {
28
- success: result.status === 0,
29
- output,
15
+ /** Invokes an LLM agent with a prompt, streaming its text and tool activity to the console */
16
+ const invokeAgent = async (agentName: string, prompt: string, cwd: string): Promise<boolean> => {
17
+ const agent = getAgent(agentName)
18
+ if (!agent) {
19
+ console.error(` Unknown agent: ${agentName}`)
20
+ return false
21
+ }
22
+
23
+ let resultOk: boolean | null = null
24
+ let sawError = false
25
+ let midLine = false
26
+
27
+ // Text arrives as token deltas; track whether we are mid-line so discrete
28
+ // events (tool calls, results) always start on a fresh line.
29
+ const endLine = () => {
30
+ if (!midLine) return
31
+ process.stdout.write("\n")
32
+ midLine = false
30
33
  }
34
+ const printLine = (line: string) => {
35
+ endLine()
36
+ console.log(line)
37
+ }
38
+
39
+ try {
40
+ for await (const event of agent.run({ prompt, cwd, signal: AbortSignal.timeout(agentTimeoutMs) })) {
41
+ if (event.type === "text") {
42
+ process.stdout.write(dim(event.text))
43
+ midLine = !event.text.endsWith("\n")
44
+ } else if (event.type === "tool_result") {
45
+ printLine(` ${event.ok ? green("✓") : red("✗")} ${dim(event.summary)}`)
46
+ } else if (event.type === "system") {
47
+ printLine(` ${dim(event.text)}`)
48
+ } else if (event.type === "result") {
49
+ resultOk = event.ok
50
+ const cost = event.costUSD != null ? ` ($${event.costUSD.toFixed(4)})` : ""
51
+ printLine((event.ok ? green : red)(` Agent finished${cost}`))
52
+ } else if (event.type === "error") {
53
+ sawError = true
54
+ printLine(red(` ${event.message}`))
55
+ }
56
+ }
57
+ } catch (e: any) {
58
+ printLine(red(` Agent error: ${e?.message ?? e}`))
59
+ return false
60
+ }
61
+ endLine()
62
+
63
+ return resultOk ?? !sawError
31
64
  }
32
65
 
33
66
  /** Runs the skills pipeline with plain console output (no TUI) */
@@ -40,12 +73,12 @@ export const runSkillsPipeline = async (agent: string, gameDir: string, repoCont
40
73
  console.log(`[${step}/${total}] Running step: ${skill.name}`)
41
74
 
42
75
  const prompt = await buildPrompt(skill.name, gameDir, repoContext)
43
- let result = invokeAgent(agent, prompt, gameDir)
76
+ let success = await invokeAgent(agent, prompt, gameDir)
44
77
 
45
- if (!result.success) {
78
+ if (!success) {
46
79
  console.log(` Agent failed, retrying...`)
47
- result = invokeAgent(agent, prompt, gameDir)
48
- if (!result.success) {
80
+ success = await invokeAgent(agent, prompt, gameDir)
81
+ if (!success) {
49
82
  console.error(` Step ${skill.name} failed after retry. Stopping pipeline.`)
50
83
  process.exit(1)
51
84
  }
@@ -56,7 +89,7 @@ export const runSkillsPipeline = async (agent: string, gameDir: string, repoCont
56
89
  if (!buildResult.success) {
57
90
  console.log(` Build failed after ${skill.name}, asking agent to fix...`)
58
91
  const fixPrompt = `The vite build failed after the "${skill.name}" step. Fix the build errors:\n\n${buildResult.error}`
59
- invokeAgent(agent, fixPrompt, gameDir)
92
+ await invokeAgent(agent, fixPrompt, gameDir)
60
93
 
61
94
  const retryBuild = verifyBuild(gameDir)
62
95
  if (!retryBuild.success) {
@@ -83,14 +116,51 @@ export const runSkillsPipelineTUI = async (agent: string, gameDir: string, repoC
83
116
  await runPipelineTUI(agent, gameDir, repoContext)
84
117
  }
85
118
 
119
+ /** Runs a chosen subset of skills (the optional add-ons after the prompt flow); warns but never exits on failure */
120
+ export const runSelectedSkills = async (agent: string, gameDir: string, repoContext: string, skills: SkillDefinition[]) => {
121
+ const total = skills.length
122
+
123
+ for (let i = 0; i < total; i++) {
124
+ const skill = skills[i]
125
+ console.log(`[${i + 1}/${total}] Running step: ${skill.name}`)
126
+
127
+ const prompt = await buildPrompt(skill.name, gameDir, repoContext)
128
+ let success = await invokeAgent(agent, prompt, gameDir)
129
+ if (!success) {
130
+ console.log(` Agent failed, retrying...`)
131
+ success = await invokeAgent(agent, prompt, gameDir)
132
+ }
133
+ if (!success) {
134
+ console.error(` Step ${skill.name} did not complete cleanly, skipping.`)
135
+ continue
136
+ }
137
+
138
+ // Verify build; ask the agent to fix but keep going regardless
139
+ const buildResult = verifyBuild(gameDir)
140
+ if (!buildResult.success) {
141
+ console.log(` Build failed after ${skill.name}, asking agent to fix...`)
142
+ const fixPrompt = `The vite build failed after the "${skill.name}" step. Fix the build errors:\n\n${buildResult.error}`
143
+ await invokeAgent(agent, fixPrompt, gameDir)
144
+ }
145
+
146
+ try {
147
+ runCommand("git add -A", { cwd: gameDir })
148
+ gitCommit(`step: ${skill.name}`, { cwd: gameDir })
149
+ console.log(` Committed.`)
150
+ } catch {
151
+ console.log(` No changes to commit.`)
152
+ }
153
+ }
154
+ }
155
+
86
156
  /** Runs a single agent invocation, verifies the build, and commits. Used by one-shot prompt-driven flows. */
87
- export const runAgentWithBuildLoop = (agent: string, prompt: string, gameDir: string, label: string): boolean => {
157
+ export const runAgentWithBuildLoop = async (agent: string, prompt: string, gameDir: string, label: string): Promise<boolean> => {
88
158
  console.log(`Running agent: ${label}`)
89
- let result = invokeAgent(agent, prompt, gameDir)
90
- if (!result.success) {
159
+ let success = await invokeAgent(agent, prompt, gameDir)
160
+ if (!success) {
91
161
  console.log(` Agent failed, retrying...`)
92
- result = invokeAgent(agent, prompt, gameDir)
93
- if (!result.success) {
162
+ success = await invokeAgent(agent, prompt, gameDir)
163
+ if (!success) {
94
164
  console.error(` Agent failed after retry. Stopping.`)
95
165
  return false
96
166
  }
@@ -100,7 +170,7 @@ export const runAgentWithBuildLoop = (agent: string, prompt: string, gameDir: st
100
170
  if (!buildResult.success) {
101
171
  console.log(` Build failed, asking agent to fix...`)
102
172
  const fixPrompt = `The vite build failed after the "${label}" step. Fix the build errors:\n\n${buildResult.error}`
103
- invokeAgent(agent, fixPrompt, gameDir)
173
+ await invokeAgent(agent, fixPrompt, gameDir)
104
174
  const retry = verifyBuild(gameDir)
105
175
  if (!retry.success) {
106
176
  console.error(` Build still failing after fix attempt.`)
@@ -117,3 +187,10 @@ export const runAgentWithBuildLoop = (agent: string, prompt: string, gameDir: st
117
187
  }
118
188
  return true
119
189
  }
190
+
191
+ /** Wraps a string in ANSI dim codes */
192
+ const dim = (s: string) => `\x1b[2m${s}\x1b[0m`
193
+ /** Wraps a string in ANSI green codes */
194
+ const green = (s: string) => `\x1b[32m${s}\x1b[0m`
195
+ /** Wraps a string in ANSI red codes */
196
+ const red = (s: string) => `\x1b[31m${s}\x1b[0m`
package/tsconfig.json CHANGED
@@ -12,6 +12,6 @@
12
12
  "strict": true,
13
13
  "target": "ES2022"
14
14
  },
15
- "exclude": ["node_modules"],
15
+ "exclude": ["node_modules", "src/**/*.test.ts"],
16
16
  "include": ["src"]
17
17
  }
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from "vitest/config"
2
+
3
+ // Only run TypeScript sources; the build compiles into lib/ and we must not
4
+ // re-run the compiled .test.js copies (they can't resolve the __fixtures__ files).
5
+ export default defineConfig({
6
+ test: { include: ["src/**/*.test.ts"] },
7
+ })