Compare commits

..

8 Commits

Author SHA1 Message Date
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
18 changed files with 338 additions and 100 deletions

2
app/Cargo.lock generated
View File

@@ -1520,7 +1520,7 @@ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
[[package]]
name = "jarvis-app"
version = "0.1.8"
version = "0.1.13"
dependencies = [
"async-trait",
"base64 0.22.1",

View File

@@ -1,6 +1,6 @@
[package]
name = "jarvis-app"
version = "0.1.8"
version = "0.1.13"
edition = "2021"
rust-version = "1.85"
description = "Jarvis v2 Windows app core: Discord voice, voice worker supervisor, chat channels"

4
app/shell/Cargo.lock generated
View File

@@ -2637,7 +2637,7 @@ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
[[package]]
name = "jarvis-app"
version = "0.1.8"
version = "0.1.13"
dependencies = [
"async-trait",
"base64 0.22.1",
@@ -2666,7 +2666,7 @@ dependencies = [
[[package]]
name = "jarvis-shell"
version = "0.1.8"
version = "0.1.13"
dependencies = [
"jarvis-app",
"serde_json",

View File

@@ -1,6 +1,6 @@
[package]
name = "jarvis-shell"
version = "0.1.8"
version = "0.1.13"
edition = "2021"
rust-version = "1.85"
description = "Jarvis v2 management app window (Tauri 2 over the app core's AdminApi)"

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"
@@ -237,11 +247,28 @@ Section "Jarvis (필수)" SecMain
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. 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")'
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); if ($$l.TargetPath -ieq $$env:JARVIS_EXE) { $$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
@@ -303,6 +330,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

@@ -20,7 +20,9 @@ setup="$out/Jarvis-Setup-$version.exe"
# 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)
makensis -V2 -DVERSION="$version" -DSRC="$out/Jarvis" -DOUT="$setup" -DICON="$here/icons/icon.ico" \
# 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

@@ -229,20 +229,23 @@ records and "Traces"), so it works while the services are stopped. Nothing it re
- 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). Jarvis's
`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, before, from, limit}`: the
- `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), the cursors `before` (only items older
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). Without the file: no items and `missing: true`.
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`)
@@ -687,7 +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, before, from, limit}` | the 대화 screen's records and answer traces (above, "Conversations") |
| `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) |
@@ -706,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).
- **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
@@ -730,17 +735,24 @@ 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). The 앱 screen has `app.closeButton` (완전 종료 or 트레이로 최소화) with a note
that the tray icon opens the window again and its menu quits; saving it needs no restart.
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).
- **대화**: 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. Filters: the three
kinds as chips, where (음성, 채팅, 정기 작업), person, channel, one day and text; "실시간" (on by
default) re-reads the live window every 3 seconds: every item from its first one on (`from`, up to
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
@@ -753,9 +765,10 @@ Plain HTML, CSS and an ES module, no build step, dark theme after `DESIGN.md`. A
shown. The paging is `app/ui/talk.js`, pure, checked by `node --test app/tests/ui/talk.test.mjs`.
- **한 일**: 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.
- **업데이트** (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**: 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.
@@ -828,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
@@ -837,7 +852,13 @@ 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`).
- 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

@@ -410,10 +410,17 @@ impl AdminApi {
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: args.get("since").and_then(Value::as_f64), until: args.get("until").and_then(Value::as_f64),
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),
@@ -428,6 +435,7 @@ impl AdminApi {
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" => {
@@ -611,6 +619,29 @@ mod tests {
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

@@ -215,11 +215,13 @@ pub fn query(path: &Path, bot: Option<&str>, q: &Query) -> Result<Value, String>
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": r.get::<_, i64>(7)?,
"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)?;
@@ -384,6 +386,21 @@ mod tests {
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"));

View File

@@ -442,16 +442,19 @@ function traceStep(s) {
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 });
const open = new Set(); // traces the user opened stay open across refreshes
// 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;
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" });
@@ -473,15 +476,20 @@ function conversationScreen() {
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) },
h("summary", {}, h("span", { class: "who" }, "자비스 생각"), " ",
h("span", { class: "small muted" }, `${i.who.name || i.who.id}의 말에 답하며`, tools ? ` · 도구 ${tools}번` : "",
` · ${(i.ms / 1000).toFixed(1)}초`, i.answer ? "" : " · 답 없음"), " ", where),
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.answer ? h("div", {}, i.answer) : h("span", { class: "badge bad" }, "답하지 못함"))));
d.addEventListener("toggle", () => (d.open ? open.add(i.key) : open.delete(i.key)));
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";
@@ -496,13 +504,13 @@ function conversationScreen() {
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 };
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]);
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;
@@ -514,10 +522,13 @@ function conversationScreen() {
kids.push(item(i));
}
box.replaceChildren(...(kids.length ? kids : [h("div", { class: "muted" },
missing ? "아직 대화 기록이 없습니다. 서비스를 켜고 자비스와 이야기하면 여기에 나옵니다." : "조건에 맞는 기록이 없습니다.")]));
missing ? "아직 대화 기록이 없습니다. 서비스를 켜고 자비스와 이야기하면 여기에 나옵니다."
: session.checked && sessionAt == null ? "앱을 켠 뒤 아직 봇을 시작하지 않았습니다. 대시보드에서 시작하면 그때부터의 대화가 여기에 나옵니다."
: "조건에 맞는 기록이 없습니다.")]));
more.hidden = !page.hasOlder;
const n = (t) => items.filter((i) => i.type === t).length;
summary.textContent = `사람 말 ${n("said")} · 자비스 말 ${n("answered")} · 생각 ${n("thought")}` + (page.hasOlder ? " (이전 기록 더 있음)" : "");
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;
@@ -537,6 +548,9 @@ function conversationScreen() {
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); }
@@ -562,19 +576,25 @@ function conversationScreen() {
const reload = () => {
epoch++; sig = null; page = empty(); first = true; loadingOlder = more.disabled = false; load();
};
for (const el of [said, answered, thought, via, person, channel, day]) el.addEventListener("change", reload);
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),
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; if (!expandAll) open.clear(); sig = null; load(); } }, "생각 모두 펼치기/접기"),
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: "hint", style: "margin:8px 0" }, "사람이 한 말, 자비스의 답, 자비스가 답을 만든 과정(참고한 기록, 고른 도구, 계획, 도구 호출과 결과, 모델 생각)을 시간순으로 보여 줍니다. 자비스가 말을 알아들은 순간 생각이 나타나고, 답을 만드는 동안 단계가 하나씩 채워집니다. 모델 생각은 생각 모드가 켜진 답에만 있습니다. 생각 기록은 30일 동안 둡니다. 실시간으로 다시 읽는 것은 최근 2,000개까지이고, 그보다 앞서 불러온 기록의 수정과 삭제는 화면을 다시 열면 보입니다."),
h("div", { class: "row", style: "justify-content:center" }, more), box);
load();
return { view, tick: () => live.checked && 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) {
@@ -818,8 +838,8 @@ function logsScreen() {
// ---- 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() {
@@ -837,7 +857,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" },
@@ -849,15 +869,15 @@ function updateScreen() {
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 ---------------------------------------------------------------------------------
@@ -894,18 +914,20 @@ async function show(name) {
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, 3000); 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 제어", app: "앱" };
const update = name === "app" ? updateCard() : null;
const extra = name === "bot" ? await tokenCard() : name === "features" ? await displayDriverCard()
: name === "app" ? h("div", { class: "hint", style: "margin-bottom:12px" }, "트레이로 최소화하면 창만 숨고 봇과 서비스는 계속 돕니다. 작업 표시줄 오른쪽의 Jarvis 아이콘을 누르면 창이 다시 열리고, 아이콘의 오른쪽 클릭 메뉴에서 완전 종료할 수 있습니다. 저장하면 바로 적용됩니다.") : null;
: 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,12 +23,10 @@
<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="conversations" class="nav">대화</button>
<button data-screen="activity" class="nav">한 일</button>
<button data-screen="game" class="nav">게임 모드</button>
<button data-screen="app" 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

@@ -44,13 +44,13 @@ CREATE TABLE IF NOT EXISTS presence (
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 the answer was ready
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,
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);
@@ -107,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()."""
@@ -225,16 +229,34 @@ class HistoryStore:
# -- maintenance --------------------------------------------------------
def add_trace(self, via: str, channel_id: Optional[str], user_id: str, question: str, answer: str,
steps: list, ms: int, ts: float) -> int:
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 (?,?,?,?,?,?,?,?)",
(ts, via, channel_id, user_id, question, answer or "", int(ms),
json.dumps(steps, ensure_ascii=False, default=str)))
"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(

View File

@@ -73,10 +73,13 @@ Setting `since` (default none, meaning the whole history) drops records older th
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.
- `add_trace(via, channel_id, user_id, question, answer, steps, ms, ts)`: one per `reply` the brain
ran (`via` `voice`, `chat` or `task`; `channel_id` where it was asked, none for a task; `answer`
empty when the brain gave none; `ts` when it was ready; `ms` how long it took). `steps` is a JSON
list in the order they happened:
- 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,
@@ -87,7 +90,7 @@ How each answer was made, for the management app's 대화 screen (`app/src/admin
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).
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.

View File

@@ -55,6 +55,37 @@ MAX_NOTE_CHARS = 300
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:
def _partials_held(self) -> bool:
return self.llm_game and self.answering > 0
@@ -118,6 +149,9 @@ 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")
@@ -609,26 +643,22 @@ class Session:
asyncio.get_running_loop().create_task(self._reply(rid, user, text, via, speak, early, channel, notes))
@staticmethod
def _trace_start(history, notes: list | None) -> list:
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 [])}]
def _trace_end(self, via: str, channel: str | None, user: str, question: str, answer: str,
steps: list, began: float) -> None:
"""Keep how this answer was made (history.spec.md, "Traces"); never stops the answer."""
if self.worker.history is None:
return
try:
self.worker.history.add_trace(via, channel, user, question, answer, steps,
ms=round((time.time() - began) * 1000), ts=time.time())
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 {"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"]:
@@ -644,14 +674,14 @@ class Session:
from jarvis.memory.history import HistoryContext
history = HistoryContext()
try:
steps = self._trace_start(history, notes)
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 [], trace=steps)
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()
self._trace_end("task", None, user, text, answer, steps, now)
trace.finish(answer)
self.send({"type": "reply_text", "id": rid, "text": answer, "failed": not answer})
def _on_llm(self, msg: dict) -> None:
@@ -791,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
@@ -830,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.
@@ -858,7 +891,7 @@ 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)
steps = self._trace_start(history, notes)
trace.append(self._records_step(history, notes))
try:
async with self._llm(rid if speak else None):
w.answering += 1
@@ -866,7 +899,7 @@ class Session:
answer = await asyncio.to_thread(w.brain.reply, user, text, history, chat=chat,
schedule=schedule, notes=notes or [],
notes_backend=notes_backend, screen=screen,
trace=steps)
trace=trace)
finally:
w.answering -= 1
if not w.answering and w.scheduler:
@@ -875,7 +908,7 @@ class Session:
debug_log(f"brain reply {rid} failed: {type(e).__name__}", "llm")
answer = None
answer = (answer or "").strip()
self._trace_end(via, channel if via == "voice" else chat_channel, user, text, answer, steps, now)
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

@@ -248,8 +248,11 @@ which carry Discord's own time.
still answering means the answer is not spoken: `reply_text` still comes, then `tts_done` with
`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; a trace that cannot be stored never stops the answer. Traces older
than 30 days are removed when the worker starts. Each user keeps their own short-term dialogue
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

@@ -243,10 +243,11 @@ def test_chat_tool_reads_and_searches_one_channels_messages(store):
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.add_trace("voice", VC, "a", "서울 날씨 어때", "맑습니다", steps, ms=1200, ts=T0)
store.add_trace("chat", CHAT, "b", "안녕", "", [], ms=50, ts=T0 + 1)
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()) == []
@@ -255,9 +256,30 @@ def test_how_an_answer_was_made_is_kept_per_person_and_never_searched(store):
def test_traces_have_their_own_retention_and_follow_the_history_retention(store):
store.add_trace("voice", VC, "a", "옛 질문", "옛 답", [], ms=1, ts=T0)
store.add_trace("voice", VC, "a", "새 질문", "새 답", [], ms=1, ts=T0 + 100)
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

@@ -244,6 +244,32 @@ def test_each_answer_keeps_how_it_was_made_with_the_records_it_was_given(store):
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):
@@ -337,15 +363,16 @@ def test_presence_left_open_by_a_previous_run_is_closed_at_start(store):
def test_traces_older_than_thirty_days_are_removed_at_start(store):
import time
now = time.time()
store.add_trace("voice", "vc1", "100", "old", "a", [], ms=1, ts=now - 31 * 86400)
store.add_trace("voice", "vc1", "100", "new", "a", [], ms=1, ts=now - 29 * 86400)
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 for t in store.traces_of("100")] == ["new"]
assert [(t.question, t.ms >= 0) for t in store.traces_of("100")] == [("new", True), ("cut off", True)]
@pytest.mark.unit