evolcore 0.0.43-test.5 → 0.0.43-test.7
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 +281 -81
- package/dist/agents/baseagent-availability.js +20 -5
- package/dist/agents/baseagent.js +2 -2
- package/dist/agents/claude-runner.js +19 -4
- package/dist/agents/codex/app-server-client.js +36 -3
- package/dist/agents/codex-runner.js +75 -8
- package/dist/aun/group/invite-service.js +3 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/aun/service-proxy.js +18 -6
- package/dist/channels/aun.js +306 -30
- package/dist/cli/agent-create.js +18 -8
- package/dist/cli/aun-commands.js +9 -1
- package/dist/cli/daemon-commands.js +34 -65
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +38 -3
- package/dist/cli/events-command.js +73 -0
- package/dist/cli/index.js +31 -14
- package/dist/cli/init.js +75 -0
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/provider-command.js +1 -1
- package/dist/cli/restart-monitor.js +67 -50
- package/dist/cli/services-command.js +111 -0
- package/dist/cli/task-context.js +38 -1
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +6 -2
- package/dist/cli/watch-logs.js +6 -4
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/boot-log.js +6 -4
- package/dist/config/builtin-roles.js +2 -2
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +1 -8
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/peer-role-resolver.js +1 -1
- package/dist/config/provider-identity-migration.js +92 -17
- package/dist/config/provider-local-sync.js +2 -0
- package/dist/config/providers-config.js +13 -0
- package/dist/config/providers-management.js +100 -10
- package/dist/config/role-service.js +8 -8
- package/dist/config/role-store.js +22 -22
- package/dist/config/schema-migration.js +86 -88
- package/dist/config/snapshot.js +70 -41
- package/dist/config-store.js +2 -1
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +146 -15
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-catalog.js +20 -0
- package/dist/core/baseagent-loader.js +75 -42
- package/dist/core/channel-loader.js +45 -13
- package/dist/core/channel-runtime.js +116 -45
- package/dist/core/command/agent-control.js +1 -1
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/chatmode-config.js +2 -36
- package/dist/core/command/command-handler.js +58 -16
- package/dist/core/command/data-root-resolver.js +32 -23
- package/dist/core/command/eventcenter-menu.js +338 -0
- package/dist/core/command/menu-catalog.js +8 -0
- package/dist/core/command/menu-handler.js +206 -87
- package/dist/core/command/menu-protocol.js +142 -22
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/role-menu.js +27 -15
- 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 +45 -15
- package/dist/core/daemon-lifecycle.js +478 -75
- package/dist/core/handoff/dispatcher.js +9 -3
- package/dist/core/handoff/runtime.js +130 -42
- package/dist/core/handoff/store.js +190 -2
- package/dist/core/handoff/types.js +5 -0
- package/dist/core/initialization/service.js +4 -4
- 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 +51 -11
- package/dist/core/lifecycle-notice.js +10 -4
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +149 -19
- package/dist/core/message/im-renderer.js +28 -84
- package/dist/core/message/message-bridge.js +57 -4
- package/dist/core/message/message-queue.js +46 -4
- 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 +4 -10
- package/dist/core/message/response-engine.js +163 -52
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +55 -7
- package/dist/core/ownership/owner-resolver.js +8 -0
- package/dist/core/permission/ec-command-parser.js +14 -3
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +24 -0
- package/dist/core/session/adapters/codex-session-file-adapter.js +80 -0
- package/dist/core/session/adapters/ecagent-session-file-adapter.js +22 -0
- package/dist/core/session/adapters/gemini-session-file-adapter.js +39 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +163 -3
- package/dist/core/session/session-idle-monitor.js +9 -1
- package/dist/core/session/session-manager.js +36 -2
- 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/directory/owner-directory-admission.js +42 -30
- package/dist/directory/owner-directory-cache.js +143 -126
- package/dist/directory/owner-directory-query-operation.js +9 -8
- package/dist/eck/kit-renderer.js +7 -5
- package/dist/ecweb/basic-settings-service.js +1 -1
- package/dist/ecweb/message-context-service.js +0 -4
- package/dist/ecweb/runtime/lifecycle.js +14 -8
- package/dist/ecweb/runtime/supervisor.js +62 -30
- package/dist/event-center/admission-materializer.js +114 -0
- package/dist/event-center/bus-gate.js +136 -0
- package/dist/event-center/bus-host.js +290 -0
- package/dist/event-center/bus-resolver.js +120 -0
- package/dist/event-center/center-config.js +100 -0
- package/dist/event-center/client-factory.js +50 -0
- package/dist/event-center/daemon.js +45 -0
- package/dist/event-center/directory-source.js +53 -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 +63 -0
- package/dist/event-center/ipc-operation.js +308 -0
- package/dist/event-center/ledger.js +52 -0
- package/dist/event-center/pack-loader.js +202 -0
- package/dist/event-center/pack-manager.js +85 -0
- package/dist/event-center/registry.js +238 -0
- package/dist/event-center/runtime.js +641 -0
- package/dist/event-center/script-runner.js +356 -0
- package/dist/event-center/types.js +35 -0
- package/dist/event-center/validation.js +413 -0
- package/dist/index.js +751 -268
- package/dist/ipc.js +66 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +43 -18
- package/dist/proxy/service-supervisor.js +78 -35
- package/dist/response-system/engines/v1/index.js +0 -1
- 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 +458 -0
- package/dist/services/ledger.js +52 -0
- package/dist/services/message-log.js +112 -0
- package/dist/services/pack-manager.js +204 -0
- package/dist/services/reply.js +55 -0
- package/dist/services/router.js +95 -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 +21 -1
- package/dist/trigger/audit.js +19 -4
- package/dist/trigger/authorization.js +14 -5
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/history.js +176 -7
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/manager.js +1 -3
- package/dist/trigger/scheduler.js +78 -5
- package/dist/trigger/script-sandbox.js +118 -22
- package/dist/utils/cross-platform.js +175 -13
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/host-info.js +11 -8
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/npm-ops.js +48 -0
- package/dist/utils/process-introspect.js +109 -10
- package/dist/utils/startup-trace.js +222 -44
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +10 -17
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +5 -2
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/ctl.md +2 -1
- package/kits/docs/evolcore/event-center.md +207 -0
- package/kits/docs/evolcore/file-navigation.md +10 -264
- package/kits/docs/evolcore/fs.md +3 -2
- package/kits/docs/evolcore/group.md +2 -2
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +21 -0
- package/kits/docs/evolcore/msg.md +27 -8
- package/kits/docs/evolcore/provider.md +23 -3
- package/kits/docs/evolcore/response.md +5 -5
- package/kits/docs/evolcore/services.md +277 -0
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +41 -0
- package/kits/eck_manifest.json +45 -7
- package/kits/eck_message_manifest.json +3 -3
- package/kits/rules/02-navigation.md +10 -1
- package/kits/rules/06-channel.md +5 -6
- 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/daemon.schema.1.json +5 -0
- package/kits/schemas/daemon.schema.2.json +5 -0
- package/kits/schemas/daemon.schema.3.json +2 -1
- package/kits/schemas/daemon.schema.4.json +2 -1
- package/kits/schemas/daemon.schema.5.json +2 -1
- package/kits/schemas/daemon.schema.6.json +1 -1
- package/kits/schemas/daemon.schema.7.json +1 -1
- package/kits/schemas/daemon.schema.8.json +2 -1
- package/kits/schemas/daemon.schema.9.json +2 -1
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/schemas/role-registry.schema.1.json +2 -2
- package/kits/schemas/single-session.schema.1.json +1 -1
- package/kits/schemas/single-session.schema.2.json +1 -1
- package/kits/schemas/single-session.schema.3.json +1 -1
- 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 +8 -5
- 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/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +9 -7
- package/kits/templates/system-fragments/reply.md +2 -6
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +11 -9
- package/package.json +5 -6
- 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
|
@@ -184,20 +184,29 @@ class OwnerDirectoryCoordinator {
|
|
|
184
184
|
*
|
|
185
185
|
* 判据是「实例还活着 + 它有授权」——授权凭证是 per-agent 的,协调者没有
|
|
186
186
|
* 自己的身份,所以必须借一个。优先选最近活跃的,避免挑到一个正在停止中的。
|
|
187
|
+
* 被远端拒过的实例排在后面:它多半还会被拒,但全员都被拒时仍要有人去试,
|
|
188
|
+
* 否则名录永远不更新。被拒只影响这里,不影响任何一方能不能用名录。
|
|
187
189
|
*/
|
|
188
190
|
pickExecutor(preferred) {
|
|
189
191
|
// 优先用发起方自己:它一定想拿到这份数据,结果也直接回给它。
|
|
190
|
-
//
|
|
192
|
+
// 只有它自身不可用(授权失效/已退役/刚被远端拒过)时才退到别人,避免出现
|
|
191
193
|
// 「A 触发、却被 B 的代拉结果覆盖」这种观测不到的错配。
|
|
192
|
-
|
|
194
|
+
// 执行者资格只看"实例还活着、没被远端拒过"——没有本地凭证可审了。
|
|
195
|
+
const usable = (cache) => !cache.isRetired() && !cache.isRevoked();
|
|
196
|
+
if (preferred && usable(preferred) && !preferred.pullBlocked())
|
|
193
197
|
return preferred;
|
|
194
|
-
}
|
|
195
198
|
for (const cache of this.caches) {
|
|
196
199
|
if (cache.isRetired()) {
|
|
197
200
|
this.caches.delete(cache);
|
|
198
201
|
continue;
|
|
199
202
|
}
|
|
200
|
-
if (cache
|
|
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
|
+
if (usable(cache))
|
|
201
210
|
return cache;
|
|
202
211
|
}
|
|
203
212
|
return undefined;
|
|
@@ -392,7 +401,7 @@ export class OwnerDirectoryCache {
|
|
|
392
401
|
if (this.options.isCurrent && !this.options.isCurrent())
|
|
393
402
|
return false;
|
|
394
403
|
const version = this.options.relationVersion;
|
|
395
|
-
for (const file of [path.join(contactAdmissionDirectory(this.options.selfAid), 'binding.json'), this.
|
|
404
|
+
for (const file of [path.join(contactAdmissionDirectory(this.options.selfAid), 'binding.json'), this.cachePath('contacts'), this.syncStatePath()]) {
|
|
396
405
|
let raw;
|
|
397
406
|
try {
|
|
398
407
|
raw = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
@@ -412,6 +421,12 @@ export class OwnerDirectoryCache {
|
|
|
412
421
|
}
|
|
413
422
|
return true;
|
|
414
423
|
}
|
|
424
|
+
isRevoked() {
|
|
425
|
+
return this.readSyncState().revoked === true;
|
|
426
|
+
}
|
|
427
|
+
canApply() {
|
|
428
|
+
return this.canMutate() && !this.isRevoked();
|
|
429
|
+
}
|
|
415
430
|
/** Local probes must not remove another runtime's in-progress atomic write. */
|
|
416
431
|
readLocalJson(file) {
|
|
417
432
|
try {
|
|
@@ -424,14 +439,19 @@ export class OwnerDirectoryCache {
|
|
|
424
439
|
}
|
|
425
440
|
}
|
|
426
441
|
/**
|
|
427
|
-
*
|
|
442
|
+
* 处理 Owner 的授权结果。
|
|
443
|
+
*
|
|
444
|
+
* `authorization.json` 已废弃;明确撤权状态单独保存在关系代际绑定的同步状态中。
|
|
445
|
+
* 这里只剩两件事——校验身份、按状态分流:
|
|
446
|
+
*
|
|
447
|
+
* - 撤销 / 拒绝:持久化撤权并删本地快照,阻止共享缓存重新落地;
|
|
448
|
+
* - 生效:清撤权状态、失败计数和拉取封锁,让下一次需要时能去取 contacts.json。
|
|
428
449
|
*
|
|
429
|
-
*
|
|
450
|
+
* 「要不要在远端取 contacts.json」由 storage ACL 与远端拒绝结果决定,不由本地票据决定。
|
|
430
451
|
*/
|
|
431
452
|
saveAuthorization(result) {
|
|
432
453
|
if (!this.canMutate())
|
|
433
454
|
return;
|
|
434
|
-
logger.info(`[OwnerDirectoryCache] Saving authorization for Owner ${this.options.ownerAid}, status: ${result.status}`);
|
|
435
455
|
if (result.owner_aid !== this.options.ownerAid || result.grantee_aid !== this.options.selfAid) {
|
|
436
456
|
throw new OwnerDirectoryCacheError('INVALID_GRANT', 'directory/access result identity is invalid');
|
|
437
457
|
}
|
|
@@ -443,53 +463,55 @@ export class OwnerDirectoryCache {
|
|
|
443
463
|
fs.mkdirSync(path.dirname(marker), { recursive: true, mode: 0o700 });
|
|
444
464
|
atomicWriteJson(marker, { ownerAid: this.options.ownerAid, granteeAid: this.options.selfAid, relationVersion: this.options.relationVersion });
|
|
445
465
|
}
|
|
446
|
-
//
|
|
466
|
+
// 撤销/拒绝:不留快照,准入随即回落到"名录不可用"。
|
|
447
467
|
if (result.status !== 'active' && result.status !== 'sync_pending' && result.status !== 'revoke_pending') {
|
|
448
468
|
this.revokeAuthorization(result.status);
|
|
449
469
|
return;
|
|
450
470
|
}
|
|
451
|
-
|
|
452
|
-
schemaVersion: 2,
|
|
453
|
-
relationVersion: this.options.relationVersion,
|
|
454
|
-
ownerAid: this.options.ownerAid,
|
|
455
|
-
granteeAid: this.options.selfAid,
|
|
456
|
-
grantedAt: this.now(),
|
|
457
|
-
expiresAt: grantExpiryMs(result),
|
|
458
|
-
};
|
|
459
|
-
fs.mkdirSync(this.options.directory, { recursive: true, mode: 0o700 });
|
|
460
|
-
atomicWriteJson(this.authorizationPath(), grant);
|
|
461
|
-
fs.chmodSync(this.authorizationPath(), 0o600);
|
|
471
|
+
this.writeRevocationState(false);
|
|
462
472
|
this.clearPullFailures();
|
|
463
|
-
logger.info(`[OwnerDirectoryCache]
|
|
473
|
+
logger.info(`[OwnerDirectoryCache] Owner directory grant applied: status=${result.status} (no local credential stored)`);
|
|
464
474
|
this._logAction({
|
|
465
475
|
action: 'auth',
|
|
466
476
|
generation: this.appliedGeneration,
|
|
467
|
-
detail:
|
|
477
|
+
detail: `授权生效 status=${result.status}`,
|
|
468
478
|
});
|
|
469
479
|
void this.updateSyncState(state => ({ ...state, blockedScopes: [] })).then(() => this.refreshMarkdown());
|
|
470
480
|
}
|
|
471
481
|
/**
|
|
472
|
-
*
|
|
482
|
+
* 是否具备使用名录的条件。
|
|
483
|
+
*
|
|
484
|
+
* 明确撤权优先拒绝,其余情况检查本地快照。准入由 `directory.md` + access 开关控制,
|
|
485
|
+
* 这里只回答「有没有可读的数据」。
|
|
486
|
+
*
|
|
487
|
+
* `authorization.json` 不参与这个判断:它(曾经)只表达「能不能去远端取
|
|
488
|
+
* contacts.json」,属于拉取能力,不是读本地数据的前置条件。拿到文件就能用,
|
|
489
|
+
* 过期与否、文件在不在都不拦。
|
|
473
490
|
*
|
|
474
|
-
*
|
|
475
|
-
*
|
|
491
|
+
* **拉取被拒不算不可用**:某次拉取被远端拒绝只影响「谁来拉」(见 `pullBlocked`),
|
|
492
|
+
* 不影响准入、查询和本地读取。数据由 owner 级共享缓存供给,别的 agent 拉到一样能用;
|
|
493
|
+
* 把自己锁死既救不了远端权限,也只会让本 agent 既发不出也收不进。
|
|
476
494
|
*/
|
|
477
495
|
scopeAccess(scope) {
|
|
478
496
|
return this.scopeAccessUnavailableReason(scope) ? 'unavailable' : 'authorized';
|
|
479
497
|
}
|
|
480
|
-
scopeAccessUnavailableReason(
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
498
|
+
scopeAccessUnavailableReason(scope) {
|
|
499
|
+
if (this.isRevoked())
|
|
500
|
+
return 'revoked';
|
|
501
|
+
return existsAtomic(this.cachePath(scope ?? OWNER_DIRECTORY_SCOPES[0])) ? undefined : 'snapshot_missing';
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* 本实例最近一次拉取是否被远端拒绝过。
|
|
505
|
+
*
|
|
506
|
+
* 只用于挑选执行者:被拒过一次的实例大概率还会被拒,优先让别人去拉。
|
|
507
|
+
* 它不是准入判据,也不删本地快照——拉不动不等于用不了。
|
|
508
|
+
*/
|
|
509
|
+
pullBlocked(scope = OWNER_DIRECTORY_SCOPES[0]) {
|
|
510
|
+
return this.readSyncState().blockedScopes.includes(scope);
|
|
489
511
|
}
|
|
490
512
|
// ── Pending update ──────────────────────────────────────────────────────────
|
|
491
513
|
writePendingUpdate(update) {
|
|
492
|
-
if (!this.
|
|
514
|
+
if (!this.canApply())
|
|
493
515
|
return;
|
|
494
516
|
const stored = { schemaVersion: 1, ...update, relationVersion: this.options.relationVersion };
|
|
495
517
|
fs.mkdirSync(this.options.directory, { recursive: true, mode: 0o700 });
|
|
@@ -516,6 +538,8 @@ export class OwnerDirectoryCache {
|
|
|
516
538
|
if (senderAid !== this.options.ownerAid) {
|
|
517
539
|
throw new OwnerDirectoryCacheError('UNTRUSTED_OWNER_EVENT', `directory change sender is not the authorized Owner: sender=${senderAid} expected=${this.options.ownerAid}`);
|
|
518
540
|
}
|
|
541
|
+
if (!this.canApply())
|
|
542
|
+
return;
|
|
519
543
|
// 报到协调者:这是「agent 只负责报告、daemon 统一维护共享区」的入口。
|
|
520
544
|
// 协调者保留**最新的**一份通知;拉取成功的判据是「拉到的东西不比它旧」,
|
|
521
545
|
// 而不是「追上它声明的那个 digest」——声明值可能已经是过期快照。
|
|
@@ -558,12 +582,19 @@ export class OwnerDirectoryCache {
|
|
|
558
582
|
+ (published?.updatedAtMs !== undefined ? ` updatedAtMs=${published.updatedAtMs}` : ''),
|
|
559
583
|
});
|
|
560
584
|
}
|
|
561
|
-
/**
|
|
585
|
+
/**
|
|
586
|
+
* 授权被明确撤销或拒绝时,清掉本地快照,避免继续拿旧数据做准入判断。
|
|
587
|
+
*
|
|
588
|
+
* **这是唯一的撤权通道**:先持久化撤权状态,再删除本地数据,防止共享广播恢复旧数据。
|
|
589
|
+
* 存量机器上遗留的 `authorization.json` 一并清掉,避免残留文件误导排查。
|
|
590
|
+
*/
|
|
562
591
|
revokeAuthorization(status) {
|
|
563
592
|
if (!this.canMutate())
|
|
564
593
|
return;
|
|
594
|
+
this.writeRevocationState(true);
|
|
595
|
+
this.clearPendingUpdate();
|
|
565
596
|
this.clearPullFailures();
|
|
566
|
-
atomicRemove(this.
|
|
597
|
+
atomicRemove(this.legacyAuthorizationPath());
|
|
567
598
|
atomicRemove(this.cachePath(OWNER_DIRECTORY_SCOPES[0]));
|
|
568
599
|
// 落地镜像一并删掉:留着它会让"已同步到共享区某一版"的结论在授权恢复后
|
|
569
600
|
// 依然成立,热路径据此跳过本该重做的一次落地。
|
|
@@ -598,7 +629,7 @@ export class OwnerDirectoryCache {
|
|
|
598
629
|
return;
|
|
599
630
|
_startupCheckDone.add(key);
|
|
600
631
|
const scope = OWNER_DIRECTORY_SCOPES[0];
|
|
601
|
-
if (this.
|
|
632
|
+
if (existsAtomic(this.cachePath(scope)))
|
|
602
633
|
return;
|
|
603
634
|
if (this.options.relationVersion === undefined && this.readCachedSnapshot(scope))
|
|
604
635
|
return;
|
|
@@ -621,6 +652,8 @@ export class OwnerDirectoryCache {
|
|
|
621
652
|
* 代价都不一样——混在一起会让"来一条消息"既可能发网络请求又可能写盘。
|
|
622
653
|
*/
|
|
623
654
|
async processPendingIfNeeded(trigger) {
|
|
655
|
+
if (!this.canApply())
|
|
656
|
+
return;
|
|
624
657
|
if (this.options.relationVersion === undefined)
|
|
625
658
|
return this.processPendingOnce(trigger);
|
|
626
659
|
if (this.pendingInFlight)
|
|
@@ -750,6 +783,8 @@ export class OwnerDirectoryCache {
|
|
|
750
783
|
* - 没人拉 → 协调者挑一个持有效授权的实例代为拉取
|
|
751
784
|
*/
|
|
752
785
|
async fetchToSharedCache(digests, trigger = 'unspecified', operationId) {
|
|
786
|
+
if (!this.canApply())
|
|
787
|
+
throw new OwnerDirectoryCacheError('NOT_AUTHORIZED', 'owner directory access is revoked or retired');
|
|
753
788
|
const coordinator = coordinatorFor(this.options.ownerAid);
|
|
754
789
|
const hintDigest = digests?.[OWNER_DIRECTORY_SCOPES[0]];
|
|
755
790
|
// ① 共享区已经是最新 → 0 次网络。判据优先用内存代号,命中不了才读盘。
|
|
@@ -775,11 +810,11 @@ export class OwnerDirectoryCache {
|
|
|
775
810
|
const outcome = coordinator.pulling
|
|
776
811
|
? await coordinator.pulling
|
|
777
812
|
: await this._startCoordinatedPull(coordinator, trigger, operationId, hintDigest);
|
|
778
|
-
//
|
|
813
|
+
// 远端明确拒绝:标记 blocked 让别的 agent 去拉,重试没有意义。逐个 scope 处理,
|
|
779
814
|
// 因为一次拉取里可能多个 scope 都被拒;共用同一个 Promise 的调用方也各自执行这一步。
|
|
815
|
+
// 只认远端结论,本地不再有凭证可以判"该不该被拒"。
|
|
780
816
|
for (const scope of outcome.denied) {
|
|
781
|
-
|
|
782
|
-
await this.blockScope(scope);
|
|
817
|
+
await this.blockScope(scope);
|
|
783
818
|
}
|
|
784
819
|
const complete = this._assertComplete(outcome.data, outcome.failures);
|
|
785
820
|
return complete;
|
|
@@ -870,7 +905,7 @@ export class OwnerDirectoryCache {
|
|
|
870
905
|
*/
|
|
871
906
|
_commitSharedCache(data, trigger, operationId, startedAt) {
|
|
872
907
|
// 退役的运行时不能替当前关系写共享文件。
|
|
873
|
-
if (this.
|
|
908
|
+
if (!this.canApply())
|
|
874
909
|
return false;
|
|
875
910
|
const ok = this._writeSharedCache(data, trigger, operationId, startedAt);
|
|
876
911
|
if (!ok)
|
|
@@ -921,7 +956,7 @@ export class OwnerDirectoryCache {
|
|
|
921
956
|
* 在这里做,否则调用方会把"一个字节都没拉下来"当成成功,把 pending 清掉。
|
|
922
957
|
*/
|
|
923
958
|
_assertComplete(fetched, failures) {
|
|
924
|
-
const missing = OWNER_DIRECTORY_SCOPES.filter(scope =>
|
|
959
|
+
const missing = OWNER_DIRECTORY_SCOPES.filter(scope => !fetched[scope]);
|
|
925
960
|
if (missing.length > 0) {
|
|
926
961
|
// 带上根因:上层只看到 "fetch incomplete" 会把内容不合格误判成"拉不到"。
|
|
927
962
|
const detail = missing
|
|
@@ -952,6 +987,8 @@ export class OwnerDirectoryCache {
|
|
|
952
987
|
return promise;
|
|
953
988
|
}
|
|
954
989
|
async _applyFromSharedCacheOnce() {
|
|
990
|
+
if (!this.canApply())
|
|
991
|
+
return false;
|
|
955
992
|
// 热路径的「要不要干活」由调用方(`applyFromSharedCacheWithin` →
|
|
956
993
|
// `hasPendingSharedUpdate` 的两次 stat)先判定,这里不再按内存代号早退:
|
|
957
994
|
// 代号与文件时间戳是两套判据,任意一套抢在前面 return 都会让另一套
|
|
@@ -980,6 +1017,8 @@ export class OwnerDirectoryCache {
|
|
|
980
1017
|
return false;
|
|
981
1018
|
}
|
|
982
1019
|
await this._applyAll(fetched);
|
|
1020
|
+
if (!this.canApply())
|
|
1021
|
+
return false;
|
|
983
1022
|
const applied = coordinatorFor(this.options.ownerAid).epoch;
|
|
984
1023
|
if (applied)
|
|
985
1024
|
this.appliedGeneration = applied.generation;
|
|
@@ -1003,6 +1042,8 @@ export class OwnerDirectoryCache {
|
|
|
1003
1042
|
* 共享区没有新版本时同理立刻返回——纯内存比较,不产生任何 IO。
|
|
1004
1043
|
*/
|
|
1005
1044
|
async applyFromSharedCacheWithin(timeoutMs) {
|
|
1045
|
+
if (this.isRevoked())
|
|
1046
|
+
return false;
|
|
1006
1047
|
// 共享区根本没有内容(从没拉成功过)时立刻返回 false,不等超时也不发网络。
|
|
1007
1048
|
// 必须先判这一步:`hasPendingSharedUpdate()` 在共享区缺失时也会返回 false,
|
|
1008
1049
|
// 但那个 false 的含义是「没有新内容」,不是「什么都不用做」。
|
|
@@ -1063,18 +1104,21 @@ export class OwnerDirectoryCache {
|
|
|
1063
1104
|
*/
|
|
1064
1105
|
async _applyAll(fetched) {
|
|
1065
1106
|
const apply = async () => {
|
|
1107
|
+
if (!this.canApply())
|
|
1108
|
+
return;
|
|
1066
1109
|
for (const scope of OWNER_DIRECTORY_SCOPES) {
|
|
1067
1110
|
const file = fetched[scope];
|
|
1068
1111
|
if (!file)
|
|
1069
1112
|
continue;
|
|
1070
|
-
//
|
|
1071
|
-
// 不降级、不涉及远端 ACL。授权只管"能不能从远端拉",两个环节分开。
|
|
1113
|
+
// 共享落地不要求本地授权凭证,但必须遵守明确撤权和关系代际边界。
|
|
1072
1114
|
await this._applyFile(scope, file);
|
|
1073
1115
|
}
|
|
1074
1116
|
};
|
|
1075
1117
|
const next = this.applyTail.then(apply);
|
|
1076
1118
|
this.applyTail = next.catch(() => { });
|
|
1077
1119
|
await next;
|
|
1120
|
+
if (!this.canApply())
|
|
1121
|
+
return;
|
|
1078
1122
|
// 对账:落地完后认下当前代号,热路径从此只比内存。
|
|
1079
1123
|
// 放在这里而不是各调用方,是因为落地有三条入口(拉取后、共享区读回、
|
|
1080
1124
|
// 广播),漏掉任何一条都会让热路径反复读盘。
|
|
@@ -1367,6 +1411,10 @@ export class OwnerDirectoryCache {
|
|
|
1367
1411
|
storageUpdatedAtMs: storageUpdatedAtMs ?? numberField(parsed, 'updated_at_ms'),
|
|
1368
1412
|
});
|
|
1369
1413
|
logger.info(`[OwnerDirectoryCache] Fetched ${scope}: total=${result[scope].total} digest=${result[scope].contentDigest?.slice(0, 8) ?? 'none'}`);
|
|
1414
|
+
// 这次拉通了,撤掉之前的拉取标记(写盘失败不影响本次结果)。
|
|
1415
|
+
if (this.pullBlocked(scope)) {
|
|
1416
|
+
await this.clearScopeBlock(scope).catch(() => { });
|
|
1417
|
+
}
|
|
1370
1418
|
}
|
|
1371
1419
|
catch (error) {
|
|
1372
1420
|
const normalized = toDirectoryError(error);
|
|
@@ -1620,7 +1668,7 @@ export class OwnerDirectoryCache {
|
|
|
1620
1668
|
}
|
|
1621
1669
|
// ── Internal: applyFile ──────────────────────────────────────────────────────
|
|
1622
1670
|
async _applyFile(scope, file) {
|
|
1623
|
-
if (!this.
|
|
1671
|
+
if (!this.canApply())
|
|
1624
1672
|
return;
|
|
1625
1673
|
const prev = this.readCachedSnapshot(scope);
|
|
1626
1674
|
const localDigest = prev?.contentDigest;
|
|
@@ -1637,7 +1685,7 @@ export class OwnerDirectoryCache {
|
|
|
1637
1685
|
}
|
|
1638
1686
|
const attemptedAt = this.now();
|
|
1639
1687
|
await this.updateFileState(scope, { lastAttemptAt: attemptedAt, status: 'syncing', error: undefined });
|
|
1640
|
-
if (!this.
|
|
1688
|
+
if (!this.canApply())
|
|
1641
1689
|
return;
|
|
1642
1690
|
try {
|
|
1643
1691
|
const entries = file.entries.map(e => normalizeEntry(e));
|
|
@@ -1666,7 +1714,7 @@ export class OwnerDirectoryCache {
|
|
|
1666
1714
|
...(file.openPaContext ? { openPaContext: file.openPaContext } : {}),
|
|
1667
1715
|
};
|
|
1668
1716
|
this.options.onSnapshotApplying?.(snapshot);
|
|
1669
|
-
if (!this.
|
|
1717
|
+
if (!this.canApply())
|
|
1670
1718
|
return;
|
|
1671
1719
|
archiveSnapshot(path.dirname(this.cachePath(scope)), scope);
|
|
1672
1720
|
const prevMeta = prev ? { owner: prev.owner, personalAssistant: prev.personalAssistant } : undefined;
|
|
@@ -1703,7 +1751,7 @@ export class OwnerDirectoryCache {
|
|
|
1703
1751
|
});
|
|
1704
1752
|
this.refreshMarkdown();
|
|
1705
1753
|
try {
|
|
1706
|
-
if (!this.
|
|
1754
|
+
if (!this.canApply())
|
|
1707
1755
|
return;
|
|
1708
1756
|
if (this.options.onSnapshotChanged && changes.length > 0) {
|
|
1709
1757
|
const agentMdAids = collectAgentMdRefreshAids(changes, nextMeta, prevMeta, snapshot);
|
|
@@ -1730,8 +1778,9 @@ export class OwnerDirectoryCache {
|
|
|
1730
1778
|
}
|
|
1731
1779
|
// ── Internal: readCachedSnapshot ────────────────────────────────────────────
|
|
1732
1780
|
readCachedSnapshot(scope) {
|
|
1733
|
-
|
|
1734
|
-
|
|
1781
|
+
if (this.isRevoked())
|
|
1782
|
+
return undefined;
|
|
1783
|
+
// 本地快照不要求授权凭证;明确撤权是独立的拒绝边界。
|
|
1735
1784
|
const stamp = this.cacheStamp(scope);
|
|
1736
1785
|
const cached = this.snapshotCache.get(scope);
|
|
1737
1786
|
if (cached !== undefined && cached.stamp === stamp)
|
|
@@ -1795,17 +1844,35 @@ export class OwnerDirectoryCache {
|
|
|
1795
1844
|
}
|
|
1796
1845
|
}
|
|
1797
1846
|
// ── Internal: authorization / sync state / paths ────────────────────────────
|
|
1847
|
+
/**
|
|
1848
|
+
* 记下「这个实例拉不动这份对象」。
|
|
1849
|
+
*
|
|
1850
|
+
* 只写 `blockedScopes`,供 `pickExecutor` 换个执行者。**不删本地快照、
|
|
1851
|
+
* 不改文件状态、不影响准入**:快照还在、内容由共享缓存供给,删了只会让本
|
|
1852
|
+
* agent 在远端权限修好之前既发不出也收不进。真正撤权走 `revokeAuthorization`。
|
|
1853
|
+
*/
|
|
1798
1854
|
async blockScope(scope) {
|
|
1799
1855
|
if (!this.canMutate())
|
|
1800
1856
|
return;
|
|
1801
|
-
|
|
1802
|
-
|
|
1857
|
+
if (this.readSyncState().blockedScopes.includes(scope))
|
|
1858
|
+
return;
|
|
1803
1859
|
await this.updateSyncState(state => ({
|
|
1804
1860
|
...state,
|
|
1805
1861
|
blockedScopes: [...new Set([...state.blockedScopes, scope])],
|
|
1806
|
-
files: { ...state.files, [scope]: { ...state.files[scope], status: 'blocked', error: 'remote storage denied access' } },
|
|
1807
1862
|
}));
|
|
1808
|
-
this.
|
|
1863
|
+
logger.info(`[OwnerDirectoryCache] Marked ${scope} as pull-blocked for ${this.options.selfAid} (other agents keep pulling)`);
|
|
1864
|
+
}
|
|
1865
|
+
/** 本实例重新拉到了:解除拉取标记,恢复执行者候选资格。 */
|
|
1866
|
+
async clearScopeBlock(scope) {
|
|
1867
|
+
if (!this.canMutate())
|
|
1868
|
+
return;
|
|
1869
|
+
if (!this.readSyncState().blockedScopes.includes(scope))
|
|
1870
|
+
return;
|
|
1871
|
+
await this.updateSyncState(state => ({
|
|
1872
|
+
...state,
|
|
1873
|
+
blockedScopes: state.blockedScopes.filter(item => item !== scope),
|
|
1874
|
+
}));
|
|
1875
|
+
logger.info(`[OwnerDirectoryCache] Cleared pull-block for ${scope} on ${this.options.selfAid}`);
|
|
1809
1876
|
}
|
|
1810
1877
|
async updateFileState(scope, update) {
|
|
1811
1878
|
await this.updateSyncState(state => ({
|
|
@@ -1826,6 +1893,12 @@ export class OwnerDirectoryCache {
|
|
|
1826
1893
|
this.stateWriteTail = run.catch(() => { });
|
|
1827
1894
|
await run;
|
|
1828
1895
|
}
|
|
1896
|
+
writeRevocationState(revoked) {
|
|
1897
|
+
const state = { ...this.readSyncState(), relationVersion: this.options.relationVersion, revoked };
|
|
1898
|
+
fs.mkdirSync(this.options.directory, { recursive: true, mode: 0o700 });
|
|
1899
|
+
atomicWriteJson(this.syncStatePath(), state);
|
|
1900
|
+
fs.chmodSync(this.syncStatePath(), 0o600);
|
|
1901
|
+
}
|
|
1829
1902
|
readSyncState() {
|
|
1830
1903
|
const raw = this.readLocalJson(this.syncStatePath());
|
|
1831
1904
|
if (!isRecord(raw) || raw.schemaVersion !== 1 || raw.ownerAid !== this.options.ownerAid
|
|
@@ -1835,56 +1908,12 @@ export class OwnerDirectoryCache {
|
|
|
1835
1908
|
}
|
|
1836
1909
|
return {
|
|
1837
1910
|
schemaVersion: 1, ownerAid: this.options.ownerAid, granteeAid: this.options.selfAid,
|
|
1911
|
+
relationVersion: raw.relationVersion,
|
|
1912
|
+
revoked: raw.revoked === true,
|
|
1838
1913
|
files: raw.files,
|
|
1839
1914
|
blockedScopes: Array.isArray(raw.blockedScopes) ? raw.blockedScopes.filter(isOwnerDirectoryScope) : [],
|
|
1840
1915
|
};
|
|
1841
1916
|
}
|
|
1842
|
-
/**
|
|
1843
|
-
* 读授权快照。
|
|
1844
|
-
*
|
|
1845
|
-
* 兼容 v1:旧版本按 scope 记录授权(`activeScopes: ['agents','contacts']`),
|
|
1846
|
-
* 里面还可能带着已经废弃的 `agents`。**未知或多余的 scope 不会作废整份授权**——
|
|
1847
|
-
* 那会让升级当场断掉拉取。v1 只要能证明"允许读名录"就算有效,过期时间取
|
|
1848
|
-
* contacts 的那一份。
|
|
1849
|
-
*/
|
|
1850
|
-
loadGrant() {
|
|
1851
|
-
const raw = this.readLocalJson(this.authorizationPath());
|
|
1852
|
-
if (!isRecord(raw))
|
|
1853
|
-
return undefined;
|
|
1854
|
-
if (raw.ownerAid !== this.options.ownerAid || raw.granteeAid !== this.options.selfAid)
|
|
1855
|
-
return undefined;
|
|
1856
|
-
if (this.options.relationVersion !== undefined && typeof raw.relationVersion === 'number' && raw.relationVersion !== this.options.relationVersion)
|
|
1857
|
-
return undefined;
|
|
1858
|
-
if (raw.schemaVersion === 2) {
|
|
1859
|
-
if (!Number.isSafeInteger(raw.grantedAt) || !Number.isSafeInteger(raw.expiresAt))
|
|
1860
|
-
return undefined;
|
|
1861
|
-
return {
|
|
1862
|
-
schemaVersion: 2,
|
|
1863
|
-
ownerAid: this.options.ownerAid,
|
|
1864
|
-
granteeAid: this.options.selfAid,
|
|
1865
|
-
grantedAt: raw.grantedAt,
|
|
1866
|
-
expiresAt: raw.expiresAt,
|
|
1867
|
-
};
|
|
1868
|
-
}
|
|
1869
|
-
if (raw.schemaVersion === 1) {
|
|
1870
|
-
if (typeof raw.status !== 'string' || !GRANT_STATUSES.has(raw.status))
|
|
1871
|
-
return undefined;
|
|
1872
|
-
if (!Array.isArray(raw.activeScopes) || !raw.activeScopes.includes('contacts'))
|
|
1873
|
-
return undefined;
|
|
1874
|
-
const expiryMap = isRecord(raw.expiresAtByScope) ? raw.expiresAtByScope : {};
|
|
1875
|
-
const expiresAt = Number(expiryMap['contacts'] ?? 0);
|
|
1876
|
-
if (!Number.isSafeInteger(expiresAt) || expiresAt < 0)
|
|
1877
|
-
return undefined;
|
|
1878
|
-
return {
|
|
1879
|
-
schemaVersion: 2,
|
|
1880
|
-
ownerAid: this.options.ownerAid,
|
|
1881
|
-
granteeAid: this.options.selfAid,
|
|
1882
|
-
grantedAt: Number.isSafeInteger(raw.storedAt) ? raw.storedAt : 0,
|
|
1883
|
-
expiresAt,
|
|
1884
|
-
};
|
|
1885
|
-
}
|
|
1886
|
-
return undefined;
|
|
1887
|
-
}
|
|
1888
1917
|
/**
|
|
1889
1918
|
* 重算并写回 `directory.md`。
|
|
1890
1919
|
*
|
|
@@ -1968,18 +1997,15 @@ export class OwnerDirectoryCache {
|
|
|
1968
1997
|
/**
|
|
1969
1998
|
* 名录是否**确证**已不可用。
|
|
1970
1999
|
*
|
|
1971
|
-
*
|
|
1972
|
-
*
|
|
1973
|
-
*
|
|
1974
|
-
* 2. 授权有效但快照文件确实不在盘上(含热备)——此时没有可渲染的内容。
|
|
2000
|
+
* 唯一的判据是快照文件不在盘上(含热备)——没有授权凭证这一层了,读不到数据
|
|
2001
|
+
* 就是全部原因。撤销授权走 `revokeAuthorization`,它会把快照删掉,在这里
|
|
2002
|
+
* 表现为 true,语义仍然成立。
|
|
1975
2003
|
*
|
|
1976
2004
|
* 快照文件存在却读不出(解析失败、字段校验不过、原子写窗口)时返回 false:
|
|
1977
2005
|
* 这是"暂时读不到",不是"名录没了",调用方应保留旧注入而不是删掉。
|
|
1978
2006
|
*/
|
|
1979
2007
|
directoryGone() {
|
|
1980
|
-
|
|
1981
|
-
return true;
|
|
1982
|
-
return !existsAtomic(this.cachePath('contacts'));
|
|
2008
|
+
return this.isRevoked() || !existsAtomic(this.cachePath('contacts'));
|
|
1983
2009
|
}
|
|
1984
2010
|
/**
|
|
1985
2011
|
* 备注集合,带目录指纹缓存。
|
|
@@ -1998,7 +2024,12 @@ export class OwnerDirectoryCache {
|
|
|
1998
2024
|
this.remarksStampCache = stamp === null ? undefined : { stamp, remarks };
|
|
1999
2025
|
return remarks;
|
|
2000
2026
|
}
|
|
2001
|
-
|
|
2027
|
+
/**
|
|
2028
|
+
* 已废弃的授权凭证路径,**只用于清理存量文件**,不参与任何判断,也不再写入。
|
|
2029
|
+
*
|
|
2030
|
+
* 撤权时顺手删掉遗留文件;其他路径一律不读它。
|
|
2031
|
+
*/
|
|
2032
|
+
legacyAuthorizationPath() { return path.join(this.options.directory, 'authorization.json'); }
|
|
2002
2033
|
syncStatePath() { return path.join(this.options.directory, 'sync-state.json'); }
|
|
2003
2034
|
pendingPath() { return path.join(this.options.directory, 'pending.json'); }
|
|
2004
2035
|
cachePath(scope) {
|
|
@@ -2009,20 +2040,6 @@ export class OwnerDirectoryCache {
|
|
|
2009
2040
|
}
|
|
2010
2041
|
}
|
|
2011
2042
|
// ── Module-level helpers ─────────────────────────────────────────────────────
|
|
2012
|
-
/**
|
|
2013
|
-
* 从 `directory/access` 的结果里取过期时间。
|
|
2014
|
-
*
|
|
2015
|
-
* 协议按 scope 给过期时间,名录只剩一份,取 contacts 的那份;都没给就不过期。
|
|
2016
|
-
* 状态不是 active 的授权(revoked/expired)直接记 0,由 `scopeAccess` 之外的
|
|
2017
|
-
* 语义处理——这里只回答"读到什么时候"。
|
|
2018
|
-
*/
|
|
2019
|
-
function grantExpiryMs(result) {
|
|
2020
|
-
if (result.status !== 'active' && result.status !== 'sync_pending' && result.status !== 'revoke_pending')
|
|
2021
|
-
return 0;
|
|
2022
|
-
const map = isRecord(result.expires_at_by_scope) ? result.expires_at_by_scope : {};
|
|
2023
|
-
const value = Number(map['contacts'] ?? 0);
|
|
2024
|
-
return Number.isSafeInteger(value) && value >= 0 ? value : 0;
|
|
2025
|
-
}
|
|
2026
2043
|
function parseIdentityField(value) {
|
|
2027
2044
|
if (!isRecord(value) || typeof value.aid !== 'string' || typeof value.name !== 'string')
|
|
2028
2045
|
return undefined;
|
|
@@ -2334,9 +2351,9 @@ function isPermissionDenied(error) {
|
|
|
2334
2351
|
/**
|
|
2335
2352
|
* 把"远端明确拒绝"的各种错误形态归一成 `PERMISSION_DENIED`。
|
|
2336
2353
|
*
|
|
2337
|
-
* `blockScope`
|
|
2338
|
-
*
|
|
2339
|
-
*
|
|
2354
|
+
* 归一的用途只是把"这次拉不动"和"网络抖动"分开:前者让 `blockScope` 换个人去拉,
|
|
2355
|
+
* 后者走普通退避重试。两者都**不影响本 agent 能不能用名录**——撤权由
|
|
2356
|
+
* `revokeAuthorization` 单独表达,不靠一次拉取失败推断。
|
|
2340
2357
|
*
|
|
2341
2358
|
* 形态来源:
|
|
2342
2359
|
* - AUN RPC 拒绝:`code` 为 `-32004` / `403` / `4030`,或错误消息里带这些词
|
|
@@ -21,7 +21,7 @@ import { describeEntry, filterDirectory, } from './owner-directory-search.js';
|
|
|
21
21
|
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
|
-
import {
|
|
24
|
+
import { snapshotOwnerAid, refreshOwnerDirectory, syncOwnerDirectoryForLookup } from './owner-directory-admission.js';
|
|
25
25
|
import { getPeerSnapshot } from '../config/peer-book.js';
|
|
26
26
|
import { resolveEntryContactable } from './owner-directory-policy.js';
|
|
27
27
|
/** `info` 按名字命中时的默认上限。 */
|
|
@@ -104,16 +104,17 @@ export async function executeDirectoryQueryCommand(command) {
|
|
|
104
104
|
if (!fs.existsSync(agentDir(command.selfAid))) {
|
|
105
105
|
return { ok: false, code: 'AGENT_NOT_FOUND', error: `agent ${command.selfAid} does not exist` };
|
|
106
106
|
}
|
|
107
|
-
// ownerAid
|
|
108
|
-
|
|
109
|
-
const ownerAid = authorizedOwnerAid(directory, command.selfAid);
|
|
107
|
+
// ownerAid 取自快照信封:快照自证归属,离线也能用。解析器只在没有快照时兜底。
|
|
108
|
+
const ownerAid = snapshotOwnerAid(directory, command.selfAid) ?? ownerResolver.owner(command.selfAid);
|
|
110
109
|
if (!ownerAid) {
|
|
111
|
-
return { ok: false, code: 'NOT_AUTHORIZED', error: 'directory is not
|
|
110
|
+
return { ok: false, code: 'NOT_AUTHORIZED', error: 'directory is not available for this agent' };
|
|
112
111
|
}
|
|
113
112
|
const cache = new OwnerDirectoryCache({ selfAid: command.selfAid, ownerAid, directory });
|
|
114
113
|
const scope = OWNER_DIRECTORY_SCOPES[0];
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
const accessReason = cache.scopeAccessUnavailableReason(scope);
|
|
115
|
+
// 明确撤权不允许刷新;仅缺少快照时允许刷新恢复数据。
|
|
116
|
+
if (accessReason && (command.action !== 'refresh' || accessReason !== 'snapshot_missing')) {
|
|
117
|
+
return { ok: false, code: 'NOT_AUTHORIZED', error: 'directory is not available for this agent' };
|
|
117
118
|
}
|
|
118
119
|
// refresh 要在快照判空之前处理:它存在的意义正是"本地没有或太旧,去拉一次"。
|
|
119
120
|
if (command.action === 'refresh') {
|
|
@@ -289,7 +290,7 @@ function readBlockedAidsFromSnapshot(directory) {
|
|
|
289
290
|
* `ec directory info <名字>` 看详情。只查 `entries` 会让最该查到的两个人查不到。
|
|
290
291
|
* 与已有条目同 AID 时以条目为准,避免同一个人出现两次。
|
|
291
292
|
*
|
|
292
|
-
*
|
|
293
|
+
* 两者在快照解析阶段已经和快照信封里的 `ownerAid` 做过一致性校验,
|
|
293
294
|
* 所以补成条目时按“已核验”处理,否则他们会被自己的归属门禁判成外部。
|
|
294
295
|
*/
|
|
295
296
|
function withIdentityEntries(snapshot) {
|
package/dist/eck/kit-renderer.js
CHANGED
|
@@ -84,7 +84,7 @@ export function renderKitSections(ctx, manifestFile = DEFAULT_MANIFEST_FILE) {
|
|
|
84
84
|
const vars = {
|
|
85
85
|
...ctx.vars,
|
|
86
86
|
...(resolvedLifecycle === null ? {} : { lifecycle: resolvedLifecycle }),
|
|
87
|
-
activePush: ctx.vars.chatMode === 'proactive'
|
|
87
|
+
activePush: ctx.vars.chatMode === 'proactive',
|
|
88
88
|
};
|
|
89
89
|
const renderCtx = { ...ctx, vars };
|
|
90
90
|
const pathMappings = buildPathMappings(vars);
|
|
@@ -239,13 +239,15 @@ const PARAM_DESCRIPTIONS = {
|
|
|
239
239
|
lifecycle: '当前 agent 生命周期(created/ownerpending/bootstrapping/active)',
|
|
240
240
|
isBootstrapping: '当前 agent 是否处于 bootstrap 首次设定阶段',
|
|
241
241
|
hasPersona: '是否有自我定义内容(soul/ 下除指南外有非空文件)',
|
|
242
|
+
hasServicePacks: '是否有已激活的服务包(services/*/service.json 且 requires 对名片通过)',
|
|
243
|
+
hasEventPacks: '是否有已启用的事件包(events/*/pack.json 且 enabled)',
|
|
242
244
|
hasOwnerDirectory: '是否有 Owner 名录注入文件($AGENT_DIR/directory/directory.md)',
|
|
243
|
-
ownerAid: 'Owner 的 AID
|
|
244
|
-
ownerName: 'Owner
|
|
245
|
+
ownerAid: 'Owner 的 AID(归属协议共识为准,与记忆写入同源;名录快照仅在与之一致时提供名字)',
|
|
246
|
+
ownerName: 'Owner 的显示名(名录快照,且仅在快照 Owner 与协议 Owner 一致时有值)',
|
|
245
247
|
personalAssistantAid: '个人助理的 AID(名录快照;没有个人助理时为空)',
|
|
246
248
|
personalAssistantName: '个人助理的显示名(名录快照)',
|
|
247
249
|
isPersonalAssistant: '当前 agent 是否就是 Owner 的个人助理(即时比较,读不到身份时为 false)',
|
|
248
|
-
isOwner: '当前 agent
|
|
250
|
+
isOwner: '当前 agent 是否就是协议确认的 Owner(即时比较;Owner 通常是人,一般恒为 false)',
|
|
249
251
|
contactsState: '准入现状一句话:内部联系人/外部联系人/名录外的人分别可不可联系',
|
|
250
252
|
peerId: '对端在该渠道的原生 ID',
|
|
251
253
|
peerKey: '对端跨渠道唯一标识(channel#urlEncode(peerId))',
|
|
@@ -280,7 +282,7 @@ const PARAM_DESCRIPTIONS = {
|
|
|
280
282
|
weekday: '当前本地星期几(按 timezone+locale)',
|
|
281
283
|
osInfo: '操作系统及版本(如 Windows 11 Pro (win32 10.0.26200))',
|
|
282
284
|
threadId: '话题 ID(多话题路由时)',
|
|
283
|
-
chatMode: '会话模式(interactive=同步交互 / proactive
|
|
285
|
+
chatMode: '会话模式(interactive=同步交互 / proactive=主动推送)',
|
|
284
286
|
activePush: '是否通过托管发送命令发送正式回复(true/false)',
|
|
285
287
|
isTriggerTask: '当前任务是否来源于 Trigger(true/false)',
|
|
286
288
|
proactivePreTool1stMsgChk: 'proactive 前置工具首消息检查(true/false)',
|
|
@@ -509,7 +509,7 @@ function validateDefaultsValue(fieldPath, value) {
|
|
|
509
509
|
return;
|
|
510
510
|
}
|
|
511
511
|
if (fieldPath === 'config.chatMode') {
|
|
512
|
-
if (!['interactive', 'proactive'
|
|
512
|
+
if (!['interactive', 'proactive'].includes(String(value)))
|
|
513
513
|
throw makeError(`${fieldPath} is invalid`, 'INVALID_SETTINGS_VALUE');
|
|
514
514
|
return;
|
|
515
515
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { isValidAid } from '../aun/aid/validation.js';
|
|
2
2
|
import { resolvePeerDisplayLabel } from '../config/peer-book.js';
|
|
3
3
|
import { resolvePeerRoleDetail } from '../config/peer-role-resolver.js';
|
|
4
|
-
import { ConfigTarget, read } from '../config/config-manager.js';
|
|
5
|
-
import { resolveAgentLifecycle } from '../config/lifecycle.js';
|
|
6
4
|
import { resolveChatMode } from '../core/message/peer-mode.js';
|
|
7
5
|
import { resolvePermissionMode } from '../core/model/config-scope.js';
|
|
8
6
|
import { formatPeerKey } from '../core/relation/peer-identity.js';
|
|
@@ -102,8 +100,6 @@ export function createEcwebMessageContextProvider(sessionManager, resolveRuntime
|
|
|
102
100
|
chatMode: resolveChatMode({
|
|
103
101
|
self: identity.selfAid, peerKey, role, chatType, peerType,
|
|
104
102
|
channelType: identity.channelType,
|
|
105
|
-
lifecycle: resolveAgentLifecycle(read(ConfigTarget.Agent, { self: identity.selfAid }) ?? {}),
|
|
106
|
-
sessionType: scopedSession?.sessionType ?? scopedSession?.metadata?.sessionType ?? 'main',
|
|
107
103
|
}),
|
|
108
104
|
...(peerLabels ? { peerLabels } : {}),
|
|
109
105
|
};
|