evolcore 0.0.45 → 0.0.47
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/CHANGELOG.md +113 -0
- package/bin/ecmsg.js +33 -23
- package/dist/ability/application-service.js +1 -2
- package/dist/ability/package.js +28 -0
- package/dist/agent-template/jobs.js +158 -36
- package/dist/agent-template/runtime.js +401 -34
- package/dist/agent-template/service.js +764 -369
- package/dist/agent-template/tool-runner.js +35 -17
- package/dist/agent-template/types.js +7 -4
- package/dist/agents/baseagent.js +10 -9
- package/dist/agents/claude-runner.js +22 -6
- package/dist/agents/codex/app-server-client.js +34 -27
- package/dist/agents/codex/diagnostics.js +18 -1
- package/dist/agents/codex-runner.js +3 -1
- package/dist/agents/ecagent-runner.js +3 -1
- package/dist/agents/gemini-runner.js +2 -1
- package/dist/aun/group/fs-download.js +1 -1
- package/dist/aun/menu/client.js +142 -182
- package/dist/aun/rpc/client.js +33 -17
- package/dist/aun/service-proxy.js +6 -23
- package/dist/channels/aun.js +675 -120
- package/dist/channels/daemon.js +1 -1
- package/dist/cli/agent-create.js +37 -10
- package/dist/cli/agent-template.js +105 -84
- package/dist/cli/agent.js +31 -18
- package/dist/cli/daemon-commands.js +42 -56
- package/dist/cli/daemon-lifecycle-client.js +55 -19
- package/dist/cli/directory.js +12 -4
- package/dist/cli/ecmsg-gateway.js +5 -2
- package/dist/cli/events-command.js +2 -1
- package/dist/cli/init-channel.js +2 -2
- package/dist/cli/init.js +57 -21
- package/dist/cli/integrity-command.js +2 -0
- package/dist/cli/managed-command-guard.js +20 -1
- package/dist/cli/menu-client.js +7 -5
- package/dist/cli/restart-monitor.js +135 -46
- package/dist/cli/services-command.js +28 -5
- package/dist/cli/task-context.js +83 -15
- package/dist/cli/upgrade-command.js +4 -2
- package/dist/config/config-field-policy.js +24 -0
- package/dist/config/config-manager.js +49 -19
- package/dist/config/peer-book-store.js +167 -127
- package/dist/config/peer-role-resolver.js +24 -4
- package/dist/config/provider-identity-migration.js +158 -6
- package/dist/config/provider-identity.js +10 -4
- package/dist/config/provider-ipc-service.js +10 -2
- package/dist/config/provider-local-sync.js +2 -2
- package/dist/config/providers-config.js +95 -10
- package/dist/config/providers-import.js +4 -6
- package/dist/config/providers.js +14 -3
- package/dist/config/role-store.js +1 -1
- package/dist/config/schema-migration.js +123 -16
- package/dist/config/schema-registry.js +6 -2
- package/dist/config-store.js +9 -1
- package/dist/core/agent-application-service.js +56 -29
- package/dist/core/agent-create-status.js +3 -1
- package/dist/core/agent-creation-claim.js +1 -0
- package/dist/core/agent-ipc-registration.js +2 -2
- package/dist/core/agent-reload-coordinator.js +38 -1
- package/dist/core/agent-runtime.js +91 -43
- package/dist/core/auth/agent-delegation.js +13 -3
- package/dist/core/auth/delegation-diagnostics.js +56 -15
- package/dist/core/auth/operation-authorizer.js +2 -2
- package/dist/core/auth/operation-catalog.js +3 -3
- package/dist/core/bootstrap-service.js +3 -0
- package/dist/core/capability/capability-manager.js +3 -1
- package/dist/core/channel-loader.js +29 -3
- package/dist/core/channel-runtime.js +1 -1
- package/dist/core/command/agent-control.js +6 -5
- package/dist/core/command/agent-template-menu.js +32 -97
- package/dist/core/command/eventcenter-menu.js +61 -13
- package/dist/core/command/menu-catalog.js +11 -4
- package/dist/core/command/menu-handler.js +39 -12
- package/dist/core/command/menu-protocol.js +8 -16
- package/dist/core/command/skill-slash.js +6 -2
- package/dist/core/command/slash-handler.js +4 -6
- package/dist/core/command/team-workspace-bootstrap.js +1 -2
- package/dist/core/command/team-workspace-management-store.js +83 -0
- package/dist/core/command/team-workspace-management.js +1 -2
- package/dist/core/command/team-workspace-team.js +26 -3
- package/dist/core/daemon-bootstrap.js +11 -9
- package/dist/core/daemon-control.js +4 -7
- package/dist/core/daemon-lifecycle.js +189 -143
- package/dist/core/evolagent-registry.js +50 -2
- package/dist/core/evolagent.js +2 -1
- package/dist/core/file-integrity/read.js +9 -16
- package/dist/core/file-integrity/store.js +94 -34
- package/dist/core/handoff/dispatcher.js +33 -7
- package/dist/core/handoff/runtime.js +8 -0
- package/dist/core/host-snapshot.js +9 -4
- package/dist/core/inference/text-inference.js +12 -2
- package/dist/core/initialization/service.js +22 -4
- package/dist/core/invoke/invoke-service.js +24 -3
- package/dist/core/ipc-registration.js +7 -3
- package/dist/core/memory/consolidation.js +6 -6
- package/dist/core/message/aun-ipc-sender.js +109 -7
- package/dist/core/message/contact-admission.js +6 -2
- package/dist/core/message/message-bridge.js +13 -0
- package/dist/core/message/message-queue.js +131 -30
- package/dist/core/message/pending-hints.js +8 -0
- package/dist/core/message/response-engine.js +48 -2
- package/dist/core/message/send-routing.js +3 -12
- package/dist/core/model/catalog-service.js +13 -0
- package/dist/core/model/model-catalog.js +57 -18
- package/dist/core/ownership/owner-resolver.js +27 -10
- package/dist/core/pack-auth.js +163 -31
- package/dist/core/pack-install.js +42 -1
- package/dist/{services/ledger.js → core/pack-ledger.js} +17 -6
- package/dist/core/permission/ec-command-parser.js +3 -1
- package/dist/core/permission/shell-environment.js +23 -0
- package/dist/core/rate-window.js +6 -1
- package/dist/core/relation/peer-identity.js +5 -1
- package/dist/core/relation/same-owner-proof.js +2 -1
- package/dist/core/session/adapters/claude-session-file-adapter.js +1 -1
- package/dist/core/session/session-file-health.js +36 -7
- package/dist/core/session/session-idle-monitor.js +0 -1
- package/dist/core/session/session-manager.js +14 -0
- package/dist/core/session/session-title.js +26 -6
- package/dist/core/skill/index-generator.js +3 -4
- package/dist/core/task/task-image-resources.js +1 -1
- package/dist/core/thread/thread-service.js +0 -1
- package/dist/core/thread/topic-id.js +8 -0
- package/dist/directory/owner-directory-admission.js +17 -0
- package/dist/directory/owner-directory-cache.js +3 -1
- package/dist/directory/owner-directory-markdown.js +145 -23
- package/dist/directory/owner-directory-policy.js +23 -0
- package/dist/directory/owner-directory-query-operation.js +20 -6
- package/dist/directory/owner-directory-search.js +47 -0
- package/dist/eck/message-renderer.js +171 -32
- package/dist/ecweb/basic-settings-service.js +7 -3
- package/dist/ecweb/providers-service.js +17 -10
- package/dist/ecweb/runtime/lifecycle.js +65 -16
- package/dist/ecweb/runtime/supervisor.js +79 -50
- package/dist/event-center/admission-materializer.js +1 -1
- package/dist/event-center/bus-gate.js +48 -4
- package/dist/event-center/bus-host.js +3 -3
- package/dist/event-center/center-config.js +57 -28
- package/dist/event-center/dispatcher.js +8 -0
- package/dist/event-center/event-log.js +69 -27
- package/dist/event-center/index-generator.js +6 -1
- package/dist/event-center/ipc-operation.js +66 -25
- package/dist/event-center/pack-loader.js +12 -55
- package/dist/event-center/pack-manager.js +5 -3
- package/dist/event-center/registry.js +48 -52
- package/dist/event-center/runtime.js +219 -81
- package/dist/event-center/script-runner.js +18 -7
- package/dist/event-center/types.js +9 -1
- package/dist/event-center/validation.js +33 -4
- package/dist/index.js +132 -75
- package/dist/ipc.js +35 -8
- package/dist/product.js +1 -0
- package/dist/proxy/manager.js +52 -11
- package/dist/proxy/service-supervisor.js +265 -67
- package/dist/services/dispatcher.js +26 -3
- package/dist/services/idempotency.js +128 -0
- package/dist/services/identity.js +3 -27
- package/dist/services/index-generator.js +5 -1
- package/dist/services/index.js +244 -45
- package/dist/services/ipc-operation.js +164 -20
- package/dist/services/pack-manager.js +37 -9
- package/dist/services/router.js +100 -31
- package/dist/services/script-runner.js +15 -4
- package/dist/services/service-payload.js +50 -2
- package/dist/services/validation.js +107 -3
- package/dist/trigger/scheduler.js +18 -4
- package/dist/trigger/script-sandbox.js +39 -2
- package/dist/trigger/state.js +7 -0
- package/dist/utils/aid-bind.js +155 -18
- package/dist/utils/atomic-write.js +3 -3
- package/dist/utils/cross-platform.js +59 -16
- package/dist/utils/error-utils.js +26 -1
- package/dist/utils/instance-registry.js +94 -35
- package/dist/utils/process-introspect.js +187 -27
- package/dist/utils/project-path.js +47 -3
- package/dist/utils/upgrade-jobs.js +4 -4
- package/dist/utils/windows-shell-trust.js +174 -68
- package/kits/docs/context-assembly.md +3 -3
- package/kits/docs/evolcore/agent.md +28 -10
- package/kits/docs/evolcore/aid.md +3 -1
- package/kits/docs/evolcore/config.md +22 -0
- package/kits/docs/evolcore/directory.md +46 -12
- package/kits/docs/evolcore/event-center.md +6 -6
- package/kits/docs/evolcore/group-collaboration.md +1 -1
- package/kits/docs/evolcore/menu-client.md +7 -5
- package/kits/docs/evolcore/menu-protocol.md +5 -3
- package/kits/docs/evolcore/msg.md +10 -3
- package/kits/docs/evolcore/provider.md +17 -5
- package/kits/docs/evolcore/services.md +145 -12
- package/kits/docs/evolcore/thread-chain.md +17 -9
- package/kits/docs/prompt-loading-architecture.md +4 -4
- package/kits/eck_message_manifest.json +46 -3
- package/kits/rules/04-relation.md +10 -2
- package/kits/rules/06-channel.md +2 -1
- package/kits/schemas/providers.schema.2.json +1 -0
- package/kits/skills/ec-group/SKILL.md +4 -0
- package/kits/skills/ec-skill/scripts/cli.mjs +1 -1
- package/kits/skills/ec-skill/scripts/skill.mjs +13 -2
- package/kits/skills/thread-ops/SKILL.md +8 -5
- package/kits/templates/message-fragments/group-batch-item.md +3 -0
- package/kits/templates/message-fragments/group-batch.md +1 -0
- package/kits/templates/message-fragments/item-group.md +4 -0
- package/kits/templates/message-fragments/item-private.md +4 -0
- package/kits/templates/message-fragments/thread-context.md +1 -1
- package/kits/templates/system-fragments/commands.md +5 -5
- package/kits/templates/system-fragments/managed-runtime.md +1 -1
- package/kits/templates/system-fragments/relation.md +11 -7
- package/package.json +3 -2
- package/scripts/agent-template/index.mjs +9 -4
- package/scripts/agent-template/inspect.mjs +16 -9
- package/scripts/agent-template/shared/plan.mjs +3 -33
- package/scripts/agent-template/shared/template-contract.mjs +186 -3
- package/scripts/agent-template/shared/template-package.mjs +119 -10
- package/scripts/agent-template/shared/template-runtime.mjs +49 -6
- package/scripts/agent-template/shared/template.mjs +5 -5
- package/scripts/agent-template/team-pack.mjs +245 -0
- package/scripts/agent-template/team-preview.mjs +111 -0
- package/scripts/aid-batch/identity-batch.mjs +143 -0
- package/dist/ability/versions.js +0 -32
- package/dist/aun/model-headers.js +0 -17
- package/dist/channels/builtin-plugins.js +0 -19
- package/dist/core/command/team-workspace-initializer.js +0 -2
- package/dist/core/command/team-workspace-job-store.js +0 -88
- package/dist/core/command/team-workspace-management-service.js +0 -2
- package/dist/core/contact-bind-registry.js +0 -27
- package/dist/event-center/ledger.js +0 -52
- package/dist/services/reply.js +0 -55
- package/kits/templates/message-fragments/item.md +0 -3
- package/scripts/agent-template/pack.mjs +0 -169
|
@@ -33,8 +33,59 @@ export function formatLocalTime(epochMs, timeZone) {
|
|
|
33
33
|
const offset = off.replace(/^GMT/, '') || '+00:00';
|
|
34
34
|
return `${g.year}-${g.month}-${g.day} ${hour}:${g.minute}:${g.second} ${offset}`;
|
|
35
35
|
}
|
|
36
|
+
/** "21:04:29"(批次逐行) */
|
|
37
|
+
function formatShortTime(epochMs, timeZone) {
|
|
38
|
+
const g = timeParts(epochMs, timeZone, { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false });
|
|
39
|
+
const hour = g.hour === '24' ? '00' : g.hour;
|
|
40
|
+
return `${hour}:${g.minute}:${g.second}`;
|
|
41
|
+
}
|
|
42
|
+
/** "2026-11-09 21:04"(群聊批次头) */
|
|
43
|
+
function formatBatchTime(epochMs, timeZone) {
|
|
44
|
+
const g = timeParts(epochMs, timeZone, { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false });
|
|
45
|
+
const hour = g.hour === '24' ? '00' : g.hour;
|
|
46
|
+
return `${g.year}-${g.month}-${g.day} ${hour}:${g.minute}`;
|
|
47
|
+
}
|
|
48
|
+
/** `名称(AID)[type/exttype]`;名称缺失/等于 AID 时只写 AID。 */
|
|
49
|
+
function identityLabel(name, aid, type, exttype) {
|
|
50
|
+
const id = String(aid ?? '').trim();
|
|
51
|
+
const n = String(name ?? '').trim();
|
|
52
|
+
const display = id && n && n !== id ? `${n}(${id})` : (id || n);
|
|
53
|
+
if (!display)
|
|
54
|
+
return '';
|
|
55
|
+
const t = String(type ?? '').trim() || 'unknown';
|
|
56
|
+
const e = String(exttype ?? '').trim();
|
|
57
|
+
return e ? `${display}[${t}/${e}]` : `${display}[${t}]`;
|
|
58
|
+
}
|
|
59
|
+
function selfLabelOf(sessionVars) {
|
|
60
|
+
return `self:${identityLabel(sessionVars.selfName, sessionVars.selfAid, sessionVars.selfType ?? 'agent', sessionVars.selfExttype)}`;
|
|
61
|
+
}
|
|
62
|
+
function groupTagOf(sessionVars) {
|
|
63
|
+
const groupAid = String(sessionVars.groupId ?? '').trim();
|
|
64
|
+
const groupName = String(sessionVars.groupName ?? '').trim();
|
|
65
|
+
return groupName && groupAid ? `${groupName}<${groupAid}>` : (groupAid || groupName);
|
|
66
|
+
}
|
|
67
|
+
function chatLabelOf(sessionVars) {
|
|
68
|
+
return `chat:${String(sessionVars.chatType ?? '')}/${String(sessionVars.chatMode ?? '')}`;
|
|
69
|
+
}
|
|
70
|
+
/** `ctx: scene=… · activity=… · location=地址(纬度,经度)`;无 sender_ctx 返回空串。 */
|
|
71
|
+
function formatSenderCtx(ctx) {
|
|
72
|
+
if (!ctx)
|
|
73
|
+
return '';
|
|
74
|
+
const parts = [];
|
|
75
|
+
if (ctx.scene)
|
|
76
|
+
parts.push(`scene=${ctx.scene}`);
|
|
77
|
+
if (ctx.activity)
|
|
78
|
+
parts.push(`activity=${ctx.activity}`);
|
|
79
|
+
const loc = ctx.location;
|
|
80
|
+
if (loc && Number.isFinite(loc.latitude_e6) && Number.isFinite(loc.longitude_e6)) {
|
|
81
|
+
const lat = (loc.latitude_e6 / 1e6).toFixed(6);
|
|
82
|
+
const lon = (loc.longitude_e6 / 1e6).toFixed(6);
|
|
83
|
+
parts.push(`location=${loc.address ? `${loc.address}(${lat},${lon})` : `${lat},${lon}`}`);
|
|
84
|
+
}
|
|
85
|
+
return parts.length > 0 ? `ctx: ${parts.join(' · ')}` : '';
|
|
86
|
+
}
|
|
36
87
|
// ── single item render ──
|
|
37
|
-
function renderOneItem(item, sessionVars, sessionCache, contentSentinel) {
|
|
88
|
+
function renderOneItem(item, sessionVars, sessionCache, contentSentinel, compact = false) {
|
|
38
89
|
const sections = loadManifest(MESSAGE_MANIFEST_FILE);
|
|
39
90
|
// 各 modeType 当前激活的 modeName:agent config.render(经 sessionVars.renderModes 透传)
|
|
40
91
|
// 覆盖 manifest 里标 isDefault 的缺省。详见 docs/observer-insert-design.md 第二部分。
|
|
@@ -106,9 +157,64 @@ function renderOneItem(item, sessionVars, sessionCache, contentSentinel) {
|
|
|
106
157
|
}]
|
|
107
158
|
: [];
|
|
108
159
|
const allOriginReplacements = [...originReplacements, ...fallbackOriginEntries];
|
|
160
|
+
// 信封标签在 JS 侧预计算:模板引擎无 else,分隔符拼装放在模板里会产生悬空 `·`。
|
|
161
|
+
const tz = sessionVars.timezone ? String(sessionVars.timezone) : undefined;
|
|
162
|
+
const selfAid = String(sessionVars.selfAid ?? '');
|
|
163
|
+
const selfName = String(sessionVars.selfName ?? '');
|
|
164
|
+
const selfType = String(sessionVars.selfType ?? 'agent');
|
|
165
|
+
const selfExttype = String(sessionVars.selfExttype ?? '');
|
|
166
|
+
const selfAddressed = item.selfAddressed === true;
|
|
167
|
+
const itemPeerId = String(item.peerId ?? sessionVars.peerId ?? '');
|
|
168
|
+
const itemPeerName = String(item.peerName ?? sessionVars.peerName ?? '');
|
|
169
|
+
const itemPeerType = String(item.peerType ?? sessionVars.peerType ?? '');
|
|
170
|
+
const itemPeerExttype = String(item.peerExttype ?? '');
|
|
171
|
+
const fromName = selfAddressed ? selfName : itemPeerName;
|
|
172
|
+
const fromAid = selfAddressed ? selfAid : itemPeerId;
|
|
173
|
+
const fromType = selfAddressed ? selfType : itemPeerType;
|
|
174
|
+
const fromExttype = selfAddressed ? selfExttype : itemPeerExttype;
|
|
175
|
+
const modeToken = selfAddressed ? '跨话题自派' : (item.originThreadId ? '跨话题委托' : '');
|
|
176
|
+
const modePart = modeToken ? ` · ${modeToken}` : '';
|
|
177
|
+
const topicPart = item.originThreadId
|
|
178
|
+
? ` · 话题:${item.originThreadId}${item.originPeer ? `(对端:${item.originPeer})` : ''}`
|
|
179
|
+
: '';
|
|
180
|
+
const groupRolePart = item.groupRole ? ` · 群角色:${item.groupRole}` : '';
|
|
181
|
+
const isMentioned = item.isMentioned === true
|
|
182
|
+
|| (item.mentionAids ?? []).some(aid => String(aid).toLowerCase() === selfAid.toLowerCase());
|
|
183
|
+
const mentionPart = isMentioned ? ' · @我' : '';
|
|
184
|
+
const timestamp = item.timestamp ?? Date.now();
|
|
185
|
+
// 时间基准是本机时间;发件人时区与本机不同时,追加对方当地时刻与时区名,
|
|
186
|
+
// 避免模型自己换算(时区名 + 当地时刻才可直接引用)。
|
|
187
|
+
const senderTz = String(item.senderCtx?.timezone ?? '').trim();
|
|
188
|
+
const tzDiffers = !!senderTz && senderTz !== String(tz ?? '');
|
|
189
|
+
const nowText = formatLocalTime(timestamp, tz)
|
|
190
|
+
+ (tzDiffers ? ` (发件人当地 ${formatLocalTime(timestamp, senderTz)} ${senderTz})` : '');
|
|
191
|
+
const shortNowText = formatShortTime(timestamp, tz)
|
|
192
|
+
+ (tzDiffers ? ` (发件人当地 ${formatShortTime(timestamp, senderTz)} ${senderTz})` : '');
|
|
193
|
+
const labels = {
|
|
194
|
+
now: nowText,
|
|
195
|
+
shortNow: shortNowText,
|
|
196
|
+
batchTime: formatBatchTime(timestamp, tz),
|
|
197
|
+
modePart,
|
|
198
|
+
topicPart,
|
|
199
|
+
groupRolePart,
|
|
200
|
+
mentionPart,
|
|
201
|
+
groupTag: groupTagOf(sessionVars),
|
|
202
|
+
fromLabel: `from:${identityLabel(fromName, fromAid, fromType, fromExttype)}`,
|
|
203
|
+
selfLabel: selfLabelOf(sessionVars),
|
|
204
|
+
speakerRelationLabel: `与发言人:${String(item.speakerRelation
|
|
205
|
+
?? (String(sessionVars.chatType ?? '') === 'group' ? 'visitor' : (item.peerRole ?? sessionVars.peerRole ?? 'visitor')))}`,
|
|
206
|
+
chatLabel: chatLabelOf(sessionVars),
|
|
207
|
+
midLabel: `mid:${item.messageId ?? '-'}`,
|
|
208
|
+
senderCtxLine: formatSenderCtx(item.senderCtx),
|
|
209
|
+
batchItem: compact || undefined,
|
|
210
|
+
// 跨话题委托提醒:原消息与来源会话,供回查定位。
|
|
211
|
+
threadContextMessageId: item.threadContext?.messageId,
|
|
212
|
+
threadContextOriginSessionId: item.threadContext?.originSessionId,
|
|
213
|
+
};
|
|
109
214
|
// item-level vars: session vars overlaid with this message's own sender/timestamp.
|
|
110
215
|
const itemVars = {
|
|
111
216
|
...sessionVars,
|
|
217
|
+
...labels,
|
|
112
218
|
peerId: item.peerId ?? sessionVars.peerId,
|
|
113
219
|
peerName: item.peerName ?? sessionVars.peerName,
|
|
114
220
|
peerType: item.peerType ?? sessionVars.peerType,
|
|
@@ -124,7 +230,6 @@ function renderOneItem(item, sessionVars, sessionCache, contentSentinel) {
|
|
|
124
230
|
encrypted: item.encrypted,
|
|
125
231
|
// 模板引擎不支持数组循环:被 @ 的 AID 预先 join 成串,空则 undefined 使 {{?mentionAids}} 落空。
|
|
126
232
|
mentionAids: (item.mentionAids && item.mentionAids.length > 0) ? item.mentionAids.join(',') : undefined,
|
|
127
|
-
now: formatLocalTime(item.timestamp ?? Date.now(), sessionVars.timezone ? String(sessionVars.timezone) : undefined),
|
|
128
233
|
// 渲染模式命中变量(manifest section 的 when 用它选中唯一模式)
|
|
129
234
|
renderMode_private: activeMode('private'),
|
|
130
235
|
renderMode_group: activeMode('group'),
|
|
@@ -244,6 +349,66 @@ function renderOneItem(item, sessionVars, sessionCache, contentSentinel) {
|
|
|
244
349
|
// if the manifest produced nothing, fall back to raw text -- never drop a message.
|
|
245
350
|
return out.length > 0 ? out.join('\n') : item.content;
|
|
246
351
|
}
|
|
352
|
+
/** 群聊分层:owner / admin / other;非普通消息各自独立成段。 */
|
|
353
|
+
function groupTierOf(item) {
|
|
354
|
+
if (item.kind && item.kind !== 'restart-resume')
|
|
355
|
+
return 'special';
|
|
356
|
+
const role = String(item.groupRole ?? '').trim();
|
|
357
|
+
if (role === 'owner')
|
|
358
|
+
return 'owner';
|
|
359
|
+
if (role === 'admin')
|
|
360
|
+
return 'admin';
|
|
361
|
+
return 'other';
|
|
362
|
+
}
|
|
363
|
+
/** 群聊批次头:`[时间 · 群聊] 群:… · self:… · chat:…` */
|
|
364
|
+
function renderGroupHeader(sessionVars, first, sessionCache) {
|
|
365
|
+
const tz = sessionVars.timezone ? String(sessionVars.timezone) : undefined;
|
|
366
|
+
const vars = {
|
|
367
|
+
...sessionVars,
|
|
368
|
+
batchTime: formatBatchTime(first.timestamp ?? Date.now(), tz),
|
|
369
|
+
groupTag: groupTagOf(sessionVars),
|
|
370
|
+
selfLabel: selfLabelOf(sessionVars),
|
|
371
|
+
chatLabel: chatLabelOf(sessionVars),
|
|
372
|
+
};
|
|
373
|
+
const section = {
|
|
374
|
+
id: 'msg-group-batch',
|
|
375
|
+
type: 'file',
|
|
376
|
+
file: '$KITS_MESSAGE_FRAGMENTS/group-batch.md',
|
|
377
|
+
needsInjection: true,
|
|
378
|
+
};
|
|
379
|
+
const files = loadSectionFiles(section, vars, sessionCache);
|
|
380
|
+
if (files.length === 0)
|
|
381
|
+
return '';
|
|
382
|
+
return renderTemplate(files[0][1], vars, /* stripBlankLines */ false).replace(/\s+$/, '');
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* 群聊渲染:按时间顺序切分为同层连续段(owner / admin / other),
|
|
386
|
+
* 段内 ≥2 条用批次头 + 逐行,单条用完整信封;非普通消息各自独立成段。
|
|
387
|
+
*/
|
|
388
|
+
function renderGroupBody(items, sessionVars, sessionCache, contentSentinel) {
|
|
389
|
+
const segments = [];
|
|
390
|
+
for (const item of items) {
|
|
391
|
+
const tier = groupTierOf(item);
|
|
392
|
+
const last = segments[segments.length - 1];
|
|
393
|
+
if (tier !== 'special' && last && last.tier === tier)
|
|
394
|
+
last.items.push(item);
|
|
395
|
+
else
|
|
396
|
+
segments.push({ tier, items: [item] });
|
|
397
|
+
}
|
|
398
|
+
const out = [];
|
|
399
|
+
for (const segment of segments) {
|
|
400
|
+
const compact = segment.tier !== 'special' && segment.items.length >= 2;
|
|
401
|
+
if (compact) {
|
|
402
|
+
const header = renderGroupHeader(sessionVars, segment.items[0], sessionCache);
|
|
403
|
+
const lines = segment.items.map(item => renderOneItem(item, sessionVars, sessionCache, contentSentinel, true));
|
|
404
|
+
out.push([header, ...lines].filter(Boolean).join('\n'));
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
out.push(...segment.items.map(item => renderOneItem(item, sessionVars, sessionCache, contentSentinel, false)));
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
return out.join('\n\n');
|
|
411
|
+
}
|
|
247
412
|
/**
|
|
248
413
|
* Render each sub-message then assemble the final message body.
|
|
249
414
|
* Also collects all images across items in order, preserving per-item attribution.
|
|
@@ -262,39 +427,13 @@ export function renderMessageBody(items, sessionVars, sessionId) {
|
|
|
262
427
|
if (item.images && item.images.length > 0)
|
|
263
428
|
allImages.push(...item.images);
|
|
264
429
|
}
|
|
265
|
-
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
// {{@loop}} 处字面量填入逐条结果(已渲染完成,不再过模板 → 哨兵天然生效)。
|
|
270
|
-
const body = wrapBatch(renderedParts, sessionVars, sessionCache) ?? renderedParts.join('\n\n');
|
|
430
|
+
const isGroup = String(sessionVars.chatType ?? '') === 'group';
|
|
431
|
+
const body = isGroup
|
|
432
|
+
? renderGroupBody(items, sessionVars, sessionCache, contentSentinel)
|
|
433
|
+
: items.map(item => renderOneItem(item, sessionVars, sessionCache, contentSentinel, false)).join('\n\n');
|
|
271
434
|
writeMessageDebug(sessionId, items, body);
|
|
272
435
|
return { body, images: allImages };
|
|
273
436
|
}
|
|
274
|
-
/**
|
|
275
|
-
* 若 message manifest 含 loop 段,用其 wrapper 包裹逐条渲染结果。返回包裹后 body,
|
|
276
|
-
* 无 loop 段则返回 null(调用方回退到 join)。
|
|
277
|
-
* 逐条结果 renderedParts 已是最终文本,作为字面量填入 wrapper 的 {{@loop}},不二次解析。
|
|
278
|
-
*/
|
|
279
|
-
function wrapBatch(renderedParts, sessionVars, sessionCache) {
|
|
280
|
-
const sections = loadManifest(MESSAGE_MANIFEST_FILE);
|
|
281
|
-
const loopSection = sections.find(s => s.loop && s.enabled !== false && evaluateWhen(s.when, sessionVars));
|
|
282
|
-
if (!loopSection || !loopSection.loop || !loopSection.file)
|
|
283
|
-
return null;
|
|
284
|
-
const wrapperFiles = loadSectionFiles(loopSection, sessionVars, sessionCache);
|
|
285
|
-
if (wrapperFiles.length === 0)
|
|
286
|
-
return null;
|
|
287
|
-
const wrapperTpl = wrapperFiles[0][1];
|
|
288
|
-
const sep = loopSection.loop.separator ?? '\n\n';
|
|
289
|
-
const loopResult = renderedParts.join(sep);
|
|
290
|
-
// wrapper 渲染批次 vars,{{@loop}} 用哨兵占位后字面量替换回 loopResult(避免逐条结果被二次解析)。
|
|
291
|
-
const LOOP_SENTINEL = '\x00ECLOOP\x00';
|
|
292
|
-
const wrapperWithSentinel = wrapperTpl.includes('{{@loop}}')
|
|
293
|
-
? wrapperTpl.split('{{@loop}}').join(LOOP_SENTINEL)
|
|
294
|
-
: wrapperTpl + '\n' + LOOP_SENTINEL;
|
|
295
|
-
const rendered = renderTemplate(wrapperWithSentinel, sessionVars, /* stripBlankLines */ false);
|
|
296
|
-
return rendered.split(LOOP_SENTINEL).join(loopResult);
|
|
297
|
-
}
|
|
298
437
|
// ── Debug ──
|
|
299
438
|
function writeMessageDebug(sessionId, items, body) {
|
|
300
439
|
if (!isEckSnapshotsEnabled())
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
|
-
import
|
|
2
|
+
import { assertProjectPathConfig } from '../utils/project-path.js';
|
|
3
3
|
import { ConfigTarget, mutateConfig, read, validateConfig, } from '../config/config-manager.js';
|
|
4
4
|
import { getLogStreamStates, LOG_LEVELS } from '../utils/logger.js';
|
|
5
5
|
const BASEAGENTS = ['claude', 'codex', 'gemini', 'ecagent'];
|
|
@@ -499,8 +499,12 @@ function validateDefaultsValue(fieldPath, value) {
|
|
|
499
499
|
}
|
|
500
500
|
if (fieldPath === 'projects.defaultPath') {
|
|
501
501
|
const configuredPath = assertString(value, fieldPath, { max: 4096 }).trim();
|
|
502
|
-
|
|
503
|
-
|
|
502
|
+
try {
|
|
503
|
+
assertProjectPathConfig(configuredPath);
|
|
504
|
+
}
|
|
505
|
+
catch (error) {
|
|
506
|
+
throw makeError(error.message, 'INVALID_SETTINGS_VALUE');
|
|
507
|
+
}
|
|
504
508
|
return;
|
|
505
509
|
}
|
|
506
510
|
if (fieldPath === 'responseMode') {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readProvidersFile, resolveProviderService } from '../config/providers.js';
|
|
1
|
+
import { isProviderModelPattern, providerModelLiteralId, providerModelEnabled, readProvidersFile, resolveProviderService } from '../config/providers.js';
|
|
2
2
|
import { resolveProviderId } from '../config/providers-config.js';
|
|
3
3
|
import { createProvider, importOrMergeBaseagentProvider, parseProviderImport, previewProviderImport, previewProviderValue, readProviderForExport, readProvidersSnapshot, resolveProviderDraftService, saveProviderChanges, updateProvider, } from '../config/providers-management.js';
|
|
4
4
|
import { listBaseagentImportSources, providerFromBaseagent } from '../config/providers-import.js';
|
|
@@ -9,21 +9,28 @@ function isRecord(value) {
|
|
|
9
9
|
function response(status, body) {
|
|
10
10
|
return { status, body };
|
|
11
11
|
}
|
|
12
|
-
function managementCatalog(snapshot, overrides) {
|
|
13
|
-
const
|
|
12
|
+
function managementCatalog(snapshot, overrides, policy) {
|
|
13
|
+
const exact = policy ? Object.fromEntries(Object.entries(overrides).filter(([id]) => !isProviderModelPattern(id))
|
|
14
|
+
.map(([id, entry]) => [providerModelLiteralId(id), entry])) : overrides;
|
|
15
|
+
const enabled = (id) => providerModelEnabled(id, overrides, policy);
|
|
16
|
+
const models = snapshot.models.map((model) => ({ ...model,
|
|
17
|
+
enabled: enabled(policy ? model.aliasFor ?? model.id : model.id), available: true }));
|
|
14
18
|
const listed = new Set(snapshot.models.map((model) => model.id));
|
|
15
|
-
const manualModels = Object.entries(
|
|
19
|
+
const manualModels = Object.entries(exact).filter(([id, override]) => (policy === 'manual' || (!policy && override.manual === true)) && !listed.has(id))
|
|
16
20
|
.map(([id, override]) => ({
|
|
17
21
|
id,
|
|
18
22
|
...(typeof override.name === 'string' && override.name ? { displayName: override.name } : {}),
|
|
19
23
|
...(typeof override.imageIn === 'boolean' ? { imageIn: override.imageIn } : {}),
|
|
20
24
|
manual: true,
|
|
21
|
-
enabled:
|
|
25
|
+
enabled: enabled(id),
|
|
22
26
|
available: true,
|
|
23
27
|
}));
|
|
24
|
-
const unseenModels = Object.entries(
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
const unseenModels = Object.entries(exact).filter(([id, override]) => !listed.has(id)
|
|
29
|
+
&& policy !== 'manual' && (policy || override.manual !== true) && !(policy && isProviderModelPattern(id)))
|
|
30
|
+
.map(([id, override]) => ({ id, ...override, enabled: enabled(id), available: false }));
|
|
31
|
+
const rules = policy ? Object.entries(overrides).filter(([id]) => isProviderModelPattern(id))
|
|
32
|
+
.map(([id, override]) => ({ id, enabled: override.enabled ?? policy !== 'denylist' })) : [];
|
|
33
|
+
return { ...snapshot, modelPolicy: policy, models: [...models, ...manualModels], unseenModels, rules };
|
|
27
34
|
}
|
|
28
35
|
async function resolveImports(value) {
|
|
29
36
|
if (value === undefined)
|
|
@@ -137,7 +144,7 @@ export async function handleProvidersService(input) {
|
|
|
137
144
|
return response(502, { success: false, code: 'PROVIDER_MODEL_TEST_FAILED',
|
|
138
145
|
error: `${diagnostic?.message || 'Model list test failed'}${diagnostic?.status ? ` (HTTP ${diagnostic.status})` : ''}` });
|
|
139
146
|
}
|
|
140
|
-
return response(200, { success: true, data: managementCatalog(snapshot, provider.modelOverrides) });
|
|
147
|
+
return response(200, { success: true, data: managementCatalog(snapshot, provider.modelOverrides, provider.modelPolicy) });
|
|
141
148
|
}
|
|
142
149
|
if (input.method === 'GET' && parts[1] === 'secret' && parts.length === 2) {
|
|
143
150
|
const registry = readProvidersFile();
|
|
@@ -155,7 +162,7 @@ export async function handleProvidersService(input) {
|
|
|
155
162
|
}
|
|
156
163
|
const provider = resolveProviderService(providerId, serviceType);
|
|
157
164
|
const snapshot = await getProviderCatalog(providerId, serviceType, query.refresh === 'true', true);
|
|
158
|
-
return response(200, { success: true, data: managementCatalog(snapshot, provider.modelOverrides) });
|
|
165
|
+
return response(200, { success: true, data: managementCatalog(snapshot, provider.modelOverrides, provider.modelPolicy) });
|
|
159
166
|
}
|
|
160
167
|
if ((input.method === 'PUT' || input.method === 'DELETE') && parts.length === 1) {
|
|
161
168
|
const body = requestBody(input.body);
|
|
@@ -3,7 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import { createServer } from 'node:net';
|
|
4
4
|
import { execFileSync } from 'node:child_process';
|
|
5
5
|
import { parseEcwebInstanceRecord, matchesEcwebInstanceHealth } from '../../contracts/ecweb-instance.js';
|
|
6
|
-
import {
|
|
6
|
+
import { getProcessSnapshotAsync, getProcessStartTime, getProcessStartTimeAsync, startTimeMatches } from '../../utils/process-introspect.js';
|
|
7
7
|
import * as platform from '../../utils/cross-platform.js';
|
|
8
8
|
import { resolveGlobalPkg } from '../../utils/npm-ops.js';
|
|
9
9
|
import { resolveEcwebLaunchCommand } from './launch.js';
|
|
@@ -11,7 +11,7 @@ import { WEB_PACKAGE_NAME } from '../../product.js';
|
|
|
11
11
|
async function sameProcess(identity) {
|
|
12
12
|
if (!platform.isProcessRunning(identity.pid))
|
|
13
13
|
return false;
|
|
14
|
-
const actual = await getProcessStartTimeAsync(identity.pid);
|
|
14
|
+
const actual = await getProcessStartTimeAsync(identity.pid, { fresh: true });
|
|
15
15
|
if (!platform.isProcessRunning(identity.pid))
|
|
16
16
|
return false;
|
|
17
17
|
if (identity.startedAt === null || actual === null) {
|
|
@@ -23,20 +23,58 @@ async function sameProcess(identity) {
|
|
|
23
23
|
* Prefer a cooperative IPC request for supervised children on every platform.
|
|
24
24
|
* Windows taskkill without /F cannot invoke Node's SIGTERM handler; only
|
|
25
25
|
* POSIX can use SIGTERM when no parent-child IPC channel is available.
|
|
26
|
-
* The
|
|
27
|
-
*
|
|
26
|
+
* The captured ChildProcess IPC channel cannot address a reused PID. Its
|
|
27
|
+
* exit event confirms termination without a delayed OS liveness poll.
|
|
28
28
|
*/
|
|
29
29
|
const IPC_GRACEFUL_STOP_MS = 3_000;
|
|
30
30
|
const POSIX_GRACEFUL_STOP_MS = 1_000;
|
|
31
31
|
const FORCED_STOP_MS = 2_000;
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
function requestChildShutdown(child, timeoutMs) {
|
|
33
|
+
return new Promise(resolve => {
|
|
34
|
+
if (child.exitCode != null || child.signalCode != null) {
|
|
35
|
+
resolve({ signalSent: false, exited: true });
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
let signalSent = false;
|
|
39
|
+
let settled = false;
|
|
40
|
+
const finish = (exited) => {
|
|
41
|
+
if (settled)
|
|
42
|
+
return;
|
|
43
|
+
settled = true;
|
|
44
|
+
clearTimeout(timer);
|
|
45
|
+
child.removeListener('exit', onExit);
|
|
46
|
+
resolve({ signalSent, exited });
|
|
47
|
+
};
|
|
48
|
+
const onExit = () => finish(true);
|
|
49
|
+
const timer = setTimeout(() => finish(false), timeoutMs);
|
|
50
|
+
// Subscribe before sending: the child may exit immediately on receipt.
|
|
51
|
+
child.once('exit', onExit);
|
|
52
|
+
try {
|
|
53
|
+
if (!child.connected) {
|
|
54
|
+
finish(false);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
signalSent = true;
|
|
58
|
+
// A false return means IPC backpressure, not a failed delivery.
|
|
59
|
+
child.send({ type: 'ecweb.shutdown' }, error => { if (error)
|
|
60
|
+
finish(false); });
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
signalSent = false;
|
|
64
|
+
finish(false);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
export async function stopEcwebProcess(identity, timeoutMs = FORCED_STOP_MS, onTiming, child) {
|
|
69
|
+
const supervisedChild = child?.pid === identity.pid ? child : undefined;
|
|
70
|
+
const waitForExit = async (force, budgetMs, target) => {
|
|
34
71
|
const startMs = Date.now();
|
|
35
|
-
let detail = `pid=${identity.pid}; timeoutMs=${budgetMs}${
|
|
72
|
+
let detail = `pid=${identity.pid}; timeoutMs=${budgetMs}${target ? '; transport=ipc; exitObserver=child' : ''}`;
|
|
36
73
|
try {
|
|
37
|
-
const signalSent =
|
|
38
|
-
|
|
39
|
-
|
|
74
|
+
const { signalSent, exited } = target ? await requestChildShutdown(target, budgetMs) : {
|
|
75
|
+
signalSent: platform.killProcessOnly(identity.pid, force),
|
|
76
|
+
exited: await platform.waitForProcessExit(identity.pid, budgetMs),
|
|
77
|
+
};
|
|
40
78
|
detail += `; signalSent=${signalSent}; exited=${exited}`;
|
|
41
79
|
return exited;
|
|
42
80
|
}
|
|
@@ -51,10 +89,10 @@ export async function stopEcwebProcess(identity, timeoutMs = FORCED_STOP_MS, onT
|
|
|
51
89
|
catch { }
|
|
52
90
|
}
|
|
53
91
|
};
|
|
54
|
-
if (
|
|
92
|
+
if (supervisedChild) {
|
|
55
93
|
// Ask our actual child first. Fresh OS identity queries are only needed
|
|
56
94
|
// before falling back to PID-addressed signals, including on IPC failure.
|
|
57
|
-
if (await waitForExit(false, IPC_GRACEFUL_STOP_MS,
|
|
95
|
+
if (await waitForExit(false, IPC_GRACEFUL_STOP_MS, supervisedChild))
|
|
58
96
|
return;
|
|
59
97
|
if (!await sameProcess(identity))
|
|
60
98
|
return;
|
|
@@ -73,8 +111,6 @@ export async function stopEcwebProcess(identity, timeoutMs = FORCED_STOP_MS, onT
|
|
|
73
111
|
}
|
|
74
112
|
function commandLineFor(pid) {
|
|
75
113
|
try {
|
|
76
|
-
if (platform.isWindows)
|
|
77
|
-
return getProcessSnapshot({ fresh: true }).commandLines.get(pid) ?? null;
|
|
78
114
|
return execFileSync('ps', ['-ww', '-p', String(pid), '-o', 'command='], {
|
|
79
115
|
encoding: 'utf8', timeout: 3_000, stdio: ['ignore', 'pipe', 'ignore'],
|
|
80
116
|
}).trim() || null;
|
|
@@ -157,13 +193,24 @@ export async function stopEcwebForRestart(paths, port, log) {
|
|
|
157
193
|
const launch = resolveEcwebLaunchCommand([], { installedPkg: installed });
|
|
158
194
|
const entries = [launch?.entry, installed ? path.join(path.dirname(installed.path), 'dist', 'index.js') : undefined]
|
|
159
195
|
.filter((entry) => !!entry);
|
|
196
|
+
let windowsListeners;
|
|
160
197
|
for (const targetPort of ports) {
|
|
161
198
|
for (const pid of platform.findProcessByPort(targetPort)) {
|
|
162
199
|
if (identities.has(pid))
|
|
163
200
|
continue;
|
|
164
|
-
|
|
165
|
-
|
|
201
|
+
// Observe creation time and command line together, rather than starting
|
|
202
|
+
// per-PID PowerShell/WMIC and then querying the whole table again. This
|
|
203
|
+
// snapshot only identifies candidates; stopEcwebProcess rechecks identity.
|
|
204
|
+
const snapshot = platform.isWindows
|
|
205
|
+
? windowsListeners ??= await getProcessSnapshotAsync({ fresh: true }) : undefined;
|
|
206
|
+
const startedAt = snapshot ? snapshot.startedAt.get(pid) ?? null : getProcessStartTime(pid);
|
|
207
|
+
const commandLine = snapshot ? snapshot.commandLines.get(pid) ?? null : commandLineFor(pid);
|
|
166
208
|
if (startedAt === null || !commandLine || !matchesEcwebCommand(commandLine, paths.root, entries)) {
|
|
209
|
+
// A listener can exit between netstat/lsof and the identity query.
|
|
210
|
+
// Recheck ownership instead of rejecting a stale PID. The final scan
|
|
211
|
+
// and exclusive bind must still prove the port was actually released.
|
|
212
|
+
if (!(await platform.findProcessByPortAsync(targetPort)).includes(pid))
|
|
213
|
+
continue;
|
|
167
214
|
throw new Error(`ECWeb 端口 ${targetPort} 被身份未确认的进程占用 (PID: ${pid});未终止该进程`);
|
|
168
215
|
}
|
|
169
216
|
let health;
|
|
@@ -174,6 +221,8 @@ export async function stopEcwebForRestart(paths, port, log) {
|
|
|
174
221
|
}
|
|
175
222
|
catch { }
|
|
176
223
|
if (!matchesEcwebInstanceHealth(health, { pid, port: targetPort })) {
|
|
224
|
+
if (!(await platform.findProcessByPortAsync(targetPort)).includes(pid))
|
|
225
|
+
continue;
|
|
177
226
|
throw new Error(`ECWeb 端口 ${targetPort} 的服务身份无法确认 (PID: ${pid});未终止该进程`);
|
|
178
227
|
}
|
|
179
228
|
identities.set(pid, { pid, startedAt });
|