Skip to content

fix(login): mask the API key prompt so a paste is visible - #8

Merged
doedja merged 1 commit into
mainfrom
agent/mask-api-key-prompt
Aug 7, 2026
Merged

fix(login): mask the API key prompt so a paste is visible#8
doedja merged 1 commit into
mainfrom
agent/mask-api-key-prompt

Conversation

@doedja

@doedja doedja commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Problem

kenari login --api-key showed nothing at all while you typed or pasted:

Paste your kenari API key (kn-...):

A paste is a single event, so a blank prompt gives no way to tell whether the clipboard actually landed. The command reads as broken even when it works.

Change

Create a key at https://kenari.id/keys
Paste your kenari API key: ***********************************
ok: stored kn-f4k...234

askHidden becomes askSecret and renders from iface.line on every readline refresh, rather than from the chunk readline happens to pass in. That is what makes a clipboard paste (which arrives as one chunk) show its full width, backspace shrink the row, and readline's cursor escapes stay out of the output.

Masking is skipped when stdout is not a TTY, so escape codes never land in a capture file. The piped form (echo "$KEY" | kenari login --api-key) is unaffected.

An ASCII * rather than a bullet: this repo runs Windows CI, and a bullet renders as ? under a legacy console codepage.

Why no visible prefix

A partial-reveal variant (kn-f4ke*****) would confirm you pasted the right key, not just a key. Not needed: setKey already enforces /^kn-[A-Za-z0-9]{8,}$/ locally, so a ghp_ token or a truncated key fails immediately with a clear error. The format check does that job without putting anything readable in scrollback.

Verification

94/94 pass. renderMasked is asserted directly, because the failure mode here is silent: writing the line instead of the mask puts a live credential into scrollback and still "works".

check result
masked row is prompt + '*' * len(key) pass
rendered output never contains kn- pass
backspace shrinks the row pass
real pty run: key absent from terminal, key stored pass

The assertions were confirmed load-bearing by running them against a deliberately echoing renderer, which fails on masked row. That was done in a throwaway script rather than by weakening the guard in src/.

The earlier Ctrl-D fix is intact: an abandoned prompt still exits 1 rather than 0.

Docs

README no longer claims the prompt is hidden, since it is now masked.

`kenari login --api-key` gave no feedback at all while typing or pasting.
A paste is a single event, so a blank prompt left no way to tell whether
the clipboard landed, and the command read as broken even when it worked.

The prompt now shows one `*` per character. `askHidden` becomes
`askSecret` and redraws from the interface's current line rather than the
chunk readline hands over, so a paste that arrives as one chunk still
shows its full width, backspace shrinks the row, and readline's cursor
escapes do not leak into the output. Masking is skipped when stdout is
redirected, to keep escape codes out of a capture file.

An ASCII `*` rather than a bullet, which renders as `?` under a legacy
Windows console codepage.

A wrong clipboard is already caught by the existing local format check in
setKey, so the mask does not need to reveal a prefix to be useful.
@doedja
doedja merged commit c34ce34 into main Aug 7, 2026
6 checks passed
@doedja
doedja deleted the agent/mask-api-key-prompt branch August 7, 2026 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant