refactor(pro): simplify ProjectMemory and CodeIntelligence components

This commit is contained in:
Hibryda 2026-03-17 03:29:14 +01:00
parent be084c8f17
commit 285f2404aa
2 changed files with 38 additions and 97 deletions

View file

@ -21,15 +21,10 @@
let loading = $state(true); let loading = $state(true);
let error = $state<string | null>(null); let error = $state<string | null>(null);
// Git
let gitCtx = $state<GitContext | null>(null); let gitCtx = $state<GitContext | null>(null);
let gitInjected = $state<string | null>(null); let gitInjected = $state<string | null>(null);
let injecting = $state(false); let injecting = $state(false);
// Branch policy
let policy = $state<PolicyDecision | null>(null); let policy = $state<PolicyDecision | null>(null);
// Symbols
let scanResult = $state<{ filesScanned: number; symbolsFound: number; durationMs: number } | null>(null); let scanResult = $state<{ filesScanned: number; symbolsFound: number; durationMs: number } | null>(null);
let scanning = $state(false); let scanning = $state(false);
let symbolQuery = $state(''); let symbolQuery = $state('');
@ -42,60 +37,39 @@
enum: 'var(--ctp-pink)', method: 'var(--ctp-sapphire)', struct: 'var(--ctp-flamingo)', enum: 'var(--ctp-pink)', method: 'var(--ctp-sapphire)', struct: 'var(--ctp-flamingo)',
}; };
function errMsg(e: unknown): string { return e instanceof Error ? e.message : String(e); }
async function loadAll() { async function loadAll() {
loading = true; loading = true; error = null;
error = null;
try { try {
const [g, p] = await Promise.all([ const [g, p] = await Promise.all([proGitContext(projectPath), proBranchCheck(projectPath)]);
proGitContext(projectPath), gitCtx = g; policy = p;
proBranchCheck(projectPath), } catch (e) { error = errMsg(e); }
]); finally { loading = false; }
gitCtx = g;
policy = p;
} catch (e) {
error = e instanceof Error ? e.message : String(e);
} finally {
loading = false;
}
} }
$effect(() => { $effect(() => { void projectPath; loadAll(); });
void projectPath;
loadAll();
});
async function injectGit() { async function injectGit() {
injecting = true; injecting = true;
try { try { gitInjected = await proGitInject(projectPath, 4000); }
gitInjected = await proGitInject(projectPath, 4000); catch (e) { error = errMsg(e); }
} catch (e) { finally { injecting = false; }
error = e instanceof Error ? e.message : String(e);
} finally {
injecting = false;
}
} }
async function scanSymbols() { async function scanSymbols() {
scanning = true; scanning = true;
try { try { scanResult = await proSymbolsScan(projectPath); }
scanResult = await proSymbolsScan(projectPath); catch (e) { error = errMsg(e); }
} catch (e) { finally { scanning = false; }
error = e instanceof Error ? e.message : String(e);
} finally {
scanning = false;
}
} }
async function searchSymbols() { async function searchSymbols() {
if (!symbolQuery.trim()) { symbols = []; return; } if (!symbolQuery.trim()) { symbols = []; return; }
searchingSymbols = true; searchingSymbols = true;
try { try { symbols = await proSymbolsSearch(projectPath, symbolQuery.trim()); }
symbols = await proSymbolsSearch(projectPath, symbolQuery.trim()); catch (e) { error = errMsg(e); }
} catch (e) { finally { searchingSymbols = false; }
error = e instanceof Error ? e.message : String(e);
} finally {
searchingSymbols = false;
}
} }
function shortHash(h: string): string { return h.slice(0, 7); } function shortHash(h: string): string { return h.slice(0, 7); }
@ -174,18 +148,9 @@
</div> </div>
<div class="search-row"> <div class="search-row">
<input <input class="search-input" type="text" bind:value={symbolQuery} placeholder="Search symbols..." onkeydown={(e: KeyboardEvent) => e.key === 'Enter' && searchSymbols()} />
class="search-input" <button class="btn" onclick={searchSymbols} disabled={searchingSymbols}>{searchingSymbols ? '...' : 'Find'}</button>
type="text"
bind:value={symbolQuery}
placeholder="Search symbols..."
onkeydown={(e: KeyboardEvent) => e.key === 'Enter' && searchSymbols()}
/>
<button class="btn" onclick={searchSymbols} disabled={searchingSymbols}>
{searchingSymbols ? '...' : 'Find'}
</button>
</div> </div>
{#if symbols.length > 0} {#if symbols.length > 0}
<div class="symbol-list"> <div class="symbol-list">
{#each symbols as sym} {#each symbols as sym}

View file

@ -38,34 +38,23 @@
auto: 'var(--ctp-blue)', auto: 'var(--ctp-blue)',
}; };
function errMsg(e: unknown): string { return e instanceof Error ? e.message : String(e); }
async function loadMemories() { async function loadMemories() {
loading = true; loading = true; error = null;
error = null; try { memories = await proMemoryList(projectId, 50); }
try { catch (e) { error = errMsg(e); }
memories = await proMemoryList(projectId, 50); finally { loading = false; }
} catch (e) {
error = e instanceof Error ? e.message : String(e);
} finally {
loading = false;
}
} }
$effect(() => { $effect(() => { void projectId; loadMemories(); });
void projectId;
loadMemories();
});
async function doSearch() { async function doSearch() {
if (!searchQuery.trim()) { loadMemories(); return; } if (!searchQuery.trim()) { loadMemories(); return; }
searching = true; searching = true; error = null;
error = null; try { memories = await proMemorySearch(projectId, searchQuery.trim()); }
try { catch (e) { error = errMsg(e); }
memories = await proMemorySearch(projectId, searchQuery.trim()); finally { searching = false; }
} catch (e) {
error = e instanceof Error ? e.message : String(e);
} finally {
searching = false;
}
} }
async function addMemory() { async function addMemory() {
@ -73,35 +62,22 @@
adding = true; adding = true;
try { try {
await proMemoryAdd(projectId, addContent.trim(), addSource, addTags.trim()); await proMemoryAdd(projectId, addContent.trim(), addSource, addTags.trim());
addContent = ''; addContent = ''; addTags = ''; showAddForm = false;
addTags = '';
showAddForm = false;
await loadMemories(); await loadMemories();
} catch (e) { } catch (e) { error = errMsg(e); }
error = e instanceof Error ? e.message : String(e); finally { adding = false; }
} finally {
adding = false;
}
} }
async function removeMemory(id: number) { async function removeMemory(id: number) {
try { try { await proMemoryDelete(id); memories = memories.filter((m) => m.id !== id); }
await proMemoryDelete(id); catch (e) { error = errMsg(e); }
memories = memories.filter((m) => m.id !== id);
} catch (e) {
error = e instanceof Error ? e.message : String(e);
}
} }
async function injectContext() { async function injectContext() {
injecting = true; injecting = true;
try { try { injectedPreview = await proMemoryInject(projectId, 4000); }
injectedPreview = await proMemoryInject(projectId, 4000); catch (e) { error = errMsg(e); }
} catch (e) { finally { injecting = false; }
error = e instanceof Error ? e.message : String(e);
} finally {
injecting = false;
}
} }
function fmtDate(ts: number): string { function fmtDate(ts: number): string {