HamzaHassanain/polyman

Add Diff Viewer for Local vs Remote Changes

Open

#10 opened on Nov 24, 2025

 (0 comments) (0 reactions) (0 assignees)TypeScript (2 forks)auto 404
enhancementgood first issuehelp wanted

Repository metrics

Stars
 (33 stars)
PR merge metrics
 (PR metrics pending)

Description

Implement a diff viewer that shows differences between the local problem state and the remote Polygon state before pushing/pulling. This helps users understand what will change and prevents accidental overwrites during collaboration.

Problem

Currently, when working with remote operations:

No visibility into what changed on Polygon since the last pull No preview of what will be uploaded during push Risk of accidentally overwriting teammate's changes Hard to debug sync issues

Proposed Commands

  1. Show Remote Changes:
polyman remote diff ./my-problem
polyman remote diff ./my-problem --component solutions

Output:

Comparing local problem with Polygon (ID: 123456)
Last synced: 2 hours ago

Solutions:
  Modified: main.cpp (local: 2024-11-24 10:30, remote: 2024-11-24 12:15)
    + Added optimization on line 23
    - Removed debug print on line 45
  
  Added locally: wa-solution.cpp
  
  Deleted remotely: old-solution.cpp

Checker:
  No changes

Validator:
  Modified: val.cpp (local newer)
    + Added constraint check on line 67

Tests:
  Added remotely: test15.txt, test16.txt
  Modified locally: test3.txt

Statements:
  Modified remotely: english/legend.tex

2. Display Diff:

import chalk from 'chalk';
import Table from 'cli-table3';

function displayDiff(diffs: DiffResult[]) {
  const table = new Table({
    head: ['Component', 'File', 'Status', 'Local', 'Remote'],
    colWidths: [15, 30, 12, 20, 20]
  });
  
  for (const diff of diffs) {
    const statusColor = {
      'added': chalk.green,
      'deleted': chalk.red,
      'modified': chalk.yellow,
      'unchanged': chalk.gray
    }[diff.status];
    
    table.push([
      diff.component,
      diff.localFile || diff.remoteFile,
      statusColor(diff.status),
      diff.localTimestamp?.toLocaleString() || '-',
      diff.remoteTimestamp?.toLocaleString() || '-'
    ]);
  }
  
  console.log(table.toString());
}

4. File Content Diff:

import { diffLines } from 'diff';
import chalk from 'chalk';

async function showFileDiff(localFile: string, remoteContent: string) {
  const localContent = await fs.readFile(localFile, 'utf-8');
  const diff = diffLines(localContent, remoteContent);
  
  for (const part of diff) {
    const color = part.added ? chalk.green : part.removed ? chalk.red : chalk.gray;
    const prefix = part.added ? '+ ' : part.removed ? '- ' : '  ';
    
    for (const line of part.value.split('\n')) {
      console.log(color(prefix + line));
    }
  }
}

Integration with Existing Commands Automatic diff before destructive operations:

Status command (like git status):

Success Criteria

  • polyman remote diff shows local vs remote differences

  • Side-by-side file diff with syntax highlighting

  • Detects conflicts (both modified since last sync)

  • --dry-run flag for push/pull operations

  • Auto-diff before push with confirmation prompt

  • Works without network (uses cached sync state)

  • Clear visual indicators (colors, symbols)

  • Export diff to file (--output diff.txt)

  • Edge Cases

  • No .polyman/sync-state.json (never synced before)

  • Network failure during remote state fetch

  • Problem doesn't exist on remote

  • Local Config.json missing problemId

Contributor guide