Skip to content

Commit

Permalink
Merge pull request #60 from CommandDash/rel-0.0.6
Browse files Browse the repository at this point in the history
Rel 0.0.6
  • Loading branch information
samyakkkk authored May 6, 2024
2 parents 570f1eb + a5d0780 commit 175a1b9
Show file tree
Hide file tree
Showing 36 changed files with 795 additions and 170 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/executables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
run: |
chmod +x ./executable/commanddash-linux
echo "Version: $(./executable/commanddash-linux version)"
echo "Minimum client version: $(./executable/commanddash-linux min_cli_version)"
echo "Minimum client version: $(./executable/commanddash-linux min_client_version)"
curl -X POST "https://api.commanddash.dev/executable/add" \
-H "Content-Type: multipart/form-data" \
-F "secret=${{ secrets.SECRET_KEY }}" \
Expand Down
2 changes: 1 addition & 1 deletion commanddash/bin/commanddash.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ void main(List<String> arguments) async {
var runner = CommandRunner("commanddash", "CLI enhancements for Dash AI")
..addCommand(ProcessCommand())
..addCommand(VersionCommand())
..addCommand(MinCLIVersionCommand());
..addCommand(MinimumClientVersionCommand());
await runner.run(arguments);
}
105 changes: 50 additions & 55 deletions commanddash/lib/agent/input_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';

import 'package:commanddash/models/chat_message.dart';
import 'package:commanddash/models/workspace_file.dart';
import 'package:commanddash/server/server.dart';

abstract class Input {
String id;
Expand All @@ -15,7 +16,7 @@ abstract class Input {
if (type == "string_input") {
return StringInput.fromJson(json);
} else if (type == "code_input") {
return CodeInput.fromJson(json);
return BaseCodeInput.fromJson(json);
} else if (type == "chat_query_input") {
return ChatQueryInput.fromJson(json);
} else {
Expand Down Expand Up @@ -47,86 +48,80 @@ class StringInput extends Input {
}
}

class CodeInput extends Input {
String? filePath;
Range? range;
bool generateFullString;
String? content;
String? fileContent;

CodeInput({
required String id,
this.filePath,
this.range,
this.content,
this.generateFullString = false,
this.fileContent,
}) : super(id, 'code_input');

factory CodeInput.fromJson(Map<String, dynamic> json) {
class BaseCodeInput extends Input {
BaseCodeInput(String id) : super(id, 'code_input');

factory BaseCodeInput.fromJson(Map<String, dynamic> json) {
sendDebugMessage(json);
if (json['value'] == null) {
return CodeInput(
return EmptyCodeInput(
id: json['id'],
);
}
final value = jsonDecode(json['value']);
return CodeInput(
id: json['id'],
filePath: value['filePath'],
range: Range.fromJson(value['referenceData']['selection']),
content: value['referenceContent'],
generateFullString: json['generate_full_string'] ?? false,
fileContent: File(value['filePath']).readAsStringSync(),
);
id: json['id'],
filePath: value['filePath'],
range: Range.fromJson(value['referenceData']['selection']),
content: value['referenceContent'],
fileContent: File(value['filePath']).readAsStringSync(),
generateFullString: json['generate_full_string'] ?? false,
includeContextualCode: json['include_contextual_code'] ?? true);
}
}

// Generates the full string which includes the cursor selection.
// Has all the content of the file with the selected range highlighted with <CURSOR_SELECTION> tag.
String getCodeWithCursorSelection() {
if (range == null) {
return 'NA';
}
final startOffet = getOffset(range!.start.line, range!.start.character);
final endOffset = getOffset(range!.end.line, range!.end.character);
return '${fileContent!.substring(0, startOffet)}<CURSOR_SELECTION>${fileContent!.substring(startOffet, endOffset)}</CURSOR_SELECTION>${fileContent!.substring(endOffset)}';
class EmptyCodeInput extends BaseCodeInput {
EmptyCodeInput({required String id}) : super(id);
@override
String toString() {
return "N/A";
}
}

/// Generates the full string with [newContent].
String getFileCodeWithReplacedCode(String newContent) {
if (range == null) {
throw Exception("Code input value is required for replacing in file");
}
final startOffet = getOffset(range!.start.line, range!.start.character);
final endOffset = getOffset(range!.end.line, range!.end.character);
return '${fileContent!.substring(0, startOffet)}$newContent${fileContent!.substring(endOffset)}';
}
class CodeInput extends BaseCodeInput {
String filePath;
Range range;
String content;
String fileContent;
final bool includeContextualCode;
final bool generateFullString;

CodeInput(
{required String id,
required this.filePath,
required this.range,
required this.content,
required this.fileContent,
this.includeContextualCode = true,
this.generateFullString = false})
: super(id);

@override
String toString() {
if (content == null) {
return 'NA';
}
return 'filepath:$filePath\n\n$content';
}

int getOffset(int line, int character) {
return fileContent.split('\n').take(line).join('\n').length + character;
}

String getFileCodeWithReplacedCode(String newContent) {
final startOffet = getOffset(range.start.line, range.start.character);
final endOffset = getOffset(range.end.line, range.end.character);
return '${fileContent.substring(0, startOffet)}$newContent${fileContent.substring(endOffset)}';
}

Map<String, dynamic> getReplaceFileJson(String newContent) {
if (range == null) {
throw Exception("Code input value is required for replacing in file");
}
if (generateFullString) {
newContent = getFileCodeWithReplacedCode(newContent);
}
return {
"path": filePath,
"optimizedCode": newContent,
"originalCode": fileContent,
"selection": range?.toJson(),
"selection": range.toJson(),
};
}

int getOffset(int line, int character) {
return fileContent!.split('\n').take(line).join('\n').length + character;
}
}

class ChatQueryInput extends Input {
Expand Down
3 changes: 1 addition & 2 deletions commanddash/lib/agent/loader_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class ProcessingFilesLoader extends Loader {
@override
Map<String, dynamic> toJson() => {
'kind': 'processingFiles',
'files': files,
if (message != null) 'message': message,
'message': {if (message != null) 'value': message, 'files': files}
};
}
35 changes: 21 additions & 14 deletions commanddash/lib/agent/output_model.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import 'dart:io';

import 'package:commanddash/models/data_source.dart';
import 'package:commanddash/models/workspace_file.dart';
import 'package:commanddash/steps/steps_utils.dart';

abstract class Output {
OutputType type;
Output(this.type);
Output(this.type, [this.maxCharsInPrompt]);
double? maxCharsInPrompt;

factory Output.fromJson(Map<String, dynamic> json) {
final type = json['type'];
Expand Down Expand Up @@ -40,7 +39,7 @@ abstract class Output {

class MultiCodeOutput extends Output {
List<WorkspaceFile>? value;
MultiCodeOutput([this.value]) : super(OutputType.multiCodeOutput);
MultiCodeOutput([this.value]) : super(OutputType.multiCodeOutput, 6000 * 2.7);

@override
String toString() {
Expand All @@ -49,14 +48,10 @@ class MultiCodeOutput extends Output {
return code;
} else {
for (WorkspaceFile file in value!) {
if (code.length > 18000) {
break; //maximum char limit ?? TODO: Replace this later with a holistic counting mechanism
}
code += 'File: ${file.path}\n';
if (file.content == null) {
code += File(file.path).readAsStringSync();
String newContent = 'File: ${file.path}\n${file.fileContent}';
if ((newContent.length + code.length) <= maxCharsInPrompt!) {
code += newContent;
}
code += file.content!;
}
}
return code;
Expand All @@ -77,7 +72,10 @@ class MultiCodeOutput extends Output {

class DefaultOutput extends Output {
String? value;
DefaultOutput([this.value]) : super(OutputType.defaultOutput);
DefaultOutput([this.value])
: super(
OutputType.defaultOutput,
);

@override
String toString() {
Expand Down Expand Up @@ -105,17 +103,26 @@ class ContinueToNextStepOutput extends Output {

class DataSourceResultOutput extends Output {
List<DataSource>? value;
// TODO: limit for each output

DataSourceResultOutput([this.value]) : super(OutputType.dataSourceOuput);
DataSourceResultOutput([this.value])
: super(OutputType.dataSourceOuput, 6000 * 2.7);

@override
String toString() {
if (value == null) {
throw Exception("DataSource value not assigned");
}
// do not add if limit is reched here.
String result = "";
for (DataSource ds in value!) {
result += "${ds.content}\n";
if (ds.content != null) {
final newLength = result.length + ds.content!.length;
if (newLength > maxCharsInPrompt!) {
return result;
}
result += "${ds.content}\n";
}
}
return result;
}
Expand Down
5 changes: 4 additions & 1 deletion commanddash/lib/agent/step_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ abstract class Step {
}).toList();
return PromptQueryStep.fromJson(
json,
(json['prompt'] as String).replacePlaceholder(inputs, outputs),
(json['prompt'] as String),
// .replacePlaceholder(inputs, outputs),
outputsList,
inputs,
outputs,
);
case 'append_to_chat':
return AppendToChatStep.fromJson(json,
Expand Down
15 changes: 15 additions & 0 deletions commanddash/lib/models/contextual_code.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:commanddash/agent/input_model.dart';

String? checkIfUnique(List<CodeInput> current, CodeInput newInput) {
for (CodeInput input in current) {
if (newInput.filePath != input.filePath) {
return null;
} else {
final isNew = input.range.includes(newInput.range);
if (isNew) {
return input.id;
}
}
}
return null;
}
Loading

0 comments on commit 175a1b9

Please sign in to comment.