# Review — Project Intelligence Layer
## Rastreabilidade
- Orquestração: Project Intelligence Layer
- Slug: project-intelligence-layer
- Origem: docs/project-intelligence-layer/06-execution.md
- ADR: docs/project-intelligence-layer/06-adr.md
- Estado atual: draft
- 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
- Fonte canônica local: docs/project-intelligence-layer/traceability-map.yaml
## Escopo revisado
Arquivos e superfícies revisadas:
- `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/*`
Critérios revisados:
- `sdd intelligence learn/status/health`.
- `sdd context build`.
- Stale detection.
- Context Pack com manifesto.
- Precedência e conflito entre fontes.
- Redaction e provider-neutralidade.
- Compatibilidade com `sdd memory learn`.
- Evidência SDD materializada.
## Evidências
Comandos executados com sucesso:
```bash
cargo fmt --check
cargo build
cargo test
cargo clippy -- -D warnings
./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 context build --name "Project Intelligence Layer" --stage ../escape --write
./target/debug/sdd validate-artifact execution docs/project-intelligence-layer/06-execution.md
./target/debug/sdd validate-artifact adr docs/project-intelligence-layer/06-adr.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:
- `cargo test`: 270 testes passaram.
- `cargo clippy -- -D warnings`: sem issues.
- Stage inválido `../escape` falha com `invalid context stage`.
- `sdd intelligence learn` é idempotente para `sources.index.jsonl`.
- `sdd intelligence status`: `stale_sources: 0`, `conflicts: 0` após reindexação da orquestração.
- `sdd context build --stage execution --write`: Context Pack gerado em `.sdd/intelligence/context-packs/project-intelligence-layer/execution.md`.
## Achados
### Resolvido — Precedência e conflitos de decisão
O review paralelo identificou que a primeira versão apenas contava learnings já marcados como `conflict`, sem detectar conflitos nem aplicar precedência real.
Correção aplicada:
- Ranking de fontes agora inclui peso de precedência por stage.
- Context Pack detecta decisões em formato `Chave: valor` dentro de seções de decisão.
- Conflitos entre fontes são registrados no manifesto.
- Teste cobre ADR vs Memory com ADR prevalecendo.
### Resolvido — `context build --dry-run` mutava JSONL
O review paralelo identificou que `context build --dry-run` podia persistir `status: stale` ao recalcular hashes.
Correção aplicada:
- `refresh_learning_statuses` ganhou modo compute-only.
- `context build --dry-run` e `context build` sem `--write` não persistem JSONL.
- Teste cobre dry-run sem mutação de stale status.
### Resolvido — `--stage` aceitava path arbitrário
O review paralelo identificou risco de path traversal porque `--stage` era usado em `join(format!("{stage}.md"))`.
Correção aplicada:
- `validate_context_stage` rejeita `..`, `/`, `\`, espaços externos, vazio e stage desconhecido.
- Apenas stages canônicos de `STAGE_FILES` são aceitos.
- Teste cobre `--stage ../escape`.
### Resolvido — `health` não recalculava stale
O review paralelo identificou que `health` dependia de status já persistido.
Correção aplicada:
- `health` recalcula stale em memória antes de montar sinais.
- Teste cobre stale detectado por `health --json` sem executar `status` antes.
### Resolvido — `08-memory.md` não era indexado
O review paralelo identificou que `build_learning_records` ignorava a etapa Memory.
Correção aplicada:
- `memory` passa a ser indexada quando `08-memory.md` existe.
- Teste cobre `source_stage: "memory"`.
### Resolvido — Evidência de execução SDD
Foi criado e validado `docs/project-intelligence-layer/06-execution.md`, e o traceability map foi atualizado com `execution: recorded` e `adr: recorded`.
## Testes
Cobertura nova em `tests/cli.rs`:
- `intelligence_help_lists_learn_status_and_health`
- `context_build_write_creates_techspec_pack_with_manifesto`
- `context_build_rejects_invalid_stage_path`
- `intelligence_learn_writes_enriched_jsonl_and_memory_learn_stays_compatible`
- `intelligence_learn_indexes_memory_when_present`
- `intelligence_status_json_marks_changed_learning_as_stale`
- `context_build_dry_run_does_not_persist_stale_status`
- `context_build_reports_decision_conflict_with_stage_precedence`
- `intelligence_health_json_reports_missing_memory_for_incomplete_orchestration`
- `intelligence_health_detects_stale_learning_without_status_first`
## Veredito
Aprovado tecnicamente para checkpoint humano de Review.
Não há achados críticos ou altos pendentes no escopo revisado. Risco residual: a implementação inicial permanece concentrada em `src/main.rs`; a extração para `src/domain/intelligence.rs` é recomendada se a camada crescer.