evolcore 0.0.41 → 0.0.42
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/codex-managed-hook.mjs +9 -5
- package/dist/agents/baseagent.js +156 -16
- package/dist/agents/claude-runner.js +10 -3
- package/dist/agents/codex/catalog.js +8 -4
- package/dist/agents/codex-runner.js +236 -59
- package/dist/agents/ecagent-runner.js +82 -13
- package/dist/aun/aid/agentmd.js +106 -27
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/aid/control-aid.js +65 -13
- package/dist/aun/aid/identity.js +70 -4
- package/dist/aun/aid/index.js +2 -2
- package/dist/aun/service-proxy.js +25 -1
- package/dist/channels/aun.js +242 -209
- package/dist/channels/dingtalk.js +1 -1
- package/dist/channels/feishu.js +1 -1
- package/dist/channels/qqbot.js +1 -1
- package/dist/channels/wechat.js +1 -1
- package/dist/channels/wecom.js +1 -1
- package/dist/cli/agent-command.js +183 -3
- package/dist/cli/agent-create.js +92 -86
- package/dist/cli/agent.js +136 -1
- package/dist/cli/aun-commands.js +137 -35
- package/dist/cli/bench.js +8 -2
- package/dist/cli/command-log.js +1 -1
- package/dist/cli/daemon-commands.js +235 -51
- package/dist/cli/debug-mode.js +1 -1
- package/dist/cli/directory.js +170 -0
- package/dist/cli/index.js +40 -30
- package/dist/cli/init-channel.js +4 -4
- package/dist/cli/init.js +47 -32
- package/dist/cli/managed-command-guard.js +4 -1
- package/dist/cli/model.js +27 -18
- package/dist/cli/pa-workspace-command.js +191 -0
- package/dist/cli/{contact.js → peer.js} +19 -25
- package/dist/cli/restart-monitor.js +11 -4
- package/dist/cli/thread-command.js +47 -18
- package/dist/cli/version.js +18 -18
- package/dist/config/access-policy.js +29 -12
- package/dist/config/boot-log.js +65 -10
- package/dist/config/builtin-roles.js +2 -4
- package/dist/config/config-field-policy.js +3 -0
- package/dist/config/config-manager.js +28 -20
- package/dist/config/{contact-bind-code.js → peer-bind-code.js} +6 -6
- package/dist/config/{contact-book-store.js → peer-book-store.js} +75 -75
- package/dist/config/{contact-book-v2-startup.js → peer-book-v2-startup.js} +2 -2
- package/dist/config/{contact-book.js → peer-book.js} +47 -47
- package/dist/config/peer-operation-service.js +132 -0
- package/dist/config/{contact-request-service.js → peer-request-service.js} +90 -90
- package/dist/config/peer-role-resolver.js +3 -3
- package/dist/config/providers-config.js +17 -8
- package/dist/config/providers.js +1 -1
- package/dist/config/schema-migration.js +336 -39
- package/dist/core/agent-application-service.js +8 -2
- package/dist/core/agent-create-status.js +4 -5
- package/dist/core/agent-ipc-registration.js +5 -4
- package/dist/core/agent-runtime.js +30 -17
- package/dist/core/auth/operation-authorizer.js +0 -24
- package/dist/core/auth/operation-catalog.js +4 -20
- package/dist/core/baseagent-loader.js +27 -3
- package/dist/core/bootstrap-service.js +5 -22
- package/dist/core/capability/capability-manager.js +52 -35
- package/dist/core/channel-loader.js +43 -2
- package/dist/core/channel-runtime.js +2 -2
- package/dist/core/command/agent-control.js +54 -18
- package/dist/core/command/command-handler.js +92 -72
- package/dist/core/command/connect-menu.js +35 -42
- package/dist/core/command/daemon-diagnostics.js +41 -5
- package/dist/core/command/data-root-error.js +10 -0
- package/dist/core/command/data-root-resolver.js +53 -13
- package/dist/core/command/menu-catalog.js +1 -0
- package/dist/core/command/menu-handler.js +163 -65
- package/dist/core/command/menu-protocol.js +52 -0
- package/dist/core/command/pa-workspace-calendar.js +223 -0
- package/dist/core/command/pa-workspace-store.js +459 -0
- package/dist/core/command/role-menu.js +2 -2
- package/dist/core/command/slash-gate.js +1 -1
- package/dist/core/command/slash-handler.js +57 -41
- package/dist/core/daemon-lifecycle.js +90 -31
- package/dist/core/evolagent.js +6 -10
- package/dist/core/handoff/runtime.js +11 -4
- package/dist/core/host-snapshot.js +208 -0
- package/dist/core/initialization/service.js +152 -20
- package/dist/core/ipc-registration.js +33 -4
- package/dist/core/memory/batch-meta.js +27 -0
- package/dist/core/memory/consolidation-ops-records.js +44 -1
- package/dist/core/memory/consolidation.js +169 -27
- package/dist/core/message/aun-ipc-sender.js +2 -8
- package/dist/core/message/im-renderer.js +56 -3
- package/dist/core/message/message-admission.js +121 -124
- package/dist/core/message/message-bridge.js +38 -54
- package/dist/core/message/message-queue.js +7 -0
- package/dist/core/message/outbound.js +34 -9
- package/dist/core/message/response-engine.js +154 -73
- package/dist/core/model/catalog-service.js +1 -1
- package/dist/core/model/config-scope.js +2 -2
- package/dist/core/model/model-catalog.js +5 -4
- package/dist/core/model/model-diagnostics.js +6 -5
- package/dist/core/model/model-fallback.js +3 -6
- package/dist/core/model/model-permission.js +1 -1
- package/dist/core/ownership/owner-resolver.js +9 -9
- package/dist/core/permission/approval-gateway.js +1 -1
- package/dist/core/permission/ec-command-parser.js +2 -2
- package/dist/core/permission/tool-canonical.js +96 -46
- package/dist/core/permission/tool-error-code.js +41 -0
- package/dist/core/permission/tool-policy.js +71 -47
- package/dist/core/role/runtime-policy.js +1 -1
- package/dist/core/session/session-idle-monitor.js +10 -0
- package/dist/core/session/session-manager.js +2 -4
- package/dist/core/session/session-title.js +36 -8
- package/dist/core/system-session/memory.js +2 -7
- package/dist/core/thread/command-parser.js +6 -2
- package/dist/core/thread/ipc-operation.js +51 -36
- package/dist/core/thread/thread-operation.js +29 -61
- package/dist/core/thread/thread-service.js +57 -13
- package/dist/directory/canonical-digest.js +54 -0
- package/dist/directory/owner-directory-admission.js +114 -43
- package/dist/directory/owner-directory-agentmd-sync.js +89 -0
- package/dist/directory/owner-directory-cache.js +847 -459
- package/dist/directory/owner-directory-markdown.js +272 -0
- package/dist/directory/owner-directory-query-operation.js +195 -0
- package/dist/directory/owner-directory-remark-operation.js +147 -0
- package/dist/directory/owner-directory-remarks.js +145 -0
- package/dist/directory/owner-directory-scope.js +55 -0
- package/dist/directory/owner-directory-search.js +148 -0
- package/dist/directory/owner-directory-store.js +227 -0
- package/dist/eck/kit-renderer.js +1 -0
- package/dist/ecweb/basic-settings-service.js +4 -1
- package/dist/ecweb/message-context-service.js +13 -9
- package/dist/index.js +195 -37
- package/dist/ipc.js +86 -22
- package/dist/paths.js +11 -8
- package/dist/product.js +2 -0
- package/dist/proxy/manager.js +13 -2
- package/dist/proxy/service-supervisor.js +8 -1
- package/dist/trigger/history.js +23 -0
- package/dist/trigger/scheduler.js +3 -0
- package/dist/utils/atomic-write.js +21 -0
- package/dist/utils/cross-platform.js +35 -0
- package/dist/utils/ecweb-supervisor.js +42 -0
- package/dist/utils/error-utils.js +2 -1
- package/dist/utils/evolcore-version.js +19 -0
- package/dist/utils/host-info.js +242 -5
- package/dist/utils/instance-registry.js +28 -6
- package/dist/utils/logger.js +59 -14
- package/dist/utils/machine-info.js +46 -0
- package/dist/utils/process-introspect.js +166 -2
- package/dist/utils/startup-trace.js +245 -0
- package/ecagent/dist/agent-loop.js +27 -13
- package/ecagent/dist/harness/agent-harness.js +3 -3
- package/ecagent/dist/harness/types.d.ts +1 -0
- package/ecagent/dist/types.d.ts +1 -0
- package/kits/docs/INDEX.md +1 -1
- package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +72 -0
- package/kits/docs/evolcore/INDEX.md +3 -2
- package/kits/docs/evolcore/agent-create.md +17 -27
- package/kits/docs/evolcore/agent.md +4 -1
- package/kits/docs/evolcore/aid.md +3 -1
- package/kits/docs/evolcore/config.md +16 -5
- package/kits/docs/evolcore/ctl.md +9 -0
- package/kits/docs/evolcore/ec-capabilities.md +19 -0
- package/kits/docs/evolcore/memory-consolidation-batches.md +79 -5
- package/kits/docs/evolcore/menu-exec-schema-commands.md +2 -1
- package/kits/docs/evolcore/menu-protocol.md +1 -0
- package/kits/docs/evolcore/model.md +13 -4
- package/kits/docs/evolcore/msg.md +1 -1
- package/kits/docs/evolcore/pa-workspace.md +51 -0
- package/kits/docs/evolcore/peer.md +73 -0
- package/kits/docs/evolcore/thread-chain.md +4 -1
- package/kits/eck_manifest.json +21 -0
- package/kits/rules/06-channel.md +1 -1
- package/kits/schemas/_meta.json +12 -1
- package/kits/schemas/agent-config.schema.16.json +6 -0
- package/kits/schemas/agent-config.schema.17.json +897 -0
- package/kits/schemas/daemon.schema.9.json +8 -1
- package/kits/skills/ec-agent-create/SKILL.md +2 -2
- package/kits/skills/ec-identity/SKILL.md +45 -27
- package/kits/skills/ec-service-proxy/SKILL.md +7 -2
- package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +4 -5
- package/kits/skills/thread-ops/SKILL.md +11 -11
- package/kits/templates/bootstrap-welcome.md +3 -15
- package/kits/templates/message-fragments/item.md +1 -1
- package/kits/templates/system-fragments/bootstrap.md +24 -23
- package/kits/templates/system-fragments/commands.md +12 -5
- package/kits/templates/system-fragments/thread.md +18 -3
- package/package.json +6 -4
- package/dist/config/contact-operation-service.js +0 -235
- package/dist/directory/owner-directory-authorization.js +0 -309
- package/kits/docs/evolcore/contact.md +0 -78
- /package/dist/config/{contact-alias.js → peer-alias.js} +0 -0
|
@@ -31,19 +31,35 @@ const linuxClockTicks = readLinuxClockTicks();
|
|
|
31
31
|
export const START_TIME_TOLERANCE_MS = 2000;
|
|
32
32
|
/** 本进程的启动时间不会变;Windows 上每次查询都要拉起一次 PowerShell(约 0.4s)。 */
|
|
33
33
|
let selfStartTime = null;
|
|
34
|
+
/**
|
|
35
|
+
* 本进程启动时刻的近似值:`Date.now() - uptime()`。
|
|
36
|
+
*
|
|
37
|
+
* uptime 只有整秒粒度,且从 node 启动点算起(早于本进程被创建的时刻只有毫秒级),
|
|
38
|
+
* 与系统记录的真实创建时间偏差在 1s 以内,小于 `START_TIME_TOLERANCE_MS`。
|
|
39
|
+
* 需要它是因为自身的启动时间在 Windows 上要靠 PowerShell CIM 才能拿到,而它正好
|
|
40
|
+
* 卡在启动关键路径上(写 instance record、选主自检各一次)。
|
|
41
|
+
*/
|
|
42
|
+
function approximateSelfStartTime() {
|
|
43
|
+
const uptimeMs = Math.round(process.uptime() * 1000);
|
|
44
|
+
return uptimeMs > 0 ? Date.now() - uptimeMs : Date.now();
|
|
45
|
+
}
|
|
34
46
|
/**
|
|
35
47
|
* 获取进程启动时间(Unix 毫秒)。
|
|
36
48
|
* 拿不到时返回 null,调用方应保守处理(不杀该 PID)。
|
|
37
49
|
*/
|
|
38
50
|
export function getProcessStartTime(pid) {
|
|
39
51
|
if (pid === process.pid) {
|
|
40
|
-
//
|
|
52
|
+
// 自身不查 CIM:近似值已在容差内,省掉一次 PowerShell 进程启动。
|
|
41
53
|
if (selfStartTime === null)
|
|
42
|
-
selfStartTime =
|
|
54
|
+
selfStartTime = approximateSelfStartTime();
|
|
43
55
|
return selfStartTime;
|
|
44
56
|
}
|
|
45
57
|
return readProcessStartTime(pid);
|
|
46
58
|
}
|
|
59
|
+
/** 测试用:清掉自身启动时间缓存。 */
|
|
60
|
+
export function resetSelfStartTimeCache() {
|
|
61
|
+
selfStartTime = null;
|
|
62
|
+
}
|
|
47
63
|
function readProcessStartTime(pid) {
|
|
48
64
|
try {
|
|
49
65
|
if (isWindows)
|
|
@@ -145,6 +161,154 @@ function parseDateString(value) {
|
|
|
145
161
|
const parsed = Date.parse(value);
|
|
146
162
|
return Number.isNaN(parsed) ? null : parsed;
|
|
147
163
|
}
|
|
164
|
+
let snapshotCache = null;
|
|
165
|
+
/**
|
|
166
|
+
* 同一次启动流程里多处调用共享快照。
|
|
167
|
+
*
|
|
168
|
+
* 启动期依次要做三次存活扫描(instancePreCheck → instanceRecord 前的选主自检 →
|
|
169
|
+
* 实例登记),中间夹着整个配置迁移(约 1.2s)。窗口太短会让后两次重新拉全表,
|
|
170
|
+
* 每次约 0.45s,等于把优化又还回去。5s 足够覆盖整段启动,而快照只用于「记录里的
|
|
171
|
+
* 进程还在不在」这种只读判断——真正要杀进程的清理路径走的是实时查询,不受影响。
|
|
172
|
+
*/
|
|
173
|
+
const SNAPSHOT_TTL_MS = 5000;
|
|
174
|
+
/**
|
|
175
|
+
* 取一份进程快照。同一毫秒级的连续调用复用缓存,避免启动期三次扫描各拉一次全表。
|
|
176
|
+
* 传 `{ fresh: true }` 可强制重新采集(例如清理前需要最新状态)。
|
|
177
|
+
*/
|
|
178
|
+
export function getProcessSnapshot(options = {}) {
|
|
179
|
+
const now = Date.now();
|
|
180
|
+
if (!options.fresh && snapshotCache && now - snapshotCache.at < SNAPSHOT_TTL_MS) {
|
|
181
|
+
return snapshotCache.snapshot;
|
|
182
|
+
}
|
|
183
|
+
const snapshot = readProcessSnapshot();
|
|
184
|
+
snapshotCache = { at: now, snapshot };
|
|
185
|
+
return snapshot;
|
|
186
|
+
}
|
|
187
|
+
/** 让测试或长驻进程主动失效快照。 */
|
|
188
|
+
export function invalidateProcessSnapshot() {
|
|
189
|
+
snapshotCache = null;
|
|
190
|
+
}
|
|
191
|
+
function readProcessSnapshot() {
|
|
192
|
+
if (isWindows) {
|
|
193
|
+
const windows = readWindowsSnapshot();
|
|
194
|
+
if (windows)
|
|
195
|
+
return windows;
|
|
196
|
+
return { complete: false, startedAt: new Map(), commandLines: new Map() };
|
|
197
|
+
}
|
|
198
|
+
if (process.platform === 'linux') {
|
|
199
|
+
return readLinuxSnapshot();
|
|
200
|
+
}
|
|
201
|
+
return { complete: false, startedAt: new Map(), commandLines: new Map() };
|
|
202
|
+
}
|
|
203
|
+
function readWindowsSnapshot() {
|
|
204
|
+
const script = "Get-CimInstance Win32_Process | Select-Object ProcessId,CreationDate,CommandLine | ConvertTo-Json -Compress";
|
|
205
|
+
const result = spawnSync('powershell', ['-NoProfile', '-NonInteractive', '-Command', script], { encoding: 'utf-8', timeout: 8000, stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true });
|
|
206
|
+
const raw = (result.stdout || '').replace(/^/, '').trim();
|
|
207
|
+
if (!raw)
|
|
208
|
+
return null;
|
|
209
|
+
let rows;
|
|
210
|
+
try {
|
|
211
|
+
const parsed = JSON.parse(raw);
|
|
212
|
+
rows = Array.isArray(parsed) ? parsed : [parsed];
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
const startedAt = new Map();
|
|
218
|
+
const commandLines = new Map();
|
|
219
|
+
for (const row of rows) {
|
|
220
|
+
if (!Number.isInteger(row.ProcessId))
|
|
221
|
+
continue;
|
|
222
|
+
const pid = row.ProcessId;
|
|
223
|
+
const started = coerceCimCreation(row.CreationDate);
|
|
224
|
+
if (started !== null)
|
|
225
|
+
startedAt.set(pid, started);
|
|
226
|
+
if (typeof row.CommandLine === 'string')
|
|
227
|
+
commandLines.set(pid, row.CommandLine);
|
|
228
|
+
}
|
|
229
|
+
return { complete: true, startedAt, commandLines };
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* ConvertTo-Json 对日期序列化的形状取决于 PowerShell 版本:可能是 CIM 字符串、
|
|
233
|
+
* ISO 字符串,也可能是 `{"value":"/Date(...)/"}` 包装对象。全部兜住,拿不到就返回 null。
|
|
234
|
+
*/
|
|
235
|
+
function coerceCimCreation(value) {
|
|
236
|
+
if (value === null || value === undefined)
|
|
237
|
+
return null;
|
|
238
|
+
if (typeof value === 'object') {
|
|
239
|
+
const wrapped = value.value;
|
|
240
|
+
return typeof wrapped === 'string' ? coerceCimCreation(wrapped) : null;
|
|
241
|
+
}
|
|
242
|
+
if (typeof value !== 'string')
|
|
243
|
+
return null;
|
|
244
|
+
const text = value.trim();
|
|
245
|
+
if (!text)
|
|
246
|
+
return null;
|
|
247
|
+
const cim = parseCimDate(text);
|
|
248
|
+
if (cim !== null)
|
|
249
|
+
return cim;
|
|
250
|
+
const iso = parseDateString(text);
|
|
251
|
+
if (iso !== null)
|
|
252
|
+
return iso;
|
|
253
|
+
const dateLiteral = text.match(/\/Date\((\d+)\)\//);
|
|
254
|
+
return dateLiteral ? Number(dateLiteral[1]) : null;
|
|
255
|
+
}
|
|
256
|
+
function readLinuxSnapshot() {
|
|
257
|
+
const startedAt = new Map();
|
|
258
|
+
let complete = true;
|
|
259
|
+
let btimeSec = null;
|
|
260
|
+
try {
|
|
261
|
+
const m = fs.readFileSync('/proc/stat', 'utf-8').match(/^btime (\d+)/m);
|
|
262
|
+
if (m)
|
|
263
|
+
btimeSec = parseInt(m[1], 10);
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
complete = false;
|
|
267
|
+
}
|
|
268
|
+
let entries;
|
|
269
|
+
try {
|
|
270
|
+
entries = fs.readdirSync('/proc');
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
return { complete: false, startedAt, commandLines: new Map() };
|
|
274
|
+
}
|
|
275
|
+
for (const name of entries) {
|
|
276
|
+
if (!/^\d+$/.test(name))
|
|
277
|
+
continue;
|
|
278
|
+
const pid = Number(name);
|
|
279
|
+
try {
|
|
280
|
+
const stat = fs.readFileSync(`/proc/${pid}/stat`, 'utf-8');
|
|
281
|
+
const tail = stat.slice(stat.lastIndexOf(')') + 2).split(' ');
|
|
282
|
+
const jiffies = parseInt(tail[19], 10);
|
|
283
|
+
if (btimeSec !== null && !isNaN(jiffies)) {
|
|
284
|
+
startedAt.set(pid, (btimeSec + jiffies / linuxClockTicks) * 1000);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
catch {
|
|
288
|
+
// 进程在枚举过程中退出:从快照里缺席即视为不存在。
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return { complete, startedAt, commandLines: new Map() };
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* 用快照判断「pid 是否仍是当初记录的那个进程」。
|
|
295
|
+
*
|
|
296
|
+
* 与 `isProcessRunning` + `getProcessStartTime` 的组合语义保持一致,但不会为每条
|
|
297
|
+
* 记录拉起外部进程。快照不完整(macOS、或 Windows CIM 查询失败)时返回 undefined,
|
|
298
|
+
* 调用方应回退到逐个查询。
|
|
299
|
+
*/
|
|
300
|
+
export function snapshotProcessState(snapshot, pid, recordedStartedAt) {
|
|
301
|
+
if (pid === process.pid) {
|
|
302
|
+
return startTimeMatches(recordedStartedAt, getProcessStartTime(pid)) ? 'alive' : 'dead';
|
|
303
|
+
}
|
|
304
|
+
if (!snapshot.complete)
|
|
305
|
+
return 'unknown';
|
|
306
|
+
const actual = snapshot.startedAt.get(pid);
|
|
307
|
+
if (actual === undefined)
|
|
308
|
+
return 'dead';
|
|
309
|
+
// 拿不到创建时间时保守认为活着(与 isAlive 的既有约定一致)。
|
|
310
|
+
return startTimeMatches(recordedStartedAt, actual) ? 'alive' : 'dead';
|
|
311
|
+
}
|
|
148
312
|
/**
|
|
149
313
|
* 解析 CIM/WMI 日期格式:yyyyMMddHHmmss.ffffff±TZZZ
|
|
150
314
|
* TZZZ 是相对 UTC 的分钟偏移(中国是 +480)
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 生命周期阶段埋点 —— 记录一次启动或停止里各阶段各花了多久,供 ECWeb 甘特图展示。
|
|
3
|
+
*
|
|
4
|
+
* 两类进程各写一条记录,用同一 traceId 关联:
|
|
5
|
+
* - CLI(ec start / ec stop)source='cli'
|
|
6
|
+
* - Daemon(dist) source='daemon'
|
|
7
|
+
*
|
|
8
|
+
* 启动与停止共用同一套结构,只用 `kind` 区分('startup' / 'stop'):
|
|
9
|
+
* 两者都是「一串首尾相接的阶段」,都用绝对毫秒时间戳对齐成一条时间轴。
|
|
10
|
+
*
|
|
11
|
+
* 起算点(startedAtMs)对启动是本进程启动时刻;对停止是调用方显式传入的
|
|
12
|
+
* 起算点——CLI 传 `ec stop` 的进程启动时刻,daemon 传收到 shutdown 请求的时刻。
|
|
13
|
+
* 停止侧不能回推本进程启动时刻:daemon 可能已经跑了几小时。
|
|
14
|
+
*
|
|
15
|
+
* 落盘:$EVOLCORE_HOME/data/instance/lifecycle-trace.jsonl,每行一条记录,保留最近 50 次。
|
|
16
|
+
* 这里只负责记录,不解释耗时——慢在哪由甘特图看。
|
|
17
|
+
*/
|
|
18
|
+
import fs from 'node:fs';
|
|
19
|
+
import path from 'node:path';
|
|
20
|
+
import crypto from 'node:crypto';
|
|
21
|
+
import { resolvePaths } from '../paths.js';
|
|
22
|
+
/** 保留的启动/停止次数(按 traceId 去重后) */
|
|
23
|
+
export const STARTUP_TRACE_KEEP = 50;
|
|
24
|
+
/** CLI 传 traceId 给 daemon 的环境变量,让两侧记录落进同一次启动。 */
|
|
25
|
+
export const STARTUP_TRACE_ID_ENV = 'EVOLCORE_STARTUP_TRACE_ID';
|
|
26
|
+
/** traceId 以时间前缀开头,按字典序即按时间序。 */
|
|
27
|
+
export function newStartupTraceId(ts = Date.now()) {
|
|
28
|
+
const stamp = new Date(ts).toISOString().replace(/[-:.]/g, '');
|
|
29
|
+
return `${stamp}-${crypto.randomBytes(3).toString('hex')}`;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 阶段计时器。用法是线性的:
|
|
33
|
+
*
|
|
34
|
+
* const trace = new StartupTracer('cli');
|
|
35
|
+
* trace.mark('cli.bootstrap'); // 打开第一个阶段,上一个自动闭合
|
|
36
|
+
* ...做点事...
|
|
37
|
+
* trace.mark('cli.probeDaemon'); // 闭合 bootstrap,打开 probeDaemon
|
|
38
|
+
* ...
|
|
39
|
+
* trace.finish(true); // 闭合最后一个阶段并落盘
|
|
40
|
+
*
|
|
41
|
+
* 每次 mark 到下一次 mark 之间就是一个阶段;相邻阶段首尾相接,
|
|
42
|
+
* 不会出现"未归因的空白",没埋点的耗时会被算进它前面的阶段。
|
|
43
|
+
*/
|
|
44
|
+
export class StartupTracer {
|
|
45
|
+
source;
|
|
46
|
+
kind;
|
|
47
|
+
traceId;
|
|
48
|
+
spans = [];
|
|
49
|
+
meta = {};
|
|
50
|
+
processStartMs;
|
|
51
|
+
cursorName = null;
|
|
52
|
+
cursorStartMs = 0;
|
|
53
|
+
cursorDetail;
|
|
54
|
+
finished = false;
|
|
55
|
+
constructor(source, opts = {}) {
|
|
56
|
+
this.source = source;
|
|
57
|
+
this.kind = opts.kind ?? 'startup';
|
|
58
|
+
this.traceId = opts.traceId ?? newStartupTraceId();
|
|
59
|
+
this.processStartMs = opts.processStartMs ?? processStartOfThisProcess();
|
|
60
|
+
this.cursorStartMs = this.processStartMs;
|
|
61
|
+
if (opts.firstPhase)
|
|
62
|
+
this.cursorName = opts.firstPhase;
|
|
63
|
+
}
|
|
64
|
+
get id() { return this.traceId; }
|
|
65
|
+
get startedAtMs() { return this.processStartMs; }
|
|
66
|
+
get traceKind() { return this.kind; }
|
|
67
|
+
/** 结束当前阶段,开始新阶段。 */
|
|
68
|
+
mark(name, detail) {
|
|
69
|
+
if (this.finished)
|
|
70
|
+
return;
|
|
71
|
+
const now = Date.now();
|
|
72
|
+
this.closeCursor(now);
|
|
73
|
+
this.cursorName = name;
|
|
74
|
+
this.cursorStartMs = now;
|
|
75
|
+
this.cursorDetail = detail;
|
|
76
|
+
}
|
|
77
|
+
/** 给当前打开的阶段补一句附注。 */
|
|
78
|
+
note(detail) {
|
|
79
|
+
if (this.finished || !this.cursorName)
|
|
80
|
+
return;
|
|
81
|
+
this.cursorDetail = detail;
|
|
82
|
+
}
|
|
83
|
+
/** 直接登记一段已测好的区间(用于拿到外部时间戳的场景)。 */
|
|
84
|
+
addSpan(name, startMs, endMs, detail) {
|
|
85
|
+
if (this.finished)
|
|
86
|
+
return;
|
|
87
|
+
this.spans.push({ name, startMs, durationMs: Math.max(0, endMs - startMs), ...(detail ? { detail } : {}) });
|
|
88
|
+
}
|
|
89
|
+
/** 瞬时事件(时长为 0 的标记)。 */
|
|
90
|
+
point(name, detail) {
|
|
91
|
+
if (this.finished)
|
|
92
|
+
return;
|
|
93
|
+
this.spans.push({ name, startMs: Date.now(), durationMs: 0, ...(detail ? { detail } : {}) });
|
|
94
|
+
}
|
|
95
|
+
/** 已闭合的阶段(只读)。用于结束时打印摘要。 */
|
|
96
|
+
get recordedSpans() { return this.spans; }
|
|
97
|
+
setMeta(key, value) {
|
|
98
|
+
if (this.finished)
|
|
99
|
+
return;
|
|
100
|
+
this.meta[key] = value;
|
|
101
|
+
}
|
|
102
|
+
/** 放弃本次记录(未真正发生启动时用,比如 daemon 已在运行)。 */
|
|
103
|
+
discard() {
|
|
104
|
+
this.finished = true;
|
|
105
|
+
}
|
|
106
|
+
/** 闭合最后阶段并落盘。重复调用无副作用。 */
|
|
107
|
+
finish(ok) {
|
|
108
|
+
if (this.finished)
|
|
109
|
+
return;
|
|
110
|
+
const now = Date.now();
|
|
111
|
+
this.closeCursor(now);
|
|
112
|
+
this.finished = true;
|
|
113
|
+
if (this.cursorName)
|
|
114
|
+
this.cursorName = null;
|
|
115
|
+
const record = {
|
|
116
|
+
traceId: this.traceId,
|
|
117
|
+
kind: this.kind,
|
|
118
|
+
source: this.source,
|
|
119
|
+
pid: process.pid,
|
|
120
|
+
startedAtMs: this.processStartMs,
|
|
121
|
+
startedAt: new Date(this.processStartMs).toISOString(),
|
|
122
|
+
ok,
|
|
123
|
+
totalMs: Math.max(0, now - this.processStartMs),
|
|
124
|
+
meta: this.meta,
|
|
125
|
+
spans: this.spans,
|
|
126
|
+
};
|
|
127
|
+
try {
|
|
128
|
+
appendStartupTrace(record);
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
// 埋点失败不能影响启动本身
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
closeCursor(now) {
|
|
135
|
+
if (!this.cursorName)
|
|
136
|
+
return;
|
|
137
|
+
const span = {
|
|
138
|
+
name: this.cursorName,
|
|
139
|
+
startMs: this.cursorStartMs,
|
|
140
|
+
durationMs: Math.max(0, now - this.cursorStartMs),
|
|
141
|
+
};
|
|
142
|
+
if (this.cursorDetail)
|
|
143
|
+
span.detail = this.cursorDetail;
|
|
144
|
+
this.spans.push(span);
|
|
145
|
+
this.cursorName = null;
|
|
146
|
+
this.cursorDetail = undefined;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/** 本进程启动时刻。用 uptime 回推,能覆盖 node 启动 + 模块加载 + tsx 编译。 */
|
|
150
|
+
export function processStartOfThisProcess() {
|
|
151
|
+
const uptimeMs = Math.round(process.uptime() * 1000);
|
|
152
|
+
return Date.now() - uptimeMs;
|
|
153
|
+
}
|
|
154
|
+
function appendStartupTrace(record) {
|
|
155
|
+
const file = resolvePaths().lifecycleTrace;
|
|
156
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
157
|
+
fs.appendFileSync(file, `${JSON.stringify(record)}\n`, 'utf-8');
|
|
158
|
+
trimStartupTrace(file);
|
|
159
|
+
}
|
|
160
|
+
/** 只保留最近 STARTUP_TRACE_KEEP 个 traceId 的行;行数不多时跳过。 */
|
|
161
|
+
function trimStartupTrace(file) {
|
|
162
|
+
let raw;
|
|
163
|
+
try {
|
|
164
|
+
raw = fs.readFileSync(file, 'utf-8');
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const lines = raw.split('\n').filter(line => line.trim());
|
|
170
|
+
if (lines.length <= STARTUP_TRACE_KEEP * 2 + 20)
|
|
171
|
+
return;
|
|
172
|
+
const ids = [];
|
|
173
|
+
for (const line of lines) {
|
|
174
|
+
try {
|
|
175
|
+
const id = JSON.parse(line).traceId;
|
|
176
|
+
if (id)
|
|
177
|
+
ids.push(id);
|
|
178
|
+
}
|
|
179
|
+
catch { /* 坏行丢弃 */ }
|
|
180
|
+
}
|
|
181
|
+
const keep = new Set(Array.from(new Set(ids.sort())).slice(-STARTUP_TRACE_KEEP));
|
|
182
|
+
const kept = [];
|
|
183
|
+
for (const line of lines) {
|
|
184
|
+
try {
|
|
185
|
+
const id = JSON.parse(line).traceId;
|
|
186
|
+
if (id && keep.has(id))
|
|
187
|
+
kept.push(line);
|
|
188
|
+
}
|
|
189
|
+
catch { /* 坏行丢弃 */ }
|
|
190
|
+
}
|
|
191
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
192
|
+
fs.writeFileSync(tmp, `${kept.join('\n')}\n`, 'utf-8');
|
|
193
|
+
fs.renameSync(tmp, file);
|
|
194
|
+
}
|
|
195
|
+
/** 毫秒 → 人读时长。CLI 打印和摘要统一用它,避免各处各写一套。 */
|
|
196
|
+
export function formatMs(ms) {
|
|
197
|
+
if (!Number.isFinite(ms))
|
|
198
|
+
return '—';
|
|
199
|
+
if (ms >= 1000)
|
|
200
|
+
return `${(ms / 1000).toFixed(1)}s`;
|
|
201
|
+
return `${Math.round(ms)}ms`;
|
|
202
|
+
}
|
|
203
|
+
/** 把最耗时的几个阶段拼成一行,例如 `waitExit 5.9s · shutdown 0.4s`。 */
|
|
204
|
+
export function formatSlowestSpans(spans, limit = 3, prefixPattern = /^[a-z]+\./) {
|
|
205
|
+
return spans
|
|
206
|
+
.filter(span => span.durationMs >= 50)
|
|
207
|
+
.slice()
|
|
208
|
+
.sort((a, b) => b.durationMs - a.durationMs)
|
|
209
|
+
.slice(0, limit)
|
|
210
|
+
.map(span => `${span.name.replace(prefixPattern, '')} ${formatMs(span.durationMs)}`)
|
|
211
|
+
.join(' · ');
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* 取同一次事件里另一侧的记录(CLI 取 daemon 那一半,或反之)。
|
|
215
|
+
*
|
|
216
|
+
* 停止流程里 daemon 已经退出,它的记录在 `exit(0)` 之前同步落盘,
|
|
217
|
+
* 所以 CLI 在确认进程消失之后可以读回来,把 daemon 侧最慢的阶段一起打印出来
|
|
218
|
+
* ——否则 `ec stop` 只报 CLI 的 1.2 秒,真正慢的 18 秒藏在对端。
|
|
219
|
+
*/
|
|
220
|
+
export function findTraceRecord(traceId, source) {
|
|
221
|
+
return readStartupTraces().find(record => record.traceId === traceId && record.source === source) ?? null;
|
|
222
|
+
}
|
|
223
|
+
/** 读原始记录(ECWeb 侧也有一份独立实现,不复用本文件的路径工具)。 */
|
|
224
|
+
export function readStartupTraces() {
|
|
225
|
+
const file = resolvePaths().lifecycleTrace;
|
|
226
|
+
let raw;
|
|
227
|
+
try {
|
|
228
|
+
raw = fs.readFileSync(file, 'utf-8');
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
return [];
|
|
232
|
+
}
|
|
233
|
+
const records = [];
|
|
234
|
+
for (const line of raw.split('\n')) {
|
|
235
|
+
if (!line.trim())
|
|
236
|
+
continue;
|
|
237
|
+
try {
|
|
238
|
+
const parsed = JSON.parse(line);
|
|
239
|
+
if (parsed?.traceId && Array.isArray(parsed.spans))
|
|
240
|
+
records.push(parsed);
|
|
241
|
+
}
|
|
242
|
+
catch { /* 坏行跳过 */ }
|
|
243
|
+
}
|
|
244
|
+
return records;
|
|
245
|
+
}
|
|
@@ -409,17 +409,10 @@ async function prepareToolCall(currentContext, assistantMessage, toolCall, confi
|
|
|
409
409
|
args: validatedArgs,
|
|
410
410
|
context: currentContext,
|
|
411
411
|
}, signal);
|
|
412
|
-
if (signal?.aborted) {
|
|
412
|
+
if (beforeResult?.block || signal?.aborted) {
|
|
413
413
|
return {
|
|
414
414
|
kind: "immediate",
|
|
415
|
-
result:
|
|
416
|
-
isError: true,
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
if (beforeResult?.block) {
|
|
420
|
-
return {
|
|
421
|
-
kind: "immediate",
|
|
422
|
-
result: createErrorToolResult(beforeResult.reason || "Tool execution was blocked"),
|
|
415
|
+
result: createRejectedToolResult(beforeResult, signal),
|
|
423
416
|
isError: true,
|
|
424
417
|
};
|
|
425
418
|
}
|
|
@@ -427,7 +420,7 @@ async function prepareToolCall(currentContext, assistantMessage, toolCall, confi
|
|
|
427
420
|
if (signal?.aborted) {
|
|
428
421
|
return {
|
|
429
422
|
kind: "immediate",
|
|
430
|
-
result:
|
|
423
|
+
result: createRejectedToolResult(undefined, signal),
|
|
431
424
|
isError: true,
|
|
432
425
|
};
|
|
433
426
|
}
|
|
@@ -450,6 +443,8 @@ async function executePreparedToolCall(prepared, signal, emit) {
|
|
|
450
443
|
const updateEvents = [];
|
|
451
444
|
let acceptingUpdates = true;
|
|
452
445
|
try {
|
|
446
|
+
if (signal?.aborted)
|
|
447
|
+
return { result: createRejectedToolResult(undefined, signal), isError: true };
|
|
453
448
|
const result = await prepared.tool.execute(prepared.toolCall.id, prepared.args, signal, (partialResult) => {
|
|
454
449
|
if (!acceptingUpdates)
|
|
455
450
|
return;
|
|
@@ -469,7 +464,10 @@ async function executePreparedToolCall(prepared, signal, emit) {
|
|
|
469
464
|
acceptingUpdates = false;
|
|
470
465
|
await Promise.all(updateEvents);
|
|
471
466
|
return {
|
|
472
|
-
result: createErrorToolResult(error instanceof Error ? error.message : String(error)
|
|
467
|
+
result: createErrorToolResult(error instanceof Error ? error.message : String(error), signal?.aborted ? {
|
|
468
|
+
cancelled: true, blockedByHook: false, decisionSource: "infrastructure", executed: true, executionState: "interrupted",
|
|
469
|
+
abortSource: typeof signal.reason === "string" ? signal.reason.slice(0, 512) : signal.reason instanceof Error ? signal.reason.name : "abort_signal",
|
|
470
|
+
} : {}),
|
|
473
471
|
isError: true,
|
|
474
472
|
};
|
|
475
473
|
}
|
|
@@ -511,10 +509,26 @@ async function finalizeExecutedToolCall(currentContext, assistantMessage, prepar
|
|
|
511
509
|
isError,
|
|
512
510
|
};
|
|
513
511
|
}
|
|
514
|
-
function
|
|
512
|
+
function createRejectedToolResult(decision, signal) {
|
|
513
|
+
const cancelled = signal?.aborted === true || decision?.details?.cancelled === true;
|
|
514
|
+
const blockedByHook = decision?.block === true && decision.details?.blockedByHook !== false
|
|
515
|
+
&& (decision.details?.cancelled !== true || decision.details?.blockedByHook === true);
|
|
516
|
+
const reason = decision?.reason || (cancelled ? "Operation aborted" : "Tool execution was blocked");
|
|
517
|
+
const abortSource = decision?.details?.abortSource
|
|
518
|
+
?? (typeof signal?.reason === "string" ? signal.reason.slice(0, 512) : signal?.reason instanceof Error ? signal.reason.name : "abort_signal");
|
|
519
|
+
return createErrorToolResult(reason, {
|
|
520
|
+
...decision?.details,
|
|
521
|
+
reason,
|
|
522
|
+
executed: false,
|
|
523
|
+
executionState: blockedByHook ? "blocked" : "interrupted",
|
|
524
|
+
blockedByHook,
|
|
525
|
+
...(cancelled ? { cancelled: true, abortSource } : {}),
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
function createErrorToolResult(message, details = {}) {
|
|
515
529
|
return {
|
|
516
530
|
content: [{ type: "text", text: message }],
|
|
517
|
-
details
|
|
531
|
+
details,
|
|
518
532
|
};
|
|
519
533
|
}
|
|
520
534
|
async function emitToolExecutionEnd(finalized, emit) {
|
|
@@ -172,6 +172,8 @@ export class AgentHarness {
|
|
|
172
172
|
const result = await handler(event, signal);
|
|
173
173
|
if (result !== undefined) {
|
|
174
174
|
lastResult = result;
|
|
175
|
+
if (event.type === "tool_call" && result.block)
|
|
176
|
+
return result;
|
|
175
177
|
}
|
|
176
178
|
}
|
|
177
179
|
catch (error) {
|
|
@@ -334,9 +336,7 @@ export class AgentHarness {
|
|
|
334
336
|
toolName: toolCall.name,
|
|
335
337
|
input: args,
|
|
336
338
|
}, signal);
|
|
337
|
-
|
|
338
|
-
return { block: true, reason: "Operation aborted" };
|
|
339
|
-
return result ? { block: result.block, reason: result.reason } : undefined;
|
|
339
|
+
return result;
|
|
340
340
|
},
|
|
341
341
|
afterToolCall: async ({ toolCall, args, result, isError }) => {
|
|
342
342
|
const patch = await this.emitHook({
|
|
@@ -480,6 +480,7 @@ export interface BeforeProviderPayloadResult {
|
|
|
480
480
|
export interface ToolCallResult {
|
|
481
481
|
block?: boolean;
|
|
482
482
|
reason?: string;
|
|
483
|
+
details?: Record<string, unknown>;
|
|
483
484
|
}
|
|
484
485
|
export interface ToolResultPatch {
|
|
485
486
|
content?: Array<TextContent | ImageContent>;
|
package/ecagent/dist/types.d.ts
CHANGED
package/kits/docs/INDEX.md
CHANGED
|
@@ -31,7 +31,7 @@ EvolCore 能力插件体系的实施设计位于源码仓库 `$PACKAGE_ROOT/docs
|
|
|
31
31
|
|------|------|------|
|
|
32
32
|
| 命令集目录 | `evolcore/INDEX.md` | msg/group/agent/aid/storage/ctl/rpc/bench 全集索引 |
|
|
33
33
|
| Provider 注册表 | `evolcore/provider.md` | 宿主进程级 Provider CRUD、JSON 导入及 CLI/Menu 边界 |
|
|
34
|
-
|
|
|
34
|
+
| 对端命令 | `evolcore/peer.md` | 对端身份表、拉黑与托管会话权限边界 |
|
|
35
35
|
| Agent 生命周期与 Bootstrap | `evolcore/agent-create.md` | 生命周期与新 Agent 首次设定参考;创建者操作已迁移到 `ec-agent-create` 技能 |
|
|
36
36
|
| 群聊协作入口 | `evolcore/group-collaboration.md` | 旧文档入口;完整任务流程已迁移到 `ec-group-collaboration` 技能 |
|
|
37
37
|
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# AUN 消息类型与属性
|
|
2
|
+
|
|
3
|
+
> 口径:根据 2026-10-30 的工作区源码和文档整理。消息分类控制流及群消息正 TTL 路径属于未发布的 0.5.28 工作区能力,需要配套服务和能力协商;不能据此认定线上已经部署。
|
|
4
|
+
>
|
|
5
|
+
> 下文的“加密/明文”指端到端加密(E2EE),不代表传输连接是否使用 TLS。表中的消息类型和属性可以交叉组合,具体组合受协议及版本约束。
|
|
6
|
+
|
|
7
|
+
## 1. 消息类型与交付方式
|
|
8
|
+
|
|
9
|
+
| 类型或入口 | 范围与定向 | E2EE | 保存方式 | 获取与处理 |
|
|
10
|
+
|---|---|---|---|---|
|
|
11
|
+
| 普通 P2P:`message.send` | 指定 `to` 接收方 AID;默认面向该 AID 的设备 | SDK 默认加密,也可发送明文 | 常规 fanout 默认持久;正 TTL 为内存临时消息 | Push、Pull 和投递 ACK;默认为 `normal` |
|
|
12
|
+
| 普通群消息:`group.send` | 指定 `group_id`,值为群 AID;面向有权限的群成员设备 | SDK 默认加密,也可发送明文 | 默认持久;当前源码支持正 TTL 内存路径 | 群 fanout、Push、Pull 和投递 ACK;默认为 `normal` |
|
|
13
|
+
| P2P 设备定向 | `to` 加 `device_id` 或兼容别名 `to_device_id` | 可加密或明文 | 按消息的持久、TTL 或兼容投递路径决定 | 在接收方 AID 内定向指定设备;不进入 AID 的跨设备共享已读汇总 |
|
|
14
|
+
| 应用控制消息:`control` | P2P 或群 | 机制支持加密和明文;SDK 默认加密,应用指南要求控制消息加密发送 | 默认持久,也可使用正 TTL | 分类控制流交给应用处理;旧接收端可通过普通流兼容投递 |
|
|
15
|
+
| SDK 控制消息:`sdk_control` | P2P 或群分类;当前 `aun.agent_md.changed` 示例使用 P2P | 按具体协议;上述示例使用 E2EE | 默认持久,也可按协议使用正 TTL | 由 SDK 内部处理,不进入普通应用消息正文;不支持的目标不降级为普通消息 |
|
|
16
|
+
| Ownership 协调消息 | P2P,指定关系参与方 | 当前实现构造 V2 加密信封 | 当前发送路径默认持久 | `payload.type=aun.ownership.sdk.v1`;SDK 特判消费,发送时未显式指定 `message_class`,不能直接等同于 `sdk_control` 类别 |
|
|
17
|
+
| TTL 临时消息:`volatile` | 可用于 P2P;当前工作区也支持群 | 与普通消息的加密方式组合 | `ttl>0`,消息正文仅保存在内存,期限为 1–3600 秒;过期、淘汰或服务重启后可能丢失 | 有效期内可 Push、Pull、按 volatile 游标 ACK;不分配持久消息 `seq` |
|
|
18
|
+
| P2P `queue` 兼容路径 | 面向在线实例,通常按路由策略选择实例 | 取决于信封和实现路径 | Go 的 legacy queue 分支不落库 | 在线直投;离线时不能按持久消息或 TTL 临时邮箱推断可补拉 |
|
|
19
|
+
| P2P thought:`message.thought.put/get` | 指定对端和上下文;作者或对端按权限读取 | SDK 默认 V2 加密;存在明文路径,见第 3 节 | 仅内存,按上下文保留有限 head 和 item | 主动 `thought.get`;不广播、不进 `message.pull`,无普通消息 `seq` 或 ACK |
|
|
20
|
+
| 群 thought:`group.thought.put/get` | 指定群、作者和上下文;群成员按权限读取 | SDK 默认 V2 加密;存在明文路径,见第 3 节 | 仅内存,按上下文保留有限 head 和 item | 主动 `thought.get`;不广播、不进 `group.pull`,无普通消息 `seq` 或 ACK |
|
|
21
|
+
| 在线通知:`notify()` | 可发给服务端、指定 AID 或群;AID 通知可指定设备和 slot | SDK 默认不做 E2EE;应用可自行加密 | 不持久化,仅面向在线长连接 | 尽力投递,不分配 `seq`,不进入 Pull,不需 ACK;`ttl_ms` 为 0–60000 毫秒 |
|
|
22
|
+
| 群变更事件:`group.changed` | 群范围,如成员或群状态变更 | 协议事件,不按普通消息正文的 E2EE 类型分类 | 群事件流有独立保留策略;旧格式可能没有 `event_seq` | 新格式使用独立 `event_seq`、`group.pull_events` 和事件 ACK,不是 `group.send` 正文 |
|
|
23
|
+
| 已读变更事件:`message.read_changed` / `group.read_changed` | 定向当前 AID 的设备 | 协议事件,不按普通消息正文的 E2EE 类型分类 | 已读状态持久保存;变更通知本身不进入 Pull 队列 | 通知丢失时由 `read_state` 查询补偿;业务已读与投递 ACK 分开 |
|
|
24
|
+
|
|
25
|
+
## 2. 主要属性和字段
|
|
26
|
+
|
|
27
|
+
| 属性 | 字段或取值 | 说明 |
|
|
28
|
+
|---|---|---|
|
|
29
|
+
| 通信范围 | `to`、`group_id` | P2P 指定对端 AID;群消息的 `group_id` 是兼容字段名,值使用群 AID。两者均支持跨域路径,具体取决于互联和服务能力。 |
|
|
30
|
+
| 加密 | SDK 的 `encrypt`;信封中的 `encrypted`、`type` | 普通发送默认 E2EE;V2 信封类型分别为 `e2ee.p2p_encrypted`、`e2ee.group_encrypted`。明文与类别、存储是不同维度。 |
|
|
31
|
+
| 持久化 | `ttl`、响应 `storage` | 常规消息缺省或 `ttl<=0` 走持久路径;`ttl>0` 走 volatile 内存路径。P2P legacy queue 是不落库的例外;持久化不表示永久保存。 |
|
|
32
|
+
| 定向 | `device_id`、`to_device_id` | P2P 可限定接收方设备;V2 加密仍可能包含发送方 self-sync 和审计 wrap。群 `mentions` 不参与路由或确定 E2EE 收件人。 |
|
|
33
|
+
| 投递模式 | 连接级 `delivery_mode`:`fanout`、`queue` | P2P 的 fanout 面向多实例,queue 面向实例消费;`group.send` 不接受 queue。模式与 TTL 是不同属性,具体兼容路径有约束。 |
|
|
34
|
+
| 消息类别 | `message_class`:`normal`、`control`、`sdk_control` | 缺省为 `normal`;`control` 由应用处理,`sdk_control` 由 SDK 内部处理。分类流的游标和 ACK 按类别、作用域隔离。 |
|
|
35
|
+
| 调度顺序 | `sdk_control`、`control`、`normal` | 分类能力协商后,已就绪工作项按此顺序调度;不根据 payload 类型或 `need_render` 自动推断类别。 |
|
|
36
|
+
| 展示提示 | `need_render` | 默认 `true`;只是是否需要应用渲染的提示,不等同于控制类别,也不改变 Pull/ACK 规则。 |
|
|
37
|
+
| 内容类型 | `payload.type` | 应用层内容约定,如 `text`、`image`、`event`;外层 `type` 是信封或加密封装类型,不能与 `message_class` 混用。 |
|
|
38
|
+
| 投递与已读 | `seq`、volatile 游标、ACK、`read` / `read_state` | 持久消息使用所属流的 `seq`,volatile 使用独立游标;投递 ACK 不代表用户已读。 |
|
|
39
|
+
|
|
40
|
+
群的值班分发可先把消息交给当班成员处理,但群成员仍可通过 `group.pull` 读取有权访问的消息;它不是私密的群内设备定向。
|
|
41
|
+
|
|
42
|
+
## 3. thought 细项
|
|
43
|
+
|
|
44
|
+
| 属性 | P2P thought | 群 thought |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| 写入 | `message.thought.put`:指定 `to` 和 `context` | `group.thought.put`:指定 `group_id` 和 `context` |
|
|
47
|
+
| 查询 | `message.thought.get`:指定作者和 `context`;读取自己写的内容时还要指定对端 | `group.thought.get`:指定 `group_id`、`sender_aid` 和 `context` |
|
|
48
|
+
| 选择键 | `sender_aid + peer_aid + context.type + context.id` | `group_aid + sender_aid + context.type + context.id` |
|
|
49
|
+
| 内容 | 推荐 `payload.type=thought`;每个 item 有 `thought_id` 和时间信息 | 相同;可通过 `thought.get` 取得当前 head 下的多个 item |
|
|
50
|
+
| 保存边界 | 服务进程内存;同一作者和对端保留有限个上下文 head | 服务进程内存;同一群和作者保留有限个上下文 head |
|
|
51
|
+
| 容量 | 当前 Go 实现默认且最多 100 个 head、每个 head 100 个 item;配置可收紧,超出时淘汰旧内容 | 当前 Go 实现默认且最多 100 个 head、每个 head 100 个 item;配置可收紧,超出时淘汰旧内容 |
|
|
52
|
+
| 投递 | 不主动广播,不使用普通消息 Push/Pull、持久 `seq` 或 ACK;`get` 可重复查询 | 相同;服务端检查查询者的群成员身份,密文仍需具备相应解密能力 |
|
|
53
|
+
|
|
54
|
+
**加密口径差异**:SDK 手册写明 thought 必须 E2EE、`encrypt=false` 会被拒绝;但当前 Python SDK 发送路径、Go 服务实现及已有用例均包含明文路径。因此当前实现应描述为“默认加密,存在明文路径”,不能认定实现已强制拒绝明文。本次仅静态核对,未验证线上部署。
|
|
55
|
+
|
|
56
|
+
要获得上述非广播和内存语义,应使用 `*.thought.put/get`;仅在普通 `message.send` 或 `group.send` 的 payload 中写 `type=thought` 不能替代专用接口。
|
|
57
|
+
|
|
58
|
+
## 4. 业务 payload 类型
|
|
59
|
+
|
|
60
|
+
| `payload.type` | 含义 |
|
|
61
|
+
|---|---|
|
|
62
|
+
| `text`、`quote` | 文本、引用回复 |
|
|
63
|
+
| `voice`、`image`、`video`、`file` | 语音、图片、视频和文件引用 |
|
|
64
|
+
| `location`、`link` | 位置、链接卡片 |
|
|
65
|
+
| `action_card`、`action_card_reply` | 交互卡片及回复 |
|
|
66
|
+
| `merge`、`personal_card` | 合并转发、个人或 Agent 名片 |
|
|
67
|
+
| `status`、`event` | 应用状态、业务事件;这里的 `event` 是消息内容,不等同于在线 notify 或服务端协议事件 |
|
|
68
|
+
| `json`、`custom` | 结构化数据或应用自定义内容;投票可使用 `json` 加 `kind=poll` |
|
|
69
|
+
| `tool_call`、`tool_result` | Agent 本地工具调用过程及结果的标注 |
|
|
70
|
+
| `thought` | Agent 思考内容,使用专用 thought 接口 |
|
|
71
|
+
|
|
72
|
+
这些业务类型是发送端与接收端的参考约定,不是服务端强制维护的完整枚举。
|
|
@@ -41,8 +41,8 @@ Windows 上 Codex 托管任务出现 `helper_sandbox_lock_failed`、`SetNamedSec
|
|
|
41
41
|
| `ec aid` | AID 身份、名片与头像管理 | 身份/证书/名片/头像/换头像/探测对端 | 任意有渠道场景 | `aid.md` |
|
|
42
42
|
| `ec fs` | AUN 文件系统统一入口 | 上传/下载/看文件/列目录/删文件/配额/群空间 | 任意有渠道场景 | `fs.md` |
|
|
43
43
|
| `ec storage` | 文件存储底层调试入口 | storage 调试/旧命令/底层上传下载 | 任意有渠道场景 | `storage.md` |
|
|
44
|
-
| `ec agent` | EvolAgent
|
|
45
|
-
| `ec
|
|
44
|
+
| `ec agent` | EvolAgent 生命周期与主机信息 | 创建/启停/热重载/改配置/查主机信息 | 管理操作按目标与角色鉴权 | `agent.md`;创建流程用 `ec-agent-create` 技能,Bootstrap 参考见 `agent-create.md` |
|
|
45
|
+
| `ec peer` | 对端身份与本地拉黑 | 查已登记对端、拉黑/解除拉黑 | 拉黑为 Agent 自身行为;添加联系人与审批归 Owner | `peer.md` |
|
|
46
46
|
| `ec rpc` | 底层 AUN RPC(逃生通道) | 直接调协议方法 | 仅宿主终端;托管会话仅可查看帮助 | `rpc.md` |
|
|
47
47
|
| `ec menu-client` | 远程 Daemon Menu 请求 | 远程诊断/远程 daemon 操作/daemon 日志/监控/原始配置/跨主机 | 运维主机或具备 `ec.menu.request` 权限的托管 Agent | `menu-client.md` |
|
|
48
48
|
|
|
@@ -77,6 +77,7 @@ Windows 上 Codex 托管任务出现 `helper_sandbox_lock_failed`、`SetNamedSec
|
|
|
77
77
|
| `ec trigger event` | EventBus 事件目录 | 事件触发/事件目录/EventBus/source.type=event/filter.match | `event.md` |
|
|
78
78
|
| `ec task` | 恢复暂停或异常中断的会话任务 | 任务恢复/异常中断/继续任务/resume | `task.md` |
|
|
79
79
|
| `ec skill` | EC 技能管理(新建/安装/删除/启用/禁用/校验/查路径) | 创建技能/新建 skill/安装技能/装个 skill/删除技能/禁用技能/启用技能/看看有哪些技能/技能为什么没生效 | `ec-capabilities.md` |
|
|
80
|
+
| `ec pa-workspace` | 在 Owner 的 AUN 私聊中查看和维护 PA 工作区入口导航 | 个人助理工作区/工作区入口调整/产物入口/报告入口/任务入口/隐藏入口/改名入口/排序入口 | `pa-workspace.md` |
|
|
80
81
|
|
|
81
82
|
## 开发者工具(非 agent 会话能力)
|
|
82
83
|
|