| 74 | ] |
| 75 | |
| 76 | export async function custom() { |
| 77 | const config = await Config.get() |
| 78 | const paths = new Set<string>() |
| 79 | |
| 80 | for (const localRuleFile of LOCAL_RULE_FILES) { |
| 81 | const matches = await Filesystem.findUp(localRuleFile, Instance.directory, Instance.worktree) |
| 82 | if (matches.length > 0) { |
| 83 | matches.forEach((path) => paths.add(path)) |
| 84 | break |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | for (const globalRuleFile of GLOBAL_RULE_FILES) { |
| 89 | if (await Bun.file(globalRuleFile).exists()) { |
| 90 | paths.add(globalRuleFile) |
| 91 | break |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | if (config.instructions) { |
| 96 | for (let instruction of config.instructions) { |
| 97 | if (instruction.startsWith("~/")) { |
| 98 | instruction = path.join(os.homedir(), instruction.slice(2)) |
| 99 | } |
| 100 | let matches: string[] = [] |
| 101 | if (path.isAbsolute(instruction)) { |
| 102 | matches = await Array.fromAsync( |
| 103 | new Bun.Glob(path.basename(instruction)).scan({ |
| 104 | cwd: path.dirname(instruction), |
| 105 | absolute: true, |
| 106 | onlyFiles: true, |
| 107 | }), |
| 108 | ).catch(() => []) |
| 109 | } else { |
| 110 | matches = await Filesystem.globUp(instruction, Instance.directory, Instance.worktree).catch(() => []) |
| 111 | } |
| 112 | matches.forEach((path) => paths.add(path)) |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | const found = Array.from(paths).map((p) => |
| 117 | Bun.file(p) |
| 118 | .text() |
| 119 | .catch(() => "") |
| 120 | .then((x) => "Instructions from: " + p + "\n" + x), |
| 121 | ) |
| 122 | return Promise.all(found).then((result) => result.filter(Boolean)) |
| 123 | } |
| 124 | |
| 125 | export function compaction(providerID: string) { |
| 126 | switch (providerID) { |