Import the client, server, skills, tests, and build scripts as the starting point for the rebuild, then trim the surfaces this project does not ship: Electron desktop packaging, the marketing website, and the ESP32 firmware tree. CI keeps the web build, e2e, lockfile, release, and Docker workflows. Rename the package and CLI entry points to hermes-ui, drop the prepare hook so npm ci no longer triggers a build, and drop the removed tsconfig and nodemon references. Rewrite AGENTS.md, ARCHITECTURE.md, DEVELOPMENT.md, and the READMEs so the documented package map and hard rules match this repository. reference_code/ is ignored: it is a read-only snapshot, not an input to the build.
118 lines
3.2 KiB
TypeScript
118 lines
3.2 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
import { ref, watch } from 'vue'
|
|
import { useProfilesStore } from './profiles'
|
|
|
|
const PIN_KEY_PREFIX = 'hermes_session_pins_v1_'
|
|
const HUMAN_ONLY_KEY_PREFIX = 'hermes_human_only_v1_'
|
|
|
|
function currentProfileName(): string {
|
|
try {
|
|
return useProfilesStore().activeProfileName || 'default'
|
|
} catch {
|
|
// Fallback during store initialization
|
|
return localStorage.getItem('hermes_active_profile_name') || 'default'
|
|
}
|
|
}
|
|
|
|
function pinsKey(profileName: string): string {
|
|
return `${PIN_KEY_PREFIX}${profileName}`
|
|
}
|
|
|
|
function humanOnlyKey(profileName: string): string {
|
|
return `${HUMAN_ONLY_KEY_PREFIX}${profileName}`
|
|
}
|
|
|
|
function loadJson<T>(key: string, fallback: T): T {
|
|
try {
|
|
const raw = localStorage.getItem(key)
|
|
return raw ? JSON.parse(raw) as T : fallback
|
|
} catch {
|
|
return fallback
|
|
}
|
|
}
|
|
|
|
function saveJson(key: string, value: unknown) {
|
|
try {
|
|
localStorage.setItem(key, JSON.stringify(value))
|
|
} catch {
|
|
// ignore quota/storage errors — fall back to in-memory only
|
|
}
|
|
}
|
|
|
|
function sameIds(a: string[], b: string[]): boolean {
|
|
return a.length === b.length && a.every((value, index) => value === b[index])
|
|
}
|
|
|
|
export const useSessionBrowserPrefsStore = defineStore('session-browser-prefs', () => {
|
|
const profileName = ref(currentProfileName())
|
|
const pinnedIds = ref<string[]>(loadJson<string[]>(pinsKey(profileName.value), []))
|
|
const humanOnly = ref<boolean>(loadJson<boolean>(humanOnlyKey(profileName.value), true))
|
|
|
|
function reload() {
|
|
profileName.value = currentProfileName()
|
|
pinnedIds.value = loadJson<string[]>(pinsKey(profileName.value), [])
|
|
humanOnly.value = loadJson<boolean>(humanOnlyKey(profileName.value), true)
|
|
}
|
|
|
|
function persistPins() {
|
|
saveJson(pinsKey(profileName.value), pinnedIds.value)
|
|
}
|
|
|
|
function persistHumanOnly() {
|
|
saveJson(humanOnlyKey(profileName.value), humanOnly.value)
|
|
}
|
|
|
|
function isPinned(sessionId: string): boolean {
|
|
return pinnedIds.value.includes(sessionId)
|
|
}
|
|
|
|
function togglePinned(sessionId: string) {
|
|
if (isPinned(sessionId)) {
|
|
pinnedIds.value = pinnedIds.value.filter(id => id !== sessionId)
|
|
} else {
|
|
pinnedIds.value = [...pinnedIds.value, sessionId]
|
|
}
|
|
persistPins()
|
|
}
|
|
|
|
function removePinned(sessionId: string): boolean {
|
|
if (!isPinned(sessionId)) return false
|
|
pinnedIds.value = pinnedIds.value.filter(id => id !== sessionId)
|
|
persistPins()
|
|
return true
|
|
}
|
|
|
|
function setHumanOnly(value: boolean) {
|
|
if (humanOnly.value === value) return
|
|
humanOnly.value = value
|
|
persistHumanOnly()
|
|
}
|
|
|
|
function pruneMissingSessions(existingIds: string[]): boolean {
|
|
if (existingIds.length === 0) return false
|
|
const existing = new Set(existingIds)
|
|
const nextPinnedIds = pinnedIds.value.filter(id => existing.has(id))
|
|
if (sameIds(nextPinnedIds, pinnedIds.value)) return false
|
|
pinnedIds.value = nextPinnedIds
|
|
persistPins()
|
|
return true
|
|
}
|
|
|
|
watch(
|
|
() => useProfilesStore().activeProfileName,
|
|
() => reload(),
|
|
)
|
|
|
|
return {
|
|
profileName,
|
|
pinnedIds,
|
|
humanOnly,
|
|
reload,
|
|
isPinned,
|
|
togglePinned,
|
|
removePinned,
|
|
setHumanOnly,
|
|
pruneMissingSessions,
|
|
}
|
|
})
|