honeytree 1.0.6 → 1.0.7

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/README.md CHANGED
@@ -1,192 +1,45 @@
1
1
  # Honeytree
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/honeytree.svg)](https://www.npmjs.com/package/honeytree)
4
- [![license](https://img.shields.io/npm/l/honeytree.svg)](https://github.com/Varun2009178/honeytree/blob/main/LICENSE)
3
+ Honeytree is a living pixel-art forest for developers. It tracks git commits, file saves, and active coding time, then renders the result as a shared forest in the terminal and the VS Code sidebar.
5
4
 
6
- Grow a pixel-art forest in your terminal every time you use Claude Code.
7
-
8
- Each prompt plants a new tree. Each tree grows over time. Your forest evolves from a quiet clearing into an ancient woodland — and it never resets.
9
-
10
- ---
11
-
12
- ## Quick Start
5
+ ## Install
13
6
 
14
7
  ```bash
15
8
  npm install -g honeytree
16
9
  honeytree init
17
- honeytree
18
- ```
19
-
20
- That's it. Three commands:
21
-
22
- 1. **Install** the CLI globally
23
- 2. **Init** creates your forest file and registers a Claude Code hook
24
- 3. **Run the viewer** in a separate terminal to watch your forest grow
25
-
26
- After setup, trees are planted automatically after every Claude Code response. No manual steps needed.
27
-
28
- ---
29
-
30
- ## How It Works
31
-
32
- When you run `honeytree init`, it does two things:
33
-
34
- - Creates `~/.honeydew/forest.json` to store your forest state
35
- - Adds a `Stop` hook to `~/.claude/settings.json` that runs after every Claude Code response
36
-
37
- From then on, every time Claude Code responds to a prompt, a new tree is planted in your forest automatically. Open the viewer in a second terminal to watch them grow in real time.
38
-
39
- ---
40
-
41
- ## Streaks
42
-
43
- Honeytree tracks your coding streak — consecutive days where you use Claude Code.
44
-
45
- - **Active streak**: The viewer and badge show your current streak count (e.g. `7-day streak`)
46
- - **Broken streak**: Miss a day and your forest starts **wilting** — trees desaturate toward brown, and fog rolls in across the scene
47
- - **Recovery**: Your next prompt resets the streak to 1 and clears the wilting immediately
48
-
49
- The longer you go without coding, the worse it gets:
50
-
51
- | Days idle | Effect |
52
- |----------:|--------|
53
- | 1 | Light desaturation, sparse fog |
54
- | 2 | Noticeable browning, moderate fog |
55
- | 3 | Heavy browning, dense fog |
56
- | 4+ | Near-dead forest, thick fog |
57
-
58
- Plant a tree to bring it all back to life.
59
-
60
- ---
61
-
62
- ## Badge
63
-
64
- Generate a badge for your GitHub README that shows your forest stats and links back to [Honeytree](https://github.com/Varun2009178/honeytree):
65
-
66
- ```bash
67
- honeytree badge
68
- ```
69
-
70
- This creates a `honeytree-badge.svg` file in your current directory and prints the markdown to embed it:
71
-
72
- ```markdown
73
- [![honeytree](./honeytree-badge.svg)](https://github.com/Varun2009178/honeytree)
74
10
  ```
75
11
 
76
- The badge displays your tree count and streak status. It links to the [Honeytree repo](https://github.com/Varun2009178/honeytree) so anyone who sees it can install it themselves.
12
+ Run `honeytree` to open the forest. `honeydew watch` is kept as the explicit watch alias.
77
13
 
78
- | State | Badge color | Example |
79
- |-------|-------------|---------|
80
- | Active streak | Green | `42 trees · 7d streak` |
81
- | Wilting | Orange-red | `42 trees · wilting` |
82
- | No streak data | Grey | `42 trees` |
14
+ ## Commands
83
15
 
84
- Re-run `honeytree badge` any time to update the SVG with your latest stats. Commit it to your repo to keep it current.
16
+ | Command | What it does |
17
+ | --- | --- |
18
+ | `honeytree init` | Creates `~/.honeytree/state.json`, migrates old `~/.honeydew/forest.json`, and prepares the forest project |
19
+ | `honeytree` | Opens the animated terminal forest |
20
+ | `honeydew watch` | Explicit watch alias for the same forest view |
85
21
 
86
- ---
22
+ Internal compatibility commands such as `plant`, `stats`, `badge`, and `md` still exist for integration flows, but they are not part of the primary public workflow.
87
23
 
88
- ## FOREST.md
24
+ ## What Grows
89
25
 
90
- Generate a shareable markdown snapshot of your forest:
91
-
92
- ```bash
93
- honeytree md
94
- ```
26
+ - Git commits plant trees.
27
+ - Every 50 file saves adds a ground element.
28
+ - Every 30 active coding minutes adds an animal.
29
+ - Your streak drives weather effects.
30
+ - The current month drives the season.
95
31
 
96
- This creates a `FOREST.md` in your current directory with:
32
+ ## Visual System
97
33
 
98
- - Your Honeytree badge (links to the [Honeytree repo](https://github.com/Varun2009178/honeytree))
99
- - Stats: tree count, streak, biome
100
- - A plain-text rendering of your forest (tree silhouettes, stars, ground)
101
- - Total prompts and forest age
102
-
103
- Commit `FOREST.md` to your repo root so your team can see the forest. When teammates see it, they can install Honeytree themselves — one install spreads to the whole team.
104
-
105
- Run `honeytree badge` first to generate the SVG, then `honeytree md` to generate the markdown that embeds it.
106
-
107
- ---
108
-
109
- ## Biomes
110
-
111
- Your forest evolves visually as it grows — the sky, ground, and atmosphere all change:
112
-
113
- | Trees | Biome | What changes |
114
- |------:|-------|-------------|
115
- | 0–9 | Clearing | Sparse stars, light ground |
116
- | 10–24 | Grove | More stars, richer ground |
117
- | 25–49 | Woodland | Dense canopy, varied starlight |
118
- | 50–99 | Old Growth | Deep greens, warm starlight |
119
- | 100+ | Ancient Forest | Richest palette, brightest sky |
120
-
121
- Trees are never deleted. The forest only grows.
122
-
123
- ---
124
-
125
- ## Tree Species
126
-
127
- Five species are randomly assigned when a tree is planted:
128
-
129
- | Species | Look |
130
- |---------|------|
131
- | Oak | Wide, rounded canopy |
132
- | Pine | Tall, triangular shape |
133
- | Birch | Light trunk, bright leaves |
134
- | Willow | Drooping canopy |
135
- | Cherry | Pink blossoms |
136
-
137
- Each species has 4 growth stages (seed, sapling, young, full). Existing trees grow a little with each new prompt.
138
-
139
- ---
140
-
141
- ## CLI Reference
142
-
143
- | Command | Description |
144
- |---------|-------------|
145
- | `honeytree init` | Create forest and register Claude Code hook |
146
- | `honeytree` | Launch the live viewer |
147
- | `honeytree plant` | Plant a tree manually (normally runs via hook) |
148
- | `honeytree badge` | Generate `honeytree-badge.svg` in current directory |
149
- | `honeytree md` | Generate `FOREST.md` in current directory |
150
-
151
- ---
152
-
153
- ## Viewer
154
-
155
- The viewer adapts to your terminal width — expand your terminal and new trees will spread across the full width.
156
-
157
- Press `Ctrl+C` to exit. The viewer shows a summary of your forest when you close it.
158
-
159
- ### Reading the Stats Bar
160
-
161
- Below your forest you'll see a stats bar like this:
162
-
163
- ```
164
- honeytree · 42 trees · 7-day streak · ████████░░░░ next: oak [woodland]
165
- ```
166
-
167
- Here's what each part means:
168
-
169
- | Segment | What it tells you |
170
- |---------|-------------------|
171
- | `42 trees` | Total trees in your forest — one planted per prompt, never deleted |
172
- | `7-day streak` | Consecutive days you've used Claude Code. Resets to 1 if you skip a day |
173
- | `wilting (2d idle)` | Appears instead of streak when you've been inactive — your forest is dying |
174
- | `████████░░░░` | Progress bar toward the next milestone (10, 25, 50, 100, 250, 500, 1000 trees) |
175
- | `next: oak` | The species of the next tree that will be planted |
176
- | `[woodland]` | Your current biome — evolves as your tree count grows |
177
-
178
- ---
34
+ - Time of day changes the sky between sunrise, day, sunset, and night.
35
+ - Seasons recolor the same pixel sprites for spring, summer, autumn, and winter.
36
+ - Weather escalates from clear to rain, rainbow, golden hour, and aurora.
37
+ - The terminal uses Unicode pixel blocks, while the VS Code extension uses an animated canvas renderer.
179
38
 
180
39
  ## Requirements
181
40
 
182
41
  - Node.js 18+
183
- - [Claude Code](https://claude.com/claude-code) (for the automatic hook)
184
-
185
- ## Links
186
-
187
- - **npm**: [npmjs.com/package/honeytree](https://www.npmjs.com/package/honeytree)
188
- - **GitHub**: [github.com/Varun2009178/honeytree](https://github.com/Varun2009178/honeytree)
189
- - **Issues**: [github.com/Varun2009178/honeytree/issues](https://github.com/Varun2009178/honeytree/issues)
42
+ - VS Code 1.85+ for the bundled extension
190
43
 
191
44
  ## License
192
45
 
package/bin/honeydew.js CHANGED
@@ -3,22 +3,19 @@
3
3
  const command = process.argv[2];
4
4
 
5
5
  if (command === "init") {
6
- const { init } = await import("../src/init.js");
6
+ const { init } = await import("../src/commands/init.js");
7
7
  await init();
8
+ } else if (command === "export") {
9
+ const { exportForest } = await import("../src/commands/export.js");
10
+ await exportForest();
11
+ } else if (command === "watch" || !command) {
12
+ const { watch } = await import("../src/commands/watch.js");
13
+ await watch();
8
14
  } else if (command === "plant") {
9
- const { plant } = await import("../src/plant.js");
15
+ const { plant } = await import("../src/commands/plant.js");
10
16
  await plant();
11
- } else if (command === "badge") {
12
- const { badge } = await import("../src/badge.js");
13
- await badge();
14
- } else if (command === "md") {
15
- const { generateForestMd } = await import("../src/markdown.js");
16
- await generateForestMd();
17
- } else if (!command) {
18
- const { viewer } = await import("../src/viewer.js");
19
- await viewer();
20
17
  } else {
21
18
  console.error(`Unknown command: ${command}`);
22
- console.error("Usage: honeytree [init|plant|badge|md]");
19
+ console.error("Usage: honeytree [init | export | watch]");
23
20
  process.exit(1);
24
21
  }
package/package.json CHANGED
@@ -1,26 +1,28 @@
1
1
  {
2
2
  "name": "honeytree",
3
- "version": "1.0.6",
4
- "description": "Grow a forest in your terminal every time you use Claude Code",
3
+ "version": "1.0.7",
4
+ "description": "A living pixel art forest that grows while you code",
5
5
  "type": "module",
6
6
  "bin": {
7
- "honeytree": "./bin/honeydew.js"
7
+ "honeytree": "./bin/honeydew.js",
8
+ "honeydew": "./bin/honeydew.js"
8
9
  },
9
10
  "files": [
10
11
  "bin",
11
12
  "src"
12
13
  ],
13
14
  "scripts": {
14
- "test": "node --test test/*.test.js"
15
+ "test": "node --test test/**/*.test.js",
16
+ "postinstall": "echo \"🌳 Thanks for planting! Star us: https://github.com/Varun2009178/honeytree\""
15
17
  },
16
18
  "keywords": [
17
19
  "cli",
18
20
  "terminal",
19
21
  "forest",
20
- "claude-code",
21
22
  "pixel-art",
22
- "ascii-art",
23
- "hooks"
23
+ "git",
24
+ "developer-tools",
25
+ "ascii-art"
24
26
  ],
25
27
  "repository": {
26
28
  "type": "git",
@@ -33,7 +35,12 @@
33
35
  "author": "Varun Nukala",
34
36
  "license": "MIT",
35
37
  "dependencies": {
36
- "chalk": "^5.4.1"
38
+ "chalk": "^5.4.1",
39
+ "chokidar": "^4.0.3",
40
+ "date-fns": "^4.1.0",
41
+ "ink": "^5.2.1",
42
+ "react": "^18.3.1",
43
+ "simple-git": "^3.36.0"
37
44
  },
38
45
  "engines": {
39
46
  "node": ">=18"
package/src/badge.js CHANGED
@@ -1,44 +1,28 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
 
4
- import { readForest } from "./state.js";
5
- import { buildScene, getWiltFactor } from "./renderer.js";
4
+ import { readState } from "./core/state.js";
5
+ import { buildTerminalScene } from "./renderers/terminal.js";
6
6
 
7
7
  const CELL = 6;
8
8
  const BG = "#0d1117";
9
9
  const TEXT_PAD = 18;
10
10
 
11
- function buildStatsText(forest, biome) {
12
- const count = forest.trees.length;
13
- const streak = forest.streak || 0;
14
- const wilt = getWiltFactor(forest.lastActiveDate);
15
-
16
- const parts = [`${count} tree${count === 1 ? "" : "s"}`];
17
-
18
- if (wilt > 0) {
19
- const a = new Date(forest.lastActiveDate + "T00:00:00");
20
- const b = new Date(new Date().toISOString().slice(0, 10) + "T00:00:00");
21
- const idle = Math.round((b - a) / (24 * 60 * 60 * 1000));
22
- parts.push(`wilting (${idle}d idle)`);
23
- } else if (streak > 0) {
24
- parts.push(`${streak}d streak`);
25
- }
26
-
27
- parts.push(biome.label);
28
- return parts.join(" · ");
11
+ function escapeXml(value) {
12
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
29
13
  }
30
14
 
31
- function generateForestSVG(forest) {
32
- const cols = Math.max(40, Math.min(forest.viewerWidth || 60, 80));
33
- const { buffer, biome, sceneRows } = buildScene(forest, cols);
15
+ function generateForestSVG(state) {
16
+ const cols = 80;
17
+ const { buffer, statsLine } = buildTerminalScene(state, cols, 0, { color: false });
34
18
 
35
19
  const artW = cols * CELL;
36
- const artH = sceneRows * CELL;
20
+ const artH = buffer.length * CELL;
37
21
  const totalW = artW;
38
22
  const totalH = artH + TEXT_PAD;
39
23
 
40
24
  let rects = "";
41
- for (let y = 0; y < sceneRows; y += 1) {
25
+ for (let y = 0; y < buffer.length; y += 1) {
42
26
  for (let x = 0; x < cols; x += 1) {
43
27
  const cell = buffer[y][x];
44
28
  if (!cell.color) continue;
@@ -46,17 +30,15 @@ function generateForestSVG(forest) {
46
30
  }
47
31
  }
48
32
 
49
- const stats = buildStatsText(forest, biome);
50
-
51
33
  return `<svg xmlns="http://www.w3.org/2000/svg" width="${totalW}" height="${totalH}" viewBox="0 0 ${totalW} ${totalH}">
52
34
  <rect width="${totalW}" height="${totalH}" fill="${BG}" rx="6"/>
53
35
  ${rects}
54
- <text x="${totalW / 2}" y="${artH + 13}" text-anchor="middle" fill="#8e8a84" font-family="monospace" font-size="10">${stats}</text>
36
+ <text x="${totalW / 2}" y="${artH + 13}" text-anchor="middle" fill="#8e8a84" font-family="monospace" font-size="10">${escapeXml(statsLine.trim())}</text>
55
37
  </svg>`;
56
38
  }
57
39
 
58
- export function writeBadgeSVG(forest, outPath) {
59
- fs.writeFileSync(outPath, generateForestSVG(forest));
40
+ export function writeBadgeSVG(state, outPath) {
41
+ fs.writeFileSync(outPath, generateForestSVG(state));
60
42
  }
61
43
 
62
44
  export function findBadgeFile() {
@@ -71,21 +53,14 @@ export function findBadgeFile() {
71
53
  }
72
54
 
73
55
  export async function badge() {
74
- const forest = readForest();
75
- if (!forest) {
76
- console.error('No forest found. Run "honeytree init" first.');
56
+ const state = readState();
57
+ if (!state) {
58
+ console.error('No Honeytree state found. Run "honeytree init" first.');
77
59
  process.exit(1);
78
60
  }
79
61
 
80
62
  const outPath = path.resolve("honeytree-badge.svg");
81
- writeBadgeSVG(forest, outPath);
63
+ writeBadgeSVG(state, outPath);
82
64
 
83
65
  console.log(`Badge written to ${outPath}`);
84
- console.log("");
85
- console.log("Add this to your README to show your Honeytree forest.");
86
- console.log("The badge links to https://github.com/Varun2009178/honeytree");
87
- console.log("");
88
- console.log(
89
- `[![honeytree](./honeytree-badge.svg)](https://github.com/Varun2009178/honeytree)`,
90
- );
91
66
  }
@@ -0,0 +1,23 @@
1
+ import path from "node:path";
2
+
3
+ import { writeBadgeSVG } from "../badge.js";
4
+ import { buildMarkdown } from "../markdown.js";
5
+ import { readState } from "../core/state.js";
6
+ import fs from "node:fs";
7
+
8
+ export async function exportForest() {
9
+ const state = readState();
10
+ if (!state) {
11
+ console.error('No Honeytree state found. Run "honeytree init" first.');
12
+ process.exit(1);
13
+ }
14
+
15
+ const badgePath = path.resolve("honeytree-badge.svg");
16
+ writeBadgeSVG(state, badgePath);
17
+
18
+ const md = buildMarkdown(state);
19
+ const mdPath = path.resolve("FOREST.md");
20
+ fs.writeFileSync(mdPath, md);
21
+
22
+ console.log("Exported honeytree-badge.svg and FOREST.md");
23
+ }
@@ -0,0 +1,54 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+
5
+ import { ensureState, getStateFile } from "../core/state.js";
6
+
7
+ function getClaudeSettingsPath() {
8
+ const root = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), ".claude");
9
+ return path.join(root, "settings.json");
10
+ }
11
+
12
+ function hasClaudeHook(settings) {
13
+ return (
14
+ settings?.hooks?.Stop?.some((entry) =>
15
+ entry?.hooks?.some((hook) => hook?.command === "honeytree plant"),
16
+ ) ?? false
17
+ );
18
+ }
19
+
20
+ function installClaudeHook() {
21
+ const settingsPath = getClaudeSettingsPath();
22
+ fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
23
+
24
+ let settings = {};
25
+ try {
26
+ settings = JSON.parse(fs.readFileSync(settingsPath, "utf8"));
27
+ } catch {
28
+ settings = {};
29
+ }
30
+
31
+ settings.hooks ??= {};
32
+ settings.hooks.Stop ??= [];
33
+
34
+ if (!hasClaudeHook(settings)) {
35
+ settings.hooks.Stop.push({
36
+ matcher: "",
37
+ hooks: [{ type: "command", command: "honeytree plant" }],
38
+ });
39
+ fs.writeFileSync(settingsPath, `${JSON.stringify(settings, null, 2)}\n`);
40
+ return settingsPath;
41
+ }
42
+
43
+ return null;
44
+ }
45
+
46
+ export async function init() {
47
+ ensureState();
48
+
49
+ const hook = process.argv.includes("--hook") || process.env.HONEYTREE_ENABLE_CLAUDE_HOOK === "1";
50
+ if (hook) installClaudeHook();
51
+
52
+ const suffix = hook ? " (Claude hook installed)" : "";
53
+ console.log(`🌳 Forest planted at ${getStateFile()}${suffix}`);
54
+ }
@@ -0,0 +1,12 @@
1
+ import { applyCommit } from "../core/progression.js";
2
+ import { updateState } from "../core/state.js";
3
+
4
+ export async function plant() {
5
+ const width = Number.parseInt(process.env.HONEYTREE_WIDTH ?? "80", 10) || 80;
6
+ const now = new Date();
7
+ const nextState = updateState((state) => applyCommit(state, { now, width }));
8
+ console.log(
9
+ `Planted ${nextState.trees.at(-1)?.species ?? "tree"} #${nextState.total_commits} (${nextState.trees.length} total trees)`,
10
+ );
11
+ }
12
+
@@ -0,0 +1,48 @@
1
+ import { getEnvironmentSnapshot } from "../core/environment.js";
2
+ import { getNextMinuteCheckpoint } from "../core/progression.js";
3
+ import { getTreeSpeciesForCommit } from "../core/sprites.js";
4
+ import { readState } from "../core/state.js";
5
+
6
+ function formatPlural(count, singular) {
7
+ return `${count} ${singular}${count === 1 ? "" : "s"}`;
8
+ }
9
+
10
+ function getNextTreeCommit(totalCommits) {
11
+ return totalCommits + 1;
12
+ }
13
+
14
+ function getNextGroundUnlock(totalFileSaves) {
15
+ return Math.ceil((totalFileSaves + 1) / 50) * 50;
16
+ }
17
+
18
+ export function buildStatsReport(state, now = new Date()) {
19
+ const environment = getEnvironmentSnapshot(now, state.current_streak);
20
+ const nextTreeCommit = getNextTreeCommit(state.total_commits);
21
+ const nextGroundUnlock = getNextGroundUnlock(state.total_file_saves);
22
+ const nextMinuteUnlock = getNextMinuteCheckpoint(state.total_minutes_coded);
23
+
24
+ return [
25
+ "Honeytree",
26
+ `Trees: ${formatPlural(state.trees.length, "tree")} (${state.total_commits} commits)`,
27
+ `Animals: ${formatPlural(state.animals.length, "animal")} (${state.total_minutes_coded} active minutes)`,
28
+ `Ground: ${formatPlural(state.ground_elements.length, "element")} (${state.total_file_saves} file saves)`,
29
+ `Streak: ${state.current_streak} day${state.current_streak === 1 ? "" : "s"}`,
30
+ `Season: ${environment.season.label}`,
31
+ `Weather: ${environment.weather.label}`,
32
+ `Sky: ${environment.sky.label}`,
33
+ `Next tree: commit ${nextTreeCommit} → ${getTreeSpeciesForCommit(nextTreeCommit)}`,
34
+ `Next ground element: ${Math.max(0, nextGroundUnlock - state.total_file_saves)} saves`,
35
+ `Next animal: ${Math.max(0, nextMinuteUnlock - state.total_minutes_coded)} minutes`,
36
+ ].join("\n");
37
+ }
38
+
39
+ export async function stats() {
40
+ const state = readState();
41
+ if (!state) {
42
+ console.error('No Honeytree state found. Run "honeytree init" first.');
43
+ process.exit(1);
44
+ }
45
+
46
+ console.log(buildStatsReport(state));
47
+ }
48
+
@@ -0,0 +1,117 @@
1
+ import React, { useEffect, useMemo, useState } from "react";
2
+ import { Box, Text, render, useApp, useInput, useStdout } from "ink";
3
+
4
+ import { applyActiveMinutes, applyActivityPulse, applyCommit, applyFileSave } from "../core/progression.js";
5
+ import { ensureState, readState, updateState } from "../core/state.js";
6
+ import { renderTerminalFrame } from "../renderers/terminal.js";
7
+ import { createActivityTracker } from "../tracker/activity.js";
8
+ import { startFileTracker } from "../tracker/files.js";
9
+ import { startGitTracker } from "../tracker/git.js";
10
+
11
+ const FRAME_MS = 100;
12
+ const POLL_MS = 1_000;
13
+ const h = React.createElement;
14
+
15
+ function buildCommandHint(width) {
16
+ const full = "init: honeytree init · watch: honeydew watch";
17
+ const compact = "honeytree init · honeydew watch";
18
+ if (width >= full.length + 2) {
19
+ return full;
20
+ }
21
+ return compact;
22
+ }
23
+
24
+ function ForestWatchApp() {
25
+ const { exit } = useApp();
26
+ const { stdout } = useStdout();
27
+ const [tick, setTick] = useState(0);
28
+ const [state, setState] = useState(() => ensureState());
29
+ const [width, setWidth] = useState(stdout.columns || 80);
30
+
31
+ useInput((input, key) => {
32
+ if (input === "q" || key.escape || key.ctrl && input === "c") {
33
+ exit();
34
+ }
35
+ });
36
+
37
+ useEffect(() => {
38
+ const onResize = () => setWidth(stdout.columns || 80);
39
+ stdout.on("resize", onResize);
40
+ return () => stdout.off("resize", onResize);
41
+ }, [stdout]);
42
+
43
+ useEffect(() => {
44
+ const frameTimer = setInterval(() => {
45
+ setTick((value) => value + 1);
46
+ }, FRAME_MS);
47
+ return () => clearInterval(frameTimer);
48
+ }, []);
49
+
50
+ useEffect(() => {
51
+ const syncTimer = setInterval(() => {
52
+ const latest = readState();
53
+ if (latest) {
54
+ setState(latest);
55
+ }
56
+ }, POLL_MS);
57
+ return () => clearInterval(syncTimer);
58
+ }, []);
59
+
60
+ useEffect(() => {
61
+ const activity = createActivityTracker({
62
+ onMinutes(minutes) {
63
+ const nextState = updateState((draft) => applyActiveMinutes(draft, { minutes, width }));
64
+ setState(nextState);
65
+ },
66
+ });
67
+ const stopActivity = activity.start();
68
+
69
+ const fileTracker = startFileTracker({
70
+ cwd: process.cwd(),
71
+ onSave() {
72
+ activity.markActive();
73
+ const nextState = updateState((draft) => {
74
+ applyActivityPulse(draft);
75
+ return applyFileSave(draft, { width });
76
+ });
77
+ setState(nextState);
78
+ },
79
+ });
80
+
81
+ const gitTracker = startGitTracker({
82
+ cwd: process.cwd(),
83
+ lastCommitHash: state.last_commit_hash,
84
+ async onCommit(commitHash) {
85
+ const nextState = updateState((draft) => applyCommit(draft, { commitHash, width }));
86
+ setState(nextState);
87
+ },
88
+ });
89
+
90
+ gitTracker.poll().catch(() => {});
91
+
92
+ return () => {
93
+ stopActivity();
94
+ fileTracker.close().catch?.(() => {});
95
+ gitTracker.stop();
96
+ };
97
+ }, [width]);
98
+
99
+ const frame = useMemo(
100
+ () => renderTerminalFrame(state, width, tick, { now: new Date() }),
101
+ [state, tick, width],
102
+ );
103
+ const commandHint = useMemo(() => buildCommandHint(width), [width]);
104
+
105
+ return h(
106
+ Box,
107
+ { flexDirection: "column" },
108
+ h(Text, null, frame),
109
+ h(Text, { color: "gray" }, commandHint),
110
+ );
111
+ }
112
+
113
+ export async function watch() {
114
+ ensureState();
115
+ const app = render(h(ForestWatchApp));
116
+ await app.waitUntilExit();
117
+ }