diff --git a/packages/ui/src/lib/stores/agents.ts b/packages/ui/src/lib/stores/agents.ts index 1c800ea..af99be0 100644 --- a/packages/ui/src/lib/stores/agents.ts +++ b/packages/ui/src/lib/stores/agents.ts @@ -4,7 +4,7 @@ * Context routing happens automatically — user just picks which session to talk to. */ -import { writable, derived } from 'svelte/store'; +import { writable, derived, get } from 'svelte/store'; export type ContextDepth = 'minimal' | 'light' | 'standard' | 'heavy' | 'full'; diff --git a/packages/ui/src/lib/stores/loader.ts b/packages/ui/src/lib/stores/loader.ts index d9975f9..9b7018c 100644 --- a/packages/ui/src/lib/stores/loader.ts +++ b/packages/ui/src/lib/stores/loader.ts @@ -27,6 +27,31 @@ export async function loadGraphFromUrl(url: string): Promise { graphStore.set(graph); } +/** + * Load the graph for the project the Workstation backend is running in. + * Tries `/api/graph/current` first (which reads `.klonode/graph.json` from + * the server cwd), and falls back to `/demo-graph.json` if no real graph + * exists. This means a fresh user who has run `klonode init` in their + * project sees the real tree, not a fake `demo-project`. See #64 / + * self-hosting survival work. + */ +export async function loadGraphForCurrentProject(): Promise< + 'real' | 'demo' +> { + try { + const res = await fetch('/api/graph/current'); + if (res.ok) { + const data: SerializedGraph = await res.json(); + graphStore.set(hydrateGraph(data)); + return 'real'; + } + } catch { + // fall through to demo + } + await loadGraphFromUrl('/demo-graph.json'); + return 'demo'; +} + /** * Convert serialized JSON into a proper RoutingGraph with Maps. */ diff --git a/packages/ui/src/routes/+page.svelte b/packages/ui/src/routes/+page.svelte index dc91cfa..4f8d542 100644 --- a/packages/ui/src/routes/+page.svelte +++ b/packages/ui/src/routes/+page.svelte @@ -1,7 +1,7 @@