Browse Source

refactor(core): drop filesystem entry mime

Dax Raad 2 months ago
parent
commit
e8610d821c

+ 0 - 1
packages/core/src/filesystem.ts

@@ -111,7 +111,6 @@ const baseLayer = Layer.effect(
                   new Entry({
                     path: RelativePath.make(relative + (item.type === "directory" ? path.sep : "")),
                     type: item.type,
-                    mime: item.type === "directory" ? "application/x-directory" : FSUtil.mimeType(absolute),
                   }),
                 ]
               })

+ 0 - 1
packages/core/src/filesystem/schema.ts

@@ -4,7 +4,6 @@ import { NonNegativeInt, PositiveInt, RelativePath } from "../schema"
 export class Entry extends Schema.Class<Entry>("FileSystem.Entry")({
   path: RelativePath,
   type: Schema.Literals(["file", "directory"]),
-  mime: Schema.String,
 }) {}
 
 export const Submatch = Schema.Struct({

+ 7 - 14
packages/core/src/filesystem/search.ts

@@ -110,12 +110,9 @@ export const ripgrepLayer = Layer.effect(
           return fuzzysort.go(input.query, items, { limit: input.limit ?? 50 }).map((item) => {
             const relative = item.target
             const type = relative.endsWith(path.sep) ? ("directory" as const) : ("file" as const)
-            const clean = type === "directory" ? relative.slice(0, -path.sep.length) : relative
-            const absolute = path.resolve(location.directory, clean)
             return new FileSystem.Entry({
               path: RelativePath.make(relative),
               type,
-              mime: type === "directory" ? "application/x-directory" : FSUtil.mimeType(absolute),
             })
           })
         }),
@@ -148,14 +145,13 @@ export const fffLayer = Layer.effect(
             pageSize: input.limit,
           })
           if (!found.ok) throw found.error
-          return found.value.items.map((item) => {
-            const absolute = path.resolve(location.directory, item.relativePath)
-            return new FileSystem.Entry({
-              path: RelativePath.make(item.relativePath.replaceAll("\\", "/")),
-              type: "file",
-              mime: FSUtil.mimeType(absolute),
-            })
-          })
+          return found.value.items.map(
+            (item) =>
+              new FileSystem.Entry({
+                path: RelativePath.make(item.relativePath.replaceAll("\\", "/")),
+                type: "file",
+              }),
+          )
         }),
       grep: (input) =>
         Effect.sync(() => {
@@ -173,7 +169,6 @@ export const fffLayer = Layer.effect(
               entry: new FileSystem.Entry({
                 path: RelativePath.make(match.relativePath.replaceAll("\\", "/")),
                 type: "file",
-                mime: FSUtil.mimeType(match.relativePath),
               }),
               line: match.lineNumber,
               offset: match.byteOffset,
@@ -220,11 +215,9 @@ export const fffLayer = Layer.effect(
             .sort((a, b) => b.score - a.score || a.path.length - b.path.length)
             .map((item) => {
               const relative = item.path.replaceAll("\\", "/").replace(/\/$/, "")
-              const absolute = path.resolve(location.directory, relative)
               return new FileSystem.Entry({
                 path: RelativePath.make(relative + (item.type === "directory" ? path.sep : "")),
                 type: item.type,
-                mime: item.type === "directory" ? "application/x-directory" : FSUtil.mimeType(absolute),
               })
             })
         }),

+ 7 - 12
packages/core/src/ripgrep.ts

@@ -5,7 +5,6 @@ import { ChildProcess } from "effect/unstable/process"
 import path from "path"
 import { LayerNode } from "./effect/layer-node"
 import { Entry, Match } from "./filesystem/schema"
-import { FSUtil } from "./fs-util"
 import { AppProcess, collectStream, waitForAbort } from "./process"
 import { NonNegativeInt, PositiveInt, RelativePath } from "./schema"
 import { RipgrepBinary } from "./ripgrep/binary"
@@ -177,14 +176,13 @@ export const layer = Layer.effect(
             ),
         }).pipe(
           Effect.map((result) =>
-            result.items.map((relative) => {
-              const absolute = path.resolve(input.cwd, relative)
-              return new Entry({
-                path: RelativePath.make(relative),
-                type: "file",
-                mime: FSUtil.mimeType(absolute),
-              })
-            }),
+            result.items.map(
+              (relative) =>
+                new Entry({
+                  path: RelativePath.make(relative),
+                  type: "file",
+                }),
+            ),
           ),
           Effect.catchTag("Ripgrep.InvalidPatternError", (cause) => Effect.fail(failure(cause.message, cause))),
         ),
@@ -211,7 +209,6 @@ export const layer = Layer.effect(
               new Entry({
                 path: RelativePath.make(relative),
                 type: "file",
-                mime: FSUtil.mimeType(path.resolve(input.cwd, relative)),
               }),
             )
           },
@@ -262,12 +259,10 @@ export const layer = Layer.effect(
                 .replace(/^(?:\.[\\/])+/u, "")
                 .replace(/^[\\/]+/u, "")
                 .replaceAll("\\", "/")
-              const absolute = path.resolve(input.cwd, relative)
               return new Match({
                 entry: new Entry({
                   path: RelativePath.make(relative),
                   type: "file",
-                  mime: FSUtil.mimeType(absolute),
                 }),
                 line: match.line_number,
                 offset: match.absolute_offset,

+ 0 - 1
packages/core/src/tool/read-filesystem.ts

@@ -338,7 +338,6 @@ export const list = Effect.fn("ReadTool.list")(function* (fs: FSUtil.Interface,
         return new FileSystem.Entry({
           path: RelativePath.make(item.name + (type === "directory" ? path.sep : "")),
           type,
-          mime: type === "directory" ? "application/x-directory" : FSUtil.mimeType(target),
         })
       }),
     { concurrency: 16 },

+ 0 - 1
packages/sdk/js/src/v2/gen/types.gen.ts

@@ -4207,7 +4207,6 @@ export type PermissionSavedInfo = {
 export type FileSystemEntry = {
   path: string
   type: "file" | "directory"
-  mime: string
 }
 
 export type CommandV2Info = {

+ 1 - 4
packages/sdk/openapi.json

@@ -27726,12 +27726,9 @@
           "type": {
             "type": "string",
             "enum": ["file", "directory"]
-          },
-          "mime": {
-            "type": "string"
           }
         },
-        "required": ["path", "type", "mime"],
+        "required": ["path", "type"],
         "additionalProperties": false
       },
       "CommandV2Info": {

+ 1 - 5
packages/tui/src/component/prompt/autocomplete.tsx

@@ -305,11 +305,7 @@ export function Autocomplete(props: {
       startLine: input.lineStart,
       endLine: input.lineEnd > input.lineStart ? input.lineEnd : undefined,
     }
-    const { filename, part } = createFilePart(
-      { path: item, type: "file", mime: "text/plain" },
-      input.filePath,
-      lineRange,
-    )
+    const { filename, part } = createFilePart({ path: item, type: "file" }, input.filePath, lineRange)
     const index = store.visible === "@" ? store.index : props.input().cursorOffset
 
     setStore("visible", false)