@event4u/agent-config 2.19.0 → 2.20.0

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 (92) hide show
  1. package/.agent-src/commands/agent-status.md +29 -0
  2. package/.agent-src/commands/onboard.md +221 -81
  3. package/.agent-src/packs/README.md +49 -0
  4. package/.agent-src/packs/agency-delivery.yml +63 -0
  5. package/.agent-src/packs/content-engine.yml +53 -0
  6. package/.agent-src/packs/founder-mvp.yml +51 -0
  7. package/.agent-src/presets/README.md +26 -0
  8. package/.agent-src/presets/balanced.yml +34 -0
  9. package/.agent-src/presets/fast.yml +31 -0
  10. package/.agent-src/presets/strict.yml +38 -0
  11. package/.agent-src/profiles/README.md +29 -0
  12. package/.agent-src/profiles/agency.yml +27 -0
  13. package/.agent-src/profiles/content_creator.yml +25 -0
  14. package/.agent-src/profiles/developer.yml +26 -0
  15. package/.agent-src/profiles/finance.yml +24 -0
  16. package/.agent-src/profiles/founder.yml +25 -0
  17. package/.agent-src/profiles/ops.yml +25 -0
  18. package/.agent-src/rules/no-cheap-questions.md +25 -17
  19. package/.agent-src/skills/adr-create/SKILL.md +78 -68
  20. package/.agent-src/skills/subagent-orchestration/SKILL.md +33 -0
  21. package/.agent-src/templates/agents/agent-project-settings.example.yml +1 -1
  22. package/.agent-src/templates/skill-archive-note.md +101 -0
  23. package/.claude-plugin/marketplace.json +1 -1
  24. package/CHANGELOG.md +52 -30
  25. package/README.md +68 -72
  26. package/config/agent-settings.template.yml +22 -0
  27. package/docs/adrs/caveman/0001-default-off-until-bench.md +93 -0
  28. package/docs/adrs/caveman/README.md +9 -0
  29. package/docs/adrs/cost/0001-hard-stop-hook.md +114 -0
  30. package/docs/adrs/cost/README.md +9 -0
  31. package/docs/adrs/memory/0001-consumer-side-snapshot.md +111 -0
  32. package/docs/adrs/memory/README.md +9 -0
  33. package/docs/adrs/router/0001-three-tier-routing.md +119 -0
  34. package/docs/adrs/router/README.md +9 -0
  35. package/docs/adrs/schema/0001-json-schema-frontmatter.md +102 -0
  36. package/docs/adrs/schema/README.md +9 -0
  37. package/docs/adrs/smoke/0001-per-tier-smoke-scripts.md +99 -0
  38. package/docs/adrs/smoke/README.md +9 -0
  39. package/docs/architecture/current-onboard-baseline.md +126 -0
  40. package/docs/architecture/current-safety-behavior.md +137 -0
  41. package/docs/archive/CHANGELOG-pre-2.16.0.md +48 -0
  42. package/docs/contracts/adr-layout.md +108 -0
  43. package/docs/contracts/benchmark-corpus-spec.md +97 -0
  44. package/docs/contracts/benchmark-report-schema.md +111 -0
  45. package/docs/contracts/command-clusters.md +1 -0
  46. package/docs/contracts/command-taxonomy.md +137 -0
  47. package/docs/contracts/compression-default-kill-criterion.md +69 -0
  48. package/docs/contracts/config-presets.md +144 -0
  49. package/docs/contracts/cost-dashboard.md +143 -0
  50. package/docs/contracts/cost-enforcement.md +134 -0
  51. package/docs/contracts/file-ownership-matrix.json +0 -7
  52. package/docs/contracts/mcp-tool-inventory.md +53 -0
  53. package/docs/contracts/measurement-baseline.md +102 -0
  54. package/docs/contracts/namespace.md +125 -0
  55. package/docs/contracts/profile-system.md +142 -0
  56. package/docs/contracts/safety-model.md +129 -0
  57. package/docs/contracts/smoke-contracts.md +144 -0
  58. package/docs/contracts/workflow-packs.md +121 -0
  59. package/docs/decisions/ADR-010-profile-pack-preset-boundary.md +132 -0
  60. package/docs/decisions/INDEX.md +1 -0
  61. package/docs/featured-commands.md +27 -0
  62. package/docs/parity/bench-ruflo.json +58 -0
  63. package/docs/parity/bench.json +41 -0
  64. package/docs/parity/ruflo.md +46 -0
  65. package/docs/profiles.md +91 -0
  66. package/package.json +1 -1
  67. package/scripts/_cli/cmd_explain.py +250 -0
  68. package/scripts/_lib/bench_cost.py +138 -0
  69. package/scripts/_lib/bench_quality.py +118 -0
  70. package/scripts/_lib/bench_report.py +150 -0
  71. package/scripts/agent-config +13 -0
  72. package/scripts/audit_adr_coverage.py +175 -0
  73. package/scripts/audit_mcp_tools.py +146 -0
  74. package/scripts/bench_baseline_ready.py +108 -0
  75. package/scripts/bench_drift_check.py +151 -0
  76. package/scripts/bench_per_tool.py +216 -0
  77. package/scripts/bench_run.py +155 -0
  78. package/scripts/config/__init__.py +9 -0
  79. package/scripts/config/presets.py +206 -0
  80. package/scripts/config/profiles.py +173 -0
  81. package/scripts/cost/budget.mjs +73 -12
  82. package/scripts/cost/preflight.mjs +89 -0
  83. package/scripts/lint_archived_skills.py +143 -0
  84. package/scripts/lint_bench_corpus.py +161 -0
  85. package/scripts/lint_namespace.py +135 -0
  86. package/scripts/skill_overlap.py +204 -0
  87. package/scripts/skill_usage_collect.py +191 -0
  88. package/scripts/skill_usage_report.py +162 -0
  89. package/scripts/smoke/kernel.sh +101 -0
  90. package/scripts/smoke/router.sh +129 -0
  91. package/scripts/smoke/schema.sh +71 -0
  92. package/scripts/smoke/skills.sh +101 -0
@@ -0,0 +1,137 @@
1
+ ---
2
+ stability: beta
3
+ keep-beta-until: 2026-08-12
4
+ ---
5
+
6
+ # Command taxonomy
7
+
8
+ > **Status:** beta — first draft 2026-05-16 (Phase 2 Item 6 of
9
+ > `step-15-product-refinement`).
10
+
11
+ The taxonomy answers **"how is the command surface organized so each
12
+ profile finds their three first commands in under 30 seconds?"** It is
13
+ a **catalog-organization contract**, not an invocation-rename. Existing
14
+ slash invocations (`/work`, `/fix ci`, `/research deep`) are preserved
15
+ by the locked verb-cluster contract at
16
+ [`command-clusters`](command-clusters.md). This file adds a **profile
17
+ axis** on top of the verb axis without breaking either.
18
+
19
+ ## The two axes
20
+
21
+ | Axis | Owner | Surface |
22
+ |---|---|---|
23
+ | **Verb-cluster** (existing) | [`command-clusters`](command-clusters.md) | Defines the invocation tree (`/fix ci` dispatches to the `ci` sub-command of the `fix` cluster). Linter-enforced. **Source of truth for invocation.** |
24
+ | **Profile** (this contract) | [`profile-system`](profile-system.md) | Defines which verb-clusters and sub-commands are surfaced first for each profile (developer · content_creator · founder · agency · finance · ops). **Source of truth for discoverability.** |
25
+
26
+ A command can be discoverable under multiple profiles. `/work` is
27
+ universal — it appears in `commands_hint` for every profile. `/dcf-modeling`
28
+ is finance-only. Discoverability is many-to-many; invocation stays
29
+ single-source.
30
+
31
+ ## Membership rules
32
+
33
+ ### Profile membership
34
+
35
+ A command appears in a profile's `commands_hint` (in
36
+ `.agent-src.uncompressed/profiles/<id>.yml`) iff **all** hold:
37
+
38
+ 1. **First-week reach.** A user of that profile will reach for this
39
+ command within their first five sessions without being told.
40
+ 2. **Profile-coherent.** The command's domain matches the profile's
41
+ primary work surface (engineering for `developer`, content for
42
+ `content_creator`, etc.).
43
+ 3. **Verb-cluster owned.** The command exists in `command-clusters` —
44
+ no profile may declare a command that has not gone through the
45
+ verb-cluster linter.
46
+ 4. **Cap of five.** A profile's `commands_hint` is capped at five
47
+ entries. The cap is what makes "three first commands" possible.
48
+
49
+ ### Top-10 most-used (for alias / deprecation policy)
50
+
51
+ The top-10 list is the **union of all six profiles' `commands_hint`
52
+ lists, ranked by per-profile membership count**. As of 2026-05-16
53
+ that union is, in rank order:
54
+
55
+ 1. `work` (6/6 profiles)
56
+ 2. `implement-ticket` (2/6 — developer, agency)
57
+ 3. `feature` (2/6 — founder, agency)
58
+ 4. `council` (2/6 — founder, finance)
59
+ 5. `challenge-me` (2/6 — founder, finance)
60
+ 6. `review-changes` (2/6 — developer, ops)
61
+ 7. `fix` (2/6 — developer, ops)
62
+ 8. `refine-ticket` (1/6 — agency)
63
+ 9. `commit` (1/6 — developer)
64
+ 10. `roadmap` (1/6 — agency)
65
+
66
+ The top-10 is regenerated automatically from the profile YAMLs by
67
+ `scripts/regen_top10.py` (Phase 2 deliverable — not yet shipped). Until
68
+ the regen script lands, the list above is the locked snapshot.
69
+
70
+ ## Backward-compat policy
71
+
72
+ The top-10 commands carry a **two-release backward-compat guarantee**:
73
+
74
+ - A rename of any top-10 command (whether by verb-cluster restructure
75
+ or profile-axis reorganization) ships with an alias for **at least
76
+ two minor releases**.
77
+ - The alias is recorded in the verb-cluster's `Replaces` column in
78
+ [`command-clusters`](command-clusters.md) and re-emits a one-line
79
+ deprecation notice to stderr on every invocation.
80
+ - Removing the alias requires the `bundled-always-rules-acknowledged`
81
+ PR label and an entry in the CHANGELOG `Removed` section naming the
82
+ end-of-deprecation release.
83
+
84
+ Commands outside the top-10 follow the existing verb-cluster
85
+ deprecation rules (one release as a shim, then disappear).
86
+
87
+ ## Discoverability surfaces
88
+
89
+ Three surfaces consume this contract:
90
+
91
+ | Surface | Path | What it shows |
92
+ |---|---|---|
93
+ | **README** | `README.md` § "Six entry paths" | Per-profile `commands_hint` (max 5) rendered as the first-commands list per profile block |
94
+ | **Catalog** | `docs/catalog.md` | All commands grouped by verb-cluster (primary axis), with a per-command `profiles:` line listing which profiles surface it |
95
+ | **Wizard** | `.agent-src.uncompressed/commands/onboard.md` | After role selection, prints the five-command starter list from the selected profile's `commands_hint` |
96
+
97
+ The README and wizard surfaces are already wired. The catalog `profiles:`
98
+ line is a Phase 2 deliverable.
99
+
100
+ ## What this contract does **not** do
101
+
102
+ - **Does not** rename any command. Invocation stays flat (`/work`, not
103
+ `/dev/work`). The `/dev/...` / `/ops/...` strawman in the Item 6
104
+ roadmap entry is **rejected** — adding a profile prefix to invocation
105
+ would dual-namespace the surface, conflict with verb-cluster cluster
106
+ heads, and require a 124-command migration with no measurable
107
+ discoverability gain over the README + wizard surfaces above.
108
+ - **Does not** modify the verb-cluster contract. `command-clusters`
109
+ remains the locked source of truth for invocation. This contract is
110
+ additive.
111
+ - **Does not** ship telemetry. The top-10 is derived from declared
112
+ profile membership, not observed usage. A usage-based top-10
113
+ recomputation is deferred to Item 10 (Cost Governance Dashboard),
114
+ which already collects per-command call counts.
115
+
116
+ ## Open questions (post-beta)
117
+
118
+ 1. **Profile evolution.** When a seventh profile lands (e.g.
119
+ `researcher`), what is the membership review process for the
120
+ top-10? Proposal: any new profile triggers a `regen_top10.py` run
121
+ and a CHANGELOG entry; no manual review unless the top-10 order
122
+ changes.
123
+ 2. **Profile-prefix invocation.** If the no-rename verdict is
124
+ revisited (e.g. user research shows discoverability still fails
125
+ even with the README + wizard surfaces), a separate ADR records
126
+ the decision; this contract does not pre-authorize it.
127
+ 3. **Catalog generator.** `docs/catalog.md` is currently
128
+ handwritten. The `profiles:` line proposed in the discoverability
129
+ table requires `scripts/regen_catalog.py` to consume profile YAMLs
130
+ — deferred to its own roadmap step.
131
+
132
+ ## See also
133
+
134
+ - [`command-clusters`](command-clusters.md) — verb-axis (invocation)
135
+ - [`profile-system`](profile-system.md) — profile-axis (discoverability)
136
+ - [`command-surface-tiers`](command-surface-tiers.md) — tier-axis (`./agent-config --help` visibility)
137
+ - `step-15-product-refinement` § Phase 2 Item 6
@@ -0,0 +1,69 @@
1
+ ---
2
+ stability: beta
3
+ keep-beta-until: 2026-08-14
4
+ ---
5
+
6
+ # Compression default — kill-criterion
7
+
8
+ > **Status:** parked, criterion-deferred · **Owner:** `step-4-measurement-and-benchmark.md`
9
+ > closeout phase · **Source:** [`council-synthesis.md` § 7](../../agents/audit-2026-05-14-north-star/council-synthesis.md)
10
+
11
+ ## Rule
12
+
13
+ ```
14
+ DEFAULT STAYS OFF UNTIL `task bench` PRODUCES A NUMBER.
15
+ DECISION OWNED BY step-4 CLOSEOUT, NOT BY THIS DOC OR BY step-99.
16
+ ```
17
+
18
+ 1. **Current state.** `caveman.speak_scope` defaults `off`. Carve-outs
19
+ (security · destructive · multi-step · code blocks · paths · numbered
20
+ options · Iron-Law markers) are documented in
21
+ [`caveman-speak`](../../.agent-src.uncompressed/rules/caveman-speak.md)
22
+ but the feature is non-promoted: no skill recommends turning it on,
23
+ no preset enables it, no profile depends on it.
24
+ 2. **Baseline window.** 60 days from the first green run of
25
+ `task bench` against the locked 25-prompt corpus
26
+ (`step-4-measurement-and-benchmark.md`
27
+ Phase 2). The corpus, the model, and the cost-tracker are frozen
28
+ for the window; mid-window changes restart the clock.
29
+ 3. **Decision points.** After the window closes, `step-4` closeout
30
+ reads `docs/parity/bench.json` and applies exactly one of:
31
+
32
+ | Measured tokens saved | Quality regression on corpus | Verdict |
33
+ |---|---|---|
34
+ | < 30 % | any | **Deprecate** — remove `caveman-speak` rule, archive `caveman-compress` script, retire `caveman.*` settings keys with a one-release deprecation window |
35
+ | ≥ 30 % | < 5 % | **Flip default on** — `caveman.speak_scope` defaults to a non-`off` value, carve-outs stay, statusline surfaces lifetime tokens saved |
36
+ | ≥ 30 % | ≥ 5 % | **Hold** — repeat the window once with tuned intensity ladder; second hold → deprecate |
37
+
38
+ "Quality regression" = host-side rubric on the corpus per
39
+ `step-4-measurement-and-benchmark.md` Phase 3. Numbers checked into
40
+ `docs/parity/bench.json` as the decision artefact.
41
+ 4. **No interim flip.** The default does not move on anecdote,
42
+ gut feeling, or a single benchmark snapshot. The 60-day window and
43
+ the table above are the only path to a default change.
44
+
45
+ ## Why this is parked, not decided
46
+
47
+ The council split (Opus = remove now, o1 = measure-then-decide) is
48
+ real. Either branch is wrong-shaped without numbers. The kill-criterion
49
+ gives the audit a deterministic resolution path and stops every
50
+ downstream roadmap from re-litigating compression on every PR.
51
+
52
+ ## Cross-references
53
+
54
+ - ``step-99-north-star-restructure.md` § Phase 4`
55
+ — parks this criterion, does not decide.
56
+ - `step-4-measurement-and-benchmark.md`
57
+ — owns `task bench`, the corpus, and the closeout that applies the
58
+ table above.
59
+ - `step-10-caveman-parity.md`
60
+ — implements the carve-outs and the statusline integration the
61
+ "flip default on" branch depends on; blocks the default flip until
62
+ acceptance is green.
63
+ - [`caveman-speak`](../../.agent-src.uncompressed/rules/caveman-speak.md)
64
+ — runtime rule; reads `caveman.speak_scope` from settings.
65
+
66
+ ## Done
67
+
68
+ This doc exists to keep the decision visible. It is **not** an action
69
+ item. `step-4` closeout closes the loop.
@@ -0,0 +1,144 @@
1
+ ---
2
+ stability: beta
3
+ keep-beta-until: 2026-08-14
4
+ ---
5
+
6
+ # Config Presets — Contract
7
+
8
+ > **Status:** beta · **Owner:** package maintainer · **Last reviewed:** 2026-05-16
9
+ >
10
+ > Schema and semantics for the **Config Preset** axis introduced in
11
+ > step-15 Phase 1 item 4. Records the **Cost Enforcement** model
12
+ > (Council v3 action #3 prerequisite) so the preset loader can ship.
13
+ > Boundary against `profile.id`, `pack.id`, and `cost_profile`:
14
+ > [`ADR-010`](../decisions/ADR-010-profile-pack-preset-boundary.md).
15
+
16
+ ## Decision
17
+
18
+ A **preset** owns governance knobs that the user wants to tune as a
19
+ bundle, not individually. Three seed presets ship; users can declare
20
+ their own under `.agent-src.uncompressed/presets/<id>.yml`.
21
+
22
+ | `preset.id` | Stance | Typical user |
23
+ |---|---|---|
24
+ | `fast` | Lowest friction; widest autonomy; loosest cost caps | Solo founder, throw-away prototype, exploration |
25
+ | **`balanced`** *(default)* | Moderate friction; per-task autonomy; sensible cost caps | Day-to-day work; default for any new install |
26
+ | `strict` | Highest friction; ask-by-default; tight cost caps; block-on-risk | Production paths, regulated work, shared trunks |
27
+
28
+ Profile-aware overlay: `developer + strict` ≠ `founder + strict` — the
29
+ profile selects which knob in the preset is read first (e.g. `developer`
30
+ reads `block_on_risk.code_paths`, `founder` reads `block_on_risk.financial_paths`).
31
+
32
+ ## Preset shape
33
+
34
+ ```yaml
35
+ preset:
36
+ id: balanced
37
+ autonomy:
38
+ default: auto # on | off | auto (see autonomous-execution rule)
39
+ trivial_suppress: true
40
+ confidence:
41
+ min_band: medium # low | medium | high — block plan if below
42
+ require_evidence: false
43
+ risk:
44
+ block_on: [security, prod_data]
45
+ ask_on: [bulk_delete, schema_change]
46
+ council:
47
+ auto_consult: false
48
+ cap_per_consult_usd: 0.50
49
+ mcp:
50
+ per_call_max_usd: 0.10
51
+ per_session_max_usd: 2.00
52
+ cost:
53
+ daily_max_usd: 10.00
54
+ weekly_max_usd: 50.00
55
+ monthly_max_usd: 150.00
56
+ enforce: hybrid # see Cost Enforcement section
57
+ notifications:
58
+ threshold_pct: [50, 75, 90, 100]
59
+ ```
60
+
61
+ ## Cost Enforcement
62
+
63
+ *Hybrid model* — recorded as the Phase 1 prerequisite per Council v3
64
+ action #3. Two enforcement surfaces, one decision per call.
65
+
66
+ ### Hard enforcement (preset loader, blocking)
67
+
68
+ The preset loader **refuses to dispatch** any council or MCP call whose
69
+ *estimated* cost exceeds the active preset's per-call ceiling. The
70
+ estimate is read from the model adapter (`council_cli.py estimate` for
71
+ council; the MCP tool manifest for MCP). The block is raised **before**
72
+ the network call. There is no override flag — the user must change the
73
+ preset, override `cost.per_call_max_usd` in `.agent-settings.yml`, or
74
+ pass `--preset=fast` on the CLI.
75
+
76
+ ```
77
+ PRE-CALL CEILING IS HARD.
78
+ NO RUNTIME OVERRIDE. NO "JUST THIS ONCE" FLAG.
79
+ EXCEED → REFUSE → SURFACE THE CEILING + THE OVERRIDE PATH.
80
+ ```
81
+
82
+ Applies to:
83
+
84
+ - AI Council consults (`scripts/council_cli.py run`).
85
+ - MCP tool calls dispatched through the universal dispatcher
86
+ ([`hook-architecture-v1`](hook-architecture-v1.md)).
87
+ - Any future skill that reads `preset.cost.per_call_max_usd`.
88
+
89
+ ### Advisory dashboard (retroactive, non-blocking)
90
+
91
+ `agent-config cost` (Phase 2 item 10) surfaces daily / weekly / monthly
92
+ spend against the active preset's caps. The dashboard **does not**
93
+ block — it warns at the thresholds in `preset.notifications.threshold_pct`
94
+ (default `50 / 75 / 90 / 100`). At 100 %, the dashboard prints a hard
95
+ warning; the next session start re-checks the cap against the running
96
+ total before dispatching the next paid call.
97
+
98
+ The advisory layer's role is **awareness**, not enforcement. Enforcement
99
+ is exclusively the per-call ceiling above; retroactive blocking would
100
+ turn a session unrecoverably hostile mid-task.
101
+
102
+ ### What the loader does **not** do
103
+
104
+ - It does **not** estimate cost for unpaid local model calls
105
+ (`ollama`, local llama.cpp). These bypass both surfaces.
106
+ - It does **not** estimate cost for non-LLM tool calls (file reads,
107
+ shell commands, MCP-static-resource fetches). The per-call ceiling
108
+ targets paid token spend.
109
+ - It does **not** override the Hard Floor in
110
+ [`non-destructive-by-default`](../../.agent-src/rules/non-destructive-by-default.md)
111
+ — a preset cannot lift the universal safety floor.
112
+
113
+ ## Resolution chain
114
+
115
+ Reads happen in this order; last writer wins for any single knob:
116
+
117
+ 1. `pack.preset_id` (if pack active) → set `preset.id`.
118
+ 2. `profile.preset_id` → set `preset.id` (if not already set by pack).
119
+ 3. `preset.<id>.yml` → fill all knobs.
120
+ 4. `.agent-settings.yml` user keys under `preset:` → override per-knob.
121
+ 5. Environment variables (`AGENT_CONFIG_PRESET_COST_DAILY_MAX_USD=…`)
122
+ → override per-knob.
123
+ 6. Runtime CLI flags (`--preset-cost-per-call-max-usd=…`) → override
124
+ per-knob, single session.
125
+
126
+ Per [`ADR-010`](../decisions/ADR-010-profile-pack-preset-boundary.md),
127
+ no other axis may write preset-owned knobs.
128
+
129
+ ## Drift detection
130
+
131
+ `task lint-config-schema` (added in Phase 1) hard-fails when:
132
+
133
+ - A pack YAML or profile YAML names a preset-owned knob.
134
+ - A preset YAML names a knob outside this contract.
135
+ - The three seed presets diverge from the documented stances above.
136
+
137
+ ## Non-goals
138
+
139
+ - This contract does **not** define profiles, packs, or `cost_profile`.
140
+ See the corresponding contracts.
141
+ - It does **not** ship a UI. CLI-first (`agent-config cost`,
142
+ `agent-config preset set <id>`).
143
+ - It does **not** auto-migrate existing installs. Without a preset,
144
+ the loader falls back to current per-knob defaults (`balanced`-equivalent).
@@ -0,0 +1,143 @@
1
+ ---
2
+ stability: beta
3
+ keep-beta-until: 2026-08-12
4
+ ---
5
+
6
+ # Cost governance dashboard
7
+
8
+ > **Status:** beta — first draft 2026-05-16 (Phase 2 Item 10 of
9
+ > `step-15-product-refinement`).
10
+ >
11
+ > **Related:** [`config-presets`](config-presets.md) (caps schema) ·
12
+ > [`cost-profile-defaults`](cost-profile-defaults.md) (default
13
+ > selection) · `scripts/cost/budget.mjs` (existing local-store
14
+ > primitive) · `scripts/cost/track.mjs` (session ingest).
15
+
16
+ The `agent-config cost` subcommand surfaces accumulated spend against
17
+ the active preset's caps. Read-only, CLI-first, no UI. Wraps the
18
+ existing `scripts/cost/*.mjs` primitives behind a single discoverable
19
+ verb so a user can ask "where am I against my budget?" without knowing
20
+ the storage layout.
21
+
22
+ ## Surface
23
+
24
+ ```
25
+ agent-config cost # default: status (this period's spend)
26
+ agent-config cost status [--json] # spend vs caps for daily/weekly/monthly
27
+ agent-config cost ingest # pull latest session.jsonl → local store
28
+ agent-config cost history [--period=today|week|month] [--limit=N]
29
+ agent-config cost reset --confirm # truncate sessions.jsonl + budget.json
30
+ ```
31
+
32
+ All subcommands are **read-only by default**. `ingest` writes only to
33
+ `agents/cost-tracking/sessions.jsonl`. `reset` is destructive and
34
+ gated by `--confirm` (Hard-Floor per
35
+ [`non-destructive-by-default`](../../.agent-src/rules/non-destructive-by-default.md)).
36
+
37
+ ## `cost status` — output contract
38
+
39
+ Human format:
40
+
41
+ ```
42
+ Cost (preset: balanced · profile: developer)
43
+
44
+ Period Spent Cap Remaining % Status
45
+ today $2.43 $10.00 $7.57 24% ✅
46
+ week $14.20 $40.00 $25.80 36% ✅
47
+ month $52.10 $150.00 $97.90 35% ✅
48
+
49
+ MCP calls: 12 today · 47 this week · 188 this month
50
+ Council calls: 1 today · 3 this week · 11 this month
51
+
52
+ Next threshold notification at 75% (week: $30.00).
53
+ ```
54
+
55
+ `--json` output schema:
56
+
57
+ ```json
58
+ {
59
+ "preset": "balanced",
60
+ "profile": "developer",
61
+ "periods": {
62
+ "today": {"spent_usd": 2.43, "cap_usd": 10.00, "remaining_usd": 7.57, "pct": 0.243, "status": "ok"},
63
+ "week": {"spent_usd": 14.20, "cap_usd": 40.00, "remaining_usd": 25.80, "pct": 0.355, "status": "ok"},
64
+ "month": {"spent_usd": 52.10, "cap_usd": 150.00, "remaining_usd": 97.90, "pct": 0.347, "status": "ok"}
65
+ },
66
+ "calls": {
67
+ "mcp": {"today": 12, "week": 47, "month": 188},
68
+ "council": {"today": 1, "week": 3, "month": 11}
69
+ },
70
+ "next_threshold": {"period": "week", "pct": 0.75, "trigger_usd": 30.00}
71
+ }
72
+ ```
73
+
74
+ ### Status field
75
+
76
+ | Value | Trigger | Exit code |
77
+ |---|---|---|
78
+ | `ok` | `pct < 0.75` | 0 |
79
+ | `warn` | `0.75 ≤ pct < 1.0` | 0 |
80
+ | `over` | `pct ≥ 1.0` | 1 |
81
+
82
+ Overall exit = worst-of across the three periods. `--json` always
83
+ emits the full object regardless of exit.
84
+
85
+ ## Data sources
86
+
87
+ | Field | Source |
88
+ |---|---|
89
+ | `preset` | Active preset id from [`config-presets`](config-presets.md) resolution chain. |
90
+ | `cap_usd` | `preset.cost.{daily,weekly,monthly}_max_usd`. |
91
+ | `spent_usd` | Sum of `cost_usd` field over `agents/cost-tracking/sessions.jsonl` records inside the period window. |
92
+ | `calls.mcp.*` | Sum of `mcp_calls` field in the same records. |
93
+ | `calls.council.*` | Count of records whose `kind` is `council`. |
94
+ | `next_threshold` | Smallest `(period, pct ∈ preset.notifications.threshold_pct)` tuple where `spent_usd < pct × cap_usd`. |
95
+
96
+ When the active preset declares no `cost.*` cap (legacy installs),
97
+ `cap_usd` is reported as `null` and `status` is `ok`. The tool does
98
+ **not** invent a default cap.
99
+
100
+ ## Enforcement vs surfacing
101
+
102
+ `agent-config cost` is **read-only**. Enforcement (refuse a council
103
+ or MCP call that would push spend over a cap) lives at the call site
104
+ per the active preset's `cost.enforce` setting (`off`, `advisory`,
105
+ `hybrid`, `hard`). This contract does not change enforcement; it only
106
+ makes the existing local-store data discoverable.
107
+
108
+ ## Refresh model
109
+
110
+ `sessions.jsonl` is appended to by the Claude Code session hooks
111
+ (see `scripts/cost/track.mjs`). `cost status` reads what's there;
112
+ `cost ingest` triggers a one-shot pull from `~/.claude/projects/`.
113
+ Users running a non-Claude-Code agent surface call `cost ingest`
114
+ manually after a session; users on Claude Code with hooks installed
115
+ never need to.
116
+
117
+ ## Validation
118
+
119
+ `scripts/lint_cost_dashboard.py` (Phase 2 deliverable — not yet
120
+ shipped) fails CI on:
121
+
122
+ - Schema drift in `sessions.jsonl` (missing required fields).
123
+ - Preset declaring `cost.*` caps that disagree with this contract's
124
+ expected period grid.
125
+ - `cost status --json` output diverging from the schema above.
126
+
127
+ ## What this contract does **not** do
128
+
129
+ - **Does not** ship a UI. CLI-first, by design.
130
+ - **Does not** introduce per-skill or per-command cost attribution
131
+ beyond `kind` (`council` vs other). Per-skill attribution is a
132
+ Phase 3 candidate.
133
+ - **Does not** override per-call hard caps from the preset.
134
+ - **Does not** roll up across multiple projects. Each project's
135
+ `agents/cost-tracking/` is its own scope.
136
+
137
+ ## See also
138
+
139
+ - [`config-presets`](config-presets.md) — preset caps + `enforce` semantics
140
+ - [`cost-profile-defaults`](cost-profile-defaults.md) — default preset selection
141
+ - [`safety-model`](safety-model.md) — `mcp_call_costly` domain
142
+ - `scripts/cost/budget.mjs`, `scripts/cost/track.mjs` — wrapped primitives
143
+ - `step-15-product-refinement` § Phase 2 Item 10
@@ -0,0 +1,134 @@
1
+ ---
2
+ stability: stable
3
+ ---
4
+
5
+ # Cost Enforcement Contract
6
+
7
+ > Status: stable · Owner: `step-11-measurement-governance-parity` · Last reviewed: 2026-05-16
8
+
9
+ How USD budgets read from `.agent-settings.yml` interact with the
10
+ session-cost ledger (`agents/cost-tracking/sessions.jsonl`) and the
11
+ budget evaluator (`scripts/cost/budget.mjs`).
12
+
13
+ ## Surface
14
+
15
+ Two files. Settings file declares the budget; ledger file accumulates
16
+ spend. The evaluator joins them and emits a tier.
17
+
18
+ | File | Role |
19
+ |---|---|
20
+ | `.agent-settings.yml § cost` | Declarative: budgets per period + enforcement mode. |
21
+ | `agents/cost-tracking/sessions.jsonl` | Append-only: per-session cost records (model, tokens, USD). |
22
+ | `scripts/cost/budget.mjs` | Evaluator: joins both, emits `{ level, utilization_pct, enforcement, source }`. |
23
+ | `scripts/cost/preflight.mjs` | Hard-stop hook: wraps `budget.mjs check` and exits non-zero at HARD_STOP when `enforcement: hard-stop`. |
24
+
25
+ ## Settings schema
26
+
27
+ ```yaml
28
+ cost:
29
+ budgets:
30
+ daily: 0 # USD ceiling for rolling 24h. 0 = unbudgeted.
31
+ weekly: 0 # USD ceiling for rolling 7d. 0 = unbudgeted.
32
+ monthly: 0 # USD ceiling for rolling 30d. 0 = unbudgeted.
33
+ enforcement: advisory # advisory | hard-stop
34
+ ```
35
+
36
+ - `0` (or absent) on any period = that period is not enforced. The
37
+ evaluator falls back to a longer-period budget when checking shorter
38
+ periods, never the other way around.
39
+ - `enforcement: advisory` is the default. Dashboards surface the
40
+ breach; the agent keeps working.
41
+ - `enforcement: hard-stop` is opt-in. `scripts/cost/preflight.mjs`
42
+ exits non-zero at the HARD_STOP tier; wrapping shells / CI / `task`
43
+ bindings must check this before composing a turn.
44
+
45
+ ## Tier ladder (5-stage)
46
+
47
+ | Utilization | Level | Emoji | Threshold-pct |
48
+ |---:|---|:---:|---:|
49
+ | `< 50 %` | `OK` | 🟢 | 0 |
50
+ | `50–74 %` | `INFO` | 🟡 | 50 |
51
+ | `75–89 %` | `WARNING` | 🟠 | 75 |
52
+ | `90–99 %` | `CRITICAL` | 🔴 | 90 |
53
+ | `≥ 100 %` | `HARD_STOP` | 🛑 | 100 |
54
+
55
+ The legacy 4-stage draft (`under / 50 / 75 / 90 / 100`) folded `OK`
56
+ into `under`. Parity-doc Phase 6 maps both forms verbatim.
57
+
58
+ ## Hook surface
59
+
60
+ `scripts/cost/preflight.mjs` is the **single** turn-start surface.
61
+ It wraps `budget.mjs check` and:
62
+
63
+ 1. Reads `cost.enforcement` from `.agent-settings.yml`.
64
+ 2. If `advisory` → always exits `0`, prints the tier as advisory text.
65
+ 3. If `hard-stop` and level is `HARD_STOP` → prints a refusal block
66
+ citing this contract and exits `1`.
67
+ 4. If no budget is configured at all → exits `0` (fail-open). Never
68
+ blocks unbudgeted work.
69
+
70
+ The hook does **not** rewrite or block individual tool calls. It is a
71
+ process-entry gate, intended to be invoked by:
72
+
73
+ - `task ci`, `task work:*`, `task roadmap:*` wrappers.
74
+ - The `/onboard` boot path (`scripts/install.py`-side guidance only).
75
+ - Manual `node scripts/cost/preflight.mjs` for shell wrappers.
76
+
77
+ ## Bypass
78
+
79
+ User-facing bypass mechanism (documented for the refusal block):
80
+
81
+ - Raise the budget: edit `.agent-settings.yml § cost.budgets.<period>`.
82
+ - Reset the ledger (drops historical spend from the calculation):
83
+ `node scripts/cost/track.mjs reset --confirm`.
84
+ - Disable enforcement: set `cost.enforcement: advisory`.
85
+
86
+ No environment-variable override. Bypass must be an explicit edit so
87
+ the change is durable and auditable.
88
+
89
+ ## Default behaviour without a budget
90
+
91
+ When `cost.budgets.{daily,weekly,monthly}` are all `0`:
92
+
93
+ - `budget.mjs check` reports cumulative spend, no tier (returns the
94
+ no-budget JSON shape).
95
+ - `preflight.mjs` exits `0`. Never blocks.
96
+ - `agent-status` panel shows **only** the measured-spend USD figure;
97
+ the tier table is suppressed.
98
+
99
+ ## Source precedence
100
+
101
+ `budget.mjs` reads budget config in this order:
102
+
103
+ 1. `.agent-settings.yml § cost` (when any value > 0).
104
+ 2. `agents/cost-tracking/budget.json` (legacy single-period JSON).
105
+ 3. None → no-budget output shape.
106
+
107
+ The evaluator output carries `source: 'agent-settings.yml' | 'budget.json'`
108
+ so dashboards can show where the figure came from.
109
+
110
+ ## Period mapping
111
+
112
+ `BUDGET_PERIOD={today|week|month|all}` selects which budget value
113
+ applies:
114
+
115
+ | `BUDGET_PERIOD` | Settings key |
116
+ |---|---|
117
+ | `today` | `cost.budgets.daily` |
118
+ | `week` | `cost.budgets.weekly` |
119
+ | `month` | `cost.budgets.monthly` |
120
+ | `all` (default) | First non-zero of `monthly → weekly → daily`. |
121
+
122
+ ## Acceptance fixtures
123
+
124
+ `tests/fixtures/cost/budget/` carries five reference fixtures:
125
+ `under-50`, `mid-75`, `high-90`, `at-100`, `over-100`. Each fixture
126
+ ships a `sessions.jsonl` slice + an expected JSON output. The fixture
127
+ suite is wired to `task test-cost-budget` per `step-11` Phase 2 Step 5.
128
+
129
+ ## See also
130
+
131
+ - `step-11-ruflo-parity` — Measurement & Governance Parity roadmap.
132
+ - `docs/contracts/cost-dashboard.md` — companion dashboard contract.
133
+ - `scripts/cost/budget.mjs` — evaluator implementation.
134
+ - `bench/pricing.yaml` — per-model USD pricing table.
@@ -6928,13 +6928,6 @@
6928
6928
  "via": "body_link",
6929
6929
  "depth": 1
6930
6930
  },
6931
- {
6932
- "source": ".agent-src.uncompressed/rules/no-cheap-questions.md",
6933
- "target": ".agent-src.uncompressed/contexts/contracts/frugality-charter.md",
6934
- "type": "READ_ONLY",
6935
- "via": "body_link",
6936
- "depth": 1
6937
- },
6938
6931
  {
6939
6932
  "source": ".agent-src.uncompressed/rules/no-cheap-questions.md",
6940
6933
  "target": ".agent-src.uncompressed/rules/ask-when-uncertain.md",