evolcore 0.0.43-test.6 → 0.0.43-test.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +95 -0
- package/bin/ecmsg.js +188 -58
- package/dist/agent-template/jobs.js +62 -0
- package/dist/agent-template/runtime.js +214 -0
- package/dist/agent-template/service.js +465 -0
- package/dist/agent-template/tool-runner.js +45 -0
- package/dist/agent-template/types.js +5 -0
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/claude-runner.js +1 -1
- package/dist/agents/codex/app-server-client.js +22 -0
- package/dist/agents/codex-runner.js +69 -2
- package/dist/aun/aid/agentmd.js +56 -1
- package/dist/aun/aid/client.js +3 -1
- package/dist/aun/menu/client.js +3 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/channels/aun.js +277 -49
- package/dist/cli/agent-command.js +5 -0
- package/dist/cli/agent-create.js +7 -3
- package/dist/cli/agent-template.js +124 -0
- package/dist/cli/aun-commands.js +2 -2
- package/dist/cli/ctl-command.js +2 -1
- package/dist/cli/daemon-commands.js +11 -66
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +35 -2
- package/dist/cli/events-command.js +109 -0
- package/dist/cli/index.js +60 -14
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/net-check.js +1 -1
- package/dist/cli/restart-monitor.js +160 -83
- package/dist/cli/services-command.js +137 -0
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +103 -13
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/boot-log.js +8 -8
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +0 -7
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/schema-migration.js +45 -15
- package/dist/config-store.js +2 -1
- package/dist/core/agent-ipc-registration.js +25 -4
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +106 -10
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-authorizer.js +2 -0
- package/dist/core/auth/operation-catalog.js +29 -0
- package/dist/core/baseagent-loader.js +60 -130
- package/dist/core/channel-loader.js +10 -1
- package/dist/core/channel-runtime.js +20 -12
- package/dist/core/command/agent-control.js +12 -2
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/agent-template-menu.js +147 -0
- package/dist/core/command/chatmode-config.js +2 -36
- package/dist/core/command/command-handler.js +80 -17
- package/dist/core/command/data-root-resolver.js +32 -23
- package/dist/core/command/eventcenter-menu.js +468 -0
- package/dist/core/command/menu-catalog.js +15 -0
- package/dist/core/command/menu-handler.js +216 -90
- package/dist/core/command/menu-protocol.js +71 -13
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/slash-gate.js +1 -1
- package/dist/core/command/slash-handler.js +34 -42
- package/dist/core/command/team-workspace-bootstrap.js +350 -0
- package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
- package/dist/core/command/team-workspace-initializer.js +2 -0
- package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
- package/dist/core/command/team-workspace-job-store.js +88 -0
- package/dist/core/command/team-workspace-management-service.js +2 -0
- package/dist/core/command/team-workspace-management-store.js +96 -0
- package/dist/core/command/team-workspace-management.js +265 -0
- package/dist/core/command/team-workspace-members-menu.js +88 -0
- package/dist/core/command/team-workspace-store.js +612 -0
- package/dist/core/command/team-workspace-team.js +193 -0
- package/dist/core/daemon-control.js +22 -5
- package/dist/core/daemon-lifecycle.js +323 -191
- package/dist/core/handoff/runtime.js +45 -13
- package/dist/core/invoke/executors/index.js +13 -0
- package/dist/core/invoke/executors/media.js +283 -0
- package/dist/core/invoke/executors/text.js +198 -0
- package/dist/core/invoke/invoke-service.js +157 -0
- package/dist/core/invoke/style-router.js +48 -0
- package/dist/core/invoke/types.js +19 -0
- package/dist/core/ipc-registration.js +50 -7
- package/dist/core/legacy-rename.js +41 -0
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +252 -17
- package/dist/core/message/im-renderer.js +116 -85
- package/dist/core/message/message-bridge.js +4 -0
- package/dist/core/message/message-queue.js +66 -15
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/pending-hints.js +29 -5
- package/dist/core/message/response-engine.js +194 -61
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +50 -5
- package/dist/core/ownership/owner-resolver.js +7 -0
- package/dist/core/pack-auth.js +94 -0
- package/dist/core/pack-install.js +194 -0
- package/dist/core/permission/ec-command-parser.js +51 -17
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/rate-window.js +48 -0
- package/dist/core/relation/peer-identity.js +28 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +67 -28
- package/dist/core/session/session-idle-monitor.js +59 -19
- package/dist/core/session/session-manager.js +13 -4
- package/dist/core/task/task-recovery-service.js +13 -2
- package/dist/core/thread/command-parser.js +9 -2
- package/dist/core/thread/thread-operation.js +21 -2
- package/dist/core/thread/thread-route.js +13 -2
- package/dist/core/thread/thread-service.js +52 -3
- package/dist/directory/owner-directory-admission.js +40 -53
- package/dist/directory/owner-directory-cache.js +89 -113
- package/dist/directory/owner-directory-query-operation.js +8 -10
- package/dist/eck/kit-renderer.js +7 -5
- package/dist/eck/message-renderer.js +2 -0
- package/dist/ecweb/basic-settings-service.js +1 -1
- package/dist/ecweb/message-context-service.js +0 -4
- package/dist/ecweb/runtime/lifecycle.js +6 -2
- package/dist/ecweb/runtime/supervisor.js +19 -4
- package/dist/event-center/admission-materializer.js +124 -0
- package/dist/event-center/bus-gate.js +154 -0
- package/dist/event-center/bus-host.js +307 -0
- package/dist/event-center/bus-resolver.js +120 -0
- package/dist/event-center/center-config.js +127 -0
- package/dist/event-center/daemon.js +44 -0
- package/dist/event-center/directory-source.js +55 -0
- package/dist/event-center/dispatcher.js +157 -0
- package/dist/event-center/event-log.js +110 -0
- package/dist/event-center/index-generator.js +73 -0
- package/dist/event-center/ipc-operation.js +423 -0
- package/dist/event-center/ledger.js +52 -0
- package/dist/event-center/pack-loader.js +207 -0
- package/dist/event-center/pack-manager.js +85 -0
- package/dist/event-center/registry.js +463 -0
- package/dist/event-center/runtime.js +837 -0
- package/dist/event-center/script-runner.js +356 -0
- package/dist/event-center/types.js +51 -0
- package/dist/event-center/validation.js +435 -0
- package/dist/index.js +424 -135
- package/dist/ipc.js +106 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +5 -1
- package/dist/proxy/service-supervisor.js +13 -4
- package/dist/response-system/engines/v1/index.js +0 -1
- package/dist/response-system/engines/v1/proactive-flow.js +4 -2
- package/dist/response-system/modes/single-session/index.js +1 -1
- package/dist/services/dispatcher.js +100 -0
- package/dist/services/idempotency.js +90 -0
- package/dist/services/identity.js +52 -0
- package/dist/services/index-generator.js +70 -0
- package/dist/services/index.js +449 -0
- package/dist/services/ipc-operation.js +550 -0
- package/dist/services/ledger.js +52 -0
- package/dist/services/message-log.js +112 -0
- package/dist/services/pack-manager.js +215 -0
- package/dist/services/reply.js +55 -0
- package/dist/services/router.js +98 -0
- package/dist/services/script-runner.js +422 -0
- package/dist/services/service-payload.js +70 -0
- package/dist/services/types.js +18 -0
- package/dist/services/validation.js +297 -0
- package/dist/trigger/application-service.js +18 -0
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/scheduler.js +38 -0
- package/dist/trigger/script-sandbox.js +170 -24
- package/dist/utils/cross-platform.js +24 -10
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +6 -3
- package/dist/utils/process-introspect.js +45 -9
- package/dist/utils/startup-trace.js +74 -37
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +9 -15
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +3 -1
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/agent.md +22 -1
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/event-center.md +227 -0
- package/kits/docs/evolcore/file-navigation.md +10 -264
- package/kits/docs/evolcore/fs.md +5 -3
- package/kits/docs/evolcore/group.md +1 -1
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-protocol.md +28 -1
- package/kits/docs/evolcore/msg.md +21 -9
- package/kits/docs/evolcore/provider.md +3 -1
- package/kits/docs/evolcore/response.md +5 -5
- package/kits/docs/evolcore/services.md +294 -0
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +41 -0
- package/kits/docs/evolcore/thread-chain.md +15 -3
- package/kits/eck_manifest.json +26 -0
- package/kits/rules/02-navigation.md +10 -1
- package/kits/rules/06-channel.md +1 -0
- package/kits/schemas/_meta.json +17 -6
- package/kits/schemas/agent-config.schema.19.json +5 -7
- package/kits/schemas/agent-config.schema.20.json +936 -0
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/skills/.switches.json +1 -5
- package/kits/skills/ability/SKILL.md +56 -0
- package/kits/skills/ability/references/calling.md +56 -0
- package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
- package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
- package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
- package/kits/skills/ec-agent-create/SKILL.md +0 -1
- package/kits/skills/ec-group/SKILL.md +5 -8
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-service-proxy/SKILL.md +34 -5
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/personal-assistant/SKILL.md +6 -6
- package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
- package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
- package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
- package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/message-fragments/item.md +1 -1
- package/kits/templates/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/reply.md +1 -5
- package/kits/templates/system-fragments/thread.md +13 -10
- package/package.json +5 -6
- package/scripts/agent-template/index.mjs +40 -0
- package/scripts/agent-template/inspect.mjs +240 -0
- package/scripts/agent-template/overlay.mjs +71 -0
- package/scripts/agent-template/pack.mjs +169 -0
- package/scripts/agent-template/shared/common.mjs +235 -0
- package/scripts/agent-template/shared/evolcore.mjs +75 -0
- package/scripts/agent-template/shared/plan.mjs +129 -0
- package/scripts/agent-template/shared/team-schema.json +70 -0
- package/scripts/agent-template/shared/template-contract.mjs +154 -0
- package/scripts/agent-template/shared/template-package.mjs +265 -0
- package/scripts/agent-template/shared/template-runtime.mjs +80 -0
- package/scripts/agent-template/shared/template.mjs +142 -0
- package/dist/cli/pa-workspace-command.js +0 -225
- package/dist/core/command/pa-workspace-store.js +0 -468
- package/dist/core/relation/pa-team.js +0 -132
- package/kits/docs/evolcore/pa-workspace.md +0 -51
- package/kits/skills/aid-ability/SKILL.md +0 -244
- package/kits/skills/ec-ability/SKILL.md +0 -67
- package/kits/skills/ec-ability/references/workflows.md +0 -15
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import { logger } from '../../utils/logger.js';
|
|
2
|
+
import { readAunPeerKind } from '../relation/peer-identity.js';
|
|
2
3
|
import { ThreadService, normalizeThreadPeer } from './thread-service.js';
|
|
3
4
|
import { isMainSessionThreadId, isTopicThreadId, safeFormatMainTopicId } from './topic-id.js';
|
|
5
|
+
/**
|
|
6
|
+
* 建话题时对端类型的默认来源:本地关系证据(agent.md 缓存 / 关系配置)。
|
|
7
|
+
* 证据不可用时不阻塞建话题,按私聊兜底——与发送路径的判定口径一致。
|
|
8
|
+
*/
|
|
9
|
+
function inferThreadPeerKind(selfAid, peer) {
|
|
10
|
+
try {
|
|
11
|
+
const kind = readAunPeerKind(selfAid, peer).kind;
|
|
12
|
+
if (kind === 'group' || kind === 'private')
|
|
13
|
+
return kind;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
// 关系证据读取失败不算错误。
|
|
17
|
+
}
|
|
18
|
+
return 'private';
|
|
19
|
+
}
|
|
4
20
|
/**
|
|
5
21
|
* Emit the existing cross-device rename event after a local rename succeeds.
|
|
6
22
|
* Storage stays in ThreadService; transport stays in the operation layer.
|
|
@@ -140,10 +156,13 @@ async function _executeThreadOperation(request, threadService, sendSystemMsg) {
|
|
|
140
156
|
case 'create': {
|
|
141
157
|
if (!request.peer || !request.name)
|
|
142
158
|
return { ok: false, code: 'MISSING_ARGS', error: 'peer and name required' };
|
|
159
|
+
// 没显式写 --group / --private 时按关系证据推断:群话题被记成 private
|
|
160
|
+
// 会让后续 scope 选择、群规则、通知范围全部走错。
|
|
161
|
+
const peerKind = request.peerKind ?? inferThreadPeerKind(selfAid, request.peer);
|
|
143
162
|
const result = await threadService.createThread({
|
|
144
163
|
selfAid,
|
|
145
164
|
peer: request.peer,
|
|
146
|
-
peerKind
|
|
165
|
+
peerKind,
|
|
147
166
|
name: request.name,
|
|
148
167
|
label: request.label ?? undefined,
|
|
149
168
|
topicStatus: request.topicStatus,
|
|
@@ -155,7 +174,7 @@ async function _executeThreadOperation(request, threadService, sendSystemMsg) {
|
|
|
155
174
|
to: request.peer,
|
|
156
175
|
threadId: result.threadId,
|
|
157
176
|
topicName: result.name,
|
|
158
|
-
peerKind
|
|
177
|
+
peerKind,
|
|
159
178
|
// 与 rename 相同:授权链需要托管上下文,宿主调用则留空(跳过通知)。
|
|
160
179
|
originSessionId: request.originSessionId,
|
|
161
180
|
delegationToken: request.delegationToken,
|
|
@@ -11,11 +11,19 @@ import { isMainSessionThreadId, resolveThreadRef } from './topic-id.js';
|
|
|
11
11
|
*
|
|
12
12
|
* 话题必须存在于本端:话题查索引,主话题查该关系的 active session。
|
|
13
13
|
* 返回 undefined 表示该引用不能作为跨话题路由依据。
|
|
14
|
+
*
|
|
15
|
+
* `options.allowSelfTarget`(self-address):`target` 是本端自己的 AID 时,
|
|
16
|
+
* 它不是「话题对端」而是「收件人」,与 `entry.peer` 天然不一致。此时跳过
|
|
17
|
+
* 一致性校验,仍按引用返回话题条目——话题归属不变,变的只是投给谁。
|
|
14
18
|
*/
|
|
15
|
-
export function resolveThreadRouteTarget(selfAid, threadRef, scope, target) {
|
|
19
|
+
export function resolveThreadRouteTarget(selfAid, threadRef, scope, target, options = {}) {
|
|
16
20
|
if (!selfAid)
|
|
17
21
|
return undefined;
|
|
18
22
|
const normalizedSelf = selfAid.replace(/^@/, '');
|
|
23
|
+
// 跨话题自派:收件人是本端,不能拿它和话题对端比。
|
|
24
|
+
const selfTargeted = options.allowSelfTarget === true
|
|
25
|
+
&& target !== undefined
|
|
26
|
+
&& target.replace(/^@/, '').toLowerCase() === normalizedSelf.toLowerCase();
|
|
19
27
|
const resolved = resolveThreadRef(threadRef, normalizedSelf);
|
|
20
28
|
if (resolved.kind === 'invalid' || resolved.kind === 'current')
|
|
21
29
|
return undefined;
|
|
@@ -26,7 +34,7 @@ export function resolveThreadRouteTarget(selfAid, threadRef, scope, target) {
|
|
|
26
34
|
const effectiveTarget = peerFromRef ?? target;
|
|
27
35
|
if (!effectiveTarget)
|
|
28
36
|
return undefined;
|
|
29
|
-
if (target !== undefined && peerFromRef !== undefined) {
|
|
37
|
+
if (target !== undefined && peerFromRef !== undefined && !selfTargeted) {
|
|
30
38
|
const normalizedTarget = target.replace(/^@/, '');
|
|
31
39
|
const matches = scope === 'group'
|
|
32
40
|
? sameGroupAid(peerFromRef, normalizedTarget)
|
|
@@ -76,6 +84,9 @@ export function resolveThreadRouteTarget(selfAid, threadRef, scope, target) {
|
|
|
76
84
|
}
|
|
77
85
|
if (target === undefined)
|
|
78
86
|
return entry;
|
|
87
|
+
// 跨话题自派:收件人是本端,话题归属仍由 entry.peer 决定,不做一致性校验。
|
|
88
|
+
if (selfTargeted)
|
|
89
|
+
return entry;
|
|
79
90
|
const normalizedTarget = target.replace(/^@/, '');
|
|
80
91
|
const matches = scope === 'group'
|
|
81
92
|
? sameGroupAid(entry.peer, normalizedTarget)
|
|
@@ -143,6 +143,29 @@ export class ThreadService {
|
|
|
143
143
|
readThreadIndex(selfAid) {
|
|
144
144
|
return readIndex(agentThreadIndexPath(selfAid));
|
|
145
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* 读索引并带上文件状态。`readIndex` 会把缺失/损坏都折成空集,
|
|
148
|
+
* 列表命令因此无法区分「没记录」和「索引坏了」——这里保留状态用于诊断。
|
|
149
|
+
*/
|
|
150
|
+
readThreadIndexWithState(selfAid) {
|
|
151
|
+
const indexPath = agentThreadIndexPath(selfAid);
|
|
152
|
+
const legacyPath = path.join(path.dirname(path.dirname(indexPath)), 'thread-index.json');
|
|
153
|
+
const existing = fs.existsSync(indexPath)
|
|
154
|
+
? indexPath
|
|
155
|
+
: (legacyPath !== indexPath && fs.existsSync(legacyPath) ? legacyPath : undefined);
|
|
156
|
+
if (!existing)
|
|
157
|
+
return { index: { version: 1, threads: [] }, state: 'missing' };
|
|
158
|
+
try {
|
|
159
|
+
const raw = atomicReadJson(existing);
|
|
160
|
+
if (!raw || !Array.isArray(raw.threads)) {
|
|
161
|
+
return { index: { version: 1, threads: [] }, state: 'corrupt' };
|
|
162
|
+
}
|
|
163
|
+
return { index: readIndex(indexPath), state: 'ok' };
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return { index: { version: 1, threads: [] }, state: 'corrupt' };
|
|
167
|
+
}
|
|
168
|
+
}
|
|
146
169
|
writeThreadIndex(selfAid, index) {
|
|
147
170
|
const indexPath = agentThreadIndexPath(selfAid);
|
|
148
171
|
fs.mkdirSync(path.dirname(indexPath), { recursive: true });
|
|
@@ -538,7 +561,12 @@ export class ThreadService {
|
|
|
538
561
|
const { selfAid, status, label, unlabeled, sort, page = 1, limit: rawLimit } = input;
|
|
539
562
|
const peer = normalizeThreadPeer(input.peer);
|
|
540
563
|
const limit = Math.min(rawLimit ?? LIST_DEFAULT_LIMIT, LIST_MAX_LIMIT);
|
|
541
|
-
const index = this.
|
|
564
|
+
const { index, state: indexState } = this.readThreadIndexWithState(selfAid);
|
|
565
|
+
// 未套过滤条件的话题数:用于把「该对端确实没有话题」与
|
|
566
|
+
// 「有话题但被 --status/--label 挡掉」区分开。
|
|
567
|
+
const peerTopicCount = peer
|
|
568
|
+
? index.threads.filter(t => normalizeThreadPeer(t.peer) === peer).length
|
|
569
|
+
: index.threads.length;
|
|
542
570
|
let threads = index.threads.filter(t => {
|
|
543
571
|
if (peer && normalizeThreadPeer(t.peer) !== peer)
|
|
544
572
|
return false;
|
|
@@ -553,8 +581,10 @@ export class ThreadService {
|
|
|
553
581
|
// 主话题由会话文件产生、从不进话题索引。只列话题会让「和某对端聊过什么」
|
|
554
582
|
// 在列表里看不到主线,而 `history <peer>` 不传话题读的恰恰是主话题消息。
|
|
555
583
|
// 指定对端时补一条合成记录,让 list 与 history 的口径一致。
|
|
584
|
+
let hasMainChat = false;
|
|
556
585
|
if (peer) {
|
|
557
586
|
const hasMain = threads.some(t => isMainSessionThreadId(t.threadId));
|
|
587
|
+
hasMainChat = hasMain;
|
|
558
588
|
if (!hasMain) {
|
|
559
589
|
const chatDir = this.chatDirFor(selfAid, peer);
|
|
560
590
|
const logPath = path.join(chatDir, 'messages.jsonl');
|
|
@@ -568,6 +598,7 @@ export class ThreadService {
|
|
|
568
598
|
}
|
|
569
599
|
catch { /* skip corrupt file */ }
|
|
570
600
|
}
|
|
601
|
+
hasMainChat = lastTs > 0;
|
|
571
602
|
// 群标识与私聊 AID 语法相同,只能靠会话记录里的 chatType 判定;
|
|
572
603
|
// 没有会话文件时退回私聊(`ec thread list <peer>` 的常见用法)。
|
|
573
604
|
const active = this.sessionManager.getActiveSessionSync('aun', peer, 'aun', selfAid);
|
|
@@ -676,7 +707,20 @@ export class ThreadService {
|
|
|
676
707
|
};
|
|
677
708
|
});
|
|
678
709
|
const totalMsgCount = threads.reduce((sum, t) => sum + (t.msgTotal ?? 0), 0);
|
|
679
|
-
|
|
710
|
+
// 对端是否有任何往来证据:索引里的独立话题、主话题消息、聊天目录或活跃会话。
|
|
711
|
+
// 只看索引会把「索引丢了但聊天记录还在」误报成对端不存在。
|
|
712
|
+
const peerKnown = peer
|
|
713
|
+
? peerTopicCount > 0
|
|
714
|
+
|| hasMainChat
|
|
715
|
+
|| fs.existsSync(this.chatDirFor(selfAid, peer))
|
|
716
|
+
|| !!this.sessionManager.getActiveSessionSync('aun', peer, 'aun', selfAid)
|
|
717
|
+
: index.threads.length > 0;
|
|
718
|
+
return {
|
|
719
|
+
threads, total, page, limit,
|
|
720
|
+
hasMore: offset + threads.length < total,
|
|
721
|
+
totalMsgCount, peer, selfAid, sort, status, label, unlabeled,
|
|
722
|
+
peerKnown, peerTopicCount, hasMainChat, indexState,
|
|
723
|
+
};
|
|
680
724
|
}
|
|
681
725
|
// ── show ──
|
|
682
726
|
async showThread(input) {
|
|
@@ -793,11 +837,16 @@ export class ThreadService {
|
|
|
793
837
|
continue;
|
|
794
838
|
// 渠道类型从目录名(channelSessionKey)解析,避免把 daemon 会话记成 aun。
|
|
795
839
|
const parsedDir = tryParseChannelSessionKey(dirEntry.name);
|
|
840
|
+
const channelType = parsedDir?.channelType ?? 'aun';
|
|
841
|
+
// daemon 内部会话(记忆整理 `bg:`、trigger 会话 `trigger:`)是伪话题,
|
|
842
|
+
// 不属于话题体系,重建时跳过,否则它们会被一直写回索引。
|
|
843
|
+
if (channelType === 'daemon' || !String(last.threadId).startsWith('thread-'))
|
|
844
|
+
continue;
|
|
796
845
|
entries.push({
|
|
797
846
|
threadId: last.threadId,
|
|
798
847
|
sessionId,
|
|
799
848
|
peer: last.channelId ?? '',
|
|
800
|
-
channelType
|
|
849
|
+
channelType,
|
|
801
850
|
peerKind: last.chatType === 'group' ? 'group' : 'private',
|
|
802
851
|
name: last.name ?? last.threadId,
|
|
803
852
|
...(typeof last.metadata?.nameUpdatedAt === 'number'
|
|
@@ -42,11 +42,10 @@ export function liveOwnerDirectoryCache(selfAid) {
|
|
|
42
42
|
* 时按 AID 临时读一次本地快照重新渲染,产出同样的字节。后者多一次读盘,
|
|
43
43
|
* 但保证"配置一改,注入就变",不必等到下一条入站消息。
|
|
44
44
|
*
|
|
45
|
-
* **ownerAid
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* 授权文件缺失时直接返回 false:没有授权就没有可渲染的内容,也不该动现有文件。
|
|
45
|
+
* **ownerAid 取自本地快照信封,不用 `ownerResolver` 猜。** 离线时解析器只能给出
|
|
46
|
+
* known owner(可能来自过期缓存或另一条关系),一旦与快照里的 owner 对不上,
|
|
47
|
+
* `directoryGone()` 会判真,`refreshMarkdown` 会把 `directory.md` 删掉——一个只读的
|
|
48
|
+
* 开关变更变成删注入源。快照不存在时直接返回 false:没有可渲染的内容,也不该动现有文件。
|
|
50
49
|
*/
|
|
51
50
|
export function refreshDirectoryMarkdown(selfAid) {
|
|
52
51
|
const live = liveOwnerDirectoryCache(selfAid);
|
|
@@ -55,7 +54,7 @@ export function refreshDirectoryMarkdown(selfAid) {
|
|
|
55
54
|
return true;
|
|
56
55
|
}
|
|
57
56
|
const directory = path.join(agentDir(selfAid), 'directory');
|
|
58
|
-
const ownerAid =
|
|
57
|
+
const ownerAid = snapshotOwnerAid(directory, selfAid);
|
|
59
58
|
if (!ownerAid)
|
|
60
59
|
return false;
|
|
61
60
|
try {
|
|
@@ -68,29 +67,12 @@ export function refreshDirectoryMarkdown(selfAid) {
|
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
/**
|
|
71
|
-
*
|
|
70
|
+
* 从本地快照信封(`contacts.json`)里读出这份名录属于哪个 Owner。
|
|
72
71
|
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
72
|
+
* 这是 ownerAid 的**唯一来源**:`authorization.json` 已废弃,不再读取。
|
|
73
|
+
* 快照自带 `ownerAid` 与 `granteeAid`,能自证归属,不需要外部凭证佐证。
|
|
75
74
|
*/
|
|
76
|
-
export function
|
|
77
|
-
try {
|
|
78
|
-
const raw = JSON.parse(fs.readFileSync(path.join(directory, 'authorization.json'), 'utf8'));
|
|
79
|
-
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
80
|
-
return undefined;
|
|
81
|
-
const record = raw;
|
|
82
|
-
if (record.granteeAid !== selfAid)
|
|
83
|
-
return undefined;
|
|
84
|
-
const ownerAid = typeof record.ownerAid === 'string' ? record.ownerAid.trim() : '';
|
|
85
|
-
return ownerAid || undefined;
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
// 没有授权文件时退到本地快照信封:预置团队只带 contacts.json,不拉远端。
|
|
89
|
-
return snapshotOwnerAid(directory, selfAid);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
/** 从 agent 本地快照信封(`contacts.json`)里读出 ownerAid。 */
|
|
93
|
-
function snapshotOwnerAid(directory, selfAid) {
|
|
75
|
+
export function snapshotOwnerAid(directory, selfAid) {
|
|
94
76
|
try {
|
|
95
77
|
const raw = JSON.parse(fs.readFileSync(path.join(directory, 'contacts.json'), 'utf8'));
|
|
96
78
|
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
@@ -118,8 +100,6 @@ export async function refreshOwnerDirectory(selfAid) {
|
|
|
118
100
|
const live = liveOwnerDirectoryCache(selfAid);
|
|
119
101
|
const scope = OWNER_DIRECTORY_SCOPES[0];
|
|
120
102
|
if (live) {
|
|
121
|
-
if (live.scopeAccess(scope) !== 'authorized')
|
|
122
|
-
return { pulled: false, regenerated: false };
|
|
123
103
|
let timer;
|
|
124
104
|
try {
|
|
125
105
|
// 空 digests = 无条件拉取,不做摘要比对。
|
|
@@ -152,8 +132,6 @@ export async function syncOwnerDirectoryForLookup(selfAid) {
|
|
|
152
132
|
if (!cache)
|
|
153
133
|
return false;
|
|
154
134
|
const scope = OWNER_DIRECTORY_SCOPES[0];
|
|
155
|
-
if (cache.scopeAccess(scope) !== 'authorized')
|
|
156
|
-
return false;
|
|
157
135
|
const before = cache.readSnapshot(scope)?.contentDigest;
|
|
158
136
|
// 把 pending 里带的通知 digest 一起传下去:与共享缓存一致时 0 次网络请求。
|
|
159
137
|
// 未命中的场景恰恰常发生在"通知刚到、共享缓存已拉过",不传等于白拉一次。
|
|
@@ -183,9 +161,16 @@ export async function prepareOwnerDirectoryAdmission(selfAid, aid) {
|
|
|
183
161
|
if (ownerResolver.owner(selfAid) !== live.ownerAid)
|
|
184
162
|
return;
|
|
185
163
|
const scope = OWNER_DIRECTORY_SCOPES[0];
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
164
|
+
// 坏快照解析会抛:这里只是准入前的预热,读不出来就当未命中,交给准入路径自己判。
|
|
165
|
+
const snapshotEntries = (() => {
|
|
166
|
+
try {
|
|
167
|
+
return live.cache.readSnapshot(scope)?.entries;
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
})();
|
|
173
|
+
const found = snapshotEntries?.some(entry => entry.aid === aid) ?? false;
|
|
189
174
|
if (found) {
|
|
190
175
|
// 已知成员:只允许一次后台刷新,不阻塞本条消息的处理。
|
|
191
176
|
void live.cache.lookupByAid(scope, aid).catch(() => { });
|
|
@@ -226,36 +211,38 @@ export function readOwnerDirectoryMembership(selfAid, aid, appOwned = false) {
|
|
|
226
211
|
const directory = path.join(agentDir(selfAid), 'directory');
|
|
227
212
|
// "从未接入名录"与"接入过但当前不可用"是两种结论,判据是盘上有没有痕迹。
|
|
228
213
|
// 原子写的热备名(`*.json_`)由 existsAtomic 负责,业务层不关心后缀。
|
|
229
|
-
const configured = existsAtomic(path.join(directory, '
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
214
|
+
const configured = existsAtomic(path.join(directory, 'contacts.json'));
|
|
215
|
+
if (!configured) {
|
|
216
|
+
// 没有名录文件:普通消息准入保持旧行为(交给调用方的开关/白名单判断);
|
|
217
|
+
// App 侧一律按目录不可用处理,不因"没数据"放宽。
|
|
218
|
+
if (!appOwned)
|
|
219
|
+
return undefined;
|
|
220
|
+
logDirectoryAdmissionUnavailable(selfAid, aid, 'snapshot_missing');
|
|
221
|
+
return { category: 'unavailable' };
|
|
222
|
+
}
|
|
223
|
+
// ownerAid 优先取快照信封:它自证归属,离线也能用。解析器只在没有快照时兜底。
|
|
224
|
+
const snapshotOwner = snapshotOwnerAid(directory, selfAid);
|
|
225
|
+
const resolvedOwner = ownerResolver.owner(selfAid);
|
|
226
|
+
// 协议 Owner 已解析、却与快照归属不同:名录是上一个 Owner 的,不能拿做过期准入。
|
|
227
|
+
// 解析不出来(离线、共识过期)不算冲突——那一侧交给快照信封自证。
|
|
228
|
+
if (snapshotOwner && resolvedOwner && snapshotOwner !== resolvedOwner) {
|
|
229
|
+
logDirectoryAdmissionUnavailable(selfAid, aid, 'owner_mismatch', resolvedOwner);
|
|
230
|
+
return { category: 'unavailable' };
|
|
231
|
+
}
|
|
232
|
+
const ownerAid = snapshotOwner ?? resolvedOwner;
|
|
234
233
|
if (!ownerAid) {
|
|
235
234
|
logDirectoryAdmissionUnavailable(selfAid, aid, 'owner_unresolved');
|
|
236
235
|
return { category: 'unavailable' };
|
|
237
236
|
}
|
|
238
237
|
try {
|
|
238
|
+
const scope = OWNER_DIRECTORY_SCOPES[0];
|
|
239
239
|
const relationVersion = appOwned ? ownerResolver.snapshot(selfAid).consensus?.relation_version : undefined;
|
|
240
240
|
if (appOwned && (!Number.isSafeInteger(relationVersion) || (relationVersion ?? 0) <= 0))
|
|
241
241
|
return { category: 'unavailable' };
|
|
242
242
|
const cache = new OwnerDirectoryCache({ selfAid, ownerAid, directory, relationVersion });
|
|
243
|
-
|
|
244
|
-
const accessReason = cache.scopeAccessUnavailableReason(scope);
|
|
245
|
-
// 本地快照可以脱离授权文件单独使用:预置团队(构建期写入 contacts.json、从不拉取远端)
|
|
246
|
-
// 没有 authorization.json,只要快照本身可读,就按快照判定准入。
|
|
247
|
-
// 授权过期(authorization_expired)仍然拦截——那是远端明确撤下的结论,不能靠本地文件续命。
|
|
248
|
-
const localSnapshotOnly = accessReason === 'authorization_missing_or_invalid';
|
|
249
|
-
if (accessReason && !localSnapshotOnly) {
|
|
250
|
-
logDirectoryAdmissionUnavailable(selfAid, aid, accessReason, ownerAid);
|
|
251
|
-
return { category: 'unavailable' };
|
|
252
|
-
}
|
|
243
|
+
// 判据只有一条:快照文件在不在。授权凭证不参与任何判断。
|
|
253
244
|
const snapshot = cache.readSnapshot(scope);
|
|
254
245
|
if (!snapshot) {
|
|
255
|
-
if (localSnapshotOnly) {
|
|
256
|
-
logDirectoryAdmissionUnavailable(selfAid, aid, accessReason, ownerAid);
|
|
257
|
-
return { category: 'unavailable' };
|
|
258
|
-
}
|
|
259
246
|
logDirectoryAdmissionUnavailable(selfAid, aid, existsAtomic(path.join(directory, `${scope}.json`)) ? 'snapshot_invalid' : 'snapshot_missing', ownerAid);
|
|
260
247
|
return { category: 'unavailable' };
|
|
261
248
|
}
|