Skip to content

Commit 6ac3ce9

Browse files
Improve aider environment setup in aitools.psm1
Replaced Resolve-Path with Join-Path to avoid errors when files do not exist. Ensured the .aider directory and history files are created if missing, improving robustness of environment variable setup.
1 parent ea30031 commit 6ac3ce9

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

.aitools/aitools.psm1

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,30 @@ $PSDefaultParameterValues['Import-Module:Verbose'] = $false
22

33
# Auto-configure aider environment variables for .aitools directory
44
try {
5-
$env:AIDER_CONFIG_FILE = (Resolve-Path "$PSScriptRoot/.aider.conf.yml").Path
6-
$env:AIDER_ENV_FILE = (Resolve-Path "$PSScriptRoot/.env").Path
7-
$env:AIDER_MODEL_SETTINGS_FILE = (Resolve-Path "$PSScriptRoot/.aider.model.settings.yml").Path
8-
$env:AIDER_INPUT_HISTORY_FILE = (Resolve-Path "$PSScriptRoot/.aider/aider.input.history").Path
9-
$env:AIDER_CHAT_HISTORY_FILE = (Resolve-Path "$PSScriptRoot/.aider/aider.chat.history.md").Path
10-
$env:AIDER_LLM_HISTORY_FILE = (Resolve-Path "$PSScriptRoot/.aider/aider.llm.history").Path
5+
# Use Join-Path instead of Resolve-Path to avoid "path does not exist" errors
6+
$env:AIDER_CONFIG_FILE = Join-Path $PSScriptRoot ".aider.conf.yml"
7+
$env:AIDER_ENV_FILE = Join-Path $PSScriptRoot ".env"
8+
$env:AIDER_MODEL_SETTINGS_FILE = Join-Path $PSScriptRoot ".aider.model.settings.yml"
9+
10+
# Ensure .aider directory exists before setting history file paths
11+
$aiderDir = Join-Path $PSScriptRoot ".aider"
12+
if (-not (Test-Path $aiderDir)) {
13+
New-Item -Path $aiderDir -ItemType Directory -Force | Out-Null
14+
Write-Verbose "Created .aider directory: $aiderDir"
15+
}
16+
17+
$env:AIDER_INPUT_HISTORY_FILE = Join-Path $aiderDir "aider.input.history"
18+
$env:AIDER_CHAT_HISTORY_FILE = Join-Path $aiderDir "aider.chat.history.md"
19+
$env:AIDER_LLM_HISTORY_FILE = Join-Path $aiderDir "aider.llm.history"
20+
21+
# Create empty history files if they don't exist
22+
@($env:AIDER_INPUT_HISTORY_FILE, $env:AIDER_CHAT_HISTORY_FILE, $env:AIDER_LLM_HISTORY_FILE) | ForEach-Object {
23+
if (-not (Test-Path $_)) {
24+
New-Item -Path $_ -ItemType File -Force | Out-Null
25+
Write-Verbose "Created aider history file: $_"
26+
}
27+
}
28+
1129
Write-Verbose "Aider environment configured for .aitools directory"
1230
} catch {
1331
Write-Verbose "Could not configure aider environment: $_"

0 commit comments

Comments
 (0)