evolcore 0.0.3 → 0.0.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 +64 -0
- package/README.md +45 -10
- package/bin/ec-safe-output.js +89 -24
- package/dist/agents/baseagent.js +46 -0
- package/dist/agents/claude-runner.js +1 -31
- package/dist/agents/codex-app-server-client.js +68 -0
- package/dist/agents/codex-runner.js +157 -5
- package/dist/agents/runner-types.js +2 -2
- package/dist/aun/aid/agentmd.js +79 -0
- package/dist/aun/aid/encryption-seed-policy.js +29 -0
- package/dist/aun/aid/index.js +1 -1
- package/dist/aun/aid/store.js +2 -5
- package/dist/channels/aun.js +220 -112
- package/dist/channels/daemon.js +18 -4
- package/dist/channels/dingtalk.js +52 -137
- package/dist/channels/feishu.js +56 -4
- package/dist/channels/qqbot.js +23 -1
- package/dist/channels/wechat.js +303 -155
- package/dist/channels/wecom.js +383 -7
- package/dist/cli/aun-commands.js +11 -11
- package/dist/cli/handoff-command.js +2 -1
- package/dist/cli/init-channel.js +185 -67
- package/dist/cli/init.js +7 -5
- package/dist/cli/trigger-command.js +92 -11
- package/dist/config/access-policy-domain.js +38 -0
- package/dist/config/access-policy.js +134 -0
- package/dist/config/builtin-role-templates.js +27 -14
- package/dist/config/builtin-roles.js +25 -6
- package/dist/config/config-field-policy.js +17 -5
- package/dist/config/config-manager.js +198 -22
- package/dist/config/config-operation-service.js +35 -38
- package/dist/config/contact-bind-code.js +274 -0
- package/dist/config/contact-book-store.js +173 -5
- package/dist/config/contact-book.js +32 -0
- package/dist/config/contact-operation-service.js +9 -3
- package/dist/config/contact-request-service.js +331 -0
- package/dist/config/peer-role-resolver.js +3 -1
- package/dist/config/schema-registry.js +49 -24
- package/dist/config-store.js +14 -2
- package/dist/core/auth/agent-delegation.js +105 -11
- package/dist/core/auth/authorization-audit.js +6 -0
- package/dist/core/auth/operation-authorizer.js +8 -0
- package/dist/core/auth/operation-catalog.js +51 -3
- package/dist/core/auth/trigger-authorization.js +15 -0
- package/dist/core/bootstrap-service.js +2 -9
- package/dist/core/channel-loader.js +6 -2
- package/dist/core/command/command-handler.js +10 -13
- package/dist/core/command/connect-menu.js +249 -24
- package/dist/core/command/evol-menu-version-gate.js +38 -0
- package/dist/core/command/group-menu.js +421 -0
- package/dist/core/command/menu-handler.js +269 -85
- package/dist/core/command/menu-protocol.js +8 -2
- package/dist/core/command/menu-token-store.js +102 -0
- package/dist/core/command/slash-gate.js +1 -1
- package/dist/core/command/slash-handler.js +158 -31
- package/dist/core/daemon-file-cache.js +28 -0
- package/dist/core/event-catalog.js +29 -0
- package/dist/core/evolagent-registry.js +4 -39
- package/dist/core/handoff/runtime.js +162 -37
- package/dist/core/handoff/store.js +46 -2
- package/dist/core/handoff/types.js +1 -0
- package/dist/core/inference/text-inference.js +16 -74
- package/dist/core/message/file-markers.js +7 -0
- package/dist/core/message/im-renderer.js +18 -14
- package/dist/core/message/inbound-admission.js +124 -0
- package/dist/core/message/message-bridge.js +616 -74
- package/dist/core/message/message-log.js +1 -0
- package/dist/core/message/message-queue.js +185 -10
- package/dist/core/message/peer-mode.js +7 -8
- package/dist/core/message/response-engine.js +381 -79
- package/dist/core/permission/approval-gateway.js +17 -10
- package/dist/core/permission/ec-command-parser.js +101 -46
- package/dist/core/permission/tool-policy.js +69 -24
- package/dist/core/protected-paths.js +36 -11
- package/dist/core/session/session-manager.js +25 -3
- package/dist/core/session/session-mapper.js +2 -0
- package/dist/core/session/session-renew.js +125 -69
- package/dist/core/session/session-turn-coordinator.js +5 -1
- package/dist/eck/kit-renderer.js +12 -1
- package/dist/eck/message-renderer.js +79 -1
- package/dist/index.js +224 -89
- package/dist/ipc.js +81 -4
- package/dist/paths.js +3 -0
- package/dist/response-system/config-resolver.js +29 -0
- package/dist/response-system/coordinator.js +8 -32
- package/dist/response-system/engines/v1/proactive-flow.js +1 -1
- package/dist/response-system/index.js +1 -0
- package/dist/response-system/modes/single-session/index.js +7 -4
- package/dist/trigger/parser.js +55 -15
- package/dist/trigger/patch.js +4 -1
- package/dist/trigger/scheduler.js +441 -39
- package/dist/utils/error-dict.json +7 -0
- package/dist/utils/evolcore-version.js +21 -0
- package/dist/utils/logger.js +2 -2
- package/dist/utils/stable-semver.js +21 -0
- package/dist/utils/stats.js +33 -9
- package/kits/docs/channels/aun.md +4 -13
- package/kits/docs/evolcore/INDEX.md +1 -1
- package/kits/docs/evolcore/config.md +47 -2
- package/kits/docs/evolcore/contact.md +7 -3
- package/kits/docs/evolcore/group-rules.md +46 -4
- package/kits/docs/evolcore/group.md +4 -4
- package/kits/docs/evolcore/msg.md +5 -5
- package/kits/docs/evolcore/trigger.md +25 -8
- package/kits/docs/path-registry.md +36 -17
- package/kits/eck_message_manifest.json +12 -1
- package/kits/migrations/migrate-contact-book-v2.mjs +7 -0
- package/kits/rules/01-overview.md +17 -7
- package/kits/rules/02-navigation.md +38 -18
- package/kits/rules/03-identity.md +28 -24
- package/kits/rules/04-relation.md +44 -28
- package/kits/rules/05-venue.md +31 -15
- package/kits/rules/06-channel.md +11 -7
- package/kits/schemas/_meta.json +18 -7
- package/kits/schemas/agent-config.schema.7.json +303 -0
- package/kits/schemas/agent-config.schema.8.json +304 -0
- package/kits/schemas/agent-config.schema.9.json +374 -0
- package/kits/schemas/contact-book.schema.3.json +67 -0
- package/kits/schemas/daemon.schema.1.json +3 -2
- package/kits/schemas/daemon.schema.2.json +101 -0
- package/kits/schemas/daemon.schema.3.json +123 -0
- package/kits/schemas/defaults.schema.2.json +85 -0
- package/kits/schemas/defaults.schema.3.json +73 -0
- package/kits/schemas/relation-config.schema.6.json +46 -0
- package/kits/schemas/relation-config.schema.7.json +59 -0
- package/kits/schemas/single-session.schema.2.json +57 -0
- package/kits/templates/message-fragments/handoff-context-to-target.md +9 -0
- package/kits/templates/message-fragments/handoff-request-to-target.md +14 -8
- package/kits/templates/message-fragments/handoff-response-to-origin.md +5 -6
- package/kits/templates/roles/admin.json +46 -0
- package/kits/templates/roles/member.json +4 -0
- package/kits/templates/roles/visitor.json +4 -0
- package/kits/templates/system-fragments/channel.md +12 -2
- package/kits/templates/system-fragments/identity.md +3 -1
- package/kits/templates/system-fragments/relation.md +1 -1
- package/kits/templates/system-fragments/session.md +6 -2
- package/package.json +4 -2
- package/MIGRATION-0.5.0.md +0 -378
- package/ROLE_ACCESS_CONTROL.md +0 -174
- package/dist/channels/contact-bind-code.js +0 -134
- package/dist/channels/wecom-card.js +0 -101
- package/dist/channels/wecom-onboarding.js +0 -82
- package/dist/channels/wecom-state.js +0 -191
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { AccessPolicyError, readAccessPolicy, } from '../../config/access-policy.js';
|
|
2
|
+
import { isAcceptedContact, resolveContactView, resolvePrincipal, } from '../../config/contact-book.js';
|
|
3
|
+
export function evaluateInboundAdmissionPreflight(input) {
|
|
4
|
+
const selfAid = String(input.selfAid || '').trim();
|
|
5
|
+
const channelType = String(input.channelType || '').trim().toLowerCase();
|
|
6
|
+
const actorId = String(input.actorId || '').trim();
|
|
7
|
+
const context = {
|
|
8
|
+
selfAid,
|
|
9
|
+
channelKey: input.channelKey,
|
|
10
|
+
channelType,
|
|
11
|
+
chatType: input.chatType,
|
|
12
|
+
actorId,
|
|
13
|
+
trustedHandoffEcho: input.trustedHandoffEcho === true,
|
|
14
|
+
isOwner: false,
|
|
15
|
+
};
|
|
16
|
+
if (context.trustedHandoffEcho)
|
|
17
|
+
return { allow: true, context };
|
|
18
|
+
if (!selfAid)
|
|
19
|
+
return { allow: false, reason: 'invalid_identity', context };
|
|
20
|
+
if (input.chatType === 'private') {
|
|
21
|
+
const principal = resolvePrincipal(selfAid, channelType, actorId, input.channelKey);
|
|
22
|
+
context.principal = principal;
|
|
23
|
+
context.primaryId = principal.principalId;
|
|
24
|
+
if (principal.principalStatus === 'conflict') {
|
|
25
|
+
return { allow: false, reason: 'identity_conflict', context };
|
|
26
|
+
}
|
|
27
|
+
if (principal.principalStatus === 'error') {
|
|
28
|
+
return { allow: false, reason: 'identity_resolution_error', context };
|
|
29
|
+
}
|
|
30
|
+
if (channelType === 'aun' && principal.principalStatus !== 'native_aid') {
|
|
31
|
+
return { allow: false, reason: 'invalid_identity', context };
|
|
32
|
+
}
|
|
33
|
+
if (principal.principalId) {
|
|
34
|
+
try {
|
|
35
|
+
const contact = resolveContactView(selfAid, principal.principalId);
|
|
36
|
+
context.contactStatus = contact.status;
|
|
37
|
+
context.contactSource = contact.source;
|
|
38
|
+
context.isOwner = contact.isOwner;
|
|
39
|
+
if (contact.blocked)
|
|
40
|
+
return { allow: false, reason: 'blocked', context };
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return { allow: false, reason: 'identity_resolution_error', context };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
context.policy = readAccessPolicy(selfAid);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (error instanceof AccessPolicyError && error.code === 'restricted_mode_without_owner') {
|
|
52
|
+
return { allow: false, reason: 'restricted_mode_without_owner', context };
|
|
53
|
+
}
|
|
54
|
+
return { allow: false, reason: 'invalid_access_policy', context };
|
|
55
|
+
}
|
|
56
|
+
return { allow: true, context };
|
|
57
|
+
}
|
|
58
|
+
export function evaluateOrdinaryInboundAdmission(context) {
|
|
59
|
+
if (context.trustedHandoffEcho)
|
|
60
|
+
return { allow: true, reason: 'trusted_handoff', context };
|
|
61
|
+
const policy = context.policy;
|
|
62
|
+
if (!policy)
|
|
63
|
+
return { allow: false, reason: 'invalid_access_policy', context };
|
|
64
|
+
if (context.chatType === 'group') {
|
|
65
|
+
if (policy.policyMode === 'owners-only') {
|
|
66
|
+
return { allow: false, reason: 'owners_only', context };
|
|
67
|
+
}
|
|
68
|
+
// `open` is genuinely open: group traffic is not gated by the optional
|
|
69
|
+
// channel allow-list. In `contacts`, AUN groups are currently open once
|
|
70
|
+
// the agent is receiving that group; non-AUN channels remain explicit.
|
|
71
|
+
if (policy.policyMode === 'open'
|
|
72
|
+
|| (policy.policyMode === 'contacts' && context.channelType === 'aun')) {
|
|
73
|
+
return { allow: true, reason: 'group_channel_allowed', context };
|
|
74
|
+
}
|
|
75
|
+
return policy.allowedGroupChannels.includes(context.channelKey)
|
|
76
|
+
? { allow: true, reason: 'group_channel_allowed', context }
|
|
77
|
+
: { allow: false, reason: 'group_channel_denied', context };
|
|
78
|
+
}
|
|
79
|
+
if (context.isOwner)
|
|
80
|
+
return { allow: true, reason: 'owner', context };
|
|
81
|
+
if (policy.policyMode === 'open')
|
|
82
|
+
return { allow: true, reason: 'open', context };
|
|
83
|
+
if (policy.policyMode === 'owners-only')
|
|
84
|
+
return { allow: false, reason: 'owners_only', context };
|
|
85
|
+
if (context.primaryId && isAcceptedContact(context.selfAid, context.primaryId)) {
|
|
86
|
+
return { allow: true, reason: 'contact', context };
|
|
87
|
+
}
|
|
88
|
+
return { allow: false, reason: 'contact_required', context };
|
|
89
|
+
}
|
|
90
|
+
const principalReplyBuckets = new Map();
|
|
91
|
+
const channelReplyBuckets = new Map();
|
|
92
|
+
const PRINCIPAL_REPLY_MAX = 3;
|
|
93
|
+
const PRINCIPAL_REPLY_WINDOW_MS = 60 * 60 * 1000;
|
|
94
|
+
/** Atomically consume both admission-control reply budgets. */
|
|
95
|
+
export function consumeAdmissionReplyBudget(context, now = Date.now()) {
|
|
96
|
+
const principalKey = `${context.selfAid}\0${context.primaryId || context.actorId || '<unknown>'}`;
|
|
97
|
+
const channelKey = `${context.selfAid}\0${context.channelKey}`;
|
|
98
|
+
const policy = context.policy;
|
|
99
|
+
const maxTimes = policy?.requestLimit.maxTimes ?? 600;
|
|
100
|
+
const coolDownMs = (policy?.requestLimit.coolDown ?? 60 * 60) * 1000;
|
|
101
|
+
if (!canConsume(principalReplyBuckets.get(principalKey), PRINCIPAL_REPLY_MAX, PRINCIPAL_REPLY_WINDOW_MS, now)) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
if (!canConsume(channelReplyBuckets.get(channelKey), maxTimes, coolDownMs, now))
|
|
105
|
+
return false;
|
|
106
|
+
consume(principalReplyBuckets, principalKey, PRINCIPAL_REPLY_WINDOW_MS, now);
|
|
107
|
+
consume(channelReplyBuckets, channelKey, coolDownMs, now);
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
export function clearAdmissionReplyBudgets() {
|
|
111
|
+
principalReplyBuckets.clear();
|
|
112
|
+
channelReplyBuckets.clear();
|
|
113
|
+
}
|
|
114
|
+
function canConsume(bucket, limit, windowMs, now) {
|
|
115
|
+
return !bucket || now - bucket.windowStart >= windowMs || bucket.count < limit;
|
|
116
|
+
}
|
|
117
|
+
function consume(buckets, key, windowMs, now) {
|
|
118
|
+
const bucket = buckets.get(key);
|
|
119
|
+
if (!bucket || now - bucket.windowStart >= windowMs) {
|
|
120
|
+
buckets.set(key, { count: 1, windowStart: now });
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
bucket.count += 1;
|
|
124
|
+
}
|