Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 22, 2025

Summary

The copilot engine now automatically creates all directories specified in --add-dir arguments before executing the copilot CLI. This prevents potential errors when the copilot CLI attempts to access directories that don't exist yet.

Problem

The copilot engine builds a list of --add-dir arguments that point to various directories:

  • Default directories: /tmp/, /tmp/gh-aw/, /tmp/gh-aw/agent/
  • Log directory: /tmp/gh-aw/.copilot/logs/
  • Cache-memory directories (when configured): /tmp/gh-aw/cache-memory/, /tmp/gh-aw/cache-memory-{id}/
  • Custom directories from engine args

However, these directories were not being created before invoking the copilot CLI, which could cause failures if the directories don't exist.

Solution

Added a helper function extractAddDirPaths that:

  1. Scans all copilot arguments after they're fully assembled
  2. Extracts directory paths following --add-dir flags
  3. Includes the log directory (--log-dir) in the list
  4. Generates mkdir -p commands for all directories
  5. Inserts these commands before the copilot CLI invocation

Example Generated Output

set -o pipefail
COPILOT_CLI_INSTRUCTION=$(cat /tmp/gh-aw/aw-prompts/prompt.txt)
mkdir -p /tmp/
mkdir -p /tmp/gh-aw/
mkdir -p /tmp/gh-aw/agent/
mkdir -p /tmp/gh-aw/.copilot/logs/
copilot --add-dir /tmp/ --add-dir /tmp/gh-aw/ --add-dir /tmp/gh-aw/agent/ --log-level all --log-dir /tmp/gh-aw/.copilot/logs/ ...

Testing

Added comprehensive unit tests covering:

  • Helper function with various argument patterns
  • Default directory creation
  • Cache-memory directory creation (multiple cache instances)
  • Custom --add-dir paths from engine configuration

All existing tests continue to pass, confirming backward compatibility.

Fixes

Resolves the issue where copilot CLI could fail if directories specified in --add-dir arguments don't exist at runtime.

Original prompt

The copilot engine should review the --add-dir folders used in the args list and make sure those folders exist before running the cli.

Emit "mkdir -p ..." to prepare those directories.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@pelikhan
Copy link
Contributor

@copilot add safe output create issue staged to dev.md

Copilot AI and others added 2 commits October 22, 2025 04:53
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Ensure add-dir folders exist before running CLI Add directory creation for copilot engine --add-dir paths Oct 22, 2025
Copilot AI requested a review from pelikhan October 22, 2025 04:59
@pelikhan pelikhan marked this pull request as ready for review October 22, 2025 05:01
@github-actions
Copy link
Contributor

Agentic Changeset Generator triggered by this pull request.

@pelikhan pelikhan merged commit 006caaf into main Oct 22, 2025
6 of 8 checks passed
@pelikhan pelikhan deleted the copilot/check-add-dir-folders-existence branch October 22, 2025 05:01
Copilot AI requested a review from pelikhan October 22, 2025 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants