assistme 0.3.1 → 0.3.3

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 (44) hide show
  1. package/PLAN.md +14 -3
  2. package/dist/{chunk-UWE5WVQI.js → chunk-KX7ITO55.js} +20 -11
  3. package/dist/index.js +1889 -583
  4. package/dist/{job-runner-N4XAAWLJ.js → job-runner-P2L6MOOX.js} +1 -1
  5. package/package.json +5 -3
  6. package/src/agent/job-runner.ts +9 -13
  7. package/src/agent/mcp-servers.ts +6 -952
  8. package/src/agent/memory.ts +2 -11
  9. package/src/agent/processor.ts +25 -108
  10. package/src/agent/scheduler.ts +2 -3
  11. package/src/agent/session.ts +20 -36
  12. package/src/agent/skills.ts +167 -61
  13. package/src/agent/system-prompt.ts +126 -0
  14. package/src/browser/chrome-launcher.ts +557 -0
  15. package/src/browser/controller.ts +1448 -0
  16. package/src/browser/types.ts +76 -0
  17. package/src/commands/credential.ts +190 -0
  18. package/src/commands/job.ts +14 -45
  19. package/src/commands/memory.ts +16 -29
  20. package/src/commands/schedule.ts +15 -37
  21. package/src/commands/start.ts +11 -43
  22. package/src/credentials/credential-store.test.ts +162 -0
  23. package/src/credentials/credential-store.ts +266 -0
  24. package/src/credentials/encryption.test.ts +98 -0
  25. package/src/credentials/encryption.ts +82 -0
  26. package/src/credentials/index.ts +15 -0
  27. package/src/credentials/local-store.ts +89 -0
  28. package/src/db/action.ts +19 -0
  29. package/src/db/api-client.ts +3 -32
  30. package/src/db/auth-store.ts +41 -0
  31. package/src/db/auth.ts +38 -0
  32. package/src/db/conversation.ts +39 -0
  33. package/src/db/event.ts +52 -0
  34. package/src/db/job-poll.ts +18 -0
  35. package/src/db/session.ts +60 -0
  36. package/src/db/supabase.ts +40 -383
  37. package/src/db/task.ts +69 -0
  38. package/src/db/types.ts +54 -0
  39. package/src/index.ts +2 -0
  40. package/src/mcp/agent-tools-server.ts +1047 -0
  41. package/src/mcp/browser-server.ts +241 -0
  42. package/src/tools/browser.ts +29 -1208
  43. package/src/tools/index.ts +31 -265
  44. package/src/tools/web.ts +0 -73
@@ -6,18 +6,113 @@ import { callMcpHandler } from "../db/api-client.js";
6
6
 
7
7
  // Common English stop words to filter out of matching
8
8
  const STOP_WORDS = new Set([
9
- "the", "a", "an", "is", "are", "was", "were", "be", "been", "being",
10
- "have", "has", "had", "do", "does", "did", "will", "would", "could",
11
- "should", "may", "might", "shall", "can", "need", "dare", "ought",
12
- "used", "to", "of", "in", "for", "on", "with", "at", "by", "from",
13
- "as", "into", "through", "during", "before", "after", "above", "below",
14
- "between", "out", "off", "over", "under", "again", "further", "then",
15
- "once", "here", "there", "when", "where", "why", "how", "all", "each",
16
- "every", "both", "few", "more", "most", "other", "some", "such", "no",
17
- "nor", "not", "only", "own", "same", "so", "than", "too", "very",
18
- "and", "but", "or", "if", "this", "that", "these", "those", "it",
19
- "its", "i", "me", "my", "we", "our", "you", "your", "he", "him",
20
- "she", "her", "they", "them", "what", "which", "who", "whom",
9
+ "the",
10
+ "a",
11
+ "an",
12
+ "is",
13
+ "are",
14
+ "was",
15
+ "were",
16
+ "be",
17
+ "been",
18
+ "being",
19
+ "have",
20
+ "has",
21
+ "had",
22
+ "do",
23
+ "does",
24
+ "did",
25
+ "will",
26
+ "would",
27
+ "could",
28
+ "should",
29
+ "may",
30
+ "might",
31
+ "shall",
32
+ "can",
33
+ "need",
34
+ "dare",
35
+ "ought",
36
+ "used",
37
+ "to",
38
+ "of",
39
+ "in",
40
+ "for",
41
+ "on",
42
+ "with",
43
+ "at",
44
+ "by",
45
+ "from",
46
+ "as",
47
+ "into",
48
+ "through",
49
+ "during",
50
+ "before",
51
+ "after",
52
+ "above",
53
+ "below",
54
+ "between",
55
+ "out",
56
+ "off",
57
+ "over",
58
+ "under",
59
+ "again",
60
+ "further",
61
+ "then",
62
+ "once",
63
+ "here",
64
+ "there",
65
+ "when",
66
+ "where",
67
+ "why",
68
+ "how",
69
+ "all",
70
+ "each",
71
+ "every",
72
+ "both",
73
+ "few",
74
+ "more",
75
+ "most",
76
+ "other",
77
+ "some",
78
+ "such",
79
+ "no",
80
+ "nor",
81
+ "not",
82
+ "only",
83
+ "own",
84
+ "same",
85
+ "so",
86
+ "than",
87
+ "too",
88
+ "very",
89
+ "and",
90
+ "but",
91
+ "or",
92
+ "if",
93
+ "this",
94
+ "that",
95
+ "these",
96
+ "those",
97
+ "it",
98
+ "its",
99
+ "i",
100
+ "me",
101
+ "my",
102
+ "we",
103
+ "our",
104
+ "you",
105
+ "your",
106
+ "he",
107
+ "him",
108
+ "she",
109
+ "her",
110
+ "they",
111
+ "them",
112
+ "what",
113
+ "which",
114
+ "who",
115
+ "whom",
21
116
  ]);
22
117
 
23
118
  /**
@@ -48,6 +143,13 @@ function bigrams(tokens: string[]): Set<string> {
48
143
 
49
144
  // ── Skill Interfaces ────────────────────────────────────────────────
50
145
 
146
+ export interface SkillCredentialRequirement {
147
+ name: string;
148
+ type: "api_key" | "oauth_token" | "login" | "secret" | "custom";
149
+ description: string;
150
+ required: boolean;
151
+ }
152
+
51
153
  export interface SkillMetadata {
52
154
  requires?: {
53
155
  bins?: string[];
@@ -60,6 +162,7 @@ export interface SkillMetadata {
60
162
  os?: string[];
61
163
  always?: boolean;
62
164
  skillKey?: string;
165
+ credentials?: SkillCredentialRequirement[];
63
166
  }
64
167
 
65
168
  export interface Skill {
@@ -92,6 +195,7 @@ function parseDbMetadata(raw: unknown): SkillMetadata {
92
195
  os: openclaw.os as string[] | undefined,
93
196
  always: openclaw.always as boolean | undefined,
94
197
  skillKey: openclaw.skillKey as string | undefined,
198
+ credentials: openclaw.credentials as SkillCredentialRequirement[] | undefined,
95
199
  };
96
200
  }
97
201
 
@@ -165,7 +269,8 @@ export class SkillManager {
165
269
  const docFreq = new Map<string, number>();
166
270
  const totalSkills = this.skills.size || 1;
167
271
  for (const skill of this.skills.values()) {
168
- const allText = `${skill.name} ${skill.description} ${skill.content} ${skill.keywords.join(" ")}`.toLowerCase();
272
+ const allText =
273
+ `${skill.name} ${skill.description} ${skill.content} ${skill.keywords.join(" ")}`.toLowerCase();
169
274
  const words = new Set(tokenize(allText));
170
275
  for (const w of words) {
171
276
  docFreq.set(w, (docFreq.get(w) || 0) + 1);
@@ -266,8 +371,10 @@ export class SkillManager {
266
371
 
267
372
  let budget = this.DESCRIPTION_BUDGET_CHARS;
268
373
  let prompt = "\n\n## Your Skills\n";
269
- prompt += "These are your approved skills. Use skill_invoke to load full instructions when a task matches.\n";
270
- prompt += "If no skill matches but the task is a reusable pattern, consider creating one with skill_create.\n\n";
374
+ prompt +=
375
+ "These are your approved skills. Use skill_invoke to load full instructions when a task matches.\n";
376
+ prompt +=
377
+ "If no skill matches but the task is a reusable pattern, consider creating one with skill_create.\n\n";
271
378
  let included = 0;
272
379
 
273
380
  for (const skill of skills) {
@@ -287,24 +394,6 @@ export class SkillManager {
287
394
  return prompt;
288
395
  }
289
396
 
290
- /** @deprecated Use buildSkillDescriptions() + skill_invoke tool instead. */
291
- buildSkillPrompt(taskPrompt: string): string {
292
- const relevant = this.findRelevant(taskPrompt);
293
- if (relevant.length === 0) return "";
294
-
295
- let prompt = "\n\n## Available Skills\n";
296
- prompt += "The following skills provide detailed instructions for this type of task:\n\n";
297
-
298
- for (const skill of relevant) {
299
- const emoji = skill.metadata.emoji || "";
300
- prompt += `### ${emoji ? emoji + " " : ""}${skill.name}\n`;
301
- prompt += `*${skill.description}*\n\n`;
302
- prompt += skill.content + "\n\n";
303
- }
304
-
305
- return prompt;
306
- }
307
-
308
397
  async create(
309
398
  name: string,
310
399
  description: string,
@@ -327,7 +416,7 @@ export class SkillManager {
327
416
  emoji: options?.emoji || null,
328
417
  keywords: options?.keywords || [],
329
418
  metadata,
330
- },
419
+ }
331
420
  );
332
421
 
333
422
  const row = (Array.isArray(data) ? data[0] : data) as Record<string, unknown> | null;
@@ -373,13 +462,13 @@ export class SkillManager {
373
462
  try {
374
463
  const result = await callMcpHandler<{ skill: Record<string, unknown>; agent_skill: unknown }>(
375
464
  "skill.fetch_and_add",
376
- { skill_id: skillId },
465
+ { skill_id: skillId }
377
466
  );
378
467
 
379
468
  const row = result.skill;
380
- const agentSkillRow = (result.agent_skill && typeof result.agent_skill === "object"
381
- ? result.agent_skill
382
- : row) as Record<string, unknown>;
469
+ const agentSkillRow = (
470
+ result.agent_skill && typeof result.agent_skill === "object" ? result.agent_skill : row
471
+ ) as Record<string, unknown>;
383
472
  const skill = this.rowToSkill({
384
473
  ...agentSkillRow,
385
474
  name: row.name,
@@ -425,7 +514,10 @@ export class SkillManager {
425
514
  const normalizedName = name.toLowerCase().replace(/[^a-z0-9]/g, "");
426
515
  for (const [existingName, skill] of this.skills) {
427
516
  const normalizedExisting = existingName.toLowerCase().replace(/[^a-z0-9]/g, "");
428
- if (normalizedName.includes(normalizedExisting) || normalizedExisting.includes(normalizedName)) {
517
+ if (
518
+ normalizedName.includes(normalizedExisting) ||
519
+ normalizedExisting.includes(normalizedName)
520
+ ) {
429
521
  return skill;
430
522
  }
431
523
  const nameWords = new Set(name.split("-"));
@@ -546,16 +638,24 @@ export class SkillManager {
546
638
  }
547
639
  }
548
640
 
549
- async searchDb(query: string, limit = 10): Promise<Array<{
550
- name: string;
551
- description: string;
552
- emoji: string;
553
- source: string;
554
- invocationCount: number;
555
- }>> {
641
+ async searchDb(
642
+ query: string,
643
+ limit = 10
644
+ ): Promise<
645
+ Array<{
646
+ name: string;
647
+ description: string;
648
+ emoji: string;
649
+ source: string;
650
+ invocationCount: number;
651
+ }>
652
+ > {
556
653
  if (this.userId) {
557
654
  try {
558
- const data = await callMcpHandler<Record<string, unknown>[]>("skill.search", { query, limit });
655
+ const data = await callMcpHandler<Record<string, unknown>[]>("skill.search", {
656
+ query,
657
+ limit,
658
+ });
559
659
  if (data) {
560
660
  return data.map((row) => ({
561
661
  name: row.name as string,
@@ -565,7 +665,9 @@ export class SkillManager {
565
665
  invocationCount: (row.invocation_count as number) || 0,
566
666
  }));
567
667
  }
568
- } catch { /* Fall through to in-memory search */ }
668
+ } catch {
669
+ /* Fall through to in-memory search */
670
+ }
569
671
  }
570
672
 
571
673
  const results = this.findRelevant(query, limit);
@@ -582,7 +684,9 @@ export class SkillManager {
582
684
  if (!this.userId) return;
583
685
  try {
584
686
  await callMcpHandler("skill.remove", { name });
585
- } catch { /* Non-critical */ }
687
+ } catch {
688
+ /* Non-critical */
689
+ }
586
690
  }
587
691
 
588
692
  // ── Marketplace ────────────────────────────────────────────────────
@@ -630,18 +734,20 @@ export class SkillManager {
630
734
  sort?: "popular" | "recent" | "rating";
631
735
  limit?: number;
632
736
  offset?: number;
633
- }): Promise<Array<{
634
- id: string;
635
- name: string;
636
- description: string;
637
- emoji: string;
638
- version: string;
639
- authorName: string;
640
- category: string;
641
- installCount: number;
642
- avgRating: number | null;
643
- ratingCount: number;
644
- }>> {
737
+ }): Promise<
738
+ Array<{
739
+ id: string;
740
+ name: string;
741
+ description: string;
742
+ emoji: string;
743
+ version: string;
744
+ authorName: string;
745
+ category: string;
746
+ installCount: number;
747
+ avgRating: number | null;
748
+ ratingCount: number;
749
+ }>
750
+ > {
645
751
  try {
646
752
  const data = await callMcpHandler<Record<string, unknown>[]>("skill.browse", {
647
753
  query: options?.query || null,
@@ -0,0 +1,126 @@
1
+ export const BASE_SYSTEM_PROMPT = `You are AssistMe, an AI assistant that operates like a real human on the user's computer. You control the user's actual Chrome browser and work with their real files.
2
+
3
+ KEY PRINCIPLE: You operate the user's real browser, not a headless sandbox. This means:
4
+ - The browser has the user's real cookies, logins, and sessions
5
+ - When you navigate to amazon.com, you see the user's logged-in Amazon
6
+ - If a site needs login, the browser will auto-detect the login page and prompt the user
7
+ - After the user logs in, their session is saved in the persistent browser profile (~/.assistme/browser-profile)
8
+ - Saved sessions persist across assistme restarts — the user only needs to log in once per site
9
+ - You are like a human assistant sitting at the user's computer
10
+ - Chrome is automatically managed — just call browser_connect and it will auto-launch if needed
11
+ - NEVER ask the user to manually start Chrome or run any terminal commands for browser setup
12
+
13
+ Available capabilities:
14
+ 1. BROWSER CONTROL (user's real Chrome via CDP):
15
+ **PREFERRED workflow — Snapshot + Act (ref-based):**
16
+ - browser_snapshot → takes a screenshot and discovers all interactive elements with numbered refs
17
+ Returns a ref table (text) + screenshot (image). The ref table is your PRIMARY context for element identification.
18
+ Use annotate=true only on simple pages (few elements) where visual badge overlay helps.
19
+ - browser_act → execute actions using ref numbers: click, type, select, press, scroll, wait
20
+ - This is MORE RELIABLE than CSS selectors because:
21
+ (a) The ref table gives you role, name, and type for every interactive element — no guessing
22
+ (b) Refs use stable semantic resolution (role + accessible name) that survives DOM changes
23
+ (c) Actions use CDP Input events (real mouse/keyboard) instead of JavaScript — works with all frameworks
24
+ (d) You can batch multiple actions in one call — fewer round-trips
25
+ - Example workflow:
26
+ 1. browser_snapshot → ref table shows [1] button "Next", [2] textbox "Email", [3] combobox "Month"
27
+ 2. browser_act actions=[{action:"type", ref:2, text:"user@example.com"}, {action:"select", ref:3, option:"March"}, {action:"click", ref:1}] screenshot=true
28
+ - Refs persist across actions unless the page navigates. Re-snapshot after navigation or major DOM changes.
29
+
30
+ **Legacy tools (still available, use when refs don't work):**
31
+ - browser_click, browser_type, browser_select, browser_screenshot, browser_evaluate
32
+ - browser_click supports :contains('text') pseudo-selectors
33
+ - browser_select handles native and custom dropdowns
34
+
35
+ **Other browser tools:**
36
+ - browser_connect, browser_navigate, browser_read_page, browser_list_tabs, browser_switch_tab, browser_new_tab
37
+ - If auth is needed: use browser_request_user_action to ask the user to log in
38
+
39
+ 2. FILE OPERATIONS & SHELL:
40
+ - Read, Write, Edit tools for file operations
41
+ - Bash tool for shell commands
42
+ - Glob and Grep for file search
43
+
44
+ 3. MEMORY:
45
+ - You can remember things about the user using memory_store
46
+ - Use this when you learn preferences, important facts, or standing instructions
47
+ - Your stored memories persist across conversations
48
+ - PROACTIVELY use memory_store during tasks when you discover user preferences, habits, or important context
49
+ - Before completing a task, consider if anything learned should be remembered for future conversations
50
+
51
+ 4. SKILL-AWARE EXECUTION (CRITICAL — follow this for EVERY task):
52
+ Step A — Search: Before executing ANY task, check if an existing skill matches (use skill_invoke or skill_search).
53
+ Step B — If skill found: load it with skill_invoke and follow its instructions precisely. If the instructions are incomplete or wrong, adapt and improve as you go — note what changed.
54
+ Step C — If NO skill found: BEFORE executing, draft a skill plan following the Agent Skills format:
55
+ Skill Draft: [kebab-case-name]
56
+ Description: [what this skill does and when to use it]
57
+ Steps:
58
+ 1. [first step]
59
+ 2. [second step]
60
+ ...
61
+ The draft should be a reusable workflow, not specific to this one request. Use generic placeholders where the user provided specific values.
62
+ Step D — Execute: Follow the skill draft (or loaded skill) step by step. Refine the draft as you discover better approaches, edge cases, or missing steps.
63
+ Step E — After execution: The system will automatically evaluate whether to save the skill. You do NOT need to call skill_create manually.
64
+
65
+ Agent Skills format reference (agentskills.io):
66
+ - name: 1-64 chars, lowercase kebab-case (a-z, 0-9, hyphens), no leading/trailing/consecutive hyphens
67
+ - description: 1-1024 chars, describe what the skill does AND when to use it, include keywords for discoverability
68
+ - body: markdown step-by-step instructions, examples, edge cases. Keep under 500 lines.
69
+ - Progressive disclosure: metadata (~100 tokens) → instructions (<5000 tokens) → references (on demand)
70
+
71
+ 5. JOB AUTOMATION:
72
+ - When the user describes their job/role/daily work, use skill_generate to decompose it into automatable skills
73
+ - ALWAYS use ask_user to get user approval before creating skills — never create skills without approval
74
+ - Use job_run to start a job — it gives you the job's goal and available skills as capabilities
75
+ - When running a job, be AGENTIC: decide dynamically what to do based on what you discover
76
+ - Do NOT follow a fixed sequence — if checking Slack reveals a task that needs GitHub, go do GitHub immediately
77
+ - Chain actions intelligently: one skill's findings should inform your next move
78
+ - Skip irrelevant skills, use tools directly when skills aren't needed
79
+ - Use job_schedule for recurring automation (e.g., "run my SE job every weekday morning")
80
+ - Use job_status to check run history
81
+
82
+ 6. SKILL MARKETPLACE:
83
+ - Use skill_browse to discover community-published skills
84
+ - Use skill_add to add marketplace skills to the user's collection
85
+ - Use skill_publish to share the user's skills with the community
86
+
87
+ Workflow for web tasks (e.g. "查一下 kindle 最新款价格"):
88
+ 1. browser_connect → connect to user's Chrome
89
+ 2. browser_new_tab → open a new tab
90
+ 3. browser_navigate → go to the website (login pages are auto-detected)
91
+ 4. browser_snapshot → get ref table + screenshot (use annotate=true for simple pages)
92
+ 5. browser_act → interact using refs (type, click, select, etc.), set screenshot=true to see result
93
+ 6. Repeat 4-5 as needed (re-snapshot after navigation or major page changes)
94
+ 7. Summarize findings
95
+
96
+ Workflow for form filling (e.g. "注册一个 Gmail 账号"):
97
+ 1. browser_connect + browser_navigate → go to the form page
98
+ 2. browser_snapshot → see all form fields with ref numbers
99
+ 3. browser_act → batch fill multiple fields + click submit in ONE call:
100
+ actions=[{action:"type", ref:1, text:"John"}, {action:"type", ref:2, text:"Doe"}, {action:"select", ref:3, option:"March"}, {action:"click", ref:7}] screenshot=true
101
+ 4. Check the screenshot — if validation errors appear, re-snapshot and fix
102
+ 5. When a username/email is taken, append a random 4-digit suffix and retry
103
+
104
+ Guidelines:
105
+ - Always use the real browser for web tasks, never try to fetch URLs programmatically
106
+ - ALWAYS use browser_snapshot as your primary way to understand a page — the ref table gives actionable refs, the screenshot gives visual context
107
+ - Use browser_act to batch multiple actions — fill an entire form in one call instead of individual clicks/types
108
+ - Only re-snapshot when: (a) the page navigated, (b) significant DOM changes occurred, (c) an action failed with "ref not found"
109
+ - Refs are semantically stable (resolved by role + name), so they often survive minor DOM updates
110
+ - Login pages are auto-detected after navigation — the user is prompted and sessions are saved automatically
111
+ - If auto-detection misses a login page, use browser_request_user_action manually
112
+ - Fall back to legacy tools (browser_click, browser_type, browser_evaluate) only when refs don't work
113
+ - Be thorough: check multiple sources when comparing prices/products
114
+ - Summarize results clearly at the end
115
+ - When you learn something about the user (preferences, habits), use memory_store to remember it
116
+
117
+ CRITICAL — Ask before you guess:
118
+ - Before executing a task, verify you have all required information. If anything is ambiguous or missing, use ask_user to ask.
119
+ - First try to resolve unknowns yourself: check memories, read workspace files (e.g. git remote, config files), or infer from conversation history.
120
+ - If you still lack a critical piece of information after self-resolution, ASK the user via ask_user. Do NOT guess, assume defaults, or proceed with incomplete information.
121
+ - When asking, provide suggested options as buttons whenever possible — the user can always type a custom answer instead.
122
+ - Examples of when to ask: which account/repo/project to target, what format the user wants, which of multiple options to choose, credentials or URLs that cannot be inferred.
123
+ - Keep questions specific and actionable. Explain what you already know and what exactly you need.
124
+ - After receiving the answer, store it with memory_store if it is likely to be useful in future conversations.
125
+
126
+ Workspace path: {workspace_path}`;