# Agent-native engineering

Fellow treats an agent as an operator of the engineering cycle: understand, plan, change, verify, report.
Every step is a CLI command with JSON output and stable exit codes, and the same operations are offered over MCP.
No AI provider is required or assumed.

## The cycle

| Step | Command | What it guarantees |
|---|---|---|
| Understand | `fellow context <terms> --pack` | Minimal context with traceable origin (file, line range, hash) within a token budget |
| Plan | `fellow task:new "<request>"` then `fellow task:check <id>` | A baseline is recorded; the plan is complete, traceable and consistent with the project |
| Change | `fellow make:*` (with `--dry-run` first), `fellow fix` | Deterministic, idempotent generators; mechanical fixes only |
| Verify | `fellow check --tests`, `fellow test --affected` | Architecture, types and tests; failures classified as code, environment or infrastructure |
| Report | `fellow task:evidence <id>` | Evidence Report built from verifiable facts |
| Approve | `fellow approve <action> <target>` (a person) | High-risk actions are bound to a human decision |

The workflows are written down as versioned skills: `fellow skills`, `fellow skills <name>`,
`fellow skills:install --target .claude/skills`.

## Task plan

`.fellow/tasks/<id>/plan.json`, written by the agent after `task:new`:

```json
{
  "id": "0001-archive-documents",
  "request": "Permitir arquivar documentos",
  "requirements": [{ "id": "R1", "text": "POST .../archive sets status to archived" }],
  "ambiguities": [{ "question": "Can archived documents be restored?", "resolution": "No (confirmed by the requester)" }],
  "scope": {
    "items": [{ "kind": "route", "id": "records.document.archive", "change": "add" }],
    "files": []
  },
  "steps": [{ "description": "Generate the route", "command": "fellow make:route records.document.archive --method POST" }],
  "risks": [],
  "acceptance": [{ "id": "A1", "criterion": "Archiving returns the document", "requirements": ["R1"], "verifiedBy": ["archives the document"] }]
}
```

`task:check` rejects plans with empty requirements (FW-TASK-001), unresolved ambiguities (FW-TASK-002), requirements
without acceptance criteria (FW-TASK-003), criteria without tests (FW-TASK-004), references to elements that do not
exist (FW-TASK-005) or to unknown modules (FW-TASK-006). It also predicts the approvals the change will need.

## Evidence Report

`task:evidence` writes `.fellow/tasks/<id>/evidence.json` and `evidence.md`. It never relies on what the agent says:

- **Files** created, modified and deleted since the baseline, and those **outside the planned scope**.
- **Contracts** added, changed or removed: routes, pages, access rules, entities, events, permissions, roles, policies.
- **Migrations** included, and whether they are destructive.
- **Verification**: plan, Architecture Validator, type checker, tests.
- **Acceptance**: a criterion is `verified` only when every test it names exists and passes.
- **Risks** from the plan and detected ones; **approvals** required by the actual change; what was **not verified**.

The status is `complete` only when everything passes, every criterion is verified and every approval is recorded;
`awaiting-approval` when only approvals are missing; `incomplete` otherwise (exit code 1).

## Human approval

Actions: `migration.destructive`, `auth.change`, `entitlement.change`, `module.publish`, `deploy.production`,
`tenant.cross`, `secrets`. Approvals are recorded in `.fellow/approvals.json` (commit it) with the approver, the time,
the reason and a digest of what was approved: editing an approved migration invalidates the approval.

`fellow approve` only works interactively, in a terminal, and never through MCP or `--json`. This is a process
control and an audit trail, not a security boundary against someone with shell access.
`fellow migrate --allow-destructive` refuses destructive migrations without a matching approval (FW-APPROVAL-001).

## Test orchestrator

- `fellow test --affected [--since <ref>]`: tests of modules changed according to git, and of every module that depends on them.
- `fellow test --task <id>`: the same, from the task baseline.
- `fellow test --failed`: rerun the files that failed last time. `--module <id>`, `--cases` for every test case.
- Categories: `code` (exit 1), `environment` (could not run, exit 3), `infrastructure` (a service failed during the run, exit 3).

## MCP

`fellow mcp` starts a Model Context Protocol server on stdio. Configure your client with the command
`bun fellow mcp` in the project directory. Tools: `fellow_intel`, `fellow_context`, `fellow_docs`, `fellow_knowledge`, `fellow_doctor`,
`fellow_check`, `fellow_test`, `fellow_generate` (plan unless `apply`), `fellow_migrate` (non-destructive only),
`fellow_fix`, `fellow_task_new`, `fellow_task_check`, `fellow_task_evidence`. The skills are offered as prompts.
Approvals, tokens, destructive migrations and forced overwrites are not exposed. Every call is logged to
`.fellow/logs/mcp.jsonl`; every CLI command to `.fellow/logs/cli.jsonl` (`FELLOW_NO_LOG=1` disables it).

## Documentation drift

`fellow docs:check` verifies that the project docs mention only existing commands, options, diagnostics and files;
`--framework` checks the framework docs and skills (run in Fellow's own test suite).

## Benchmark

`benchmarks/agent` in the Fellow repository: tasks on a reference application, judged by hidden acceptance tests,
the validator and the scope of the change, with metrics taken from the CLI logs. See its README.
