D 2026-11-24T18:06:38.873 L checkin/6b85612d46257df0bc0a4d97d6c3dd3657908bfaa434f8141820646c6e5e3229 N text/x-markdown U dmestas W 2358 # /auth step 4 (#73): rules give a model family its own key A rule is the setting `keyFor:PATTERN`, whose value is a key label. PATTERN is a model id (`provider/id`) with `*` for any part. The models it matches use that key of their own provider. The rest of the provider keeps its key. A rule never sends a model to another provider. Which key a request uses, in order: 1. the per-process label: `--key`, the conversation's own key (step 1), or RPC `set_credential` 2. the rule for the request's model: an exact pattern first, then the longest pattern that matches 3. `activeKey:PROVIDER`, and the rest of the existing lookup order ## Where - cred.c (core): `pic_cred_model(model)` tells cred which model the next requests are for. `pic_cred_rules`, `pic_cred_rule_for` and `pic_cred_rule_set` read, match and save rules; `cred_rule_of` is one new step in `cred_choose`. `pic_cred_used` gains `rule`. A rule as long as an existing one that could match the same models is refused, naming the existing one. - provider_http.c sets the model just before a request fetches its key, and main.c `model_provider` sets it too. - Shell: `pic auth use P L --for PATTERN [--json]` and `pic auth use P --for PATTERN --clear`. `pic auth status` lists the rules. - JSON: `bindings` in `get_credentials` and `pic auth status --json`. Each `pic models --json` row gains `credential`, `bound_by` and `rule`. - RPC: `set_model_credential {pattern, label|null}`, saved. - TUI: the model picker's key column (tui_mrow.key) reads "second" or "work by rule". In /auth, `b` on a key takes a pattern, and Enter saves it, or removes it when the key already has that rule. Each row says which families its rules give it. For the MCP work: cred.c gained new functions and one branch in `cred_choose`; no existing function changed shape. ## Not here The proposal's scope `session` for set_model_credential (a rule for one process) is not implemented: rules are always saved. ## Tests - test/pic/authcmd.sh: a rules section covering the shell, RPC, which key is actually sent, that `--key` still wins, the conflict refusal, and the `pic models --json` fields. - test/tui/auth.sh: `b` and the picker's key column. Tier: core (cred.c, provider_http.c), root (main.c), client (tui); no new file. Clock: pi. Record: settings `keyFor:PATTERN`. Default: no rules. Z 2f0413eb0617c0918f3e92382b5da778