Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 2, 2025

The compiler only processed direct imports from workflow frontmatter, ignoring nested imports in shared files. This meant workflows importing shared files that themselves had imports would miss transitive dependencies.

Changes

Queue-based BFS traversal

  • Replaced linear iteration with queue-based BFS in ProcessImportsFromFrontmatterWithManifest
  • Added importQueueItem struct to track import path, resolved path, section, and base directory
  • Processes imports level-by-level for deterministic ordering

Recursive import discovery

  • Extracts frontmatter from each imported file to discover nested imports: field
  • Enqueues discovered imports for processing
  • Maintains visited set for cycle detection

Import path resolution

  • Nested imports now resolve relative to base workflows directory, not parent file location
  • Fixes issue where shared/trends.md importing shared/python-dataviz.md looked in wrong path

Validation relaxation

  • Updated isUnderWorkflowsDirectory to only flag top-level workflow files
  • Shared workflow files in subdirectories can now use imports:, mcp-servers: fields
  • Prevents validation errors on legitimate shared file patterns

Example

Before (only direct imports processed):

# main.md
imports:
  - shared/trends.md  # ✓ processed

# shared/trends.md  
imports:
  - shared/python-dataviz.md  # ✗ ignored

After (recursive processing):

# main.md
imports:
  - shared/trends.md  # ✓ processed (level 1)

# shared/trends.md
imports:
  - shared/python-dataviz.md  # ✓ now processed (level 2)

All three files are now correctly merged in BFS order: trends → python-dataviz.

Original prompt

Update compiler to support imports from imported share agentic workflows.

The compiler should recursively import all imported workflows and their imports.

  • must handle cycles (cross referenced workflows)
  • must have deterministic ordering
  • must use queues to maintain node sets and todos instead of functional recursion.
  • extensive testing
  • use BFS traversal to generate ordering

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Nov 2, 2025
- Refactored ProcessImportsFromFrontmatterWithManifest to use queue-based BFS
- Added cycle detection for cross-referenced imports
- Maintains deterministic ordering through breadth-first traversal
- Added comprehensive tests for recursive, cyclic, diamond, and ordering scenarios
- Fixed import path resolution for nested imports (relative to base dir)
- Updated validation to allow imports field in shared workflow files
- All existing tests passing

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Update compiler to support recursive imports of workflows Implement recursive import processing with BFS traversal for shared agentic workflows Nov 2, 2025
Copilot AI requested a review from pelikhan November 2, 2025 16:07
@pelikhan pelikhan marked this pull request as ready for review November 2, 2025 17:14
Copilot AI review requested due to automatic review settings November 2, 2025 17:14
@pelikhan pelikhan enabled auto-merge (squash) November 2, 2025 17:14
@pelikhan pelikhan merged commit 3c3118e into main Nov 2, 2025
55 checks passed
@pelikhan pelikhan deleted the copilot/update-compiler-imports branch November 2, 2025 17:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements recursive import support for workflow files with BFS (Breadth-First Search) traversal, cycle detection, and improved validation. The changes enable workflow files to import other files that themselves contain imports, creating a hierarchical import structure.

Key Changes

  • Added BFS-based recursive import processing with cycle detection in frontmatter parser
  • Updated isUnderWorkflowsDirectory to correctly identify top-level workflow files vs. shared files in subdirectories
  • Added comprehensive test suite covering recursive imports, cyclic imports, diamond patterns, and import ordering

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pkg/workflow/imports_recursive_test.go New comprehensive test suite for recursive imports, cyclic dependencies, diamond patterns, and BFS ordering
pkg/parser/frontmatter_test.go Updated test expectation for subdirectory file detection
pkg/parser/frontmatter.go Implemented BFS-based recursive import processing with queue-based traversal and cycle detection; enhanced validation for imported files
.github/workflows/daily-news.lock.yml Regenerated lock file reflecting new imports, Python data visualization support, and firewall configuration changes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +542 to +543
// Resolve nested import path relative to the workflows directory, not the nested file's directory
nestedFullPath, err := resolveIncludePath(nestedFilePath, baseDir)
Copy link

Copilot AI Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The comment on line 542 states nested imports are resolved relative to the workflows directory, but this design decision may be problematic. In typical import systems, relative paths in nested files should be resolved relative to the importing file's directory, not the root. This inconsistency could confuse users and make it difficult to create reusable shared file hierarchies. Consider documenting this behavior prominently in user-facing documentation, or reconsider the design to support relative-to-file resolution.

Copilot uses AI. Check for mistakes.
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