evolclaw 2.6.3 → 2.7.0

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.
@@ -0,0 +1,103 @@
1
+ # EvolClaw 运行时系统提示模板
2
+
3
+ # 本文件定义 LLM 每次收到消息时注入到 system prompt 尾部的三段内容。
4
+ # 修改后执行 `evolclaw restart` 生效。
5
+ # 放在 {EVOLCLAW_HOME}/data/prompts.md 会覆盖内置默认。
6
+
7
+ ## runtime
8
+
9
+ [当前环境] 会话通道: {{channel}} | 当前项目: {{project}}{{?sessionName}} | 会话名称: {{sessionName}}{{/}}{{?selfIdentity}} | 当前名称: {{selfIdentity}}{{/}} | 对端身份: {{peerRole}}{{?peerIdentity}} | 对端名称: {{peerIdentity}}{{/}}{{?peerType}} | 对端类型: {{peerType}}{{/}}{{?chatType}} | 聊天类型: {{chatType}}{{/}}{{?agent}} | 当前Agent: {{agent}}{{/}}
10
+ {{?readonly}}[只读模式] 禁止修改项目文件。如需生成文件供用户下载,请写入 .evolclaw/tmp/ 目录后{{readonlySendHint}}{{/}}
11
+ {{?fileSendCurrent}}[SEND_FILE:路径] 发送文件到当前通道{{/}}
12
+ {{?fileSendCross}}[SEND_FILE:{{crossPrimary}}:路径] 发送文件到指定通道(可用: {{crossTypes}}){{/}}
13
+ {{?capability}}[通道能力] {{capabilities}}{{/}}
14
+
15
+ ## group
16
+
17
+ [群聊回复规则] 回复时必须在开头添加 @{{peerId}} 来通知对方
18
+
19
+ ## proactive
20
+
21
+ [Proactive 模式] 本次对话中你的流式输出不会自动发送给用户,必须通过以下命令主动发送:
22
+ - 发送文本:evolclaw ctl send "<消息内容>"
23
+ - 发送文件:evolclaw ctl file <路径>
24
+ 可多次调用。如不调用,用户将看不到任何回复。
25
+
26
+
27
+ ---
28
+
29
+ ## 格式说明
30
+
31
+ 模板由多个以 `## 段名` 分隔的段组成,加载器只识别 `runtime`、`group`、`proactive` 三段,其它段(包括本说明)会被忽略,可以随意增删。
32
+
33
+ **占位符语法:**
34
+
35
+ | 语法 | 作用 | 示例 |
36
+ |---|---|---|
37
+ | `{{var}}` | 变量替换。值为空串/undefined/null/false 时替换为空 | `{{project}}` → `evolclaw` |
38
+ | `{{?var}}...{{/}}` | 条件段。var 为真值时保留整段(含字面量),否则整段删除。段内可嵌套 `{{var}}` | `{{?peerId}} | @{{peerId}}{{/}}` |
39
+ | 空行 | 渲染后若某行只剩空白,整行自动删除 | 条件段删完后的空行会消失 |
40
+
41
+ **注入时机:**
42
+
43
+ | 段 | 触发条件 | 说明 |
44
+ |---|---|---|
45
+ | `runtime` | 每次消息 | 每条用户消息都会注入 |
46
+ | `group` | `chatType === 'group' && peerId` | 仅群聊消息注入 |
47
+ | `proactive` | `sessionMode === 'proactive'` | 仅 proactive 会话注入 |
48
+
49
+ 三段以换行拼接,追加到该消息的 system prompt 末尾。
50
+
51
+ ---
52
+
53
+ ## 参数说明
54
+
55
+ ### runtime 段
56
+
57
+ | 字段 | 类型 | 说明 | 示例 |
58
+ |---|---|---|---|
59
+ | `channel` | string | 当前通道类型 | `feishu` / `wechat` / `aun` |
60
+ | `project` | string | 当前项目目录名(非完整路径) | `evolclaw` |
61
+ | `sessionName` | string? | 会话名(用户通过 `/name` 设置) | `CLI开发` |
62
+ | `selfIdentity` | string? | 机器人自身标识「名称 (ID)」 | `Evol (evolai.xxx.pub)` |
63
+ | `peerRole` | string | 对端角色 | `owner` / `admin` / `guest` / `unknown` |
64
+ | `peerIdentity` | string? | 对端标识「名称 (ID)」 | `张三 (u_abc)` |
65
+ | `peerType` | string? | 对端类型(`unknown` 时为空) | `user` / `group` |
66
+ | `chatType` | string? | 聊天类型 | `private` / `group` |
67
+ | `agent` | string? | 当前 agent(`claude` 时为空不显示) | `hermes` / `gemini` |
68
+ | `readonly` | bool | 是否只读模式(触发只读行) | `true` / `false` |
69
+ | `readonlySendHint` | string | 只读模式下提示使用的发送方式 | `使用 [SEND_FILE:] 发送` |
70
+ | `fileSendCurrent` | bool | 当前通道是否支持发文件(触发该行) | `true` / `false` |
71
+ | `fileSendCross` | bool | 是否存在可跨通道发文件的其它通道 | `true` / `false` |
72
+ | `crossPrimary` | string | 跨通道发送示例用的首选通道 | `wechat` |
73
+ | `crossTypes` | string | 所有支持跨通道发送的通道列表 | `wechat/aun` |
74
+ | `capability` | bool | 是否有任何通道能力要展示(触发通道能力行) | `true` / `false` |
75
+ | `capabilities` | string | 通道能力清单 | `图片输入、图片输出、文件发送` |
76
+
77
+ ### group 段
78
+
79
+ | 字段 | 类型 | 说明 | 示例 |
80
+ |---|---|---|---|
81
+ | `peerId` | string | 对端用户 ID(@ 所需) | `ou_xxx` / `wxid_xxx` |
82
+
83
+ ### proactive 段
84
+
85
+ 无参数。
86
+
87
+ ---
88
+
89
+ ## 修改示例
90
+
91
+ **只改文案,不改结构:**
92
+
93
+ ```
94
+ ## runtime
95
+ 当前项目 {{project}},你正在和 {{peerIdentity}} 对话。
96
+ {{?readonly}}⚠ 只读模式,不要修改代码{{/}}
97
+ ```
98
+
99
+ **关闭某一行:** 模板里删掉那一行即可。内置条件段(如只读提示)删了之后,只读模式就不再在 system prompt 里出现(但权限拦截依然生效)。
100
+
101
+ **追加自定义规则:** 直接在对应段里加行文本,不需要占位符。
102
+
103
+ **用英文:** 所有文案重写成英文即可,字段含义不变。
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Channel Fingerprint
3
+ *
4
+ * 为每个 channel 实例提取一个全局唯一标识,用于冲突检测和路由索引。
5
+ * 格式:{type}:{primaryKey}
6
+ */
7
+ /** Channel 类型 → 主键字段映射 */
8
+ const PRIMARY_KEY_MAP = {
9
+ feishu: 'appId',
10
+ aun: 'aid',
11
+ wechat: 'token',
12
+ wecom: 'botId',
13
+ dingtalk: 'clientId',
14
+ qqbot: 'appId',
15
+ };
16
+ export function extractFingerprint(channelType, instance) {
17
+ const keyField = PRIMARY_KEY_MAP[channelType];
18
+ if (!keyField)
19
+ return null;
20
+ const value = instance[keyField];
21
+ if (!value || typeof value !== 'string')
22
+ return null;
23
+ return `${channelType}:${value}`;
24
+ }
25
+ export function detectDuplicates(config) {
26
+ const seen = new Map();
27
+ const channels = config.channels || {};
28
+ for (const [type, raw] of Object.entries(channels)) {
29
+ if (type === 'defaultChannel')
30
+ continue;
31
+ const instances = Array.isArray(raw) ? raw : [raw];
32
+ for (const inst of instances) {
33
+ if (!inst || typeof inst !== 'object')
34
+ continue;
35
+ const fingerprint = extractFingerprint(type, inst);
36
+ if (!fingerprint)
37
+ continue;
38
+ const instName = inst.name ?? type;
39
+ const entry = seen.get(fingerprint);
40
+ if (entry) {
41
+ entry.instances.push(instName);
42
+ }
43
+ else {
44
+ seen.set(fingerprint, { channelType: type, instances: [instName] });
45
+ }
46
+ }
47
+ }
48
+ const duplicates = [];
49
+ for (const [fingerprint, entry] of seen) {
50
+ if (entry.instances.length > 1) {
51
+ duplicates.push({
52
+ fingerprint,
53
+ channelType: entry.channelType,
54
+ instances: entry.instances,
55
+ });
56
+ }
57
+ }
58
+ return duplicates;
59
+ }
@@ -503,7 +503,7 @@ export async function cmdInit(options) {
503
503
  const config = JSON.parse(fs.readFileSync(sampleSrc, 'utf-8'));
504
504
  config.projects.defaultPath = defaultPath;
505
505
  config.projects.list = { [path.basename(defaultPath)]: defaultPath };
506
- config.agents.anthropic.model = model;
506
+ config.agents.claude.model = model;
507
507
  let channelConfigured = false;
508
508
  while (!channelConfigured) {
509
509
  console.log('\n选择消息渠道:');
@@ -2,7 +2,7 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { resolvePaths } from '../paths.js';
4
4
  const LOG_DIR = resolvePaths().logs;
5
- const LOG_LEVEL = process.env.LOG_LEVEL || 'INFO';
5
+ let currentLevel = process.env.LOG_LEVEL || 'INFO';
6
6
  const LEVELS = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
7
7
  const config = {
8
8
  messageLog: process.env.MESSAGE_LOG === 'true',
@@ -17,7 +17,7 @@ const streams = {
17
17
  event: config.eventLog ? fs.createWriteStream(path.join(LOG_DIR, 'events.log'), { flags: 'a' }) : null
18
18
  };
19
19
  function shouldLog(level) {
20
- return LEVELS[level] >= LEVELS[LOG_LEVEL];
20
+ return (LEVELS[level] ?? 1) >= (LEVELS[currentLevel] ?? 1);
21
21
  }
22
22
  function write(stream, data) {
23
23
  if (!stream)
@@ -35,9 +35,21 @@ function log(level, ...args) {
35
35
  return;
36
36
  const timestamp = localTimestamp();
37
37
  const msg = `[${timestamp}] [${level}] ${args.join(' ')}`;
38
- // 只写文件,不输出到 console(避免重定向时重复)
39
38
  write(streams.main, msg);
40
39
  }
40
+ /**
41
+ * 设置日志级别(config 加载后调用,覆盖环境变量默认值)
42
+ * 优先级:config.debug.logLevel → LOG_LEVEL 环境变量 → 'INFO'
43
+ */
44
+ export function setLogLevel(level) {
45
+ const upper = level.toUpperCase();
46
+ if (upper in LEVELS) {
47
+ currentLevel = upper;
48
+ }
49
+ }
50
+ export function getLogLevel() {
51
+ return currentLevel;
52
+ }
41
53
  export const logger = {
42
54
  debug: (...args) => log('DEBUG', ...args),
43
55
  info: (...args) => log('INFO', ...args),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evolclaw",
3
- "version": "2.6.3",
3
+ "version": "2.7.0",
4
4
  "description": "Lightweight AI Agent gateway connecting Claude Agent SDK to messaging channels (Feishu, ACP) with multi-project session management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",