evolcore 0.0.46 → 0.0.48
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 +93 -0
- package/bin/ec-build.mjs +86 -0
- package/dist/agent-template/jobs.js +12 -4
- package/dist/agent-template/runtime.js +139 -39
- package/dist/agent-template/service.js +66 -13
- package/dist/agents/baseagent.js +60 -20
- package/dist/agents/claude-runner.js +43 -18
- package/dist/agents/codex/app-server-client.js +32 -23
- package/dist/agents/codex-runner.js +31 -16
- package/dist/agents/ecagent-runner.js +7 -4
- package/dist/agents/gemini-runner.js +5 -2
- package/dist/agents/runner-types.js +5 -21
- package/dist/aun/aid/agentmd.js +5 -1
- package/dist/aun/group/fs-download.js +1 -1
- package/dist/aun/service-proxy.js +4 -2
- package/dist/build-identity.json +1 -0
- package/dist/channels/aun.js +100 -32
- package/dist/channels/daemon.js +10 -26
- package/dist/cli/aun-commands.js +86 -51
- package/dist/cli/code-stats.js +19 -8
- package/dist/cli/command-log.js +1 -1
- package/dist/cli/daemon-commands.js +65 -76
- package/dist/cli/daemon-lifecycle-client.js +17 -3
- package/dist/cli/directory.js +7 -1
- package/dist/cli/ecmsg-gateway.js +5 -2
- package/dist/cli/index.js +2 -8
- package/dist/cli/init-channel.js +6 -8
- package/dist/cli/init.js +74 -46
- package/dist/cli/invoke-command.js +1 -1
- package/dist/cli/provider-command.js +74 -13
- package/dist/cli/restart-monitor.js +104 -28
- package/dist/cli/role.js +61 -17
- package/dist/cli/stats.js +3 -3
- package/dist/cli/task-context.js +83 -15
- package/dist/cli/thread-command.js +16 -51
- package/dist/cli/upgrade-command.js +4 -2
- package/dist/config/boot-log.js +3 -9
- package/dist/config/builtin-roles.js +5 -7
- package/dist/config/config-manager.js +31 -23
- package/dist/config/daemon-services.js +30 -3
- package/dist/config/gateway-config.js +2 -2
- package/dist/config/invoke-ipc-service.js +6 -4
- package/dist/config/peer-bind-code.js +3 -4
- package/dist/config/peer-book-store.js +59 -218
- package/dist/config/peer-book.js +26 -27
- package/dist/config/peer-role-resolver.js +16 -1
- package/dist/config/provider-identity-migration.js +161 -6
- package/dist/config/provider-ipc-service.js +56 -11
- package/dist/config/provider-menu-request.js +24 -5
- package/dist/config/provider-templates.js +127 -0
- package/dist/config/providers-config.js +59 -8
- package/dist/config/providers-management.js +467 -49
- package/dist/config/role-command-service.js +248 -1
- package/dist/config/schema-migration.js +228 -20
- package/dist/config/schema-registry.js +6 -2
- package/dist/core/agent-application-service.js +6 -1
- package/dist/core/agent-runtime.js +10 -5
- package/dist/core/auth/agent-delegation.js +10 -4
- package/dist/core/auth/auth-gateway.js +2 -1
- package/dist/core/auth/delegation-authorization.js +3 -0
- package/dist/core/auth/delegation-diagnostics.js +56 -15
- package/dist/core/auth/operation-authorizer.js +26 -1
- package/dist/core/auth/operation-catalog.js +28 -64
- package/dist/core/capability/providers/codex-capability-provider.js +7 -8
- package/dist/core/channel-loader.js +18 -0
- package/dist/core/command/agent-control.js +32 -0
- package/dist/core/command/command-handler.js +81 -85
- package/dist/core/command/menu-catalog.js +1 -0
- package/dist/core/command/menu-handler.js +65 -153
- package/dist/core/command/menu-protocol.js +7 -1
- package/dist/core/command/provider-menu.js +13 -3
- package/dist/core/command/role-menu.js +47 -23
- package/dist/core/command/slash-handler.js +30 -49
- package/dist/core/command/team-workspace-items.js +81 -12
- package/dist/core/command/team-workspace-team.js +9 -71
- package/dist/core/command/topic-slash.js +9 -30
- package/dist/core/daemon-bootstrap.js +19 -10
- package/dist/core/daemon-control.js +8 -10
- package/dist/core/daemon-lifecycle.js +50 -40
- package/dist/core/evolagent-registry.js +22 -3
- package/dist/core/file-integrity/store.js +2 -0
- package/dist/core/handoff/runtime.js +37 -1
- package/dist/core/host-snapshot.js +9 -4
- package/dist/core/inference/text-inference.js +3 -1
- package/dist/core/initialization/service.js +31 -8
- package/dist/core/interaction-router.js +3 -0
- package/dist/core/invoke/executors/text.js +72 -19
- package/dist/core/ipc-registration.js +6 -4
- package/dist/core/memory/consolidation.js +6 -6
- package/dist/core/message/aun-ipc-sender.js +165 -55
- package/dist/core/message/im-renderer.js +1 -1
- package/dist/core/message/message-bridge.js +51 -334
- package/dist/core/message/message-log.js +5 -0
- package/dist/core/message/message-queue.js +22 -0
- package/dist/core/message/message-utils.js +8 -0
- package/dist/core/message/response-engine.js +429 -116
- package/dist/core/message/send-routing.js +5 -1
- package/dist/core/model/catalog-service.js +31 -11
- package/dist/core/model/model-capabilities.js +22 -4
- package/dist/core/model/model-catalog.js +1 -0
- package/dist/core/ownership/owner-resolver.js +355 -60
- package/dist/core/permission/protected-paths.js +6 -6
- package/dist/core/relation/peer-identity.js +28 -2
- package/dist/core/relation/same-owner-proof.js +81 -111
- package/dist/core/session/adapters/claude-session-file-adapter.js +1 -1
- package/dist/core/session/adapters/codex-session-file-adapter.js +96 -15
- package/dist/core/session/session-file-health.js +49 -14
- package/dist/core/session/session-fs-store.js +91 -35
- package/dist/core/session/session-manager.js +68 -24
- package/dist/core/session/session-mapper.js +14 -34
- package/dist/core/session/session-transcript.js +5 -1
- package/dist/core/task/task-activity-store.js +84 -0
- package/dist/core/task/task-image-resources.js +1 -1
- package/dist/core/task/task-recovery-service.js +12 -0
- package/dist/core/thread/command-parser.js +7 -12
- package/dist/core/thread/thread-context-storage.js +3 -2
- package/dist/core/thread/thread-operation.js +2 -13
- package/dist/core/thread/thread-service.js +15 -46
- package/dist/directory/owner-directory-admission.js +1 -1
- package/dist/directory/owner-directory-cache.js +45 -28
- package/dist/directory/owner-directory-markdown.js +13 -1
- package/dist/directory/owner-directory-query-operation.js +29 -3
- package/dist/directory/owner-directory-remarks.js +11 -3
- package/dist/eck/message-renderer.js +84 -24
- package/dist/ecweb/basic-settings-service.js +3 -1
- package/dist/ecweb/message-context-service.js +1 -1
- package/dist/ecweb/pairing.js +4 -3
- package/dist/ecweb/providers-service.js +26 -1
- package/dist/ecweb/runtime/lifecycle.js +82 -23
- package/dist/ecweb/runtime/proxy-access.js +74 -0
- package/dist/ecweb/runtime/supervisor.js +6 -17
- package/dist/event-center/registry.js +13 -2
- package/dist/event-center/runtime.js +103 -11
- package/dist/event-center/script-runner.js +5 -5
- package/dist/index.js +129 -93
- package/dist/ipc.js +15 -3
- package/dist/outputs/events.js +62 -0
- package/dist/outputs/protocol.js +102 -0
- package/dist/outputs/service.js +279 -0
- package/dist/paths.js +3 -0
- package/dist/proxy/manager.js +43 -13
- package/dist/services/index.js +89 -4
- package/dist/services/ipc-operation.js +4 -15
- package/dist/services/pack-manager.js +12 -1
- package/dist/services/router.js +21 -6
- package/dist/services/script-runner.js +5 -4
- package/dist/services/validation.js +1 -1
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +19 -0
- package/dist/stats/index.js +1 -1
- package/dist/stats/{price-resolver.js → model-resolver.js} +305 -24
- package/dist/stats/normalizer.js +2 -0
- package/dist/stats/query.js +35 -27
- package/dist/stats/role-budget.js +5 -2
- package/dist/stats/writer.js +10 -6
- package/dist/trigger/audit.js +7 -0
- package/dist/trigger/authorization.js +105 -11
- package/dist/trigger/feedback.js +10 -0
- package/dist/trigger/history.js +37 -11
- package/dist/trigger/ipc-service.js +12 -1
- package/dist/trigger/manager.js +1 -0
- package/dist/trigger/scheduler.js +11 -5
- package/dist/trigger/script-executor.js +2 -1
- package/dist/trigger/script-sandbox.js +9 -3
- package/dist/trigger/state.js +7 -0
- package/dist/trigger/validation.js +22 -0
- package/dist/utils/aid-bind.js +155 -18
- package/dist/utils/atomic-write.js +3 -3
- package/dist/utils/cross-platform.js +97 -31
- package/dist/utils/error-dict.json +94 -4
- package/dist/utils/error-utils.js +40 -4
- package/dist/utils/evolcore-version.js +36 -65
- package/dist/utils/instance-registry.js +61 -0
- package/dist/utils/msg-diag.js +1 -0
- package/dist/utils/process-introspect.js +158 -8
- package/dist/utils/process-tree.js +50 -2
- package/dist/utils/upgrade-jobs.js +4 -4
- package/dist/utils/windows-shell-trust.js +2 -0
- package/dist/workbench/protocol.js +80 -0
- package/dist/workbench/service.js +359 -0
- package/ecagent/dist/types.d.ts +6 -2
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +2 -2
- package/kits/docs/evolcore/aid.md +3 -1
- package/kits/docs/evolcore/config.md +12 -0
- package/kits/docs/evolcore/directory.md +22 -3
- package/kits/docs/evolcore/ecweb-lifecycle.md +15 -0
- package/kits/docs/evolcore/model.md +10 -0
- package/kits/docs/evolcore/peer.md +19 -65
- package/kits/docs/evolcore/provider.md +133 -5
- package/kits/docs/evolcore/role.md +80 -0
- package/kits/docs/evolcore/services.md +6 -6
- package/kits/docs/evolcore/team-workspace.md +1 -1
- package/kits/docs/evolcore/thread-chain.md +14 -15
- package/kits/docs/evolcore/tool-authorization.md +5 -0
- package/kits/docs/evolcore/trigger.md +10 -0
- package/kits/eck_message_manifest.json +12 -0
- package/kits/provider-templates.json +1213 -0
- package/kits/rules/04-relation.md +3 -3
- package/kits/schemas/_meta.json +14 -2
- package/kits/schemas/contact-book.schema.4.json +52 -0
- package/kits/schemas/providers.schema.3.json +200 -0
- package/kits/skills/.switches.json +4 -0
- package/kits/skills/ability/references/calling.md +1 -1
- package/kits/skills/ec-group/SKILL.md +2 -2
- package/kits/skills/ec-identity/SKILL.md +19 -72
- package/kits/skills/ec-provider/SKILL.md +221 -0
- package/kits/skills/ec-provider/scripts/check-model.mjs +80 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/skills/thread-ops/SKILL.md +34 -21
- package/kits/templates/message-fragments/group-batch-item.md +1 -1
- package/kits/templates/message-fragments/group-batch.md +1 -1
- package/kits/templates/message-fragments/inject-default.md +1 -1
- package/kits/templates/message-fragments/interrupt-insert.md +1 -0
- package/kits/templates/message-fragments/item-group.md +1 -1
- package/kits/templates/message-fragments/item-private.md +1 -1
- package/kits/templates/message-fragments/thread-context.md +1 -1
- package/kits/templates/message-fragments/trigger-session.md +1 -1
- package/kits/templates/message-fragments/trigger-thread-check.md +1 -1
- package/kits/templates/roles/admin.json +2 -19
- package/kits/templates/roles/member.json +0 -3
- package/kits/templates/system-fragments/baseagent.md +6 -0
- package/kits/templates/system-fragments/commands.md +3 -3
- package/kits/templates/system-fragments/managed-runtime.md +1 -1
- package/kits/templates/system-fragments/relation.md +1 -1
- package/kits/templates/system-fragments/thread.md +6 -5
- package/package.json +6 -4
- package/scripts/agent-template/inspect.mjs +4 -1
- package/scripts/agent-template/shared/common.mjs +2 -3
- package/scripts/agent-template/shared/template-contract.mjs +2 -1
- package/scripts/agent-template/shared/template-package.mjs +9 -2
- package/scripts/agent-template/shared/template-runtime.mjs +20 -5
- package/scripts/agent-template/team-pack.mjs +6 -3
- package/dist/cli/peer.js +0 -127
- package/dist/config/peer-operation-service.js +0 -132
- package/dist/config/peer-request-service.js +0 -532
- package/dist/core/command/connect-menu.js +0 -624
|
@@ -56,16 +56,19 @@ function identityLabel(name, aid, type, exttype) {
|
|
|
56
56
|
const e = String(exttype ?? '').trim();
|
|
57
57
|
return e ? `${display}[${t}/${e}]` : `${display}[${t}]`;
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
/** 本端 `名称(AID)[type/exttype]`;`self:` 前缀由模版提供。 */
|
|
60
|
+
function selfIdentityOf(sessionVars) {
|
|
61
|
+
return identityLabel(sessionVars.selfName, sessionVars.selfAid, sessionVars.selfType ?? 'agent', sessionVars.selfExttype);
|
|
61
62
|
}
|
|
62
63
|
function groupTagOf(sessionVars) {
|
|
63
64
|
const groupAid = String(sessionVars.groupId ?? '').trim();
|
|
64
65
|
const groupName = String(sessionVars.groupName ?? '').trim();
|
|
65
66
|
return groupName && groupAid ? `${groupName}<${groupAid}>` : (groupAid || groupName);
|
|
66
67
|
}
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
/** 关系角色:逐条显式值优先,其次按会话类型兜底。`关系角色:` 前缀由模版提供。 */
|
|
69
|
+
function speakerRelationOf(item, sessionVars) {
|
|
70
|
+
return String(item.speakerRelation
|
|
71
|
+
?? (String(sessionVars.chatType ?? '') === 'group' ? 'visitor' : (item.peerRole ?? sessionVars.peerRole ?? 'visitor')));
|
|
69
72
|
}
|
|
70
73
|
/** `ctx: scene=… · activity=… · location=地址(纬度,经度)`;无 sender_ctx 返回空串。 */
|
|
71
74
|
function formatSenderCtx(ctx) {
|
|
@@ -103,6 +106,34 @@ function renderOneItem(item, sessionVars, sessionCache, contentSentinel, compact
|
|
|
103
106
|
const isHandoff = item.kind === 'handoff';
|
|
104
107
|
const isThreadContext = item.kind === 'thread-context';
|
|
105
108
|
const isTriggerMsg = item.kind === 'trigger';
|
|
109
|
+
// 「因上一轮被新消息中断而插入」的那一条。与 kind 正交:普通消息直接写
|
|
110
|
+
// kind='interrupt-insert',已有专属 kind 的消息(trigger 等)用 interruptInsert 布尔位。
|
|
111
|
+
const isInterruptInsert = item.kind === 'interrupt-insert' || item.interruptInsert === true;
|
|
112
|
+
// 中断原因 → 提示文案。模板引擎只有真值判断、没有等值条件,逐原因文案在 JS 侧选好,
|
|
113
|
+
// 模板只做 {{interruptNotice}} 占位。首段文字保持「【中断后新消息…】」形态:
|
|
114
|
+
// 历史剥离正则(session-manager / session-transcript)按该前缀清理会话记录。
|
|
115
|
+
const interruptNotice = !isInterruptInsert ? undefined : (() => {
|
|
116
|
+
switch (item.interruptReason) {
|
|
117
|
+
case 'daemon_restart':
|
|
118
|
+
return '【中断后新消息 · 上一轮因进程重启中断,这是待处理的新消息;请根据前后消息酌情处理】';
|
|
119
|
+
case 'proactive_circuit_break':
|
|
120
|
+
return '【中断后新消息 · 上一轮因长时间无反馈被自动中断;请根据前后消息酌情处理】';
|
|
121
|
+
case 'timeout':
|
|
122
|
+
case 'execution_error':
|
|
123
|
+
return '【中断后新消息 · 上一轮执行异常中断,这是新的消息;请根据前后消息酌情处理】';
|
|
124
|
+
case 'stop':
|
|
125
|
+
case 'explicit_cancel':
|
|
126
|
+
return '【中断后新消息 · 上一轮已被叫停,这是新的消息;请根据前后消息酌情处理】';
|
|
127
|
+
case 'recalled':
|
|
128
|
+
return '【中断后新消息 · 上一轮原消息已撤回,这是新的消息;请根据前后消息酌情处理】';
|
|
129
|
+
case 'new_message':
|
|
130
|
+
case 'restart':
|
|
131
|
+
return '【中断后新消息 · 上一轮被这条新消息打断;请根据前后消息酌情处理】';
|
|
132
|
+
default:
|
|
133
|
+
// 未知/缺省原因也要出提示,不能漏。
|
|
134
|
+
return '【中断后新消息 · 请根据前后消息酌情处理】';
|
|
135
|
+
}
|
|
136
|
+
})();
|
|
106
137
|
const handoffPreviousSentinel = `\x00ECMSG-HANDOFF-PREV-${randomUUID()}\x00`;
|
|
107
138
|
const requiredReplacements = (item.handoff?.requiredEntries ?? []).map(entry => ({
|
|
108
139
|
entry,
|
|
@@ -157,7 +188,8 @@ function renderOneItem(item, sessionVars, sessionCache, contentSentinel, compact
|
|
|
157
188
|
}]
|
|
158
189
|
: [];
|
|
159
190
|
const allOriginReplacements = [...originReplacements, ...fallbackOriginEntries];
|
|
160
|
-
//
|
|
191
|
+
// 信封字段只在这里「取值」,`from:`/`self:`/`关系角色:`/`chat:`/`mid:` 等词与
|
|
192
|
+
// ` · ` 分隔符一律写在模版里(条件块内嵌分隔符,假值分支整块消失,不留悬空 `·`)。
|
|
161
193
|
const tz = sessionVars.timezone ? String(sessionVars.timezone) : undefined;
|
|
162
194
|
const selfAid = String(sessionVars.selfAid ?? '');
|
|
163
195
|
const selfName = String(sessionVars.selfName ?? '');
|
|
@@ -173,14 +205,8 @@ function renderOneItem(item, sessionVars, sessionCache, contentSentinel, compact
|
|
|
173
205
|
const fromType = selfAddressed ? selfType : itemPeerType;
|
|
174
206
|
const fromExttype = selfAddressed ? selfExttype : itemPeerExttype;
|
|
175
207
|
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
208
|
const isMentioned = item.isMentioned === true
|
|
182
209
|
|| (item.mentionAids ?? []).some(aid => String(aid).toLowerCase() === selfAid.toLowerCase());
|
|
183
|
-
const mentionPart = isMentioned ? ' · @我' : '';
|
|
184
210
|
const timestamp = item.timestamp ?? Date.now();
|
|
185
211
|
// 时间基准是本机时间;发件人时区与本机不同时,追加对方当地时刻与时区名,
|
|
186
212
|
// 避免模型自己换算(时区名 + 当地时刻才可直接引用)。
|
|
@@ -194,17 +220,22 @@ function renderOneItem(item, sessionVars, sessionCache, contentSentinel, compact
|
|
|
194
220
|
now: nowText,
|
|
195
221
|
shortNow: shortNowText,
|
|
196
222
|
batchTime: formatBatchTime(timestamp, tz),
|
|
197
|
-
modePart,
|
|
198
|
-
topicPart,
|
|
199
|
-
groupRolePart,
|
|
200
|
-
mentionPart,
|
|
201
223
|
groupTag: groupTagOf(sessionVars),
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
224
|
+
fromIdentity: identityLabel(fromName, fromAid, fromType, fromExttype),
|
|
225
|
+
selfIdentity: selfIdentityOf(sessionVars),
|
|
226
|
+
// 消息接收者:本会话的投递目标。与 `fromIdentity`(逐条 item 的发送方)是两个维度,
|
|
227
|
+
// 供「消息维度」的模版(如 thread-context 提醒)显式渲染 from/to。
|
|
228
|
+
// 群聊的 peerId 是**发言人**(群消息的发送者),投递目标其实是群本身,故按群 tag 渲染。
|
|
229
|
+
// 当前话题的对端:优先用会话提供的 topicPeer*(与「本轮谁唤醒」正交)。
|
|
230
|
+
// 只有伪对端(trigger:/bg:)轮次才有值;普通轮次落空,仍按 peerId 渲染。
|
|
231
|
+
toIdentity: String(sessionVars.chatType ?? '') === 'group'
|
|
232
|
+
? groupTagOf(sessionVars)
|
|
233
|
+
: (sessionVars.topicPeerId
|
|
234
|
+
? identityLabel(sessionVars.topicPeerName ?? sessionVars.peerName, sessionVars.topicPeerId, sessionVars.topicPeerType ?? sessionVars.peerType, sessionVars.peerExttype)
|
|
235
|
+
: identityLabel(sessionVars.peerName, sessionVars.peerId, sessionVars.peerType, sessionVars.peerExttype)),
|
|
236
|
+
speakerRelation: speakerRelationOf(item, sessionVars),
|
|
237
|
+
// `mid:` 是恒出现字段:缺 messageId(非 AUN 渠道)时保留占位,不能让整段消失。
|
|
238
|
+
messageId: item.messageId ?? '-',
|
|
208
239
|
senderCtxLine: formatSenderCtx(item.senderCtx),
|
|
209
240
|
batchItem: compact || undefined,
|
|
210
241
|
// 跨话题委托提醒:原消息与来源会话,供回查定位。
|
|
@@ -220,6 +251,12 @@ function renderOneItem(item, sessionVars, sessionCache, contentSentinel, compact
|
|
|
220
251
|
peerType: item.peerType ?? sessionVars.peerType,
|
|
221
252
|
// 本端给自己派的任务:信封头标「跨话题自派」,让模型分清「我派的活」和「对端说的话」。
|
|
222
253
|
selfAddressed: item.selfAddressed || undefined,
|
|
254
|
+
// 信封可选段的原值:`{{?x}} ... {{/}}` 的开关与内容都由模版自己拼。
|
|
255
|
+
modeToken: modeToken || undefined,
|
|
256
|
+
originThreadId: item.originThreadId,
|
|
257
|
+
originPeer: item.originThreadId ? item.originPeer : undefined,
|
|
258
|
+
groupRole: item.groupRole,
|
|
259
|
+
isMentioned,
|
|
223
260
|
peerRole: item.peerRole ?? sessionVars.peerRole,
|
|
224
261
|
sameDevice: item.sameDevice ?? sessionVars.sameDevice,
|
|
225
262
|
sameNetwork: item.sameNetwork ?? sessionVars.sameNetwork,
|
|
@@ -234,6 +271,11 @@ function renderOneItem(item, sessionVars, sessionCache, contentSentinel, compact
|
|
|
234
271
|
renderMode_private: activeMode('private'),
|
|
235
272
|
renderMode_group: activeMode('group'),
|
|
236
273
|
renderMode_inject: activeMode('inject'),
|
|
274
|
+
// 中断插入标记:只给被插入的那一条挂一行提示(见 interrupt-insert.md)。
|
|
275
|
+
// 与 kind 正交,已有专属信封的消息用 interruptInsert 布尔位标记。
|
|
276
|
+
isInterruptInsert,
|
|
277
|
+
interruptNotice,
|
|
278
|
+
interruptReason: item.interruptReason,
|
|
237
279
|
// owner 插话提示标记 + 信封头字段
|
|
238
280
|
isOwnerHint,
|
|
239
281
|
ownerAid: isOwnerHint ? (item.ownerAid ?? undefined) : undefined,
|
|
@@ -244,6 +286,12 @@ function renderOneItem(item, sessionVars, sessionCache, contentSentinel, compact
|
|
|
244
286
|
isThreadContext,
|
|
245
287
|
threadContextOriginThreadId: item.threadContext?.originThreadId,
|
|
246
288
|
threadContextOriginPeer: item.threadContext?.originPeer,
|
|
289
|
+
// 来源话题对端的展示形态:有名字用 `名称(AID)[type]`,旧条目只有裸 AID。
|
|
290
|
+
// 类型取 inbox 落盘的真实值;旧条目没有该字段时由 identityLabel 落成 `unknown`,
|
|
291
|
+
// 不能硬编码 'agent'——来源对端常常是人。
|
|
292
|
+
threadContextOriginPeerLabel: item.threadContext?.originPeer
|
|
293
|
+
? identityLabel(item.threadContext.originPeerName, item.threadContext.originPeer, item.threadContext.originPeerType, undefined)
|
|
294
|
+
: undefined,
|
|
247
295
|
threadContextTime: item.timestamp !== undefined
|
|
248
296
|
? formatLocalTime(item.timestamp, sessionVars.timezone ? String(sessionVars.timezone) : undefined)
|
|
249
297
|
: undefined,
|
|
@@ -283,6 +331,16 @@ function renderOneItem(item, sessionVars, sessionCache, contentSentinel, compact
|
|
|
283
331
|
...(isTriggerMsg && item.triggerInfo?.labels
|
|
284
332
|
? Object.fromEntries(Object.entries(item.triggerInfo.labels).map(([k, v]) => [`triggerMsgLabel_${k}`, v]))
|
|
285
333
|
: {}),
|
|
334
|
+
// 来源话题对端的展示形态:labels 里存了名称就显示 `名称(AID)[type]`,否则退回裸 AID。
|
|
335
|
+
// 模版引擎没有 else,兜底在 JS 侧合成,模版只插一个变量。
|
|
336
|
+
triggerOriginPeerLabel: (() => {
|
|
337
|
+
const aid = item.triggerInfo?.labels?.originPeer;
|
|
338
|
+
if (!isTriggerMsg || !aid)
|
|
339
|
+
return undefined;
|
|
340
|
+
// 与 thread-context 的 `threadContextOriginPeerLabel` 同形态:缺名字也带类型标签,
|
|
341
|
+
// 类型取 labels 里落盘的真实值,旧 Trigger 缺失时落成 `unknown`。
|
|
342
|
+
return identityLabel(item.triggerInfo?.labels?.originPeerName, aid, item.triggerInfo?.labels?.originPeerType, undefined);
|
|
343
|
+
})(),
|
|
286
344
|
// msg send 跨会话一次性上下文
|
|
287
345
|
isHandoff,
|
|
288
346
|
handoffKind: item.handoff?.kind,
|
|
@@ -367,8 +425,7 @@ function renderGroupHeader(sessionVars, first, sessionCache) {
|
|
|
367
425
|
...sessionVars,
|
|
368
426
|
batchTime: formatBatchTime(first.timestamp ?? Date.now(), tz),
|
|
369
427
|
groupTag: groupTagOf(sessionVars),
|
|
370
|
-
|
|
371
|
-
chatLabel: chatLabelOf(sessionVars),
|
|
428
|
+
selfIdentity: selfIdentityOf(sessionVars),
|
|
372
429
|
};
|
|
373
430
|
const section = {
|
|
374
431
|
id: 'msg-group-batch',
|
|
@@ -439,7 +496,10 @@ function writeMessageDebug(sessionId, items, body) {
|
|
|
439
496
|
if (!isEckSnapshotsEnabled())
|
|
440
497
|
return;
|
|
441
498
|
try {
|
|
442
|
-
|
|
499
|
+
// 文件名精确到毫秒并带随机后缀:同一秒内多次渲染(同批多段、并发会话)会撞名,
|
|
500
|
+
// 异步 writeFile 覆盖同一路径时两个写流交错,落盘的是半截拼接内容。
|
|
501
|
+
const ts = new Date().toISOString().replace(/[T:.]/g, '-').slice(0, 23);
|
|
502
|
+
const uniq = randomUUID().slice(0, 8);
|
|
443
503
|
const dir = eckDebugDir();
|
|
444
504
|
fs.mkdirSync(dir, { recursive: true });
|
|
445
505
|
const out = [
|
|
@@ -2,6 +2,7 @@ import crypto from 'node:crypto';
|
|
|
2
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
|
+
import { resolveDaemonServices } from '../config/daemon-services.js';
|
|
5
6
|
const BASEAGENTS = ['claude', 'codex', 'gemini', 'ecagent'];
|
|
6
7
|
const BASEAGENT_SET = new Set(BASEAGENTS);
|
|
7
8
|
const EFFORTS = new Set(['low', 'medium', 'high', 'xhigh', 'max']);
|
|
@@ -197,7 +198,8 @@ function hideBaseagentConnectionFields(config) {
|
|
|
197
198
|
export function readBasicSettings() {
|
|
198
199
|
const rawDaemon = readSettingsFile('daemon');
|
|
199
200
|
const rawDefaults = readSettingsFile('defaults');
|
|
200
|
-
const daemon = rawDaemon ? clone(rawDaemon) :
|
|
201
|
+
const daemon = rawDaemon ? clone(rawDaemon) : {};
|
|
202
|
+
daemon.services = resolveDaemonServices(daemon.services);
|
|
201
203
|
if (daemon) {
|
|
202
204
|
delete daemon.owner;
|
|
203
205
|
delete daemon.owners;
|
|
@@ -110,7 +110,7 @@ export function createEcwebMessageContextProvider(sessionManager, resolveRuntime
|
|
|
110
110
|
result.status = status;
|
|
111
111
|
if (session.agentSessionId && session.projectPath && session.baseagent) {
|
|
112
112
|
try {
|
|
113
|
-
const fileInfo = sessionManager.
|
|
113
|
+
const fileInfo = await sessionManager.getSessionFileInfoAsync(session.projectPath, session.agentSessionId, session.baseagent, session.selfAID);
|
|
114
114
|
if (Number.isFinite(fileInfo.turns) && fileInfo.turns > 0)
|
|
115
115
|
result.turns = fileInfo.turns;
|
|
116
116
|
}
|
package/dist/ecweb/pairing.js
CHANGED
|
@@ -3,7 +3,8 @@ import { ipcQuery } from '../ipc.js';
|
|
|
3
3
|
import { ecwebService } from '../config/daemon-services.js';
|
|
4
4
|
export function resolveEcwebExternalUrl(config) {
|
|
5
5
|
const aid = config.aid?.trim();
|
|
6
|
-
|
|
6
|
+
const service = ecwebService(config.services);
|
|
7
|
+
if (!aid || service?.enabled !== true || service.proxy?.enabled !== true)
|
|
7
8
|
return null;
|
|
8
9
|
return `https://${aid}/proxy/ecweb`;
|
|
9
10
|
}
|
|
@@ -11,11 +12,11 @@ export function resolveEcwebExternalUrl(config) {
|
|
|
11
12
|
* One-click ECWeb pairing link. The code travels in the URL fragment so it never
|
|
12
13
|
* reaches proxy-server or ECWeb access logs; the page redeems it on load.
|
|
13
14
|
*/
|
|
14
|
-
export function buildEcwebPairingUrl(config, code) {
|
|
15
|
+
export function buildEcwebPairingUrl(config, code, initialization = false) {
|
|
15
16
|
const externalUrl = resolveEcwebExternalUrl(config);
|
|
16
17
|
if (!externalUrl || !/^\d{6}$/.test(code))
|
|
17
18
|
return null;
|
|
18
|
-
return `${externalUrl}
|
|
19
|
+
return `${externalUrl}/${initialization ? 'init' : ''}#code=${code}`;
|
|
19
20
|
}
|
|
20
21
|
/** Shared pairing-code announcement used by the control-AID and slash /pair paths. */
|
|
21
22
|
export function formatPairingCodeMessage(pair, config, now = Date.now()) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isProviderModelPattern, providerModelLiteralId, providerModelEnabled, readProvidersFile, resolveProviderService } from '../config/providers.js';
|
|
2
2
|
import { resolveProviderId } from '../config/providers-config.js';
|
|
3
|
-
import { createProvider, importOrMergeBaseagentProvider, parseProviderImport, previewProviderImport, previewProviderValue, readProviderForExport, readProvidersSnapshot, resolveProviderDraftService, saveProviderChanges, updateProvider, } from '../config/providers-management.js';
|
|
3
|
+
import { createProvider, importOrMergeBaseagentProvider, parseProviderImport, previewProviderImport, previewProviderValue, readProviderForExport, readProvidersSnapshot, resolveProviderDraftService, saveProviderChanges, updateProvider, prepareProviderTemplate, previewProviderTemplate, } from '../config/providers-management.js';
|
|
4
|
+
import { readProviderTemplates, providerTemplateDetail } from '../config/provider-templates.js';
|
|
4
5
|
import { listBaseagentImportSources, providerFromBaseagent } from '../config/providers-import.js';
|
|
5
6
|
import { getProviderCatalog, previewProviderCatalog } from '../core/model/model-catalog.js';
|
|
6
7
|
function isRecord(value) {
|
|
@@ -49,6 +50,10 @@ async function resolveImports(value) {
|
|
|
49
50
|
return parseProviderImport(item.text);
|
|
50
51
|
if (item.provider !== undefined)
|
|
51
52
|
return item.provider;
|
|
53
|
+
if (isRecord(item.template)) {
|
|
54
|
+
const draft = prepareProviderTemplate(String(item.template.templateId), item.template.config);
|
|
55
|
+
return { templateProvider: draft.incoming };
|
|
56
|
+
}
|
|
52
57
|
throw new Error('Invalid Provider import');
|
|
53
58
|
});
|
|
54
59
|
}
|
|
@@ -70,6 +75,26 @@ export async function handleProvidersService(input) {
|
|
|
70
75
|
if (input.method === 'GET' && !parts.length) {
|
|
71
76
|
return response(200, { success: true, data: readProvidersSnapshot() });
|
|
72
77
|
}
|
|
78
|
+
if (parts[0] === 'templates') {
|
|
79
|
+
if (input.method === 'GET' && parts.length === 1) {
|
|
80
|
+
return response(200, { success: true, data: readProviderTemplates() });
|
|
81
|
+
}
|
|
82
|
+
if (input.method === 'GET' && parts.length === 2) {
|
|
83
|
+
return response(200, { success: true, data: providerTemplateDetail(parts[1]) });
|
|
84
|
+
}
|
|
85
|
+
if (input.method === 'POST' && parts.length === 3 && parts[2] === 'preview') {
|
|
86
|
+
const body = requestBody(input.body);
|
|
87
|
+
let context;
|
|
88
|
+
if (body.draft !== undefined) {
|
|
89
|
+
if (!isRecord(body.draft) || typeof body.draft.providerId !== 'string')
|
|
90
|
+
throw new Error('Invalid Provider draft');
|
|
91
|
+
context = { providerId: body.draft.providerId, value: body.draft.provider,
|
|
92
|
+
imports: await resolveImports(body.draft.imports) };
|
|
93
|
+
}
|
|
94
|
+
return response(200, { success: true, data: previewProviderTemplate(parts[1], body.config ?? body, context) });
|
|
95
|
+
}
|
|
96
|
+
return response(405, { success: false, error: 'Unsupported template operation' });
|
|
97
|
+
}
|
|
73
98
|
if (input.method === 'POST' && !parts.length) {
|
|
74
99
|
const body = requestBody(input.body);
|
|
75
100
|
if (typeof body.revision !== 'string')
|
|
@@ -3,16 +3,16 @@ 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';
|
|
10
10
|
import { WEB_PACKAGE_NAME } from '../../product.js';
|
|
11
11
|
async function sameProcess(identity) {
|
|
12
|
-
if (!platform.
|
|
12
|
+
if (!await platform.isProcessRunningAsync(identity.pid))
|
|
13
13
|
return false;
|
|
14
14
|
const actual = await getProcessStartTimeAsync(identity.pid, { fresh: true });
|
|
15
|
-
if (!platform.
|
|
15
|
+
if (!await platform.isProcessRunningAsync(identity.pid))
|
|
16
16
|
return false;
|
|
17
17
|
if (identity.startedAt === null || actual === null) {
|
|
18
18
|
throw new Error(`Cannot verify ECWeb process identity (PID: ${identity.pid}); refusing to terminate it`);
|
|
@@ -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,18 +89,20 @@ 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;
|
|
97
|
+
}
|
|
98
|
+
// Verify immediately before each PID-addressed signal. Windows has no TERM
|
|
99
|
+
// attempt here, so it only needs the verification before forced termination.
|
|
100
|
+
if (!platform.isWindows) {
|
|
59
101
|
if (!await sameProcess(identity))
|
|
60
102
|
return;
|
|
103
|
+
if (await waitForExit(false, POSIX_GRACEFUL_STOP_MS))
|
|
104
|
+
return;
|
|
61
105
|
}
|
|
62
|
-
else if (!await sameProcess(identity))
|
|
63
|
-
return;
|
|
64
|
-
if (!platform.isWindows && await waitForExit(false, POSIX_GRACEFUL_STOP_MS))
|
|
65
|
-
return;
|
|
66
106
|
if (!await sameProcess(identity))
|
|
67
107
|
return;
|
|
68
108
|
if (await waitForExit(true, timeoutMs))
|
|
@@ -73,8 +113,6 @@ export async function stopEcwebProcess(identity, timeoutMs = FORCED_STOP_MS, onT
|
|
|
73
113
|
}
|
|
74
114
|
function commandLineFor(pid) {
|
|
75
115
|
try {
|
|
76
|
-
if (platform.isWindows)
|
|
77
|
-
return getProcessSnapshot({ fresh: true }).commandLines.get(pid) ?? null;
|
|
78
116
|
return execFileSync('ps', ['-ww', '-p', String(pid), '-o', 'command='], {
|
|
79
117
|
encoding: 'utf8', timeout: 3_000, stdio: ['ignore', 'pipe', 'ignore'],
|
|
80
118
|
}).trim() || null;
|
|
@@ -157,13 +195,26 @@ export async function stopEcwebForRestart(paths, port, log) {
|
|
|
157
195
|
const launch = resolveEcwebLaunchCommand([], { installedPkg: installed });
|
|
158
196
|
const entries = [launch?.entry, installed ? path.join(path.dirname(installed.path), 'dist', 'index.js') : undefined]
|
|
159
197
|
.filter((entry) => !!entry);
|
|
198
|
+
let windowsListeners;
|
|
160
199
|
for (const targetPort of ports) {
|
|
161
200
|
for (const pid of platform.findProcessByPort(targetPort)) {
|
|
162
201
|
if (identities.has(pid))
|
|
163
202
|
continue;
|
|
164
|
-
|
|
165
|
-
|
|
203
|
+
// Observe creation time and command line together, rather than starting
|
|
204
|
+
// per-PID PowerShell/WMIC and then querying the whole table again. This
|
|
205
|
+
// snapshot only identifies candidates; stopEcwebProcess rechecks identity.
|
|
206
|
+
const snapshot = platform.isWindows
|
|
207
|
+
? windowsListeners ??= await getProcessSnapshotAsync({ fresh: true }) : undefined;
|
|
208
|
+
const startedAt = snapshot ? snapshot.startedAt.get(pid) ?? null : getProcessStartTime(pid);
|
|
209
|
+
const commandLine = snapshot ? snapshot.commandLines.get(pid) ?? null : commandLineFor(pid);
|
|
166
210
|
if (startedAt === null || !commandLine || !matchesEcwebCommand(commandLine, paths.root, entries)) {
|
|
211
|
+
// A listener can exit between netstat/lsof and the identity query.
|
|
212
|
+
// Recheck ownership instead of rejecting a stale PID. The final scan
|
|
213
|
+
// and exclusive bind must still prove the port was actually released.
|
|
214
|
+
if (!(await platform.findProcessByPortAsync(targetPort)).includes(pid))
|
|
215
|
+
continue;
|
|
216
|
+
if (!await platform.isProcessRunningAsync(pid))
|
|
217
|
+
continue;
|
|
167
218
|
throw new Error(`ECWeb 端口 ${targetPort} 被身份未确认的进程占用 (PID: ${pid});未终止该进程`);
|
|
168
219
|
}
|
|
169
220
|
let health;
|
|
@@ -174,6 +225,10 @@ export async function stopEcwebForRestart(paths, port, log) {
|
|
|
174
225
|
}
|
|
175
226
|
catch { }
|
|
176
227
|
if (!matchesEcwebInstanceHealth(health, { pid, port: targetPort })) {
|
|
228
|
+
if (!(await platform.findProcessByPortAsync(targetPort)).includes(pid))
|
|
229
|
+
continue;
|
|
230
|
+
if (!await platform.isProcessRunningAsync(pid))
|
|
231
|
+
continue;
|
|
177
232
|
throw new Error(`ECWeb 端口 ${targetPort} 的服务身份无法确认 (PID: ${pid});未终止该进程`);
|
|
178
233
|
}
|
|
179
234
|
identities.set(pid, { pid, startedAt });
|
|
@@ -188,8 +243,12 @@ export async function stopEcwebForRestart(paths, port, log) {
|
|
|
188
243
|
}
|
|
189
244
|
for (const targetPort of ports) {
|
|
190
245
|
const listeners = platform.findProcessByPort(targetPort);
|
|
191
|
-
|
|
192
|
-
|
|
246
|
+
// Listener scans can race with process exit. Never signal a stale PID
|
|
247
|
+
// or fail on that row alone; exclusive binding remains mandatory below.
|
|
248
|
+
const running = await Promise.all(listeners.map(pid => platform.isProcessRunningAsync(pid)));
|
|
249
|
+
const liveListeners = listeners.filter((_pid, index) => running[index]);
|
|
250
|
+
if (liveListeners.length > 0)
|
|
251
|
+
throw new Error(`ECWeb 端口 ${targetPort} 未释放 (PID: ${liveListeners.join(', ')});已中止重启`);
|
|
193
252
|
await verifyPortReleased(targetPort);
|
|
194
253
|
}
|
|
195
254
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { DEFAULT_ECWEB_PORT, ecwebService } from '../../config/daemon-services.js';
|
|
2
|
+
import { ipcQuery } from '../../ipc.js';
|
|
3
|
+
import { resolvePaths } from '../../paths.js';
|
|
4
|
+
import { resolveEcwebExternalUrl } from '../pairing.js';
|
|
5
|
+
export async function readEcwebProxyAccess(config, options = {}) {
|
|
6
|
+
if (!config.aid && ecwebService(config.services).enabled && ecwebService(config.services).proxy?.enabled) {
|
|
7
|
+
return { state: 'starting', url: null, message: '主机身份待准备;请运行 ec init --web,本地 ECWeb 可继续访问' };
|
|
8
|
+
}
|
|
9
|
+
const url = resolveEcwebExternalUrl(config);
|
|
10
|
+
if (!url)
|
|
11
|
+
return { state: 'disabled', url: null, message: '未启用,保留当前设置' };
|
|
12
|
+
const deadline = Date.now() + (options.timeoutMs ?? 3000);
|
|
13
|
+
let snapshot = options.snapshot;
|
|
14
|
+
if (snapshot === undefined) {
|
|
15
|
+
try {
|
|
16
|
+
const response = await ipcQuery(resolvePaths().socket, { type: 'status' }, Math.max(1, Math.min(1000, deadline - Date.now())));
|
|
17
|
+
snapshot = response?.serviceProxy;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return { state: 'unconfirmed', url: null, message: '运行状态暂不可用;本地初始化不受影响' };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const configured = snapshot?.items.find(service => service.name === 'ecweb');
|
|
24
|
+
if (configured && (!configured.serviceEnabled || !configured.proxyEnabled)) {
|
|
25
|
+
return { state: 'starting', url: null, message: '等待 daemon 应用代理配置' };
|
|
26
|
+
}
|
|
27
|
+
const transport = snapshot?.transport;
|
|
28
|
+
if (!transport)
|
|
29
|
+
return { state: 'unconfirmed', url: null, message: '尚未取得代理运行状态' };
|
|
30
|
+
if (!transport.gatewayRegistered || !transport.registeredServices.includes('ecweb')) {
|
|
31
|
+
return {
|
|
32
|
+
state: transport.state === 'degraded' ? 'failed' : 'starting', url: null,
|
|
33
|
+
message: transport.error ?? '等待控制通道、服务端点与网关登记就绪',
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const timeoutMs = Math.min(2000, deadline - Date.now());
|
|
37
|
+
if (timeoutMs <= 0)
|
|
38
|
+
return { state: 'unconfirmed', url: null, message: '代理已登记,外网连通性尚未验证' };
|
|
39
|
+
try {
|
|
40
|
+
const port = ecwebService(config.services)?.port ?? DEFAULT_ECWEB_PORT;
|
|
41
|
+
const [localResponse, remoteResponse] = await Promise.all([
|
|
42
|
+
fetch(`http://127.0.0.1:${port}/api/health`, { signal: AbortSignal.timeout(timeoutMs), redirect: 'error' }),
|
|
43
|
+
fetch(`${url}/api/health`, { signal: AbortSignal.timeout(timeoutMs), redirect: 'follow' }),
|
|
44
|
+
]);
|
|
45
|
+
if (!localResponse.ok || !remoteResponse.ok) {
|
|
46
|
+
return { state: 'unconfirmed', url: null, message: `代理已登记,外网连通性未确认(本地 HTTP ${localResponse.status},外网 HTTP ${remoteResponse.status})` };
|
|
47
|
+
}
|
|
48
|
+
const [local, remote] = await Promise.all([localResponse.json(), remoteResponse.json()]);
|
|
49
|
+
if (local?.ok === true && remote?.ok === true && local.service === 'ecweb' && remote.service === 'ecweb'
|
|
50
|
+
&& typeof local.instanceId === 'string' && local.instanceId.length > 0 && remote.instanceId === local.instanceId
|
|
51
|
+
&& typeof local.homeId === 'string' && local.homeId.length > 0 && remote.homeId === local.homeId
|
|
52
|
+
&& remote.ready === true && remote.daemonProtocolCompatible === true) {
|
|
53
|
+
return { state: 'ready', url, message: '已就绪' };
|
|
54
|
+
}
|
|
55
|
+
return { state: 'unconfirmed', url: null, message: '代理已登记,外网响应尚未匹配当前就绪实例' };
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return { state: 'unconfirmed', url: null, message: '代理已登记,外网访问暂未验证;可继续本地初始化' };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export async function waitForEcwebProxyAccess(config, timeoutMs = 15000) {
|
|
62
|
+
const deadline = Date.now() + timeoutMs;
|
|
63
|
+
let access;
|
|
64
|
+
do {
|
|
65
|
+
access = await readEcwebProxyAccess(config, { timeoutMs: Math.max(1, deadline - Date.now()) });
|
|
66
|
+
if (access.state === 'ready' || access.state === 'disabled' || !config.aid)
|
|
67
|
+
return access;
|
|
68
|
+
const remaining = deadline - Date.now();
|
|
69
|
+
if (remaining <= 0)
|
|
70
|
+
break;
|
|
71
|
+
await new Promise(resolve => setTimeout(resolve, Math.min(500, remaining)));
|
|
72
|
+
} while (Date.now() < deadline);
|
|
73
|
+
return { ...access, message: `${access.message};本次等待已超时,可继续本地初始化` };
|
|
74
|
+
}
|
|
@@ -246,21 +246,8 @@ export function createEcwebSupervisor(options) {
|
|
|
246
246
|
logFd = null;
|
|
247
247
|
};
|
|
248
248
|
const stopTrackedProcess = (identity, onTiming) => {
|
|
249
|
-
const target = child?.pid === identity.pid ? child :
|
|
250
|
-
|
|
251
|
-
try {
|
|
252
|
-
if (!target.connected)
|
|
253
|
-
return false;
|
|
254
|
-
// The callback handles an asynchronously closed channel without an
|
|
255
|
-
// unhandled child 'error' event. Exit confirmation remains separate.
|
|
256
|
-
target.send({ type: 'ecweb.shutdown' }, () => { });
|
|
257
|
-
return true;
|
|
258
|
-
}
|
|
259
|
-
catch {
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
} : undefined;
|
|
263
|
-
return stopEcwebProcess(identity, undefined, onTiming, requestShutdown);
|
|
249
|
+
const target = child?.pid === identity.pid ? child : undefined;
|
|
250
|
+
return stopEcwebProcess(identity, undefined, onTiming, target);
|
|
264
251
|
};
|
|
265
252
|
const killActive = async (onTiming) => {
|
|
266
253
|
intentionalStop = true;
|
|
@@ -353,9 +340,11 @@ export function createEcwebSupervisor(options) {
|
|
|
353
340
|
if (stopping || !desiredEnabled || runtimeMode !== 'managed')
|
|
354
341
|
return;
|
|
355
342
|
if (occupiedPids.length > 0) {
|
|
356
|
-
options.logger.error(`ECWeb
|
|
343
|
+
options.logger.error(`ECWeb 本次启动失败:端口 ${desiredPort} 被占用 (PID: ${occupiedPids.join(', ')})`);
|
|
357
344
|
failureCount = failureThreshold;
|
|
358
|
-
|
|
345
|
+
// Occupancy can be temporary; keep the unknown owner untouched and
|
|
346
|
+
// retry through the same bounded recovery path as other launch failures.
|
|
347
|
+
scheduleRecovery();
|
|
359
348
|
return;
|
|
360
349
|
}
|
|
361
350
|
fs.mkdirSync(resolvePaths().logs, { recursive: true });
|
|
@@ -19,6 +19,7 @@ import { PublicationLog } from './event-log.js';
|
|
|
19
19
|
import { ScriptRunner } from './script-runner.js';
|
|
20
20
|
import { errorMessage } from './types.js';
|
|
21
21
|
import { readBusResolverContext } from './directory-source.js';
|
|
22
|
+
import { registerOutputEvent, outputAllowlist } from '../outputs/events.js';
|
|
22
23
|
/** 旧方案残留的订阅 Trigger(labels.kind=bus-subscription),启动时一次性清理。 */
|
|
23
24
|
const LEGACY_SUBSCRIPTION_KIND = 'bus-subscription';
|
|
24
25
|
/** 解析上下文签名:只有 owner/pa/paRoles 三要素参与(fetchedAt 等时间戳字段不参与,
|
|
@@ -64,6 +65,15 @@ export class EventCenterRegistry {
|
|
|
64
65
|
values() {
|
|
65
66
|
return this.units.values();
|
|
66
67
|
}
|
|
68
|
+
/** Publish a fixed event from an internal read-only projection when configured. */
|
|
69
|
+
async publishAgentEvent(aid, event, data) {
|
|
70
|
+
if (event !== 'team.outputs.changed' && event !== 'team.workbench.changed')
|
|
71
|
+
return;
|
|
72
|
+
const unit = this.units.get(aid);
|
|
73
|
+
if (!unit)
|
|
74
|
+
return;
|
|
75
|
+
await unit.runtime.publishNativeProjection(event, data);
|
|
76
|
+
}
|
|
67
77
|
ensureStarted(aid) {
|
|
68
78
|
const existing = this.starts.get(aid);
|
|
69
79
|
if (existing)
|
|
@@ -185,6 +195,7 @@ export class EventCenterRegistry {
|
|
|
185
195
|
// ① 扫描 + 校验。
|
|
186
196
|
const loaded = loadPacks(eventsDir);
|
|
187
197
|
const state = buildPackState(loaded.valid, loaded.invalid.map(item => ({ id: item.packId, errors: item.errors })));
|
|
198
|
+
registerOutputEvent(state);
|
|
188
199
|
// ② 台账:invalid / load(签名去重)。
|
|
189
200
|
for (const item of loaded.invalid) {
|
|
190
201
|
const reason = item.errors.join('; ').slice(0, 500);
|
|
@@ -262,7 +273,7 @@ export class EventCenterRegistry {
|
|
|
262
273
|
for (const error of centerResult.errors) {
|
|
263
274
|
logger.warn(`[EventCenter] ${aid} events-config.json: ${error}`);
|
|
264
275
|
}
|
|
265
|
-
const materialized = materializeAllowlist(centerResult.config, agentDirPath, aid, runtimeState.catalog.map(entry => entry.event));
|
|
276
|
+
const materialized = outputAllowlist(aid, materializeAllowlist(centerResult.config, agentDirPath, aid, runtimeState.catalog.map(entry => entry.event)));
|
|
266
277
|
// contacts 监听需求:包里有占位符引用(含被解析淘汰的包——它们在 enabledPacks 里)
|
|
267
278
|
// 或上次解析有失败/degraded(等 contacts 到位后重解析)。
|
|
268
279
|
const usesPlaceholderRefs = loaded.valid.some(pack => [...pack.publish, ...pack.subscribe].some(entry => isBusPlaceholder(entry.bus)));
|
|
@@ -344,7 +355,7 @@ export class EventCenterRegistry {
|
|
|
344
355
|
getClient: this.options.getClient,
|
|
345
356
|
contactsPath: path.join(agentDirPath, 'directory', 'contacts.json'),
|
|
346
357
|
onContactsChanged: () => this.handleContactsChanged(aid),
|
|
347
|
-
materializeAllowlist: (center, registeredEvents) => materializeAllowlist(center, agentDirPath, aid, registeredEvents),
|
|
358
|
+
materializeAllowlist: (center, registeredEvents) => outputAllowlist(aid, materializeAllowlist(center, agentDirPath, aid, registeredEvents)),
|
|
348
359
|
onBusRequestRejected: entry => centerLedger(eventsDir).append({
|
|
349
360
|
action: 'bus.request.rejected', result: 'failed', aid: entry.aid, operation: entry.operation,
|
|
350
361
|
...(entry.event ? { event: entry.event } : {}), ...(entry.action ? { direction: entry.action } : {}),
|