| 938 | }; |
| 939 | |
| 940 | const findRulesFile = () => { |
| 941 | const configPath = getConfigPath(); |
| 942 | if (!configPath) return { path: null, source: 'none' }; |
| 943 | |
| 944 | let dir = path.dirname(configPath); |
| 945 | let last = null; |
| 946 | while (dir && dir !== last) { |
| 947 | const agentsPath = path.join(dir, 'AGENTS.md'); |
| 948 | if (fs.existsSync(agentsPath)) return { path: agentsPath, source: 'AGENTS.md' }; |
| 949 | const claudePath = path.join(dir, 'CLAUDE.md'); |
| 950 | if (fs.existsSync(claudePath)) return { path: claudePath, source: 'CLAUDE.md' }; |
| 951 | last = dir; |
| 952 | dir = path.dirname(dir); |
| 953 | } |
| 954 | |
| 955 | return { path: null, source: 'none' }; |
| 956 | }; |
| 957 | |
| 958 | const detectTool = (tool) => { |
| 959 | const command = process.platform === 'win32' ? `where ${tool}` : `which ${tool}`; |