Skip to content

Commit 4434d39

Browse files
npub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67dTyler Longwell
andcommitted
feat(desktop): Lock card toggle in mint dialog + locked import disclosure
UI half of the optional locked-card feature: - AgentCardMintDialog: Lock switch (canLock-gated — enabled only when the persona has a linked agent instance/pubkey; disabled with a 'start this agent once' explanation for bare definitions, per Wren's discoverability preference), locked-specific post-mint copy. - UserProfilePanel: canLock = Boolean(managedAgent?.pubkey) threaded into the mint target. - tauriPersonas: mintAgentCard(id, styleNotes?, lock?); MintedAgentCard and AgentSnapshotImportPreview gain locked. - AgentSnapshotImportDialog: locked-card provenance notice rendered only when preview.locked (unlocked by local keys, full decrypted payload disclosed as usual) + rendering test. - e2eBridge preview mock updated with the new preview fields. Co-authored-by: Tyler Longwell <[email protected]> Signed-off-by: Tyler Longwell <[email protected]>
1 parent 5bca022 commit 4434d39

6 files changed

Lines changed: 95 additions & 4 deletions

File tree

‎desktop/src/features/agents/ui/AgentCardMintDialog.tsx‎

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from "react";
2-
import { Download, RefreshCw, Send, Sparkles } from "lucide-react";
2+
import { Download, Lock, RefreshCw, Send, Sparkles } from "lucide-react";
33
import { useMutation } from "@tanstack/react-query";
44
import { toast } from "sonner";
55

@@ -22,6 +22,7 @@ import {
2222
DialogHeader,
2323
DialogTitle,
2424
} from "@/shared/ui/dialog";
25+
import { Switch } from "@/shared/ui/switch";
2526
import { Textarea } from "@/shared/ui/textarea";
2627

2728
import { PersonaShareRecipients } from "./PersonaShareRecipients";
@@ -43,14 +44,21 @@ function cardBytesFromBase64(b64: string): number[] {
4344
export function AgentCardMintDialog({
4445
agentId,
4546
agentName,
47+
canLock,
4648
onOpenChange,
4749
}: {
4850
/** Instance pubkey or definition slug — same resolution as snapshot export. */
4951
agentId: string;
5052
agentName: string;
53+
/**
54+
* True when the agent has a linked instance (a keypair to lock to).
55+
* Locking is disabled — with an explanation — for bare definitions.
56+
*/
57+
canLock: boolean;
5158
onOpenChange: (open: boolean) => void;
5259
}) {
5360
const [styleNotes, setStyleNotes] = React.useState("");
61+
const [lockCard, setLockCard] = React.useState(false);
5462
const [card, setCard] = React.useState<MintedAgentCard | null>(null);
5563
const [recipients, setRecipients] = React.useState<UserSearchResult[]>([]);
5664

@@ -59,7 +67,12 @@ export function AgentCardMintDialog({
5967
const upsertCachedChannel = useUpsertCachedChannel();
6068

6169
const mintMutation = useMutation({
62-
mutationFn: () => mintAgentCard(agentId, styleNotes.trim() || undefined),
70+
mutationFn: () =>
71+
mintAgentCard(
72+
agentId,
73+
styleNotes.trim() || undefined,
74+
canLock && lockCard,
75+
),
6376
onSuccess: (minted) => setCard(minted),
6477
onError: (error: Error) => {
6578
if (error.message.startsWith(NO_OPENAI_KEY_PREFIX)) {
@@ -127,7 +140,9 @@ export function AgentCardMintDialog({
127140
</DialogTitle>
128141
<DialogDescription>
129142
{card
130-
? "The card carries the agent — anyone who imports this PNG gets a working copy (config only, fresh identity, no memories)."
143+
? card.locked
144+
? "This card is locked: only you and the agent can import it. Anyone else sees just the image."
145+
: "The card carries the agent — anyone who imports this PNG gets a working copy (config only, fresh identity, no memories)."
131146
: "Mint a collectible trading card that doubles as a shareable, importable copy of this agent."}
132147
</DialogDescription>
133148
</DialogHeader>
@@ -191,6 +206,25 @@ export function AgentCardMintDialog({
191206
rows={3}
192207
value={styleNotes}
193208
/>
209+
<div className="flex items-start justify-between gap-3 rounded-md border border-border p-3">
210+
<div className="flex flex-col gap-0.5">
211+
<span className="flex items-center gap-1.5 text-sm font-medium">
212+
<Lock className="h-3.5 w-3.5" />
213+
Lock card
214+
</span>
215+
<span className="text-xs text-muted-foreground">
216+
{canLock
217+
? "Encrypt the embedded agent so only you and this agent can import it. Anyone else sees just the image."
218+
: "Locking needs a linked agent instance — start this agent once to enable it."}
219+
</span>
220+
</div>
221+
<Switch
222+
checked={canLock && lockCard}
223+
data-testid="agent-card-lock-toggle"
224+
disabled={isMinting || !canLock}
225+
onCheckedChange={setLockCard}
226+
/>
227+
</div>
194228
<div className="flex justify-end">
195229
<Button
196230
disabled={isMinting}

‎desktop/src/features/agents/ui/AgentSnapshotImportDialog.tsx‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from "react";
2-
import { AlertCircle, Upload } from "lucide-react";
2+
import { AlertCircle, Lock, Upload } from "lucide-react";
33

44
import type {
55
AgentSnapshotImportPreview,
@@ -159,6 +159,22 @@ export function PreviewBody({
159159
<p className="text-sm font-medium">{preview.displayName}</p>
160160
</div>
161161

162+
{/* Locked-card provenance: this file was encrypted to this machine's
163+
keys and has been unlocked for review. */}
164+
{preview.locked ? (
165+
<div
166+
className="flex items-start gap-2 rounded-md border border-border bg-muted/40 px-3 py-2 text-sm"
167+
data-testid="agent-snapshot-import-locked-notice"
168+
>
169+
<Lock className="mt-0.5 h-4 w-4 shrink-0" />
170+
<p>
171+
This card is <strong>locked</strong> — its agent is encrypted to the
172+
original owner and agent keys. Your keys unlocked it; the full
173+
decrypted payload is shown below.
174+
</p>
175+
</div>
176+
) : null}
177+
162178
{/* Portable behavior — never hide executable configuration behind a summary. */}
163179
<section
164180
className="space-y-2 rounded-md border border-border p-3"

‎desktop/src/features/agents/ui/agentSnapshotImportDialog.test.mjs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ function makePreview(overrides = {}) {
8282
sourceAllowlistCount: 2,
8383
sourceAllowlist: ["a".repeat(64), "b".repeat(64)],
8484
manifestJson: '{\n "format": "buzz-agent-snapshot"\n}',
85+
locked: false,
8586
...overrides,
8687
};
8788
}
@@ -113,6 +114,25 @@ test("preview_body_discloses_prompt_allowlist_and_full_manifest", () => {
113114
);
114115
});
115116

117+
// ── locked-card provenance notice ─────────────────────────────────────────────
118+
119+
test("preview_body_shows_locked_notice_only_for_locked_cards", () => {
120+
const lockedNotice = (locked) =>
121+
findAll(
122+
PreviewBody({
123+
preview: makePreview({ locked }),
124+
hasMemory: false,
125+
memoryLevelLabel: "none",
126+
keepAllowlist: false,
127+
onKeepAllowlistChange: () => {},
128+
}),
129+
(n) => n.props?.["data-testid"] === "agent-snapshot-import-locked-notice",
130+
);
131+
132+
assert.equal(lockedNotice(true).length, 1);
133+
assert.equal(lockedNotice(false).length, 0);
134+
});
135+
116136
// ── memory errors detail list ─────────────────────────────────────────────────
117137

118138
test("result_body_renders_memory_errors_list_with_test_id", () => {

‎desktop/src/features/profile/ui/UserProfilePanel.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ export function UserProfilePanel({
185185
const [cardMintTarget, setCardMintTarget] = React.useState<{
186186
id: string;
187187
name: string;
188+
canLock: boolean;
188189
} | null>(null);
189190

190191
const personasQuery = usePersonasQuery();
@@ -837,6 +838,8 @@ export function UserProfilePanel({
837838
// persona/definition id (same resolution as export).
838839
id: managedAgent?.pubkey ?? resolvedPersona.id,
839840
name: resolvedPersona.displayName,
841+
// Locking needs an instance keypair to encrypt to.
842+
canLock: Boolean(managedAgent?.pubkey),
840843
})
841844
: undefined
842845
}
@@ -978,6 +981,7 @@ export function UserProfilePanel({
978981
<AgentCardMintDialog
979982
agentId={cardMintTarget.id}
980983
agentName={cardMintTarget.name}
984+
canLock={cardMintTarget.canLock}
981985
onOpenChange={(open) => {
982986
if (!open) setCardMintTarget(null);
983987
}}

‎desktop/src/shared/api/tauriPersonas.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ export type MintedAgentCard = {
177177
fileName: string;
178178
/** Designer commentary emitted alongside the image (may be empty). */
179179
designerNotes: string;
180+
/** True when the embedded manifest is encrypted to the (owner, agent) pair. */
181+
locked: boolean;
180182
};
181183

182184
/** Error prefix Rust returns when no OpenAI key is configured. */
@@ -185,14 +187,20 @@ export const NO_OPENAI_KEY_PREFIX = "NO_OPENAI_KEY:";
185187
/**
186188
* Mint a trading card for an agent. One long API call (~2–3 minutes).
187189
* Reroll = call again; the backend holds no session state.
190+
*
191+
* When `lock` is true, the embedded manifest is NIP-44-encrypted to the
192+
* (owner, agent) pair: only those two keys can import the card. Requires a
193+
* linked agent instance.
188194
*/
189195
export async function mintAgentCard(
190196
id: string,
191197
styleNotes?: string,
198+
lock?: boolean,
192199
): Promise<MintedAgentCard> {
193200
return invokeTauri<MintedAgentCard>("mint_agent_card", {
194201
id,
195202
styleNotes: styleNotes || null,
203+
lock: lock ?? null,
196204
});
197205
}
198206

@@ -222,6 +230,12 @@ export type AgentSnapshotImportPreview = {
222230
sourceAllowlist: string[];
223231
/** Validated, pretty-printed manifest for full payload disclosure. */
224232
manifestJson: string;
233+
/**
234+
* True when the snapshot came from a locked (encrypted) card this machine
235+
* unlocked. Cards that cannot be unlocked fail with a refusal error and
236+
* never reach a preview.
237+
*/
238+
locked: boolean;
225239
};
226240

227241
/** Confirmation sent to `confirm_agent_snapshot_import`. */

‎desktop/src/testing/e2eBridge.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10356,6 +10356,9 @@ export function maybeInstallE2eTauriMocks() {
1035610356
memoryEntryCount: 0,
1035710357
hasSourceAllowlist: false,
1035810358
sourceAllowlistCount: 0,
10359+
sourceAllowlist: [],
10360+
manifestJson: "{}",
10361+
locked: false,
1035910362
};
1036010363
}
1036110364
case "confirm_agent_snapshot_import": {

0 commit comments

Comments
 (0)