evolclaw 2.8.3 → 3.1.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.
- package/README.md +21 -12
- package/bin/ec.js +29 -0
- package/dist/agents/baseagent-normalize.js +19 -0
- package/dist/agents/claude-runner.js +108 -46
- package/dist/agents/codex-runner.js +13 -14
- package/dist/agents/gemini-runner.js +15 -17
- package/dist/agents/kit-renderer.js +281 -0
- package/dist/agents/resolve.js +134 -0
- package/dist/aun/aid/agentmd.js +186 -0
- package/dist/aun/aid/client.js +134 -0
- package/dist/aun/aid/identity.js +159 -0
- package/dist/aun/aid/index.js +3 -0
- package/dist/aun/aid/lifecycle-log.js +33 -0
- package/dist/aun/aid/types.js +1 -0
- package/dist/aun/aid/validation.js +21 -0
- package/dist/aun/msg/group.js +293 -0
- package/dist/aun/msg/index.js +4 -0
- package/dist/aun/msg/p2p.js +147 -0
- package/dist/aun/msg/payload-type.js +27 -0
- package/dist/aun/msg/upload.js +98 -0
- package/dist/aun/outbox.js +138 -0
- package/dist/aun/rpc/caller.js +42 -0
- package/dist/aun/rpc/connection.js +34 -0
- package/dist/aun/rpc/index.js +2 -0
- package/dist/aun/storage/download.js +29 -0
- package/dist/aun/storage/index.js +3 -0
- package/dist/aun/storage/manage.js +10 -0
- package/dist/aun/storage/upload.js +35 -0
- package/dist/channels/aun.js +1340 -349
- package/dist/channels/dingtalk.js +59 -5
- package/dist/channels/feishu.js +381 -32
- package/dist/channels/qqbot.js +68 -12
- package/dist/channels/wechat.js +63 -4
- package/dist/channels/wecom.js +59 -5
- package/dist/cli/agent.js +800 -0
- package/dist/cli/bench.js +1219 -0
- package/dist/cli/index.js +4513 -0
- package/dist/{utils → cli}/init-channel.js +211 -621
- package/dist/cli/init.js +178 -0
- package/dist/cli/link-rules.js +245 -0
- package/dist/cli/net-check.js +640 -0
- package/dist/cli/watch-msg.js +589 -0
- package/dist/config-store.js +645 -0
- package/dist/core/{agent-loader.js → baseagent-loader.js} +6 -12
- package/dist/core/channel-loader.js +176 -12
- package/dist/core/command-handler.js +883 -848
- package/dist/core/evolagent-registry.js +191 -371
- package/dist/core/evolagent.js +202 -238
- package/dist/core/interaction-router.js +52 -5
- package/dist/core/message/im-renderer.js +486 -0
- package/dist/core/message/items-formatter.js +68 -0
- package/dist/core/message/message-bridge.js +109 -56
- package/dist/core/message/message-log.js +93 -0
- package/dist/core/message/message-processor.js +430 -212
- package/dist/core/message/message-queue.js +13 -6
- package/dist/core/permission.js +116 -11
- package/dist/core/session/adapters/codex-session-file-adapter.js +24 -2
- package/dist/core/session/session-fs-store.js +230 -0
- package/dist/core/session/session-manager.js +740 -777
- package/dist/core/session/session-mapper.js +87 -0
- package/dist/core/trigger/manager.js +122 -0
- package/dist/core/trigger/parser.js +128 -0
- package/dist/core/trigger/scheduler.js +224 -0
- package/dist/data/error-dict.json +118 -0
- package/dist/eck/baseagent-caps.js +18 -0
- package/dist/eck/detect.js +47 -0
- package/dist/eck/init.js +77 -0
- package/dist/eck/rules-loader.js +28 -0
- package/dist/index.js +560 -283
- package/dist/ipc.js +49 -0
- package/dist/net-check.js +640 -0
- package/dist/paths.js +73 -9
- package/dist/types.js +8 -2
- package/dist/utils/aid-lifecycle-log.js +33 -0
- package/dist/utils/atomic-write.js +89 -0
- package/dist/utils/channel-helpers.js +46 -0
- package/dist/utils/cross-platform.js +17 -26
- package/dist/utils/error-utils.js +10 -2
- package/dist/utils/instance-registry.js +434 -0
- package/dist/utils/log-writer.js +217 -0
- package/dist/utils/logger.js +34 -77
- package/dist/utils/media-cache.js +23 -0
- package/dist/utils/npm-ops.js +163 -0
- package/dist/utils/process-introspect.js +122 -0
- package/dist/utils/stats.js +192 -0
- package/dist/watch-msg.js +544 -0
- package/evolclaw-install-aun.md +127 -47
- package/kits/docs/GUIDE.md +20 -0
- package/kits/docs/INDEX.md +52 -0
- package/kits/docs/aun/CHEATSHEET.md +17 -0
- package/kits/docs/aun/SYNC_PROTOCOL.md +15 -0
- package/kits/docs/channels/aun.md +25 -0
- package/kits/docs/channels/feishu.md +27 -0
- package/kits/docs/eck_templates/GUIDE.template.md +22 -0
- package/kits/docs/eck_templates/INDEX.template.md +28 -0
- package/kits/docs/eck_templates/path-registry.template.md +33 -0
- package/kits/docs/eck_templates/runtime.template.md +19 -0
- package/kits/docs/evolclaw/AGENT_CMD.md +31 -0
- package/kits/docs/evolclaw/MSG_GROUP.md +30 -0
- package/kits/docs/evolclaw/MSG_PRIVATE.md +25 -0
- package/kits/docs/evolclaw/self-summary.md +29 -0
- package/kits/docs/evolclaw/tools.md +25 -0
- package/kits/docs/identity/AID_PROFILE_SPEC.md +27 -0
- package/kits/docs/identity/PATH_OPS.md +16 -0
- package/kits/docs/identity/ROLE_DETAIL.md +20 -0
- package/kits/docs/identity/identity-tools.md +26 -0
- package/kits/docs/path-registry.md +43 -0
- package/kits/eck_manifest.json +95 -0
- package/kits/rules/01-overview.md +120 -0
- package/kits/rules/02-navigation.md +75 -0
- package/kits/rules/03-identity.md +34 -0
- package/kits/rules/04-relation.md +49 -0
- package/kits/rules/05-venue.md +45 -0
- package/kits/rules/06-channel.md +43 -0
- package/kits/templates/system-fragments/baseagent.md +2 -0
- package/kits/templates/system-fragments/channel.md +10 -0
- package/kits/templates/system-fragments/identity.md +12 -0
- package/kits/templates/system-fragments/relation.md +9 -0
- package/kits/templates/system-fragments/runtime.md +19 -0
- package/kits/templates/system-fragments/venue.md +5 -0
- package/package.json +10 -6
- package/data/evolclaw.sample.json +0 -60
- package/dist/agents/templates.js +0 -122
- package/dist/channels/aun-ops.js +0 -275
- package/dist/cli.js +0 -2178
- package/dist/config.js +0 -591
- package/dist/core/agent-registry.js +0 -450
- package/dist/core/evolagent-schema.js +0 -72
- package/dist/core/message/stream-flusher.js +0 -238
- package/dist/core/message/thought-emitter.js +0 -162
- package/dist/core/reload-hooks.js +0 -87
- package/dist/prompts/templates.js +0 -122
- package/dist/templates/prompts.md +0 -104
- package/dist/templates/skills.md +0 -66
- package/dist/utils/channel-fingerprint.js +0 -59
- package/dist/utils/error-dict.js +0 -63
- package/dist/utils/format.js +0 -32
- package/dist/utils/init.js +0 -645
- package/dist/utils/migrate-project.js +0 -122
- package/dist/utils/reload-hooks.js +0 -87
- package/dist/utils/stats-collector.js +0 -99
- package/dist/utils/upgrade.js +0 -100
|
@@ -1,104 +0,0 @@
|
|
|
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
|
-
调用 Bash 工具执行命令 :evolclaw ctl send "<消息内容>"
|
|
23
|
-
发送文件: evolclaw ctl file <路径>
|
|
24
|
-
可多次调用发送多条消息 ,如果不想回复停止调用即可。
|
|
25
|
-
禁止使用 AskUserQuestion 和 ExitPlanMode 工具——proactive 模式下应由你主动用 ctl send 与用户沟通。
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
---
|
|
29
|
-
|
|
30
|
-
## 格式说明
|
|
31
|
-
|
|
32
|
-
模板由多个以 `## 段名` 分隔的段组成,加载器只识别 `runtime`、`group`、`proactive` 三段,其它段(包括本说明)会被忽略,可以随意增删。
|
|
33
|
-
|
|
34
|
-
**占位符语法:**
|
|
35
|
-
|
|
36
|
-
| 语法 | 作用 | 示例 |
|
|
37
|
-
|---|---|---|
|
|
38
|
-
| `{{var}}` | 变量替换。值为空串/undefined/null/false 时替换为空 | `{{project}}` → `evolclaw` |
|
|
39
|
-
| `{{?var}}...{{/}}` | 条件段。var 为真值时保留整段(含字面量),否则整段删除。段内可嵌套 `{{var}}` | `{{?peerId}} | @{{peerId}}{{/}}` |
|
|
40
|
-
| 空行 | 渲染后若某行只剩空白,整行自动删除 | 条件段删完后的空行会消失 |
|
|
41
|
-
|
|
42
|
-
**注入时机:**
|
|
43
|
-
|
|
44
|
-
| 段 | 触发条件 | 说明 |
|
|
45
|
-
|---|---|---|
|
|
46
|
-
| `runtime` | 每次消息 | 每条用户消息都会注入 |
|
|
47
|
-
| `group` | `chatType === 'group' && peerId` | 仅群聊消息注入 |
|
|
48
|
-
| `proactive` | `sessionMode === 'proactive'` | 仅 proactive 会话注入 |
|
|
49
|
-
|
|
50
|
-
三段以换行拼接,追加到该消息的 system prompt 末尾。
|
|
51
|
-
|
|
52
|
-
---
|
|
53
|
-
|
|
54
|
-
## 参数说明
|
|
55
|
-
|
|
56
|
-
### runtime 段
|
|
57
|
-
|
|
58
|
-
| 字段 | 类型 | 说明 | 示例 |
|
|
59
|
-
|---|---|---|---|
|
|
60
|
-
| `channel` | string | 当前通道类型 | `feishu` / `wechat` / `aun` |
|
|
61
|
-
| `project` | string | 当前项目目录名(非完整路径) | `evolclaw` |
|
|
62
|
-
| `sessionName` | string? | 会话名(用户通过 `/name` 设置) | `CLI开发` |
|
|
63
|
-
| `selfIdentity` | string? | 机器人自身标识「名称 (ID)」 | `Evol (evolai.xxx.pub)` |
|
|
64
|
-
| `peerRole` | string | 对端角色 | `owner` / `admin` / `guest` / `unknown` |
|
|
65
|
-
| `peerIdentity` | string? | 对端标识「名称 (ID)」 | `张三 (u_abc)` |
|
|
66
|
-
| `peerType` | string? | 对端类型(`unknown` 时为空) | `user` / `group` |
|
|
67
|
-
| `chatType` | string? | 聊天类型 | `private` / `group` |
|
|
68
|
-
| `agent` | string? | 当前 agent(`claude` 时为空不显示) | `hermes` / `gemini` |
|
|
69
|
-
| `readonly` | bool | 是否只读模式(触发只读行) | `true` / `false` |
|
|
70
|
-
| `readonlySendHint` | string | 只读模式下提示使用的发送方式 | `使用 [SEND_FILE:] 发送` |
|
|
71
|
-
| `fileSendCurrent` | bool | 当前通道是否支持发文件(触发该行) | `true` / `false` |
|
|
72
|
-
| `fileSendCross` | bool | 是否存在可跨通道发文件的其它通道 | `true` / `false` |
|
|
73
|
-
| `crossPrimary` | string | 跨通道发送示例用的首选通道 | `wechat` |
|
|
74
|
-
| `crossTypes` | string | 所有支持跨通道发送的通道列表 | `wechat/aun` |
|
|
75
|
-
| `capability` | bool | 是否有任何通道能力要展示(触发通道能力行) | `true` / `false` |
|
|
76
|
-
| `capabilities` | string | 通道能力清单 | `图片输入、图片输出、文件发送` |
|
|
77
|
-
|
|
78
|
-
### group 段
|
|
79
|
-
|
|
80
|
-
| 字段 | 类型 | 说明 | 示例 |
|
|
81
|
-
|---|---|---|---|
|
|
82
|
-
| `peerId` | string | 对端用户 ID(@ 所需) | `ou_xxx` / `wxid_xxx` |
|
|
83
|
-
|
|
84
|
-
### proactive 段
|
|
85
|
-
|
|
86
|
-
无参数。
|
|
87
|
-
|
|
88
|
-
---
|
|
89
|
-
|
|
90
|
-
## 修改示例
|
|
91
|
-
|
|
92
|
-
**只改文案,不改结构:**
|
|
93
|
-
|
|
94
|
-
```
|
|
95
|
-
## runtime
|
|
96
|
-
当前项目 {{project}},你正在和 {{peerIdentity}} 对话。
|
|
97
|
-
{{?readonly}}⚠ 只读模式,不要修改代码{{/}}
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
**关闭某一行:** 模板里删掉那一行即可。内置条件段(如只读提示)删了之后,只读模式就不再在 system prompt 里出现(但权限拦截依然生效)。
|
|
101
|
-
|
|
102
|
-
**追加自定义规则:** 直接在对应段里加行文本,不需要占位符。
|
|
103
|
-
|
|
104
|
-
**用英文:** 所有文案重写成英文即可,字段含义不变。
|
package/dist/templates/skills.md
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: evolclaw-ctl
|
|
3
|
-
version: 1.1.0
|
|
4
|
-
description: 仅在 evolclaw 运行时可用
|
|
5
|
-
trigger: 用户询问或需要切换模型、调整推理强度、查看运行状态、压缩上下文、检查通道健康、管理权限模式、重启服务、重连渠道等
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# EvolClaw Ctl
|
|
9
|
-
|
|
10
|
-
通过 `evolclaw ctl <command> [args]` 管理运行时配置。仅在 evolclaw 托管环境中可用(`EVOLCLAW_SESSION_ID` 已设置)。
|
|
11
|
-
|
|
12
|
-
## 可用指令
|
|
13
|
-
|
|
14
|
-
### 查询类(所有用户)
|
|
15
|
-
- `evolclaw ctl help` — 显示帮助
|
|
16
|
-
- `evolclaw ctl status` — 显示会话状态
|
|
17
|
-
- `evolclaw ctl check` — 检查渠道健康状态
|
|
18
|
-
|
|
19
|
-
### 配置类(管理员)
|
|
20
|
-
- `evolclaw ctl model` — 查看当前模型和可选列表
|
|
21
|
-
- `evolclaw ctl model <model-id>` — 切换模型(如 `opus`, `sonnet`, `haiku`)
|
|
22
|
-
- `evolclaw ctl effort` — 查看当前推理强度
|
|
23
|
-
- `evolclaw ctl effort <low|medium|high|max>` — 切换推理强度
|
|
24
|
-
- `evolclaw ctl compact` — 压缩当前会话上下文
|
|
25
|
-
|
|
26
|
-
### 权限类
|
|
27
|
-
- `evolclaw ctl perm` — 查看当前权限模式(管理员)
|
|
28
|
-
- `evolclaw ctl perm <mode>` — 切换权限模式(仅 owner)
|
|
29
|
-
|
|
30
|
-
### 运维类(仅 owner)
|
|
31
|
-
- `evolclaw ctl activity <all|dm|owner|none>` — 查看/控制中间输出显示模式
|
|
32
|
-
- `evolclaw ctl send [channel] <path>` — 发送项目内文件(仅限项目目录内)
|
|
33
|
-
- `evolclaw ctl restart` — 重启服务(慎用:中断所有会话)
|
|
34
|
-
- `evolclaw ctl restart <channel>` — 重连指定渠道(管理员可用)
|
|
35
|
-
- `evolclaw ctl agentmd` — 查看当前 agent.md
|
|
36
|
-
- `evolclaw ctl agentmd put` — 发布本地 agent.md
|
|
37
|
-
- `evolclaw ctl agentmd set <内容>` — 直接设置 agent.md 内容
|
|
38
|
-
- `evolclaw ctl aid` — 列出所有 AUN 实例及连接状态
|
|
39
|
-
- `evolclaw ctl aid new <aid>` — 创建新 AID 并热加载(仅 AUN 通道)
|
|
40
|
-
|
|
41
|
-
## 使用示例
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
# 查看当前模型
|
|
45
|
-
evolclaw ctl model
|
|
46
|
-
|
|
47
|
-
# 切换到 opus
|
|
48
|
-
evolclaw ctl model opus
|
|
49
|
-
|
|
50
|
-
# 降低推理强度以加快响应
|
|
51
|
-
evolclaw ctl effort low
|
|
52
|
-
|
|
53
|
-
# 压缩上下文
|
|
54
|
-
evolclaw ctl compact
|
|
55
|
-
|
|
56
|
-
# 查看服务状态
|
|
57
|
-
evolclaw ctl status
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
## 注意事项
|
|
61
|
-
|
|
62
|
-
- 仅在 evolclaw 托管环境中可用(EVOLCLAW_SESSION_ID 环境变量已设置时)
|
|
63
|
-
- 权限继承当前会话用户的角色(owner / admin / guest)
|
|
64
|
-
- `compact` 不能在当前会话处理消息期间执行
|
|
65
|
-
- `send` 只能发送项目目录下的文件
|
|
66
|
-
- `restart` 会中断当前所有会话,谨慎使用
|
|
@@ -1,59 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/utils/error-dict.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import { logger } from './logger.js';
|
|
3
|
-
let rules = [];
|
|
4
|
-
/**
|
|
5
|
-
* 加载错误字典文件
|
|
6
|
-
* 文件不存在或格式错误 → 警告日志,rules = [](不影响启动)
|
|
7
|
-
*/
|
|
8
|
-
export function loadErrorDict(dictPath) {
|
|
9
|
-
try {
|
|
10
|
-
if (!fs.existsSync(dictPath)) {
|
|
11
|
-
logger.debug('[error-dict] 字典文件不存在,使用内置规则: %s', dictPath);
|
|
12
|
-
rules = [];
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const raw = JSON.parse(fs.readFileSync(dictPath, 'utf-8'));
|
|
16
|
-
if (!Array.isArray(raw?.rules)) {
|
|
17
|
-
logger.warn('[error-dict] 字典格式错误(缺少 rules 数组),忽略: %s', dictPath);
|
|
18
|
-
rules = [];
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
// 校验每条规则的必填字段
|
|
22
|
-
rules = raw.rules.filter((r) => {
|
|
23
|
-
if (!r.id || !r.match || !r.action) {
|
|
24
|
-
logger.warn('[error-dict] 跳过无效规则(缺少 id/match/action): %o', r);
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
if (!['retry', 'stop', 'ignore'].includes(r.action)) {
|
|
28
|
-
logger.warn('[error-dict] 跳过无效 action "%s": %s', r.action, r.id);
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
return true;
|
|
32
|
-
});
|
|
33
|
-
logger.info('[error-dict] 已加载 %d 条规则: %s', rules.length, dictPath);
|
|
34
|
-
}
|
|
35
|
-
catch (err) {
|
|
36
|
-
logger.warn('[error-dict] 加载失败: %s — %s', dictPath, err.message);
|
|
37
|
-
rules = [];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
/** 运行时重新加载(供 /reload 命令使用) */
|
|
41
|
-
export function reloadErrorDict(dictPath) {
|
|
42
|
-
loadErrorDict(dictPath);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* 匹配错误消息,返回首条命中的规则
|
|
46
|
-
* @param errorMessage 已 toLowerCase 的错误消息
|
|
47
|
-
*/
|
|
48
|
-
export function matchErrorRule(errorMessage) {
|
|
49
|
-
for (const rule of rules) {
|
|
50
|
-
if (errorMessage.includes(rule.match.toLowerCase())) {
|
|
51
|
-
return rule;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
/** 获取当前已加载的规则数量(供测试和状态查询使用) */
|
|
57
|
-
export function getLoadedRuleCount() {
|
|
58
|
-
return rules.length;
|
|
59
|
-
}
|
|
60
|
-
/** 重置规则(仅供测试使用) */
|
|
61
|
-
export function _resetRules() {
|
|
62
|
-
rules = [];
|
|
63
|
-
}
|
package/dist/utils/format.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// ── Markdown → Plain Text ───────────────────────────────────────────────────
|
|
2
|
-
export function markdownToPlainText(text) {
|
|
3
|
-
let result = text;
|
|
4
|
-
// Code blocks: strip fences, keep content
|
|
5
|
-
result = result.replace(/```[^\n]*\n?([\s\S]*?)```/g, (_, code) => code.trim());
|
|
6
|
-
// Images: remove entirely
|
|
7
|
-
result = result.replace(/!\[[^\]]*\]\([^)]*\)/g, '');
|
|
8
|
-
// Links: keep display text only
|
|
9
|
-
result = result.replace(/\[([^\]]+)\]\([^)]*\)/g, '$1');
|
|
10
|
-
// Tables: remove separator rows
|
|
11
|
-
result = result.replace(/^\|[\s:|-]+\|$/gm, '');
|
|
12
|
-
result = result.replace(/^\|(.+)\|$/gm, (_, inner) => inner.split('|').map(cell => cell.trim()).join(' '));
|
|
13
|
-
// Bold/italic
|
|
14
|
-
result = result.replace(/\*\*(.+?)\*\*/g, '$1');
|
|
15
|
-
result = result.replace(/\*(.+?)\*/g, '$1');
|
|
16
|
-
result = result.replace(/__(.+?)__/g, '$1');
|
|
17
|
-
result = result.replace(/_(.+?)_/g, '$1');
|
|
18
|
-
// Strikethrough
|
|
19
|
-
result = result.replace(/~~(.+?)~~/g, '$1');
|
|
20
|
-
// Inline code
|
|
21
|
-
result = result.replace(/`([^`]+)`/g, '$1');
|
|
22
|
-
// Headers
|
|
23
|
-
result = result.replace(/^#{1,6}\s+/gm, '');
|
|
24
|
-
// Blockquotes
|
|
25
|
-
result = result.replace(/^>\s?/gm, '');
|
|
26
|
-
// Horizontal rules
|
|
27
|
-
result = result.replace(/^[-*_]{3,}$/gm, '');
|
|
28
|
-
// List markers
|
|
29
|
-
result = result.replace(/^(\s*)[-*+]\s/gm, '$1');
|
|
30
|
-
result = result.replace(/^(\s*)\d+\.\s/gm, '$1');
|
|
31
|
-
return result.trim();
|
|
32
|
-
}
|