evolcore 0.0.47 → 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 +90 -1
- package/bin/ec-build.mjs +86 -0
- package/dist/agent-template/jobs.js +12 -4
- package/dist/agent-template/runtime.js +143 -40
- package/dist/agent-template/service.js +66 -13
- package/dist/agents/baseagent.js +60 -20
- package/dist/agents/claude-runner.js +34 -17
- package/dist/agents/codex-runner.js +36 -17
- package/dist/agents/ecagent-runner.js +7 -4
- package/dist/agents/gemini-runner.js +5 -2
- package/dist/agents/runner-types.js +5 -21
- package/dist/aun/aid/agentmd.js +5 -1
- package/dist/aun/msg/p2p.js +2 -1
- package/dist/aun/service-proxy.js +4 -2
- package/dist/build-identity.json +1 -0
- package/dist/channels/aun.js +722 -295
- package/dist/channels/daemon.js +9 -25
- package/dist/cli/aun-commands.js +86 -51
- package/dist/cli/code-stats.js +19 -8
- package/dist/cli/command-log.js +1 -1
- package/dist/cli/daemon-commands.js +44 -43
- package/dist/cli/directory.js +13 -2
- package/dist/cli/ecmsg-gateway.js +5 -2
- package/dist/cli/index.js +9 -9
- package/dist/cli/init-channel.js +4 -6
- package/dist/cli/init.js +72 -50
- package/dist/cli/invoke-command.js +1 -1
- package/dist/cli/managed-command-guard.js +2 -0
- package/dist/cli/model.js +20 -5
- package/dist/cli/provider-command.js +74 -13
- package/dist/cli/quota.js +89 -0
- package/dist/cli/role.js +62 -17
- package/dist/cli/services-command.js +1 -0
- package/dist/cli/stats.js +3 -3
- package/dist/cli/team-workspace-command.js +56 -2
- package/dist/cli/thread-command.js +16 -51
- package/dist/config/boot-log.js +3 -9
- package/dist/config/builtin-roles.js +5 -7
- package/dist/config/config-field-policy.js +71 -1
- package/dist/config/config-manager.js +13 -7
- package/dist/config/daemon-services.js +30 -3
- package/dist/config/gateway-config.js +2 -2
- package/dist/config/invoke-ipc-service.js +6 -4
- package/dist/config/peer-bind-code.js +3 -4
- package/dist/config/peer-book-store.js +62 -229
- package/dist/config/peer-book.js +26 -27
- package/dist/config/peer-role-resolver.js +16 -1
- package/dist/config/provider-identity-migration.js +4 -1
- package/dist/config/provider-ipc-service.js +56 -11
- package/dist/config/provider-menu-request.js +24 -5
- package/dist/config/provider-templates.js +127 -0
- package/dist/config/providers-config.js +67 -12
- package/dist/config/providers-management.js +477 -51
- package/dist/config/resolved-config-op.js +3 -2
- package/dist/config/role-command-service.js +248 -1
- package/dist/config/schema-migration.js +105 -4
- package/dist/core/agent-application-service.js +6 -1
- package/dist/core/agent-runtime.js +4 -0
- package/dist/core/auth/agent-delegation.js +2 -1
- package/dist/core/auth/auth-gateway.js +2 -1
- package/dist/core/auth/delegation-authorization.js +36 -26
- package/dist/core/auth/operation-authorizer.js +25 -0
- package/dist/core/auth/operation-catalog.js +37 -64
- package/dist/core/capability/providers/codex-capability-provider.js +7 -8
- package/dist/core/channel-loader.js +18 -0
- package/dist/core/command/agent-control.js +32 -0
- package/dist/core/command/cli-intent-parser.js +13 -0
- package/dist/core/command/command-handler.js +126 -87
- package/dist/core/command/menu-catalog.js +1 -0
- package/dist/core/command/menu-handler.js +67 -150
- package/dist/core/command/menu-protocol.js +31 -1
- package/dist/core/command/provider-menu.js +13 -3
- package/dist/core/command/remote-shell.js +565 -0
- package/dist/core/command/role-menu.js +47 -23
- package/dist/core/command/slash-handler.js +26 -43
- package/dist/core/command/team-workspace-items.js +81 -12
- package/dist/core/command/team-workspace-team.js +9 -71
- package/dist/core/command/topic-slash.js +9 -30
- package/dist/core/daemon-bootstrap.js +8 -1
- package/dist/core/daemon-control.js +64 -8
- package/dist/core/daemon-lifecycle.js +16 -2
- package/dist/core/evolagent-registry.js +20 -3
- package/dist/core/file-integrity/store.js +2 -0
- package/dist/core/handoff/runtime.js +37 -1
- package/dist/core/inference/text-inference.js +3 -1
- package/dist/core/initialization/service.js +11 -6
- package/dist/core/interaction-router.js +3 -0
- package/dist/core/invoke/executors/text.js +72 -19
- package/dist/core/ipc-registration.js +3 -1
- package/dist/core/message/aun-ipc-sender.js +279 -107
- 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 +41 -2
- package/dist/core/message/message-admission.js +5 -39
- package/dist/core/message/message-bridge.js +140 -370
- package/dist/core/message/message-log.js +29 -0
- package/dist/core/message/message-queue.js +119 -15
- package/dist/core/message/message-utils.js +8 -0
- package/dist/core/message/response-engine.js +580 -134
- package/dist/core/message/send-routing.js +5 -1
- package/dist/core/model/catalog-service.js +31 -11
- package/dist/core/model/config-scope.js +6 -14
- package/dist/core/model/model-capabilities.js +22 -4
- package/dist/core/model/model-catalog.js +1 -0
- package/dist/core/model/model-diagnostics.js +19 -0
- package/dist/core/model/model-fallback.js +13 -2
- package/dist/core/ownership/owner-resolver.js +328 -50
- 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/protected-paths.js +6 -6
- 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 +36 -1
- package/dist/core/relation/same-owner-proof.js +81 -112
- package/dist/core/session/adapters/codex-session-file-adapter.js +96 -15
- package/dist/core/session/session-file-health.js +13 -7
- package/dist/core/session/session-fs-store.js +91 -35
- package/dist/core/session/session-manager.js +68 -24
- package/dist/core/session/session-mapper.js +14 -34
- package/dist/core/session/session-transcript.js +5 -1
- package/dist/core/task/task-activity-store.js +84 -0
- package/dist/core/task/task-recovery-service.js +13 -0
- package/dist/core/thread/command-parser.js +7 -12
- package/dist/core/thread/thread-context-storage.js +3 -2
- package/dist/core/thread/thread-operation.js +2 -13
- package/dist/core/thread/thread-service.js +15 -46
- package/dist/core/thread/topic-id.js +15 -0
- package/dist/directory/owner-directory-admission.js +12 -9
- package/dist/directory/owner-directory-cache.js +64 -28
- package/dist/directory/owner-directory-markdown.js +14 -2
- package/dist/directory/owner-directory-policy.js +5 -30
- package/dist/directory/owner-directory-query-operation.js +29 -3
- package/dist/directory/owner-directory-remarks.js +11 -3
- package/dist/directory/owner-directory-request-operation.js +5 -2
- package/dist/eck/kit-renderer.js +1 -1
- package/dist/eck/message-renderer.js +112 -29
- package/dist/ecweb/basic-settings-service.js +3 -1
- package/dist/ecweb/message-context-service.js +1 -1
- package/dist/ecweb/pairing.js +4 -3
- package/dist/ecweb/providers-service.js +26 -1
- package/dist/ecweb/runtime/lifecycle.js +18 -8
- package/dist/ecweb/runtime/proxy-access.js +74 -0
- package/dist/ecweb/runtime/supervisor.js +36 -6
- 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 +29 -3
- package/dist/event-center/runtime.js +106 -11
- package/dist/event-center/script-runner.js +5 -5
- package/dist/index.js +96 -59
- package/dist/ipc.js +38 -3
- package/dist/outputs/authorization.js +16 -0
- package/dist/outputs/cards.js +336 -0
- package/dist/outputs/events.js +63 -0
- package/dist/outputs/protocol.js +103 -0
- package/dist/outputs/service.js +266 -0
- package/dist/paths.js +3 -0
- package/dist/proxy/manager.js +43 -13
- package/dist/services/index.js +114 -5
- package/dist/services/ipc-operation.js +88 -15
- package/dist/services/pack-manager.js +13 -1
- package/dist/services/router.js +21 -6
- package/dist/services/script-runner.js +5 -4
- package/dist/services/service-payload.js +13 -7
- package/dist/services/validation.js +1 -1
- package/dist/stats/budget.js +2 -2
- package/dist/stats/db.js +19 -0
- package/dist/stats/index.js +1 -1
- package/dist/stats/{price-resolver.js → model-resolver.js} +304 -23
- package/dist/stats/normalizer.js +2 -0
- package/dist/stats/query.js +35 -27
- package/dist/stats/quota-query.js +95 -0
- package/dist/stats/role-budget.js +5 -2
- package/dist/stats/writer.js +10 -6
- package/dist/trigger/audit.js +7 -0
- package/dist/trigger/authorization.js +105 -11
- package/dist/trigger/feedback.js +10 -0
- package/dist/trigger/history.js +37 -11
- package/dist/trigger/ipc-service.js +12 -1
- package/dist/trigger/manager.js +1 -0
- package/dist/trigger/scheduler.js +7 -5
- package/dist/trigger/script-executor.js +2 -1
- package/dist/trigger/script-sandbox.js +21 -3
- package/dist/trigger/validation.js +22 -0
- package/dist/utils/atomic-write.js +22 -8
- package/dist/utils/cross-platform.js +73 -26
- package/dist/utils/error-dict.json +94 -4
- package/dist/utils/error-utils.js +27 -4
- package/dist/utils/evolcore-version.js +36 -65
- package/dist/utils/host-info.js +100 -1
- package/dist/utils/msg-diag.js +1 -0
- package/dist/utils/npm-ops.js +43 -8
- package/dist/utils/process-introspect.js +12 -7
- package/dist/utils/process-tree.js +50 -2
- package/dist/utils/windows-shell-trust.js +2 -0
- package/dist/workbench/protocol.js +80 -0
- package/dist/workbench/service.js +359 -0
- package/ecagent/dist/types.d.ts +6 -2
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +4 -2
- package/kits/docs/evolcore/aid.md +25 -0
- package/kits/docs/evolcore/config.md +16 -1
- package/kits/docs/evolcore/directory.md +30 -12
- package/kits/docs/evolcore/ecweb-lifecycle.md +15 -0
- package/kits/docs/evolcore/model.md +10 -0
- package/kits/docs/evolcore/msg.md +9 -0
- package/kits/docs/evolcore/peer.md +19 -65
- package/kits/docs/evolcore/provider.md +124 -4
- package/kits/docs/evolcore/quota.md +54 -0
- package/kits/docs/evolcore/role.md +83 -0
- package/kits/docs/evolcore/services.md +6 -6
- package/kits/docs/evolcore/stats.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +1 -1
- package/kits/docs/evolcore/thread-chain.md +14 -15
- package/kits/docs/evolcore/tool-authorization.md +5 -0
- package/kits/docs/evolcore/trigger.md +12 -0
- package/kits/eck_message_manifest.json +12 -0
- package/kits/provider-templates.json +1213 -0
- package/kits/rules/04-relation.md +3 -3
- package/kits/schemas/_meta.json +14 -2
- package/kits/schemas/agent-config.schema.20.json +24 -0
- package/kits/schemas/contact-book.schema.4.json +52 -0
- package/kits/schemas/providers.schema.3.json +200 -0
- package/kits/skills/.switches.json +8 -0
- package/kits/skills/ability/references/calling.md +1 -1
- package/kits/skills/agent-output-cards/SKILL.md +57 -0
- package/kits/skills/ec-group/SKILL.md +2 -2
- package/kits/skills/ec-identity/SKILL.md +19 -72
- package/kits/skills/ec-provider/SKILL.md +270 -0
- package/kits/skills/ec-provider/scripts/check-model.mjs +80 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/skills/thread-ops/SKILL.md +34 -21
- package/kits/templates/message-fragments/group-batch-item.md +1 -1
- package/kits/templates/message-fragments/group-batch.md +1 -1
- package/kits/templates/message-fragments/inject-default.md +1 -1
- package/kits/templates/message-fragments/interrupt-insert.md +1 -0
- package/kits/templates/message-fragments/item-group.md +1 -1
- package/kits/templates/message-fragments/item-private.md +1 -1
- package/kits/templates/message-fragments/thread-context.md +1 -1
- package/kits/templates/message-fragments/trigger-session.md +1 -1
- package/kits/templates/message-fragments/trigger-thread-check.md +1 -1
- package/kits/templates/roles/admin.json +2 -19
- package/kits/templates/roles/member.json +0 -3
- package/kits/templates/roles/visitor.json +1 -0
- package/kits/templates/system-fragments/baseagent.md +6 -0
- package/kits/templates/system-fragments/commands.md +4 -3
- package/kits/templates/system-fragments/directory-contacts.md +3 -4
- package/kits/templates/system-fragments/managed-runtime.md +1 -1
- package/kits/templates/system-fragments/relation.md +1 -1
- package/kits/templates/system-fragments/thread.md +7 -5
- package/kits/templates/system-fragments/venue.md +11 -0
- package/package.json +6 -4
- package/scripts/agent-template/inspect.mjs +50 -11
- package/scripts/agent-template/shared/common.mjs +11 -6
- package/scripts/agent-template/shared/team-schema.json +6 -4
- package/scripts/agent-template/shared/template-contract.mjs +62 -11
- package/scripts/agent-template/shared/template-package.mjs +189 -21
- package/scripts/agent-template/shared/template-runtime.mjs +54 -6
- package/scripts/agent-template/shared/template.mjs +2 -2
- package/scripts/agent-template/team-pack.mjs +52 -14
- package/dist/cli/peer.js +0 -127
- package/dist/config/peer-operation-service.js +0 -132
- package/dist/config/peer-request-service.js +0 -532
- package/dist/core/command/connect-menu.js +0 -624
|
@@ -233,8 +233,7 @@ export class ThreadService {
|
|
|
233
233
|
channelType: parsedDir.channelType,
|
|
234
234
|
peerKind: last.chatType === 'group' ? 'group' : 'private',
|
|
235
235
|
name: last.name ?? threadId,
|
|
236
|
-
|
|
237
|
-
topicStatus: last.topicStatus ?? 'pending',
|
|
236
|
+
topicStatus: last.topicStatus ?? 'active',
|
|
238
237
|
createdAt: last.createdAt ?? 0,
|
|
239
238
|
lastActiveAt: last.updatedAt ?? 0,
|
|
240
239
|
...(typeof last.metadata?.nameUpdatedAt === 'number'
|
|
@@ -262,7 +261,7 @@ export class ThreadService {
|
|
|
262
261
|
}
|
|
263
262
|
// ── P1a.1.2: 话题创建 ──
|
|
264
263
|
async createThread(input) {
|
|
265
|
-
const { selfAid, peerKind, name,
|
|
264
|
+
const { selfAid, peerKind, name, topicStatus } = input;
|
|
266
265
|
const peer = normalizeThreadPeer(input.peer) ?? input.peer;
|
|
267
266
|
// Validate name
|
|
268
267
|
const sanitized = sanitizeSessionTitle(name);
|
|
@@ -293,8 +292,7 @@ export class ThreadService {
|
|
|
293
292
|
'aun', // channelType
|
|
294
293
|
peerKind === 'group' ? 'group' : 'agent', // peerType
|
|
295
294
|
undefined, // identity
|
|
296
|
-
|
|
297
|
-
topicStatus ?? 'pending');
|
|
295
|
+
topicStatus ?? 'active');
|
|
298
296
|
const entry = {
|
|
299
297
|
threadId,
|
|
300
298
|
sessionId: session.id,
|
|
@@ -303,8 +301,7 @@ export class ThreadService {
|
|
|
303
301
|
peerKind,
|
|
304
302
|
name: sanitized,
|
|
305
303
|
nameUpdatedAt: now,
|
|
306
|
-
|
|
307
|
-
topicStatus: topicStatus ?? 'pending',
|
|
304
|
+
topicStatus: topicStatus ?? 'active',
|
|
308
305
|
createdAt: now,
|
|
309
306
|
lastActiveAt: now,
|
|
310
307
|
};
|
|
@@ -409,8 +406,7 @@ export class ThreadService {
|
|
|
409
406
|
peerKind: input.peerKind ?? 'private',
|
|
410
407
|
name: sanitized,
|
|
411
408
|
nameUpdatedAt: input.nameUpdatedAt,
|
|
412
|
-
|
|
413
|
-
topicStatus: 'pending',
|
|
409
|
+
topicStatus: 'active',
|
|
414
410
|
createdAt: input.nameUpdatedAt,
|
|
415
411
|
lastActiveAt: input.nameUpdatedAt,
|
|
416
412
|
});
|
|
@@ -426,23 +422,6 @@ export class ThreadService {
|
|
|
426
422
|
await this.sessionManager.renameSession(session.id, sanitized, input.nameUpdatedAt);
|
|
427
423
|
return { applied: true };
|
|
428
424
|
}
|
|
429
|
-
// ── P1a.1.6: 话题标签 ──
|
|
430
|
-
async labelThread(input) {
|
|
431
|
-
const { selfAid, threadId, label } = input;
|
|
432
|
-
const peer = normalizeThreadPeer(input.peer) ?? input.peer;
|
|
433
|
-
const index = this.readThreadIndex(selfAid);
|
|
434
|
-
const entry = index.threads.find(t => t.peer === peer && t.threadId === threadId);
|
|
435
|
-
if (!entry)
|
|
436
|
-
throw new ThreadServiceError(`话题不存在: ${threadId}`, 'TOPIC_NOT_FOUND');
|
|
437
|
-
entry.label = label;
|
|
438
|
-
entry.lastActiveAt = Date.now();
|
|
439
|
-
this.writeThreadIndex(selfAid, index);
|
|
440
|
-
this.appendThreadSnapshot(selfAid, entry);
|
|
441
|
-
const session = await this.sessionManager.getThreadSession(entryChannelType(entry), entry.peer, threadId, selfAid);
|
|
442
|
-
if (session) {
|
|
443
|
-
await this.sessionManager.setTopicLabel(session.id, label);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
425
|
// ── P1a.1.6: 话题状态 ──
|
|
447
426
|
async statusThread(input) {
|
|
448
427
|
const { selfAid, threadId, topicStatus } = input;
|
|
@@ -557,12 +536,12 @@ export class ThreadService {
|
|
|
557
536
|
}
|
|
558
537
|
// ── list ──
|
|
559
538
|
listThreads(input) {
|
|
560
|
-
const { selfAid, status,
|
|
539
|
+
const { selfAid, status, sort, page = 1, limit: rawLimit } = input;
|
|
561
540
|
const peer = normalizeThreadPeer(input.peer);
|
|
562
541
|
const limit = Math.min(rawLimit ?? LIST_DEFAULT_LIMIT, LIST_MAX_LIMIT);
|
|
563
542
|
const { index, state: indexState } = this.readThreadIndexWithState(selfAid);
|
|
564
543
|
// 未套过滤条件的话题数:用于把「该对端确实没有话题」与
|
|
565
|
-
// 「有话题但被 --status
|
|
544
|
+
// 「有话题但被 --status 挡掉」区分开。
|
|
566
545
|
const peerTopicCount = peer
|
|
567
546
|
? index.threads.filter(t => normalizeThreadPeer(t.peer) === peer).length
|
|
568
547
|
: index.threads.length;
|
|
@@ -571,10 +550,6 @@ export class ThreadService {
|
|
|
571
550
|
return false;
|
|
572
551
|
if (status && t.topicStatus !== status)
|
|
573
552
|
return false;
|
|
574
|
-
if (unlabeled && t.label)
|
|
575
|
-
return false;
|
|
576
|
-
if (label && t.label !== label)
|
|
577
|
-
return false;
|
|
578
553
|
return true;
|
|
579
554
|
});
|
|
580
555
|
// 主话题由会话文件产生、从不进话题索引。只列话题会让「和某对端聊过什么」
|
|
@@ -613,7 +588,6 @@ export class ThreadService {
|
|
|
613
588
|
// 读真实值而不是写死 `主会话`:否则列表里的名字和会话存档对不上,
|
|
614
589
|
// 用户也没法从列表确认改名是否生效。`[主话题]` 前缀由 CLI 渲染。
|
|
615
590
|
name: active?.name || '主会话',
|
|
616
|
-
label: null,
|
|
617
591
|
createdAt: lastTs,
|
|
618
592
|
lastActiveAt: lastTs,
|
|
619
593
|
mainSession: true,
|
|
@@ -622,9 +596,9 @@ export class ThreadService {
|
|
|
622
596
|
msg24h: 0,
|
|
623
597
|
lastMsgSnippet: '',
|
|
624
598
|
};
|
|
625
|
-
//
|
|
599
|
+
// 该对端没有任何主会话往来时不造空行;状态过滤对主会话无意义,
|
|
626
600
|
// 只在未过滤时加入。
|
|
627
|
-
if (lastTs > 0 && !status
|
|
601
|
+
if (lastTs > 0 && !status)
|
|
628
602
|
threads = [synthetic, ...threads];
|
|
629
603
|
}
|
|
630
604
|
}
|
|
@@ -717,7 +691,7 @@ export class ThreadService {
|
|
|
717
691
|
return {
|
|
718
692
|
threads, total, page, limit,
|
|
719
693
|
hasMore: offset + threads.length < total,
|
|
720
|
-
totalMsgCount, peer, selfAid, sort, status,
|
|
694
|
+
totalMsgCount, peer, selfAid, sort, status,
|
|
721
695
|
peerKnown, peerTopicCount, hasMainChat, indexState,
|
|
722
696
|
};
|
|
723
697
|
}
|
|
@@ -853,8 +827,7 @@ export class ThreadService {
|
|
|
853
827
|
: typeof last.nameUpdatedAt === 'number'
|
|
854
828
|
? { nameUpdatedAt: last.nameUpdatedAt }
|
|
855
829
|
: {}),
|
|
856
|
-
|
|
857
|
-
topicStatus: last.topicStatus ?? 'pending',
|
|
830
|
+
topicStatus: last.topicStatus ?? 'active',
|
|
858
831
|
createdAt: last.createdAt ?? 0,
|
|
859
832
|
lastActiveAt: last.updatedAt ?? 0,
|
|
860
833
|
});
|
|
@@ -873,7 +846,7 @@ export class ThreadService {
|
|
|
873
846
|
/**
|
|
874
847
|
* 检查话题索引的健康状态,区分两类问题:
|
|
875
848
|
* missing — _threads JSONL 文件不存在(数据问题,严重,rebuild 会丢失属性改动)
|
|
876
|
-
* stale — 文件存在但最后一行的 name/
|
|
849
|
+
* stale — 文件存在但最后一行的 name/topicStatus 与索引不一致(写盘时序问题,轻微)
|
|
877
850
|
*/
|
|
878
851
|
checkIndex(selfAid) {
|
|
879
852
|
const index = this.readThreadIndex(selfAid);
|
|
@@ -888,13 +861,12 @@ export class ThreadService {
|
|
|
888
861
|
missingIds.push(entry.threadId);
|
|
889
862
|
continue;
|
|
890
863
|
}
|
|
891
|
-
// 检查最后一行是否与索引一致(name /
|
|
864
|
+
// 检查最后一行是否与索引一致(name / topicStatus)
|
|
892
865
|
try {
|
|
893
866
|
const lines = readAllJsonlLines(metaPath);
|
|
894
867
|
const last = lines[lines.length - 1];
|
|
895
868
|
if (last && (last.name !== entry.name ||
|
|
896
|
-
(last.
|
|
897
|
-
(last.topicStatus ?? 'pending') !== entry.topicStatus)) {
|
|
869
|
+
(last.topicStatus ?? 'active') !== entry.topicStatus)) {
|
|
898
870
|
staleIds.push(entry.threadId);
|
|
899
871
|
}
|
|
900
872
|
}
|
|
@@ -927,7 +899,6 @@ export class ThreadService {
|
|
|
927
899
|
peerKind: session.chatType === 'group' ? 'group' : 'private',
|
|
928
900
|
name: session.name ?? peer,
|
|
929
901
|
nameUpdatedAt: typeof session.metadata?.nameUpdatedAt === 'number' ? session.metadata.nameUpdatedAt : undefined,
|
|
930
|
-
label: session.label ?? null,
|
|
931
902
|
createdAt: session.createdAt ?? 0,
|
|
932
903
|
lastActiveAt: session.updatedAt ?? 0,
|
|
933
904
|
running: session.processingState?.startsWith('processing') ?? false,
|
|
@@ -946,7 +917,6 @@ export class ThreadService {
|
|
|
946
917
|
peerKind: entry.peerKind,
|
|
947
918
|
name: entry.name,
|
|
948
919
|
nameUpdatedAt: undefined,
|
|
949
|
-
label: null,
|
|
950
920
|
createdAt: entry.createdAt,
|
|
951
921
|
lastActiveAt: entry.lastActiveAt,
|
|
952
922
|
running: false,
|
|
@@ -1014,7 +984,7 @@ export class ThreadService {
|
|
|
1014
984
|
}
|
|
1015
985
|
/**
|
|
1016
986
|
* 把话题的当前元数据追加一行到 _threads/<sessionId>.jsonl,
|
|
1017
|
-
* 使 rebuildIndex 读最后一行时能拿到 rename/
|
|
987
|
+
* 使 rebuildIndex 读最后一行时能拿到 rename/status 后的最新值。
|
|
1018
988
|
* 追加的行以最后一行(当前权威快照)为底,只覆盖话题字段,
|
|
1019
989
|
* 确保 readMetaLatest 读最后一行时不报 "baseagent is empty"。
|
|
1020
990
|
*
|
|
@@ -1042,7 +1012,6 @@ export class ThreadService {
|
|
|
1042
1012
|
threadId: entry.threadId,
|
|
1043
1013
|
channelIdAlias: entry.peer,
|
|
1044
1014
|
name: entry.name,
|
|
1045
|
-
label: entry.label,
|
|
1046
1015
|
topicStatus: entry.topicStatus,
|
|
1047
1016
|
createdAt: entry.createdAt,
|
|
1048
1017
|
createdAtStr: latest.createdAtStr ?? '',
|
|
@@ -126,6 +126,21 @@ export function isMainSessionThreadId(value) {
|
|
|
126
126
|
export function isTopicThreadId(value) {
|
|
127
127
|
return typeof value === 'string' && value !== '' && !isMainSessionThreadId(value);
|
|
128
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Normalize a local thread identity for the specified relation. Explicit main IDs
|
|
131
|
+
* must name these two peers; topic IDs still need their caller's index checks.
|
|
132
|
+
* Main identities remain local and must never be emitted as wire thread_id.
|
|
133
|
+
*/
|
|
134
|
+
export function normalizeThreadIdForPeer(value, selfAid, peerId) {
|
|
135
|
+
if (isTopicThreadId(value))
|
|
136
|
+
return value;
|
|
137
|
+
if (!isMainSessionThreadId(value))
|
|
138
|
+
return undefined;
|
|
139
|
+
const main = safeFormatMainTopicId(selfAid, peerId);
|
|
140
|
+
if (typeof value === 'string' && isMainTopicId(value) && canonicalizeMainTopicId(value) !== main)
|
|
141
|
+
return undefined;
|
|
142
|
+
return main;
|
|
143
|
+
}
|
|
129
144
|
/** 别名:旧代码中广泛使用的 isSubTopicThreadId,语义与 isTopicThreadId 完全一致。 */
|
|
130
145
|
export const isSubTopicThreadId = isTopicThreadId;
|
|
131
146
|
/**
|
|
@@ -217,7 +217,7 @@ export function readOwnerDirectoryMembership(selfAid, aid, appOwned = false) {
|
|
|
217
217
|
// App 侧一律按目录不可用处理,不因"没数据"放宽。
|
|
218
218
|
if (!appOwned)
|
|
219
219
|
return undefined;
|
|
220
|
-
logDirectoryAdmissionUnavailable(selfAid, aid, 'snapshot_missing');
|
|
220
|
+
logDirectoryAdmissionUnavailable(selfAid, aid, 'snapshot_missing', ownerResolver.owner(selfAid));
|
|
221
221
|
return { category: 'unavailable' };
|
|
222
222
|
}
|
|
223
223
|
// ownerAid 优先取快照信封:它自证归属,离线也能用。解析器只在没有快照时兜底。
|
|
@@ -247,37 +247,40 @@ export function readOwnerDirectoryMembership(selfAid, aid, appOwned = false) {
|
|
|
247
247
|
return { category: 'unavailable' };
|
|
248
248
|
}
|
|
249
249
|
const effectiveAllowExternalContacts = resolveAllowExternalContacts(selfAid, snapshot);
|
|
250
|
+
// `blockedAids` 是快照级字段,与调用方是否 appOwned 无关:以前只在 appOwned 分支里
|
|
251
|
+
// 计算,导致团队校验(不传 appOwned)读到 blocked=undefined,被屏蔽的联系人仍能被
|
|
252
|
+
// 拉进团队。这里统一算出来,两个分支共用。
|
|
253
|
+
const blocked = snapshot.blockedAids?.includes(aid) ?? false;
|
|
250
254
|
if (appOwned) {
|
|
251
255
|
const entry = snapshot.entries.find(item => item.aid === aid);
|
|
252
|
-
const blocked = snapshot.blockedAids?.includes(aid) ?? false;
|
|
253
256
|
const scopeExcluded = entry?.agent_scope?.mode === 'selected' && !entry.agent_scope.agent_aids.includes(selfAid);
|
|
254
257
|
const internal = entry ? isInternalEntry(entry, ownerRefAid(snapshot, ownerAid)) : undefined;
|
|
255
258
|
return { category: entry ? (entry.type === 'agent' ? 'agent' : entry.type === 'human' ? 'human' : 'other') : 'not_found',
|
|
256
259
|
entry, blocked, scopeExcluded, internal, effectiveAllowExternalContacts };
|
|
257
260
|
}
|
|
258
261
|
if (aid === ownerAid || snapshot.owner?.aid === aid) {
|
|
259
|
-
return { category: 'owner', internal: true, effectiveAllowExternalContacts };
|
|
262
|
+
return { category: 'owner', internal: true, blocked, effectiveAllowExternalContacts };
|
|
260
263
|
}
|
|
261
264
|
if (snapshot.personalAssistant?.aid === aid) {
|
|
262
|
-
return { category: 'assistant', internal: true, effectiveAllowExternalContacts };
|
|
265
|
+
return { category: 'assistant', internal: true, blocked, effectiveAllowExternalContacts };
|
|
263
266
|
}
|
|
264
267
|
if (aid === selfAid)
|
|
265
|
-
return { category: 'agent', internal: true, effectiveAllowExternalContacts };
|
|
268
|
+
return { category: 'agent', internal: true, blocked, effectiveAllowExternalContacts };
|
|
266
269
|
const entry = snapshot.entries.find(item => item.aid === aid);
|
|
267
270
|
if (!entry)
|
|
268
|
-
return { category: 'not_found', effectiveAllowExternalContacts };
|
|
271
|
+
return { category: 'not_found', blocked, effectiveAllowExternalContacts };
|
|
269
272
|
// 内外判据只有一个来源:Owner 身份块里的 aid。
|
|
270
273
|
const ownerRef = ownerRefAid(snapshot, ownerAid);
|
|
271
274
|
const internal = isInternalEntry(entry, ownerRef);
|
|
272
275
|
const type = entry.type;
|
|
273
276
|
if (type === 'agent')
|
|
274
|
-
return { category: 'agent', internal, entry, effectiveAllowExternalContacts };
|
|
277
|
+
return { category: 'agent', internal, entry, blocked, effectiveAllowExternalContacts };
|
|
275
278
|
if (type === 'human')
|
|
276
|
-
return { category: 'human', internal, entry, effectiveAllowExternalContacts };
|
|
279
|
+
return { category: 'human', internal, entry, blocked, effectiveAllowExternalContacts };
|
|
277
280
|
// 协议外的 type(`ai`、`codeagent`、缺失…)落 `other`:它既不是会发消息的
|
|
278
281
|
// agent/human,也不是协议允许的 service/device/org/custom/host,用途未知。
|
|
279
282
|
// 准入仍按内外分档(与宿主类型一致),只是不假装知道它是什么。
|
|
280
|
-
return { category: 'other', internal, entry, effectiveAllowExternalContacts };
|
|
283
|
+
return { category: 'other', internal, entry, blocked, effectiveAllowExternalContacts };
|
|
281
284
|
}
|
|
282
285
|
catch (error) {
|
|
283
286
|
const code = error && typeof error === 'object' && 'code' in error
|
|
@@ -46,6 +46,8 @@ export const OWNER_DIRECTORY_APPLY_WAIT_MS = 300;
|
|
|
46
46
|
* 退避按时间而不是按次数,既不会造成拉取风暴,也不会永久放弃。
|
|
47
47
|
*/
|
|
48
48
|
export const OWNER_DIRECTORY_PULL_BACKOFF_MS = [15_000, 30_000, 60_000, 120_000, 240_000, 480_000, 960_000, 1_800_000, 3_600_000];
|
|
49
|
+
/** A denied credential needs a grant/change event, a new runtime, or an hourly probe. */
|
|
50
|
+
const PERMISSION_DENIED_PROBE_MS = 3_600_000;
|
|
49
51
|
/**
|
|
50
52
|
* 拉取前的防抖窗口。
|
|
51
53
|
*
|
|
@@ -149,6 +151,7 @@ class OwnerDirectoryCoordinator {
|
|
|
149
151
|
pullGeneration = 0;
|
|
150
152
|
/** 已经计过失败的那一轮序号;同一轮无论几个 agent 报告都只记一次。 */
|
|
151
153
|
countedFailureGeneration;
|
|
154
|
+
deniedUntil = new Map();
|
|
152
155
|
constructor(ownerAid) {
|
|
153
156
|
this.ownerAid = ownerAid;
|
|
154
157
|
}
|
|
@@ -169,10 +172,14 @@ class OwnerDirectoryCoordinator {
|
|
|
169
172
|
}
|
|
170
173
|
/** 距离退避窗口结束还有多久;0 表示可以立刻拉取。 */
|
|
171
174
|
backoffRemainingMs(now) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
175
|
+
const window = this.failures === 0 || this.lastFailureAtMs === undefined ? 0
|
|
176
|
+
: Math.max(0, this.lastFailureAtMs
|
|
177
|
+
+ OWNER_DIRECTORY_PULL_BACKOFF_MS[Math.min(this.failures, OWNER_DIRECTORY_PULL_BACKOFF_MS.length) - 1] - now);
|
|
178
|
+
if (!this.deniedUntil.size)
|
|
179
|
+
return window;
|
|
180
|
+
const candidates = [...this.caches].filter(cache => !cache.isRetired() && !cache.isRevoked());
|
|
181
|
+
const permissionWait = candidates.length ? Math.min(...candidates.map(cache => Math.max(0, (this.deniedUntil.get(cache) ?? 0) - now))) : 0;
|
|
182
|
+
return Math.max(window, permissionWait);
|
|
176
183
|
}
|
|
177
184
|
clearFailures() {
|
|
178
185
|
this.failures = 0;
|
|
@@ -184,28 +191,24 @@ class OwnerDirectoryCoordinator {
|
|
|
184
191
|
*
|
|
185
192
|
* 判据是「实例还活着 + 它有授权」——授权凭证是 per-agent 的,协调者没有
|
|
186
193
|
* 自己的身份,所以必须借一个。优先选最近活跃的,避免挑到一个正在停止中的。
|
|
187
|
-
*
|
|
188
|
-
*
|
|
194
|
+
* 明确被拒的凭证暂停一小时;新授权、新通知或新运行时可提前恢复候选资格。
|
|
195
|
+
* 被拒只影响远端拉取,不影响读取已有本地快照。
|
|
189
196
|
*/
|
|
190
|
-
pickExecutor(preferred) {
|
|
197
|
+
pickExecutor(preferred, now) {
|
|
191
198
|
// 优先用发起方自己:它一定想拿到这份数据,结果也直接回给它。
|
|
192
199
|
// 只有它自身不可用(授权失效/已退役/刚被远端拒过)时才退到别人,避免出现
|
|
193
200
|
// 「A 触发、却被 B 的代拉结果覆盖」这种观测不到的错配。
|
|
194
201
|
// 执行者资格只看"实例还活着、没被远端拒过"——没有本地凭证可审了。
|
|
195
|
-
const usable = (cache) => !cache.isRetired() && !cache.isRevoked()
|
|
196
|
-
|
|
202
|
+
const usable = (cache) => !cache.isRetired() && !cache.isRevoked()
|
|
203
|
+
&& (this.deniedUntil.get(cache) ?? 0) <= now;
|
|
204
|
+
if (preferred && usable(preferred))
|
|
197
205
|
return preferred;
|
|
198
206
|
for (const cache of this.caches) {
|
|
199
207
|
if (cache.isRetired()) {
|
|
200
208
|
this.caches.delete(cache);
|
|
209
|
+
this.deniedUntil.delete(cache);
|
|
201
210
|
continue;
|
|
202
211
|
}
|
|
203
|
-
if (usable(cache) && !cache.pullBlocked())
|
|
204
|
-
return cache;
|
|
205
|
-
}
|
|
206
|
-
if (preferred && usable(preferred))
|
|
207
|
-
return preferred;
|
|
208
|
-
for (const cache of this.caches) {
|
|
209
212
|
if (usable(cache))
|
|
210
213
|
return cache;
|
|
211
214
|
}
|
|
@@ -469,6 +472,7 @@ export class OwnerDirectoryCache {
|
|
|
469
472
|
return;
|
|
470
473
|
}
|
|
471
474
|
this.writeRevocationState(false);
|
|
475
|
+
coordinatorFor(this.options.ownerAid).deniedUntil.delete(this);
|
|
472
476
|
this.clearPullFailures();
|
|
473
477
|
logger.info(`[OwnerDirectoryCache] Owner directory grant applied: status=${result.status} (no local credential stored)`);
|
|
474
478
|
this._logAction({
|
|
@@ -558,6 +562,7 @@ export class OwnerDirectoryCache {
|
|
|
558
562
|
...(contentDigest ? { contentDigest } : {}),
|
|
559
563
|
receivedAtMs: this.now(),
|
|
560
564
|
};
|
|
565
|
+
coordinator.deniedUntil.delete(this);
|
|
561
566
|
// 新通知意味着新的变更意图:退避归零,立刻给一次机会。
|
|
562
567
|
coordinator.clearFailures();
|
|
563
568
|
this.writePendingUpdate({
|
|
@@ -720,6 +725,7 @@ export class OwnerDirectoryCache {
|
|
|
720
725
|
// 若各自 ++,一次网络故障就会把退避直接推到封顶。
|
|
721
726
|
coordinator.recordFailure(this.now(), coordinator.pullGeneration);
|
|
722
727
|
const failures = coordinator.failures;
|
|
728
|
+
const next = coordinator.backoffRemainingMs(this.now());
|
|
723
729
|
this._logAction({
|
|
724
730
|
action: 'error',
|
|
725
731
|
trigger: trigger ?? (pending.operationId.startsWith('notification-') ? 'notification' : 'startup'),
|
|
@@ -728,9 +734,8 @@ export class OwnerDirectoryCache {
|
|
|
728
734
|
sharedGeneration: coordinator.epoch?.generation,
|
|
729
735
|
error: errorText(error),
|
|
730
736
|
detail: `拉取失败(连续第 ${failures} 次,下一档退避 `
|
|
731
|
-
+ `${
|
|
737
|
+
+ `${next}ms)`,
|
|
732
738
|
});
|
|
733
|
-
const next = OWNER_DIRECTORY_PULL_BACKOFF_MS[Math.min(failures, OWNER_DIRECTORY_PULL_BACKOFF_MS.length) - 1];
|
|
734
739
|
const message = `[OwnerDirectoryCache] Pending pull failed (${failures} in a row, next retry in ${next}ms): ${errorText(error)}`;
|
|
735
740
|
// 连续失败不是抖动:升级日志级别,让"名录一直没更新"能被发现,
|
|
736
741
|
// 而不是翻两小时前的 WARN 才知道。
|
|
@@ -810,12 +815,8 @@ export class OwnerDirectoryCache {
|
|
|
810
815
|
const outcome = coordinator.pulling
|
|
811
816
|
? await coordinator.pulling
|
|
812
817
|
: await this._startCoordinatedPull(coordinator, trigger, operationId, hintDigest);
|
|
813
|
-
//
|
|
814
|
-
//
|
|
815
|
-
// 只认远端结论,本地不再有凭证可以判"该不该被拒"。
|
|
816
|
-
for (const scope of outcome.denied) {
|
|
817
|
-
await this.blockScope(scope);
|
|
818
|
-
}
|
|
818
|
+
// Only the executor's credential was tested. Single-flight waiters must not
|
|
819
|
+
// inherit its denial; one of them may be able to supply the shared snapshot.
|
|
819
820
|
const complete = this._assertComplete(outcome.data, outcome.failures);
|
|
820
821
|
return complete;
|
|
821
822
|
}
|
|
@@ -840,11 +841,25 @@ export class OwnerDirectoryCache {
|
|
|
840
841
|
return { data: cached, denied: [], failures: {} };
|
|
841
842
|
}
|
|
842
843
|
}
|
|
843
|
-
|
|
844
|
+
let executor = coordinator.pickExecutor(this, this.now());
|
|
844
845
|
if (!executor) {
|
|
845
|
-
throw new OwnerDirectoryCacheError('
|
|
846
|
+
throw new OwnerDirectoryCacheError('PERMISSION_DENIED', 'no owner directory executor is currently eligible to pull');
|
|
847
|
+
}
|
|
848
|
+
let result;
|
|
849
|
+
const attempted = new Set();
|
|
850
|
+
while (true) {
|
|
851
|
+
attempted.add(executor);
|
|
852
|
+
result = await executor._doFetch();
|
|
853
|
+
if (!result.denied.length)
|
|
854
|
+
break;
|
|
855
|
+
coordinator.deniedUntil.set(executor, this.now() + PERMISSION_DENIED_PROBE_MS);
|
|
856
|
+
for (const scope of result.denied)
|
|
857
|
+
await executor.blockScope(scope);
|
|
858
|
+
const alternative = coordinator.pickExecutor(undefined, this.now());
|
|
859
|
+
if (!alternative || attempted.has(alternative))
|
|
860
|
+
break;
|
|
861
|
+
executor = alternative;
|
|
846
862
|
}
|
|
847
|
-
const result = await executor._doFetch();
|
|
848
863
|
const written = executor._commitSharedCache(result.data, trigger, operationId, startedAt);
|
|
849
864
|
if (written) {
|
|
850
865
|
// 执行者**自己**先同步落地:`onSnapshotApplying` 这类前置校验失败必须
|
|
@@ -1003,6 +1018,7 @@ export class OwnerDirectoryCache {
|
|
|
1003
1018
|
for (const scope of OWNER_DIRECTORY_SCOPES)
|
|
1004
1019
|
this._writeSyncStamp(scope);
|
|
1005
1020
|
this.refreshMarkdown();
|
|
1021
|
+
this.notifySnapshotApplied();
|
|
1006
1022
|
return true;
|
|
1007
1023
|
}
|
|
1008
1024
|
const fetched = this._readSharedCache();
|
|
@@ -1102,6 +1118,23 @@ export class OwnerDirectoryCache {
|
|
|
1102
1118
|
*
|
|
1103
1119
|
* 完整性由阶段一保证(`_assertComplete`);这里只跳过"拉取之后权限被撤"的范围。
|
|
1104
1120
|
*/
|
|
1121
|
+
notifySnapshotApplied() {
|
|
1122
|
+
if (!this.canApply())
|
|
1123
|
+
return;
|
|
1124
|
+
try {
|
|
1125
|
+
this.options.onSnapshotApplied?.();
|
|
1126
|
+
}
|
|
1127
|
+
catch (error) {
|
|
1128
|
+
logger.warn('[OwnerDirectoryCache] onSnapshotApplied failed:', error);
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
/** Used only while durable inbound messages await approval. Honors Owner-wide backoff. */
|
|
1132
|
+
async reconcilePendingContacts() {
|
|
1133
|
+
if (!this.readPendingUpdate())
|
|
1134
|
+
await this.handleOwnerChangedEvent(this.options.ownerAid);
|
|
1135
|
+
await this.processPendingIfNeeded();
|
|
1136
|
+
await this.applyFromSharedCache();
|
|
1137
|
+
}
|
|
1105
1138
|
async _applyAll(fetched) {
|
|
1106
1139
|
const apply = async () => {
|
|
1107
1140
|
if (!this.canApply())
|
|
@@ -1125,6 +1158,7 @@ export class OwnerDirectoryCache {
|
|
|
1125
1158
|
const epoch = coordinatorFor(this.options.ownerAid).epoch;
|
|
1126
1159
|
if (epoch)
|
|
1127
1160
|
this.appliedGeneration = epoch.generation;
|
|
1161
|
+
this.notifySnapshotApplied();
|
|
1128
1162
|
}
|
|
1129
1163
|
// ── 共享缓存($EVOLCORE_HOME/data/owner-directory/<ownerAid>/) ────────────
|
|
1130
1164
|
_sharedCacheDir() {
|
|
@@ -1424,8 +1458,8 @@ export class OwnerDirectoryCache {
|
|
|
1424
1458
|
if (this.canMutate())
|
|
1425
1459
|
this.options.onError?.(scope, normalized);
|
|
1426
1460
|
this._appendFetchFailure(scope, code, errorText(normalized));
|
|
1427
|
-
//
|
|
1428
|
-
//
|
|
1461
|
+
// The coordinator suspends only this executor's denied credential.
|
|
1462
|
+
// Existing snapshots remain usable, and other executors may still fetch.
|
|
1429
1463
|
if (isPermissionDenied(normalized))
|
|
1430
1464
|
denied.push(scope);
|
|
1431
1465
|
}
|
|
@@ -1942,6 +1976,8 @@ export class OwnerDirectoryCache {
|
|
|
1942
1976
|
ownerAid: this.options.ownerAid,
|
|
1943
1977
|
selfAid: this.options.selfAid,
|
|
1944
1978
|
snapshot,
|
|
1979
|
+
// 备注不走命令,注入里要写出文件的真实位置,模型才知道往哪写。
|
|
1980
|
+
directory: this.options.directory,
|
|
1945
1981
|
remarks: this.remarksSnapshot(),
|
|
1946
1982
|
policy: resolveOwnerDirectoryRenderPolicy(this.options.selfAid, snapshot),
|
|
1947
1983
|
// `config.team` 每轮现读:Owner 在 App 里改完团队成员,下一次重算就生效。
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { splitAliases } from './owner-directory-remarks.js';
|
|
3
|
+
import { OWNER_DIRECTORY_REMARKS_DIR, splitAliases, } from './owner-directory-remarks.js';
|
|
4
4
|
import { classifyEntry, entryOwnerAid, isInPaTeam, ownerRefAid, } from './owner-directory-scope.js';
|
|
5
5
|
/** ECK 载入的名录文件,与名录快照同目录。 */
|
|
6
6
|
export const OWNER_DIRECTORY_MARKDOWN_FILE = 'directory.md';
|
|
@@ -76,6 +76,17 @@ export function resolveMyAgentTeamAids(team, snapshot, selfAid, ownerAid) {
|
|
|
76
76
|
const visible = total.slice(0, MY_AGENT_TEAM_LIMIT);
|
|
77
77
|
return { visible, total: total.length, dropped: total.length - visible.length };
|
|
78
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* 注入内容里示例备注文件的路径。
|
|
81
|
+
*
|
|
82
|
+
* 备注不走命令,模型必须知道写哪个文件才不会靠猜。知道 `directory/` 的真实位置时
|
|
83
|
+
* 写绝对路径;不知道(测试、或调用方没传)时回落成占位写法,不编一个假路径。
|
|
84
|
+
*/
|
|
85
|
+
function remarksExamplePath(input) {
|
|
86
|
+
return input.directory
|
|
87
|
+
? path.join(input.directory, OWNER_DIRECTORY_REMARKS_DIR, '<AID>.md')
|
|
88
|
+
: '<agent 目录>/directory/remarks/<AID>.md';
|
|
89
|
+
}
|
|
79
90
|
export function renderOwnerDirectoryMarkdown(input) {
|
|
80
91
|
const { selfAid, ownerAid, snapshot, remarks } = input;
|
|
81
92
|
if (!snapshot)
|
|
@@ -159,8 +170,9 @@ export function renderOwnerDirectoryMarkdown(input) {
|
|
|
159
170
|
'- `ec directory refresh`:立即同步一次,然后重算本文件。怀疑名录过期时用。',
|
|
160
171
|
'- `ec directory blocked`:查被拉黑的主体。名录里不渲染黑名单,要判断某人能不能联系就查这个。',
|
|
161
172
|
'- `ec directory request <AID> [--note <说明>]`:给一个**还不在名录里**的人发加好友申请。',
|
|
162
|
-
'
|
|
173
|
+
' 向目标发送显式好友邀请,仅表示已提交;普通消息出站无需先入录,入站仍按当前许可判断。',
|
|
163
174
|
'- 需要名片原文时:`ec aid agentmd get <AID>`。',
|
|
175
|
+
`- **备注不走命令**:直接写 \`${remarksExamplePath(input)}\`,frontmatter 用 \`aid\`/\`remark\`/\`updated_at\`,正文写「什么事找他」,写完 \`ec directory refresh\`。文件名须与 \`aid\` 一致,否则整条作废。`,
|
|
164
176
|
];
|
|
165
177
|
if (owner?.aid) {
|
|
166
178
|
head.push('', '## Owner(1)', identityRow(owner.aid, owner.name, remarks?.get(owner.aid)));
|
|
@@ -13,8 +13,8 @@ import { ConfigTarget, read } from '../config/config-manager.js';
|
|
|
13
13
|
/**
|
|
14
14
|
* 外部联系开关的最终值:**显式配置 > 个人助理判据 > false**。
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* 个人助理默认接收外部联系人的入站;其余 agent 默认关闭,
|
|
17
|
+
* 可由 Owner 打开。普通出站不使用此开关。
|
|
18
18
|
*/
|
|
19
19
|
export function resolveAllowExternalContacts(selfAid, snapshot,
|
|
20
20
|
/** 显式配置;缺省时从配置文件读。测试用来固定优先级。 */
|
|
@@ -100,32 +100,7 @@ export function resolveOwnerDirectoryRenderPolicy(selfAid, snapshot) {
|
|
|
100
100
|
allowedAids: policy.allowedAids ?? [],
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
|
-
/**
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
* 发出去却被拒"。
|
|
107
|
-
*
|
|
108
|
-
* 判据顺序照搬准入:总开关 > 名单(白名单命中即通)> 内部档 / 外部档。
|
|
109
|
-
* 黑名单**参与**这里:它是 Owner 显式指定的拒绝,总开关也翻不动它。
|
|
110
|
-
*/
|
|
111
|
-
export function resolveEntryContactable(selfAid, snapshot, entry) {
|
|
112
|
-
let policy;
|
|
113
|
-
try {
|
|
114
|
-
policy = readAccessPolicy(selfAid);
|
|
115
|
-
}
|
|
116
|
-
catch {
|
|
117
|
-
// 配置读不出不等于"谁都不能联系":外部档仍按"显式配置 > 个人助理判据"回落,
|
|
118
|
-
// 与注入侧口径保持一致(那份快照在同样的失败下也只关掉外部与总开关)。
|
|
119
|
-
return entry.internal === true || resolveAllowExternalContacts(selfAid, snapshot) === true;
|
|
120
|
-
}
|
|
121
|
-
if (policy.deniedAids?.includes(entry.aid))
|
|
122
|
-
return false;
|
|
123
|
-
if (entry.internal === true)
|
|
124
|
-
return policy.allowInternalContacts !== false;
|
|
125
|
-
if (policy.allowedAids?.includes(entry.aid))
|
|
126
|
-
return true;
|
|
127
|
-
if (policy.allowAllContacts === true)
|
|
128
|
-
return true;
|
|
129
|
-
// 同 `resolveOwnerDirectoryRenderPolicy`:传 undefined 让函数自己去读显式配置。
|
|
130
|
-
return resolveAllowExternalContacts(selfAid, snapshot) === true;
|
|
103
|
+
/** Ordinary outbound messaging is independent of inbound contact admission. */
|
|
104
|
+
export function resolveEntryContactable(_selfAid, _snapshot, _entry) {
|
|
105
|
+
return true;
|
|
131
106
|
}
|
|
@@ -22,6 +22,7 @@ import { isInternalEntry, ownerRefAid } from './owner-directory-scope.js';
|
|
|
22
22
|
import { editDistance, normalizeDirectoryText, sameDirectoryName, stripTrailingParenthetical, } from './owner-directory-text.js';
|
|
23
23
|
import { ownerResolver } from '../core/ownership/owner-resolver.js';
|
|
24
24
|
import { snapshotOwnerAid, refreshOwnerDirectory, syncOwnerDirectoryForLookup } from './owner-directory-admission.js';
|
|
25
|
+
import { mutatePeerBook } from '../config/peer-book-store.js';
|
|
25
26
|
import { getPeerSnapshot } from '../config/peer-book.js';
|
|
26
27
|
import { resolveEntryContactable, resolveMyAgentTeam } from './owner-directory-policy.js';
|
|
27
28
|
import { resolveMyAgentTeamAids } from './owner-directory-markdown.js';
|
|
@@ -43,8 +44,8 @@ export function resolveDirectoryQueryCommand(argv) {
|
|
|
43
44
|
const [rawAction, ...rest] = argv;
|
|
44
45
|
const action = rawAction;
|
|
45
46
|
if (action !== 'list' && action !== 'info'
|
|
46
|
-
&& action !== 'refresh' && action !== 'blocked') {
|
|
47
|
-
throw new DirectoryQueryError('INVALID_ACTION', 'directory requires one of: list, info, refresh, blocked');
|
|
47
|
+
&& action !== 'refresh' && action !== 'blocked' && action !== 'block' && action !== 'unblock') {
|
|
48
|
+
throw new DirectoryQueryError('INVALID_ACTION', 'directory requires one of: list, info, refresh, blocked, block, unblock');
|
|
48
49
|
}
|
|
49
50
|
const selfAid = takeFlag(rest, '--self') ?? process.env.EVOLCORE_SELF_AID?.trim();
|
|
50
51
|
if (!selfAid)
|
|
@@ -57,6 +58,12 @@ export function resolveDirectoryQueryCommand(argv) {
|
|
|
57
58
|
const page = parsePage(takeFlag(rest, '--page'));
|
|
58
59
|
const ownerAid = parseOwnerFilter(takeFlag(rest, '--owner'));
|
|
59
60
|
const positional = takePositional(rest);
|
|
61
|
+
if (action === 'block' || action === 'unblock') {
|
|
62
|
+
if (positional.length !== 1 || !isValidAid(positional[0])) {
|
|
63
|
+
throw new DirectoryQueryError('INVALID_ARGUMENT', action + ' requires one valid target AID');
|
|
64
|
+
}
|
|
65
|
+
return { action, selfAid, target: positional[0] };
|
|
66
|
+
}
|
|
60
67
|
if (action === 'info') {
|
|
61
68
|
const target = positional.join(' ').trim();
|
|
62
69
|
if (!target)
|
|
@@ -100,13 +107,32 @@ export function resolveDirectoryQueryCommand(argv) {
|
|
|
100
107
|
* 快照优先取 channel 正在用的实例(能共享模块级单飞);拿不到时构造一个只读实例,
|
|
101
108
|
* 读本地文件即可——查询不需要网络,除非关键词未命中要触发同步。
|
|
102
109
|
*/
|
|
103
|
-
export async function executeDirectoryQueryCommand(command) {
|
|
110
|
+
export async function executeDirectoryQueryCommand(command, actorId = 'local-cli') {
|
|
104
111
|
const directory = path.join(agentDir(command.selfAid), 'directory');
|
|
105
112
|
if (!fs.existsSync(agentDir(command.selfAid))) {
|
|
106
113
|
return { ok: false, code: 'AGENT_NOT_FOUND', error: `agent ${command.selfAid} does not exist` };
|
|
107
114
|
}
|
|
115
|
+
if (command.action === 'block' || command.action === 'unblock') {
|
|
116
|
+
try {
|
|
117
|
+
const result = await mutatePeerBook({
|
|
118
|
+
selfAid: command.selfAid, actor: actorId,
|
|
119
|
+
mutation: { type: 'set-status', primaryId: command.target,
|
|
120
|
+
status: command.action === 'block' ? 'blocked' : 'active' },
|
|
121
|
+
});
|
|
122
|
+
return { ok: true, action: command.action, selfAid: command.selfAid, targetAid: command.target,
|
|
123
|
+
blocked: command.action === 'block', changed: result.changed };
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
return { ok: false, code: error.code ?? 'BLACKLIST_WRITE_FAILED',
|
|
127
|
+
error: error instanceof Error ? error.message : String(error) };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
108
130
|
// ownerAid 取自快照信封:快照自证归属,离线也能用。解析器只在没有快照时兜底。
|
|
109
131
|
const ownerAid = snapshotOwnerAid(directory, command.selfAid) ?? ownerResolver.owner(command.selfAid);
|
|
132
|
+
if (!ownerAid && command.action === 'blocked') {
|
|
133
|
+
return { ok: true, action: 'blocked', entries: [...getPeerSnapshot(command.selfAid).blockedIndex]
|
|
134
|
+
.sort().map(aid => ({ aid, source: 'local', contactable: false })) };
|
|
135
|
+
}
|
|
110
136
|
if (!ownerAid) {
|
|
111
137
|
return { ok: false, code: 'NOT_AUTHORIZED', error: 'directory is not available for this agent' };
|
|
112
138
|
}
|
|
@@ -2,9 +2,17 @@
|
|
|
2
2
|
* 本地备注:`$AGENT_DIR/directory/remarks/<aid>.md`。
|
|
3
3
|
*
|
|
4
4
|
* 备注描述的是"这个 agent 自己怎么看这个人",和 Owner 侧发布的远端条目不是
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* 一回事,所以存在本地、由 Agent 自己用文件工具直接读写,引擎只读。
|
|
6
|
+
*
|
|
7
|
+
* **没有对应命令**:备注只落在写者自己的 agent 目录里,没有跨目录写入的需求,
|
|
8
|
+
* 包一层 CLI + daemon IPC 只是把"写一个文件"变复杂。原先的
|
|
9
|
+
* `ec directory remark get|set|rm` 已在 `7a2f5032` 下线,改完 `ec directory
|
|
10
|
+
* refresh` 即重算注入。
|
|
11
|
+
*
|
|
12
|
+
* 渲染目录时按 AID 覆盖远端的 `description`(正文)和 `remark`(frontmatter)。
|
|
13
|
+
*
|
|
14
|
+
* 文件位置:`$AGENT_DIR/directory/remarks/<aid>.md`(`$EVOLCORE_HOME/agents/<自己的 AID>/directory/remarks/`)。
|
|
15
|
+
* 文件名必须与 frontmatter 的 `aid` 一致,否则整条作废——防止备注挂到别人头上。
|
|
8
16
|
*
|
|
9
17
|
* 文件格式:
|
|
10
18
|
*
|