Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

feat(desktop): describe steps with a desktop prompt and the step before them

Luis Ortizc24bc1428001
diff --git a/apps/desktop/src/renderer/ai/describe-step.ts b/apps/desktop/src/renderer/ai/describe-step.ts
index 8d424b3..15e5107 100644
--- a/apps/desktop/src/renderer/ai/describe-step.ts
+++ b/apps/desktop/src/renderer/ai/describe-step.ts
@@ -1,5 +1,6 @@
import { getAIDescription } from '@mimik/core/capture/ai/description';
import { describeAiFailure } from '@mimik/core/capture/ai/errors';
+import { SCREEN_STEP_DESCRIPTION_PROMPT } from '@mimik/core/capture/ai/prompts';
import { serializeScreenContext } from '@mimik/core/capture/ai/screen-context';
import type { ElementMeta } from '@mimik/core/guides/types';
import { logger } from '@mimik/core/logger';
@@ -9,16 +10,18 @@ import { credentials } from './credentials';
export async function describeStep(
action: string,
meta: ElementMeta,
+ previous?: string,
): Promise<{ text: string | null; failure: OverlayAiFailure | null }> {
const keys = await credentials();
if (!keys) return { text: null, failure: null };
try {
const text = await getAIDescription(
- serializeScreenContext(action, meta),
+ serializeScreenContext(action, meta, previous),
keys.provider,
keys.model,
keys.apiKey,
keys.baseUrl,
+ SCREEN_STEP_DESCRIPTION_PROMPT,
);
return { text: text || null, failure: null };
} catch (err) {
diff --git a/apps/desktop/src/renderer/capture-sink.ts b/apps/desktop/src/renderer/capture-sink.ts
index 658c629..9146ad9 100644
--- a/apps/desktop/src/renderer/capture-sink.ts
+++ b/apps/desktop/src/renderer/capture-sink.ts
@@ -85,7 +85,8 @@ export class DesktopCaptureSink implements CaptureSink {
if (pending) {
queueDescription(data.guideId, async () => {
- const { text, failure } = await describeStep(data.action, meta);
+ const previous = (await getStepsForGuide(data.guideId)).find((step) => step.index === index - 1);
+ const { text, failure } = await describeStep(data.action, meta, previous?.description);
if (text) await updateStepDescription(stepId, text, 'ai');
await clearStepAiPending(stepId);
window.mimik.capture.described(stepId, text, failure);
diff --git a/packages/core/src/capture/ai/__tests__/screen-context.test.ts b/packages/core/src/capture/ai/__tests__/screen-context.test.ts
index 8934a52..801b492 100644
--- a/packages/core/src/capture/ai/__tests__/screen-context.test.ts
+++ b/packages/core/src/capture/ai/__tests__/screen-context.test.ts
@@ -40,6 +40,12 @@ describe('serializeScreenContext', () => {
expect(key).toContain('Key: Ctrl+S');
});
+ it('reads the control type as words and carries the step before', () => {
+ const text = serializeScreenContext('click', meta({ role: 'treeitem', ariaLabel: 'Downloads' }), 'Click "Home"');
+ expect(text).toContain('β†’ Target: tree item "Downloads" (click)');
+ expect(text).toContain('Previous step: "Click "Home""');
+ });
+
it('says what it does not know rather than inventing it', () => {
const text = serializeScreenContext('click', meta());
expect(text).toContain('Application: unknown');
diff --git a/packages/core/src/capture/ai/description.ts b/packages/core/src/capture/ai/description.ts
index 2ef7387..10642d9 100644
--- a/packages/core/src/capture/ai/description.ts
+++ b/packages/core/src/capture/ai/description.ts
@@ -9,12 +9,13 @@ export async function getAIDescription(
model: string,
apiKey: string,
baseUrl?: string,
+ template = STEP_DESCRIPTION_PROMPT,
): Promise<string | null> {
const settings = await localStorage.get(['aiLanguage']);
const locale = (settings.aiLanguage as string) || 'en';
const { text } = await generateText({
model: createModel(provider, model, apiKey, baseUrl),
- prompt: STEP_DESCRIPTION_PROMPT.replace('{{context}}', context) + getLanguageSuffix(locale),
+ prompt: template.replace('{{context}}', context) + getLanguageSuffix(locale),
maxOutputTokens: 50,
});
return text.trim().replace(/^"|"$/g, '') || null;
diff --git a/packages/core/src/capture/ai/prompts.ts b/packages/core/src/capture/ai/prompts.ts
index 72759bb..686e463 100644
--- a/packages/core/src/capture/ai/prompts.ts
+++ b/packages/core/src/capture/ai/prompts.ts
@@ -10,6 +10,20 @@ Examples of good descriptions:
Write only the description, no preamble.`;
+export const SCREEN_STEP_DESCRIPTION_PROMPT = `You are describing steps in a guide to a desktop application. Given the following context about one action the user took, write a single concise sentence describing this step.
+
+{{context}}
+
+Name the control by the label it shows, in quotes. Do not use technical control names such as "tree item", "treeview", "pane", "list item" or "group"; say "list", "menu", "field" or "button" only where a reader would. Only mention names that appear above. The previous step is there for context; describe only this one.
+
+Examples of good descriptions:
+- "Click "Downloads" in File Explorer"
+- "Select "Dark" from the Theme list"
+- "Enter "Quarterly report" as the file name"
+- "Press Ctrl+S to save the document"
+
+Write only the description, no preamble.`;
+
export const GUIDE_META_PROMPT = `These are the steps of a recorded workflow. Each one shows where it happened, a page URL or an application and its window, and what the user did:
{{steps}}
diff --git a/packages/core/src/capture/ai/screen-context.ts b/packages/core/src/capture/ai/screen-context.ts
index 787a45a..481d79e 100644
--- a/packages/core/src/capture/ai/screen-context.ts
+++ b/packages/core/src/capture/ai/screen-context.ts
@@ -1,13 +1,35 @@
import type { ElementMeta } from '@/core/guides/types';
-export function serializeScreenContext(action: string, meta: ElementMeta): string {
+const READABLE_ROLES: Record<string, string> = {
+ banner: 'title bar',
+ columnheader: 'column header',
+ combobox: 'drop-down list',
+ img: 'image',
+ listitem: 'list item',
+ menubar: 'menu bar',
+ menuitem: 'menu item',
+ progressbar: 'progress bar',
+ radio: 'radio button',
+ rowgroup: 'header',
+ scrollbar: 'scroll bar',
+ spinbutton: 'number box',
+ status: 'status bar',
+ tablist: 'tab bar',
+ textbox: 'text field',
+ thumb: 'slider handle',
+ treeitem: 'tree item',
+};
+
+export function serializeScreenContext(action: string, meta: ElementMeta, previous?: string): string {
const lines: string[] = [];
lines.push(`Application: ${meta.app?.name ?? 'unknown'}`);
if (meta.window?.title) lines.push(`Window: "${meta.window.title}"`);
+ if (previous) lines.push(`Previous step: "${previous}"`);
const name = meta.ariaLabel ?? meta.name;
- const control = [meta.role ?? 'control', name ? `"${name}"` : null].filter(Boolean).join(' ');
+ const role = meta.role ? (READABLE_ROLES[meta.role] ?? meta.role) : 'control';
+ const control = [role, name ? `"${name}"` : null].filter(Boolean).join(' ');
lines.push(`β†’ Target: ${control} (${action.startsWith('keydown:') ? 'key press' : action})`);
if (meta.textContent) lines.push(`Value: "${meta.textContent.slice(0, 120)}"`);