mirror of
https://github.com/davidkaya/aryx.git
synced 2026-08-28 13:47:12 +02:00
feat: add scratchpad chat sessions
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -5,7 +5,7 @@ import { dialog } from 'electron';
|
||||
|
||||
import type { AgentActivityEvent, TurnDeltaEvent } from '@shared/contracts/sidecar';
|
||||
import { buildSessionTitle, validatePatternDefinition, type PatternDefinition } from '@shared/domain/pattern';
|
||||
import type { ProjectRecord } from '@shared/domain/project';
|
||||
import { isScratchpadProject, type ProjectRecord } from '@shared/domain/project';
|
||||
import type { SessionEventRecord } from '@shared/domain/event';
|
||||
import type { ChatMessageRecord, SessionRecord } from '@shared/domain/session';
|
||||
import type { WorkspaceState } from '@shared/domain/workspace';
|
||||
@@ -75,6 +75,10 @@ export class KopayaAppService extends EventEmitter<AppServiceEvents> {
|
||||
}
|
||||
|
||||
async removeProject(projectId: string): Promise<WorkspaceState> {
|
||||
if (isScratchpadProject(projectId)) {
|
||||
throw new Error('Scratchpad cannot be removed.');
|
||||
}
|
||||
|
||||
const workspace = await this.loadWorkspace();
|
||||
workspace.projects = workspace.projects.filter((project) => project.id !== projectId);
|
||||
workspace.sessions = workspace.sessions.filter((session) => session.projectId !== projectId);
|
||||
@@ -187,6 +191,7 @@ export class KopayaAppService extends EventEmitter<AppServiceEvents> {
|
||||
});
|
||||
|
||||
const requestId = createId('turn');
|
||||
const workspaceKind = isScratchpadProject(project) ? 'scratchpad' : 'project';
|
||||
try {
|
||||
const responseMessages = await this.sidecar.runTurn(
|
||||
{
|
||||
@@ -194,6 +199,7 @@ export class KopayaAppService extends EventEmitter<AppServiceEvents> {
|
||||
requestId,
|
||||
sessionId: session.id,
|
||||
projectPath: project.path,
|
||||
workspaceKind,
|
||||
pattern,
|
||||
messages: session.messages,
|
||||
},
|
||||
|
||||
@@ -4,3 +4,7 @@ import { join } from 'node:path';
|
||||
export function getWorkspaceFilePath(): string {
|
||||
return join(app.getPath('userData'), 'workspace.json');
|
||||
}
|
||||
|
||||
export function getScratchpadDirectoryPath(): string {
|
||||
return join(app.getPath('userData'), 'scratchpad');
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { mkdir } from 'node:fs/promises';
|
||||
|
||||
import { createBuiltinPatterns } from '@shared/domain/pattern';
|
||||
import type { PatternDefinition } from '@shared/domain/pattern';
|
||||
import { mergeScratchpadProject } from '@shared/domain/project';
|
||||
import { createWorkspaceSeed, type WorkspaceState } from '@shared/domain/workspace';
|
||||
import { nowIso } from '@shared/utils/ids';
|
||||
|
||||
import { getWorkspaceFilePath } from '@main/persistence/appPaths';
|
||||
import { getScratchpadDirectoryPath, getWorkspaceFilePath } from '@main/persistence/appPaths';
|
||||
import { readJsonFile, writeJsonFile } from '@main/persistence/jsonStore';
|
||||
|
||||
function mergePatterns(existingPatterns: PatternDefinition[]): PatternDefinition[] {
|
||||
@@ -32,20 +35,34 @@ function mergePatterns(existingPatterns: PatternDefinition[]): PatternDefinition
|
||||
|
||||
export class WorkspaceRepository {
|
||||
readonly filePath = getWorkspaceFilePath();
|
||||
readonly scratchpadPath = getScratchpadDirectoryPath();
|
||||
|
||||
async load(): Promise<WorkspaceState> {
|
||||
await mkdir(this.scratchpadPath, { recursive: true });
|
||||
|
||||
const stored = await readJsonFile<WorkspaceState>(this.filePath);
|
||||
if (!stored) {
|
||||
const seeded = createWorkspaceSeed();
|
||||
const seededBase = createWorkspaceSeed();
|
||||
const projects = mergeScratchpadProject([], this.scratchpadPath);
|
||||
const seeded: WorkspaceState = {
|
||||
...seededBase,
|
||||
projects,
|
||||
selectedProjectId: projects[0]?.id,
|
||||
};
|
||||
await this.save(seeded);
|
||||
return seeded;
|
||||
}
|
||||
|
||||
const projects = mergeScratchpadProject(stored.projects ?? [], this.scratchpadPath);
|
||||
|
||||
const workspace: WorkspaceState = {
|
||||
...stored,
|
||||
patterns: mergePatterns(stored.patterns ?? []),
|
||||
projects: stored.projects ?? [],
|
||||
projects,
|
||||
sessions: stored.sessions ?? [],
|
||||
selectedProjectId: projects.some((project) => project.id === stored.selectedProjectId)
|
||||
? stored.selectedProjectId
|
||||
: projects[0]?.id,
|
||||
lastUpdatedAt: stored.lastUpdatedAt ?? nowIso(),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user