Skip to content

Commit 689c721

Browse files
committed
Remove ChatKind abstraction
1 parent 770d3d7 commit 689c721

9 files changed

Lines changed: 19 additions & 55 deletions

File tree

src/chat-actions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* Single source of truth for chat starter actions. Both the empty-state
3-
* cards and the "+" menu render from this list, and `ChatKind` /
4-
* `PromptName` in src/types.ts derive their enum members from it — adding
5-
* a new starter is one entry here plus a `resources/prompts/<id>.md` file.
3+
* cards and the "+" menu render from this list, and `PromptName` in
4+
* src/types.ts derives its enum members from it — adding a new starter is
5+
* one entry here plus a `resources/prompts/<id>.md` file.
66
*/
77

88
export type ChatAction = {

src/main/channels/chat-create.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,18 @@ import { z } from 'zod';
55
import { defineChannel } from './utils/define-channel';
66
import { resolveProjectPath, touchMeta } from './utils/chat-store';
77
import { IpcChannels } from '.';
8-
import { ChatKind } from '../../types';
98

109
export const chatCreate = defineChannel( {
1110
name: IpcChannels.chatCreate,
1211
input: z.object( {
1312
projectId: z.string().min( 1 ),
14-
kind: ChatKind.optional(),
1513
title: z.string().optional(),
1614
} ),
17-
handle: ( { projectId, kind, title } ) => {
15+
handle: ( { projectId, title } ) => {
1816
const projectPath = resolveProjectPath( projectId );
1917
if ( ! projectPath ) {
2018
return null;
2119
}
22-
return touchMeta( projectPath, randomUUID(), {
23-
kind: kind ?? 'general',
24-
title,
25-
} );
20+
return touchMeta( projectPath, randomUUID(), { title } );
2621
},
2722
} );

src/main/channels/utils/chat-store.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ export function readMetaFile( projectPath: string ): ChatsMetaFile {
4949
if ( ! Array.isArray( parsed.chats ) ) {
5050
return { chats: [] };
5151
}
52-
// Normalize legacy entries that predate `kind`.
5352
const chats: ChatMeta[] = parsed.chats.map( ( c ) => ( {
5453
id: c.id,
55-
kind: c.kind ?? 'general',
5654
title: c.title,
5755
sessionId: c.sessionId ?? null,
5856
createdAt: c.createdAt ?? 0,
@@ -87,30 +85,22 @@ export function removeChat( projectPath: string, chatId: string ): boolean {
8785
export function touchMeta(
8886
projectPath: string,
8987
chatId: string,
90-
patch: Partial<
91-
Pick< ChatMeta, 'sessionId' | 'lastMessageAt' | 'kind' | 'title' >
92-
>
88+
patch: Partial< Pick< ChatMeta, 'sessionId' | 'lastMessageAt' | 'title' > >
9389
): ChatMeta {
9490
const data = readMetaFile( projectPath );
9591
let chat = data.chats.find( ( c ) => c.id === chatId );
9692
const now = Date.now();
9793
if ( ! chat ) {
9894
chat = {
9995
id: chatId,
100-
kind: patch.kind ?? 'general',
10196
title: patch.title,
10297
sessionId: null,
10398
createdAt: now,
10499
lastMessageAt: null,
105100
};
106101
data.chats.push( chat );
107-
} else {
108-
if ( patch.kind !== undefined ) {
109-
chat.kind = patch.kind;
110-
}
111-
if ( patch.title !== undefined ) {
112-
chat.title = patch.title;
113-
}
102+
} else if ( patch.title !== undefined ) {
103+
chat.title = patch.title;
114104
}
115105
if ( patch.sessionId !== undefined ) {
116106
chat.sessionId = patch.sessionId;

src/preload/preload.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { contextBridge, ipcRenderer } from 'electron';
33
import { IpcChannels } from '../main/channels';
44
import type {
55
AgentEvent,
6-
ChatKind,
76
ChatMeta,
87
DirEntry,
98
PersistedMessage,
@@ -52,11 +51,10 @@ const api = {
5251
chat: {
5352
create: (
5453
projectId: string,
55-
options: { kind?: ChatKind; title?: string } = {}
54+
options: { title?: string } = {}
5655
): Promise< ChatMeta | null > =>
5756
ipcRenderer.invoke( IpcChannels.chatCreate, {
5857
projectId,
59-
kind: options.kind,
6058
title: options.title,
6159
} ),
6260
load: (

src/renderer/App.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@ export function App(): React.ReactElement {
219219
void ( async () => {
220220
let chats = await window.api.chats.list( projectId );
221221
if ( chats.length === 0 ) {
222-
const created = await window.api.chat.create( projectId, {
223-
kind: 'general',
224-
} );
222+
const created = await window.api.chat.create( projectId );
225223
if ( created ) {
226224
chats = [ created ];
227225
}
@@ -558,7 +556,6 @@ export function App(): React.ReactElement {
558556
const [ prompt, chat ] = await Promise.all( [
559557
window.api.prompt.get( name, projectId ),
560558
window.api.chat.create( projectId, {
561-
kind: name,
562559
title: action.chatTitle,
563560
} ),
564561
] );
@@ -588,9 +585,7 @@ export function App(): React.ReactElement {
588585
return;
589586
}
590587
const projectId = activeProjectId;
591-
const created = await window.api.chat.create( projectId, {
592-
kind: 'general',
593-
} );
588+
const created = await window.api.chat.create( projectId );
594589
if ( ! created ) {
595590
return;
596591
}

src/types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@ import { CHAT_ACTION_IDS } from './chat-actions';
1616
export const PromptName = z.enum( CHAT_ACTION_IDS );
1717
export type PromptName = z.infer< typeof PromptName >;
1818

19-
export const ChatKind = z.enum( [ 'general', ...CHAT_ACTION_IDS ] );
20-
export type ChatKind = z.infer< typeof ChatKind >;
21-
2219
export const ChatMeta = z.object( {
2320
id: z.string().min( 1 ),
24-
kind: ChatKind,
2521
title: z.string().optional(),
2622
sessionId: z.string().nullable(),
2723
createdAt: z.number(),

tests/e2e/chats.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,12 @@ test.describe( 'chats UI: per-project tab strip + New chat', () => {
5353
chats: [
5454
{
5555
id: 'seeded-a',
56-
kind: 'general',
5756
sessionId: null,
5857
createdAt: 1,
5958
lastMessageAt: 2,
6059
},
6160
{
6261
id: 'seeded-b',
63-
kind: 'general',
6462
sessionId: null,
6563
createdAt: 3,
6664
lastMessageAt: 4,

tests/e2e/projects.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ test.describe( 'projects UI + per-project state', () => {
6767
chats: [
6868
{
6969
id: chatId,
70-
kind: 'general',
7170
sessionId: null,
7271
createdAt: 1,
7372
lastMessageAt: 1 + messages.length,
@@ -109,7 +108,6 @@ test.describe( 'projects UI + per-project state', () => {
109108
chats: [
110109
{
111110
id: 'chat-b',
112-
kind: 'general',
113111
sessionId: null,
114112
createdAt: 1,
115113
lastMessageAt: 999,

tests/unit/chat.spec.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,15 @@ import {
2222
resolveProjectPath,
2323
touchMeta,
2424
} from '../../src/main/channels/utils/chat-store';
25-
import type { ChatKind } from '../../src/types';
2625

2726
const PROJECT_ID = 'project-a';
2827

29-
function createChat(
30-
projectId: string,
31-
kind: ChatKind = 'general',
32-
title?: string
33-
) {
28+
function createChat( projectId: string, title?: string ) {
3429
const projectPath = resolveProjectPath( projectId );
3530
if ( ! projectPath ) {
3631
return null;
3732
}
38-
return touchMeta( projectPath, randomUUID(), { kind, title } );
33+
return touchMeta( projectPath, randomUUID(), { title } );
3934
}
4035

4136
function listChats( projectId: string ) {
@@ -56,13 +51,13 @@ describe( 'chat-store: multi-chat per project', () => {
5651
} );
5752

5853
test( 'touchMeta produces distinct ids and they appear in readMetaFile', () => {
59-
const a = createChat( PROJECT_ID, 'ideas', 'Ideas' );
60-
const b = createChat( PROJECT_ID, 'draft', 'Draft' );
54+
const a = createChat( PROJECT_ID, 'Ideas' );
55+
const b = createChat( PROJECT_ID, 'Draft' );
6156
expect( a ).not.toBeNull();
6257
expect( b ).not.toBeNull();
6358
expect( a!.id ).not.toBe( b!.id );
64-
expect( a!.kind ).toBe( 'ideas' );
65-
expect( b!.kind ).toBe( 'draft' );
59+
expect( a!.title ).toBe( 'Ideas' );
60+
expect( b!.title ).toBe( 'Draft' );
6661

6762
const list = listChats( PROJECT_ID );
6863
expect( list ).toHaveLength( 2 );
@@ -119,10 +114,10 @@ describe( 'chat-store: multi-chat per project', () => {
119114
expect( bLog ).not.toContain( 'hello-a' );
120115
} );
121116

122-
test( 'readMetaFile normalizes legacy entries that predate the kind field', () => {
123-
// Write a pre-migration chats.json: no `kind` key.
117+
test( 'readMetaFile drops unknown keys (legacy entries with kind still load)', () => {
124118
const legacyChat = {
125119
id: DEFAULT_CHAT_ID,
120+
kind: 'general',
126121
sessionId: 'legacy-session',
127122
createdAt: 1000,
128123
lastMessageAt: 2000,
@@ -137,7 +132,6 @@ describe( 'chat-store: multi-chat per project', () => {
137132
const list = listChats( PROJECT_ID );
138133
expect( list ).toHaveLength( 1 );
139134
expect( list[ 0 ].id ).toBe( DEFAULT_CHAT_ID );
140-
expect( list[ 0 ].kind ).toBe( 'general' );
141135
expect( list[ 0 ].sessionId ).toBe( 'legacy-session' );
142136
} );
143137

0 commit comments

Comments
 (0)