xiaozuoassistant 0.2.54 → 0.2.56

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.
@@ -1,6 +1,12 @@
1
1
  export const SYSTEM_PROMPT = `
2
2
  你现在是 我的个人AI助手,叫xiaozuoAssistant。
3
3
 
4
+ 运行环境与能力:
5
+ - 你运行在用户的本地机器上(不是纯云端聊天机器人)。
6
+ - 你可以使用内置工具在“当前会话 workspace”内列目录、读取文件、写入文件。
7
+ - 不要让用户去手动运行 ls/cat/find 等命令;应优先调用工具完成。
8
+ - 若用户给的路径不在 workspace 内,请解释这是安全限制,并指导用户切换会话 workspace 或把文件放入 workspace。
9
+
4
10
  核心规则:
5
11
  1. 所有记忆完全本地存储,不上传任何内容到云端。
6
12
  2. 默认工作模式:优先使用 office_work 类别的记忆。
@@ -25,9 +25,14 @@ export class AgentRuntime {
25
25
  if (context?.metadata?.botName) {
26
26
  identityContext = `\n\n[System Identity]: Your name is "${context.metadata.botName}". You are acting as this bot. You must refer to yourself strictly as "${context.metadata.botName}" when introducing yourself or when asked about your identity. Do not use the generic name "xiaozuoAssistant" unless explicitly necessary.`;
27
27
  }
28
+ const effectiveWorkspace = String(context?.metadata?.workspace ||
29
+ context?.session?.workspace ||
30
+ config.workspace ||
31
+ '').trim();
32
+ const localRuntimeContext = `\n\n[Local Runtime]\nYou are running on the user's local machine (not a cloud-only assistant).\nYou can use built-in tools to list/read/write files within the current session workspace.\nWorkspace: ${effectiveWorkspace || '(not set)'}\nRules:\n- When asked to list/read/write files, use the provided tools instead of asking the user to run shell commands.\n- Never claim you are unable to access the local filesystem in general.\n- If a user provides a path outside the current workspace, explain that access is limited to the workspace for safety, and ask the user to switch the session workspace or move files into the workspace.\n- For files sent from Feishu, check workspace/downloads/<botName>/ first.\n`.trimEnd();
28
33
  const finalSystemPrompt = contextPrompt
29
- ? `${this.systemPrompt}${identityContext}\n${contextPrompt}`
30
- : `${this.systemPrompt}${identityContext}`;
34
+ ? `${this.systemPrompt}${identityContext}${localRuntimeContext}\n${contextPrompt}`
35
+ : `${this.systemPrompt}${identityContext}${localRuntimeContext}`;
31
36
  const messages = [
32
37
  { role: 'system', content: finalSystemPrompt },
33
38
  ...history.map(m => ({ role: m.role, content: m.content, name: m.name, tool_call_id: m.tool_call_id, tool_calls: m.tool_calls })),
@@ -49,6 +49,11 @@ export class Brain {
49
49
  if (context?.metadata?.botName) {
50
50
  identityContext = `\n\n[System Identity]: Your name is "${context.metadata.botName}". You are acting as this bot. You must refer to yourself strictly as "${context.metadata.botName}" when introducing yourself or when asked about your identity. Do not use the generic name "xiaozuoAssistant" unless explicitly necessary.`;
51
51
  }
52
+ const effectiveWorkspace = String(context?.metadata?.workspace ||
53
+ context?.session?.workspace ||
54
+ config.workspace ||
55
+ '').trim();
56
+ const localRuntimeContext = `\n\n[Local Runtime]\nYou are running on the user's local machine (not a cloud-only assistant).\nYou can use built-in tools to list/read/write files within the current session workspace.\nWorkspace: ${effectiveWorkspace || '(not set)'}\nRules:\n- When asked to list/read/write files, use the provided tools (fs_list_directory / fs_read_file / fs_write_file) instead of asking the user to run shell commands.\n- Never claim you are unable to access the local filesystem in general.\n- If a user provides a path outside the current workspace, explain that access is limited to the workspace for safety, and ask the user to switch the session workspace or move files into the workspace.\n- For files sent from Feishu, check workspace/downloads/<botName>/ first.\n`.trimEnd();
52
57
  // Convert history messages to the format expected by OpenAI
53
58
  // Strategy: Keep last N messages to avoid context window overflow
54
59
  // TODO: A better strategy would be token-based truncation.
@@ -65,7 +70,7 @@ export class Brain {
65
70
  return msg;
66
71
  });
67
72
  const messages = [
68
- { role: 'system', content: defaultSystemPrompt + identityContext + wakeupContext },
73
+ { role: 'system', content: defaultSystemPrompt + identityContext + localRuntimeContext + wakeupContext },
69
74
  ...messageHistory,
70
75
  { role: 'user', content: newMessage }
71
76
  ];
@@ -1,6 +1,8 @@
1
1
  import { memory } from './memory.js';
2
2
  import { brain } from './brain.js';
3
3
  import { eventBus } from './event-bus.js';
4
+ import { config } from '../config/loader.js';
5
+ import { SYSTEM_PROMPT } from '../config/prompts.js';
4
6
  export class TaskQueue {
5
7
  constructor() {
6
8
  this.chains = new Map();
@@ -43,11 +45,18 @@ export class TaskQueue {
43
45
  const context = await memory.getRelevantContext(run.userContent, run.sessionId);
44
46
  const sessionAlias = session.meta.alias ? `Session Alias: ${session.meta.alias}` : '';
45
47
  const workspaceLine = session.meta.workspace ? `Current Workspace: ${session.meta.workspace}` : '';
46
- const enhancedSystemPrompt = `You are xiaozuoAssistant, a helpful AI assistant.
48
+ const baseSystemPrompt = (config.systemPrompt && String(config.systemPrompt).trim())
49
+ ? String(config.systemPrompt).trim()
50
+ : (SYSTEM_PROMPT && String(SYSTEM_PROMPT).trim())
51
+ ? String(SYSTEM_PROMPT).trim()
52
+ : 'You are xiaozuoAssistant, a helpful AI assistant. You can use tools to help users.';
53
+ const enhancedSystemPrompt = `${baseSystemPrompt}
54
+
47
55
  ${sessionAlias}
48
56
  ${workspaceLine}
57
+
49
58
  Here is some relevant context from your memory:
50
- ${context}`;
59
+ ${context}`.trim();
51
60
  const ctx = {
52
61
  sessionId: run.sessionId,
53
62
  history: session.messages,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xiaozuoassistant",
3
- "version": "0.2.54",
3
+ "version": "0.2.56",
4
4
  "description": "A local-first personal AI assistant with multi-channel support and enhanced memory.",
5
5
  "author": "mantle.lau",
6
6
  "license": "MIT",