Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions packages/navie/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum CommandMode {
Suggest = 'suggest',
Observe = 'observe',
Review = 'review',
Diff = 'diff',
Welcome = 'welcome',
}

Expand Down
47 changes: 47 additions & 0 deletions packages/navie/src/commands/diff-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import Command, { CommandRequest } from '../command';
import { ProjectInfo } from '../project-info';
import ProjectInfoService from '../services/project-info-service';

// Define output formats: text, json, jsonl
export type DiffOutputFormat = 'text' | 'json' | 'jsonl';

export interface ProjectDiffInfo {
directory: string;
diff?: string;
}

// Transform ProjectInfo to ProjectDiffInfo
export function projectInfoToProjectDiffInfo(projectInfo: ProjectInfo): ProjectDiffInfo {
return {
directory: projectInfo.directory,
diff: projectInfo.diff,
};
}

export default class DiffCommand implements Command {
constructor(private readonly projectInfoService: ProjectInfoService) {}

async *execute(request: CommandRequest): AsyncIterable<string> {
const outputFormat = request.userOptions.stringValue('format') || 'text';
const baseBranch = request.userOptions.stringValue('base');

const projectInfoResponse = await this.projectInfoService.lookupProjectInfo(true, baseBranch);
const projectInfo = Array.isArray(projectInfoResponse)
? projectInfoResponse
: [projectInfoResponse];

if (outputFormat === 'text') {
for (const info of projectInfo) {
yield `Changes in ${info.directory}:\n`;
yield info.diff || 'No changes detected.';
yield '\n';
}
} else if (outputFormat === 'json') {
yield JSON.stringify(projectInfo.map(projectInfoToProjectDiffInfo), null, 2);
} else if (outputFormat === 'jsonl') {
for (const info of projectInfo) {
yield JSON.stringify(projectInfoToProjectDiffInfo(info)) + '\n';
}
}
}
}
7 changes: 7 additions & 0 deletions packages/navie/src/navie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import ReviewCommand from './commands/review-command';
import WelcomeCommand from './commands/welcome-command';
import InvokeTestsService from './services/invoke-tests-service';
import { TestInvocationProvider } from './test-invocation';
import DiffCommand from './commands/diff-command';

export type ChatHistory = Message[];

Expand Down Expand Up @@ -194,6 +195,11 @@ export default function navie(
interactionHistory,
projectInfoService
);

const buildDiffCommand = () =>
new DiffCommand(
projectInfoService
)
Copy link

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Add a semicolon after the buildDiffCommand arrow function definition to stay consistent with the project’s coding style.

Suggested change
)
);

Copilot uses AI. Check for mistakes.

const buildReviewCommand = () =>
new ReviewCommand(
Expand All @@ -217,6 +223,7 @@ export default function navie(
[CommandMode.Suggest]: buildSuggestCommand,
[CommandMode.Observe]: buildObserveCommand,
[CommandMode.Review]: buildReviewCommand,
[CommandMode.Diff]: buildDiffCommand,
[CommandMode.Welcome]: buildWelcomeCommand,
};

Expand Down
Loading