Repository: microsoft/playwright
File: packages/playwright/src/mcp/browser/response.ts (TypeScript)

Code before:
    // Handle modal states.
    if (tabSnapshot?.modalStates.length)
      addSection('Modal state', renderModalStates(this._context.config, tabSnapshot.modalStates));

    // Handle tab snapshot
    if (tabSnapshot && this._includeSnapshot !== 'none') {
      const snapshot = this._includeSnapshot === 'full' ? tabSnapshot.ariaSnapshot : tabSnapshot.ariaSnapshotDiff ?? tabSnapshot.ariaSnapshot;
      if (this._context.config.outputMode === 'file' || this._includeSnapshotFileName) {
        const resolvedFile = await this.resolveFile({ prefix: 'page', ext: 'yml', suggestedFilename: this._includeSnapshotFileName }, 'Snapshot');
        await fs.promises.writeFile(resolvedFile.fileName, snapshot, 'utf-8');
        addSection('Snapshot', [resolvedFile.printableLink]);
      } else {
        addSection('Snapshot', [snapshot], 'yaml');
      }
    }

    // Handle tab log
    if (tabSnapshot?.events.filter(event => event.type !== 'request').length) {
      const text: string[] = [];
      if (tabSnapshot.consoleLog) {
        const logFilePath = this._computRelativeTo(tabSnapshot.consoleLog.file);
        const entryWord = tabSnapshot.consoleLog.newEntryCount === 1 ? 'entry' : 'entries';
        const lineRange = tabSnapshot.consoleLog.firstNewLine === tabSnapshot.consoleLog.lastNewLine
            ? `line ${tabSnapshot.consoleLog.firstNewLine}`
            : `lines ${tabSnapshot.consoleLog.firstNewLine}-${tabSnapshot.consoleLog.lastNewLine}`;
        text.push(`- ${tabSnapshot.consoleLog.newEntryCount} new console ${entryWord} in ${logFilePath}, ${lineRange}`);
      }
      for (const event of tabSnapshot.events) {
        if (event.type === 'console' && !tabSnapshot.consoleLog) {
          if (shouldIncludeMessage(this._context.config.console.level, event.message.type))
            text.push(`- ${trimMiddle(event.message.toString(), 100)}`);
        } else if (event.type === 'download-start') {

          text.push(`- Downloading file ${event.download.download.suggestedFilename()} ...`);
        } else if (event.type === 'download-finish') {
          text.push(`- Downloaded file ${event.download.download.suggestedFilename()} to "${this._computRelativeTo(event.download.outputFile)}"`);
        }
      }
      addSection('Events', text);
    }
    return sections;
  }
}

export function renderTabMarkdown(tab: TabHeader): string[] {
  const lines = [`- Page URL: ${tab.url}`];
  if (tab.title)
    lines.push(`- Page Title: ${tab.title}`);
  return lines;
}


Review comment (suggestion):
quote the file name, use github notation `foo.log#L10-L20`

Code after:
    // Handle modal states.
    if (tabSnapshot?.modalStates.length)
      addSection('Modal state', renderModalStates(this._context.config, tabSnapshot.modalStates));

    // Handle tab snapshot
    if (tabSnapshot && this._includeSnapshot !== 'none') {
      const snapshot = this._includeSnapshot === 'full' ? tabSnapshot.ariaSnapshot : tabSnapshot.ariaSnapshotDiff ?? tabSnapshot.ariaSnapshot;
      if (this._context.config.outputMode === 'file' || this._includeSnapshotFileName) {
        const resolvedFile = await this.resolveFile({ prefix: 'page', ext: 'yml', suggestedFilename: this._includeSnapshotFileName }, 'Snapshot');
        await fs.promises.writeFile(resolvedFile.fileName, snapshot, 'utf-8');
        addSection('Snapshot', [resolvedFile.printableLink]);
      } else {
        addSection('Snapshot', [snapshot], 'yaml');
      }
    }

    // Handle tab log
    const text: string[] = renderLogChunk(tabSnapshot?.logChunk, 'console', file => this._computRelativeTo(file));
    if (tabSnapshot?.events.filter(event => event.type !== 'request').length) {
      for (const event of tabSnapshot.events) {
        if (event.type === 'console' && !tabSnapshot.logChunk) {
          if (shouldIncludeMessage(this._context.config.console.level, event.message.type))
            text.push(`- ${trimMiddle(event.message.toString(), 100)}`);
        } else if (event.type === 'download-start') {

          text.push(`- Downloading file ${event.download.download.suggestedFilename()} ...`);
        } else if (event.type === 'download-finish') {
          text.push(`- Downloaded file ${event.download.download.suggestedFilename()} to "${this._computRelativeTo(event.download.outputFile)}"`);
        }
      }
    }
    addSection('Events', text);
    return sections;
  }
}

export function renderTabMarkdown(tab: TabHeader): string[] {
  const lines = [`- Page URL: ${tab.url}`];
  if (tab.title)
    lines.push(`- Page Title: ${tab.title}`);
  return lines;
}

export function renderTabsMarkdown(tabs: TabHeader[]): string[] {
  if (!tabs.length)
    return ['No open tabs. Navigate to a URL to create one.'];

  const lines: string[] = [];
  for (let i = 0; i < tabs.length; i++) {
    const tab = tabs[i];
    const current = tab.current ? ' (current)' : '';