(skillDir: string)
| 57 | return null; |
| 58 | } |
| 59 | export async function playAnimation(skillDir: string): Promise<{ |
| 60 | success: boolean; |
| 61 | message: string; |
| 62 | }> { |
| 63 | const dataPath = join(skillDir, 'year_in_review.js'); |
| 64 | const playerPath = join(skillDir, 'player.js'); |
| 65 | |
| 66 | // Both files are prerequisites for the node subprocess. Read them here |
| 67 | // (not at call sites) so all callers get consistent error messaging. The |
| 68 | // subprocess runs with reject: false, so a missing file would otherwise |
| 69 | // silently return success. Using readFile (not access) per CLAUDE.md. |
| 70 | // |
| 71 | // Non-ENOENT errors (EACCES etc) are logged and returned as failures rather |
| 72 | // than thrown — the old pathExists-based code never threw, and one caller |
| 73 | // (handleSelect) uses `void playAnimation().then(...)` without a .catch(). |
| 74 | try { |
| 75 | await readFile(dataPath); |
| 76 | } catch (e: unknown) { |
| 77 | if (isENOENT(e)) { |
| 78 | return { |
| 79 | success: false, |
| 80 | message: 'No animation found. Run /think-back first to generate one.' |
| 81 | }; |
| 82 | } |
| 83 | logError(e); |
| 84 | return { |
| 85 | success: false, |
| 86 | message: `Could not access animation data: ${toError(e).message}` |
| 87 | }; |
| 88 | } |
| 89 | try { |
| 90 | await readFile(playerPath); |
| 91 | } catch (e: unknown) { |
| 92 | if (isENOENT(e)) { |
| 93 | return { |
| 94 | success: false, |
| 95 | message: 'Player script not found. The player.js file is missing from the thinkback skill.' |
| 96 | }; |
| 97 | } |
| 98 | logError(e); |
| 99 | return { |
| 100 | success: false, |
| 101 | message: `Could not access player script: ${toError(e).message}` |
| 102 | }; |
| 103 | } |
| 104 | |
| 105 | // Get ink instance for terminal takeover |
| 106 | const inkInstance = instances.get(process.stdout); |
| 107 | if (!inkInstance) { |
| 108 | return { |
| 109 | success: false, |
| 110 | message: 'Failed to access terminal instance' |
| 111 | }; |
| 112 | } |
| 113 | inkInstance.enterAlternateScreen(); |
| 114 | try { |
| 115 | await execa('node', [playerPath], { |
| 116 | stdio: 'inherit', |
no test coverage detected