Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(ok): key bug-report screenshot by report, not window (PRD-8214) (#3729)

Andrew Mikofalvy9dc495991c4b
diff --git a/.changeset/bug-report-retry-keeps-own-screenshot.md b/.changeset/bug-report-retry-keeps-own-screenshot.md
new file mode 100644
index 000000000..585717015
--- /dev/null
+++ b/.changeset/bug-report-retry-keeps-own-screenshot.md
@@ -0,0 +1,9 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+**Retrying a bug report no longer attaches a different report's screenshot.** When you filed one report, it failed to send, and you filed a second one from the same window before retrying the first, the retry's ticket came back carrying the second report's picture. The saved bundle was always right; only the image shown on the ticket was wrong, which is the worst version of it, because the picture is the first thing anyone reads and nothing about it looked stale.
+
+The app used to hold one screenshot per window, captured when the report dialog opened, and looked it up again at the moment a report was sent. Opening the dialog a second time replaced it, so a send that happened after that read whatever the newer dialog had captured. Screenshots are now held per report from the moment the report is written, so a retry attaches the picture that report was composed from no matter what has been filed since. A report with no picture on hand still files without one, which is what already happened for a retry in a later session.
+
+This was only reachable once sends started running in the background with a Try again affordance, so two reports could be in flight from one window at the same time. No released build is affected.
diff --git a/knip.config.ts b/knip.config.ts
index 78162ec09..f9179f2d4 100644
--- a/knip.config.ts
+++ b/knip.config.ts
@@ -123,7 +123,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/core/src/bridge/bind-frontmatter-doc.ts b/packages/core/src/bridge/bind-frontmatter-doc.ts
index d7a845280..dfd95ef49 100644
--- a/packages/core/src/bridge/bind-frontmatter-doc.ts
+++ b/packages/core/src/bridge/bind-frontmatter-doc.ts
@@ -1,3 +1,4 @@
+
import type * as Y from 'yjs';
import type { Err, Ok, Result } from '../config/result.ts';
import { type FrontmatterValidationError, toFrontmatterIssue } from '../frontmatter/errors.ts';
diff --git a/packages/core/src/bridge/bridge-invariant.ts b/packages/core/src/bridge/bridge-invariant.ts
index 005627195..8bfdb40cd 100644
--- a/packages/core/src/bridge/bridge-invariant.ts
+++ b/packages/core/src/bridge/bridge-invariant.ts
@@ -1,3 +1,4 @@
+
import { fnv1aDigest } from './hash-util.ts';
export type BridgeInvariantSite = 'observer-b' | 'persistence' | 'test-harness';
diff --git a/packages/core/src/bridge/compose.ts b/packages/core/src/bridge/compose.ts
index 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/divergence-locate.ts b/packages/core/src/bridge/divergence-locate.ts
index 6b505314d..d979f4b39 100644
--- a/packages/core/src/bridge/divergence-locate.ts
+++ b/packages/core/src/bridge/divergence-locate.ts
@@ -1,3 +1,4 @@
+
import { findFirstDivergenceIndex } from './tolerance-telemetry.ts';
export const BRIDGE_LINE_KINDS = [
diff --git a/packages/core/src/bridge/doc-boundary-space.ts b/packages/core/src/bridge/doc-boundary-space.ts
index 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/bridge/growth-detect.ts b/packages/core/src/bridge/growth-detect.ts
index 9d9c244b0..463e89595 100644
--- a/packages/core/src/bridge/growth-detect.ts
+++ b/packages/core/src/bridge/growth-detect.ts
@@ -1,3 +1,4 @@
+
const DEFAULT_MIN_SUBSTANTIVE_LINE_LENGTH = 16;
export const DUPLICATION_GATE_MIN_LINE_LENGTH = 8;
diff --git a/packages/core/src/bridge/intraline-predicate.ts b/packages/core/src/bridge/intraline-predicate.ts
index c43fdd7e7..0939885bb 100644
--- a/packages/core/src/bridge/intraline-predicate.ts
+++ b/packages/core/src/bridge/intraline-predicate.ts
@@ -1,3 +1,4 @@
+
export function rawLineCounts(doc: string): Map<string, number> {
const counts = new Map<string, number>();
for (const line of doc.split('\n')) {
diff --git a/packages/core/src/bridge/merge-three-way.ts b/packages/core/src/bridge/merge-three-way.ts
index 251560a35..c0dc65705 100644
--- a/packages/core/src/bridge/merge-three-way.ts
+++ b/packages/core/src/bridge/merge-three-way.ts
@@ -65,6 +65,7 @@ export function tryLineLevelCombine(
return { clean: true, merged };
}
+
export type BridgeMergeContentLossSide = 'user' | 'agent';
export type BridgeMergeContentLossWhich = 'substring' | 'order' | 'growth';
diff --git a/packages/core/src/bridge/normalize.ts b/packages/core/src/bridge/normalize.ts
index 01ac80099..dcc5b0690 100644
--- a/packages/core/src/bridge/normalize.ts
+++ b/packages/core/src/bridge/normalize.ts
@@ -1,3 +1,4 @@
+
import { stripFrontmatter } from '../extensions/frontmatter.ts';
import { bodyEdgeEmpties } from './doc-boundary-space.ts';
diff --git a/packages/core/src/bridge/pm-structural-equivalence.ts b/packages/core/src/bridge/pm-structural-equivalence.ts
index 754dc5cc2..0be5203e4 100644
--- a/packages/core/src/bridge/pm-structural-equivalence.ts
+++ b/packages/core/src/bridge/pm-structural-equivalence.ts
@@ -32,6 +32,7 @@ const BR_SENTINEL: PmStructuralNode = { type: '__br__' };
const BR_LITERAL_RE = /^<br\s*\/?>$/i;
+
interface DegradeEntry {
readonly label: string;
readonly severity: ToleranceClassSeverity;
@@ -127,6 +128,7 @@ export interface ComparePmStructuralOptions {
ignoreAttrs?: (attrKey: string) => boolean;
}
+
/** Rebuild a node with `fn` applied to each child; identity when childless.
* Shared by the degrade canonicalizers so none re-implements the walk. */
function mapChildren(
@@ -248,6 +250,7 @@ function applyDegrades(tree: PmStructuralNode): {
return { normalized: current, fired };
}
+
export function comparePmStructural(
expected: PmStructuralNode,
actual: PmStructuralNode,
diff --git a/packages/core/src/bridge/subsequence.ts b/packages/core/src/bridge/subsequence.ts
index af20de1e2..dca644141 100644
--- a/packages/core/src/bridge/subsequence.ts
+++ b/packages/core/src/bridge/subsequence.ts
@@ -1,3 +1,4 @@
+
/** True when `needle` is a subsequence of `haystack` (two-pointer, O(n+m)):
* insertions in `haystack` are free; any dropped or substituted `needle` byte
* fails. */
diff --git a/packages/core/src/markdown/callout-transformer.ts b/packages/core/src/markdown/callout-transformer.ts
index 83d47404a..a363dfd54 100644
--- a/packages/core/src/markdown/callout-transformer.ts
+++ b/packages/core/src/markdown/callout-transformer.ts
@@ -1,3 +1,4 @@
+
import type { Blockquote, 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/code-fence.ts b/packages/core/src/markdown/code-fence.ts
index 9807a7e82..4499dbc92 100644
--- a/packages/core/src/markdown/code-fence.ts
+++ b/packages/core/src/markdown/code-fence.ts
@@ -1,3 +1,4 @@
+
export function selectFenceChar(info: string): '`' | '~' {
return info.includes('`') ? '~' : '`';
}
diff --git a/packages/core/src/markdown/comment-promoter.ts b/packages/core/src/markdown/comment-promoter.ts
index 7415c474a..34704165b 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/dedent-block-jsx-close.ts b/packages/core/src/markdown/dedent-block-jsx-close.ts
index ece5c02a1..b6299a948 100644
--- a/packages/core/src/markdown/dedent-block-jsx-close.ts
+++ b/packages/core/src/markdown/dedent-block-jsx-close.ts
@@ -1,3 +1,4 @@
+
import { findFencedRegions, isInsideFence } from './fence-regions.ts';
const INDENTED_BLOCK_JSX_CLOSE_RE = /^([ ]{1,3})(<\/[A-Z][A-Za-z0-9_]*\s*>)([ \t]*)$/gm;
diff --git a/packages/core/src/markdown/details-accordion-promoter.ts b/packages/core/src/markdown/details-accordion-promoter.ts
index 54774764a..acd398aa6 100644
--- a/packages/core/src/markdown/details-accordion-promoter.ts
+++ b/packages/core/src/markdown/details-accordion-promoter.ts
@@ -1,3 +1,4 @@
+
import type { Nodes, Paragraph, Parent, Root, Text } from 'mdast';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/div-align-promoter.ts b/packages/core/src/markdown/div-align-promoter.ts
index 43ecdc709..ba9b56384 100644
--- a/packages/core/src/markdown/div-align-promoter.ts
+++ b/packages/core/src/markdown/div-align-promoter.ts
@@ -1,3 +1,4 @@
+
import type { Nodes, Paragraph, Parent, Root, Text } from 'mdast';
import type { MdxJsxFlowElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/fence-regions.ts b/packages/core/src/markdown/fence-regions.ts
index 6d3f3643e..4513da9bb 100644
--- a/packages/core/src/markdown/fence-regions.ts
+++ b/packages/core/src/markdown/fence-regions.ts
@@ -1,3 +1,4 @@
+
const FENCE_RE = /^(`{3,}|~{3,})/gm;
export function findFencedRegions(src: string): Array<[number, number]> {
diff --git a/packages/core/src/markdown/fixtures/index.ts b/packages/core/src/markdown/fixtures/index.ts
index 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.ts
index 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/guard-flanking-matrix.ts b/packages/core/src/markdown/guard-flanking-matrix.ts
index 420dc0fe5..32c055c5b 100644
--- a/packages/core/src/markdown/guard-flanking-matrix.ts
+++ b/packages/core/src/markdown/guard-flanking-matrix.ts
@@ -7,6 +7,7 @@ import {
import { BACKSLASH_GUARD_SUBSTITUTIONS, encodeBackslashEscapes } from './backslash-escape-guard.ts';
import { ENTITY_REF_GUARD_SUBSTITUTIONS, encodeEntityRefs } from './entity-ref-guard.ts';
+
export const ATTENTION_DELIMITERS = ['*', '_', '**', '~~', '=='] as const;
export type FlankClass = 'whitespace' | 'punctuation' | 'other';
diff --git a/packages/core/src/markdown/handler-shadow-audit.ts b/packages/core/src/markdown/handler-shadow-audit.ts
index 2653473da..283913255 100644
--- a/packages/core/src/markdown/handler-shadow-audit.ts
+++ b/packages/core/src/markdown/handler-shadow-audit.ts
@@ -1,3 +1,4 @@
+
export interface HandlerShadowWitness {
input: string;
expect: 'byte' | 'byte-and-reparse-type';
diff --git a/packages/core/src/markdown/highlight-promoter.ts b/packages/core/src/markdown/highlight-promoter.ts
index da0a81d23..5d1000cc4 100644
--- a/packages/core/src/markdown/highlight-promoter.ts
+++ b/packages/core/src/markdown/highlight-promoter.ts
@@ -1,3 +1,4 @@
+
import type { Nodes, Parent, PhrasingContent, Root, Text } from 'mdast';
import type { MdxJsxTextElement } from 'mdast-util-mdx';
import { SKIP, visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/html-to-mdast.ts b/packages/core/src/markdown/html-to-mdast.ts
index 787315157..9681c0056 100644
--- a/packages/core/src/markdown/html-to-mdast.ts
+++ b/packages/core/src/markdown/html-to-mdast.ts
@@ -1,3 +1,4 @@
+
import type { Element as HastElement, Root as HastRoot } from 'hast';
import type { List, Nodes as MdastNodes, Root as MdastRoot } from 'mdast';
import rehypeParse from 'rehype-parse';
@@ -128,7 +129,8 @@ export function htmlToMdast(html: string, options?: HtmlToMdastOptions): MdastRo
throw new HtmlPayloadTooLargeError(html.length, maxBytes);
}
- const processor = unified().use(rehypeParse, { fragment: true });
+ const processor = unified()
+ .use(rehypeParse, { fragment: true });
for (const plugin of cleanupPlugins) {
processor.use(plugin);
diff --git a/packages/core/src/markdown/image-promoter.ts b/packages/core/src/markdown/image-promoter.ts
index 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/index.ts b/packages/core/src/markdown/index.ts
index 779e27500..ec1ac1b7e 100644
--- a/packages/core/src/markdown/index.ts
+++ b/packages/core/src/markdown/index.ts
@@ -1,3 +1,4 @@
+
import {
type FromProseMirrorOptions,
fromPmMark,
@@ -206,6 +207,7 @@ export class MarkdownManager {
}
}
+
const registry = createRegistry();
function destructureAttrs(
@@ -254,6 +256,7 @@ function destructureAttrs(
return result;
}
+
function hasDirtyDescendant(node: PmNode): boolean {
let found = false;
node.descendants((child) => {
@@ -276,6 +279,7 @@ function effectiveDirty(node: PmNode, freshnessChecker?: StructuralFreshnessChec
return freshnessChecker ? freshnessChecker.isDiverged(node.toJSON()) : false;
}
+
function isEmptyMdastParagraph(node: MdastNodes): boolean {
if (node.type !== 'paragraph') return false;
const children = node.children ?? [];
@@ -344,6 +348,7 @@ function extractTextFromMdastNodes(nodes: MdastNodes[]): string {
return out;
}
+
import {
AUDIO_EXTENSIONS,
FILE_ATTACHMENT_EXTENSIONS,
@@ -596,6 +601,7 @@ function buildMdastToPmHandlers(
}));
}
+
if (m.emphasis) {
handlers.emphasis = toPmMark(m.emphasis, (node: Emphasis) => ({
sourceDelimiter: node.data?.sourceDelimiter ?? '*',
@@ -676,6 +682,7 @@ function buildMdastToPmHandlers(
}));
}
+
if (m.link) {
const sourceLiteralMark = m.sourceLiteral;
handlers.link = (node: Link, _parent: MdastParent, state: MdastToPmState) => {
@@ -973,6 +980,7 @@ function buildMdastToPmHandlers(
};
}
+
const blockUnknownHandler = (node: {
type: string;
position?: { start: { offset: number }; end: { offset: number } };
@@ -1098,6 +1106,7 @@ function buildMdastToPmHandlers(
return handlers as RemarkProseMirrorOptions['handlers'];
}
+
function buildPmToMdastHandlers(
schema: Schema,
freshness: FreshnessCheckerHolder,
diff --git a/packages/core/src/markdown/lint/applies-to.ts b/packages/core/src/markdown/lint/applies-to.ts
index fa0be9e86..b79e9aef7 100644
--- a/packages/core/src/markdown/lint/applies-to.ts
+++ b/packages/core/src/markdown/lint/applies-to.ts
@@ -1,3 +1,4 @@
+
import picomatch from 'picomatch';
import { SUPPORTED_DOC_EXTENSIONS } from '../../constants/doc-extensions.ts';
diff --git a/packages/core/src/markdown/lint/config-files.ts b/packages/core/src/markdown/lint/config-files.ts
index 312c9c74b..94b34dee1 100644
--- a/packages/core/src/markdown/lint/config-files.ts
+++ b/packages/core/src/markdown/lint/config-files.ts
@@ -1,3 +1,4 @@
+
const MARKDOWNLINT_JSON_CONFIG_FILES: ReadonlySet<string> = new Set([
'.markdownlint.json',
'.markdownlint.jsonc',
diff --git a/packages/core/src/markdown/lint/config-schemas.ts b/packages/core/src/markdown/lint/config-schemas.ts
index 1a81aa524..fbbd309df 100644
--- a/packages/core/src/markdown/lint/config-schemas.ts
+++ b/packages/core/src/markdown/lint/config-schemas.ts
@@ -52,6 +52,7 @@ const fullPluginShape = Object.fromEntries(
LINT_PLUGINS.map((plugin) => [plugin.id, plugin.sliceSchema]),
) as z.ZodRawShape;
+
export const LinterConfigSchema = z.object({
enabled: z.boolean(),
plugins: z.object(fullPluginShape),
diff --git a/packages/core/src/markdown/lint/default-config.ts b/packages/core/src/markdown/lint/default-config.ts
index d48eea5e4..a51f2ffb0 100644
--- a/packages/core/src/markdown/lint/default-config.ts
+++ b/packages/core/src/markdown/lint/default-config.ts
@@ -6,6 +6,7 @@ export const DEFAULT_MARKDOWNLINT_CONFIG: Record<string, MarkdownlintRuleSetting
MD013: false,
};
+
export function resolveMarkdownlintConfig(
rules: Record<string, MarkdownlintRuleSetting> | undefined,
): Configuration {
diff --git a/packages/core/src/markdown/lint/frontmatter-schema-edit.ts b/packages/core/src/markdown/lint/frontmatter-schema-edit.ts
index ef478e268..9c9542661 100644
--- a/packages/core/src/markdown/lint/frontmatter-schema-edit.ts
+++ b/packages/core/src/markdown/lint/frontmatter-schema-edit.ts
@@ -1,3 +1,4 @@
+
import { CANONICAL_SCHEMA_DIALECT_URIS, DEFAULT_SCHEMA_DIALECT } from './frontmatter-validate.ts';
export interface FrontmatterFieldConstraint {
diff --git a/packages/core/src/markdown/lint/frontmatter-validate.ts b/packages/core/src/markdown/lint/frontmatter-validate.ts
index 5f953d667..b0e7833fd 100644
--- a/packages/core/src/markdown/lint/frontmatter-validate.ts
+++ b/packages/core/src/markdown/lint/frontmatter-validate.ts
@@ -1,3 +1,4 @@
+
import Ajv, { type ValidateFunction } from 'ajv';
import Ajv2019 from 'ajv/dist/2019.js';
import Ajv2020 from 'ajv/dist/2020.js';
diff --git a/packages/core/src/markdown/lint/index.ts b/packages/core/src/markdown/lint/index.ts
index 11b5abdfd..ffd277a90 100644
--- a/packages/core/src/markdown/lint/index.ts
+++ b/packages/core/src/markdown/lint/index.ts
@@ -1,3 +1,4 @@
+
import { LINT_PLUGINS, type LinterConfig } from './plugins.ts';
import type { LintDiagnostic } from './types.ts';
diff --git a/packages/core/src/markdown/lint/okf-frontmatter/materialize.ts b/packages/core/src/markdown/lint/okf-frontmatter/materialize.ts
index 7a5af097e..f438f1b16 100644
--- a/packages/core/src/markdown/lint/okf-frontmatter/materialize.ts
+++ b/packages/core/src/markdown/lint/okf-frontmatter/materialize.ts
@@ -1,3 +1,4 @@
+
import type { OkfRuleId } from '../okf-rule-meta.ts';
import { fileNameFor, OKF_SCHEMA_DIR, okfSchemaPathFor } from './paths.ts';
import { OKF_FRONTMATTER_REGISTRY } from './registry.ts';
diff --git a/packages/core/src/markdown/lint/okf-frontmatter/paths.ts b/packages/core/src/markdown/lint/okf-frontmatter/paths.ts
index 1ee913527..c290b6878 100644
--- a/packages/core/src/markdown/lint/okf-frontmatter/paths.ts
+++ b/packages/core/src/markdown/lint/okf-frontmatter/paths.ts
@@ -1,3 +1,4 @@
+
import type { OkfRuleId } from '../okf-rule-meta.ts';
export const OKF_SCHEMA_DIR = '.ok/okf';
diff --git a/packages/core/src/markdown/lint/okf-frontmatter/registry.ts b/packages/core/src/markdown/lint/okf-frontmatter/registry.ts
index f325fbbb4..53ecb619d 100644
--- a/packages/core/src/markdown/lint/okf-frontmatter/registry.ts
+++ b/packages/core/src/markdown/lint/okf-frontmatter/registry.ts
@@ -1,3 +1,4 @@
+
import { compileAppliesTo } from '../applies-to.ts';
import { validateFrontmatterSource } from '../frontmatter-validate.ts';
import {
diff --git a/packages/core/src/markdown/lint/okf-frontmatter/schemas.ts b/packages/core/src/markdown/lint/okf-frontmatter/schemas.ts
index f1c37671b..89845d3d5 100644
--- a/packages/core/src/markdown/lint/okf-frontmatter/schemas.ts
+++ b/packages/core/src/markdown/lint/okf-frontmatter/schemas.ts
@@ -1,3 +1,4 @@
+
// file-level form is deliberate: the sibling `biome-ignore` must sit on the line
// oxlint-disable unicorn/no-thenable
diff --git a/packages/core/src/markdown/lint/okf-project/rules.ts b/packages/core/src/markdown/lint/okf-project/rules.ts
index 6d691ae2b..8b476332e 100644
--- a/packages/core/src/markdown/lint/okf-project/rules.ts
+++ b/packages/core/src/markdown/lint/okf-project/rules.ts
@@ -1,3 +1,4 @@
+
import { SUPPORTED_DOC_EXTENSIONS } from '../../../constants/doc-extensions.ts';
import { isOkfRuleEnabled, type OkfRuleId, type OkfRuleToggles } from '../okf-rule-meta.ts';
diff --git a/packages/core/src/markdown/lint/okf-rule-meta.ts b/packages/core/src/markdown/lint/okf-rule-meta.ts
index 4de50d79f..44913a9dc 100644
--- a/packages/core/src/markdown/lint/okf-rule-meta.ts
+++ b/packages/core/src/markdown/lint/okf-rule-meta.ts
@@ -1,3 +1,4 @@
+
export const OKF_RULE_IDS = [
'no-wiki-links',
'log-shape',
diff --git a/packages/core/src/markdown/lint/okf-rules.ts b/packages/core/src/markdown/lint/okf-rules.ts
index 1d5538421..d0999b62e 100644
--- a/packages/core/src/markdown/lint/okf-rules.ts
+++ b/packages/core/src/markdown/lint/okf-rules.ts
@@ -1,3 +1,4 @@
+
import { isOkfRuleEnabled, type OkfRuleId, type OkfRuleToggles } from './okf-rule-meta.ts';
import type { OkfRule } from './okf-runner.ts';
import { indexShape } from './rules/index-shape.ts';
diff --git a/packages/core/src/markdown/lint/okf-runner.ts b/packages/core/src/markdown/lint/okf-runner.ts
index de130e3f4..fabb08d6e 100644
--- a/packages/core/src/markdown/lint/okf-runner.ts
+++ b/packages/core/src/markdown/lint/okf-runner.ts
@@ -1,3 +1,4 @@
+
import type { Root } from 'mdast';
import remarkFrontmatter from 'remark-frontmatter';
import remarkGfm from 'remark-gfm';
diff --git a/packages/core/src/markdown/lint/plugins.ts b/packages/core/src/markdown/lint/plugins.ts
index 09c8450ee..0a089990e 100644
--- a/packages/core/src/markdown/lint/plugins.ts
+++ b/packages/core/src/markdown/lint/plugins.ts
@@ -1,3 +1,4 @@
+
import { z } from 'zod';
import { DEFAULT_MARKDOWNLINT_CONFIG, resolveMarkdownlintConfig } from './default-config.ts';
import {
@@ -23,6 +24,7 @@ import {
type OkfSlice,
} from './types.ts';
+
const MarkdownlintRuleSettingSchema = z.union([
z.boolean(),
z.enum(MARKDOWNLINT_RULE_SEVERITIES),
diff --git a/packages/core/src/markdown/lint/rules/index-shape.ts b/packages/core/src/markdown/lint/rules/index-shape.ts
index 59fe9b87d..fcbb1b56c 100644
--- a/packages/core/src/markdown/lint/rules/index-shape.ts
+++ b/packages/core/src/markdown/lint/rules/index-shape.ts
@@ -1,3 +1,4 @@
+
import type { List, ListItem } from 'mdast';
import { EXIT, visit } from 'unist-util-visit';
import { defineScopedOkfRule } from '../okf-runner.ts';
diff --git a/packages/core/src/markdown/lint/rules/log-shape.ts b/packages/core/src/markdown/lint/rules/log-shape.ts
index e0159519f..431e4e9c8 100644
--- a/packages/core/src/markdown/lint/rules/log-shape.ts
+++ b/packages/core/src/markdown/lint/rules/log-shape.ts
@@ -1,3 +1,4 @@
+
import type { Heading } from 'mdast';
import { toString as headingText } from 'mdast-util-to-string';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/lint/rules/no-wiki-links.ts b/packages/core/src/markdown/lint/rules/no-wiki-links.ts
index 2123e977f..f75a04d15 100644
--- a/packages/core/src/markdown/lint/rules/no-wiki-links.ts
+++ b/packages/core/src/markdown/lint/rules/no-wiki-links.ts
@@ -1,3 +1,4 @@
+
import type { Point } from 'unist';
import { visit } from 'unist-util-visit';
import { defineOkfRule } from '../okf-runner.ts';
diff --git a/packages/core/src/markdown/lint/rules/reserved-casing.ts b/packages/core/src/markdown/lint/rules/reserved-casing.ts
index 89ef3e4a9..c8b4d8f28 100644
--- a/packages/core/src/markdown/lint/rules/reserved-casing.ts
+++ b/packages/core/src/markdown/lint/rules/reserved-casing.ts
@@ -1,3 +1,4 @@
+
import { SUPPORTED_DOC_EXTENSIONS } from '../../../constants/doc-extensions.ts';
import { defineOkfRule } from '../okf-runner.ts';
diff --git a/packages/core/src/markdown/lint/types.ts b/packages/core/src/markdown/lint/types.ts
index 6836b962d..c04fa4de0 100644
--- a/packages/core/src/markdown/lint/types.ts
+++ b/packages/core/src/markdown/lint/types.ts
@@ -1,3 +1,4 @@
+
import type { BrokenLinkReason } from '../../schemas/api/agent-write.ts';
import type { OkfRuleId } from './okf-rule-meta.ts';
@@ -112,6 +113,7 @@ export interface OkfSlice {
generate?: { index?: boolean };
}
+
interface RuleOptionSpecBase {
key: string;
description: string;
diff --git a/packages/core/src/markdown/lint/validation-counts.ts b/packages/core/src/markdown/lint/validation-counts.ts
index 98238656e..437cc539a 100644
--- a/packages/core/src/markdown/lint/validation-counts.ts
+++ b/packages/core/src/markdown/lint/validation-counts.ts
@@ -1,3 +1,4 @@
+
export interface ValidationSourceCounts {
errorCount: number;
warningCount: number;
diff --git a/packages/core/src/markdown/math-promoter.ts b/packages/core/src/markdown/math-promoter.ts
index 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/mdast-to-hast-handlers.ts b/packages/core/src/markdown/mdast-to-hast-handlers.ts
index ed89371d0..00fbc0035 100644
--- a/packages/core/src/markdown/mdast-to-hast-handlers.ts
+++ b/packages/core/src/markdown/mdast-to-hast-handlers.ts
@@ -1,3 +1,4 @@
+
import type { Comment, Element, ElementContent, Properties } from 'hast';
import type { FootnoteDefinition, FootnoteReference } from 'mdast';
import type { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx';
diff --git a/packages/core/src/markdown/mdast-to-html.ts b/packages/core/src/markdown/mdast-to-html.ts
index 8ce2b2492..df788a80d 100644
--- a/packages/core/src/markdown/mdast-to-html.ts
+++ b/packages/core/src/markdown/mdast-to-html.ts
@@ -1,3 +1,4 @@
+
import type { Element, Root as HastRoot, Text as HastText } from 'hast';
import type { Root as MdastRoot, Text as MdastText } from 'mdast';
import type { Handler } from 'mdast-util-to-hast';
diff --git a/packages/core/src/markdown/merged-walker.ts b/packages/core/src/markdown/merged-walker.ts
index 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/mermaid-promoter.ts b/packages/core/src/markdown/mermaid-promoter.ts
index 1a897fca8..17ed2b829 100644
--- a/packages/core/src/markdown/mermaid-promoter.ts
+++ b/packages/core/src/markdown/mermaid-promoter.ts
@@ -1,3 +1,4 @@
+
import type { Code, Root } from 'mdast';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/parse-with-fallback.ts b/packages/core/src/markdown/parse-with-fallback.ts
index d988f4b8b..4aa0490c4 100644
--- a/packages/core/src/markdown/parse-with-fallback.ts
+++ b/packages/core/src/markdown/parse-with-fallback.ts
@@ -168,6 +168,7 @@ export function parseRecursive(
}
}
+
interface VFilePlace {
offset?: number;
start?: { offset?: number };
@@ -186,6 +187,7 @@ function extractErrorOffset(err: unknown): number | undefined {
return undefined;
}
+
interface Region {
start: number;
end: number;
@@ -209,6 +211,7 @@ function nearestBlankLineAfter(src: string, offset: number): number | null {
return null;
}
+
export interface TagEvent {
kind: 'open' | 'close' | 'self-close';
name: string;
@@ -355,6 +358,7 @@ function findFallbackRegion(src: string, errorOffset: number): Region {
return { start: blockStart, end: blockEnd };
}
+
interface SourceBlock {
src: string;
start: number;
@@ -452,6 +456,7 @@ function tryPerBlockFallback(
};
}
+
function wholeDocRawText(source: string): JSONContent {
return {
type: 'doc',
diff --git a/packages/core/src/markdown/parser-drop-closure.ts b/packages/core/src/markdown/parser-drop-closure.ts
index e6ab4fd57..43d420187 100644
--- a/packages/core/src/markdown/parser-drop-closure.ts
+++ b/packages/core/src/markdown/parser-drop-closure.ts
@@ -1,3 +1,4 @@
+
export type DroppedTokenAdjudication =
| {
kind: 'format-dof-axis';
diff --git a/packages/core/src/markdown/pipeline.ts b/packages/core/src/markdown/pipeline.ts
index 0e3224206..55736041c 100644
--- a/packages/core/src/markdown/pipeline.ts
+++ b/packages/core/src/markdown/pipeline.ts
@@ -1,3 +1,4 @@
+
import {
type FromProseMirrorOptions,
fromProseMirror,
diff --git a/packages/core/src/markdown/position-aware-join.ts b/packages/core/src/markdown/position-aware-join.ts
index 91cdf658f..ccf06e94d 100644
--- a/packages/core/src/markdown/position-aware-join.ts
+++ b/packages/core/src/markdown/position-aware-join.ts
@@ -1,3 +1,4 @@
+
import type { Join } from 'mdast-util-to-markdown';
import type { Position } from 'unist';
import { isBlankLineParagraph } from './zero-emission-blocks.ts';
diff --git a/packages/core/src/markdown/position-slice.ts b/packages/core/src/markdown/position-slice.ts
index 0f399d34c..e5b4c9eba 100644
--- a/packages/core/src/markdown/position-slice.ts
+++ b/packages/core/src/markdown/position-slice.ts
@@ -1,3 +1,4 @@
+
import type { Nodes, Root } from 'mdast';
import { visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
@@ -476,7 +477,8 @@ export function applyPositionSliceToNode(
const first = source[startOff];
if (first !== '[' && first !== '<' && !node.title) {
node.data.sourceStyle = 'gfm-autolink';
- } else if (first === '[') {
+ }
+ else if (first === '[') {
const slice = source.slice(startOff, endOff);
const closeBracketIdx = slice.lastIndexOf('](');
if (closeBracketIdx !== -1) {
diff --git a/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts b/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts
index db10fa54b..ca225ce9b 100644
--- a/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts
+++ b/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts
@@ -1,3 +1,4 @@
+
import type { Comment, Element, Root, Text } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts b/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts
index 34068d103..3a2524a9a 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts
@@ -1,3 +1,4 @@
+
import type { Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts b/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts
index 93151d43b..2279a0189 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts
@@ -1,3 +1,4 @@
+
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts b/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts
index 188f02d83..a0f467c42 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts
@@ -1,3 +1,4 @@
+
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts b/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts
index 4ba2c3418..4e8542a21 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts
@@ -1,3 +1,4 @@
+
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts b/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts
index 1a74b1272..a3c96b24a 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts
@@ -1,3 +1,4 @@
+
import type { Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts b/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts
index de35e7b79..e95cf43d6 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts
@@ -1,3 +1,4 @@
+
import type { Comment, Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts b/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts
index b4be1b2ea..ffdb4d5b5 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts
@@ -1,3 +1,4 @@
+
import type { Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts b/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts
index 3c8d88b7c..e2a96d1a7 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts
@@ -1,3 +1,4 @@
+
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/resolve-image-url.ts b/packages/core/src/markdown/resolve-image-url.ts
index cf2c9da8e..0389575ac 100644
--- a/packages/core/src/markdown/resolve-image-url.ts
+++ b/packages/core/src/markdown/resolve-image-url.ts
@@ -1,3 +1,4 @@
+
import { isRelativeUrl } from './safe-url.ts';
function isDevDiagnosticContext(): boolean {
diff --git a/packages/core/src/markdown/safe-url.ts b/packages/core/src/markdown/safe-url.ts
index 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/core/src/markdown/serialize-fidelity.test-helper.ts b/packages/core/src/markdown/serialize-fidelity.test-helper.ts
index 0dd54070e..96304e7a5 100644
--- a/packages/core/src/markdown/serialize-fidelity.test-helper.ts
+++ b/packages/core/src/markdown/serialize-fidelity.test-helper.ts
@@ -1,3 +1,4 @@
+
import type { JSONContent } from '@tiptap/core';
import type { Nodes } from 'mdast';
import { expect } from 'vitest';
diff --git a/packages/core/src/markdown/serialize-helpers.ts b/packages/core/src/markdown/serialize-helpers.ts
index 7cac5b042..93798cf83 100644
--- a/packages/core/src/markdown/serialize-helpers.ts
+++ b/packages/core/src/markdown/serialize-helpers.ts
@@ -1,3 +1,4 @@
+
import type { Node as PmNode } from '@tiptap/pm/model';
import type {
MdxJsxAttribute,
diff --git a/packages/core/src/markdown/single-dollar-math-promoter.ts b/packages/core/src/markdown/single-dollar-math-promoter.ts
index b012a5aff..8c08b7a04 100644
--- a/packages/core/src/markdown/single-dollar-math-promoter.ts
+++ b/packages/core/src/markdown/single-dollar-math-promoter.ts
@@ -1,3 +1,4 @@
+
import type { PhrasingContent, Root, Text } from 'mdast';
import type { InlineMath } from 'mdast-util-math';
import { SKIP, visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/to-markdown-handlers.ts b/packages/core/src/markdown/to-markdown-handlers.ts
index 3e79f8cb6..959cc0bd2 100644
--- a/packages/core/src/markdown/to-markdown-handlers.ts
+++ b/packages/core/src/markdown/to-markdown-handlers.ts
@@ -1,3 +1,4 @@
+
import type { Nodes, Parents } from 'mdast';
import type { MdxJsxAttribute, MdxJsxExpressionAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import type { Handle, Info, State } from 'mdast-util-to-markdown';
diff --git a/packages/core/src/markdown/underline-promoter.ts b/packages/core/src/markdown/underline-promoter.ts
index 0f1b0f27d..6e6d73400 100644
--- a/packages/core/src/markdown/underline-promoter.ts
+++ b/packages/core/src/markdown/underline-promoter.ts
@@ -1,3 +1,4 @@
+
import type { Nodes, Parent, Root } from 'mdast';
import type { MdxJsxTextElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/unknown-mdast-guard.ts b/packages/core/src/markdown/unknown-mdast-guard.ts
index 1a082bda7..932d7d2a8 100644
--- a/packages/core/src/markdown/unknown-mdast-guard.ts
+++ b/packages/core/src/markdown/unknown-mdast-guard.ts
@@ -1,3 +1,4 @@
+
import type { Root as MdastRoot } from 'mdast';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/whitespace-char-ref.ts b/packages/core/src/markdown/whitespace-char-ref.ts
index d578476a7..ac9f5239b 100644
--- a/packages/core/src/markdown/whitespace-char-ref.ts
+++ b/packages/core/src/markdown/whitespace-char-ref.ts
@@ -1,3 +1,4 @@
+
const INLINE_WHITESPACE_BY_CODE: ReadonlyMap<number, string> = new Map([
[0x20, ' '],
[0x09, '\t'],
diff --git a/packages/core/src/markdown/wiki-link-micromark.ts b/packages/core/src/markdown/wiki-link-micromark.ts
index 6dad26200..afd9936fe 100644
--- a/packages/core/src/markdown/wiki-link-micromark.ts
+++ b/packages/core/src/markdown/wiki-link-micromark.ts
@@ -17,6 +17,7 @@ declare module 'micromark-util-types' {
}
}
+
const CODE_BANG = 33; // !
const CODE_LBRACKET = 91; // [
const CODE_RBRACKET = 93; // ]
@@ -260,6 +261,7 @@ export function wikiLinkSyntax(): Extension {
};
}
+
function enterWikiLink(this: CompileContext, token: Token) {
this.enter(
{
@@ -385,6 +387,7 @@ export const wikiLinkToMarkdown: {
unsafe: [{ character: '[', inConstruct: ['phrasing'] }],
};
+
const MICROMARK_EXT = wikiLinkSyntax();
export function remarkWikiLink(this: Processor) {
diff --git a/packages/desktop/src/main/index.ts b/packages/desktop/src/main/index.ts
index a218b3aa3..e16d2ca0c 100644
--- a/packages/desktop/src/main/index.ts
+++ b/packages/desktop/src/main/index.ts
@@ -277,6 +277,7 @@ import {
} from './integrations-settings.ts';
import {
type BugReportScreenshotEntry,
+ createBugReportScreenshotHold,
handleBugReportCaptureScreenshot,
handleBugReportCrashAck,
handleBugReportCrashDumpAvailability,
@@ -1483,9 +1484,44 @@ function getServerExitRecorder(): ServerExitRecorder {
* previewed; it is overwritten by the next open's capture and deleted when the
* window's contents are destroyed, so at most one screenshot per live window
* sits in memory.
+ *
+ * This slot answers "what did the window look like when its dialog opened?", so
+ * it is the right source for `create`, which runs while that dialog is still up.
+ * It is NOT a report identity — `send` uses the hold below instead.
*/
const bugReportScreenshots = new Map<number, BugReportScreenshotEntry>();
+/**
+ * Screenshots held per REPORT for the standalone Linear asset upload, filled by
+ * `create` the moment a bundle (and therefore a report id) exists. Sends run in
+ * the background and stay retryable, so by the time one is retried the sender
+ * window's slot above may belong to a report composed afterwards; resolving the
+ * asset by report id is what keeps a retry attaching its own picture.
+ *
+ * Entries are filed under the composing window and released when its contents are
+ * destroyed, because the send toast that can retry a report lives in that
+ * window's renderer: once it is gone nothing can ask for the bytes again, and a
+ * picture of the user's whole screen should not sit in memory waiting for the
+ * cap to evict it. `MAX_PENDING_REPORT_SCREENSHOTS` is the backstop behind that,
+ * not the lifetime.
+ */
+const bugReportSendScreenshots = createBugReportScreenshotHold({
+ onEvict: (reportId) => {
+ getLogger('bug-report').info(
+ { event: 'bug-report.screenshot-evicted', reportId },
+ 'bug-report: dropped a held screenshot to stay under the cap',
+ );
+ },
+});
+
+/**
+ * Windows that already carry a `destroyed` reaper for the hold above. One
+ * listener per composing window however many reports it files — the sibling
+ * capture store learned the same lesson about accumulating MaxListeners-worth of
+ * reapers on a single `WebContents`.
+ */
+const bugReportSendScreenshotReapers = new Set<number>();
+
/** Max width (logical px) of the screenshot preview data-URL handed to the renderer. */
const BUG_REPORT_SCREENSHOT_PREVIEW_WIDTH = 720;
@@ -5983,7 +6019,12 @@ function registerIpcHandlers() {
return bugReportSidecar.list();
}
if (request.kind === 'delete') {
- return bugReportSidecar.remove(request.id);
+ const removed = await bugReportSidecar.remove(request.id);
+ // Only once the report is actually gone. A refused delete leaves it in the
+ // list (`in-flight` most of all, where the send may still fail and be
+ // retried), and that report keeps needing its picture.
+ if (removed.ok) bugReportSendScreenshots.forget(request.id);
+ return removed;
}
if (request.kind === 'send') {
return handleBugReportSend(
@@ -6000,12 +6041,28 @@ function registerIpcHandlers() {
bugReportsRoot: dirname(defaultBugReportZipPath()),
// Records uploading → sent/upload-failed/email-drafted on the sidecar
// and holds the in-flight lock, for the first send and a list retry.
- sidecar: bugReportSidecar.sendHooks,
- // Same per-window capture `create` stages into the zip, uploaded
- // separately as its own Linear asset so the ticket embeds it inline.
- // Still present here because the dialog has not closed yet; a list retry
- // in a later session finds nothing and files without the inline image.
- screenshotPngBytes: () => bugReportScreenshots.get(event.sender.id)?.png ?? null,
+ sidecar: {
+ onSendStart: (id) => bugReportSidecar.sendHooks.onSendStart(id),
+ onSendResult: async (id, outcome) => {
+ try {
+ await bugReportSidecar.sendHooks.onSendResult(id, outcome);
+ } finally {
+ // A confirmed send has already uploaded the asset and the report
+ // can no longer be retried, so nothing wants these bytes again —
+ // a picture of the user's screen should not outlive its use.
+ // Every other outcome stays retryable and keeps its capture.
+ // In `finally` so releasing them never depends on the sidecar
+ // honoring its never-throws contract.
+ if (outcome.kind === 'sent') bugReportSendScreenshots.forget(id);
+ }
+ },
+ },
+ // The capture THIS report was composed from, uploaded separately as its
+ // own Linear asset so the ticket embeds it inline. Keyed by report, not
+ // by window: a retry that lands after a second report was composed must
+ // still attach its own picture. A retry in a later session finds nothing
+ // and files without the inline image.
+ screenshotPngBytes: (reportId) => bugReportSendScreenshots.read(reportId),
},
request,
);
@@ -6069,6 +6126,19 @@ function registerIpcHandlers() {
// Main-owned bytes captured for this exact window; `create` stages them
// only when the renderer opted in via `includeScreenshot`.
screenshotPngBytes: () => bugReportScreenshots.get(event.sender.id)?.png ?? null,
+ // Whatever reached the bundle is filed under the new report's id, so the
+ // later (possibly retried) send resolves this report's picture rather
+ // than the window slot's current occupant.
+ onScreenshotStaged: (reportId, png) => {
+ const composedBy = event.sender.id;
+ bugReportSendScreenshots.remember(reportId, png, composedBy);
+ if (bugReportSendScreenshotReapers.has(composedBy)) return;
+ bugReportSendScreenshotReapers.add(composedBy);
+ event.sender.once('destroyed', () => {
+ bugReportSendScreenshotReapers.delete(composedBy);
+ bugReportSendScreenshots.forgetOwner(composedBy);
+ });
+ },
// Persist the report's `generated` sidecar and run the retention sweep
// once the bundle is written, so it survives dialog close + restart.
onReportGenerated: (meta) => bugReportSidecar.recordGenerated(meta),
diff --git a/packages/desktop/src/main/ipc/bug-report.test.ts b/packages/desktop/src/main/ipc/bug-report.test.ts
index 1b3622608..cec4502ec 100644
--- a/packages/desktop/src/main/ipc/bug-report.test.ts
+++ b/packages/desktop/src/main/ipc/bug-report.test.ts
@@ -30,7 +30,7 @@ import {
} from 'node:fs';
import { createServer, type Server } from 'node:http';
import { tmpdir } from 'node:os';
-import { dirname, join, resolve } from 'node:path';
+import { basename, dirname, join, resolve } from 'node:path';
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
/**
@@ -72,6 +72,7 @@ import {
type BugReportSendDeps,
type CapturableImage,
type CaptureScreenshotDeps,
+ createBugReportScreenshotHold,
DEFAULT_BUG_REPORT_INTAKE_URL,
handleBugReportCaptureScreenshot,
handleBugReportCrashAck,
@@ -868,6 +869,201 @@ describe('handleBugReportSend — inline screenshot upload', () => {
});
});
+describe('bug-report screenshot hold — two reports composed from one window', () => {
+ // Distinguishable PNG signatures: WHICH report's capture reached the ticket is
+ // the entire assertion, so the two must never compare equal.
+ const SCREENSHOT_A = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x0a, 0x0a]);
+ const SCREENSHOT_B = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x0b, 0x0b]);
+
+ test('a retried send uploads its own capture, not that of a report composed after it', async () => {
+ const stub = await startIntakeStub();
+ const bugReportsRoot = makeBugReportsRoot();
+ // main keeps ONE open-time capture per window, and both dialogs open on the
+ // same window — the shape that makes the second report overwrite the first.
+ const SENDER_ID = 7;
+ const windowStore = new Map<number, BugReportScreenshotEntry>();
+ const capture = (png: Buffer) =>
+ windowStore.set(SENDER_ID, { png, cleanup: () => windowStore.delete(SENDER_ID) });
+ const hold = createBugReportScreenshotHold();
+ const createDeps = (zipName: string): BugReportCreateDeps => ({
+ projectDir: null,
+ desktopMeta: DESKTOP_META,
+ outputPath: join(bugReportsRoot, zipName),
+ userLogsDir: makeTmpDir(),
+ screenshotPngBytes: () => windowStore.get(SENDER_ID)?.png ?? null,
+ onScreenshotStaged: (reportId, png) => hold.remember(reportId, png, SENDER_ID),
+ });
+
+ capture(SCREENSHOT_A);
+ const reportA = await handleBugReportCreate(
+ createDeps('2026-07-15T18-30-00-000Z-bugreport.zip'),
+ { kind: 'create', level: 'standard', includeScreenshot: true },
+ );
+ if (!reportA.ok) throw new Error(`expected report A to build, got: ${reportA.error}`);
+
+ // The reporter opens the dialog again while A's send is still retryable.
+ capture(SCREENSHOT_B);
+ const reportB = await handleBugReportCreate(
+ createDeps('2026-07-15T18-31-00-000Z-bugreport.zip'),
+ { kind: 'create', level: 'standard', includeScreenshot: true },
+ );
+ if (!reportB.ok) throw new Error(`expected report B to build, got: ${reportB.error}`);
+
+ // Each bundle stages its own capture at collect time, so the zips are right
+ // even when the standalone asset is not — that asymmetry is the bug.
+ expect(readZipEntryBytes(reportA.zipPath, 'extra/screenshot.png').equals(SCREENSHOT_A)).toBe(
+ true,
+ );
+ expect(readZipEntryBytes(reportB.zipPath, 'extra/screenshot.png').equals(SCREENSHOT_B)).toBe(
+ true,
+ );
+
+ const result = await handleBugReportSend(
+ {
+ ...makeSendDeps(stub.url, bugReportsRoot),
+ screenshotPngBytes: (reportId) => hold.read(reportId),
+ },
+ {
+ kind: 'send',
+ zipPath: reportA.zipPath,
+ metadata: SEND_METADATA,
+ includeScreenshot: true,
+ },
+ );
+
+ expect(result).toEqual({ ok: true, reference: 'OK-1042' });
+ const imagePut = stub.requests[3];
+ expect(imagePut?.headers['content-type']).toBe('image/png');
+ expect(imagePut?.body.equals(SCREENSHOT_A)).toBe(true);
+ });
+
+ test('create files the capture under the report id, and files nothing without one', async () => {
+ const hold = createBugReportScreenshotHold();
+ const reportsDir = makeTmpDir();
+ // Distinct basenames because the basename IS the report id.
+ const holdDeps = (zipName: string) =>
+ makeDeps({
+ outputPath: join(reportsDir, zipName),
+ screenshotPngBytes: () => SCREENSHOT_A,
+ onScreenshotStaged: (reportId, png) => hold.remember(reportId, png, 7),
+ });
+
+ const withCapture = await handleBugReportCreate(holdDeps('opted-in-bugreport.zip'), {
+ kind: 'create',
+ level: 'standard',
+ includeScreenshot: true,
+ });
+ if (!withCapture.ok) throw new Error(`expected ok, got: ${withCapture.error}`);
+ expect(hold.read(basename(withCapture.zipPath))?.equals(SCREENSHOT_A)).toBe(true);
+
+ // Opting out is indistinguishable at send time from never having captured:
+ // both leave the hold empty, and the ticket files without the inline image.
+ const optedOut = await handleBugReportCreate(holdDeps('opted-out-bugreport.zip'), {
+ kind: 'create',
+ level: 'standard',
+ });
+ if (!optedOut.ok) throw new Error(`expected ok, got: ${optedOut.error}`);
+ expect(hold.read(basename(optedOut.zipPath))).toBeNull();
+ });
+
+ test('a create whose screenshot bookkeeping throws still succeeds, logger included', async () => {
+ // The zip is on disk by this point, so neither a hand-off that throws nor a
+ // logger that throws while reporting it may turn a written report into a
+ // create failure. Same fail-soft posture `recordMinidumpDecision` takes.
+ const result = await handleBugReportCreate(
+ makeDeps({
+ screenshotPngBytes: () => SCREENSHOT_A,
+ onScreenshotStaged: () => {
+ throw new Error('hold refused the capture');
+ },
+ logger: {
+ info: () => {},
+ warn: () => {
+ throw new Error('logger is down');
+ },
+ },
+ }),
+ { kind: 'create', level: 'standard', includeScreenshot: true },
+ );
+
+ if (!result.ok) throw new Error(`expected ok, got: ${result.error}`);
+ expect(existsSync(result.zipPath)).toBe(true);
+ // The bundle still carries its own capture; only the send-time hold was lost.
+ expect(readZipEntryBytes(result.zipPath, 'extra/screenshot.png').equals(SCREENSHOT_A)).toBe(
+ true,
+ );
+ });
+
+ test('an unknown report reads as null rather than as some other report', () => {
+ const hold = createBugReportScreenshotHold();
+ hold.remember('report-a', SCREENSHOT_A, 7);
+
+ expect(hold.read('report-never-created')).toBeNull();
+ hold.forget('report-a');
+ expect(hold.read('report-a')).toBeNull();
+ });
+
+ test('reading is non-destructive, so a failed send leaves the bytes for the retry', () => {
+ // The retry reading its own bytes is the whole point of this change, and a
+ // send reads before it can know it failed. A consume-on-read would leave
+ // every retry imageless while every other test here still passed.
+ const hold = createBugReportScreenshotHold();
+ hold.remember('report-a', SCREENSHOT_A, 7);
+
+ expect(hold.read('report-a')?.equals(SCREENSHOT_A)).toBe(true);
+ expect(hold.read('report-a')?.equals(SCREENSHOT_A)).toBe(true);
+ expect(hold.read('report-a')?.equals(SCREENSHOT_A)).toBe(true);
+ });
+
+ test('the hold evicts oldest-first at the cap, and re-filing refreshes recency', () => {
+ const hold = createBugReportScreenshotHold({ maxReports: 2 });
+ hold.remember('one', Buffer.from([1]), 7);
+ hold.remember('two', Buffer.from([2]), 7);
+ // Re-filing `one` must move it behind `two`, or the freshest report is the
+ // next evicted.
+ hold.remember('one', Buffer.from([1]), 7);
+ hold.remember('three', Buffer.from([3]), 7);
+
+ expect(hold.read('two')).toBeNull();
+ expect(hold.read('one')?.equals(Buffer.from([1]))).toBe(true);
+ expect(hold.read('three')?.equals(Buffer.from([3]))).toBe(true);
+ });
+
+ test('an eviction names the report it dropped, so triage can tell it from a stale retry', () => {
+ // Send logs an unavailable capture identically whether it was evicted here or
+ // never existed, so the eviction is the only place the difference is knowable.
+ const evicted: string[] = [];
+ const hold = createBugReportScreenshotHold({
+ maxReports: 1,
+ onEvict: (reportId) => evicted.push(reportId),
+ });
+
+ hold.remember('first', Buffer.from([1]), 7);
+ hold.remember('second', Buffer.from([2]), 7);
+
+ expect(evicted).toEqual(['first']);
+ // A report dropped explicitly is not an eviction — nothing was over cap.
+ hold.forget('second');
+ expect(evicted).toEqual(['first']);
+ });
+
+ test('losing a window drops every report it composed and nothing another window did', () => {
+ // The send toast that can retry a report lives in the composing window's
+ // renderer, so once that window's contents are gone its captures are
+ // unreachable and must not wait for the cap to evict them.
+ const hold = createBugReportScreenshotHold();
+ hold.remember('from-window-7-a', Buffer.from([1]), 7);
+ hold.remember('from-window-7-b', Buffer.from([2]), 7);
+ hold.remember('from-window-9', Buffer.from([3]), 9);
+
+ hold.forgetOwner(7);
+
+ expect(hold.read('from-window-7-a')).toBeNull();
+ expect(hold.read('from-window-7-b')).toBeNull();
+ expect(hold.read('from-window-9')?.equals(Buffer.from([3]))).toBe(true);
+ });
+});
+
describe('handleBugReportSend — upload happy path', () => {
test('runs mint, direct PUT with verbatim signed headers, and completion, returning the reference', async () => {
const stub = await startIntakeStub();
diff --git a/packages/desktop/src/main/ipc/bug-report.ts b/packages/desktop/src/main/ipc/bug-report.ts
index d149d1651..fbdba078e 100644
--- a/packages/desktop/src/main/ipc/bug-report.ts
+++ b/packages/desktop/src/main/ipc/bug-report.ts
@@ -192,6 +192,15 @@ export interface BugReportCreateDeps {
* outcome — the zip is already on disk.
*/
onReportGenerated?: (meta: GeneratedReportMeta) => Promise<void>;
+ /**
+ * Bind the staged screenshot bytes to the report that was just written, keyed
+ * by the same `basename(zipPath)` report id `send` and the sidecar use. Called
+ * only when a capture actually reached this bundle, so what `send` later
+ * resolves is the picture this report was composed from — not whatever the
+ * sender window's capture slot happens to hold by then. Absent simply means
+ * the standalone asset upload has nothing to resolve.
+ */
+ onScreenshotStaged?: (reportId: string, png: Buffer) => void;
}
/**
@@ -446,6 +455,21 @@ export async function handleBugReportCreate(
readLanguage: deps.readLanguage,
});
const { size: zipSizeBytes } = await stat(zipPath);
+ if (screenshotBytes !== null) {
+ // The report has an id for the first time here, so this is the earliest
+ // point the capture can be filed under it. Guarded for the same reason
+ // the sidecar write below is: the zip is already on disk, and a
+ // bookkeeping fault must not turn a written report into a create failure.
+ try {
+ deps.onScreenshotStaged?.(basename(zipPath), screenshotBytes);
+ } catch (err) {
+ try {
+ deps.logger?.warn({ zipPath, err }, 'bug-report: failed to retain screenshot for send');
+ } catch {
+ // The logger is the thing that failed; there is nowhere left to report it.
+ }
+ }
+ }
// Persist the durable `generated` record next to the zip. A failure here
// must never lose the report (the zip is written) — the writer is fail-soft
// and the call is guarded, so create still succeeds if the sidecar can't be
@@ -595,6 +619,99 @@ export async function handleBugReportCaptureScreenshot(
}
}
+/**
+ * Ceiling on reports whose screenshot is held for a later send. Each entry is a
+ * full-resolution PNG of one screen (~1 MB), so a small cap keeps the ceiling in
+ * single-digit megabytes while still covering the case this store exists for: a
+ * handful of reports composed in one sitting, each retryable on its own. Bounding
+ * by report count rather than by window lifetime is the point — the window slot
+ * cannot tell two reports apart.
+ *
+ * Deliberately smaller than `MAX_UNSENT_REPORT_COUNT`: the retry list keeps more
+ * bundles on disk than this keeps pictures in memory, so a report far enough down
+ * that list files without its inline image. Bundles are the report; the inline
+ * image is a nicety, and megabytes of screen captures are the wrong thing to hold
+ * in main to serve it. An eviction is logged so triage can tell that case apart
+ * from a capture that never existed.
+ */
+const MAX_PENDING_REPORT_SCREENSHOTS = 4;
+
+/**
+ * Report-keyed hold for the standalone screenshot upload, filled by `create` and
+ * read by `send`.
+ *
+ * `create` stages its capture into the bundle synchronously, so a zip is always
+ * self-consistent. The Linear asset is a separate client upload the intake cannot
+ * derive from the bundle, and it is resolved when the user sends — which, since
+ * sends became backgrounded and retryable, can be long after a second report was
+ * composed from the same window. Keying on the report rather than the window is
+ * what makes a retry resolve its own bytes.
+ *
+ * Eviction is oldest-first and costs the evicted report only its inline image;
+ * a report with nothing held files without one, which is the same safe shape as
+ * a capture that never happened. The cap is a backstop, not the lifetime: every
+ * entry is filed under an owner so the caller can release a whole group at once
+ * (desktop main passes the composing window, whose renderer holds the only
+ * surface that can ask for these bytes).
+ */
+export interface BugReportScreenshotHold {
+ /**
+ * File a report's staged capture under its id, evicting the oldest over cap.
+ * `owner` is an opaque grouping key for `forgetOwner`.
+ */
+ remember(reportId: string, png: Buffer, owner: number): void;
+ /** Non-destructive — a failed send must leave the bytes for the retry. */
+ read(reportId: string): Buffer | null;
+ /** Drop a report's capture once no send can want it again. */
+ forget(reportId: string): void;
+ /** Drop every capture filed by one owner, for when that owner goes away. */
+ forgetOwner(owner: number): void;
+}
+
+export interface BugReportScreenshotHoldOptions {
+ maxReports?: number;
+ /**
+ * Called with a report id dropped to stay under the cap. Send logs an
+ * unavailable capture the same way whether it was evicted here or never
+ * existed (a retry in a later session), so without this the two are one
+ * indistinguishable line in a diagnostic bundle.
+ */
+ onEvict?: (reportId: string) => void;
+}
+
+export function createBugReportScreenshotHold(
+ options: BugReportScreenshotHoldOptions = {},
+): BugReportScreenshotHold {
+ const maxReports = options.maxReports ?? MAX_PENDING_REPORT_SCREENSHOTS;
+ const byReport = new Map<string, { png: Buffer; owner: number }>();
+ return {
+ remember(reportId, png, owner) {
+ // Delete-then-set so a re-created report moves to the back of the queue;
+ // Map preserves first-insertion order otherwise, which would make the
+ // freshest report the next one evicted.
+ byReport.delete(reportId);
+ byReport.set(reportId, { png, owner });
+ while (byReport.size > maxReports) {
+ const oldest = byReport.keys().next();
+ if (oldest.done === true) break;
+ byReport.delete(oldest.value);
+ options.onEvict?.(oldest.value);
+ }
+ },
+ read(reportId) {
+ return byReport.get(reportId)?.png ?? null;
+ },
+ forget(reportId) {
+ byReport.delete(reportId);
+ },
+ forgetOwner(owner) {
+ for (const [reportId, entry] of byReport) {
+ if (entry.owner === owner) byReport.delete(reportId);
+ }
+ },
+ };
+}
+
const SUPPORT_EMAIL = '[email protected]';
/**
@@ -656,13 +773,16 @@ export interface BugReportSendDeps {
*/
sidecar?: BugReportSendSidecarHooks;
/**
- * Main-owned PNG bytes of the screenshot captured when the report dialog
- * opened, uploaded as its own Linear asset so the ticket embeds it inline.
- * Returns null when nothing was captured, when the reporter opted out, or on a
- * list retry in a later session. Absent (or null) simply means the ticket files
- * without the inline image.
+ * Main-owned PNG bytes of the screenshot THIS report was composed from,
+ * uploaded as its own Linear asset so the ticket embeds it inline. Resolved by
+ * report id, never by sender window: a window's capture slot belongs to
+ * whichever dialog opened last, so a report retried after a second one was
+ * composed would otherwise attach the second report's picture. Returns null
+ * when nothing was captured, when the reporter opted out, or on a retry in a
+ * later session; absent (or null) simply means the ticket files without the
+ * inline image.
*/
- screenshotPngBytes?: () => Buffer | null;
+ screenshotPngBytes?: (reportId: string) => Buffer | null;
}
/**
@@ -1449,13 +1569,13 @@ export async function handleBugReportSend(
return { ok: false, reason: 'send-in-flight', fallback };
}
}
- // Consent gate first, bytes second. main holds the capture for this window
- // regardless of what the reporter chose, so reading it without checking
- // `includeScreenshot` would upload a screenshot the reporter declined. The flag
- // reflects the bundle's own inventory, so it is the same decision the reporter
- // reviewed. Absent (a list retry, or an older renderer) means no upload.
+ // Consent gate first, bytes second. main holds this report's capture whatever
+ // the reporter chose, so reading it without checking `includeScreenshot` would
+ // upload a screenshot the reporter declined. The flag reflects the bundle's own
+ // inventory, so it is the same decision the reporter reviewed. Absent (a list
+ // retry, or an older renderer) means no upload.
const screenshotBytes =
- request.includeScreenshot === true ? (deps.screenshotPngBytes?.() ?? null) : null;
+ request.includeScreenshot === true ? (deps.screenshotPngBytes?.(reportId) ?? null) : null;
if (request.includeScreenshot === true && screenshotBytes === null) {
// Consent was given and the capture is gone — a list retry in a later session
// is the ordinary cause. Distinct from consent being withheld, and traced for