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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface RenderableDocumentReader : DocumentReader {
fun renderImage(pageIndex: Int, dpi: Float): BufferedImage
}

fun File.getReader(): DocumentReader = when {
fun File.getDocumentReader(): DocumentReader = when {
this.name.endsWith(".pdf", ignoreCase = true) -> PDFReader(this)
this.name.endsWith(".docx", ignoreCase = true) -> DocxReader(this)
this.name.endsWith(".doc", ignoreCase = true) -> DocReader(this)
Expand All @@ -32,4 +32,12 @@ fun File.getReader(): DocumentReader = when {
this.name.endsWith(".htm", ignoreCase = true) -> HTMLReader(this)
this.name.endsWith(".eml", ignoreCase = true) -> EmlReader(this)
else -> TextReader(this)
}

fun File.isDocumentFile(): Boolean {
val supportedExtensions = listOf(
".pdf", ".docx", ".doc", ".xlsx", ".xls", ".pptx", ".ppt",
".odt", ".rtf", ".html", ".htm", ".eml", ".txt"
)
return supportedExtensions.any { this.name.endsWith(it, ignoreCase = true) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class EmlReader(file: File) : DocumentReader {
}
}
// Use the file extension to determine the appropriate reader
val attachmentReader = tempFile.getReader()
val attachmentReader = tempFile.getDocumentReader()
attachmentReader.use {
val attachmentText = it.getText()
result.appendLine(attachmentText)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.simiacryptus.cognotik.util

import com.simiacryptus.cognotik.input.isDocumentFile
import org.apache.commons.text.similarity.LevenshteinDistance
import java.io.File
import java.io.InputStream
Expand All @@ -18,7 +19,7 @@ fun filteredWalkAsciiTree(
): String {
val sb = StringBuilder()
val filterFn = if (treatDocumentsAsText) {
{ file: File -> fn(file) && isDocumentFile(file) }
{ file: File -> fn(file) && file.isDocumentFile() }
} else fn
if (!filterFn(rootFile)) {
log.debug("Skipping root file for tree: ${rootFile.absolutePath}")
Expand Down Expand Up @@ -77,7 +78,7 @@ fun filteredWalkAsciiTree(
fn: (File) -> Boolean = { !isLLMIgnored(it.toPath()) }
): List<File> {
val filterFn = if (treatDocumentsAsText) {
{ f: File -> fn(f) || isDocumentFile(f) }
{ f: File -> fn(f) || f.isDocumentFile() }
} else fn
val result = mutableListOf<File>()
if (filterFn(file)) {
Expand Down Expand Up @@ -115,7 +116,7 @@ fun filteredWalkAsciiTree(
}
(when {
it.name.endsWith(".data") -> arrayOf(it)
treatDocumentsAsText && isDocumentFile(it) -> arrayOf(it)
treatDocumentsAsText && it.isDocumentFile() -> arrayOf(it)
isGitignore(it.toPath()) -> {
log.debug("File ignored by gitignore: ${it.absolutePath}")
arrayOf()
Expand Down Expand Up @@ -156,7 +157,7 @@ fun filteredWalkAsciiTree(
!file.exists() -> false
file.isDirectory -> false
file.name.endsWith(".data") -> true
treatDocumentsAsText && isDocumentFile(file) -> true
treatDocumentsAsText && file.isDocumentFile() -> true
file.length() > 100_000_000L -> false // 100MB limit
isGitignore(file.toPath()) -> false
isLLMIgnored(file.toPath()) -> false
Expand Down Expand Up @@ -384,11 +385,6 @@ fun filteredWalkAsciiTree(
this
}

fun isDocumentFile(file: File): Boolean {
val extension = file.extension.lowercase(Locale.getDefault())
return extension in setOf("pdf", "html", "htm")
}

fun resolveToRelativePath(root: Path, filename: String): String? {
log.debug("Resolving filename '{}' relative to root '{}'", filename, root)
if (!root.toFile().exists() || !root.toFile().isDirectory) {
Expand Down
1 change: 1 addition & 0 deletions desktop/src/main/resources/welcome/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ <h3>Step 2: Configure Settings</h3>
<div style="display: flex; gap: 10px;">
<input id="working-dir" style="flex-grow: 1;" type="text" value=".">
<button class="button secondary" id="generate-working-dir">New Directory</button>
<!--<button class="button secondary" id="select-working-dir">Select Directory</button>-->
</div>
</div>
<div class="form-group">
Expand Down
21 changes: 20 additions & 1 deletion desktop/src/main/resources/welcome/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,32 @@ function setupWizardNavigation() {
tempValue.textContent = this.value;
});
}
// Setup working directory generator
// Setup working directory generator
document.getElementById('generate-working-dir')?.addEventListener('click', () => {
const workingDirInput = document.getElementById('working-dir');
if (workingDirInput) {
workingDirInput.value = Utils.generateCognotikWorkingDir();
}
});
// Setup working directory selector
// document.getElementById('select-working-dir')?.addEventListener('click', () => {
// const workingDirInput = document.getElementById('working-dir');
// if (workingDirInput) {
// // Create a file input element to trigger directory selection
// const fileInput = document.createElement('input');
// fileInput.type = 'file';
// fileInput.webkitdirectory = true;
// fileInput.directory = true;
// fileInput.addEventListener('change', (e) => {
// if (e.target.files && e.target.files.length > 0) {
// // Get the path from the first file's webkitRelativePath
// const firstFilePath = e.target.files[0].webkitRelativePath;
// workingDirInput.value = firstFilePath;
// }
// });
// fileInput.click();
// }
// });

// Next buttons
document.getElementById('next-to-task-settings')?.addEventListener('click', () => {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pluginName=Cognotik
pluginRepositoryUrl=https://github.com/SimiaCryptus/Cognotik
libraryGroup=com.simiacryptus
libraryVersion=2.0.26
libraryVersion=2.0.27

gradleVersion=8.13
org.gradle.caching=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.simiacryptus.cognotik.agents.ChatAgent
import com.simiacryptus.cognotik.apps.general.renderMarkdown
import com.simiacryptus.cognotik.config.AppSettingsState
import com.simiacryptus.cognotik.diff.PatchProcessor
import com.simiacryptus.cognotik.input.getReader
import com.simiacryptus.cognotik.input.getDocumentReader
import com.simiacryptus.cognotik.models.ModelSchema
import com.simiacryptus.cognotik.platform.Session
import com.simiacryptus.cognotik.platform.model.User
Expand Down Expand Up @@ -671,7 +671,7 @@ class CustomFileSetPatchServer(
ignoreCase = true
) || file.name.endsWith(".htm", ignoreCase = true) -> {
try {
file.getReader().use { reader ->
file.getDocumentReader().use { reader ->
reader.getText()
}
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.simiacryptus.cognotik.CognotikAppServer
import com.simiacryptus.cognotik.apps.general.renderMarkdown
import com.simiacryptus.cognotik.chat.model.ChatInterface
import com.simiacryptus.cognotik.config.AppSettingsState
import com.simiacryptus.cognotik.input.getReader
import com.simiacryptus.cognotik.input.getDocumentReader
import com.simiacryptus.cognotik.models.ModelSchema
import com.simiacryptus.cognotik.platform.ApplicationServices
import com.simiacryptus.cognotik.platform.Session
Expand Down Expand Up @@ -231,7 +231,7 @@ class MultiCodeChatAction : BaseAction() {

fun readFileContent(file: File): String {
return try {
file.getReader().use { reader ->
file.getDocumentReader().use { reader ->
reader.getText()
}
} catch (e: Exception) {
Expand Down
Loading
Loading