Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

docs(ink): link the public fork; skip hidden subtrees in the cursor search

Salman Qureshi70c6e8d8225e
diff --git a/DECISIONS.md b/DECISIONS.md
index 20d0b2ce..eab584dd 100644
--- a/DECISIONS.md
+++ b/DECISIONS.md
@@ -168,4 +168,4 @@
- **Context**: ADR-017 vendored ink 5.2.1 with seven Mercury hunks (eight after synchronized output). Upstream reached 8.0.0 with most of that work done properly: incremental rendering, synchronized output, a cursor API, Yoga free-node hygiene, scrollback-preserving fullscreen handling, and dozens of `<Static>`, input, CJK-text and Windows fixes Mercury did not have. Each ink upgrade on the old base meant re-implementing those by hand. Ink 7+ requires Node 22 and ink 8 requires React 19.3.
- **Decision**: Vendor ink 8.0.0 (same pipeline as ADR-017) and keep only what upstream still lacks: `<Static itemKey>`, the freeze gate, the live-region guard (trim instead of writing an over-tall frame, which on ink 8 pushes copies of the live region into scrollback), and a small cursor-anchor hunk that resolves Mercury's `internal_cursor` cell after layout and feeds it to ink's own `setCursorPosition`. Mercury turns on `incrementalRendering`, and after the output wrapper sheds writes it calls `instance.clear()` so the next frame is a full repaint. React moves to 19.3; `engines.node` to `>=22`; the build target to `node22`; CI drops Node 20. The bundle banner exits with a clear message on Node < 22 (Bun is exempt) instead of failing at the first render.
- **Alternatives considered**: backport ink 6–8 fixes into the 5.2.1 fork one by one (rebuilds ink 8 by hand, and every fix touches internals that changed); move to OpenTUI (native renderer, but needs Node ≥ 26.4 with `--experimental-ffi` or Bun, has no Android build for Termux, and is pre-1.0); stay on ink 5 and Node 20 (Node 20 reached end of life in April 2026).
-- **Consequence**: The patch shrinks from about a thousand lines to 168 (`patches/ink+8.0.0.patch`). Node 20 users must upgrade before installing; `mercury doctor` and the docs say Node 22. Hardware-cursor and live-region tests now assert the result on an emulated terminal (`src/ui/vt-screen.ts`) instead of exact escape bytes, so they survive ink's encoding choices. The SQLite driver keeps better-sqlite3 first; Node 22.13+ also has `node:sqlite` (ADR-018).
+- **Consequence**: The patch shrinks from about a thousand lines to 168 (`patches/ink+8.0.0.patch`). The same four changes are kept as TypeScript commits on the `mercury` branch of the public fork [cosmicstack-labs/ink](https://github.com/cosmicstack-labs/ink), for review, rebasing and upstream proposals; Mercury still vendors from the stock tarball plus the applier, and no package is published from the fork. Node 20 users must upgrade before installing; `mercury doctor` and the docs say Node 22. Hardware-cursor and live-region tests now assert the result on an emulated terminal (`src/ui/vt-screen.ts`) instead of exact escape bytes, so they survive ink's encoding choices. The SQLite driver keeps better-sqlite3 first; Node 22.13+ also has `node:sqlite` (ADR-018).
diff --git a/docs/ink-patch.md b/docs/ink-patch.md
index e59a6ae3..fdd8d2b8 100644
--- a/docs/ink-patch.md
+++ b/docs/ink-patch.md
@@ -1,10 +1,11 @@
# Mercury's ink patch set
-Mercury renders its TUI with [ink](https://github.com/vadimdemedes/ink) 8.0.0 and carries four changes to it. Since ADR-017 the patched build is vendored in `vendor/ink/` and bundled into `dist/index.js`, so no install step has to apply them. This page describes each hunk, why it exists, and what an upstream version could look like.
+Mercury renders its TUI with [ink](https://github.com/vadimdemedes/ink) 8.0.0 and carries four changes to it. The same four changes live as reviewable TypeScript commits on the `mercury` branch of our fork, [cosmicstack-labs/ink](https://github.com/cosmicstack-labs/ink) (see its `FORK.md`); that is where they are rebased onto new ink releases and proposed upstream. Since ADR-017 the patched build is vendored in `vendor/ink/` and bundled into `dist/index.js`, so no install step has to apply them. This page describes each hunk, why it exists, and what an upstream version could look like.
| Item | Where |
|---|---|
| Single source of truth for the hunks | `scripts/apply-ink-patch.cjs` |
+| The same changes as TypeScript commits | [cosmicstack-labs/ink](https://github.com/cosmicstack-labs/ink), branch `mercury` |
| Regenerate `vendor/ink` (stock tarball + hunks) | `node scripts/vendor-ink.cjs` |
| Prove the committed files are exactly tarball + hunks | `node scripts/vendor-ink.cjs --check` (runs in CI) |
| Reviewable stock-vs-vendored diff | `patches/ink+8.0.0.patch` (generated) |
diff --git a/patches/ink+8.0.0.patch b/patches/ink+8.0.0.patch
index 56f45a86..e00433a2 100644
--- a/patches/ink+8.0.0.patch
+++ b/patches/ink+8.0.0.patch
@@ -76,7 +76,7 @@ index 0c519c3..4c8fb63 100644
const style = useMemo(() => ({
position: 'absolute',
diff --git a/node_modules/ink/build/ink.js b/node_modules/ink/build/ink.js
-index 29d1a98..6ee4d5a 100644
+index 29d1a98..be21856 100644
--- a/node_modules/ink/build/ink.js
+++ b/node_modules/ink/build/ink.js
@@ -23,6 +23,45 @@ import { AccessibilityContext } from './components/AccessibilityContext.js';
@@ -106,12 +106,12 @@ index 29d1a98..6ee4d5a 100644
+globalThis.__mercuryInkPatch = inkPatch;
+// Depth-first search for the first element with a truthy `internal_cursor`
+// attribute, accumulating Yoga offsets like render-node-to-output does.
-+// <Static> and display:none subtrees are never part of the live frame. The
++// <Static>, hidden and display:none subtrees are never part of the live frame. The
+// DOM attribute is read instead of a ref because refs attach in React's
+// layout phase, after the frame has already been rendered.
+const findCursorCell = (node, x, y) => {
+ const yoga = node.yogaNode;
-+ if (!yoga || node.internal_static || node.style?.display === 'none') return undefined;
++ if (!yoga || node.internal_static || node.isHidden || node.style?.display === 'none') return undefined;
+ const nx = x + yoga.getComputedLeft();
+ const ny = y + yoga.getComputedTop();
+ if (node.attributes?.internal_cursor) return { x: nx, y: ny };
diff --git a/scripts/apply-ink-patch.cjs b/scripts/apply-ink-patch.cjs
index aaffbcd9..f4e0263e 100644
--- a/scripts/apply-ink-patch.cjs
+++ b/scripts/apply-ink-patch.cjs
@@ -180,12 +180,12 @@ export const inkPatch = {
globalThis.__mercuryInkPatch = inkPatch;
// Depth-first search for the first element with a truthy \`internal_cursor\`
// attribute, accumulating Yoga offsets like render-node-to-output does.
-// <Static> and display:none subtrees are never part of the live frame. The
+// <Static>, hidden and display:none subtrees are never part of the live frame. The
// DOM attribute is read instead of a ref because refs attach in React's
// layout phase, after the frame has already been rendered.
const findCursorCell = (node, x, y) => {
const yoga = node.yogaNode;
- if (!yoga || node.internal_static || node.style?.display === 'none') return undefined;
+ if (!yoga || node.internal_static || node.isHidden || node.style?.display === 'none') return undefined;
const nx = x + yoga.getComputedLeft();
const ny = y + yoga.getComputedTop();
if (node.attributes?.internal_cursor) return { x: nx, y: ny };
diff --git a/vendor/ink/build/ink.js b/vendor/ink/build/ink.js
index 6ee4d5ae..be218569 100644
--- a/vendor/ink/build/ink.js
+++ b/vendor/ink/build/ink.js
@@ -46,12 +46,12 @@ export const inkPatch = {
globalThis.__mercuryInkPatch = inkPatch;
// Depth-first search for the first element with a truthy `internal_cursor`
// attribute, accumulating Yoga offsets like render-node-to-output does.
-// <Static> and display:none subtrees are never part of the live frame. The
+// <Static>, hidden and display:none subtrees are never part of the live frame. The
// DOM attribute is read instead of a ref because refs attach in React's
// layout phase, after the frame has already been rendered.
const findCursorCell = (node, x, y) => {
const yoga = node.yogaNode;
- if (!yoga || node.internal_static || node.style?.display === 'none') return undefined;
+ if (!yoga || node.internal_static || node.isHidden || node.style?.display === 'none') return undefined;
const nx = x + yoga.getComputedLeft();
const ny = y + yoga.getComputedTop();
if (node.attributes?.internal_cursor) return { x: nx, y: ny };