feat: instance manifest, tool profiles, metrics, and budget enforcement

Land HARNESS-WP-0001 T01/T02/T04/T05: extend ADR-005 schedule.yml with
harness fields, named tool-profile registry, ADR-004 metrics writes, and
BudgetTracker wiring. CLI gains validate/profiles; task-file path kept.
This commit is contained in:
tegwick 2026-07-17 23:49:03 +02:00
parent 16f5c29c08
commit 4144eba160
17 changed files with 1387 additions and 60 deletions

View file

@ -32,25 +32,27 @@
| Component | File | Today | Target |
|---|---|---|---|
| Instance manifest | `manifest.py` | extends `.kaizen/schedule.yml`; `validate` CLI | unchanged contract; tenant onboarding |
| Tool profiles | `profiles.py` | `green-commit-only`, `blue-mail-triage` registry | additional named profiles as needed |
| Task intake | `taskspec.py` | JSON task-spec file | poll issue-core sink / TaskExecutorWorkflow |
| Persona | `persona.py` | `kaizen-agentic schedule prepare` (ADR-005) | unchanged, plus phase-memory profile hook |
| Session | `adapter.py` | `AgenticClaudeCodeAdapter` (llm-connect subclass, cwd-pinned, hard allow-list) | + hosted adapters; tool profiles (below) |
| Orchestration | `runner.py` | HEAD snapshot → session → commit check → report | + budget enforcement, kaizen metrics write |
| Session | `adapter.py` | `AgenticClaudeCodeAdapter` (cwd-pinned, profile allow-list) | + hosted adapters |
| Orchestration | `runner.py` | profile/budget → session → commit → metrics → hub | activity-core intake |
| Metrics | `metrics.py` | ADR-004 `.kaizen/metrics` write per run | correlate with Helix fleet metrics |
| Mail lane | `mailscan.py` | deterministic credentialed pre-step outside the session | pattern generalizes to other credentialed pre-steps |
| Hub reporting | `hub.py` | REST progress event + task close | unchanged |
| Hub reporting | `hub.py` | REST progress event + task close + token event | unchanged |
## Contracts
**Instance manifest** (in the consuming repo; `.kaizen/schedule.yml` today,
extended per-agent fields as the manifest spec lands in HARNESS-WP-0001):
blueprint name, cadence, `enabled`, plus target additions: `lane`
(green/blue), `tool_profile` (named, defined here), `budget`
(tokens/run), `harness` (pinned major version).
**Instance manifest** — `.kaizen/schedule.yml` (ADR-005 base + harness
extensions). Full contract: [instance-manifest.md](instance-manifest.md).
Fields: blueprint, cadence, `enabled`, `lane` (green/blue),
`tool_profile` (named), `budget` (tokens/run), `harness` (pinned major).
**Tool profiles** are named allow-lists defined centrally in the harness,
referenced by name from manifests — instances never enumerate tools.
Seed profile `green-commit-only` = Read/Write/Edit/Glob/Grep + local git
add/commit/status/log/diff. No push, no network, no arbitrary shell.
**Tool profiles** are named allow-lists defined centrally in the harness
(`profiles.py`), referenced by name from manifests — instances never
enumerate tools. Seed: `green-commit-only`, `blue-mail-triage`. No push,
no network, no arbitrary shell. Unknown profile = refuse to run.
**Completion events** are the idempotence currency: each run posts a
progress event (e.g. `binky_daily_brief`, `binky_mail_intake`) with

105
docs/instance-manifest.md Normal file
View file

@ -0,0 +1,105 @@
# Instance manifest
> Contract for declarative agent instances in consuming repos.
> Companion to ADR-001, ADR-005 (kaizen-agentic), and HARNESS-WP-0001-T01.
## Location
```
<project-root>/.kaizen/schedule.yml
```
**Same file as ADR-005.** kaizen-agentic owns the base schedule keys;
agent-harness owns the extension keys below. A sibling file is reserved
only if kaizen owners later prefer hard separation — until then, one
manifest keeps cadence and runtime policy colocated.
Validate:
```bash
kaizen-agentic schedule validate --target <repo> # base ADR-005 keys
agent-harness validate --target <repo> # base + harness extensions
agent-harness validate --target <repo> --strict # require harness fields on enabled agents
```
## Schema
| Key | Owner | Required | Type | Notes |
|-----|-------|----------|------|-------|
| `version` | kaizen | yes | string | Must be `"1"` |
| `timezone` | kaizen | no | string | IANA tz |
| `harness` | harness | no\* | int | Pinned harness **major** for the repo |
| `agents` | both | yes | mapping | `name → settings` |
| `agents.<name>.cadence` | kaizen | yes | enum | `daily` \| `weekly` \| `monthly` |
| `agents.<name>.cron` | kaizen | no | string | 5-field cron override |
| `agents.<name>.enabled` | kaizen | no | bool | Default `true` |
| `agents.<name>.blueprint` | harness | no | string | Defaults to agent name (kaizen blueprint) |
| `agents.<name>.lane` | harness | no\* | enum | `green` \| `blue` |
| `agents.<name>.tool_profile` | harness | no\* | string | Named profile in the harness registry |
| `agents.<name>.budget` | harness | no | int | Token cap per run (positive) |
| `agents.<name>.harness` | harness | no | int | Per-agent major pin; overrides top-level |
\* Required for enabled agents under `agent-harness validate --strict`.
## Example (tenant-ready)
```yaml
# .kaizen/schedule.yml — ADR-005 + agent-harness extensions
version: "1"
timezone: Europe/Berlin
harness: 0
agents:
coach:
cadence: daily
cron: "0 7 * * 1-5"
enabled: true
lane: green
tool_profile: green-commit-only
budget: 80000
mail-triage:
cadence: weekly
cron: "0 8 * * 1"
enabled: true
blueprint: coach
lane: blue
tool_profile: blue-mail-triage
budget: 40000
review-prep:
cadence: weekly
cron: "0 9 * * 5"
enabled: true
lane: green
tool_profile: green-commit-only
budget: 60000
```
## Tool profiles
Defined **only** in agent-harness (see `agent_harness/profiles.py`).
Manifests reference them by name; unknown names refuse to run.
| Name | Lane | Session tools |
|------|------|---------------|
| `green-commit-only` | green | Read/Write/Edit/Glob/Grep + local git add/commit/status/log/diff (+ date, ls) |
| `blue-mail-triage` | blue | Same session tools; credentialed IMAP scan is a deterministic pre-step outside the session |
No push, no network, no arbitrary shell in either profile.
## Budget
`budget` is tokens per run. The runner wires llm-connect `BudgetTracker`
when set; exhaustion refuses or truncates the run and is reported to the
State Hub (token events feed the Token Cost dashboard).
## Harness pin
Instances pin a harness **major**. This runtime implements major `0`
(package `0.x`). A mismatched pin fails `validate` so upgrades are
deliberate.
## Relationship to task files
Local development may still use JSON task files (`agent-harness run
--task-file …`). When the target repo has a matching agent entry, the
runner resolves `tool_profile`, `budget`, and `lane` from the manifest;
otherwise it defaults to `green-commit-only` with no budget cap.