Skip to content

The agent that grows with you

fix(desktop): hash persisted agent tip identities

wangtao7a15dd19434f
diff --git a/apps/desktop/src/store/tips.test.ts b/apps/desktop/src/store/tips.test.ts
index 0b24a1f9237..1eb5227e11c 100644
--- a/apps/desktop/src/store/tips.test.ts
+++ b/apps/desktop/src/store/tips.test.ts
@@ -25,6 +25,7 @@ describe('agent tip retirement', () => {
showAgentTip('[data-tour="model-pill"]', 'Choose a model here.')
expect(tipId).toBe(agentTipId('[data-tour="model-pill"]', 'Choose a model here.'))
+ expect(tipId).not.toContain('Choose a model here.')
expect($retiredTips.get()).toContain(tipId)
expect($activeTip.get()).toBeNull()
})
diff --git a/apps/desktop/src/store/tips.ts b/apps/desktop/src/store/tips.ts
index 3a58baf4d8f..40739b3b735 100644
--- a/apps/desktop/src/store/tips.ts
+++ b/apps/desktop/src/store/tips.ts
@@ -69,9 +69,18 @@ export const $nextTipAt = persistentAtom<null | number>(
)
export const $activeTip = atom<ActiveTip | null>(null)
-/** Agent tips have no catalog entry, so their content is their durable identity. */
+/** Agent tips have no catalog entry, so hash their content into a compact durable identity. */
export function agentTipId(selector: string, text: string): string {
- return `agent:${JSON.stringify([selector, text])}`
+ let hash = 0xcbf29ce484222325n
+ const identity = JSON.stringify([selector, text])
+
+ // Hash the tuple encoding so neither arbitrary agent copy nor selectors are persisted verbatim.
+ for (let index = 0; index < identity.length; index += 1) {
+ hash ^= BigInt(identity.charCodeAt(index))
+ hash = BigInt.asUintN(64, hash * 0x100000001b3n)
+ }
+
+ return `agent:${hash.toString(16).padStart(16, '0')}`
}
// Off has to reach the agent, not just the renderer: the `tip` tool leaves the