sdd-layer 0.14.0

Spec-Driven Development CLI and agent harness
# Execution — Project Intelligence Layer

## Rastreabilidade
- Orquestração: Project Intelligence Layer
- Slug: project-intelligence-layer
- Origem: docs/project-intelligence-layer/05-refinement.md
- Estado atual: recorded
- PRD aprovado: docs/project-intelligence-layer/02-prd.md
- Tech Spec aprovada: docs/project-intelligence-layer/03-techspec.md
- Tasks registradas: docs/project-intelligence-layer/04-tasks.md
- Refinement aprovado: docs/project-intelligence-layer/05-refinement.md
- Context Pack de execução: .sdd/intelligence/context-packs/project-intelligence-layer/execution.md
- Fonte canônica local: docs/project-intelligence-layer/traceability-map.yaml

## Tarefa

Executar todas as ondas aprovadas no Refinement:

- Onda 1: fundação compatível de CLI/config/inventário/learnings.
- Onda 2: Context Pack, stale detection e precedência mínima.
- Onda 3: status, health, documentação, testes e evidência.

## Resumo da implementação

Foi implementada a Project Intelligence Layer no CLI `sdd` com comportamento local, determinístico e provider-neutral.

Principais entregas:

- Novo comando `sdd intelligence` com subcomandos `learn`, `status` e `health`.
- Novo comando `sdd context build` preservando `sdd context recommend`.
- Configuração `intelligence` com defaults seguros e compatíveis.
- Inventário local de fontes por artifact store, traceability map, config e rules.
- Índices derivados em `.sdd/intelligence/sources.index.jsonl` e `.sdd/intelligence/learnings.jsonl`.
- Context Packs em `.sdd/intelligence/context-packs/<slug>/<stage>.md`.
- Stale detection por `source_hash`, persistindo `status: stale` quando a fonte muda.
- Validação de `--stage` em `context build`, bloqueando path traversal e stages desconhecidos.
- `context build --dry-run` e `context build` sem `--write` não persistem mudanças em JSONL.
- `health --json` recalcula stale em memória sem depender de `intelligence status`.
- `08-memory.md` passa a ser indexado quando presente.
- Context Pack registra conflitos de decisão por chave, aplicando precedência ADR > Tech Spec > PRD > Tasks > Execution/Review > Memory > índice derivado.
- Health signals objetivos para memória ausente, artefatos ausentes e learnings obsoletos.
- Compatibilidade preservada com `sdd memory learn`.
- Documentação operacional em `docs/PROJECT-INTELLIGENCE.md`, `README.md` e `docs/USAGE.md`.
- Testes CLI cobrindo help, context build, learnings enriquecidos, idempotência, stale detection, health e compatibilidade de memory.

## Arquivos alterados

- `src/main.rs`
- `src/domain/providers.rs`
- `tests/cli.rs`
- `sdd.config.yaml`
- `sdd.config.example.yaml`
- `README.md`
- `docs/USAGE.md`
- `docs/PROJECT-INTELLIGENCE.md`
- `docs/project-intelligence-layer/01-idea.md`
- `docs/project-intelligence-layer/02-prd.md`
- `docs/project-intelligence-layer/03-techspec.md`
- `docs/project-intelligence-layer/04-tasks.md`
- `docs/project-intelligence-layer/05-refinement.md`
- `docs/project-intelligence-layer/06-execution.md`
- `docs/project-intelligence-layer/traceability-map.yaml`

Observação: o worktree já continha várias alterações locais antes desta execução, inclusive em arquivos centrais do SDD. A execução preservou essas mudanças e evitou reverter trabalho fora do escopo.

## Testes e evidências

Comandos executados com sucesso:

```bash
cargo check
cargo build
cargo fmt --check
cargo test --test cli intelligence -- --nocapture
cargo test --test cli intelligence_status_json_marks_changed_learning_as_stale -- --nocapture
cargo test --test cli context_build_write_creates_techspec_pack_with_manifesto -- --nocapture
cargo test --test cli context_build_rejects_invalid_stage_path -- --nocapture
cargo test --test cli context_build_dry_run_does_not_persist_stale_status -- --nocapture
cargo test --test cli context_build_reports_decision_conflict_with_stage_precedence -- --nocapture
cargo test --test cli intelligence_learn_indexes_memory_when_present -- --nocapture
cargo test --test cli intelligence_health_detects_stale_learning_without_status_first -- --nocapture
cargo test
cargo clippy -- -D warnings
./target/debug/sdd intelligence --help
./target/debug/sdd context --help
./target/debug/sdd intelligence learn --name "Project Intelligence Layer" --json
./target/debug/sdd intelligence status --json
./target/debug/sdd intelligence health --json
./target/debug/sdd context build --name "Project Intelligence Layer" --stage execution --write --json
./target/debug/sdd memory learn --name "Project Intelligence Layer"
./target/debug/sdd memory status --json
./target/debug/sdd validate-artifact tasks docs/project-intelligence-layer/04-tasks.md
./target/debug/sdd validate-artifact refinement docs/project-intelligence-layer/05-refinement.md
git diff --check -- src/main.rs src/domain/providers.rs tests/cli.rs README.md docs/USAGE.md docs/PROJECT-INTELLIGENCE.md sdd.config.yaml sdd.config.example.yaml docs/project-intelligence-layer
```

Resultados principais:

- `cargo test`: 270 testes passaram.
- `cargo clippy -- -D warnings`: sem issues.
- `sdd intelligence learn`: `learnings: 7`, `sources_indexed: 14`.
- `sdd intelligence status`: `stale_sources: 0`, `conflicts: 0`.
- `sdd context build --stage execution --write`: gerou `.sdd/intelligence/context-packs/project-intelligence-layer/execution.md`.
- `sdd memory learn`: manteve `.sdd/memory/learnings.jsonl` compatível com `source_artifact` e `source_hash`.
- Testes pós-review confirmam que `context build --stage "../escape"` falha, `--dry-run` não persiste stale status, `health --json` detecta stale sem `status` prévio, `08-memory.md` é indexado quando presente e conflitos ADR vs Memory aparecem no manifesto com precedência.

Subagentes usados:

- Agente de docs para T-08, alterando `README.md`, `docs/USAGE.md` e `docs/PROJECT-INTELLIGENCE.md`.
- Agente de testes para cobertura CLI em `tests/cli.rs`.
- Agente de review despachado após a implementação para revisão read-only.
- Correções pós-review: precedência/conflito, `--dry-run` compute-only, validação de stage, stale em health e indexação de memory.

## Riscos e pendências

- A implementação inicial fica em `src/main.rs`, seguindo o padrão atual do CLI. Se a camada crescer, a próxima evolução recomendada é extrair tipos e funções para `src/domain/intelligence.rs`.
- Health signals são objetivos e conservadores; ainda não há score agregado nem dashboard visual.
- Busca semântica, embeddings, vector DB, MCP e integrações externas continuam fora do MVP por decisão aprovada.
- `.sdd/intelligence/*` e `.sdd/memory/learnings.jsonl` são caches derivados e reconstruíveis; a fonte canônica continua em `docs/<slug>/` e `traceability-map.yaml`.