@puzzmo/cli 1.0.71 → 1.0.72

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 (70) hide show
  1. package/lib/agents/claude.d.ts +2 -2
  2. package/lib/agents/claude.js +67 -16
  3. package/lib/agents/claude.js.map +1 -1
  4. package/lib/agents/codex.js +12 -1
  5. package/lib/agents/codex.js.map +1 -1
  6. package/lib/agents/copilot.js +10 -1
  7. package/lib/agents/copilot.js.map +1 -1
  8. package/lib/agents/gemini.js +9 -1
  9. package/lib/agents/gemini.js.map +1 -1
  10. package/lib/agents/index.d.ts +1 -1
  11. package/lib/agents/stream-json-cli.d.ts +5 -4
  12. package/lib/agents/stream-json-cli.js +29 -4
  13. package/lib/agents/stream-json-cli.js.map +1 -1
  14. package/lib/agents/types.d.ts +15 -0
  15. package/lib/commands/game/create.js +46 -18
  16. package/lib/commands/game/create.js.map +1 -1
  17. package/lib/commands/game/seedImport.d.ts +13 -0
  18. package/lib/commands/game/seedImport.js +25 -0
  19. package/lib/commands/game/seedImport.js.map +1 -0
  20. package/lib/download/page-downloader.js +20 -7
  21. package/lib/download/page-downloader.js.map +1 -1
  22. package/lib/skills/context.d.ts +6 -0
  23. package/lib/skills/context.js +74 -0
  24. package/lib/skills/context.js.map +1 -0
  25. package/lib/skills/mcp-client.d.ts +5 -0
  26. package/lib/skills/mcp-client.js +21 -0
  27. package/lib/skills/mcp-client.js.map +1 -1
  28. package/lib/skills/registry.d.ts +24 -3
  29. package/lib/skills/registry.js +47 -11
  30. package/lib/skills/registry.js.map +1 -1
  31. package/lib/skills/runner.d.ts +3 -6
  32. package/lib/skills/runner.js +45 -94
  33. package/lib/skills/runner.js.map +1 -1
  34. package/lib/skills/step.d.ts +25 -0
  35. package/lib/skills/step.js +29 -0
  36. package/lib/skills/step.js.map +1 -0
  37. package/lib/tui/pipeline.d.ts +3 -1
  38. package/lib/tui/pipeline.js +138 -65
  39. package/lib/tui/pipeline.js.map +1 -1
  40. package/lib/util/duration.d.ts +7 -0
  41. package/lib/util/duration.js +25 -0
  42. package/lib/util/duration.js.map +1 -0
  43. package/lib/util/exec.d.ts +15 -3
  44. package/lib/util/exec.js +37 -7
  45. package/lib/util/exec.js.map +1 -1
  46. package/package.json +1 -1
  47. package/src/agents/__fixtures__/README.md +1 -0
  48. package/src/agents/__fixtures__/claude-bash.jsonl +114 -0
  49. package/src/agents/claude.ts +64 -16
  50. package/src/agents/codex.ts +12 -1
  51. package/src/agents/copilot.ts +10 -1
  52. package/src/agents/gemini.ts +9 -1
  53. package/src/agents/index.ts +1 -1
  54. package/src/agents/parse-line.test.ts +40 -6
  55. package/src/agents/stream-json-cli.ts +32 -8
  56. package/src/agents/types.ts +16 -0
  57. package/src/commands/game/create.ts +47 -18
  58. package/src/commands/game/seedImport.ts +30 -0
  59. package/src/download/page-downloader.ts +22 -7
  60. package/src/skills/context.ts +75 -0
  61. package/src/skills/mcp-client.ts +24 -0
  62. package/src/skills/registry.ts +66 -11
  63. package/src/skills/runner.ts +52 -103
  64. package/src/skills/step.ts +47 -0
  65. package/src/tui/pipeline.ts +141 -61
  66. package/src/util/duration.test.ts +37 -0
  67. package/src/util/duration.ts +25 -0
  68. package/src/util/exec.ts +40 -7
  69. package/templates/minesweeper/README.md +3 -1
  70. package/templates/minesweeper/package.json +3 -1
@@ -0,0 +1,37 @@
1
+ import { describe, expect, it } from "vitest"
2
+
3
+ import { formatDuration, formatElapsed } from "./duration.js"
4
+
5
+ describe("formatDuration", () => {
6
+ it("uses milliseconds under a second", () => {
7
+ expect(formatDuration(0)).toBe("0ms")
8
+ expect(formatDuration(283)).toBe("283ms")
9
+ expect(formatDuration(999)).toBe("999ms")
10
+ })
11
+
12
+ it("uses one decimal of seconds under a minute", () => {
13
+ expect(formatDuration(1000)).toBe("1.0s")
14
+ expect(formatDuration(12_400)).toBe("12.4s")
15
+ })
16
+
17
+ it("uses zero-padded minutes and seconds above a minute", () => {
18
+ expect(formatDuration(60_000)).toBe("1m00s")
19
+ expect(formatDuration(362_000)).toBe("6m02s")
20
+ })
21
+
22
+ it("carries seconds that round up to a full minute", () => {
23
+ expect(formatDuration(119_700)).toBe("2m00s")
24
+ })
25
+ })
26
+
27
+ describe("formatElapsed", () => {
28
+ it("drops sub-second precision so a live counter doesn't flicker", () => {
29
+ expect(formatElapsed(9)).toBe("0s")
30
+ expect(formatElapsed(999)).toBe("0s")
31
+ expect(formatElapsed(12_400)).toBe("12s")
32
+ })
33
+
34
+ it("matches formatDuration above a minute", () => {
35
+ expect(formatElapsed(65_400)).toBe("1m05s")
36
+ })
37
+ })
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Coarser sibling of `formatDuration` for a counter that repaints while it runs, where
3
+ * sub-second precision only flickers: 0s / 12s / 6m02s.
4
+ */
5
+ export const formatElapsed = (ms: number): string => {
6
+ const secs = Math.floor(ms / 1000)
7
+ return secs < 60 ? `${secs}s` : formatDuration(secs * 1000)
8
+ }
9
+
10
+ /** Renders a span as 340ms / 12.4s / 6m02s — short enough to sit at the end of a log line */
11
+ export const formatDuration = (ms: number): string => {
12
+ if (ms < 1000) return `${Math.round(ms)}ms`
13
+
14
+ const totalSecs = ms / 1000
15
+ if (totalSecs < 60) return `${totalSecs.toFixed(1)}s`
16
+
17
+ let mins = Math.floor(totalSecs / 60)
18
+ let secs = Math.round(totalSecs % 60)
19
+ // Rounding can push seconds to a full minute (119.7s would read "1m60s")
20
+ if (secs === 60) {
21
+ mins += 1
22
+ secs = 0
23
+ }
24
+ return `${mins}m${String(secs).padStart(2, "0")}s`
25
+ }
package/src/util/exec.ts CHANGED
@@ -1,7 +1,11 @@
1
- import { execSync } from "node:child_process"
1
+ import { execSync, spawn } from "node:child_process"
2
+ import fs from "node:fs"
3
+ import path from "node:path"
2
4
 
3
5
  type ExecOptions = { cwd?: string }
4
6
 
7
+ export type PackageManagerName = "npm" | "yarn" | "pnpm"
8
+
5
9
  /** Runs a shell command, printing output */
6
10
  export const runCommand = (cmd: string, opts: ExecOptions = {}) => {
7
11
  execSync(cmd, {
@@ -37,12 +41,41 @@ export const isGitInstalled = (): boolean => {
37
41
  }
38
42
  }
39
43
 
40
- /** Runs vite build and returns success/failure */
41
- export const verifyBuild = (cwd: string): { success: boolean; error?: string } => {
44
+ /** Runs a command without blocking the event loop, capturing stdout and stderr together */
45
+ export const runCapture = (cmd: string, opts: ExecOptions = {}): Promise<{ success: boolean; output: string }> =>
46
+ new Promise((resolve) => {
47
+ const child = spawn(cmd, { cwd: opts.cwd, shell: true })
48
+ let output = ""
49
+ child.stdout?.on("data", (chunk: Buffer) => (output += chunk.toString("utf-8")))
50
+ child.stderr?.on("data", (chunk: Buffer) => (output += chunk.toString("utf-8")))
51
+ child.on("error", (e) => resolve({ success: false, output: output + e.message }))
52
+ child.on("close", (code) => resolve({ success: code === 0, output }))
53
+ })
54
+
55
+ /** Runs the project's build and returns success/failure */
56
+ export const verifyBuild = async (cwd: string, buildCmd: string): Promise<{ success: boolean; error?: string }> => {
57
+ const { success, output } = await runCapture(buildCmd, { cwd })
58
+ return success ? { success: true } : { success: false, error: output }
59
+ }
60
+
61
+ /**
62
+ * The command that builds a game directory. Prefers the project's own `build` script so
63
+ * monorepo/PnP setups resolve the way they normally do, and only falls back to invoking
64
+ * vite directly for games that share a parent package.json.
65
+ */
66
+ export const resolveBuildCommand = (gameDir: string, pm: PackageManagerName): string => {
67
+ if (hasBuildScript(gameDir)) return pm === "yarn" ? "yarn build" : `${pm} run build`
68
+ if (pm === "yarn") return "yarn vite build"
69
+ if (pm === "pnpm") return "pnpm exec vite build"
70
+ return "npx vite build"
71
+ }
72
+
73
+ /** True when the directory has its own package.json declaring a build script */
74
+ const hasBuildScript = (dir: string): boolean => {
42
75
  try {
43
- execSync("npx vite build", { cwd, encoding: "utf-8", stdio: "pipe" })
44
- return { success: true }
45
- } catch (e: any) {
46
- return { success: false, error: e.stderr || e.stdout || e.message }
76
+ const pkg = JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf-8"))
77
+ return Boolean(pkg.scripts?.build)
78
+ } catch {
79
+ return false
47
80
  }
48
81
  }
@@ -15,5 +15,7 @@ Edit puzzles in `fixtures/puzzles/`. Game logic is in `src/main.ts`.
15
15
  ## Deployment
16
16
 
17
17
  ```
18
- yarn puzzmo games upload
18
+ puzzmo login <your-token> # token from dev.puzzmo.com
19
+ yarn deploy # builds, then uploads to Puzzmo
20
+ yarn deploy:only # uploads the current dist/
19
21
  ```
@@ -5,7 +5,9 @@
5
5
  "scripts": {
6
6
  "dev": "vite",
7
7
  "build": "vite build",
8
- "preview": "vite preview"
8
+ "preview": "vite preview",
9
+ "deploy": "vite build && puzzmo games upload",
10
+ "deploy:only": "puzzmo games upload"
9
11
  },
10
12
  "dependencies": {
11
13
  "@puzzmo/cli": "*",