0022 · Generator with per-site rules, generator and password history sealed with the vault key, vault health on the client, and agent-assisted password change
- Status: accepted
- Date: 2026-11-04
Accepted on 2026-11-04.
Implemented on
main(phase 1, PRs #88–#92):
- generator (§1): smart, random, memorable and PIN kinds; a
passwordrulesinterpreter and bundled Apple rules; strength bar and per-character colors; in the extension, on iOS and inklav generate --type;- generator history (§2):
generator_historyin the system project, local-first writing (0x43) fromklavd, retention, and deletion with a purge of versions;- password history (§3): the
0x16record sealed with the vault key, backfill from the versions, "Previous passwords" in the extension and on iOS, andklav item history.Implemented on
main(fourth step of Omar's work order, PRs #118, #119, #121 and #123–#126):
- vault health (§4):
klav-client(featurehealth, withzxcvbnand the optional HIBP lookup, off),vault_healthinklavd,klav health, the "Health" view in the popup and on iOS;- assisted change (§5): the
rotatepermission only in tasks, the/v1/agent/rotationsroutes and the person's,agent_rotate_*inklavd, the pending password in the0x16record written before filling, the fill in the extension, and the "Pending change" card in the popup and on iOS;- "Fix my reused passwords" (§6): tasks offered from the popup, iOS and
klav health --fix-with;- MCP and SDK tools (§7),
create_itemwithgenerate, and the skill (§8).The end-to-end test (
apps/extension/e2e/cambio-asistido.spec.ts) also covers the sign-up that fails and two sites where the second rejects the new one. The ADR is fully implemented.
Context
Omar asked for three things:
- a generator like 1Password's;
- a history, so that no password is ever lost;
- that an agent go to each site where passwords are reused, change it to a strong one, and that Klav be updated.
What already exists:
klav-core::generator: password (PasswordPolicy, 4–256 characters, four classes, no ambiguous ones) and passphrase (PassphrasePolicy, EFF Large Wordlist), with rejection sampling andentropy_bits();klav generatein the CLI;- in the extension, a basic version (
generator()inapps/extension/src/ui/menu.ts): a fixed 20 characters, "Another" and "Use this password", which types into new-password fields; - the server keeps the previous versions of each item (
item_versions), up tomax_item_versions(50 by default). It deletes them on passing the cap with any edit, whether it is a change of tag or of title.
The reference is 1Password's generator: Copy, regenerate and Autofill buttons; the password with colors by character type; a strength bar; the "Smart Password" (respects the site's requirements), "Random", "Memorable" and "PIN Code" kinds; "Use as default for suggestions"; and "Password Generator History". The function is copied; the look is Klav's (diseno-visual).
Rule that stays: Klav doesn't query third parties unless the person turns it on, as with site icons (they are fetched from the site itself only if the person turns it on). It affects per-site rules (§1.3) and the breached-password lookup (§4.3).
Decision
1. Generator
1.1 Kinds
| Kind | Key | What it generates | Default |
|---|---|---|---|
| Smart | smart |
random within the site's rules (§1.3) | yes |
| Random | random |
current PasswordPolicy |
20 characters, all four classes |
| Memorable | memorable |
current PassphrasePolicy |
5 words, -, initial capital and a number |
| PIN | pin |
digits only, uniform | 6 digits (4–12) |
pinis a new function,generate_pin(len), with rejection sampling like the others.- Options: length, classes, no ambiguous characters, number of words, separator and capitals, as in
klav generatetoday. - Default kind: the person chooses it with "Use as default for suggestions". It is a local setting on each device (it isn't secret and doesn't need syncing in v1).
1.2 Strength
For a generated password,
entropy_bits()comes from the alphabet and the length, not from an estimate over the text. It is an upper bound, not the exact entropy: rejection sampling discards passwords that don't meet the rules (one of each class, the page's rules such as "no consecutive repeats"), and that narrows the space a little. With Klav's policies the difference is small, but the number isn't "the truth". Since the security round (ADR 0030, layer 09), the generator always rejects an alphabet of fewer than 2 characters (the entropy would be 0) and has a total budget of draws, so that impossible rules on the page don't hang it. The bar uses that number:Bits Label < 40 weak 40–63 fair 64–99 strong ≥ 100 very strong A 6-digit PIN (≈ 20 bits) comes out "weak", and that is honest: it is for where the site limits attempts. A strict site rule (for example, 6–16 digits) also lowers the bar, and the item page explains it: "the site doesn't allow more".
For passwords the person typed, the strength comes from
zxcvbn(§4).
1.3 Smart: per-site rules, without the network
In this order:
- The field's
passwordrulesattribute (Apple's proposal, which some sites use), which the extension reads from the page. Also the<input>'sminlengthandmaxlength. - Bundled rules from
apple/password-manager-resources, filequirks/password-rules.json:- MIT license (verified on 2026-11-04 in
LICENSE.md, "Copyright 2020 - 2026 Apple Inc."); the repository is still active (last push 2026-11-03); - about 67 KB of JSON, one entry per domain with the same grammar as
passwordrules; - it sits next to the code with a
PASSWORD-RULES-NOTICE.md(likeWORDLIST-NOTICE.md) and is updated with a repository script, never at run time: no network; - the lookup goes by the exact host, and then by stripping labels from the left (
login.accor.com→accor.com), without reaching a single label. The PSL is not used: it is an exact key lookup in a list, as ADR 0006 §6 requires.
- MIT license (verified on 2026-11-04 in
- If there are no rules,
randomwith 20 characters.
- The interpreter lives in
klav-core::generator::rules, pure, and also in WASM. It understandsminlength,maxlength,required,allowed,max-consecutiveand the classesupper,lower,digit,special,ascii-printableand[…]. - Generation stays uniform: it picks the longest allowed length up to 20 (or the minimum if that is larger), requires one of each
requiredclass and rejects those that breakmax-consecutive. - Impossible or unintelligible rules: they are ignored with a warning, and
randomis used. - From the same repository,
quirks/change-password-URLs.json(MIT) gives each site's change-password page for the assisted change (§5). If it isn't there,https://<host>/.well-known/change-passwordis used, which belongs to the site itself, not to a third party.
1.4 Where it is
Extension: the menu of the new-password field gains the kind selector, "Copy", "Another", "Use this password" and the bar. The password is set in Geist Mono, colored by character type and without using blue, which in Klav means agents:
- letters in Tinta;
- digits in Gris;
- symbols in Tinta on Niebla.
It is noted in
diseno-visualwhen implemented.iOS: on the item page when creating or editing a login, with the rules of its URL's host.
CLI:
klav generate [--type smart|random|memorable|pin] [--site HOST] [--length N] [--words N] ….All three call the same
klav-coreAPI (WASM,klav-ffiand Rust), so they give the same result.
2. Generator history
Problem: a generated password typed into a sign-up or change form is lost if the form fails, if the page reloads or if the person doesn't press "Save".
Decision: every generated password is saved encrypted before it goes out to the page. It is saved in an item of its own, synced, and is written locally first.
- The item: a new
ItemKind::GeneratorHistory, one per account, in a system projectKlavin the personal vault.- The client never includes that project in a grant:
--vault Vskips it and a grant that names it isn't signed. An agent never receives its key. - It doesn't appear in the item list; it is opened from the generator ("Generator history").
- It syncs like any item, so the password generated on the Mac is on the iPhone.
- The client never includes that project in a grant:
- Local-first writing:
- On the desktop, the extension sends the password to
klavd(new operationgenerator_record, with the host).klavdadds it to a sealed local queue and only then does the extension type it into the page. The queue is the0x43type of ADR 0020 §11, which stops being iOS-only. - The queue is flushed to the item in the background. Without the network, the password stays in the queue and isn't lost.
- On iOS, the app generates and saves in the same flow. The AutoFill extension uses the outbox of ADR 0020 §11.
- Without
klavd(for example, if the extension isn't hooked up), the menu says "Without Klav on this computer, this password isn't kept in the history" and lets you copy it.
- On the desktop, the extension sends the password to
- Each entry: the value (secret), the date, the host and, if it was saved afterwards, the
item_idof the login where it ended up. - How many and for how long:
- the last 200 entries, or 365 days, whichever comes first;
- an entry already saved in a login is deleted after 30 days, because that login already has it in its own history (§3).
- How it is deleted:
- one entry or "Delete all", from the generator history;
- deleting writes a new version of the item without those entries, and then purges its previous versions on the server (new person route,
DELETE /v1/vaults/{v}/items/{i}/versions). Otherwise, the 50 stored versions would keep what was deleted.
- Rejected alternatives:
- only the local queue: it doesn't sync and is lost with the computer;
- keeping it in the vault without an item (a new vault blob): it would force a sync route of its own.
3. Per-item password history
Problem: the version history doesn't work as a password history.
- It deletes after 50 edits of any kind: changing the tags 50 times takes old passwords with it.
- Versions go in details with the item key, so an agent with
fillcould also ask for them.
Decision: the password history goes separately, inside the item, sealed with the vault key.
- The password record: new blob
0x16password-record, the same envelope as0x15:- sealed with the
VaultKey, which no agent receives (ADR 0014 §2.2); - AAD =
header ‖ tuple("klav/v1/item/password-record", account_id, vault_id, item_id); - it goes in details as
password_record(base64url), like the passkey blob; - the content is JSON:
{v, history: [{field, value, from_ms, to_ms}], pending: {field, value, created_at_ms, task_id?}?};pendingis the assisted change's (§5); - fields it covers: those of type
passwordandconcealed, by name.
- sealed with the
- Why with the vault key: old passwords are often still alive on other sites (exactly the reused case), so they are worth as much as the current ones. A runtime with
fillreceives the current one because it needs it; it never needs the old ones.- Cost: the same as ADR 0020 P4: a person with whom only a project is shared doesn't see the history.
- An agent with
updatecan't read it or move it to another item (AAD), but it could remove it from details when rewriting the item. The server's 50 versions and the audit log mitigate this (residual risk 27).
- Cap: 100 previous passwords per field; past that, the oldest is discarded. It is a few bytes and doesn't depend on how many times the item is edited.
- When it is written: each time one of the person's clients (or
klavdin the assisted change) changes apasswordorconcealedfield, it moves the previous value tohistorywith its dates.klav-coredoes it (Item::set_secret_field), not each interface. - What already exists isn't lost: the first time one of the person's clients writes an item's record, it backfills it from the server's versions: it decrypts them and takes the distinct values, with each version's date.
- Where it is shown: "Previous passwords" on the item page in the extension and on iOS, with the date and copy or show; and
klav item history <ref> [--reveal N] [--copy N], which by default only shows dates and masks. - The server's version history stays, to restore the whole item (
api.md§4.4).max_item_versionsdoesn't change. - Rejected alternative: raising
max_item_versionsor not counting edits without a password. It doesn't solve the old ones reaching an agent withfill, and the server doesn't know what changed (it doesn't see the content).
4. Vault health
It is computed on the client: the server sees nothing, so it can't.
- What it measures:
- reused: the same value in two or more items. They are compared in memory, by the SHA-256 of a random salt for that run and the value, and none of that is saved;
- weak:
zxcvbnwith a score ≤ 2, or known entropy < 40 bits if it came from the generator; - old: unchanged for more than a year (according to the record of §3, or the creation date).
- Where:
klavd(operationvault_health, which the popup shows),klav healthin the CLI and the iOS app throughklav-ffi. The extension computes nothing: it asksklavdfor the result, like everything else. zxcvbn3.1.1 (MIT, verified on crates.io on 2026-11-04) goes inklav-clientbehind thehealthfeature. It isn't cryptography.klav-wasmdoesn't build it (its dictionaries weigh about 1 MB).- Breached passwords (optional, off by default): a Have I Been Pwned lookup with k-anonymity.
- Only the 5-hex-character prefix of the SHA-1 is sent, to
api.pwnedpasswords.com/range/, withAdd-Padding: trueso that the response size gives nothing away. - It is a query to a third party, so the rule applies: it is turned on only if the person turns it on, with a text that says what is sent (the prefix, and the IP and the time the third party sees). The setting is local.
- SHA-1 is a new cryptographic dependency for
klav-core, and this ADR lists it:sha10.11 (MIT OR Apache-2.0, from RustCrypto, already inCargo.lockviatungstenite), behind thebreach-checkfeature. It is only used to compute HIBP's prefix and suffix, never for a Klav security purpose.klav-clientdoes the networking. On accepting, it goes into theCLAUDE.mdlist.
- Only the 5-hex-character prefix of the SHA-1 is sent, to
- What it offers: each problem links to the item, and the reused ones offer "Fix with an agent" (§6).
5. Agent-assisted password change
- It is a task (ADR 0021) with the new
rotatepermission.- Like
passkey, it only exists inside a task: no grant can haverotaterules (ADR 0021 §5). rotateimplies filling the current password in the change form, so there is no need to ask forfillseparately for that item.
- Like
- The agent never sees the old password or the new one.
klavdgenerates and types them.- There is only the
extensiontarget, with the person'sklavd, unlocked and on their machine. Withsdk:the new value would go through the agent's runtime. - It is the same restriction as with passkeys (ADR 0020 §9): an agent in the cloud can't.
- There is only the
- The flow, for each site:
- The agent opens the change page.
change_password_url(ref)gives the site's (§1.3). rotate_password(ref, target: "extension", reason): the server checks the task and records the event.klavdverifies the task's signed decision, as in ADR 0020 §9, step 3.klavdgenerates the new one with the site's rules (the form'spasswordrules, or the bundled ones).- Before touching the page,
klavdwrites a new version of the item: the current one stays the same, the new one goes aspendingin the0x16record, and the old one is already inhistory. If that write fails, it fills nothing. - The extension fills "current password" with the old one, and "new" and "confirm" with the new one (the
current-passwordandnew-passwordfieldsfill.tsalready recognizes). Only in a tab whose host matches the item (T61). To the agent it only answers{filled: [...], pending_id}. - The agent submits the form (
submit: trueor a click) and looks at the result: a success message, or an error that says why the site rejected it. rotate_confirm(ref, pending_id, reason):klavdwrites another version, in which the new one becomes the current one and the old one stays inhistorywith its end date.rotate_cancel(ref, pending_id, reason)keeps the current one and moves the pending one tohistory, marked "generated, not confirmed".
- The agent opens the change page.
- No password is lost. On any failure (the site rejects it, the network drops, the agent stops) the old one and the pending one stay saved.
- While there is a pending one, the item page says "Pending change: did the new password work?", with [Use the new one] and [Keep the current one].
- The page's menu offers both to the person, so they aren't locked out if the site accepted the new one and nobody confirmed it.
- Audit log: each step is an event under the task (
rotate.started,rotate.confirmed,rotate.cancelled), with theitem_idand the host, never values.
6. "Fix my reused passwords"
- Vault health proposes the list: the logins that share a password, with their change page.
- The person offers the task to an agent, without the agent seeing the list of reused ones:
- in the popup, the app or
klav health --fix-with <agente>, the person chooses the agent, reviews the list (unchecks what they don't want) and approves once with Face ID or Touch ID; - their client signs a task decision (ADR 0021 §4) without a prior request from the agent, with
rotate(andtotpwhere needed) for those logins. It is an "offered task":requestis empty and the person writestaskandreason.
- in the popup, the app or
- The agent sees it with
list_tasks()and goes through the sites one by one with the flow of §5.klav log --task <id>shows each site as changed, pending or failed. - Why this way: if the agent could ask "which passwords are reused", the LLM would learn which accounts share a secret. The person already knows; the agent only needs the list of sites.
7. MCP tools
| Tool | Permission | Returns |
|---|---|---|
change_password_url(ref) |
list |
the site's change URL, or /.well-known/change-password |
rotate_password(ref, target, reason, task_id?) |
rotate (in a task) |
{filled, pending_id} |
rotate_confirm(ref, pending_id, reason) |
rotate |
{ok: true} |
rotate_cancel(ref, pending_id, reason) |
rotate |
{ok: true} |
list_tasks() |
— | the agent's tasks, also the offered ones (ADR 0021 §7) |
- There is no tool to generate a password and return it: the value would enter the LLM's context. Instead,
create_itemgainsgenerate: true(with optionaltypeandsite). The runtime generates the password with the site's rules and seals it; to the LLM it only returns the metadata. It is the way for an agent to create an account with a strong password without seeing it. It is governed bycreate, as today.
8. Skill (when it is implemented, not now)
skill/SKILL.md gains a few lines:
- to change passwords, ask for a task with
rotate, or use the one the person offered you (list_tasks); - for each site:
change_password_url, open the page,rotate_passwordwithtarget: "extension", submit the form, check, and callrotate_confirm(orrotate_cancelif the site rejected it); - never try to see, copy or type the password yourself;
- for a new account,
create_itemwithgenerate: true.
Consequences
Specification:
- §2.3, the label
klav/v1/item/password-record; - §3, the type
0x16; - §7.1, the
password_recordkey in details and thegenerator_historykind; - a new §7.3 for the password record.
vstays at 1. An old client skips items with these keys ("does not decrypt"), as with passkeys; nothing is published.- §2.3, the label
klav-core:generator::rules(thepasswordrulesinterpreter) and Apple's data with its license notice;generate_pin;- the
0x16record andItem::set_secret_field; ItemKind::GeneratorHistory;Permission::Rotate;- the
breach-checkfeature withsha1.
klav-client: thehealthfeature withzxcvbn, the record backfill from versions, and the optional HIBP lookup.klavd:generator_record,vault_healthand the assisted-change operations (agent_rotate_begin,agent_rotate_confirm,agent_rotate_cancel). The0x43queue is also used on the desktop.Server:
DELETE /v1/vaults/{v}/items/{i}/versions(person) and therotate.*events. Blobs stay opaque.Interfaces: the new generator in the extension, iOS and the CLI; "Previous passwords"; vault health;
klav item historyandklav health.Threat model: §5.10 (T96–T101) and residual risk 27.
docs/diseno-visual: the colors of the generated password (§1.4), when implemented.
Questions for Omar
Each one had a default value, which is what this ADR describes. Omar accepted the ADR on 2026-11-04 without changing any, so all of them keep their default value. Omar also set the work order (1) generator and history (ADR 0022 §1–3, done), 2) importers, 3) task requests (ADR 0021), 4) assisted change (ADR 0022 §5–7), 5) passkeys (ADR 0020) and 6) Android (phase 7)), which puts the assisted change after task requests.
| # | Question | Default |
|---|---|---|
| G1 | The generator's default kind? | Smart, with 20 characters if the site sets no rules |
| G2 | Bundle Apple's rules (MIT)? | Yes, updated by a repository script, never at run time |
| G3 | Where does the generator history live? | An item of its own in a system project that no grant includes, with local-first writing (0x43) |
| G4 | How many entries and for how long? | 200 entries or 365 days; 30 days if it was already saved in a login |
| G5 | Password history separate from versions? | Yes: the 0x16 record sealed with the vault key, 100 per field |
| G6 | Backfill the history from the versions that already exist? | Yes, the first time a client writes the record |
| G7 | Breached-password lookup (HIBP)? | Optional and off by default, with k-anonymity and padding |
| G8 | sha1 in klav-core for HIBP? |
Yes, behind breach-check; only for the HIBP prefix |
| G9 | Who starts "fix the reused ones"? | The person, who offers the task to an agent; the agent doesn't query the health |
| G10 | Password colors | Letters in Tinta, digits in Gris, symbols in Tinta on Niebla; no blue |