@njeybe/nativ 2.3.1 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +55 -1
  2. package/README.md +676 -190
  3. package/dist/commands/db.js +3 -0
  4. package/dist/commands/doctor.d.ts +2 -1
  5. package/dist/commands/doctor.js +4 -0
  6. package/dist/commands/init.js +1 -0
  7. package/dist/commands/learn.d.ts +19 -0
  8. package/dist/commands/learn.js +121 -0
  9. package/dist/commands/session.d.ts +22 -0
  10. package/dist/commands/session.js +106 -0
  11. package/dist/commands/task.js +34 -7
  12. package/dist/commands/verify.js +6 -0
  13. package/dist/core/code-shape.js +4 -2
  14. package/dist/core/enforcement.d.ts +1 -0
  15. package/dist/core/enforcement.js +22 -4
  16. package/dist/core/harness-integrity.d.ts +15 -0
  17. package/dist/core/harness-integrity.js +198 -0
  18. package/dist/core/human-gate.d.ts +7 -0
  19. package/dist/core/human-gate.js +16 -0
  20. package/dist/core/learnings.d.ts +63 -0
  21. package/dist/core/learnings.js +227 -0
  22. package/dist/core/root-resolver.d.ts +5 -0
  23. package/dist/core/root-resolver.js +46 -0
  24. package/dist/core/session-memory.d.ts +42 -0
  25. package/dist/core/session-memory.js +121 -0
  26. package/dist/core/setup-assets.d.ts +1 -1
  27. package/dist/core/setup-assets.js +5 -2
  28. package/dist/core/spec-slices.js +119 -7
  29. package/dist/core/verifier.d.ts +36 -0
  30. package/dist/core/verifier.js +92 -4
  31. package/dist/db/introspector.js +59 -59
  32. package/dist/governor/store.d.ts +18 -0
  33. package/dist/governor/store.js +53 -0
  34. package/dist/index.js +41 -0
  35. package/dist/mcp/server.js +12 -0
  36. package/dist/runner/agent-supervisor.d.ts +16 -0
  37. package/dist/runner/agent-supervisor.js +63 -8
  38. package/dist/scanner/types.d.ts +1 -0
  39. package/dist/server/studio-ui/shell/model.js +3 -1
  40. package/package.json +2 -2
  41. package/plugin/.claude-plugin/plugin.json +2 -2
  42. package/plugin/agents/architect.md +3 -3
  43. package/plugin/agents/explorer.md +49 -0
  44. package/plugin/agents/worker.md +2 -1
  45. package/plugin/skills/nativ/SKILL.md +15 -0
  46. package/templates/AGENTS.md +15 -0
  47. package/templates/CLAUDE.md +32 -32
  48. package/templates/GEMINI.md +2 -2
  49. package/templates/claude-agents/architect.md +3 -3
  50. package/templates/claude-agents/explorer.md +49 -0
  51. package/templates/claude-agents/worker.md +2 -1
  52. package/templates/dot-ai/api_contracts.json +66 -66
  53. package/templates/dot-ai/context.md +38 -38
  54. package/templates/dot-ai/db_schema.json +39 -39
  55. package/templates/dot-ai/subagents/frontend.md +33 -0
  56. package/templates/dot-ai/ui_specs.md +17 -0
package/README.md CHANGED
@@ -1,331 +1,771 @@
1
1
  # nativ
2
2
 
3
- A role-based multi-agent workflow for AI coding agents. **Claude Code is the default**; other agents plug in. `nativ` keeps the design contracts, the task plan and the guardrails in your repository, so the same rules hold whichever tool or model does the work.
3
+ **A role-based workflow harness for AI coding agents.** nativ keeps your design contracts, the task plan and the guardrails in your repository, so the same rules hold whichever agent or model does the work. Claude Code is the default; other agents plug in through `AGENTS.md` and MCP.
4
4
 
5
- > **Package:** `@njeybe/nativ` | **Command:** `nativ`
5
+ [![npm](https://img.shields.io/npm/v/@njeybe/nativ)](https://www.npmjs.com/package/@njeybe/nativ)
6
+ ![node](https://img.shields.io/badge/node-%3E%3D20-339933)
7
+ ![license](https://img.shields.io/badge/license-MIT-blue)
8
+
9
+ ```bash
10
+ npm install -g @njeybe/nativ # the package is @njeybe/nativ, the command is nativ
11
+ cd your-project && nativ init # scaffold .ai/ and the Claude Code configuration
12
+ ```
6
13
 
7
14
  ---
8
15
 
9
- ## The idea
16
+ ## Contents
10
17
 
11
- Four roles, fixed. The model or vendor behind each role is configurable.
18
+ | Start here | Command reference | Reference |
19
+ | :--- | :--- | :--- |
20
+ | [Why nativ](#why-nativ) | [Command map](#command-map) | [Configuration](#configuration) |
21
+ | [Quick start](#quick-start) | [Setup and health](#setup-and-health) | [Guardrails](#guardrails) |
22
+ | [How it works](#how-it-works) | [Tasks](#tasks) | [Files nativ manages](#files-nativ-manages) |
23
+ | [Everyday workflow](#everyday-workflow) | [Verification](#verification) | [MCP server](#mcp-server) |
24
+ | | [Learnings](#learnings) | [Providers](#providers) |
25
+ | | [Escalations and triage](#escalations-and-triage) | [Concurrency and telemetry](#concurrency-and-telemetry) |
26
+ | | [Database](#database) | [Troubleshooting](#troubleshooting) |
27
+ | | [Worktrees](#worktrees) | [For maintainers](#for-maintainers) |
28
+ | | [Studio, tests and benchmarks](#studio-tests-and-benchmarks) | |
12
29
 
13
- ```
14
- Architect designs contracts (database, API, UI); the human approves each step
15
- |
16
- v .ai/ contracts + master_plan.json
17
- Project Manager runs the task loop, delegates, reports (the main Claude Code session)
18
- |
19
- v one task, one role guide, its own worktree if you like
20
- Workers backend, frontend, database, QA, Flutter, DevOps, security, migration
21
- |
22
- v
23
- Verifier independent checks; cannot edit files
24
- ```
30
+ ---
25
31
 
26
- Why it works:
32
+ ## Why nativ
27
33
 
28
- - **Contracts, not chat.** `.ai/db_schema.json`, `.ai/api_contracts.json` and `.ai/ui_specs.md` are the source of truth. Workers implement against them and escalate gaps instead of improvising.
34
+ - **Contracts, not chat.** `.ai/db_schema.json`, `.ai/api_contracts.json` and `.ai/ui_specs.md` are the source of truth. Workers build against them and escalate gaps instead of improvising.
29
35
  - **Boundaries enforced by code.** A Claude Code hook checks every file write against the active task, the protected contracts and your secret files. It does not rely on the model remembering a rule.
30
- - **Independent verification.** Each task has a `verificationCommand` that a gatekeeper re-runs before the task can complete, and a separate verifier agent reviews the result.
36
+ - **Independent verification.** A gatekeeper re-runs each task's checks before it can complete, and a separate verifier agent reviews the result.
37
+ - **A project that remembers.** Settled escalations and human-approved lessons travel with later tasks, so the same gap is not raised twice.
31
38
  - **Zero-credential air-gap.** Agents see database structure, never passwords, connection strings or rows.
32
39
 
33
40
  ---
34
41
 
35
42
  ## Quick start
36
43
 
37
- ### 1. Install
38
-
39
- You need Node.js 20 or newer and Git.
44
+ **1. Install.** You need Node.js 20 or newer and Git. More options are in [docs/installation.md](docs/installation.md).
40
45
 
41
46
  ```bash
42
47
  npm install -g @njeybe/nativ
43
48
  nativ --version
44
49
  ```
45
50
 
46
- The package is `@njeybe/nativ`; the command is `nativ`. More options, including running it without installing, are in [docs/installation.md](docs/installation.md).
47
-
48
- ### 2. Set up a project
51
+ **2. Set up a project.** `init` scaffolds `.ai/` and runs `setup`, which writes the Claude Code configuration. Setup merges: it never overwrites your own settings, hooks, MCP servers or edited files.
49
52
 
50
53
  ```bash
51
54
  cd your-project
52
55
  nativ init
56
+ nativ doctor # confirm everything is wired
53
57
  ```
54
58
 
55
- `nativ init` scaffolds the `.ai/` workflow and then runs `nativ setup`, which writes the Claude Code configuration:
59
+ **3. Trust the folder.** Open Claude Code in the project once and accept the workspace trust dialog. Until you do, Claude Code ignores the project's `permissions.allow` entries.
56
60
 
57
- | File | What it does |
58
- | :--- | :--- |
59
- | `.mcp.json` | Registers the `nativ` MCP server |
60
- | `.claude/settings.json` | Permission rules, the enforcement hook, the session-start orientation hook |
61
- | `.claude/agents/` | The `architect`, `worker` and `verifier` agents |
62
- | `AGENTS.md` | The one directive every agent follows. `CLAUDE.md` and `GEMINI.md` point at it |
63
- | `.nativ/config.json` | Enforcement mode and provider choices |
61
+ **4. Ask Claude to work.** On existing code, start with the explorer; then the architect designs, workers build, and the verifier checks. See [Everyday workflow](#everyday-workflow).
62
+
63
+ > **About the Claude Code plugin.** The package also ships a plugin (`plugin/`), but you do not need it: a plugin cannot ship permission rules, so `nativ setup` is the complete route. To try the plugin for one session, point `claude --plugin-dir` at that folder under your global `node_modules` (`npm root -g` prints it).
64
+
65
+ ---
66
+
67
+ ## How it works
68
+
69
+ Four roles, plus a read-only explorer for existing code. Each one has a single job and hands a
70
+ concrete result to the next.
71
+
72
+ ```
73
+ ┌──────────────────────────────────────┐
74
+ │ EXPLORER │
75
+ │ maps the existing code │
76
+ └───────────────────┬──────────────────┘
77
+ │ codebase map
78
+ ▼
79
+ ┌──────────────────────────────────────┐
80
+ │ ARCHITECT │ ◀── you approve each step
81
+ │ designs the contracts │
82
+ └───────────────────┬──────────────────┘
83
+ │ contracts + task plan
84
+ ▼
85
+ ┌──────────────────────────────────────┐
86
+ │ PROJECT MANAGER │
87
+ │ hands out one task at a time │
88
+ └───────────────────┬──────────────────┘
89
+ │ one task + only its context
90
+ ▼
91
+ ┌──────────────────────────────────────┐
92
+ │ WORKERS │
93
+ │ build inside the task's files │
94
+ └───────────────────┬──────────────────┘
95
+ │ finished change
96
+ ▼
97
+ ┌──────────────────────────────────────┐
98
+ │ VERIFIER │
99
+ │ checks the result independently │
100
+ └──────────────────────────────────────┘
101
+ ```
102
+
103
+ | Role | Job | Runs on | Never |
104
+ | :--- | :--- | :--- | :--- |
105
+ | **Explorer** | Maps components, routes, models, conventions and drift from the contracts. Has only Read, Grep and Glob | Sonnet · Haiku for quick lookups | Edits, designs or decides |
106
+ | **Architect** | Designs the database, API and UI contracts; resolves escalations | Opus | Writes application code |
107
+ | **Project Manager** | Runs the task loop, delegates, reports back to you | Your main Claude Code session | Edits contracts or does tasks itself |
108
+ | **Workers** | Build one task each: backend, frontend, database, QA, Flutter, DevOps, security, migration | Picked per task: Haiku, Sonnet or Opus | Touch files outside the task, or contracts |
109
+ | **Verifier** | Reruns the checks and reviews the diff against the contracts | Haiku | Edits anything |
110
+
111
+ - **One rulebook.** Every agent follows `AGENTS.md`; `CLAUDE.md` and `GEMINI.md` point at it.
112
+ - **The project manager starts everyone else.** Subagents cannot start other subagents, so it
113
+ runs the explorer, the workers and the verifier.
114
+ - **Swap any model or vendor.** The roles are fixed; what runs behind them is configurable.
115
+
116
+ ---
117
+
118
+ ## Everyday workflow
119
+
120
+ | Step | You ask Claude to... | What happens |
121
+ | :--- | :--- | :--- |
122
+ | 1. Explore | run the **explorer** (existing code only) | A map of components, routes, models and conventions, plus drift from the contracts. The architect saves it as `.ai/codebase_map.md`. |
123
+ | 2. Design | use the **architect** | Experience-First or Data-First track, design brief, style tiles, wireframes, component map. It stops for your approval after each contract. |
124
+ | 3. Plan | let the architect add tasks | Each task has `targetFiles`, `acceptanceCriteria`, `specRefs` and a `complexity` that picks the worker's model. |
125
+ | 4. Build | run `nativ task next` and delegate to a **worker** | The worker gets only what it needs: contract slices, settled escalations and approved lessons. |
126
+ | 5. Check | let the worker complete the task | The gatekeeper runs your verify phases, then the task's command, then a code-style check. |
127
+ | 6. Review | ask for a **verifier** pass | An independent read of the diff against the contracts. |
128
+ | 7. Improve | approve lessons agents proposed | `nativ learn list --status proposed`, then `approve` or `reject`. |
129
+
130
+ ---
131
+
132
+ ## Command reference
133
+
134
+ Every command takes an optional `[targetDir]` (default: the current directory) and most accept `--json` for scripting. Run `nativ <command> --help` for the full option list.
135
+
136
+ ### Command map
137
+
138
+ **Who** says who should run it: **You** in a terminal, an **Agent** (directly or through MCP), or a Claude Code **Hook**. Commands marked *You only* refuse to run without an interactive terminal, and the permission rules `nativ setup` writes also deny them to agents.
64
139
 
65
- Setup **merges**: it never overwrites your own settings, hooks, MCP servers or edited files. It is safe to run any number of times, and `nativ setup --dry-run` shows what it would change.
140
+ | Command | What it does | Who |
141
+ | :--- | :--- | :--- |
142
+ | [`init`](#nativ-init) | Scaffold `.ai/` and the Claude Code configuration | You |
143
+ | [`setup`](#nativ-setup) | Write or merge the Claude Code configuration | You |
144
+ | [`doctor`](#nativ-doctor) | Check the integration and the harness; `--fix` repairs | You, Agent (read-only) |
145
+ | [`update`](#nativ-update) | Refresh directives, role guides and agents to the latest templates | You |
146
+ | [`validate`](#nativ-validate) | Check the contracts and role guides are well formed | You, Agent |
147
+ | [`status`](#nativ-status) | Progress and telemetry | You, Agent |
148
+ | [`hook status`](#nativ-hook) | Enforcement mode, role and active task scope | You, Agent |
149
+ | [`task next`](#nativ-task-next) | The next executable task with its context | Agent |
150
+ | [`task list`](#nativ-task-list) / `tasks` | List tasks with filters | You, Agent |
151
+ | [`task add`](#nativ-task-add) | Add a task | Architect |
152
+ | [`task start`](#nativ-task-start) | Mark a task in progress | Agent |
153
+ | [`task complete`](#nativ-task-complete) | Complete a task through the gatekeeper | Agent |
154
+ | [`task block`](#nativ-task-block) | Block a task with a reason | Agent |
155
+ | [`task escalate`](#nativ-task-escalate) | Escalate a contract gap to the architect | Agent |
156
+ | [`task propose-patch`](#nativ-task-propose-patch) | Propose a governed contract change | Agent |
157
+ | [`task unlock`](#nativ-task-unlock) | Lift a task's file scope in an emergency | *You only* |
158
+ | [`verify`](#nativ-verify) | Run verification for a task, a milestone or all | You, Agent |
159
+ | [`learn propose`](#nativ-learn-propose) | Propose a lesson for later workers | Agent |
160
+ | [`learn list`](#nativ-learn-list) | List lessons | You, Agent |
161
+ | [`learn approve` / `reject`](#nativ-learn-approve--reject) | Decide on a lesson | *You only* |
162
+ | [`triage`](#nativ-triage) | Evaluate pending escalations; decision cards for you | You |
163
+ | [`db status` / `inspect` / `diff`](#nativ-db-status--inspect--diff) | Masked, structure-only database checks | You, Agent |
164
+ | [`db sync`](#nativ-db-sync) | Copy a live schema into `.ai/db_schema.json` | *You only* |
165
+ | [`worktree create` / `list` / `merge` / `remove`](#nativ-worktree) | Isolated worktrees for parallel tasks | You, Agent |
166
+ | [`studio`](#nativ-studio) / `db ui` | Local dashboard at <http://localhost:4983> | You |
167
+ | [`test gen`](#nativ-test-gen) | Generate contract and database tests | You, Agent |
168
+ | [`bench`](#nativ-bench) | Synthetic benchmarks | You, Agent |
169
+ | [`mcp`](#nativ-mcp) | Run the MCP server over stdio | Claude Code |
170
+ | `hook check` / `hook context` | PreToolUse and SessionStart hooks | Hook |
171
+
172
+ [Back to contents](#contents)
173
+
174
+ ---
66
175
 
67
- Open Claude Code in the folder once and accept the workspace trust dialog. Until you do, Claude Code ignores the project's `permissions.allow` entries.
176
+ ### Setup and health
68
177
 
69
- ### 3. About the Claude Code plugin
178
+ #### `nativ init`
70
179
 
71
- You do not need the plugin. `nativ setup` writes the same agents, enforcement hook and MCP entry into your project, and also the permission rules that deny `nativ task unlock` and `nativ db sync`, block reading `.env*` files, and make Claude Code ask before any write under `.ai/`. **A plugin cannot ship permission rules**, so `nativ setup` is the complete route.
180
+ Scaffold the workflow (`.ai/`, `AGENTS.md`, directives), scan the stack into `.ai/context.md`, then run `setup`.
72
181
 
73
- The plugin files ship inside the package (`plugin/`). To try them for a single Claude Code session, point `claude --plugin-dir` at that folder under your global `node_modules` (`npm root -g` prints its location).
182
+ ```bash
183
+ nativ init [targetDir] [-f, --force]
184
+ ```
74
185
 
75
- ### 4. Work
186
+ | Option | Description |
187
+ | :--- | :--- |
188
+ | `-f, --force` | Overwrite existing specification and directive files |
76
189
 
77
- 1. Ask Claude to use the **architect** agent to design your contracts. It stops for your approval after the database schema, then the API, then the UI. Claude Code asks you to confirm every write under `.ai/`.
78
- 2. Ask Claude to run `nativ task next` and delegate each task to a **worker** agent. It works only inside the task's `targetFiles`, verifies, and completes.
79
- 3. Ask for a **verifier** pass before you call a milestone done.
190
+ #### `nativ setup`
80
191
 
81
- ### 5. Keep it healthy
192
+ Write the Claude Code configuration: `.mcp.json`, `.claude/settings.json` (permissions and hooks), `.claude/agents/`, `AGENTS.md` and `.nativ/config.json`. Safe to run any number of times.
82
193
 
83
194
  ```bash
84
- nativ doctor # checks the MCP server, hooks, permissions, agents, providers
85
- nativ doctor --fix # repairs what it can, idempotently
195
+ nativ setup [targetDir] [options]
86
196
  ```
87
197
 
88
- Run it after updating Claude Code or nativ. It also asks Claude Code itself whether the `nativ` server connects, and warns when a `nativ` server registered in your user or local scope is shadowing the project's.
198
+ | Option | Description |
199
+ | :--- | :--- |
200
+ | `--command <cli>` | How Claude Code should start nativ, e.g. `"npx -y @njeybe/nativ"` (default: `nativ` when installed globally) |
201
+ | `--enforcement <mode>` | `warn` (default), `block` or `off` |
202
+ | `--dry-run` | Show what would change without writing |
203
+ | `-f, --force` | Also replace agent and directive files you edited |
204
+ | `--json` | Output the result as JSON |
205
+
206
+ #### `nativ doctor`
89
207
 
90
- ### 6. Update
208
+ Check the integration for drift (MCP server, hooks, permissions, agents, providers) and the harness itself: settings that switch the guardrails off (`disableAllHooks`, `bypassPermissions`), credentials in files agents read (file and line only), roles with no guide, and lessons waiting for approval.
209
+
210
+ ```bash
211
+ nativ doctor [targetDir] [options]
212
+ ```
213
+
214
+ | Option | Description |
215
+ | :--- | :--- |
216
+ | `--fix` | Repair missing or out-of-date files (runs setup) |
217
+ | `--command <cli>` | How Claude Code should start nativ (see `setup`) |
218
+ | `--no-deep` | Skip asking Claude Code (`claude mcp list`) whether the server connects |
219
+ | `--json` | Output the report as JSON |
220
+
221
+ Run it after updating Claude Code or nativ.
222
+
223
+ #### `nativ update`
224
+
225
+ Refresh directives, role guides, agents and hooks that nativ wrote and you have not edited. Edited files are kept and reported. Contracts and the plan (`db_schema.json`, `api_contracts.json`, `ui_specs.md`, `master_plan.json`, `context.md`) are never touched.
91
226
 
92
227
  ```bash
93
228
  npm install -g @njeybe/nativ@latest
94
- nativ update # in each project
229
+ nativ update [targetDir] [-f, --force] # --force also replaces files you edited
95
230
  nativ doctor
96
231
  ```
97
232
 
98
- `nativ update` refreshes the directives, role guides, agents and hooks that nativ wrote and you have not edited. Anything you edited is kept and reported; `nativ update --force` replaces it. It never touches your contracts (`.ai/db_schema.json`, `.ai/api_contracts.json`, `.ai/ui_specs.md`, `.ai/master_plan.json`, `.ai/context.md`). See [CHANGELOG.md](CHANGELOG.md) before upgrading across a major version.
233
+ Read the [CHANGELOG](CHANGELOG.md) before upgrading across a major version.
234
+
235
+ #### `nativ validate`
236
+
237
+ Check that every `.ai/` contract parses and has the expected shape, that role guides exist, and that each task's `specRefs` resolve.
238
+
239
+ ```bash
240
+ nativ validate [targetDir]
241
+ ```
242
+
243
+ #### `nativ status`
244
+
245
+ Progress per milestone; with `--telemetry`, durations, token and cost estimates, pass rates and role violations.
246
+
247
+ ```bash
248
+ nativ status [targetDir] [-t, --telemetry] [--json]
249
+ ```
250
+
251
+ #### `nativ hook`
252
+
253
+ ```bash
254
+ nativ hook status [targetDir] [--json] # enforcement mode, role and active task scope
255
+ nativ hook check # PreToolUse hook (reads the tool call from stdin)
256
+ nativ hook context # SessionStart hook (prints orientation)
257
+ ```
258
+
259
+ `check` and `context` are wired by `setup`; you do not run them by hand.
260
+
261
+ [Back to contents](#contents)
99
262
 
100
263
  ---
101
264
 
102
- ## Role enforcement
265
+ ### Tasks
103
266
 
104
- `nativ hook check` runs before every `Write`, `Edit`, `MultiEdit` and `NotebookEdit`. It looks at three things:
267
+ The task lifecycle lives in `.ai/master_plan.json`. Never edit it by hand; these commands lock it, so parallel agents never lose updates.
105
268
 
106
- | Rule | Applies to | Meaning |
107
- | :--- | :--- | :--- |
108
- | `out_of_scope` | Workers and the project manager | The file is not in the active task's `targetFiles` (exact files, directories with a trailing `/`, and `*`/`**` globs) |
109
- | `protected_path` | Everyone but the architect | Anything under `.ai/` |
110
- | `secret_path` | Everyone, architect included | `.env`, `.env.*` (not `.env.example`), `.nativ/*.local.json`, `*.pem`, `*.key` |
269
+ ```
270
+ pending ──start──> in_progress ──complete (gatekeeper passes)──> completed
271
+ │
272
+ ├──block──────> blocked
273
+ └──escalate───> blocked ──(architect resolves)──> pending
274
+ ```
111
275
 
112
- Who is the architect? Inside a subagent, Claude Code reports the agent's name, so the `architect` agent (or the plugin's `nativ:architect`) is recognised. For a whole session, start it with `NATIV_ROLE=architect`.
276
+ #### `nativ task next`
113
277
 
114
- **Modes** (`"enforcement"` in `.nativ/config.json`, or `nativ setup --enforcement <mode>`):
278
+ The next executable task in the active milestone: an in-progress task first, otherwise the first pending task whose dependencies are done.
115
279
 
116
- | Mode | Behaviour |
280
+ ```bash
281
+ nativ task next [targetDir] [--json]
282
+ ```
283
+
284
+ With `--json`, the task carries everything a worker needs:
285
+
286
+ | Field | Contents |
117
287
  | :--- | :--- |
118
- | `warn` (default) | The write goes through, the agent is told why it is out of scope, and the violation is logged to `.ai/telemetry.json` |
119
- | `block` | The write is denied with the reason |
120
- | `off` | No checks |
288
+ | `roleGuide`, `recommendedContractSlice` | Which guide and which contracts the role reads |
289
+ | `recommendedModel` | `haiku`, `sonnet` or `opus`, from the task's `complexity` |
290
+ | `specSlices`, `specWarnings` | The referenced contract sections, size-capped, and any refs that did not resolve |
291
+ | `priorEscalations` | The task's settled escalations with their resolution notes (last 3) |
292
+ | `learnings` | Approved lessons that fit the task's role and files (at most 5) |
121
293
 
122
- Start in `warn`, look at the log, then switch to `block`. If a task genuinely needs to leave its scope, `nativ task unlock <taskId>` lifts the scope rule for that task (contracts and secrets stay protected) and `--revoke` restores it. Unlock is a CLI command on purpose: it is not an MCP tool, so an agent cannot remove its own guardrail.
294
+ #### `nativ task list`
123
295
 
124
- `nativ hook status` shows the mode, the role and the active task's scope. Two limits to know: the hook watches the file-editing tools, not shell commands (`sed -i` or a redirect can still write a file), and it fails open, so a broken payload never stops your work. The permission rules that `nativ setup` writes add a second layer.
296
+ ```bash
297
+ nativ task list [targetDir] [options] # also available as: nativ tasks
298
+ ```
125
299
 
126
- ---
300
+ | Option | Description |
301
+ | :--- | :--- |
302
+ | `-a, --available` | Only unblocked tasks ready to run |
303
+ | `-s, --status <status>` | `pending`, `in_progress`, `completed` or `blocked` |
304
+ | `-m, --milestone <id>` | Milestone ID or name |
305
+ | `--fast-path` | Only fast-path tasks |
306
+ | `--json` | Output as JSON |
127
307
 
128
- ## Design-first planning, task fields and model routing
308
+ #### `nativ task add`
129
309
 
130
- **Planning levels.** The `.ai/ui_specs.md` template opens with a planning level: Quick (small fix, no design phase), Standard (new screen in an existing design) or Full (new app or redesign). It then walks through the design brief, users and top tasks, real content samples, user flows, design directions with a style tile, wireframes, a component map and one section per component. The architect and frontend/flutter guides were trimmed to match.
310
+ Append a task with an auto-incremented ID.
131
311
 
132
- **UI/UX design enhancements.** The template supports two intake approaches: Experience-First (start with user flows and wireframes) or Data-First (start with entity relationships and table schemas), both leading to the same component map. The component map now organizes components into semantic trees reflecting their roles in the interface (layout, data display, input, feedback, navigation). Style tiles are stack-aware, showing platform-specific token variants for web breakpoints and Flutter platform adaptations. Typography is specified in context with font scales per platform and semantic role, mapped directly to components. Every interactive element and input carries a mutation state spec: default, hover, focus, disabled, loading, error and success states, documented in wireframe notes and component sections.
312
+ ```bash
313
+ nativ task add <title> [targetDir] [options]
314
+ ```
133
315
 
134
- **Optional task fields.** A task can carry `specRefs` (anchors such as `ui_specs.md#appointment-list`), `complexity` (`simple`, `standard` or `complex`) and `acceptanceCriteria` ("done when" lines):
316
+ | Option | Description |
317
+ | :--- | :--- |
318
+ | `-a, --agent <name>` | Role: `backend` (default), `frontend`, `database`, `qa-tester`, `flutter-developer`, `devops-agent`, `security-auditor`, `db-migration` |
319
+ | `-f, --files <paths>` | Comma-separated target files: exact files, `dir/`, or `*` / `**` globs |
320
+ | `-v, --verify <command>` | Verification command the gatekeeper runs |
321
+ | `-d, --description <text>` | Task description |
322
+ | `-m, --milestone <id>` | Target milestone (default: the active one) |
323
+ | `--deps <ids>` | Comma-separated dependency task IDs |
324
+ | `--spec-refs <refs>` | Contract anchors, e.g. `ui_specs.md#appointment-list` or `api_contracts.json#GET /appointments` |
325
+ | `--complexity <level>` | `simple`, `standard` or `complex` (routes the worker's model) |
326
+ | `--accept <text>` | "Done when" line; repeatable or `\|`-separated |
327
+ | `--fast-path` | Route to the fast-path milestone for quick fixes |
328
+ | `--json` | Output the created task as JSON |
135
329
 
136
330
  ```bash
137
- nativ task add "Appointment list" -a frontend --complexity standard --spec-refs "ui_specs.md#appointment-list" --accept "Empty state shown|Rows sorted by time"
331
+ nativ task add "Appointment list" -a frontend --complexity standard \
332
+ --spec-refs "ui_specs.md#appointment-list" \
333
+ --accept "Shows name and time per row" --accept "Empty and error states shown" \
334
+ -f src/components/AppointmentList.tsx --deps task-3 -v "npm test"
138
335
  ```
139
336
 
140
- `--accept` can be repeated or `|`-separated. The `nativ_task_add` MCP tool takes the same three fields.
337
+ #### `nativ task start`
141
338
 
142
- **Spec slices.** For a task with `specRefs`, `nativ task next --json` adds `specSlices` (the referenced heading sections or JSON pointers, size-capped) and `specWarnings` (a ref that is missing or outside `.ai/`). The native run engine puts the same slices in a `<spec_slices>` block of the worker prompt, and `nativ validate` prints the warnings for the whole plan. Workers read a whole contract only when a slice is missing or cut short.
339
+ ```bash
340
+ nativ task start <taskId> [targetDir]
341
+ ```
143
342
 
144
- **Model routing.** `nativ task next --json` returns `recommendedModel` from the task's `complexity`: `simple` gives `haiku`, `standard` gives `sonnet`, `complex` gives `opus`. A task with no complexity gets no recommendation and nothing changes. Override the mapping with `workerModels` in `.nativ/config.json`:
343
+ Marks the task `in_progress` and records the baseline the test-integrity guard compares against.
145
344
 
146
- ```json
147
- { "workerModels": { "simple": "haiku", "standard": "sonnet", "complex": "opus" } }
345
+ #### `nativ task complete`
346
+
347
+ Runs the [verification gatekeeper](#verification) and completes the task only if it passes. A change that deletes or weakens tests is refused.
348
+
349
+ ```bash
350
+ nativ task complete <taskId> [targetDir] [options]
148
351
  ```
149
352
 
150
- The run engine uses the routed model when you did not pass one explicitly, and the project manager passes `recommendedModel` as the `model` parameter of the Agent tool. These are Claude Code model aliases, so a Claude Pro login is enough and no API key is needed.
353
+ | Option | Description |
354
+ | :--- | :--- |
355
+ | `-n, --notes <notes>` | Completion notes |
356
+ | `--timeout <ms>` | Verification timeout (default 120000) |
357
+ | `--no-verify` | Skip verification. *You only*: needs an interactive terminal, is denied to agents, and the MCP tool refuses it |
151
358
 
152
- **Code style.** `AGENTS.md` gives workers short style rules: lines of 100 characters or fewer (hard maximum 120), functions of about 40 lines, files of about 300, comments of at most 2 lines, and your own formatter config wins. `nativ verify` also runs a check on a task's target files for over-long lines and long comment blocks. It only warns by default. Tune it with `codeStyle` in `.nativ/config.json` (`mode`: `warn`, `block` or `off`; `maxLineLength`, default 120; `maxCommentLines`, default 2). The `nativ task complete` gatekeeper runs it too, warn-only.
359
+ #### `nativ task block`
360
+
361
+ ```bash
362
+ nativ task block <taskId> [targetDir] -r "Verification failed after 3 attempts: <short error>"
363
+ ```
364
+
365
+ #### `nativ task escalate`
366
+
367
+ Record a contract gap in `.ai/escalation.json` and block the task until the architect resolves it.
368
+
369
+ ```bash
370
+ nativ task escalate <taskId> [targetDir] -t <type> -d "what is missing" [-a <contracts>]
371
+ ```
372
+
373
+ | Option | Description |
374
+ | :--- | :--- |
375
+ | `-t, --type <type>` | `contract_drift`, `schema_flaw`, `missing_credential`, `dependency_conflict` or `architectural_ambiguity` |
376
+ | `-d, --details <text>` | What is missing |
377
+ | `-a, --affected <list>` | Comma-separated affected contracts |
378
+
379
+ #### `nativ task propose-patch`
380
+
381
+ Propose a small contract change through the [Contract Governor](#contract-governor): additive changes are applied, destructive ones are rejected.
382
+
383
+ ```bash
384
+ nativ task propose-patch <taskId> --target db_schema --op ADD \
385
+ --path users.columns.bio --value '{"type":"text","nullable":true}' -r "profile bio"
386
+ ```
387
+
388
+ | Option | Description |
389
+ | :--- | :--- |
390
+ | `--target <target>` | `db_schema` or `api_contracts` (required) |
391
+ | `--op <op>` | `ADD`, `ALTER`, `DROP` or `RENAME` (required) |
392
+ | `--path <path>` | Dot or pointer path, e.g. `users.columns.status` (required) |
393
+ | `--value <json>` | Value or schema definition |
394
+ | `-r, --reason <text>` | Why (required) |
395
+ | `--base-hash <hash>` | Reject if the contract changed since this hash |
396
+ | `--json` | Output the verdict as JSON |
397
+
398
+ #### `nativ task unlock`
399
+
400
+ *You only, in an interactive terminal.* Lift the file-scope rule for one task when it genuinely must leave its `targetFiles`. Contracts and secrets stay protected. `--revoke` re-locks and works anywhere.
401
+
402
+ ```bash
403
+ nativ task unlock <taskId> [targetDir] -r "refactor touches a shared file"
404
+ nativ task unlock <taskId> --revoke
405
+ ```
406
+
407
+ [Back to contents](#contents)
153
408
 
154
409
  ---
155
410
 
156
- ## Providers
411
+ ### Verification
157
412
 
158
- nativ's own model calls (currently triage of escalations) go through one adapter, so no single vendor is on the critical path.
413
+ #### `nativ verify`
159
414
 
160
- Default order: `claude-cli`, `claude-api`, `gemini`, then a deterministic rules engine.
415
+ Re-run verification for one task, a milestone or every completed task. Also available as `nativ task verify`.
161
416
 
162
- | Provider | Needs | Notes |
163
- | :--- | :--- | :--- |
164
- | `claude-cli` | Claude Code signed in | Runs `claude -p` with your subscription login. No API key. Uses Haiku by default, with all tools disabled, from an empty working directory |
165
- | `claude-api` | `ANTHROPIC_API_KEY` | Anthropic SDK |
166
- | `gemini` | `GEMINI_API_KEY` or `GOOGLE_API_KEY` | The key is sent in a header, never the URL |
417
+ ```bash
418
+ nativ verify task-01
419
+ nativ verify --milestone m1 --timeout 60000
420
+ nativ verify --all --json
421
+ ```
422
+
423
+ | Option | Description |
424
+ | :--- | :--- |
425
+ | `-a, --all` | Every completed task |
426
+ | `-m, --milestone <id>` | Every task in a milestone |
427
+ | `--timeout <ms>` | Per command (default 120000) |
428
+ | `--json` | Output as JSON |
167
429
 
168
- If a provider reports a rate or usage limit, nativ remembers it in `.nativ/provider-state.json` and skips that provider until the limit resets, so a limit costs seconds, not a long wait. If nothing is available, triage still answers from the offline rules engine. Prompts pass through secret redaction before leaving the machine.
430
+ **What runs, in order** (the same for `verify`, the `task complete` gatekeeper and Studio dispatch):
169
431
 
170
- Choose providers and models per role in `.nativ/config.json`:
432
+ 1. **Verify phases** from `.nativ/config.json`, in order, stopping at the first failure. A failure names the phase.
433
+ 2. The task's own `verificationCommand`.
434
+ 3. The **code-style check** on the task's target files (warn-only unless `codeStyle.mode` is `block`).
171
435
 
172
436
  ```json
173
- {
174
- "enforcement": "warn",
175
- "providers": { "triage": ["claude-cli", "gemini"] },
176
- "models": { "claude-cli": "haiku", "gemini": "gemini-3.8-flash" }
177
- }
437
+ { "verifyPhases": [
438
+ { "name": "types", "run": "npx tsc --noEmit" },
439
+ { "name": "lint", "run": "npm run lint" }
440
+ ] }
178
441
  ```
179
442
 
180
- Roles are `architect`, `pm`, `worker`, `verifier` and `triage`. Adding a vendor means adding one file under `src/providers/`.
443
+ With no phases configured, verification is just the task's command and the style check. The settings always come from the main checkout, never a task worktree's copy. If `.nativ/config.json` cannot be read, or a phase has no `name` or `run`, verification fails with a clear message instead of skipping the checks.
444
+
445
+ [Back to contents](#contents)
181
446
 
182
447
  ---
183
448
 
184
- ## CLI reference
449
+ ### Learnings
185
450
 
186
- ### Setup and health
451
+ Lessons from earlier tasks that the contracts do not capture: a setup quirk, a library gotcha, a convention. Agents propose; only you approve. Stored in `.ai/learnings.json`.
452
+
453
+ #### `nativ learn propose`
187
454
 
188
455
  ```bash
189
- nativ init # scaffold .ai/ and run setup
190
- nativ setup [--dry-run] [--enforcement warn|block|off] [--command "npx -y @njeybe/nativ"] [--force]
191
- nativ doctor [--fix] [--no-deep] [--json]
192
- nativ hook status [--json] # enforcement mode, role, active task scope
456
+ nativ learn propose "<one-line insight>" [targetDir] [options]
193
457
  ```
194
458
 
195
- ### Task management and JIT context slicing
459
+ | Option | Description |
460
+ | :--- | :--- |
461
+ | `--role <role>` | Only workers with this role see it |
462
+ | `--files <globs>` | Comma-separated files, `dir/` or globs; only tasks touching them see it |
463
+ | `--task <taskId>` | The task where it came up |
464
+ | `-d, --details <text>` | Longer explanation |
465
+ | `--by <who>` | Who proposed it (default: `NATIV_ROLE`) |
466
+ | `--json` | Output the stored lesson as JSON |
196
467
 
197
468
  ```bash
198
- nativ task next # next executable task and its contract slice
199
- nativ task list --available
200
- nativ task list --milestone m1 --status pending
201
- nativ task add "Implement OAuth2 callback" -a backend -v "npm test" -f "src/auth.ts"
202
- nativ task add "Login form" -a frontend --complexity simple --spec-refs "ui_specs.md#login-form" --accept "Errors shown inline"
203
- nativ task start task-01
204
- nativ task complete task-01 # runs the verification command
205
- nativ task complete task-01 --timeout 600000 # for slow suites
206
- nativ task block task-01 --reason "Missing Stripe API key"
207
- nativ task escalate task-01 --type schema_flaw --details "Missing foreign key on orders table"
208
- nativ task propose-patch task-01 --target db_schema --op ADD --path users.columns.bio --reason "..."
209
- nativ task unlock task-01 --reason "refactor touches a shared file" # emergency; --revoke to re-lock
210
- nativ triage # evaluate pending escalations; decision cards for the human
469
+ nativ learn propose "Set the date picker locale before it mounts" \
470
+ --role frontend --files "src/components/forms/" --task task-12
211
471
  ```
212
472
 
213
- ### Verification
473
+ #### `nativ learn list`
214
474
 
215
475
  ```bash
216
- nativ verify task-01
217
- nativ verify --all
218
- nativ verify --milestone m1 --timeout 60000 --json
476
+ nativ learn list [targetDir] [-s, --status proposed|approved|rejected] [--role <role>] [--json]
219
477
  ```
220
478
 
221
- ### Status and telemetry
479
+ #### `nativ learn approve` / `reject`
480
+
481
+ *You only, in an interactive terminal.* Both show the full lesson (insight, details, scope) and ask you to confirm; `-y` skips the question but not the terminal check, so a headless agent cannot run them.
222
482
 
223
483
  ```bash
224
- nativ status
225
- nativ status --telemetry # durations, token estimates, cost estimates, pass rates, role violations
226
- nativ status --json
484
+ nativ learn approve learn-01 [-n "confirmed on two tasks"] [-y]
485
+ nativ learn reject learn-02 [-n "one-off, not a rule"] [-y]
227
486
  ```
228
487
 
229
- ### Benchmarks
488
+ If the lesson changed while you were reviewing it, nothing is decided and you are asked to run the command again. `.ai/learnings.json` is protected like the contracts: the hook flags agent edits and Claude Code asks you before any write under `.ai/`. An approved lesson travels with `nativ task next` to the tasks it fits: lessons scoped to the task's files first, then to its role, then project-wide ones, at most five.
489
+
490
+ [Back to contents](#contents)
491
+
492
+ ---
493
+
494
+ ### Escalations and triage
495
+
496
+ A worker that finds a contract gap escalates (`nativ task escalate`) and stops. The gap is then resolved by the architect, or first assessed by triage.
497
+
498
+ #### `nativ triage`
499
+
500
+ Run the strategist (Claude by default, see [Providers](#providers)) on pending escalations: it proves safe additive fixes in a sandbox, or gives you a four-part decision card (what the user would see, why, what is affected, options).
230
501
 
231
502
  ```bash
232
- nativ bench
233
- nativ bench --scenario concurrency --concurrency 8
234
- nativ bench --json
503
+ nativ triage [escalationId] [targetDir] [options]
235
504
  ```
236
505
 
237
- ### Studio
506
+ | Option | Description |
507
+ | :--- | :--- |
508
+ | `-a, --all` | Triage every pending escalation (report only, no prompts) |
509
+ | `--apply` | Write sandbox-proven additive patches and unblock their tasks |
510
+ | `--threshold <policy>` | `safe_contracts_only` (default) or `all_non_destructive` |
511
+ | `--json` | Output evaluations as JSON (no prompts) |
512
+
513
+ When an escalation is settled, its resolution notes reach the next worker on that task as `priorEscalations`.
238
514
 
239
- `nativ studio` runs a local dashboard at http://localhost:4983 with live updates. It loads
240
- nothing from the internet and runs under a strict content security policy. The sidebar
241
- groups pages by role.
515
+ [Back to contents](#contents)
516
+
517
+ ---
242
518
 
243
- **Home** shows what needs you, what's running now, and what just finished.
244
- **Tasks** displays one milestone at a time, sorted newest completed first.
245
- **Flow** shows how the work connects and visualizes how the run really happened.
246
- **Team** lists each agent's activity in plain terms: tasks done, time spent, cost.
247
- **Worktrees, Benchmarks, Database** are system tools for branches, performance and schemas.
519
+ ### Database
248
520
 
249
- Press Ctrl+K (or Cmd+K or /) to find any task by id, title, agent or file name. The theme
250
- toggle switches between light and dark; your choice is saved locally.
521
+ Masked and structure-only: credentials stay inside the local nativ process, and row data is never read. Connections come from your `.env` files; see [Environment variables](#environment-variables).
251
522
 
252
- ### Database studio and schema telemetry (masked, structure only)
523
+ #### `nativ db status` / `inspect` / `diff`
253
524
 
254
525
  ```bash
255
- nativ db status
256
- nativ db inspect --env dev
257
- nativ db diff --target contract --exit-code
258
- nativ studio # local dashboard at http://localhost:4983
526
+ nativ db status [--json] # dev/prod health, engine, latency, table count
527
+ nativ db inspect [-e dev|prod] [-t <table>] [--json] # columns, types, keys, indexes
528
+ nativ db diff [--target prod|contract] [--exit-code] # drift; --exit-code fails CI on drift
259
529
  ```
260
530
 
261
- ### Git worktree sandboxing
531
+ `nativ db diff --target contract` compares the dev database with `.ai/db_schema.json`.
532
+
533
+ #### `nativ db sync`
534
+
535
+ *You only.* Copy a live schema (structure only) into `.ai/db_schema.json`. It previews unless `--yes` is given, and `--yes` needs an interactive terminal; changing the contract is an architect decision you approve.
536
+
537
+ ```bash
538
+ nativ db sync [-s dev|prod] # preview
539
+ nativ db sync --yes # write
540
+ ```
541
+
542
+ [Back to contents](#contents)
543
+
544
+ ---
545
+
546
+ ### Worktrees
547
+
548
+ #### `nativ worktree`
549
+
550
+ Run independent tasks in parallel, each in its own git worktree with the `.ai/` contracts mounted.
262
551
 
263
552
  ```bash
264
- nativ worktree create task-01
265
- nativ worktree list
266
- nativ worktree merge task-01 # Safe Merge Gatekeeper enforced
267
- nativ worktree remove task-01
553
+ nativ worktree create <taskId> [--json]
554
+ nativ worktree list [--json]
555
+ nativ worktree merge <taskId> [-f] [--json] # Safe Merge Gatekeeper; -f bypasses it
556
+ nativ worktree remove <taskId> [-f] [--json] # alias: cleanup; discards the branch
268
557
  ```
269
558
 
559
+ Parallel agents share your Claude usage limit; two or three at a time is a sensible default on a subscription.
560
+
561
+ [Back to contents](#contents)
562
+
270
563
  ---
271
564
 
272
- ## Contract Governor
565
+ ### Studio, tests and benchmarks
273
566
 
274
- A deterministic firewall between agents and the contracts (`.ai/db_schema.json`, `.ai/api_contracts.json`):
567
+ #### `nativ studio`
275
568
 
569
+ A local dashboard at <http://localhost:4983> with live updates. It loads nothing from the internet and runs under a strict content security policy. Also available as `nativ db ui`.
570
+
571
+ ```bash
572
+ nativ studio [targetDir] [-p, --port <port>] [--no-open]
276
573
  ```
277
- An agent proposes a contract change
278
- |
279
- v
280
- [ Contract Governor ]
281
- |
282
- +-----------------+------------------+
283
- v v
284
- LOW_ADDITIVE HIGH_DESTRUCTIVE
285
- new nullable columns, new tables, dropping tables or columns,
286
- optional params, new response fields changing column types, dropping
287
- routes, new required params
288
- | |
289
- v v
290
- auto-approved and patched rejected with a structured
291
- atomically violation; three strikes trip the
292
- circuit breaker and log an escalation
574
+
575
+ | Page | Shows |
576
+ | :--- | :--- |
577
+ | **Home** | What needs you, what is running, what just finished |
578
+ | **Tasks** | One milestone at a time, newest completed first |
579
+ | **Flow** | How the work connects and how the run actually happened |
580
+ | **Team** | Each agent's tasks, time and cost |
581
+ | **Worktrees, Benchmarks, Database** | Branches, performance and schemas |
582
+
583
+ Press **Ctrl+K** (or Cmd+K or `/`) to find any task by id, title, agent or file. The theme toggle switches light and dark.
584
+
585
+ #### `nativ test gen`
586
+
587
+ Generate API contract and database integrity tests from `.ai/api_contracts.json` and `.ai/db_schema.json`.
588
+
589
+ ```bash
590
+ nativ test gen [targetDir] [options]
293
591
  ```
294
592
 
593
+ | Option | Description |
594
+ | :--- | :--- |
595
+ | `-f, --framework <name>` | `vitest` (default), `jest`, `node:test`, `pytest` or `go` |
596
+ | `-o, --output <dir>` | Output directory (default `tests/contract`) |
597
+ | `-b, --base-url <url>` | Base URL the API suites call (default `http://localhost:3000`) |
598
+ | `--dry-run` | Show what would be generated |
599
+ | `--json` | Output the result as JSON |
600
+
601
+ #### `nativ bench`
602
+
603
+ ```bash
604
+ nativ bench [-s concurrency|governor|verification|telemetry|e2e|all] [-c <workers>] [-o report.json] [--json]
605
+ ```
606
+
607
+ #### `nativ mcp`
608
+
609
+ Run the MCP server over stdio. `setup` registers it; see [MCP server](#mcp-server).
610
+
611
+ [Back to contents](#contents)
612
+
295
613
  ---
296
614
 
297
- ## Concurrency
615
+ ## Configuration
298
616
 
299
- `.ai/master_plan.json` and `.ai/telemetry.json` are protected by OS-level advisory file locks (`proper-lockfile`) with atomic read-modify-write and retry backoff for Windows `EBUSY`/`EPERM`. Several agents in separate terminals can start, complete and add tasks without lost updates. Long verification commands run outside the lock.
617
+ ### `.nativ/config.json`
300
618
 
301
- Parallel agents share your Claude usage limit. Two or three at a time is a sensible default on a subscription.
619
+ Written by `setup`; every key is optional.
620
+
621
+ ```json
622
+ {
623
+ "enforcement": "warn",
624
+ "workerModels": { "simple": "haiku", "standard": "sonnet", "complex": "opus" },
625
+ "verifyPhases": [{ "name": "types", "run": "npx tsc --noEmit" }],
626
+ "codeStyle": { "mode": "warn", "maxLineLength": 120, "maxCommentLines": 2 },
627
+ "providers": { "triage": ["claude-cli", "gemini"] },
628
+ "models": { "claude-cli": "haiku", "gemini": "gemini-3.8-flash" }
629
+ }
630
+ ```
631
+
632
+ | Key | Default | Meaning |
633
+ | :--- | :--- | :--- |
634
+ | `enforcement` | `warn` | Role enforcement mode: `warn`, `block` or `off`. See [Guardrails](#guardrails) |
635
+ | `workerModels` | as above | Model per task `complexity`, returned as `recommendedModel` |
636
+ | `verifyPhases` | none | Checks run before every task's own command. See [Verification](#verification) |
637
+ | `codeStyle.mode` | `warn` | `warn`, `block` or `off` for the line-length and comment check |
638
+ | `codeStyle.maxLineLength` | `120` | Longest allowed line |
639
+ | `codeStyle.maxCommentLines` | `2` | Longest allowed comment block |
640
+ | `providers` | see [Providers](#providers) | Provider order per role: `architect`, `pm`, `worker`, `verifier`, `triage` |
641
+ | `models` | provider default | Model per provider |
642
+
643
+ ### Environment variables
644
+
645
+ | Variable | Used for |
646
+ | :--- | :--- |
647
+ | `NATIV_ROLE` | Session role; `NATIV_ROLE=architect` lets a whole session write `.ai/` |
648
+ | `ANTHROPIC_API_KEY` | The `claude-api` provider and the Studio native runner |
649
+ | `GEMINI_API_KEY` or `GOOGLE_API_KEY` | The `gemini` provider |
650
+ | `NATIV_DEV_DATABASE_URL`, `DEV_DATABASE_URL`, `DATABASE_URL` | Dev database for `nativ db`, checked in that order, read from your `.env*` files. MongoDB (`MONGODB_URI`) and Firestore variants work too, and names declared in `.env.example` are checked first |
651
+ | `NATIV_PROD_DATABASE_URL`, `PROD_DATABASE_URL`, `DATABASE_URL_PROD` | Prod database for `nativ db`, same rules |
652
+
653
+ [Back to contents](#contents)
302
654
 
303
655
  ---
304
656
 
305
- ## Telemetry
657
+ ## Guardrails
658
+
659
+ ### Role enforcement
660
+
661
+ `nativ hook check` runs before every `Write`, `Edit`, `MultiEdit` and `NotebookEdit`.
662
+
663
+ | Rule | Applies to | Meaning |
664
+ | :--- | :--- | :--- |
665
+ | `out_of_scope` | Workers and the project manager | The file is not in the active task's `targetFiles` |
666
+ | `protected_path` | Everyone but the architect | Anything under `.ai/` |
667
+ | `protected_path` | Everyone, architect included | Anything under `.nativ/`: the settings decide what the gate runs and how strict the hook is |
668
+ | `secret_path` | Everyone, architect included | `.env`, `.env.*` (not `.env.example`), `.nativ/*.local.json`, `*.pem`, `*.key` |
306
669
 
307
- Task transitions and role violations are recorded in `.ai/telemetry.json`: durations, token estimates priced with the model table in `src/core/telemetry.ts`, verification pass rates, circuit-breaker trips, and (capped at the latest 200) enforcement violations with the rule, mode, tool, project-relative path and task. File contents are never logged.
670
+ | Mode | Behaviour |
671
+ | :--- | :--- |
672
+ | `warn` (default) | The write goes through, the agent is told why, and the violation is logged to `.ai/telemetry.json` |
673
+ | `block` | The write is denied with the reason |
674
+ | `off` | No checks |
675
+
676
+ Start in `warn`, look at the log, then switch to `block`. Two limits: the hook watches file-editing tools, not shell commands (`sed -i` can still write a file), and it fails open, so a broken payload never stops your work.
677
+
678
+ ### Permission rules
679
+
680
+ `setup` adds rules that Claude Code enforces even under a broad `nativ *` allow:
681
+
682
+ | Rule | Effect |
683
+ | :--- | :--- |
684
+ | Deny `nativ task unlock`, `nativ db sync`, `nativ task complete --no-verify` | Agents cannot lift their own guardrails or rewrite the schema |
685
+ | Deny `nativ learn approve`, `nativ learn reject` | Agents cannot approve their own lessons (the commands also refuse to run without a terminal) |
686
+ | Deny reading `.env*`, `*.pem`, `*.key` | Secrets stay out of agent context |
687
+ | Ask before `Edit` or `Write` under `.ai/` and `.nativ/` | Every contract or settings change needs your yes |
688
+
689
+ Studio's native runner runs headless, so the terminal-only commands refuse there too. Its editor cannot write `.ai/` or `.nativ/` (in any letter case), and its shell refuses commands that name `.nativ/`. The shell check is a best-effort guard against mistakes, not a sandbox: a worker that runs `node` or other programs can still reach any file the process can. Run untrusted work in a container or VM.
690
+
691
+ ### Air-gap
692
+
693
+ Credentials exist only in `.env*` files and inside the local nativ process. Agents use the masked, structure-only `nativ db` commands and never read row data. Migrations and destructive changes run only against local or staging databases, and any `[DROPPED]` or `[DESTRUCTIVE]` diff goes to you.
694
+
695
+ ### Contract Governor
696
+
697
+ A deterministic firewall between agents and the contracts:
698
+
699
+ ```
700
+ An agent proposes a contract change
701
+ |
702
+ [ Contract Governor ]
703
+ |
704
+ +-----------------+------------------+
705
+ v v
706
+ LOW_ADDITIVE HIGH_DESTRUCTIVE
707
+ new nullable columns, new tables, dropping tables or columns,
708
+ optional params, new response fields changing types, dropping routes,
709
+ new required params
710
+ | |
711
+ v v
712
+ applied atomically rejected with a structured violation;
713
+ three strikes trip the circuit breaker
714
+ and log an escalation
715
+ ```
716
+
717
+ [Back to contents](#contents)
718
+
719
+ ---
720
+
721
+ ## Files nativ manages
722
+
723
+ | Path | Written by | Contents |
724
+ | :--- | :--- | :--- |
725
+ | `AGENTS.md` | setup | The directive every agent follows |
726
+ | `CLAUDE.md`, `GEMINI.md` | setup | Pointers to `AGENTS.md` (only created when absent) |
727
+ | `.mcp.json` | setup | The `nativ` MCP server entry |
728
+ | `.claude/settings.json` | setup | Permission rules and the enforcement and orientation hooks |
729
+ | `.claude/agents/` | setup | `architect`, `worker`, `verifier` and `explorer` |
730
+ | `.nativ/config.json` | setup | [Configuration](#configuration) |
731
+ | `.ai/context.md` | init | Stack scan: runtime, framework, ORM, main folders |
732
+ | `.ai/codebase_map.md` | architect, from the explorer | Map of existing code, stamped with the commit it describes |
733
+ | `.ai/db_schema.json`, `.ai/api_contracts.json`, `.ai/ui_specs.md` | architect | The contracts |
734
+ | `.ai/design/style-tile.html` | architect | The chosen visual direction |
735
+ | `.ai/master_plan.json` | `nativ task` commands | Milestones and tasks |
736
+ | `.ai/subagents/*.md` | init, update | One guide per worker role |
737
+ | `.ai/escalation.json` | `task escalate`, triage | Escalations and how they were settled |
738
+ | `.ai/learnings.json` | `nativ learn` | Proposed, approved and rejected lessons |
739
+ | `.ai/telemetry.json` | nativ | Durations, costs, pass rates, role violations |
740
+
741
+ Files nativ wrote carry a marker, so `update` and `doctor` can tell untouched files from ones you edited.
742
+
743
+ [Back to contents](#contents)
308
744
 
309
745
  ---
310
746
 
311
747
  ## MCP server
312
748
 
313
- `nativ mcp` speaks the Model Context Protocol over stdio. `nativ setup` registers it for Claude Code; the same server works with Cursor, Claude Desktop and Antigravity.
749
+ `nativ mcp` speaks the Model Context Protocol over stdio. `setup` registers it for Claude Code; the same server works with Cursor, Claude Desktop and Antigravity.
314
750
 
315
- | Tool / resource | Description |
751
+ | Tools | Purpose |
316
752
  | :--- | :--- |
317
753
  | `nativ_task_next`, `nativ_task_list`, `nativ_task_add` | Find and add work |
318
- | `nativ_task_start`, `nativ_task_complete`, `nativ_task_block` | Move a task through its lifecycle (complete runs the gatekeeper and refuses skipVerify) |
319
- | `nativ_task_escalate`, `nativ_task_propose_patch` | Escalate a contract gap, or propose a governed patch |
320
- | `nativ_verify`, `nativ_bench`, `nativ_status` | Verification, benchmarks, progress |
321
- | `nativ_worktree_*` | Create, list, merge and remove task worktrees |
322
- | `nativ_db_status`, `nativ_db_inspect`, `nativ_db_diff` | Masked, structure-only database telemetry |
323
- | `nativ_doctor` | Read-only health report. Repairs are `nativ doctor --fix` in a terminal |
324
- | `nativ://context`, `nativ://master-plan`, `nativ://db-schema`, `nativ://api-contracts`, `nativ://escalation`, `nativ://telemetry` | Read-only resources |
754
+ | `nativ_task_start`, `nativ_task_complete`, `nativ_task_block` | Move a task through its lifecycle (complete always runs the gatekeeper) |
755
+ | `nativ_task_escalate`, `nativ_task_propose_patch` | Escalate a gap or propose a governed patch |
756
+ | `nativ_learn_propose` | Propose a lesson; you approve it in a terminal |
757
+ | `nativ_verify`, `nativ_status`, `nativ_bench`, `nativ_test_gen` | Verification, progress, benchmarks, test generation |
758
+ | `nativ_worktree_create`, `_list`, `_merge`, `_remove` | Task worktrees |
759
+ | `nativ_db_status`, `nativ_db_inspect`, `nativ_db_diff` | Masked, structure-only database checks |
760
+ | `nativ_init`, `nativ_doctor` | Scaffold, and a read-only health report |
325
761
 
326
- There is deliberately no MCP tool to unlock a task, write a contract, sync a database schema or run setup.
762
+ | Resources (read-only) |
763
+ | :--- |
764
+ | `nativ://context`, `nativ://master-plan`, `nativ://db-schema`, `nativ://api-contracts`, `nativ://escalation`, `nativ://telemetry` |
327
765
 
328
- Manual registration, if you prefer:
766
+ There is deliberately no MCP tool to unlock a task, approve a lesson, write a contract, sync a database schema or run setup.
767
+
768
+ **Manual registration:**
329
769
 
330
770
  ```bash
331
771
  claude mcp add nativ -- nativ mcp
@@ -339,31 +779,77 @@ claude mcp add nativ -- nativ mcp
339
779
  }
340
780
  ```
341
781
 
782
+ [Back to contents](#contents)
783
+
784
+ ---
785
+
786
+ ## Providers
787
+
788
+ nativ's own model calls (triage of escalations) go through one adapter, so no single vendor is on the critical path. Default order: `claude-cli`, `claude-api`, `gemini`, then a deterministic rules engine.
789
+
790
+ | Provider | Needs | Notes |
791
+ | :--- | :--- | :--- |
792
+ | `claude-cli` | Claude Code signed in | Uses your subscription login, no API key. Haiku by default, tools disabled, empty working directory |
793
+ | `claude-api` | `ANTHROPIC_API_KEY` | Anthropic SDK |
794
+ | `gemini` | `GEMINI_API_KEY` or `GOOGLE_API_KEY` | The key goes in a header, never the URL |
795
+
796
+ A provider that hits a usage limit is remembered in `.nativ/provider-state.json` and skipped until it resets. If none is available, triage still answers from the offline rules engine. Prompts pass through secret redaction before leaving the machine.
797
+
798
+ [Back to contents](#contents)
799
+
800
+ ---
801
+
802
+ ## Concurrency and telemetry
803
+
804
+ - **Locks.** `.ai/master_plan.json`, `.ai/telemetry.json`, `.ai/escalation.json` and `.ai/learnings.json` use OS-level advisory locks with atomic writes and retry backoff for Windows `EBUSY`/`EPERM`. Agents in separate terminals can start, complete and add tasks without lost updates. Long verification runs outside the lock.
805
+ - **Telemetry.** `.ai/telemetry.json` records task durations, token and cost estimates, verification pass rates, circuit-breaker trips and the latest 200 enforcement violations (rule, mode, tool, path, task). File contents are never logged. View it with `nativ status --telemetry` or in Studio.
806
+
807
+ [Back to contents](#contents)
808
+
342
809
  ---
343
810
 
344
- ## Repository structure
811
+ ## Troubleshooting
812
+
813
+ | Symptom | Fix |
814
+ | :--- | :--- |
815
+ | Claude Code ignores the project's permissions | Open Claude Code in the folder and accept the trust dialog |
816
+ | `doctor` reports missing or out-of-date files | `nativ doctor --fix` |
817
+ | `doctor` fails on `disableAllHooks` | Remove it from `.claude/settings.json` or `.claude/settings.local.json`; enforcement is off while it is set |
818
+ | The MCP server does not connect | `nativ doctor` (it asks `claude mcp list`); check for a `nativ` server in your user scope shadowing the project's |
819
+ | The generated config points at a path on your machine | Install globally, or `nativ setup --command "npx -y @njeybe/nativ"` |
820
+ | A worker keeps editing outside its task | Switch to `"enforcement": "block"`; a genuine need is an escalation, or `nativ task unlock` |
821
+ | `task complete` fails in a phase | The output names it; run that phase's command yourself to see the error |
822
+ | Triage says no provider | Sign in to Claude Code, or set `ANTHROPIC_API_KEY` or `GEMINI_API_KEY`; the offline rules engine still answers |
823
+
824
+ [Back to contents](#contents)
825
+
826
+ ---
827
+
828
+ ## For maintainers
345
829
 
346
830
  ```
347
831
  nativ/
348
- bin/cli.js entry point (a fast path serves the hook commands without loading the whole CLI)
832
+ bin/cli.js entry point (a fast path serves the hooks without loading the whole CLI)
349
833
  src/
350
834
  index.ts command registry
351
- commands/ init, setup, doctor, hook, task, verify, worktree, db, triage, ...
352
- core/ enforcement, setup-assets, tier1-liaison, telemetry, lock-manager, verifier, ...
835
+ commands/ init, setup, doctor, task, verify, learn, worktree, db, triage, ...
836
+ core/ enforcement, verifier, learnings, harness-integrity, setup-assets, telemetry, ...
353
837
  providers/ claude-cli, claude-api, gemini, registry (fallback chain and cooldown)
354
- governor/ contract evaluator, circuit breaker, rules
838
+ governor/ contract evaluator, circuit breaker, rules, escalation store
355
839
  mcp/server.ts MCP server
356
840
  db/ masked env parser, introspection, schema diff
357
- server/ Studio web dashboard
358
- runner/ agent supervisor
841
+ server/ Studio dashboard
842
+ runner/ agent supervisor (Studio dispatch)
359
843
  templates/ AGENTS.md, CLAUDE.md, GEMINI.md, claude-agents/, dot-ai/
360
844
  plugin/ Claude Code plugin (generated by `npm run sync-plugin`)
361
- .claude-plugin/ marketplace entry for the plugin
362
- scripts/sync-plugin.mjs renders plugin/ from the same sources as `nativ setup`
363
845
  tests/ regression suites (`npm test`)
364
846
  ```
365
847
 
366
- Changed a template or the setup generator? Run `npm run sync-plugin`; a test fails if `plugin/` is out of date.
848
+ ```bash
849
+ npm install && npm run build
850
+ npm test
851
+ npm run sync-plugin # after changing a template or the setup generator; a test fails if plugin/ is stale
852
+ ```
367
853
 
368
854
  ---
369
855