HamzaHassanain / HamzaHassanain/polyman
Add Diff Viewer for Local vs Remote Changes
- Dominant language
- TypeScript
- Stars
- 35
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
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:
```bash
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:**
```ts
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:**
```ts
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
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.