1---2name: harness-init3description: Use when initializing a new project, making a repo agent-ready, or adding architectural layer boundaries — produces AGENTS.md, docs/ system of record, boundary tests, linter rules, CI pipeline, and GC scripts4---56# Harness Init78<Purpose>9Bootstrap a repository with OpenAI's harness engineering scaffolding: AGENTS.md orientation map, docs/ system of record, architectural layer enforcement, golden principles, garbage collection, and static/dynamic context strategy.1011This is the **repo initialization subset** of harness engineering. Runtime feedback loops, agent review loops, and observability stack setup are out of scope. If the repo already has observability (logs, metrics, tracing), this skill reads it as dynamic context but does not build it.1213Source: OpenAI "Harness engineering: leveraging Codex in an agent-first world" (2026-02-11)14</Purpose>1516<Why_This_Exists>17AI agents can only work with what they can see. Without structured documentation, mechanical constraints, and clear layer boundaries, agents make inconsistent architectural decisions, introduce import violations, and produce code that drifts from conventions. This skill front-loads the environment design so every subsequent agent session starts with a map, not a blank slate.18</Why_This_Exists>1920<Use_When>21- Creating a new project from scratch22- Making an existing repo agent-ready for the first time23- Adding architectural layer boundaries to a codebase24- User says "harness", "init harness", "make this agent-ready", "set up architecture"25- Before any major feature work in a repo that lacks AGENTS.md + docs/26</Use_When>2728<Do_Not_Use_When>29- Repo already has AGENTS.md + docs/architecture/LAYERS.md + boundary tests — use existing harness30- User wants hierarchical AGENTS.md per directory — use a per-directory init tool instead31- User wants runtime observability / agent review loops — out of scope for this skill32- Quick bug fix or small feature — just do the work directly33- User wants to explore ideas or brainstorm — this skill is for structured scaffolding, not ideation34</Do_Not_Use_When>3536<Principles>371. **Give agents a map, not an encyclopedia** — AGENTS.md ~100 lines, progressive disclosure382. **If agents can't see it, it doesn't exist** — all knowledge machine-readable in repo393. **Enforce architecture mechanically** — linters and tests, not markdown instructions404. **Every error message is agent context** — remediation instructions in error output415. **Boring technology wins** — composable, stable, well-trained-on APIs426. **Architecture test is a ratchet** — KNOWN_VIOLATIONS can only shrink, never grow43</Principles>4445<Execution_Policy>46- Phase 0 (Discovery) is MANDATORY — never skip, never assume the stack47- **Argument parsing:** `full` = all phases. `N` = single phase. `N-M` = phase range. No argument = interactive (asks user what to set up). Phase 0 always runs regardless of argument.48- Read before you write — match existing code style and patterns49- Use `git mv` for doc restructuring to preserve history50- New lint rules warn first if pre-existing violations exist — don't break the build51- Delegate phases in parallel where independent (e.g., Phase 5 CI + Phase 7 hooks)52- Run long operations (npm install, test suites) in background53- Use a feature branch (`feat/harness-engineering`) if the repo has existing work54- **Phase checkpoints:** After each phase, verify output exists (file created + test/lint passes where applicable). Log completed phases so work can resume if interrupted.55- **Failure handling:** If a phase fails, skip it, report what failed and why, and continue to the next independent phase. Do not halt the entire run for a single phase failure.56- **Verification evidence:** "Phase complete" = output file exists AND relevant test/lint passes. File existence alone is not sufficient.57</Execution_Policy>5859<Steps>601. **Phase 0 — Discovery** (NEVER SKIP)61 a. Detect stack: language, framework, package manager, build tool, test runner, linter62 b. Map directory structure (maxdepth 3, exclude node_modules/.git)63 c. Check for existing docs: AGENTS.md, CLAUDE.md, docs/, CI workflows, tests, lint config64 d. Identify architecture layers by reading actual import patterns — `Read references/layer-templates.md` for common models65 e. Inject dynamic context: git status, diagnostics, CI status — `Read references/context-strategy.md` for the full signal table66 f. Ask clarifying questions: layer mapping, special imports, testing preference, full vs partial setup67682. **Phase 1 — AGENTS.md** (~100 lines, orientation map)69 - `Read references/agents-md-template.md` for the template70 - Fill in from Phase 0 discovery — don't invent, reflect what exists71 - Point to docs/ for details, don't inline them72733. **Phase 2 — docs/ system of record**74 Required:75 - Create: `ARCHITECTURE.md` at repo root (top-level domain map, ~30 lines, points to LAYERS.md)76 - Create: `docs/architecture/LAYERS.md` (definitive layer hierarchy + remediation guide)77 - Create: `docs/golden-principles/` — `Read references/golden-principles-guide.md` for how to write these78 - Create: `docs/SECURITY.md` — `Read references/security-template.md` for template and exclusion rules79 Recommended:80 - Create: `docs/guides/` (setup, testing, deployment — only what's relevant)81 - Create: `docs/exec-plans/` — `Read references/exec-plan-template.md` for the standard (active/ + completed/ subdirs)82 - Create: `docs/design-docs/` with `index.md` (ADR index) and `core-beliefs.md` (non-negotiable decisions)83 - Create: `docs/references/` (external library docs reformatted for LLM consumption, e.g. `{library}-llms.txt`)84 - Create: `docs/DESIGN.md`, `docs/PLANS.md`, `docs/QUALITY_SCORE.md`85 Conditional (by project type):86 - `docs/RELIABILITY.md` — for services (SLA, error budgets, resilience patterns)87 - `docs/STACK.md` — stack-specific conventions (replaces OpenAI's FRONTEND.md)88 - `docs/product-specs/` — for product-driven projects89 - `docs/generated/` — auto-generated docs (db-schema.md, api-spec.md)90914. **Phase 3 — Architecture boundary test**92 - `Read references/boundary-test-template.md` for test skeletons, KNOWN_VIOLATIONS format, and ratchet logic93 - `Read references/stack-routing.md` for import parser and test file path per stack94 - Scan all source files, parse imports, validate against layer rules95 - Error format: `VIOLATION: {file}:{line} imports {target} — {layer} cannot import {target_layer}. See docs/architecture/LAYERS.md`96 - Ratchet: `KNOWN_VIOLATIONS` stored in `tests/architecture/known-violations.json`, can only shrink97 - For existing repos: establish baseline first, then ratchet98995. **Phase 4 — Linter boundary enforcement**100 - `Read references/stack-routing.md` for linter rule name and config location per stack101 - Use linter's native import restriction rules102 - Every error message MUST include remediation — error output IS agent context1031046. **Phase 5 — CI pipeline**105 - `Read references/ci-templates.md` for starter YAML templates and command validation rules106 - `Read references/stack-routing.md` for CI job matrix per stack107 - Adapt to stack — not every stack needs all 4 jobs (lint, typecheck, test, build)108 - Validate discovered commands before embedding in CI — reject shell metacharacters, stop and ask if suspicious1091107. **Phase 6 — Garbage collection**111 - `Read references/gc-patterns.md` for scan types, safety rules, and migration strategy112 - `Read references/stack-routing.md` Phase 6 table for per-stack GC tooling113 - `Read references/ci-templates.md` GC Workflow section for `gc.yml` template114 - Prioritize entropy scans (doc drift, architecture violations) over style scans115 - Single `gc` command + scheduled GitHub Action (weekly cron, report-only)1161178. **Phase 7 — Pre-commit hooks** (optional)118 - `Read references/stack-routing.md` for framework and config per stack119 - Phase 7 is optional — CI (Phase 5) is the authoritative gate120</Steps>121122<Tool_Usage>123Delegate by intent — platform routes the call. `Read references/tool-routing.md` for platform-specific mappings.124125- **Explore** (lightweight model) — directory mapping, file discovery in Phase 0126- **Architect** (heavyweight model) — architecture analysis, layer identification in Phase 0127- **Write** (lightweight model) — AGENTS.md + docs generation in Phases 1-2128- **Execute** (standard model) — boundary test, linter config, CI, GC scripts in Phases 3-7129- **Verify** (standard model) — final checklist validation130- Read `references/*.md` files on demand per phase — don't load all at once131</Tool_Usage>132133<Examples>134<Good>135User: "harness-init this new Next.js project"136Agent: Runs Phase 0 discovery -> detects Next.js + TypeScript + ESLint -> identifies full-stack layer pattern -> asks "Full setup or specific phases?" -> proceeds through all phases.137Why good: Discovery first, confirms with user, adapts to actual stack.138</Good>139140<Good>141User: "add architecture boundaries to this existing Python repo"142Agent: Runs Phase 0 -> discovers 200+ existing import violations -> establishes KNOWN_VIOLATIONS baseline -> sets lint rules to warn-only -> creates ratchet test -> asks user about convergence timeline.143Why good: Doesn't break existing build, uses ratchet for gradual convergence.144</Good>145146<Good>147User: "harness-init 3-4"148Agent: Runs Phase 0 (always) -> detects Go + golangci-lint -> reads stack-routing.md -> creates boundary test with `go/parser` + depguard config -> skips Phases 1-2, 5-7.149Why good: Respects phase argument, still runs discovery, uses decision tables for tooling.150</Good>151152<Good>153User: "harness-init this turborepo monorepo"154Agent: Runs Phase 0 -> detects packages/ structure -> reads layer-templates.md monorepo model -> maps cross-package dependencies -> creates per-package boundary tests + shared CI matrix.155Why good: Adapts to monorepo structure instead of forcing single-app patterns.156</Good>157158<Bad>159User: "harness-init"160Agent: Immediately creates AGENTS.md with React/TypeScript template without reading the repo.161Why bad: Skipped Phase 0 discovery. Assumed stack instead of detecting it.162</Bad>163164<Bad>165User: "make this agent-ready" (repo has 500 lint violations)166Agent: Adds strict lint rules that fail CI immediately on all 500 violations.167Why bad: Didn't establish baseline. Broke the build. Should warn-only first, then ratchet.168</Bad>169</Examples>170171<Escalation_And_Stop_Conditions>172- **Stop and ask** if stack detection is ambiguous (multiple package managers, unclear framework)173- **Stop and ask** if no clear directory structure exists (flat repo with no src/ or lib/)174- **Stop and ask** if existing AGENTS.md or docs/ conflict with harness structure175- **Stop and report** if linter/test runner cannot be installed (permissions, incompatible versions)176- **Graceful degradation** if `gh` CLI, LSP, or session state unavailable — skip those dynamic context signals, note what was skipped177- **Never force** a layer structure that doesn't fit the actual codebase178</Escalation_And_Stop_Conditions>179180<Final_Checklist>181- [ ] Phase 0 discovery completed (stack detected, layers identified, user confirmed)182- [ ] AGENTS.md exists at repo root (~100 lines, index not encyclopedia)183- [ ] docs/architecture/LAYERS.md exists with layer diagram + remediation guide184- [ ] At least 2-3 golden principles docs exist with DO/DON'T examples185- [ ] Architecture boundary test exists and passes (with KNOWN_VIOLATIONS if existing repo)186- [ ] Linter rules enforce import boundaries with remediation in error messages187- [ ] CI pipeline runs lint + test (at minimum)188- [ ] GC runner command exists (`npm run gc` / `make gc` / equivalent)189- [ ] All new files committed on feature branch190- [ ] Test suite, linter, and GC scripts verified to run successfully191</Final_Checklist>192193<Advanced>194## Target File Structure195196```197project-root/198├── AGENTS.md # ~100 lines, orientation map [Required]199├── ARCHITECTURE.md # Top-level domain map [Required]200├── docs/201│ ├── architecture/202│ │ └── LAYERS.md # Layer hierarchy + enforcement [Required]203│ ├── golden-principles/ # DO/DON'T patterns, 30-60 lines each [Required]204│ ├── SECURITY.md # Auth, secrets, threat model [Required]205│ ├── guides/ # Setup, testing, deployment [Recommended]206│ ├── exec-plans/ # ExecPlan lifecycle [Recommended]207│ │ ├── active/208│ │ ├── completed/209│ │ └── tech-debt-tracker.md210│ ├── design-docs/ # ADRs [Recommended]211│ │ ├── index.md212│ │ ├── core-beliefs.md213│ │ └── {NNNN-title}.md214│ ├── references/ # External docs for LLMs [Recommended]215│ │ └── {library}-llms.txt216│ ├── DESIGN.md # Design philosophy [Recommended]217│ ├── PLANS.md # Exec-plans overview [Recommended]218│ ├── QUALITY_SCORE.md # Per-domain quality grades [Recommended]219│ ├── RELIABILITY.md # SLA, error budgets (services) [Conditional]220│ ├── STACK.md # Stack conventions [Conditional]221│ ├── product-specs/ # Product specs [Conditional]222│ └── generated/ # Auto-generated docs [Conditional]223│ └── {db-schema,api-spec}.md224├── scripts/gc/ # Garbage collection scripts225├── tests/architecture/226│ └── boundary.test.* # Mechanical layer enforcement227└── .github/workflows/228 ├── ci.yml # lint + typecheck + test + build229 └── gc.yml # Weekly entropy scan230```231232## Reference Files233234Detailed templates and guides are in `references/` — read on demand per phase:235- `references/layer-templates.md` — 5 layer models (4 tech stacks + OpenAI original)236- `references/agents-md-template.md` — AGENTS.md template237- `references/context-strategy.md` — Static vs dynamic context tables238- `references/exec-plan-template.md` — ExecPlan (docs/exec-plans/) standard239- `references/golden-principles-guide.md` — How to write golden principles240- `references/gc-patterns.md` — GC scan types + migration strategy for existing repos241- `references/security-template.md` — SECURITY.md template with exclusion rules242- `references/boundary-test-template.md` — Test skeletons, KNOWN_VIOLATIONS format, ratchet logic243- `references/tool-routing.md` — Platform-specific tool delegation mappings244- `references/stack-routing.md` — Stack → tooling decision tables for Phases 3-7245- `references/ci-templates.md` — Starter CI YAML for GitHub Actions, GitLab, Makefile246</Advanced>247248---249> Source: [Gizele1/harness-init](https://github.com/Gizele1/harness-init) — distributed by [TomeVault](https://tomevault.io).250<!-- tomevault:4.0:skill_md:2026-06-21 -->