screenhand 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/.claude/commands/automate.md +28 -0
  2. package/.claude/commands/debug-ui.md +19 -0
  3. package/.claude/commands/screenshot.md +15 -0
  4. package/.github/FUNDING.yml +1 -0
  5. package/.github/ISSUE_TEMPLATE/bug_report.md +27 -0
  6. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  7. package/.mcp.json +8 -0
  8. package/DESKTOP_MCP_GUIDE.md +92 -0
  9. package/LICENSE +661 -21
  10. package/README.md +97 -292
  11. package/SECURITY.md +44 -0
  12. package/docs/architecture.md +47 -0
  13. package/install-skills.sh +19 -0
  14. package/mcp-bridge.ts +271 -0
  15. package/mcp-desktop.ts +1221 -0
  16. package/native/macos-bridge/Package.swift +21 -0
  17. package/native/macos-bridge/Sources/AccessibilityBridge.swift +261 -0
  18. package/native/macos-bridge/Sources/AppManagement.swift +129 -0
  19. package/native/macos-bridge/Sources/CoreGraphicsBridge.swift +242 -0
  20. package/native/macos-bridge/Sources/ObserverBridge.swift +120 -0
  21. package/native/macos-bridge/Sources/VisionBridge.swift +80 -0
  22. package/native/macos-bridge/Sources/main.swift +345 -0
  23. package/native/windows-bridge/AppManagement.cs +234 -0
  24. package/native/windows-bridge/InputBridge.cs +436 -0
  25. package/native/windows-bridge/Program.cs +265 -0
  26. package/native/windows-bridge/ScreenCapture.cs +329 -0
  27. package/native/windows-bridge/UIAutomationBridge.cs +571 -0
  28. package/native/windows-bridge/WindowsBridge.csproj +17 -0
  29. package/package.json +3 -14
  30. package/playbooks/devpost.json +186 -0
  31. package/playbooks/instagram.json +41 -0
  32. package/playbooks/instagram_v2.json +201 -0
  33. package/playbooks/x_v1.json +211 -0
  34. package/scripts/devpost-live-loop.mjs +421 -0
  35. package/src/config.ts +30 -0
  36. package/src/index.ts +92 -0
  37. package/src/logging/timeline-logger.ts +55 -0
  38. package/src/mcp/server.ts +449 -0
  39. package/src/memory/recall.ts +191 -0
  40. package/src/memory/research.ts +146 -0
  41. package/src/memory/seeds.ts +123 -0
  42. package/src/memory/session.ts +201 -0
  43. package/src/memory/store.ts +434 -0
  44. package/src/memory/types.ts +69 -0
  45. package/src/native/bridge-client.ts +239 -0
  46. package/src/native/macos-bridge-client.ts +22 -0
  47. package/src/runtime/accessibility-adapter.ts +487 -0
  48. package/src/runtime/app-adapter.ts +169 -0
  49. package/src/runtime/applescript-adapter.ts +376 -0
  50. package/src/runtime/ax-role-map.ts +102 -0
  51. package/src/runtime/browser-adapter.ts +129 -0
  52. package/src/runtime/cdp-chrome-adapter.ts +676 -0
  53. package/src/runtime/composite-adapter.ts +274 -0
  54. package/src/runtime/executor.ts +396 -0
  55. package/src/runtime/locator-cache.ts +33 -0
  56. package/src/runtime/planning-loop.ts +81 -0
  57. package/src/runtime/service.ts +448 -0
  58. package/src/runtime/session-manager.ts +50 -0
  59. package/src/runtime/state-observer.ts +136 -0
  60. package/src/runtime/vision-adapter.ts +297 -0
  61. package/src/types.ts +297 -0
  62. package/tests/bridge-client.test.ts +176 -0
  63. package/tests/browser-stealth.test.ts +210 -0
  64. package/tests/composite-adapter.test.ts +64 -0
  65. package/tests/mcp-server.test.ts +151 -0
  66. package/tests/memory-recall.test.ts +339 -0
  67. package/tests/memory-research.test.ts +159 -0
  68. package/tests/memory-seeds.test.ts +120 -0
  69. package/tests/memory-store.test.ts +392 -0
  70. package/tests/types.test.ts +92 -0
  71. package/tsconfig.check.json +17 -0
  72. package/tsconfig.json +19 -0
  73. package/vitest.config.ts +8 -0
  74. package/dist/config.js +0 -9
  75. package/dist/index.js +0 -55
  76. package/dist/logging/timeline-logger.js +0 -29
  77. package/dist/mcp/mcp-stdio-server.js +0 -284
  78. package/dist/mcp/server.js +0 -347
  79. package/dist/mcp-entry.js +0 -62
  80. package/dist/memory/recall.js +0 -160
  81. package/dist/memory/research.js +0 -98
  82. package/dist/memory/seeds.js +0 -89
  83. package/dist/memory/session.js +0 -161
  84. package/dist/memory/store.js +0 -391
  85. package/dist/memory/types.js +0 -4
  86. package/dist/native/bridge-client.js +0 -173
  87. package/dist/native/macos-bridge-client.js +0 -5
  88. package/dist/runtime/accessibility-adapter.js +0 -377
  89. package/dist/runtime/app-adapter.js +0 -48
  90. package/dist/runtime/applescript-adapter.js +0 -283
  91. package/dist/runtime/ax-role-map.js +0 -80
  92. package/dist/runtime/browser-adapter.js +0 -36
  93. package/dist/runtime/cdp-chrome-adapter.js +0 -505
  94. package/dist/runtime/composite-adapter.js +0 -205
  95. package/dist/runtime/executor.js +0 -250
  96. package/dist/runtime/locator-cache.js +0 -12
  97. package/dist/runtime/planning-loop.js +0 -47
  98. package/dist/runtime/service.js +0 -372
  99. package/dist/runtime/session-manager.js +0 -28
  100. package/dist/runtime/state-observer.js +0 -105
  101. package/dist/runtime/vision-adapter.js +0 -208
  102. package/dist/test-mcp-protocol.js +0 -138
  103. package/dist/types.js +0 -1
@@ -0,0 +1,146 @@
1
+ // Copyright (C) 2025 Clazro Technology Private Limited
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+ //
4
+ // This file is part of ScreenHand.
5
+ //
6
+ // ScreenHand is free software: you can redistribute it and/or modify
7
+ // it under the terms of the GNU Affero General Public License as
8
+ // published by the Free Software Foundation, version 3.
9
+ //
10
+ // ScreenHand is distributed in the hope that it will be useful,
11
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ // GNU Affero General Public License for more details.
14
+ //
15
+ // You should have received a copy of the GNU Affero General Public License
16
+ // along with ScreenHand. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ /**
19
+ * Background web research — fire-and-forget resolution lookup.
20
+ *
21
+ * When a tool fails and no resolution exists, this searches for a fix
22
+ * in the background (non-blocking) and saves it for next time.
23
+ *
24
+ * Resolution paths:
25
+ * 1. Claude API (haiku) — if ANTHROPIC_API_KEY is set
26
+ * 2. DuckDuckGo instant answer — free fallback, no auth
27
+ */
28
+
29
+ import type { MemoryStore } from "./store.js";
30
+
31
+ export function backgroundResearch(
32
+ store: MemoryStore,
33
+ tool: string,
34
+ params: Record<string, unknown>,
35
+ errorMessage: string,
36
+ ): void {
37
+ // Fire-and-forget — never blocks, never throws
38
+ doResearch(store, tool, params, errorMessage).catch(() => {});
39
+ }
40
+
41
+ async function doResearch(
42
+ store: MemoryStore,
43
+ tool: string,
44
+ params: Record<string, unknown>,
45
+ errorMessage: string,
46
+ ): Promise<void> {
47
+ const query = `macOS automation: "${tool}" failed with "${errorMessage.slice(0, 200)}"`;
48
+
49
+ let resolution: string | null = null;
50
+
51
+ const apiKey = process.env["ANTHROPIC_API_KEY"];
52
+ if (apiKey) {
53
+ resolution = await tryClaudeAPI(apiKey, query);
54
+ }
55
+
56
+ if (!resolution) {
57
+ resolution = await tryDuckDuckGo(query);
58
+ }
59
+
60
+ if (!resolution) return;
61
+
62
+ // Save resolution to error cache
63
+ store.appendError({
64
+ id: "err_research_" + Date.now().toString(36),
65
+ tool,
66
+ params,
67
+ error: errorMessage,
68
+ resolution,
69
+ occurrences: 1,
70
+ lastSeen: new Date().toISOString(),
71
+ });
72
+
73
+ // Save as a reusable strategy
74
+ store.appendStrategy({
75
+ id: "str_research_" + Date.now().toString(36),
76
+ task: `Fix: ${tool} — ${errorMessage.slice(0, 100)}`,
77
+ steps: [{ tool, params }],
78
+ totalDurationMs: 0,
79
+ successCount: 1,
80
+ failCount: 0,
81
+ lastUsed: new Date().toISOString(),
82
+ tags: [tool, "research", "fix"],
83
+ fingerprint: "",
84
+ });
85
+ }
86
+
87
+ async function tryClaudeAPI(apiKey: string, query: string): Promise<string | null> {
88
+ try {
89
+ const controller = new AbortController();
90
+ const timeout = setTimeout(() => controller.abort(), 10000);
91
+
92
+ const response = await fetch("https://api.anthropic.com/v1/messages", {
93
+ method: "POST",
94
+ headers: {
95
+ "Content-Type": "application/json",
96
+ "x-api-key": apiKey,
97
+ "anthropic-version": "2023-06-01",
98
+ },
99
+ body: JSON.stringify({
100
+ model: "claude-haiku-4-5-20251001",
101
+ max_tokens: 200,
102
+ messages: [{
103
+ role: "user",
104
+ content: `You are a macOS automation expert. Give a brief fix (1-2 sentences) for this error:\n\n${query}`,
105
+ }],
106
+ }),
107
+ signal: controller.signal,
108
+ });
109
+
110
+ clearTimeout(timeout);
111
+
112
+ if (!response.ok) return null;
113
+
114
+ const data = await response.json() as {
115
+ content?: Array<{ type: string; text?: string }>;
116
+ };
117
+ const text = data.content?.[0]?.text;
118
+ return text && text.length > 10 ? text.trim() : null;
119
+ } catch {
120
+ return null;
121
+ }
122
+ }
123
+
124
+ async function tryDuckDuckGo(query: string): Promise<string | null> {
125
+ try {
126
+ const controller = new AbortController();
127
+ const timeout = setTimeout(() => controller.abort(), 5000);
128
+
129
+ const url = `https://api.duckduckgo.com/?q=${encodeURIComponent(query)}&format=json&no_html=1`;
130
+ const response = await fetch(url, { signal: controller.signal });
131
+
132
+ clearTimeout(timeout);
133
+
134
+ if (!response.ok) return null;
135
+
136
+ const data = await response.json() as {
137
+ AbstractText?: string;
138
+ Abstract?: string;
139
+ Answer?: string;
140
+ };
141
+ const text = data.AbstractText || data.Abstract || data.Answer;
142
+ return text && text.length > 10 ? text.trim() : null;
143
+ } catch {
144
+ return null;
145
+ }
146
+ }
@@ -0,0 +1,123 @@
1
+ // Copyright (C) 2025 Clazro Technology Private Limited
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+ //
4
+ // This file is part of ScreenHand.
5
+ //
6
+ // ScreenHand is free software: you can redistribute it and/or modify
7
+ // it under the terms of the GNU Affero General Public License as
8
+ // published by the Free Software Foundation, version 3.
9
+ //
10
+ // ScreenHand is distributed in the hope that it will be useful,
11
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ // GNU Affero General Public License for more details.
14
+ //
15
+ // You should have received a copy of the GNU Affero General Public License
16
+ // along with ScreenHand. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ /**
19
+ * Predefined seed strategies — common macOS desktop workflows.
20
+ * Loaded on first boot so the memory system has knowledge from day one.
21
+ */
22
+
23
+ import type { Strategy, StrategyStep } from "./types.js";
24
+
25
+ let seedCounter = 0;
26
+
27
+ function makeFingerprint(tools: string[]): string {
28
+ return tools.join("→");
29
+ }
30
+
31
+ function seed(task: string, steps: StrategyStep[], tags: string[]): Strategy {
32
+ seedCounter++;
33
+ return {
34
+ id: `seed_${String(seedCounter).padStart(3, "0")}`,
35
+ task,
36
+ steps,
37
+ totalDurationMs: 0,
38
+ successCount: 10,
39
+ failCount: 0,
40
+ lastUsed: new Date().toISOString(),
41
+ tags,
42
+ fingerprint: makeFingerprint(steps.map((s) => s.tool)),
43
+ };
44
+ }
45
+
46
+ export const SEED_STRATEGIES: Strategy[] = [
47
+ // 1. Take a photo with Photo Booth
48
+ seed("Take a photo with Photo Booth", [
49
+ { tool: "launch", params: { bundleId: "com.apple.PhotoBooth" } },
50
+ { tool: "ui_press", params: { title: "Take Photo" } },
51
+ ], ["photo", "booth", "camera"]),
52
+
53
+ // 2. Open a URL in Chrome
54
+ seed("Open a URL in Chrome", [
55
+ { tool: "launch", params: { bundleId: "com.google.Chrome" } },
56
+ { tool: "browser_navigate", params: { url: "" } },
57
+ ], ["chrome", "browse", "url"]),
58
+
59
+ // 3. Save current document
60
+ seed("Save current document", [
61
+ { tool: "focus", params: { bundleId: "" } },
62
+ { tool: "key", params: { combo: "cmd+s" } },
63
+ ], ["save", "document"]),
64
+
65
+ // 4. Copy from one app and paste into another
66
+ seed("Copy from one app and paste into another", [
67
+ { tool: "focus", params: { bundleId: "" } },
68
+ { tool: "key", params: { combo: "cmd+c" } },
69
+ { tool: "focus", params: { bundleId: "" } },
70
+ { tool: "key", params: { combo: "cmd+v" } },
71
+ ], ["copy", "paste"]),
72
+
73
+ // 5. Navigate to a folder in Finder
74
+ seed("Navigate to a folder in Finder", [
75
+ { tool: "focus", params: { bundleId: "com.apple.finder" } },
76
+ { tool: "key", params: { combo: "cmd+shift+g" } },
77
+ { tool: "type_text", params: { text: "" } },
78
+ ], ["finder", "folder", "navigate"]),
79
+
80
+ // 6. Create a new folder in Finder
81
+ seed("Create a new folder in Finder", [
82
+ { tool: "focus", params: { bundleId: "com.apple.finder" } },
83
+ { tool: "key", params: { combo: "cmd+shift+n" } },
84
+ { tool: "type_text", params: { text: "" } },
85
+ ], ["finder", "folder", "create"]),
86
+
87
+ // 7. Close the current window
88
+ seed("Close the current window", [
89
+ { tool: "focus", params: { bundleId: "" } },
90
+ { tool: "key", params: { combo: "cmd+w" } },
91
+ ], ["close", "window"]),
92
+
93
+ // 8. Select all and copy
94
+ seed("Select all content and copy", [
95
+ { tool: "focus", params: { bundleId: "" } },
96
+ { tool: "key", params: { combo: "cmd+a" } },
97
+ { tool: "key", params: { combo: "cmd+c" } },
98
+ ], ["select", "all", "copy"]),
99
+
100
+ // 9. List running apps
101
+ seed("List all running applications", [
102
+ { tool: "apps", params: {} },
103
+ ], ["apps", "list", "running"]),
104
+
105
+ // 10. Inspect app UI tree
106
+ seed("Inspect an app's UI element tree", [
107
+ { tool: "focus", params: { bundleId: "" } },
108
+ { tool: "ui_tree", params: { pid: 0 } },
109
+ ], ["inspect", "tree", "accessibility"]),
110
+
111
+ // 11. Open a new tab in Chrome and navigate
112
+ seed("Open a new Chrome tab and navigate to URL", [
113
+ { tool: "focus", params: { bundleId: "com.google.Chrome" } },
114
+ { tool: "key", params: { combo: "cmd+t" } },
115
+ { tool: "browser_navigate", params: { url: "" } },
116
+ ], ["chrome", "tab", "new"]),
117
+
118
+ // 12. Export as PDF via menu
119
+ seed("Export document as PDF", [
120
+ { tool: "focus", params: { bundleId: "" } },
121
+ { tool: "menu_click", params: { menuPath: "File/Export as PDF" } },
122
+ ], ["export", "pdf"]),
123
+ ];
@@ -0,0 +1,201 @@
1
+ // Copyright (C) 2025 Clazro Technology Private Limited
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+ //
4
+ // This file is part of ScreenHand.
5
+ //
6
+ // ScreenHand is free software: you can redistribute it and/or modify
7
+ // it under the terms of the GNU Affero General Public License as
8
+ // published by the Free Software Foundation, version 3.
9
+ //
10
+ // ScreenHand is distributed in the hope that it will be useful,
11
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ // GNU Affero General Public License for more details.
14
+ //
15
+ // You should have received a copy of the GNU Affero General Public License
16
+ // along with ScreenHand. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ /**
19
+ * Learning Memory — Session tracking with auto-save
20
+ *
21
+ * Tracks a rolling buffer of actions within a "task session".
22
+ * Auto-saves strategies when a successful sequence is detected:
23
+ * - 3+ consecutive successes followed by a gap (>60s) or session end
24
+ * - Or explicit endSession() call
25
+ */
26
+
27
+ import type { ActionEntry, Strategy, StrategyStep } from "./types.js";
28
+ import { MemoryStore } from "./store.js";
29
+ import type { RecallEngine } from "./recall.js";
30
+
31
+ const SESSION_GAP_MS = 60_000; // 60s gap = new session
32
+ const MAX_BUFFER_SIZE = 100;
33
+ const MIN_AUTO_SAVE_STEPS = 3; // Need at least 3 successful steps to auto-save
34
+
35
+ export class SessionTracker {
36
+ private store: MemoryStore;
37
+ private sessionId: string;
38
+ private taskDescription: string | null = null;
39
+ private buffer: ActionEntry[] = [];
40
+ private lastActionTime = 0;
41
+
42
+ constructor(store: MemoryStore) {
43
+ this.store = store;
44
+ this.sessionId = SessionTracker.generateId();
45
+ }
46
+
47
+ private static generateId(): string {
48
+ return "s_" + Date.now().toString(36) + Math.random().toString(36).slice(2, 6);
49
+ }
50
+
51
+ /** Start (or restart) a named task session */
52
+ startSession(taskDescription?: string): string {
53
+ // Auto-save previous session if it had successful actions
54
+ this.tryAutoSave();
55
+
56
+ this.sessionId = SessionTracker.generateId();
57
+ this.taskDescription = taskDescription ?? null;
58
+ this.buffer = [];
59
+ this.lastActionTime = Date.now();
60
+ return this.sessionId;
61
+ }
62
+
63
+ /** Get the current session ID, auto-rotating if stale */
64
+ getSessionId(): string {
65
+ const now = Date.now();
66
+ if (this.lastActionTime > 0 && now - this.lastActionTime > SESSION_GAP_MS) {
67
+ // Session gap detected — auto-save previous sequence then start fresh
68
+ this.tryAutoSave();
69
+ this.sessionId = SessionTracker.generateId();
70
+ this.buffer = [];
71
+ this.taskDescription = null;
72
+ }
73
+ return this.sessionId;
74
+ }
75
+
76
+ /** Record an action into the current session buffer */
77
+ recordAction(entry: ActionEntry): void {
78
+ const now = Date.now();
79
+ if (this.lastActionTime > 0 && now - this.lastActionTime > SESSION_GAP_MS) {
80
+ // Gap detected — auto-save then start new session
81
+ this.tryAutoSave();
82
+ this.sessionId = SessionTracker.generateId();
83
+ this.buffer = [];
84
+ this.taskDescription = null;
85
+ }
86
+ this.lastActionTime = now;
87
+
88
+ this.buffer.push(entry);
89
+ if (this.buffer.length > MAX_BUFFER_SIZE) {
90
+ this.buffer.shift();
91
+ }
92
+ }
93
+
94
+ /** End the session and save a strategy if successful */
95
+ endSession(success: boolean, taskDescription?: string): Strategy | null {
96
+ const task = taskDescription ?? this.taskDescription;
97
+ if (!success || !task || this.buffer.length === 0) {
98
+ this.buffer = [];
99
+ return null;
100
+ }
101
+
102
+ const strategy = this.buildStrategy(task, this.buffer);
103
+ this.store.appendStrategy(strategy);
104
+ this.buffer = [];
105
+ return strategy;
106
+ }
107
+
108
+ /** Get the current session's action buffer */
109
+ getBuffer(): ActionEntry[] {
110
+ return [...this.buffer];
111
+ }
112
+
113
+ /** Get recent tool names (for strategy hint matching) */
114
+ getRecentToolNames(limit = 10): string[] {
115
+ return this.buffer.slice(-limit).map((a) => a.tool);
116
+ }
117
+
118
+ /** Get current task description */
119
+ getTaskDescription(): string | null {
120
+ return this.taskDescription;
121
+ }
122
+
123
+ // ── auto-save logic ────────────────────────────
124
+
125
+ /**
126
+ * Try to auto-save the current buffer as a strategy.
127
+ * Only saves if there are MIN_AUTO_SAVE_STEPS+ consecutive successes.
128
+ * Uses tool sequence as task description if no explicit one was given.
129
+ */
130
+ private tryAutoSave(): void {
131
+ if (this.buffer.length < MIN_AUTO_SAVE_STEPS) return;
132
+
133
+ // Find the longest trailing streak of successes
134
+ let successStreak: ActionEntry[] = [];
135
+ for (let i = this.buffer.length - 1; i >= 0; i--) {
136
+ if (this.buffer[i]!.success) {
137
+ successStreak.unshift(this.buffer[i]!);
138
+ } else {
139
+ break;
140
+ }
141
+ }
142
+
143
+ if (successStreak.length < MIN_AUTO_SAVE_STEPS) return;
144
+
145
+ // Build a task description from the tool sequence if none provided
146
+ const task = this.taskDescription ?? this.inferTaskDescription(successStreak);
147
+
148
+ const strategy = this.buildStrategy(task, successStreak);
149
+ this.store.appendStrategy(strategy);
150
+ }
151
+
152
+ /** Infer a task description from a sequence of actions */
153
+ private inferTaskDescription(actions: ActionEntry[]): string {
154
+ const tools = [...new Set(actions.map((a) => a.tool))];
155
+ // Extract key param values (bundle IDs, titles, URLs, etc.)
156
+ const keyParams: string[] = [];
157
+ for (const a of actions) {
158
+ for (const [key, val] of Object.entries(a.params)) {
159
+ if (typeof val === "string" && val.length > 2 && val.length < 60) {
160
+ if (["bundleId", "title", "url", "text", "script", "selector", "menuPath"].includes(key)) {
161
+ keyParams.push(val);
162
+ }
163
+ }
164
+ }
165
+ }
166
+ const paramHint = keyParams.length > 0 ? ` (${keyParams.slice(0, 3).join(", ")})` : "";
167
+ return `${tools.join(" → ")}${paramHint}`;
168
+ }
169
+
170
+ private buildStrategy(task: string, actions: ActionEntry[]): Strategy {
171
+ const steps: StrategyStep[] = actions.map((a) => ({
172
+ tool: a.tool,
173
+ params: a.params,
174
+ }));
175
+
176
+ const totalDurationMs = actions.reduce((sum, a) => sum + a.durationMs, 0);
177
+ const tags = extractTags(task, steps);
178
+ const fingerprint = MemoryStore.makeFingerprint(steps.map((s) => s.tool));
179
+
180
+ return {
181
+ id: "str_" + Date.now().toString(36) + Math.random().toString(36).slice(2, 6),
182
+ task,
183
+ steps,
184
+ totalDurationMs,
185
+ successCount: 1,
186
+ failCount: 0,
187
+ lastUsed: new Date().toISOString(),
188
+ tags,
189
+ fingerprint,
190
+ };
191
+ }
192
+ }
193
+
194
+ /** Extract tags from task description and tool names */
195
+ function extractTags(task: string, steps: StrategyStep[]): string[] {
196
+ const tags = new Set<string>();
197
+ const words = task.toLowerCase().split(/\W+/).filter((w) => w.length >= 3);
198
+ for (const w of words) tags.add(w);
199
+ for (const s of steps) tags.add(s.tool);
200
+ return [...tags];
201
+ }