evolcore 0.0.43-test.8 → 0.0.46
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 +75 -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 +13 -5
- package/dist/agents/codex/app-server-client.js +2 -4
- 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/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 +656 -112
- 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 +15 -17
- package/dist/cli/daemon-lifecycle-client.js +40 -18
- 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.js +50 -20
- 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 +33 -20
- package/dist/cli/services-command.js +28 -5
- package/dist/config/config-field-policy.js +24 -0
- package/dist/config/config-manager.js +20 -2
- package/dist/config/peer-book-store.js +152 -120
- package/dist/config/peer-role-resolver.js +24 -4
- package/dist/config/provider-identity-migration.js +1 -1
- 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-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 +85 -38
- package/dist/core/auth/agent-delegation.js +5 -0
- package/dist/core/auth/operation-authorizer.js +1 -1
- 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 +35 -8
- package/dist/core/command/menu-protocol.js +8 -16
- package/dist/core/command/skill-slash.js +6 -2
- 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-control.js +3 -4
- package/dist/core/daemon-lifecycle.js +146 -110
- package/dist/core/evolagent-registry.js +42 -0
- 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/inference/text-inference.js +12 -2
- package/dist/core/invoke/invoke-service.js +24 -3
- package/dist/core/ipc-registration.js +3 -0
- 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/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/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/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 +1 -1
- package/dist/ecweb/runtime/supervisor.js +77 -35
- 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 +96 -42
- package/dist/ipc.js +33 -7
- 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 +14 -4
- package/dist/trigger/script-sandbox.js +39 -2
- package/dist/utils/cross-platform.js +35 -11
- package/dist/utils/error-utils.js +13 -1
- package/dist/utils/instance-registry.js +33 -35
- package/dist/utils/process-introspect.js +35 -20
- package/dist/utils/project-path.js +47 -3
- 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/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 +7 -3
- 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
|
@@ -45,6 +45,8 @@ export function searchDirectory(snapshot, ownerAid, remarks, options) {
|
|
|
45
45
|
continue;
|
|
46
46
|
if (scope === 'pa-team' && !isInPaTeam(entry, snapshot.openPaContext ?? []))
|
|
47
47
|
continue;
|
|
48
|
+
if (scope === 'my-agent-team' && !(options.teamAids ?? []).includes(entry.aid))
|
|
49
|
+
continue;
|
|
48
50
|
if (typeFilter && (entry.type ?? '').toLowerCase() !== typeFilter)
|
|
49
51
|
continue;
|
|
50
52
|
if (ownerFilter) {
|
|
@@ -163,6 +165,11 @@ export function filterDirectory(snapshot, ownerAid, remarks, options = {}) {
|
|
|
163
165
|
const scope = options.scope ?? 'all';
|
|
164
166
|
const typeFilter = normalizeDirectoryText(options.type ?? '');
|
|
165
167
|
const ownerFilter = normalizeDirectoryText(options.ownerAid ?? '');
|
|
168
|
+
if (scope === 'my-agent-team') {
|
|
169
|
+
return filterMyAgentTeam(snapshot, options.teamAids ?? [], {
|
|
170
|
+
groups, typeFilter, ownerFilter, remarks,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
166
173
|
return snapshot.entries
|
|
167
174
|
.filter(entry => {
|
|
168
175
|
const internal = isInternalEntry(entry, ownerRef);
|
|
@@ -188,6 +195,46 @@ export function filterDirectory(snapshot, ownerAid, remarks, options = {}) {
|
|
|
188
195
|
|| normalizeDirectoryText(a.name).localeCompare(normalizeDirectoryText(b.name))
|
|
189
196
|
|| a.aid.localeCompare(b.aid));
|
|
190
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* `--scope my-agent-team`:以 `config.team` 为基准,左连名录条目。
|
|
200
|
+
*
|
|
201
|
+
* 不能复用上面的 `entries.filter(...)`:那份名单里的 AID 可能根本不在名录中
|
|
202
|
+
* (成员被移出联系人、名录尚未同步、名单残留),而 `filter` 只会漏掉它们。
|
|
203
|
+
* 漏掉恰恰是这个 scope 最该回答的问题——"我配了他,为什么用不了"。
|
|
204
|
+
* 所以名录里找不到的成员补一条只有 AID 的占位条目,`ownerAid` 天然为空,
|
|
205
|
+
* 调用方据此判它不可用。
|
|
206
|
+
*
|
|
207
|
+
* 顺序照名单本身,不做内部优先排序:这里回答的是"我的团队有谁",
|
|
208
|
+
* 名单顺序就是 Owner 看到的顺序。
|
|
209
|
+
*/
|
|
210
|
+
function filterMyAgentTeam(snapshot, teamAids, filters) {
|
|
211
|
+
const remarks = filters.remarks;
|
|
212
|
+
const byAid = new Map(snapshot.entries.map(entry => [entry.aid, entry]));
|
|
213
|
+
const seen = new Set();
|
|
214
|
+
const out = [];
|
|
215
|
+
for (const raw of teamAids) {
|
|
216
|
+
const aid = raw.trim();
|
|
217
|
+
if (!aid || seen.has(aid))
|
|
218
|
+
continue;
|
|
219
|
+
seen.add(aid);
|
|
220
|
+
const entry = byAid.get(aid) ?? { aid, name: aid };
|
|
221
|
+
if (filters.typeFilter && normalizeDirectoryText(entry.type ?? '') !== filters.typeFilter)
|
|
222
|
+
continue;
|
|
223
|
+
const entryOwner = normalizeDirectoryText(entry.ownerAid ?? '');
|
|
224
|
+
if (filters.ownerFilter) {
|
|
225
|
+
if (filters.ownerFilter === 'unbound' ? entryOwner !== '' : entryOwner !== filters.ownerFilter)
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (filters.groups.length > 0) {
|
|
229
|
+
const remark = remarks?.get(aid);
|
|
230
|
+
const hit = filters.groups.every(group => group.some(keyword => scoreToken(keyword, entry, remark, remark?.body).score > 0));
|
|
231
|
+
if (!hit)
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
out.push(entry);
|
|
235
|
+
}
|
|
236
|
+
return out;
|
|
237
|
+
}
|
|
191
238
|
/**
|
|
192
239
|
* 单个条目的完整记录,用于 `show`。描述与备注不截断。
|
|
193
240
|
*
|
|
@@ -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);
|
|
@@ -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) {
|
|
@@ -7,7 +7,7 @@ import { RUNTIME_HOME_ENV, WEB_PACKAGE_NAME } from '../../product.js';
|
|
|
7
7
|
import { resolveGlobalPkgAsync } from '../../utils/npm-ops.js';
|
|
8
8
|
import { ecwebVersionRequirementError, resolveEcwebLaunchCommand } from './launch.js';
|
|
9
9
|
import * as platform from '../../utils/cross-platform.js';
|
|
10
|
-
import { getProcessStartTimeAsync } from '../../utils/process-introspect.js';
|
|
10
|
+
import { getProcessStartTimeAsync, startTimeMatches } from '../../utils/process-introspect.js';
|
|
11
11
|
import { matchesEcwebInstanceHealth, parseEcwebInstanceRecord } from '../../contracts/ecweb-instance.js';
|
|
12
12
|
import { sanitizeMenuLogValue } from '../../core/command/menu-protocol.js';
|
|
13
13
|
import { stopEcwebProcess } from './lifecycle.js';
|
|
@@ -107,8 +107,10 @@ async function probe(record, timeoutMs) {
|
|
|
107
107
|
const response = await fetch(`http://127.0.0.1:${record.port}/api/health`, {
|
|
108
108
|
signal,
|
|
109
109
|
});
|
|
110
|
-
if (!response.ok)
|
|
110
|
+
if (!response.ok) {
|
|
111
|
+
await response.body?.cancel().catch(() => { });
|
|
111
112
|
return { healthy: false, reason: `HTTP ${response.status}` };
|
|
113
|
+
}
|
|
112
114
|
return matchesEcwebInstanceHealth(await response.json(), record)
|
|
113
115
|
? { healthy: true }
|
|
114
116
|
: { healthy: false, reason: '健康响应或实例身份不匹配' };
|
|
@@ -170,25 +172,41 @@ export function createEcwebSupervisor(options) {
|
|
|
170
172
|
}
|
|
171
173
|
};
|
|
172
174
|
const setActiveFromEntry = async (entry, owned) => {
|
|
175
|
+
// Recheck after the HTTP response and asynchronous identity lookup. Child
|
|
176
|
+
// exit events can invalidate even a liveness query that returned true.
|
|
177
|
+
const actual = await getProcessStartTimeAsync(entry.record.pid);
|
|
178
|
+
const running = await isAlive(entry.record);
|
|
179
|
+
if (!running || (entry.observedChild && child !== entry.observedChild)) {
|
|
180
|
+
lastHealthFailure = '实例进程在健康检查期间退出';
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
if (actual !== null && entry.observedStartedAt != null && !startTimeMatches(entry.observedStartedAt, actual)) {
|
|
184
|
+
lastHealthFailure = '实例 PID 在健康检查期间被复用';
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
if (!stopping && entry.record.port !== desiredPort)
|
|
188
|
+
return false;
|
|
173
189
|
active = {
|
|
174
190
|
pid: entry.record.pid,
|
|
175
191
|
port: entry.record.port,
|
|
176
192
|
// Capture the current PID start time rather than trusting the record.
|
|
177
193
|
// Older ECWeb builds could write a clock-skewed `startedAt` value.
|
|
178
|
-
startedAt:
|
|
179
|
-
?? (typeof entry.record.startedAt === 'number' ? entry.record.startedAt : null),
|
|
194
|
+
startedAt: actual ?? (typeof entry.record.startedAt === 'number' ? entry.record.startedAt : null),
|
|
180
195
|
owned,
|
|
181
196
|
};
|
|
197
|
+
return true;
|
|
182
198
|
};
|
|
183
199
|
const findHealthyInstance = async () => {
|
|
184
200
|
lastHealthFailure = '未发现有效的 ECWeb 实例注册';
|
|
185
201
|
for (const entry of readEntries()) {
|
|
202
|
+
entry.observedChild = child?.pid === entry.record.pid ? child : undefined;
|
|
186
203
|
if (!await isAlive(entry.record)) {
|
|
187
204
|
lastHealthFailure = '实例进程不存在';
|
|
188
205
|
removeEntry(entry);
|
|
189
206
|
continue;
|
|
190
207
|
}
|
|
191
208
|
const actual = await getProcessStartTimeAsync(entry.record.pid);
|
|
209
|
+
entry.observedStartedAt = actual;
|
|
192
210
|
if (actual !== null && entry.record.startedAt !== undefined
|
|
193
211
|
&& (entry.record.schemaVersion === 1 ? Math.abs(actual - entry.record.startedAt) >= 2000 : actual - entry.record.startedAt > 2000)) {
|
|
194
212
|
lastHealthFailure = '实例 PID 启动时间不匹配';
|
|
@@ -247,31 +265,44 @@ export function createEcwebSupervisor(options) {
|
|
|
247
265
|
const killActive = async (onTiming) => {
|
|
248
266
|
intentionalStop = true;
|
|
249
267
|
const current = active;
|
|
268
|
+
const retiringChild = child && (!current || child.pid === current.pid) ? child : null;
|
|
250
269
|
// Keep stop intent with the child: its exit event may arrive after a
|
|
251
270
|
// replacement has reset the supervisor's intentionalStop flag.
|
|
252
|
-
if (
|
|
253
|
-
expectedChildExits.add(
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
271
|
+
if (retiringChild)
|
|
272
|
+
expectedChildExits.add(retiringChild);
|
|
273
|
+
try {
|
|
274
|
+
if (!current) {
|
|
275
|
+
// During the short window between spawn() and ECWeb writing its
|
|
276
|
+
// instance record there is no `active` entry yet, but the daemon still
|
|
277
|
+
// owns the child and must not leave it behind on shutdown.
|
|
278
|
+
const pendingPid = child?.pid;
|
|
279
|
+
if (pendingPid && (await platform.isProcessRunningAsync(pendingPid))) {
|
|
280
|
+
await stopTrackedProcess({ pid: pendingPid, startedAt: childIdentityStartedAt }, onTiming);
|
|
281
|
+
}
|
|
282
|
+
child = null;
|
|
283
|
+
childIdentityStartedAt = null;
|
|
284
|
+
healthy = false;
|
|
285
|
+
checkedAt = undefined;
|
|
286
|
+
return;
|
|
261
287
|
}
|
|
288
|
+
await stopTrackedProcess({ pid: current.pid, startedAt: current.startedAt }, onTiming);
|
|
289
|
+
removeEntriesForPid(current.pid);
|
|
290
|
+
active = null;
|
|
262
291
|
child = null;
|
|
263
292
|
childIdentityStartedAt = null;
|
|
264
293
|
healthy = false;
|
|
265
294
|
checkedAt = undefined;
|
|
266
|
-
return;
|
|
267
295
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
296
|
+
catch (error) {
|
|
297
|
+
// A failed replacement must not suppress a later real crash forever.
|
|
298
|
+
// Global shutdown and disabled services still retain their stop intent.
|
|
299
|
+
if (!stopping && desiredEnabled && runtimeMode === 'managed') {
|
|
300
|
+
intentionalStop = false;
|
|
301
|
+
if (retiringChild)
|
|
302
|
+
expectedChildExits.delete(retiringChild);
|
|
303
|
+
}
|
|
304
|
+
throw error;
|
|
305
|
+
}
|
|
275
306
|
};
|
|
276
307
|
const spawnEcweb = async () => {
|
|
277
308
|
if (stopping || !desiredEnabled || runtimeMode !== 'managed')
|
|
@@ -422,15 +453,16 @@ export function createEcwebSupervisor(options) {
|
|
|
422
453
|
}
|
|
423
454
|
if (!desiredEnabled || runtimeMode !== 'managed')
|
|
424
455
|
return;
|
|
425
|
-
|
|
456
|
+
const previousActive = active;
|
|
457
|
+
const adopted = instance !== null && await setActiveFromEntry(instance, active?.pid === instance.record.pid ? active.owned : false);
|
|
458
|
+
if (stopping || !desiredEnabled || runtimeMode !== 'managed')
|
|
459
|
+
return;
|
|
460
|
+
healthy = adopted;
|
|
426
461
|
checkedAt = Date.now();
|
|
427
|
-
if (instance) {
|
|
462
|
+
if (instance && adopted) {
|
|
428
463
|
launchRequested = false;
|
|
429
464
|
cancelRecovery();
|
|
430
|
-
const changed = !
|
|
431
|
-
await setActiveFromEntry(instance, active?.pid === instance.record.pid ? active.owned : false);
|
|
432
|
-
if (stopping || !desiredEnabled || runtimeMode !== 'managed')
|
|
433
|
-
return;
|
|
465
|
+
const changed = !previousActive || previousActive.pid !== instance.record.pid || previousActive.port !== instance.record.port;
|
|
434
466
|
failureCount = 0;
|
|
435
467
|
hasBeenReady = true;
|
|
436
468
|
settleInitialHealth?.('ok');
|
|
@@ -475,6 +507,10 @@ export function createEcwebSupervisor(options) {
|
|
|
475
507
|
if (recoveryTimer)
|
|
476
508
|
clearTimeout(recoveryTimer);
|
|
477
509
|
recoveryTimer = null;
|
|
510
|
+
// The timer may already be waiting for an in-flight health probe. Cancel
|
|
511
|
+
// that request too, while preserving explicitly requested restarts.
|
|
512
|
+
if (launchRequested === 'recovery')
|
|
513
|
+
launchRequested = false;
|
|
478
514
|
};
|
|
479
515
|
const scheduleRecovery = () => {
|
|
480
516
|
if (!healthy && desiredEnabled && !stopping)
|
|
@@ -515,6 +551,8 @@ export function createEcwebSupervisor(options) {
|
|
|
515
551
|
await startInFlight.catch(() => { });
|
|
516
552
|
if (stopping)
|
|
517
553
|
return;
|
|
554
|
+
// A health probe joined above may have scheduled another recovery.
|
|
555
|
+
cancelRecovery();
|
|
518
556
|
await killActive();
|
|
519
557
|
if (stopping)
|
|
520
558
|
return;
|
|
@@ -525,7 +563,7 @@ export function createEcwebSupervisor(options) {
|
|
|
525
563
|
return restartInFlight;
|
|
526
564
|
};
|
|
527
565
|
const scheduleCheck = () => {
|
|
528
|
-
if (stopping)
|
|
566
|
+
if (stopping || timer)
|
|
529
567
|
return;
|
|
530
568
|
const interval = active || hasBeenReady ? SERVICE_HEALTH_INTERVALS.http.running : SERVICE_HEALTH_INTERVALS.http.startup;
|
|
531
569
|
timer = setTimeout(() => {
|
|
@@ -541,7 +579,6 @@ export function createEcwebSupervisor(options) {
|
|
|
541
579
|
return;
|
|
542
580
|
if (!desiredEnabled || runtimeMode !== 'managed') {
|
|
543
581
|
settleInitialHealth?.('skipped');
|
|
544
|
-
scheduleCheck();
|
|
545
582
|
return;
|
|
546
583
|
}
|
|
547
584
|
// Give an independently started ECWeb time to publish its instance record.
|
|
@@ -552,11 +589,12 @@ export function createEcwebSupervisor(options) {
|
|
|
552
589
|
await setActiveFromEntry(existing, false);
|
|
553
590
|
return;
|
|
554
591
|
}
|
|
555
|
-
if (existing) {
|
|
592
|
+
if (existing && await setActiveFromEntry(existing, false)) {
|
|
593
|
+
if (stopping || !desiredEnabled || runtimeMode !== 'managed')
|
|
594
|
+
return;
|
|
556
595
|
healthy = true;
|
|
557
596
|
checkedAt = Date.now();
|
|
558
597
|
hasBeenReady = true;
|
|
559
|
-
await setActiveFromEntry(existing, false);
|
|
560
598
|
options.logger.info(`✓ ECWeb supervisor 接管现有实例 (PID: ${existing.record.pid}, 端口: ${existing.record.port})`);
|
|
561
599
|
settleInitialHealth?.('ok');
|
|
562
600
|
}
|
|
@@ -566,9 +604,6 @@ export function createEcwebSupervisor(options) {
|
|
|
566
604
|
launchRequested = 'manual';
|
|
567
605
|
await check();
|
|
568
606
|
}
|
|
569
|
-
if (stopping)
|
|
570
|
-
return;
|
|
571
|
-
scheduleCheck();
|
|
572
607
|
};
|
|
573
608
|
const configure = async (config) => {
|
|
574
609
|
if (stopping)
|
|
@@ -598,6 +633,7 @@ export function createEcwebSupervisor(options) {
|
|
|
598
633
|
await restartInFlight.catch(() => { });
|
|
599
634
|
if (stopping)
|
|
600
635
|
return;
|
|
636
|
+
cancelRecovery();
|
|
601
637
|
if (runtimeMode === 'external') {
|
|
602
638
|
child?.removeAllListeners();
|
|
603
639
|
child = null;
|
|
@@ -625,11 +661,17 @@ export function createEcwebSupervisor(options) {
|
|
|
625
661
|
};
|
|
626
662
|
return {
|
|
627
663
|
start() {
|
|
664
|
+
// A failed initial inspection must not disable supervision permanently.
|
|
628
665
|
if (!startup)
|
|
629
666
|
startup = start().catch(error => {
|
|
667
|
+
healthy = false;
|
|
668
|
+
checkedAt = Date.now();
|
|
669
|
+
failureCount = failureThreshold;
|
|
670
|
+
lastHealthFailure = error instanceof Error ? error.message : String(error);
|
|
630
671
|
settleInitialHealth?.('failed');
|
|
672
|
+
scheduleRecovery();
|
|
631
673
|
throw error;
|
|
632
|
-
});
|
|
674
|
+
}).finally(scheduleCheck);
|
|
633
675
|
return startup;
|
|
634
676
|
},
|
|
635
677
|
configure(config) {
|
|
@@ -112,7 +112,7 @@ export function materializeAllowlist(config, agentDir, selfAid, registeredEvents
|
|
|
112
112
|
}
|
|
113
113
|
return { allowlist, degraded: false, admittedAids: [...base] };
|
|
114
114
|
}
|
|
115
|
-
function explicitAllowlist(config) {
|
|
115
|
+
export function explicitAllowlist(config) {
|
|
116
116
|
const result = {};
|
|
117
117
|
for (const [event, entry] of Object.entries(config.rules)) {
|
|
118
118
|
result[event] = {
|