Skip to content

Commit 75b5f57

Browse files
refactor: consolidate first-class tools — colocate compile-time and runtime code per tool (#290)
* Initial plan * refactor: consolidate first-class tools and runtimes into colocated modules Move compile-time (CompilerExtension) and runtime (Stage 3) code for each tool/runtime into a single directory: - tools/cache_memory/ — extension.rs + execute.rs - tools/azure_devops/ — extension.rs - runtimes/lean/ — extension.rs + mod.rs (config/helpers) Infrastructure extensions (GitHub, SafeOutputs) remain in compile/extensions/ as they are always-on and not user-configured. compile/extensions/mod.rs re-exports tool/runtime extensions from their new colocated homes. Agent-Logs-Url: https://github.com/githubnext/ado-aw/sessions/3cae398b-84f6-450a-8e39-31f2c20687f3 Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com> * docs: update AGENTS.md with new directory structure and colocation methodology Agent-Logs-Url: https://github.com/githubnext/ado-aw/sessions/3cae398b-84f6-450a-8e39-31f2c20687f3 Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com> * fix: remove unused MCPG_PORT re-export from compile/mod.rs MCPG_PORT is only used within the compile module (onees.rs, standalone.rs import via super::common). The pub re-export was generating an unused_imports warning. Agent-Logs-Url: https://github.com/githubnext/ado-aw/sessions/cf879e88-1dcc-48b9-94d4-3d0df7bbaba4 Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com>
1 parent a078012 commit 75b5f57

12 files changed

Lines changed: 78 additions & 24 deletions

File tree

AGENTS.md

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ Alongside the correctly generated pipeline yaml, an agent file is generated from
2929
│ │ ├── common.rs # Shared helpers across targets
3030
│ │ ├── standalone.rs # Standalone pipeline compiler
3131
│ │ ├── onees.rs # 1ES Pipeline Template compiler
32-
│ │ ├── extensions.rs # CompilerExtension trait for runtimes/tools
32+
│ │ ├── extensions/ # CompilerExtension trait and infrastructure extensions
33+
│ │ │ ├── mod.rs # Trait, Extension enum, collect_extensions(), re-exports
34+
│ │ │ ├── github.rs # Always-on GitHub MCP extension
35+
│ │ │ └── safe_outputs.rs # Always-on SafeOutputs MCP extension
3336
│ │ └── types.rs # Front matter grammar and types
3437
│ ├── init.rs # Repository initialization for AI-first authoring
3538
│ ├── execute.rs # Stage 3 safe output execution
@@ -65,18 +68,26 @@ Alongside the correctly generated pipeline yaml, an agent file is generated from
6568
│ │ ├── update_wiki_page.rs
6669
│ │ ├── update_work_item.rs
6770
│ │ └── upload_attachment.rs
68-
│ ├── runtimes/ # Runtime environment implementations
71+
│ ├── runtimes/ # Runtime environment implementations (one dir per runtime)
6972
│ │ ├── mod.rs # Module entry point
70-
│ │ └── lean.rs # Lean 4 theorem prover runtime
73+
│ │ └── lean/ # Lean 4 theorem prover runtime
74+
│ │ ├── mod.rs # Config types, install helpers
75+
│ │ └── extension.rs # CompilerExtension impl
7176
│ ├── data/
7277
│ │ ├── base.yml # Base pipeline template for standalone
7378
│ │ ├── 1es-base.yml # Base pipeline template for 1ES target
7479
│ │ ├── ecosystem_domains.json # Network allowlists per ecosystem
7580
│ │ ├── init-agent.md # Dispatcher agent template for `init` command
7681
│ │ └── threat-analysis.md # Threat detection analysis prompt template
77-
│ └── tools/ # First-class tool implementations (compiler auto-configures)
82+
│ └── tools/ # First-class tool implementations (one dir per tool)
7883
│ ├── mod.rs
79-
│ └── cache_memory.rs
84+
│ ├── azure_devops/ # Azure DevOps MCP tool
85+
│ │ ├── mod.rs
86+
│ │ └── extension.rs # CompilerExtension impl
87+
│ └── cache_memory/ # Persistent agent memory tool
88+
│ ├── mod.rs
89+
│ ├── extension.rs # CompilerExtension impl (compile-time)
90+
│ └── execute.rs # Stage 3 runtime (validate/copy)
8091
├── examples/ # Example agent definitions
8192
├── tests/ # Integration tests and fixtures
8293
├── Cargo.toml # Rust dependencies
@@ -1481,13 +1492,24 @@ When extending the compiler:
14811492
3. **New front matter fields**: Add fields to `FrontMatter` in `src/compile/types.rs`
14821493
4. **New template markers**: Handle replacements in the target-specific compiler (e.g., `standalone.rs` or `onees.rs`)
14831494
5. **New safe-output tools**: Add to `src/safeoutputs/` — implement `ToolResult`, `Executor`, register in `mod.rs`, `mcp.rs`, `execute.rs`
1484-
6. **New first-class tools**: Add to `src/tools/` — extend `ToolsConfig` in `types.rs`, implement `CompilerExtension` trait in `src/compile/extensions.rs`, add collection in `collect_extensions()`
1485-
7. **New runtimes**: Add to `src/runtimes/` — extend `RuntimesConfig` in `types.rs`, implement `CompilerExtension` trait in `src/compile/extensions.rs`, add collection in `collect_extensions()`
1495+
6. **New first-class tools**: Create `src/tools/<name>/` with `mod.rs` and `extension.rs` (CompilerExtension impl). Add `execute.rs` if the tool has Stage 3 runtime logic. Extend `ToolsConfig` in `types.rs`, add collection in `collect_extensions()`
1496+
7. **New runtimes**: Create `src/runtimes/<name>/` with `mod.rs` (config types) and `extension.rs` (CompilerExtension impl). Extend `RuntimesConfig` in `types.rs`, add collection in `collect_extensions()`
14861497
8. **Validation**: Add compile-time validation for safe outputs and permissions
14871498

1499+
#### Code Organization Principles
1500+
1501+
The codebase follows a **colocation** principle for tools and runtimes:
1502+
1503+
- **Tools** (`tools:` front matter) live in `src/tools/<name>/` — one directory per tool, containing both compile-time (`extension.rs`) and runtime (`execute.rs`) code. This means you can look at a single directory to understand everything a tool does.
1504+
- **Runtimes** (`runtimes:` front matter) live in `src/runtimes/<name>/` — one directory per runtime, with config types in `mod.rs` and the `CompilerExtension` impl in `extension.rs`.
1505+
- **Infrastructure extensions** (GitHub MCP, SafeOutputs MCP) that are always-on and not user-configured stay in `src/compile/extensions/`. These are internal plumbing, not user-facing tools.
1506+
- **Safe outputs** (`safe-outputs:` front matter) stay in `src/safeoutputs/` — they follow a different lifecycle (Stage 1 NDJSON → Stage 3 execution) and are not `CompilerExtension` implementations.
1507+
1508+
The `src/compile/extensions/mod.rs` file owns the `CompilerExtension` trait, the `Extension` enum, and `collect_extensions()`. It re-exports tool/runtime extension types from their colocated homes so the rest of the compiler can import them from a single path.
1509+
14881510
#### `CompilerExtension` Trait
14891511

1490-
Runtimes and first-party tools declare their compilation requirements via the `CompilerExtension` trait (`src/compile/extensions.rs`). Instead of scattering special-case `if` blocks across the compiler, each runtime/tool implements this trait and the compiler collects requirements generically:
1512+
Runtimes and first-party tools declare their compilation requirements via the `CompilerExtension` trait (`src/compile/extensions/mod.rs`). Instead of scattering special-case `if` blocks across the compiler, each runtime/tool implements this trait and the compiler collects requirements generically:
14911513

14921514
```rust
14931515
pub trait CompilerExtension: Send {
@@ -1501,7 +1523,7 @@ pub trait CompilerExtension: Send {
15011523
}
15021524
```
15031525

1504-
To add a new runtime or tool: (1) create a struct implementing `CompilerExtension`, (2) add a collection check in `collect_extensions()`. No other files need modification.
1526+
To add a new runtime or tool: (1) create a directory under `src/tools/` or `src/runtimes/`, (2) implement `CompilerExtension` in `extension.rs`, (3) add a variant to the `Extension` enum and a collection check in `collect_extensions()` in `src/compile/extensions/mod.rs`.
15051527

15061528
### Security Considerations
15071529

src/compile/extensions/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,16 +362,14 @@ macro_rules! extension_enum {
362362
};
363363
}
364364

365-
mod azure_devops;
366-
mod cache_memory;
367365
mod github;
368-
mod lean;
369366
mod safe_outputs;
370367

371-
pub use azure_devops::{AdoAuthMode, AzureDevOpsExtension};
372-
pub use cache_memory::CacheMemoryExtension;
368+
// Re-export tool/runtime extensions from their colocated homes
369+
pub use crate::tools::azure_devops::{AdoAuthMode, AzureDevOpsExtension};
370+
pub use crate::tools::cache_memory::CacheMemoryExtension;
373371
pub use github::GitHubExtension;
374-
pub use lean::LeanExtension;
372+
pub use crate::runtimes::lean::LeanExtension;
375373
pub use safe_outputs::SafeOutputsExtension;
376374

377375
extension_enum! {

src/compile/extensions/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::*;
2-
use crate::compile::common::{ADO_MCP_SERVER_NAME, parse_markdown};
2+
use crate::compile::{ADO_MCP_SERVER_NAME, parse_markdown};
33
use crate::compile::types::{AzureDevOpsToolConfig, CacheMemoryToolConfig};
44
use crate::runtimes::lean::LeanRuntimeConfig;
55

src/compile/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ pub use common::HEADER_MARKER;
2222
pub use common::generate_mcpg_config;
2323
pub use common::MCPG_IMAGE;
2424
pub use common::MCPG_VERSION;
25-
pub use common::MCPG_PORT;
25+
pub use common::ADO_MCP_ENTRYPOINT;
26+
pub use common::ADO_MCP_IMAGE;
27+
pub use common::ADO_MCP_PACKAGE;
28+
pub use common::ADO_MCP_SERVER_NAME;
2629
pub use types::{CompileTarget, FrontMatter};
2730

2831
/// Trait for pipeline compilers.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ─── Lean 4 ──────────────────────────────────────────────────────────
22

3-
use super::{CompileContext, CompilerExtension, ExtensionPhase};
4-
use crate::runtimes::lean::{self, LEAN_BASH_COMMANDS, LeanRuntimeConfig};
3+
use crate::compile::extensions::{CompileContext, CompilerExtension, ExtensionPhase};
4+
use super::{LEAN_BASH_COMMANDS, LeanRuntimeConfig, generate_lean_install};
55
use anyhow::Result;
66

77
/// Lean 4 runtime extension.
@@ -53,7 +53,7 @@ the toolchain. Lean files use the `.lean` extension.\n"
5353
}
5454

5555
fn prepare_steps(&self) -> Vec<String> {
56-
vec![lean::generate_lean_install(&self.config)]
56+
vec![generate_lean_install(&self.config)]
5757
}
5858

5959
fn validate(&self, ctx: &CompileContext) -> Result<Vec<String>> {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
//! Lean is installed via elan (the Lean toolchain manager) into `$HOME/.elan/bin`,
99
//! then symlinked into `/tmp/awf-tools/` for AWF chroot compatibility.
1010
11+
pub mod extension;
12+
13+
pub use extension::LeanExtension;
14+
1115
use ado_aw_derive::SanitizeConfig;
1216
use serde::Deserialize;
1317

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// ─── Azure DevOps MCP ────────────────────────────────────────────────
22

3-
use super::{
3+
use crate::compile::extensions::{
44
CompileContext, CompilerExtension, ExtensionPhase, McpgServerConfig, PipelineEnvMapping,
55
};
66
use crate::allowed_hosts::mcp_required_hosts;
7-
use crate::compile::common::{
7+
use crate::compile::{
88
ADO_MCP_ENTRYPOINT, ADO_MCP_IMAGE, ADO_MCP_PACKAGE, ADO_MCP_SERVER_NAME,
99
};
1010
use crate::compile::types::AzureDevOpsToolConfig;

src/tools/azure_devops/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//! Azure DevOps first-class tool.
2+
//!
3+
//! Compile-time: injects network hosts (ADO domains), MCPG server entry
4+
//! (containerized ADO MCP), and compile-time validation (org inference,
5+
//! duplicate MCP).
6+
7+
pub mod extension;
8+
9+
pub use extension::{AdoAuthMode, AzureDevOpsExtension};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{CompilerExtension, ExtensionPhase};
1+
use crate::compile::extensions::{CompilerExtension, ExtensionPhase};
22
use crate::compile::types::CacheMemoryToolConfig;
33

44
/// Cache memory tool extension.

0 commit comments

Comments
 (0)