Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Command } from 'commander';
import { createHash } from 'node:crypto';
import { existsSync, statSync } from 'node:fs';
import { resolve } from 'node:path';
import { createRequire } from 'node:module';
import open from 'open';
import pc from 'picocolors';
Expand Down Expand Up @@ -31,13 +33,35 @@ const pkg = require('../package.json');

const program = new Command();

// Project directories often hold several worktrees as subdirectories, so the repository to
// review is not always the directory the command was run from. Everything downstream resolves
// against the working directory, so switching it here is enough.
function applyRepoOption(repo: unknown): void {
if (typeof repo !== 'string' || !repo) {
return;
}

const target = resolve(repo);
if (!existsSync(target) || !statSync(target).isDirectory()) {
console.error(pc.red(`Error: --repo is not a directory: ${repo}`));
process.exit(1);
}

process.chdir(target);
}

program.hook('preAction', (thisCommand) => {
applyRepoOption(thisCommand.opts().repo);
});

program
.name('diffity')
.description('GitHub-style git diff viewer in the browser')
.version(pkg.version)
.enablePositionalOptions()
.passThroughOptions()
.option('--skills-hash', 'Print skills hash and exit', false)
.option('--repo <path>', 'Repository to work on, when the current directory is not one')
.argument('[refs...]', 'Git refs to diff')
.option('--base <ref>', 'Base ref to compare from (e.g. main, HEAD~3, v1.0.0)')
.option('--compare <ref>', 'Ref to compare against base (default: working tree)')
Expand Down
10 changes: 9 additions & 1 deletion packages/skills/diffity-resolve/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ You are reading open review comments and resolving them by making the requested
## Prerequisites

1. Check that `{{binary}}` is available: run `which {{binary}}`. If not found, {{install_hint}}.
2. Check that a review session exists: run `{{binary}} agent list`. If this fails with "No active review session", tell the user to start diffity first (e.g. `{{binary}}` or **{{slash}}diff**).
2. **Work out which repository to use.** A project directory often holds several worktrees as
subdirectories rather than being a repository itself, so the current directory may not be one.
- If the current directory is a git repository (`git rev-parse --show-toplevel` succeeds), use it.
- Otherwise look one level down for directories containing a `.git` entry. Exactly one → use it.
Several → **ask the user which one**, listing them with their current branch, and stop until
they answer. Guessing here reviews the wrong branch, which wastes the whole review.
- Pass the chosen directory to every `{{binary}}` call as `--repo <path>`, before any positional
argument. Do not `cd`.
3. Check that a review session exists: run `{{binary}} agent list`. If this fails with "No active review session", tell the user to start diffity first (e.g. `{{binary}}` or **{{slash}}diff**).

## Instructions

Expand Down
31 changes: 30 additions & 1 deletion packages/skills/diffity-review/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ You are reviewing a diff and leaving inline comments using the `{{binary}} agent

## Arguments

- `ref` (optional): Git ref to review (e.g. `main..feature`, `HEAD~3`). Defaults to working tree changes. When both `ref` and `focus` are provided, use both (e.g. `/diffity-review main..feature security`).
- `ref` (optional): Git ref to review (e.g. `main..feature`, `HEAD~3`). When both `ref` and `focus` are provided, use both (e.g. `/diffity-review main..feature security`).
With no `ref`, review **the pull request for the current branch** if there is one, and the working
tree otherwise — see Step 0. "Review my draft PR" with everything committed means the pull
request, not the empty set of uncommitted changes.
- `focus` (optional): Focus the review on a specific area. One of: `security`, `performance`, `naming`, `errors`, `types`, `logic`. If omitted, review everything.

## CLI Reference
Expand Down Expand Up @@ -38,9 +41,35 @@ You are reviewing a diff and leaving inline comments using the `{{binary}} agent
## Prerequisites

1. Check that `{{binary}}` is available: run `which {{binary}}`. If not found, {{install_hint}}.
2. **Work out which repository to use.** A project directory often holds several worktrees as
subdirectories rather than being a repository itself, so the current directory may not be one.
- If the current directory is a git repository (`git rev-parse --show-toplevel` succeeds), use it.
- Otherwise look one level down for directories containing a `.git` entry. Exactly one → use it.
Several → **ask the user which one**, listing them with their current branch, and stop until
they answer. Guessing here reviews the wrong branch, which wastes the whole review.
- Pass the chosen directory to every `{{binary}}` call as `--repo <path>`, before any positional
argument. Do not `cd`.


## Instructions

### Step 0: Decide what to review

Only when no `ref` argument was given:

1. Ask GitHub whether the current branch has a pull request:
```
gh pr view --json number,url,isDraft,baseRefName
```
2. If it returns one, **review the pull request**: use its URL as the ref
(`{{binary}} --repo <path> --no-open <pr-url>`). diffity pins the diff to the pull request's base
commit, so it matches what GitHub shows — a plain working-tree diff on a branch whose work is
committed would be empty. A draft counts; that is the usual case for a review before marking it
Ready.
3. If there is no pull request, or `gh` is unavailable, review the working tree as before.

State which one you chose in your first message, so the user can correct you cheaply.

### Step 1: Ensure diffity is running for the correct ref (without opening browser)

The review needs a running session whose ref matches the requested ref. A ref mismatch causes "file not in current diff" errors when adding comments.
Expand Down
10 changes: 9 additions & 1 deletion skills/diffity-resolve/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ diffity agent reply <id> --body "<text>"
## Prerequisites

1. Check that `diffity` is available: run `which diffity`. If not found, install it with `npm install -g diffity`.
2. Check that a review session exists: run `diffity agent list`. If this fails with "No active review session", tell the user to start diffity first (e.g. `diffity` or **/diffity-diff**).
2. **Work out which repository to use.** A project directory often holds several worktrees as
subdirectories rather than being a repository itself, so the current directory may not be one.
- If the current directory is a git repository (`git rev-parse --show-toplevel` succeeds), use it.
- Otherwise look one level down for directories containing a `.git` entry. Exactly one → use it.
Several → **ask the user which one**, listing them with their current branch, and stop until
they answer. Guessing here reviews the wrong branch, which wastes the whole review.
- Pass the chosen directory to every `diffity` call as `--repo <path>`, before any positional
argument. Do not `cd`.
3. Check that a review session exists: run `diffity agent list`. If this fails with "No active review session", tell the user to start diffity first (e.g. `diffity` or **/diffity-diff**).

## Instructions

Expand Down
31 changes: 30 additions & 1 deletion skills/diffity-review/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ You are reviewing a diff and leaving inline comments using the `diffity agent` C

## Arguments

- `ref` (optional): Git ref to review (e.g. `main..feature`, `HEAD~3`). Defaults to working tree changes. When both `ref` and `focus` are provided, use both (e.g. `/diffity-review main..feature security`).
- `ref` (optional): Git ref to review (e.g. `main..feature`, `HEAD~3`). When both `ref` and `focus` are provided, use both (e.g. `/diffity-review main..feature security`).
With no `ref`, review **the pull request for the current branch** if there is one, and the working
tree otherwise — see Step 0. "Review my draft PR" with everything committed means the pull
request, not the empty set of uncommitted changes.
- `focus` (optional): Focus the review on a specific area. One of: `security`, `performance`, `naming`, `errors`, `types`, `logic`. If omitted, review everything.

## CLI Reference
Expand Down Expand Up @@ -38,9 +41,35 @@ diffity agent tour-done --tour <id>
## Prerequisites

1. Check that `diffity` is available: run `which diffity`. If not found, install it with `npm install -g diffity`.
2. **Work out which repository to use.** A project directory often holds several worktrees as
subdirectories rather than being a repository itself, so the current directory may not be one.
- If the current directory is a git repository (`git rev-parse --show-toplevel` succeeds), use it.
- Otherwise look one level down for directories containing a `.git` entry. Exactly one → use it.
Several → **ask the user which one**, listing them with their current branch, and stop until
they answer. Guessing here reviews the wrong branch, which wastes the whole review.
- Pass the chosen directory to every `diffity` call as `--repo <path>`, before any positional
argument. Do not `cd`.


## Instructions

### Step 0: Decide what to review

Only when no `ref` argument was given:

1. Ask GitHub whether the current branch has a pull request:
```
gh pr view --json number,url,isDraft,baseRefName
```
2. If it returns one, **review the pull request**: use its URL as the ref
(`diffity --repo <path> --no-open <pr-url>`). diffity pins the diff to the pull request's base
commit, so it matches what GitHub shows — a plain working-tree diff on a branch whose work is
committed would be empty. A draft counts; that is the usual case for a review before marking it
Ready.
3. If there is no pull request, or `gh` is unavailable, review the working tree as before.

State which one you chose in your first message, so the user can correct you cheaply.

### Step 1: Ensure diffity is running for the correct ref (without opening browser)

The review needs a running session whose ref matches the requested ref. A ref mismatch causes "file not in current diff" errors when adding comments.
Expand Down