<!-- SPDX-License-Identifier: MIT -->
<!-- SPDX-FileCopyrightText: 2025-2026 Marcus Quinn -->

# t1364.5: Create Bundle Detection and Resolution Logic

## Origin

- **Created:** 2026-02-28
- **Session:** claude-code:headless
- **Created by:** ai-interactive
- **Parent task:** t1364
- **Conversation context:** Decomposition of issue #2558 item 4. This subtask implements the detection and resolution logic.

## What

A helper script that auto-detects project type from file structure and resolves the effective bundle configuration.

Produces:
1. `.agents/scripts/bundle-helper.sh` — CLI with detect/resolve/show/list/validate subcommands
2. Auto-detection logic for 6+ project types based on marker files
3. Resolution priority chain: explicit > auto-detected > fallback
4. Integration API functions callable from other scripts

## Why

Without detection logic, users must manually configure bundles for every repo. Auto-detection makes the system zero-config for common project types while still allowing explicit overrides.

## How (Approach)

- Create bundle-helper.sh following existing helper script patterns (ShellCheck clean, `local var="$1"`, explicit returns, source shared-constants.sh)
- **Detection**: scan for marker files (package.json → web-app, Dockerfile → infrastructure, *.sh → cli-tool, wp-config.php → content-site, Cargo.toml/go.mod/pyproject.toml → library)
- **Resolution chain**: repos.json `bundle` → .aidevops.json `bundle` → auto-detected → `cli-tool` fallback
- **Composition**: when multiple types detected (e.g., web-app + infrastructure), merge bundles (union quality_gates, most-restrictive model_defaults)
- **Caching**: store detection result in .aidevops.json for performance (re-detect on `--force`)
- **API functions**: `get_bundle_config()`, `get_quality_gates()`, `get_model_default()`, `should_skip_gate()` — sourceable by other scripts

## Acceptance Criteria

- [ ] bundle-helper.sh exists and passes ShellCheck
  ```yaml
  verify:
    method: bash
    run: "shellcheck .agents/scripts/bundle-helper.sh"
  ```
- [ ] `detect` subcommand correctly identifies project types from marker files
  ```yaml
  verify:
    method: bash
    run: ".agents/scripts/bundle-helper.sh list | grep -q 'web-app'"
  ```
- [ ] Resolution priority chain works (explicit > auto > fallback)
- [ ] Composition merges multiple detected types correctly
- [ ] API functions are sourceable from other scripts

## Context & Decisions

- Detection is heuristic, not definitive — a project with both package.json and Dockerfile gets both web-app and infrastructure bundles composed
- Caching avoids re-scanning on every dispatch but can be invalidated with --force
- The fallback is cli-tool (most conservative — runs shellcheck, basic tests) rather than no-bundle

## Relevant Files

- `.agents/bundles/*.json` — bundle definitions (from t1364.4)
- `.agents/scripts/shared-constants.sh` — shared functions pattern
- `~/.config/aidevops/repos.json` — explicit bundle configuration
- `.aidevops.json` — per-repo configuration

## Dependencies

- **Blocked by:** t1364.4
- **Blocks:** t1364.6

## Estimate Breakdown

| Phase | Time | Notes |
|-------|------|-------|
| Research/read | 30m | Review existing helper patterns |
| Implementation | 2.5h | Detection + resolution + API |
| Testing | 1h | ShellCheck + manual testing |
| **Total** | **~4h** | |
