evolcore 0.0.43-test.3 → 0.0.43-test.4
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 +36 -0
- package/bin/ecmsg.js +229 -0
- package/bin/install-codex-managed-hooks.mjs +130 -8
- package/dist/ability/application-service.js +37 -0
- package/dist/ability/resources.js +28 -0
- package/dist/ability/runtime.js +6 -1
- package/dist/agents/claude-runner.js +7 -5
- package/dist/agents/codex/app-server-client.js +0 -12
- package/dist/agents/codex-runner.js +0 -37
- package/dist/agents/ecagent-runner.js +130 -35
- package/dist/aun/aid/agentmd.js +31 -12
- package/dist/aun/menu/client.js +8 -7
- package/dist/aun/menu/index.js +1 -1
- package/dist/aun/menu/transport.js +8 -5
- package/dist/aun/service-proxy.js +3 -0
- package/dist/channels/aun.js +26 -5
- package/dist/channels/daemon.js +10 -2
- package/dist/cli/agent-command.js +5 -0
- package/dist/cli/agent-create.js +28 -6
- package/dist/cli/agent.js +9 -3
- package/dist/cli/aun-commands.js +2 -2
- package/dist/cli/daemon-commands.js +30 -18
- package/dist/cli/directory.js +4 -7
- package/dist/cli/getmeta-command.js +2 -1
- package/dist/cli/init.js +13 -5
- package/dist/cli/trigger-command.js +20 -14
- package/dist/config/boot-log.js +12 -2
- package/dist/config/config-field-policy.js +2 -0
- package/dist/config/config-manager.js +9 -4
- package/dist/config/peer-role-resolver.js +1 -1
- package/dist/config/role-schema.js +3 -3
- package/dist/config/schema-migration.js +121 -0
- package/dist/core/agent-application-service.js +11 -0
- package/dist/core/agent-ipc-registration.js +2 -0
- package/dist/core/agent-runtime.js +41 -9
- package/dist/core/auth/auth-gateway.js +3 -3
- package/dist/core/auth/operation-authorizer.js +2 -1
- package/dist/core/baseagent-loader.js +11 -3
- package/dist/core/bootstrap-service.js +8 -0
- package/dist/core/channel-loader.js +61 -23
- package/dist/core/command/agent-control.js +4 -1
- package/dist/core/command/chatmode-config.js +46 -0
- package/dist/core/command/command-handler.js +5 -14
- package/dist/core/command/daemon-diagnostics.js +2 -1
- package/dist/core/command/menu-catalog.js +1 -1
- package/dist/core/command/menu-handler.js +16 -16
- package/dist/core/command/slash-handler.js +4 -26
- package/dist/core/daemon-lifecycle.js +35 -17
- package/dist/core/event-catalog.js +19 -0
- package/dist/core/evolagent-registry.js +3 -0
- package/dist/core/ipc-registration.js +6 -0
- package/dist/core/message/im-renderer.js +24 -19
- package/dist/core/message/message-admission.js +11 -2
- package/dist/core/message/response-engine.js +17 -18
- package/dist/core/model/model-capabilities.js +37 -0
- package/dist/core/model/model-catalog.js +6 -2
- package/dist/core/ownership/owner-resolver.js +6 -6
- package/dist/core/permission/ec-command-parser.js +47 -12
- package/dist/core/plugin-lifecycle.js +6 -2
- package/dist/core/relation/pa-team.js +7 -2
- package/dist/directory/owner-directory-cache.js +4 -2
- package/dist/directory/owner-directory-query-operation.js +5 -7
- package/dist/ecweb/runtime/lifecycle.js +29 -5
- package/dist/ecweb/runtime/supervisor.js +83 -27
- package/dist/index.js +198 -38
- package/dist/proxy/service-supervisor.js +377 -141
- package/dist/trigger/audit.js +3 -2
- package/dist/trigger/authorization.js +2 -3
- package/dist/trigger/history.js +4 -3
- package/dist/trigger/ipc-service.js +24 -19
- package/dist/trigger/manager.js +3 -5
- package/dist/trigger/parser.js +4 -21
- package/dist/trigger/patch.js +3 -15
- package/dist/trigger/scheduler.js +45 -10
- package/dist/trigger/validation.js +0 -13
- package/dist/utils/error-utils.js +8 -0
- package/dist/utils/macos-autostart.js +31 -0
- package/dist/utils/model-prices.jsonl +15 -8
- package/dist/utils/process-introspect.js +21 -1
- package/dist/utils/startup-trace.js +7 -1
- package/dist/utils/windows-autostart.js +1 -0
- package/ecagent/dist/harness/compaction/branch-summarization.js +1 -1
- package/ecagent/dist/harness/compaction/compaction.js +4 -4
- package/kits/docs/evolcore/INDEX.md +1 -1
- package/kits/docs/evolcore/file-navigation.md +63 -49
- package/kits/docs/evolcore/menu-protocol.md +1 -0
- package/kits/docs/evolcore/model.md +5 -3
- package/kits/docs/evolcore/response.md +2 -0
- package/kits/docs/evolcore/thread-chain.md +1 -1
- package/kits/docs/evolcore/tool-authorization.md +4 -1
- package/kits/docs/evolcore/trigger.md +10 -7
- package/kits/eck_manifest.json +0 -21
- package/kits/rules/01-overview.md +42 -44
- package/kits/rules/02-navigation.md +44 -53
- package/kits/rules/03-identity.md +21 -25
- package/kits/rules/04-relation.md +23 -33
- package/kits/rules/05-venue.md +24 -25
- package/kits/schemas/_meta.json +13 -26
- package/kits/schemas/agent-config.schema.19.json +10 -6
- package/kits/schemas/relation-config.schema.12.json +2 -2
- package/kits/schemas/role-config.schema.2.json +5 -5
- package/kits/skills/ec-service-proxy/SKILL.md +10 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/templates/system-fragments/commands.md +1 -1
- package/kits/templates/system-fragments/identity.md +0 -1
- package/package.json +18 -13
- package/kits/schemas/agent-config.schema.20.json +0 -925
- package/kits/schemas/relation-config.schema.13.json +0 -289
- package/kits/schemas/role-config.schema.3.json +0 -1038
|
@@ -2439,7 +2439,7 @@ export class ResponseEngine {
|
|
|
2439
2439
|
.catch(error => logger.warn(`[ResponseEngine] compact-start notice send failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
2440
2440
|
}
|
|
2441
2441
|
async emitOperationalNotice(renderer, text, severity, subtype) {
|
|
2442
|
-
if (await renderer.
|
|
2442
|
+
if (await renderer.sendOperationalNotice(text, subtype))
|
|
2443
2443
|
return;
|
|
2444
2444
|
renderer.addNotice(text, severity, subtype, true);
|
|
2445
2445
|
}
|
|
@@ -2489,7 +2489,7 @@ export class ResponseEngine {
|
|
|
2489
2489
|
}
|
|
2490
2490
|
: modelOverride;
|
|
2491
2491
|
// text event 在进入 renderer 前已经剔除了上下文超限错误行。保留缓冲中的
|
|
2492
|
-
// 有效正文,由
|
|
2492
|
+
// 有效正文,由 sendOperationalNotice 先 flush,避免恢复过程丢失已有模型输出。
|
|
2493
2493
|
await this.emitOperationalNotice(renderer, '上下文过长,正在压缩会话...', 'warn', 'compact-trigger');
|
|
2494
2494
|
await renderer.flush();
|
|
2495
2495
|
this.announcedCompactStarts.add(session.id);
|
|
@@ -3822,11 +3822,9 @@ export class ResponseEngine {
|
|
|
3822
3822
|
: isShowActivitiesMode(effectiveAgentConfig?.show_activities)
|
|
3823
3823
|
? effectiveAgentConfig.show_activities
|
|
3824
3824
|
: legacyMiddleOutputMode();
|
|
3825
|
-
const middleOutputMode = isProactive
|
|
3826
|
-
? '
|
|
3827
|
-
:
|
|
3828
|
-
? 'none'
|
|
3829
|
-
: configuredMiddleOutputMode;
|
|
3825
|
+
const middleOutputMode = systemOrServicePeer && !isProactive
|
|
3826
|
+
? 'none'
|
|
3827
|
+
: configuredMiddleOutputMode;
|
|
3830
3828
|
outputState.middleOutputMode = middleOutputMode;
|
|
3831
3829
|
// 诊断日志:记录 inbound message_id 和生成的 task_id 的对应关系
|
|
3832
3830
|
logger.info(`[ResponseEngine] task.started: inboundMsgId=${message.messageId ?? 'none'} taskId=${taskId} sessionId=${session.id} chatmode=${chatmode} mode=${resolvedMode?.mode.id ?? 'override/fallback'}`);
|
|
@@ -4294,11 +4292,11 @@ export class ResponseEngine {
|
|
|
4294
4292
|
agentAid: session.selfAID,
|
|
4295
4293
|
permissionMode: () => effectivePermissionMode,
|
|
4296
4294
|
flushDelay: (options?.flushDelay ?? this.agentRegistry?.resolveByChannel(channelKey)?.config?.flush_delay ?? 3) * 1000,
|
|
4297
|
-
suppressActivityItems:
|
|
4298
|
-
suppressIntermediateText:
|
|
4295
|
+
suppressActivityItems: middleOutputMode !== 'all',
|
|
4296
|
+
suppressIntermediateText: middleOutputMode === 'none',
|
|
4299
4297
|
deferTextUntilBoundary: (message.channelType ?? session.channelType) === 'aun' && session.chatType === 'private',
|
|
4300
4298
|
noopSentinel: message.source === 'trigger' ? message.triggerMeta?.noopSentinel : undefined,
|
|
4301
|
-
|
|
4299
|
+
operationalNoticesEnabled: !isProactive && middleOutputMode !== 'none',
|
|
4302
4300
|
fileMarkerPattern: options?.fileMarkerPattern,
|
|
4303
4301
|
recordActivity: async (item, activityId) => {
|
|
4304
4302
|
if (!taskActivityStore || (turnLease && !this.turnCoordinator.canPublish(turnLease)))
|
|
@@ -4402,7 +4400,7 @@ export class ResponseEngine {
|
|
|
4402
4400
|
}
|
|
4403
4401
|
renderer.addLifecycle('started');
|
|
4404
4402
|
if (isProactive) {
|
|
4405
|
-
logger.info(`[ResponseEngine] proactive mode:
|
|
4403
|
+
logger.info(`[ResponseEngine] proactive mode: thought visibility=${middleOutputMode} task=${taskId}`);
|
|
4406
4404
|
}
|
|
4407
4405
|
// 调用 AgentRunner(含上下文过长自动 compact 重试)
|
|
4408
4406
|
// 捕获当前消息的上下文(闭包),避免后续消息处理时串台
|
|
@@ -4643,15 +4641,15 @@ export class ResponseEngine {
|
|
|
4643
4641
|
chatmode: effectiveChatMode,
|
|
4644
4642
|
// 系统会话没有角色
|
|
4645
4643
|
role: systemSessionMarker ? undefined : peerRole,
|
|
4646
|
-
|
|
4644
|
+
internalContactAuthorization: !systemSessionMarker && configChannelType === 'aun' && configChatType === 'private'
|
|
4647
4645
|
&& !!selfAid && !!configActorId && (paTeamQualification(selfAid, configActorId) === 'matched'
|
|
4648
4646
|
|| requiresPaTeamVerification(selfAid, configActorId)),
|
|
4649
|
-
|
|
4647
|
+
internalContactDefaultRole: peerRoleDetail?.source === 'internal-contact-default'
|
|
4650
4648
|
|| (authorizationIdentity?.role === peerRole && configChannelType === 'aun'
|
|
4651
4649
|
&& configChatType === 'private' && !!selfAid && !!configActorId
|
|
4652
4650
|
&& resolvePeerRoleDetail({ selfAid, channelKey: authorizationIdentity.originChannelKey, channelType: 'aun', chatType: 'private',
|
|
4653
|
-
actorId: configActorId, conversationId: configActorId }).source === '
|
|
4654
|
-
|
|
4651
|
+
actorId: configActorId, conversationId: configActorId }).source === 'internal-contact-default'),
|
|
4652
|
+
internalContactPolicy: JSON.stringify(getRoleDefinition(peerRole, selfAid)),
|
|
4655
4653
|
chatType: authChatType,
|
|
4656
4654
|
selfAid,
|
|
4657
4655
|
managedTempDir: sessionRuntimeDir,
|
|
@@ -6257,9 +6255,10 @@ export class ResponseEngine {
|
|
|
6257
6255
|
// 由响应模式插件统一处理(InteractiveMode.afterProcess / ProactiveMode.afterProcess)
|
|
6258
6256
|
const finalReplyText = streamResult.lastReplyText || streamResult.fullText;
|
|
6259
6257
|
const visibleFinalReplyText = stripContextLimitErrorLines(finalReplyText);
|
|
6260
|
-
const
|
|
6258
|
+
const triggerNoopSentinel = message.source === 'trigger' ? message.triggerMeta?.noopSentinel : undefined;
|
|
6259
|
+
const isNoopReply = !!triggerNoopSentinel && !streamResult.isError
|
|
6261
6260
|
&& !isExpectedTerminalInterrupt(streamResult.terminalReason)
|
|
6262
|
-
&& isNoopText(visibleFinalReplyText,
|
|
6261
|
+
&& isNoopText(visibleFinalReplyText, triggerNoopSentinel);
|
|
6263
6262
|
if (resolvedMode?.mode.afterProcess && !isNoopReply) {
|
|
6264
6263
|
const flusherText = renderer.getFinalText();
|
|
6265
6264
|
const fullText = flusherText.length >= (streamResult.fullText?.length || 0) ? flusherText : streamResult.fullText;
|
|
@@ -7161,7 +7160,7 @@ export class ResponseEngine {
|
|
|
7161
7160
|
await adapter.send(withEnvelopeReplyContext(envelope, sendOpts), errorPayload);
|
|
7162
7161
|
}
|
|
7163
7162
|
// Proactive 可观测:catch 块的基础设施错误也透传为 thought,保证按 task_id 聚合完整
|
|
7164
|
-
if (isProactive && adapter.capabilities?.thought) {
|
|
7163
|
+
if (isProactive && adapter.capabilities?.thought && middleOutputMode === 'all') {
|
|
7165
7164
|
await adapter.send(withEnvelopeReplyContext(envelope, sendOpts), {
|
|
7166
7165
|
kind: 'activity.batch',
|
|
7167
7166
|
items: [{
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { findModelSpec } from '../../stats/price-resolver.js';
|
|
2
|
+
import { resolveCatalogModel } from './catalog-service.js';
|
|
3
|
+
import { parseModelId } from './context-window-suffix.js';
|
|
4
|
+
export function resolveModelCapabilities(evolcoreHome, modelId, options) {
|
|
5
|
+
const model = options.catalog ? resolveCatalogModel(options.catalog, modelId) : modelId;
|
|
6
|
+
const entry = options.catalog?.models.find(candidate => candidate.id === model);
|
|
7
|
+
const spec = findModelSpec(evolcoreHome, model);
|
|
8
|
+
const positiveToken = (value) => typeof value === 'number' && Number.isFinite(value) && value >= 1;
|
|
9
|
+
const windowCandidates = [
|
|
10
|
+
[parseModelId(model).contextWindow, 'explicit-suffix'],
|
|
11
|
+
[options.runtimeContextWindow, 'runtime-report'],
|
|
12
|
+
[entry?.contextWindow, 'provider-catalog'],
|
|
13
|
+
[spec?.context_window, 'local-parameters'],
|
|
14
|
+
[options.fallbackContextWindow, 'safe-fallback'],
|
|
15
|
+
];
|
|
16
|
+
const outputCandidates = [
|
|
17
|
+
[entry?.maxOutputTokens, 'provider-catalog'],
|
|
18
|
+
[spec?.max_output_tokens, 'local-parameters'],
|
|
19
|
+
[options.fallbackMaxOutputTokens ?? 8192, 'safe-fallback'],
|
|
20
|
+
];
|
|
21
|
+
const window = windowCandidates.find(([value]) => positiveToken(value));
|
|
22
|
+
const output = outputCandidates.find(([value]) => positiveToken(value));
|
|
23
|
+
if (!window || !output)
|
|
24
|
+
throw new Error('No valid model capabilities for ' + model);
|
|
25
|
+
const contextWindow = Math.floor(window[0]);
|
|
26
|
+
return {
|
|
27
|
+
model,
|
|
28
|
+
contextWindow,
|
|
29
|
+
maxOutputTokens: Math.max(1, Math.min(Math.floor(output[0]), contextWindow - 1)),
|
|
30
|
+
contextWindowSource: window[1],
|
|
31
|
+
maxOutputTokensSource: output[1],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function resolveAutoCompactWindow(contextWindow, maxOutputTokens, reserveTokens) {
|
|
35
|
+
const safetyReserve = Math.min(10_000, Math.floor(contextWindow * 0.05));
|
|
36
|
+
return Math.min(650_000, Math.max(1, contextWindow - Math.max(reserveTokens, maxOutputTokens, safetyReserve)));
|
|
37
|
+
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { clearRuntimeBaseagentModelDefaults } from '../../agents/baseagent.js';
|
|
7
|
+
import { buildModelRequestHeaders } from '../../agents/request-identity.js';
|
|
7
8
|
import { activeBaseagent } from './config-scope.js';
|
|
8
9
|
import { resolveEffective } from '../../config/config-manager.js';
|
|
9
10
|
import { readRuntimeEnvironmentVariable } from '../../config/runtime-env.js';
|
|
@@ -137,7 +138,8 @@ export function resolveCatalogContext(self, ba) {
|
|
|
137
138
|
if (envBaseUrl) {
|
|
138
139
|
const envApiKey = readRuntimeEnvironmentVariable('ANTHROPIC_AUTH_TOKEN', self).value
|
|
139
140
|
?? readRuntimeEnvironmentVariable('ANTHROPIC_API_KEY', self).value;
|
|
140
|
-
return { ...context, baseUrl: envBaseUrl, apiKey: envApiKey, style: 'claude'
|
|
141
|
+
return { ...context, baseUrl: envBaseUrl, apiKey: envApiKey, style: 'claude',
|
|
142
|
+
headers: buildModelRequestHeaders({ baseagent: 'claude', baseUrl: envBaseUrl, agentAid: self }) };
|
|
141
143
|
}
|
|
142
144
|
}
|
|
143
145
|
// 模型选择只在 Agent 级且必须指向 provider;没有 provider 就没有目录可查。
|
|
@@ -152,7 +154,9 @@ export function resolveCatalogContext(self, ba) {
|
|
|
152
154
|
style: provider.style,
|
|
153
155
|
baseUrl: provider.baseUrl,
|
|
154
156
|
apiKey: provider.apiKey,
|
|
155
|
-
headers:
|
|
157
|
+
headers: baseagent === 'claude' || baseagent === 'codex' || baseagent === 'ecagent'
|
|
158
|
+
? buildModelRequestHeaders({ baseagent, baseUrl: provider.baseUrl, agentAid: self, configuredHeaders: provider.headers })
|
|
159
|
+
: provider.headers,
|
|
156
160
|
queryParams: provider.queryParams,
|
|
157
161
|
modelOverrides: provider.modelOverrides,
|
|
158
162
|
});
|
|
@@ -425,7 +425,7 @@ export class OwnerResolver {
|
|
|
425
425
|
return this.snapshot(subjectAid);
|
|
426
426
|
}
|
|
427
427
|
const ownerAid = consensus.status === 'consensus' && consensus.sub_aid === subjectAid
|
|
428
|
-
&& typeof consensus.owner_aid === 'string' && isValidAid(consensus.owner_aid)
|
|
428
|
+
&& typeof consensus.owner_aid === 'string' && isValidAid(consensus.owner_aid) && consensus.owner_aid !== subjectAid
|
|
429
429
|
? consensus.owner_aid : undefined;
|
|
430
430
|
if (consensus.sub_aid !== subjectAid || (consensus.status === 'consensus' && !ownerAid)) {
|
|
431
431
|
throw new Error('Ownership consensus contains a mismatched subject or invalid owner');
|
|
@@ -1298,7 +1298,7 @@ export class OwnerResolver {
|
|
|
1298
1298
|
throw new OwnershipError('TASK_MISMATCH', 'Ownership consensus subject does not match');
|
|
1299
1299
|
}
|
|
1300
1300
|
const ownerAid = consensus.status === 'consensus' && typeof consensus.owner_aid === 'string'
|
|
1301
|
-
&& isValidAid(consensus.owner_aid) ? consensus.owner_aid : undefined;
|
|
1301
|
+
&& isValidAid(consensus.owner_aid) && consensus.owner_aid !== subjectAid ? consensus.owner_aid : undefined;
|
|
1302
1302
|
if (consensus.status === 'consensus' && !ownerAid) {
|
|
1303
1303
|
this.invalidate(subject, 'Ownership consensus owner is invalid');
|
|
1304
1304
|
throw new OwnershipError('TASK_MISMATCH', 'Ownership consensus owner is invalid');
|
|
@@ -1613,7 +1613,7 @@ export async function refreshOwnershipForAuthorization(subjectAid, options = {})
|
|
|
1613
1613
|
}
|
|
1614
1614
|
}
|
|
1615
1615
|
export async function assertOwnershipAuthorization(context) {
|
|
1616
|
-
if (context?.
|
|
1616
|
+
if (context?.internalContactAuthorization && context.selfAid && context.actor?.principalId) {
|
|
1617
1617
|
const { preparePaTeamQualification } = await import('../relation/pa-team.js');
|
|
1618
1618
|
const { resolvePeerRoleDetail } = await import('../../config/peer-role-resolver.js');
|
|
1619
1619
|
const { getRoleDefinition } = await import('../../config/roles.js');
|
|
@@ -1623,9 +1623,9 @@ export async function assertOwnershipAuthorization(context) {
|
|
|
1623
1623
|
chatType: 'private', actorId: context.actor.principalId, conversationId: context.actor.principalId,
|
|
1624
1624
|
});
|
|
1625
1625
|
if (!current.allowAccess || current.effectiveRole !== context.role
|
|
1626
|
-
|| (context.
|
|
1627
|
-
|| (context.
|
|
1628
|
-
throw new OwnershipError('
|
|
1626
|
+
|| (context.internalContactDefaultRole && current.source !== 'internal-contact-default')
|
|
1627
|
+
|| (context.internalContactPolicy !== undefined && context.internalContactPolicy !== JSON.stringify(getRoleDefinition(context.role ?? '', context.selfAid)))) {
|
|
1628
|
+
throw new OwnershipError('INTERNAL_CONTACT_AUTHORIZATION_CHANGED', 'Internal-contact authorization changed; start a new task with the current role');
|
|
1629
1629
|
}
|
|
1630
1630
|
}
|
|
1631
1631
|
const authorization = context?.executionPermission;
|
|
@@ -328,6 +328,16 @@ const CODEX_POWERSHELL_INERT_SWITCHES = new Set([
|
|
|
328
328
|
// intentionally not treated as a trusted Codex carrier.
|
|
329
329
|
const CODEX_CMD_INERT_SWITCHES = new Set(['/d', '/s', '/q', '/a', '/u']);
|
|
330
330
|
const EVOLCORE_EXECUTABLE_ALIASES = new Set(['ec', 'ec.cmd', 'ec.exe', 'ec.ps1']);
|
|
331
|
+
/**
|
|
332
|
+
* 轻量发送入口 `ecmsg` 的前缀映射:`ecmsg <args...>` 等价于 `ec msg <args...>`。
|
|
333
|
+
*
|
|
334
|
+
* 必须在这里归一,不能只做一个独立脚本——委托审批是按规范化 argv 的哈希
|
|
335
|
+
* arm 的(codex-runner 的 armApprovedDelegationCommand)。若 `ecmsg` 不归一到
|
|
336
|
+
* `['ec','msg',...]`,策略层会把它当普通命令(kind: 'none'),既不 arm 审批,
|
|
337
|
+
* daemon 侧也算不出匹配的哈希,最终必然 INVALID_DELEGATION;更糟的是它会绕过
|
|
338
|
+
* ec_shell_composite_command 与会话身份绑定,成为冒充发送的后门。
|
|
339
|
+
*/
|
|
340
|
+
const EVOLCORE_MSG_ENTRY_ALIASES = new Set(['ecmsg', 'ecmsg.cmd', 'ecmsg.exe', 'ecmsg.ps1']);
|
|
331
341
|
const EVOLCORE_NODE_EXECUTABLES = new Set(['node', 'node.exe']);
|
|
332
342
|
const APPLY_PATCH_EXECUTABLE_BASENAMES = new Set([
|
|
333
343
|
'apply_patch',
|
|
@@ -439,6 +449,10 @@ function hasEcCommandPrefix(command) {
|
|
|
439
449
|
continue;
|
|
440
450
|
if (boundary && /^ec(?:\.cmd|\.exe|\.ps1)?(?=$|\s|[;&|`()<>])/i.test(command.slice(index)))
|
|
441
451
|
return true;
|
|
452
|
+
// `ecmsg` 是 `ec msg` 的同义词,同样算 EC 命令边界——否则
|
|
453
|
+
// `ecmsg ... && rm -rf /` 会落成 kind:'none',绕过复合命令拦截。
|
|
454
|
+
if (boundary && /^ecmsg(?:\.cmd|\.exe|\.ps1)?(?=$|\s|[;&|`()<>])/i.test(command.slice(index)))
|
|
455
|
+
return true;
|
|
442
456
|
boundary = false;
|
|
443
457
|
}
|
|
444
458
|
return false;
|
|
@@ -694,6 +708,17 @@ function hasCarrierEcCommandPrefix(command, dialect) {
|
|
|
694
708
|
return /^\s*ec(?:\.cmd|\.exe|\.ps1)?(?:\s|$)/i.test(inner);
|
|
695
709
|
}
|
|
696
710
|
/** Normalize the Windows npm shims to the canonical EvolCore CLI name. */
|
|
711
|
+
/**
|
|
712
|
+
* 取可执行名的 basename(小写)。与 hasEcCommandPrefix 里的算法一致:
|
|
713
|
+
* 兼容 `C:\path\ecmsg.cmd` 与 `./ecmsg` 这类调用形态。
|
|
714
|
+
*/
|
|
715
|
+
function executableBasename(value) {
|
|
716
|
+
if (!value)
|
|
717
|
+
return undefined;
|
|
718
|
+
const normalized = value.replaceAll('\\', '/');
|
|
719
|
+
const base = normalized.slice(normalized.lastIndexOf('/') + 1).toLowerCase();
|
|
720
|
+
return base || undefined;
|
|
721
|
+
}
|
|
697
722
|
export function normalizeEvolcoreCommandArgv(argv) {
|
|
698
723
|
if (argv.length === 0)
|
|
699
724
|
return [];
|
|
@@ -702,6 +727,12 @@ export function normalizeEvolcoreCommandArgv(argv) {
|
|
|
702
727
|
if (typeof executable === 'string' && EVOLCORE_EXECUTABLE_ALIASES.has(executable.toLowerCase())) {
|
|
703
728
|
return ['ec', ...materialized.slice(1)];
|
|
704
729
|
}
|
|
730
|
+
// `ecmsg` 是 `ec msg` 的同义词:归一到 EC 命令族,才能进入同一条
|
|
731
|
+
// 审批、委托与复合命令拦截链路(见 EVOLCORE_MSG_ENTRY_ALIASES 注释)。
|
|
732
|
+
const entryAlias = executableBasename(executable);
|
|
733
|
+
if (entryAlias && EVOLCORE_MSG_ENTRY_ALIASES.has(entryAlias)) {
|
|
734
|
+
return ['ec', 'msg', ...materialized.slice(1)];
|
|
735
|
+
}
|
|
705
736
|
if (typeof executable === 'string' && isNodeExecutable(executable) && materialized.length >= 2
|
|
706
737
|
&& typeof materialized[1] === 'string' && normalizeNodeWrapperPath(materialized[1])) {
|
|
707
738
|
return ['ec', ...materialized.slice(2)];
|
|
@@ -1567,17 +1598,18 @@ function resolveCodexPowerShellCarrierString(command) {
|
|
|
1567
1598
|
let nested = match[4].trim();
|
|
1568
1599
|
let failure;
|
|
1569
1600
|
if (nested.startsWith('"') || nested.startsWith("'")) {
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1601
|
+
// The outer `-Command` argument is a PowerShell string literal. Strip
|
|
1602
|
+
// that one transport-level pair without tokenizing the body as POSIX
|
|
1603
|
+
// shell: doing so removes the `$env:` assignment marker and collapses
|
|
1604
|
+
// doubled single quotes around the credential token before the
|
|
1605
|
+
// PowerShell credential-prefix parser sees them.
|
|
1606
|
+
const quote = nested[0];
|
|
1607
|
+
if (nested.length >= 2 && nested.endsWith(quote)) {
|
|
1608
|
+
nested = nested.slice(1, -1);
|
|
1573
1609
|
}
|
|
1574
1610
|
else {
|
|
1575
|
-
failure =
|
|
1576
|
-
|
|
1577
|
-
: { ...parsed, dialect: 'powershell' };
|
|
1578
|
-
nested = nested.length > 1 && nested.endsWith(nested[0])
|
|
1579
|
-
? nested.slice(1, -1)
|
|
1580
|
-
: nested.slice(1);
|
|
1611
|
+
failure = parseFailure('invalid-quote', nested, 0, 0, 'powershell');
|
|
1612
|
+
nested = nested.slice(1);
|
|
1581
1613
|
}
|
|
1582
1614
|
}
|
|
1583
1615
|
const switches = match[3].trim().split(/[ \t]+/);
|
|
@@ -2965,12 +2997,15 @@ export function parseCdPrefixedEcCommand(input) {
|
|
|
2965
2997
|
*/
|
|
2966
2998
|
function parseEcTail(segment) {
|
|
2967
2999
|
const literal = parseLiteralShellArgv(segment);
|
|
3000
|
+
// 归一化后再判首元素:`ecmsg ...` 等价于 `ec msg ...`,必须与 ec 同权进审批链。
|
|
3001
|
+
// 返回的 argv 也必须是归一化后的形态,否则审批哈希与 daemon 侧解析会错位。
|
|
2968
3002
|
if (literal && literal.length > 0 && normalizeEvolcoreCommandArgv(literal)[0] === 'ec') {
|
|
2969
|
-
return { argv: literal, mergeStderr: false };
|
|
3003
|
+
return { argv: normalizeEvolcoreCommandArgv(literal), mergeStderr: false };
|
|
2970
3004
|
}
|
|
2971
3005
|
const bounded = parseBoundedOutputShellCommand(segment);
|
|
2972
|
-
if (bounded && bounded.argv[0] === 'ec')
|
|
2973
|
-
return bounded;
|
|
3006
|
+
if (bounded && normalizeEvolcoreCommandArgv(bounded.argv)[0] === 'ec') {
|
|
3007
|
+
return { ...bounded, argv: normalizeEvolcoreCommandArgv(bounded.argv) };
|
|
3008
|
+
}
|
|
2974
3009
|
return null;
|
|
2975
3010
|
}
|
|
2976
3011
|
/**
|
|
@@ -97,7 +97,11 @@ export class PluginHandle {
|
|
|
97
97
|
this.timeouts.set(timer, release);
|
|
98
98
|
return timer;
|
|
99
99
|
}
|
|
100
|
-
|
|
100
|
+
/**
|
|
101
|
+
* `options.teardownBudgetMs` 只给进程退出路径用,透传给 teardown(目前只有 AUN 渠道
|
|
102
|
+
* 的 `client.close()` 关心):daemon 反正马上 `exit(0)`,等不满的网络握手没有意义。
|
|
103
|
+
*/
|
|
104
|
+
dispose(options = {}) {
|
|
101
105
|
if (this.disposal)
|
|
102
106
|
return this.disposal;
|
|
103
107
|
this.currentState = 'disposing';
|
|
@@ -118,7 +122,7 @@ export class PluginHandle {
|
|
|
118
122
|
...pending.map(([operation, label]) => cleanup(operation, label)),
|
|
119
123
|
]);
|
|
120
124
|
try {
|
|
121
|
-
await this.teardown?.();
|
|
125
|
+
await this.teardown?.(options.teardownBudgetMs);
|
|
122
126
|
}
|
|
123
127
|
catch (cause) {
|
|
124
128
|
errors.push(new Error(`Plugin ${this.owner}: teardown`, { cause }));
|
|
@@ -73,8 +73,13 @@ export async function preparePaTeamQualification(selfAid, peerAid) {
|
|
|
73
73
|
throw new Error('Mismatched PA profile');
|
|
74
74
|
return profile;
|
|
75
75
|
});
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
// The same-owner proof is now the internal-agent qualification. Keep the
|
|
77
|
+
// pa-team API names for registry/config compatibility, but do not require
|
|
78
|
+
// an exttype prefix: non-PA agents owned by the same Owner are internal
|
|
79
|
+
// contacts as well. Human/service/device identities do not participate in
|
|
80
|
+
// this automatic role because they cannot provide the required agent.md
|
|
81
|
+
// ownership statement used by the protocol consensus check.
|
|
82
|
+
if (!profiles.every(profile => String(profile.type || '').trim().toLowerCase() === 'agent'))
|
|
78
83
|
return 'unmatched';
|
|
79
84
|
const consensuses = await Promise.all([selfAid, peerAid].map(aid => runtime.client.checkOwnershipConsensus(aid, true)));
|
|
80
85
|
for (const [index, consensus] of consensuses.entries()) {
|
|
@@ -1069,7 +1069,9 @@ export class OwnerDirectoryCache {
|
|
|
1069
1069
|
if (personalAssistant !== undefined && !isRecord(personalAssistant)) {
|
|
1070
1070
|
throw new OwnerDirectoryCacheError('INVALID_FIELD', `${scope}.json personal_assistant is not an object`);
|
|
1071
1071
|
}
|
|
1072
|
-
//
|
|
1072
|
+
// 摘要以服务端为准:本地重算只用来报告口径差异,不作为拒绝依据。
|
|
1073
|
+
// Owner 存储上的那份文件就是权威内容,摘要算法在两端不一致时(例如服务端
|
|
1074
|
+
// 改了参与摘要的字段),拒绝会让整份名录永远拉不下来,且重试毫无意义。
|
|
1073
1075
|
const declared = parsed.content_digest;
|
|
1074
1076
|
if (typeof declared !== 'string' || !isValidContentDigest(declared)) {
|
|
1075
1077
|
throw new OwnerDirectoryCacheError('INVALID_FIELD', `${scope}.json content_digest is not a sha256 hex string`);
|
|
@@ -1082,7 +1084,7 @@ export class OwnerDirectoryCache {
|
|
|
1082
1084
|
personalAssistant,
|
|
1083
1085
|
});
|
|
1084
1086
|
if (recomputed !== declared) {
|
|
1085
|
-
|
|
1087
|
+
logger.warn(`[OwnerDirectoryCache] ${scope}.json content_digest mismatch (accepted, server authoritative): declared=${declared.slice(0, 12)} recomputed=${recomputed.slice(0, 12)}`);
|
|
1086
1088
|
}
|
|
1087
1089
|
return {
|
|
1088
1090
|
raw: parsed, bytes, sha256, ownerAid: this.options.ownerAid, scope, schemaVersion: schemaVersion,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `ec directory list|info
|
|
2
|
+
* `ec directory list|info`:查名录。
|
|
3
3
|
*
|
|
4
4
|
* 命令面与 `ec skill` 对齐:`list` 列举/过滤(`--filter` + 分页),`info` 看单条详情。
|
|
5
5
|
* 和 `directory.md` 的分工:注入内容给的是截断后的概览(描述 100 字、名字 32 字,
|
|
@@ -24,8 +24,6 @@ import { ownerResolver } from '../core/ownership/owner-resolver.js';
|
|
|
24
24
|
import { authorizedOwnerAid, refreshOwnerDirectory, syncOwnerDirectoryForLookup } from './owner-directory-admission.js';
|
|
25
25
|
import { getPeerSnapshot } from '../config/peer-book.js';
|
|
26
26
|
import { resolveEntryContactable } from './owner-directory-policy.js';
|
|
27
|
-
/** 旧命令名 → 新命令。`find` 合入 `list --filter`,`show` 改名为 `info`。 */
|
|
28
|
-
const LEGACY_ACTIONS = { find: 'list', show: 'info' };
|
|
29
27
|
/** `info` 按名字命中时的默认上限。 */
|
|
30
28
|
const INFO_NAME_MATCH_LIMIT = 20;
|
|
31
29
|
/** `list` 的分页默认值与上限;与 `ec skill list` 的默认 20 条一致。 */
|
|
@@ -42,7 +40,7 @@ export class DirectoryQueryError extends Error {
|
|
|
42
40
|
/** 解析 `ec directory <list|info|refresh|blocked> ...` 之后的 argv。 */
|
|
43
41
|
export function resolveDirectoryQueryCommand(argv) {
|
|
44
42
|
const [rawAction, ...rest] = argv;
|
|
45
|
-
const action =
|
|
43
|
+
const action = rawAction;
|
|
46
44
|
if (action !== 'list' && action !== 'info'
|
|
47
45
|
&& action !== 'refresh' && action !== 'blocked') {
|
|
48
46
|
throw new DirectoryQueryError('INVALID_ACTION', 'directory requires one of: list, info, refresh, blocked');
|
|
@@ -74,7 +72,7 @@ export function resolveDirectoryQueryCommand(argv) {
|
|
|
74
72
|
const filterGroups = takeFlags(rest, '--filter')
|
|
75
73
|
.map(value => value.split(',').map(item => item.trim()).filter(Boolean))
|
|
76
74
|
.filter(group => group.length > 0);
|
|
77
|
-
//
|
|
75
|
+
// 位置参数按“多个词同时命中”处理:每个词一组(AND)。
|
|
78
76
|
const positionalGroups = positional
|
|
79
77
|
.map(token => token.trim()).filter(Boolean)
|
|
80
78
|
.map(token => [token]);
|
|
@@ -99,7 +97,7 @@ export function resolveDirectoryQueryCommand(argv) {
|
|
|
99
97
|
* 执行查询。
|
|
100
98
|
*
|
|
101
99
|
* 快照优先取 channel 正在用的实例(能共享模块级单飞);拿不到时构造一个只读实例,
|
|
102
|
-
*
|
|
100
|
+
* 读本地文件即可——查询不需要网络,除非关键词未命中要触发同步。
|
|
103
101
|
*/
|
|
104
102
|
export async function executeDirectoryQueryCommand(command) {
|
|
105
103
|
const directory = path.join(agentDir(command.selfAid), 'directory');
|
|
@@ -318,7 +316,7 @@ function identityEntry(field, ownerAid) {
|
|
|
318
316
|
};
|
|
319
317
|
}
|
|
320
318
|
/**
|
|
321
|
-
* `
|
|
319
|
+
* `info` 的目标解析:合法 AID 精确匹配;否则当名字匹配,分两级——
|
|
322
320
|
* 归一后精确相等(全角/空格/结尾括号称呼不影响),没命中再按名字包含放宽。
|
|
323
321
|
* 两级都不碰描述字段:描述里提到某人(「李文江的助理」)不代表那条就是某人。
|
|
324
322
|
*
|
|
@@ -17,16 +17,40 @@ function sameProcess(identity) {
|
|
|
17
17
|
}
|
|
18
18
|
return startTimeMatches(identity.startedAt, actual);
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Windows 上 taskkill 不带 /F 只会给控制台进程投一个 WM_CLOSE,Node 进程根本不响应,
|
|
22
|
+
* 结果是必然失败再白等满一个超时;POSIX 上 SIGTERM 仍是有效的优雅退出路径,保留。
|
|
23
|
+
*/
|
|
24
|
+
const GRACEFUL_STOP_MS = platform.isWindows ? 0 : 1_000;
|
|
25
|
+
const FORCED_STOP_MS = 2_000;
|
|
26
|
+
export async function stopEcwebProcess(identity, timeoutMs = FORCED_STOP_MS, onTiming) {
|
|
27
|
+
const waitForExit = async (force, budgetMs) => {
|
|
28
|
+
const startMs = Date.now();
|
|
29
|
+
let detail = `pid=${identity.pid}; timeoutMs=${budgetMs}`;
|
|
30
|
+
try {
|
|
31
|
+
const signalSent = platform.killProcessOnly(identity.pid, force);
|
|
32
|
+
const exited = await platform.waitForProcessExit(identity.pid, budgetMs);
|
|
33
|
+
detail += `; signalSent=${signalSent}; exited=${exited}`;
|
|
34
|
+
return exited;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
detail += `; 失败: ${error instanceof Error ? error.message : String(error)}`;
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
try {
|
|
42
|
+
onTiming?.({ phase: force ? 'forceExit' : 'gracefulExit', startMs, endMs: Date.now(), detail });
|
|
43
|
+
}
|
|
44
|
+
catch { }
|
|
45
|
+
}
|
|
46
|
+
};
|
|
21
47
|
if (!sameProcess(identity))
|
|
22
48
|
return;
|
|
23
|
-
|
|
24
|
-
if (await platform.waitForProcessExit(identity.pid, timeoutMs))
|
|
49
|
+
if (GRACEFUL_STOP_MS > 0 && await waitForExit(false, GRACEFUL_STOP_MS))
|
|
25
50
|
return;
|
|
26
51
|
if (!sameProcess(identity))
|
|
27
52
|
return;
|
|
28
|
-
|
|
29
|
-
if (await platform.waitForProcessExit(identity.pid, timeoutMs))
|
|
53
|
+
if (await waitForExit(true, timeoutMs))
|
|
30
54
|
return;
|
|
31
55
|
if (!sameProcess(identity))
|
|
32
56
|
return;
|