evolcore 0.0.48 → 0.0.49
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 +34 -0
- package/dist/agent-template/runtime.js +5 -2
- package/dist/agents/codex-runner.js +5 -1
- package/dist/aun/msg/p2p.js +2 -1
- package/dist/build-identity.json +1 -1
- package/dist/channels/aun.js +643 -273
- package/dist/cli/directory.js +6 -1
- package/dist/cli/index.js +7 -1
- package/dist/cli/managed-command-guard.js +2 -0
- package/dist/cli/model.js +20 -5
- package/dist/cli/quota.js +89 -0
- package/dist/cli/role.js +1 -0
- package/dist/cli/services-command.js +1 -0
- package/dist/cli/team-workspace-command.js +56 -2
- package/dist/config/config-field-policy.js +71 -1
- package/dist/config/config-manager.js +11 -1
- package/dist/config/providers-config.js +8 -4
- package/dist/config/providers-management.js +11 -3
- package/dist/config/resolved-config-op.js +3 -2
- package/dist/core/auth/delegation-authorization.js +33 -26
- package/dist/core/auth/operation-catalog.js +9 -0
- package/dist/core/command/cli-intent-parser.js +13 -0
- package/dist/core/command/command-handler.js +45 -2
- package/dist/core/command/menu-handler.js +6 -1
- package/dist/core/command/menu-protocol.js +24 -0
- package/dist/core/command/remote-shell.js +565 -0
- package/dist/core/daemon-control.js +57 -1
- package/dist/core/daemon-lifecycle.js +16 -2
- package/dist/core/evolagent-registry.js +6 -2
- package/dist/core/ipc-registration.js +1 -0
- package/dist/core/message/aun-ipc-sender.js +118 -56
- package/dist/core/message/contact-admission.js +91 -6
- package/dist/core/message/contact-pending-inbound.js +113 -0
- package/dist/core/message/contact-thread-approval.js +212 -0
- package/dist/core/message/im-renderer.js +40 -1
- package/dist/core/message/message-admission.js +5 -39
- package/dist/core/message/message-bridge.js +92 -39
- package/dist/core/message/message-log.js +24 -0
- package/dist/core/message/message-queue.js +97 -15
- package/dist/core/message/response-engine.js +151 -18
- package/dist/core/model/config-scope.js +6 -14
- package/dist/core/model/model-diagnostics.js +19 -0
- package/dist/core/model/model-fallback.js +13 -2
- package/dist/core/pack-auth.js +3 -0
- package/dist/core/pack-install.js +1 -1
- package/dist/core/permission/ec-command-parser.js +106 -19
- package/dist/core/permission/services-path-acl.js +451 -0
- package/dist/core/permission/tool-policy.js +5 -1
- package/dist/core/relation/peer-identity.js +13 -0
- package/dist/core/task/task-recovery-service.js +1 -0
- package/dist/core/thread/topic-id.js +15 -0
- package/dist/directory/owner-directory-admission.js +11 -8
- package/dist/directory/owner-directory-cache.js +19 -0
- package/dist/directory/owner-directory-markdown.js +1 -1
- package/dist/directory/owner-directory-policy.js +5 -30
- package/dist/directory/owner-directory-request-operation.js +5 -2
- package/dist/eck/kit-renderer.js +1 -1
- package/dist/eck/message-renderer.js +28 -5
- package/dist/ecweb/runtime/supervisor.js +36 -8
- package/dist/event-center/center-config.js +9 -5
- package/dist/event-center/dispatcher.js +10 -1
- package/dist/event-center/ipc-operation.js +19 -0
- package/dist/event-center/registry.js +20 -5
- package/dist/event-center/runtime.js +10 -7
- package/dist/index.js +4 -0
- package/dist/ipc.js +25 -1
- package/dist/outputs/authorization.js +16 -0
- package/dist/outputs/cards.js +336 -0
- package/dist/outputs/events.js +3 -2
- package/dist/outputs/protocol.js +1 -0
- package/dist/outputs/service.js +2 -15
- package/dist/services/index.js +29 -5
- package/dist/services/ipc-operation.js +84 -0
- package/dist/services/pack-manager.js +1 -0
- package/dist/services/service-payload.js +13 -7
- package/dist/stats/budget.js +1 -1
- package/dist/stats/model-resolver.js +2 -2
- package/dist/stats/quota-query.js +95 -0
- package/dist/trigger/script-sandbox.js +12 -0
- package/dist/utils/atomic-write.js +22 -8
- package/dist/utils/evolcore-version.js +2 -2
- package/dist/utils/host-info.js +100 -1
- package/dist/utils/npm-ops.js +43 -8
- package/dist/workbench/service.js +1 -1
- package/kits/docs/evolcore/INDEX.md +2 -0
- package/kits/docs/evolcore/aid.md +25 -0
- package/kits/docs/evolcore/config.md +4 -1
- package/kits/docs/evolcore/directory.md +8 -9
- package/kits/docs/evolcore/msg.md +9 -0
- package/kits/docs/evolcore/provider.md +1 -1
- package/kits/docs/evolcore/quota.md +54 -0
- package/kits/docs/evolcore/role.md +3 -0
- package/kits/docs/evolcore/stats.md +2 -0
- package/kits/docs/evolcore/trigger.md +2 -0
- package/kits/schemas/agent-config.schema.20.json +24 -0
- package/kits/skills/.switches.json +4 -0
- package/kits/skills/agent-output-cards/SKILL.md +57 -0
- package/kits/skills/ec-provider/SKILL.md +57 -8
- package/kits/templates/roles/visitor.json +1 -0
- package/kits/templates/system-fragments/commands.md +1 -0
- package/kits/templates/system-fragments/directory-contacts.md +3 -4
- package/kits/templates/system-fragments/thread.md +1 -0
- package/kits/templates/system-fragments/venue.md +11 -0
- package/package.json +2 -2
- package/scripts/agent-template/inspect.mjs +46 -10
- package/scripts/agent-template/shared/common.mjs +9 -3
- package/scripts/agent-template/shared/team-schema.json +6 -4
- package/scripts/agent-template/shared/template-contract.mjs +60 -10
- package/scripts/agent-template/shared/template-package.mjs +182 -21
- package/scripts/agent-template/shared/template-runtime.mjs +35 -2
- package/scripts/agent-template/shared/template.mjs +2 -2
- package/scripts/agent-template/team-pack.mjs +46 -11
|
@@ -62,12 +62,15 @@ export async function executeDirectoryRequestCommand(command, send) {
|
|
|
62
62
|
};
|
|
63
63
|
try {
|
|
64
64
|
const result = await send({ from: command.selfAid, to: command.targetAid, payload, encrypt: true });
|
|
65
|
-
if (!result.ok || !result.message_id) {
|
|
65
|
+
if (!result.ok || (!result.message_id && result.status !== 'queued')) {
|
|
66
66
|
return { ok: false, code: String(result.code ?? 'FRIEND_INVITE_FAILED'),
|
|
67
67
|
error: `向目标 ${command.targetAid} 发送加好友申请失败:${result.error ?? '未获得消息发送回执'}` };
|
|
68
68
|
}
|
|
69
69
|
return { ok: true, action: 'request', selfAid: command.selfAid, targetAid: command.targetAid,
|
|
70
|
-
status: '
|
|
70
|
+
status: result.status === 'queued' ? 'queued' : 'sent',
|
|
71
|
+
...(result.message_id ? { message_id: result.message_id } : {}),
|
|
72
|
+
...(result.outbox_id ? { outbox_id: result.outbox_id } : {}),
|
|
73
|
+
};
|
|
71
74
|
}
|
|
72
75
|
catch (error) {
|
|
73
76
|
return { ok: false, code: 'FRIEND_INVITE_FAILED',
|
package/dist/eck/kit-renderer.js
CHANGED
|
@@ -248,7 +248,7 @@ const PARAM_DESCRIPTIONS = {
|
|
|
248
248
|
personalAssistantName: '个人助理的显示名(名录快照)',
|
|
249
249
|
isPersonalAssistant: '当前 agent 是否就是 Owner 的个人助理(即时比较,读不到身份时为 false)',
|
|
250
250
|
isOwner: '当前 agent 是否就是协议确认的 Owner(即时比较;Owner 通常是人,一般恒为 false)',
|
|
251
|
-
contactsState: '
|
|
251
|
+
contactsState: '出站可发送与入站须准入的说明',
|
|
252
252
|
peerId: '对端在该渠道的原生 ID',
|
|
253
253
|
peerKey: '对端跨渠道唯一标识(channel#urlEncode(peerId))',
|
|
254
254
|
peerName: '对端显示名',
|
|
@@ -16,7 +16,17 @@ const MESSAGE_MANIFEST_FILE = 'eck_message_manifest.json';
|
|
|
16
16
|
// ── time formatting (per IANA timezone) ──
|
|
17
17
|
function timeParts(epochMs, timeZone, opts) {
|
|
18
18
|
const d = new Date(epochMs);
|
|
19
|
-
|
|
19
|
+
// 时区可能来自客户端上报(sender_ctx.timezone)或 agent 配置,非法 IANA 名会让
|
|
20
|
+
// Intl 抛 RangeError——那会整个消息渲染失败、消息直接丢给模型。这里退化为本机时区,
|
|
21
|
+
// 宁可时间基准退回本地,也不能让一条消息因为时区串写错而整条渲染不出来。
|
|
22
|
+
let p;
|
|
23
|
+
try {
|
|
24
|
+
p = new Intl.DateTimeFormat('en-US', { ...(timeZone ? { timeZone } : {}), ...opts }).formatToParts(d);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
logger.debug(`[MessageRenderer] invalid timezone ignored: ${String(timeZone)}`);
|
|
28
|
+
p = new Intl.DateTimeFormat('en-US', opts).formatToParts(d);
|
|
29
|
+
}
|
|
20
30
|
const out = {};
|
|
21
31
|
for (const part of p)
|
|
22
32
|
out[part.type] = part.value;
|
|
@@ -70,8 +80,14 @@ function speakerRelationOf(item, sessionVars) {
|
|
|
70
80
|
return String(item.speakerRelation
|
|
71
81
|
?? (String(sessionVars.chatType ?? '') === 'group' ? 'visitor' : (item.peerRole ?? sessionVars.peerRole ?? 'visitor')));
|
|
72
82
|
}
|
|
73
|
-
/**
|
|
74
|
-
|
|
83
|
+
/**
|
|
84
|
+
* `ctx: scene=… · activity=… · location=地址(纬度,经度 ±精度, 采集于 时刻)`;无 sender_ctx 返回空串。
|
|
85
|
+
*
|
|
86
|
+
* 精度与采集时刻缺省时**整段不写**——缺省的含义是「发件人没上报」,不是「精确」也
|
|
87
|
+
* 不是「就是此刻」。坐标恒定保留 6 位小数(协议原值的展示形态),精度另以 `±Nm` 标注,
|
|
88
|
+
* 两者语义分离:小数位只表示上报精度,不表示真实定位精度。
|
|
89
|
+
*/
|
|
90
|
+
function formatSenderCtx(ctx, timeZone) {
|
|
75
91
|
if (!ctx)
|
|
76
92
|
return '';
|
|
77
93
|
const parts = [];
|
|
@@ -83,7 +99,14 @@ function formatSenderCtx(ctx) {
|
|
|
83
99
|
if (loc && Number.isFinite(loc.latitude_e6) && Number.isFinite(loc.longitude_e6)) {
|
|
84
100
|
const lat = (loc.latitude_e6 / 1e6).toFixed(6);
|
|
85
101
|
const lon = (loc.longitude_e6 / 1e6).toFixed(6);
|
|
86
|
-
|
|
102
|
+
let coord = `${lat},${lon}`;
|
|
103
|
+
if (Number.isFinite(loc.accuracy_m) && loc.accuracy_m > 0) {
|
|
104
|
+
coord += ` ±${Math.round(loc.accuracy_m)}m`;
|
|
105
|
+
}
|
|
106
|
+
if (Number.isFinite(loc.timestamp_ms) && loc.timestamp_ms > 0) {
|
|
107
|
+
coord += `, 采集于 ${formatLocalTime(loc.timestamp_ms, timeZone)}`;
|
|
108
|
+
}
|
|
109
|
+
parts.push(`location=${loc.address ? `${loc.address}(${coord})` : coord}`);
|
|
87
110
|
}
|
|
88
111
|
return parts.length > 0 ? `ctx: ${parts.join(' · ')}` : '';
|
|
89
112
|
}
|
|
@@ -236,7 +259,7 @@ function renderOneItem(item, sessionVars, sessionCache, contentSentinel, compact
|
|
|
236
259
|
speakerRelation: speakerRelationOf(item, sessionVars),
|
|
237
260
|
// `mid:` 是恒出现字段:缺 messageId(非 AUN 渠道)时保留占位,不能让整段消失。
|
|
238
261
|
messageId: item.messageId ?? '-',
|
|
239
|
-
senderCtxLine: formatSenderCtx(item.senderCtx),
|
|
262
|
+
senderCtxLine: formatSenderCtx(item.senderCtx, tz),
|
|
240
263
|
batchItem: compact || undefined,
|
|
241
264
|
// 跨话题委托提醒:原消息与来源会话,供回查定位。
|
|
242
265
|
threadContextMessageId: item.threadContext?.messageId,
|
|
@@ -13,6 +13,7 @@ import { sanitizeMenuLogValue } from '../../core/command/menu-protocol.js';
|
|
|
13
13
|
import { stopEcwebProcess } from './lifecycle.js';
|
|
14
14
|
import { sanitizeServiceEnvironment } from '../../core/permission/shell-environment.js';
|
|
15
15
|
const INSTANCE_FILE_RE = /^(?:ecweb|watch-web)-\d+\.json$/;
|
|
16
|
+
const OCCUPIED_PORT_DISCOVERY_MS = 3000;
|
|
16
17
|
function sleep(ms) {
|
|
17
18
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
18
19
|
}
|
|
@@ -226,7 +227,10 @@ export function createEcwebSupervisor(options) {
|
|
|
226
227
|
};
|
|
227
228
|
const waitForHealthyInstance = async (timeoutMs) => {
|
|
228
229
|
const deadline = Date.now() + timeoutMs;
|
|
230
|
+
const port = desiredPort;
|
|
229
231
|
do {
|
|
232
|
+
if (stopping || !desiredEnabled || runtimeMode !== 'managed' || desiredPort !== port)
|
|
233
|
+
return null;
|
|
230
234
|
const found = await findHealthyInstance();
|
|
231
235
|
if (found)
|
|
232
236
|
return found;
|
|
@@ -336,16 +340,40 @@ export function createEcwebSupervisor(options) {
|
|
|
336
340
|
scheduleRecovery();
|
|
337
341
|
return;
|
|
338
342
|
}
|
|
339
|
-
const
|
|
340
|
-
|
|
343
|
+
const port = desiredPort;
|
|
344
|
+
let occupiedPids = await platform.findProcessByPortAsync(port);
|
|
345
|
+
if (stopping || !desiredEnabled || runtimeMode !== 'managed' || desiredPort !== port)
|
|
341
346
|
return;
|
|
342
347
|
if (occupiedPids.length > 0) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
//
|
|
346
|
-
//
|
|
347
|
-
|
|
348
|
-
|
|
348
|
+
// A CLI-started instance can bind before publishing its record or
|
|
349
|
+
// becoming healthy. Give discovery a bounded window before treating
|
|
350
|
+
// that normal startup overlap as a failure. Only a verified instance
|
|
351
|
+
// from this HOME can be adopted; unknown port owners stay untouched.
|
|
352
|
+
const existing = await waitForHealthyInstance(OCCUPIED_PORT_DISCOVERY_MS);
|
|
353
|
+
if (stopping || !desiredEnabled || runtimeMode !== 'managed' || desiredPort !== port)
|
|
354
|
+
return;
|
|
355
|
+
if (existing && await setActiveFromEntry(existing, false)) {
|
|
356
|
+
if (stopping || !desiredEnabled || runtimeMode !== 'managed' || desiredPort !== port)
|
|
357
|
+
return;
|
|
358
|
+
healthy = true;
|
|
359
|
+
checkedAt = Date.now();
|
|
360
|
+
launchRequested = false;
|
|
361
|
+
cancelRecovery();
|
|
362
|
+
failureCount = 0;
|
|
363
|
+
hasBeenReady = true;
|
|
364
|
+
settleInitialHealth?.('ok');
|
|
365
|
+
options.logger.info(`✓ ECWeb supervisor 接管现有实例 (PID: ${existing.record.pid}, 端口: ${existing.record.port})`);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
occupiedPids = await platform.findProcessByPortAsync(port);
|
|
369
|
+
if (stopping || !desiredEnabled || runtimeMode !== 'managed' || desiredPort !== port)
|
|
370
|
+
return;
|
|
371
|
+
if (occupiedPids.length > 0) {
|
|
372
|
+
options.logger.error(`ECWeb 本次启动失败:端口 ${port} 被占用 (PID: ${occupiedPids.join(', ')})`);
|
|
373
|
+
failureCount = failureThreshold;
|
|
374
|
+
scheduleRecovery();
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
349
377
|
}
|
|
350
378
|
fs.mkdirSync(resolvePaths().logs, { recursive: true });
|
|
351
379
|
fs.appendFileSync(logFile, `\n# daemon supervisor start ${new Date().toISOString()}\n`);
|
|
@@ -10,9 +10,9 @@ import { logger } from '../utils/logger.js';
|
|
|
10
10
|
import { EventCenterError } from './types.js';
|
|
11
11
|
import { AID_PATTERN, validateCenterConfig } from './validation.js';
|
|
12
12
|
export const EVENTS_CONFIG_JSON = 'events-config.json';
|
|
13
|
-
function defaultCenterConfig() {
|
|
13
|
+
function defaultCenterConfig(enabled = false) {
|
|
14
14
|
return {
|
|
15
|
-
enabled
|
|
15
|
+
enabled, authMode: 'allowlist',
|
|
16
16
|
admission: { coupling: 'on', rematerializeMs: 300_000 },
|
|
17
17
|
rules: {}, rateLimit: { perMinute: 60, perHour: 600 },
|
|
18
18
|
};
|
|
@@ -22,8 +22,12 @@ function readCenterConfig(filePath, migrateLegacyRules) {
|
|
|
22
22
|
try {
|
|
23
23
|
rawText = fs.readFileSync(filePath, 'utf8');
|
|
24
24
|
}
|
|
25
|
-
catch {
|
|
26
|
-
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error.code === 'ENOENT') {
|
|
27
|
+
return { config: defaultCenterConfig(true), exists: false, errors: [] };
|
|
28
|
+
}
|
|
29
|
+
return { config: defaultCenterConfig(), exists: true,
|
|
30
|
+
errors: [`Cannot read ${EVENTS_CONFIG_JSON}: ${error instanceof Error ? error.message : String(error)}`] };
|
|
27
31
|
}
|
|
28
32
|
let raw;
|
|
29
33
|
try {
|
|
@@ -54,7 +58,7 @@ function readCenterConfig(filePath, migrateLegacyRules) {
|
|
|
54
58
|
}
|
|
55
59
|
return { config: validated.value, exists: true, errors: [] };
|
|
56
60
|
}
|
|
57
|
-
/**
|
|
61
|
+
/** 缺少配置时启用默认通知;显式关闭、非法和不可读配置保持关闭。 */
|
|
58
62
|
export function loadCenterConfig(eventsDir) {
|
|
59
63
|
migrateLegacyFileName(eventsDir, 'center.json', EVENTS_CONFIG_JSON, 'events config');
|
|
60
64
|
return readCenterConfig(path.join(eventsDir, EVENTS_CONFIG_JSON), true);
|
|
@@ -17,13 +17,18 @@ function resolveEntryBus(resolutions, packId, entry) {
|
|
|
17
17
|
export class EventDispatcher {
|
|
18
18
|
scriptRunner;
|
|
19
19
|
limits;
|
|
20
|
+
canDispatch;
|
|
20
21
|
queues = new Map();
|
|
21
22
|
running = 0;
|
|
22
23
|
closed = false;
|
|
23
24
|
idleResolvers = [];
|
|
24
|
-
constructor(scriptRunner, limits = DEFAULT_DISPATCHER_LIMITS) {
|
|
25
|
+
constructor(scriptRunner, limits = DEFAULT_DISPATCHER_LIMITS, canDispatch = () => true) {
|
|
25
26
|
this.scriptRunner = scriptRunner;
|
|
26
27
|
this.limits = limits;
|
|
28
|
+
this.canDispatch = canDispatch;
|
|
29
|
+
}
|
|
30
|
+
isBusy() {
|
|
31
|
+
return this.running > 0 || !this.isEmpty();
|
|
27
32
|
}
|
|
28
33
|
setLimits(limits) {
|
|
29
34
|
this.limits = { ...this.limits, ...limits };
|
|
@@ -40,6 +45,10 @@ export class EventDispatcher {
|
|
|
40
45
|
const log = EventLog.forPack(pack);
|
|
41
46
|
// 写前日志:received 一定先落盘。
|
|
42
47
|
log.writeReceived(event);
|
|
48
|
+
if (!this.canDispatch()) {
|
|
49
|
+
log.writeDropped(event, 'agent_mutation_paused');
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
43
52
|
if (entry.filter && !this.matches(entry.filter, event)) {
|
|
44
53
|
log.writeFiltered(event, 'filter_mismatch');
|
|
45
54
|
continue;
|
|
@@ -13,6 +13,7 @@ import { installPack, listPackDirs, removePack, setPackEnabled } from '../core/p
|
|
|
13
13
|
import { CenterConfigStore } from './center-config.js';
|
|
14
14
|
import { agentEventsDir } from '../paths.js';
|
|
15
15
|
import { authorizePackTarget, packOperation } from '../core/pack-auth.js';
|
|
16
|
+
import { OUTPUT_CARDS_EVENT } from '../outputs/protocol.js';
|
|
16
17
|
const HELP = `ec events — 事件中心运维
|
|
17
18
|
|
|
18
19
|
用法:
|
|
@@ -121,6 +122,9 @@ export function parseEventsArgv(argv) {
|
|
|
121
122
|
parsed.command = `rules:${positional[0] ?? ''}`;
|
|
122
123
|
parsed.event = parsed.event ?? positional[1];
|
|
123
124
|
}
|
|
125
|
+
else if (command === 'native-publish') {
|
|
126
|
+
parsed.nativeEvent = positional[0];
|
|
127
|
+
}
|
|
124
128
|
return parsed;
|
|
125
129
|
}
|
|
126
130
|
function resolveAid(deps, parsed, opts = {}) {
|
|
@@ -200,6 +204,21 @@ async function execute(deps, parsed) {
|
|
|
200
204
|
});
|
|
201
205
|
if (!auth.allowed)
|
|
202
206
|
return { ok: false, code: auth.code, error: auth.error };
|
|
207
|
+
if (command === 'native-publish') {
|
|
208
|
+
const data = parsed.data;
|
|
209
|
+
if (parsed.caller?.kind !== 'managed' || parsed.caller.selfAid !== aid
|
|
210
|
+
|| parsed.caller.peerRole !== 'owner'
|
|
211
|
+
|| parsed.nativeEvent !== OUTPUT_CARDS_EVENT || !data || typeof data !== 'object' || Array.isArray(data)
|
|
212
|
+
|| data.sourceAid !== aid || typeof data.revision !== 'string'
|
|
213
|
+
|| typeof data.cursor !== 'string') {
|
|
214
|
+
return { ok: false, code: 'NOT_ALLOWED', error: 'Native output-card notifications may only be published for the current Agent' };
|
|
215
|
+
}
|
|
216
|
+
const published = await deps.registry.publishAgentEvent(aid, OUTPUT_CARDS_EVENT, data);
|
|
217
|
+
if (!published) {
|
|
218
|
+
return { ok: false, code: 'EVENT_CENTER_NOT_RUNNING', error: `output-card notifications are unavailable for ${aid}` };
|
|
219
|
+
}
|
|
220
|
+
return { ok: true, result: { aid, event: OUTPUT_CARDS_EVENT } };
|
|
221
|
+
}
|
|
203
222
|
if (command === 'reload') {
|
|
204
223
|
await deps.registry.reload(aid);
|
|
205
224
|
const unit = deps.registry.get(aid);
|
|
@@ -40,6 +40,21 @@ export class EventCenterRegistry {
|
|
|
40
40
|
scanLedgerSigs = new Map();
|
|
41
41
|
/** reload 串行队列:aid → 队尾 promise。 */
|
|
42
42
|
reloadQueues = new Map();
|
|
43
|
+
mutationPauses = new Map();
|
|
44
|
+
/** Freeze handler starts without replacing the Agent's AUN connection or Bus lease. */
|
|
45
|
+
pauseForMutation(aid, token) {
|
|
46
|
+
if (this.units.get(aid)?.dispatcher.isBusy()) {
|
|
47
|
+
throw Object.assign(new Error('Agent event handlers are busy: ' + aid), { code: 'AGENT_BUSY' });
|
|
48
|
+
}
|
|
49
|
+
const tokens = this.mutationPauses.get(aid) ?? new Set();
|
|
50
|
+
tokens.add(token);
|
|
51
|
+
this.mutationPauses.set(aid, tokens);
|
|
52
|
+
return () => {
|
|
53
|
+
tokens.delete(token);
|
|
54
|
+
if (!tokens.size && this.mutationPauses.get(aid) === tokens)
|
|
55
|
+
this.mutationPauses.delete(aid);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
43
58
|
/** 签名未变则跳过 append。 */
|
|
44
59
|
ledgerOnce(aid, key, sig, append) {
|
|
45
60
|
let sigs = this.scanLedgerSigs.get(aid);
|
|
@@ -67,12 +82,12 @@ export class EventCenterRegistry {
|
|
|
67
82
|
}
|
|
68
83
|
/** Publish a fixed event from an internal read-only projection when configured. */
|
|
69
84
|
async publishAgentEvent(aid, event, data) {
|
|
70
|
-
if (event !== 'team.outputs.changed' && event !== 'team.workbench.changed')
|
|
71
|
-
return;
|
|
85
|
+
if (event !== 'team.outputs.changed' && event !== 'team.output-cards.changed' && event !== 'team.workbench.changed')
|
|
86
|
+
return false;
|
|
72
87
|
const unit = this.units.get(aid);
|
|
73
88
|
if (!unit)
|
|
74
|
-
return;
|
|
75
|
-
|
|
89
|
+
return false;
|
|
90
|
+
return unit.runtime.publishNativeProjection(event, data);
|
|
76
91
|
}
|
|
77
92
|
ensureStarted(aid) {
|
|
78
93
|
const existing = this.starts.get(aid);
|
|
@@ -349,7 +364,7 @@ export class EventCenterRegistry {
|
|
|
349
364
|
}
|
|
350
365
|
},
|
|
351
366
|
});
|
|
352
|
-
const dispatcher = new EventDispatcher(scriptRunner);
|
|
367
|
+
const dispatcher = new EventDispatcher(scriptRunner, undefined, () => !this.mutationPauses.get(aid)?.size);
|
|
353
368
|
const runtime = new EventRuntime({
|
|
354
369
|
aid,
|
|
355
370
|
getClient: this.options.getClient,
|
|
@@ -105,27 +105,29 @@ export class EventRuntime {
|
|
|
105
105
|
}
|
|
106
106
|
async publishNativeProjection(event, data) {
|
|
107
107
|
if (!PRIVATE_PROJECTION_EVENTS.some(value => value === event))
|
|
108
|
-
return;
|
|
108
|
+
return false;
|
|
109
109
|
if (!this.nativeOutputAvailable)
|
|
110
|
-
return;
|
|
110
|
+
return false;
|
|
111
111
|
this.nativeOutputPending.set(event, data);
|
|
112
112
|
if (this.nativeOutputFlight)
|
|
113
113
|
return this.nativeOutputFlight;
|
|
114
114
|
this.nativeOutputFlight = (async () => {
|
|
115
115
|
// Bound a burst to one in-flight notification and one latest invalidation.
|
|
116
|
-
while (this.nativeOutputPending.size
|
|
116
|
+
while (this.nativeOutputPending.size) {
|
|
117
|
+
if (!this.nativeOutputAvailable)
|
|
118
|
+
return false;
|
|
117
119
|
const [event, latest] = this.nativeOutputPending.entries().next().value;
|
|
118
120
|
this.nativeOutputPending.delete(event);
|
|
119
121
|
const handle = await this.ensureClient();
|
|
120
122
|
if (!handle || !this.nativeOutputAvailable)
|
|
121
|
-
return;
|
|
123
|
+
return false;
|
|
122
124
|
const owner = await ownerResolver.refresh(this.options.aid, { source: 'outputs.publish',
|
|
123
125
|
maxAgeMs: OWNERSHIP_AUTHORIZATION_MAX_AGE_MS, allowTransient: false });
|
|
124
126
|
if (!await this.rematerialize())
|
|
125
|
-
return;
|
|
127
|
+
return false;
|
|
126
128
|
if (owner.authorizationStatus !== 'verified' || owner.refreshFailure?.fallbackUsed
|
|
127
129
|
|| (owner.validUntil ?? 0) <= Date.now() || !this.nativeOutputAvailable)
|
|
128
|
-
return;
|
|
130
|
+
return false;
|
|
129
131
|
const events = new Set([...PRIVATE_PROJECTION_EVENTS, ...(this.registeredPubBuses.get(this.options.aid) ?? [])]);
|
|
130
132
|
if (this.nativeOutputPublisher !== handle || PRIVATE_PROJECTION_EVENTS.some(value => !this.registeredPubBuses.get(this.options.aid)?.has(value))) {
|
|
131
133
|
await handle.EventService.authorize(this.options.aid, 'pub', 'allowlist', [...events]);
|
|
@@ -136,9 +138,10 @@ export class EventRuntime {
|
|
|
136
138
|
if (currentOwner.authorizationStatus !== 'verified' || currentOwner.refreshFailure?.fallbackUsed
|
|
137
139
|
|| (currentOwner.validUntil ?? 0) <= Date.now() || currentOwner.ownerAid !== owner.ownerAid
|
|
138
140
|
|| currentOwner.revision !== owner.revision || !this.nativeOutputAvailable)
|
|
139
|
-
return;
|
|
141
|
+
return false;
|
|
140
142
|
await handle.EventService.publish(this.options.aid, event, latest, { ttlSeconds: 30, schemaVersion: 1 });
|
|
141
143
|
}
|
|
144
|
+
return true;
|
|
142
145
|
})().finally(() => { this.nativeOutputFlight = undefined; this.nativeOutputPending.clear(); });
|
|
143
146
|
return this.nativeOutputFlight;
|
|
144
147
|
}
|
package/dist/index.js
CHANGED
|
@@ -93,6 +93,7 @@ import { TargetSessionLockRegistry } from './trigger/session-lock.js';
|
|
|
93
93
|
import { buildTriggerScheduler, createTriggerChannelResolver, TriggerSchedulerRegistry } from './trigger/application-service.js';
|
|
94
94
|
import { createDaemonEventCenter } from './event-center/daemon.js';
|
|
95
95
|
import { setOutputChangePublisher } from './outputs/service.js';
|
|
96
|
+
import { setOutputCardsNotificationsAvailable } from './outputs/cards.js';
|
|
96
97
|
import { setWorkbenchChangePublisher, setWorkbenchRuntimeProvider, notifyWorkbenchRuntimeChanged } from './workbench/service.js';
|
|
97
98
|
import { DaemonChannel } from './channels/daemon.js';
|
|
98
99
|
import { DAEMON_RUNTIME_EPOCH_ENV, ensureProcessManagedTempDir } from './cli/task-context.js';
|
|
@@ -856,6 +857,7 @@ async function main() {
|
|
|
856
857
|
setOutputChangePublisher((aid, data) => {
|
|
857
858
|
void eventCenter.publishAgentEvent(aid, 'team.outputs.changed', data).catch(() => { });
|
|
858
859
|
}, aid => eventCenter.get(aid)?.runtime.nativeOutputAvailable === true);
|
|
860
|
+
setOutputCardsNotificationsAvailable(aid => eventCenter.get(aid)?.runtime.nativeOutputAvailable === true);
|
|
859
861
|
setWorkbenchChangePublisher((aid, data) => {
|
|
860
862
|
void eventCenter.publishAgentEvent(aid, 'team.workbench.changed', data).catch(() => { });
|
|
861
863
|
}, aid => eventCenter.get(aid)?.runtime.nativeOutputAvailable === true);
|
|
@@ -874,6 +876,7 @@ async function main() {
|
|
|
874
876
|
setWorkbenchRuntimeProvider();
|
|
875
877
|
setWorkbenchChangePublisher();
|
|
876
878
|
setOutputChangePublisher(undefined);
|
|
879
|
+
setOutputCardsNotificationsAvailable();
|
|
877
880
|
for (const type of ['agent:started', 'agent:stopped', 'agent:enabled', 'agent:disabled', 'agent:error']) {
|
|
878
881
|
eventBus.unsubscribe(type, workbenchLifecycle);
|
|
879
882
|
}
|
|
@@ -1459,6 +1462,7 @@ async function main() {
|
|
|
1459
1462
|
}
|
|
1460
1463
|
},
|
|
1461
1464
|
getScheduler: aid => triggerSchedulers.get(aid),
|
|
1465
|
+
pauseEvents: (aid, token) => eventCenter.pauseForMutation(aid, token),
|
|
1462
1466
|
recoveryComplete: (aid, succeeded) => {
|
|
1463
1467
|
if (succeeded && (templateStartupRecovery.pending.has(aid) || templateRecoveryMutes.has(aid))) {
|
|
1464
1468
|
const agent = agentRegistry.get(aid);
|
package/dist/ipc.js
CHANGED
|
@@ -7,6 +7,7 @@ import os from 'os';
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { execFile } from 'node:child_process';
|
|
9
9
|
import { logger, logOwnershipEvent } from './utils/logger.js';
|
|
10
|
+
import { readEffectiveCpuCount } from './utils/host-info.js';
|
|
10
11
|
import { fileCache } from './core/daemon-file-cache.js';
|
|
11
12
|
import { DAEMON_RUNTIME_EPOCH_ENV, isTrustedFullAccessRuntimeContext } from './cli/task-context.js';
|
|
12
13
|
import { HANDOFF_QUERY_MAX_LIMIT, HANDOFF_STATES } from './core/handoff/types.js';
|
|
@@ -99,6 +100,7 @@ const MEMORY_COMMAND_ENDPOINTS = new Set([
|
|
|
99
100
|
'memory.create', 'memory.update', 'memory.archive', 'memory.demote', 'memory.consolidate',
|
|
100
101
|
]);
|
|
101
102
|
const DELEGATED_ARGV_ENDPOINTS = new Set([
|
|
103
|
+
'quota.op',
|
|
102
104
|
'agent.op', 'ability.op', 'config.op', 'peer.op', 'aid.op', 'aid.ownership', 'group.op', 'msg.op', 'fs.op', 'proxy.op', 'provider.op', 'invoke.op',
|
|
103
105
|
'upgrade.op',
|
|
104
106
|
'ctl', 'diag', 'menu-client.request', 'task.resume', 'queue.op', 'storage.auth', 'storage.upload',
|
|
@@ -246,6 +248,7 @@ export class IpcServer {
|
|
|
246
248
|
configOperationExecutor;
|
|
247
249
|
peerOperationExecutor;
|
|
248
250
|
roleOperationExecutor;
|
|
251
|
+
quotaOperationExecutor;
|
|
249
252
|
aidOperationExecutor;
|
|
250
253
|
directoryOperationExecutor;
|
|
251
254
|
groupOperationExecutor;
|
|
@@ -368,6 +371,9 @@ export class IpcServer {
|
|
|
368
371
|
setRoleOperationExecutor(executor) {
|
|
369
372
|
this.roleOperationExecutor = executor;
|
|
370
373
|
}
|
|
374
|
+
setQuotaOperationExecutor(executor) {
|
|
375
|
+
this.quotaOperationExecutor = executor;
|
|
376
|
+
}
|
|
371
377
|
setSkillRefreshExecutor(executor) {
|
|
372
378
|
this.skillRefreshExecutor = executor;
|
|
373
379
|
}
|
|
@@ -469,7 +475,7 @@ export class IpcServer {
|
|
|
469
475
|
snapshot: {
|
|
470
476
|
ts: Date.now(),
|
|
471
477
|
uptimeMs: Math.round(process.uptime() * 1000),
|
|
472
|
-
cpuCount:
|
|
478
|
+
cpuCount: readEffectiveCpuCount(),
|
|
473
479
|
memory: {
|
|
474
480
|
rss: processTreeRss,
|
|
475
481
|
heapUsed: mem.heapUsed,
|
|
@@ -2477,6 +2483,24 @@ export class IpcServer {
|
|
|
2477
2483
|
}
|
|
2478
2484
|
return await this.peerOperationExecutor(argv, sessionId, delegationToken, typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined);
|
|
2479
2485
|
}
|
|
2486
|
+
case 'quota.op': {
|
|
2487
|
+
if (!this.quotaOperationExecutor)
|
|
2488
|
+
return { ok: false, code: 'NOT_CONFIGURED', error: 'quota.op not configured; restart the host after building' };
|
|
2489
|
+
if (!Array.isArray(cmd.argv) || cmd.argv.some((value) => typeof value !== 'string')) {
|
|
2490
|
+
return { ok: false, code: 'INVALID_REQUEST', error: 'invalid argv' };
|
|
2491
|
+
}
|
|
2492
|
+
const delegated = cmd.sessionId !== undefined || cmd.delegationToken !== undefined || cmd.actorSessionId !== undefined;
|
|
2493
|
+
if (!delegated) {
|
|
2494
|
+
if (!this.hasValidControlToken(cmd.controlToken))
|
|
2495
|
+
return { ok: false, code: 'CONTROL_TOKEN_REQUIRED', error: 'Host quota queries require a valid control token' };
|
|
2496
|
+
return await this.quotaOperationExecutor(cmd.argv, '', undefined, undefined, true);
|
|
2497
|
+
}
|
|
2498
|
+
if (typeof cmd.sessionId !== 'string' || !cmd.sessionId)
|
|
2499
|
+
return { ok: false, code: 'INVALID_REQUEST', error: 'missing sessionId' };
|
|
2500
|
+
if (typeof cmd.delegationToken !== 'string' || !cmd.delegationToken)
|
|
2501
|
+
return { ok: false, code: 'INVALID_DELEGATION', error: 'missing delegationToken' };
|
|
2502
|
+
return await this.quotaOperationExecutor(cmd.argv, cmd.sessionId, cmd.delegationToken, typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined);
|
|
2503
|
+
}
|
|
2480
2504
|
case 'role.op': {
|
|
2481
2505
|
if (!this.roleOperationExecutor)
|
|
2482
2506
|
return { ok: false, code: 'NOT_CONFIGURED', error: 'role.op not configured' };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ownerResolver, OWNERSHIP_AUTHORIZATION_MAX_AGE_MS } from '../core/ownership/owner-resolver.js';
|
|
2
|
+
import { DataRootError } from '../core/command/team-workspace-store.js';
|
|
3
|
+
export async function authorizeOutput(aid, from) {
|
|
4
|
+
const view = await ownerResolver.refresh(aid, { maxAgeMs: OWNERSHIP_AUTHORIZATION_MAX_AGE_MS, source: 'outputs.read', allowTransient: false });
|
|
5
|
+
if (view.authorizationStatus !== 'verified' || view.ownerAid !== from || view.refreshFailure?.fallbackUsed
|
|
6
|
+
|| (view.validUntil ?? 0) <= Date.now()) {
|
|
7
|
+
throw new DataRootError('OUTPUT_FORBIDDEN', 'Current protocol Owner authorization is required');
|
|
8
|
+
}
|
|
9
|
+
return `${view.ownerAid}:${view.revision}`;
|
|
10
|
+
}
|
|
11
|
+
export function currentOutputOwner(aid, from, generation) {
|
|
12
|
+
const view = ownerResolver.snapshot(aid);
|
|
13
|
+
return view.authorizationStatus === 'verified' && !view.refreshFailure?.fallbackUsed
|
|
14
|
+
&& (view.validUntil ?? 0) > Date.now()
|
|
15
|
+
&& view.ownerAid === from && `${view.ownerAid}:${view.revision}` === generation;
|
|
16
|
+
}
|