D 2026-11-24T19:03:12.429 L checkin/340fc2d952a2244242bd01bdbc3a32178cd8758953a39dbcf42d36c455e240d0 N text/x-markdown U dmestas W 2893 # /auth step 5 (#74): expiry, what is left with its age, keys from a command ## Expiry - New table `picu_credential_meta(name, expires_ms, expiry_source, value_hash, rotated_ms)`, keyed by the credential's health name. It is removed with the key, and cleared when the key gets a new value (`pic_cred_login_as`, a command key's new output). - Sources: OpenRouter's free check (`$.data.expires_at`, through `pic_key_health.expires_ms`), recorded as `provider`; otherwise `recorded` from `pic auth expires P[:L] DATE|Nd|never`, `--expires` on `auth login --api-key` and `auth import`, RPC `set_credential_expiry`, or `add_credential`'s `expires_at`. A date alone means the end of that day, UTC. - Warnings, controlled by `keyExpiryWarnDays` (default 7): - `-p` and `ask` print one stderr line for the key the request uses. - The TUI footer shows a red "! expires in N days". - The /auth row puts the expiry first and is red once expired; `e` records a new date. - The request still goes past the date, since a recorded date can be wrong. This differs from the proposal, which asks before sending. - `pic auth status --expiring DAYS` exits 1 when a key in use expires within DAYS. - `get_credentials` adds `expires_at`, `days_left`, `expiry_source`, `expired` and `rotated_at`. ## What is left - `get_credentials` carries `left {kind money|none, amount, currency, source check|reply, as_of, stale}`. - /auth adds the reading's age ("checked 12 min ago", or "last known" after a day). - Not done: reading rate-limit and ChatGPT plan headers from replies (the proposal's `rate` and `plan_window` kinds). ## Keys from a command - A new credential kind, `command`. userdb's CHECK is widened and the table rebuilt once, the same way `credential_kinds` added oauth. - `pic auth login P [--as L] --command 'CMD'` seals the command. No key is stored. - It runs through a new platform hook, `key_command`: /bin/sh -c, first line of stdout, a 10-second limit, and the first line of stderr on failure. The value is held in memory for 5 minutes. - On a 401 or 403, `pic_cred_rerun` runs the command again. A new value is sent once more; the same value is a real refusal. - A changed value (salted hash) forgets the key's health and expiry, and records `rotated_at`. - A failing command stops the request with one line, with no fallback. - RPC cannot add one. ## Offline Free checks already skip when `offline` is on; a test now covers it. Key commands run locally. ## Tests - New `test/pic/keyexpiry.sh` (dev only). - An expiry case in test/tui/auth.sh. - rpc.sh's settings count is now 37. Tier: core (cred.c, platform.c/.h, userdb.c, provider_http.c), bundled (provider_chat.c, keyprobe.c), root (main.c), client (tui); no new file. Clock: vendor (expiry fields), os (the command). Record: picu_credential_meta; picu_credential kind command. Default: none recorded. Z 8ee361fb6cb2ac479a3d2638f712d102