Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(ok): stop fitting the terminal grid from an unrendered box (#4136)
Nick Gomezccfd7ba85e11
diff --git a/.changeset/terminal-content-loss-across-layout.md b/.changeset/terminal-content-loss-across-layout.mdnew file mode 100644index 000000000..fd6500670--- /dev/null+++ b/.changeset/terminal-content-loss-across-layout.md@@ -0,0 +1,13 @@+---+"@inkeep/open-knowledge": patch+---++Terminal content no longer disappears when the terminal changes shape around it.++Switching to another terminal tab, reordering tabs, or moving the terminal between the bottom dock and the right column could wipe what was on screen. On Windows the symptom was stark: a command you had just run, and its output, would be replaced by a repeated shell prompt, or older scrollback would vanish while the newest lines survived.++The terminal sizes its grid to fit the box it is drawn in. Hiding a tab, or reparenting the panel mid-move, leaves that box with no size for a moment, and the sizing pass had no way to tell "this box is zero because nothing is drawn right now" from "this box is genuinely tiny". It read a missing size as a real one and fitted the terminal to a grid roughly eleven columns by five rows, then handed that grid to the shell. On Windows the shell owns its screen buffer and repaints it on every resize, so collapsing to a sliver and back destroyed the content in between.++The terminal now sizes itself only from a box that is actually being drawn, and only the sizing pass that measured that box tells the shell about it. A resize that arrives while the terminal is hidden or mid-move is ignored, and the real size is picked up as soon as it is on screen again, so tab switches, reorders, and moves leave the buffer and the running shell untouched.++The same rule covers the terminals that come back when you reload the window. They are restored all at once, but only the tab you are looking at has a size yet, so the ones still waiting their turn are no longer told a size that was never measured. Each is told its real size when it is shown.diff --git a/knip.config.ts b/knip.config.tsindex a0ba1bf42..68adb81cc 100644--- a/knip.config.ts+++ b/knip.config.ts@@ -127,7 +127,9 @@ export default {'packages/server': {entry: ['src/**/*.test.ts', 'src/parse-worker.ts'],project: 'src/**',- ignoreDependencies: ['@types/shell-quote'],+ ignoreDependencies: [+ '@types/shell-quote',+ ],},'packages/cli': {entry: ['src/**/*.test.ts', 'scripts/*.ts', 'tests/**/*.ts', 'src/parse-worker.ts'],diff --git a/packages/app/src/components/TerminalPanel.dom.test.tsx b/packages/app/src/components/TerminalPanel.dom.test.tsxindex 3d5a90ca7..d3bf0c091 100644--- a/packages/app/src/components/TerminalPanel.dom.test.tsx+++ b/packages/app/src/components/TerminalPanel.dom.test.tsx@@ -168,17 +168,49 @@ let deferTerminalWrites = false;let terminalGeneratedInput: string | null = null;let mockResolvedTheme: string | undefined = 'dark';-let roCallback: (() => void) | null = null;+type MockResizeEntry = { contentRect: { width: number; height: number } };+type MockResizeCallback = (entries?: readonly MockResizeEntry[]) => void;+const sizedEntries = (width: number, height: number): readonly MockResizeEntry[] => [+ { contentRect: { width, height } },+];++const stubContainerLayout = (+ rect: { width: number; height: number },+ style: { width: string; height: string },+) => {+ const measure = Element.prototype.getBoundingClientRect;+ const computed = window.getComputedStyle;+ Element.prototype.getBoundingClientRect = function (this: Element) {+ return (this.matches('[data-terminal-status]') ? rect : measure.call(this)) as DOMRect;+ };+ window.getComputedStyle = ((element: Element, pseudo?: string | null) => {+ const base = computed.call(window, element, pseudo ?? undefined);+ if (!element.matches('[data-terminal-status]')) return base;+ return new Proxy(base, {+ get(target, prop, receiver) {+ if (prop === 'width') return style.width;+ if (prop === 'height') return style.height;+ return Reflect.get(target, prop, receiver);+ },+ });+ }) as typeof window.getComputedStyle;+ onTestFinished(() => {+ Element.prototype.getBoundingClientRect = measure;+ window.getComputedStyle = computed;+ });+};++let roCallback: MockResizeCallback | null = null;let allROs: MockResizeObserver[] = [];class MockResizeObserver {- cb: () => void;+ cb: MockResizeCallback;observed: Array<{ el: Element; opts?: ResizeObserverOptions }> = [];observe = vi.fn((el: Element, opts?: ResizeObserverOptions) => {this.observed.push({ el, opts });});unobserve = vi.fn(() => {});disconnect = vi.fn(() => {});- constructor(cb: () => void) {+ constructor(cb: MockResizeCallback) {this.cb = cb;roCallback = cb;allROs.push(this);@@ -382,7 +414,7 @@ describe('TerminalPanel', () => {await waitFor(() => expect(terminal.adopt).toHaveBeenCalledWith('pty-survivor'));expect(terminal.create).not.toHaveBeenCalled();- expect(terminal.resize).toHaveBeenCalledWith('pty-survivor', 80, 24);+ expect(terminal.resize).not.toHaveBeenCalled();act(() => lastTerm?.onDataCb?.('user input'));expect(terminal.input).toHaveBeenCalledWith('pty-survivor', 'user input');});@@ -414,7 +446,7 @@ describe('TerminalPanel', () => {expect(lastTerm?.focus).not.toHaveBeenCalled();act(() => lastTerm?.onDataCb?.('early user input'));expect(terminal.input).not.toHaveBeenCalledWith('pty-survivor', 'early user input');- expect(terminal.resize).toHaveBeenCalledWith('pty-survivor', 80, 24);+ expect(terminal.resize).not.toHaveBeenCalled();act(() => lastTerm?.flushPendingWrites());expect(terminal.input).not.toHaveBeenCalledWith('pty-survivor', '\x1b[?1;2c');@@ -852,7 +884,7 @@ describe('TerminalPanel', () => {await waitFor(() => expect(roCallback).toBeTruthy());const fitsBefore = lastFit?.fit.mock.calls.length ?? 0;- act(() => roCallback?.());+ act(() => roCallback?.(sizedEntries(742, 380)));expect(lastFit?.fit.mock.calls.length ?? 0).toBeGreaterThan(fitsBefore);expect(terminal.resize).toHaveBeenCalledWith('pty-1', 80, 24);@@ -866,9 +898,9 @@ describe('TerminalPanel', () => {const fitsBefore = lastFit?.fit.mock.calls.length ?? 0;const resizesBefore = terminal.resize.mock.calls.length;act(() => {- roCallback?.();- roCallback?.();- roCallback?.();+ roCallback?.(sizedEntries(742, 380));+ roCallback?.(sizedEntries(742, 380));+ roCallback?.(sizedEntries(742, 380));});expect((lastFit?.fit.mock.calls.length ?? 0) - fitsBefore).toBe(3);expect(terminal.resize.mock.calls.length - resizesBefore).toBe(1);@@ -878,18 +910,116 @@ describe('TerminalPanel', () => {});});+ test('a resize notification from an unrendered container never collapses the grid or the PTY', async () => {+ const { bridge, terminal } = makeBridge({ ok: true, ptyId: 'pty-1' });+ render(<TerminalPanel bridge={bridge} />);+ await waitFor(() => expect(roCallback).toBeTruthy());++ expect(lastFit).not.toBeNull();+ lastFit?.fit.mockImplementation(() => {+ if (lastTerm) {+ lastTerm.cols = 11;+ lastTerm.rows = 5;+ }+ });+ const fitsBefore = lastFit?.fit.mock.calls.length ?? 0;+ const resizesBefore = terminal.resize.mock.calls.length;++ act(() => roCallback?.(sizedEntries(0, 0)));++ expect(lastFit?.fit.mock.calls.length ?? 0).toBe(fitsBefore);+ expect(lastTerm?.cols).toBe(80);+ expect(lastTerm?.rows).toBe(24);+ expect(terminal.resize.mock.calls.length).toBe(resizesBefore);+ expect(terminal.resize).not.toHaveBeenCalledWith('pty-1', 11, 5);+ });++ test('the mount-time fit is skipped while the container is not rendered', async () => {+ const { bridge } = makeBridge({ ok: true, ptyId: 'pty-1' });+ render(<TerminalPanel bridge={bridge} />);+ await waitFor(() => expect(roCallback).toBeTruthy());++ expect(lastFit).not.toBeNull();+ expect(lastFit?.fit.mock.calls.length).toBe(0);+ });++ test('the mount-time fit is skipped when only padding gives the container width', async () => {+ stubContainerLayout({ width: 12, height: 380 }, { width: '0px', height: '380px' });++ const { bridge } = makeBridge({ ok: true, ptyId: 'pty-1' });+ render(<TerminalPanel bridge={bridge} />);+ await waitFor(() => expect(roCallback).toBeTruthy());++ expect(lastFit).not.toBeNull();+ expect(lastFit?.fit.mock.calls.length).toBe(0);+ });++ test('the mount-time fit runs once the container is rendered', async () => {+ stubContainerLayout({ width: 742, height: 380 }, { width: '730px', height: '380px' });++ const { bridge } = makeBridge({ ok: true, ptyId: 'pty-1' });+ render(<TerminalPanel bridge={bridge} />);++ await waitFor(() => expect(lastFit?.fit.mock.calls.length ?? 0).toBeGreaterThan(0));+ });++ test('an adopted session forwards only the measured grid, never an unmeasured one', async () => {+ stubContainerLayout({ width: 742, height: 380 }, { width: '730px', height: '380px' });++ const { bridge, terminal } = makeBridge({ ok: true, ptyId: 'pty-fresh' });+ render(<TerminalPanel bridge={bridge} adoptPtyId="pty-survivor" />);++ await waitFor(() => expect(terminal.adopt).toHaveBeenCalledWith('pty-survivor'));+ expect(lastFit).not.toBeNull();+ expect(lastFit?.fit.mock.calls.length).toBeGreaterThan(0);+ expect(terminal.resize).not.toHaveBeenCalled();++ await waitFor(() => expect(roCallback).toBeTruthy());+ lastFit?.fit.mockImplementation(() => {+ if (lastTerm) {+ lastTerm.cols = 200;+ lastTerm.rows = 50;+ }+ });+ act(() => roCallback?.(sizedEntries(742, 380)));++ expect(terminal.resize).toHaveBeenCalledWith('pty-survivor', 200, 50);+ });++ test('an adopted session mounted hidden sends the live PTY no grid until the container is rendered', async () => {+ const { bridge, terminal } = makeBridge({ ok: true, ptyId: 'pty-fresh' });+ render(<TerminalPanel bridge={bridge} adoptPtyId="pty-survivor" />);++ await waitFor(() => expect(terminal.adopt).toHaveBeenCalledWith('pty-survivor'));+ expect(lastFit).not.toBeNull();+ expect(lastFit?.fit.mock.calls.length).toBe(0);+ expect(terminal.resize).not.toHaveBeenCalled();++ await waitFor(() => expect(roCallback).toBeTruthy());+ lastFit?.fit.mockImplementation(() => {+ if (lastTerm) {+ lastTerm.cols = 200;+ lastTerm.rows = 50;+ }+ });+ act(() => roCallback?.(sizedEntries(742, 380)));++ expect(lastFit?.fit.mock.calls.length ?? 0).toBe(1);+ expect(terminal.resize).toHaveBeenCalledWith('pty-survivor', 200, 50);+ });+test('a grid-changing fit repaints synchronously in the same frame (no blank-frame flash)', async () => {const { bridge } = makeBridge({ ok: true, ptyId: 'pty-1' });render(<TerminalPanel bridge={bridge} />);await waitFor(() => expect(roCallback).toBeTruthy());- act(() => roCallback?.());+ act(() => roCallback?.(sizedEntries(742, 380)));expect(lastTerm?.renderFlush).not.toHaveBeenCalled();lastFit?.fit.mockImplementation(() => {if (lastTerm) lastTerm.cols = 100;});- act(() => roCallback?.());+ act(() => roCallback?.(sizedEntries(742, 380)));expect(lastTerm?.refresh).toHaveBeenCalled();expect(lastTerm?.renderFlush).toHaveBeenCalledTimes(1);});@@ -907,7 +1037,7 @@ describe('TerminalPanel', () => {lastFit?.fit.mockImplementation(() => {if (lastTerm) lastTerm.cols += 1;});- act(() => roCallback?.());+ act(() => roCallback?.(sizedEntries(742, 380)));expect(lastTerm?.viewportY).toBe(120);expect(lastTerm?.scrollbarLine).toBe(7);expect(lastTerm?.pendingScrollTarget).toBeNull();@@ -919,7 +1049,7 @@ describe('TerminalPanel', () => {lastTerm.renderFlush.mockClear();lastTerm.scrollToBottom.mockClear();}- act(() => roCallback?.());+ act(() => roCallback?.(sizedEntries(742, 380)));expect(lastTerm?.renderFlush.mock.invocationCallOrder[0]).toBeLessThan(lastTerm?.scrollToBottom.mock.invocationCallOrder[0] ?? 0,);@@ -934,7 +1064,7 @@ describe('TerminalPanel', () => {lastTerm.scrollbarLine = 3;}lastFit?.fit.mockImplementation(() => {});- act(() => roCallback?.());+ act(() => roCallback?.(sizedEntries(742, 380)));expect(lastTerm?.viewportY).toBe(12);expect(lastTerm?.scrollbarLine).toBe(3);expect(lastTerm?.pendingScrollTarget).toBeNull();diff --git a/packages/app/src/components/TerminalPanel.tsx b/packages/app/src/components/TerminalPanel.tsxindex 1f0a90cc6..13dc600f3 100644--- a/packages/app/src/components/TerminalPanel.tsx+++ b/packages/app/src/components/TerminalPanel.tsx@@ -38,6 +38,7 @@ import { type TerminalExitInfo, TerminalExitNotice } from './TerminalExitNotice'import { TerminalNoticeBanner } from './TerminalNoticeBanner';import { TerminalRefusalNotice } from './TerminalRefusalNotice';import { TerminalStartingNotice } from './TerminalStartingNotice';+import { isRenderedContainer, shouldFitForResize } from './terminal-fit-gate';import { createTerminalFileLinkProvider } from './terminal-link-provider';import { createRecentOpenGuard, type TerminalLinkTarget } from './terminal-links';import { createSameFrameRepaint } from './terminal-render-flush';@@ -336,7 +337,11 @@ function TerminalSession({}}- fit.fit();+ if (+ isRenderedContainer(container.getBoundingClientRect(), window.getComputedStyle(container))+ ) {+ fit.fit();+ }const repaintSameFrame = createSameFrameRepaint(term);@@ -521,7 +526,8 @@ function TerminalSession({ptyResizeThrottle = createResizeThrottle(() => {if (ptyId) bridge.terminal.resize(ptyId, term.cols, term.rows);}, PTY_RESIZE_THROTTLE_MS);- observer = new ResizeObserver(() => {+ observer = new ResizeObserver((entries) => {+ if (!shouldFitForResize(entries)) return;const colsBefore = term.cols;const rowsBefore = term.rows;fit.fit();@@ -621,7 +627,6 @@ function TerminalSession({} else {markInteractive();}- bridge.terminal.resize(adoptPtyId, term.cols, term.rows);return;}}diff --git a/packages/app/src/components/terminal-fit-gate.test.ts b/packages/app/src/components/terminal-fit-gate.test.tsnew file mode 100644index 000000000..84ecb8fd2--- /dev/null+++ b/packages/app/src/components/terminal-fit-gate.test.ts@@ -0,0 +1,83 @@+import { describe, expect, test } from 'vitest';+import { isRenderedBox, isRenderedContainer, shouldFitForResize } from './terminal-fit-gate';++describe('isRenderedBox', () => {+ test('accepts a box with positive width and height', () => {+ expect(isRenderedBox({ width: 742, height: 380 })).toBe(true);+ });++ test('rejects a box that is not being rendered', () => {+ expect(isRenderedBox({ width: 0, height: 0 })).toBe(false);+ expect(isRenderedBox({ width: 742, height: 0 })).toBe(false);+ expect(isRenderedBox({ width: 0, height: 380 })).toBe(false);+ });++ test('rejects a missing or non-finite box', () => {+ expect(isRenderedBox(null)).toBe(false);+ expect(isRenderedBox(undefined)).toBe(false);+ expect(isRenderedBox({ width: Number.NaN, height: 380 })).toBe(false);+ expect(isRenderedBox({ width: 742, height: Number.POSITIVE_INFINITY })).toBe(false);+ });+});++describe('shouldFitForResize', () => {+ test('fits when an observed box is being rendered', () => {+ expect(shouldFitForResize([{ contentRect: { width: 742, height: 380 } }])).toBe(true);+ });++ test('does not fit when every observed box is unrendered', () => {+ expect(shouldFitForResize([{ contentRect: { width: 0, height: 0 } }])).toBe(false);+ expect(+ shouldFitForResize([+ { contentRect: { width: 0, height: 0 } },+ { contentRect: { width: 0, height: 380 } },+ ]),+ ).toBe(false);+ });++ test('fits when at least one observed box is being rendered', () => {+ expect(+ shouldFitForResize([+ { contentRect: { width: 0, height: 0 } },+ { contentRect: { width: 742, height: 380 } },+ ]),+ ).toBe(true);+ });++ test('does not fit when no observations were delivered at all', () => {+ expect(shouldFitForResize()).toBe(false);+ expect(shouldFitForResize(null)).toBe(false);+ expect(shouldFitForResize([])).toBe(false);+ });++ test('does not fit when an observation carries no measurement', () => {+ expect(shouldFitForResize([{}])).toBe(false);+ expect(shouldFitForResize([{ contentRect: null }])).toBe(false);+ });+});++describe('isRenderedContainer', () => {+ const rendered = { width: 742, height: 380 };++ test('fits when both the border box and the content box are rendered', () => {+ expect(isRenderedContainer(rendered, { width: '730px', height: '380px' })).toBe(true);+ });++ test('does not fit when the content box has no usable width', () => {+ expect(isRenderedContainer({ width: 12, height: 380 }, { width: '0px', height: '380px' })).toBe(+ false,+ );+ });++ test('does not fit when the element is not rendered, despite a percentage content box', () => {+ expect(isRenderedContainer({ width: 0, height: 0 }, { width: '100%', height: '100%' })).toBe(+ false,+ );+ });++ test('does not fit when the content box is unresolvable', () => {+ expect(isRenderedContainer(rendered, { width: '', height: '' })).toBe(false);+ expect(isRenderedContainer(rendered, { width: 'auto', height: 'auto' })).toBe(false);+ expect(isRenderedContainer(rendered, null)).toBe(false);+ });+});diff --git a/packages/app/src/components/terminal-fit-gate.ts b/packages/app/src/components/terminal-fit-gate.tsnew file mode 100644index 000000000..d44e82807--- /dev/null+++ b/packages/app/src/components/terminal-fit-gate.ts@@ -0,0 +1,36 @@+export interface MeasuredBox {+ readonly width: number;+ readonly height: number;+}++export interface ResizeNotification {+ readonly contentRect?: MeasuredBox | null;+}++export function isRenderedBox(box: MeasuredBox | null | undefined): boolean {+ if (box == null) return false;+ const { width, height } = box;+ return Number.isFinite(width) && Number.isFinite(height) && width > 0 && height > 0;+}++export function shouldFitForResize(entries?: readonly ResizeNotification[] | null): boolean {+ if (entries == null || entries.length === 0) return false;+ return entries.some((entry) => isRenderedBox(entry.contentRect));+}++export interface ComputedBox {+ readonly width: string;+ readonly height: string;+}++export function isRenderedContainer(+ rect: MeasuredBox | null | undefined,+ computed: ComputedBox | null | undefined,+): boolean {+ if (!isRenderedBox(rect)) return false;+ if (computed == null) return false;+ return isRenderedBox({+ width: Number.parseFloat(computed.width),+ height: Number.parseFloat(computed.height),+ });+}diff --git a/packages/app/src/editor/extensions/source-dirty-fold-atomicity.dom.test.tsx b/packages/app/src/editor/extensions/source-dirty-fold-atomicity.dom.test.tsxindex 9e043d02b..3a15d1233 100644--- a/packages/app/src/editor/extensions/source-dirty-fold-atomicity.dom.test.tsx+++ b/packages/app/src/editor/extensions/source-dirty-fold-atomicity.dom.test.tsx@@ -1,3 +1,4 @@+import { sharedExtensions as coreExtensions, MarkdownManager } from '@inkeep/open-knowledge-core';import { type ObserverDispatchKind, setupServerObservers } from '@inkeep/open-knowledge-server';import { cleanup } from '@testing-library/react';diff --git a/packages/app/tests/dom/input-rule-atom-ranges.dom.test.tsx b/packages/app/tests/dom/input-rule-atom-ranges.dom.test.tsxindex f81d64a77..65162a22f 100644--- a/packages/app/tests/dom/input-rule-atom-ranges.dom.test.tsx+++ b/packages/app/tests/dom/input-rule-atom-ranges.dom.test.tsx@@ -1,3 +1,4 @@+import { cleanup } from '@testing-library/react';import { Editor, getSchema } from '@tiptap/core';import type { MarkType, Node as PMNode } from '@tiptap/pm/model';diff --git a/packages/app/tests/dom/jsx-interior-input-rule-suppression.dom.test.tsx b/packages/app/tests/dom/jsx-interior-input-rule-suppression.dom.test.tsxindex c4c510031..c5b8ad023 100644--- a/packages/app/tests/dom/jsx-interior-input-rule-suppression.dom.test.tsx+++ b/packages/app/tests/dom/jsx-interior-input-rule-suppression.dom.test.tsx@@ -1,3 +1,4 @@+import { cleanup } from '@testing-library/react';import { Editor, type JSONContent } from '@tiptap/core';import type { Node as PMNode } from '@tiptap/pm/model';diff --git a/packages/app/tests/dom/plain-text-clipboard.dom.test.tsx b/packages/app/tests/dom/plain-text-clipboard.dom.test.tsxindex 931aaa880..65b32f4b3 100644--- a/packages/app/tests/dom/plain-text-clipboard.dom.test.tsx+++ b/packages/app/tests/dom/plain-text-clipboard.dom.test.tsx@@ -1,3 +1,4 @@+import { cleanup } from '@testing-library/react';import { Editor } from '@tiptap/core';import type { Node as PMNode } from '@tiptap/pm/model';diff --git a/packages/app/tests/dom/serializer-seam-rederive.dom.test.tsx b/packages/app/tests/dom/serializer-seam-rederive.dom.test.tsxindex c9744993d..2ab40357a 100644--- a/packages/app/tests/dom/serializer-seam-rederive.dom.test.tsx+++ b/packages/app/tests/dom/serializer-seam-rederive.dom.test.tsx@@ -1,3 +1,4 @@+import { MarkdownManager, stripFrontmatter } from '@inkeep/open-knowledge-core';import { cleanup } from '@testing-library/react';import { Editor, type JSONContent } from '@tiptap/core';diff --git a/packages/app/tests/dom/task-list-input-rule.dom.test.tsx b/packages/app/tests/dom/task-list-input-rule.dom.test.tsxindex e01856aac..1db8b25a9 100644--- a/packages/app/tests/dom/task-list-input-rule.dom.test.tsx+++ b/packages/app/tests/dom/task-list-input-rule.dom.test.tsx@@ -1,3 +1,4 @@+import { cleanup } from '@testing-library/react';import type { Editor } from '@tiptap/core';import type { Node as PMNode } from '@tiptap/pm/model';diff --git a/packages/app/tests/dom/underline-round-trip.dom.test.tsx b/packages/app/tests/dom/underline-round-trip.dom.test.tsxindex f0bea3f33..652d75f43 100644--- a/packages/app/tests/dom/underline-round-trip.dom.test.tsx+++ b/packages/app/tests/dom/underline-round-trip.dom.test.tsx@@ -1,3 +1,4 @@+import { MarkdownManager, sharedExtensions, stripFrontmatter } from '@inkeep/open-knowledge-core';import { cleanup } from '@testing-library/react';import { Editor, getSchema, type JSONContent } from '@tiptap/core';diff --git a/packages/app/tests/integration/api-error-envelope/create-folder.test.ts b/packages/app/tests/integration/api-error-envelope/create-folder.test.tsindex 49257d365..079b42e9a 100644--- a/packages/app/tests/integration/api-error-envelope/create-folder.test.ts+++ b/packages/app/tests/integration/api-error-envelope/create-folder.test.ts@@ -1,3 +1,4 @@+import { CreateFolderSuccessSchema, ProblemDetailsSchema } from '@inkeep/open-knowledge-core';import { afterAll, beforeAll, describe, expect, test } from 'vitest';import { HARNESS_BOOT_TIMEOUT_MS } from '../harness-boot-timeout';diff --git a/packages/app/tests/integration/bug3-source-mode-writeback.test.ts b/packages/app/tests/integration/bug3-source-mode-writeback.test.tsindex 8a60e5826..a28cc2b18 100644--- a/packages/app/tests/integration/bug3-source-mode-writeback.test.ts+++ b/packages/app/tests/integration/bug3-source-mode-writeback.test.ts@@ -1,3 +1,4 @@+import { readFileSync } from 'node:fs';import { join } from 'node:path';import { setTimeout as wait } from 'node:timers/promises';diff --git a/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts b/packages/app/tests/integration/indented-jsx-byte-sacred.test.tsindex 6fcdc23f2..4fc2c11f9 100644--- a/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts+++ b/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts@@ -1,3 +1,4 @@+import { setTimeout as wait } from 'node:timers/promises';import { normalizeBridge } from '@inkeep/open-knowledge-core';import { updateYFragment } from '@tiptap/y-tiptap';diff --git a/packages/app/tests/integration/interior-edit-freshness.test.ts b/packages/app/tests/integration/interior-edit-freshness.test.tsindex 40b5cdfd6..9f2f6feb6 100644--- a/packages/app/tests/integration/interior-edit-freshness.test.ts+++ b/packages/app/tests/integration/interior-edit-freshness.test.ts@@ -1,3 +1,4 @@+import { setTimeout as wait } from 'node:timers/promises';import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';import { afterAll, beforeAll, describe, expect, test } from 'vitest';diff --git a/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts b/packages/app/tests/integration/keystroke-cadence-danger-space.test.tsindex 93666af70..2a085742b 100644--- a/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts+++ b/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts@@ -1,3 +1,4 @@+import { setTimeout as wait } from 'node:timers/promises';import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';import { afterAll, beforeAll, describe, expect, test } from 'vitest';diff --git a/packages/app/tests/integration/producer-guard-wiring.test.ts b/packages/app/tests/integration/producer-guard-wiring.test.tsindex 867598d34..878d5196b 100644--- a/packages/app/tests/integration/producer-guard-wiring.test.ts+++ b/packages/app/tests/integration/producer-guard-wiring.test.ts@@ -1,3 +1,4 @@+import { setTimeout as wait } from 'node:timers/promises';import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';import { afterAll, beforeAll, describe, expect, test } from 'vitest';diff --git a/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts b/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.tsindex 0970ac12f..4ada3cf26 100644--- a/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts+++ b/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts@@ -1,3 +1,4 @@+import { randomUUID } from 'node:crypto';import { afterEach, describe, expect, test } from 'vitest';import { agentWriteMd, createTestServer, type TestServer } from './test-harness';diff --git a/packages/app/tests/integration/qa-045-restore-after-gc.test.ts b/packages/app/tests/integration/qa-045-restore-after-gc.test.tsindex b632185e1..cbe2b705f 100644--- a/packages/app/tests/integration/qa-045-restore-after-gc.test.ts+++ b/packages/app/tests/integration/qa-045-restore-after-gc.test.ts@@ -1,3 +1,4 @@+import { execFileSync } from 'node:child_process';import { randomUUID } from 'node:crypto';import { join } from 'node:path';diff --git a/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts b/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.tsindex c530ce4ba..89bc9b4d9 100644--- a/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts+++ b/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts@@ -1,3 +1,4 @@+import { randomUUID } from 'node:crypto';import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';import type * as Y from 'yjs';diff --git a/packages/app/tests/integration/undo-after-rollback.test.ts b/packages/app/tests/integration/undo-after-rollback.test.tsindex d3767adc9..a78aeb0e4 100644--- a/packages/app/tests/integration/undo-after-rollback.test.ts+++ b/packages/app/tests/integration/undo-after-rollback.test.ts@@ -1,3 +1,4 @@+import { ROLLBACK_ORIGIN } from '@inkeep/open-knowledge-server';import { afterAll, beforeAll, describe, expect, test } from 'vitest';import * as Y from 'yjs';diff --git a/packages/app/tests/integration/undo-recycle-reset.test.ts b/packages/app/tests/integration/undo-recycle-reset.test.tsindex be1a29fbc..39e64a221 100644--- a/packages/app/tests/integration/undo-recycle-reset.test.ts+++ b/packages/app/tests/integration/undo-recycle-reset.test.ts@@ -1,3 +1,4 @@+import { writeFileSync } from 'node:fs';import { join } from 'node:path';import { setTimeout as wait } from 'node:timers/promises';diff --git a/packages/app/tests/integration/undo-rederive-survival.test.ts b/packages/app/tests/integration/undo-rederive-survival.test.tsindex 7935e35f8..9ddcd0730 100644--- a/packages/app/tests/integration/undo-rederive-survival.test.ts+++ b/packages/app/tests/integration/undo-rederive-survival.test.ts@@ -1,3 +1,4 @@+import { prependFrontmatter } from '@inkeep/open-knowledge-core';import { Plugin, PluginKey } from '@tiptap/pm/state';import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';diff --git a/packages/core/src/bridge/compose.ts b/packages/core/src/bridge/compose.tsindex f4cc8a286..2a597ec3d 100644--- a/packages/core/src/bridge/compose.ts+++ b/packages/core/src/bridge/compose.ts@@ -1,3 +1,4 @@+import { prependFrontmatter, stripFrontmatter } from '../extensions/frontmatter.ts';export type ComposeAdjustment = 'none' | 'body' | 'frontmatter' | 'unresolved';diff --git a/packages/core/src/bridge/doc-boundary-space.ts b/packages/core/src/bridge/doc-boundary-space.tsindex 8fb428b90..01ef76a9f 100644--- a/packages/core/src/bridge/doc-boundary-space.ts+++ b/packages/core/src/bridge/doc-boundary-space.ts@@ -1,3 +1,4 @@+import { FRONTMATTER_RE, stripFrontmatter } from '../extensions/frontmatter.ts';import { carriedEdgeEmpties, type DocEdgeEmpties } from '../markdown/doc-edge-blank-runs.ts';diff --git a/packages/core/src/markdown/comment-promoter.ts b/packages/core/src/markdown/comment-promoter.tsindex bfbd5a2e8..20a68d2a1 100644--- a/packages/core/src/markdown/comment-promoter.ts+++ b/packages/core/src/markdown/comment-promoter.ts@@ -1,3 +1,4 @@+import type { Nodes, Paragraph, PhrasingContent, Root, RootContent, Text } from 'mdast';import { SKIP, visit } from 'unist-util-visit';import type { VFile } from 'vfile';diff --git a/packages/core/src/markdown/fixtures/index.ts b/packages/core/src/markdown/fixtures/index.tsindex 00f5771ee..6931623c7 100644--- a/packages/core/src/markdown/fixtures/index.ts+++ b/packages/core/src/markdown/fixtures/index.ts@@ -1,3 +1,4 @@+import { readFileSync } from 'node:fs';import { dirname, resolve } from 'node:path';import { fileURLToPath } from 'node:url';@@ -8,6 +9,7 @@ function fixturePath(...segments: string[]): string {return resolve(FIXTURES_DIR, ...segments);}+interface GfmExample {section: string;markdown: string;@@ -17,6 +19,7 @@ export function loadGfmExamples(): GfmExample[] {return JSON.parse(readFileSync(fixturePath('gfm', 'examples.json'), 'utf8')) as GfmExample[];}+interface MdxCrashEntry {id: string;input: string;@@ -68,6 +71,7 @@ export function loadLargeEmbedFixtures(): LargeEmbedFixture[] {) as LargeEmbedFixture[];}+export function loadPrd6955Before(): string {return readFileSync(fixturePath('regression', 'prd-6955-before.md'), 'utf8');}@@ -76,6 +80,7 @@ export function loadPrd6955CorruptedTriplicated(): string {return readFileSync(fixturePath('regression', 'prd-6955-corrupted-triplicated.md'), 'utf8');}+export interface NgPinnedCase {id: string;name: string;@@ -92,6 +97,7 @@ export function loadNgPinnedCases(): NgPinnedCase[] {) as NgPinnedCase[];}+export function loadLargeRealistic(): string {return readFileSync(fixturePath('perf', 'large-realistic.md'), 'utf8');}diff --git a/packages/core/src/markdown/fixtures/perf/generate.ts b/packages/core/src/markdown/fixtures/perf/generate.tsindex 8b1eb8519..daa3ef82b 100644--- a/packages/core/src/markdown/fixtures/perf/generate.ts+++ b/packages/core/src/markdown/fixtures/perf/generate.ts@@ -1,3 +1,4 @@+import { writeFileSync } from 'node:fs';import { dirname, resolve } from 'node:path';import { fileURLToPath } from 'node:url';@@ -10,6 +11,7 @@ const BASELINE_ONLY_COUNTS = [500, 2500] as const;const SEED = 0xf1de1117;+function mulberry32(seed: number): () => number {let a = seed >>> 0;return () => {@@ -36,6 +38,7 @@ function pickWeighted<T>(rand: () => number, items: readonly [T, number][]): T {return items[items.length - 1][0];}+const WORDS = ['lorem','ipsum',@@ -153,6 +156,7 @@ function mdxBlock(rand: () => number): string {return `<${name}>\n\n${sentence(rand)}\n\n</${name}>`;}+type BlockKind = 'paragraph' | 'heading' | 'list' | 'code' | 'table' | 'mdx';const MIX: readonly [BlockKind, number][] = [@@ -191,6 +195,7 @@ function generateDocument(blockCount: number, seed: number): string {return `${blocks.join('\n\n')}\n`;}+function main(): void {for (const count of [...BLOCK_COUNTS, ...BASELINE_ONLY_COUNTS]) {const doc = generateDocument(count, SEED);diff --git a/packages/core/src/markdown/image-promoter.ts b/packages/core/src/markdown/image-promoter.tsindex 706fa9afb..994eb6917 100644--- a/packages/core/src/markdown/image-promoter.ts+++ b/packages/core/src/markdown/image-promoter.ts@@ -1,3 +1,4 @@+import type { Image, Paragraph, Root } from 'mdast';import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';import { visit } from 'unist-util-visit';diff --git a/packages/core/src/markdown/math-promoter.ts b/packages/core/src/markdown/math-promoter.tsindex a5b511f25..bd79424c7 100644--- a/packages/core/src/markdown/math-promoter.ts+++ b/packages/core/src/markdown/math-promoter.ts@@ -1,3 +1,4 @@+import type { Code, Root } from 'mdast';import type { Math as MdastMath } from 'mdast-util-math';import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';diff --git a/packages/core/src/markdown/merged-walker.ts b/packages/core/src/markdown/merged-walker.tsindex bfd7e3109..fa3cfcd86 100644--- a/packages/core/src/markdown/merged-walker.ts+++ b/packages/core/src/markdown/merged-walker.ts@@ -1,3 +1,4 @@+import type { Nodes, Parent, Root } from 'mdast';import { SKIP, visit } from 'unist-util-visit';import type { VFile } from 'vfile';diff --git a/packages/core/src/markdown/safe-url.ts b/packages/core/src/markdown/safe-url.tsindex 4d3250d3a..8be632ba4 100644--- a/packages/core/src/markdown/safe-url.ts+++ b/packages/core/src/markdown/safe-url.ts@@ -1,3 +1,4 @@+export const SAFE_URL_SCHEMES = ['https', 'http', 'mailto', 'tel', 'ftp', 'sms'] as const;const SCHEME_ALT = SAFE_URL_SCHEMES.map((s) => `${s}:`).join('|');diff --git a/packages/server/src/checkpoint-retention-tie.test.ts b/packages/server/src/checkpoint-retention-tie.test.tsindex 8a5d82998..0a43a2773 100644--- a/packages/server/src/checkpoint-retention-tie.test.ts+++ b/packages/server/src/checkpoint-retention-tie.test.ts@@ -1,3 +1,4 @@+import { execFileSync } from 'node:child_process';import { mkdirSync, mkdtempSync, rmSync } from 'node:fs';import { tmpdir } from 'node:os';diff --git a/packages/server/src/qa-degradation-matrix.test.ts b/packages/server/src/qa-degradation-matrix.test.tsindex 84e3e5297..00bb6efe7 100644--- a/packages/server/src/qa-degradation-matrix.test.ts+++ b/packages/server/src/qa-degradation-matrix.test.ts@@ -1,3 +1,4 @@+import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';import type * as Y from 'yjs';import { createBridgeDeriveLossReporter } from './bridge-loss-detector.ts';diff --git a/packages/server/src/qa-gc-budget-isolation.test.ts b/packages/server/src/qa-gc-budget-isolation.test.tsindex a800ca9f3..b65c4693e 100644--- a/packages/server/src/qa-gc-budget-isolation.test.ts+++ b/packages/server/src/qa-gc-budget-isolation.test.ts@@ -1,3 +1,4 @@+import { mkdirSync, mkdtempSync, rmSync } from 'node:fs';import { tmpdir } from 'node:os';import { join, resolve } from 'node:path';diff --git a/packages/server/src/qa-watcher-intake-lens.test.ts b/packages/server/src/qa-watcher-intake-lens.test.tsindex 2337e6c3c..4669d1b98 100644--- a/packages/server/src/qa-watcher-intake-lens.test.ts+++ b/packages/server/src/qa-watcher-intake-lens.test.ts@@ -1,3 +1,4 @@+import { Hocuspocus } from '@hocuspocus/server';import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';import * as Y from 'yjs';