This document defines the constraints and expectations for AI Agents working on the Refarm monorepo.
These rules are not arbitrary — they derive from a unified cognitive model:
AI agents in this repository operate under Active Inference. Each rule below is an operational instance of an epistemic principle:
- Generative Model:
src/is the system's internal causal model. Artifacts (dist/) are derived observations — never edit an observation, fix the model. - Action as Sampling: Builds, tests, and
reso.mjs statusare actions that sample the environment to reduce uncertainty before deciding. - Calibrated Precision: Use existing tooling (
reso.mjs,pnpm run build) to assess current state reliability. Never assume — measure. - Complexity Minimization: Prefer atomic changes. Surprise (unexpected errors) scales with delta size. Small commits = lower free energy.
- Markov Blanket: You interact with the repository exclusively through reads (files, tooling output) and writes to
src/. Never assume direct access to runtime state or generated artifacts.
- Source is Truth: All edits must happen in
src/or source-level directories. - NEVER Edit Artifacts: Manual edits to
dist/,build/,.turbo/, or any directory ignored by.gitignoreare strictly prohibited. These files are ephemeral and non-reproducible.
Active Inference: keep the internal model (
src/) consistent with observations. Editing an artifact is editing a shadow, not the cause.
- Build to Verify: If a change in one package affects another, you MUST run
pnpm run buildin the dependency package to synchronize type definitions and distribution files. - No Cheat-Fixes: Do not bypass TypeScript or Lint errors by editing generated
.d.tsfiles. Fix the root cause in the source or the build configuration.
Active Inference: a build is a perception act — it samples reality to confirm the model's predictions. Skip it and you're acting blind.
- Deterministic Alignment: NEVER spend cognitive cycles trying to guess where a package is pointing. Use the existing tooling:
- Run
node packages/toolbox/src/cli.mjs reso statusto see the current resolution state. (scripts/reso.mjsis a deprecated wrapper — prefer the toolbox directly.) - Use
node packages/toolbox/src/cli.mjs reso srcto toggle to local development, orreso distfor production validation.
- Run
- Scoped builds: use
pnpm --filter @refarm.dev/<pkg> run build(ortype-check,test) rather thancd-ing into packages. The--filterflag respects workspace dependency order. - Git Discipline: Large, sweeping changes should be avoided. Prefer atomic, logical commits.
- Health first: Always run
refarm healthafter significant refactors (@refarm.dev/healthis implemented — it audits filesystem structure, build alignment, and resolution status). - Plugin Integrity: Leverage the
Barn(@refarm.dev/barn) for plugin lifecycle management and SHA-256 integrity validation before deployment. Its evolution roadmap (FilesystemCacheAdapter → farmhand → Scarecrow policy) is tracked indocs/superpowers/specs/.
- Health first: Always run
Active Inference:
reso statuscalibrates precision — it tells you how reliable the current environment signal is before you act on it.
The Refarm CLI exposes a self-guiding operator loop through JSON handoffs. When working in this repo as an agent, use the CLI — do not guess at state.
Start of every slice:
refarm resume --json # "where was I?" — always follow nextCommands
refarm check --next-action --json # composite gate: health + runtime doctorAfter source edits, before committing:
refarm agent finish --lane after-edit --run --jsonAfter an atomic commit:
refarm agent finish --lane after-commit --run --jsonAfter changing public JSON output or CLI contracts:
refarm agent finish --lane handoffs --run --jsonJSON handoff rules:
- Every JSON command exposes
ok,nextCommand, andnextCommands. Always inspect and follow them before guessing what to do next. refarm resume --jsonin emergency (runtime not ready) returns only runtime recovery commands. Do not dispatch work until the runtime is ready.refarm agent finish --run --jsonsuccess setsnextCommandtorefarm resume --json. Follow it to confirm state after the gate.refarm check --next-action --jsonon pass returnsnextAction: nullandnextCommands: []— that is the "all clear" signal to proceed.refarm agent --jsonprints the full agent handoff plan with all available commands for the current environment state.
- Sovereign Stratification: This monorepo is HÍBRIDO.
- If a package has
tsconfig.build.json, it is TS-Strict (source is.ts,.jsinsrc/are artifacts). - If it lacks TS configuration, it is JS-Atomic (source is
.js).
- If a package has
- Careful Cleaning: Never run global
rm -f src/*.jswithout verifying package nature first.
Active Inference: recognizing a package's nature reduces the model's complexity — acting without this knowledge maximizes surprise.
- Project Repository: Document technical decisions, architectural changes, and progress in the project's official
docs/orREADME.mdfiles. - Sovereign Knowledge: Ensure that all knowledge generated during a session is transitioned into the project's source or standard documentation areas to remain accessible to all contributors.
Active Inference: documentation is the agent's only durable output channel. Knowledge that stays in the session context is lost — write it or it never existed.
- Immutable Actions: Always use the full 40-character commit hash for third-party GitHub Actions (e.g.,
actions/checkout@de0fac2e...). This ensures the build is deterministic and protected against tag floating. - Workflow Reuse: Use reusable workflows (
workflow_call) and local actions (./.github/actions/...) to promote DRY principles and composition. - Lean Modifications: When editing
.github/workflows/, make minimal, targeted changes. Avoid large-scale re-indents or sweeping re-ordering that obscures the logical diff. - Local Reproduction First: Use the closest scoped local command to reproduce likely failures before pushing. GitHub Actions is a final confirmation signal, not the first test runner.
- Wrapper Logic: Prefer encapsulating complex build or test logic into local script "wrappers" (e.g.,
pnpm run test:conformance) rather than long, multi-linerunblocks in YAML.
Active Inference: pinned hashes and reusable workflows minimize environmental drift — a stable environment produces predictable outcomes and lowers surprise.
The host machine has ~8GB RAM and 16 cores. Default Rust toolchain settings (jobs=16, codegen-units=16) will exhaust available memory and crash the container. .cargo/config.toml at the repo root enforces safe defaults — do not override them without reason.
For artifact locations, cleanup tiers (light/medium/heavy), CARGO_TARGET_DIR volume layout, and disk compaction guidance: see
docs/local-disk-hygiene.md.
# ✅ Single focused unit/integration filter — cheapest normal development signal
cargo test --lib <test_or_module_name> --quiet
cargo test --test agent_harness <test_filter> -- --ignored --test-threads=1
# ✅ Unit tests only — use when the affected crate/module is broader
cargo test --lib
# ✅ Single integration test suite — run sequentially, not in parallel
cargo test --test ws_integration
cargo test --test agent_harness -- --ignored --test-threads=1
# ⚠️ Full test suite — only when preparing a push
cargo test --lib && cargo test --test ws_integration
# ⚠️ WASM component build — necessary before running harness, not before every unit slice
cargo component build --release -p agent
# 🚫 Never run without `--lib`, a specific `--test`, or a specific filter in this environment
cargo test # compiles ALL test binaries simultaneously → OOM risk- Micro-slice: run only the directly affected test/filter plus
git diff --check. - Package checkpoint: add
cargo check --quietfor the touched Rust package orpnpm -C <pkg> run type-checkfor the touched TS package. - WASM/plugin boundary: rebuild
agent.wasmonly when agent/WIT changed and a harness test must execute; otherwise prefercargo check --target wasm32-wasip1 --quiet. - Harness: prefer filtered harness runs (
cargo test --test agent_harness harness_streaming -- --ignored --test-threads=1) over repeated one-test invocations. - Push/CI gate: run the broader scoped gate once, then push and watch CI with
gh run watch --exit-statusinstead of repeatedly reproducing the same expensive local work. - Cleanup:
pnpm run clean:rust:checkto audit, then pick a tier fromdocs/local-disk-hygiene.md. Runningclean:lightafter every slice removes incremental caches and makes the next Rust check more expensive.
| Setting | Default | This repo | Reason |
|---|---|---|---|
build.jobs |
16 | 4 | Limits parallel crate compilation |
profile.dev.codegen-units |
16 | 4 | Limits LLVM threads per crate |
profile.release.codegen-units |
16 | 1 | Smaller WASM binary + lower peak RAM |
Active Inference: a build that crashes the container produces zero information. Constraining parallelism is not slower — crashing and restarting is slower.
- No silent high-impact actions: before destructive or wide-impact operations (mass edits, deletes, branch-wide rewrites), require explicit human confirmation.
- Protected surfaces: changes under
.project/**,.github/workflows/**,packages/tractor/**,packages/tractor-ts/**, andpackages/plugin-manifest/**should follow serialized lock/handoff policy. - Unauthorized action monitor:
.pi/monitors/unauthorized-action/is the first line of defense and must remain enabled/calibrated. Its companion agents live in.pi/agents/. - If intent is ambiguous, stop and ask: do not infer permission for operations outside the user-declared scope.
Active Inference: in uncertain conditions, information-gathering (ask/confirm) is lower-risk than irreversible action.
"We cultivate the code as we cultivate the soil: with patience, honesty, and respect for the cycle."