MÓDULO 3.7

🌉 Longo Horizonte e Multi-Context

Scaffold mínimo (init.sh, tests.json, progress.txt, spec.md), context awareness e git como state tracker para tarefas que atravessam múltiplas janelas.

7
Tópicos
55
Minutos
Avançado
Nível
Arquitetura
Tipo
3 CONTEXT WINDOWS CONECTADAS POR DISCO Janela 1 monta scaffold escreve spec.md Janela 2 itera tests.json atualiza progress.txt Janela 3 fecha testes falhos abre PR cabo = spec.md + tests.json + progress.txt + git log
1

🗂️ Scaffold mínimo

init.sh

cria estrutura idempotente

tests.json

estado estruturado: todo/pass/fail

progress.txt

append-only log de decisões

spec.md

briefing permanente (ICCA)

2

🔬 init.sh completo

#!/usr/bin/env bash
# init.sh — idempotente, rodar 1x para criar scaffold
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
cd "$ROOT"

mkdir -p .agent
[ -f .agent/spec.md ] || cat > .agent/spec.md <<'EOF'
# Spec

## Intent
<descreva o objetivo em 2 linhas>

## Constraints
- <o que NÃO pode quebrar>

## Criteria
- [ ] todos os testes em .agent/tests.json passando
- [ ] nenhum arquivo fora do escopo modificado

## Files
- src/...
EOF

[ -f .agent/tests.json ] || cat > .agent/tests.json <<'EOF'
{
  "tests": [
    { "id": "t1", "desc": "...", "status": "todo" }
  ]
}
EOF

[ -f .agent/progress.txt ] || echo "# progress.txt — append-only" > .agent/progress.txt

grep -q '^\.agent/$' .gitignore 2>/dev/null || echo ".agent/scratch/" >> .gitignore
echo "scaffold ok."
3

📊 tests.json

{
  "tests": [
    { "id": "t1", "desc": "POST /users cria usuário",     "status": "passed", "last_run": "2026-04-20T13:05:00Z" },
    { "id": "t2", "desc": "GET /users/:id retorna 404",   "status": "failed", "error": "returns 500" },
    { "id": "t3", "desc": "middleware valida JWT",        "status": "todo" },
    { "id": "t4", "desc": "rate limit por IP",            "status": "todo" }
  ],
  "summary": { "total": 4, "passed": 1, "failed": 1, "todo": 2 }
}

Estrutura > texto livre. Fácil de patching por humano e modelo.

4

🧠 Context awareness prompt

<context_awareness>
Your context window will be automatically compacted when it
approaches its limit. Treat this as inevitable — your job is
to ensure that a future instance (with a fresh or compacted
context) can resume your work from disk.

Before making non-trivial progress:
  1. Read .agent/spec.md to re-anchor on the goal.
  2. Read .agent/tests.json to see current status.
  3. Read .agent/progress.txt to see what was already tried.

After meaningful progress:
  1. Update .agent/tests.json (status transitions).
  2. Append to .agent/progress.txt one line per decision:
     `YYYY-MM-DD HH:MM <what> — <why>`.
  3. If a new insight changes the plan, patch spec.md.
  4. Commit with message starting `chore(agent): `.

Assume a compact can happen at any turn. Never keep critical
state only in memory — write it down.
</context_awareness>
5

🔄 Workflow: janela 1 → N

JanelaFocoEntradaSaída
1scaffold + specbriefing humanospec.md + tests.json
2primeiro ciclospec + tests + progress3 testes verdes
3+fechar restantesmesmo + git logPR com tudo verde

Entre janelas: /clear total. Briefing = "read .agent/* and continue."

6

🌿 Git como state tracker

Rewind via git é mais seguro que rewind via sessão — estado explícito, no disco.

7

🏗️ Laboratório T3

Desafio final

Escolha uma tarefa real de 2–3h que obrigatoriamente passe de 200k tokens. Ex.: migrar módulo com 15+ arquivos, reescrever suíte de testes, integrar API desconhecida.

Entregáveis

  1. Branch attempt/YYYYMMDD-* com scaffold aplicado
  2. Pelo menos 1 compact atravessado sem perda de contexto
  3. tests.json com ≥80% dos testes verdes
  4. progress.txt com ≥20 entradas
  5. Relatório final: janelas usadas, compacts, commits, tempo humano real

Ao terminar, você sabe o que significa "sustenta tarefas multi-context". A Trilha 4 transforma isso em produção.

📋 Resumo da Trilha 3

Scaffold .agent/ — disco > contexto
Context awareness — modelo sabe que vai compactar
Git state tracker — branch por tentativa
Laboratório final — tarefa real de horas, compact real

Próxima Trilha:

T4 Expert — Migração e Produção (Amber)