Kaynağa Gözat

feat: include ignored files

Adam 5 ay önce
ebeveyn
işleme
aa9ab0a304

+ 6 - 5
bun.lock

@@ -113,6 +113,7 @@
         "gray-matter": "4.0.3",
         "hono": "catalog:",
         "hono-openapi": "0.4.8",
+        "ignore": "7.0.5",
         "isomorphic-git": "1.32.1",
         "jsonc-parser": "3.3.1",
         "minimatch": "10.0.3",
@@ -1032,7 +1033,7 @@
 
     "@types/braces": ["@types/[email protected]", "", {}, "sha512-SQFof9H+LXeWNz8wDe7oN5zu7ket0qwMu5vZubW4GCJ8Kkeh6nBWUz87+KTz/G3Kqsrp0j/W253XJb3KMEeg3w=="],
 
-    "@types/bun": ["@types/[email protected]0", "", { "dependencies": { "bun-types": "1.2.20" } }, "sha512-dX3RGzQ8+KgmMw7CsW4xT5ITBSCrSbfHc36SNT31EOUg/LA9JWq0VDdEXDRSe1InVWpd2yLUM1FUF/kEOyTzYA=="],
+    "@types/bun": ["@types/[email protected]1", "", { "dependencies": { "bun-types": "1.2.21" } }, "sha512-NiDnvEqmbfQ6dmZ3EeUO577s4P5bf4HCTXtI6trMc6f6RzirY5IrF3aIookuSpyslFzrnvv2lmEWv5HyC1X79A=="],
 
     "@types/cacheable-request": ["@types/[email protected]", "", { "dependencies": { "@types/http-cache-semantics": "*", "@types/keyv": "^3.1.4", "@types/node": "*", "@types/responselike": "^1.0.0" } }, "sha512-IQ3EbTzGxIigb1I3qPZc1rWJnH0BmSKv5QYTalEwweFvyBDLSAe24zP0le/hyi7ecGfZVlIVAg4BZqb8WBwKqw=="],
 
@@ -1836,7 +1837,7 @@
 
     "ieee754": ["[email protected]", "", {}, "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg=="],
 
-    "ignore": ["ignore@5.3.2", "", {}, "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g=="],
+    "ignore": ["ignore@7.0.5", "", {}, "sha512-Hs59xBNfUIunMFgWAbGX5cq6893IbWg4KnrjbYwX3tx0ztorVgTDA6B2sxf8ejHJ4wz8BqGUMYlnzNBer5NvGg=="],
 
     "ignore-walk": ["[email protected]", "", { "dependencies": { "minimatch": "^9.0.0" } }, "sha512-VuuG0wCnjhnylG1ABXT3dAuIpTNDs/G8jlpmwXY03fXoXy/8ZK8/T+hMzt8L4WnrLCJgdybqgPagnF/f97cg3A=="],
 
@@ -3302,7 +3303,7 @@
 
     "@tufjs/models/minimatch": ["[email protected]", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow=="],
 
-    "@types/bun/bun-types": ["[email protected]0", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-pxTnQYOrKvdOwyiyd/7sMt9yFOenN004Y6O4lCcCUoKVej48FS5cvTw9geRaEcB9TsDZaJKAxPTVvi8tFsVuXA=="],
+    "@types/bun/bun-types": ["[email protected]1", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-sa2Tj77Ijc/NTLS0/Odjq/qngmEPZfbfnOERi0KRUYhT9R8M4VBioWVmMWE5GrYbKMc+5lVybXygLdibHaqVqw=="],
 
     "@typescript-eslint/typescript-estree/minimatch": ["[email protected]", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow=="],
 
@@ -3380,8 +3381,6 @@
 
     "glob/minimatch": ["[email protected]", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow=="],
 
-    "globby/ignore": ["[email protected]", "", {}, "sha512-Hs59xBNfUIunMFgWAbGX5cq6893IbWg4KnrjbYwX3tx0ztorVgTDA6B2sxf8ejHJ4wz8BqGUMYlnzNBer5NvGg=="],
-
     "gray-matter/js-yaml": ["[email protected]", "", { "dependencies": { "argparse": "^1.0.7", "esprima": "^4.0.0" }, "bin": { "js-yaml": "bin/js-yaml.js" } }, "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g=="],
 
     "hast-util-to-parse5/property-information": ["[email protected]", "", {}, "sha512-PgTgs/BlvHxOu8QuEN7wi5A0OmXaBcHpmCSTehcs6Uuu9IkDIEo13Hy7n898RHfrQ49vKCoGeWZSaAK01nwVig=="],
@@ -3394,6 +3393,8 @@
 
     "ip-address/sprintf-js": ["[email protected]", "", {}, "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA=="],
 
+    "isomorphic-git/ignore": ["[email protected]", "", {}, "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g=="],
+
     "lambda-local/commander": ["[email protected]", "", {}, "sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug=="],
 
     "lazystream/readable-stream": ["[email protected]", "", { "dependencies": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", "isarray": "~1.0.0", "process-nextick-args": "~2.0.0", "safe-buffer": "~5.1.1", "string_decoder": "~1.1.1", "util-deprecate": "~1.0.1" } }, "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA=="],

+ 1 - 0
packages/opencode/package.json

@@ -41,6 +41,7 @@
     "gray-matter": "4.0.3",
     "hono": "catalog:",
     "hono-openapi": "0.4.8",
+    "ignore": "7.0.5",
     "isomorphic-git": "1.32.1",
     "jsonc-parser": "3.3.1",
     "minimatch": "10.0.3",

+ 16 - 3
packages/opencode/src/file/index.ts

@@ -6,6 +6,7 @@ import path from "path"
 import * as git from "isomorphic-git"
 import { App } from "../app/app"
 import fs from "fs"
+import ignore from "ignore"
 import { Log } from "../util/log"
 
 export namespace File {
@@ -29,6 +30,7 @@ export namespace File {
       name: z.string(),
       path: z.string(),
       type: z.enum(["file", "directory"]),
+      ignored: z.boolean(),
     })
     .openapi({
       ref: "FileNode",
@@ -133,18 +135,29 @@ export namespace File {
   }
 
   export async function list(dir?: string) {
-    const ignore = [".git", ".DS_Store"]
+    const exclude = [".git", ".DS_Store"]
     const app = App.info()
+    let ignored = (_: string) => false
+    if (app.git) {
+      const gitignore = Bun.file(path.join(app.path.root, ".gitignore"))
+      if (await gitignore.exists()) {
+        const ig = ignore().add(await gitignore.text())
+        ignored = ig.ignores.bind(ig)
+      }
+    }
     const resolved = dir ? path.join(app.path.cwd, dir) : app.path.cwd
     const nodes: Node[] = []
     for (const entry of await fs.promises.readdir(resolved, { withFileTypes: true })) {
-      if (ignore.includes(entry.name)) continue
+      if (exclude.includes(entry.name)) continue
       const fullPath = path.join(resolved, entry.name)
       const relativePath = path.relative(app.path.cwd, fullPath)
+      const relativeToRoot = path.relative(app.path.root, fullPath)
+      const type = entry.isDirectory() ? "directory" : "file"
       nodes.push({
         name: entry.name,
         path: relativePath,
-        type: entry.isDirectory() ? "directory" : "file",
+        type,
+        ignored: ignored(type === "directory" ? relativeToRoot + "/" : relativeToRoot),
       })
     }
     return nodes.sort((a, b) => {

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

@@ -1142,6 +1142,7 @@ export type FileNode = {
   name: string
   path: string
   type: "file" | "directory"
+  ignored: boolean
 }
 
 export type File = {