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 error = $state<string | null>(null);
// Git
let gitCtx = $state<GitContext | null>(null);
let gitInjected = $state<string | null>(null);
let injecting = $state(false);
// Branch policy
let policy = $state<PolicyDecision | null>(null);
// Symbols
let scanResult = $state<{ filesScanned: number; symbolsFound: number; durationMs: number } | null>(null);
let scanning = $state(false);
let symbolQuery = $state('');
@ -42,60 +37,39 @@
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() {
loading = true;
error = null;
loading = true; error = null;
try {
const [g, p] = await Promise.all([
proGitContext(projectPath),
proBranchCheck(projectPath),
]);
gitCtx = g;
policy = p;
} catch (e) {
error = e instanceof Error ? e.message : String(e);
} finally {
loading = false;
}
const [g, p] = await Promise.all([proGitContext(projectPath), proBranchCheck(projectPath)]);
gitCtx = g; policy = p;
} catch (e) { error = errMsg(e); }
finally { loading = false; }
}
$effect(() => {
void projectPath;
loadAll();
});
$effect(() => { void projectPath; loadAll(); });
async function injectGit() {
injecting = true;
try {
gitInjected = await proGitInject(projectPath, 4000);
} catch (e) {
error = e instanceof Error ? e.message : String(e);
} finally {
injecting = false;
}
try { gitInjected = await proGitInject(projectPath, 4000); }
catch (e) { error = errMsg(e); }
finally { injecting = false; }
}
async function scanSymbols() {
scanning = true;
try {
scanResult = await proSymbolsScan(projectPath);
} catch (e) {
error = e instanceof Error ? e.message : String(e);
} finally {
scanning = false;
}
try { scanResult = await proSymbolsScan(projectPath); }
catch (e) { error = errMsg(e); }
finally { scanning = false; }
}
async function searchSymbols() {
if (!symbolQuery.trim()) { symbols = []; return; }
searchingSymbols = true;
try {
symbols = await proSymbolsSearch(projectPath, symbolQuery.trim());
} catch (e) {
error = e instanceof Error ? e.message : String(e);
} finally {
searchingSymbols = false;
}
try { symbols = await proSymbolsSearch(projectPath, symbolQuery.trim()); }
catch (e) { error = errMsg(e); }
finally { searchingSymbols = false; }
}
function shortHash(h: string): string { return h.slice(0, 7); }
@ -174,18 +148,9 @@
</div>
<div class="search-row">
<input
class="search-input"
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>
<input class="search-input" 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>
{#if symbols.length > 0}
<div class="symbol-list">
{#each symbols as sym}

View file

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