Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/api/src/routes/content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,18 @@ describe('GET /api/content/inflight', () => {
expect(data[0]).toEqual({ pr: 42, branch: 'idea/abc-draft', title: 'Draft Idea' });
});

it('includes id when cache has matching branch entry', async () => {
it('includes id and type when cache has matching branch entry', async () => {
vi.mocked(mockCache.findByBranch).mockReturnValueOnce(ENTRIES[0]);
const res = await authed('/api/content/inflight');
const data = (await res.json()) as Array<{
pr: number;
branch: string;
title: string;
id?: string;
type?: string;
}>;
expect(data[0].id).toBe('idea-1');
expect(data[0].type).toBe('idea');
});
});

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function contentRoutes(cache: IndexCache, github: GitHubClient) {
pr: pr.number,
branch: pr.head.ref,
title: pr.title,
...(entry ? { id: entry.id } : {}),
...(entry ? { id: entry.id, type: entry.type } : {}),
};
})
);
Expand Down
20 changes: 19 additions & 1 deletion apps/web/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ export interface InFlightItem {
branch: string;
title: string;
id?: string;
type?: ContentType;
}

export const api = {
me: () => req<{ email: string; name: string } | null>('/auth/me'),
logout: () => req('/auth/logout', { method: 'POST' }),
content: (params?: { type?: string; status?: string; q?: string }) => {
const qs = new URLSearchParams(params as Record<string, string>).toString();
const defined = Object.fromEntries(
Object.entries(params ?? {}).filter(([, v]) => v !== undefined)
);
const qs = new URLSearchParams(defined as Record<string, string>).toString();
return req<IndexEntry[]>(`/api/content${qs ? `?${qs}` : ''}`);
},
contentById: (id: string) => req<ContentDetail>(`/api/content/${id}`),
Expand All @@ -61,7 +65,21 @@ export const api = {
body: JSON.stringify(body),
}),
commit: (id: string) => req(`/api/content/${id}/commit`, { method: 'POST' }),
park: (id: string) => req(`/api/content/${id}/park`, { method: 'POST' }),
dismiss: (id: string) => req(`/api/content/${id}/dismiss`, { method: 'POST' }),
promote: (id: string, title: string, summary: string) =>
req<{ id: string; pr: number; branch: string }>('/api/capture', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
type: 'plan',
title: `Plan: ${title}`,
tags: [],
summary,
promoted_from: [id],
body: `## Goal\n${summary || title}\n\n## Steps\n- (to be refined)\n\n## Success criteria\n- (to be refined)`,
}),
}),
chat: (messages: unknown[], query?: string, relatedToId?: string) =>
req<{ reply: string; context: Array<{ id: string; title: string }> }>('/api/chat', {
method: 'POST',
Expand Down
19 changes: 17 additions & 2 deletions apps/web/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ import EntryList from '$lib/components/EntryList.svelte';
import { onMount } from 'svelte';

const TYPES = ['all', 'idea', 'plan', 'discussion', 'solution', 'insight'];
const STATUSES = ['all', 'draft', 'active', 'parked', 'promoted', 'done', 'dismissed'];
let activeType = 'all';
let activeStatus = 'all';
let query = '';
let entries: IndexEntry[] = [];
let inflightCount = 0;
let searchTimer: ReturnType<typeof setTimeout> | null = null;

async function load() {
const [items, inflight] = await Promise.all([
api.content({ type: activeType === 'all' ? undefined : activeType, q: query || undefined }),
api.content({
type: activeType === 'all' ? undefined : activeType,
status: activeStatus === 'all' ? undefined : activeStatus,
q: query || undefined,
}),
api.inflight(),
]);
entries = items;
Expand Down Expand Up @@ -51,7 +57,7 @@ function onSelect(entry: IndexEntry) {
/>
</div>

<div style="display:flex;gap:0;overflow-x:auto;border-bottom:1px solid #222">
<div style="display:flex;gap:0;overflow-x:auto;border-bottom:1px solid #111">
{#each TYPES as t}
<button
on:click={() => { activeType = t; load() }}
Expand All @@ -60,5 +66,14 @@ function onSelect(entry: IndexEntry) {
{/each}
</div>

<div aria-label="Status filter" style="display:flex;gap:0;overflow-x:auto;border-bottom:1px solid #222">
{#each STATUSES as s}
<button
on:click={() => { activeStatus = s; load() }}
style="padding:6px 10px;border:none;background:{activeStatus===s?'#1a1a1a':'transparent'};color:{activeStatus===s?'#ccc':'#555'};cursor:pointer;font-size:11px;white-space:nowrap"
>{s}</button>
{/each}
</div>

<EntryList {entries} {onSelect} />
</div>
37 changes: 35 additions & 2 deletions apps/web/src/routes/chat/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ let messages: Array<{ role: 'user' | 'assistant'; content: string }> = [];
let input = '';
let loading = false;
let finishing = false;
let parking = false;
let promoting = false;
let contextTitles: string[] = [];
let error = '';

Expand Down Expand Up @@ -44,6 +46,31 @@ async function send() {
}
}

async function park() {
parking = true;
error = '';
try {
await api.park(id);
goto('/');
} catch {
error = 'Failed to park. Please try again.';
parking = false;
}
}

async function promote() {
if (!item) return;
promoting = true;
error = '';
try {
const { id: planId } = await api.promote(id, item.title, item.summary);
goto(`/chat/${planId}`);
} catch {
error = 'Failed to promote. Please try again.';
promoting = false;
}
}

async function finish() {
if (!confirm('Commit this session to GitHub?')) return;
finishing = true;
Expand All @@ -65,8 +92,14 @@ async function finish() {
<header style="padding:12px 16px;border-bottom:1px solid #222;display:flex;align-items:center;gap:8px">
<a href="/" style="color:#aaa;text-decoration:none">←</a>
<span style="flex:1;font-weight:500;font-size:14px">{item?.title ?? '...'}</span>
{#if item?.pr}
<button on:click={finish} disabled={finishing} style="font-size:12px;background:#1a3a1a;color:#4ade80;border:1px solid #4ade80;padding:4px 10px;border-radius:6px;cursor:pointer">{finishing ? '...' : 'Commit ✓'}</button>
{#if item}
{#if item.type === 'idea'}
<button on:click={promote} disabled={promoting || finishing} style="font-size:12px;background:#1a2a3a;color:#a78bfa;border:1px solid #a78bfa;padding:4px 10px;border-radius:6px;cursor:pointer">{promoting ? '...' : '→ Plan'}</button>
{/if}
<button on:click={park} disabled={parking || finishing} style="font-size:12px;background:#2a2a1a;color:#facc15;border:1px solid #facc15;padding:4px 10px;border-radius:6px;cursor:pointer">{parking ? '...' : 'Park'}</button>
{#if item.pr}
<button on:click={finish} disabled={finishing || parking} style="font-size:12px;background:#1a3a1a;color:#4ade80;border:1px solid #4ade80;padding:4px 10px;border-radius:6px;cursor:pointer">{finishing ? '...' : 'Commit ✓'}</button>
{/if}
{/if}
</header>

Expand Down
49 changes: 49 additions & 0 deletions apps/web/src/routes/chat/[id]/page.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,55 @@ describe('/chat/[id]', () => {
await waitFor(() => expect(calls).toEqual(['summarise', 'patch', 'commit']));
});

test('shows Park button when item is loaded', async () => {
render(Page);
await waitFor(() => expect(screen.getByRole('button', { name: /park/i })).toBeInTheDocument());
});

test('shows Promote button for idea type', async () => {
render(Page);
await waitFor(() => expect(screen.getByRole('button', { name: /plan/i })).toBeInTheDocument());
});

test('does not show Promote button for plan type', async () => {
server.use(
http.get('http://localhost:8744/api/content/test-id', () =>
HttpResponse.json({
id: 'test-id',
type: 'plan',
title: 'A plan',
status: 'draft',
tags: [],
summary: '',
created: '2026-01-01',
updated: '2026-01-01',
path: 'plans/a-plan.md',
body: '',
})
)
);
render(Page);
await waitFor(() => expect(screen.getByRole('button', { name: /park/i })).toBeInTheDocument());
expect(screen.queryByRole('button', { name: /plan/i })).toBeNull();
});

test('Park button calls park endpoint and navigates home', async () => {
const { goto: mockGoto } = await import('$app/navigation');
const parkCalled = vi.fn();
server.use(
http.post('http://localhost:8744/api/content/test-id/park', () => {
parkCalled();
return HttpResponse.json({ ok: true });
})
);
const user = userEvent.setup();
render(Page);
await waitFor(() => screen.getByRole('button', { name: /park/i }));
await user.click(screen.getByRole('button', { name: /park/i }));
await waitFor(() => expect(parkCalled).toHaveBeenCalled());
expect(mockGoto).toHaveBeenCalledWith('/');
});

test('shows error message when chat send fails', async () => {
server.use(
http.post('http://localhost:8744/api/chat', () =>
Expand Down
102 changes: 102 additions & 0 deletions apps/web/src/routes/page.stories.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<script module>
import { defineMeta } from '@storybook/addon-svelte-csf';
import { http, HttpResponse } from 'msw';
import Page from './+page.svelte';

const { Story } = defineMeta({
title: 'Routes/Browse',
component: Page,
});
</script>

<!-- Default handler returns [] -->
<Story name="Empty" />

<Story
name="Default — mixed entries"
parameters={{
msw: {
handlers: [
http.get('http://localhost:8744/api/content', () =>
HttpResponse.json([
{
id: '01JIDEA1',
type: 'idea',
title: 'Build a focus system',
status: 'active',
tags: ['productivity'],
summary: 'An idea for focusing better',
created: '2026-03-01T00:00:00Z',
updated: '2026-03-01T00:00:00Z',
path: 'ideas/focus.md',
},
{
id: '01JPLAN1',
type: 'plan',
title: 'Plan: Refactor API',
status: 'parked',
tags: ['api', 'tech'],
summary: 'Structured plan to refactor the API layer',
created: '2026-03-02T00:00:00Z',
updated: '2026-03-02T00:00:00Z',
path: 'plans/api-refactor.md',
},
{
id: '01JIDEA2',
type: 'idea',
title: 'Add dark mode',
status: 'done',
tags: ['ui'],
summary: 'Ship dark mode toggle',
created: '2026-03-03T00:00:00Z',
updated: '2026-03-03T00:00:00Z',
path: 'ideas/dark-mode.md',
},
])
),
],
},
}}
/>

<Story
name="Status filter — parked only"
parameters={{
msw: {
handlers: [
http.get('http://localhost:8744/api/content', () =>
HttpResponse.json([
{
id: '01JPLAN1',
type: 'plan',
title: 'Plan: Refactor API',
status: 'parked',
tags: ['api'],
summary: 'Structured plan to refactor the API layer',
created: '2026-03-02T00:00:00Z',
updated: '2026-03-02T00:00:00Z',
path: 'plans/api-refactor.md',
},
])
),
],
},
}}
/>

<Story
name="In-flight badge"
parameters={{
msw: {
handlers: [
http.get('http://localhost:8744/api/content', () => HttpResponse.json([])),
http.get('http://localhost:8744/api/content/inflight', () =>
HttpResponse.json([
{ pr: 7, branch: 'idea/abc', title: 'Draft idea' },
{ pr: 8, branch: 'idea/xyz', title: 'Another draft' },
])
),
],
},
}}
/>
53 changes: 53 additions & 0 deletions apps/web/src/routes/page.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { render, screen, waitFor, within } from '@testing-library/svelte';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
import { describe, expect, test } from 'vitest';
import { server } from '../tests/server';
import Page from './+page.svelte';

const BASE = 'http://localhost:8744';

describe('/ browse', () => {
test('renders status filter row with all statuses', async () => {
render(Page);
const statusFilter = await screen.findByRole('group', { name: /status filter/i }).catch(() =>
// fallback: find the aria-label div
screen.findByLabelText(/status filter/i)
);
expect(within(statusFilter).getByRole('button', { name: 'parked' })).toBeInTheDocument();
expect(within(statusFilter).getByRole('button', { name: 'dismissed' })).toBeInTheDocument();
expect(within(statusFilter).getByRole('button', { name: 'all' })).toBeInTheDocument();
});

test('selecting a status filter reloads content with that status', async () => {
let capturedUrl = '';
server.use(
http.get(`${BASE}/api/content`, ({ request }) => {
capturedUrl = request.url;
return HttpResponse.json([]);
})
);
const user = userEvent.setup();
render(Page);
const statusFilter = await screen.findByLabelText(/status filter/i);
await user.click(within(statusFilter).getByRole('button', { name: 'parked' }));
await waitFor(() => expect(capturedUrl).toContain('status=parked'));
});

test('all status filter does not send status param', async () => {
let capturedUrl = '';
server.use(
http.get(`${BASE}/api/content`, ({ request }) => {
capturedUrl = request.url;
return HttpResponse.json([]);
})
);
const user = userEvent.setup();
render(Page);
const statusFilter = await screen.findByLabelText(/status filter/i);
await user.click(within(statusFilter).getByRole('button', { name: 'parked' }));
await waitFor(() => expect(capturedUrl).toContain('status=parked'));
await user.click(within(statusFilter).getByRole('button', { name: 'all' }));
await waitFor(() => expect(capturedUrl).not.toContain('status='));
});
});
Loading