Compare commits
9 Commits
f8e989c5ab
...
v0.2.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
bc596867d4
|
|||
| e877f4aaf2 | |||
| 377f81d978 | |||
| d83697e5cf | |||
| 2d3adcab1c | |||
| 70fcaa8650 | |||
| a8f98406e1 | |||
| 0065bb4afc | |||
| ac84366716 |
@@ -0,0 +1,51 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Colors for output
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Function to run a command and check its status
|
||||||
|
run_check() {
|
||||||
|
local desc=$1
|
||||||
|
local cmd=$2
|
||||||
|
|
||||||
|
echo -e "\n${YELLOW}Running: ${desc}${NC}"
|
||||||
|
echo -e "${YELLOW}Command: ${cmd}${NC}"
|
||||||
|
|
||||||
|
if eval "$cmd"; then
|
||||||
|
echo -e "${GREEN}✓ ${desc} passed${NC}"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo -e "${RED}✗ ${desc} failed${NC}"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Track if any checks fail
|
||||||
|
failed=0
|
||||||
|
|
||||||
|
echo -e "${YELLOW}🔍 Running all checks for Hikari Desktop...${NC}"
|
||||||
|
|
||||||
|
# Frontend checks
|
||||||
|
run_check "Frontend lint" "pnpm lint" || failed=1
|
||||||
|
run_check "Frontend format check" "pnpm format:check" || failed=1
|
||||||
|
run_check "Frontend type check" "pnpm check" || failed=1
|
||||||
|
run_check "Frontend tests" "pnpm test" || failed=1
|
||||||
|
|
||||||
|
# Backend checks
|
||||||
|
run_check "Backend clippy (strict)" "cd src-tauri && cargo clippy --all-targets --all-features -- -D warnings" || failed=1
|
||||||
|
run_check "Backend tests" "cargo test" || failed=1
|
||||||
|
|
||||||
|
# Summary
|
||||||
|
echo -e "\n${YELLOW}========================================${NC}"
|
||||||
|
if [ $failed -eq 0 ]; then
|
||||||
|
echo -e "${GREEN}✨ All checks passed! The code is looking great!${NC}"
|
||||||
|
echo -e "${GREEN} Naomi would be so proud of us! 💖${NC}"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo -e "${RED}❌ Some checks failed. Let's fix them together!${NC}"
|
||||||
|
echo -e "${RED} Don't worry, we'll get through this! 💪${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hikari-desktop",
|
"name": "hikari-desktop",
|
||||||
"version": "0.1.0",
|
"version": "0.2.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -27,7 +27,9 @@
|
|||||||
"@tauri-apps/plugin-dialog": "^2",
|
"@tauri-apps/plugin-dialog": "^2",
|
||||||
"@tauri-apps/plugin-opener": "^2",
|
"@tauri-apps/plugin-opener": "^2",
|
||||||
"@tauri-apps/plugin-shell": "^2.3.4",
|
"@tauri-apps/plugin-shell": "^2.3.4",
|
||||||
"@tauri-apps/plugin-store": "^2"
|
"@tauri-apps/plugin-store": "^2",
|
||||||
|
"@tauri-apps/plugin-notification": "^2",
|
||||||
|
"@tauri-apps/plugin-os": "^2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.39.2",
|
"@eslint/js": "^9.39.2",
|
||||||
|
|||||||
@@ -14,9 +14,15 @@ importers:
|
|||||||
'@tauri-apps/plugin-dialog':
|
'@tauri-apps/plugin-dialog':
|
||||||
specifier: ^2
|
specifier: ^2
|
||||||
version: 2.6.0
|
version: 2.6.0
|
||||||
|
'@tauri-apps/plugin-notification':
|
||||||
|
specifier: ^2
|
||||||
|
version: 2.3.3
|
||||||
'@tauri-apps/plugin-opener':
|
'@tauri-apps/plugin-opener':
|
||||||
specifier: ^2
|
specifier: ^2
|
||||||
version: 2.5.3
|
version: 2.5.3
|
||||||
|
'@tauri-apps/plugin-os':
|
||||||
|
specifier: ^2
|
||||||
|
version: 2.3.2
|
||||||
'@tauri-apps/plugin-shell':
|
'@tauri-apps/plugin-shell':
|
||||||
specifier: ^2.3.4
|
specifier: ^2.3.4
|
||||||
version: 2.3.4
|
version: 2.3.4
|
||||||
@@ -726,9 +732,15 @@ packages:
|
|||||||
'@tauri-apps/plugin-dialog@2.6.0':
|
'@tauri-apps/plugin-dialog@2.6.0':
|
||||||
resolution: {integrity: sha512-q4Uq3eY87TdcYzXACiYSPhmpBA76shgmQswGkSVio4C82Sz2W4iehe9TnKYwbq7weHiL88Yw19XZm7v28+Micg==}
|
resolution: {integrity: sha512-q4Uq3eY87TdcYzXACiYSPhmpBA76shgmQswGkSVio4C82Sz2W4iehe9TnKYwbq7weHiL88Yw19XZm7v28+Micg==}
|
||||||
|
|
||||||
|
'@tauri-apps/plugin-notification@2.3.3':
|
||||||
|
resolution: {integrity: sha512-Zw+ZH18RJb41G4NrfHgIuofJiymusqN+q8fGUIIV7vyCH+5sSn5coqRv/MWB9qETsUs97vmU045q7OyseCV3Qg==}
|
||||||
|
|
||||||
'@tauri-apps/plugin-opener@2.5.3':
|
'@tauri-apps/plugin-opener@2.5.3':
|
||||||
resolution: {integrity: sha512-CCcUltXMOfUEArbf3db3kCE7Ggy1ExBEBl51Ko2ODJ6GDYHRp1nSNlQm5uNCFY5k7/ufaK5Ib3Du/Zir19IYQQ==}
|
resolution: {integrity: sha512-CCcUltXMOfUEArbf3db3kCE7Ggy1ExBEBl51Ko2ODJ6GDYHRp1nSNlQm5uNCFY5k7/ufaK5Ib3Du/Zir19IYQQ==}
|
||||||
|
|
||||||
|
'@tauri-apps/plugin-os@2.3.2':
|
||||||
|
resolution: {integrity: sha512-n+nXWeuSeF9wcEsSPmRnBEGrRgOy6jjkSU+UVCOV8YUGKb2erhDOxis7IqRXiRVHhY8XMKks00BJ0OAdkpf6+A==}
|
||||||
|
|
||||||
'@tauri-apps/plugin-shell@2.3.4':
|
'@tauri-apps/plugin-shell@2.3.4':
|
||||||
resolution: {integrity: sha512-ktsRWf8wHLD17aZEyqE8c5x98eNAuTizR1FSX475zQ4TxaiJnhwksLygQz+AGwckJL5bfEP13nWrlTNQJUpKpA==}
|
resolution: {integrity: sha512-ktsRWf8wHLD17aZEyqE8c5x98eNAuTizR1FSX475zQ4TxaiJnhwksLygQz+AGwckJL5bfEP13nWrlTNQJUpKpA==}
|
||||||
|
|
||||||
@@ -2263,10 +2275,18 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@tauri-apps/api': 2.9.1
|
'@tauri-apps/api': 2.9.1
|
||||||
|
|
||||||
|
'@tauri-apps/plugin-notification@2.3.3':
|
||||||
|
dependencies:
|
||||||
|
'@tauri-apps/api': 2.9.1
|
||||||
|
|
||||||
'@tauri-apps/plugin-opener@2.5.3':
|
'@tauri-apps/plugin-opener@2.5.3':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@tauri-apps/api': 2.9.1
|
'@tauri-apps/api': 2.9.1
|
||||||
|
|
||||||
|
'@tauri-apps/plugin-os@2.3.2':
|
||||||
|
dependencies:
|
||||||
|
'@tauri-apps/api': 2.9.1
|
||||||
|
|
||||||
'@tauri-apps/plugin-shell@2.3.4':
|
'@tauri-apps/plugin-shell@2.3.4':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@tauri-apps/api': 2.9.1
|
'@tauri-apps/api': 2.9.1
|
||||||
|
|||||||
@@ -429,6 +429,12 @@ version = "1.0.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg_aliases"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chrono"
|
name = "chrono"
|
||||||
version = "0.4.43"
|
version = "0.4.43"
|
||||||
@@ -436,8 +442,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "fac4744fb15ae8337dc853fee7fb3f4e48c0fbaa23d0afe49c447b4fab126118"
|
checksum = "fac4744fb15ae8337dc853fee7fb3f4e48c0fbaa23d0afe49c447b4fab126118"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iana-time-zone",
|
"iana-time-zone",
|
||||||
|
"js-sys",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"serde",
|
"serde",
|
||||||
|
"wasm-bindgen",
|
||||||
"windows-link 0.2.1",
|
"windows-link 0.2.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1173,6 +1181,16 @@ dependencies = [
|
|||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gethostname"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8"
|
||||||
|
dependencies = [
|
||||||
|
"rustix",
|
||||||
|
"windows-link 0.2.1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.1.16"
|
version = "0.1.16"
|
||||||
@@ -1393,20 +1411,24 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hikari-desktop"
|
name = "hikari-desktop"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tauri",
|
"tauri",
|
||||||
"tauri-build",
|
"tauri-build",
|
||||||
"tauri-plugin-dialog",
|
"tauri-plugin-dialog",
|
||||||
|
"tauri-plugin-notification",
|
||||||
"tauri-plugin-opener",
|
"tauri-plugin-opener",
|
||||||
|
"tauri-plugin-os",
|
||||||
"tauri-plugin-shell",
|
"tauri-plugin-shell",
|
||||||
"tauri-plugin-store",
|
"tauri-plugin-store",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"tokio",
|
"tokio",
|
||||||
"uuid",
|
"uuid",
|
||||||
|
"windows 0.62.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1909,6 +1931,18 @@ version = "0.1.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4"
|
checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mac-notification-sys"
|
||||||
|
version = "0.6.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "65fd3f75411f4725061682ed91f131946e912859d0044d39c4ec0aac818d7621"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"objc2",
|
||||||
|
"objc2-foundation",
|
||||||
|
"time",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "markup5ever"
|
name = "markup5ever"
|
||||||
version = "0.14.1"
|
version = "0.14.1"
|
||||||
@@ -2039,12 +2073,38 @@ version = "1.0.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086"
|
checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nix"
|
||||||
|
version = "0.30.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.10.0",
|
||||||
|
"cfg-if",
|
||||||
|
"cfg_aliases",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nodrop"
|
name = "nodrop"
|
||||||
version = "0.1.14"
|
version = "0.1.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
|
checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "notify-rust"
|
||||||
|
version = "4.11.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6442248665a5aa2514e794af3b39661a8e73033b1cc5e59899e1276117ee4400"
|
||||||
|
dependencies = [
|
||||||
|
"futures-lite",
|
||||||
|
"log",
|
||||||
|
"mac-notification-sys",
|
||||||
|
"serde",
|
||||||
|
"tauri-winrt-notification",
|
||||||
|
"zbus",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-conv"
|
name = "num-conv"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -2169,6 +2229,16 @@ dependencies = [
|
|||||||
"objc2-foundation",
|
"objc2-foundation",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "objc2-core-location"
|
||||||
|
version = "0.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ca347214e24bc973fc025fd0d36ebb179ff30536ed1f80252706db19ee452009"
|
||||||
|
dependencies = [
|
||||||
|
"objc2",
|
||||||
|
"objc2-foundation",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "objc2-core-text"
|
name = "objc2-core-text"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
@@ -2273,8 +2343,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "d87d638e33c06f577498cbcc50491496a3ed4246998a7fbba7ccb98b1e7eab22"
|
checksum = "d87d638e33c06f577498cbcc50491496a3ed4246998a7fbba7ccb98b1e7eab22"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.10.0",
|
"bitflags 2.10.0",
|
||||||
|
"block2",
|
||||||
"objc2",
|
"objc2",
|
||||||
|
"objc2-cloud-kit",
|
||||||
|
"objc2-core-data",
|
||||||
"objc2-core-foundation",
|
"objc2-core-foundation",
|
||||||
|
"objc2-core-graphics",
|
||||||
|
"objc2-core-image",
|
||||||
|
"objc2-core-location",
|
||||||
|
"objc2-core-text",
|
||||||
|
"objc2-foundation",
|
||||||
|
"objc2-quartz-core",
|
||||||
|
"objc2-user-notifications",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "objc2-user-notifications"
|
||||||
|
version = "0.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9df9128cbbfef73cda168416ccf7f837b62737d748333bfe9ab71c245d76613e"
|
||||||
|
dependencies = [
|
||||||
|
"objc2",
|
||||||
"objc2-foundation",
|
"objc2-foundation",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -2328,6 +2417,22 @@ dependencies = [
|
|||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "os_info"
|
||||||
|
version = "3.14.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e4022a17595a00d6a369236fdae483f0de7f0a339960a53118b818238e132224"
|
||||||
|
dependencies = [
|
||||||
|
"android_system_properties",
|
||||||
|
"log",
|
||||||
|
"nix",
|
||||||
|
"objc2",
|
||||||
|
"objc2-foundation",
|
||||||
|
"objc2-ui-kit",
|
||||||
|
"serde",
|
||||||
|
"windows-sys 0.61.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "os_pipe"
|
name = "os_pipe"
|
||||||
version = "1.2.3"
|
version = "1.2.3"
|
||||||
@@ -2575,7 +2680,7 @@ checksum = "740ebea15c5d1428f910cd1a5f52cebf8d25006245ed8ade92702f4943d91e07"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
"indexmap 2.13.0",
|
"indexmap 2.13.0",
|
||||||
"quick-xml",
|
"quick-xml 0.38.4",
|
||||||
"serde",
|
"serde",
|
||||||
"time",
|
"time",
|
||||||
]
|
]
|
||||||
@@ -2705,6 +2810,15 @@ dependencies = [
|
|||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quick-xml"
|
||||||
|
version = "0.37.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "331e97a1af0bf59823e6eadffe373d7b27f485be8748f71471c662c1f269b7fb"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quick-xml"
|
name = "quick-xml"
|
||||||
version = "0.38.4"
|
version = "0.38.4"
|
||||||
@@ -2754,6 +2868,16 @@ dependencies = [
|
|||||||
"rand_core 0.6.4",
|
"rand_core 0.6.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.9.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
|
||||||
|
dependencies = [
|
||||||
|
"rand_chacha 0.9.0",
|
||||||
|
"rand_core 0.9.5",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_chacha"
|
name = "rand_chacha"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
@@ -2774,6 +2898,16 @@ dependencies = [
|
|||||||
"rand_core 0.6.4",
|
"rand_core 0.6.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_chacha"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
|
||||||
|
dependencies = [
|
||||||
|
"ppv-lite86",
|
||||||
|
"rand_core 0.9.5",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_core"
|
name = "rand_core"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
@@ -2792,6 +2926,15 @@ dependencies = [
|
|||||||
"getrandom 0.2.17",
|
"getrandom 0.2.17",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.9.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom 0.3.4",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_hc"
|
name = "rand_hc"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
@@ -3479,6 +3622,15 @@ dependencies = [
|
|||||||
"syn 2.0.114",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sys-locale"
|
||||||
|
version = "0.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8eab9a99a024a169fe8a903cf9d4a3b3601109bcc13bd9e3c6fff259138626c4"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "system-deps"
|
name = "system-deps"
|
||||||
version = "6.2.2"
|
version = "6.2.2"
|
||||||
@@ -3526,7 +3678,7 @@ dependencies = [
|
|||||||
"tao-macros",
|
"tao-macros",
|
||||||
"unicode-segmentation",
|
"unicode-segmentation",
|
||||||
"url",
|
"url",
|
||||||
"windows",
|
"windows 0.61.3",
|
||||||
"windows-core 0.61.2",
|
"windows-core 0.61.2",
|
||||||
"windows-version",
|
"windows-version",
|
||||||
"x11-dl",
|
"x11-dl",
|
||||||
@@ -3597,7 +3749,7 @@ dependencies = [
|
|||||||
"webkit2gtk",
|
"webkit2gtk",
|
||||||
"webview2-com",
|
"webview2-com",
|
||||||
"window-vibrancy",
|
"window-vibrancy",
|
||||||
"windows",
|
"windows 0.61.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3720,6 +3872,25 @@ dependencies = [
|
|||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tauri-plugin-notification"
|
||||||
|
version = "2.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "01fc2c5ff41105bd1f7242d8201fdf3efd70749b82fa013a17f2126357d194cc"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"notify-rust",
|
||||||
|
"rand 0.9.2",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"serde_repr",
|
||||||
|
"tauri",
|
||||||
|
"tauri-plugin",
|
||||||
|
"thiserror 2.0.17",
|
||||||
|
"time",
|
||||||
|
"url",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-plugin-opener"
|
name = "tauri-plugin-opener"
|
||||||
version = "2.5.3"
|
version = "2.5.3"
|
||||||
@@ -3738,10 +3909,28 @@ dependencies = [
|
|||||||
"tauri-plugin",
|
"tauri-plugin",
|
||||||
"thiserror 2.0.17",
|
"thiserror 2.0.17",
|
||||||
"url",
|
"url",
|
||||||
"windows",
|
"windows 0.61.3",
|
||||||
"zbus",
|
"zbus",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tauri-plugin-os"
|
||||||
|
version = "2.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d8f08346c8deb39e96f86973da0e2d76cbb933d7ac9b750f6dc4daf955a6f997"
|
||||||
|
dependencies = [
|
||||||
|
"gethostname",
|
||||||
|
"log",
|
||||||
|
"os_info",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"serialize-to-javascript",
|
||||||
|
"sys-locale",
|
||||||
|
"tauri",
|
||||||
|
"tauri-plugin",
|
||||||
|
"thiserror 2.0.17",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-plugin-shell"
|
name = "tauri-plugin-shell"
|
||||||
version = "2.3.4"
|
version = "2.3.4"
|
||||||
@@ -3801,7 +3990,7 @@ dependencies = [
|
|||||||
"url",
|
"url",
|
||||||
"webkit2gtk",
|
"webkit2gtk",
|
||||||
"webview2-com",
|
"webview2-com",
|
||||||
"windows",
|
"windows 0.61.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3827,7 +4016,7 @@ dependencies = [
|
|||||||
"url",
|
"url",
|
||||||
"webkit2gtk",
|
"webkit2gtk",
|
||||||
"webview2-com",
|
"webview2-com",
|
||||||
"windows",
|
"windows 0.61.3",
|
||||||
"wry",
|
"wry",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -3880,6 +4069,18 @@ dependencies = [
|
|||||||
"toml 0.9.11+spec-1.1.0",
|
"toml 0.9.11+spec-1.1.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tauri-winrt-notification"
|
||||||
|
version = "0.7.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b1e66e07de489fe43a46678dd0b8df65e0c973909df1b60ba33874e297ba9b9"
|
||||||
|
dependencies = [
|
||||||
|
"quick-xml 0.37.5",
|
||||||
|
"thiserror 2.0.17",
|
||||||
|
"windows 0.61.3",
|
||||||
|
"windows-version",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tempfile"
|
name = "tempfile"
|
||||||
version = "3.24.0"
|
version = "3.24.0"
|
||||||
@@ -4557,7 +4758,7 @@ checksum = "7130243a7a5b33c54a444e54842e6a9e133de08b5ad7b5861cd8ed9a6a5bc96a"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"webview2-com-macros",
|
"webview2-com-macros",
|
||||||
"webview2-com-sys",
|
"webview2-com-sys",
|
||||||
"windows",
|
"windows 0.61.3",
|
||||||
"windows-core 0.61.2",
|
"windows-core 0.61.2",
|
||||||
"windows-implement",
|
"windows-implement",
|
||||||
"windows-interface",
|
"windows-interface",
|
||||||
@@ -4581,7 +4782,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "381336cfffd772377d291702245447a5251a2ffa5bad679c99e61bc48bacbf9c"
|
checksum = "381336cfffd772377d291702245447a5251a2ffa5bad679c99e61bc48bacbf9c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"thiserror 2.0.17",
|
"thiserror 2.0.17",
|
||||||
"windows",
|
"windows 0.61.3",
|
||||||
"windows-core 0.61.2",
|
"windows-core 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -4637,11 +4838,23 @@ version = "0.61.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893"
|
checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-collections",
|
"windows-collections 0.2.0",
|
||||||
"windows-core 0.61.2",
|
"windows-core 0.61.2",
|
||||||
"windows-future",
|
"windows-future 0.2.1",
|
||||||
"windows-link 0.1.3",
|
"windows-link 0.1.3",
|
||||||
"windows-numerics",
|
"windows-numerics 0.2.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows"
|
||||||
|
version = "0.62.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580"
|
||||||
|
dependencies = [
|
||||||
|
"windows-collections 0.3.2",
|
||||||
|
"windows-core 0.62.2",
|
||||||
|
"windows-future 0.3.2",
|
||||||
|
"windows-numerics 0.3.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4653,6 +4866,15 @@ dependencies = [
|
|||||||
"windows-core 0.61.2",
|
"windows-core 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-collections"
|
||||||
|
version = "0.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "23b2d95af1a8a14a3c7367e1ed4fc9c20e0a26e79551b1454d72583c97cc6610"
|
||||||
|
dependencies = [
|
||||||
|
"windows-core 0.62.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-core"
|
name = "windows-core"
|
||||||
version = "0.61.2"
|
version = "0.61.2"
|
||||||
@@ -4687,7 +4909,18 @@ checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-core 0.61.2",
|
"windows-core 0.61.2",
|
||||||
"windows-link 0.1.3",
|
"windows-link 0.1.3",
|
||||||
"windows-threading",
|
"windows-threading 0.1.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-future"
|
||||||
|
version = "0.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb"
|
||||||
|
dependencies = [
|
||||||
|
"windows-core 0.62.2",
|
||||||
|
"windows-link 0.2.1",
|
||||||
|
"windows-threading 0.2.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4734,6 +4967,16 @@ dependencies = [
|
|||||||
"windows-link 0.1.3",
|
"windows-link 0.1.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-numerics"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26"
|
||||||
|
dependencies = [
|
||||||
|
"windows-core 0.62.2",
|
||||||
|
"windows-link 0.2.1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-result"
|
name = "windows-result"
|
||||||
version = "0.3.4"
|
version = "0.3.4"
|
||||||
@@ -4863,6 +5106,15 @@ dependencies = [
|
|||||||
"windows-link 0.1.3",
|
"windows-link 0.1.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-threading"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37"
|
||||||
|
dependencies = [
|
||||||
|
"windows-link 0.2.1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-version"
|
name = "windows-version"
|
||||||
version = "0.1.7"
|
version = "0.1.7"
|
||||||
@@ -5089,7 +5341,7 @@ dependencies = [
|
|||||||
"webkit2gtk",
|
"webkit2gtk",
|
||||||
"webkit2gtk-sys",
|
"webkit2gtk-sys",
|
||||||
"webview2-com",
|
"webview2-com",
|
||||||
"windows",
|
"windows 0.61.3",
|
||||||
"windows-core 0.61.2",
|
"windows-core 0.61.2",
|
||||||
"windows-version",
|
"windows-version",
|
||||||
"x11-dl",
|
"x11-dl",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "hikari-desktop"
|
name = "hikari-desktop"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
description = "Hikari - Claude Code Visual Assistant"
|
description = "Hikari - Claude Code Visual Assistant"
|
||||||
authors = ["Naomi Carrigan"]
|
authors = ["Naomi Carrigan"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
@@ -23,5 +23,16 @@ tokio = { version = "1", features = ["full"] }
|
|||||||
parking_lot = "0.12"
|
parking_lot = "0.12"
|
||||||
uuid = { version = "1", features = ["v4"] }
|
uuid = { version = "1", features = ["v4"] }
|
||||||
tauri-plugin-store = "2.4.2"
|
tauri-plugin-store = "2.4.2"
|
||||||
|
tauri-plugin-notification = "2"
|
||||||
|
tauri-plugin-os = "2"
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
|
chrono = { version = "0.4.43", features = ["serde"] }
|
||||||
|
|
||||||
|
[target.'cfg(windows)'.dependencies]
|
||||||
|
windows = { version = "0.62", features = [
|
||||||
|
"Data_Xml_Dom",
|
||||||
|
"UI_Notifications",
|
||||||
|
"Win32_System_Com",
|
||||||
|
"Win32_Foundation",
|
||||||
|
] }
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,10 @@
|
|||||||
"opener:default",
|
"opener:default",
|
||||||
"shell:allow-spawn",
|
"shell:allow-spawn",
|
||||||
"shell:allow-stdin-write",
|
"shell:allow-stdin-write",
|
||||||
"shell:allow-kill"
|
"shell:allow-kill",
|
||||||
|
"notification:default",
|
||||||
|
"notification:allow-is-permission-granted",
|
||||||
|
"notification:allow-request-permission",
|
||||||
|
"notification:allow-notify"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,808 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::collections::HashSet;
|
||||||
|
use chrono::{DateTime, Utc, Timelike, Datelike};
|
||||||
|
use tauri_plugin_store::StoreExt;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||||
|
pub enum AchievementId {
|
||||||
|
// Token Milestones
|
||||||
|
FirstSteps, // 1,000 tokens
|
||||||
|
GrowingStrong, // 10,000 tokens
|
||||||
|
BlossomingCoder, // 100,000 tokens
|
||||||
|
TokenMaster, // 1,000,000 tokens
|
||||||
|
|
||||||
|
// Code Generation
|
||||||
|
HelloWorld, // First code block
|
||||||
|
CodeWizard, // 100 code blocks
|
||||||
|
ThousandBlocks, // 1,000 code blocks
|
||||||
|
|
||||||
|
// File Operations
|
||||||
|
FileManipulator, // 10 files edited
|
||||||
|
FileArchitect, // 100 files edited
|
||||||
|
|
||||||
|
// Conversation milestones
|
||||||
|
ConversationStarter, // 10 messages
|
||||||
|
ChattyKathy, // 100 messages
|
||||||
|
Conversationalist, // 1,000 messages
|
||||||
|
|
||||||
|
// Tool usage
|
||||||
|
Toolsmith, // 5 different tools
|
||||||
|
ToolMaster, // 10 different tools
|
||||||
|
|
||||||
|
// Time-based achievements
|
||||||
|
EarlyBird, // Started session 5-7 AM
|
||||||
|
NightOwl, // Coding after midnight
|
||||||
|
AllNighter, // Worked 2-5 AM
|
||||||
|
WeekendWarrior, // Coding on weekend
|
||||||
|
DedicatedDeveloper, // 30 days in a row
|
||||||
|
|
||||||
|
// Search and exploration
|
||||||
|
Explorer, // 50 searches
|
||||||
|
MasterSearcher, // 500 searches
|
||||||
|
|
||||||
|
// Session achievements
|
||||||
|
QuickSession, // Productive session < 5 min
|
||||||
|
FocusedWork, // 30 min session
|
||||||
|
DeepDive, // 2 hour session
|
||||||
|
MarathonSession, // 5+ hour session
|
||||||
|
|
||||||
|
// Special achievements
|
||||||
|
FirstMessage, // First message sent
|
||||||
|
FirstTool, // First tool used
|
||||||
|
FirstCodeBlock, // First code generated
|
||||||
|
FirstFileEdit, // First file edit
|
||||||
|
Polyglot, // 5+ languages in one session
|
||||||
|
SpeedCoder, // 10 code blocks in 10 minutes
|
||||||
|
ClaudeConnoisseur, // Used all Claude models
|
||||||
|
MarathonCoder, // 10k tokens in one session
|
||||||
|
|
||||||
|
// Relationship & Greetings
|
||||||
|
GoodMorning, // Say "good morning"
|
||||||
|
GoodNight, // Say "good night" or "goodnight"
|
||||||
|
ThankYou, // Say "thank you" or "thanks"
|
||||||
|
LoveYou, // Say "love you" or "ily"
|
||||||
|
|
||||||
|
// Personality & Fun
|
||||||
|
EmojiUser, // Use an emoji in a message
|
||||||
|
QuestionMaster, // Use "?" in 20 messages
|
||||||
|
CapsLock, // Send a message in ALL CAPS
|
||||||
|
PleaseAndThankYou, // Use "please" in messages
|
||||||
|
|
||||||
|
// Git & Development
|
||||||
|
GitGuru, // Use git commands 10 times
|
||||||
|
TestWriter, // Create test files
|
||||||
|
Debugger, // Fix bugs (messages with "fix", "bug", "error")
|
||||||
|
|
||||||
|
// Tool Mastery
|
||||||
|
BashMaster, // Use Bash tool 50 times
|
||||||
|
FileExplorer, // Use Read tool 100 times
|
||||||
|
SearchExpert, // Use Grep tool 50 times
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct Achievement {
|
||||||
|
pub id: AchievementId,
|
||||||
|
pub name: String,
|
||||||
|
pub description: String,
|
||||||
|
pub icon: String,
|
||||||
|
pub unlocked_at: Option<DateTime<Utc>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct AchievementProgress {
|
||||||
|
pub unlocked: HashSet<AchievementId>,
|
||||||
|
pub newly_unlocked: Vec<AchievementId>, // Achievements unlocked but not yet notified
|
||||||
|
#[serde(skip)]
|
||||||
|
pub session_start: Option<DateTime<Utc>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AchievementProgress {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
unlocked: HashSet::new(),
|
||||||
|
newly_unlocked: Vec::new(),
|
||||||
|
session_start: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unlock(&mut self, achievement: AchievementId) -> bool {
|
||||||
|
if self.unlocked.insert(achievement.clone()) {
|
||||||
|
self.newly_unlocked.push(achievement);
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn take_newly_unlocked(&mut self) -> Vec<AchievementId> {
|
||||||
|
std::mem::take(&mut self.newly_unlocked)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn is_unlocked(&self, achievement: &AchievementId) -> bool {
|
||||||
|
self.unlocked.contains(achievement)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn start_session(&mut self) {
|
||||||
|
self.session_start = Some(Utc::now());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for AchievementProgress {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_achievement_info(id: &AchievementId) -> Achievement {
|
||||||
|
match id {
|
||||||
|
// Token Milestones
|
||||||
|
AchievementId::FirstSteps => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "First Steps!".to_string(),
|
||||||
|
description: "Used 1,000 tokens".to_string(),
|
||||||
|
icon: "🌱".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::GrowingStrong => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Growing Strong!".to_string(),
|
||||||
|
description: "Used 10,000 tokens".to_string(),
|
||||||
|
icon: "🌸".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::BlossomingCoder => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Blossoming Coder!".to_string(),
|
||||||
|
description: "Used 100,000 tokens".to_string(),
|
||||||
|
icon: "🌺".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::TokenMaster => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Token Master!".to_string(),
|
||||||
|
description: "Used 1,000,000 tokens".to_string(),
|
||||||
|
icon: "🌟".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Code Generation
|
||||||
|
AchievementId::HelloWorld => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Hello World!".to_string(),
|
||||||
|
description: "Generated your first code block".to_string(),
|
||||||
|
icon: "📝".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::CodeWizard => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Code Wizard!".to_string(),
|
||||||
|
description: "Generated 100 code blocks".to_string(),
|
||||||
|
icon: "🎯".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::ThousandBlocks => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Thousand Blocks".to_string(),
|
||||||
|
description: "1,000 code blocks! You're a code machine!".to_string(),
|
||||||
|
icon: "🏗️".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
|
||||||
|
// File Operations
|
||||||
|
AchievementId::FileManipulator => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "File Manipulator".to_string(),
|
||||||
|
description: "Edited 10 files".to_string(),
|
||||||
|
icon: "📝".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::FileArchitect => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "File Architect".to_string(),
|
||||||
|
description: "Created or edited 100 files".to_string(),
|
||||||
|
icon: "🏛️".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Conversation milestones
|
||||||
|
AchievementId::ConversationStarter => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Conversation Starter".to_string(),
|
||||||
|
description: "Exchanged 10 messages".to_string(),
|
||||||
|
icon: "💬".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::ChattyKathy => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Chatty Kathy".to_string(),
|
||||||
|
description: "100 messages exchanged".to_string(),
|
||||||
|
icon: "🗣️".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::Conversationalist => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Master Conversationalist".to_string(),
|
||||||
|
description: "1,000 messages! We're really connecting!".to_string(),
|
||||||
|
icon: "💖".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Tool usage
|
||||||
|
AchievementId::Toolsmith => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Toolsmith".to_string(),
|
||||||
|
description: "Used 5 different tools".to_string(),
|
||||||
|
icon: "🔨".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::ToolMaster => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Tool Master".to_string(),
|
||||||
|
description: "Used 10 different tools efficiently".to_string(),
|
||||||
|
icon: "🛠️".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Time-based achievements
|
||||||
|
AchievementId::EarlyBird => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Early Bird".to_string(),
|
||||||
|
description: "Started a session between 5 AM and 7 AM".to_string(),
|
||||||
|
icon: "🌅".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::NightOwl => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Night Owl".to_string(),
|
||||||
|
description: "Coding after midnight".to_string(),
|
||||||
|
icon: "🦉".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::AllNighter => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "All Nighter".to_string(),
|
||||||
|
description: "Worked through the night (2 AM - 5 AM)".to_string(),
|
||||||
|
icon: "🌙".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::WeekendWarrior => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Weekend Warrior".to_string(),
|
||||||
|
description: "Coding on a weekend".to_string(),
|
||||||
|
icon: "⚔️".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::DedicatedDeveloper => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Dedicated Developer".to_string(),
|
||||||
|
description: "Coded for 30 days in a row".to_string(),
|
||||||
|
icon: "🏆".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Search and exploration
|
||||||
|
AchievementId::Explorer => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Explorer".to_string(),
|
||||||
|
description: "Used search tools 50 times".to_string(),
|
||||||
|
icon: "🔍".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::MasterSearcher => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Master Searcher".to_string(),
|
||||||
|
description: "Searched 500 times across files".to_string(),
|
||||||
|
icon: "🕵️♀️".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Session achievements
|
||||||
|
AchievementId::QuickSession => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Quick Session".to_string(),
|
||||||
|
description: "Completed a productive session in under 5 minutes".to_string(),
|
||||||
|
icon: "⚡".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::FocusedWork => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Focused Work".to_string(),
|
||||||
|
description: "Worked for 30 minutes straight".to_string(),
|
||||||
|
icon: "🎯".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::DeepDive => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Deep Dive".to_string(),
|
||||||
|
description: "Worked for 2 hours continuously".to_string(),
|
||||||
|
icon: "🏊♀️".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::MarathonSession => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Marathon Session".to_string(),
|
||||||
|
description: "5+ hour coding session!".to_string(),
|
||||||
|
icon: "🏃♀️".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Special achievements
|
||||||
|
AchievementId::FirstMessage => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "First Message".to_string(),
|
||||||
|
description: "Sent your first message to Hikari".to_string(),
|
||||||
|
icon: "✨".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::FirstTool => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "First Tool".to_string(),
|
||||||
|
description: "Used your first tool".to_string(),
|
||||||
|
icon: "🔧".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::FirstCodeBlock => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "First Code".to_string(),
|
||||||
|
description: "Generated your first code block".to_string(),
|
||||||
|
icon: "📦".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::FirstFileEdit => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "First Edit".to_string(),
|
||||||
|
description: "Made your first file edit".to_string(),
|
||||||
|
icon: "✏️".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::Polyglot => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Polyglot".to_string(),
|
||||||
|
description: "Generated code in 5+ languages in one session".to_string(),
|
||||||
|
icon: "🌍".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::SpeedCoder => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Speed Coder".to_string(),
|
||||||
|
description: "Generated 10 code blocks in 10 minutes".to_string(),
|
||||||
|
icon: "🚀".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::ClaudeConnoisseur => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Claude Connoisseur".to_string(),
|
||||||
|
description: "Used all available Claude models".to_string(),
|
||||||
|
icon: "🎨".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::MarathonCoder => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Marathon Coder".to_string(),
|
||||||
|
description: "10,000 tokens in a single session".to_string(),
|
||||||
|
icon: "🏃♂️".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Relationship & Greetings
|
||||||
|
AchievementId::GoodMorning => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Good Morning!".to_string(),
|
||||||
|
description: "Greeted Hikari with a good morning".to_string(),
|
||||||
|
icon: "🌅".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::GoodNight => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Good Night".to_string(),
|
||||||
|
description: "Said good night to Hikari".to_string(),
|
||||||
|
icon: "🌙".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::ThankYou => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Grateful Heart".to_string(),
|
||||||
|
description: "Thanked Hikari for her help".to_string(),
|
||||||
|
icon: "💝".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::LoveYou => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Love Connection".to_string(),
|
||||||
|
description: "Expressed love to Hikari".to_string(),
|
||||||
|
icon: "💕".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Personality & Fun
|
||||||
|
AchievementId::EmojiUser => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Emoji Enthusiast".to_string(),
|
||||||
|
description: "Used an emoji in your message".to_string(),
|
||||||
|
icon: "😊".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::QuestionMaster => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Question Master".to_string(),
|
||||||
|
description: "Asked 20 questions".to_string(),
|
||||||
|
icon: "❓".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::CapsLock => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "CAPS LOCK ENGAGED".to_string(),
|
||||||
|
description: "SENT A MESSAGE IN ALL CAPS".to_string(),
|
||||||
|
icon: "📢".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::PleaseAndThankYou => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Polite Programmer".to_string(),
|
||||||
|
description: "Said please in a request".to_string(),
|
||||||
|
icon: "🎩".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Git & Development
|
||||||
|
AchievementId::GitGuru => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Git Guru".to_string(),
|
||||||
|
description: "Used git commands 10 times".to_string(),
|
||||||
|
icon: "🌿".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::TestWriter => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Test Writer".to_string(),
|
||||||
|
description: "Created test files".to_string(),
|
||||||
|
icon: "🧪".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::Debugger => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Bug Squasher".to_string(),
|
||||||
|
description: "Fixed bugs and errors".to_string(),
|
||||||
|
icon: "🐛".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Tool Mastery
|
||||||
|
AchievementId::BashMaster => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Bash Master".to_string(),
|
||||||
|
description: "Used Bash tool 50 times".to_string(),
|
||||||
|
icon: "🐚".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::FileExplorer => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "File Explorer".to_string(),
|
||||||
|
description: "Read 100 files".to_string(),
|
||||||
|
icon: "📂".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
AchievementId::SearchExpert => Achievement {
|
||||||
|
id: id.clone(),
|
||||||
|
name: "Search Expert".to_string(),
|
||||||
|
description: "Used Grep tool 50 times".to_string(),
|
||||||
|
icon: "🔎".to_string(),
|
||||||
|
unlocked_at: None,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check achievements based on message content
|
||||||
|
pub fn check_message_achievements(
|
||||||
|
message: &str,
|
||||||
|
progress: &mut AchievementProgress,
|
||||||
|
) -> Vec<AchievementId> {
|
||||||
|
let mut newly_unlocked = Vec::new();
|
||||||
|
let message_lower = message.to_lowercase();
|
||||||
|
|
||||||
|
println!("Checking message achievements for: {}", message);
|
||||||
|
|
||||||
|
// Relationship & Greetings
|
||||||
|
if message_lower.contains("good morning") && progress.unlock(AchievementId::GoodMorning) {
|
||||||
|
newly_unlocked.push(AchievementId::GoodMorning);
|
||||||
|
}
|
||||||
|
if (message_lower.contains("good night") || message_lower.contains("goodnight"))
|
||||||
|
&& progress.unlock(AchievementId::GoodNight) {
|
||||||
|
newly_unlocked.push(AchievementId::GoodNight);
|
||||||
|
}
|
||||||
|
if (message_lower.contains("thank you") || message_lower.contains("thanks") || message_lower.contains("thx"))
|
||||||
|
&& progress.unlock(AchievementId::ThankYou) {
|
||||||
|
newly_unlocked.push(AchievementId::ThankYou);
|
||||||
|
}
|
||||||
|
if (message_lower.contains("love you") || message_lower.contains("ily"))
|
||||||
|
&& progress.unlock(AchievementId::LoveYou) {
|
||||||
|
newly_unlocked.push(AchievementId::LoveYou);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Personality & Fun
|
||||||
|
if message.chars().any(|c| c as u32 >= 0x1F300) && progress.unlock(AchievementId::EmojiUser) {
|
||||||
|
newly_unlocked.push(AchievementId::EmojiUser);
|
||||||
|
}
|
||||||
|
if message == message.to_uppercase() && message.len() > 5
|
||||||
|
&& message.chars().any(|c| c.is_alphabetic())
|
||||||
|
&& progress.unlock(AchievementId::CapsLock) {
|
||||||
|
newly_unlocked.push(AchievementId::CapsLock);
|
||||||
|
}
|
||||||
|
if message_lower.contains("please") && progress.unlock(AchievementId::PleaseAndThankYou) {
|
||||||
|
newly_unlocked.push(AchievementId::PleaseAndThankYou);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Git & Development patterns in messages
|
||||||
|
if (message_lower.contains("fix") || message_lower.contains("bug") || message_lower.contains("error"))
|
||||||
|
&& progress.unlock(AchievementId::Debugger) {
|
||||||
|
newly_unlocked.push(AchievementId::Debugger);
|
||||||
|
}
|
||||||
|
|
||||||
|
newly_unlocked
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check which achievements should be unlocked based on current stats
|
||||||
|
pub fn check_achievements(
|
||||||
|
stats: &crate::stats::UsageStats,
|
||||||
|
progress: &mut AchievementProgress,
|
||||||
|
) -> Vec<AchievementId> {
|
||||||
|
let mut newly_unlocked = Vec::new();
|
||||||
|
|
||||||
|
println!("Checking achievements with stats: messages={}, tokens={}, code_blocks={}",
|
||||||
|
stats.messages_exchanged,
|
||||||
|
stats.total_input_tokens + stats.total_output_tokens,
|
||||||
|
stats.code_blocks_generated);
|
||||||
|
println!("Currently unlocked: {:?}", progress.unlocked);
|
||||||
|
|
||||||
|
// Token milestones
|
||||||
|
let total_tokens = stats.total_input_tokens + stats.total_output_tokens;
|
||||||
|
if total_tokens >= 1_000 && progress.unlock(AchievementId::FirstSteps) {
|
||||||
|
println!("Unlocked FirstSteps achievement!");
|
||||||
|
newly_unlocked.push(AchievementId::FirstSteps);
|
||||||
|
}
|
||||||
|
if total_tokens >= 10_000 && progress.unlock(AchievementId::GrowingStrong) {
|
||||||
|
newly_unlocked.push(AchievementId::GrowingStrong);
|
||||||
|
}
|
||||||
|
if total_tokens >= 100_000 && progress.unlock(AchievementId::BlossomingCoder) {
|
||||||
|
newly_unlocked.push(AchievementId::BlossomingCoder);
|
||||||
|
}
|
||||||
|
if total_tokens >= 1_000_000 && progress.unlock(AchievementId::TokenMaster) {
|
||||||
|
newly_unlocked.push(AchievementId::TokenMaster);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Code generation
|
||||||
|
if stats.code_blocks_generated >= 1 && progress.unlock(AchievementId::HelloWorld) {
|
||||||
|
newly_unlocked.push(AchievementId::HelloWorld);
|
||||||
|
}
|
||||||
|
if stats.code_blocks_generated >= 100 && progress.unlock(AchievementId::CodeWizard) {
|
||||||
|
newly_unlocked.push(AchievementId::CodeWizard);
|
||||||
|
}
|
||||||
|
if stats.code_blocks_generated >= 1000 && progress.unlock(AchievementId::ThousandBlocks) {
|
||||||
|
newly_unlocked.push(AchievementId::ThousandBlocks);
|
||||||
|
}
|
||||||
|
|
||||||
|
// File operations
|
||||||
|
if stats.files_edited >= 10 && progress.unlock(AchievementId::FileManipulator) {
|
||||||
|
newly_unlocked.push(AchievementId::FileManipulator);
|
||||||
|
}
|
||||||
|
let total_files = stats.files_edited + stats.files_created;
|
||||||
|
if total_files >= 100 && progress.unlock(AchievementId::FileArchitect) {
|
||||||
|
newly_unlocked.push(AchievementId::FileArchitect);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Conversation milestones
|
||||||
|
if stats.messages_exchanged >= 1 && progress.unlock(AchievementId::FirstMessage) {
|
||||||
|
newly_unlocked.push(AchievementId::FirstMessage);
|
||||||
|
}
|
||||||
|
if stats.messages_exchanged >= 10 && progress.unlock(AchievementId::ConversationStarter) {
|
||||||
|
newly_unlocked.push(AchievementId::ConversationStarter);
|
||||||
|
}
|
||||||
|
if stats.messages_exchanged >= 100 && progress.unlock(AchievementId::ChattyKathy) {
|
||||||
|
newly_unlocked.push(AchievementId::ChattyKathy);
|
||||||
|
}
|
||||||
|
if stats.messages_exchanged >= 1000 && progress.unlock(AchievementId::Conversationalist) {
|
||||||
|
newly_unlocked.push(AchievementId::Conversationalist);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tool usage
|
||||||
|
let unique_tools = stats.tools_usage.len();
|
||||||
|
if unique_tools >= 5 && progress.unlock(AchievementId::Toolsmith) {
|
||||||
|
newly_unlocked.push(AchievementId::Toolsmith);
|
||||||
|
}
|
||||||
|
if unique_tools >= 10 && progress.unlock(AchievementId::ToolMaster) {
|
||||||
|
newly_unlocked.push(AchievementId::ToolMaster);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search and exploration
|
||||||
|
let search_tools = ["Glob", "Grep", "search", "Task"];
|
||||||
|
let search_count: u64 = search_tools.iter()
|
||||||
|
.filter_map(|tool| stats.tools_usage.get(*tool))
|
||||||
|
.sum();
|
||||||
|
if search_count >= 50 && progress.unlock(AchievementId::Explorer) {
|
||||||
|
newly_unlocked.push(AchievementId::Explorer);
|
||||||
|
}
|
||||||
|
if search_count >= 500 && progress.unlock(AchievementId::MasterSearcher) {
|
||||||
|
newly_unlocked.push(AchievementId::MasterSearcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Session duration achievements
|
||||||
|
let session_secs = stats.session_duration_seconds;
|
||||||
|
if session_secs < 300 && stats.session_messages_exchanged >= 5 && progress.unlock(AchievementId::QuickSession) {
|
||||||
|
newly_unlocked.push(AchievementId::QuickSession);
|
||||||
|
}
|
||||||
|
if session_secs >= 1800 && progress.unlock(AchievementId::FocusedWork) {
|
||||||
|
newly_unlocked.push(AchievementId::FocusedWork);
|
||||||
|
}
|
||||||
|
if session_secs >= 7200 && progress.unlock(AchievementId::DeepDive) {
|
||||||
|
newly_unlocked.push(AchievementId::DeepDive);
|
||||||
|
}
|
||||||
|
if session_secs >= 18000 && progress.unlock(AchievementId::MarathonSession) {
|
||||||
|
newly_unlocked.push(AchievementId::MarathonSession);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Session token achievement
|
||||||
|
let session_tokens = stats.session_input_tokens + stats.session_output_tokens;
|
||||||
|
if session_tokens >= 10000 && progress.unlock(AchievementId::MarathonCoder) {
|
||||||
|
newly_unlocked.push(AchievementId::MarathonCoder);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Special first-time achievements
|
||||||
|
if !stats.tools_usage.is_empty() && progress.unlock(AchievementId::FirstTool) {
|
||||||
|
newly_unlocked.push(AchievementId::FirstTool);
|
||||||
|
}
|
||||||
|
if stats.code_blocks_generated >= 1 && progress.unlock(AchievementId::FirstCodeBlock) {
|
||||||
|
newly_unlocked.push(AchievementId::FirstCodeBlock);
|
||||||
|
}
|
||||||
|
if stats.files_edited >= 1 && progress.unlock(AchievementId::FirstFileEdit) {
|
||||||
|
newly_unlocked.push(AchievementId::FirstFileEdit);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Speed coder - need to track time for this
|
||||||
|
// TODO: Implement tracking for 10 code blocks in 10 minutes
|
||||||
|
|
||||||
|
// Polyglot - need to track languages
|
||||||
|
// TODO: Implement tracking for multiple programming languages
|
||||||
|
|
||||||
|
// Claude Connoisseur - check model usage
|
||||||
|
// TODO: Track different Claude models used
|
||||||
|
|
||||||
|
// Tool mastery achievements
|
||||||
|
if let Some(bash_count) = stats.tools_usage.get("Bash") {
|
||||||
|
if *bash_count >= 50 && progress.unlock(AchievementId::BashMaster) {
|
||||||
|
newly_unlocked.push(AchievementId::BashMaster);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(read_count) = stats.tools_usage.get("Read") {
|
||||||
|
if *read_count >= 100 && progress.unlock(AchievementId::FileExplorer) {
|
||||||
|
newly_unlocked.push(AchievementId::FileExplorer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(grep_count) = stats.tools_usage.get("Grep") {
|
||||||
|
if *grep_count >= 50 && progress.unlock(AchievementId::SearchExpert) {
|
||||||
|
newly_unlocked.push(AchievementId::SearchExpert);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Git Guru - check git command usage in Bash
|
||||||
|
if let Some(bash_count) = stats.tools_usage.get("Bash") {
|
||||||
|
if *bash_count >= 10 && progress.unlock(AchievementId::GitGuru) {
|
||||||
|
// TODO: More specific git command tracking
|
||||||
|
newly_unlocked.push(AchievementId::GitGuru);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Time-based achievements
|
||||||
|
if let Some(session_start) = progress.session_start {
|
||||||
|
let hour = session_start.hour();
|
||||||
|
let weekday = session_start.weekday();
|
||||||
|
|
||||||
|
// Early bird - 5 AM to 7 AM
|
||||||
|
if (5..=7).contains(&hour) && progress.unlock(AchievementId::EarlyBird) {
|
||||||
|
newly_unlocked.push(AchievementId::EarlyBird);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Night owl - after midnight
|
||||||
|
let current_hour = Utc::now().hour();
|
||||||
|
if current_hour < 6 && progress.unlock(AchievementId::NightOwl) {
|
||||||
|
newly_unlocked.push(AchievementId::NightOwl);
|
||||||
|
}
|
||||||
|
|
||||||
|
// All nighter - 2 AM to 5 AM
|
||||||
|
if (2..=5).contains(¤t_hour) && progress.unlock(AchievementId::AllNighter) {
|
||||||
|
newly_unlocked.push(AchievementId::AllNighter);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Weekend warrior
|
||||||
|
use chrono::Weekday;
|
||||||
|
if (weekday == Weekday::Sat || weekday == Weekday::Sun) && progress.unlock(AchievementId::WeekendWarrior) {
|
||||||
|
newly_unlocked.push(AchievementId::WeekendWarrior);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dedicated Developer - need to track consecutive days
|
||||||
|
// TODO: Implement 30 days in a row tracking
|
||||||
|
|
||||||
|
newly_unlocked
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct AchievementUnlockedEvent {
|
||||||
|
pub achievement: Achievement,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save achievements to persistent store
|
||||||
|
pub async fn save_achievements(app: &tauri::AppHandle, progress: &AchievementProgress) -> Result<(), String> {
|
||||||
|
let store = app.store("achievements.json")
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
// Create a serializable version with just the unlocked achievement IDs
|
||||||
|
let unlocked_list: Vec<AchievementId> = progress.unlocked.iter().cloned().collect();
|
||||||
|
|
||||||
|
println!("Saving achievements: {:?}", unlocked_list);
|
||||||
|
|
||||||
|
store.set("unlocked", serde_json::to_value(unlocked_list).map_err(|e| e.to_string())?);
|
||||||
|
store.save().map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
println!("Achievements saved successfully");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load achievements from persistent store
|
||||||
|
pub async fn load_achievements(app: &tauri::AppHandle) -> AchievementProgress {
|
||||||
|
println!("Loading achievements from store...");
|
||||||
|
|
||||||
|
let store = match app.store("achievements.json") {
|
||||||
|
Ok(s) => s,
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to open achievements store: {}", e);
|
||||||
|
return AchievementProgress::new();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut progress = AchievementProgress::new();
|
||||||
|
|
||||||
|
// Get unlocked achievements
|
||||||
|
if let Some(unlocked_value) = store.get("unlocked") {
|
||||||
|
println!("Found unlocked value in store: {:?}", unlocked_value);
|
||||||
|
if let Ok(unlocked_list) = serde_json::from_value::<Vec<AchievementId>>(unlocked_value.clone()) {
|
||||||
|
println!("Loaded {} achievements", unlocked_list.len());
|
||||||
|
for achievement_id in unlocked_list {
|
||||||
|
progress.unlocked.insert(achievement_id);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("Failed to parse unlocked achievements");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("No unlocked achievements found in store");
|
||||||
|
}
|
||||||
|
|
||||||
|
progress
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_achievement_unlock() {
|
||||||
|
let mut progress = AchievementProgress::new();
|
||||||
|
|
||||||
|
// First unlock should return true
|
||||||
|
assert!(progress.unlock(AchievementId::FirstSteps));
|
||||||
|
assert!(progress.is_unlocked(&AchievementId::FirstSteps));
|
||||||
|
|
||||||
|
// Second unlock of same achievement should return false
|
||||||
|
assert!(!progress.unlock(AchievementId::FirstSteps));
|
||||||
|
|
||||||
|
// Newly unlocked should contain the achievement
|
||||||
|
let newly = progress.take_newly_unlocked();
|
||||||
|
assert_eq!(newly.len(), 1);
|
||||||
|
assert_eq!(newly[0], AchievementId::FirstSteps);
|
||||||
|
|
||||||
|
// After taking, newly unlocked should be empty
|
||||||
|
let newly = progress.take_newly_unlocked();
|
||||||
|
assert!(newly.is_empty());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
use parking_lot::Mutex;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use tauri::AppHandle;
|
||||||
|
|
||||||
|
use crate::config::ClaudeStartOptions;
|
||||||
|
use crate::stats::UsageStats;
|
||||||
|
use crate::wsl_bridge::WslBridge;
|
||||||
|
|
||||||
|
pub struct BridgeManager {
|
||||||
|
bridges: HashMap<String, WslBridge>,
|
||||||
|
app_handle: Option<AppHandle>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BridgeManager {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
BridgeManager {
|
||||||
|
bridges: HashMap::new(),
|
||||||
|
app_handle: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_app_handle(&mut self, app: AppHandle) {
|
||||||
|
self.app_handle = Some(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn start_claude(
|
||||||
|
&mut self,
|
||||||
|
conversation_id: &str,
|
||||||
|
options: ClaudeStartOptions,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
// Check if a bridge already exists for this conversation
|
||||||
|
if self.bridges.get(conversation_id).map(|b| b.is_running()).unwrap_or(false) {
|
||||||
|
return Err("Claude is already running for this conversation".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
let app = self.app_handle.as_ref()
|
||||||
|
.ok_or_else(|| "App handle not set".to_string())?
|
||||||
|
.clone();
|
||||||
|
|
||||||
|
// Create a new bridge for this conversation
|
||||||
|
let mut bridge = WslBridge::new_with_conversation_id(conversation_id.to_string());
|
||||||
|
|
||||||
|
// Start the Claude process
|
||||||
|
bridge.start(app, options)?;
|
||||||
|
|
||||||
|
// Store the bridge
|
||||||
|
self.bridges.insert(conversation_id.to_string(), bridge);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn stop_claude(&mut self, conversation_id: &str) -> Result<(), String> {
|
||||||
|
if let Some(bridge) = self.bridges.get_mut(conversation_id) {
|
||||||
|
let app = self.app_handle.as_ref()
|
||||||
|
.ok_or_else(|| "App handle not set".to_string())?;
|
||||||
|
bridge.stop(app);
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err("No Claude instance found for this conversation".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn interrupt_claude(&mut self, conversation_id: &str) -> Result<(), String> {
|
||||||
|
if let Some(bridge) = self.bridges.get_mut(conversation_id) {
|
||||||
|
let app = self.app_handle.as_ref()
|
||||||
|
.ok_or_else(|| "App handle not set".to_string())?;
|
||||||
|
bridge.interrupt(app)
|
||||||
|
} else {
|
||||||
|
Err("No Claude instance found for this conversation".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn send_prompt(&mut self, conversation_id: &str, message: String) -> Result<(), String> {
|
||||||
|
if let Some(bridge) = self.bridges.get_mut(conversation_id) {
|
||||||
|
bridge.send_message(&message)
|
||||||
|
} else {
|
||||||
|
Err("No Claude instance found for this conversation".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_claude_running(&self, conversation_id: &str) -> bool {
|
||||||
|
self.bridges.get(conversation_id)
|
||||||
|
.map(|b| b.is_running())
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_working_directory(&self, conversation_id: &str) -> Result<String, String> {
|
||||||
|
self.bridges.get(conversation_id)
|
||||||
|
.map(|b| b.get_working_directory().to_string())
|
||||||
|
.ok_or_else(|| "No Claude instance found for this conversation".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_usage_stats(&self, conversation_id: &str) -> Result<UsageStats, String> {
|
||||||
|
self.bridges.get(conversation_id)
|
||||||
|
.map(|b| b.get_stats())
|
||||||
|
.ok_or_else(|| "No Claude instance found for this conversation".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn cleanup_stopped_bridges(&mut self) {
|
||||||
|
// Remove bridges that are no longer running
|
||||||
|
self.bridges.retain(|_, bridge| bridge.is_running());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn stop_all(&mut self) {
|
||||||
|
if let Some(app) = &self.app_handle {
|
||||||
|
for (_, bridge) in self.bridges.iter_mut() {
|
||||||
|
bridge.stop(app);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.bridges.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn get_active_conversations(&self) -> Vec<String> {
|
||||||
|
self.bridges.keys()
|
||||||
|
.filter(|id| self.bridges.get(*id).map(|b| b.is_running()).unwrap_or(false))
|
||||||
|
.cloned()
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for BridgeManager {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type SharedBridgeManager = Arc<Mutex<BridgeManager>>;
|
||||||
|
|
||||||
|
pub fn create_shared_bridge_manager() -> SharedBridgeManager {
|
||||||
|
Arc::new(Mutex::new(BridgeManager::new()))
|
||||||
|
}
|
||||||
@@ -2,43 +2,66 @@ use tauri::{AppHandle, State};
|
|||||||
use tauri_plugin_store::StoreExt;
|
use tauri_plugin_store::StoreExt;
|
||||||
|
|
||||||
use crate::config::{ClaudeStartOptions, HikariConfig};
|
use crate::config::{ClaudeStartOptions, HikariConfig};
|
||||||
use crate::wsl_bridge::SharedBridge;
|
use crate::stats::UsageStats;
|
||||||
|
use crate::bridge_manager::SharedBridgeManager;
|
||||||
|
use crate::achievements::{load_achievements, get_achievement_info, AchievementUnlockedEvent};
|
||||||
|
|
||||||
const CONFIG_STORE_KEY: &str = "config";
|
const CONFIG_STORE_KEY: &str = "config";
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn start_claude(
|
pub async fn start_claude(
|
||||||
app: AppHandle,
|
bridge_manager: State<'_, SharedBridgeManager>,
|
||||||
bridge: State<'_, SharedBridge>,
|
conversation_id: String,
|
||||||
options: ClaudeStartOptions,
|
options: ClaudeStartOptions,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let mut bridge = bridge.lock();
|
let mut manager = bridge_manager.lock();
|
||||||
bridge.start(app, options)
|
manager.start_claude(&conversation_id, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn stop_claude(app: AppHandle, bridge: State<'_, SharedBridge>) -> Result<(), String> {
|
pub async fn stop_claude(
|
||||||
let mut bridge = bridge.lock();
|
bridge_manager: State<'_, SharedBridgeManager>,
|
||||||
bridge.stop(&app);
|
conversation_id: String,
|
||||||
Ok(())
|
) -> Result<(), String> {
|
||||||
|
let mut manager = bridge_manager.lock();
|
||||||
|
manager.stop_claude(&conversation_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn send_prompt(bridge: State<'_, SharedBridge>, message: String) -> Result<(), String> {
|
pub async fn interrupt_claude(
|
||||||
let mut bridge = bridge.lock();
|
bridge_manager: State<'_, SharedBridgeManager>,
|
||||||
bridge.send_message(&message)
|
conversation_id: String,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
let mut manager = bridge_manager.lock();
|
||||||
|
manager.interrupt_claude(&conversation_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn is_claude_running(bridge: State<'_, SharedBridge>) -> Result<bool, String> {
|
pub async fn send_prompt(
|
||||||
let bridge = bridge.lock();
|
bridge_manager: State<'_, SharedBridgeManager>,
|
||||||
Ok(bridge.is_running())
|
conversation_id: String,
|
||||||
|
message: String,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
let mut manager = bridge_manager.lock();
|
||||||
|
manager.send_prompt(&conversation_id, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn get_working_directory(bridge: State<'_, SharedBridge>) -> Result<String, String> {
|
pub async fn is_claude_running(
|
||||||
let bridge = bridge.lock();
|
bridge_manager: State<'_, SharedBridgeManager>,
|
||||||
Ok(bridge.get_working_directory().to_string())
|
conversation_id: String,
|
||||||
|
) -> Result<bool, String> {
|
||||||
|
let manager = bridge_manager.lock();
|
||||||
|
Ok(manager.is_claude_running(&conversation_id))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn get_working_directory(
|
||||||
|
bridge_manager: State<'_, SharedBridgeManager>,
|
||||||
|
conversation_id: String,
|
||||||
|
) -> Result<String, String> {
|
||||||
|
let manager = bridge_manager.lock();
|
||||||
|
manager.get_working_directory(&conversation_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -72,3 +95,32 @@ pub async fn save_config(app: AppHandle, config: HikariConfig) -> Result<(), Str
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn get_usage_stats(
|
||||||
|
bridge_manager: State<'_, SharedBridgeManager>,
|
||||||
|
conversation_id: String,
|
||||||
|
) -> Result<UsageStats, String> {
|
||||||
|
let manager = bridge_manager.lock();
|
||||||
|
manager.get_usage_stats(&conversation_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn load_saved_achievements(app: AppHandle) -> Result<Vec<AchievementUnlockedEvent>, String> {
|
||||||
|
use chrono::Utc;
|
||||||
|
|
||||||
|
// Load achievements from persistent store
|
||||||
|
let progress = load_achievements(&app).await;
|
||||||
|
|
||||||
|
// Create events for all previously unlocked achievements
|
||||||
|
let mut events = Vec::new();
|
||||||
|
for achievement_id in &progress.unlocked {
|
||||||
|
let mut info = get_achievement_info(achievement_id);
|
||||||
|
info.unlocked_at = Some(Utc::now()); // We don't store timestamps, so just use now
|
||||||
|
events.push(AchievementUnlockedEvent {
|
||||||
|
achievement: info,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(events)
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,9 +19,12 @@ pub struct ClaudeStartOptions {
|
|||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub allowed_tools: Vec<String>,
|
pub allowed_tools: Vec<String>,
|
||||||
|
|
||||||
|
#[serde(default)]
|
||||||
|
pub skip_greeting: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct HikariConfig {
|
pub struct HikariConfig {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub model: Option<String>,
|
pub model: Option<String>,
|
||||||
@@ -40,6 +43,47 @@ pub struct HikariConfig {
|
|||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub theme: Theme,
|
pub theme: Theme,
|
||||||
|
|
||||||
|
#[serde(default = "default_greeting_enabled")]
|
||||||
|
pub greeting_enabled: bool,
|
||||||
|
|
||||||
|
#[serde(default)]
|
||||||
|
pub greeting_custom_prompt: Option<String>,
|
||||||
|
|
||||||
|
#[serde(default = "default_notifications_enabled")]
|
||||||
|
pub notifications_enabled: bool,
|
||||||
|
|
||||||
|
#[serde(default = "default_notification_volume")]
|
||||||
|
pub notification_volume: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for HikariConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
model: None,
|
||||||
|
api_key: None,
|
||||||
|
custom_instructions: None,
|
||||||
|
mcp_servers_json: None,
|
||||||
|
auto_granted_tools: Vec::new(),
|
||||||
|
theme: Theme::default(),
|
||||||
|
greeting_enabled: true,
|
||||||
|
greeting_custom_prompt: None,
|
||||||
|
notifications_enabled: true,
|
||||||
|
notification_volume: 0.7,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_greeting_enabled() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_notifications_enabled() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_notification_volume() -> f32 {
|
||||||
|
0.7
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
|
||||||
@@ -63,6 +107,8 @@ mod tests {
|
|||||||
assert!(config.mcp_servers_json.is_none());
|
assert!(config.mcp_servers_json.is_none());
|
||||||
assert!(config.auto_granted_tools.is_empty());
|
assert!(config.auto_granted_tools.is_empty());
|
||||||
assert_eq!(config.theme, Theme::Dark);
|
assert_eq!(config.theme, Theme::Dark);
|
||||||
|
assert!(config.greeting_enabled);
|
||||||
|
assert!(config.greeting_custom_prompt.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -74,6 +120,10 @@ mod tests {
|
|||||||
mcp_servers_json: None,
|
mcp_servers_json: None,
|
||||||
auto_granted_tools: vec!["Read".to_string(), "Glob".to_string()],
|
auto_granted_tools: vec!["Read".to_string(), "Glob".to_string()],
|
||||||
theme: Theme::Light,
|
theme: Theme::Light,
|
||||||
|
greeting_enabled: true,
|
||||||
|
greeting_custom_prompt: Some("Hello!".to_string()),
|
||||||
|
notifications_enabled: true,
|
||||||
|
notification_volume: 0.7,
|
||||||
};
|
};
|
||||||
|
|
||||||
let json = serde_json::to_string(&config).unwrap();
|
let json = serde_json::to_string(&config).unwrap();
|
||||||
@@ -83,6 +133,8 @@ mod tests {
|
|||||||
assert_eq!(deserialized.custom_instructions, config.custom_instructions);
|
assert_eq!(deserialized.custom_instructions, config.custom_instructions);
|
||||||
assert_eq!(deserialized.auto_granted_tools, config.auto_granted_tools);
|
assert_eq!(deserialized.auto_granted_tools, config.auto_granted_tools);
|
||||||
assert_eq!(deserialized.theme, Theme::Light);
|
assert_eq!(deserialized.theme, Theme::Light);
|
||||||
|
assert!(deserialized.greeting_enabled);
|
||||||
|
assert_eq!(deserialized.greeting_custom_prompt, Some("Hello!".to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -1,30 +1,58 @@
|
|||||||
|
mod achievements;
|
||||||
|
mod bridge_manager;
|
||||||
mod commands;
|
mod commands;
|
||||||
mod config;
|
mod config;
|
||||||
|
mod notifications;
|
||||||
|
mod stats;
|
||||||
mod types;
|
mod types;
|
||||||
mod wsl_bridge;
|
mod wsl_bridge;
|
||||||
|
mod wsl_notifications;
|
||||||
|
mod vbs_notification;
|
||||||
|
mod windows_toast;
|
||||||
|
|
||||||
use commands::*;
|
use commands::*;
|
||||||
use wsl_bridge::create_shared_bridge;
|
use notifications::*;
|
||||||
|
use bridge_manager::create_shared_bridge_manager;
|
||||||
|
use commands::load_saved_achievements;
|
||||||
|
use wsl_notifications::*;
|
||||||
|
use vbs_notification::*;
|
||||||
|
use windows_toast::*;
|
||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
let bridge = create_shared_bridge();
|
let bridge_manager = create_shared_bridge_manager();
|
||||||
|
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.plugin(tauri_plugin_dialog::init())
|
.plugin(tauri_plugin_dialog::init())
|
||||||
.plugin(tauri_plugin_opener::init())
|
.plugin(tauri_plugin_opener::init())
|
||||||
.plugin(tauri_plugin_shell::init())
|
.plugin(tauri_plugin_shell::init())
|
||||||
.plugin(tauri_plugin_store::Builder::new().build())
|
.plugin(tauri_plugin_store::Builder::new().build())
|
||||||
.manage(bridge)
|
.plugin(tauri_plugin_notification::init())
|
||||||
|
.plugin(tauri_plugin_os::init())
|
||||||
|
.manage(bridge_manager.clone())
|
||||||
|
.setup(move |app| {
|
||||||
|
// Initialize the app handle in the bridge manager
|
||||||
|
bridge_manager.lock().set_app_handle(app.handle().clone());
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
start_claude,
|
start_claude,
|
||||||
stop_claude,
|
stop_claude,
|
||||||
|
interrupt_claude,
|
||||||
send_prompt,
|
send_prompt,
|
||||||
is_claude_running,
|
is_claude_running,
|
||||||
get_working_directory,
|
get_working_directory,
|
||||||
select_wsl_directory,
|
select_wsl_directory,
|
||||||
get_config,
|
get_config,
|
||||||
save_config,
|
save_config,
|
||||||
|
get_usage_stats,
|
||||||
|
load_saved_achievements,
|
||||||
|
send_windows_notification,
|
||||||
|
send_simple_notification,
|
||||||
|
send_windows_toast,
|
||||||
|
send_notify_send,
|
||||||
|
send_wsl_notification,
|
||||||
|
send_vbs_notification,
|
||||||
])
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
use tauri::command;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
pub async fn send_notify_send(title: String, body: String) -> Result<(), String> {
|
||||||
|
// Use notify-send for Linux/WSL
|
||||||
|
let output = Command::new("notify-send")
|
||||||
|
.arg(&title)
|
||||||
|
.arg(&body)
|
||||||
|
.arg("--urgency=normal")
|
||||||
|
.arg("--app-name=Hikari Desktop")
|
||||||
|
.output()
|
||||||
|
.map_err(|e| format!("Failed to execute notify-send: {}. Make sure libnotify-bin is installed.", e))?;
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
let error = String::from_utf8_lossy(&output.stderr);
|
||||||
|
return Err(format!("notify-send failed: {}", error));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
pub async fn send_windows_notification(title: String, body: String) -> Result<(), String> {
|
||||||
|
// Create PowerShell script for Windows Toast Notification
|
||||||
|
let ps_script = format!(
|
||||||
|
r#"
|
||||||
|
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
|
||||||
|
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] > $null
|
||||||
|
|
||||||
|
$APP_ID = 'Hikari Desktop'
|
||||||
|
|
||||||
|
$template = @"
|
||||||
|
<toast>
|
||||||
|
<visual>
|
||||||
|
<binding template="ToastText02">
|
||||||
|
<text id="1">{}</text>
|
||||||
|
<text id="2">{}</text>
|
||||||
|
</binding>
|
||||||
|
</visual>
|
||||||
|
<audio src="ms-winsoundevent:Notification.Default" />
|
||||||
|
</toast>
|
||||||
|
"@
|
||||||
|
|
||||||
|
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
|
||||||
|
$xml.LoadXml($template)
|
||||||
|
|
||||||
|
$toast = New-Object Windows.UI.Notifications.ToastNotification $xml
|
||||||
|
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($APP_ID).Show($toast)
|
||||||
|
"#,
|
||||||
|
title.replace("\"", "`\""),
|
||||||
|
body.replace("\"", "`\"")
|
||||||
|
);
|
||||||
|
|
||||||
|
// Try PowerShell Core first (pwsh), then fall back to Windows PowerShell
|
||||||
|
let output = Command::new("pwsh.exe")
|
||||||
|
.arg("-NoProfile")
|
||||||
|
.arg("-WindowStyle")
|
||||||
|
.arg("Hidden")
|
||||||
|
.arg("-Command")
|
||||||
|
.arg(&ps_script)
|
||||||
|
.output()
|
||||||
|
.or_else(|_| {
|
||||||
|
Command::new("powershell.exe")
|
||||||
|
.arg("-NoProfile")
|
||||||
|
.arg("-WindowStyle")
|
||||||
|
.arg("Hidden")
|
||||||
|
.arg("-Command")
|
||||||
|
.arg(&ps_script)
|
||||||
|
.output()
|
||||||
|
})
|
||||||
|
.map_err(|e| format!("Failed to execute PowerShell: {}", e))?;
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
let error = String::from_utf8_lossy(&output.stderr);
|
||||||
|
return Err(format!("PowerShell script failed: {}", error));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alternative: Use Windows built-in MSG command for simple notifications
|
||||||
|
#[command]
|
||||||
|
pub async fn send_simple_notification(title: String, body: String) -> Result<(), String> {
|
||||||
|
let message = format!("{}\n\n{}", title, body);
|
||||||
|
|
||||||
|
Command::new("cmd.exe")
|
||||||
|
.arg("/c")
|
||||||
|
.arg("msg")
|
||||||
|
.arg("*")
|
||||||
|
.arg(&message)
|
||||||
|
.output()
|
||||||
|
.map_err(|e| format!("Failed to send message: {}", e))?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -0,0 +1,216 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::time::Instant;
|
||||||
|
use crate::achievements::{AchievementProgress, check_achievements};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
|
pub struct UsageStats {
|
||||||
|
pub total_input_tokens: u64,
|
||||||
|
pub total_output_tokens: u64,
|
||||||
|
pub total_cost_usd: f64,
|
||||||
|
pub session_input_tokens: u64,
|
||||||
|
pub session_output_tokens: u64,
|
||||||
|
pub session_cost_usd: f64,
|
||||||
|
pub model: Option<String>,
|
||||||
|
|
||||||
|
// New fields
|
||||||
|
pub messages_exchanged: u64,
|
||||||
|
pub session_messages_exchanged: u64,
|
||||||
|
pub code_blocks_generated: u64,
|
||||||
|
pub session_code_blocks_generated: u64,
|
||||||
|
pub files_edited: u64,
|
||||||
|
pub session_files_edited: u64,
|
||||||
|
pub files_created: u64,
|
||||||
|
pub session_files_created: u64,
|
||||||
|
pub tools_usage: HashMap<String, u64>,
|
||||||
|
pub session_tools_usage: HashMap<String, u64>,
|
||||||
|
pub session_duration_seconds: u64,
|
||||||
|
#[serde(skip)]
|
||||||
|
pub session_start: Option<Instant>,
|
||||||
|
|
||||||
|
// Achievement tracking
|
||||||
|
#[serde(skip)]
|
||||||
|
pub achievements: AchievementProgress,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UsageStats {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
let mut stats = Self::default();
|
||||||
|
stats.achievements.start_session();
|
||||||
|
stats
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_usage(&mut self, input_tokens: u64, output_tokens: u64, model: &str) {
|
||||||
|
self.total_input_tokens += input_tokens;
|
||||||
|
self.total_output_tokens += output_tokens;
|
||||||
|
self.session_input_tokens += input_tokens;
|
||||||
|
self.session_output_tokens += output_tokens;
|
||||||
|
|
||||||
|
let cost = calculate_cost(input_tokens, output_tokens, model);
|
||||||
|
self.total_cost_usd += cost;
|
||||||
|
self.session_cost_usd += cost;
|
||||||
|
|
||||||
|
self.model = Some(model.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reset_session(&mut self) {
|
||||||
|
self.session_input_tokens = 0;
|
||||||
|
self.session_output_tokens = 0;
|
||||||
|
self.session_cost_usd = 0.0;
|
||||||
|
self.session_messages_exchanged = 0;
|
||||||
|
self.session_code_blocks_generated = 0;
|
||||||
|
self.session_files_edited = 0;
|
||||||
|
self.session_files_created = 0;
|
||||||
|
self.session_tools_usage.clear();
|
||||||
|
self.session_duration_seconds = 0;
|
||||||
|
self.session_start = Some(Instant::now());
|
||||||
|
self.achievements.start_session();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn increment_messages(&mut self) {
|
||||||
|
self.messages_exchanged += 1;
|
||||||
|
self.session_messages_exchanged += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn increment_code_blocks(&mut self) {
|
||||||
|
self.code_blocks_generated += 1;
|
||||||
|
self.session_code_blocks_generated += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn increment_files_edited(&mut self) {
|
||||||
|
self.files_edited += 1;
|
||||||
|
self.session_files_edited += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn increment_files_created(&mut self) {
|
||||||
|
self.files_created += 1;
|
||||||
|
self.session_files_created += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn increment_tool_usage(&mut self, tool_name: &str) {
|
||||||
|
*self.tools_usage.entry(tool_name.to_string()).or_insert(0) += 1;
|
||||||
|
*self.session_tools_usage.entry(tool_name.to_string()).or_insert(0) += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_session_duration(&mut self) -> u64 {
|
||||||
|
// Only update if more than 1 second has passed to reduce calculations
|
||||||
|
if let Some(start) = self.session_start {
|
||||||
|
let elapsed = start.elapsed().as_secs();
|
||||||
|
if elapsed > self.session_duration_seconds {
|
||||||
|
self.session_duration_seconds = elapsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.session_duration_seconds
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn check_achievements(&mut self) -> Vec<crate::achievements::AchievementId> {
|
||||||
|
let stats_copy = UsageStats {
|
||||||
|
total_input_tokens: self.total_input_tokens,
|
||||||
|
total_output_tokens: self.total_output_tokens,
|
||||||
|
total_cost_usd: self.total_cost_usd,
|
||||||
|
session_input_tokens: self.session_input_tokens,
|
||||||
|
session_output_tokens: self.session_output_tokens,
|
||||||
|
session_cost_usd: self.session_cost_usd,
|
||||||
|
model: self.model.clone(),
|
||||||
|
messages_exchanged: self.messages_exchanged,
|
||||||
|
session_messages_exchanged: self.session_messages_exchanged,
|
||||||
|
code_blocks_generated: self.code_blocks_generated,
|
||||||
|
session_code_blocks_generated: self.session_code_blocks_generated,
|
||||||
|
files_edited: self.files_edited,
|
||||||
|
session_files_edited: self.session_files_edited,
|
||||||
|
files_created: self.files_created,
|
||||||
|
session_files_created: self.session_files_created,
|
||||||
|
tools_usage: self.tools_usage.clone(),
|
||||||
|
session_tools_usage: self.session_tools_usage.clone(),
|
||||||
|
session_duration_seconds: self.session_duration_seconds,
|
||||||
|
session_start: self.session_start,
|
||||||
|
achievements: AchievementProgress::new(), // Dummy for copy
|
||||||
|
};
|
||||||
|
check_achievements(&stats_copy, &mut self.achievements)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pricing as of January 2025
|
||||||
|
// https://www.anthropic.com/pricing
|
||||||
|
fn calculate_cost(input_tokens: u64, output_tokens: u64, model: &str) -> f64 {
|
||||||
|
let (input_price_per_million, output_price_per_million) = match model {
|
||||||
|
// Opus 4.5
|
||||||
|
"claude-opus-4-5-20251101" => (15.0, 75.0),
|
||||||
|
|
||||||
|
// Opus 4
|
||||||
|
"claude-opus-4-20250514" => (15.0, 75.0),
|
||||||
|
|
||||||
|
// Sonnet 4
|
||||||
|
"claude-sonnet-4-20250514" => (3.0, 15.0),
|
||||||
|
|
||||||
|
// Previous generation models
|
||||||
|
"claude-3-5-sonnet-20241022" => (3.0, 15.0),
|
||||||
|
"claude-3-5-sonnet-20240620" => (3.0, 15.0),
|
||||||
|
"claude-3-5-haiku-20241022" => (1.0, 5.0),
|
||||||
|
"claude-3-opus-20240229" => (15.0, 75.0),
|
||||||
|
"claude-3-sonnet-20240229" => (3.0, 15.0),
|
||||||
|
"claude-3-haiku-20240307" => (0.25, 1.25),
|
||||||
|
|
||||||
|
// Default to Sonnet pricing if model unknown
|
||||||
|
_ => (3.0, 15.0),
|
||||||
|
};
|
||||||
|
|
||||||
|
let input_cost = (input_tokens as f64 / 1_000_000.0) * input_price_per_million;
|
||||||
|
let output_cost = (output_tokens as f64 / 1_000_000.0) * output_price_per_million;
|
||||||
|
|
||||||
|
input_cost + output_cost
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct StatsUpdateEvent {
|
||||||
|
pub stats: UsageStats,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cost_calculation_sonnet() {
|
||||||
|
let cost = calculate_cost(1000, 2000, "claude-sonnet-4-20250514");
|
||||||
|
// 1000 input * $3/M = $0.003
|
||||||
|
// 2000 output * $15/M = $0.030
|
||||||
|
// Total = $0.033
|
||||||
|
assert!((cost - 0.033).abs() < 0.0001);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cost_calculation_opus() {
|
||||||
|
let cost = calculate_cost(1000, 2000, "claude-opus-4-20250514");
|
||||||
|
// 1000 input * $15/M = $0.015
|
||||||
|
// 2000 output * $75/M = $0.150
|
||||||
|
// Total = $0.165
|
||||||
|
assert!((cost - 0.165).abs() < 0.0001);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_usage_stats_accumulation() {
|
||||||
|
let mut stats = UsageStats::new();
|
||||||
|
stats.add_usage(1000, 2000, "claude-sonnet-4-20250514");
|
||||||
|
|
||||||
|
assert_eq!(stats.total_input_tokens, 1000);
|
||||||
|
assert_eq!(stats.total_output_tokens, 2000);
|
||||||
|
assert_eq!(stats.session_input_tokens, 1000);
|
||||||
|
assert_eq!(stats.session_output_tokens, 2000);
|
||||||
|
assert!((stats.total_cost_usd - 0.033).abs() < 0.0001);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_session_reset() {
|
||||||
|
let mut stats = UsageStats::new();
|
||||||
|
stats.add_usage(1000, 2000, "claude-sonnet-4-20250514");
|
||||||
|
stats.reset_session();
|
||||||
|
|
||||||
|
assert_eq!(stats.total_input_tokens, 1000);
|
||||||
|
assert_eq!(stats.total_output_tokens, 2000);
|
||||||
|
assert_eq!(stats.session_input_tokens, 0);
|
||||||
|
assert_eq!(stats.session_output_tokens, 0);
|
||||||
|
assert_eq!(stats.session_cost_usd, 0.0);
|
||||||
|
assert!(stats.total_cost_usd > 0.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,11 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct UsageInfo {
|
||||||
|
pub input_tokens: u64,
|
||||||
|
pub output_tokens: u64,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum CharacterState {
|
pub enum CharacterState {
|
||||||
@@ -87,6 +93,8 @@ pub enum ClaudeMessage {
|
|||||||
num_turns: Option<u32>,
|
num_turns: Option<u32>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
permission_denials: Option<Vec<PermissionDenial>>,
|
permission_denials: Option<Vec<PermissionDenial>>,
|
||||||
|
#[serde(default)]
|
||||||
|
usage: Option<UsageInfo>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,6 +105,8 @@ pub struct AssistantMessageContent {
|
|||||||
pub model: Option<String>,
|
pub model: Option<String>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub stop_reason: Option<String>,
|
pub stop_reason: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub usage: Option<UsageInfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
@@ -162,6 +172,8 @@ pub struct DeltaContent {
|
|||||||
pub struct StateChangeEvent {
|
pub struct StateChangeEvent {
|
||||||
pub state: CharacterState,
|
pub state: CharacterState,
|
||||||
pub tool_name: Option<String>,
|
pub tool_name: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub conversation_id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
@@ -169,6 +181,8 @@ pub struct OutputEvent {
|
|||||||
pub line_type: String,
|
pub line_type: String,
|
||||||
pub content: String,
|
pub content: String,
|
||||||
pub tool_name: Option<String>,
|
pub tool_name: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub conversation_id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
@@ -177,6 +191,29 @@ pub struct PermissionPromptEvent {
|
|||||||
pub tool_name: String,
|
pub tool_name: String,
|
||||||
pub tool_input: serde_json::Value,
|
pub tool_input: serde_json::Value,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub conversation_id: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct ConnectionEvent {
|
||||||
|
pub status: ConnectionStatus,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub conversation_id: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct SessionEvent {
|
||||||
|
pub session_id: String,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub conversation_id: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct WorkingDirectoryEvent {
|
||||||
|
pub directory: String,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub conversation_id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -284,6 +321,7 @@ mod tests {
|
|||||||
let event = StateChangeEvent {
|
let event = StateChangeEvent {
|
||||||
state: CharacterState::Coding,
|
state: CharacterState::Coding,
|
||||||
tool_name: Some("Edit".to_string()),
|
tool_name: Some("Edit".to_string()),
|
||||||
|
conversation_id: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let serialized = serde_json::to_string(&event).unwrap();
|
let serialized = serde_json::to_string(&event).unwrap();
|
||||||
@@ -297,6 +335,7 @@ mod tests {
|
|||||||
line_type: "assistant".to_string(),
|
line_type: "assistant".to_string(),
|
||||||
content: "Test output".to_string(),
|
content: "Test output".to_string(),
|
||||||
tool_name: None,
|
tool_name: None,
|
||||||
|
conversation_id: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let serialized = serde_json::to_string(&event).unwrap();
|
let serialized = serde_json::to_string(&event).unwrap();
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
use std::process::Command;
|
||||||
|
use std::io::Write;
|
||||||
|
use tempfile::NamedTempFile;
|
||||||
|
use tauri::command;
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
pub async fn send_vbs_notification(title: String, body: String) -> Result<(), String> {
|
||||||
|
// Create a VBScript that shows a Windows notification
|
||||||
|
let vbs_content = format!(
|
||||||
|
r#"
|
||||||
|
Set objShell = CreateObject("WScript.Shell")
|
||||||
|
objShell.Popup "{}" & vbCrLf & vbCrLf & "{}", 5, "{}", 64
|
||||||
|
"#,
|
||||||
|
body.replace("\"", "\"\"").replace("\n", "\" & vbCrLf & \""),
|
||||||
|
title.replace("\"", "\"\""),
|
||||||
|
title.replace("\"", "\"\"")
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create a temporary VBS file
|
||||||
|
let mut temp_file = NamedTempFile::new()
|
||||||
|
.map_err(|e| format!("Failed to create temp file: {}", e))?;
|
||||||
|
|
||||||
|
temp_file
|
||||||
|
.write_all(vbs_content.as_bytes())
|
||||||
|
.map_err(|e| format!("Failed to write VBS content: {}", e))?;
|
||||||
|
|
||||||
|
let temp_path = temp_file.path().to_string_lossy().to_string();
|
||||||
|
|
||||||
|
// Convert WSL path to Windows path
|
||||||
|
let windows_path = if temp_path.starts_with("/mnt/") {
|
||||||
|
// Convert /mnt/c/... to C:\...
|
||||||
|
let path_parts: Vec<&str> = temp_path.split('/').collect();
|
||||||
|
if path_parts.len() > 2 {
|
||||||
|
let drive_letter = path_parts[2].to_uppercase();
|
||||||
|
let rest_of_path = path_parts[3..].join("\\");
|
||||||
|
format!("{}:\\{}", drive_letter, rest_of_path)
|
||||||
|
} else {
|
||||||
|
temp_path.clone()
|
||||||
|
}
|
||||||
|
} else if temp_path.starts_with("/tmp/") {
|
||||||
|
// WSL temp files might be in a different location
|
||||||
|
// Try to use wslpath to convert
|
||||||
|
let output = Command::new("wslpath")
|
||||||
|
.arg("-w")
|
||||||
|
.arg(&temp_path)
|
||||||
|
.output();
|
||||||
|
|
||||||
|
if let Ok(result) = output {
|
||||||
|
if result.status.success() {
|
||||||
|
String::from_utf8_lossy(&result.stdout).trim().to_string()
|
||||||
|
} else {
|
||||||
|
temp_path.clone()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
temp_path.clone()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
temp_path.clone()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Execute the VBScript using wscript.exe
|
||||||
|
let output = Command::new("/mnt/c/Windows/System32/wscript.exe")
|
||||||
|
.arg("//NoLogo")
|
||||||
|
.arg(&windows_path)
|
||||||
|
.output()
|
||||||
|
.map_err(|e| format!("Failed to execute VBScript: {}", e))?;
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
let error = String::from_utf8_lossy(&output.stderr);
|
||||||
|
return Err(format!("VBScript execution failed: {}", error));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
use tauri::command;
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
use windows::{
|
||||||
|
core::{HSTRING, Result as WindowsResult},
|
||||||
|
Data::Xml::Dom::*,
|
||||||
|
UI::Notifications::*,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
#[command]
|
||||||
|
pub async fn send_windows_toast(title: String, body: String) -> Result<(), String> {
|
||||||
|
show_toast_notification(&title, &body)
|
||||||
|
.map_err(|e| format!("Failed to show toast notification: {}", e))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
fn show_toast_notification(title: &str, body: &str) -> WindowsResult<()> {
|
||||||
|
// Create the XML for the toast notification
|
||||||
|
let toast_xml = format!(
|
||||||
|
r#"<toast>
|
||||||
|
<visual>
|
||||||
|
<binding template="ToastGeneric">
|
||||||
|
<text>{}</text>
|
||||||
|
<text>{}</text>
|
||||||
|
</binding>
|
||||||
|
</visual>
|
||||||
|
<audio src="ms-winsoundevent:Notification.Default" />
|
||||||
|
</toast>"#,
|
||||||
|
escape_xml(title),
|
||||||
|
escape_xml(body)
|
||||||
|
);
|
||||||
|
|
||||||
|
let xml_doc = XmlDocument::new()?;
|
||||||
|
xml_doc.LoadXml(&HSTRING::from(toast_xml))?;
|
||||||
|
|
||||||
|
// Create the toast notification
|
||||||
|
let toast = ToastNotification::CreateToastNotification(&xml_doc)?;
|
||||||
|
|
||||||
|
// Create a toast notifier with an application ID
|
||||||
|
let notifier = ToastNotificationManager::CreateToastNotifierWithId(&HSTRING::from("Hikari Desktop"))?;
|
||||||
|
|
||||||
|
// Show the notification
|
||||||
|
notifier.Show(&toast)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
fn escape_xml(text: &str) -> String {
|
||||||
|
text.replace('&', "&")
|
||||||
|
.replace('<', "<")
|
||||||
|
.replace('>', ">")
|
||||||
|
.replace('"', """)
|
||||||
|
.replace('\'', "'")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stub for non-Windows platforms
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
#[command]
|
||||||
|
pub async fn send_windows_toast(_title: String, _body: String) -> Result<(), String> {
|
||||||
|
Err("Windows toast notifications are only available on Windows".to_string())
|
||||||
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
use parking_lot::Mutex;
|
|
||||||
use std::io::{BufRead, BufReader, Write};
|
use std::io::{BufRead, BufReader, Write};
|
||||||
use std::process::{Child, ChildStdin, Command, Stdio};
|
use std::process::{Child, ChildStdin, Command, Stdio};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -10,7 +9,10 @@ use tempfile::NamedTempFile;
|
|||||||
use std::os::windows::process::CommandExt;
|
use std::os::windows::process::CommandExt;
|
||||||
|
|
||||||
use crate::config::ClaudeStartOptions;
|
use crate::config::ClaudeStartOptions;
|
||||||
use crate::types::{CharacterState, ClaudeMessage, ConnectionStatus, ContentBlock, StateChangeEvent, OutputEvent, PermissionPromptEvent};
|
use crate::stats::{UsageStats, StatsUpdateEvent};
|
||||||
|
use parking_lot::RwLock;
|
||||||
|
use crate::types::{CharacterState, ClaudeMessage, ConnectionStatus, ContentBlock, StateChangeEvent, OutputEvent, PermissionPromptEvent, ConnectionEvent, SessionEvent, WorkingDirectoryEvent};
|
||||||
|
use crate::achievements::{get_achievement_info, AchievementUnlockedEvent};
|
||||||
|
|
||||||
const SEARCH_TOOLS: [&str; 5] = ["Read", "Glob", "Grep", "WebSearch", "WebFetch"];
|
const SEARCH_TOOLS: [&str; 5] = ["Read", "Glob", "Grep", "WebSearch", "WebFetch"];
|
||||||
const CODING_TOOLS: [&str; 3] = ["Edit", "Write", "NotebookEdit"];
|
const CODING_TOOLS: [&str; 3] = ["Edit", "Write", "NotebookEdit"];
|
||||||
@@ -72,6 +74,8 @@ pub struct WslBridge {
|
|||||||
working_directory: String,
|
working_directory: String,
|
||||||
session_id: Option<String>,
|
session_id: Option<String>,
|
||||||
mcp_config_file: Option<NamedTempFile>,
|
mcp_config_file: Option<NamedTempFile>,
|
||||||
|
stats: Arc<RwLock<UsageStats>>,
|
||||||
|
conversation_id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WslBridge {
|
impl WslBridge {
|
||||||
@@ -82,18 +86,43 @@ impl WslBridge {
|
|||||||
working_directory: String::new(),
|
working_directory: String::new(),
|
||||||
session_id: None,
|
session_id: None,
|
||||||
mcp_config_file: None,
|
mcp_config_file: None,
|
||||||
|
stats: Arc::new(RwLock::new(UsageStats::new())),
|
||||||
|
conversation_id: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_with_conversation_id(conversation_id: String) -> Self {
|
||||||
|
WslBridge {
|
||||||
|
process: None,
|
||||||
|
stdin: None,
|
||||||
|
working_directory: String::new(),
|
||||||
|
session_id: None,
|
||||||
|
mcp_config_file: None,
|
||||||
|
stats: Arc::new(RwLock::new(UsageStats::new())),
|
||||||
|
conversation_id: Some(conversation_id),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn start(&mut self, app: AppHandle, options: ClaudeStartOptions) -> Result<(), String> {
|
pub fn start(&mut self, app: AppHandle, options: ClaudeStartOptions) -> Result<(), String> {
|
||||||
if self.process.is_some() {
|
if self.process.is_some() {
|
||||||
return Err("Process already running".to_string());
|
return Err("Process already running".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load saved achievements when starting a new session
|
||||||
|
let app_clone = app.clone();
|
||||||
|
let stats = self.stats.clone();
|
||||||
|
tauri::async_runtime::spawn(async move {
|
||||||
|
println!("Loading saved achievements...");
|
||||||
|
let achievements = crate::achievements::load_achievements(&app_clone).await;
|
||||||
|
println!("Loaded {} unlocked achievements", achievements.unlocked.len());
|
||||||
|
stats.write().achievements = achievements;
|
||||||
|
});
|
||||||
|
|
||||||
let working_dir = &options.working_dir;
|
let working_dir = &options.working_dir;
|
||||||
self.working_directory = working_dir.clone();
|
self.working_directory = working_dir.clone();
|
||||||
|
|
||||||
emit_connection_status(&app, ConnectionStatus::Connecting);
|
emit_connection_status(&app, ConnectionStatus::Connecting, self.conversation_id.clone());
|
||||||
|
|
||||||
// Create temp file for MCP config if provided
|
// Create temp file for MCP config if provided
|
||||||
let mcp_config_path = if let Some(ref mcp_json) = options.mcp_servers_json {
|
let mcp_config_path = if let Some(ref mcp_json) = options.mcp_servers_json {
|
||||||
@@ -249,21 +278,35 @@ impl WslBridge {
|
|||||||
self.stdin = stdin;
|
self.stdin = stdin;
|
||||||
self.process = Some(child);
|
self.process = Some(child);
|
||||||
|
|
||||||
|
// Reset session stats when starting new session
|
||||||
|
self.stats.write().reset_session();
|
||||||
|
|
||||||
|
// Load saved achievements
|
||||||
|
let app_handle = app.clone();
|
||||||
|
let stats_clone = self.stats.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let saved_progress = crate::achievements::load_achievements(&app_handle).await;
|
||||||
|
stats_clone.write().achievements = saved_progress;
|
||||||
|
});
|
||||||
|
|
||||||
if let Some(stdout) = stdout {
|
if let Some(stdout) = stdout {
|
||||||
let app_clone = app.clone();
|
let app_clone = app.clone();
|
||||||
|
let stats_clone = self.stats.clone();
|
||||||
|
let conv_id = self.conversation_id.clone();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
handle_stdout(stdout, app_clone);
|
handle_stdout(stdout, app_clone, stats_clone, conv_id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(stderr) = stderr {
|
if let Some(stderr) = stderr {
|
||||||
let app_clone = app.clone();
|
let app_clone = app.clone();
|
||||||
|
let conv_id = self.conversation_id.clone();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
handle_stderr(stderr, app_clone);
|
handle_stderr(stderr, app_clone, conv_id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
emit_connection_status(&app, ConnectionStatus::Connected);
|
emit_connection_status(&app, ConnectionStatus::Connected, self.conversation_id.clone());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -293,6 +336,30 @@ impl WslBridge {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn interrupt(&mut self, app: &AppHandle) -> Result<(), String> {
|
||||||
|
// Due to persistent bug in Claude Code where ESC/Ctrl+C doesn't work,
|
||||||
|
// we have to kill the process. This is the only reliable way to stop it.
|
||||||
|
// See: https://github.com/anthropics/claude-code/issues/3455
|
||||||
|
if let Some(mut process) = self.process.take() {
|
||||||
|
// Kill the process immediately
|
||||||
|
let _ = process.kill();
|
||||||
|
let _ = process.wait();
|
||||||
|
|
||||||
|
// Clear stdin
|
||||||
|
self.stdin = None;
|
||||||
|
|
||||||
|
// Keep session_id and working directory for user reference
|
||||||
|
// The user will see what session was interrupted
|
||||||
|
|
||||||
|
// Emit disconnected status
|
||||||
|
emit_connection_status(app, ConnectionStatus::Disconnected, self.conversation_id.clone());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err("No active process to interrupt".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn stop(&mut self, app: &AppHandle) {
|
pub fn stop(&mut self, app: &AppHandle) {
|
||||||
if let Some(mut process) = self.process.take() {
|
if let Some(mut process) = self.process.take() {
|
||||||
let _ = process.kill();
|
let _ = process.kill();
|
||||||
@@ -301,7 +368,7 @@ impl WslBridge {
|
|||||||
self.stdin = None;
|
self.stdin = None;
|
||||||
self.session_id = None;
|
self.session_id = None;
|
||||||
self.mcp_config_file = None; // Temp file is automatically deleted when dropped
|
self.mcp_config_file = None; // Temp file is automatically deleted when dropped
|
||||||
emit_connection_status(app, ConnectionStatus::Disconnected);
|
emit_connection_status(app, ConnectionStatus::Disconnected, self.conversation_id.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_running(&self) -> bool {
|
pub fn is_running(&self) -> bool {
|
||||||
@@ -311,6 +378,11 @@ impl WslBridge {
|
|||||||
pub fn get_working_directory(&self) -> &str {
|
pub fn get_working_directory(&self) -> &str {
|
||||||
&self.working_directory
|
&self.working_directory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_stats(&self) -> UsageStats {
|
||||||
|
self.stats.read().clone()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for WslBridge {
|
impl Default for WslBridge {
|
||||||
@@ -319,13 +391,13 @@ impl Default for WslBridge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_stdout(stdout: std::process::ChildStdout, app: AppHandle) {
|
fn handle_stdout(stdout: std::process::ChildStdout, app: AppHandle, stats: Arc<RwLock<UsageStats>>, conversation_id: Option<String>) {
|
||||||
let reader = BufReader::new(stdout);
|
let reader = BufReader::new(stdout);
|
||||||
|
|
||||||
for line in reader.lines() {
|
for line in reader.lines() {
|
||||||
match line {
|
match line {
|
||||||
Ok(line) if !line.is_empty() => {
|
Ok(line) if !line.is_empty() => {
|
||||||
if let Err(e) = process_json_line(&line, &app) {
|
if let Err(e) = process_json_line(&line, &app, &stats, &conversation_id) {
|
||||||
eprintln!("Error processing line: {}", e);
|
eprintln!("Error processing line: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -337,10 +409,10 @@ fn handle_stdout(stdout: std::process::ChildStdout, app: AppHandle) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit_connection_status(&app, ConnectionStatus::Disconnected);
|
emit_connection_status(&app, ConnectionStatus::Disconnected, conversation_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_stderr(stderr: std::process::ChildStderr, app: AppHandle) {
|
fn handle_stderr(stderr: std::process::ChildStderr, app: AppHandle, conversation_id: Option<String>) {
|
||||||
let reader = BufReader::new(stderr);
|
let reader = BufReader::new(stderr);
|
||||||
|
|
||||||
for line in reader.lines() {
|
for line in reader.lines() {
|
||||||
@@ -350,6 +422,7 @@ fn handle_stderr(stderr: std::process::ChildStderr, app: AppHandle) {
|
|||||||
line_type: "error".to_string(),
|
line_type: "error".to_string(),
|
||||||
content: line,
|
content: line,
|
||||||
tool_name: None,
|
tool_name: None,
|
||||||
|
conversation_id: conversation_id.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Err(_) => break,
|
Err(_) => break,
|
||||||
@@ -358,7 +431,7 @@ fn handle_stderr(stderr: std::process::ChildStderr, app: AppHandle) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_json_line(line: &str, app: &AppHandle) -> Result<(), String> {
|
fn process_json_line(line: &str, app: &AppHandle, stats: &Arc<RwLock<UsageStats>>, conversation_id: &Option<String>) -> Result<(), String> {
|
||||||
let message: ClaudeMessage = serde_json::from_str(line)
|
let message: ClaudeMessage = serde_json::from_str(line)
|
||||||
.map_err(|e| format!("Failed to parse JSON: {} - Line: {}", e, line))?;
|
.map_err(|e| format!("Failed to parse JSON: {} - Line: {}", e, line))?;
|
||||||
|
|
||||||
@@ -366,12 +439,18 @@ fn process_json_line(line: &str, app: &AppHandle) -> Result<(), String> {
|
|||||||
ClaudeMessage::System { subtype, session_id, cwd, .. } => {
|
ClaudeMessage::System { subtype, session_id, cwd, .. } => {
|
||||||
if subtype == "init" {
|
if subtype == "init" {
|
||||||
if let Some(id) = session_id {
|
if let Some(id) = session_id {
|
||||||
let _ = app.emit("claude:session", id.clone());
|
let _ = app.emit("claude:session", SessionEvent {
|
||||||
|
session_id: id.clone(),
|
||||||
|
conversation_id: conversation_id.clone(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if let Some(dir) = cwd {
|
if let Some(dir) = cwd {
|
||||||
let _ = app.emit("claude:cwd", dir.clone());
|
let _ = app.emit("claude:cwd", WorkingDirectoryEvent {
|
||||||
|
directory: dir.clone(),
|
||||||
|
conversation_id: conversation_id.clone(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
emit_state_change(app, CharacterState::Idle, None);
|
emit_state_change(app, CharacterState::Idle, None, conversation_id.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,24 +458,67 @@ fn process_json_line(line: &str, app: &AppHandle) -> Result<(), String> {
|
|||||||
let mut state = CharacterState::Typing;
|
let mut state = CharacterState::Typing;
|
||||||
let mut tool_name = None;
|
let mut tool_name = None;
|
||||||
|
|
||||||
|
// Only update stats if we have usage information
|
||||||
|
if let Some(usage) = &message.usage {
|
||||||
|
if let Some(model) = &message.model {
|
||||||
|
// Batch all stats updates in a single write lock
|
||||||
|
{
|
||||||
|
let mut stats_guard = stats.write();
|
||||||
|
stats_guard.increment_messages();
|
||||||
|
stats_guard.add_usage(usage.input_tokens, usage.output_tokens, model);
|
||||||
|
stats_guard.get_session_duration();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't emit here - we'll emit on Result message instead
|
||||||
|
// This reduces the frequency of updates
|
||||||
|
} else {
|
||||||
|
// Just increment message count if no usage info
|
||||||
|
stats.write().increment_messages();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Just increment message count if no usage info
|
||||||
|
stats.write().increment_messages();
|
||||||
|
}
|
||||||
|
|
||||||
for block in &message.content {
|
for block in &message.content {
|
||||||
match block {
|
match block {
|
||||||
ContentBlock::ToolUse { name, input, .. } => {
|
ContentBlock::ToolUse { name, input, .. } => {
|
||||||
tool_name = Some(name.clone());
|
tool_name = Some(name.clone());
|
||||||
state = get_tool_state(name);
|
state = get_tool_state(name);
|
||||||
|
|
||||||
|
// Batch tool tracking updates
|
||||||
|
{
|
||||||
|
let mut stats_guard = stats.write();
|
||||||
|
stats_guard.increment_tool_usage(name);
|
||||||
|
|
||||||
|
// Track file operations
|
||||||
|
match name.as_str() {
|
||||||
|
"Edit" => stats_guard.increment_files_edited(),
|
||||||
|
"Write" => stats_guard.increment_files_created(),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let desc = format_tool_description(name, input);
|
let desc = format_tool_description(name, input);
|
||||||
let _ = app.emit("claude:output", OutputEvent {
|
let _ = app.emit("claude:output", OutputEvent {
|
||||||
line_type: "tool".to_string(),
|
line_type: "tool".to_string(),
|
||||||
content: desc,
|
content: desc,
|
||||||
tool_name: Some(name.clone()),
|
tool_name: Some(name.clone()),
|
||||||
|
conversation_id: conversation_id.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ContentBlock::Text { text } => {
|
ContentBlock::Text { text } => {
|
||||||
|
// Count code blocks in the text
|
||||||
|
let code_blocks = text.matches("```").count() / 2;
|
||||||
|
for _ in 0..code_blocks {
|
||||||
|
stats.write().increment_code_blocks();
|
||||||
|
}
|
||||||
|
|
||||||
let _ = app.emit("claude:output", OutputEvent {
|
let _ = app.emit("claude:output", OutputEvent {
|
||||||
line_type: "assistant".to_string(),
|
line_type: "assistant".to_string(),
|
||||||
content: text.clone(),
|
content: text.clone(),
|
||||||
tool_name: None,
|
tool_name: None,
|
||||||
|
conversation_id: conversation_id.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ContentBlock::Thinking { thinking } => {
|
ContentBlock::Thinking { thinking } => {
|
||||||
@@ -405,13 +527,14 @@ fn process_json_line(line: &str, app: &AppHandle) -> Result<(), String> {
|
|||||||
line_type: "system".to_string(),
|
line_type: "system".to_string(),
|
||||||
content: format!("[Thinking] {}", thinking),
|
content: format!("[Thinking] {}", thinking),
|
||||||
tool_name: None,
|
tool_name: None,
|
||||||
|
conversation_id: conversation_id.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit_state_change(app, state, tool_name);
|
emit_state_change(app, state, tool_name, conversation_id.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
ClaudeMessage::StreamEvent { event } => {
|
ClaudeMessage::StreamEvent { event } => {
|
||||||
@@ -429,7 +552,7 @@ fn process_json_line(line: &str, app: &AppHandle) -> Result<(), String> {
|
|||||||
}
|
}
|
||||||
_ => CharacterState::Typing,
|
_ => CharacterState::Typing,
|
||||||
};
|
};
|
||||||
emit_state_change(app, state, block.name.clone());
|
emit_state_change(app, state, block.name.clone(), conversation_id.clone());
|
||||||
}
|
}
|
||||||
} else if event.event_type == "content_block_delta" {
|
} else if event.event_type == "content_block_delta" {
|
||||||
if let Some(delta) = &event.delta {
|
if let Some(delta) = &event.delta {
|
||||||
@@ -440,13 +563,55 @@ fn process_json_line(line: &str, app: &AppHandle) -> Result<(), String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ClaudeMessage::Result { subtype, result, permission_denials, .. } => {
|
ClaudeMessage::Result { subtype, result, permission_denials, usage: _, .. } => {
|
||||||
let state = if subtype == "success" {
|
let state = if subtype == "success" {
|
||||||
CharacterState::Success
|
CharacterState::Success
|
||||||
} else {
|
} else {
|
||||||
CharacterState::Error
|
CharacterState::Error
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Always emit updated stats on result message (less frequent)
|
||||||
|
// This includes the latest session duration
|
||||||
|
let newly_unlocked = {
|
||||||
|
let mut stats_guard = stats.write();
|
||||||
|
stats_guard.get_session_duration();
|
||||||
|
println!("Checking achievements after result message...");
|
||||||
|
let unlocked = stats_guard.check_achievements();
|
||||||
|
println!("Newly unlocked achievements: {:?}", unlocked);
|
||||||
|
unlocked
|
||||||
|
};
|
||||||
|
|
||||||
|
// Emit achievement events for any newly unlocked achievements
|
||||||
|
for achievement_id in &newly_unlocked {
|
||||||
|
let info = get_achievement_info(achievement_id);
|
||||||
|
let _ = app.emit("achievement:unlocked", AchievementUnlockedEvent {
|
||||||
|
achievement: info,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save achievements after unlocking new ones
|
||||||
|
if !newly_unlocked.is_empty() {
|
||||||
|
println!("Saving newly unlocked achievements: {:?}", newly_unlocked);
|
||||||
|
let app_handle = app.clone();
|
||||||
|
let achievements_progress = stats.read().achievements.clone();
|
||||||
|
|
||||||
|
// Use Tauri's async runtime instead of tokio::spawn
|
||||||
|
tauri::async_runtime::spawn(async move {
|
||||||
|
println!("Spawned save task for achievements");
|
||||||
|
if let Err(e) = crate::achievements::save_achievements(&app_handle, &achievements_progress).await {
|
||||||
|
eprintln!("Failed to save achievements: {}", e);
|
||||||
|
} else {
|
||||||
|
println!("Achievement save task completed successfully");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let current_stats = stats.read().clone();
|
||||||
|
let stats_event = StatsUpdateEvent {
|
||||||
|
stats: current_stats,
|
||||||
|
};
|
||||||
|
let _ = app.emit("claude:stats", stats_event);
|
||||||
|
|
||||||
// Only emit error results - success content is already sent via Assistant message
|
// Only emit error results - success content is already sent via Assistant message
|
||||||
if subtype != "success" {
|
if subtype != "success" {
|
||||||
if let Some(text) = result {
|
if let Some(text) = result {
|
||||||
@@ -454,6 +619,7 @@ fn process_json_line(line: &str, app: &AppHandle) -> Result<(), String> {
|
|||||||
line_type: "error".to_string(),
|
line_type: "error".to_string(),
|
||||||
content: text.clone(),
|
content: text.clone(),
|
||||||
tool_name: None,
|
tool_name: None,
|
||||||
|
conversation_id: conversation_id.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -467,21 +633,75 @@ fn process_json_line(line: &str, app: &AppHandle) -> Result<(), String> {
|
|||||||
tool_name: denial.tool_name.clone(),
|
tool_name: denial.tool_name.clone(),
|
||||||
tool_input: denial.tool_input.clone(),
|
tool_input: denial.tool_input.clone(),
|
||||||
description,
|
description,
|
||||||
|
conversation_id: conversation_id.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show permission state if there were denials
|
// Show permission state if there were denials
|
||||||
if !denials.is_empty() {
|
if !denials.is_empty() {
|
||||||
emit_state_change(app, CharacterState::Permission, None);
|
emit_state_change(app, CharacterState::Permission, None, conversation_id.clone());
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit_state_change(app, state, None);
|
emit_state_change(app, state, None, conversation_id.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
ClaudeMessage::User { .. } => {
|
ClaudeMessage::User { message } => {
|
||||||
emit_state_change(app, CharacterState::Thinking, None);
|
// Increment message count for user messages
|
||||||
|
stats.write().increment_messages();
|
||||||
|
|
||||||
|
// Extract text content from the message
|
||||||
|
let message_text = message.content.iter()
|
||||||
|
.filter_map(|block| match block {
|
||||||
|
crate::types::ContentBlock::Text { text } => Some(text.clone()),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join(" ");
|
||||||
|
|
||||||
|
// Check achievements after user message
|
||||||
|
let newly_unlocked = {
|
||||||
|
let mut stats_guard = stats.write();
|
||||||
|
println!("User sent message, checking achievements...");
|
||||||
|
|
||||||
|
// Check message-based achievements
|
||||||
|
let mut unlocked = crate::achievements::check_message_achievements(
|
||||||
|
&message_text,
|
||||||
|
&mut stats_guard.achievements,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check stats-based achievements
|
||||||
|
let stats_unlocked = stats_guard.check_achievements();
|
||||||
|
unlocked.extend(stats_unlocked);
|
||||||
|
|
||||||
|
unlocked
|
||||||
|
};
|
||||||
|
|
||||||
|
// Emit achievement events for any newly unlocked achievements
|
||||||
|
for achievement_id in &newly_unlocked {
|
||||||
|
println!("User message unlocked achievement: {:?}", achievement_id);
|
||||||
|
let info = get_achievement_info(achievement_id);
|
||||||
|
let _ = app.emit("achievement:unlocked", AchievementUnlockedEvent {
|
||||||
|
achievement: info,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save achievements after unlocking new ones
|
||||||
|
if !newly_unlocked.is_empty() {
|
||||||
|
println!("Saving newly unlocked achievements from user message");
|
||||||
|
let app_handle = app.clone();
|
||||||
|
let achievements_progress = stats.read().achievements.clone();
|
||||||
|
tauri::async_runtime::spawn(async move {
|
||||||
|
if let Err(e) = crate::achievements::save_achievements(&app_handle, &achievements_progress).await {
|
||||||
|
eprintln!("Failed to save achievements: {}", e);
|
||||||
|
} else {
|
||||||
|
println!("Achievements saved after user message");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
emit_state_change(app, CharacterState::Thinking, None, conversation_id.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -548,19 +768,14 @@ fn format_tool_description(name: &str, input: &serde_json::Value) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_state_change(app: &AppHandle, state: CharacterState, tool_name: Option<String>) {
|
fn emit_state_change(app: &AppHandle, state: CharacterState, tool_name: Option<String>, conversation_id: Option<String>) {
|
||||||
let _ = app.emit("claude:state", StateChangeEvent { state, tool_name });
|
let _ = app.emit("claude:state", StateChangeEvent { state, tool_name, conversation_id });
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_connection_status(app: &AppHandle, status: ConnectionStatus) {
|
fn emit_connection_status(app: &AppHandle, status: ConnectionStatus, conversation_id: Option<String>) {
|
||||||
let _ = app.emit("claude:connection", status);
|
let _ = app.emit("claude:connection", ConnectionEvent { status, conversation_id });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type SharedBridge = Arc<Mutex<WslBridge>>;
|
|
||||||
|
|
||||||
pub fn create_shared_bridge() -> SharedBridge {
|
|
||||||
Arc::new(Mutex::new(WslBridge::new()))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
@@ -679,9 +894,10 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create_shared_bridge() {
|
fn test_create_shared_bridge_manager() {
|
||||||
let shared = create_shared_bridge();
|
use crate::bridge_manager::create_shared_bridge_manager;
|
||||||
let bridge = shared.lock();
|
let shared = create_shared_bridge_manager();
|
||||||
assert!(!bridge.is_running());
|
let manager = shared.lock();
|
||||||
|
assert!(manager.get_active_conversations().is_empty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
use std::process::Command;
|
||||||
|
use tauri::command;
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
pub async fn send_wsl_notification(title: String, body: String) -> Result<(), String> {
|
||||||
|
// Method 1: Try Windows 10/11 toast notification using PowerShell
|
||||||
|
let toast_command = format!(
|
||||||
|
r#"
|
||||||
|
Add-Type -AssemblyName System.Runtime.WindowsRuntime
|
||||||
|
$null = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]
|
||||||
|
$null = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]
|
||||||
|
|
||||||
|
$APP_ID = 'Hikari Desktop'
|
||||||
|
|
||||||
|
$template = @"
|
||||||
|
<toast>
|
||||||
|
<visual>
|
||||||
|
<binding template="ToastGeneric">
|
||||||
|
<text>{0}</text>
|
||||||
|
<text>{1}</text>
|
||||||
|
</binding>
|
||||||
|
</visual>
|
||||||
|
</toast>
|
||||||
|
"@
|
||||||
|
|
||||||
|
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
|
||||||
|
$xml.LoadXml($template -f ('{0}' -replace "'", "''"), ('{1}' -replace "'", "''"))
|
||||||
|
|
||||||
|
$toast = New-Object Windows.UI.Notifications.ToastNotification $xml
|
||||||
|
$notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($APP_ID)
|
||||||
|
$notifier.Show($toast)
|
||||||
|
"#,
|
||||||
|
title.replace("'", "''").replace("\"", "\\\""),
|
||||||
|
body.replace("'", "''").replace("\"", "\\\"")
|
||||||
|
);
|
||||||
|
|
||||||
|
// Try PowerShell.exe through WSL
|
||||||
|
let output = Command::new("/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe")
|
||||||
|
.arg("-NoProfile")
|
||||||
|
.arg("-ExecutionPolicy")
|
||||||
|
.arg("Bypass")
|
||||||
|
.arg("-WindowStyle")
|
||||||
|
.arg("Hidden")
|
||||||
|
.arg("-Command")
|
||||||
|
.arg(&toast_command)
|
||||||
|
.output();
|
||||||
|
|
||||||
|
match output {
|
||||||
|
Ok(result) => {
|
||||||
|
if result.status.success() {
|
||||||
|
println!("WSL notification sent successfully");
|
||||||
|
return Ok(());
|
||||||
|
} else {
|
||||||
|
let stderr = String::from_utf8_lossy(&result.stderr);
|
||||||
|
println!("PowerShell toast failed: {}", stderr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to run PowerShell: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip msg.exe as it creates alert boxes
|
||||||
|
// Method 2 removed
|
||||||
|
|
||||||
|
// Method 3: Try wsl-notify-send if available
|
||||||
|
let notify_result = Command::new("wsl-notify-send")
|
||||||
|
.arg("--appId")
|
||||||
|
.arg("HikariDesktop")
|
||||||
|
.arg("--category")
|
||||||
|
.arg(&title)
|
||||||
|
.arg(&body)
|
||||||
|
.output();
|
||||||
|
|
||||||
|
if let Ok(result) = notify_result {
|
||||||
|
if result.status.success() {
|
||||||
|
println!("Notification sent via wsl-notify-send");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If all methods fail, return an error
|
||||||
|
Err("All WSL notification methods failed".to_string())
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"productName": "hikari-desktop",
|
"productName": "hikari-desktop",
|
||||||
"version": "0.1.0",
|
"version": "0.2.0",
|
||||||
"identifier": "com.naomi.hikari-desktop",
|
"identifier": "com.naomi.hikari-desktop",
|
||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": "pnpm dev",
|
"beforeDevCommand": "pnpm dev",
|
||||||
|
|||||||
@@ -10,7 +10,14 @@
|
|||||||
--accent-secondary: #ff6b9d;
|
--accent-secondary: #ff6b9d;
|
||||||
--text-primary: #ffffff;
|
--text-primary: #ffffff;
|
||||||
--text-secondary: #a0a0a0;
|
--text-secondary: #a0a0a0;
|
||||||
|
--text-tertiary: #6b7280;
|
||||||
--border-color: #2a2a4a;
|
--border-color: #2a2a4a;
|
||||||
|
|
||||||
|
/* Terminal specific colors */
|
||||||
|
--terminal-user: #22d3ee;
|
||||||
|
--terminal-tool: #c084fc;
|
||||||
|
--terminal-tool-name: #ddd6fe;
|
||||||
|
--terminal-error: #f87171;
|
||||||
}
|
}
|
||||||
|
|
||||||
[data-theme="light"] {
|
[data-theme="light"] {
|
||||||
@@ -22,7 +29,14 @@
|
|||||||
--accent-secondary: #ff6b9d;
|
--accent-secondary: #ff6b9d;
|
||||||
--text-primary: #1a1a2e;
|
--text-primary: #1a1a2e;
|
||||||
--text-secondary: #5a5a7a;
|
--text-secondary: #5a5a7a;
|
||||||
|
--text-tertiary: #9ca3af;
|
||||||
--border-color: #d0d0e0;
|
--border-color: #d0d0e0;
|
||||||
|
|
||||||
|
/* Terminal specific colors */
|
||||||
|
--terminal-user: #0891b2;
|
||||||
|
--terminal-tool: #7c3aed;
|
||||||
|
--terminal-tool-name: #8b5cf6;
|
||||||
|
--terminal-error: #dc2626;
|
||||||
}
|
}
|
||||||
|
|
||||||
html,
|
html,
|
||||||
|
|||||||
@@ -0,0 +1,151 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { openUrl } from "@tauri-apps/plugin-opener";
|
||||||
|
import { getVersion } from "@tauri-apps/api/app";
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { onClose }: Props = $props();
|
||||||
|
|
||||||
|
let appVersion = $state("");
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
appVersion = await getVersion();
|
||||||
|
});
|
||||||
|
|
||||||
|
const links = {
|
||||||
|
source: "https://git.nhcarrigan.com/nhcarrigan/hikari-desktop",
|
||||||
|
discord: "https://chat.nhcarrigan.com",
|
||||||
|
website: "https://nhcarrigan.com",
|
||||||
|
license: "https://docs.nhcarrigan.com/legal/license/",
|
||||||
|
changelog: "https://git.nhcarrigan.com/nhcarrigan/hikari-desktop/releases",
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="fixed inset-0 bg-black/50 backdrop-blur-sm z-50 flex items-center justify-center p-4"
|
||||||
|
onclick={onClose}
|
||||||
|
role="button"
|
||||||
|
tabindex="0"
|
||||||
|
onkeydown={(e) => e.key === "Escape" && onClose()}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-lg shadow-xl max-w-md w-full p-6"
|
||||||
|
onclick={(e) => e.stopPropagation()}
|
||||||
|
onkeydown={(e) => e.stopPropagation()}
|
||||||
|
role="dialog"
|
||||||
|
aria-labelledby="about-title"
|
||||||
|
tabindex="-1"
|
||||||
|
>
|
||||||
|
<div class="flex items-center justify-between mb-4">
|
||||||
|
<h2 id="about-title" class="text-xl font-semibold text-gray-100">About Hikari Desktop</h2>
|
||||||
|
<button
|
||||||
|
onclick={onClose}
|
||||||
|
class="p-1 text-gray-500 hover:text-gray-300 transition-colors"
|
||||||
|
aria-label="Close"
|
||||||
|
>
|
||||||
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
stroke-width="2"
|
||||||
|
d="M6 18L18 6M6 6l12 12"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="space-y-4 text-sm">
|
||||||
|
<div>
|
||||||
|
<h3 class="font-medium text-gray-200 mb-2">What is Hikari Desktop?</h3>
|
||||||
|
<p class="text-gray-400">
|
||||||
|
Hikari Desktop is an AI-powered desktop assistant that brings Claude directly to your
|
||||||
|
desktop. Built with love using Tauri, Svelte, and Rust for a fast, native experience.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h3 class="font-medium text-gray-200 mb-2">Version</h3>
|
||||||
|
<p class="text-gray-400 mb-1">
|
||||||
|
{appVersion || "Loading..."}
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
onclick={() => openUrl(links.changelog)}
|
||||||
|
class="text-[var(--accent-primary)] hover:text-[var(--accent-primary-hover)] transition-colors underline"
|
||||||
|
>
|
||||||
|
View Changelog
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h3 class="font-medium text-gray-200 mb-2">Source Code</h3>
|
||||||
|
<button
|
||||||
|
onclick={() => openUrl(links.source)}
|
||||||
|
class="text-[var(--accent-primary)] hover:text-[var(--accent-primary-hover)] transition-colors underline"
|
||||||
|
>
|
||||||
|
View on Git
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h3 class="font-medium text-gray-200 mb-2">Support & Community</h3>
|
||||||
|
<p class="text-gray-400 mb-1">Found a bug or have a suggestion?</p>
|
||||||
|
<button
|
||||||
|
onclick={() => openUrl(links.discord)}
|
||||||
|
class="text-[var(--accent-primary)] hover:text-[var(--accent-primary-hover)] transition-colors underline"
|
||||||
|
>
|
||||||
|
Join our Discord
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h3 class="font-medium text-gray-200 mb-2">Built with 💕 by</h3>
|
||||||
|
<button
|
||||||
|
onclick={() => openUrl(links.website)}
|
||||||
|
class="text-[var(--accent-primary)] hover:text-[var(--accent-primary-hover)] transition-colors underline"
|
||||||
|
>
|
||||||
|
Naomi Carrigan
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h3 class="font-medium text-gray-200 mb-2">License</h3>
|
||||||
|
<p class="text-gray-400 mb-1">
|
||||||
|
This project is open source and available under our license terms.
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
onclick={() => openUrl(links.license)}
|
||||||
|
class="text-[var(--accent-primary)] hover:text-[var(--accent-primary-hover)] transition-colors underline"
|
||||||
|
>
|
||||||
|
View License
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="pt-4 mt-4 border-t border-[var(--border-color)]">
|
||||||
|
<p class="text-xs text-gray-500 text-center">
|
||||||
|
Copyright © {new Date().getFullYear()} Naomi Carrigan. All rights reserved.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
/* Ensure the panel appears above other content */
|
||||||
|
[role="dialog"] {
|
||||||
|
animation: slideIn 0.2s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes slideIn {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: scale(0.95);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,202 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
import { fade, fly } from "svelte/transition";
|
||||||
|
import { cubicOut } from "svelte/easing";
|
||||||
|
import { listen } from "@tauri-apps/api/event";
|
||||||
|
import type { AchievementUnlockedEvent } from "$lib/types/achievements";
|
||||||
|
|
||||||
|
let achievements = $state<AchievementUnlockedEvent[]>([]);
|
||||||
|
let currentAchievement = $state<AchievementUnlockedEvent | null>(null);
|
||||||
|
let showNotification = $state(false);
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
let unlisten: (() => void) | undefined;
|
||||||
|
|
||||||
|
const setupListener = async () => {
|
||||||
|
unlisten = await listen<AchievementUnlockedEvent>("achievement:unlocked", (event) => {
|
||||||
|
achievements.push(event.payload);
|
||||||
|
if (!showNotification) {
|
||||||
|
showNext();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
setupListener();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (unlisten) {
|
||||||
|
unlisten();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
function showNext() {
|
||||||
|
if (achievements.length > 0) {
|
||||||
|
currentAchievement = achievements.shift() || null;
|
||||||
|
showNotification = true;
|
||||||
|
|
||||||
|
// Auto-hide after 5 seconds
|
||||||
|
setTimeout(() => {
|
||||||
|
showNotification = false;
|
||||||
|
// Show next achievement after animation completes
|
||||||
|
setTimeout(() => showNext(), 300);
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function dismiss() {
|
||||||
|
showNotification = false;
|
||||||
|
// Show next achievement after animation completes
|
||||||
|
setTimeout(() => showNext(), 300);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRarityColor(rarity: string): string {
|
||||||
|
switch (rarity) {
|
||||||
|
case "legendary":
|
||||||
|
return "from-yellow-400 to-orange-500";
|
||||||
|
case "epic":
|
||||||
|
return "from-purple-400 to-pink-500";
|
||||||
|
case "rare":
|
||||||
|
return "from-blue-400 to-indigo-500";
|
||||||
|
default:
|
||||||
|
return "from-green-400 to-emerald-500";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAchievementRarity(id: string): string {
|
||||||
|
// Determine rarity based on achievement ID
|
||||||
|
if (id === "TokenMaster") return "legendary";
|
||||||
|
if (["CodeMachine", "Unstoppable"].includes(id)) return "epic";
|
||||||
|
if (
|
||||||
|
[
|
||||||
|
"BlossomingCoder",
|
||||||
|
"CodeWizard",
|
||||||
|
"MasterBuilder",
|
||||||
|
"EnduranceChamp",
|
||||||
|
"DeepDive",
|
||||||
|
"CreativeCoder",
|
||||||
|
].includes(id)
|
||||||
|
)
|
||||||
|
return "rare";
|
||||||
|
return "common";
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if showNotification && currentAchievement}
|
||||||
|
<div
|
||||||
|
class="fixed top-20 right-4 z-50 max-w-sm"
|
||||||
|
in:fly={{ x: 300, duration: 500, easing: cubicOut }}
|
||||||
|
out:fade={{ duration: 300 }}
|
||||||
|
>
|
||||||
|
<!-- Backdrop with animated gradient border -->
|
||||||
|
<div class="relative p-[2px] rounded-lg overflow-hidden">
|
||||||
|
<!-- Animated gradient border -->
|
||||||
|
<div
|
||||||
|
class="absolute inset-0 bg-gradient-to-r {getRarityColor(
|
||||||
|
getAchievementRarity(currentAchievement.achievement.id)
|
||||||
|
)} animate-pulse"
|
||||||
|
></div>
|
||||||
|
|
||||||
|
<!-- Main notification content -->
|
||||||
|
<div class="relative bg-[var(--bg-primary)] rounded-lg p-4 shadow-2xl backdrop-blur-sm">
|
||||||
|
<button
|
||||||
|
onclick={dismiss}
|
||||||
|
onkeydown={(e) => e.key === "Enter" && dismiss()}
|
||||||
|
class="absolute top-2 right-2 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 transition-colors"
|
||||||
|
aria-label="Dismiss notification"
|
||||||
|
>
|
||||||
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
stroke-width="2"
|
||||||
|
d="M6 18L18 6M6 6l12 12"
|
||||||
|
></path>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div class="flex items-start gap-4">
|
||||||
|
<!-- Icon with animated sparkles -->
|
||||||
|
<div class="relative flex-shrink-0">
|
||||||
|
<div class="text-5xl animate-bounce">{currentAchievement.achievement.icon}</div>
|
||||||
|
|
||||||
|
<!-- Sparkle animations -->
|
||||||
|
<div class="absolute -top-1 -right-1 text-yellow-400 animate-ping">✨</div>
|
||||||
|
<div
|
||||||
|
class="absolute -bottom-1 -left-1 text-yellow-400 animate-ping animation-delay-200"
|
||||||
|
>
|
||||||
|
✨
|
||||||
|
</div>
|
||||||
|
<div class="absolute top-1/2 -right-2 text-yellow-400 animate-ping animation-delay-400">
|
||||||
|
✨
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Text content -->
|
||||||
|
<div class="flex-1 min-w-0 pt-1">
|
||||||
|
<h3
|
||||||
|
class="text-sm font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wide"
|
||||||
|
>
|
||||||
|
Achievement Unlocked!
|
||||||
|
</h3>
|
||||||
|
<p class="text-lg font-bold text-[var(--text-primary)] mt-1">
|
||||||
|
{currentAchievement.achievement.name}
|
||||||
|
</p>
|
||||||
|
<p class="text-sm text-gray-600 dark:text-gray-400 mt-1">
|
||||||
|
{currentAchievement.achievement.description}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<!-- Rarity badge -->
|
||||||
|
<div class="mt-2 inline-flex items-center">
|
||||||
|
<span
|
||||||
|
class="px-2 py-1 text-xs font-medium rounded-full bg-gradient-to-r {getRarityColor(
|
||||||
|
getAchievementRarity(currentAchievement.achievement.id)
|
||||||
|
)} text-white capitalize"
|
||||||
|
>
|
||||||
|
{getAchievementRarity(currentAchievement.achievement.id)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Celebration confetti effect (CSS only) -->
|
||||||
|
<div class="absolute inset-0 pointer-events-none overflow-hidden rounded-lg">
|
||||||
|
{#each Array(10) as _ (_)}
|
||||||
|
<div
|
||||||
|
class="absolute w-2 h-2 bg-gradient-to-br {getRarityColor(
|
||||||
|
getAchievementRarity(currentAchievement.achievement.id)
|
||||||
|
)} rounded-full animate-fall"
|
||||||
|
style="left: {Math.random() * 100}%; animation-delay: {Math.random() *
|
||||||
|
2}s; animation-duration: {2 + Math.random() * 2}s;"
|
||||||
|
></div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
@keyframes fall {
|
||||||
|
0% {
|
||||||
|
transform: translateY(-20px) rotate(0deg);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: translateY(400px) rotate(720deg);
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.animate-fall {
|
||||||
|
animation: fall linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.animation-delay-200 {
|
||||||
|
animation-delay: 200ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
.animation-delay-400 {
|
||||||
|
animation-delay: 400ms;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,266 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { slide } from "svelte/transition";
|
||||||
|
import { quintOut } from "svelte/easing";
|
||||||
|
import {
|
||||||
|
achievementsStore,
|
||||||
|
achievementProgress,
|
||||||
|
achievementCategories,
|
||||||
|
} from "$lib/stores/achievements";
|
||||||
|
import type { Achievement } from "$lib/types/achievements";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
isOpen: boolean;
|
||||||
|
onClose?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { isOpen = $bindable(false), onClose }: Props = $props();
|
||||||
|
let selectedCategory = $state<string | null>(null);
|
||||||
|
|
||||||
|
const achievementsState = $derived($achievementsStore);
|
||||||
|
const progress = $derived($achievementProgress);
|
||||||
|
|
||||||
|
function getRarityColor(rarity: string): string {
|
||||||
|
switch (rarity) {
|
||||||
|
case "legendary":
|
||||||
|
return "text-yellow-500 dark:text-yellow-400";
|
||||||
|
case "epic":
|
||||||
|
return "text-purple-500 dark:text-purple-400";
|
||||||
|
case "rare":
|
||||||
|
return "text-blue-500 dark:text-blue-400";
|
||||||
|
default:
|
||||||
|
return "text-green-500 dark:text-green-400";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRarityBg(rarity: string): string {
|
||||||
|
switch (rarity) {
|
||||||
|
case "legendary":
|
||||||
|
return "bg-yellow-500/10";
|
||||||
|
case "epic":
|
||||||
|
return "bg-purple-500/10";
|
||||||
|
case "rare":
|
||||||
|
return "bg-blue-500/10";
|
||||||
|
default:
|
||||||
|
return "bg-green-500/10";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDate(date: Date | undefined): string {
|
||||||
|
if (!date) return "";
|
||||||
|
return new Date(date).toLocaleDateString("en-US", {
|
||||||
|
month: "short",
|
||||||
|
day: "numeric",
|
||||||
|
year: "numeric",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAchievementsForCategory(categoryIds: string[]): Achievement[] {
|
||||||
|
return categoryIds
|
||||||
|
.map(
|
||||||
|
(id) => achievementsState.achievements[id as keyof typeof achievementsState.achievements]
|
||||||
|
)
|
||||||
|
.filter(Boolean);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- Achievements panel -->
|
||||||
|
{#if isOpen}
|
||||||
|
<div
|
||||||
|
class="fixed inset-0 bg-black/50 z-40"
|
||||||
|
onclick={onClose}
|
||||||
|
onkeydown={(e) => e.key === "Escape" && onClose?.()}
|
||||||
|
role="button"
|
||||||
|
tabindex="-1"
|
||||||
|
aria-label="Close achievements panel"
|
||||||
|
transition:slide={{ duration: 300, easing: quintOut }}
|
||||||
|
></div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="fixed left-0 top-0 h-full w-96 bg-[var(--bg-primary)] border-r border-[var(--border-color)]
|
||||||
|
shadow-2xl z-50 flex flex-col"
|
||||||
|
transition:slide={{ duration: 300, easing: quintOut, axis: "x" }}
|
||||||
|
>
|
||||||
|
<!-- Header -->
|
||||||
|
<div class="p-6 border-b border-[var(--border-color)]">
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<h2 class="text-2xl font-bold text-[var(--text-primary)]">Achievements</h2>
|
||||||
|
<button
|
||||||
|
onclick={onClose}
|
||||||
|
onkeydown={(e) => e.key === "Enter" && onClose?.()}
|
||||||
|
class="text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"
|
||||||
|
aria-label="Close achievements panel"
|
||||||
|
>
|
||||||
|
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
stroke-width="2"
|
||||||
|
d="M6 18L18 6M6 6l12 12"
|
||||||
|
></path>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Overall progress -->
|
||||||
|
<div class="mt-4">
|
||||||
|
<div
|
||||||
|
class="flex items-center justify-between text-sm text-gray-600 dark:text-gray-400 mb-2"
|
||||||
|
>
|
||||||
|
<span>{progress.unlocked} / {progress.total} Unlocked</span>
|
||||||
|
<span>{progress.percentage}%</span>
|
||||||
|
</div>
|
||||||
|
<div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
|
||||||
|
<div
|
||||||
|
class="bg-gradient-to-r from-[var(--accent-primary)] to-[var(--accent-secondary)] h-2 rounded-full transition-all duration-500"
|
||||||
|
style="width: {progress.percentage}%"
|
||||||
|
></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Categories -->
|
||||||
|
<div class="flex-1 overflow-y-auto">
|
||||||
|
{#each achievementCategories as category (category.name)}
|
||||||
|
{@const achievements = getAchievementsForCategory(category.ids)}
|
||||||
|
{@const unlockedCount = achievements.filter((a) => a.unlocked).length}
|
||||||
|
|
||||||
|
<div class="border-b border-[var(--border-color)]">
|
||||||
|
<button
|
||||||
|
onclick={() =>
|
||||||
|
(selectedCategory = selectedCategory === category.name ? null : category.name)}
|
||||||
|
onkeydown={(e) =>
|
||||||
|
e.key === "Enter" &&
|
||||||
|
(selectedCategory = selectedCategory === category.name ? null : category.name)}
|
||||||
|
class="w-full p-4 text-left hover:bg-[var(--bg-secondary)] transition-colors"
|
||||||
|
>
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<div>
|
||||||
|
<h3 class="font-semibold text-[var(--text-primary)]">{category.name}</h3>
|
||||||
|
<p class="text-sm text-gray-600 dark:text-gray-400">{category.description}</p>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<span class="text-sm text-gray-600 dark:text-gray-400">
|
||||||
|
{unlockedCount} / {achievements.length}
|
||||||
|
</span>
|
||||||
|
<svg
|
||||||
|
class="w-5 h-5 transition-transform {selectedCategory === category.name
|
||||||
|
? 'rotate-180'
|
||||||
|
: ''}"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
stroke-width="2"
|
||||||
|
d="M19 9l-7 7-7-7"
|
||||||
|
></path>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{#if selectedCategory === category.name}
|
||||||
|
<div class="p-4 space-y-3" transition:slide={{ duration: 200, easing: quintOut }}>
|
||||||
|
{#each achievements as achievement (achievement.id)}
|
||||||
|
<div
|
||||||
|
class="p-3 rounded-lg border {achievement.unlocked
|
||||||
|
? 'border-[var(--border-color)] bg-[var(--bg-secondary)]'
|
||||||
|
: 'border-gray-300 dark:border-gray-600 bg-gray-100 dark:bg-gray-800 opacity-50'}"
|
||||||
|
>
|
||||||
|
<div class="flex items-start gap-3">
|
||||||
|
<!-- Icon -->
|
||||||
|
<div class="text-3xl flex-shrink-0 {achievement.unlocked ? '' : 'grayscale'}">
|
||||||
|
{achievement.icon}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Details -->
|
||||||
|
<div class="flex-1 min-w-0">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<h4 class="font-semibold text-[var(--text-primary)]">
|
||||||
|
{achievement.name}
|
||||||
|
</h4>
|
||||||
|
<span
|
||||||
|
class="text-xs px-2 py-0.5 rounded-full {getRarityBg(
|
||||||
|
achievement.rarity
|
||||||
|
)} {getRarityColor(achievement.rarity)} capitalize"
|
||||||
|
>
|
||||||
|
{achievement.rarity}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<p class="text-sm text-gray-600 dark:text-gray-400 mt-1">
|
||||||
|
{achievement.description}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{#if achievement.unlocked && achievement.unlockedAt}
|
||||||
|
<p class="text-xs text-gray-500 dark:text-gray-500 mt-2">
|
||||||
|
Unlocked {formatDate(achievement.unlockedAt)}
|
||||||
|
</p>
|
||||||
|
{:else if achievement.maxProgress && achievement.progress !== undefined}
|
||||||
|
<!-- Progress bar for locked achievements -->
|
||||||
|
<div class="mt-2">
|
||||||
|
<div class="flex items-center justify-between text-xs text-gray-500 mb-1">
|
||||||
|
<span>Progress</span>
|
||||||
|
<span>{achievement.progress} / {achievement.maxProgress}</span>
|
||||||
|
</div>
|
||||||
|
<div class="w-full bg-gray-300 dark:bg-gray-700 rounded-full h-1.5">
|
||||||
|
<div
|
||||||
|
class="bg-gray-500 h-1.5 rounded-full transition-all duration-300"
|
||||||
|
style="width: {Math.min(
|
||||||
|
(achievement.progress / achievement.maxProgress) * 100,
|
||||||
|
100
|
||||||
|
)}%"
|
||||||
|
></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Footer with last unlocked -->
|
||||||
|
{#if achievementsState.lastUnlocked}
|
||||||
|
<div class="p-4 border-t border-[var(--border-color)] bg-[var(--bg-secondary)]">
|
||||||
|
<p class="text-sm text-gray-600 dark:text-gray-400 mb-1">Last Unlocked:</p>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<span class="text-xl">{achievementsState.lastUnlocked.icon}</span>
|
||||||
|
<div>
|
||||||
|
<p class="font-semibold text-[var(--text-primary)]">
|
||||||
|
{achievementsState.lastUnlocked.name}
|
||||||
|
</p>
|
||||||
|
<p class="text-xs text-gray-500">
|
||||||
|
{formatDate(achievementsState.lastUnlocked.unlockedAt)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
/* Custom scrollbar for achievement list */
|
||||||
|
:global(.overflow-y-auto::-webkit-scrollbar) {
|
||||||
|
width: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.overflow-y-auto::-webkit-scrollbar-track) {
|
||||||
|
background: var(--bg-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.overflow-y-auto::-webkit-scrollbar-thumb) {
|
||||||
|
background: var(--border-color);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.overflow-y-auto::-webkit-scrollbar-thumb:hover) {
|
||||||
|
background: var(--accent-primary);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -9,6 +9,10 @@
|
|||||||
mcp_servers_json: null,
|
mcp_servers_json: null,
|
||||||
auto_granted_tools: [],
|
auto_granted_tools: [],
|
||||||
theme: "dark",
|
theme: "dark",
|
||||||
|
greeting_enabled: true,
|
||||||
|
greeting_custom_prompt: null,
|
||||||
|
notifications_enabled: true,
|
||||||
|
notification_volume: 0.7,
|
||||||
});
|
});
|
||||||
|
|
||||||
let isOpen = $state(false);
|
let isOpen = $state(false);
|
||||||
@@ -220,6 +224,44 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<!-- Greeting Section -->
|
||||||
|
<section class="mb-6">
|
||||||
|
<h3 class="text-sm font-medium text-[var(--accent-primary)] uppercase tracking-wider mb-3">
|
||||||
|
Greeting
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<!-- Enable/Disable Toggle -->
|
||||||
|
<div class="mb-4">
|
||||||
|
<label class="flex items-center gap-3 cursor-pointer">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
bind:checked={config.greeting_enabled}
|
||||||
|
class="w-4 h-4 rounded border-[var(--border-color)] bg-[var(--bg-primary)] text-[var(--accent-primary)] focus:ring-[var(--accent-primary)]"
|
||||||
|
/>
|
||||||
|
<span class="text-sm text-gray-300">Send greeting on connect</span>
|
||||||
|
</label>
|
||||||
|
<p class="text-xs text-gray-500 mt-1 ml-7">
|
||||||
|
Automatically greet you when a session starts with time-based messages
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Custom Greeting Prompt -->
|
||||||
|
{#if config.greeting_enabled}
|
||||||
|
<div class="mb-4">
|
||||||
|
<label for="greeting-prompt" class="block text-sm text-gray-400 mb-1">
|
||||||
|
Custom Greeting Prompt <span class="text-gray-600">(optional)</span>
|
||||||
|
</label>
|
||||||
|
<textarea
|
||||||
|
id="greeting-prompt"
|
||||||
|
bind:value={config.greeting_custom_prompt}
|
||||||
|
rows="3"
|
||||||
|
placeholder="Leave empty for time-based greetings, or customize how you'd like to be greeted..."
|
||||||
|
class="w-full px-3 py-2 bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-lg text-[var(--text-primary)] focus:outline-none focus:border-[var(--accent-primary)] resize-none"
|
||||||
|
></textarea>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</section>
|
||||||
|
|
||||||
<!-- MCP Servers Section -->
|
<!-- MCP Servers Section -->
|
||||||
<section class="mb-6">
|
<section class="mb-6">
|
||||||
<h3 class="text-sm font-medium text-[var(--accent-primary)] uppercase tracking-wider mb-3">
|
<h3 class="text-sm font-medium text-[var(--accent-primary)] uppercase tracking-wider mb-3">
|
||||||
@@ -354,6 +396,51 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<!-- Notifications Section -->
|
||||||
|
<section class="mb-6">
|
||||||
|
<h3 class="text-sm font-medium text-[var(--accent-primary)] uppercase tracking-wider mb-3">
|
||||||
|
Notifications
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<!-- Enable/Disable Notifications -->
|
||||||
|
<div class="mb-4">
|
||||||
|
<label class="flex items-center gap-3 cursor-pointer">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
bind:checked={config.notifications_enabled}
|
||||||
|
class="w-4 h-4 text-[var(--accent-primary)] bg-[var(--bg-primary)] border-[var(--border-color)] rounded focus:ring-[var(--accent-primary)] focus:ring-2"
|
||||||
|
/>
|
||||||
|
<span class="text-sm text-gray-300">Enable sound notifications</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Volume Control -->
|
||||||
|
<div class="mb-4">
|
||||||
|
<label for="notification-volume" class="block text-sm text-gray-400 mb-2">
|
||||||
|
Notification Volume
|
||||||
|
</label>
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<input
|
||||||
|
id="notification-volume"
|
||||||
|
type="range"
|
||||||
|
bind:value={config.notification_volume}
|
||||||
|
min="0"
|
||||||
|
max="1"
|
||||||
|
step="0.1"
|
||||||
|
disabled={!config.notifications_enabled}
|
||||||
|
class="flex-1 h-2 bg-[var(--bg-primary)] rounded-lg appearance-none cursor-pointer disabled:opacity-50"
|
||||||
|
/>
|
||||||
|
<span class="text-sm text-gray-300 w-12 text-right">
|
||||||
|
{Math.round(config.notification_volume * 100)}%
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="text-xs text-gray-500">
|
||||||
|
Sound notifications will play when I complete tasks, encounter errors, or need permissions.
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<!-- Save Button -->
|
<!-- Save Button -->
|
||||||
<div class="sticky bottom-0 pt-4 pb-2 bg-[var(--bg-secondary)]">
|
<div class="sticky bottom-0 pt-4 pb-2 bg-[var(--bg-secondary)]">
|
||||||
<button
|
<button
|
||||||
@@ -366,3 +453,34 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
/* Custom range input styling */
|
||||||
|
input[type="range"]::-webkit-slider-thumb {
|
||||||
|
appearance: none;
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
background: var(--accent-primary);
|
||||||
|
border-radius: 50%;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="range"]::-moz-range-thumb {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
background: var(--accent-primary);
|
||||||
|
border-radius: 50%;
|
||||||
|
cursor: pointer;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="range"]:disabled::-webkit-slider-thumb {
|
||||||
|
background: var(--text-tertiary);
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="range"]:disabled::-moz-range-thumb {
|
||||||
|
background: var(--text-tertiary);
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -0,0 +1,279 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { claudeStore } from "$lib/stores/claude";
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
import type { Conversation } from "$lib/stores/conversations";
|
||||||
|
import { SvelteMap } from "svelte/reactivity";
|
||||||
|
|
||||||
|
let conversations: Map<string, Conversation> = new Map();
|
||||||
|
let activeConversationId: string | null = null;
|
||||||
|
let editingTabId: string | null = null;
|
||||||
|
let editingName = "";
|
||||||
|
|
||||||
|
// Track which conversation actually has the Claude connection
|
||||||
|
let connectedConversationId: string | null = null;
|
||||||
|
|
||||||
|
// Track last seen message count for each conversation
|
||||||
|
let lastSeenMessageCount = new SvelteMap<string, number>();
|
||||||
|
|
||||||
|
claudeStore.conversations.subscribe((convs) => {
|
||||||
|
conversations = convs;
|
||||||
|
|
||||||
|
// Update the last seen count for the active conversation
|
||||||
|
if (activeConversationId) {
|
||||||
|
const activeConv = convs.get(activeConversationId);
|
||||||
|
if (activeConv) {
|
||||||
|
lastSeenMessageCount.set(activeConversationId, activeConv.terminalLines.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
claudeStore.activeConversationId.subscribe((id) => {
|
||||||
|
activeConversationId = id;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Find the connected conversation
|
||||||
|
$: {
|
||||||
|
let foundConnected = false;
|
||||||
|
for (const [id, conv] of conversations) {
|
||||||
|
if (conv.connectionStatus === "connected" || conv.connectionStatus === "connecting") {
|
||||||
|
connectedConversationId = id;
|
||||||
|
foundConnected = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!foundConnected) {
|
||||||
|
connectedConversationId = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createNewTab() {
|
||||||
|
claudeStore.createConversation();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function switchTab(id: string) {
|
||||||
|
if (editingTabId) {
|
||||||
|
saveTabName();
|
||||||
|
}
|
||||||
|
await claudeStore.switchConversation(id);
|
||||||
|
|
||||||
|
// Mark messages as seen when switching to this tab
|
||||||
|
const conv = conversations.get(id);
|
||||||
|
if (conv) {
|
||||||
|
lastSeenMessageCount.set(id, conv.terminalLines.length);
|
||||||
|
// Trigger reactivity
|
||||||
|
lastSeenMessageCount = lastSeenMessageCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteTab(id: string, event: MouseEvent) {
|
||||||
|
event.stopPropagation();
|
||||||
|
if (conversations.size > 1) {
|
||||||
|
claudeStore.deleteConversation(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function startEditing(id: string, name: string, event: MouseEvent) {
|
||||||
|
event.stopPropagation();
|
||||||
|
editingTabId = id;
|
||||||
|
editingName = name;
|
||||||
|
// Focus input after DOM update
|
||||||
|
setTimeout(() => {
|
||||||
|
const input = document.querySelector('.tab-item input[type="text"]') as HTMLInputElement;
|
||||||
|
if (input) input.focus();
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveTabName() {
|
||||||
|
if (editingTabId && editingName.trim()) {
|
||||||
|
claudeStore.renameConversation(editingTabId, editingName.trim());
|
||||||
|
}
|
||||||
|
editingTabId = null;
|
||||||
|
editingName = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function getConnectionStatusColor(status: Conversation["connectionStatus"]): string {
|
||||||
|
switch (status) {
|
||||||
|
case "connected":
|
||||||
|
return "bg-green-500";
|
||||||
|
case "connecting":
|
||||||
|
return "bg-yellow-500";
|
||||||
|
case "disconnected":
|
||||||
|
return "bg-red-500";
|
||||||
|
default:
|
||||||
|
return "bg-gray-500";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasUnreadMessages(id: string, conversation: Conversation): boolean {
|
||||||
|
if (id === activeConversationId) return false; // Active tab never has unread
|
||||||
|
const lastSeen = lastSeenMessageCount.get(id) || 0;
|
||||||
|
return conversation.terminalLines.length > lastSeen;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleKeydown(event: KeyboardEvent) {
|
||||||
|
if (event.key === "Enter") {
|
||||||
|
saveTabName();
|
||||||
|
} else if (event.key === "Escape") {
|
||||||
|
editingTabId = null;
|
||||||
|
editingName = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleTabKeydown(id: string, event: KeyboardEvent) {
|
||||||
|
if (event.key === "Enter" || event.key === " ") {
|
||||||
|
event.preventDefault();
|
||||||
|
switchTab(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keyboard shortcuts
|
||||||
|
onMount(() => {
|
||||||
|
function handleGlobalKeydown(event: KeyboardEvent) {
|
||||||
|
// Ctrl/Cmd + T: New tab
|
||||||
|
if ((event.ctrlKey || event.metaKey) && event.key === "t") {
|
||||||
|
event.preventDefault();
|
||||||
|
createNewTab();
|
||||||
|
}
|
||||||
|
// Ctrl/Cmd + W: Close current tab
|
||||||
|
else if ((event.ctrlKey || event.metaKey) && event.key === "w") {
|
||||||
|
event.preventDefault();
|
||||||
|
if (activeConversationId && conversations.size > 1) {
|
||||||
|
claudeStore.deleteConversation(activeConversationId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Ctrl/Cmd + Tab: Next tab
|
||||||
|
else if ((event.ctrlKey || event.metaKey) && event.key === "Tab" && !event.shiftKey) {
|
||||||
|
event.preventDefault();
|
||||||
|
const tabs = Array.from(conversations.keys());
|
||||||
|
const currentIndex = tabs.findIndex((id) => id === activeConversationId);
|
||||||
|
if (currentIndex !== -1) {
|
||||||
|
const nextIndex = (currentIndex + 1) % tabs.length;
|
||||||
|
claudeStore.switchConversation(tabs[nextIndex]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Ctrl/Cmd + Shift + Tab: Previous tab
|
||||||
|
else if ((event.ctrlKey || event.metaKey) && event.key === "Tab" && event.shiftKey) {
|
||||||
|
event.preventDefault();
|
||||||
|
const tabs = Array.from(conversations.keys());
|
||||||
|
const currentIndex = tabs.findIndex((id) => id === activeConversationId);
|
||||||
|
if (currentIndex !== -1) {
|
||||||
|
const prevIndex = (currentIndex - 1 + tabs.length) % tabs.length;
|
||||||
|
claudeStore.switchConversation(tabs[prevIndex]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("keydown", handleGlobalKeydown);
|
||||||
|
return () => window.removeEventListener("keydown", handleGlobalKeydown);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="terminal-tabs flex items-center gap-1 px-2 py-1 bg-[var(--bg-secondary)] border-b border-[var(--border-color)]"
|
||||||
|
>
|
||||||
|
{#each Array.from(conversations.entries()) as [id, conversation] (id)}
|
||||||
|
<div
|
||||||
|
class="tab-item group relative flex items-center px-3 py-1.5 rounded-t cursor-pointer transition-all
|
||||||
|
{id === activeConversationId
|
||||||
|
? 'bg-[var(--bg-terminal)] text-[var(--text-primary)] border-t border-l border-r border-[var(--border-color)]'
|
||||||
|
: 'bg-[var(--bg-tertiary)] text-[var(--text-secondary)] hover:bg-[var(--bg-terminal)]/50'}"
|
||||||
|
onclick={() => switchTab(id)}
|
||||||
|
onkeydown={(e) => handleTabKeydown(id, e)}
|
||||||
|
role="tab"
|
||||||
|
tabindex={0}
|
||||||
|
aria-selected={id === activeConversationId}
|
||||||
|
>
|
||||||
|
{#if editingTabId === id}
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
bind:value={editingName}
|
||||||
|
onblur={saveTabName}
|
||||||
|
onkeydown={handleKeydown}
|
||||||
|
onclick={(e) => e.stopPropagation()}
|
||||||
|
class="bg-transparent border-b border-[var(--border-color)] outline-none px-0 py-0 text-sm w-32"
|
||||||
|
/>
|
||||||
|
{:else}
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<div
|
||||||
|
class="w-2 h-2 rounded-full {getConnectionStatusColor(conversation.connectionStatus)}"
|
||||||
|
title="Connection: {conversation.connectionStatus}{id !== connectedConversationId &&
|
||||||
|
connectedConversationId
|
||||||
|
? ' (Another tab is connected)'
|
||||||
|
: ''}"
|
||||||
|
></div>
|
||||||
|
<span
|
||||||
|
class="text-sm pr-6 max-w-[150px] truncate"
|
||||||
|
ondblclick={(e) => startEditing(id, conversation.name, e)}
|
||||||
|
role="button"
|
||||||
|
tabindex={-1}
|
||||||
|
>
|
||||||
|
{conversation.name}
|
||||||
|
</span>
|
||||||
|
{#if id !== activeConversationId && id === connectedConversationId}
|
||||||
|
<span
|
||||||
|
class="text-xs text-[var(--text-tertiary)]"
|
||||||
|
title="This tab has the Claude connection"
|
||||||
|
>
|
||||||
|
(connected)
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
{#if hasUnreadMessages(id, conversation)}
|
||||||
|
<div
|
||||||
|
class="absolute -top-1 -right-1 w-2 h-2 rounded-full bg-blue-500 animate-pulse"
|
||||||
|
title="New messages"
|
||||||
|
></div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if conversations.size > 1}
|
||||||
|
<button
|
||||||
|
onclick={(e) => deleteTab(id, e)}
|
||||||
|
class="absolute right-1 top-1/2 -translate-y-1/2 w-4 h-4 flex items-center justify-center rounded hover:bg-[var(--bg-secondary)] opacity-0 group-hover:opacity-100 transition-opacity"
|
||||||
|
title="Close tab"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
class="w-3 h-3"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
stroke-width="2"
|
||||||
|
d="M6 18L18 6M6 6l12 12"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
|
||||||
|
<button
|
||||||
|
onclick={createNewTab}
|
||||||
|
class="new-tab-btn flex items-center justify-center w-7 h-7 rounded hover:bg-[var(--bg-tertiary)] text-[var(--text-secondary)] transition-colors"
|
||||||
|
title="New conversation (Ctrl+T)"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
class="w-4 h-4"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
>
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.terminal-tabs {
|
||||||
|
min-height: 36px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-item {
|
||||||
|
min-width: 100px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
console.log("ConversationTabs component loading...");
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="terminal-tabs" style="background: red; height: 36px; color: white;">
|
||||||
|
Debug: Tabs Component Loaded
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
interface Props {
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { onClose }: Props = $props();
|
||||||
|
|
||||||
|
const sections = [
|
||||||
|
{
|
||||||
|
title: "Getting Started",
|
||||||
|
items: [
|
||||||
|
"Enter your Claude API key in Settings (gear icon)",
|
||||||
|
"Set your working directory and click Connect",
|
||||||
|
"Start chatting with Hikari - your AI assistant!",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Key Features",
|
||||||
|
items: [
|
||||||
|
"🗂️ File Management: Hikari can read, write, and edit files in your project",
|
||||||
|
"💻 Terminal Access: Execute commands and run scripts",
|
||||||
|
"🔍 Code Search: Find files and search through code",
|
||||||
|
"🌐 Web Access: Fetch information from the web",
|
||||||
|
"📊 MCP Servers: Connect to external tools via Model Context Protocol",
|
||||||
|
"📁 Multi-tab Support: Work on multiple conversations simultaneously",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Available Commands",
|
||||||
|
items: [
|
||||||
|
"Type naturally - Hikari understands context!",
|
||||||
|
"Ask to read, create, or modify files",
|
||||||
|
"Request code explanations or debugging help",
|
||||||
|
"Have Hikari run tests or build commands",
|
||||||
|
"Search for specific functions or patterns",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Tips & Tricks",
|
||||||
|
items: [
|
||||||
|
"💡 Use the stats panel to track your usage",
|
||||||
|
"🎯 Be specific about file paths and requirements",
|
||||||
|
"🔒 Grant tool permissions as needed for security",
|
||||||
|
"📌 Pin important conversations for quick access",
|
||||||
|
"🎨 Customize your theme and preferences in Settings",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Keyboard Shortcuts",
|
||||||
|
items: [
|
||||||
|
"Ctrl/Cmd + Enter: Send message",
|
||||||
|
"Ctrl/Cmd + K: Clear chat (when supported)",
|
||||||
|
"Escape: Close modals and panels",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="fixed inset-0 bg-black/50 backdrop-blur-sm z-50 flex items-center justify-center p-4"
|
||||||
|
onclick={onClose}
|
||||||
|
role="button"
|
||||||
|
tabindex="0"
|
||||||
|
onkeydown={(e) => e.key === "Escape" && onClose()}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-lg shadow-xl max-w-2xl w-full max-h-[80vh] overflow-hidden flex flex-col"
|
||||||
|
onclick={(e) => e.stopPropagation()}
|
||||||
|
onkeydown={(e) => e.stopPropagation()}
|
||||||
|
role="dialog"
|
||||||
|
aria-labelledby="help-title"
|
||||||
|
tabindex="-1"
|
||||||
|
>
|
||||||
|
<div class="flex items-center justify-between p-6 pb-4 border-b border-[var(--border-color)]">
|
||||||
|
<h2 id="help-title" class="text-xl font-semibold text-gray-100">How to Use Hikari Desktop</h2>
|
||||||
|
<button
|
||||||
|
onclick={onClose}
|
||||||
|
class="p-1 text-gray-500 hover:text-gray-300 transition-colors"
|
||||||
|
aria-label="Close"
|
||||||
|
>
|
||||||
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
stroke-width="2"
|
||||||
|
d="M6 18L18 6M6 6l12 12"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="overflow-y-auto flex-1 p-6 space-y-6">
|
||||||
|
{#each sections as section (section.title)}
|
||||||
|
<div>
|
||||||
|
<h3 class="font-medium text-gray-200 mb-3">{section.title}</h3>
|
||||||
|
<ul class="space-y-2 text-sm text-gray-400">
|
||||||
|
{#each section.items as item (item)}
|
||||||
|
<li class="flex items-start">
|
||||||
|
<span class="text-[var(--accent-primary)] mr-2 mt-0.5">•</span>
|
||||||
|
<span>{item}</span>
|
||||||
|
</li>
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
|
||||||
|
<div class="pt-4 border-t border-[var(--border-color)]">
|
||||||
|
<p class="text-sm text-gray-500">
|
||||||
|
<strong>Need more help?</strong> Join our Discord community for support and updates!
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
/* Ensure the panel appears above other content */
|
||||||
|
[role="dialog"] {
|
||||||
|
animation: slideIn 0.2s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes slideIn {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: scale(0.95) translateY(10px);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: scale(1) translateY(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Custom scrollbar styling */
|
||||||
|
.overflow-y-auto {
|
||||||
|
scrollbar-width: thin;
|
||||||
|
scrollbar-color: var(--border-color) transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.overflow-y-auto::-webkit-scrollbar {
|
||||||
|
width: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.overflow-y-auto::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.overflow-y-auto::-webkit-scrollbar-thumb {
|
||||||
|
background-color: var(--border-color);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.overflow-y-auto::-webkit-scrollbar-thumb:hover {
|
||||||
|
background-color: var(--accent-primary);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,16 +1,34 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import { claudeStore } from "$lib/stores/claude";
|
import { get } from "svelte/store";
|
||||||
|
import { claudeStore, isClaudeProcessing } from "$lib/stores/claude";
|
||||||
import { characterState } from "$lib/stores/character";
|
import { characterState } from "$lib/stores/character";
|
||||||
|
import { handleNewUserMessage } from "$lib/notifications/rules";
|
||||||
|
import { setSkipNextGreeting } from "$lib/tauri";
|
||||||
|
import {
|
||||||
|
setShouldRestoreHistory,
|
||||||
|
setSavedHistory,
|
||||||
|
getShouldRestoreHistory,
|
||||||
|
getSavedHistory,
|
||||||
|
clearHistoryRestore,
|
||||||
|
} from "$lib/stores/historyRestore";
|
||||||
|
import MessageModeSelector from "$lib/components/MessageModeSelector.svelte";
|
||||||
|
import { getCurrentMode } from "$lib/stores/messageMode";
|
||||||
|
import { formatMessageWithMode } from "$lib/types/messageMode";
|
||||||
|
|
||||||
let inputValue = $state("");
|
let inputValue = $state("");
|
||||||
let isSubmitting = $state(false);
|
let isSubmitting = $state(false);
|
||||||
let isConnected = $state(false);
|
let isConnected = $state(false);
|
||||||
|
let isProcessing = $state(false);
|
||||||
|
|
||||||
claudeStore.connectionStatus.subscribe((status) => {
|
claudeStore.connectionStatus.subscribe((status) => {
|
||||||
isConnected = status === "connected";
|
isConnected = status === "connected";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
isClaudeProcessing.subscribe((processing) => {
|
||||||
|
isProcessing = processing;
|
||||||
|
});
|
||||||
|
|
||||||
async function handleSubmit(event: Event) {
|
async function handleSubmit(event: Event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
@@ -20,11 +38,43 @@
|
|||||||
isSubmitting = true;
|
isSubmitting = true;
|
||||||
inputValue = "";
|
inputValue = "";
|
||||||
|
|
||||||
claudeStore.addLine("user", message);
|
// Apply mode prefix if needed
|
||||||
|
const currentMode = getCurrentMode();
|
||||||
|
const formattedMessage = formatMessageWithMode(message, currentMode);
|
||||||
|
|
||||||
|
// Check if we need to restore conversation history
|
||||||
|
let messageToSend = formattedMessage;
|
||||||
|
if (getShouldRestoreHistory()) {
|
||||||
|
const savedHistory = getSavedHistory();
|
||||||
|
|
||||||
|
if (savedHistory) {
|
||||||
|
// Prepend the conversation history with a context message
|
||||||
|
messageToSend = `[Previous conversation context:]
|
||||||
|
${savedHistory}
|
||||||
|
|
||||||
|
[Continuing conversation after reconnection:]
|
||||||
|
User: ${formattedMessage}`;
|
||||||
|
|
||||||
|
// Clear the restoration flags
|
||||||
|
clearHistoryRestore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset notification state for new user message
|
||||||
|
handleNewUserMessage();
|
||||||
|
|
||||||
|
claudeStore.addLine("user", formattedMessage);
|
||||||
characterState.setState("thinking");
|
characterState.setState("thinking");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await invoke("send_prompt", { message });
|
const conversationId = get(claudeStore.activeConversationId);
|
||||||
|
if (!conversationId) {
|
||||||
|
throw new Error("No active conversation");
|
||||||
|
}
|
||||||
|
await invoke("send_prompt", {
|
||||||
|
conversationId,
|
||||||
|
message: messageToSend,
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to send prompt:", error);
|
console.error("Failed to send prompt:", error);
|
||||||
claudeStore.addLine("error", `Failed to send: ${error}`);
|
claudeStore.addLine("error", `Failed to send: ${error}`);
|
||||||
@@ -34,6 +84,60 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleInterrupt() {
|
||||||
|
// Save the conversation history FIRST before anything else
|
||||||
|
const history = claudeStore.getConversationHistory();
|
||||||
|
|
||||||
|
if (history) {
|
||||||
|
setSavedHistory(history);
|
||||||
|
setShouldRestoreHistory(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const conversationId = get(claudeStore.activeConversationId);
|
||||||
|
if (!conversationId) {
|
||||||
|
throw new Error("No active conversation");
|
||||||
|
}
|
||||||
|
await invoke("interrupt_claude", { conversationId });
|
||||||
|
claudeStore.addLine("system", "Process interrupted - reconnecting...");
|
||||||
|
characterState.setState("idle");
|
||||||
|
|
||||||
|
// Show connecting status while we reconnect
|
||||||
|
claudeStore.setConnectionStatus("connecting");
|
||||||
|
|
||||||
|
// Auto-reconnect after a brief delay
|
||||||
|
setTimeout(async () => {
|
||||||
|
try {
|
||||||
|
const conversationId = get(claudeStore.activeConversationId);
|
||||||
|
if (!conversationId) {
|
||||||
|
throw new Error("No active conversation");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get current working directory before reconnecting
|
||||||
|
const workingDir = await invoke<string>("get_working_directory", { conversationId });
|
||||||
|
|
||||||
|
// Set the flag to skip greeting on next connection
|
||||||
|
setSkipNextGreeting(true);
|
||||||
|
|
||||||
|
// Reconnect to Claude
|
||||||
|
await invoke("start_claude", {
|
||||||
|
conversationId,
|
||||||
|
options: {
|
||||||
|
working_dir: workingDir,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (reconnectError) {
|
||||||
|
console.error("Failed to auto-reconnect:", reconnectError);
|
||||||
|
claudeStore.addLine("error", `Failed to reconnect: ${reconnectError}`);
|
||||||
|
claudeStore.addLine("system", "Please manually reconnect to continue");
|
||||||
|
}
|
||||||
|
}, 500); // Brief delay to ensure process is fully terminated
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to interrupt:", error);
|
||||||
|
claudeStore.addLine("error", `Failed to interrupt: ${error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handleKeyDown(event: KeyboardEvent) {
|
function handleKeyDown(event: KeyboardEvent) {
|
||||||
if (event.key === "Enter" && !event.shiftKey) {
|
if (event.key === "Enter" && !event.shiftKey) {
|
||||||
handleSubmit(event);
|
handleSubmit(event);
|
||||||
@@ -41,34 +145,73 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form onsubmit={handleSubmit} class="input-bar flex gap-3 items-end">
|
<form onsubmit={handleSubmit} class="input-bar">
|
||||||
<div class="flex-1 relative">
|
<div class="input-controls flex gap-2 mb-2">
|
||||||
<textarea
|
<MessageModeSelector />
|
||||||
bind:value={inputValue}
|
</div>
|
||||||
onkeydown={handleKeyDown}
|
|
||||||
placeholder={isConnected ? "Ask Hikari anything..." : "Connect to Claude first..."}
|
<div class="input-row flex gap-3 items-end">
|
||||||
disabled={!isConnected || isSubmitting}
|
<div class="flex-1 relative">
|
||||||
rows={1}
|
<textarea
|
||||||
class="w-full px-4 py-3 bg-[var(--bg-secondary)] border border-[var(--border-color)]
|
bind:value={inputValue}
|
||||||
rounded-lg text-white placeholder-gray-500 resize-none
|
onkeydown={handleKeyDown}
|
||||||
|
placeholder={isConnected ? "Ask Hikari anything..." : "Connect to Claude first..."}
|
||||||
|
disabled={!isConnected || isSubmitting}
|
||||||
|
rows={1}
|
||||||
|
class="w-full px-4 py-3 bg-[var(--bg-secondary)] border border-[var(--border-color)]
|
||||||
|
rounded-lg text-[var(--text-primary)] placeholder-gray-500 resize-none
|
||||||
focus:outline-none focus:border-[var(--accent-primary)] focus:ring-1 focus:ring-[var(--accent-primary)]
|
focus:outline-none focus:border-[var(--accent-primary)] focus:ring-1 focus:ring-[var(--accent-primary)]
|
||||||
disabled:opacity-50 disabled:cursor-not-allowed
|
disabled:opacity-50 disabled:cursor-not-allowed
|
||||||
transition-all duration-200"
|
transition-all duration-200"
|
||||||
></textarea>
|
></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
{#if isProcessing}
|
||||||
type="submit"
|
<button
|
||||||
disabled={!isConnected || isSubmitting || !inputValue.trim()}
|
type="button"
|
||||||
class="px-6 py-3 bg-[var(--accent-primary)] hover:bg-[var(--accent-secondary)]
|
onclick={handleInterrupt}
|
||||||
text-white font-medium rounded-lg
|
class="px-6 py-3 bg-red-600 hover:bg-red-700
|
||||||
disabled:opacity-50 disabled:cursor-not-allowed
|
text-white font-medium rounded-lg
|
||||||
transition-all duration-200 transform hover:scale-105 active:scale-95"
|
transition-all duration-200 transform hover:scale-105 active:scale-95"
|
||||||
>
|
title="Interrupt the current response (Ctrl+C)"
|
||||||
{#if isSubmitting}
|
>
|
||||||
<span class="inline-block animate-spin">⏳</span>
|
<span class="font-bold">■</span> Stop
|
||||||
|
</button>
|
||||||
{:else}
|
{:else}
|
||||||
Send
|
<button
|
||||||
|
type="submit"
|
||||||
|
disabled={!isConnected || isSubmitting || !inputValue.trim()}
|
||||||
|
class="px-6 py-3 bg-[var(--accent-primary)] hover:bg-[var(--accent-secondary)]
|
||||||
|
text-white font-medium rounded-lg
|
||||||
|
disabled:opacity-50 disabled:cursor-not-allowed
|
||||||
|
transition-all duration-200 transform hover:scale-105 active:scale-95"
|
||||||
|
>
|
||||||
|
{#if isSubmitting}
|
||||||
|
<span class="inline-block animate-spin">⏳</span>
|
||||||
|
{:else}
|
||||||
|
Send
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
</button>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.input-bar {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-controls {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-row {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
align-items: flex-end;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -0,0 +1,157 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { MESSAGE_MODES, type MessageMode } from "$lib/types/messageMode";
|
||||||
|
import { messageMode } from "$lib/stores/messageMode";
|
||||||
|
|
||||||
|
let currentMode = $state("chat");
|
||||||
|
let isOpen = $state(false);
|
||||||
|
|
||||||
|
messageMode.subscribe((mode) => {
|
||||||
|
currentMode = mode;
|
||||||
|
});
|
||||||
|
|
||||||
|
let selectedMode = $derived(MESSAGE_MODES.find((m) => m.id === currentMode) || MESSAGE_MODES[0]);
|
||||||
|
|
||||||
|
function selectMode(mode: MessageMode) {
|
||||||
|
messageMode.set(mode.id);
|
||||||
|
isOpen = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleDropdown(event: MouseEvent) {
|
||||||
|
event.stopPropagation();
|
||||||
|
isOpen = !isOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close dropdown when clicking outside
|
||||||
|
function handleClickOutside() {
|
||||||
|
if (isOpen) {
|
||||||
|
isOpen = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:window onclick={handleClickOutside} />
|
||||||
|
|
||||||
|
<div class="mode-selector-container">
|
||||||
|
<button
|
||||||
|
class="mode-selector-button"
|
||||||
|
onclick={toggleDropdown}
|
||||||
|
title={`Current mode: ${selectedMode.name} - ${selectedMode.description}`}
|
||||||
|
>
|
||||||
|
<span class="mode-icon">{selectedMode.icon}</span>
|
||||||
|
<span class="mode-name">{selectedMode.name}</span>
|
||||||
|
<svg class="dropdown-arrow" class:open={isOpen} width="12" height="12" viewBox="0 0 12 12">
|
||||||
|
<path d="M3 4.5L6 7.5L9 4.5" stroke="currentColor" stroke-width="1.5" fill="none" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{#if isOpen}
|
||||||
|
<div class="dropdown-menu">
|
||||||
|
{#each MESSAGE_MODES as mode (mode.id)}
|
||||||
|
<button
|
||||||
|
class="dropdown-item"
|
||||||
|
class:active={mode.id === currentMode}
|
||||||
|
onclick={() => selectMode(mode)}
|
||||||
|
>
|
||||||
|
<span class="mode-icon">{mode.icon}</span>
|
||||||
|
<div class="mode-info">
|
||||||
|
<div class="mode-name">{mode.name}</div>
|
||||||
|
<div class="mode-description">{mode.description}</div>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.mode-selector-container {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-selector-button {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 8px 16px;
|
||||||
|
background: var(--bg-secondary);
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 8px;
|
||||||
|
color: var(--text-primary);
|
||||||
|
font-size: 14px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-selector-button:hover {
|
||||||
|
background: var(--bg-hover);
|
||||||
|
border-color: var(--accent-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-icon {
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-name {
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-arrow {
|
||||||
|
margin-left: 4px;
|
||||||
|
transition: transform 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-arrow.open {
|
||||||
|
transform: rotate(180deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-menu {
|
||||||
|
position: absolute;
|
||||||
|
bottom: calc(100% + 4px);
|
||||||
|
left: 0;
|
||||||
|
min-width: 280px;
|
||||||
|
background: var(--bg-secondary);
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
||||||
|
z-index: 1000;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
width: 100%;
|
||||||
|
padding: 12px 16px;
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
color: var(--text-primary);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background 0.2s;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-item:hover {
|
||||||
|
background: var(--bg-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-item.active {
|
||||||
|
background: var(--accent-primary);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-info {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-item .mode-name {
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 14px;
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-description {
|
||||||
|
font-size: 12px;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
import { notificationManager } from "$lib/notifications/notificationManager";
|
||||||
|
|
||||||
|
let results: { method: string; success: boolean; error?: string }[] = [];
|
||||||
|
let testing = false;
|
||||||
|
|
||||||
|
async function testNotificationMethod(method: string, invokeCommand: string) {
|
||||||
|
try {
|
||||||
|
await invoke(invokeCommand, {
|
||||||
|
title: "Hikari Test",
|
||||||
|
body: `Testing ${method} notification method`,
|
||||||
|
});
|
||||||
|
return { method, success: true };
|
||||||
|
} catch (error) {
|
||||||
|
return { method, success: false, error: String(error) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function testAllMethods() {
|
||||||
|
testing = true;
|
||||||
|
results = [];
|
||||||
|
|
||||||
|
const methods = [
|
||||||
|
{ name: "WSL Toast (System Tray)", command: "send_wsl_notification" },
|
||||||
|
{ name: "VBScript (Popup Dialog)", command: "send_vbs_notification" },
|
||||||
|
{ name: "Notify-send (Linux)", command: "send_notify_send" },
|
||||||
|
{ name: "Windows PowerShell", command: "send_windows_notification" },
|
||||||
|
{ name: "Simple Message (Dialog)", command: "send_simple_notification" },
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const method of methods) {
|
||||||
|
const result = await testNotificationMethod(method.name, method.command);
|
||||||
|
results = [...results, result];
|
||||||
|
// Wait a bit between tests
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||||
|
}
|
||||||
|
|
||||||
|
testing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function testIntegratedNotification() {
|
||||||
|
await notificationManager.notifySuccess("Integrated notification test!");
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="notification-debugger">
|
||||||
|
<h3>Notification Method Debugger</h3>
|
||||||
|
|
||||||
|
<div class="test-buttons">
|
||||||
|
<button on:click={testAllMethods} disabled={testing}>
|
||||||
|
{testing ? "Testing..." : "Test All Methods"}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button on:click={testIntegratedNotification}> Test Integrated Notification </button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if results.length > 0}
|
||||||
|
<div class="results">
|
||||||
|
<h4>Test Results:</h4>
|
||||||
|
{#each results as result (result.method)}
|
||||||
|
<div class="result" class:success={result.success} class:failed={!result.success}>
|
||||||
|
<span class="method">{result.method}:</span>
|
||||||
|
<span class="status">{result.success ? "✓ Success" : "✗ Failed"}</span>
|
||||||
|
{#if result.error}
|
||||||
|
<div class="error">{result.error}</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.notification-debugger {
|
||||||
|
padding: 1rem;
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
margin: 1rem;
|
||||||
|
background: var(--bg-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
h3,
|
||||||
|
h4 {
|
||||||
|
margin-top: 0;
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.test-buttons {
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
margin: 1rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
background: var(--accent-color);
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: opacity 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:hover:not(:disabled) {
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.results {
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.result {
|
||||||
|
padding: 0.5rem;
|
||||||
|
margin: 0.25rem 0;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.result.success {
|
||||||
|
background: rgba(0, 255, 0, 0.1);
|
||||||
|
border: 1px solid rgba(0, 255, 0, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.result.failed {
|
||||||
|
background: rgba(255, 0, 0, 0.1);
|
||||||
|
border: 1px solid rgba(255, 0, 0, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.method {
|
||||||
|
font-weight: bold;
|
||||||
|
min-width: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
width: 100%;
|
||||||
|
margin-top: 0.25rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
color: var(--error-color);
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
import { get } from "svelte/store";
|
||||||
import { claudeStore, hasPermissionPending } from "$lib/stores/claude";
|
import { claudeStore, hasPermissionPending } from "$lib/stores/claude";
|
||||||
import { characterState } from "$lib/stores/character";
|
import { characterState } from "$lib/stores/character";
|
||||||
import type { PermissionRequest } from "$lib/types/messages";
|
import type { PermissionRequest } from "$lib/types/messages";
|
||||||
@@ -45,14 +46,22 @@
|
|||||||
|
|
||||||
// Stop current session and reconnect with new permissions
|
// Stop current session and reconnect with new permissions
|
||||||
try {
|
try {
|
||||||
await invoke("stop_claude");
|
const conversationId = get(claudeStore.activeConversationId);
|
||||||
|
if (!conversationId) {
|
||||||
|
throw new Error("No active conversation");
|
||||||
|
}
|
||||||
|
|
||||||
|
await invoke("stop_claude", { conversationId });
|
||||||
|
|
||||||
// Small delay to ensure clean shutdown
|
// Small delay to ensure clean shutdown
|
||||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||||
|
|
||||||
await invoke("start_claude", {
|
await invoke("start_claude", {
|
||||||
workingDir: workingDirectory || "/home/naomi",
|
conversationId,
|
||||||
allowedTools: newGrantedTools,
|
options: {
|
||||||
|
working_dir: workingDirectory || "/home/naomi",
|
||||||
|
allowed_tools: newGrantedTools,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Wait for connection to establish
|
// Wait for connection to establish
|
||||||
@@ -70,7 +79,10 @@ ${JSON.stringify(toolInput, null, 2)}
|
|||||||
|
|
||||||
Please continue where we left off and retry that action now that you have permission.`;
|
Please continue where we left off and retry that action now that you have permission.`;
|
||||||
|
|
||||||
await invoke("send_prompt", { message: contextMessage });
|
await invoke("send_prompt", {
|
||||||
|
conversationId,
|
||||||
|
message: contextMessage,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to reconnect:", error);
|
console.error("Failed to reconnect:", error);
|
||||||
|
|||||||
@@ -0,0 +1,168 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { formattedStats } from "$lib/stores/stats";
|
||||||
|
import { fade } from "svelte/transition";
|
||||||
|
|
||||||
|
let showToolsBreakdown = false;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="stats-display" transition:fade={{ duration: 200 }}>
|
||||||
|
<div class="stats-row">
|
||||||
|
<span class="stat-label">Duration:</span>
|
||||||
|
<span class="stat-value">{$formattedStats.sessionDuration}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="stats-row">
|
||||||
|
<span class="stat-label">Messages:</span>
|
||||||
|
<span class="stat-value">{$formattedStats.messagesSession}</span>
|
||||||
|
<span class="stat-secondary">/ {$formattedStats.messagesTotal}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="stats-section">
|
||||||
|
<h3>Tokens & Cost</h3>
|
||||||
|
<div class="stat-row">
|
||||||
|
<span class="stat-label">Session:</span>
|
||||||
|
<span class="stat-value">{$formattedStats.sessionTokens}</span>
|
||||||
|
<span class="stat-cost">{$formattedStats.sessionCost}</span>
|
||||||
|
</div>
|
||||||
|
<div class="stat-row stat-detail">
|
||||||
|
<span class="stat-label">Input:</span>
|
||||||
|
<span class="stat-value">{$formattedStats.sessionInputTokens}</span>
|
||||||
|
</div>
|
||||||
|
<div class="stat-row stat-detail">
|
||||||
|
<span class="stat-label">Output:</span>
|
||||||
|
<span class="stat-value">{$formattedStats.sessionOutputTokens}</span>
|
||||||
|
</div>
|
||||||
|
<div class="stat-row stat-highlight">
|
||||||
|
<span class="stat-label">Total:</span>
|
||||||
|
<span class="stat-value">{$formattedStats.totalTokens}</span>
|
||||||
|
<span class="stat-cost">{$formattedStats.totalCost}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="stats-section">
|
||||||
|
<h3>Activity</h3>
|
||||||
|
<div class="stat-row">
|
||||||
|
<span class="stat-label">Code blocks:</span>
|
||||||
|
<span class="stat-value">{$formattedStats.codeBlocksSession}</span>
|
||||||
|
<span class="stat-secondary">/ {$formattedStats.codeBlocksTotal}</span>
|
||||||
|
</div>
|
||||||
|
<div class="stat-row">
|
||||||
|
<span class="stat-label">Files edited:</span>
|
||||||
|
<span class="stat-value">{$formattedStats.filesEditedSession}</span>
|
||||||
|
<span class="stat-secondary">/ {$formattedStats.filesEditedTotal}</span>
|
||||||
|
</div>
|
||||||
|
<div class="stat-row">
|
||||||
|
<span class="stat-label">Files created:</span>
|
||||||
|
<span class="stat-value">{$formattedStats.filesCreatedSession}</span>
|
||||||
|
<span class="stat-secondary">/ {$formattedStats.filesCreatedTotal}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if Object.keys($formattedStats.sessionToolsUsage).length > 0}
|
||||||
|
<div class="stats-section">
|
||||||
|
<h3 class="tools-header">
|
||||||
|
<button class="tools-toggle" onclick={() => (showToolsBreakdown = !showToolsBreakdown)}>
|
||||||
|
Tools Used
|
||||||
|
<span class="toggle-icon">{showToolsBreakdown ? "▼" : "▶"}</span>
|
||||||
|
</button>
|
||||||
|
</h3>
|
||||||
|
{#if showToolsBreakdown}
|
||||||
|
<div class="tools-breakdown">
|
||||||
|
{#each Object.entries($formattedStats.sessionToolsUsage).sort((a, b) => b[1] - a[1]) as [tool, count] (tool)}
|
||||||
|
<div class="stat-row stat-detail">
|
||||||
|
<span class="stat-label">{tool}:</span>
|
||||||
|
<span class="stat-value">{count}</span>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div class="model-info">
|
||||||
|
<span class="model-label">Model:</span>
|
||||||
|
<span class="model-value">{$formattedStats.model}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.stats-display {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
padding: 0.75rem;
|
||||||
|
background: var(--bg-secondary);
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 8px;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
box-shadow:
|
||||||
|
0 4px 6px rgba(0, 0, 0, 0.1),
|
||||||
|
0 1px 3px rgba(0, 0, 0, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-section {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-section h3 {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--text-primary);
|
||||||
|
margin: 0 0 0.25rem 0;
|
||||||
|
padding-bottom: 0.25rem;
|
||||||
|
border-bottom: 1px solid var(--border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-row {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0.125rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-detail {
|
||||||
|
margin-left: 1rem;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-highlight {
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--accent-primary);
|
||||||
|
margin-top: 0.25rem;
|
||||||
|
padding-top: 0.25rem;
|
||||||
|
border-top: 1px solid var(--border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-label {
|
||||||
|
color: var(--text-secondary, #9ca3af);
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-value {
|
||||||
|
font-family: var(--font-mono, monospace);
|
||||||
|
color: var(--text-primary, #e5e7eb);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-info {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0.5rem;
|
||||||
|
background: var(--bg-primary);
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-label {
|
||||||
|
color: var(--text-secondary, #9ca3af);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-value {
|
||||||
|
font-family: var(--font-mono, monospace);
|
||||||
|
color: var(--text-primary, #e5e7eb);
|
||||||
|
font-size: 0.75rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,14 +1,26 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
interface Props {
|
||||||
|
onToggleAchievements?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { onToggleAchievements = () => {} }: Props = $props();
|
||||||
|
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import { getVersion } from "@tauri-apps/api/app";
|
import { getVersion } from "@tauri-apps/api/app";
|
||||||
import { open } from "@tauri-apps/plugin-dialog";
|
import { open } from "@tauri-apps/plugin-dialog";
|
||||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
import { openUrl } from "@tauri-apps/plugin-opener";
|
||||||
|
import { get } from "svelte/store";
|
||||||
import { claudeStore } from "$lib/stores/claude";
|
import { claudeStore } from "$lib/stores/claude";
|
||||||
import { configStore, type HikariConfig } from "$lib/stores/config";
|
import { configStore, type HikariConfig } from "$lib/stores/config";
|
||||||
import type { ConnectionStatus } from "$lib/types/messages";
|
import type { ConnectionStatus } from "$lib/types/messages";
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
|
import StatsDisplay from "./StatsDisplay.svelte";
|
||||||
|
import AboutPanel from "./AboutPanel.svelte";
|
||||||
|
import HelpPanel from "./HelpPanel.svelte";
|
||||||
|
import { achievementProgress } from "$lib/stores/achievements";
|
||||||
|
|
||||||
const DISCORD_URL = "https://chat.nhcarrigan.com";
|
const DISCORD_URL = "https://chat.nhcarrigan.com";
|
||||||
|
const DONATE_URL = "https://donate.nhcarrigan.com";
|
||||||
|
|
||||||
let connectionStatus: ConnectionStatus = $state("disconnected");
|
let connectionStatus: ConnectionStatus = $state("disconnected");
|
||||||
let workingDirectory = $state("");
|
let workingDirectory = $state("");
|
||||||
@@ -16,6 +28,10 @@
|
|||||||
let isConnecting = $state(false);
|
let isConnecting = $state(false);
|
||||||
let grantedToolsList: string[] = $state([]);
|
let grantedToolsList: string[] = $state([]);
|
||||||
let appVersion = $state("");
|
let appVersion = $state("");
|
||||||
|
let showStats = $state(false);
|
||||||
|
let showAbout = $state(false);
|
||||||
|
let showHelp = $state(false);
|
||||||
|
const progress = $derived($achievementProgress);
|
||||||
let currentConfig: HikariConfig = $state({
|
let currentConfig: HikariConfig = $state({
|
||||||
model: null,
|
model: null,
|
||||||
api_key: null,
|
api_key: null,
|
||||||
@@ -23,6 +39,10 @@
|
|||||||
mcp_servers_json: null,
|
mcp_servers_json: null,
|
||||||
auto_granted_tools: [],
|
auto_granted_tools: [],
|
||||||
theme: "dark",
|
theme: "dark",
|
||||||
|
greeting_enabled: true,
|
||||||
|
greeting_custom_prompt: null,
|
||||||
|
notifications_enabled: true,
|
||||||
|
notification_volume: 0.5,
|
||||||
});
|
});
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
@@ -73,7 +93,12 @@
|
|||||||
];
|
];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const conversationId = get(claudeStore.activeConversationId);
|
||||||
|
if (!conversationId) {
|
||||||
|
throw new Error("No active conversation");
|
||||||
|
}
|
||||||
await invoke("start_claude", {
|
await invoke("start_claude", {
|
||||||
|
conversationId,
|
||||||
options: {
|
options: {
|
||||||
working_dir: targetDir,
|
working_dir: targetDir,
|
||||||
model: currentConfig.model || null,
|
model: currentConfig.model || null,
|
||||||
@@ -91,7 +116,11 @@
|
|||||||
|
|
||||||
async function handleDisconnect() {
|
async function handleDisconnect() {
|
||||||
try {
|
try {
|
||||||
await invoke("stop_claude");
|
const conversationId = get(claudeStore.activeConversationId);
|
||||||
|
if (!conversationId) {
|
||||||
|
throw new Error("No active conversation");
|
||||||
|
}
|
||||||
|
await invoke("stop_claude", { conversationId });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to stop Claude:", error);
|
console.error("Failed to stop Claude:", error);
|
||||||
}
|
}
|
||||||
@@ -122,6 +151,10 @@
|
|||||||
return "Disconnected";
|
return "Disconnected";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggleAchievements() {
|
||||||
|
onToggleAchievements();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
@@ -163,6 +196,36 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex items-center gap-3">
|
<div class="flex items-center gap-3">
|
||||||
|
<button
|
||||||
|
onclick={toggleAchievements}
|
||||||
|
class="p-1 text-gray-500 hover:text-[var(--accent-primary)] transition-colors relative"
|
||||||
|
title="Achievements"
|
||||||
|
>
|
||||||
|
<span class="text-lg">🏆</span>
|
||||||
|
{#if progress.unlocked > 0}
|
||||||
|
<span
|
||||||
|
class="absolute -top-1 -right-1 bg-[var(--accent-primary)] text-white text-xs rounded-full w-4 h-4 flex items-center justify-center text-[10px]"
|
||||||
|
>
|
||||||
|
{progress.unlocked}
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onclick={() => (showStats = !showStats)}
|
||||||
|
class="p-1 text-gray-500 hover:text-[var(--accent-primary)] transition-colors {showStats
|
||||||
|
? 'text-[var(--accent-primary)]'
|
||||||
|
: ''}"
|
||||||
|
title="Usage Stats"
|
||||||
|
>
|
||||||
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
stroke-width="2"
|
||||||
|
d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zM13 19v-4a2 2 0 00-2-2H9a2 2 0 00-2 2v4a2 2 0 002 2h2a2 2 0 002-2zM21 19V8a2 2 0 00-2-2h-2a2 2 0 00-2 2v11a2 2 0 002 2h2a2 2 0 002-2z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
onclick={configStore.openSidebar}
|
onclick={configStore.openSidebar}
|
||||||
class="p-1 text-gray-500 hover:text-[var(--accent-primary)] transition-colors"
|
class="p-1 text-gray-500 hover:text-[var(--accent-primary)] transition-colors"
|
||||||
@@ -183,6 +246,45 @@
|
|||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
onclick={() => openUrl(DONATE_URL)}
|
||||||
|
class="p-1 text-gray-500 hover:text-[var(--accent-primary)] transition-colors"
|
||||||
|
title="Support our work"
|
||||||
|
>
|
||||||
|
<svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path
|
||||||
|
d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onclick={() => (showAbout = true)}
|
||||||
|
class="p-1 text-gray-500 hover:text-[var(--accent-primary)] transition-colors"
|
||||||
|
title="About Hikari Desktop"
|
||||||
|
>
|
||||||
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
stroke-width="2"
|
||||||
|
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onclick={() => (showHelp = true)}
|
||||||
|
class="p-1 text-gray-500 hover:text-[var(--accent-primary)] transition-colors"
|
||||||
|
title="Help"
|
||||||
|
>
|
||||||
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
stroke-width="2"
|
||||||
|
d="M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
onclick={() => openUrl(DISCORD_URL)}
|
onclick={() => openUrl(DISCORD_URL)}
|
||||||
class="p-1 text-gray-500 hover:text-[var(--accent-primary)] transition-colors"
|
class="p-1 text-gray-500 hover:text-[var(--accent-primary)] transition-colors"
|
||||||
@@ -197,6 +299,12 @@
|
|||||||
{#if appVersion}
|
{#if appVersion}
|
||||||
<span class="text-xs text-gray-600">v{appVersion}</span>
|
<span class="text-xs text-gray-600">v{appVersion}</span>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
{#if showStats}
|
||||||
|
<div class="absolute top-full right-0 mt-2 mr-4 z-50">
|
||||||
|
<StatsDisplay />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
{#if connectionStatus === "connected"}
|
{#if connectionStatus === "connected"}
|
||||||
<button
|
<button
|
||||||
onclick={handleDisconnect}
|
onclick={handleDisconnect}
|
||||||
@@ -215,3 +323,20 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#if showStats}
|
||||||
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||||
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||||
|
<div class="fixed inset-0 z-40" onclick={() => (showStats = false)}></div>
|
||||||
|
<div class="fixed top-14 right-4 z-50">
|
||||||
|
<StatsDisplay />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if showAbout}
|
||||||
|
<AboutPanel onClose={() => (showAbout = false)} />
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if showHelp}
|
||||||
|
<HelpPanel onClose={() => (showHelp = false)} />
|
||||||
|
{/if}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { claudeStore, type TerminalLine } from "$lib/stores/claude";
|
import { claudeStore, type TerminalLine } from "$lib/stores/claude";
|
||||||
import { afterUpdate } from "svelte";
|
import { afterUpdate } from "svelte";
|
||||||
|
import ConversationTabs from "./ConversationTabs.svelte";
|
||||||
|
|
||||||
let terminalElement: HTMLDivElement;
|
let terminalElement: HTMLDivElement;
|
||||||
let shouldAutoScroll = true;
|
let shouldAutoScroll = true;
|
||||||
@@ -25,17 +26,17 @@
|
|||||||
function getLineClass(type: string): string {
|
function getLineClass(type: string): string {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "user":
|
case "user":
|
||||||
return "text-cyan-400";
|
return "terminal-user";
|
||||||
case "assistant":
|
case "assistant":
|
||||||
return "text-gray-100";
|
return "terminal-assistant";
|
||||||
case "system":
|
case "system":
|
||||||
return "text-gray-500 italic";
|
return "terminal-system italic";
|
||||||
case "tool":
|
case "tool":
|
||||||
return "text-purple-400";
|
return "terminal-tool";
|
||||||
case "error":
|
case "error":
|
||||||
return "text-red-400";
|
return "terminal-error";
|
||||||
default:
|
default:
|
||||||
return "text-gray-300";
|
return "terminal-default";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,25 +76,29 @@
|
|||||||
<div class="w-3 h-3 rounded-full bg-yellow-500"></div>
|
<div class="w-3 h-3 rounded-full bg-yellow-500"></div>
|
||||||
<div class="w-3 h-3 rounded-full bg-green-500"></div>
|
<div class="w-3 h-3 rounded-full bg-green-500"></div>
|
||||||
</div>
|
</div>
|
||||||
<span class="text-sm text-gray-400 ml-2">Terminal</span>
|
<span class="text-sm terminal-header-text ml-2">Terminal</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<ConversationTabs />
|
||||||
|
|
||||||
<div
|
<div
|
||||||
bind:this={terminalElement}
|
bind:this={terminalElement}
|
||||||
onscroll={handleScroll}
|
onscroll={handleScroll}
|
||||||
class="terminal-content h-[calc(100%-40px)] overflow-y-auto p-4 font-mono text-sm"
|
class="terminal-content h-[calc(100%-76px)] overflow-y-auto p-4 font-mono text-sm"
|
||||||
>
|
>
|
||||||
{#if lines.length === 0}
|
{#if lines.length === 0}
|
||||||
<div class="text-gray-500 italic">Waiting for Claude... Type a message below to start!</div>
|
<div class="terminal-waiting italic">
|
||||||
|
Waiting for Claude... Type a message below to start!
|
||||||
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
{#each lines as line (line.id)}
|
{#each lines as line (line.id)}
|
||||||
<div class="terminal-line mb-2 {getLineClass(line.type)}">
|
<div class="terminal-line mb-2 {getLineClass(line.type)}">
|
||||||
<span class="text-gray-600 text-xs mr-2">{formatTime(line.timestamp)}</span>
|
<span class="terminal-timestamp text-xs mr-2">{formatTime(line.timestamp)}</span>
|
||||||
{#if getLinePrefix(line.type)}
|
{#if getLinePrefix(line.type)}
|
||||||
<span class="text-gray-500 mr-2">{getLinePrefix(line.type)}</span>
|
<span class="terminal-prefix mr-2">{getLinePrefix(line.type)}</span>
|
||||||
{/if}
|
{/if}
|
||||||
{#if line.toolName}
|
{#if line.toolName}
|
||||||
<span class="text-purple-300 mr-2">[{line.toolName}]</span>
|
<span class="terminal-tool-name mr-2">[{line.toolName}]</span>
|
||||||
{/if}
|
{/if}
|
||||||
<span class="whitespace-pre-wrap">{line.content}</span>
|
<span class="whitespace-pre-wrap">{line.content}</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -107,4 +112,49 @@
|
|||||||
scrollbar-width: thin;
|
scrollbar-width: thin;
|
||||||
scrollbar-color: var(--border-color) var(--bg-terminal);
|
scrollbar-color: var(--border-color) var(--bg-terminal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Terminal text colors that adapt to theme */
|
||||||
|
.terminal-user {
|
||||||
|
color: var(--terminal-user, #22d3ee);
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-assistant {
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-system {
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-tool {
|
||||||
|
color: var(--terminal-tool, #c084fc);
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-error {
|
||||||
|
color: var(--terminal-error, #f87171);
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-default {
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-timestamp {
|
||||||
|
color: var(--text-tertiary, #6b7280);
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-prefix {
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-tool-name {
|
||||||
|
color: var(--terminal-tool-name, #ddd6fe);
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-waiting {
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-header-text {
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export * from "./types";
|
||||||
|
export { soundPlayer } from "./soundPlayer";
|
||||||
|
export { notificationManager } from "./notificationManager";
|
||||||
|
export { initializeNotificationRules } from "./rules";
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
import { soundPlayer } from "./soundPlayer";
|
||||||
|
import { NotificationType, NOTIFICATION_SOUNDS } from "./types";
|
||||||
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
import { sendTerminalNotification } from "./terminalNotifier";
|
||||||
|
|
||||||
|
class NotificationManager {
|
||||||
|
async notify(type: NotificationType, message?: string): Promise<void> {
|
||||||
|
// Always play sound (if enabled)
|
||||||
|
await soundPlayer.play(type);
|
||||||
|
|
||||||
|
const sound = NOTIFICATION_SOUNDS[type];
|
||||||
|
const title = sound.phrase;
|
||||||
|
const body = message || this.getDefaultMessage(type);
|
||||||
|
|
||||||
|
// Try multiple notification methods in order
|
||||||
|
const notificationMethods = [
|
||||||
|
// Method 1: Try Windows PowerShell (best for system tray notifications)
|
||||||
|
async () => {
|
||||||
|
console.log("Trying Windows PowerShell notifications...");
|
||||||
|
await invoke("send_windows_notification", { title, body });
|
||||||
|
},
|
||||||
|
|
||||||
|
// Method 2: Try native Windows toast (for Windows builds)
|
||||||
|
async () => {
|
||||||
|
console.log("Trying native Windows toast...");
|
||||||
|
await invoke("send_windows_toast", { title, body });
|
||||||
|
},
|
||||||
|
|
||||||
|
// Method 3: Try WSL-specific notification (Windows toast via PowerShell - for WSL)
|
||||||
|
async () => {
|
||||||
|
console.log("Trying WSL notification...");
|
||||||
|
await invoke("send_wsl_notification", { title, body });
|
||||||
|
},
|
||||||
|
|
||||||
|
// Method 4: Try native Tauri notifications
|
||||||
|
async () => {
|
||||||
|
console.log("Trying Tauri native notifications...");
|
||||||
|
const { sendNotification, isPermissionGranted, requestPermission } =
|
||||||
|
await import("@tauri-apps/plugin-notification");
|
||||||
|
|
||||||
|
let hasPermission = await isPermissionGranted();
|
||||||
|
if (!hasPermission) {
|
||||||
|
const permission = await requestPermission();
|
||||||
|
hasPermission = permission === "granted";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasPermission) {
|
||||||
|
await sendNotification({ title, body });
|
||||||
|
} else {
|
||||||
|
throw new Error("Notification permission denied");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Method 5: Try notify-send (for native Linux)
|
||||||
|
async () => {
|
||||||
|
console.log("Trying notify-send...");
|
||||||
|
await invoke("send_notify_send", { title, body });
|
||||||
|
},
|
||||||
|
|
||||||
|
// Skip VBScript and simple message as they create popup dialogs
|
||||||
|
// Only use them in the debugger for testing
|
||||||
|
];
|
||||||
|
|
||||||
|
// Try each method until one succeeds
|
||||||
|
for (const method of notificationMethods) {
|
||||||
|
try {
|
||||||
|
await method();
|
||||||
|
console.log("Notification sent successfully");
|
||||||
|
return; // Success, stop trying other methods
|
||||||
|
} catch (error) {
|
||||||
|
console.warn("Notification method failed:", error);
|
||||||
|
// Continue to next method
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.error("All notification methods failed, using terminal notification");
|
||||||
|
// Final fallback: Show in terminal
|
||||||
|
sendTerminalNotification(type, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
private getDefaultMessage(type: NotificationType): string {
|
||||||
|
switch (type) {
|
||||||
|
case NotificationType.SUCCESS:
|
||||||
|
return "Task completed successfully!";
|
||||||
|
case NotificationType.ERROR:
|
||||||
|
return "Something went wrong...";
|
||||||
|
case NotificationType.PERMISSION:
|
||||||
|
return "Permission needed to continue";
|
||||||
|
case NotificationType.CONNECTION:
|
||||||
|
return "Successfully connected to Claude Code";
|
||||||
|
case NotificationType.TASK_START:
|
||||||
|
return "Starting task...";
|
||||||
|
default:
|
||||||
|
return "Notification";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper methods for common notifications
|
||||||
|
async notifySuccess(message?: string): Promise<void> {
|
||||||
|
await this.notify(NotificationType.SUCCESS, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
async notifyError(message?: string): Promise<void> {
|
||||||
|
await this.notify(NotificationType.ERROR, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
async notifyPermission(message?: string): Promise<void> {
|
||||||
|
await this.notify(NotificationType.PERMISSION, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
async notifyConnection(message?: string): Promise<void> {
|
||||||
|
await this.notify(NotificationType.CONNECTION, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
async notifyTaskStart(message?: string): Promise<void> {
|
||||||
|
await this.notify(NotificationType.TASK_START, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export singleton instance
|
||||||
|
export const notificationManager = new NotificationManager();
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
import { characterState } from "$lib/stores/character";
|
||||||
|
import { notificationManager } from "./notificationManager";
|
||||||
|
import type { CharacterState } from "$lib/types/states";
|
||||||
|
import type { ConnectionStatus } from "$lib/types/messages";
|
||||||
|
|
||||||
|
// Track previous states to detect transitions
|
||||||
|
let previousCharacterState: CharacterState | null = null;
|
||||||
|
let previousConnectionStatus: ConnectionStatus | null = null;
|
||||||
|
let taskStartTime: number | null = null;
|
||||||
|
let hasNotifiedTaskStart = false;
|
||||||
|
|
||||||
|
export function handleCharacterStateChange(newState: CharacterState): void {
|
||||||
|
// Detect state transitions
|
||||||
|
if (previousCharacterState === newState) return;
|
||||||
|
|
||||||
|
// Task completion: any state -> success
|
||||||
|
if (newState === "success" && previousCharacterState !== null) {
|
||||||
|
const taskDuration = taskStartTime ? Date.now() - taskStartTime : 0;
|
||||||
|
// Only notify for tasks that took more than 2 seconds
|
||||||
|
if (taskDuration > 2000) {
|
||||||
|
notificationManager.notifySuccess();
|
||||||
|
}
|
||||||
|
taskStartTime = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error occurred
|
||||||
|
if (newState === "error" && previousCharacterState !== "error") {
|
||||||
|
notificationManager.notifyError();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Permission needed
|
||||||
|
if (newState === "permission") {
|
||||||
|
notificationManager.notifyPermission();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Starting long tasks - only notify once per response
|
||||||
|
if (
|
||||||
|
(newState === "coding" || newState === "searching") &&
|
||||||
|
previousCharacterState !== "coding" &&
|
||||||
|
previousCharacterState !== "searching" &&
|
||||||
|
!hasNotifiedTaskStart
|
||||||
|
) {
|
||||||
|
taskStartTime = Date.now();
|
||||||
|
hasNotifiedTaskStart = true;
|
||||||
|
notificationManager.notifyTaskStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
previousCharacterState = newState;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function handleConnectionStatusChange(newStatus: ConnectionStatus): void {
|
||||||
|
// Only notify on successful connection after being disconnected
|
||||||
|
if (
|
||||||
|
newStatus === "connected" &&
|
||||||
|
previousConnectionStatus &&
|
||||||
|
previousConnectionStatus !== "connected"
|
||||||
|
) {
|
||||||
|
notificationManager.notifyConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
previousConnectionStatus = newStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
export function handleToolExecution(_toolName: string): void {
|
||||||
|
// For now, we don't notify on every tool execution
|
||||||
|
// But we could add specific rules here if needed
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset notification state for a new response
|
||||||
|
export function handleNewUserMessage(): void {
|
||||||
|
hasNotifiedTaskStart = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store unsubscribe functions
|
||||||
|
let unsubscribeCharacterState: (() => void) | null = null;
|
||||||
|
|
||||||
|
// Initialize listeners
|
||||||
|
export function initializeNotificationRules(): void {
|
||||||
|
// Clean up any existing subscriptions first
|
||||||
|
cleanupNotificationRules();
|
||||||
|
|
||||||
|
// Subscribe to character state changes
|
||||||
|
unsubscribeCharacterState = characterState.subscribe((state) => {
|
||||||
|
handleCharacterStateChange(state);
|
||||||
|
});
|
||||||
|
|
||||||
|
// We'll connect to connection status in the next step
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup function to prevent duplicate listeners
|
||||||
|
export function cleanupNotificationRules(): void {
|
||||||
|
if (unsubscribeCharacterState) {
|
||||||
|
unsubscribeCharacterState();
|
||||||
|
unsubscribeCharacterState = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset state tracking
|
||||||
|
previousCharacterState = null;
|
||||||
|
previousConnectionStatus = null;
|
||||||
|
taskStartTime = null;
|
||||||
|
hasNotifiedTaskStart = false;
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import { NOTIFICATION_SOUNDS, type NotificationType } from "./types";
|
||||||
|
|
||||||
|
class SoundPlayer {
|
||||||
|
private audioCache: Map<NotificationType, HTMLAudioElement> = new Map();
|
||||||
|
private enabled: boolean = false; // Start disabled until config loads
|
||||||
|
private globalVolume: number = 1.0;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
// Preload all essential sounds
|
||||||
|
this.preloadSounds();
|
||||||
|
}
|
||||||
|
|
||||||
|
private preloadSounds(): void {
|
||||||
|
Object.entries(NOTIFICATION_SOUNDS).forEach(([type, sound]) => {
|
||||||
|
const audio = new Audio(`/sounds/${sound.filename}`);
|
||||||
|
audio.preload = "auto";
|
||||||
|
audio.volume = (sound.volume || 0.7) * this.globalVolume;
|
||||||
|
this.audioCache.set(type as NotificationType, audio);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async play(type: NotificationType): Promise<void> {
|
||||||
|
if (!this.enabled) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const audio = this.audioCache.get(type);
|
||||||
|
if (!audio) {
|
||||||
|
console.warn(`No audio found for notification type: ${type}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone the audio to allow overlapping sounds
|
||||||
|
const audioClone = audio.cloneNode() as HTMLAudioElement;
|
||||||
|
audioClone.volume = audio.volume;
|
||||||
|
|
||||||
|
await audioClone.play();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to play notification sound:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setEnabled(enabled: boolean): void {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
setGlobalVolume(volume: number): void {
|
||||||
|
this.globalVolume = Math.max(0, Math.min(1, volume));
|
||||||
|
// Update all cached audio volumes
|
||||||
|
this.audioCache.forEach((audio, type) => {
|
||||||
|
const sound = NOTIFICATION_SOUNDS[type];
|
||||||
|
audio.volume = (sound.volume || 0.7) * this.globalVolume;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
isEnabled(): boolean {
|
||||||
|
return this.enabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export singleton instance
|
||||||
|
export const soundPlayer = new SoundPlayer();
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import { claudeStore } from "$lib/stores/claude";
|
||||||
|
import { NOTIFICATION_SOUNDS, type NotificationType } from "./types";
|
||||||
|
|
||||||
|
export function sendTerminalNotification(type: NotificationType, message?: string): void {
|
||||||
|
const sound = NOTIFICATION_SOUNDS[type];
|
||||||
|
const title = sound.phrase;
|
||||||
|
|
||||||
|
// Create a formatted notification message
|
||||||
|
const separator = "═".repeat(50);
|
||||||
|
const timestamp = new Date().toLocaleTimeString();
|
||||||
|
|
||||||
|
let emoji = "";
|
||||||
|
let color = "";
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case "success":
|
||||||
|
emoji = "✨";
|
||||||
|
color = "\x1b[32m"; // Green
|
||||||
|
break;
|
||||||
|
case "error":
|
||||||
|
emoji = "❌";
|
||||||
|
color = "\x1b[31m"; // Red
|
||||||
|
break;
|
||||||
|
case "permission":
|
||||||
|
emoji = "🔐";
|
||||||
|
color = "\x1b[33m"; // Yellow
|
||||||
|
break;
|
||||||
|
case "connection":
|
||||||
|
emoji = "🔗";
|
||||||
|
color = "\x1b[36m"; // Cyan
|
||||||
|
break;
|
||||||
|
case "task_start":
|
||||||
|
emoji = "🚀";
|
||||||
|
color = "\x1b[34m"; // Blue
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const reset = "\x1b[0m";
|
||||||
|
|
||||||
|
// Format the notification
|
||||||
|
const notification = `
|
||||||
|
${color}${separator}${reset}
|
||||||
|
${emoji} ${color}NOTIFICATION${reset} - ${timestamp}
|
||||||
|
${color}${title}${reset}
|
||||||
|
${message || ""}
|
||||||
|
${color}${separator}${reset}`;
|
||||||
|
|
||||||
|
// Add to terminal as a special system message
|
||||||
|
claudeStore.addLine("system", notification);
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { notificationManager } from "./notificationManager";
|
||||||
|
|
||||||
|
// Test function to trigger each notification type
|
||||||
|
export async function testAllNotifications() {
|
||||||
|
console.log("Testing all notification types...");
|
||||||
|
|
||||||
|
// Test success notification
|
||||||
|
setTimeout(async () => {
|
||||||
|
console.log("Testing SUCCESS notification");
|
||||||
|
await notificationManager.notifySuccess("Test task completed!");
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
// Test error notification
|
||||||
|
setTimeout(async () => {
|
||||||
|
console.log("Testing ERROR notification");
|
||||||
|
await notificationManager.notifyError("Test error occurred!");
|
||||||
|
}, 3000);
|
||||||
|
|
||||||
|
// Test permission notification
|
||||||
|
setTimeout(async () => {
|
||||||
|
console.log("Testing PERMISSION notification");
|
||||||
|
await notificationManager.notifyPermission("Test permission request!");
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
|
// Test connection notification
|
||||||
|
setTimeout(async () => {
|
||||||
|
console.log("Testing CONNECTION notification");
|
||||||
|
await notificationManager.notifyConnection("Test connection established!");
|
||||||
|
}, 7000);
|
||||||
|
|
||||||
|
// Test task start notification
|
||||||
|
setTimeout(async () => {
|
||||||
|
console.log("Testing TASK_START notification");
|
||||||
|
await notificationManager.notifyTaskStart("Test task starting!");
|
||||||
|
}, 9000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make it available on window for easy testing
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
(window as unknown as { testNotifications: typeof testAllNotifications }).testNotifications =
|
||||||
|
testAllNotifications;
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
export enum NotificationType {
|
||||||
|
SUCCESS = "success",
|
||||||
|
ERROR = "error",
|
||||||
|
PERMISSION = "permission",
|
||||||
|
CONNECTION = "connection",
|
||||||
|
TASK_START = "task_start",
|
||||||
|
ACHIEVEMENT = "achievement",
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NotificationSound {
|
||||||
|
type: NotificationType;
|
||||||
|
filename: string;
|
||||||
|
phrase: string;
|
||||||
|
volume?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Essential notification sounds mapping
|
||||||
|
export const NOTIFICATION_SOUNDS: Record<NotificationType, NotificationSound> = {
|
||||||
|
[NotificationType.SUCCESS]: {
|
||||||
|
type: NotificationType.SUCCESS,
|
||||||
|
filename: "im-done.mp3",
|
||||||
|
phrase: "I'm done!",
|
||||||
|
volume: 0.7,
|
||||||
|
},
|
||||||
|
[NotificationType.ERROR]: {
|
||||||
|
type: NotificationType.ERROR,
|
||||||
|
filename: "oh-no.mp3",
|
||||||
|
phrase: "Oh no...",
|
||||||
|
volume: 0.8,
|
||||||
|
},
|
||||||
|
[NotificationType.PERMISSION]: {
|
||||||
|
type: NotificationType.PERMISSION,
|
||||||
|
filename: "access-please.mp3",
|
||||||
|
phrase: "Access please!",
|
||||||
|
volume: 0.9,
|
||||||
|
},
|
||||||
|
[NotificationType.CONNECTION]: {
|
||||||
|
type: NotificationType.CONNECTION,
|
||||||
|
filename: "connected.mp3",
|
||||||
|
phrase: "Connected!",
|
||||||
|
volume: 0.7,
|
||||||
|
},
|
||||||
|
[NotificationType.TASK_START]: {
|
||||||
|
type: NotificationType.TASK_START,
|
||||||
|
filename: "working-on-it.mp3",
|
||||||
|
phrase: "Working on it!",
|
||||||
|
volume: 0.6,
|
||||||
|
},
|
||||||
|
[NotificationType.ACHIEVEMENT]: {
|
||||||
|
type: NotificationType.ACHIEVEMENT,
|
||||||
|
filename: "achievement.mp3",
|
||||||
|
phrase: "Achievement Get~!",
|
||||||
|
volume: 0.8,
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
import { platform } from "@tauri-apps/plugin-os";
|
||||||
|
|
||||||
|
export async function sendWSLNotification(title: string, body: string): Promise<void> {
|
||||||
|
const currentPlatform = await platform();
|
||||||
|
|
||||||
|
// Check if we're on Windows (WSL shows as 'windows')
|
||||||
|
if (currentPlatform === "windows") {
|
||||||
|
try {
|
||||||
|
// Use PowerShell to send Windows native notifications
|
||||||
|
await invoke("send_windows_notification", { title, body });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to send Windows notification:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// Achievement sound player using the notification system
|
||||||
|
|
||||||
|
import { soundPlayer } from "$lib/notifications";
|
||||||
|
import { NotificationType } from "$lib/notifications/types";
|
||||||
|
|
||||||
|
export function playAchievementSound() {
|
||||||
|
// Use the soundPlayer which respects global notification settings
|
||||||
|
soundPlayer.play(NotificationType.ACHIEVEMENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test function for development
|
||||||
|
export function testAchievementSound() {
|
||||||
|
try {
|
||||||
|
playAchievementSound();
|
||||||
|
console.log("Achievement sound played successfully!");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error playing achievement sound:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,649 @@
|
|||||||
|
import { writable, derived } from "svelte/store";
|
||||||
|
import { listen } from "@tauri-apps/api/event";
|
||||||
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
import type { Achievement, AchievementUnlockedEvent, AchievementId } from "$lib/types/achievements";
|
||||||
|
import { playAchievementSound } from "$lib/sounds/achievement";
|
||||||
|
|
||||||
|
interface AchievementState {
|
||||||
|
achievements: Record<AchievementId, Achievement>;
|
||||||
|
totalUnlocked: number;
|
||||||
|
lastUnlocked: Achievement | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initial achievement definitions
|
||||||
|
const achievementDefinitions: Record<
|
||||||
|
AchievementId,
|
||||||
|
Omit<Achievement, "unlocked" | "unlockedAt">
|
||||||
|
> = {
|
||||||
|
// Token milestones
|
||||||
|
FirstSteps: {
|
||||||
|
id: "FirstSteps",
|
||||||
|
name: "First Steps",
|
||||||
|
description: "Generated your first 1,000 tokens",
|
||||||
|
icon: "👶",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 1000,
|
||||||
|
},
|
||||||
|
GrowingStrong: {
|
||||||
|
id: "GrowingStrong",
|
||||||
|
name: "Growing Strong",
|
||||||
|
description: "Reached 10,000 tokens total",
|
||||||
|
icon: "🌱",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 10000,
|
||||||
|
},
|
||||||
|
BlossomingCoder: {
|
||||||
|
id: "BlossomingCoder",
|
||||||
|
name: "Blossoming Coder",
|
||||||
|
description: "Generated 100,000 tokens - you're really growing!",
|
||||||
|
icon: "🌸",
|
||||||
|
rarity: "rare",
|
||||||
|
maxProgress: 100000,
|
||||||
|
},
|
||||||
|
TokenMaster: {
|
||||||
|
id: "TokenMaster",
|
||||||
|
name: "Token Master",
|
||||||
|
description: "One million tokens! You're unstoppable!",
|
||||||
|
icon: "👑",
|
||||||
|
rarity: "legendary",
|
||||||
|
maxProgress: 1000000,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Code generation
|
||||||
|
HelloWorld: {
|
||||||
|
id: "HelloWorld",
|
||||||
|
name: "Hello, World!",
|
||||||
|
description: "Generated your first code block",
|
||||||
|
icon: "👋",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 1,
|
||||||
|
},
|
||||||
|
CodeWizard: {
|
||||||
|
id: "CodeWizard",
|
||||||
|
name: "Code Wizard",
|
||||||
|
description: "100 code blocks generated",
|
||||||
|
icon: "🧙♀️",
|
||||||
|
rarity: "rare",
|
||||||
|
maxProgress: 100,
|
||||||
|
},
|
||||||
|
ThousandBlocks: {
|
||||||
|
id: "ThousandBlocks",
|
||||||
|
name: "Thousand Blocks",
|
||||||
|
description: "1,000 code blocks! You're a code machine!",
|
||||||
|
icon: "🏗️",
|
||||||
|
rarity: "epic",
|
||||||
|
maxProgress: 1000,
|
||||||
|
},
|
||||||
|
|
||||||
|
// File operations
|
||||||
|
FileManipulator: {
|
||||||
|
id: "FileManipulator",
|
||||||
|
name: "File Manipulator",
|
||||||
|
description: "Edited 10 files",
|
||||||
|
icon: "📝",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 10,
|
||||||
|
},
|
||||||
|
FileArchitect: {
|
||||||
|
id: "FileArchitect",
|
||||||
|
name: "File Architect",
|
||||||
|
description: "Created or edited 100 files",
|
||||||
|
icon: "🏛️",
|
||||||
|
rarity: "rare",
|
||||||
|
maxProgress: 100,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Conversation milestones
|
||||||
|
ConversationStarter: {
|
||||||
|
id: "ConversationStarter",
|
||||||
|
name: "Conversation Starter",
|
||||||
|
description: "Exchanged 10 messages",
|
||||||
|
icon: "💬",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 10,
|
||||||
|
},
|
||||||
|
ChattyKathy: {
|
||||||
|
id: "ChattyKathy",
|
||||||
|
name: "Chatty Kathy",
|
||||||
|
description: "100 messages exchanged",
|
||||||
|
icon: "🗣️",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 100,
|
||||||
|
},
|
||||||
|
Conversationalist: {
|
||||||
|
id: "Conversationalist",
|
||||||
|
name: "Master Conversationalist",
|
||||||
|
description: "1,000 messages! We're really connecting!",
|
||||||
|
icon: "💖",
|
||||||
|
rarity: "rare",
|
||||||
|
maxProgress: 1000,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Tool usage
|
||||||
|
Toolsmith: {
|
||||||
|
id: "Toolsmith",
|
||||||
|
name: "Toolsmith",
|
||||||
|
description: "Used 5 different tools",
|
||||||
|
icon: "🔨",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 5,
|
||||||
|
},
|
||||||
|
ToolMaster: {
|
||||||
|
id: "ToolMaster",
|
||||||
|
name: "Tool Master",
|
||||||
|
description: "Used 10 different tools efficiently",
|
||||||
|
icon: "🛠️",
|
||||||
|
rarity: "rare",
|
||||||
|
maxProgress: 10,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Time-based achievements
|
||||||
|
EarlyBird: {
|
||||||
|
id: "EarlyBird",
|
||||||
|
name: "Early Bird",
|
||||||
|
description: "Started a session between 5 AM and 7 AM",
|
||||||
|
icon: "🌅",
|
||||||
|
rarity: "common",
|
||||||
|
},
|
||||||
|
NightOwl: {
|
||||||
|
id: "NightOwl",
|
||||||
|
name: "Night Owl",
|
||||||
|
description: "Coding after midnight",
|
||||||
|
icon: "🦉",
|
||||||
|
rarity: "common",
|
||||||
|
},
|
||||||
|
AllNighter: {
|
||||||
|
id: "AllNighter",
|
||||||
|
name: "All Nighter",
|
||||||
|
description: "Worked through the night (2 AM - 5 AM)",
|
||||||
|
icon: "🌙",
|
||||||
|
rarity: "rare",
|
||||||
|
},
|
||||||
|
WeekendWarrior: {
|
||||||
|
id: "WeekendWarrior",
|
||||||
|
name: "Weekend Warrior",
|
||||||
|
description: "Coding on a weekend",
|
||||||
|
icon: "⚔️",
|
||||||
|
rarity: "common",
|
||||||
|
},
|
||||||
|
DedicatedDeveloper: {
|
||||||
|
id: "DedicatedDeveloper",
|
||||||
|
name: "Dedicated Developer",
|
||||||
|
description: "Coded for 30 days in a row",
|
||||||
|
icon: "🏆",
|
||||||
|
rarity: "legendary",
|
||||||
|
},
|
||||||
|
|
||||||
|
// Search and exploration
|
||||||
|
Explorer: {
|
||||||
|
id: "Explorer",
|
||||||
|
name: "Explorer",
|
||||||
|
description: "Used search tools 50 times",
|
||||||
|
icon: "🔍",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 50,
|
||||||
|
},
|
||||||
|
MasterSearcher: {
|
||||||
|
id: "MasterSearcher",
|
||||||
|
name: "Master Searcher",
|
||||||
|
description: "Searched 500 times across files",
|
||||||
|
icon: "🕵️♀️",
|
||||||
|
rarity: "rare",
|
||||||
|
maxProgress: 500,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Session achievements
|
||||||
|
QuickSession: {
|
||||||
|
id: "QuickSession",
|
||||||
|
name: "Quick Session",
|
||||||
|
description: "Completed a productive session in under 5 minutes",
|
||||||
|
icon: "⚡",
|
||||||
|
rarity: "common",
|
||||||
|
},
|
||||||
|
FocusedWork: {
|
||||||
|
id: "FocusedWork",
|
||||||
|
name: "Focused Work",
|
||||||
|
description: "Worked for 30 minutes straight",
|
||||||
|
icon: "🎯",
|
||||||
|
rarity: "common",
|
||||||
|
},
|
||||||
|
DeepDive: {
|
||||||
|
id: "DeepDive",
|
||||||
|
name: "Deep Dive",
|
||||||
|
description: "Worked for 2 hours continuously",
|
||||||
|
icon: "🏊♀️",
|
||||||
|
rarity: "rare",
|
||||||
|
},
|
||||||
|
MarathonSession: {
|
||||||
|
id: "MarathonSession",
|
||||||
|
name: "Marathon Session",
|
||||||
|
description: "5+ hour coding session!",
|
||||||
|
icon: "🏃♀️",
|
||||||
|
rarity: "epic",
|
||||||
|
},
|
||||||
|
|
||||||
|
// Special achievements
|
||||||
|
FirstMessage: {
|
||||||
|
id: "FirstMessage",
|
||||||
|
name: "First Message",
|
||||||
|
description: "Sent your first message to Hikari",
|
||||||
|
icon: "✨",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 1,
|
||||||
|
},
|
||||||
|
FirstTool: {
|
||||||
|
id: "FirstTool",
|
||||||
|
name: "First Tool",
|
||||||
|
description: "Used your first tool",
|
||||||
|
icon: "🔧",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 1,
|
||||||
|
},
|
||||||
|
FirstCodeBlock: {
|
||||||
|
id: "FirstCodeBlock",
|
||||||
|
name: "First Code",
|
||||||
|
description: "Generated your first code block",
|
||||||
|
icon: "📦",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 1,
|
||||||
|
},
|
||||||
|
FirstFileEdit: {
|
||||||
|
id: "FirstFileEdit",
|
||||||
|
name: "First Edit",
|
||||||
|
description: "Made your first file edit",
|
||||||
|
icon: "✏️",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 1,
|
||||||
|
},
|
||||||
|
Polyglot: {
|
||||||
|
id: "Polyglot",
|
||||||
|
name: "Polyglot",
|
||||||
|
description: "Generated code in 5+ languages in one session",
|
||||||
|
icon: "🌍",
|
||||||
|
rarity: "rare",
|
||||||
|
maxProgress: 5,
|
||||||
|
},
|
||||||
|
SpeedCoder: {
|
||||||
|
id: "SpeedCoder",
|
||||||
|
name: "Speed Coder",
|
||||||
|
description: "Generated 10 code blocks in 10 minutes",
|
||||||
|
icon: "🚀",
|
||||||
|
rarity: "rare",
|
||||||
|
},
|
||||||
|
ClaudeConnoisseur: {
|
||||||
|
id: "ClaudeConnoisseur",
|
||||||
|
name: "Claude Connoisseur",
|
||||||
|
description: "Used all available Claude models",
|
||||||
|
icon: "🎨",
|
||||||
|
rarity: "epic",
|
||||||
|
maxProgress: 5, // Adjust based on available models
|
||||||
|
},
|
||||||
|
MarathonCoder: {
|
||||||
|
id: "MarathonCoder",
|
||||||
|
name: "Marathon Coder",
|
||||||
|
description: "10,000 tokens in a single session",
|
||||||
|
icon: "🏃♂️",
|
||||||
|
rarity: "epic",
|
||||||
|
maxProgress: 10000,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Relationship & Greetings
|
||||||
|
GoodMorning: {
|
||||||
|
id: "GoodMorning",
|
||||||
|
name: "Good Morning!",
|
||||||
|
description: "Greeted Hikari with a good morning",
|
||||||
|
icon: "🌅",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 1,
|
||||||
|
},
|
||||||
|
GoodNight: {
|
||||||
|
id: "GoodNight",
|
||||||
|
name: "Sweet Dreams",
|
||||||
|
description: "Said good night to Hikari",
|
||||||
|
icon: "🌙",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 1,
|
||||||
|
},
|
||||||
|
ThankYou: {
|
||||||
|
id: "ThankYou",
|
||||||
|
name: "Grateful Heart",
|
||||||
|
description: "Thanked Hikari for her help",
|
||||||
|
icon: "🙏",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 1,
|
||||||
|
},
|
||||||
|
LoveYou: {
|
||||||
|
id: "LoveYou",
|
||||||
|
name: "Heartfelt",
|
||||||
|
description: "Expressed love to Hikari",
|
||||||
|
icon: "💕",
|
||||||
|
rarity: "rare",
|
||||||
|
maxProgress: 1,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Personality & Fun
|
||||||
|
EmojiUser: {
|
||||||
|
id: "EmojiUser",
|
||||||
|
name: "Emoji Master",
|
||||||
|
description: "Used 20+ emojis in messages",
|
||||||
|
icon: "😄",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 20,
|
||||||
|
},
|
||||||
|
CapsLock: {
|
||||||
|
id: "CapsLock",
|
||||||
|
name: "CAPS LOCK",
|
||||||
|
description: "SENT A MESSAGE IN ALL CAPS",
|
||||||
|
icon: "🔊",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 1,
|
||||||
|
},
|
||||||
|
QuestionMaster: {
|
||||||
|
id: "QuestionMaster",
|
||||||
|
name: "Question Master",
|
||||||
|
description: "Asked 50 questions",
|
||||||
|
icon: "❓",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 50,
|
||||||
|
},
|
||||||
|
PleaseAndThankYou: {
|
||||||
|
id: "PleaseAndThankYou",
|
||||||
|
name: "Polite Programmer",
|
||||||
|
description: "Always says please and thank you",
|
||||||
|
icon: "🎩",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 10,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Git & Development
|
||||||
|
CommitMaster: {
|
||||||
|
id: "CommitMaster",
|
||||||
|
name: "Commit Master",
|
||||||
|
description: "Made 100 commits through Hikari",
|
||||||
|
icon: "📝",
|
||||||
|
rarity: "rare",
|
||||||
|
maxProgress: 100,
|
||||||
|
},
|
||||||
|
PRO: {
|
||||||
|
id: "PRO",
|
||||||
|
name: "PRO",
|
||||||
|
description: "Created 10 pull requests",
|
||||||
|
icon: "🔀",
|
||||||
|
rarity: "rare",
|
||||||
|
maxProgress: 10,
|
||||||
|
},
|
||||||
|
Reviewer: {
|
||||||
|
id: "Reviewer",
|
||||||
|
name: "Code Reviewer",
|
||||||
|
description: "Reviewed 10 pull requests",
|
||||||
|
icon: "👀",
|
||||||
|
rarity: "rare",
|
||||||
|
maxProgress: 10,
|
||||||
|
},
|
||||||
|
IssueTracker: {
|
||||||
|
id: "IssueTracker",
|
||||||
|
name: "Issue Tracker",
|
||||||
|
description: "Created 25 issues",
|
||||||
|
icon: "🎯",
|
||||||
|
rarity: "rare",
|
||||||
|
maxProgress: 25,
|
||||||
|
},
|
||||||
|
GitGuru: {
|
||||||
|
id: "GitGuru",
|
||||||
|
name: "Git Guru",
|
||||||
|
description: "Mastered git operations",
|
||||||
|
icon: "🌲",
|
||||||
|
rarity: "epic",
|
||||||
|
},
|
||||||
|
|
||||||
|
// Tool Mastery
|
||||||
|
BashMaster: {
|
||||||
|
id: "BashMaster",
|
||||||
|
name: "Bash Master",
|
||||||
|
description: "Used bash commands 100 times",
|
||||||
|
icon: "💻",
|
||||||
|
rarity: "rare",
|
||||||
|
maxProgress: 100,
|
||||||
|
},
|
||||||
|
FileExplorer: {
|
||||||
|
id: "FileExplorer",
|
||||||
|
name: "File Explorer",
|
||||||
|
description: "Explored files 100 times",
|
||||||
|
icon: "📂",
|
||||||
|
rarity: "common",
|
||||||
|
maxProgress: 100,
|
||||||
|
},
|
||||||
|
SearchExpert: {
|
||||||
|
id: "SearchExpert",
|
||||||
|
name: "Search Expert",
|
||||||
|
description: "Mastered advanced search queries",
|
||||||
|
icon: "🔎",
|
||||||
|
rarity: "rare",
|
||||||
|
},
|
||||||
|
AgentCommander: {
|
||||||
|
id: "AgentCommander",
|
||||||
|
name: "Agent Commander",
|
||||||
|
description: "Used task agents effectively",
|
||||||
|
icon: "🤖",
|
||||||
|
rarity: "rare",
|
||||||
|
},
|
||||||
|
MCPMaster: {
|
||||||
|
id: "MCPMaster",
|
||||||
|
name: "MCP Master",
|
||||||
|
description: "Mastered MCP tool usage",
|
||||||
|
icon: "🛠️",
|
||||||
|
rarity: "epic",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Initialize all achievements as locked
|
||||||
|
const initialAchievements: Record<AchievementId, Achievement> = {} as Record<
|
||||||
|
AchievementId,
|
||||||
|
Achievement
|
||||||
|
>;
|
||||||
|
for (const [id, def] of Object.entries(achievementDefinitions)) {
|
||||||
|
initialAchievements[id as AchievementId] = {
|
||||||
|
...def,
|
||||||
|
unlocked: false,
|
||||||
|
progress: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the main store
|
||||||
|
function createAchievementsStore() {
|
||||||
|
const { subscribe, update } = writable<AchievementState>({
|
||||||
|
achievements: initialAchievements,
|
||||||
|
totalUnlocked: 0,
|
||||||
|
lastUnlocked: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
subscribe,
|
||||||
|
unlockAchievement: (event: AchievementUnlockedEvent, playSound: boolean = true) => {
|
||||||
|
update((state) => {
|
||||||
|
const achievement = state.achievements[event.achievement.id];
|
||||||
|
if (achievement && !achievement.unlocked) {
|
||||||
|
achievement.unlocked = true;
|
||||||
|
achievement.unlockedAt = event.achievement.unlocked_at
|
||||||
|
? new Date(event.achievement.unlocked_at)
|
||||||
|
: new Date();
|
||||||
|
state.totalUnlocked++;
|
||||||
|
state.lastUnlocked = achievement;
|
||||||
|
|
||||||
|
// Play achievement sound only for new unlocks, not when loading saved ones
|
||||||
|
if (playSound) {
|
||||||
|
try {
|
||||||
|
playAchievementSound();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to play achievement sound:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
updateProgress: (id: AchievementId, progress: number) => {
|
||||||
|
update((state) => {
|
||||||
|
const achievement = state.achievements[id];
|
||||||
|
if (achievement) {
|
||||||
|
achievement.progress = progress;
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
reset: () => {
|
||||||
|
update(() => ({
|
||||||
|
achievements: initialAchievements,
|
||||||
|
totalUnlocked: 0,
|
||||||
|
lastUnlocked: null,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const achievementsStore = createAchievementsStore();
|
||||||
|
|
||||||
|
// Derived stores for different views
|
||||||
|
export const unlockedAchievements = derived(achievementsStore, ($store) =>
|
||||||
|
Object.values($store.achievements).filter((a) => a.unlocked)
|
||||||
|
);
|
||||||
|
|
||||||
|
export const lockedAchievements = derived(achievementsStore, ($store) =>
|
||||||
|
Object.values($store.achievements).filter((a) => !a.unlocked)
|
||||||
|
);
|
||||||
|
|
||||||
|
export const achievementsByRarity = derived(achievementsStore, ($store) => {
|
||||||
|
const byRarity: Record<string, Achievement[]> = {
|
||||||
|
common: [],
|
||||||
|
rare: [],
|
||||||
|
epic: [],
|
||||||
|
legendary: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const achievement of Object.values($store.achievements)) {
|
||||||
|
byRarity[achievement.rarity].push(achievement);
|
||||||
|
}
|
||||||
|
|
||||||
|
return byRarity;
|
||||||
|
});
|
||||||
|
|
||||||
|
export const achievementProgress = derived(achievementsStore, ($store) => ({
|
||||||
|
unlocked: $store.totalUnlocked,
|
||||||
|
total: Object.keys($store.achievements).length,
|
||||||
|
percentage: Math.round(($store.totalUnlocked / Object.keys($store.achievements).length) * 100),
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Initialize achievement listener
|
||||||
|
export async function initAchievementsListener() {
|
||||||
|
// Listen for achievement unlocked events
|
||||||
|
await listen<AchievementUnlockedEvent>("achievement:unlocked", (event) => {
|
||||||
|
achievementsStore.unlockAchievement(event.payload);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Load saved achievements from persistent storage
|
||||||
|
try {
|
||||||
|
const savedAchievements = await invoke<AchievementUnlockedEvent[]>("load_saved_achievements");
|
||||||
|
|
||||||
|
// Update the store with saved achievements (don't play sounds)
|
||||||
|
for (const event of savedAchievements) {
|
||||||
|
achievementsStore.unlockAchievement(event, false);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to load saved achievements:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export achievement categories for the display panel
|
||||||
|
export const achievementCategories = [
|
||||||
|
{
|
||||||
|
name: "Token Milestones",
|
||||||
|
description: "Track your token generation progress",
|
||||||
|
ids: ["FirstSteps", "GrowingStrong", "BlossomingCoder", "TokenMaster"] as AchievementId[],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Code Generation",
|
||||||
|
description: "Achievements for generating code",
|
||||||
|
ids: ["HelloWorld", "CodeWizard", "ThousandBlocks"] as AchievementId[],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "File Operations",
|
||||||
|
description: "Working with files and projects",
|
||||||
|
ids: ["FileManipulator", "FileArchitect"] as AchievementId[],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Conversations",
|
||||||
|
description: "Building our relationship through chat",
|
||||||
|
ids: ["ConversationStarter", "ChattyKathy", "Conversationalist"] as AchievementId[],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Tools & Skills",
|
||||||
|
description: "Mastering different tools",
|
||||||
|
ids: ["Toolsmith", "ToolMaster"] as AchievementId[],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Time-Based",
|
||||||
|
description: "When you code matters too!",
|
||||||
|
ids: [
|
||||||
|
"EarlyBird",
|
||||||
|
"NightOwl",
|
||||||
|
"AllNighter",
|
||||||
|
"WeekendWarrior",
|
||||||
|
"DedicatedDeveloper",
|
||||||
|
] as AchievementId[],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Search & Explore",
|
||||||
|
description: "Finding what you need",
|
||||||
|
ids: ["Explorer", "MasterSearcher"] as AchievementId[],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Session Records",
|
||||||
|
description: "Your coding session achievements",
|
||||||
|
ids: [
|
||||||
|
"QuickSession",
|
||||||
|
"FocusedWork",
|
||||||
|
"DeepDive",
|
||||||
|
"MarathonSession",
|
||||||
|
"MarathonCoder",
|
||||||
|
] as AchievementId[],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Relationship & Greetings",
|
||||||
|
description: "Our special moments together",
|
||||||
|
ids: ["GoodMorning", "GoodNight", "ThankYou", "LoveYou"] as AchievementId[],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Personality & Fun",
|
||||||
|
description: "Express yourself!",
|
||||||
|
ids: ["EmojiUser", "CapsLock", "QuestionMaster", "PleaseAndThankYou"] as AchievementId[],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Git & Development",
|
||||||
|
description: "Version control mastery",
|
||||||
|
ids: ["CommitMaster", "PRO", "Reviewer", "IssueTracker", "GitGuru"] as AchievementId[],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Tool Mastery",
|
||||||
|
description: "Master of all tools",
|
||||||
|
ids: [
|
||||||
|
"BashMaster",
|
||||||
|
"FileExplorer",
|
||||||
|
"SearchExpert",
|
||||||
|
"AgentCommander",
|
||||||
|
"MCPMaster",
|
||||||
|
] as AchievementId[],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Special",
|
||||||
|
description: "Unique accomplishments",
|
||||||
|
ids: [
|
||||||
|
"FirstMessage",
|
||||||
|
"FirstTool",
|
||||||
|
"FirstCodeBlock",
|
||||||
|
"FirstFileEdit",
|
||||||
|
"Polyglot",
|
||||||
|
"SpeedCoder",
|
||||||
|
"ClaudeConnoisseur",
|
||||||
|
] as AchievementId[],
|
||||||
|
},
|
||||||
|
];
|
||||||
@@ -1,127 +1,100 @@
|
|||||||
import { writable, derived } from "svelte/store";
|
import { derived } from "svelte/store";
|
||||||
import type { ConnectionStatus, PermissionRequest } from "$lib/types/messages";
|
import { conversationsStore } from "./conversations";
|
||||||
|
import type { TerminalLine } from "$lib/types/messages";
|
||||||
|
import { characterState } from "$lib/stores/character";
|
||||||
|
import {
|
||||||
|
setShouldRestoreHistory,
|
||||||
|
setSavedHistory,
|
||||||
|
getShouldRestoreHistory,
|
||||||
|
getSavedHistory,
|
||||||
|
clearHistoryRestore,
|
||||||
|
} from "./historyRestore";
|
||||||
|
|
||||||
export interface TerminalLine {
|
// Re-export TerminalLine type for backwards compatibility
|
||||||
id: string;
|
export type { TerminalLine };
|
||||||
type: "user" | "assistant" | "system" | "tool" | "error";
|
|
||||||
content: string;
|
|
||||||
timestamp: Date;
|
|
||||||
toolName?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createClaudeStore() {
|
// Re-export from conversations store for backwards compatibility
|
||||||
const connectionStatus = writable<ConnectionStatus>("disconnected");
|
export const claudeStore = {
|
||||||
const sessionId = writable<string | null>(null);
|
// Existing subscriptions
|
||||||
const currentWorkingDirectory = writable<string>("");
|
connectionStatus: conversationsStore.connectionStatus,
|
||||||
const terminalLines = writable<TerminalLine[]>([]);
|
sessionId: conversationsStore.sessionId,
|
||||||
const pendingPermission = writable<PermissionRequest | null>(null);
|
currentWorkingDirectory: conversationsStore.currentWorkingDirectory,
|
||||||
const isProcessing = writable<boolean>(false);
|
terminalLines: conversationsStore.terminalLines,
|
||||||
const grantedTools = writable<Set<string>>(new Set());
|
pendingPermission: conversationsStore.pendingPermission,
|
||||||
const pendingRetryMessage = writable<string | null>(null);
|
isProcessing: conversationsStore.isProcessing,
|
||||||
|
grantedTools: conversationsStore.grantedTools,
|
||||||
|
pendingRetryMessage: conversationsStore.pendingRetryMessage,
|
||||||
|
|
||||||
let lineIdCounter = 0;
|
// New conversation-aware subscriptions
|
||||||
|
conversations: conversationsStore.conversations,
|
||||||
|
activeConversationId: conversationsStore.activeConversationId,
|
||||||
|
activeConversation: conversationsStore.activeConversation,
|
||||||
|
|
||||||
function generateLineId(): string {
|
// Methods
|
||||||
return `line-${Date.now()}-${lineIdCounter++}`;
|
setConnectionStatus: conversationsStore.setConnectionStatus,
|
||||||
}
|
setConnectionStatusForConversation: conversationsStore.setConnectionStatusForConversation,
|
||||||
|
setCharacterStateForConversation: conversationsStore.setCharacterStateForConversation,
|
||||||
|
setSessionId: conversationsStore.setSessionId,
|
||||||
|
setSessionIdForConversation: conversationsStore.setSessionIdForConversation,
|
||||||
|
setWorkingDirectory: conversationsStore.setWorkingDirectory,
|
||||||
|
setWorkingDirectoryForConversation: conversationsStore.setWorkingDirectoryForConversation,
|
||||||
|
setProcessing: conversationsStore.setProcessing,
|
||||||
|
addLine: conversationsStore.addLine,
|
||||||
|
addLineToConversation: conversationsStore.addLineToConversation,
|
||||||
|
updateLine: conversationsStore.updateLine,
|
||||||
|
appendToLine: conversationsStore.appendToLine,
|
||||||
|
clearTerminal: conversationsStore.clearTerminal,
|
||||||
|
getConversationHistory: conversationsStore.getConversationHistory,
|
||||||
|
requestPermission: conversationsStore.requestPermission,
|
||||||
|
clearPermission: conversationsStore.clearPermission,
|
||||||
|
grantTool: conversationsStore.grantTool,
|
||||||
|
revokeAllTools: conversationsStore.revokeAllTools,
|
||||||
|
isToolGranted: conversationsStore.isToolGranted,
|
||||||
|
setPendingRetryMessage: conversationsStore.setPendingRetryMessage,
|
||||||
|
|
||||||
return {
|
// Conversation management
|
||||||
connectionStatus: { subscribe: connectionStatus.subscribe },
|
createConversation: conversationsStore.createConversation,
|
||||||
sessionId: { subscribe: sessionId.subscribe },
|
deleteConversation: conversationsStore.deleteConversation,
|
||||||
currentWorkingDirectory: { subscribe: currentWorkingDirectory.subscribe },
|
switchConversation: conversationsStore.switchConversation,
|
||||||
terminalLines: { subscribe: terminalLines.subscribe },
|
renameConversation: conversationsStore.renameConversation,
|
||||||
pendingPermission: { subscribe: pendingPermission.subscribe },
|
|
||||||
isProcessing: { subscribe: isProcessing.subscribe },
|
|
||||||
grantedTools: { subscribe: grantedTools.subscribe },
|
|
||||||
pendingRetryMessage: { subscribe: pendingRetryMessage.subscribe },
|
|
||||||
|
|
||||||
setConnectionStatus: (status: ConnectionStatus) => connectionStatus.set(status),
|
getGrantedTools: (): string[] => {
|
||||||
setSessionId: (id: string | null) => sessionId.set(id),
|
let tools: string[] = [];
|
||||||
setWorkingDirectory: (dir: string) => currentWorkingDirectory.set(dir),
|
conversationsStore.grantedTools.subscribe((t) => (tools = Array.from(t)))();
|
||||||
setProcessing: (processing: boolean) => isProcessing.set(processing),
|
return tools;
|
||||||
|
},
|
||||||
|
|
||||||
addLine: (type: TerminalLine["type"], content: string, toolName?: string) => {
|
// History restoration methods from main branch
|
||||||
const line: TerminalLine = {
|
setShouldRestoreHistory: setShouldRestoreHistory,
|
||||||
id: generateLineId(),
|
setSavedConversationHistory: setSavedHistory,
|
||||||
type,
|
getShouldRestoreHistory: getShouldRestoreHistory,
|
||||||
content,
|
getSavedConversationHistory: getSavedHistory,
|
||||||
timestamp: new Date(),
|
|
||||||
toolName,
|
|
||||||
};
|
|
||||||
terminalLines.update((lines) => [...lines, line]);
|
|
||||||
return line.id;
|
|
||||||
},
|
|
||||||
|
|
||||||
updateLine: (id: string, content: string) => {
|
reset: () => {
|
||||||
terminalLines.update((lines) =>
|
// Reset only the active conversation
|
||||||
lines.map((line) => (line.id === id ? { ...line, content } : line))
|
conversationsStore.clearTerminal();
|
||||||
);
|
conversationsStore.setSessionId(null);
|
||||||
},
|
conversationsStore.setWorkingDirectory("");
|
||||||
|
conversationsStore.setProcessing(false);
|
||||||
appendToLine: (id: string, additionalContent: string) => {
|
conversationsStore.revokeAllTools();
|
||||||
terminalLines.update((lines) =>
|
// Also clear history restoration
|
||||||
lines.map((line) =>
|
clearHistoryRestore();
|
||||||
line.id === id ? { ...line, content: line.content + additionalContent } : line
|
},
|
||||||
)
|
};
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
clearTerminal: () => terminalLines.set([]),
|
|
||||||
|
|
||||||
getConversationHistory: (): string => {
|
|
||||||
let lines: TerminalLine[] = [];
|
|
||||||
terminalLines.subscribe((l) => (lines = l))();
|
|
||||||
|
|
||||||
// Filter to just user and assistant messages, skip system/tool noise
|
|
||||||
const relevantLines = lines.filter(
|
|
||||||
(line) => line.type === "user" || line.type === "assistant"
|
|
||||||
);
|
|
||||||
|
|
||||||
if (relevantLines.length === 0) return "";
|
|
||||||
|
|
||||||
return relevantLines
|
|
||||||
.map((line) => {
|
|
||||||
const role = line.type === "user" ? "User" : "Assistant";
|
|
||||||
return `${role}: ${line.content}`;
|
|
||||||
})
|
|
||||||
.join("\n\n");
|
|
||||||
},
|
|
||||||
|
|
||||||
requestPermission: (request: PermissionRequest) => pendingPermission.set(request),
|
|
||||||
clearPermission: () => pendingPermission.set(null),
|
|
||||||
|
|
||||||
grantTool: (toolName: string) => {
|
|
||||||
grantedTools.update((tools) => {
|
|
||||||
const newTools = new Set(tools);
|
|
||||||
newTools.add(toolName);
|
|
||||||
return newTools;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
getGrantedTools: (): string[] => {
|
|
||||||
let tools: string[] = [];
|
|
||||||
grantedTools.subscribe((t) => (tools = Array.from(t)))();
|
|
||||||
return tools;
|
|
||||||
},
|
|
||||||
|
|
||||||
setPendingRetryMessage: (message: string | null) => pendingRetryMessage.set(message),
|
|
||||||
|
|
||||||
reset: () => {
|
|
||||||
connectionStatus.set("disconnected");
|
|
||||||
sessionId.set(null);
|
|
||||||
currentWorkingDirectory.set("");
|
|
||||||
terminalLines.set([]);
|
|
||||||
pendingPermission.set(null);
|
|
||||||
isProcessing.set(false);
|
|
||||||
grantedTools.set(new Set());
|
|
||||||
pendingRetryMessage.set(null);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export const claudeStore = createClaudeStore();
|
|
||||||
|
|
||||||
export const hasPermissionPending = derived(
|
export const hasPermissionPending = derived(
|
||||||
claudeStore.pendingPermission,
|
claudeStore.pendingPermission,
|
||||||
($permission) => $permission !== null
|
($permission) => $permission !== null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Derived store to check if Claude is currently processing (can be interrupted)
|
||||||
|
export const isClaudeProcessing = derived(
|
||||||
|
[claudeStore.connectionStatus, characterState],
|
||||||
|
([$connectionStatus, $characterState]) => {
|
||||||
|
// Must be connected and in one of the processing states
|
||||||
|
return (
|
||||||
|
$connectionStatus === "connected" &&
|
||||||
|
["thinking", "typing", "searching", "coding", "mcp"].includes($characterState)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ export interface HikariConfig {
|
|||||||
mcp_servers_json: string | null;
|
mcp_servers_json: string | null;
|
||||||
auto_granted_tools: string[];
|
auto_granted_tools: string[];
|
||||||
theme: Theme;
|
theme: Theme;
|
||||||
|
greeting_enabled: boolean;
|
||||||
|
greeting_custom_prompt: string | null;
|
||||||
|
notifications_enabled: boolean;
|
||||||
|
notification_volume: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultConfig: HikariConfig = {
|
const defaultConfig: HikariConfig = {
|
||||||
@@ -19,6 +23,10 @@ const defaultConfig: HikariConfig = {
|
|||||||
mcp_servers_json: null,
|
mcp_servers_json: null,
|
||||||
auto_granted_tools: [],
|
auto_granted_tools: [],
|
||||||
theme: "dark",
|
theme: "dark",
|
||||||
|
greeting_enabled: true,
|
||||||
|
greeting_custom_prompt: null,
|
||||||
|
notifications_enabled: true,
|
||||||
|
notification_volume: 0.7,
|
||||||
};
|
};
|
||||||
|
|
||||||
function createConfigStore() {
|
function createConfigStore() {
|
||||||
|
|||||||
@@ -0,0 +1,459 @@
|
|||||||
|
import { writable, derived, get } from "svelte/store";
|
||||||
|
import type { TerminalLine, ConnectionStatus, PermissionRequest } from "$lib/types/messages";
|
||||||
|
import type { CharacterState } from "$lib/types/states";
|
||||||
|
import { cleanupConversationTracking } from "$lib/tauri";
|
||||||
|
import { characterState } from "$lib/stores/character";
|
||||||
|
|
||||||
|
export interface Conversation {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
terminalLines: TerminalLine[];
|
||||||
|
sessionId: string | null;
|
||||||
|
connectionStatus: ConnectionStatus;
|
||||||
|
workingDirectory: string;
|
||||||
|
characterState: CharacterState;
|
||||||
|
isProcessing: boolean;
|
||||||
|
grantedTools: Set<string>;
|
||||||
|
createdAt: Date;
|
||||||
|
lastActivityAt: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createConversationsStore() {
|
||||||
|
const conversations = writable<Map<string, Conversation>>(new Map());
|
||||||
|
const activeConversationId = writable<string | null>(null);
|
||||||
|
const pendingPermission = writable<PermissionRequest | null>(null);
|
||||||
|
const pendingRetryMessage = writable<string | null>(null);
|
||||||
|
|
||||||
|
let conversationCounter = 0;
|
||||||
|
let lineIdCounter = 0;
|
||||||
|
|
||||||
|
function generateConversationId(): string {
|
||||||
|
return `conv-${Date.now()}-${conversationCounter++}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateLineId(): string {
|
||||||
|
return `line-${Date.now()}-${lineIdCounter++}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createNewConversation(name?: string): Conversation {
|
||||||
|
const id = generateConversationId();
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
name: name || `Conversation ${conversationCounter}`,
|
||||||
|
terminalLines: [],
|
||||||
|
sessionId: null,
|
||||||
|
connectionStatus: "disconnected",
|
||||||
|
workingDirectory: "",
|
||||||
|
characterState: "idle",
|
||||||
|
isProcessing: false,
|
||||||
|
grantedTools: new Set(),
|
||||||
|
createdAt: new Date(),
|
||||||
|
lastActivityAt: new Date(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize with first conversation lazily
|
||||||
|
let initialized = false;
|
||||||
|
function ensureInitialized() {
|
||||||
|
if (!initialized) {
|
||||||
|
initialized = true;
|
||||||
|
const initialConversation = createNewConversation("Main");
|
||||||
|
conversations.update((convs) => {
|
||||||
|
convs.set(initialConversation.id, initialConversation);
|
||||||
|
return convs;
|
||||||
|
});
|
||||||
|
activeConversationId.set(initialConversation.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Derived store for current conversation
|
||||||
|
const activeConversation = derived(
|
||||||
|
[conversations, activeConversationId],
|
||||||
|
([$conversations, $activeId]) => {
|
||||||
|
if (!$activeId) return null;
|
||||||
|
return $conversations.get($activeId) || null;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Derived stores for compatibility with existing code
|
||||||
|
const connectionStatus = derived(
|
||||||
|
activeConversation,
|
||||||
|
($conv) => $conv?.connectionStatus || "disconnected"
|
||||||
|
);
|
||||||
|
const terminalLines = derived(activeConversation, ($conv) => {
|
||||||
|
return $conv?.terminalLines || [];
|
||||||
|
});
|
||||||
|
const sessionId = derived(activeConversation, ($conv) => $conv?.sessionId || null);
|
||||||
|
const currentWorkingDirectory = derived(
|
||||||
|
activeConversation,
|
||||||
|
($conv) => $conv?.workingDirectory || ""
|
||||||
|
);
|
||||||
|
const isProcessing = derived(activeConversation, ($conv) => $conv?.isProcessing || false);
|
||||||
|
const grantedTools = derived(
|
||||||
|
activeConversation,
|
||||||
|
($conv) => $conv?.grantedTools || new Set<string>()
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
// Expose derived stores for compatibility
|
||||||
|
connectionStatus: { subscribe: connectionStatus.subscribe },
|
||||||
|
sessionId: { subscribe: sessionId.subscribe },
|
||||||
|
currentWorkingDirectory: { subscribe: currentWorkingDirectory.subscribe },
|
||||||
|
terminalLines: { subscribe: terminalLines.subscribe },
|
||||||
|
pendingPermission: { subscribe: pendingPermission.subscribe },
|
||||||
|
isProcessing: { subscribe: isProcessing.subscribe },
|
||||||
|
grantedTools: { subscribe: grantedTools.subscribe },
|
||||||
|
pendingRetryMessage: { subscribe: pendingRetryMessage.subscribe },
|
||||||
|
|
||||||
|
// New conversation-specific stores
|
||||||
|
conversations: { subscribe: conversations.subscribe },
|
||||||
|
activeConversationId: { subscribe: activeConversationId.subscribe },
|
||||||
|
activeConversation: { subscribe: activeConversation.subscribe },
|
||||||
|
|
||||||
|
// Connection management
|
||||||
|
setConnectionStatus: (status: ConnectionStatus) => {
|
||||||
|
const activeId = get(activeConversationId);
|
||||||
|
if (!activeId) return;
|
||||||
|
|
||||||
|
conversations.update((convs) => {
|
||||||
|
const conv = convs.get(activeId);
|
||||||
|
if (conv) {
|
||||||
|
conv.connectionStatus = status;
|
||||||
|
conv.lastActivityAt = new Date();
|
||||||
|
}
|
||||||
|
return convs;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
setConnectionStatusForConversation: (conversationId: string, status: ConnectionStatus) => {
|
||||||
|
conversations.update((convs) => {
|
||||||
|
const conv = convs.get(conversationId);
|
||||||
|
if (conv) {
|
||||||
|
conv.connectionStatus = status;
|
||||||
|
conv.lastActivityAt = new Date();
|
||||||
|
}
|
||||||
|
return convs;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
setCharacterStateForConversation: (conversationId: string, state: CharacterState) => {
|
||||||
|
conversations.update((convs) => {
|
||||||
|
const conv = convs.get(conversationId);
|
||||||
|
if (conv) {
|
||||||
|
conv.characterState = state;
|
||||||
|
// If this is the active conversation, update the global character state
|
||||||
|
if (conversationId === get(activeConversationId)) {
|
||||||
|
characterState.setState(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return convs;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
requestPermission: (request: PermissionRequest) => pendingPermission.set(request),
|
||||||
|
clearPermission: () => pendingPermission.set(null),
|
||||||
|
setPendingRetryMessage: (message: string | null) => pendingRetryMessage.set(message),
|
||||||
|
|
||||||
|
// Conversation management
|
||||||
|
createConversation: (name?: string) => {
|
||||||
|
ensureInitialized();
|
||||||
|
const newConv = createNewConversation(name);
|
||||||
|
conversations.update((convs) => {
|
||||||
|
convs.set(newConv.id, newConv);
|
||||||
|
return convs;
|
||||||
|
});
|
||||||
|
activeConversationId.set(newConv.id);
|
||||||
|
return newConv.id;
|
||||||
|
},
|
||||||
|
|
||||||
|
deleteConversation: (id: string) => {
|
||||||
|
ensureInitialized();
|
||||||
|
const convs = get(conversations);
|
||||||
|
const activeId = get(activeConversationId);
|
||||||
|
|
||||||
|
if (convs.size <= 1) {
|
||||||
|
// Don't delete the last conversation
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up tracking for this conversation
|
||||||
|
cleanupConversationTracking(id);
|
||||||
|
|
||||||
|
conversations.update((c) => {
|
||||||
|
c.delete(id);
|
||||||
|
return c;
|
||||||
|
});
|
||||||
|
|
||||||
|
// If we deleted the active conversation, switch to another
|
||||||
|
if (activeId === id) {
|
||||||
|
const remaining = Array.from(get(conversations).keys());
|
||||||
|
if (remaining.length > 0) {
|
||||||
|
activeConversationId.set(remaining[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
switchConversation: async (id: string) => {
|
||||||
|
const convs = get(conversations);
|
||||||
|
if (!convs.has(id)) return;
|
||||||
|
|
||||||
|
const currentId = get(activeConversationId);
|
||||||
|
const targetConv = convs.get(id);
|
||||||
|
|
||||||
|
// If switching to a different conversation
|
||||||
|
if (currentId !== id) {
|
||||||
|
activeConversationId.set(id);
|
||||||
|
|
||||||
|
// Update the global character state to match the conversation's state
|
||||||
|
if (targetConv) {
|
||||||
|
characterState.setState(targetConv.characterState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
renameConversation: (id: string, newName: string) => {
|
||||||
|
conversations.update((convs) => {
|
||||||
|
const conv = convs.get(id);
|
||||||
|
if (conv) {
|
||||||
|
conv.name = newName;
|
||||||
|
conv.lastActivityAt = new Date();
|
||||||
|
}
|
||||||
|
return convs;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// Methods that operate on the active conversation
|
||||||
|
setSessionId: (id: string | null) => {
|
||||||
|
ensureInitialized();
|
||||||
|
const activeId = get(activeConversationId);
|
||||||
|
if (!activeId) return;
|
||||||
|
|
||||||
|
conversations.update((convs) => {
|
||||||
|
const conv = convs.get(activeId);
|
||||||
|
if (conv) {
|
||||||
|
conv.sessionId = id;
|
||||||
|
conv.lastActivityAt = new Date();
|
||||||
|
}
|
||||||
|
return convs;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
setSessionIdForConversation: (conversationId: string, id: string | null) => {
|
||||||
|
conversations.update((convs) => {
|
||||||
|
const conv = convs.get(conversationId);
|
||||||
|
if (conv) {
|
||||||
|
conv.sessionId = id;
|
||||||
|
conv.lastActivityAt = new Date();
|
||||||
|
}
|
||||||
|
return convs;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
setWorkingDirectory: (dir: string) => {
|
||||||
|
const activeId = get(activeConversationId);
|
||||||
|
if (!activeId) return;
|
||||||
|
|
||||||
|
conversations.update((convs) => {
|
||||||
|
const conv = convs.get(activeId);
|
||||||
|
if (conv) {
|
||||||
|
conv.workingDirectory = dir;
|
||||||
|
conv.lastActivityAt = new Date();
|
||||||
|
}
|
||||||
|
return convs;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
setWorkingDirectoryForConversation: (conversationId: string, dir: string) => {
|
||||||
|
conversations.update((convs) => {
|
||||||
|
const conv = convs.get(conversationId);
|
||||||
|
if (conv) {
|
||||||
|
conv.workingDirectory = dir;
|
||||||
|
conv.lastActivityAt = new Date();
|
||||||
|
}
|
||||||
|
return convs;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
setProcessing: (processing: boolean) => {
|
||||||
|
const activeId = get(activeConversationId);
|
||||||
|
if (!activeId) return;
|
||||||
|
|
||||||
|
conversations.update((convs) => {
|
||||||
|
const conv = convs.get(activeId);
|
||||||
|
if (conv) {
|
||||||
|
conv.isProcessing = processing;
|
||||||
|
conv.lastActivityAt = new Date();
|
||||||
|
}
|
||||||
|
return convs;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
addLine: (type: TerminalLine["type"], content: string, toolName?: string) => {
|
||||||
|
ensureInitialized();
|
||||||
|
const activeId = get(activeConversationId);
|
||||||
|
if (!activeId) return "";
|
||||||
|
|
||||||
|
const line: TerminalLine = {
|
||||||
|
id: generateLineId(),
|
||||||
|
type,
|
||||||
|
content,
|
||||||
|
timestamp: new Date(),
|
||||||
|
toolName,
|
||||||
|
};
|
||||||
|
|
||||||
|
conversations.update((convs) => {
|
||||||
|
const conv = convs.get(activeId);
|
||||||
|
if (conv) {
|
||||||
|
conv.terminalLines.push(line);
|
||||||
|
conv.lastActivityAt = new Date();
|
||||||
|
}
|
||||||
|
return convs;
|
||||||
|
});
|
||||||
|
|
||||||
|
return line.id;
|
||||||
|
},
|
||||||
|
|
||||||
|
addLineToConversation: (
|
||||||
|
conversationId: string,
|
||||||
|
type: TerminalLine["type"],
|
||||||
|
content: string,
|
||||||
|
toolName?: string
|
||||||
|
) => {
|
||||||
|
ensureInitialized();
|
||||||
|
|
||||||
|
const line: TerminalLine = {
|
||||||
|
id: generateLineId(),
|
||||||
|
type,
|
||||||
|
content,
|
||||||
|
timestamp: new Date(),
|
||||||
|
toolName,
|
||||||
|
};
|
||||||
|
|
||||||
|
conversations.update((convs) => {
|
||||||
|
const conv = convs.get(conversationId);
|
||||||
|
if (conv) {
|
||||||
|
conv.terminalLines.push(line);
|
||||||
|
conv.lastActivityAt = new Date();
|
||||||
|
}
|
||||||
|
return convs;
|
||||||
|
});
|
||||||
|
|
||||||
|
return line.id;
|
||||||
|
},
|
||||||
|
|
||||||
|
updateLine: (id: string, content: string) => {
|
||||||
|
const activeId = get(activeConversationId);
|
||||||
|
if (!activeId) return;
|
||||||
|
|
||||||
|
conversations.update((convs) => {
|
||||||
|
const conv = convs.get(activeId);
|
||||||
|
if (conv) {
|
||||||
|
const line = conv.terminalLines.find((l) => l.id === id);
|
||||||
|
if (line) {
|
||||||
|
line.content = content;
|
||||||
|
conv.lastActivityAt = new Date();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return convs;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
appendToLine: (id: string, additionalContent: string) => {
|
||||||
|
const activeId = get(activeConversationId);
|
||||||
|
if (!activeId) return;
|
||||||
|
|
||||||
|
conversations.update((convs) => {
|
||||||
|
const conv = convs.get(activeId);
|
||||||
|
if (conv) {
|
||||||
|
const line = conv.terminalLines.find((l) => l.id === id);
|
||||||
|
if (line) {
|
||||||
|
line.content += additionalContent;
|
||||||
|
conv.lastActivityAt = new Date();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return convs;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
clearTerminal: () => {
|
||||||
|
const activeId = get(activeConversationId);
|
||||||
|
if (!activeId) return;
|
||||||
|
|
||||||
|
conversations.update((convs) => {
|
||||||
|
const conv = convs.get(activeId);
|
||||||
|
if (conv) {
|
||||||
|
conv.terminalLines = [];
|
||||||
|
conv.lastActivityAt = new Date();
|
||||||
|
}
|
||||||
|
return convs;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
getConversationHistory: (): string => {
|
||||||
|
const activeId = get(activeConversationId);
|
||||||
|
if (!activeId) return "";
|
||||||
|
|
||||||
|
const convs = get(conversations);
|
||||||
|
const conv = convs.get(activeId);
|
||||||
|
if (!conv) return "";
|
||||||
|
|
||||||
|
const relevantLines = conv.terminalLines.filter(
|
||||||
|
(line) => line.type === "user" || line.type === "assistant"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (relevantLines.length === 0) return "";
|
||||||
|
|
||||||
|
return relevantLines
|
||||||
|
.map((line) => {
|
||||||
|
const role = line.type === "user" ? "User" : "Assistant";
|
||||||
|
return `${role}: ${line.content}`;
|
||||||
|
})
|
||||||
|
.join("\n\n");
|
||||||
|
},
|
||||||
|
|
||||||
|
grantTool: (toolName: string) => {
|
||||||
|
const activeId = get(activeConversationId);
|
||||||
|
if (!activeId) return;
|
||||||
|
|
||||||
|
conversations.update((convs) => {
|
||||||
|
const conv = convs.get(activeId);
|
||||||
|
if (conv) {
|
||||||
|
conv.grantedTools.add(toolName);
|
||||||
|
conv.lastActivityAt = new Date();
|
||||||
|
}
|
||||||
|
return convs;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
revokeAllTools: () => {
|
||||||
|
const activeId = get(activeConversationId);
|
||||||
|
if (!activeId) return;
|
||||||
|
|
||||||
|
conversations.update((convs) => {
|
||||||
|
const conv = convs.get(activeId);
|
||||||
|
if (conv) {
|
||||||
|
conv.grantedTools.clear();
|
||||||
|
conv.lastActivityAt = new Date();
|
||||||
|
}
|
||||||
|
return convs;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
isToolGranted: (toolName: string): boolean => {
|
||||||
|
const activeId = get(activeConversationId);
|
||||||
|
if (!activeId) return false;
|
||||||
|
|
||||||
|
const convs = get(conversations);
|
||||||
|
const conv = convs.get(activeId);
|
||||||
|
return conv?.grantedTools.has(toolName) || false;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Add initialization helper
|
||||||
|
initialize: () => {
|
||||||
|
ensureInitialized();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const conversationsStore = createConversationsStore();
|
||||||
|
// Initialize immediately
|
||||||
|
conversationsStore.initialize();
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
// Separate module for history restoration to ensure persistence across reconnects
|
||||||
|
let shouldRestore = false;
|
||||||
|
let savedHistory: string | null = null;
|
||||||
|
|
||||||
|
export function setShouldRestoreHistory(should: boolean) {
|
||||||
|
shouldRestore = should;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setSavedHistory(history: string | null) {
|
||||||
|
savedHistory = history;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getShouldRestoreHistory(): boolean {
|
||||||
|
return shouldRestore;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSavedHistory(): string | null {
|
||||||
|
return savedHistory;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearHistoryRestore() {
|
||||||
|
shouldRestore = false;
|
||||||
|
savedHistory = null;
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { writable } from "svelte/store";
|
||||||
|
|
||||||
|
// Default to chat mode
|
||||||
|
const messageModeStore = writable<string>("chat");
|
||||||
|
|
||||||
|
export const messageMode = {
|
||||||
|
subscribe: messageModeStore.subscribe,
|
||||||
|
set: (mode: string) => {
|
||||||
|
messageModeStore.set(mode);
|
||||||
|
},
|
||||||
|
reset: () => messageModeStore.set("chat"),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper to get current mode
|
||||||
|
export function getCurrentMode(): string {
|
||||||
|
let currentMode = "chat";
|
||||||
|
messageMode.subscribe((mode) => (currentMode = mode))();
|
||||||
|
return currentMode;
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { configStore } from "./config";
|
||||||
|
import { soundPlayer } from "$lib/notifications";
|
||||||
|
|
||||||
|
let unsubscribe: (() => void) | null = null;
|
||||||
|
|
||||||
|
// Initialize notification settings sync - call this once on app startup
|
||||||
|
export function initNotificationSync() {
|
||||||
|
// Prevent duplicate subscriptions
|
||||||
|
if (unsubscribe) return;
|
||||||
|
|
||||||
|
unsubscribe = configStore.config.subscribe(($config) => {
|
||||||
|
soundPlayer.setEnabled($config.notifications_enabled);
|
||||||
|
soundPlayer.setGlobalVolume($config.notification_volume);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup function if needed
|
||||||
|
export function cleanupNotificationSync() {
|
||||||
|
if (unsubscribe) {
|
||||||
|
unsubscribe();
|
||||||
|
unsubscribe = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
import { writable, derived } from "svelte/store";
|
||||||
|
import { listen } from "@tauri-apps/api/event";
|
||||||
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
|
||||||
|
export interface UsageStats {
|
||||||
|
total_input_tokens: number;
|
||||||
|
total_output_tokens: number;
|
||||||
|
total_cost_usd: number;
|
||||||
|
session_input_tokens: number;
|
||||||
|
session_output_tokens: number;
|
||||||
|
session_cost_usd: number;
|
||||||
|
model: string | null;
|
||||||
|
|
||||||
|
// New fields
|
||||||
|
messages_exchanged: number;
|
||||||
|
session_messages_exchanged: number;
|
||||||
|
code_blocks_generated: number;
|
||||||
|
session_code_blocks_generated: number;
|
||||||
|
files_edited: number;
|
||||||
|
session_files_edited: number;
|
||||||
|
files_created: number;
|
||||||
|
session_files_created: number;
|
||||||
|
tools_usage: Record<string, number>;
|
||||||
|
session_tools_usage: Record<string, number>;
|
||||||
|
session_duration_seconds: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main stats store
|
||||||
|
export const stats = writable<UsageStats>({
|
||||||
|
total_input_tokens: 0,
|
||||||
|
total_output_tokens: 0,
|
||||||
|
total_cost_usd: 0,
|
||||||
|
session_input_tokens: 0,
|
||||||
|
session_output_tokens: 0,
|
||||||
|
session_cost_usd: 0,
|
||||||
|
model: null,
|
||||||
|
messages_exchanged: 0,
|
||||||
|
session_messages_exchanged: 0,
|
||||||
|
code_blocks_generated: 0,
|
||||||
|
session_code_blocks_generated: 0,
|
||||||
|
files_edited: 0,
|
||||||
|
session_files_edited: 0,
|
||||||
|
files_created: 0,
|
||||||
|
session_files_created: 0,
|
||||||
|
tools_usage: {},
|
||||||
|
session_tools_usage: {},
|
||||||
|
session_duration_seconds: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Derived store for formatted display values
|
||||||
|
export const formattedStats = derived(stats, ($stats) => {
|
||||||
|
const formatNumber = (num: number) => num.toLocaleString();
|
||||||
|
const formatCost = (cost: number) => `$${cost.toFixed(4)}`;
|
||||||
|
const formatDuration = (seconds: number) => {
|
||||||
|
const hours = Math.floor(seconds / 3600);
|
||||||
|
const minutes = Math.floor((seconds % 3600) / 60);
|
||||||
|
const secs = seconds % 60;
|
||||||
|
|
||||||
|
if (hours > 0) {
|
||||||
|
return `${hours}h ${minutes}m ${secs}s`;
|
||||||
|
} else if (minutes > 0) {
|
||||||
|
return `${minutes}m ${secs}s`;
|
||||||
|
} else {
|
||||||
|
return `${secs}s`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
totalTokens: formatNumber($stats.total_input_tokens + $stats.total_output_tokens),
|
||||||
|
totalInputTokens: formatNumber($stats.total_input_tokens),
|
||||||
|
totalOutputTokens: formatNumber($stats.total_output_tokens),
|
||||||
|
totalCost: formatCost($stats.total_cost_usd),
|
||||||
|
sessionTokens: formatNumber($stats.session_input_tokens + $stats.session_output_tokens),
|
||||||
|
sessionInputTokens: formatNumber($stats.session_input_tokens),
|
||||||
|
sessionOutputTokens: formatNumber($stats.session_output_tokens),
|
||||||
|
sessionCost: formatCost($stats.session_cost_usd),
|
||||||
|
model: $stats.model || "No model selected",
|
||||||
|
|
||||||
|
// New formatted fields
|
||||||
|
messagesTotal: formatNumber($stats.messages_exchanged),
|
||||||
|
messagesSession: formatNumber($stats.session_messages_exchanged),
|
||||||
|
codeBlocksTotal: formatNumber($stats.code_blocks_generated),
|
||||||
|
codeBlocksSession: formatNumber($stats.session_code_blocks_generated),
|
||||||
|
filesEditedTotal: formatNumber($stats.files_edited),
|
||||||
|
filesEditedSession: formatNumber($stats.session_files_edited),
|
||||||
|
filesCreatedTotal: formatNumber($stats.files_created),
|
||||||
|
filesCreatedSession: formatNumber($stats.session_files_created),
|
||||||
|
sessionDuration: formatDuration($stats.session_duration_seconds),
|
||||||
|
toolsUsage: $stats.tools_usage,
|
||||||
|
sessionToolsUsage: $stats.session_tools_usage,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Note: Cost calculation is now done in the Rust backend
|
||||||
|
|
||||||
|
// Initialize stats listener
|
||||||
|
export async function initStatsListener() {
|
||||||
|
// Listen for stats updates from the backend
|
||||||
|
await listen("claude:stats", (event) => {
|
||||||
|
const payload = event.payload as { stats: UsageStats };
|
||||||
|
const { stats: newStats } = payload;
|
||||||
|
|
||||||
|
// The backend already tracks all totals - just set the stats directly
|
||||||
|
stats.set(newStats);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Load initial stats from backend
|
||||||
|
try {
|
||||||
|
const initialStats = await invoke<UsageStats>("get_usage_stats");
|
||||||
|
stats.set(initialStats);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to load initial stats:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset session stats (call when starting new session)
|
||||||
|
export function resetSessionStats() {
|
||||||
|
stats.update((current) => ({
|
||||||
|
...current,
|
||||||
|
session_input_tokens: 0,
|
||||||
|
session_output_tokens: 0,
|
||||||
|
session_cost_usd: 0,
|
||||||
|
session_messages_exchanged: 0,
|
||||||
|
session_code_blocks_generated: 0,
|
||||||
|
session_files_edited: 0,
|
||||||
|
session_files_created: 0,
|
||||||
|
session_tools_usage: {},
|
||||||
|
session_duration_seconds: 0,
|
||||||
|
}));
|
||||||
|
}
|
||||||
@@ -1,39 +1,197 @@
|
|||||||
import { listen } from "@tauri-apps/api/event";
|
import { listen } from "@tauri-apps/api/event";
|
||||||
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
import { get } from "svelte/store";
|
||||||
import { claudeStore } from "$lib/stores/claude";
|
import { claudeStore } from "$lib/stores/claude";
|
||||||
import { characterState } from "$lib/stores/character";
|
import { characterState } from "$lib/stores/character";
|
||||||
|
import { configStore } from "$lib/stores/config";
|
||||||
|
import { initStatsListener, resetSessionStats } from "$lib/stores/stats";
|
||||||
|
import { initAchievementsListener } from "$lib/stores/achievements";
|
||||||
import type { ConnectionStatus, PermissionPromptEvent } from "$lib/types/messages";
|
import type { ConnectionStatus, PermissionPromptEvent } from "$lib/types/messages";
|
||||||
import type { CharacterState } from "$lib/types/states";
|
import type { CharacterState } from "$lib/types/states";
|
||||||
|
import {
|
||||||
|
initializeNotificationRules,
|
||||||
|
cleanupNotificationRules,
|
||||||
|
handleConnectionStatusChange,
|
||||||
|
handleNewUserMessage,
|
||||||
|
} from "$lib/notifications/rules";
|
||||||
|
|
||||||
interface StateChangePayload {
|
interface StateChangePayload {
|
||||||
state: CharacterState;
|
state: CharacterState;
|
||||||
tool_name: string | null;
|
tool_name: string | null;
|
||||||
|
conversation_id?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const connectedConversations = new Set<string>();
|
||||||
|
let unlisteners: Array<() => void> = [];
|
||||||
|
let skipNextGreeting = false;
|
||||||
|
|
||||||
|
export function setSkipNextGreeting(skip: boolean) {
|
||||||
|
skipNextGreeting = skip;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTimeOfDay(): string {
|
||||||
|
const hour = new Date().getHours();
|
||||||
|
|
||||||
|
if (hour >= 5 && hour < 12) {
|
||||||
|
return "morning";
|
||||||
|
} else if (hour >= 12 && hour < 17) {
|
||||||
|
return "afternoon";
|
||||||
|
} else if (hour >= 17 && hour < 21) {
|
||||||
|
return "evening";
|
||||||
|
} else {
|
||||||
|
return "late night";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateGreetingPrompt(): string {
|
||||||
|
const timeOfDay = getTimeOfDay();
|
||||||
|
return `[System: A new session has started. It's currently ${timeOfDay}. Please greet the user warmly and briefly. Keep it short - just 1-2 sentences.]`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function sendGreeting(conversationId: string) {
|
||||||
|
// Check if we should skip this greeting
|
||||||
|
if (skipNextGreeting) {
|
||||||
|
skipNextGreeting = false; // Reset the flag
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = configStore.getConfig();
|
||||||
|
|
||||||
|
if (!config.greeting_enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const greetingPrompt = config.greeting_custom_prompt?.trim() || generateGreetingPrompt();
|
||||||
|
|
||||||
|
// Don't show the system prompt in the UI - just trigger Claude to respond
|
||||||
|
characterState.setState("thinking");
|
||||||
|
|
||||||
|
// Reset notification state for greeting
|
||||||
|
handleNewUserMessage();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await invoke("send_prompt", {
|
||||||
|
conversationId,
|
||||||
|
message: greetingPrompt,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to send greeting:", error);
|
||||||
|
claudeStore.addLineToConversation(conversationId, "error", `Failed to send greeting: ${error}`);
|
||||||
|
characterState.setTemporaryState("error", 3000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface OutputPayload {
|
interface OutputPayload {
|
||||||
line_type: string;
|
line_type: string;
|
||||||
content: string;
|
content: string;
|
||||||
tool_name: string | null;
|
tool_name: string | null;
|
||||||
|
conversation_id?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ConnectionPayload {
|
||||||
|
status: ConnectionStatus;
|
||||||
|
conversation_id?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SessionPayload {
|
||||||
|
session_id: string;
|
||||||
|
conversation_id?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface WorkingDirectoryPayload {
|
||||||
|
directory: string;
|
||||||
|
conversation_id?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function cleanupConversationTracking(conversationId: string) {
|
||||||
|
connectedConversations.delete(conversationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function initializeTauriListeners() {
|
export async function initializeTauriListeners() {
|
||||||
await listen<string>("claude:connection", (event) => {
|
// Cleanup any existing listeners first
|
||||||
const status = event.payload as ConnectionStatus;
|
cleanupTauriListeners();
|
||||||
claudeStore.setConnectionStatus(status);
|
|
||||||
|
// Initialize notification rules
|
||||||
|
initializeNotificationRules();
|
||||||
|
|
||||||
|
// Initialize stats listener
|
||||||
|
await initStatsListener();
|
||||||
|
|
||||||
|
// Initialize achievements listener
|
||||||
|
await initAchievementsListener();
|
||||||
|
|
||||||
|
const connectionUnlisten = await listen<ConnectionPayload>("claude:connection", async (event) => {
|
||||||
|
const { status, conversation_id } = event.payload;
|
||||||
|
|
||||||
|
// Update connection status for the specific conversation
|
||||||
|
if (conversation_id) {
|
||||||
|
claudeStore.setConnectionStatusForConversation(conversation_id, status);
|
||||||
|
} else {
|
||||||
|
// Fallback to active conversation if no conversation_id
|
||||||
|
claudeStore.setConnectionStatus(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle notification for connection status
|
||||||
|
handleConnectionStatusChange(status);
|
||||||
|
|
||||||
if (status === "connected") {
|
if (status === "connected") {
|
||||||
claudeStore.addLine("system", "Connected to Claude Code");
|
// Get the actual conversation ID (fallback to active if not provided)
|
||||||
characterState.setState("idle");
|
const targetConversationId = conversation_id || get(claudeStore.activeConversationId);
|
||||||
|
|
||||||
|
if (targetConversationId) {
|
||||||
|
// Add system message to the correct conversation
|
||||||
|
claudeStore.addLineToConversation(
|
||||||
|
targetConversationId,
|
||||||
|
"system",
|
||||||
|
"Connected to Claude Code"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Update character state for this conversation
|
||||||
|
claudeStore.setCharacterStateForConversation(targetConversationId, "idle");
|
||||||
|
|
||||||
|
// Check if this specific conversation has connected before
|
||||||
|
if (!connectedConversations.has(targetConversationId)) {
|
||||||
|
connectedConversations.add(targetConversationId);
|
||||||
|
resetSessionStats(); // Reset session stats on new connection
|
||||||
|
await sendGreeting(targetConversationId);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (status === "disconnected") {
|
} else if (status === "disconnected") {
|
||||||
claudeStore.addLine("system", "Disconnected from Claude Code");
|
const targetConversationId = conversation_id || get(claudeStore.activeConversationId);
|
||||||
characterState.setState("idle");
|
|
||||||
|
// Only remove from connected set if we're not about to reconnect
|
||||||
|
if (!skipNextGreeting && targetConversationId) {
|
||||||
|
connectedConversations.delete(targetConversationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't add system message if we're about to reconnect
|
||||||
|
if (!skipNextGreeting && targetConversationId) {
|
||||||
|
claudeStore.addLineToConversation(
|
||||||
|
targetConversationId,
|
||||||
|
"system",
|
||||||
|
"Disconnected from Claude Code"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update character state for this conversation
|
||||||
|
if (targetConversationId) {
|
||||||
|
claudeStore.setCharacterStateForConversation(targetConversationId, "idle");
|
||||||
|
}
|
||||||
} else if (status === "error") {
|
} else if (status === "error") {
|
||||||
claudeStore.addLine("error", "Connection error");
|
const targetConversationId = conversation_id || get(claudeStore.activeConversationId);
|
||||||
|
|
||||||
|
if (targetConversationId) {
|
||||||
|
connectedConversations.delete(targetConversationId);
|
||||||
|
claudeStore.addLineToConversation(targetConversationId, "error", "Connection error");
|
||||||
|
}
|
||||||
|
|
||||||
characterState.setTemporaryState("error", 3000);
|
characterState.setTemporaryState("error", 3000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
unlisteners.push(connectionUnlisten);
|
||||||
|
|
||||||
await listen<StateChangePayload>("claude:state", (event) => {
|
const stateUnlisten = await listen<StateChangePayload>("claude:state", (event) => {
|
||||||
const { state } = event.payload;
|
const { state, conversation_id } = event.payload;
|
||||||
|
|
||||||
const stateMap: Record<string, CharacterState> = {
|
const stateMap: Record<string, CharacterState> = {
|
||||||
idle: "idle",
|
idle: "idle",
|
||||||
@@ -49,45 +207,121 @@ export async function initializeTauriListeners() {
|
|||||||
|
|
||||||
const mappedState = stateMap[state.toLowerCase()] || "idle";
|
const mappedState = stateMap[state.toLowerCase()] || "idle";
|
||||||
|
|
||||||
if (mappedState === "success" || mappedState === "error") {
|
// Always update the conversation's state
|
||||||
characterState.setTemporaryState(mappedState, 3000);
|
if (conversation_id) {
|
||||||
|
claudeStore.setCharacterStateForConversation(conversation_id, mappedState);
|
||||||
} else {
|
} else {
|
||||||
characterState.setState(mappedState);
|
// Fallback to active conversation if no conversation_id
|
||||||
|
const activeConversationId = get(claudeStore.activeConversationId);
|
||||||
|
if (activeConversationId) {
|
||||||
|
claudeStore.setCharacterStateForConversation(activeConversationId, mappedState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only update global character state for active conversation
|
||||||
|
const activeConversationId = get(claudeStore.activeConversationId);
|
||||||
|
if (!conversation_id || conversation_id === activeConversationId) {
|
||||||
|
if (mappedState === "success" || mappedState === "error") {
|
||||||
|
characterState.setTemporaryState(mappedState, 3000);
|
||||||
|
} else {
|
||||||
|
characterState.setState(mappedState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
unlisteners.push(stateUnlisten);
|
||||||
|
|
||||||
await listen<OutputPayload>("claude:output", (event) => {
|
const outputUnlisten = await listen<OutputPayload>("claude:output", (event) => {
|
||||||
const { line_type, content, tool_name } = event.payload;
|
const { line_type, content, tool_name, conversation_id } = event.payload;
|
||||||
claudeStore.addLine(
|
|
||||||
line_type as "user" | "assistant" | "system" | "tool" | "error",
|
// Always store the output to the correct conversation
|
||||||
content,
|
if (conversation_id) {
|
||||||
tool_name || undefined
|
claudeStore.addLineToConversation(
|
||||||
);
|
conversation_id,
|
||||||
|
line_type as "user" | "assistant" | "system" | "tool" | "error",
|
||||||
|
content,
|
||||||
|
tool_name || undefined
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Fallback to active conversation if no conversation_id provided
|
||||||
|
claudeStore.addLine(
|
||||||
|
line_type as "user" | "assistant" | "system" | "tool" | "error",
|
||||||
|
content,
|
||||||
|
tool_name || undefined
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
unlisteners.push(outputUnlisten);
|
||||||
|
|
||||||
await listen<string>("claude:stream", () => {
|
const streamUnlisten = await listen<string>("claude:stream", () => {
|
||||||
// no-op
|
// no-op
|
||||||
});
|
});
|
||||||
|
unlisteners.push(streamUnlisten);
|
||||||
|
|
||||||
await listen<string>("claude:session", (event) => {
|
const sessionUnlisten = await listen<SessionPayload>("claude:session", (event) => {
|
||||||
claudeStore.setSessionId(event.payload);
|
const { session_id, conversation_id } = event.payload;
|
||||||
claudeStore.addLine("system", `Session: ${event.payload.substring(0, 8)}...`);
|
|
||||||
|
// Store session ID for the correct conversation
|
||||||
|
if (conversation_id) {
|
||||||
|
claudeStore.setSessionIdForConversation(conversation_id, session_id);
|
||||||
|
claudeStore.addLineToConversation(
|
||||||
|
conversation_id,
|
||||||
|
"system",
|
||||||
|
`Session: ${session_id.substring(0, 8)}...`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Fallback to active conversation if no conversation_id
|
||||||
|
claudeStore.setSessionId(session_id);
|
||||||
|
claudeStore.addLine("system", `Session: ${session_id.substring(0, 8)}...`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
unlisteners.push(sessionUnlisten);
|
||||||
|
|
||||||
await listen<string>("claude:cwd", (event) => {
|
const cwdUnlisten = await listen<WorkingDirectoryPayload>("claude:cwd", (event) => {
|
||||||
claudeStore.setWorkingDirectory(event.payload);
|
const { directory, conversation_id } = event.payload;
|
||||||
|
|
||||||
|
// Store working directory for the correct conversation
|
||||||
|
if (conversation_id) {
|
||||||
|
claudeStore.setWorkingDirectoryForConversation(conversation_id, directory);
|
||||||
|
} else {
|
||||||
|
// Fallback to active conversation if no conversation_id
|
||||||
|
claudeStore.setWorkingDirectory(directory);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
unlisteners.push(cwdUnlisten);
|
||||||
|
|
||||||
await listen<PermissionPromptEvent>("claude:permission", (event) => {
|
const permissionUnlisten = await listen<PermissionPromptEvent>("claude:permission", (event) => {
|
||||||
const { id, tool_name, tool_input, description } = event.payload;
|
const { id, tool_name, tool_input, description, conversation_id } = event.payload;
|
||||||
claudeStore.requestPermission({
|
|
||||||
id,
|
// Only process permission requests for the active conversation
|
||||||
tool: tool_name,
|
const activeConversationId = get(claudeStore.activeConversationId);
|
||||||
description,
|
if (conversation_id === activeConversationId) {
|
||||||
input: tool_input,
|
claudeStore.requestPermission({
|
||||||
});
|
id,
|
||||||
claudeStore.addLine("system", `Permission requested for: ${tool_name}`);
|
tool: tool_name,
|
||||||
|
description,
|
||||||
|
input: tool_input,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always store the permission message to the correct conversation
|
||||||
|
if (conversation_id) {
|
||||||
|
claudeStore.addLineToConversation(
|
||||||
|
conversation_id,
|
||||||
|
"system",
|
||||||
|
`Permission requested for: ${tool_name}`
|
||||||
|
);
|
||||||
|
} else if (conversation_id === activeConversationId) {
|
||||||
|
claudeStore.addLine("system", `Permission requested for: ${tool_name}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
unlisteners.push(permissionUnlisten);
|
||||||
console.log("Tauri event listeners initialized");
|
}
|
||||||
|
|
||||||
|
export function cleanupTauriListeners() {
|
||||||
|
// Cleanup all event listeners
|
||||||
|
unlisteners.forEach((unlisten) => unlisten());
|
||||||
|
unlisteners = [];
|
||||||
|
|
||||||
|
// Cleanup notification rules
|
||||||
|
cleanupNotificationRules();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
export interface AchievementUnlockedEvent {
|
||||||
|
achievement: {
|
||||||
|
id: AchievementId;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
icon: string;
|
||||||
|
unlocked_at: string | null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AchievementId =
|
||||||
|
// Token Milestones
|
||||||
|
| "FirstSteps" // 1,000 tokens
|
||||||
|
| "GrowingStrong" // 10,000 tokens
|
||||||
|
| "BlossomingCoder" // 100,000 tokens
|
||||||
|
| "TokenMaster" // 1,000,000 tokens
|
||||||
|
// Code Generation
|
||||||
|
| "HelloWorld" // First code block
|
||||||
|
| "CodeWizard" // 100 code blocks
|
||||||
|
| "ThousandBlocks" // 1,000 code blocks
|
||||||
|
// File Operations
|
||||||
|
| "FileManipulator" // 10 files edited
|
||||||
|
| "FileArchitect" // 100 files edited
|
||||||
|
// Conversation milestones
|
||||||
|
| "ConversationStarter" // 10 messages
|
||||||
|
| "ChattyKathy" // 100 messages
|
||||||
|
| "Conversationalist" // 1,000 messages
|
||||||
|
// Tool usage
|
||||||
|
| "Toolsmith" // 5 different tools
|
||||||
|
| "ToolMaster" // 10 different tools
|
||||||
|
// Time-based achievements
|
||||||
|
| "EarlyBird" // Started session 5-7 AM
|
||||||
|
| "NightOwl" // Coding after midnight
|
||||||
|
| "AllNighter" // Worked 2-5 AM
|
||||||
|
| "WeekendWarrior" // Coding on weekend
|
||||||
|
| "DedicatedDeveloper" // 30 days in a row
|
||||||
|
// Search and exploration
|
||||||
|
| "Explorer" // 50 searches
|
||||||
|
| "MasterSearcher" // 500 searches
|
||||||
|
// Session achievements
|
||||||
|
| "QuickSession" // Productive session < 5 min
|
||||||
|
| "FocusedWork" // 30 min session
|
||||||
|
| "DeepDive" // 2 hour session
|
||||||
|
| "MarathonSession" // 5+ hour session
|
||||||
|
// Special achievements
|
||||||
|
| "FirstMessage" // First message sent
|
||||||
|
| "FirstTool" // First tool used
|
||||||
|
| "FirstCodeBlock" // First code generated
|
||||||
|
| "FirstFileEdit" // First file edit
|
||||||
|
| "Polyglot" // 5+ languages in one session
|
||||||
|
| "SpeedCoder" // 10 code blocks in 10 minutes
|
||||||
|
| "ClaudeConnoisseur" // Used all Claude models
|
||||||
|
| "MarathonCoder" // 10k tokens in one session
|
||||||
|
// Relationship & Greetings
|
||||||
|
| "GoodMorning" // Said good morning
|
||||||
|
| "GoodNight" // Said good night
|
||||||
|
| "ThankYou" // Said thank you
|
||||||
|
| "LoveYou" // Said love you
|
||||||
|
// Personality & Fun
|
||||||
|
| "EmojiUser" // Used 20+ emojis
|
||||||
|
| "CapsLock" // ALL CAPS MESSAGE
|
||||||
|
| "QuestionMaster" // Asked 50 questions
|
||||||
|
| "PleaseAndThankYou" // Polite user
|
||||||
|
// Git & Development
|
||||||
|
| "CommitMaster" // 100 commits
|
||||||
|
| "PRO" // Created 10 PRs
|
||||||
|
| "Reviewer" // Reviewed 10 PRs
|
||||||
|
| "IssueTracker" // Created 25 issues
|
||||||
|
| "GitGuru" // Used git commands
|
||||||
|
// Tool Mastery
|
||||||
|
| "BashMaster" // Used bash 100 times
|
||||||
|
| "FileExplorer" // Searched files 100 times
|
||||||
|
| "SearchExpert" // Advanced searches
|
||||||
|
| "AgentCommander" // Used task agents
|
||||||
|
| "MCPMaster"; // Used MCP tools
|
||||||
|
|
||||||
|
export interface Achievement {
|
||||||
|
id: AchievementId;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
icon: string;
|
||||||
|
rarity: "common" | "rare" | "epic" | "legendary";
|
||||||
|
unlocked: boolean;
|
||||||
|
unlockedAt?: Date;
|
||||||
|
progress?: number;
|
||||||
|
maxProgress?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AchievementCategory {
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
achievements: Achievement[];
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
export interface MessageMode {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
prefix?: string;
|
||||||
|
icon: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const MESSAGE_MODES: MessageMode[] = [
|
||||||
|
{
|
||||||
|
id: "chat",
|
||||||
|
name: "Chat",
|
||||||
|
description: "Normal conversation mode",
|
||||||
|
icon: "💬",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "architect",
|
||||||
|
name: "Architect",
|
||||||
|
description: "High-level design and architecture planning",
|
||||||
|
prefix: "[Architect Mode] ",
|
||||||
|
icon: "🏗️",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "code",
|
||||||
|
name: "Code",
|
||||||
|
description: "Focused on writing and editing code",
|
||||||
|
prefix: "[Code Mode] ",
|
||||||
|
icon: "💻",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "debug",
|
||||||
|
name: "Debug",
|
||||||
|
description: "Help with debugging and troubleshooting",
|
||||||
|
prefix: "[Debug Mode] ",
|
||||||
|
icon: "🐛",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "ask",
|
||||||
|
name: "Ask",
|
||||||
|
description: "Technical questions and explanations",
|
||||||
|
prefix: "[Ask Mode] ",
|
||||||
|
icon: "❓",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "review",
|
||||||
|
name: "Review",
|
||||||
|
description: "Code review and feedback",
|
||||||
|
prefix: "[Review Mode] ",
|
||||||
|
icon: "👀",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export function getMessageMode(id: string): MessageMode | undefined {
|
||||||
|
return MESSAGE_MODES.find((mode) => mode.id === id);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatMessageWithMode(message: string, modeId: string): string {
|
||||||
|
const mode = getMessageMode(modeId);
|
||||||
|
if (!mode || !mode.prefix) {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't double-prefix if the message already starts with the prefix
|
||||||
|
if (message.startsWith(mode.prefix)) {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mode.prefix + message;
|
||||||
|
}
|
||||||
@@ -1,3 +1,11 @@
|
|||||||
|
export interface TerminalLine {
|
||||||
|
id: string;
|
||||||
|
type: "user" | "assistant" | "system" | "tool" | "error";
|
||||||
|
content: string;
|
||||||
|
timestamp: Date;
|
||||||
|
toolName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface SystemInitMessage {
|
export interface SystemInitMessage {
|
||||||
type: "system";
|
type: "system";
|
||||||
subtype: "init";
|
subtype: "init";
|
||||||
@@ -115,6 +123,7 @@ export interface PermissionPromptEvent {
|
|||||||
tool_name: string;
|
tool_name: string;
|
||||||
tool_input: Record<string, unknown>;
|
tool_input: Record<string, unknown>;
|
||||||
description: string;
|
description: string;
|
||||||
|
conversation_id?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ConnectionStatus = "disconnected" | "connecting" | "connected" | "error";
|
export type ConnectionStatus = "disconnected" | "connecting" | "connected" | "error";
|
||||||
|
|||||||
@@ -1,26 +1,52 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte";
|
import { onMount, onDestroy } from "svelte";
|
||||||
import { initializeTauriListeners } from "$lib/tauri";
|
import { initializeTauriListeners, cleanupTauriListeners } from "$lib/tauri";
|
||||||
import { configStore, applyTheme } from "$lib/stores/config";
|
import { configStore, applyTheme } from "$lib/stores/config";
|
||||||
|
import { initNotificationSync, cleanupNotificationSync } from "$lib/stores/notifications";
|
||||||
|
import { conversationsStore } from "$lib/stores/conversations";
|
||||||
|
import "$lib/notifications/testNotifications";
|
||||||
import Terminal from "$lib/components/Terminal.svelte";
|
import Terminal from "$lib/components/Terminal.svelte";
|
||||||
import InputBar from "$lib/components/InputBar.svelte";
|
import InputBar from "$lib/components/InputBar.svelte";
|
||||||
import StatusBar from "$lib/components/StatusBar.svelte";
|
import StatusBar from "$lib/components/StatusBar.svelte";
|
||||||
import AnimeGirl from "$lib/components/AnimeGirl.svelte";
|
import AnimeGirl from "$lib/components/AnimeGirl.svelte";
|
||||||
import PermissionModal from "$lib/components/PermissionModal.svelte";
|
import PermissionModal from "$lib/components/PermissionModal.svelte";
|
||||||
import ConfigSidebar from "$lib/components/ConfigSidebar.svelte";
|
import ConfigSidebar from "$lib/components/ConfigSidebar.svelte";
|
||||||
|
import AchievementNotification from "$lib/components/AchievementNotification.svelte";
|
||||||
|
import AchievementsPanel from "$lib/components/AchievementsPanel.svelte";
|
||||||
|
|
||||||
|
let initialized = false;
|
||||||
|
let achievementPanelOpen = $state(false);
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await initializeTauriListeners();
|
if (!initialized) {
|
||||||
await configStore.loadConfig();
|
initialized = true;
|
||||||
|
|
||||||
// Apply saved theme on startup
|
// Initialize conversations store first to ensure activeConversationId is set
|
||||||
const config = configStore.getConfig();
|
conversationsStore.initialize();
|
||||||
applyTheme(config.theme);
|
|
||||||
|
await initializeTauriListeners();
|
||||||
|
await configStore.loadConfig();
|
||||||
|
|
||||||
|
// Apply saved theme on startup
|
||||||
|
const config = configStore.getConfig();
|
||||||
|
applyTheme(config.theme);
|
||||||
|
|
||||||
|
// Initialize notification settings sync
|
||||||
|
initNotificationSync();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
if (initialized) {
|
||||||
|
cleanupTauriListeners();
|
||||||
|
cleanupNotificationSync();
|
||||||
|
initialized = false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="app-container h-screen w-screen flex flex-col bg-[var(--bg-primary)] overflow-hidden">
|
<div class="app-container h-screen w-screen flex flex-col bg-[var(--bg-primary)] overflow-hidden">
|
||||||
<StatusBar />
|
<StatusBar onToggleAchievements={() => (achievementPanelOpen = !achievementPanelOpen)} />
|
||||||
|
|
||||||
<main class="flex-1 flex overflow-hidden">
|
<main class="flex-1 flex overflow-hidden">
|
||||||
<!-- Left panel: Character display -->
|
<!-- Left panel: Character display -->
|
||||||
@@ -39,6 +65,11 @@
|
|||||||
|
|
||||||
<PermissionModal />
|
<PermissionModal />
|
||||||
<ConfigSidebar />
|
<ConfigSidebar />
|
||||||
|
<AchievementNotification />
|
||||||
|
<AchievementsPanel
|
||||||
|
bind:isOpen={achievementPanelOpen}
|
||||||
|
onClose={() => (achievementPanelOpen = false)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { testAchievementSound } from "$lib/sounds/achievement";
|
||||||
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
|
||||||
|
async function testSound() {
|
||||||
|
testAchievementSound();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function triggerAchievement() {
|
||||||
|
// This will trigger an achievement that hasn't been unlocked yet
|
||||||
|
try {
|
||||||
|
await invoke("check_achievements", {
|
||||||
|
eventType: "message_sent",
|
||||||
|
data: {},
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to trigger achievement:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="container mx-auto p-8">
|
||||||
|
<h1 class="text-2xl font-bold mb-6">Achievement Sound Test</h1>
|
||||||
|
|
||||||
|
<div class="space-y-4">
|
||||||
|
<button
|
||||||
|
onclick={testSound}
|
||||||
|
class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 transition-colors"
|
||||||
|
>
|
||||||
|
Test Achievement Sound
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onclick={triggerAchievement}
|
||||||
|
class="px-4 py-2 bg-green-500 text-white rounded hover:bg-green-600 transition-colors"
|
||||||
|
>
|
||||||
|
Trigger Test Achievement
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<p class="text-sm text-gray-600 dark:text-gray-400 mt-4">
|
||||||
|
Click the first button to test just the sound effect.<br />
|
||||||
|
Click the second button to trigger a real achievement (if any are available to unlock).
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Notification Sound Test</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
max-width: 600px;
|
||||||
|
margin: 50px auto;
|
||||||
|
padding: 20px;
|
||||||
|
background: #1a1a1a;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.test-button {
|
||||||
|
padding: 10px 20px;
|
||||||
|
margin: 10px;
|
||||||
|
background: #0066ff;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 5px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
.test-button:hover {
|
||||||
|
background: #0052cc;
|
||||||
|
}
|
||||||
|
.info {
|
||||||
|
margin-top: 20px;
|
||||||
|
padding: 15px;
|
||||||
|
background: #333;
|
||||||
|
border-radius: 5px;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
.sound-item {
|
||||||
|
margin: 10px 0;
|
||||||
|
padding: 10px;
|
||||||
|
background: #2a2a2a;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>🎵 Hikari Notification Test Page</h1>
|
||||||
|
|
||||||
|
<div class="info">
|
||||||
|
<h2>Required Sound Files:</h2>
|
||||||
|
<p>Please generate these TTS sounds and place them in <code>/static/sounds/</code>:</p>
|
||||||
|
|
||||||
|
<div class="sound-item">
|
||||||
|
<strong>im-done.mp3</strong> - "I'm done!" (cheerful, accomplished)
|
||||||
|
</div>
|
||||||
|
<div class="sound-item">
|
||||||
|
<strong>oh-no.mp3</strong> - "Oh no..." (concerned, but not panicked)
|
||||||
|
</div>
|
||||||
|
<div class="sound-item">
|
||||||
|
<strong>access-please.mp3</strong> - "Access please!" (polite, questioning)
|
||||||
|
</div>
|
||||||
|
<div class="sound-item"><strong>connected.mp3</strong> - "Connected!" (happy, energetic)</div>
|
||||||
|
<div class="sound-item">
|
||||||
|
<strong>working-on-it.mp3</strong> - "Working on it!" (determined, focused)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h2>Test Sounds:</h2>
|
||||||
|
<p>Click to test each notification sound (once files are in place):</p>
|
||||||
|
|
||||||
|
<button class="test-button" onclick="playSound('im-done.mp3')">Success - "I'm done!"</button>
|
||||||
|
<button class="test-button" onclick="playSound('oh-no.mp3')">Error - "Oh no..."</button>
|
||||||
|
<button class="test-button" onclick="playSound('access-please.mp3')">
|
||||||
|
Permission - "Access please!"
|
||||||
|
</button>
|
||||||
|
<button class="test-button" onclick="playSound('connected.mp3')">
|
||||||
|
Connection - "Connected!"
|
||||||
|
</button>
|
||||||
|
<button class="test-button" onclick="playSound('working-on-it.mp3')">
|
||||||
|
Task Start - "Working on it!"
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function playSound(filename) {
|
||||||
|
const audio = new Audio("/sounds/" + filename);
|
||||||
|
audio.volume = 0.7;
|
||||||
|
audio.play().catch((err) => {
|
||||||
|
alert(
|
||||||
|
"Sound file not found: " + filename + "\n\nPlease add the sound file to /static/sounds/"
|
||||||
|
);
|
||||||
|
console.error("Audio playback failed:", err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
Before Width: | Height: | Size: 680 KiB After Width: | Height: | Size: 680 KiB |
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 442 KiB |
|
Before Width: | Height: | Size: 414 KiB After Width: | Height: | Size: 413 KiB |
|
Before Width: | Height: | Size: 778 KiB After Width: | Height: | Size: 777 KiB |