evolcore 0.0.43-test.6 → 0.0.43-test.8
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 +95 -0
- package/bin/ecmsg.js +188 -58
- package/dist/agent-template/jobs.js +62 -0
- package/dist/agent-template/runtime.js +214 -0
- package/dist/agent-template/service.js +465 -0
- package/dist/agent-template/tool-runner.js +45 -0
- package/dist/agent-template/types.js +5 -0
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/claude-runner.js +1 -1
- package/dist/agents/codex/app-server-client.js +22 -0
- package/dist/agents/codex-runner.js +69 -2
- package/dist/aun/aid/agentmd.js +56 -1
- package/dist/aun/aid/client.js +3 -1
- package/dist/aun/menu/client.js +3 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/channels/aun.js +277 -49
- package/dist/cli/agent-command.js +5 -0
- package/dist/cli/agent-create.js +7 -3
- package/dist/cli/agent-template.js +124 -0
- package/dist/cli/aun-commands.js +2 -2
- package/dist/cli/ctl-command.js +2 -1
- package/dist/cli/daemon-commands.js +11 -66
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +35 -2
- package/dist/cli/events-command.js +109 -0
- package/dist/cli/index.js +60 -14
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/net-check.js +1 -1
- package/dist/cli/restart-monitor.js +160 -83
- package/dist/cli/services-command.js +137 -0
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +103 -13
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/boot-log.js +8 -8
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +0 -7
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/schema-migration.js +45 -15
- package/dist/config-store.js +2 -1
- package/dist/core/agent-ipc-registration.js +25 -4
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +106 -10
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-authorizer.js +2 -0
- package/dist/core/auth/operation-catalog.js +29 -0
- package/dist/core/baseagent-loader.js +60 -130
- package/dist/core/channel-loader.js +10 -1
- package/dist/core/channel-runtime.js +20 -12
- package/dist/core/command/agent-control.js +12 -2
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/agent-template-menu.js +147 -0
- package/dist/core/command/chatmode-config.js +2 -36
- package/dist/core/command/command-handler.js +80 -17
- package/dist/core/command/data-root-resolver.js +32 -23
- package/dist/core/command/eventcenter-menu.js +468 -0
- package/dist/core/command/menu-catalog.js +15 -0
- package/dist/core/command/menu-handler.js +216 -90
- package/dist/core/command/menu-protocol.js +71 -13
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/slash-gate.js +1 -1
- package/dist/core/command/slash-handler.js +34 -42
- package/dist/core/command/team-workspace-bootstrap.js +350 -0
- package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
- package/dist/core/command/team-workspace-initializer.js +2 -0
- package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
- package/dist/core/command/team-workspace-job-store.js +88 -0
- package/dist/core/command/team-workspace-management-service.js +2 -0
- package/dist/core/command/team-workspace-management-store.js +96 -0
- package/dist/core/command/team-workspace-management.js +265 -0
- package/dist/core/command/team-workspace-members-menu.js +88 -0
- package/dist/core/command/team-workspace-store.js +612 -0
- package/dist/core/command/team-workspace-team.js +193 -0
- package/dist/core/daemon-control.js +22 -5
- package/dist/core/daemon-lifecycle.js +323 -191
- package/dist/core/handoff/runtime.js +45 -13
- package/dist/core/invoke/executors/index.js +13 -0
- package/dist/core/invoke/executors/media.js +283 -0
- package/dist/core/invoke/executors/text.js +198 -0
- package/dist/core/invoke/invoke-service.js +157 -0
- package/dist/core/invoke/style-router.js +48 -0
- package/dist/core/invoke/types.js +19 -0
- package/dist/core/ipc-registration.js +50 -7
- package/dist/core/legacy-rename.js +41 -0
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +252 -17
- package/dist/core/message/im-renderer.js +116 -85
- package/dist/core/message/message-bridge.js +4 -0
- package/dist/core/message/message-queue.js +66 -15
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/pending-hints.js +29 -5
- package/dist/core/message/response-engine.js +194 -61
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +50 -5
- package/dist/core/ownership/owner-resolver.js +7 -0
- package/dist/core/pack-auth.js +94 -0
- package/dist/core/pack-install.js +194 -0
- package/dist/core/permission/ec-command-parser.js +51 -17
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/rate-window.js +48 -0
- package/dist/core/relation/peer-identity.js +28 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +67 -28
- package/dist/core/session/session-idle-monitor.js +59 -19
- package/dist/core/session/session-manager.js +13 -4
- package/dist/core/task/task-recovery-service.js +13 -2
- package/dist/core/thread/command-parser.js +9 -2
- package/dist/core/thread/thread-operation.js +21 -2
- package/dist/core/thread/thread-route.js +13 -2
- package/dist/core/thread/thread-service.js +52 -3
- package/dist/directory/owner-directory-admission.js +40 -53
- package/dist/directory/owner-directory-cache.js +89 -113
- package/dist/directory/owner-directory-query-operation.js +8 -10
- package/dist/eck/kit-renderer.js +7 -5
- package/dist/eck/message-renderer.js +2 -0
- package/dist/ecweb/basic-settings-service.js +1 -1
- package/dist/ecweb/message-context-service.js +0 -4
- package/dist/ecweb/runtime/lifecycle.js +6 -2
- package/dist/ecweb/runtime/supervisor.js +19 -4
- package/dist/event-center/admission-materializer.js +124 -0
- package/dist/event-center/bus-gate.js +154 -0
- package/dist/event-center/bus-host.js +307 -0
- package/dist/event-center/bus-resolver.js +120 -0
- package/dist/event-center/center-config.js +127 -0
- package/dist/event-center/daemon.js +44 -0
- package/dist/event-center/directory-source.js +55 -0
- package/dist/event-center/dispatcher.js +157 -0
- package/dist/event-center/event-log.js +110 -0
- package/dist/event-center/index-generator.js +73 -0
- package/dist/event-center/ipc-operation.js +423 -0
- package/dist/event-center/ledger.js +52 -0
- package/dist/event-center/pack-loader.js +207 -0
- package/dist/event-center/pack-manager.js +85 -0
- package/dist/event-center/registry.js +463 -0
- package/dist/event-center/runtime.js +837 -0
- package/dist/event-center/script-runner.js +356 -0
- package/dist/event-center/types.js +51 -0
- package/dist/event-center/validation.js +435 -0
- package/dist/index.js +424 -135
- package/dist/ipc.js +106 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +5 -1
- package/dist/proxy/service-supervisor.js +13 -4
- package/dist/response-system/engines/v1/index.js +0 -1
- package/dist/response-system/engines/v1/proactive-flow.js +4 -2
- package/dist/response-system/modes/single-session/index.js +1 -1
- package/dist/services/dispatcher.js +100 -0
- package/dist/services/idempotency.js +90 -0
- package/dist/services/identity.js +52 -0
- package/dist/services/index-generator.js +70 -0
- package/dist/services/index.js +449 -0
- package/dist/services/ipc-operation.js +550 -0
- package/dist/services/ledger.js +52 -0
- package/dist/services/message-log.js +112 -0
- package/dist/services/pack-manager.js +215 -0
- package/dist/services/reply.js +55 -0
- package/dist/services/router.js +98 -0
- package/dist/services/script-runner.js +422 -0
- package/dist/services/service-payload.js +70 -0
- package/dist/services/types.js +18 -0
- package/dist/services/validation.js +297 -0
- package/dist/trigger/application-service.js +18 -0
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/scheduler.js +38 -0
- package/dist/trigger/script-sandbox.js +170 -24
- package/dist/utils/cross-platform.js +24 -10
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +6 -3
- package/dist/utils/process-introspect.js +45 -9
- package/dist/utils/startup-trace.js +74 -37
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +9 -15
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +3 -1
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/agent.md +22 -1
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/event-center.md +227 -0
- package/kits/docs/evolcore/file-navigation.md +10 -264
- package/kits/docs/evolcore/fs.md +5 -3
- package/kits/docs/evolcore/group.md +1 -1
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-protocol.md +28 -1
- package/kits/docs/evolcore/msg.md +21 -9
- package/kits/docs/evolcore/provider.md +3 -1
- package/kits/docs/evolcore/response.md +5 -5
- package/kits/docs/evolcore/services.md +294 -0
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +41 -0
- package/kits/docs/evolcore/thread-chain.md +15 -3
- package/kits/eck_manifest.json +26 -0
- package/kits/rules/02-navigation.md +10 -1
- package/kits/rules/06-channel.md +1 -0
- package/kits/schemas/_meta.json +17 -6
- package/kits/schemas/agent-config.schema.19.json +5 -7
- package/kits/schemas/agent-config.schema.20.json +936 -0
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/skills/.switches.json +1 -5
- package/kits/skills/ability/SKILL.md +56 -0
- package/kits/skills/ability/references/calling.md +56 -0
- package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
- package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
- package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
- package/kits/skills/ec-agent-create/SKILL.md +0 -1
- package/kits/skills/ec-group/SKILL.md +5 -8
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-service-proxy/SKILL.md +34 -5
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/personal-assistant/SKILL.md +6 -6
- package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
- package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
- package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
- package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/message-fragments/item.md +1 -1
- package/kits/templates/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/reply.md +1 -5
- package/kits/templates/system-fragments/thread.md +13 -10
- package/package.json +5 -6
- package/scripts/agent-template/index.mjs +40 -0
- package/scripts/agent-template/inspect.mjs +240 -0
- package/scripts/agent-template/overlay.mjs +71 -0
- package/scripts/agent-template/pack.mjs +169 -0
- package/scripts/agent-template/shared/common.mjs +235 -0
- package/scripts/agent-template/shared/evolcore.mjs +75 -0
- package/scripts/agent-template/shared/plan.mjs +129 -0
- package/scripts/agent-template/shared/team-schema.json +70 -0
- package/scripts/agent-template/shared/template-contract.mjs +154 -0
- package/scripts/agent-template/shared/template-package.mjs +265 -0
- package/scripts/agent-template/shared/template-runtime.mjs +80 -0
- package/scripts/agent-template/shared/template.mjs +142 -0
- package/dist/cli/pa-workspace-command.js +0 -225
- package/dist/core/command/pa-workspace-store.js +0 -468
- package/dist/core/relation/pa-team.js +0 -132
- package/kits/docs/evolcore/pa-workspace.md +0 -51
- package/kits/skills/aid-ability/SKILL.md +0 -244
- package/kits/skills/ec-ability/SKILL.md +0 -67
- package/kits/skills/ec-ability/references/workflows.md +0 -15
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pack.json / services-config.json 校验。
|
|
3
|
+
* 约束 1:1 映射 docs/services/schema/{service,router}.schema.json;Schema 为权威,
|
|
4
|
+
* 两者不一致改这里并同步 Schema。手写校验器(不引 ajv),失败逐条报错。
|
|
5
|
+
*/
|
|
6
|
+
import { isListenableType } from './service-payload.js';
|
|
7
|
+
export const SCRIPT_EXTENSIONS = ['mjs', 'cjs', 'js', 'py', 'sh', 'ps1'];
|
|
8
|
+
export const RUNTIME_WHITELIST = ['node', 'python', 'bash', 'powershell'];
|
|
9
|
+
const TIMEOUT_MIN = 1000;
|
|
10
|
+
const TIMEOUT_MAX = 300_000;
|
|
11
|
+
const TIMEOUT_DEFAULT = 30_000;
|
|
12
|
+
const QUOTA_DEFAULT_BUILTIN = { perMinute: 20, perHour: 200 };
|
|
13
|
+
const QUOTA_DEFAULT_SERVICE = { perMinute: 50, perHour: 1000 };
|
|
14
|
+
function isRecord(value) {
|
|
15
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
16
|
+
}
|
|
17
|
+
function optionalString(value, field, errors, max) {
|
|
18
|
+
if (value === undefined)
|
|
19
|
+
return undefined;
|
|
20
|
+
if (typeof value !== 'string') {
|
|
21
|
+
errors.push(`${field} must be a string`);
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
if (max !== undefined && value.length > max)
|
|
25
|
+
errors.push(`${field} is too long (max ${max})`);
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
function intInRange(value, field, min, max, errors) {
|
|
29
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value < min || value > max) {
|
|
30
|
+
errors.push(`${field} must be an integer between ${min} and ${max}`);
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
/** requires 的值:单个字符串、非空字符串数组,或 "*"。 */
|
|
36
|
+
function validateScopeValue(value, field, errors) {
|
|
37
|
+
if (typeof value === 'string') {
|
|
38
|
+
if (!value)
|
|
39
|
+
errors.push(`${field} must not be empty`);
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
if (Array.isArray(value)) {
|
|
43
|
+
if (value.length === 0) {
|
|
44
|
+
errors.push(`${field} must not be an empty array`);
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
if (value.some(item => typeof item !== 'string' || !item)) {
|
|
48
|
+
errors.push(`${field} must be an array of non-empty strings`);
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
errors.push(`${field} must be a string, a string array, or "*"`);
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
function validateValueAgainst(value, scope) {
|
|
57
|
+
if (scope === '*')
|
|
58
|
+
return true;
|
|
59
|
+
if (Array.isArray(scope))
|
|
60
|
+
return scope.includes(value);
|
|
61
|
+
return scope === value;
|
|
62
|
+
}
|
|
63
|
+
/** requires 判定:本机名片 type / exttype 是否满足。 */
|
|
64
|
+
export function requiresSatisfied(requires, identity) {
|
|
65
|
+
return validateValueAgainst(identity.type, requires.type)
|
|
66
|
+
&& validateValueAgainst(identity.exttype, requires.exttype);
|
|
67
|
+
}
|
|
68
|
+
/** handler.script 结构校验(存在性/越界由 pack-manager 做文件系统校验)。 */
|
|
69
|
+
function validateScriptPath(script, errors) {
|
|
70
|
+
if (typeof script !== 'string' || !script) {
|
|
71
|
+
errors.push('handler.script is required');
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
if (script.startsWith('/') || /^[a-zA-Z]:[\\/]/.test(script)) {
|
|
75
|
+
errors.push(`handler.script must be a relative path: ${script}`);
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
if (script.includes('..')) {
|
|
79
|
+
errors.push(`handler.script must not contain '..': ${script}`);
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
if (script.includes('\\')) {
|
|
83
|
+
errors.push(`handler.script must use forward slashes: ${script}`);
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
if (!script.startsWith('scripts/')) {
|
|
87
|
+
errors.push(`handler.script must be under scripts/: ${script}`);
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
const ext = script.split('.').pop() ?? '';
|
|
91
|
+
if (!SCRIPT_EXTENSIONS.includes(ext)) {
|
|
92
|
+
errors.push(`handler.script extension must be one of ${SCRIPT_EXTENSIONS.join('/')}: ${script}`);
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
return script;
|
|
96
|
+
}
|
|
97
|
+
function validateHandler(raw, errors) {
|
|
98
|
+
if (!isRecord(raw)) {
|
|
99
|
+
errors.push('listen[].handler must be an object');
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
const extra = Object.keys(raw).filter(key => !['script', 'runtime', 'args', 'timeoutMs'].includes(key));
|
|
103
|
+
if (extra.length)
|
|
104
|
+
errors.push(`listen[].handler has unknown fields: ${extra.join(', ')}`);
|
|
105
|
+
const script = validateScriptPath(raw.script, errors);
|
|
106
|
+
if (raw.runtime !== undefined && !RUNTIME_WHITELIST.includes(raw.runtime)) {
|
|
107
|
+
errors.push(`listen[].handler.runtime must be one of ${RUNTIME_WHITELIST.join('/')}`);
|
|
108
|
+
}
|
|
109
|
+
if (raw.args !== undefined && (!Array.isArray(raw.args) || raw.args.some(item => typeof item !== 'string'))) {
|
|
110
|
+
errors.push('listen[].handler.args must be an array of strings');
|
|
111
|
+
}
|
|
112
|
+
const timeoutMs = raw.timeoutMs === undefined
|
|
113
|
+
? TIMEOUT_DEFAULT
|
|
114
|
+
: intInRange(raw.timeoutMs, 'listen[].handler.timeoutMs', TIMEOUT_MIN, TIMEOUT_MAX, errors);
|
|
115
|
+
if (script === undefined)
|
|
116
|
+
return undefined;
|
|
117
|
+
return {
|
|
118
|
+
script,
|
|
119
|
+
...(raw.runtime !== undefined ? { runtime: raw.runtime } : {}),
|
|
120
|
+
...(Array.isArray(raw.args) ? { args: raw.args } : {}),
|
|
121
|
+
timeoutMs: timeoutMs ?? TIMEOUT_DEFAULT,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function validateListenEntry(raw, errors) {
|
|
125
|
+
if (!isRecord(raw)) {
|
|
126
|
+
errors.push('listen[] entries must be objects');
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
const extra = Object.keys(raw).filter(key => !['type', 'handler', 'filter'].includes(key));
|
|
130
|
+
if (extra.length)
|
|
131
|
+
errors.push(`listen entry has unknown fields: ${extra.join(', ')}`);
|
|
132
|
+
if (typeof raw.type !== 'string' || !isListenableType(raw.type)) {
|
|
133
|
+
errors.push(`listen.type must be services[.<seg>[.<seg>]] or services[.<seg>].*, and must not end with .result: ${String(raw.type)}`);
|
|
134
|
+
}
|
|
135
|
+
if (raw.filter !== undefined && !isRecord(raw.filter))
|
|
136
|
+
errors.push('listen[].filter must be an object');
|
|
137
|
+
const handler = validateHandler(raw.handler, errors);
|
|
138
|
+
if (typeof raw.type !== 'string' || !isListenableType(raw.type) || handler === undefined)
|
|
139
|
+
return undefined;
|
|
140
|
+
return {
|
|
141
|
+
type: raw.type,
|
|
142
|
+
...(isRecord(raw.filter) ? { filter: raw.filter } : {}),
|
|
143
|
+
handler,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function validateRequires(raw, errors) {
|
|
147
|
+
if (!isRecord(raw)) {
|
|
148
|
+
errors.push('requires is required and must be an object');
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
const extra = Object.keys(raw).filter(key => !['type', 'exttype'].includes(key));
|
|
152
|
+
if (extra.length)
|
|
153
|
+
errors.push(`requires has unknown fields: ${extra.join(', ')}`);
|
|
154
|
+
if (raw.type === undefined)
|
|
155
|
+
errors.push('requires.type is required');
|
|
156
|
+
if (raw.exttype === undefined)
|
|
157
|
+
errors.push('requires.exttype is required');
|
|
158
|
+
const type = raw.type === undefined ? undefined : validateScopeValue(raw.type, 'requires.type', errors);
|
|
159
|
+
const exttype = raw.exttype === undefined ? undefined : validateScopeValue(raw.exttype, 'requires.exttype', errors);
|
|
160
|
+
if (type === undefined || exttype === undefined)
|
|
161
|
+
return undefined;
|
|
162
|
+
return { type, exttype };
|
|
163
|
+
}
|
|
164
|
+
function validateReplyPolicy(raw, errors) {
|
|
165
|
+
if (raw === undefined)
|
|
166
|
+
return { allowed: false, payloadTypes: ['service-result'] };
|
|
167
|
+
if (!isRecord(raw)) {
|
|
168
|
+
errors.push('reply must be an object');
|
|
169
|
+
return { allowed: false, payloadTypes: ['service-result'] };
|
|
170
|
+
}
|
|
171
|
+
const extra = Object.keys(raw).filter(key => !['allowed', 'payloadTypes'].includes(key));
|
|
172
|
+
if (extra.length)
|
|
173
|
+
errors.push(`reply has unknown fields: ${extra.join(', ')}`);
|
|
174
|
+
if (raw.allowed !== undefined && typeof raw.allowed !== 'boolean')
|
|
175
|
+
errors.push('reply.allowed must be a boolean');
|
|
176
|
+
let payloadTypes = ['service-result'];
|
|
177
|
+
if (raw.payloadTypes !== undefined) {
|
|
178
|
+
if (!Array.isArray(raw.payloadTypes))
|
|
179
|
+
errors.push('reply.payloadTypes must be an array');
|
|
180
|
+
else if (raw.payloadTypes.some(item => item !== 'service-result')) {
|
|
181
|
+
errors.push('reply.payloadTypes only accepts "service-result"');
|
|
182
|
+
}
|
|
183
|
+
else
|
|
184
|
+
payloadTypes = ['service-result'];
|
|
185
|
+
}
|
|
186
|
+
return { allowed: raw.allowed === true, payloadTypes };
|
|
187
|
+
}
|
|
188
|
+
/** 校验 pack.json 原始对象(不做文件系统检查)。 */
|
|
189
|
+
export function validateServiceJson(raw) {
|
|
190
|
+
const errors = [];
|
|
191
|
+
if (!isRecord(raw))
|
|
192
|
+
return { ok: false, errors: ['pack.json must be a JSON object'] };
|
|
193
|
+
const extra = Object.keys(raw).filter(key => !['v', 'name', 'description', 'enabled', 'requires', 'listen', 'unmatched', 'reply'].includes(key));
|
|
194
|
+
if (extra.length)
|
|
195
|
+
errors.push(`unknown top-level fields: ${extra.join(', ')}`);
|
|
196
|
+
if (raw.v !== 1)
|
|
197
|
+
errors.push('v must be 1');
|
|
198
|
+
if (typeof raw.name !== 'string' || !raw.name || raw.name.length > 64) {
|
|
199
|
+
errors.push('name must be a non-empty string (max 64)');
|
|
200
|
+
}
|
|
201
|
+
const description = optionalString(raw.description, 'description', errors, 200);
|
|
202
|
+
if (raw.enabled !== undefined && typeof raw.enabled !== 'boolean')
|
|
203
|
+
errors.push('enabled must be a boolean');
|
|
204
|
+
if (raw.unmatched !== undefined && raw.unmatched !== 'silent' && raw.unmatched !== 'reject') {
|
|
205
|
+
errors.push('unmatched must be "silent" or "reject"');
|
|
206
|
+
}
|
|
207
|
+
const requires = validateRequires(raw.requires, errors);
|
|
208
|
+
const listen = [];
|
|
209
|
+
if (raw.listen === undefined)
|
|
210
|
+
errors.push('listen is required');
|
|
211
|
+
else if (!Array.isArray(raw.listen))
|
|
212
|
+
errors.push('listen must be an array');
|
|
213
|
+
else if (raw.listen.length === 0)
|
|
214
|
+
errors.push('listen must have at least one entry');
|
|
215
|
+
else {
|
|
216
|
+
for (const item of raw.listen) {
|
|
217
|
+
const entry = validateListenEntry(item, errors);
|
|
218
|
+
if (entry)
|
|
219
|
+
listen.push(entry);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// 包内 type 唯一(含通配原文,同字面重复)。
|
|
223
|
+
const seen = new Set();
|
|
224
|
+
for (const entry of listen) {
|
|
225
|
+
if (seen.has(entry.type))
|
|
226
|
+
errors.push(`duplicate listen.type: ${entry.type}`);
|
|
227
|
+
else
|
|
228
|
+
seen.add(entry.type);
|
|
229
|
+
}
|
|
230
|
+
const reply = validateReplyPolicy(raw.reply, errors);
|
|
231
|
+
if (errors.length)
|
|
232
|
+
return { ok: false, errors };
|
|
233
|
+
return {
|
|
234
|
+
ok: true,
|
|
235
|
+
errors: [],
|
|
236
|
+
value: {
|
|
237
|
+
name: raw.name,
|
|
238
|
+
...(description !== undefined ? { description } : {}),
|
|
239
|
+
enabled: raw.enabled !== false,
|
|
240
|
+
requires: requires,
|
|
241
|
+
listen,
|
|
242
|
+
unmatched: raw.unmatched ?? 'silent',
|
|
243
|
+
reply,
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function validateQuota(raw, field, fallback, errors) {
|
|
248
|
+
if (raw === undefined)
|
|
249
|
+
return { ...fallback };
|
|
250
|
+
if (!isRecord(raw)) {
|
|
251
|
+
errors.push(`${field} must be an object`);
|
|
252
|
+
return { ...fallback };
|
|
253
|
+
}
|
|
254
|
+
const extra = Object.keys(raw).filter(key => !['perMinute', 'perHour'].includes(key));
|
|
255
|
+
if (extra.length)
|
|
256
|
+
errors.push(`${field} has unknown fields: ${extra.join(', ')}`);
|
|
257
|
+
const perMinute = intInRange(raw.perMinute, `${field}.perMinute`, 1, Number.MAX_SAFE_INTEGER, errors);
|
|
258
|
+
const perHour = intInRange(raw.perHour, `${field}.perHour`, 1, Number.MAX_SAFE_INTEGER, errors);
|
|
259
|
+
return { perMinute: perMinute ?? fallback.perMinute, perHour: perHour ?? fallback.perHour };
|
|
260
|
+
}
|
|
261
|
+
/** 校验 services-config.json 原始对象。 */
|
|
262
|
+
export function validateRouterConfig(raw) {
|
|
263
|
+
const errors = [];
|
|
264
|
+
if (!isRecord(raw))
|
|
265
|
+
return { ok: false, errors: ['services-config.json must be a JSON object'] };
|
|
266
|
+
const extra = Object.keys(raw).filter(key => !['v', 'enabled', 'rateLimit'].includes(key));
|
|
267
|
+
if (extra.length)
|
|
268
|
+
errors.push(`unknown top-level fields: ${extra.join(', ')}`);
|
|
269
|
+
if (raw.v !== 1)
|
|
270
|
+
errors.push('v must be 1');
|
|
271
|
+
if (raw.enabled !== undefined && typeof raw.enabled !== 'boolean')
|
|
272
|
+
errors.push('enabled must be a boolean');
|
|
273
|
+
let rateLimit = {
|
|
274
|
+
builtin: { ...QUOTA_DEFAULT_BUILTIN },
|
|
275
|
+
service: { ...QUOTA_DEFAULT_SERVICE },
|
|
276
|
+
};
|
|
277
|
+
if (raw.rateLimit !== undefined) {
|
|
278
|
+
if (!isRecord(raw.rateLimit))
|
|
279
|
+
errors.push('rateLimit must be an object');
|
|
280
|
+
else {
|
|
281
|
+
const rateExtra = Object.keys(raw.rateLimit).filter(key => !['builtin', 'service'].includes(key));
|
|
282
|
+
if (rateExtra.length)
|
|
283
|
+
errors.push(`rateLimit has unknown fields: ${rateExtra.join(', ')}`);
|
|
284
|
+
rateLimit = {
|
|
285
|
+
builtin: validateQuota(raw.rateLimit.builtin, 'rateLimit.builtin', QUOTA_DEFAULT_BUILTIN, errors),
|
|
286
|
+
service: validateQuota(raw.rateLimit.service, 'rateLimit.service', QUOTA_DEFAULT_SERVICE, errors),
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (errors.length)
|
|
291
|
+
return { ok: false, errors };
|
|
292
|
+
return {
|
|
293
|
+
ok: true,
|
|
294
|
+
errors: [],
|
|
295
|
+
value: { v: 1, enabled: raw.enabled === true, rateLimit },
|
|
296
|
+
};
|
|
297
|
+
}
|
|
@@ -9,6 +9,20 @@ import { logger } from '../utils/logger.js';
|
|
|
9
9
|
export class TriggerSchedulerRegistry {
|
|
10
10
|
schedulers = new Map();
|
|
11
11
|
starts = new Map();
|
|
12
|
+
listeners = [];
|
|
13
|
+
addLifecycleListener(listener) {
|
|
14
|
+
this.listeners.push(listener);
|
|
15
|
+
}
|
|
16
|
+
async notify(action) {
|
|
17
|
+
for (const listener of this.listeners) {
|
|
18
|
+
try {
|
|
19
|
+
await action(listener);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
logger.error(`[Trigger] lifecycle listener failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
12
26
|
get(agentAid) {
|
|
13
27
|
return this.schedulers.get(agentAid);
|
|
14
28
|
}
|
|
@@ -39,6 +53,8 @@ export class TriggerSchedulerRegistry {
|
|
|
39
53
|
// Propagate failure to admission/readiness and allow ensureStarted to retry.
|
|
40
54
|
throw error;
|
|
41
55
|
}
|
|
56
|
+
// 附属服务不阻塞调度器启动。
|
|
57
|
+
void this.notify(listener => listener.started?.(agentAid));
|
|
42
58
|
}
|
|
43
59
|
async ensureStarted(agentAid, start) {
|
|
44
60
|
const existing = this.starts.get(agentAid);
|
|
@@ -56,6 +72,7 @@ export class TriggerSchedulerRegistry {
|
|
|
56
72
|
}
|
|
57
73
|
}
|
|
58
74
|
async remove(agentAid) {
|
|
75
|
+
await this.notify(listener => listener.removed?.(agentAid));
|
|
59
76
|
await this.schedulers.get(agentAid)?.stop();
|
|
60
77
|
this.schedulers.delete(agentAid);
|
|
61
78
|
this.starts.delete(agentAid);
|
|
@@ -69,6 +86,7 @@ export class TriggerSchedulerRegistry {
|
|
|
69
86
|
await Promise.all([...this.schedulers.values()].map(scheduler => scheduler.waitForIdle(timeoutMs)));
|
|
70
87
|
}
|
|
71
88
|
async suspendForDaemonExit() {
|
|
89
|
+
await this.notify(listener => listener.suspending?.());
|
|
72
90
|
await Promise.all([...this.schedulers.values()].map(scheduler => scheduler.suspendForDaemonExit()));
|
|
73
91
|
}
|
|
74
92
|
}
|
|
@@ -99,7 +99,7 @@ function matchPattern(eventType, pattern) {
|
|
|
99
99
|
return eventType.startsWith(pattern.slice(0, -1));
|
|
100
100
|
return false;
|
|
101
101
|
}
|
|
102
|
-
function matchFilter(event, filter) {
|
|
102
|
+
export function matchFilter(event, filter) {
|
|
103
103
|
if (!filter.match)
|
|
104
104
|
return true;
|
|
105
105
|
for (const [path, expected] of Object.entries(filter.match)) {
|
|
@@ -5,12 +5,14 @@ import { assertTriggerLocalFileAuthority, daemonPrivilegedTriggerReason, isTrigg
|
|
|
5
5
|
import { decodeTriggerScriptFile } from './local-files.js';
|
|
6
6
|
import { applyTriggerPatch } from './patch.js';
|
|
7
7
|
import { definitionRevision, normalizeTriggerDefinition, splitScriptCommand } from './validation.js';
|
|
8
|
-
export function createTriggerBaseagentResolver({ daemonTriggerOwnerAid, getAgentName, getDaemonAgentName, agentMap, }) {
|
|
8
|
+
export function createTriggerBaseagentResolver({ daemonTriggerOwnerAid, getAgentName, getDaemonAgentName, agentMap, getConfiguredBaseagents, }) {
|
|
9
9
|
return agentAid => {
|
|
10
10
|
const ownerName = getAgentName(agentAid)
|
|
11
11
|
?? (agentAid === daemonTriggerOwnerAid ? getDaemonAgentName() : undefined);
|
|
12
12
|
if (!ownerName)
|
|
13
13
|
return [];
|
|
14
|
+
if (getConfiguredBaseagents)
|
|
15
|
+
return getConfiguredBaseagents(ownerName);
|
|
14
16
|
const prefix = `${ownerName}::`;
|
|
15
17
|
return [...agentMap.keys()]
|
|
16
18
|
.filter(key => key.startsWith(prefix))
|
|
@@ -41,6 +41,25 @@ export class TriggerRuntimeScheduler {
|
|
|
41
41
|
initialized = false;
|
|
42
42
|
stopping = false;
|
|
43
43
|
lifecycleGeneration = 0;
|
|
44
|
+
mutationPaused = false;
|
|
45
|
+
pendingMutationStarts = 0;
|
|
46
|
+
/** Hold scheduling without changing definitions or consuming one-shot triggers. */
|
|
47
|
+
async pauseForMutation() {
|
|
48
|
+
if (this.mutationPaused || this.running.size || this.runStartLocks.size || this.pendingMutationStarts) {
|
|
49
|
+
throw Object.assign(new Error('Trigger scheduler has active work'), { code: 'AGENT_BUSY' });
|
|
50
|
+
}
|
|
51
|
+
this.mutationPaused = true;
|
|
52
|
+
for (const timer of this.timers.values())
|
|
53
|
+
clearTimeout(timer);
|
|
54
|
+
this.timers.clear();
|
|
55
|
+
this.eventSource?.stop();
|
|
56
|
+
return async () => {
|
|
57
|
+
this.mutationPaused = false;
|
|
58
|
+
if (!this.stopping)
|
|
59
|
+
for (const definition of this.manager.list())
|
|
60
|
+
this.schedule(definition);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
44
63
|
constructor(manager, state, audit, scriptExecutor, feedback, daemonChannel, runtime, eventBus, targetSessionLocks = new TargetSessionLockRegistry()) {
|
|
45
64
|
this.manager = manager;
|
|
46
65
|
this.state = state;
|
|
@@ -329,6 +348,8 @@ export class TriggerRuntimeScheduler {
|
|
|
329
348
|
return this.manager.delete(triggerId);
|
|
330
349
|
}
|
|
331
350
|
async run(triggerId, opts = {}) {
|
|
351
|
+
if (this.mutationPaused)
|
|
352
|
+
throw Object.assign(new Error('Agent installation is in progress'), { code: 'AGENT_BUSY' });
|
|
332
353
|
const definition = this.manager.require(triggerId);
|
|
333
354
|
const firedAt = Date.now();
|
|
334
355
|
let sourcePayload = this.sourcePayload(definition.source);
|
|
@@ -366,6 +387,8 @@ export class TriggerRuntimeScheduler {
|
|
|
366
387
|
});
|
|
367
388
|
}
|
|
368
389
|
schedule(definition) {
|
|
390
|
+
if (this.mutationPaused)
|
|
391
|
+
return;
|
|
369
392
|
this.clearTimer(definition.id);
|
|
370
393
|
this.unregisterEvent(definition.id);
|
|
371
394
|
if (definition.limits)
|
|
@@ -404,6 +427,8 @@ export class TriggerRuntimeScheduler {
|
|
|
404
427
|
this.timers.set(definition.id, timer);
|
|
405
428
|
}
|
|
406
429
|
async handleScheduledFire(triggerId, scheduledAt) {
|
|
430
|
+
if (this.mutationPaused)
|
|
431
|
+
return;
|
|
407
432
|
const definition = this.manager.get(triggerId);
|
|
408
433
|
if (!definition?.enabled)
|
|
409
434
|
return;
|
|
@@ -455,6 +480,17 @@ export class TriggerRuntimeScheduler {
|
|
|
455
480
|
}
|
|
456
481
|
}
|
|
457
482
|
async startRun(definition, payload) {
|
|
483
|
+
if (this.mutationPaused)
|
|
484
|
+
return { ok: false, runId: 'mutation', triggerId: definition.id, status: 'skipped', reason: 'stopped' };
|
|
485
|
+
this.pendingMutationStarts++;
|
|
486
|
+
try {
|
|
487
|
+
return await this.startRunUnpaused(definition, payload);
|
|
488
|
+
}
|
|
489
|
+
finally {
|
|
490
|
+
this.pendingMutationStarts--;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
async startRunUnpaused(definition, payload) {
|
|
458
494
|
const firedAt = payload.firedAt;
|
|
459
495
|
const runId = `run_${firedAt}_${crypto.randomBytes(3).toString('hex')}`;
|
|
460
496
|
if (this.stopping) {
|
|
@@ -1975,6 +2011,8 @@ export class TriggerRuntimeScheduler {
|
|
|
1975
2011
|
return { status: 'inactive', warning: 'event subscription is not registered' };
|
|
1976
2012
|
}
|
|
1977
2013
|
async fireEventTrigger(triggerId, event) {
|
|
2014
|
+
if (this.mutationPaused)
|
|
2015
|
+
return;
|
|
1978
2016
|
const definition = this.manager.get(triggerId);
|
|
1979
2017
|
if (!definition?.enabled || definition.source.type !== 'event')
|
|
1980
2018
|
return;
|