Skip to content

Commit e9a1ba3

Browse files
committed
Show content preview in note/task/skill list, truncate to 500 chars in API
1 parent 5b18e10 commit e9a1ba3

7 files changed

Lines changed: 55 additions & 7 deletions

File tree

src/graphs/knowledge.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ export function listNotes(
176176
filter?: string,
177177
tag?: string,
178178
limit: number = 20,
179-
): Array<{ id: string; title: string; tags: string[]; updatedAt: number }> {
179+
): Array<{ id: string; title: string; content: string; tags: string[]; updatedAt: number }> {
180180
const lowerFilter = filter?.toLowerCase();
181181
const lowerTag = tag?.toLowerCase();
182182

183-
const results: Array<{ id: string; title: string; tags: string[]; updatedAt: number }> = [];
183+
const results: Array<{ id: string; title: string; content: string; tags: string[]; updatedAt: number }> = [];
184184

185185
graph.forEachNode((id, attrs: KnowledgeNodeAttributes) => {
186186
if (attrs.proxyFor) return; // skip proxy nodes
@@ -192,7 +192,7 @@ export function listNotes(
192192
if (lowerTag) {
193193
if (!attrs.tags.some(t => t.toLowerCase() === lowerTag)) return;
194194
}
195-
results.push({ id, title: attrs.title, tags: attrs.tags, updatedAt: attrs.updatedAt });
195+
results.push({ id, title: attrs.title, content: attrs.content.slice(0, 500), tags: attrs.tags, updatedAt: attrs.updatedAt });
196196
});
197197

198198
return results

src/graphs/skill.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ export function listSkills(
365365
results.push({
366366
id,
367367
title: attrs.title,
368-
description: attrs.description,
368+
description: attrs.description?.slice(0, 500),
369369
steps: attrs.steps,
370370
triggers: attrs.triggers,
371371
inputHints: attrs.inputHints,

src/graphs/task.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ export function listTasks(
375375
results.push({
376376
id,
377377
title: attrs.title,
378-
description: attrs.description,
378+
description: attrs.description?.slice(0, 500),
379379
status: attrs.status,
380380
priority: attrs.priority,
381381
tags: attrs.tags,

src/tests/knowledge-graph.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,19 @@ describe('CRUD — Notes', () => {
200200
it('limit=1 returns 1', () => {
201201
expect(listNotes(g, undefined, undefined, 1)).toHaveLength(1);
202202
});
203+
204+
it('returns content field', () => {
205+
const note = listNotes(g).find(n => n.id === id1);
206+
expect(note?.content).toBe('Updated: JWT with refresh tokens.');
207+
});
208+
209+
it('truncates content to 500 chars', () => {
210+
const longContent = 'x'.repeat(1000);
211+
const g2 = createKnowledgeGraph();
212+
createNote(g2, 'Long Note', longContent, [], unitVec(0));
213+
const note = listNotes(g2)[0];
214+
expect(note.content).toHaveLength(500);
215+
});
203216
});
204217

205218
describe('createRelation', () => {

src/tests/skill-graph.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,19 @@ describe('CRUD — Skills', () => {
244244
it('limit=1 returns 1', () => {
245245
expect(listSkills(g, { limit: 1 })).toHaveLength(1);
246246
});
247+
248+
it('returns description field', () => {
249+
const skill = listSkills(g).find(s => s.id === id1);
250+
expect(skill?.description).toBe('Updated: complete guide to REST endpoints.');
251+
});
252+
253+
it('truncates description to 500 chars', () => {
254+
const longDesc = 'x'.repeat(1000);
255+
const g2 = createSkillGraph();
256+
createSkill(g2, 'Long Skill', longDesc, ['step'], ['trigger'], [], [], [], 'user', 1, unitVec(0));
257+
const skill = listSkills(g2)[0];
258+
expect(skill.description).toHaveLength(500);
259+
});
247260
});
248261

249262
describe('createSkillRelation', () => {

src/tests/task-graph.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,19 @@ describe('CRUD — Tasks', () => {
246246
expect(listTasks(g, { limit: 1 })).toHaveLength(1);
247247
});
248248

249+
it('returns description field', () => {
250+
const task = listTasks(g).find(t => t.id === id1);
251+
expect(task?.description).toBe('Updated: redirect loop fixed.');
252+
});
253+
254+
it('truncates description to 500 chars', () => {
255+
const longDesc = 'x'.repeat(1000);
256+
const g2 = createTaskGraph();
257+
createTask(g2, 'Long Task', longDesc, 'todo', 'medium', [], unitVec(0));
258+
const task = listTasks(g2)[0];
259+
expect(task.description).toHaveLength(500);
260+
});
261+
249262
it('dueDate sorting: tasks with dueDate before nulls', () => {
250263
// id2 has dueDate, others don't; among same priority, dueDate first
251264
const medTasks = listTasks(g, { priority: 'medium' });

ui/src/entities/note/NoteCard.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,17 @@ export function NoteCard({ note, score, onClick, onEdit }: NoteCardProps) {
3333
)}
3434
</Box>
3535
{note.content && (
36-
<Typography variant="body2" sx={{ color: palette.custom.textMuted }} noWrap>
37-
{note.content}
36+
<Typography
37+
variant="body2"
38+
sx={{
39+
color: palette.custom.textMuted,
40+
display: '-webkit-box',
41+
WebkitLineClamp: 2,
42+
WebkitBoxOrient: 'vertical',
43+
overflow: 'hidden',
44+
}}
45+
>
46+
{note.content.replace(/^#+\s*/gm, '').replace(/[*_`]/g, '').trim()}
3847
</Typography>
3948
)}
4049
{note.tags?.length > 0 && (

0 commit comments

Comments
 (0)