Skip to content

feat(chat): secret card in the chat when an agent asks for a key - #1712

Merged
vansin merged 4 commits into
mainfrom
feat/chat-secret-card
Nov 24, 2026
Merged

vansin merged 4 commits into
mainfrom
feat/chat-secret-card

Conversation

@vansin

@vansin vansin commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

admin 需求(2026-11-24):用户在聊天里说「帮我存个 GitHub 密钥」时,不让人把值贴进对话,而是在聊天里弹一张加密输入卡(参考 Grok Bot 截图的 Secrets 卡)。

配套:Hub 侧 request_secret 工具 —— sleep2agi/agent-network#3864(把 {node_id,key,label,hint} 作为 reply_secret_request 落到回复的任务行,永无值)。

这个 PR(App 侧,第 2/3 步)

  • 回复气泡读到 meta_json.reply_secret_request ⇒ 渲染成密钥卡,代替兜底文字(旧 Hub / 读不出 ⇒ 照常显示兜底文字「到设置 → 密钥里添加」)
  • 卡片:标题 = 人话名(如「GitHub 密钥」)+ 变量名;一行用途说明;输入默认隐藏 + 小眼睛切换;保存;底部「安全保存,AI 看不到内容;这个 AI 下次启动后可用(环境变量 X)」;在气泡里不再套第二层框
  • 保存 = 读节点密钥拿 revision → put(复用设置页的 scopedSecrets),成功后以用户身份走正常发送路径发一句「🔑 已在卡片里保存「GitHub 密钥」(GITHUB_TOKEN)…」——只含名字不含值,AI 收到才继续
  • 重开聊天:后面已有那句「已保存」⇒ 卡片直接显示已保存,不为此发任何请求(不拖慢打开聊天)
  • 失败说人话 + 下一步:非管理员 / 机器版本太旧 / 内容为空或超 8KB / 机器没回应
  • 值只在输入框状态和 put 参数里:不进消息、不进日志、不给 AI

验证

  • 新增 src/chat-secret-request.test.ts 15/15;原有 secret-request-card 6/6、secret-request-wiring 8/8、settings-subpages 56/56、ui-scale-wiring 48/48、wide-layout-wiring 37/37
  • 新增真导出 drive tests/test-chat-secret-card 23/23:桌面 1440 / 手机 390 × 浅 / 深,卡片出现、兜底文字隐藏、默认隐藏、小眼睛可切换、值不以文本出现;后面有「已保存」⇒ 卡片显示已保存
  • tsc 本次改动文件无错误

下一步:Dashboard 同款卡片(第 3/3 步);合并发版后真机(两台小米 + Mac)走一遍「说要存密钥 → 弹卡 → 保存 → AI 继续」。

🤖 Generated with Claude Code

admin 2026-11-24: when a user wants to hand an agent a key, show a secure input
card in the conversation instead of having them paste it. Hub request_secret
(agent-network#3864) puts {node_id,key,label,hint} on the reply's task row as
reply_secret_request; the reply bubble renders it as a card (masked input, eye
toggle, save) in place of the fallback text. Save reads the node secrets for
the revision, puts the value, then sends a normal user message saying the key
was saved (name only) so the agent continues. A later saved message marks the
card saved when the chat is reopened, with no extra request. Errors are plain
language with a next step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T09:11:14.094094Z 1b7bf59 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1b7bf59d30

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/ChatScreen.tsx Outdated
<MessageHoverActions side="reply" styles={styles} onCopy={() => void copyMessage(item.result ?? item.reply ?? '')} onMore={at => openMenuAt(at, { item, text: item.result ?? item.reply ?? '', author: alias })} />
) : null}
{secretCard ? (
<ChatSecretCard cfg={cfg} request={secretCard} alreadySaved={savedSecrets.has(secretCard.key)} onSaved={sendPlainText} />

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Match saved confirmations to the individual secret request

If a user saves GITHUB_TOKEN and later asks to replace an expired or revoked token, the earlier confirmation remains in savedSecrets, so the new request immediately renders as saved. ChatSecretCard then hides the input and refuses further saves, preventing the replacement through chat. Because the set includes the entire loaded history without timestamps or request identity, even a confirmation predating this request satisfies it. Associate confirmations with the corresponding request, or at least require a matching confirmation after that request, rather than treating a key as permanently saved.

Useful? React with 👍 / 👎.

Comment thread src/ChatScreen.tsx Outdated
<MessageHoverActions side="reply" styles={styles} onCopy={() => void copyMessage(item.result ?? item.reply ?? '')} onMore={at => openMenuAt(at, { item, text: item.result ?? item.reply ?? '', author: alias })} />
) : null}
{secretCard ? (
<ChatSecretCard cfg={cfg} request={secretCard} alreadySaved={savedSecrets.has(secretCard.key)} onSaved={sendPlainText} />

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exempt the secret input from the message context-menu handler

On desktop with a fine pointer, right-clicking the new secret input cannot open its native editing menu, so users cannot paste a credential through right-click → Paste. The input is now inside the reply's [data-message-key] wrapper, and handleMessageContextMenu in ChatScreen.tsx:1463–1483 intercepts every context-menu event within that wrapper at document capture phase, calls preventDefault() and stopImmediatePropagation(), and opens the message menu instead. Exempt editable input targets from that handler so the secret field retains its normal paste/edit actions.

Useful? React with 👍 / 👎.

ANet负责人 and others added 3 commits November 24, 2026 09:17
…fter it

Review on #1712 (通信客户端欧) and #463 (通信Dash欧): the saved check was a
key-wide set over the whole history, so an old GITHUB_TOKEN confirmation marked
a later re-request (e.g. replacing an expired token) as saved and disabled the
input. Now a card is saved only by a 'saved' message the current user sent
after that card; others' messages and failed sends don't count. Tests cover
the re-request, other sender, other key and pending-echo cases (19/19).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review on #1712 (通信客户端欧): a missing or unparsable card/confirmation time
was treated as 'after the card', so an old confirmation could still swallow a
new request. Unknown times now never count; a fresh save stays saved through
the card's own phase, and local echoes carry a real timestamp. Negative tests
for missing/invalid confirmation and card times.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…json

Fixes the drive-registry.test.ts failure on #1712 (all 4 CI failures
shared this single cause): test-chat-secret-card/drive.mjs is a
stub-only Playwright drive (web export + Chromium, no Hub/seed env)
and now registers as kind "stub" (secs: 20).

Diff-Shape: +4/-0
@vansin
vansin merged commit 28d0c61 into main Nov 24, 2026
22 checks passed
vansin added a commit that referenced this pull request Nov 24, 2026
…er & QA fixes (#1719)

* chore(release): 0.2.618 chat secret card, desktop warm glow, iOS viewer & QA fixes

Ships #1701-#1710, #1712 (chat secret card), #1713 (iOS ImageViewer Fabric
stability), #1714 (#5420 Android Fresco EmptyDrawable), #1715 (Settings
window warm yellow glow), #1716 (Windows popout ChatToolRail top offset),
and #1718 (transparent Windows WinTitleBar + hollow restore glyph).

Diff-Shape: +24/-10

* docs(release): clarify 618 validation and secret card availability

---------

Co-authored-by: 通信欧 <comm-ou@anet.sh>
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