refactor(server): search memory through the contract in artifacts, agent runs, route proposals and onboarding (P1.5)

- Artifact Center related search lists personal and workspace memories
  through server.memory and finds related chat sessions in the session
  files (UF-034).
- /api/agent/run searches the requested workspace's memory, or personal
  memory when no known workspace is given.
- Executor briefs search only the workspace's own memory and leave out
  temporary memories in the query; route proposals no longer borrow a
  mind from the cache.
- Onboarding treats any personal memory as evidence of prior use.
- The service no longer creates personal.mind on a fresh install, and
  isFirstRun also looks for waggle.db.
This commit is contained in:
shumeiko.it
2026-10-24 12:50:15 +02:00
parent e9ed8c0765
commit f310333970
13 changed files with 239 additions and 219 deletions

View File

@@ -1,7 +1,7 @@
import type { FastifyPluginAsync } from 'fastify';
import fs from 'node:fs';
import path from 'node:path';
import { FrameStore } from '@waggle/core';
import { PERSONAL_SCOPE } from '@waggle/memory-contract';
/**
* P4 (UX-Refactor) — server-authoritative onboarding status.
@@ -17,9 +17,9 @@ import { FrameStore } from '@waggle/core';
* Tauri `mark_first_launch_complete` command writes for default installs)
* is stamped by POST /api/onboarding/complete when any client finishes the
* wizard, and
* - LEGACY EVIDENCE covers installs that predate the flag: real usage in the
* personal mind (any frame) or user-created workspaces beyond the seeded
* default.
* - LEGACY EVIDENCE covers installs that predate the flag: real usage in
* personal memory (any memory) or user-created workspaces beyond the
* seeded default.
*
* Fail direction: no flag + no evidence → completed:false → the wizard runs.
* Better to show it once too often than to silently skip it (same rule as the
@@ -37,9 +37,9 @@ export const onboardingRoutes: FastifyPluginAsync = async (server) => {
// that finds no flag and no evidence stamps a durable PENDING marker — from
// then on, only explicit completion flips the status. Without the latch,
// the wizard's own pre-completion writes count as "evidence" (step 1's
// PUT /api/profile writes a 'User identity:' frame; C33 import writes
// frames; workspace-create makes list().length > 1) — and so does the
// monthly-assessment CRON frame, with zero user interaction. Any of those
// PUT /api/profile writes a 'User identity:' memory; C33 import writes
// memories; workspace-create makes list().length > 1) — and so do
// background writes, with zero user interaction. Any of those
// plus a lost localStorage (fresh WebView profile on reinstall, site-data
// clear) would silently skip the wizard for a user who never finished it —
// the exact failure direction this surface exists to prevent (review P4,
@@ -52,11 +52,10 @@ export const onboardingRoutes: FastifyPluginAsync = async (server) => {
return { completed: false, source: 'pending' };
}
try {
const frames = new FrameStore(server.multiMind.personal);
if (frames.getRecent(1).length > 0) {
if ((await server.memory.list({ scopes: [PERSONAL_SCOPE], limit: 1 })).length > 0) {
return { completed: true, source: 'legacy-evidence' };
}
} catch { /* personal mind unavailable → not evidence of prior use */ }
} catch { /* memory unavailable → not evidence of prior use */ }
try {
if (server.workspaceManager.list().length > 1) {
return { completed: true, source: 'legacy-evidence' };