Put the Scheduler dock on the same conversation store as everything else

This commit is contained in:
Gmer4Lfe
2026-08-09 00:16:09 -04:00
parent f4fd17be4d
commit 073352b21e
4 changed files with 105 additions and 9 deletions
+9 -1
View File
@@ -1207,6 +1207,7 @@ function vv_ai_chats_list(): array {
'id' => $d['id'],
'ts' => (int)($d['ts'] ?? 0),
'profile' => (string)($d['profile'] ?? 'chat'),
'scope' => (string)($d['scope'] ?? ''),
'title' => (string)($d['title'] ?? 'Untitled conversation'),
'turns' => (int)($d['turns'] ?? count($d['messages'] ?? [])),
];
@@ -1244,7 +1245,7 @@ function vv_ai_chats_prune(?int $max = null): int {
// Writes a whole conversation. An empty id mints one; a known id overwrites in place, which is
// what makes a continued conversation stay one row in the list instead of breeding a new one per
// turn. Written to a temp file and renamed, so a reader never sees half a transcript.
function vv_ai_chat_save(string $id, string $profile, array $messages): array {
function vv_ai_chat_save(string $id, string $profile, array $messages, string $scope = ''): array {
if (!$messages) return ['ok' => false, 'error' => 'Nothing to save'];
if ($id === '') $id = bin2hex(random_bytes(16));
@@ -1257,12 +1258,19 @@ function vv_ai_chat_save(string $id, string $profile, array $messages): array {
$prev = vv_ai_chat_read($id);
$created = (int)($prev['created'] ?? time());
// Scope travels with the conversation. A Scheduler dock thread is bound to what the operator
// had open — a script, a log, a conf key — and its turns carry log excerpts chosen for that
// thing. Storing the scope means reopening the thread anywhere restores the context it was
// reasoned in, rather than silently continuing a troubleshooting conversation against
// whatever happens to be on screen. The isolation the dock enforces in memory becomes a
// property of the record instead of something lost the moment it is saved.
$rec = [
'id' => $id,
'created' => $created,
'ts' => $created,
'updated' => time(),
'profile' => $profile,
'scope' => $scope,
'title' => vv_ai_chat_title($messages),
'turns' => (int)floor(count($messages) / 2),
'messages' => $messages,