Skip to content

features workspace

Claude edited this page Sep 23, 2026 · 2 revisions

Workspace and library

Active contributors: ferdiiskandar

Purpose

This feature area covers everything MyPrompt remembers and reuses: local desktop drafts, recent runs, and benchmark cases; the server-backed prompt library; and the template catalog that the Optimizer matches against. The local store is a single JSON file; the library is Prisma-backed; templates are in-repo data matched by keyword and embeddings.

Directory layout


  desktop/ipc/
    workspace-store.ts    JSON store (drafts, recent runs, benchmarks)
    workspace.ts          workspace:* IPC handlers
    library.ts            Prisma prompt list/create and template listing
    benchmark.ts          benchmark save/run against the acceptance harness
  data/templates/
    index.ts              aggregates the eight categories
  lib/templates/
    loader.ts             lookup by slug, category, and count
    matcher.ts            keyword + embedding matching
    renderer.ts           template to prompt text

Key abstractions

Abstraction Role Source
createWorkspaceStore Atomic, serialized JSON mutations desktop/ipc/workspace-store.ts
listDesktopPrompts / createDesktopPrompt Prisma-backed library desktop/ipc/library.ts
runDesktopBenchmark Benchmark against the acceptance harness desktop/ipc/benchmark.ts
matchTemplateWithEmbeddings Semantic template match with keyword fallback lib/templates/matcher.ts
renderTemplate Template to prompt text lib/templates/renderer.ts

How it works

The workspace store holds drafts, recent runs, and benchmarks in one JSON file under Electron userData. Every write goes through serializeMutation, which chains operations onto a single promise so concurrent callers never interleave, and writeSnapshotAtomic, which writes to a temp file and renames it into place, removing the temp file on failure. Reads wait for the chain and fall back to an empty snapshot if the file is missing or fails schema validation. saveDraft and saveBenchmarkCase upsert by id and preserve createdAt; appendRecentRun stamps createdAt. The workspace:* IPC handlers in workspace.ts wrap these; the desktop renderer uses them for drafts, recent runs, and the log command.

The prompt library is separate and server-backed. listDesktopPrompts reads from Prisma with pagination, task-type and tag filters, and case-insensitive search over raw input and optimized text. createDesktopPrompt validates with CreatePromptSchema, forces isPublic: false, and tags new rows desktop. See Data and Prisma for the client and schema.

Benchmarks are saved prompt cases with per-lane budgets. saveDesktopBenchmark normalises lanes, infers a title when omitted, and fills default budgets for INTERACTIVE (first-visible 5s, total 12s) and DEEP (first-visible 15s, total 45s). runDesktopBenchmark loads the acceptance environment, converts the case to an acceptance suite, runs it with the resolved provider and key, and returns the report plus a summary.

Templates live in data/templates/, aggregated into eight categories (CODING, EMAIL, ANALYSIS, CREATIVE, RESEARCH, BUSINESS, EDUCATION, MARKETING) by data/templates/index.ts. The loader resolves by slug, category, or count. The matcher scores candidates by token overlap between the idea and the template slug, name, and description, expanding both sides through a bilingual synonym map; matchTemplateWithEmbeddings adds a semantic score from cosineSimilarity and prefers the semantic result when keyword matching found nothing (similarity above 0.35) or the semantic result is clearly better (above 0.55), falling back to keyword on any embedding error. Template embeddings are cached per process and computed in one batch. The renderer emits the role, task structure, chain-of-thought guidance, constraints, and format, optionally with a quality checklist for humans, and substitutes variables and defaults.

flowchart LR
  idea[raw idea] --> M{match}
  M -->|keyword| K[scoreTemplate]
  M -->|embeddings| E[cosineSimilarity]
  E -->|error| K
  K --> T[TemplateDefinition]
  E --> T
  T --> R[renderTemplate]
  R --> O[Optimizer guidance]
Loading

Integration points

Entry points for modification

Change store shape in desktop/ipc/workspace-store.ts and the matching types in types/index.ts. Add a template category in data/templates/index.ts. Change matching weights in scoreTemplate in lib/templates/matcher.ts.

Key source files

File Purpose
desktop/ipc/workspace-store.ts Atomic JSON store
desktop/ipc/workspace.ts Workspace IPC handlers
desktop/ipc/library.ts Prisma library
desktop/ipc/benchmark.ts Benchmark cases and harness
data/templates/index.ts Template aggregation
lib/templates/loader.ts Template lookup
lib/templates/matcher.ts Keyword and embedding matching
lib/templates/renderer.ts Template rendering

Clone this wiki locally