Compare commits

..

18 Commits

Author SHA1 Message Date
javis-bot
1f2a8ec05e chore(app): version 0.1.14
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 12:20:33 +09:00
javis-bot
04b516dbc1 feat(app): 한 일 as a view of the 로그 screen, shortcuts to a left-behind copy start the current Jarvis
The 한 일 screen is gone: 로그 has 로그 and 한 일 views switched at the top.

An update before 0.1.12 could install into Program Files while the desktop
shortcut kept pointing at the first install's folder, an old copy that no
update reaches: its jarvis.exe shows the old icon and starts a second, old
Jarvis next to the running one. The installer now points every desktop and
start menu shortcut to another Jarvis install's jarvis.exe at this install.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 12:20:33 +09:00
javis-bot
b386c905b2 chore(app): version 0.1.13
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 12:04:00 +09:00
javis-bot
b29150a767 feat(app): updates on the 앱 screen, traces that fill in live on 대화
The separate 업데이트 screen is gone: its card is first on the 앱 screen
and a newer release renames the 앱 button. On 대화 a trace appears when
the question is recognised, opens and fills in step by step (re-read
every second while one is being made) and stays open with its answer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 12:03:45 +09:00
javis-bot
6fc3ad3d57 feat(worker): answer traces stored from the question on and filled in as the answer is made
A trace is now kept the moment the request arrives (at the time it was
asked, ms -1), its steps are stored as the engine adds each one, and it
ends with the answer. Traces a killed run left unfinished are closed at
start. The 대화 screen reads a trace still being made as pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 12:03:45 +09:00
javis-bot
fd7ccab55b fix(app): shortcut icons in start menu folders and any install folder, updates go where Jarvis is
- The icon pass also walks the start menus' folders, so a shortcut kept
  in one (and a later icon change) is not missed.
- The install folder and icon path reach PowerShell through the
  environment: a folder name with an apostrophe broke the whole command.
  A failure is now a line in the install details.
- InstallDirRegKey read the 32-bit registry view before .onInit switched
  to the 64-bit one where the folder is written, so a silent update of
  Jarvis installed elsewhere put a second copy in Program Files. .onInit
  now reads the 64-bit key; a folder given with /D wins.
- Version 0.1.12.

Checked on the Windows VM with Jarvis 0.1.6 in C:\Tools\Kim's Jarvis and
shortcuts on both desktops and in start menu subfolders: 0.1.11 left the
desktop and subfolder shortcuts old; 0.1.12 (no /D) updated that folder
and every shortcut, and a fresh 0.1.12 still goes to Program Files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 10:56:24 +09:00
javis-bot
2b832c1c3b feat(app): 앱 last in the side menu, version 0.1.11
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 10:47:03 +09:00
javis-bot
3d8801b691 chore(app): version 0.1.10
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 10:42:09 +09:00
javis-bot
1a12755649 feat(app): 대화 under 대시보드, a current session view, shortcuts that follow the app icon
- The side menu has 대화 right under 대시보드.
- 대화 screen: a "현재 세션" chip (off by default) shows only what came
  since the bot was last started. The controller keeps when the latest
  start began; history_query takes `session` and answers it back, so the
  count line names that start and a new start starts the list over.
- Installer: the shortcuts' icon is a file named by its content
  (jarvis-<sha256 prefix>.ico). Windows keeps an icon it has shown by its
  path, so after an update the desktop shortcuts kept the old icon. Every
  .lnk to jarvis.exe on the desktops and in the start menus (an earlier
  version's and the person's own too) now points at the new file, set by
  the 64-bit PowerShell: a 32-bit one reads Program Files links as
  Program Files (x86). Checked on the Windows VM: 0.1.6 to 0.1.9 left both
  desktop shortcuts old; to this build they and search show the new icon.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 10:42:09 +09:00
javis-bot
fbdf274b9d chore(app): version 0.1.9, an installer that starts
The 0.1.7 and 0.1.8 installers were built with NSIS 3.0.4.1 stubs under
makensis 3.10 and crashed at start (0xC0000005) before installing
anything. 0.1.9 is the same app built with makensis's own stubs, checked
on the Windows VM: silent install, the close button set to tray hides
the window and a second start shows it, the tray icon shows it again,
the real X hides it, the tray menu's 완전 종료 quits, and the close
button set to quit exits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 09:56:33 +09:00
javis-bot
2a6b350079 feat(app): app icon, close button to quit or hide to the tray, one Jarvis at a time
- New icon (voice bars in a ring on the accent gradient; three thicker
  bars at 32 px and below) for the program file, window, taskbar,
  installer and a tray icon of its own.
- 앱 settings screen with app.closeButton: "quit" (default, as before)
  or "tray", read each time X is pressed (no restart). Tray mode only
  hides the window; the bot and services keep running. The tray icon is
  always there: a left click shows the window, its menu has 열기 and
  완전 종료 (the same stop-then-exit as closing).
- tauri-plugin-single-instance: starting Jarvis again while it runs
  shows the running one's window instead of a second app driving the
  same services.
- Version 0.1.8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 09:37:08 +09:00
javis-bot
53d522db69 fix(app): update screen no longer shows "null" when there is no new version
The update screen passed a missing release-notes card straight to the
DOM's replaceChildren, which writes null as the text "null" (h() skips
nulls, replaceChildren does not). Version 0.1.7, which also carries the
대화 screen and the kept answer traces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 09:24:50 +09:00
javis-bot
6c1bc31236 fix(app): 대화 screen keeps loaded pages when new items fill the window and loads one older page at a time
- paging moves to app/ui/talk.js (pure, node --test app/tests/ui/talk.test.mjs)
- items the full live window no longer reaches join the older pages instead of being dropped
- "이전 기록 더 보기" runs one request at a time and never adds a loaded item twice
- the screen and spec state that only the newest 2,000 items are re-read live

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 07:13:35 +09:00
javis-bot
27fcea4e3d fix(app): 대화 screen pages back without limit, shows edits and drops stale answers
- history_query takes item cursors (before / from) ordered by time, source and id,
  so paging never skips or repeats an item and has no 2,000 item ceiling
- live refresh re-reads the window from the oldest item shown and compares whole
  items, so an edited message is redrawn
- answers to requests made before a filter change, and live answers older than
  the newest one asked, are dropped

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 07:07:20 +09:00
javis-bot
46f71e7f03 feat(app): 대화 screen to read what people said, Jarvis's answers and how each answer was made
The management app reads the worker's history store (read only) and shows
people's words, Jarvis's answers and the answer traces in time order, with
filters for kind, place, person, channel, day and text, live follow, older
items on demand and expandable traces (records given, tools offered, plan,
model thinking, tool calls and results).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 03:08:38 +09:00
javis-bot
a20ebe4eae feat(brain): keep how each answer was made (records, tools, plan, thinking, tool calls)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 03:00:10 +09:00
javis-bot
2a140d8490 fix(installer): count the uninstall size at build time instead of walking the install folder
The setup ran GetSize on the whole install folder for the uninstall entry's size. With the data
folder kept inside it (models, Python runtime) that walked tens of thousands of files after the
install had already finished, which looked like a hung install. The size of what the setup
installs is now counted by installer.sh and passed in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 02:48:24 +09:00
javis-bot
27eb1315b9 fix(tts): MeloTTS speaks up to 1.25 itself so fast speech sounds natural
Stretching all of the speed-up from 1.0 kept every sound but sounded
awkward (UTMOS 3.13 at 1.5, against 3.73 for MeloTTS's own 1.5), while
MeloTTS's own speed past 1.25 drops sounds (sentence-final "요" and first
syllables, 4.6% character errors at 1.5). MeloTTS now speaks up to 1.25
and the WSOLA stretch does only the rest, with a 5 ms search: 2.6% and
UTMOS 3.56 at 1.5 through the real child. Version 0.1.6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 00:06:52 +09:00
38 changed files with 2131 additions and 94 deletions

View File

@@ -32,7 +32,7 @@ Any code change must either adhere to our spec files perfectly or you should ask
| `src/jarvis/tools/builtin/nutrition/log_meal.spec.md` | logMeal tool: single-property schema for planner fast-path, internal nutrition extraction, untrusted-data fence, follow-ups | Public schema is a single optional `meal` string; nutrition fields are internal; user text is fenced as data |
| `src/jarvis/utils/location.spec.md` | GeoIP location detection | Privacy-first; local GeoLite2 DB only |
| `src/jarvis/memory/graph.spec.md` | Node graph memory (v2), self-organising tree, UI explorer | Dynamic structure; access-aware; auto-split/merge (future) |
| `src/jarvis/memory/history.spec.md` | v2 conversation history store: voice transcripts, answers and registered chat channel messages; per-asker scope (own, chat channels, others only while co-present); language-agnostic prefix search; size-budgeted context for the reply engine | Only what the asker may see; logs carry no record text; whole history searched, little sent |
| `src/jarvis/memory/history.spec.md` | v2 conversation history store: voice transcripts, answers and registered chat channel messages; per-asker scope (own, chat channels, others only while co-present); language-agnostic prefix search; size-budgeted context for the reply engine; answer traces (how each answer was made) for the 대화 screen | Only what the asker may see; traces never reach a prompt; logs carry no record text; whole history searched, little sent |
| `src/jarvis/memory/summariser.spec.md` | Diary summariser prompt contract, hygiene rules (deflection, attribution, topic separation), post-process scrub, and bulk-sweep clean button | Two-layer defence: prompt + deterministic scrub; corrupted summaries poison every downstream consumer |
| `src/jarvis/memory/recall_gate.spec.md` | Deterministic skip-enrichment heuristic when the hot window covers a follow-up | Fail-open; language-agnostic via `\w{3,}` + `re.UNICODE`; planner intent always wins |
| `src/voice_worker/voice_worker.spec.md` | v2 voice worker: multi-speaker streaming STT (shared Whisper, batched) and sentence TTS over a local WebSocket | Loopback only with an app token; no transcript text in logs; finals before partials; language-agnostic |

70
app/Cargo.lock generated
View File

@@ -744,6 +744,18 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af9673d8203fcb076b19dfd17e38b3d4ae9f44959416ea532ce72415a6020365"
[[package]]
name = "fallible-iterator"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649"
[[package]]
name = "fallible-streaming-iterator"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
[[package]]
name = "fastrand"
version = "2.5.0"
@@ -816,6 +828,12 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "foldhash"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
[[package]]
name = "form_urlencoded"
version = "1.2.2"
@@ -1024,12 +1042,30 @@ version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
[[package]]
name = "hashbrown"
version = "0.15.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
dependencies = [
"foldhash",
]
[[package]]
name = "hashbrown"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
[[package]]
name = "hashlink"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1"
dependencies = [
"hashbrown 0.15.5",
]
[[package]]
name = "hashmap_derive"
version = "0.1.0"
@@ -1484,7 +1520,7 @@ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
[[package]]
name = "jarvis-app"
version = "0.1.5"
version = "0.1.14"
dependencies = [
"async-trait",
"base64 0.22.1",
@@ -1497,6 +1533,7 @@ dependencies = [
"opus2",
"rand 0.9.5",
"reqwest",
"rusqlite",
"serde",
"serde_json",
"serenity",
@@ -1786,6 +1823,17 @@ dependencies = [
"pkg-config",
]
[[package]]
name = "libsqlite3-sys"
version = "0.35.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "133c182a6a2c87864fe97778797e46c7e999672690dc9fa3ee8e241aa4a9c13f"
dependencies = [
"cc",
"pkg-config",
"vcpkg",
]
[[package]]
name = "linux-raw-sys"
version = "0.12.1"
@@ -2756,6 +2804,20 @@ dependencies = [
"realfft",
]
[[package]]
name = "rusqlite"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "165ca6e57b20e1351573e3729b958bc62f0e48025386970b6e4d29e7a7e71f3f"
dependencies = [
"bitflags 2.13.2",
"fallible-iterator",
"fallible-streaming-iterator",
"hashlink",
"libsqlite3-sys",
"smallvec",
]
[[package]]
name = "rustc-hash"
version = "2.1.3"
@@ -4108,6 +4170,12 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "version_check"
version = "0.9.5"

View File

@@ -1,6 +1,6 @@
[package]
name = "jarvis-app"
version = "0.1.5"
version = "0.1.14"
edition = "2021"
rust-version = "1.85"
description = "Jarvis v2 Windows app core: Discord voice, voice worker supervisor, chat channels"
@@ -35,6 +35,7 @@ chrono = { version = "0.4", default-features = false, features = ["clock", "std"
zip = { version = "9", default-features = false, features = ["deflate"] }
unicode-normalization = "0.1"
jpeg-encoder = "0.6"
rusqlite = { version = "0.37", features = ["bundled"] }
[dev-dependencies]
jpeg-decoder = "0.3"

531
app/shell/Cargo.lock generated
View File

@@ -91,6 +91,126 @@ dependencies = [
"serde",
]
[[package]]
name = "async-broadcast"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "435a87a52755b8f27fcf321ac4f04b2802e337c8c4872923137471ec39c37532"
dependencies = [
"event-listener",
"event-listener-strategy",
"futures-core",
"pin-project-lite",
]
[[package]]
name = "async-channel"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "924ed96dd52d1b75e9c1a3e6275715fd320f5f9439fb5a4a11fa51f4221158d2"
dependencies = [
"concurrent-queue",
"event-listener-strategy",
"futures-core",
"pin-project-lite",
]
[[package]]
name = "async-executor"
version = "1.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f426a31126c735126297bc5ea7a521263c9faff4f63ca415267ee625651c4f37"
dependencies = [
"async-task",
"concurrent-queue",
"fastrand",
"futures-lite",
"pin-project-lite",
"slab",
]
[[package]]
name = "async-io"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "456b8a8feb6f42d237746d4b3e9a178494627745c3c56c6ea55d92ba50d026fc"
dependencies = [
"autocfg",
"cfg-if",
"concurrent-queue",
"futures-io",
"futures-lite",
"parking",
"polling",
"rustix",
"slab",
"windows-sys 0.61.2",
]
[[package]]
name = "async-lock"
version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0876700b0d007ad25d5508865a4259c3af9af6d296bf663a0d586d0bc3369f6f"
dependencies = [
"event-listener",
"event-listener-strategy",
"pin-project-lite",
]
[[package]]
name = "async-process"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc50921ec0055cdd8a16de48773bfeec5c972598674347252c0399676be7da75"
dependencies = [
"async-channel",
"async-io",
"async-lock",
"async-signal",
"async-task",
"blocking",
"cfg-if",
"event-listener",
"futures-lite",
"rustix",
]
[[package]]
name = "async-recursion"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f8abc12baad266b1c8cec146854c195b5864b4221d4b2ca7296a7ae82d9e451"
dependencies = [
"proc-macro2",
"quote",
"syn 3.0.10",
]
[[package]]
name = "async-signal"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52b5aaafa020cf5053a01f2a60e8ff5dccf550f0f77ec54a4e47285ac2bab485"
dependencies = [
"async-io",
"async-lock",
"atomic-waker",
"cfg-if",
"futures-core",
"futures-io",
"rustix",
"signal-hook-registry",
"slab",
"windows-sys 0.61.2",
]
[[package]]
name = "async-task"
version = "4.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de"
[[package]]
name = "async-trait"
version = "0.1.92"
@@ -230,6 +350,19 @@ dependencies = [
"objc2",
]
[[package]]
name = "blocking"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a70e4329df6cb94385eed412ec92375c3cdd8a6e502493d1229b6414e4036dfa"
dependencies = [
"async-channel",
"async-task",
"futures-io",
"futures-lite",
"piper",
]
[[package]]
name = "brotli"
version = "9.1.1"
@@ -278,6 +411,12 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "byteorder-lite"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
[[package]]
name = "bytes"
version = "1.12.1"
@@ -481,6 +620,15 @@ dependencies = [
"memchr",
]
[[package]]
name = "concurrent-queue"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "const-oid"
version = "0.9.6"
@@ -1059,7 +1207,7 @@ checksum = "fac5fca71e65e94cc718a6e2af65d6e0f9c6027751c2aa562fbb5087fda639bc"
dependencies = [
"bit-set 0.8.0",
"cssparser 0.37.0",
"foldhash",
"foldhash 0.2.0",
"html5ever 0.39.0",
"precomputed-hash",
"selectors 0.38.0",
@@ -1074,7 +1222,7 @@ checksum = "498c698ac51127148a3984450e51fca7f01805a91d7a1f7a24af0a5f761e3385"
dependencies = [
"bit-set 0.11.1",
"cssparser 0.38.0",
"foldhash",
"foldhash 0.2.0",
"html5ever 0.40.1",
"precomputed-hash",
"selectors 0.41.0",
@@ -1217,6 +1365,12 @@ dependencies = [
"simdutf8",
]
[[package]]
name = "endi"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66b7e2430c6dff6a955451e2cfc438f09cea1965a9d6f87f7e3b90decc014099"
[[package]]
name = "enum-map"
version = "2.7.3"
@@ -1237,6 +1391,27 @@ dependencies = [
"syn 2.0.119",
]
[[package]]
name = "enumflags2"
version = "0.7.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1027f7680c853e056ebcec683615fb6fbbc07dbaa13b4d5d9442b146ded4ecef"
dependencies = [
"enumflags2_derive",
"serde",
]
[[package]]
name = "enumflags2_derive"
version = "0.7.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67c78a4d8fdf9953a5c9d458f9efe940fd97a0cab0941c075a813ac594733827"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
]
[[package]]
name = "equivalent"
version = "1.0.3"
@@ -1264,12 +1439,44 @@ dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "event-listener"
version = "5.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a23add41df1562121a9393cb065eab5146a1242410f23a644851e90cfd669d2"
dependencies = [
"parking",
"pin-project-lite",
]
[[package]]
name = "event-listener-strategy"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93"
dependencies = [
"event-listener",
"pin-project-lite",
]
[[package]]
name = "extended"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af9673d8203fcb076b19dfd17e38b3d4ae9f44959416ea532ce72415a6020365"
[[package]]
name = "fallible-iterator"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649"
[[package]]
name = "fallible-streaming-iterator"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
[[package]]
name = "fastrand"
version = "2.5.0"
@@ -1361,6 +1568,12 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "foldhash"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
[[package]]
name = "foldhash"
version = "0.2.0"
@@ -1470,6 +1683,19 @@ version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed"
[[package]]
name = "futures-lite"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad"
dependencies = [
"fastrand",
"futures-core",
"futures-io",
"parking",
"pin-project-lite",
]
[[package]]
name = "futures-macro"
version = "0.3.34"
@@ -1855,12 +2081,30 @@ version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
[[package]]
name = "hashbrown"
version = "0.15.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
dependencies = [
"foldhash 0.1.5",
]
[[package]]
name = "hashbrown"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
[[package]]
name = "hashlink"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1"
dependencies = [
"hashbrown 0.15.5",
]
[[package]]
name = "hashmap_derive"
version = "0.1.0"
@@ -2313,6 +2557,19 @@ dependencies = [
"icu_properties",
]
[[package]]
name = "image"
version = "0.25.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85ab80394333c02fe689eaf900ab500fbd0c2213da414687ebf995a65d5a6104"
dependencies = [
"bytemuck",
"byteorder-lite",
"moxcms",
"num-traits",
"png",
]
[[package]]
name = "indexmap"
version = "1.9.3"
@@ -2380,7 +2637,7 @@ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
[[package]]
name = "jarvis-app"
version = "0.1.5"
version = "0.1.14"
dependencies = [
"async-trait",
"base64 0.22.1",
@@ -2392,6 +2649,7 @@ dependencies = [
"opus2",
"rand 0.9.5",
"reqwest 0.12.28",
"rusqlite",
"serde",
"serde_json",
"serenity",
@@ -2408,12 +2666,13 @@ dependencies = [
[[package]]
name = "jarvis-shell"
version = "0.1.5"
version = "0.1.14"
dependencies = [
"jarvis-app",
"serde_json",
"tauri",
"tauri-build",
"tauri-plugin-single-instance",
"tokio",
]
@@ -2886,6 +3145,17 @@ dependencies = [
"libc",
]
[[package]]
name = "libsqlite3-sys"
version = "0.35.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "133c182a6a2c87864fe97778797e46c7e999672690dc9fa3ee8e241aa4a9c13f"
dependencies = [
"cc",
"pkg-config",
"vcpkg",
]
[[package]]
name = "linux-raw-sys"
version = "0.12.1"
@@ -3027,6 +3297,16 @@ dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "moxcms"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb85c154ba489f01b25c0d36ae69a87e4a1c73a72631fc6c0eb6dde34a73e44b"
dependencies = [
"num-traits",
"pxfm",
]
[[package]]
name = "muda"
version = "0.20.0"
@@ -3542,6 +3822,16 @@ dependencies = [
"num-traits",
]
[[package]]
name = "ordered-stream"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9aa2b01e1d916879f73a53d01d1d6cee68adbb31d6d9177a8cfce093cced1d50"
dependencies = [
"futures-core",
"pin-project-lite",
]
[[package]]
name = "p256"
version = "0.13.2"
@@ -3589,6 +3879,12 @@ dependencies = [
"system-deps",
]
[[package]]
name = "parking"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba"
[[package]]
name = "parking_lot"
version = "0.11.2"
@@ -3815,6 +4111,17 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13bee6c73da26345c729282832b60b0363cf3dd9f4bfd81d8551b7a1c889a113"
[[package]]
name = "piper"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c835479a4443ded371d6c535cbfd8d31ad92c5d23ae9770a61bc155e4992a3c1"
dependencies = [
"atomic-waker",
"fastrand",
"futures-io",
]
[[package]]
name = "pkcs8"
version = "0.10.2"
@@ -3887,6 +4194,20 @@ dependencies = [
"miniz_oxide 0.8.9",
]
[[package]]
name = "polling"
version = "3.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d0e4f59085d47d8241c88ead0f274e8a0cb551f3625263c05eb8dd897c34218"
dependencies = [
"cfg-if",
"concurrent-queue",
"hermit-abi",
"pin-project-lite",
"rustix",
"windows-sys 0.61.2",
]
[[package]]
name = "poly1305"
version = "0.8.0"
@@ -3993,6 +4314,15 @@ dependencies = [
"toml_edit 0.20.2",
]
[[package]]
name = "proc-macro-crate"
version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f"
dependencies = [
"toml_edit 0.25.19+spec-1.1.0",
]
[[package]]
name = "proc-macro-error"
version = "1.0.4"
@@ -4048,6 +4378,12 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "pxfm"
version = "0.1.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0c5ccf5294c6ccd63a74f1565028353830a9c2f5eb0c682c355c471726a6e3f"
[[package]]
name = "quick-xml"
version = "0.42.0"
@@ -4464,6 +4800,20 @@ dependencies = [
"realfft",
]
[[package]]
name = "rusqlite"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "165ca6e57b20e1351573e3729b958bc62f0e48025386970b6e4d29e7a7e71f3f"
dependencies = [
"bitflags 2.13.2",
"fallible-iterator",
"fallible-streaming-iterator",
"hashlink",
"libsqlite3-sys",
"smallvec",
]
[[package]]
name = "rustc-hash"
version = "2.1.3"
@@ -5657,6 +6007,7 @@ dependencies = [
"gtk",
"heck 0.5.0",
"http",
"image",
"jni",
"libc",
"log",
@@ -5755,6 +6106,22 @@ dependencies = [
"tauri-utils",
]
[[package]]
name = "tauri-plugin-single-instance"
version = "2.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "726b6da0dd5bd1344f84f4108a622c07d01923baacb5c803a605189672c5352f"
dependencies = [
"serde",
"serde_json",
"tauri",
"thiserror 2.0.21",
"tokio",
"tracing",
"windows-sys 0.61.2",
"zbus",
]
[[package]]
name = "tauri-runtime"
version = "2.12.2"
@@ -5854,6 +6221,19 @@ dependencies = [
"toml 1.2.1+spec-1.1.0",
]
[[package]]
name = "tempfile"
version = "3.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
dependencies = [
"fastrand",
"getrandom 0.4.3",
"once_cell",
"rustix",
"windows-sys 0.61.2",
]
[[package]]
name = "tendril"
version = "0.5.1"
@@ -6189,6 +6569,18 @@ dependencies = [
"winnow 0.5.40",
]
[[package]]
name = "toml_edit"
version = "0.25.19+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd43688c4858d7264ae1cf9a9f874a67c3feb74a883b1cd7bebd6a4ea8307218"
dependencies = [
"indexmap 2.14.2",
"toml_datetime 1.1.3+spec-1.1.0",
"toml_parser",
"winnow 1.0.5",
]
[[package]]
name = "toml_parser"
version = "1.1.5+spec-1.1.0"
@@ -6466,6 +6858,17 @@ version = "1.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
[[package]]
name = "uds_windows"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2f6fb2847f6742cd76af783a2a2c49e9375d0a111c7bef6f71cd9e738c72d6e"
dependencies = [
"memoffset",
"tempfile",
"windows-sys 0.61.2",
]
[[package]]
name = "unicase"
version = "2.10.0"
@@ -6573,6 +6976,12 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "version-compare"
version = "0.2.1"
@@ -7254,6 +7663,9 @@ name = "winnow"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c3b93199df0ab874cdf0c6a94f0a0dc3423fe41f1cafb62b8bd7b1deb277aef"
dependencies = [
"memchr",
]
[[package]]
name = "winreg"
@@ -7376,6 +7788,76 @@ dependencies = [
"synstructure",
]
[[package]]
name = "zbus"
version = "5.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5db4be7c075cb421e4b7ee645541604239bd243ba7c357511f4ff3a74b555907"
dependencies = [
"async-broadcast",
"async-executor",
"async-io",
"async-lock",
"async-process",
"async-recursion",
"async-task",
"async-trait",
"blocking",
"enumflags2",
"event-listener",
"futures-core",
"futures-lite",
"hex",
"libc",
"ordered-stream",
"rustix",
"serde",
"serde_repr",
"tracing",
"uds_windows",
"uuid",
"windows-sys 0.61.2",
"winnow 1.0.5",
"zbus_macros",
"zbus_names",
"zvariant",
]
[[package]]
name = "zbus_macros"
version = "5.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2990635d09ade6df1868f72f8cac69a876a90981e8bd3c40b1be413f8dc88f40"
dependencies = [
"proc-macro-crate 3.5.0",
"proc-macro2",
"quote",
"syn 3.0.10",
"zbus_names",
"zvariant",
"zvariant_utils",
]
[[package]]
name = "zbus_names"
version = "4.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "812a12be4ead7a59e18ea8f047d08add0066b73bc62fc1467066a2472ae088dd"
dependencies = [
"serde",
"winnow 1.0.5",
"zvariant",
]
[[package]]
name = "zcheapstr"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "939f186d9ecebe044315a5cb6d6f78568bbc21152adc954d5a0c2f58bdbc9920"
dependencies = [
"serde",
]
[[package]]
name = "zerocopy"
version = "0.8.63"
@@ -7513,3 +7995,44 @@ dependencies = [
"log",
"simd-adler32",
]
[[package]]
name = "zvariant"
version = "5.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80bf6d6cd6a4b601acb64cfb8284cdc643fcfa75ef26ae3c46ec8aa4e8a1fbb7"
dependencies = [
"endi",
"enumflags2",
"serde",
"winnow 1.0.5",
"zcheapstr",
"zvariant_derive",
"zvariant_utils",
]
[[package]]
name = "zvariant_derive"
version = "5.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef2672456ba1cb54b5eaec136e63135b3c7495fb938e53b28a62e633496d486d"
dependencies = [
"proc-macro-crate 3.5.0",
"proc-macro2",
"quote",
"syn 3.0.10",
"zvariant_utils",
]
[[package]]
name = "zvariant_utils"
version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bad0294361a320b694a328460dc73add56c306150f5cb6bfafc44446120008a3"
dependencies = [
"proc-macro2",
"quote",
"serde",
"syn 3.0.10",
"winnow 1.0.5",
]

View File

@@ -1,6 +1,6 @@
[package]
name = "jarvis-shell"
version = "0.1.5"
version = "0.1.14"
edition = "2021"
rust-version = "1.85"
description = "Jarvis v2 management app window (Tauri 2 over the app core's AdminApi)"
@@ -16,7 +16,8 @@ tauri-build = { version = "2", features = [] }
[dependencies]
jarvis-app = { path = ".." }
tauri = { version = "2", features = [] }
tauri = { version = "2", features = ["tray-icon", "image-png"] }
tauri-plugin-single-instance = "2"
serde_json = "1"
tokio = { version = "1", features = ["full"] }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 53 KiB

BIN
app/shell/icons/tray.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -1,5 +1,5 @@
; The Jarvis installer (admin.spec.md, "Installer"). Built on Linux by installer.sh with makensis:
; makensis -DVERSION=0.1.0 -DSRC=<Jarvis folder> -DOUT=<setup.exe> -DICON=<icon.ico> -DWEBVIEW2=<bootstrapper>
; makensis -DVERSION=0.1.0 -DSRC=<Jarvis folder> -DOUT=<setup.exe> -DICON=<icon.ico> -DICON_FILE=<jarvis-<hash>.ico> -DWEBVIEW2=<bootstrapper>
; -DUNINSTALL_LIST=<the Delete/RMDir lines of the installed files> installer.nsi
; Program Files, one administrator prompt; the data folder is chosen by the app's first-run wizard
; and never touched here. /S installs silently (the app's updates: /S /RUN starts the app afterwards).
@@ -19,7 +19,6 @@ SetCompressor /SOLID lzma
Name "Jarvis"
OutFile "${OUT}"
InstallDir "$PROGRAMFILES64\Jarvis"
InstallDirRegKey HKLM "Software\JarvisBot" "InstallDir"
RequestExecutionLevel admin
BrandingText "Jarvis ${VERSION}"
VIProductVersion "${VERSION}.0"
@@ -149,6 +148,13 @@ Function .onInit
Abort
${EndIf}
SetRegView 64
; An update goes where Jarvis is installed (the key is in the 64-bit view, which InstallDirRegKey
; would not read); a folder given with /D wins.
ReadRegStr $0 HKLM "Software\JarvisBot" "InstallDir"
${If} $0 != ""
${AndIf} $INSTDIR == "$PROGRAMFILES64\Jarvis"
StrCpy $INSTDIR $0
${EndIf}
; Shortcuts for every user of the PC, like the Program Files install itself.
SetShellVarContext all
!insertmacro TakeLock
@@ -220,6 +226,10 @@ Section "Jarvis (필수)" SecMain
SetOutPath "$INSTDIR"
File "${SRC}/jarvis.exe"
File "${SRC}/WebView2Loader.dll"
; The shortcuts' icon, named by its content: Windows keeps an icon it has shown by the file's path,
; so a changed icon under the old path would stay the old one on the desktop and in search.
Delete "$INSTDIR\jarvis-*.ico"
File "/oname=${ICON_FILE}" "${ICON}"
File /r "${SRC}/python-src"
File /r "${SRC}/display-driver"
WriteUninstaller "$INSTDIR\uninstall.exe"
@@ -233,16 +243,36 @@ Section "Jarvis (필수)" SecMain
WriteRegStr HKLM "${UNINST_KEY}" "QuietUninstallString" '"$INSTDIR\uninstall.exe" /S'
WriteRegDWORD HKLM "${UNINST_KEY}" "NoModify" 1
WriteRegDWORD HKLM "${UNINST_KEY}" "NoRepair" 1
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
WriteRegDWORD HKLM "${UNINST_KEY}" "EstimatedSize" $0
WriteRegDWORD HKLM "${UNINST_KEY}" "EstimatedSize" ${SIZE_KB}
SectionEnd
Section "시작 메뉴 바로 가기" SecStart
CreateShortCut "$SMPROGRAMS\Jarvis.lnk" "$INSTDIR\jarvis.exe"
CreateShortCut "$SMPROGRAMS\Jarvis.lnk" "$INSTDIR\jarvis.exe" "" "$INSTDIR\${ICON_FILE}" 0
SectionEnd
Section /o "바탕 화면 바로 가기" SecDesktop
CreateShortCut "$DESKTOP\Jarvis.lnk" "$INSTDIR\jarvis.exe"
CreateShortCut "$DESKTOP\Jarvis.lnk" "$INSTDIR\jarvis.exe" "" "$INSTDIR\${ICON_FILE}" 0
SectionEnd
; Every shortcut to jarvis.exe on the desktops and in the start menus, their folders included (the
; person's own too, and the installer's from an earlier version, which an update does not make
; again) shows this version's icon file; then Explorer redraws its icons. A shortcut to another
; Jarvis install's jarvis.exe (a folder with uninstall.exe and python-src, left behind when an
; earlier update installed into Program Files instead) starts this one instead, so it opens the
; Jarvis that runs, not an old copy. The paths go in through
; the environment, so no install folder name can break the command. The 64-bit PowerShell
; (SysNative from this 32-bit installer): a 32-bit one reads a link to Program Files as one to
; Program Files (x86).
Section "-Icons"
System::Call 'kernel32::SetEnvironmentVariable(t "JARVIS_EXE", t "$INSTDIR\jarvis.exe")'
System::Call 'kernel32::SetEnvironmentVariable(t "JARVIS_ICON", t "$INSTDIR\${ICON_FILE},0")'
System::Call 'kernel32::SetEnvironmentVariable(t "JARVIS_DIR", t "$INSTDIR")'
nsExec::Exec `"$WINDIR\SysNative\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -NonInteractive -Command "$$w = New-Object -ComObject WScript.Shell; foreach ($$d in 'Desktop', 'CommonDesktopDirectory', 'Programs', 'CommonPrograms') { Get-ChildItem -LiteralPath ([Environment]::GetFolderPath($$d)) -Filter *.lnk -Recurse:($$d -like '*Programs') -EA 0 | ForEach-Object { $$l = $$w.CreateShortcut($$_.FullName); $$t = $$l.TargetPath; if ($$t -and (Split-Path -Leaf $$t) -ieq 'jarvis.exe' -and (Test-Path -LiteralPath (Join-Path (Split-Path $$t) 'uninstall.exe')) -and (Test-Path -LiteralPath (Join-Path (Split-Path $$t) 'python-src'))) { if ($$t -ine $$env:JARVIS_EXE) { $$l.TargetPath = $$env:JARVIS_EXE; $$l.WorkingDirectory = $$env:JARVIS_DIR }; $$l.IconLocation = $$env:JARVIS_ICON; $$l.Save() } } }"`
Pop $0
${If} $0 != 0
DetailPrint "바로 가기 아이콘을 바꾸지 못했습니다 ($0)"
${EndIf}
System::Call 'shell32::SHChangeNotify(i 0x08000000, i 0, p 0, p 0)' ; SHCNE_ASSOCCHANGED
SectionEnd
Section "가상 모니터 드라이버" SecDriver
@@ -304,6 +334,7 @@ Section "Uninstall"
; folder the person chose may hold other things; folders go only when empty.
Delete "$INSTDIR\jarvis.exe"
Delete "$INSTDIR\WebView2Loader.dll"
Delete "$INSTDIR\jarvis-*.ico"
!include "${UNINSTALL_LIST}"
Delete "$INSTDIR\uninstall.exe"
RMDir "$INSTDIR"

View File

@@ -17,7 +17,12 @@ list="$target/uninstall-list.nsh"
(cd "$out/Jarvis" && find python-src display-driver -type f | sort | sed 's|/|\\|g; s|^| Delete "$INSTDIR\\|; s|$|"|'
cd "$out/Jarvis" && find python-src display-driver -type d | sort -r | sed 's|/|\\|g; s|^| RMDir "$INSTDIR\\|; s|$|"|') > "$list"
setup="$out/Jarvis-Setup-$version.exe"
makensis -V2 -DVERSION="$version" -DSRC="$out/Jarvis" -DOUT="$setup" -DICON="$here/icons/icon.ico" \
-DWEBVIEW2="$wv2" -DUNINSTALL_LIST="$list" ${NSIS_EXTRA:-} "$here/installer.nsi"
# The uninstall entry's size: what this setup installs, counted here. Counting the install folder on
# the user's PC would also walk a data folder kept inside it (models, runtime: many thousand files).
size_kb=$(cd "$out/Jarvis" && du -sk --apparent-size -c jarvis.exe WebView2Loader.dll python-src display-driver | tail -1 | cut -f1)
# The shortcuts' icon file is named by its content, so a new icon gets a path Windows has not seen.
icon_file="jarvis-$(sha256sum "$here/icons/icon.ico" | cut -c1-12).ico"
makensis -V2 -DVERSION="$version" -DSRC="$out/Jarvis" -DOUT="$setup" -DICON="$here/icons/icon.ico" -DICON_FILE="$icon_file" \
-DWEBVIEW2="$wv2" -DUNINSTALL_LIST="$list" -DSIZE_KB="$size_kb" ${NSIS_EXTRA:-} "$here/installer.nsi"
(cd "$out" && sha256sum "Jarvis-Setup-$version.exe" > "Jarvis-Setup-$version.exe.sha256")
echo "$setup"

View File

@@ -1,7 +1,9 @@
//! Jarvis management app: one Tauri 2 window over the app core (`app/src/admin.spec.md`, "Window
//! and Windows build"). The screens (`app/ui`) call `invoke("admin", {command, args})`, passed to the
//! same `AdminApi` the development server uses. Closing the window first stops what the app started;
//! if that cannot be confirmed the window stays open and says so, and closing it again quits.
//! same `AdminApi` the development server uses. Quitting first stops what the app started; if that
//! cannot be confirmed the window stays open and says so, and quitting again quits. The close button
//! quits, or hides the window to the tray when `app.closeButton` is "tray"; the tray icon opens it
//! again or quits. Starting Jarvis again while it runs shows the running one's window.
//!
//! jarvis [--location FILE]
//! jarvis --display-driver install|uninstall --result FILE (elevated, started by the app)
@@ -14,7 +16,9 @@ use std::sync::Arc;
use jarvis_app::admin_api::AdminApi;
use serde_json::Value;
use tauri::{Emitter, Manager, RunEvent, WebviewUrl, WebviewWindowBuilder, WindowEvent};
use tauri::menu::{Menu, MenuItem};
use tauri::tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent};
use tauri::{AppHandle, Emitter, Manager, RunEvent, WebviewUrl, WebviewWindowBuilder, WindowEvent};
/// Where closing stands: open, closing (stopping what runs), or the stop could not be confirmed.
const OPEN: u8 = 0;
@@ -37,6 +41,45 @@ async fn admin(app: tauri::AppHandle, state: tauri::State<'_, Api>, command: Str
Ok(out)
}
/// Bring the window back: from the tray, or when Jarvis is started again.
fn show_window(app: &AppHandle) {
if let Some(w) = app.get_webview_window("main") {
let _ = w.unminimize();
let _ = w.show();
let _ = w.set_focus();
}
}
/// Quit (the close button set to quit, or the tray's "완전 종료"): stop what the app started, then
/// exit; the window shows while that runs. If the stop fails the window stays with the reason, and
/// quitting again exits anyway.
fn quit(app: &AppHandle) {
let state = app.state::<Api>();
match state.phase.load(Ordering::SeqCst) {
CLOSE_FAILED => {
jarvis_app::warn_log!("app", "quitting again: quitting although the stop was not confirmed");
app.exit(0);
}
CLOSING => {}
_ => {
state.phase.store(CLOSING, Ordering::SeqCst);
show_window(app);
let _ = app.emit("closing", ());
let (handle, api) = (app.clone(), state.api.clone());
tauri::async_runtime::spawn(async move {
jarvis_app::info_log!("app", "quitting: stopping what the app started");
match api.shutdown().await {
Ok(()) => handle.exit(0),
Err(e) => {
handle.state::<Api>().phase.store(CLOSE_FAILED, Ordering::SeqCst);
let _ = handle.emit("close-failed", e);
}
}
});
}
}
}
fn arg(name: &str) -> Option<String> {
let args: Vec<String> = std::env::args().collect();
args.iter().position(|a| a == name).and_then(|i| args.get(i + 1).cloned())
@@ -66,6 +109,8 @@ fn main() {
let (webview_data, _) = jarvis_app::datadir::webview_data_dir(&location);
let app = tauri::Builder::default()
// First, so a second start only shows this one's window and exits.
.plugin(tauri_plugin_single_instance::init(|app, _, _| show_window(app)))
.manage(Api { api, phase: AtomicU8::new(OPEN) })
.invoke_handler(tauri::generate_handler![admin])
.setup({
@@ -76,6 +121,24 @@ fn main() {
.min_inner_size(900.0, 600.0)
.data_directory(webview_data)
.build()?;
let open = MenuItem::with_id(app, "open", "열기", true, None::<&str>)?;
let quit_item = MenuItem::with_id(app, "quit", "완전 종료", true, None::<&str>)?;
TrayIconBuilder::with_id("main")
.tooltip("Jarvis")
.menu(&Menu::with_items(app, &[&open, &quit_item])?)
.show_menu_on_left_click(false)
.on_menu_event(|app, e| match e.id.as_ref() {
"open" => show_window(app),
"quit" => quit(app),
_ => {}
})
.on_tray_icon_event(|tray, e| {
if let TrayIconEvent::Click { button: MouseButton::Left, button_state: MouseButtonState::Up, .. } = e {
show_window(tray.app_handle());
}
})
.icon(tauri::image::Image::from_bytes(include_bytes!("../icons/tray.png"))?)
.build(app)?;
Ok(())
}
})
@@ -83,25 +146,17 @@ fn main() {
let WindowEvent::CloseRequested { api: close, .. } = event else { return };
let state = window.state::<Api>();
match state.phase.load(Ordering::SeqCst) {
CLOSE_FAILED => {
jarvis_app::warn_log!("app", "window closed again: quitting although the stop was not confirmed");
}
// After a failed stop the window closes, and with it the app.
CLOSE_FAILED => jarvis_app::warn_log!("app", "window closed again: quitting although the stop was not confirmed"),
CLOSING => close.prevent_close(),
_ if state.api.close_to_tray() => {
close.prevent_close();
let _ = window.hide();
jarvis_app::info_log!("app", "window hidden to the tray");
}
_ => {
close.prevent_close();
state.phase.store(CLOSING, Ordering::SeqCst);
let _ = window.emit("closing", ());
let (handle, api) = (window.app_handle().clone(), state.api.clone());
tauri::async_runtime::spawn(async move {
jarvis_app::info_log!("app", "window closing: stopping what the app started");
match api.shutdown().await {
Ok(()) => handle.exit(0),
Err(e) => {
handle.state::<Api>().phase.store(CLOSE_FAILED, Ordering::SeqCst);
let _ = handle.emit("close-failed", e);
}
}
});
quit(window.app_handle());
}
}
})

View File

@@ -38,7 +38,7 @@ that is not absolute, or is a file, is refused with a message.
`config/settings.json` keeps the format of `discord_core.spec.md` and `conversation.spec.md`.
- `fields()` describes every key the screens edit: its dotted path (`call.mode`), screen
(`bot`, `channels`, `chat`, `memory`, `model`, `features`, `collect`), kind (bool, integer with a range, number with a
(`bot`, `channels`, `chat`, `memory`, `model`, `features`, `collect`, `schedule`, `pcControl`, `game`, `app`), kind (bool, integer with a range, number with a
range, text, text list, choice with its values, Discord ID, Discord ID list, ID to number map,
chat channel list, MCP server list, collection target list, free object), its default and a Korean label. The screens are built from this
list, so a key is added in one place.
@@ -221,9 +221,35 @@ editable on the 사람별 지침 screen.
- `notes_list` (everyone's, by person, IDs as strings), `note_update` `{id, text}` and `note_delete`
`{id}` serve the screen. Logs carry note ids only, never their text.
## Conversations (`app/src/history_view.rs`)
What people said, what Jarvis answered and how it made each answer, for the 대화 screen. Read
only, from the worker's history store `memory/history.sqlite` (`src/jarvis/memory/history.spec.md`,
records and "Traces"), so it works while the services are stopped. Nothing it reads goes to a log.
- Each item is `said` (a voice transcript, or a chat message by someone other than Jarvis),
`answered` (a spoken answer, or Jarvis's own chat message; to whom, when it answers someone) or
`thought` (a trace: the question, the answer or none, how long it took and its steps so far, at
the time it was asked; `pending` while the answer is being made, with `ms` 0 until it ends). Jarvis's
chat messages are known by the bot's user id (the first part of the stored token is that id in
base64) and by the author of any chat answer to someone.
- `history_query` `{said, answered, thought, via, person, channel, find, since, until, session, before, from, limit}`: the
three kinds (each on unless false), where (`voice`, `chat`, `task`; a task has traces only), a
person (their records, answers to them and traces of their questions), a channel, text the record
or the trace's question, answer or steps contains (records folded like the store: NFKC, lower
case), Unix seconds from (inclusive) and to (exclusive), `session` (only items from when the
latest service start of this app run began; none before the first start), the cursors `before` (only items older
than it) and `from` (it and newer), each an item's `{at, key}`, and `limit` (1-2000, default 200).
Items are ordered by time, then records before traces, then id, so paging by cursor never skips or
repeats an item, even at equal times. Answers
`{items, more, people, channels}`: the newest `limit` items in time order, whether older ones
were left out, the people who spoke (their latest name) and the channels with records (with the
name given a chat channel in the settings), and `session`, when the latest start began (Unix
seconds, null before the first). Without the file: no items and `missing: true`.
## Activity (`app/src/activity.rs`)
`docs/v2/proactive.md` (제안 5). What Jarvis did outside its answers, for the 한 일 screen: each chat
`docs/v2/proactive.md` (제안 5). What Jarvis did outside its answers, for the 로그 screen's 한 일 view: each chat
channel action the brain's tool asked for (`chat.send`, `chat.edit`, `chat.react`, `chat.delete`,
`chat.pin`, `chat.unpin`), each schedule delivery (`schedule.remind`, `schedule.task`) and each
news notification (`collect.notify`), each screen capture (`screen.view`, "Screen viewing"), done or failed. The other PC control actions join it with M7. Ordinary answers are not recorded.
@@ -664,6 +690,7 @@ back as Korean messages for the screen. The Tauri shell passes the screens' `inv
| `service_start` / `service_stop` / `service_restart` / `dashboard` | the controller and its snapshot; start and restart run in the background, stop also cancels a start |
| `discord_channel_info` `{id}` / `channel_sync_status` | a channel's Discord name and topic / each synced chat channel's last result (above) |
| `notes_list` / `note_update` `{id, text}` / `note_delete` `{id}` | everyone's personal notes (above) / change one's text / delete one |
| `history_query` `{said, answered, thought, via, person, channel, find, since, until, session, before, from, limit}` | the 대화 screen's records and answer traces (above, "Conversations") |
| `activity_list` `{limit}` | what Jarvis did (above, "Activity"), newest first |
| `schedules_list` / `schedule_delete` `{id}` | every person's schedules (above), soonest first, with IDs as strings / delete one |
| `collect_results` `{target, limit}` | `{targets, items}`: every target folder with results, and the collected items newest first (`target` null: every target; `limit` 1-500, default 100) |
@@ -682,6 +709,8 @@ its data folder, and again after each one is saved. The log hub writes to the da
## Screens (`app/ui/`)
Plain HTML, CSS and an ES module, no build step, dark theme after `DESIGN.md`. All text is Korean.
The side menu has 대화 right under 대시보드 and 앱 last; there is no separate update screen (updates
are on the 앱 screen) and no separate 한 일 screen (it is a view of the 로그 screen).
- **First-run wizard** (while `firstRun`): data folder (free space, warning under 200 GB), PC check,
the model to download, Discord bot (token check with the
@@ -694,7 +723,7 @@ Plain HTML, CSS and an ES module, no build step, dark theme after `DESIGN.md`. A
Strata's last line, and stop in the header; the header with start, restart and stop is rebuilt
only when the state changes, so a click is never lost to the refresh. Every screen change starts
a new generation: an answer that arrives after the user moved to another screen is dropped.
- **Settings screens** (봇, 채널·호출, 채팅 채널, 대화 기억, 모델, 기능, 백그라운드 수집, 예약, PC 제어, 게임 모드): built from `settings_fields`; only
- **Settings screens** (봇, 채널·호출, 채팅 채널, 대화 기억, 모델, 기능, 백그라운드 수집, 예약, PC 제어, 게임 모드, 앱): built from `settings_fields`; only
changed fields are sent; the server and voice channel are pickers (choosing another server clears
the voice channel and lists only that server's channels); the chat channels are a table
with their switches; the bot screen also changes the token; the 기능 screen has the feature
@@ -706,14 +735,41 @@ Plain HTML, CSS and an ES module, no build step, dark theme after `DESIGN.md`. A
newest 100, filtered by any target that has results, each with its time, title, link and the start of its text shown
as plain text). The 예약 screen has `schedule.chatChannel` and every person's schedules (next time
or "다시 울리지 않음", repeat, who and how they asked, kind and text as plain text, the last
outcome, delete).
outcome, delete). The 앱 screen has the update card (below) first, then `app.closeButton` (완전 종료
or 트레이로 최소화) with a note that the tray icon opens the window again and its menu quits;
saving it needs no restart.
- **사람별 지침**: every person's notes (name and ID, the text in a box, save and delete).
- **한 일**: the activity (time, kind, target, who asked, outcome and why it failed), newest 200,
with a refresh button.
- **업데이트**: the version here, the state, "다시 확인", "받기" (with its percentage) and "설치하고
다시 시작", and the release's notes as plain text. The app checks once when the main screens open;
a newer release renames the button "업데이트 (새 버전)" and says so once.
- **Logs**: tab, level and text filters, pause, live follow (lines after the last seen), "최근 오류
- **대화**: what people said, Jarvis's answers and how each answer was made, in time order with a
date line between days; people's words on the left, Jarvis's on the right with whom it answered,
each with its time, voice or chat and channel, and a copy button. A trace is a closed card (whose
question, how many tool calls, seconds, no answer) that opens to the question, the records and
notes it was given, the tools offered, the plan, the model's thinking, each tool call (name,
arguments, success, failure or skipped and why, its result) and the answer. A trace sits at the
time it was asked and is there while the answer is made (`pending`, "답을 만드는 중"): it fills in
step by step, and one seen being made is open and stays open with its answer unless the user
closes it. Filters: the three
kinds as chips, "현재 세션" (off by default: only items since the bot was last started, `session`;
the count line starts with that start's date and time, and with no start yet in this app run the
list says so; a new start while it is on starts the list over from that start), where (음성,
채팅, 정기 작업), person, channel, one day and text; "실시간" (on by
default) re-reads the live window every second while a trace in it is being made, else every 3 seconds: every item from its first one on (`from`, up to
2,000). Only items in that window change on screen, an edited message included; items paged back
past it stay as they were loaded (edits and deletes there show after a reload of the screen). The
screen redraws only when an item changed, keeping the cards the user opened open and the scroll
where it was unless it was at the end. When more new items arrive than the window holds, the
shown items it no longer reaches join the pages kept as loaded, so nothing on screen disappears.
"이전 기록 더 보기" adds the 200 items before the oldest loaded (`before`), one request at a time
(the button is off meanwhile, and an item already loaded is never added again), with no end to
how far back it goes; a filter change drops every answer to a request made before it, and a live
answer older than the newest one asked is dropped; "생각 모두 펼치기/접기"; a count of each kind
shown. The paging is `app/ui/talk.js`, pure, checked by `node --test app/tests/ui/talk.test.mjs`.
- **업데이트** (a card on the 앱 screen, re-read every second while it is shown): the version here,
the state, "다시 확인", "받기" (with its percentage) and "설치하고 다시 시작", and the release's
notes as plain text. The app checks once when the main screens open; a newer release renames the
앱 button "앱 (새 버전)" and says so once.
- **Logs** (로그): two views switched at the top, 로그 and 한 일. 한 일 is the activity (time, kind,
target, who asked, outcome and why it failed), newest 200, read when the view opens, with a
refresh button; there is no separate 한 일 screen. 로그 has tab, level and text filters, pause, live follow (lines after the last seen), "최근 오류
복사" (to the clipboard; over 2,000 characters it suggests the zip), and the zip export by days.
`jarvis-admin-dev [--port N] [--ui DIR] [--location FILE]` (development only) serves `app/ui` and
@@ -760,6 +816,16 @@ both to a release with that tag. The repository's other releases (v1's `v1.x`) a
left is cleared (`Controller::shutdown`: the LLM's server stopped and confirmed gone). While that
runs the window says so; if it fails the window stays open with the reason, and closing it again
quits anyway. Quitting another way (the system shutting down) runs the same shutdown.
- The close button (X) quits as above, or, when `app.closeButton` is `"tray"` (`"quit"` by default,
read each time it is pressed; no data folder or settings that do not parse: quit), only hides the
window: the bot and services keep running. A tray icon (`icons/tray.png`, tooltip "Jarvis") is
always there: a left click shows the window again, its menu has 열기 and 완전 종료 (the quit
above, with the window shown while it runs).
- One Jarvis at a time (`tauri-plugin-single-instance`): starting it again while it runs shows the
running one's window (hidden or minimised) and the new start exits.
- The icon (`icons/icon.ico` for the program file, window, taskbar and installer, 16-256 px;
`icons/icon.png` 512 px): voice bars in a ring on the accent colour's gradient; at 32 px and below
only three thicker bars, so it stays readable in the taskbar and tray.
- `app/shell/package.sh <folder>` builds it on Linux (`x86_64-pc-windows-gnu`, mingw-w64) and lays
out `Jarvis/`: `jarvis.exe`, `WebView2Loader.dll`, `python-src/` (the `voice_worker` and
`jarvis` packages, no caches or specs) and `display-driver/` (the virtual monitor's driver). The worker's sources are `python-src` next to the
@@ -775,7 +841,9 @@ both to a release with that tag. The repository's other releases (v1's `v1.x`) a
`Jarvis-Setup-<version>.exe` with its `.sha256`. The installer is about 10 MB; models and runtimes
come with the first-run wizard into the data folder, which the installer never touches.
- Program Files (`Jarvis`), one administrator prompt, 64-bit Windows 10/11 only; Korean pages:
- Program Files (`Jarvis`), or where Jarvis is already installed (`HKLM\Software\JarvisBot`
`InstallDir`, 64-bit view; a folder given with `/D` wins), one administrator prompt, 64-bit
Windows 10/11 only; Korean pages:
folder, components, progress, finish ("Jarvis 실행", started through Explorer so the app runs as
the signed-in user, not as administrator).
- Components: Jarvis (always), start menu shortcut (on), desktop shortcut (off), the virtual
@@ -784,7 +852,18 @@ come with the first-run wizard into the data folder, which the installer never t
installed later from the features screen, with the reason the app wrote (UTF-8), and the app is
installed all the same; never in a
silent install, so an update neither asks nor brings back a driver the person removed).
Shortcuts are for every user of the PC.
Shortcuts are for every user of the PC. Their icon is a file next to `jarvis.exe` named by its
content (`jarvis-<sha256 prefix>.ico`; the old one is deleted), because Windows keeps an icon it
has shown by its path and a changed icon under the old path stays old on the desktop and in
search. After the shortcuts, every `.lnk` to `jarvis.exe` on the desktops and in the start menus
and their folders (the installing user's and every user's, the person's own and an earlier
version's included) gets this icon file (the paths reach PowerShell through the environment, so
any folder name works; a failure is a line in the details), and Explorer is told to redraw (`SHCNE_ASSOCCHANGED`).
A shortcut to the `jarvis.exe` of another folder that holds a Jarvis install (`uninstall.exe` and
`python-src` next to it: a copy left behind when an update before 0.1.12 installed into Program
Files instead of the chosen folder) is pointed at this install's `jarvis.exe` (and its working
folder at this folder), so it starts the Jarvis that is kept up to date, and a start while it runs
shows the running window instead of a second, old Jarvis. The old copy itself is not touched.
- The WebView2 runtime is installed with Microsoft's bootstrapper (inside the installer) only when
the PC has none, before any file is copied. When it is still missing afterwards the installer
asks to retry or cancel; silently it stops with exit code 3, nothing installed and nothing

View File

@@ -157,6 +157,14 @@ impl AdminApi {
Ok(c.get_or_insert_with(|| Controller::new(ServicesHost::new(dir.path().to_path_buf()))).clone())
}
/// Whether the window's close button hides it to the tray (`app.closeButton`) rather than
/// quitting. Without a data folder or with settings that do not parse, closing quits.
pub fn close_to_tray(&self) -> bool {
self.dir.lock().unwrap().as_ref()
.and_then(|d| crate::settings::load_settings(&d.settings_file()).ok())
.is_some_and(|s| s.close_to_tray)
}
/// The app is closing: cancel an install in progress and wait for it (its commands and their
/// children end), stop the services (a start in progress is cancelled and waited for) and clear
/// what a failed run may have left (the LLM's server). An error means something may still run;
@@ -317,7 +325,8 @@ impl AdminApi {
let speed = crate::settings::load_settings(&file).map_err(|e| e.0)?.voice.tts_speed;
self.controller()?.set_tts_speed(speed);
}
let restart = changes.keys().any(|k| k != "voice.tts.speed");
// The close button's choice is read when it is pressed.
let restart = changes.keys().any(|k| k != "voice.tts.speed" && k != "app.closeButton");
Ok(json!({"saved": changes.len(),
"restartNeeded": restart && self.controller()?.state() == crate::control::State::Running,
"sync": sync}))
@@ -396,6 +405,39 @@ impl AdminApi {
crate::info_log!("admin", "note {id} deleted");
Ok(json!({"deleted": id.to_string()}))
}
// The 대화 screen (admin.spec.md, "Conversations"): records and answer traces.
"history_query" => {
let dir = self.dir()?;
let text = |k: &str| args.get(k).and_then(Value::as_str).map(str::trim).filter(|s| !s.is_empty()).map(String::from);
let flag = |k: &str| args.get(k).and_then(Value::as_bool).unwrap_or(true);
// The current session: from when the latest start began (none yet: nothing to show).
let session = self.controller.lock().unwrap().as_ref().and_then(|c| c.session_start());
let only_session = args.get("session").and_then(Value::as_bool).unwrap_or(false);
let mut since = args.get("since").and_then(Value::as_f64);
if only_session {
since = Some(since.unwrap_or(f64::MIN).max(session.unwrap_or(f64::INFINITY)));
}
let q = crate::history_view::Query {
said: flag("said"), answered: flag("answered"), thought: flag("thought"),
via: text("via"), person: text("person"), channel: text("channel"), find: text("find"),
since, until: args.get("until").and_then(Value::as_f64),
before: args.get("before").and_then(crate::history_view::Cursor::of),
from: args.get("from").and_then(crate::history_view::Cursor::of),
limit: args.get("limit").and_then(Value::as_u64).map_or(crate::history_view::DEFAULT_LIMIT, |n| n as usize),
};
let bot = self.secrets()?.get(DISCORD_TOKEN).ok().flatten().and_then(|t| crate::history_view::bot_id_of_token(&t));
let path = dir.path().join("memory").join("history.sqlite");
let mut v = tokio::task::spawn_blocking(move || crate::history_view::query(&path, bot.as_deref(), &q))
.await.map_err(|e| e.to_string())??;
// Chat channels by the names given them in the settings.
let named = crate::settings::load_settings(&dir.settings_file()).map(|s| s.chat_channels).unwrap_or_default();
for ch in v["channels"].as_array_mut().into_iter().flatten() {
let name = named.iter().find(|c| Some(c.id.to_string().as_str()) == ch["id"].as_str()).map(|c| c.name.clone());
ch["name"] = json!(name.unwrap_or_default());
}
v["session"] = json!(session);
Ok(v)
}
"activity_list" => {
let limit = args.get("limit").and_then(Value::as_u64).unwrap_or(200).clamp(1, 1000) as usize;
Ok(json!({"items": crate::activity::Activity::new(self.dir()?.path()).recent(limit)}))
@@ -525,6 +567,20 @@ mod tests {
assert!(a.call("nope", json!({})).await.is_err());
}
#[tokio::test]
async fn the_close_button_follows_the_saved_choice() {
let (a, base) = api("api-close");
assert!(!a.close_to_tray(), "no data folder yet: closing quits");
let data = base.join("d");
a.call("folder_choose", json!({"path": data.to_string_lossy()})).await.unwrap();
assert!(!a.close_to_tray());
a.call("settings_apply", json!({"changes": {"app.closeButton": "tray"}})).await.unwrap();
assert!(a.close_to_tray());
// A settings file that does not parse never leaves the window unable to close.
std::fs::write(data.join("config").join("settings.json"), "{").unwrap();
assert!(!a.close_to_tray());
}
#[tokio::test]
async fn the_notes_screen_lists_edits_and_deletes_anyones_notes() {
let (a, base) = api("api-notes");
@@ -541,6 +597,51 @@ mod tests {
assert!(store.all().unwrap().is_empty());
}
#[tokio::test]
async fn the_conversation_screen_reads_records_and_traces_with_channel_names() {
let (a, base) = api("api-history");
let data = base.join("d");
a.call("folder_choose", json!({"path": data.to_string_lossy()})).await.unwrap();
assert_eq!(a.call("history_query", json!({})).await.unwrap()["missing"], true);
std::fs::create_dir_all(data.join("memory")).unwrap();
let c = rusqlite::Connection::open(data.join("memory").join("history.sqlite")).unwrap();
c.execute_batch(crate::history_view::TEST_SCHEMA).unwrap();
c.execute_batch("INSERT INTO history(ts, kind, channel_id, author_id, author_name, text, norm)
VALUES (1, 'chat', '123456789012345678', '1', 'Alice', '안녕', '안녕');
INSERT INTO traces(ts, via, channel_id, user_id, question, answer, ms, steps)
VALUES (2, 'chat', '123456789012345678', '1', '안녕', '반가워요', 5, '[]');").unwrap();
a.call("settings_apply", json!({"changes": {"chatChannels": [{"id": "123456789012345678", "name": "잡담"}]}})).await.unwrap();
let v = a.call("history_query", json!({"thought": false})).await.unwrap();
assert_eq!(v["items"].as_array().unwrap().len(), 1);
assert_eq!(v["items"][0]["who"]["name"], "Alice");
assert_eq!(v["channels"][0]["name"], "잡담");
let v = a.call("history_query", json!({"said": false, "find": "반가"})).await.unwrap();
assert_eq!(v["items"][0]["type"], "thought");
}
#[tokio::test]
async fn the_current_session_shows_only_what_came_since_the_latest_start() {
let (a, base) = api("api-history-session");
let data = base.join("d");
a.call("folder_choose", json!({"path": data.to_string_lossy()})).await.unwrap();
std::fs::create_dir_all(data.join("memory")).unwrap();
let c = rusqlite::Connection::open(data.join("memory").join("history.sqlite")).unwrap();
c.execute_batch(crate::history_view::TEST_SCHEMA).unwrap();
let rec = |ts: f64, text: &str| c.execute("INSERT INTO history(ts, kind, channel_id, author_id, author_name, text, norm) \
VALUES (?, 'voice', 'vc', '1', 'Alice', ?, ?)", rusqlite::params![ts, text, text]).unwrap();
rec(1.0, "지난번 말");
let texts = |v: &Value| v["items"].as_array().unwrap().iter().map(|i| i["text"].as_str().unwrap().to_string()).collect::<Vec<_>>();
// Not started yet in this app run: no session, so nothing in it.
let v = a.call("history_query", json!({"session": true})).await.unwrap();
assert_eq!((texts(&v), v["session"].clone()), (Vec::<String>::new(), Value::Null));
a.call("service_start", json!({})).await.unwrap();
let started = a.call("history_query", json!({})).await.unwrap()["session"].as_f64().unwrap();
rec(started + 1.0, "이번 말");
assert_eq!(texts(&a.call("history_query", json!({"session": true})).await.unwrap()), ["이번 말"]);
assert_eq!(texts(&a.call("history_query", json!({})).await.unwrap()), ["지난번 말", "이번 말"]);
a.shutdown().await.unwrap();
}
#[tokio::test]
async fn the_activity_screen_reads_the_newest_entries() {
let (a, base) = api("api-activity");

View File

@@ -69,6 +69,8 @@ struct Inner {
/// The latest speech speed saved (equal to the settings file's): a start may have read the
/// settings before it was saved, so the services get it again once they run.
tts_speed: Option<f64>,
/// When the latest start began (Unix seconds): the 대화 screen's current session.
session: Option<f64>,
}
pub struct Controller {
@@ -80,13 +82,18 @@ pub struct Controller {
impl Controller {
pub fn new(host: impl Host) -> Arc<Self> {
Arc::new(Self { host: Box::new(host), inner: Mutex::new(Inner { state: State::Stopped, error: None, running: None,
dashboard: Arc::default(), feeder: None, stop_asked: false, tts_speed: None }), usage: tokio::sync::Mutex::new(None) })
dashboard: Arc::default(), feeder: None, stop_asked: false, tts_speed: None, session: None }), usage: tokio::sync::Mutex::new(None) })
}
pub fn state(&self) -> State {
self.inner.lock().unwrap().state
}
/// When the latest start began (Unix seconds), none before the first start of this app run.
pub fn session_start(&self) -> Option<f64> {
self.inner.lock().unwrap().session
}
/// Start from stopped or failed; a failed start leaves nothing running.
pub async fn start(&self) -> Result<(), String> {
self.begin_start()?;
@@ -112,6 +119,7 @@ impl Controller {
i.state = State::Starting;
i.error = None;
i.stop_asked = false;
i.session = Some(chrono::Utc::now().timestamp_millis() as f64 / 1000.0);
self.host.prepare_start();
Ok(())
}

View File

@@ -70,7 +70,7 @@ strings (numbers would lose precision).
| `voice.wakeWords` | `["자비스"]` | Sent to the worker as STT `hotwords`, and the voice wake words of call detection. |
| `voice.stt` | `{}` | Other worker STT settings (`partials`, `end_silence_ms`, `final_beam`, `language`, ...); the worker validates them. |
| `chatChannels` | `[]` | `{id, name, description, read (true), send (true), edit (true), react (true), delete (false), pin (false), answer ("wakeWord"), syncDiscord (true)}` per channel; `answer` is in `conversation.spec.md`, `syncDiscord` (the channel's Discord name and topic follow `name` and `description`) in `admin.spec.md`. |
| `voice.tts.speed` | `1.5` | How fast the voice speaks, 0.5-2.0 (1.0 is MeloTTS's natural pace; above it the worker stretches the speech and keeps its pitch, `voice_worker.spec.md`, "TTS"). Passed to the worker as `--melo-speed` when it speaks (`--melo-python`) and its arguments set no speed. A change saved while the services run goes to the worker at once (`tts_speed`) and applies from the next sentence, without a restart (saved while they start, it goes once they run, since the start may have read the settings before); it is sent again whenever the worker connects again. MeloTTS's Korean model has one voice, so there is no voice choice. |
| `voice.tts.speed` | `1.5` | How fast the voice speaks, 0.5-2.0 (1.0 is MeloTTS's natural pace; MeloTTS speaks up to 1.25 itself and above that the worker stretches the speech and keeps its pitch, `voice_worker.spec.md`, "TTS"). Passed to the worker as `--melo-speed` when it speaks (`--melo-python`) and its arguments set no speed. A change saved while the services run goes to the worker at once (`tts_speed`) and applies from the next sentence, without a restart (saved while they start, it goes once they run, since the start may have read the settings before); it is sent again whenever the worker connects again. MeloTTS's Korean model has one voice, so there is no voice choice. |
| `voiceWorker.python` | `python3` (`python.exe` on Windows) | Python of the worker venv. |
| `voiceWorker.cwd` | `python-src` next to the app's executable when it is there (the Windows build), else the repo's `src/` | Folder holding the `voice_worker` package. |
| `voiceWorker.args` | `[]` | Extra worker arguments, e.g. `["--melo-python", "<MeloTTS venv python>"]`. |

421
app/src/history_view.rs Normal file
View File

@@ -0,0 +1,421 @@
//! The 대화 screen's reads (`app/src/admin.spec.md`, "Conversations"): what people said, what Jarvis
//! answered and how each answer was made, from the worker's history store
//! (`memory/history.sqlite`, schema owned by `src/jarvis/memory/history.py`). Read only; the
//! screen is the only reader, and nothing it reads goes to a log.
use std::collections::HashMap;
use std::path::Path;
use rusqlite::{params_from_iter, types::Value as Sql, Connection, OpenFlags};
use serde_json::{json, Value};
use unicode_normalization::UnicodeNormalization;
pub const DEFAULT_LIMIT: usize = 200;
pub const MAX_LIMIT: usize = 2000;
/// What the screen asks for. `None` filters match everything.
#[derive(Debug, Clone)]
pub struct Query {
/// People's words (voice transcripts and chat messages).
pub said: bool,
/// Jarvis's answers and its own chat messages.
pub answered: bool,
/// How each answer was made (the traces).
pub thought: bool,
/// `voice`, `chat` or `task` (a task has traces only; its answer is a chat message).
pub via: Option<String>,
/// A person's records: written by them or answers to them.
pub person: Option<String>,
pub channel: Option<String>,
/// Text the record (or the trace's question, answer or steps) contains, case folded.
pub find: Option<String>,
/// Unix seconds, inclusive / exclusive.
pub since: Option<f64>,
pub until: Option<f64>,
/// Only items older than this one (paging back) / this one and newer (the window shown).
pub before: Option<Cursor>,
pub from: Option<Cursor>,
pub limit: usize,
}
/// An item's place in the order: time, then records before traces, then id. Items are ordered by
/// it, so paging by it never skips or repeats one, even when two share a time.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Cursor {
pub at: f64,
/// 0: a record (`h<id>`), 1: a trace (`t<id>`).
pub src: u8,
pub id: i64,
}
impl Cursor {
/// From `{at, key}`, as the screen sends an item back.
pub fn of(v: &Value) -> Option<Self> {
let at = v.get("at")?.as_f64()?;
let key = v.get("key")?.as_str()?;
let src = match key.get(..1)? { "h" => 0, "t" => 1, _ => return None };
Some(Self { at, src, id: key[1..].parse().ok()? })
}
/// SQL for "a row of table `src` comes before this cursor", over columns `{p}ts` and `{p}id`.
fn before_sql(&self, src: u8, p: &str) -> (String, Vec<Sql>) {
use std::cmp::Ordering::*;
match src.cmp(&self.src) {
Less => (format!("{p}ts <= ?"), vec![Sql::Real(self.at)]),
Greater => (format!("{p}ts < ?"), vec![Sql::Real(self.at)]),
Equal => (format!("({p}ts < ? OR ({p}ts = ? AND {p}id < ?))"),
vec![Sql::Real(self.at), Sql::Real(self.at), Sql::Integer(self.id)]),
}
}
}
/// The cursor conditions of `q` for table `src`, appended to `sql` and `args`.
fn cursor_sql(q: &Query, src: u8, p: &str, sql: &mut String, args: &mut Vec<Sql>) {
if let Some(c) = &q.before {
let (cond, a) = c.before_sql(src, p);
*sql += &format!(" AND {cond}");
args.extend(a);
}
if let Some(c) = &q.from {
let (cond, a) = c.before_sql(src, p);
*sql += &format!(" AND NOT {cond}");
args.extend(a);
}
}
impl Default for Query {
fn default() -> Self {
Self { said: true, answered: true, thought: true, via: None, person: None, channel: None, find: None,
since: None, until: None, before: None, from: None, limit: DEFAULT_LIMIT }
}
}
/// Jarvis's Discord user id, from its bot token: the token's first part is the id in base64.
pub fn bot_id_of_token(token: &str) -> Option<String> {
use base64::Engine;
let first = token.trim().split('.').next()?.trim_end_matches('=');
let raw = base64::engine::general_purpose::STANDARD_NO_PAD.decode(first)
.or_else(|_| base64::engine::general_purpose::URL_SAFE_NO_PAD.decode(first)).ok()?;
let id = String::from_utf8(raw).ok()?;
(!id.is_empty() && id.len() <= 20 && id.bytes().all(|b| b.is_ascii_digit())).then_some(id)
}
/// The history store's own text folding (`history.py`, `_fold`): NFKC, then lower case.
fn fold(text: &str) -> String {
text.nfkc().collect::<String>().to_lowercase()
}
fn like(text: &str) -> String {
let escaped = text.replace('\\', "\\\\").replace('%', "\\%").replace('_', "\\_");
format!("%{escaped}%")
}
fn open(path: &Path) -> Result<Connection, String> {
// Read-write without create: a WAL database needs its shared-memory file, which a read-only
// connection may not make. Only SELECTs run (query_only).
let c = Connection::open_with_flags(path, OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_NO_MUTEX)
.map_err(|e| format!("대화 기록을 열 수 없습니다: {e}"))?;
c.busy_timeout(std::time::Duration::from_secs(3)).map_err(|e| e.to_string())?;
c.pragma_update(None, "query_only", true).map_err(|e| e.to_string())?;
Ok(c)
}
fn has_traces(c: &Connection) -> bool {
c.query_row("SELECT 1 FROM sqlite_master WHERE type='table' AND name='traces'", [], |_| Ok(())).is_ok()
}
/// The records and traces `q` asks for, newest `q.limit` of them in time order, with the people
/// and channels the filters can pick from. `bot`: Jarvis's Discord user id, when known (its chat
/// messages count as answers; without it only those that answer someone do, and the authors of those).
pub fn query(path: &Path, bot: Option<&str>, q: &Query) -> Result<Value, String> {
if !path.is_file() {
return Ok(json!({"items": [], "more": false, "people": [], "channels": [], "missing": true}));
}
let c = open(path)?;
let limit = q.limit.clamp(1, MAX_LIMIT);
let bot = bot.unwrap_or("");
let is_bot = "(h.to_id IS NOT NULL OR h.author_id = ?1 OR h.author_id IN \
(SELECT author_id FROM history WHERE kind = 'chat' AND to_id IS NOT NULL))";
let err = |e: rusqlite::Error| format!("대화 기록을 읽지 못했습니다: {e}");
let names: HashMap<String, String> = {
let mut st = c.prepare("SELECT author_id, author_name, MAX(ts) FROM history \
WHERE kind IN ('voice', 'chat') AND author_id != '' GROUP BY author_id").map_err(err)?;
let rows = st.query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?))).map_err(err)?;
rows.collect::<Result<_, _>>().map_err(err)?
};
let name_of = |id: &str| names.get(id).cloned().unwrap_or_default();
let mut items: Vec<((f64, u8, i64), Value)> = Vec::new();
let mut more = false;
if q.said || q.answered {
let mut sql = format!("SELECT h.id, h.ts, h.kind, h.channel_id, h.author_id, h.author_name, h.to_id, h.text, \
({is_bot} AND h.kind = 'chat') OR h.kind = 'reply' FROM history h WHERE 1");
let mut args: Vec<Sql> = vec![Sql::Text(bot.into())];
match (q.said, q.answered) {
(true, false) => sql += &format!(" AND (h.kind = 'voice' OR (h.kind = 'chat' AND NOT {is_bot}))"),
(false, true) => sql += &format!(" AND (h.kind = 'reply' OR (h.kind = 'chat' AND {is_bot}))"),
_ => {}
}
match q.via.as_deref() {
Some("voice") => sql += " AND h.kind IN ('voice', 'reply')",
Some("chat") => sql += " AND h.kind = 'chat'",
Some(_) => sql += " AND 0",
None => {}
}
if let Some(p) = &q.person {
sql += " AND (h.author_id = ? OR h.to_id = ?)";
args.extend([Sql::Text(p.clone()), Sql::Text(p.clone())]);
}
if let Some(ch) = &q.channel {
sql += " AND h.channel_id = ?";
args.push(Sql::Text(ch.clone()));
}
if let Some(f) = q.find.as_deref().map(str::trim).filter(|f| !f.is_empty()) {
sql += " AND h.norm LIKE ? ESCAPE '\\'";
args.push(Sql::Text(like(&fold(f))));
}
if let Some(t) = q.since { sql += " AND h.ts >= ?"; args.push(Sql::Real(t)); }
if let Some(t) = q.until { sql += " AND h.ts < ?"; args.push(Sql::Real(t)); }
cursor_sql(q, 0, "h.", &mut sql, &mut args);
sql += &format!(" ORDER BY h.ts DESC, h.id DESC LIMIT {}", limit + 1);
let mut st = c.prepare(&sql).map_err(err)?;
let rows = st.query_map(params_from_iter(args), |r| {
let (id, ts, kind): (i64, f64, String) = (r.get(0)?, r.get(1)?, r.get(2)?);
let (author, author_name, to): (String, String, Option<String>) = (r.get(4)?, r.get(5)?, r.get(6)?);
let answer: bool = r.get(8)?;
Ok(((ts, 0, id), json!({
"key": format!("h{id}"), "type": if answer { "answered" } else { "said" }, "at": ts,
"via": if kind == "chat" { "chat" } else { "voice" }, "channel": r.get::<_, String>(3)?,
"who": {"id": author, "name": author_name},
"to": to.map(|t| json!({"id": t, "name": name_of(&t)})),
"text": r.get::<_, String>(7)?,
})))
}).map_err(err)?;
let got = rows.collect::<Result<Vec<_>, _>>().map_err(err)?;
more |= got.len() > limit;
items.extend(got.into_iter().take(limit));
}
if q.thought && has_traces(&c) {
let mut sql = String::from("SELECT id, ts, via, channel_id, user_id, question, answer, ms, steps FROM traces WHERE 1");
let mut args: Vec<Sql> = Vec::new();
if let Some(v) = &q.via { sql += " AND via = ?"; args.push(Sql::Text(v.clone())); }
if let Some(p) = &q.person { sql += " AND user_id = ?"; args.push(Sql::Text(p.clone())); }
if let Some(ch) = &q.channel { sql += " AND channel_id = ?"; args.push(Sql::Text(ch.clone())); }
if let Some(f) = q.find.as_deref().map(str::trim).filter(|f| !f.is_empty()) {
sql += " AND (question LIKE ? ESCAPE '\\' OR answer LIKE ? ESCAPE '\\' OR steps LIKE ? ESCAPE '\\')";
args.extend(std::iter::repeat_n(Sql::Text(like(f)), 3));
}
if let Some(t) = q.since { sql += " AND ts >= ?"; args.push(Sql::Real(t)); }
if let Some(t) = q.until { sql += " AND ts < ?"; args.push(Sql::Real(t)); }
cursor_sql(q, 1, "", &mut sql, &mut args);
let sql = format!("{sql} ORDER BY ts DESC, id DESC LIMIT {}", limit + 1);
let mut st = c.prepare(&sql).map_err(err)?;
let rows = st.query_map(params_from_iter(args), |r| {
let (id, ts): (i64, f64) = (r.get(0)?, r.get(1)?);
let user: String = r.get(4)?;
let steps: String = r.get(8)?;
let ms: i64 = r.get(7)?;
Ok(((ts, 1, id), json!({
"key": format!("t{id}"), "type": "thought", "at": ts, "via": r.get::<_, String>(2)?,
"channel": r.get::<_, Option<String>>(3)?,
"who": {"id": user.clone(), "name": name_of(&user)},
"question": r.get::<_, String>(5)?, "answer": r.get::<_, String>(6)?, "ms": ms.max(0),
"pending": ms < 0,
"steps": serde_json::from_str::<Value>(&steps).unwrap_or(json!([])),
})))
}).map_err(err)?;
let got = rows.collect::<Result<Vec<_>, _>>().map_err(err)?;
more |= got.len() > limit;
items.extend(got.into_iter().take(limit));
}
items.sort_by(|a, b| b.0.0.total_cmp(&a.0.0).then(b.0.1.cmp(&a.0.1)).then(b.0.2.cmp(&a.0.2)));
more |= items.len() > limit;
items.truncate(limit);
items.reverse();
let mut people: Vec<Value> = {
let mut st = c.prepare(&format!("SELECT h.author_id, h.author_name, MAX(h.ts) FROM history h \
WHERE (h.kind = 'voice' OR (h.kind = 'chat' AND NOT {is_bot})) AND h.author_id != '' GROUP BY h.author_id"))
.map_err(err)?;
let rows = st.query_map([bot], |r| Ok(json!({"id": r.get::<_, String>(0)?, "name": r.get::<_, String>(1)?})))
.map_err(err)?;
rows.collect::<Result<_, _>>().map_err(err)?
};
people.sort_by(|a, b| a["name"].as_str().cmp(&b["name"].as_str()));
let channels: Vec<Value> = {
let mut st = c.prepare("SELECT channel_id, MAX(kind = 'chat'), MAX(ts) FROM history GROUP BY channel_id \
ORDER BY MAX(ts) DESC").map_err(err)?;
let rows = st.query_map([], |r| Ok(json!({"id": r.get::<_, String>(0)?,
"via": if r.get::<_, bool>(1)? { "chat" } else { "voice" }}))).map_err(err)?;
rows.collect::<Result<_, _>>().map_err(err)?
};
Ok(json!({"items": items.into_iter().map(|(_, v)| v).collect::<Vec<_>>(), "more": more,
"people": people, "channels": channels}))
}
/// The history store's tables as `src/jarvis/memory/history.py` makes them, for tests.
#[cfg(test)]
pub(crate) const TEST_SCHEMA: &str = "
CREATE TABLE history (id INTEGER PRIMARY KEY, ts REAL NOT NULL, kind TEXT NOT NULL, channel_id TEXT NOT NULL,
author_id TEXT NOT NULL, author_name TEXT NOT NULL, to_id TEXT, message_id TEXT, text TEXT NOT NULL,
norm TEXT NOT NULL);
CREATE TABLE traces (id INTEGER PRIMARY KEY, ts REAL NOT NULL, via TEXT NOT NULL, channel_id TEXT,
user_id TEXT NOT NULL, question TEXT NOT NULL, answer TEXT NOT NULL, ms INTEGER NOT NULL, steps TEXT NOT NULL);";
#[cfg(test)]
mod tests {
use super::*;
use std::path::PathBuf;
fn db(tag: &str) -> (PathBuf, Connection) {
let dir = std::env::temp_dir().join(format!("jarvis-history-view-{tag}-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
let path = dir.join("history.sqlite");
let c = Connection::open(&path).unwrap();
c.pragma_update(None, "journal_mode", "WAL").unwrap();
c.execute_batch(TEST_SCHEMA).unwrap();
(path, c)
}
fn rec(c: &Connection, ts: f64, kind: &str, ch: &str, author: &str, name: &str, to: Option<&str>, text: &str) {
c.execute("INSERT INTO history(ts, kind, channel_id, author_id, author_name, to_id, text, norm) VALUES (?,?,?,?,?,?,?,?)",
rusqlite::params![ts, kind, ch, author, name, to, text, fold(text)]).unwrap();
}
fn trace(c: &Connection, ts: f64, via: &str, ch: Option<&str>, user: &str, q: &str, a: &str, steps: &str) {
c.execute("INSERT INTO traces(ts, via, channel_id, user_id, question, answer, ms, steps) VALUES (?,?,?,?,?,?,?,?)",
rusqlite::params![ts, via, ch, user, q, a, 900, steps]).unwrap();
}
/// Alice speaks and Jarvis answers by voice; Bob writes in chat and Jarvis (bot 900) answers there
/// and also posts a reminder of its own.
fn sample(tag: &str) -> PathBuf {
let (path, c) = db(tag);
rec(&c, 10.0, "voice", "vc", "1", "Alice", None, "서울 날씨 어때");
trace(&c, 11.0, "voice", Some("vc"), "1", "서울 날씨 어때", "맑습니다",
r#"[{"kind":"tools","names":["getWeather"]},{"kind":"think","text":"날씨 도구를 쓰자"}]"#);
rec(&c, 12.0, "reply", "vc", "", "Jarvis", Some("1"), "맑습니다");
rec(&c, 20.0, "chat", "ch", "2", "Bob", None, "Hello THERE");
trace(&c, 21.0, "chat", Some("ch"), "2", "Hello THERE", "안녕하세요", "[]");
rec(&c, 22.0, "chat", "ch", "900", "Jarvis", Some("2"), "안녕하세요");
rec(&c, 30.0, "chat", "ch", "900", "Jarvis", None, "약속 알림");
path
}
fn kinds(v: &Value) -> Vec<(String, String)> {
v["items"].as_array().unwrap().iter()
.map(|i| (i["type"].as_str().unwrap().into(), i["text"].as_str().or(i["question"].as_str()).unwrap().into()))
.collect()
}
#[test]
fn everything_comes_in_time_order_with_who_said_it() {
let path = sample("all");
let v = query(&path, None, &Query::default()).unwrap();
let k = kinds(&v);
assert_eq!(k.iter().map(|(t, _)| t.as_str()).collect::<Vec<_>>(),
["said", "thought", "answered", "said", "thought", "answered", "answered"]);
let items = v["items"].as_array().unwrap();
assert_eq!(items[2]["to"], json!({"id": "1", "name": "Alice"}));
assert_eq!(items[1]["who"]["name"], "Alice");
assert_eq!(items[1]["steps"][1]["text"], "날씨 도구를 쓰자");
assert_eq!(items[1]["ms"], 900);
// Jarvis's reminder counts as its own words because it answered in chat before.
assert_eq!(k[6], ("answered".into(), "약속 알림".into()));
assert_eq!(v["people"], json!([{"id": "1", "name": "Alice"}, {"id": "2", "name": "Bob"}]));
assert_eq!(v["channels"], json!([{"id": "ch", "via": "chat"}, {"id": "vc", "via": "voice"}]));
assert_eq!(v["more"], false);
}
#[test]
fn the_filters_pick_kinds_people_places_text_and_time() {
let path = sample("filters");
let only = |q: Query| kinds(&query(&path, Some("900"), &q).unwrap());
assert_eq!(only(Query { answered: false, thought: false, ..Query::default() }),
[("said".into(), "서울 날씨 어때".into()), ("said".into(), "Hello THERE".into())]);
assert_eq!(only(Query { said: false, answered: false, ..Query::default() }).len(), 2);
assert_eq!(only(Query { via: Some("voice".into()), ..Query::default() }).len(), 3);
assert_eq!(only(Query { via: Some("task".into()), ..Query::default() }), Vec::<(String, String)>::new());
assert_eq!(only(Query { person: Some("2".into()), ..Query::default() }).len(), 3);
assert_eq!(only(Query { channel: Some("vc".into()), ..Query::default() }).len(), 3);
// Text search ignores case, and finds a trace by what it thought.
assert_eq!(only(Query { find: Some("hello there".into()), thought: false, ..Query::default() }),
[("said".into(), "Hello THERE".into())]);
assert_eq!(only(Query { find: Some("도구를".into()), ..Query::default() }),
[("thought".into(), "서울 날씨 어때".into())]);
assert_eq!(only(Query { find: Some("100%".into()), ..Query::default() }).len(), 0);
assert_eq!(only(Query { since: Some(20.0), until: Some(30.0), ..Query::default() }).len(), 3);
}
#[test]
fn the_newest_come_first_when_there_are_more_than_asked() {
let path = sample("limit");
let v = query(&path, None, &Query { limit: 2, ..Query::default() }).unwrap();
assert_eq!(kinds(&v), [("answered".into(), "안녕하세요".into()), ("answered".into(), "약속 알림".into())]);
assert_eq!(v["more"], true);
}
/// Every item, walking back page by page with the cursor of the oldest one shown.
#[test]
fn pages_walk_back_through_everything_past_any_limit_even_at_equal_times() {
let (path, c) = db("pages");
for i in 0..7 {
// Records and traces at the same moments, so a page edge falls inside equal times.
rec(&c, (i / 2) as f64, "voice", "vc", "1", "Alice", None, &format!("말 {i}"));
trace(&c, (i / 2) as f64, "voice", Some("vc"), "1", &format!("생각 {i}"), "", "[]");
}
let all = query(&path, None, &Query { limit: MAX_LIMIT, ..Query::default() }).unwrap()["items"].clone();
let all: Vec<Value> = all.as_array().unwrap().clone();
assert_eq!(all.len(), 14);
let cursor = |i: &Value| Cursor::of(&json!({"at": i["at"], "key": i["key"]})).unwrap();
let mut got: Vec<Value> = Vec::new();
let mut before = None;
loop {
let v = query(&path, None, &Query { limit: 3, before, ..Query::default() }).unwrap();
let page = v["items"].as_array().unwrap().clone();
before = page.first().map(cursor);
got.splice(0..0, page);
if v["more"] == false { break; }
}
assert_eq!(got, all);
// From a cursor on: that item and everything newer, whatever the limit was before.
let from = query(&path, None, &Query { limit: MAX_LIMIT, from: Some(cursor(&all[5])), ..Query::default() }).unwrap();
assert_eq!(from["items"].as_array().unwrap()[..], all[5..]);
assert!(Cursor::of(&json!({"at": 1.0, "key": "x1"})).is_none());
}
#[test]
fn a_trace_still_being_made_reads_as_pending_with_its_steps_so_far() {
let (path, c) = db("pending");
rec(&c, 10.0, "voice", "vc", "1", "Alice", None, "서울 날씨 어때");
c.execute("INSERT INTO traces(ts, via, channel_id, user_id, question, answer, ms, steps) VALUES (?,?,?,?,?,?,?,?)",
rusqlite::params![10.5, "voice", "vc", "1", "서울 날씨 어때", "", -1, r#"[{"kind":"tools","names":["getWeather"]}]"#])
.unwrap();
let v = query(&path, None, &Query::default()).unwrap();
let t = &v["items"][1];
assert_eq!((t["type"].as_str(), t["pending"].as_bool()), (Some("thought"), Some(true)));
assert_eq!(t["steps"][0]["names"], json!(["getWeather"]));
let done = query(&sample("pending-done"), None, &Query::default()).unwrap();
assert_eq!(done["items"][1]["pending"], false);
}
#[test]
fn the_bot_id_comes_from_its_token() {
assert_eq!(bot_id_of_token("MTIzNDU2Nzg5MDEyMzQ1Njc4.GxYzAb.abcdef").as_deref(), Some("123456789012345678"));
assert_eq!(bot_id_of_token("bm90IGFuIGlk.x.y"), None);
assert_eq!(bot_id_of_token(""), None);
}
#[test]
fn a_missing_store_or_one_without_traces_reads_as_empty() {
let dir = std::env::temp_dir().join(format!("jarvis-history-view-none-{}", std::process::id()));
let v = query(&dir.join("history.sqlite"), None, &Query::default()).unwrap();
assert_eq!((v["items"].clone(), v["missing"].clone()), (json!([]), json!(true)));
let (path, c) = db("old");
c.execute_batch("DROP TABLE traces").unwrap();
rec(&c, 1.0, "voice", "vc", "1", "Alice", None, "안녕");
assert_eq!(kinds(&query(&path, None, &Query::default()).unwrap()), [("said".into(), "안녕".into())]);
}
}

View File

@@ -18,6 +18,7 @@ pub mod discord_setup;
pub mod download;
pub mod earcon;
pub mod features;
pub mod history_view;
pub mod game;
pub mod frames;
pub mod install;

View File

@@ -221,6 +221,9 @@ pub struct Settings {
/// Jarvis's voice channel (admin.spec.md, "Schedules"); None: not delivered then.
pub schedule_channel: Option<u64>,
pub pc_control: PcControlSettings,
/// The window's close button (X) hides it to the tray instead of quitting (`app.closeButton`:
/// "tray" or "quit", default "quit"; admin.spec.md, "Window and Windows build").
pub close_to_tray: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -272,6 +275,7 @@ impl Default for Settings {
pc_control: PcControlSettings { allowed_users: vec![], view: Level::Auto, click: Level::Ask,
type_text: Level::Ask, run: Level::Ask,
screen_exclude: ["1Password", "Bitwarden", "KeePass", "KeePassXC"].map(String::from).into() },
close_to_tray: false,
}
}
}
@@ -618,6 +622,11 @@ pub fn parse_settings(raw: &Value) -> Result<Settings, SettingsError> {
game: parse_game(raw, &d.game)?,
schedule_channel,
pc_control: parse_pc_control(raw, &d.pc_control)?,
close_to_tray: match get_str(section(raw, "app")?, "closeButton", "app", "quit")?.as_str() {
"tray" => true,
"quit" => false,
_ => return err("app.closeButton must be tray or quit"),
},
})
}
@@ -984,6 +993,16 @@ mod tests {
}
}
#[test]
fn the_close_button_choice_is_read_and_checked() {
assert!(!parse_settings(&json!({})).unwrap().close_to_tray, "closing quits by default");
assert!(parse_settings(&json!({"app": {"closeButton": "tray"}})).unwrap().close_to_tray);
assert!(!parse_settings(&json!({"app": {"closeButton": "quit"}})).unwrap().close_to_tray);
for bad in [json!({"app": {"closeButton": "hide"}}), json!({"app": {"closeButton": 1}}), json!({"app": 1})] {
assert!(parse_settings(&bad).unwrap_err().0.contains("app"), "{bad}");
}
}
#[test]
fn game_detection_settings_are_read_and_checked() {
assert_eq!(parse_settings(&json!({})).unwrap().game, GameSettings { detect: true, games: vec![], not_games: vec![], other_room_gb: 1.0, reserve_gb: 8.0, revert_seconds: 30, pause_in_game: false });

View File

@@ -24,6 +24,7 @@ pub enum Screen {
Game,
Schedule,
PcControl,
App,
}
#[derive(Debug, Clone, PartialEq, serde::Serialize)]
@@ -159,6 +160,8 @@ pub fn fields() -> Vec<Field> {
f("game.revertSeconds", Game, Int { min: 0, max: 600 }, json!(30), "게임이 끝난 뒤 평소 배치로 돌아가기까지(초)"),
f("game.pauseInGame", Game, Bool, json!(false), "게임 중 일시정지(대답하지 않음)"),
f("game.notGames", Game, TextList { max_items: 100, nullable: false }, json!([]), "게임이 아닌 프로그램(파일 이름)"),
// The window (admin.spec.md, "Window and Windows build"): read when the close button is pressed.
f("app.closeButton", App, Choice { values: &["quit", "tray"] }, json!("quit"), "창 닫기(X) 버튼을 누르면"),
]
}

View File

@@ -0,0 +1,48 @@
// The 대화 screen's paging (app/ui/talk.js; admin.spec.md, "Screens"). Run: node --test app/tests/ui/talk.test.mjs
import test from "node:test";
import assert from "node:assert/strict";
import { PAGE, PAGE_MAX, compare, empty, withLive, withOlder } from "../../ui/talk.js";
const rec = (n) => ({ key: `h${n}`, at: n, type: "said", text: `말 ${n}` });
const range = (a, b) => Array.from({ length: b - a }, (_, i) => rec(a + i));
const keys = (s) => s.older.concat(s.shown).map((i) => i.key);
/** The screen's state after the first page and as many "이전 기록 더 보기" as the store allows. */
function allLoaded(total) {
const store = range(0, total);
let s = withLive(empty(), store.slice(-PAGE), total > PAGE);
while (s.hasOlder) {
const oldest = (s.older[0] || s.shown[0]).at;
const before = store.filter((i) => i.at < oldest);
s = withOlder(s, before.slice(-PAGE), before.length > PAGE);
}
return { s, store };
}
test("every older page joins once, past the live window", () => {
const { s } = allLoaded(2501);
assert.equal(s.shown.length, PAGE_MAX);
assert.deepEqual(keys(s), range(0, 2501).map((i) => i.key));
});
test("the same older page arriving twice is not added twice", () => {
let s = withLive(empty(), range(300, 500), true);
s = withOlder(s, range(100, 300), true);
s = withOlder(s, range(100, 300), true);
assert.deepEqual(keys(s), range(100, 500).map((i) => i.key));
});
test("a new item on a full window keeps everything loaded, in order and once", () => {
const { s, store } = allLoaded(2501);
const now = store.concat(rec(2501));
// The live answer: from the window's start, at most PAGE_MAX, newest first cut.
const since = now.filter((i) => compare(i, s.shown[0]) >= 0);
const next = withLive(s, since.slice(-PAGE_MAX), since.length > PAGE_MAX);
assert.deepEqual(keys(next), range(0, 2502).map((i) => i.key));
assert.equal(next.shown.length, PAGE_MAX);
});
test("items are ordered by time, then records before traces, then id", () => {
const items = [{ key: "t2", at: 1 }, { key: "h10", at: 1 }, { key: "h9", at: 1 }, { key: "h1", at: 0 }];
assert.deepEqual(items.sort(compare).map((i) => i.key), ["h1", "h9", "h10", "t2"]);
});

View File

@@ -2,6 +2,8 @@
// the Tauri shell and the development server load the same files. Every action goes through
// api(command, args), which the shell answers with AdminApi::call.
import { PAGE, PAGE_MAX, cursorOf, empty, withLive, withOlder } from "./talk.js";
const $ = (sel, el = document) => el.querySelector(sel);
const h = (tag, attrs = {}, ...kids) => {
const el = document.createElement(tag);
@@ -40,6 +42,7 @@ const LEVEL = { auto: "자동", ask: "먼저 묻기", never: "안 함" };
const CHOICE = {
"pcControl.view": LEVEL, "pcControl.click": LEVEL, "pcControl.type": LEVEL, "pcControl.run": LEVEL,
"call.mode": { wakeWord: "호출어로 부를 때만", addressed: "자비스에게 하는 말로 보이면", everything: "모든 말" },
"app.closeButton": { quit: "완전 종료", tray: "트레이로 최소화" },
"response.policy": { first: "처음 대화만", inOrder: "순서대로", latest: "가장 최근 것", important: "중요한 것 먼저" },
};
const REASON = { busy: "다른 답을 하는 중", queue_full: "대기열이 가득 참", replaced: "더 새 요청이 대신함",
@@ -382,7 +385,8 @@ const ACTIVITY = { "chat.send": "채팅 보내기", "chat.edit": "채팅 고치
"chat.delete": "채팅 지우기", "chat.pin": "고정", "chat.unpin": "고정 풀기",
"schedule.remind": "예약 알림 전달", "schedule.task": "정기 작업 전달", "collect.notify": "수집 소식 알림" };
/** What Jarvis did outside its answers (admin.spec.md, "Activity"): kind, target, who asked, outcome. */
function activityScreen() {
/** The 로그 screen's 한 일 view: what Jarvis did in chat channels and schedule deliveries. */
function activityView() {
const list = h("div");
const load = async () => {
try {
@@ -397,9 +401,201 @@ function activityScreen() {
} catch (err) { fail(err); }
};
load();
return h("div", {}, h("h1", {}, "한 일"), h("div", { class: "card" },
return h("div", { class: "card" },
h("div", { class: "hint" }, "자비스가 채팅 채널에서 한 동작과 예약 전달을 종류, 대상, 시킨 사람, 결과만 남깁니다. 내용은 남기지 않고 30일 뒤 지웁니다."),
h("div", { class: "field" }, h("button", { class: "btn", onclick: load }, "새로 고침")), list));
h("div", { class: "field" }, h("button", { class: "btn", onclick: load }, "새로 고침")), list);
}
// ---- conversations ------------------------------------------------------------------------------
const VIA = { voice: "음성", chat: "채팅", task: "정기 작업" };
const SKIPPED = { not_allowed: "허용되지 않은 도구라 부르지 않음", duplicate: "같은 호출을 되풀이해 부르지 않음" };
const p2 = (n) => String(n).padStart(2, "0");
const dayOf = (ts) => { const d = new Date(ts * 1000); return `${d.getFullYear()}-${p2(d.getMonth() + 1)}-${p2(d.getDate())}`; };
const timeOf = (ts) => { const d = new Date(ts * 1000); return `${p2(d.getHours())}:${p2(d.getMinutes())}:${p2(d.getSeconds())}`; };
const pre = (text) => h("pre", { class: "pre" }, text);
/** One step of how an answer was made (history.spec.md, "Traces"). */
function traceStep(s) {
if (s.kind === "records") {
const lines = (title, xs) => xs.length ? h("details", {}, h("summary", { class: "small" }, `${title} ${xs.length}줄`), pre(xs.join("\n"))) : null;
return h("div", { class: "step-row" }, h("div", { class: "k" }, "참고한 기록"),
h("div", {}, (s.recent || []).length + (s.matches || []).length ? null : h("span", { class: "muted" }, "없음"),
lines("최근 대화", s.recent || []), lines("관련 기록", s.matches || []),
s.notes ? h("div", { class: "small muted" }, `사람별 지침 ${s.notes}개`) : null));
}
if (s.kind === "tools") return h("div", { class: "step-row" }, h("div", { class: "k" }, "쓸 수 있게 고른 도구"),
h("div", { class: "row" }, (s.names || []).length ? s.names.map((n) => h("span", { class: "badge" }, n)) : h("span", { class: "muted" }, "없음")));
if (s.kind === "plan") return h("div", { class: "step-row" }, h("div", { class: "k" }, "계획"), h("ol", { class: "plan" }, (s.steps || []).map((x) => h("li", {}, x))));
if (s.kind === "think") return h("div", { class: "step-row" }, h("div", { class: "k" }, "모델 생각"), pre(s.text || ""));
if (s.kind === "tool") {
const state = s.skipped ? ["건너뜀", "warn"] : s.ok ? ["성공", "ok"] : ["실패", "bad"];
return h("div", { class: "step-row" }, h("div", { class: "k" }, "도구 호출"),
h("div", {}, h("div", { class: "row" }, h("b", {}, s.name), h("span", { class: "badge " + state[1] }, state[0])),
Object.keys(s.args || {}).length ? pre(JSON.stringify(s.args, null, 2)) : null,
s.skipped ? h("div", { class: "small muted" }, SKIPPED[s.skipped] || s.skipped) : null,
s.result ? h("details", {}, h("summary", { class: "small" }, "결과"), pre(s.result)) : null));
}
return h("div", { class: "step-row" }, h("div", { class: "k" }, s.kind), pre(JSON.stringify(s, null, 2)));
}
/** The 대화 screen (admin.spec.md, "Conversations"): what people said, what Jarvis answered, how. */
function conversationScreen() {
const chip = (label, on = true) => { const c = h("input", { type: "checkbox", checked: on }); return [c, h("label", { class: "chip" }, c, label)]; };
const [said, saidChip] = chip("사람 말"), [answered, answeredChip] = chip("자비스 말"), [thought, thoughtChip] = chip("자비스 생각");
const [session, sessionChip] = chip("현재 세션", false); // from when the bot was last started
const via = h("select", {}, h("option", { value: "" }, "모든 곳"), Object.entries(VIA).map(([v, t]) => h("option", { value: v }, t)));
const person = h("select", {}, h("option", { value: "" }, "모든 사람"));
const channel = h("select", {}, h("option", { value: "" }, "모든 채널"));
const day = h("input", { type: "date" });
const find = h("input", { type: "text", placeholder: "찾기 (말, 답, 생각)", style: "max-width:220px" });
const live = h("input", { type: "checkbox", class: "switch", checked: true });
// Traces the user opened stay open across refreshes, and so does one seen while being made
// unless the user closed it.
const open = new Set(), shut = new Set();
// `page`: the live window and the older pages (talk.js). Each filter change starts a new epoch;
// answers from an earlier epoch, and live answers older than the newest one asked, are dropped.
let expandAll = false, sig = null, page = empty(), missing = false, sessionAt = null;
let epoch = 0, liveSeq = 0, first = true, loadingOlder = false;
const box = h("div", { class: "talk" });
const summary = h("div", { class: "small muted" });
const more = h("button", { class: "btn", hidden: true, onclick: () => loadOlder() }, "이전 기록 더 보기");
const fill = (sel, list, label) => {
const key = JSON.stringify(list);
if (sel.dataset.list === key) return; // an open picker is not rebuilt under the user
sel.dataset.list = key;
const keep = sel.value;
sel.replaceChildren(sel.firstChild, ...list.map((x) => h("option", { value: x.id }, label(x))));
sel.value = list.some((x) => x.id === keep) ? keep : "";
};
const channelLabel = (c) => c.name ? `${c.name} (${VIA[c.via]})` : `${VIA[c.via]} 채널 ${c.id}`;
const channelName = (id) => { const c = (load.channels || []).find((x) => x.id === id); return c ? channelLabel(c) : id || ""; };
const copy = (text) => async () => { try { await navigator.clipboard.writeText(text); toast("복사했습니다"); } catch (e) { fail(e); } };
function item(i) {
const where = h("span", { class: "small muted" }, timeOf(i.at), " · ", VIA[i.via] || i.via, i.channel ? " · " + channelName(i.channel) : "");
if (i.type === "thought") {
const tools = (i.steps || []).filter((s) => s.kind === "tool" && !s.skipped).length;
const summary = h("summary", {}, h("span", { class: "who" }, "자비스 생각"), " ",
h("span", { class: "small muted" }, `${i.who.name || i.who.id}의 말에 답하며`, tools ? ` · 도구 ${tools}번` : "",
i.pending ? " · 답을 만드는 중" : ` · ${(i.ms / 1000).toFixed(1)}초${i.answer ? "" : " · 답 없음"}`), " ", where);
if (i.pending && !shut.has(i.key)) open.add(i.key); // stays open with its answer once done
const d = h("details", { class: "msg thought", open: expandAll || open.has(i.key) },
summary,
h("div", { class: "steps" },
h("div", { class: "step-row" }, h("div", { class: "k" }, "받은 말"), h("div", {}, i.question)),
(i.steps || []).map(traceStep),
h("div", { class: "step-row" }, h("div", { class: "k" }, "답"), i.pending ? h("div", {}, h("span", { class: "badge warn" }, "만드는 중"))
: i.answer ? h("div", {}, i.answer) : h("span", { class: "badge bad" }, "답하지 못함"))));
summary.addEventListener("click", () => {
if (d.open) { open.delete(i.key); shut.add(i.key); } else { open.add(i.key); shut.delete(i.key); }
});
return d;
}
const mine = i.type === "answered";
const who = mine ? (i.to ? `자비스 → ${i.to.name || i.to.id}` : "자비스") : (i.who.name || i.who.id);
return h("div", { class: "msg " + (mine ? "answered" : "said") },
h("div", { class: "row" }, h("span", { class: "who" }, who), where,
h("button", { class: "linkbtn small", title: "글 복사", onclick: copy(i.text) }, "복사")),
h("div", { class: "text" }, i.text));
}
function filters() {
const since = day.value ? new Date(day.value + "T00:00:00").getTime() / 1000 : null;
return { said: said.checked, answered: answered.checked, thought: thought.checked,
via: via.value || null, person: person.value || null, channel: channel.value || null, find: find.value || null,
since, until: since == null ? null : since + 86400, session: session.checked };
}
function render(keepTop = false) {
const items = page.older.concat(page.shown);
// The whole items, so an edited message or a changed answer is redrawn too.
const s = JSON.stringify([items, expandAll, page.hasOlder, missing, session.checked, sessionAt]);
if (s === sig) return;
sig = s;
const stick = box.scrollTop + box.clientHeight >= box.scrollHeight - 30, fromBottom = box.scrollHeight - box.scrollTop;
const kids = [];
let lastDay = null;
for (const i of items) {
const d = dayOf(i.at);
if (d !== lastDay) { kids.push(h("div", { class: "day" }, d)); lastDay = d; }
kids.push(item(i));
}
box.replaceChildren(...(kids.length ? kids : [h("div", { class: "muted" },
missing ? "아직 대화 기록이 없습니다. 서비스를 켜고 자비스와 이야기하면 여기에 나옵니다."
: session.checked && sessionAt == null ? "앱을 켠 뒤 아직 봇을 시작하지 않았습니다. 대시보드에서 시작하면 그때부터의 대화가 여기에 나옵니다."
: "조건에 맞는 기록이 없습니다.")]));
more.hidden = !page.hasOlder;
const n = (t) => items.filter((i) => i.type === t).length;
summary.textContent = (session.checked && sessionAt != null ? `${dayOf(sessionAt)} ${timeOf(sessionAt)}에 시작한 봇부터 · ` : "")
+ `사람 말 ${n("said")} · 자비스 말 ${n("answered")} · 생각 ${n("thought")}` + (page.hasOlder ? " (이전 기록 더 있음)" : "");
if (keepTop) box.scrollTop = box.scrollHeight - fromBottom;
else if (stick || first) box.scrollTop = box.scrollHeight;
first = false;
}
function lists(r) {
load.channels = r.channels;
fill(person, r.people, (p) => `${p.name || p.id}`);
fill(channel, r.channels, channelLabel);
}
/** The live window, from its first item on (the newest page at first), re-read on every tick. */
async function load() {
const ep = epoch, my = ++liveSeq, from = page.from;
try {
const r = await api("history_query", { ...filters(), ...(from ? { from, limit: PAGE_MAX } : { limit: PAGE }) });
if (ep !== epoch || my !== liveSeq) return;
lists(r);
missing = !!r.missing;
// A new start while the current session is shown: its window starts over at the new start.
if (session.checked && sessionAt != null && r.session !== sessionAt) { sessionAt = r.session; reload(); return; }
sessionAt = r.session ?? null;
page = withLive(page, r.items, r.more);
render();
} catch (e) { fail(e); }
}
/** The page before the oldest item loaded; one at a time, so a double click adds it once. */
async function loadOlder() {
const oldest = page.older[0] || page.shown[0];
if (!oldest || loadingOlder) return;
const ep = epoch;
loadingOlder = more.disabled = true;
try {
const r = await api("history_query", { ...filters(), before: cursorOf(oldest), limit: PAGE });
if (ep !== epoch) return;
++liveSeq; // a live answer asked with the old window would drop this page
page = withOlder(page, r.items, r.more);
render(true);
} catch (e) { fail(e); } finally {
if (ep === epoch) loadingOlder = more.disabled = false;
}
}
const reload = () => {
epoch++; sig = null; page = empty(); first = true; loadingOlder = more.disabled = false; load();
};
for (const el of [said, answered, thought, session, via, person, channel, day]) el.addEventListener("change", reload);
find.addEventListener("input", () => { clearTimeout(find.t); find.t = setTimeout(reload, 300); });
const view = h("div", {}, h("h1", {}, "대화"),
h("div", { class: "card filters" },
h("div", { class: "row" }, saidChip, answeredChip, thoughtChip, sessionChip),
h("div", { class: "row" }, via, person, channel, day, find),
h("div", { class: "row" }, h("label", { class: "row small muted" }, live, "실시간"),
h("button", { class: "btn", onclick: () => { expandAll = !expandAll; open.clear(); shut.clear(); sig = null; load(); } }, "생각 모두 펼치기/접기"),
h("button", { class: "btn", onclick: () => { sig = null; load(); } }, "새로 고침"), summary)),
h("div", { class: "hint", style: "margin:8px 0" }, "사람이 한 말, 자비스의 답, 자비스가 답을 만든 과정(참고한 기록, 고른 도구, 계획, 도구 호출과 결과, 모델 생각)을 시간순으로 보여 줍니다. 자비스가 말을 알아들은 순간 생각이 나타나고, 답을 만드는 동안 단계가 하나씩 채워집니다. 모델 생각은 생각 모드가 켜진 답에만 있습니다. 생각 기록은 30일 동안 둡니다. 실시간으로 다시 읽는 것은 최근 2,000개까지이고, 그보다 앞서 불러온 기록의 수정과 삭제는 화면을 다시 열면 보입니다."),
h("div", { class: "row", style: "justify-content:center" }, more), box);
load();
// Every second while an answer is being made, so its trace fills in as it goes; else every 3 seconds.
let ticks = 0;
const tick = () => {
const making = page.shown.some((i) => i.pending);
if (live.checked && (making || ++ticks % 3 === 0)) load();
};
return { view, tick };
}
async function settingsScreen(screen, title, extra) {
@@ -619,7 +815,7 @@ function logsScreen() {
find.addEventListener("input", () => { clearTimeout(find.t); find.t = setTimeout(reload, 300); });
const today = new Date().toISOString().slice(0, 10);
const from = h("input", { type: "date", value: today }), to = h("input", { type: "date", value: today });
const view = h("div", {}, h("h1", {}, "로그"),
const logs = h("div", {},
h("div", { class: "row", style: "margin-bottom:10px" }, tab, level, find, h("label", { class: "row small muted" }, pause, "일시정지"),
h("button", { class: "btn", onclick: async () => {
try {
@@ -637,14 +833,25 @@ function logsScreen() {
toast(`${r.path}에 저장했습니다${r.droppedLines ? ` (10MB를 넘어 오래된 ${r.droppedLines}줄은 뺐습니다)` : ""}`);
} catch (e) { fail(e); }
} }, "zip으로 저장")));
// 로그 and 한 일 (the activity) on one screen; 한 일 is read again each time it is opened.
const body = h("div");
const switches = [["로그", () => logs], ["한 일", activityView]].map(([label, make]) => {
const b = h("button", { class: "btn", onclick: () => {
for (const x of switches) x.classList.toggle("primary", x === b);
body.replaceChildren(make());
} }, label);
return b;
});
const view = h("div", {}, h("h1", {}, "로그"), h("div", { class: "row", style: "margin-bottom:12px" }, switches), body);
switches[0].click();
reload();
return { view, tick: poll };
return { view, tick: () => logs.isConnected && poll() };
}
// ---- update -------------------------------------------------------------------------------------
/** The update screen: the version here, the newest release, its download and install. */
function updateScreen() {
/** The 앱 screen's update card: the version here, the newest release, its download and install. */
function updateCard() {
const body = h("div");
let key = null;
async function tick() {
@@ -662,7 +869,7 @@ function updateScreen() {
const line = { idle: "아직 확인하지 않았습니다", checking: "확인하는 중…", upToDate: "최신 버전입니다",
available: `새 버전 ${u.latest?.version}이 있습니다`, downloading: `받는 중${pct != null ? ` ${pct}%` : ""}`,
ready: `${u.latest?.version}을 설치할 준비가 됐습니다`, failed: u.error ?? "실패했습니다" }[u.phase] ?? u.phase;
body.replaceChildren(h("div", { class: "card" },
body.replaceChildren(h("div", { class: "card" }, h("h2", {}, "업데이트"),
h("div", { class: "kv" }, h("span", { class: "k" }, "현재 버전"), h("span", {}, u.current),
h("span", { class: "k" }, "상태"), h("span", { style: u.phase === "failed" ? "color:var(--bad)" : "" }, line)),
h("div", { class: "row", style: "margin-top:12px" },
@@ -671,18 +878,18 @@ function updateScreen() {
u.phase === "ready" ? act("update_install", "설치하고 다시 시작", true) : null),
u.phase === "ready" ? h("p", { class: "small muted" }, "설치하면 봇과 서비스를 멈추고 Jarvis를 닫은 뒤 새 버전을 설치하고 다시 켭니다. Windows가 관리자 권한을 한 번 묻습니다.") : null),
u.latest?.notes ? h("div", { class: "card" }, h("h2", {}, `${u.latest.version} 바뀐 점`),
h("pre", { class: "small", style: "white-space:pre-wrap" }, u.latest.notes)) : null);
h("pre", { class: "small", style: "white-space:pre-wrap" }, u.latest.notes)) : "");
}
tick();
return { view: h("div", {}, h("h1", {}, "업데이트"), body), tick };
return { view: body, tick };
}
/** Look for a new version once when the app opens; the nav button says so when there is one. */
async function checkUpdate() {
try {
const u = await api("update_check");
if (u.latest) { $("#nav-update").textContent = "업데이트 (새 버전)"; toast(`새 버전 ${u.latest.version}이 있습니다. 업데이트 화면에서 설치할 수 있습니다.`); }
} catch (e) { /* offline: the update screen shows why */ }
if (u.latest) { $("#nav-app").textContent = "앱 (새 버전)"; toast(`새 버전 ${u.latest.version}이 있습니다. 앱 화면에서 설치할 수 있습니다.`); }
} catch (e) { /* offline: the 앱 screen shows why */ }
}
// ---- navigation ---------------------------------------------------------------------------------
@@ -718,17 +925,20 @@ async function show(name) {
try {
if (name === "dashboard") { screen.replaceChildren(); await refresh(); ticker = setInterval(refresh, 1000); return; }
if (name === "logs") { const l = logsScreen(); screen.replaceChildren(l.view); ticker = setInterval(l.tick, 1000); return; }
if (name === "activity") { screen.replaceChildren(activityScreen()); return; }
if (name === "conversations") { const c = conversationScreen(); screen.replaceChildren(c.view); ticker = setInterval(c.tick, 1000); return; }
if (name === "notes") { screen.replaceChildren(notesScreen()); return; }
if (name === "update") { const u = updateScreen(); screen.replaceChildren(u.view); ticker = setInterval(u.tick, 1000); return; }
const titles = { bot: "봇", channels: "채널·호출", chat: "채팅 채널", memory: "대화 기억", model: "모델", features: "기능",
collect: "백그라운드 수집", game: "게임 모드", schedule: "예약", pcControl: "PC 제어" };
const extra = name === "bot" ? await tokenCard() : name === "features" ? await displayDriverCard() : null;
collect: "백그라운드 수집", game: "게임 모드", schedule: "예약", pcControl: "PC 제어", app: "앱" };
const update = name === "app" ? updateCard() : null;
const extra = name === "bot" ? await tokenCard() : name === "features" ? await displayDriverCard()
: name === "app" ? h("div", {}, update.view, h("div", { class: "hint", style: "margin:12px 0" }, "트레이로 최소화하면 창만 숨고 봇과 서비스는 계속 돕니다. 작업 표시줄 오른쪽의 Jarvis 아이콘을 누르면 창이 다시 열리고, 아이콘의 오른쪽 클릭 메뉴에서 완전 종료할 수 있습니다. 저장하면 바로 적용됩니다.")) : null;
const view = await settingsScreen(name, titles[name], extra);
if (name === "collect") view.append(await collectResults());
if (name === "schedule") view.append(await scheduleList());
if (name === "pcControl") view.append(await permissionsCard());
if (my === gen) screen.replaceChildren(view);
if (my !== gen) return;
screen.replaceChildren(view);
if (update) ticker = setInterval(update.tick, 1000);
} catch (e) { fail(e); }
}

View File

@@ -12,6 +12,7 @@
<nav class="side">
<div class="brand">Jarvis</div>
<button data-screen="dashboard" class="nav">대시보드</button>
<button data-screen="conversations" class="nav">대화</button>
<button data-screen="bot" class="nav">봇</button>
<button data-screen="channels" class="nav">채널·호출</button>
<button data-screen="chat" class="nav">채팅 채널</button>
@@ -22,10 +23,9 @@
<button data-screen="schedule" class="nav">예약</button>
<button data-screen="pcControl" class="nav">PC 제어</button>
<button data-screen="notes" class="nav">사람별 지침</button>
<button data-screen="activity" class="nav">한 일</button>
<button data-screen="game" class="nav">게임 모드</button>
<button data-screen="logs" class="nav">로그</button>
<button data-screen="update" class="nav" id="nav-update">업데이트</button>
<button data-screen="app" class="nav" id="nav-app">앱</button>
<div class="side-foot" id="version"></div>
</nav>
<main id="screen" class="screen"></main>

View File

@@ -73,3 +73,23 @@ a { color: var(--accent2); }
.row > select, .row > input[type=date] { width: auto; }
input[type=date] { color-scheme: dark; }
th, .btn { white-space: nowrap; }
.filters { display: flex; flex-direction: column; gap: 10px; }
.filters select, .filters input[type=date] { width: auto; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line2); border-radius: 999px; padding: 4px 12px; cursor: pointer; color: var(--ink2); }
.chip:has(input:checked) { border-color: var(--accent); color: var(--ink); background: var(--s3); }
.talk { background: var(--s1); border: 1px solid var(--line); border-radius: 10px; height: 62vh; overflow: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; }
.day { align-self: center; color: var(--ink4); font-size: 12px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 12px; margin: 6px 0; }
.msg { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; max-width: 85%; background: var(--s2); }
.msg.said { align-self: flex-start; }
.msg.answered { align-self: flex-end; border-color: #2f3570; background: #12142a; }
.msg.thought { align-self: stretch; max-width: none; border-style: dashed; background: var(--canvas); }
.msg.thought > summary { cursor: pointer; }
.msg .who { font-weight: 600; }
.msg .text { white-space: pre-wrap; word-break: break-word; margin-top: 4px; line-height: 1.5; }
.steps { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.step-row { display: grid; grid-template-columns: 150px 1fr; gap: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.step-row .k { color: var(--ink3); font-size: 12px; padding-top: 2px; }
.pre { white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, Consolas, monospace; font-size: 12px; background: var(--s1); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; margin: 4px 0; max-height: 320px; overflow: auto; }
.plan { margin: 0; padding-left: 18px; }
.linkbtn { background: none; border: 0; color: var(--ink4); cursor: pointer; padding: 0 4px; margin-left: auto; }
.linkbtn:hover { color: var(--ink2); }

42
app/ui/talk.js Normal file
View File

@@ -0,0 +1,42 @@
// Paging of the 대화 screen (app/src/admin.spec.md, "Screens"). Pure, so app/tests/ui checks it.
//
// The screen keeps a live window, every item from the cursor `from` on (re-read on each tick, at
// most PAGE_MAX), and before it the `older` pages kept as loaded. Items are ordered like
// history_query: time, then records (`h<id>`) before traces (`t<id>`), then id.
export const PAGE = 200, PAGE_MAX = 2000;
export const cursorOf = (i) => ({ at: i.at, key: i.key });
export function compare(a, b) {
return a.at - b.at || (a.key[0] === b.key[0] ? 0 : a.key[0] < b.key[0] ? -1 : 1)
|| Number(a.key.slice(1)) - Number(b.key.slice(1));
}
export const empty = () => ({ shown: [], older: [], from: null, hasOlder: false });
/** A live answer: the items from `from` on (the newest page while there is no `from`), and
* whether there were more than it holds. */
export function withLive(s, items, more) {
let { older, hasOlder } = s;
if (!s.from) hasOlder = more;
else if (more && items.length) {
// More new items than the window holds: the shown ones it no longer reaches join the pages
// kept as loaded, so nothing the user had on screen disappears.
const seen = new Set(older.map((i) => i.key));
older = older.concat(s.shown.filter((i) => compare(i, items[0]) < 0 && !seen.has(i.key)));
}
return { shown: items, older, hasOlder, from: items.length ? cursorOf(items[0]) : s.from };
}
/** The page before the oldest item loaded: it joins the live window while that stays within
* PAGE_MAX, else the older pages. Items already loaded are not added again. */
export function withOlder(s, page, more) {
const seen = new Set(s.older.concat(s.shown).map((i) => i.key));
const fresh = page.filter((i) => !seen.has(i.key));
if (!s.older.length && s.shown.length + fresh.length <= PAGE_MAX) {
const shown = fresh.concat(s.shown);
return { ...s, shown, hasOlder: more, from: shown.length ? cursorOf(shown[0]) : s.from };
}
return { ...s, older: fresh.concat(s.older), hasOlder: more };
}

View File

@@ -61,6 +61,7 @@
| 화면 보기 | 볼 수 있는 대상(전체 화면, 모니터별, 창별), 캡처 제외 프로그램 목록, 볼 수 있는 조건, 캡처 미리 준비(말하는 중에만/항상/끔), 기본 화질 단계, 화면공유 창 분리 대기 시간, "봇용 크롬창 화면공유 선택 표시" 켜기/끄기 |
| 백그라운드 수집 | 수집 대상(사이트, 검색어, RSS), 주기, 보관 기간, 결과 보기. 기본 수집 대상은 비워 둠 |
| 데이터 | 폴더별 사용량, 캐시 정리, 데이터 이동, 설정 내보내기/가져오기, 메모리 백업 |
| 대화 | 사람이 한 말, 자비스의 답, 자비스가 답을 만든 과정(참고한 기록, 고른 도구, 계획, 도구 호출과 결과, 모델 생각)을 시간순으로 보기. 종류·장소·사람·채널·날짜·글자로 거르기, 실시간 따라가기 |
| 로그 | 실시간 로그 보기·검색·복사·다운로드 |
| 업데이트 | 새 버전 확인과 설치 (Gitea 릴리스 기준) |

View File

@@ -6,6 +6,7 @@
- 채팅은 GUI에 등록한 채팅 채널만 읽고 저장합니다. 그 밖의 채널은 읽지 않습니다. 채팅에 올라온 글은 명령이 아니라 데이터로 다룹니다.
- 음성 원본은 기본적으로 저장하지 않습니다. 디버그용 저장은 직접 켰을 때만 하고, 기간이 지나면 자동 삭제합니다.
- 대화 기록(음성 전사, 채팅 채널 메시지)은 [memory.md](memory.md) 설정대로 저장하고, 사람별로 보고 지울 수 있습니다. 기본으로 참고하는 것은 말한 사람 본인의 기록, 등록한 채팅 채널, 그리고 그 사람과 같은 음성 채널에 함께 있던 동안 다른 사람이 한 말입니다. 다른 사람 말 참고는 GUI에서 끌 수 있습니다.
- 자비스가 답을 만든 과정(참고한 기록, 고른 도구, 계획, 도구 호출과 결과, 모델 생각)은 대화 기록 저장소에 함께 남겨 관리 앱 "대화" 화면에서만 봅니다. 로그에는 넣지 않고, 30일이 지나면 지우며, 사람별로 지우면 같이 지웁니다.
- 화면 캡처는 자비스가 볼 때만 쓰고 기본적으로 저장하지 않습니다.
- 빠른 응답을 위해 미리 잡아 두는 화면도 메모리에 최근 한 장만 두고 계속 덮어씁니다.
- 캡처 제외 목록에 넣은 프로그램은 보지 않습니다.

View File

@@ -4,6 +4,7 @@ registered chat channel messages, searched per asker. Contract:
from __future__ import annotations
import json
import math
import re
import sqlite3
@@ -41,6 +42,19 @@ CREATE TABLE IF NOT EXISTS presence (
left_at REAL
);
CREATE INDEX IF NOT EXISTS presence_user ON presence(user_id, channel_id);
CREATE TABLE IF NOT EXISTS traces (
id INTEGER PRIMARY KEY,
ts REAL NOT NULL, -- when it was asked
via TEXT NOT NULL, -- voice | chat | task
channel_id TEXT, -- where it was asked; none for a task
user_id TEXT NOT NULL,
question TEXT NOT NULL,
answer TEXT NOT NULL, -- empty when the brain gave none
ms INTEGER NOT NULL, -- -1 while the answer is being made
steps TEXT NOT NULL -- JSON list (history.spec.md, "Traces")
);
CREATE INDEX IF NOT EXISTS traces_ts ON traces(ts);
CREATE INDEX IF NOT EXISTS traces_user ON traces(user_id);
"""
_WORD = re.compile(r"\w{2,}", re.UNICODE)
@@ -70,6 +84,21 @@ class Record:
text: str
@dataclass(frozen=True)
class Trace:
"""How one answer was made: never read back into a prompt (``history.spec.md``, "Traces")."""
id: int
ts: float
via: str
channel_id: Optional[str]
user_id: str
question: str
answer: str
ms: int
steps: list
@dataclass
class HistoryContext:
"""Lines for the prompt: the recent window and the search matches, kept apart for labelling."""
@@ -78,6 +107,10 @@ class HistoryContext:
matches: List[str] = field(default_factory=list)
def _steps_json(steps: list) -> str:
return json.dumps(steps, ensure_ascii=False, default=str)
def _fold(text: str) -> str:
"""One Unicode folding for stored text and query words alike (NFKC, then case folding),
so matching does not depend on SQLite's ASCII-only lower()."""
@@ -196,6 +229,47 @@ class HistoryStore:
# -- maintenance --------------------------------------------------------
def start_trace(self, via: str, channel_id: Optional[str], user_id: str, question: str, ts: float) -> int:
"""A trace from the moment it was asked: no answer yet and ``ms`` -1."""
with self._lock:
cur = self._conn.execute(
"INSERT INTO traces(ts, via, channel_id, user_id, question, answer, ms, steps) VALUES (?,?,?,?,?,'',-1,'[]')",
(ts, via, channel_id, user_id, question))
self._conn.commit()
return int(cur.lastrowid)
def trace_steps(self, trace_id: int, steps: list) -> None:
"""The steps so far of a trace still being made."""
with self._lock:
self._conn.execute("UPDATE traces SET steps=? WHERE id=?", (_steps_json(steps), trace_id))
self._conn.commit()
def finish_trace(self, trace_id: int, answer: str, steps: list, ms: int) -> None:
with self._lock:
self._conn.execute("UPDATE traces SET answer=?, steps=?, ms=? WHERE id=?",
(answer or "", _steps_json(steps), max(0, int(ms)), trace_id))
self._conn.commit()
def close_unfinished_traces(self) -> int:
"""End, with no answer, the traces a killed run left being made (the host calls it at start)."""
with self._lock:
n = self._conn.execute("UPDATE traces SET ms=0 WHERE ms < 0").rowcount
self._conn.commit()
return n
def traces_of(self, person: str) -> List[Trace]:
with self._lock:
rows = self._conn.execute(
"SELECT id, ts, via, channel_id, user_id, question, answer, ms, steps FROM traces"
" WHERE user_id=? ORDER BY ts, id", (person,)).fetchall()
return [Trace(**{**dict(r), "steps": json.loads(r["steps"])}) for r in rows]
def purge_traces_older_than(self, ts: float) -> int:
with self._lock:
n = self._conn.execute("DELETE FROM traces WHERE ts < ?", (ts,)).rowcount
self._conn.commit()
return n
def records_of(self, person: str) -> List[Record]:
with self._lock:
rows = self._conn.execute(
@@ -207,6 +281,7 @@ class HistoryStore:
with self._lock:
n = self._conn.execute("DELETE FROM history WHERE author_id=? OR to_id=?", (person, person)).rowcount
self._conn.execute("DELETE FROM presence WHERE user_id=?", (person,))
self._conn.execute("DELETE FROM traces WHERE user_id=?", (person,))
self._conn.commit()
debug_log(f"history: forgot a person ({n} records)", "memory")
@@ -214,6 +289,7 @@ class HistoryStore:
with self._lock:
n = self._conn.execute("DELETE FROM history WHERE ts < ?", (ts,)).rowcount
self._conn.execute("DELETE FROM presence WHERE left_at IS NOT NULL AND left_at < ?", (ts,))
self._conn.execute("DELETE FROM traces WHERE ts < ?", (ts,))
self._conn.commit()
debug_log(f"history: retention removed {n} records", "memory")

View File

@@ -68,6 +68,33 @@ Setting `since` (default none, meaning the whole history) drops records older th
A record that is a match is not repeated in the recent block. Returns the two blocks separately
so the prompt can label them.
## Traces
How each answer was made, for the management app's 대화 screen (`app/src/admin.spec.md`,
"Conversations"). A trace is never a record: no read above returns it and it never reaches a prompt.
- One per `reply` the brain ran, kept from the moment it was asked so the screen can show it while
the answer is made: `start_trace(via, channel_id, user_id, question, ts)` (`via` `voice`, `chat` or
`task`; `channel_id` where it was asked, none for a task; `ts` when it was asked) stores it with no
answer and `ms` -1, `trace_steps(id, steps)` stores the steps so far, and
`finish_trace(id, answer, steps, ms)` the end (`answer` empty when the brain gave none; `ms` how
long it took). `close_unfinished_traces()`, which the host calls at start, ends with no answer the
traces a killed run left at -1. `steps` is a JSON list in the order they happened:
- `{"kind": "records", "recent": [...], "matches": [...], "notes": n}`: the history lines and the
number of personal notes the brain was given (the voice worker adds it first),
- `{"kind": "tools", "names": [...]}`: the tools the turn was offered after routing,
- `{"kind": "plan", "steps": [...]}`: the planner's steps, when it ran,
- `{"kind": "think", "text": "..."}`: the model's thinking in one round, when thinking is on
(at most 8,000 characters),
- `{"kind": "tool", "name", "args", "ok", "result"}`: a tool call and the start of its result or
error (at most 2,000 characters), or `"skipped": "not_allowed" | "duplicate"` with `ok` false
for a call the engine refused.
The engine writes them through `turn_state.trace` (`reply/turn_state.py`), which does nothing when
no trace list was set (v1, evals); the voice worker's list stores the steps as each is added.
- `traces_of(person)`: the person's traces, oldest first. `forget_person` deletes them too.
- `purge_traces_older_than(ts)`: the voice worker keeps traces 30 days (`TRACE_KEEP_DAYS`) and
removes older ones when it starts. `purge_older_than` removes old traces with the records.
## Writes and maintenance
- `add_voice`, `add_reply`, `add_chat`, `edit_chat`, `delete_chat`.

View File

@@ -27,6 +27,7 @@ from .enrichment import (
digest_tool_result_for_query,
digest_loop_for_max_turns,
)
from . import turn_state as _turn_state
from .prompt_dump import dump_reply_turn, is_enabled as _prompt_dump_enabled, new_session_id
from .prompts import ModelSize, detect_model_size, get_system_prompts
from .compound_query import split_compound_query
@@ -61,6 +62,22 @@ if TYPE_CHECKING:
# ── Helpers ─────────────────────────────────────────────────────────────────
# How much of a tool result and of the model's thinking a trace keeps (history.spec.md, "Traces").
TRACE_RESULT_CHARS = 2000
TRACE_THINKING_CHARS = 8000
def _clip(text: str, limit: int) -> str:
return text if len(text) <= limit else text[:limit] + "…"
def _trace_tool(name: str, args, result) -> None:
"""One executed tool call in the turn's trace: name, arguments, outcome and the start of its result."""
text = result.reply_text or result.error_message or ""
_turn_state.trace("tool", name=name, args=args or {}, ok=bool(result.success),
result=_clip(str(text), TRACE_RESULT_CHARS))
def _indent_text(text: str, prefix: str = " ") -> str:
return f"\n{prefix}".join(text.splitlines())
@@ -1419,6 +1436,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
routed_tools = [t for t in routed_tools if t != "webSearch"]
debug_log("screen-share: site named — dropping webSearch so controlBrowser wins", "tools")
_turn_state.trace("tools", names=list(routed_tools))
_planner_schema = generate_tools_json_schema(routed_tools, mcp_tools)
_planner_tool_catalog = planner_tool_catalog(_planner_schema or [])
@@ -1438,6 +1456,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
debug_log(f"planner step failed (non-fatal): {_plan_exc}", "planning")
action_plan = []
if action_plan:
_turn_state.trace("plan", steps=list(action_plan))
_plan_preview = " | ".join(s[:50] for s in action_plan)
print(
f" 🗺️ Plan: {len(action_plan)} step(s) — {_plan_preview}",
@@ -2389,6 +2408,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
max_retries=1,
language=language,
)
_trace_tool(_name, _args, _plan_result)
if _plan_result.reply_text:
_plan_text = _maybe_digest_tool_result(
cfg=cfg,
@@ -2602,6 +2622,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
# Always show thinking if present, regardless of content
if thinking:
_turn_state.trace("think", text=_clip(str(thinking), TRACE_THINKING_CHARS))
debug_log(f" 💭 LLM thinking: '{thinking[:300]}{'...' if len(thinking) > 300 else ''}'", "planning")
# Extract tool call if present
@@ -2647,6 +2668,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
# Check if tool is not allowed - respond with tool error
if tool_name not in allowed_tools:
debug_log(f" ⚠️ tool not allowed: {tool_name}", "planning")
_turn_state.trace("tool", name=tool_name, args=tool_args or {}, ok=False, skipped="not_allowed")
print(f" ⚠️ Tool '{tool_name}' not in allow-list", flush=True)
# Use tool response instead of system message to maintain native tool calling compatibility
messages.append({
@@ -2694,6 +2716,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
if signature in recent_tool_signatures:
debug_log(f" ⚠️ Duplicate {tool_name} call - returning cached guidance", "planning")
_turn_state.trace("tool", name=tool_name, args=tool_args or {}, ok=False, skipped="duplicate")
if use_text_tools:
messages.append({"role": "user", "content": f"[Tool: {tool_name}] You already called this tool with these arguments. Use the results from the previous tool call to answer the user."})
else:
@@ -2713,6 +2736,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
)
if duplicate_tool_count >= 2:
debug_log(f" ⚠️ Too many {tool_name} calls ({duplicate_tool_count}) - returning guidance", "planning")
_turn_state.trace("tool", name=tool_name, args=tool_args or {}, ok=False, skipped="duplicate")
if use_text_tools:
messages.append({"role": "user", "content": f"[Tool: {tool_name}] You have already called this tool {duplicate_tool_count} times. Use the results from those calls to answer the user's question."})
else:
@@ -2731,6 +2755,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
max_retries=1,
language=language,
)
_trace_tool(tool_name, tool_args, result)
# Handle stop tool - end conversation without response
if result.reply_text == STOP_SIGNAL:

View File

@@ -31,6 +31,9 @@ notes : Optional[object]
screen : Optional[object]
v2: the app's screen backend for the asker (screen_view.spec.md). None means the screenView
tool is not offered.
trace : Optional[list]
v2: where the engine writes down how it made this answer (history.spec.md, "Traces"): the
tools it was given, the plan, the model's thinking and each tool call. None records nothing.
"""
from __future__ import annotations
@@ -50,6 +53,22 @@ def reset() -> None:
_state.schedule = None
_state.notes = None
_state.screen = None
_state.trace = None
def set_trace(steps: Optional[list]) -> None:
_state.trace = steps
def get_trace() -> Optional[list]:
return getattr(_state, "trace", None)
def trace(kind: str, **data) -> None:
"""Add one step to this turn's trace, if one is kept."""
steps = get_trace()
if steps is not None:
steps.append({"kind": kind, **data})
def set_screen(backend) -> None:

View File

@@ -19,7 +19,7 @@ from jarvis.memory.history import HistoryContext, Scope
class Brain(Protocol):
def reply(self, user: str, text: str, history: HistoryContext, chat=None, schedule=None,
task: bool = False, notes: Optional[list] = None, notes_backend=None,
screen=None) -> Optional[str]:
screen=None, trace: Optional[list] = None) -> Optional[str]:
"""Blocking; called on a worker thread, one call per person at a time (a voice and a chat
reply for different people may overlap). ``chat``: the chat backend for
the chatChannels tool (voice_worker/chat_bridge.py), or None without registered channels.
@@ -27,7 +27,8 @@ class Brain(Protocol):
``task``: a scheduled task runs, with the read-only tools only (``TASK_TOOLS``).
``notes``: the asker's standing instructions, put in the prompt; ``notes_backend``: the
backend for the personalNotes tool (personal_notes.spec.md); ``screen``: the backend for the
screenView tool (screen_view.spec.md)."""
screenView tool (screen_view.spec.md); ``trace``: a list the engine adds the steps of
this answer to (history.spec.md, "Traces")."""
def addressed(self, user: str, text: str, names: list[str]) -> Optional[bool]:
"""Blocking: was ``text`` said to the assistant (called ``names``)? None when it could not tell.
@@ -296,7 +297,7 @@ class JarvisBrain:
def reply(self, user: str, text: str, history: HistoryContext, chat=None, schedule=None,
task: bool = False, notes: Optional[list] = None, notes_backend=None,
screen=None) -> Optional[str]:
screen=None, trace: Optional[list] = None) -> Optional[str]:
from jarvis.memory.conversation import DialogueMemory
from jarvis.reply import turn_state
from jarvis.reply.engine import run_reply_engine
@@ -317,6 +318,7 @@ class JarvisBrain:
turn_state.set_schedule(None if task else schedule)
turn_state.set_notes(None if task else notes_backend)
turn_state.set_screen(None if task else screen)
turn_state.set_trace(trace)
try:
return run_reply_engine(self.db, cfg, None, text, memory,
language=self.language, history=history, legacy_memory=False,

View File

@@ -9,11 +9,13 @@ stdout: frames of u32 LE header length | header JSON | payload. The first frame
int16 LE mono samples at the requested rate, or {"ok": false, "error": "..."} with no payload.
Library output that would land on stdout is sent to stderr so it cannot corrupt the frames.
Speed: MeloTTS's own speed shortens every sound and slurs faster speech (Whisper large-v3 on five
Korean sentences, three renders each: character errors 5.5% at 1.5 and 20% at 2.0, against 1.4% at
1.0). So the model speaks at most at MODEL_SPEED_MAX (its natural pace) and a time stretch that keeps
the pitch (WSOLA) makes it faster: 1.9% at 1.5 and 2.2% at 2.0. Letting the model go to 1.25 first
measured slightly worse (2.2% and 3.1%).
Speed: MeloTTS's own speed past about 1.25 drops sounds (five Korean sentences, three renders each,
read back by Whisper large-v3: at 1.5 sentence-final "요" and first syllables went missing, 4.6%
character errors, 9.6% at 1.75, against 1.2% at 1.0 and none added at 1.25). A time stretch that keeps
the pitch (WSOLA) keeps every sound but sounds less natural the more it stretches (UTMOS 3.13 at 1.5
stretched from 1.0, against 3.73 for the model's own 1.5). So the model speaks up to MODEL_SPEED_MAX
and the stretch does only the rest: 2.6% and UTMOS 3.56 at 1.5, 1.9% and 3.09 at 1.75 (through this
child). A 5 ms search scored higher than 10 ms (UTMOS 3.42 against 3.27 for a 1.2 stretch).
"""
from __future__ import annotations
@@ -26,7 +28,7 @@ import struct
import sys
import types
MODEL_SPEED_MAX = 1.0
MODEL_SPEED_MAX = 1.25
def split_speed(speed: float) -> tuple[float, float]:
@@ -35,7 +37,7 @@ def split_speed(speed: float) -> tuple[float, float]:
return model, speed / model
def stretch(audio, factor: float, rate: int, frame_ms: float = 30.0, search_ms: float = 10.0):
def stretch(audio, factor: float, rate: int, frame_ms: float = 30.0, search_ms: float = 5.0):
"""Shorten ``audio`` by ``factor`` and keep its pitch (WSOLA): half-overlapping Hann frames are
taken ``factor`` times further apart than they are laid down, each shifted within ``search_ms``
to where it best continues the frame before it, so the pieces join without dips or clicks."""

View File

@@ -51,6 +51,39 @@ class _LlmPaused(Exception):
# The asker's standing instructions the app sends with a reply (personal_notes.spec.md).
MAX_NOTES = 20
MAX_NOTE_CHARS = 300
# How long answer traces stay (history.spec.md, "Traces"); removed when the worker starts.
TRACE_KEEP_DAYS = 30
class _LiveTrace(list):
"""A reply's trace (history.spec.md, "Traces"): stored as soon as the request arrives and again
as each step is added, so the 대화 screen fills it in while the answer is made. The engine adds
steps from the brain's thread. Storing never stops the answer."""
def __init__(self, store, via: str, channel: str | None, user: str, question: str):
super().__init__()
self.store, self.began, self.id = store, time.time(), None
if store is not None:
self.id = self._keep(store.start_trace, via, channel, user, question, ts=self.began)
@staticmethod
def _keep(write, *args, **kw):
try:
return write(*args, **kw)
except Exception as e: # noqa: BLE001 - a trace is a view, not part of the answer
debug_log(f"trace not kept: {type(e).__name__}", "llm")
return None
def append(self, step) -> None:
super().append(step)
if self.id is not None:
self._keep(self.store.trace_steps, self.id, list(self))
def finish(self, answer: str) -> None:
if self.id is not None:
self._keep(self.store.finish_trace, self.id, answer, list(self),
ms=round((time.time() - self.began) * 1000))
self.id = None
class VoiceWorker:
@@ -116,6 +149,12 @@ class VoiceWorker:
n = self.history.close_open_presence(time.time())
if n:
debug_log(f"closed {n} presence intervals left open by a previous run", "voice_worker")
n = self.history.close_unfinished_traces()
if n:
debug_log(f"closed {n} answer traces left unfinished by a previous run", "voice_worker")
n = self.history.purge_traces_older_than(time.time() - TRACE_KEEP_DAYS * 86400)
if n:
debug_log(f"removed {n} answer traces older than {TRACE_KEEP_DAYS} days", "voice_worker")
if self.transcriber is not None:
self.scheduler = SttScheduler(self.transcriber, partials_held=self._partials_held)
self.scheduler.start()
@@ -603,10 +642,23 @@ class Session:
waiting[user] = waiting.get(user, 0) + 1
asyncio.get_running_loop().create_task(self._reply(rid, user, text, via, speak, early, channel, notes))
@staticmethod
def _records_step(history, notes: list | None) -> dict:
"""The first step of an answer's trace: the records and notes it was given."""
return {"kind": "records", "recent": list(history.recent), "matches": list(history.matches),
"notes": len(notes or [])}
async def _task(self, rid: str, user: str, text: str, notes: list | None = None) -> None:
"""A scheduled task (schedule.spec.md, "Tasks"): answered in the chat lane with the read-only
tools, its own short-term memory and the person's history scope. It is not a turn of their
conversation, so their turn count and delete confirmations stay as they are."""
trace = _LiveTrace(self.worker.history, "task", None, user, text)
try:
await self._task_inner(rid, user, text, notes, trace)
finally:
trace.finish("") # only when it did not get to its answer
async def _task_inner(self, rid: str, user: str, text: str, notes: list | None, trace: _LiveTrace) -> None:
w = self.worker
answer = None
async with w.brain_people.setdefault(user, asyncio.Lock()), w.brain_lanes["chat"]:
@@ -622,12 +674,14 @@ class Session:
from jarvis.memory.history import HistoryContext
history = HistoryContext()
try:
trace.append(self._records_step(history, notes))
async with self._llm():
answer = await asyncio.to_thread(w.brain.reply, user, text, history, task=True,
notes=notes or [])
notes=notes or [], trace=trace)
except Exception as e: # the brain must never take the session down
debug_log(f"brain task {rid} failed: {type(e).__name__}", "llm")
answer = (answer or "").strip()
answer = (answer or "").strip()
trace.finish(answer)
self.send({"type": "reply_text", "id": rid, "text": answer, "failed": not answer})
def _on_llm(self, msg: dict) -> None:
@@ -767,9 +821,11 @@ class Session:
async def _reply(self, rid: str, user: str, text: str, via: str, speak: bool, early: bool = False,
channel: str | None = None, notes: list | None = None) -> None:
trace = _LiveTrace(self.worker.history, via, self.voice_channel if via == "voice" else channel, user, text)
try:
await self._reply_inner(rid, user, text, via, speak, early, channel, notes or [])
await self._reply_inner(rid, user, text, via, speak, early, channel, notes or [], trace=trace)
finally:
trace.finish("") # only when it did not get to its answer
self.thinking_replies.discard(rid)
self.cancelled_replies.discard(rid)
if not self._handed_over.pop(rid, False): # else _delivered counts it
@@ -806,7 +862,8 @@ class Session:
self._delivered(rid, ok)
async def _reply_inner(self, rid: str, user: str, text: str, via: str, speak: bool, early: bool,
chat_channel: str | None = None, notes: list | None = None) -> None:
chat_channel: str | None = None, notes: list | None = None, *,
trace: _LiveTrace) -> None:
w = self.worker
channel = self.voice_channel
# Person first, then lane: a reply waiting for its asker's other answer holds no lane.
@@ -834,13 +891,15 @@ class Session:
schedule = AppBridge(self, asyncio.get_running_loop(), "schedule", *origin)
notes_backend = AppBridge(self, asyncio.get_running_loop(), "note", *origin)
screen = AppBridge(self, asyncio.get_running_loop(), "screen", *origin)
trace.append(self._records_step(history, notes))
try:
async with self._llm(rid if speak else None):
w.answering += 1
try:
answer = await asyncio.to_thread(w.brain.reply, user, text, history, chat=chat,
schedule=schedule, notes=notes or [],
notes_backend=notes_backend, screen=screen)
notes_backend=notes_backend, screen=screen,
trace=trace)
finally:
w.answering -= 1
if not w.answering and w.scheduler:
@@ -848,7 +907,8 @@ class Session:
except Exception as e: # the brain must never take the session down
debug_log(f"brain reply {rid} failed: {type(e).__name__}", "llm")
answer = None
answer = (answer or "").strip()
answer = (answer or "").strip()
trace.finish(answer)
if not answer and rid in self.tts_requests:
self._on_tts({"type": "tts", "id": rid, "text": "", "more": False}) # ends the notice's speech
self.send({"type": "reply_text", "id": rid, "text": answer, "failed": not answer})

View File

@@ -181,11 +181,14 @@ synthesise is reported with `error` (`code: "tts_failed"`) and the request ends
Speed starts at `--melo-speed` and `tts_speed` changes it for every sentence made after it (a speed
outside 0.5-2.0 or not a number is `bad_message` and the last good one stays). MeloTTS itself speaks
at most at its natural pace (1.0): its own speed shortens every sound and slurs faster speech
(Whisper large-v3 on five Korean sentences, three renders each: 5.5% character errors at 1.5 and 20%
at 2.0, against 1.4% at 1.0). Faster speech is made at 1.0 and shortened with WSOLA, a time stretch
that keeps the pitch (30 ms half-overlapping Hann frames, each shifted within 10 ms to where it best
continues the one before): 1.9% at 1.5 and 2.2% at 2.0, about 15 ms per 4 s of speech.
up to 1.25: its own speed shortens every sound, and past that it drops them (five Korean sentences,
three renders each, read back by Whisper large-v3: at 1.5 sentence-final "요" and first syllables went
missing, 4.6% character errors, 9.6% at 1.75, against 1.2% at 1.0). Faster speech is made at 1.25 and
shortened with WSOLA, a time stretch that keeps the pitch (30 ms half-overlapping Hann frames, each
shifted within 5 ms to where it best continues the one before): 2.6% at 1.5 and 1.9% at 1.75. The
stretch costs naturalness the more it does (UTMOS at 1.5: 3.56, against 3.13 when all of it is
stretched from 1.0), so it does only the part the model cannot; up to 1.25 nothing is stretched. About 15 ms per 4 s
of speech.
### History and brain (M3)
@@ -243,7 +246,13 @@ which carry Discord's own time.
`speak: true` the answer is also spoken through the TTS path under the same id (audio frames and
`tts_done`), and `tts_cancel` with that id stops it. A `tts_cancel` that arrives while the brain is
still answering means the answer is not spoken: `reply_text` still comes, then `tts_done` with
`cancelled: true` and no audio. Each user keeps their own short-term dialogue
`cancelled: true` and no audio. Every reply, a task's too and one that failed, leaves a trace of
how it was made (`history.spec.md`, "Traces"): the history lines and number of notes it was given,
then what the engine wrote down. It is stored as soon as the request arrives (before it waits for
the asker's previous answer) and again as each step is added, then ends with the answer, or with
none when the reply fails, the session closes or the reply is cancelled; a trace that cannot be
stored never stops the answer. At start the worker ends the traces a killed run left unfinished
and removes those older than 30 days. Each user keeps their own short-term dialogue
memory (tool carry-over) across replies. The brain runs the reply engine with v1's single-user
memory off (`legacy_memory=False`: no warm profile, diary or graph), because several people share
this assistant and only the asker's scoped history may reach the prompt. It answers in Korean

View File

@@ -0,0 +1,59 @@
"""The reply engine writes down how it made an answer (history.spec.md, "Traces").
With a trace list set on the turn state, a reply records the tools it was given, the plan, the
model's thinking and each tool call with its outcome. Without one nothing is recorded.
"""
from unittest.mock import Mock, patch
import pytest
from src.jarvis.memory.conversation import DialogueMemory
from src.jarvis.reply import turn_state
from src.jarvis.reply.engine import run_reply_engine
from tests.test_engine_tool_carryover import _mock_cfg
def _run(trace):
tool = Mock(reply_text="서울: 맑음, 12도", error_message=None, success=True)
replies = [
{"message": {"content": "", "thinking": "날씨를 찾아봐야겠다", "tool_calls": [{
"id": "c1", "type": "function",
"function": {"name": "webSearch", "arguments": {"query": "서울 날씨"}}}]}},
{"message": {"content": "서울은 맑고 12도입니다."}},
]
turn_state.reset()
turn_state.set_trace(trace)
try:
with patch("src.jarvis.reply.engine.plan_query", return_value=["Search the web", "Reply to the user."]), \
patch("src.jarvis.reply.engine.extract_search_params_for_memory", return_value={}), \
patch("src.jarvis.reply.engine.run_tool_with_retries", return_value=tool), \
patch("src.jarvis.reply.engine.extract_text_from_response",
side_effect=lambda r: r["message"]["content"]), \
patch("src.jarvis.reply.engine.chat_with_messages", side_effect=replies):
return run_reply_engine(db=Mock(), cfg=_mock_cfg(), tts=None, text="서울 날씨 어때",
dialogue_memory=DialogueMemory())
finally:
turn_state.reset()
@pytest.mark.unit
def test_a_reply_records_its_tools_plan_thinking_and_tool_calls():
trace = []
assert _run(trace)
kinds = [s["kind"] for s in trace]
assert kinds.index("tools") < kinds.index("plan") < kinds.index("think") < kinds.index("tool")
tools = next(s for s in trace if s["kind"] == "tools")
assert "webSearch" in tools["names"]
assert next(s for s in trace if s["kind"] == "plan")["steps"] == ["Search the web", "Reply to the user."]
assert next(s for s in trace if s["kind"] == "think")["text"] == "날씨를 찾아봐야겠다"
call = next(s for s in trace if s["kind"] == "tool")
assert (call["name"], call["args"], call["ok"], call["result"]) == \
("webSearch", {"query": "서울 날씨"}, True, "서울: 맑음, 12도")
@pytest.mark.unit
def test_without_a_trace_nothing_is_recorded():
assert _run(None)
assert turn_state.get_trace() is None

View File

@@ -238,3 +238,48 @@ def test_chat_tool_reads_and_searches_one_channels_messages(store):
assert sorted(texts(store.search_chat(["c1", "c2"], "회의"))) == ["회의 취소", "회의는 3시"]
assert store.search_chat([], "회의") == []
assert store.chat_channel_of("m3") == "c2" and store.chat_channel_of("nope") is None
def test_how_an_answer_was_made_is_kept_per_person_and_never_searched(store):
steps = [{"kind": "tools", "names": ["getWeather"]},
{"kind": "tool", "name": "getWeather", "args": {"location": "서울"}, "ok": True, "result": "맑음"}]
store.finish_trace(store.start_trace("voice", VC, "a", "서울 날씨 어때", ts=T0), "맑습니다", steps, ms=1200)
store.finish_trace(store.start_trace("chat", CHAT, "b", "안녕", ts=T0 + 1), "", [], ms=50)
[t] = store.traces_of("a")
assert (t.via, t.channel_id, t.question, t.answer, t.ms, t.steps) == ("voice", VC, "서울 날씨 어때", "맑습니다", 1200, steps)
assert t.ts == T0 # when it was asked, not when the answer was ready
# A trace is no record: the brain never reads it back as history.
assert store.search("a", "날씨", scope=Scope()) == []
assert store.recent("a", T0 + 2, scope=Scope()) == []
store.forget_person("a")
assert store.traces_of("a") == [] and len(store.traces_of("b")) == 1
def test_traces_have_their_own_retention_and_follow_the_history_retention(store):
store.finish_trace(store.start_trace("voice", VC, "a", "옛 질문", ts=T0), "옛 답", [], ms=1)
store.finish_trace(store.start_trace("voice", VC, "a", "새 질문", ts=T0 + 100), "새 답", [], ms=1)
store.purge_traces_older_than(T0 + 50)
assert [t.question for t in store.traces_of("a")] == ["새 질문"]
store.purge_older_than(T0 + 200)
assert store.traces_of("a") == []
def test_a_trace_is_kept_from_the_question_on_and_filled_in_as_the_answer_is_made(store):
tid = store.start_trace("voice", VC, "a", "서울 날씨 어때", ts=T0)
[t] = store.traces_of("a")
assert (t.question, t.answer, t.ms, t.steps) == ("서울 날씨 어때", "", -1, []) # -1: still being made
store.trace_steps(tid, [{"kind": "tools", "names": ["getWeather"]}])
assert store.traces_of("a")[0].steps == [{"kind": "tools", "names": ["getWeather"]}]
assert store.traces_of("a")[0].ms == -1
store.finish_trace(tid, "맑습니다", [{"kind": "tools", "names": ["getWeather"]}], ms=900)
[t] = store.traces_of("a")
assert (t.answer, t.ms, t.ts) == ("맑습니다", 900, T0)
def test_traces_a_killed_run_left_unfinished_are_closed_without_an_answer(store):
store.start_trace("voice", VC, "a", "끊긴 질문", ts=T0)
store.finish_trace(store.start_trace("voice", VC, "a", "끝난 질문", ts=T0 + 1), "답", [], ms=5)
assert store.close_unfinished_traces() == 1
cut, done = store.traces_of("a")
assert (cut.answer, cut.ms >= 0) == ("", True)
assert (done.answer, done.ms) == ("답", 5)

View File

@@ -29,8 +29,10 @@ class FakeBrain:
self.calls = []
def reply(self, user, text, history, chat=None, schedule=None, task=False, notes=None, notes_backend=None,
screen=None):
screen=None, trace=None):
self.calls.append((user, text, history))
if trace is not None:
trace.append({"kind": "tools", "names": ["getWeather"]})
self.chat, self.schedule, self.task = chat, schedule, task
self.notes, self.notes_backend, self.screen = notes, notes_backend, screen
return self.answer(user, text)
@@ -211,6 +213,63 @@ def test_a_failed_brain_answer_is_reported(store, answer):
assert seen[-1] == {"type": "reply_text", "id": "r1", "text": "", "failed": True}
@pytest.mark.unit
def test_each_answer_keeps_how_it_was_made_with_the_records_it_was_given(store):
async def body(url):
async with connect(url) as ws:
await hello(ws, stt={"partials": False})
await send(ws, type="voice_join", channel="vc1")
await send(ws, type="member_join", user="100", name="Alice")
await say(ws, "100", 0.9)
await send(ws, type="reply", id="r1", user="100", text="what did I say", via="voice", speak=False,
notes=["반말로 해"])
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("id") == "r1")
await send(ws, type="reply", id="c1", user="100", text="hi", via="chat", speak=False, channel="ch1")
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("id") == "c1")
await send(ws, type="reply", id="t1", user="100", text="task", via="task")
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("id") == "t1")
brain = FakeBrain(lambda u, t: None if t == "hi" else f"answer for {t}")
asyncio.run(with_worker(body, store=store, brain=brain))
voice, chat, task = store.traces_of("100")
assert (voice.via, voice.channel_id, voice.question, voice.answer) == \
("voice", "vc1", "what did I say", "answer for what did I say")
assert voice.ms >= 0
records = voice.steps[0]
assert records["kind"] == "records" and records["notes"] == 1
assert any("Alice: level 0.9" in x for x in records["recent"])
assert voice.steps[1:] == [{"kind": "tools", "names": ["getWeather"]}]
# A failed answer is kept too, with no answer; a task has no channel.
assert (chat.via, chat.channel_id, chat.answer) == ("chat", "ch1", "")
assert (task.via, task.channel_id, task.answer) == ("task", None, "answer for task")
@pytest.mark.unit
def test_a_trace_is_stored_from_the_request_on_and_fills_in_while_the_answer_is_made(store):
import time
during = []
def answer(user, text):
during.append((store.traces_of(user), time.time())) # the engine has added its steps
return "answer"
async def body(url):
async with connect(url) as ws:
await hello(ws)
await send(ws, type="voice_join", channel="vc1")
await send(ws, type="reply", id="r1", user="100", text="q", via="voice", speak=False)
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("id") == "r1")
asyncio.run(with_worker(body, store=store, brain=FakeBrain(answer)))
[(traces, answering_at)] = during
[t] = traces
assert (t.question, t.answer, t.ms) == ("q", "", -1) # -1: still being made
assert [s["kind"] for s in t.steps] == ["records", "tools"]
assert t.ts <= answering_at
[t] = store.traces_of("100")
assert (t.answer, t.ms >= 0, t.ts) == ("answer", True, traces[0].ts)
@pytest.mark.unit
def test_without_a_brain_reply_is_an_error():
async def body(url):
@@ -300,6 +359,22 @@ def test_presence_left_open_by_a_previous_run_is_closed_at_start(store):
assert store.recent("old", now=4_000_000_000, scope=Scope(), minutes=10 ** 9) == []
@pytest.mark.unit
def test_traces_older_than_thirty_days_are_removed_at_start(store):
import time
now = time.time()
store.finish_trace(store.start_trace("voice", "vc1", "100", "old", ts=now - 31 * 86400), "a", [], ms=1)
store.finish_trace(store.start_trace("voice", "vc1", "100", "new", ts=now - 29 * 86400), "a", [], ms=1)
store.start_trace("voice", "vc1", "100", "cut off", ts=now - 60) # a killed run never finished it
async def body(url):
async with connect(url) as ws:
await hello(ws)
asyncio.run(with_worker(body, store=store))
assert [(t.question, t.ms >= 0) for t in store.traces_of("100")] == [("new", True), ("cut off", True)]
@pytest.mark.unit
def test_the_brain_prints_no_text_from_its_thread(tmp_path, monkeypatch, capfd):
pytest.importorskip("mcp") # the real brain needs the jarvis dependencies (--brain)

View File

@@ -1,5 +1,5 @@
"""How the MeloTTS child speeds speech up: the model never speaks faster than MODEL_SPEED_MAX (faster
slurs), and the rest is a time stretch that keeps the pitch. And the engine sends its current speed
drops sounds), and the rest is a time stretch that keeps the pitch. And the engine sends its current speed
with every sentence."""
from __future__ import annotations