Skip to content
Open
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
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';
}
}
}
}
4 changes: 4 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 @@ -195,6 +196,8 @@ export default function navie(
projectInfoService
);

const buildDiffCommand = () => new DiffCommand(projectInfoService);

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

Expand Down
Loading