Commit 8d85a4f
committed
feat(policy): a typed behavior-policy layer
memcode behaved one way for everyone. Where a user might reasonably want a
say — which model explores, whether plans get reviewed and by whom, what a
session starts on — the answer was a hardcoded constant or a scattered
config field.
The delegated pin proved the shape but solved exactly one decision point,
and the obvious next step (explore_model, plan_review_model,
advisor_model, startup_model, theme_mode) is a bag of special cases. This
generalises it into one primitive: typed policy on named targets.
natural-language instruction
-> policy tool
-> typed policy store
-> scope resolution
-> runtime decision point: policy.Resolve("agent.explore")
The rule the package exists to enforce, stated in its doc comment and
enforced by a guard test:
Policy chooses behavior. The model may not synthesize policy.
"Always review plans with grok" is a settings write. "Review this plan
with kimi" is an override on that plan. A model deciding a plan looks hard
enough to warrant a stronger model is neither, and is forbidden — that is
the automatic routing this codebase deleted, and it does not come back
through a settings API.
v1 is UNCONDITIONAL. Every policy fires every time; nothing inspects or
classifies a task. The representation leaves room for conditions later,
but there is no condition field and no evaluator, because task
classification is exactly where hidden routing regrows.
Inheritance is DECLARED, not special-cased: a schema names a Parent, and
agent.explore -> agent.delegated -> the primary pin falls out of that. A
future agent.research or plan.scout declares a parent and needs no
resolution code of its own. The shipped "unset delegated means inherit
your own model" behavior is now schema (InheritsPrimaryModel) rather than
a second hand-written chain.
Invocation overrides belong to the OPERATION, not to a store. "Review
this plan with kimi" lives on the plan controller and is cleared at every
transition that begins or ends a plan — there is no global
consume-on-next-use state that could leak into an unrelated later
operation. A test asserts it does not survive its plan.
fallback_models is narrow on purpose: models to try when the chosen one
cannot be REACHED, under the same provider/transport semantics the
catalog's declared chain already uses. Nothing consults it because a
result looked weak. Capability gaps still refuse rather than substitute.
Seven targets, chosen so this is provably about behavior and not models:
agent.delegated, agent.explore (+ concurrency, replacing the hardcoded
maxReaders), plan.review, plan.advisor, startup.model, ui.theme,
session.effort. Modes are three-valued enums (off/offer/always) rather
than a bool plus a nil model, so "never review", "offer review" and
"always review with X" are each expressible.
Policy is kept completely separate from internal/prefs, in both
directions. That system infers standing preferences from repeated signals
and injects advisory prose; this one is explicit, immediate and
programmatic. A guard test asserts prefs has no import of policy: an
inferred pattern must never rewire which model runs.
Storage is two plain JSON files (.memcode/policy.json and the user-level
equivalent), deliberately outside config.json, so a target can be listed,
diffed and reset as a unit — "reset how explore agents behave" deletes one
object. `/policy` and the tool's `show` report every effective value and
which scope it came from, because per-field resolution across four layers
is only comprehensible if the source is visible.
The wire budget for tool defs is raised 31KB -> 32KB. The policy tool's
description was trimmed twice first; what remains is the guardrail
sentence, which is the last thing that should be cut for bytes.1 parent 556fe78 commit 8d85a4f
29 files changed
Lines changed: 1630 additions & 595 deletions
File tree
- cmd
- internal
- agent
- plan
- runtime
- tools
- config
- explore
- guard
- policy
- vxui
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
36 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
| 83 | + | |
88 | 84 | | |
89 | 85 | | |
90 | 86 | | |
| |||
124 | 120 | | |
125 | 121 | | |
126 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
38 | | - | |
| 36 | + | |
39 | 37 | | |
40 | 38 | | |
41 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
150 | | - | |
151 | | - | |
| 149 | + | |
152 | 150 | | |
153 | 151 | | |
154 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
106 | 111 | | |
107 | 112 | | |
108 | 113 | | |
| |||
145 | 150 | | |
146 | 151 | | |
147 | 152 | | |
| 153 | + | |
148 | 154 | | |
149 | 155 | | |
150 | 156 | | |
| |||
166 | 172 | | |
167 | 173 | | |
168 | 174 | | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
169 | 207 | | |
170 | 208 | | |
171 | 209 | | |
| |||
234 | 272 | | |
235 | 273 | | |
236 | 274 | | |
| 275 | + | |
237 | 276 | | |
238 | 277 | | |
239 | 278 | | |
| |||
262 | 301 | | |
263 | 302 | | |
264 | 303 | | |
| 304 | + | |
265 | 305 | | |
266 | 306 | | |
267 | 307 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
50 | 52 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
56 | 67 | | |
57 | 68 | | |
58 | 69 | | |
59 | | - | |
| 70 | + | |
60 | 71 | | |
61 | 72 | | |
62 | 73 | | |
| |||
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
325 | 325 | | |
326 | 326 | | |
327 | 327 | | |
328 | | - | |
329 | | - | |
| 328 | + | |
| 329 | + | |
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
| |||
0 commit comments