evolcore 0.0.40 → 0.0.41-test.1
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 +94 -1
- package/bin/codex-managed-hook.mjs +11 -0
- package/bin/ec-safe-output.js +11 -1
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/baseagent.js +20 -43
- package/dist/agents/claude-runner.js +197 -197
- package/dist/agents/codex-runner.js +535 -259
- package/dist/agents/ecagent-runner.js +31 -12
- package/dist/agents/gemini-runner.js +27 -7
- package/dist/agents/runner-types.js +11 -3
- package/dist/aun/ability-device-routing.js +26 -0
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/group/fs-download.js +39 -0
- package/dist/aun/group/identity.js +36 -13
- package/dist/aun/group/operations.js +5 -0
- package/dist/aun/msg/managed-operation.js +72 -11
- package/dist/aun/msg/p2p.js +32 -7
- package/dist/aun/service-proxy.js +36 -12
- package/dist/aun/storage/download.js +30 -0
- package/dist/aun/storage/index.js +14 -6
- package/dist/channels/aun.js +367 -24
- package/dist/channels/daemon.js +39 -5
- package/dist/cli/agent-command.js +2 -0
- package/dist/cli/agent-create.js +98 -19
- package/dist/cli/agent.js +10 -3
- package/dist/cli/aun-commands.js +85 -41
- package/dist/cli/daemon-commands.js +678 -688
- package/dist/cli/fs-command.js +64 -2
- package/dist/cli/index.js +48 -4
- package/dist/cli/managed-command-guard.js +4 -0
- package/dist/cli/model.js +40 -40
- package/dist/cli/proxy-command.js +92 -0
- package/dist/cli/restart-monitor.js +17 -0
- package/dist/cli/role.js +85 -0
- package/dist/cli/session-command.js +128 -13
- package/dist/cli/stats.js +60 -4
- package/dist/cli/trigger-command.js +2 -2
- package/dist/config/access-policy.js +8 -1
- package/dist/config/boot-log.js +38 -1
- package/dist/config/config-field-policy.js +5 -32
- package/dist/config/config-manager.js +46 -39
- package/dist/config/config-operation-service.js +8 -11
- package/dist/config/contact-book-store.js +47 -21
- package/dist/config/contact-book.js +18 -12
- package/dist/config/contact-operation-service.js +3 -4
- package/dist/config/contact-request-service.js +11 -0
- package/dist/config/daemon-services.js +11 -0
- package/dist/config/gateway-config.js +89 -595
- package/dist/config/peer-role-resolver.js +15 -11
- package/dist/config/providers-config.js +12 -7
- package/dist/config/providers-import.js +3 -21
- package/dist/config/resolved-config-op.js +3 -0
- package/dist/config/role-command-service.js +166 -0
- package/dist/config/role-request-service.js +193 -0
- package/dist/config/schema-migration.js +686 -25
- package/dist/config-store.js +79 -3
- package/dist/contracts/ecweb-instance.js +41 -0
- package/dist/contracts/ecweb-service-protocol.js +3 -1
- package/dist/core/agent-application-service.js +11 -1
- package/dist/core/agent-ipc-registration.js +4 -0
- package/dist/core/agent-runtime.js +1 -1
- package/dist/core/auth/agent-delegation.js +82 -6
- package/dist/core/auth/auth-gateway.js +1 -1
- package/dist/core/auth/authorization-audit.js +37 -9
- package/dist/core/auth/delegation-authorization.js +3 -1
- package/dist/core/auth/operation-authorizer.js +15 -0
- package/dist/core/auth/operation-catalog.js +39 -6
- package/dist/core/command/agent-control.js +94 -19
- package/dist/core/command/agent-storage-menu.js +5 -3
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +105 -145
- package/dist/core/command/connect-menu.js +31 -2
- package/dist/core/command/data-root-resolver.js +5 -4
- package/dist/core/command/memory-slash.js +16 -8
- package/dist/core/command/menu-catalog.js +6 -6
- package/dist/core/command/menu-handler.js +87 -163
- package/dist/core/command/menu-protocol.js +9 -2
- package/dist/core/command/role-menu.js +148 -30
- package/dist/core/command/slash-gate.js +13 -10
- package/dist/core/command/slash-handler.js +157 -352
- package/dist/core/daemon-control.js +8 -14
- package/dist/core/event-catalog.js +15 -0
- package/dist/core/evolagent-registry.js +4 -4
- package/dist/core/evolagent.js +2 -2
- package/dist/core/inference/text-inference.js +31 -40
- package/dist/core/ipc-registration.js +24 -3
- package/dist/core/memory/consolidation-context.js +51 -5
- package/dist/core/memory/consolidation-ops-records.js +1 -1
- package/dist/core/memory/consolidation-trigger.js +190 -190
- package/dist/core/memory/consolidation.js +316 -29
- package/dist/core/memory/forget-log.js +96 -0
- package/dist/core/memory/index-manager.js +27 -5
- package/dist/core/memory/memory-admin.js +45 -5
- package/dist/core/memory/memory-writer.js +163 -18
- package/dist/core/memory/relation-idle-monitor.js +119 -58
- package/dist/core/memory/relation-sweep.js +44 -39
- package/dist/core/message/aun-ipc-sender.js +34 -7
- package/dist/core/message/aun-request-registry.js +97 -3
- package/dist/core/message/im-renderer.js +11 -4
- package/dist/core/message/message-admission.js +97 -8
- package/dist/core/message/message-bridge.js +71 -24
- package/dist/core/message/message-log.js +55 -0
- package/dist/core/message/message-queue.js +5 -5
- package/dist/core/message/response-engine.js +387 -144
- package/dist/core/model/catalog-service.js +4 -2
- package/dist/core/model/config-scope.js +24 -64
- package/dist/core/model/field-scope.js +1 -1
- package/dist/core/model/model-catalog.js +37 -47
- package/dist/core/model/model-diagnostics.js +4 -3
- package/dist/core/model/model-fallback.js +10 -7
- package/dist/core/model/model-permission.js +3 -2
- package/dist/core/ownership/owner-resolver.js +25 -23
- package/dist/core/permission/ec-command-parser.js +138 -5
- package/dist/core/permission/sandbox-runtime.js +18 -1
- package/dist/core/permission/tool-policy.js +42 -10
- package/dist/core/relation/peer-identity.js +64 -1
- package/dist/core/role/runtime-policy.js +72 -13
- package/dist/core/session/session-capsule.js +197 -0
- package/dist/core/session/session-idle-monitor.js +1 -1
- package/dist/core/session/session-manager.js +168 -14
- package/dist/core/session/session-mapper.js +2 -0
- package/dist/core/session/session-renew.js +3 -3
- package/dist/core/skill/index-generator.js +15 -5
- package/dist/core/system-session/memory.js +6 -1
- package/dist/core/thread/thread-service.js +19 -6
- package/dist/directory/owner-directory-admission.js +95 -0
- package/dist/directory/owner-directory-authorization.js +309 -0
- package/dist/directory/owner-directory-cache.js +635 -0
- package/dist/eck/kit-renderer.js +2 -2
- package/dist/ecweb/basic-settings-service.js +33 -40
- package/dist/ecweb/message-context-service.js +110 -0
- package/dist/index.js +79 -17
- package/dist/ipc.js +189 -17
- package/dist/paths.js +4 -0
- package/dist/proxy/command.js +122 -0
- package/dist/proxy/ipc-service.js +68 -0
- package/dist/proxy/manager.js +485 -0
- package/dist/proxy/service-supervisor.js +603 -0
- package/dist/response-system/engines/v1/proactive-flow.js +16 -6
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +15 -0
- package/dist/stats/index.js +2 -2
- package/dist/stats/price-resolver.js +304 -5
- package/dist/stats/query.js +82 -3
- package/dist/stats/writer.js +38 -5
- package/dist/trigger/feedback.js +18 -7
- package/dist/trigger/manager.js +20 -3
- package/dist/trigger/parser.js +6 -3
- package/dist/trigger/patch.js +1 -1
- package/dist/trigger/system-definitions.js +43 -7
- package/dist/trigger/validation.js +13 -5
- package/dist/utils/cross-platform.js +14 -0
- package/dist/utils/ecweb-supervisor.js +258 -83
- package/dist/utils/error-utils.js +16 -2
- package/dist/utils/logger.js +24 -5
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +5 -3
- package/dist/utils/upgrade-jobs.js +45 -5
- package/kits/docs/INDEX.md +1 -1
- package/kits/docs/aun/ABILITY_CALLING.md +20 -2
- package/kits/docs/channels/aun.md +9 -0
- package/kits/docs/evolcore/INDEX.md +2 -1
- package/kits/docs/evolcore/agent-create.md +3 -2
- package/kits/docs/evolcore/agent.md +1 -1
- package/kits/docs/evolcore/config.md +18 -7
- package/kits/docs/evolcore/contact.md +3 -0
- package/kits/docs/evolcore/event.md +1 -0
- package/kits/docs/evolcore/fs.md +16 -0
- package/kits/docs/evolcore/memory-architecture.md +2 -2
- package/kits/docs/evolcore/memory-consolidation.md +32 -8
- package/kits/docs/evolcore/memory.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +36 -0
- package/kits/docs/evolcore/model.md +23 -20
- package/kits/docs/evolcore/msg.md +21 -8
- package/kits/docs/evolcore/session.md +14 -0
- package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
- package/kits/schemas/_meta.json +37 -4
- package/kits/schemas/agent-config.schema.13.json +23 -3
- package/kits/schemas/agent-config.schema.16.json +891 -0
- package/kits/schemas/daemon.schema.9.json +366 -0
- package/kits/schemas/defaults.schema.5.json +406 -127
- package/kits/schemas/relation-config.schema.11.json +260 -0
- package/kits/schemas/role-config.schema.1.json +7 -7
- package/kits/skills/.switches.json +3 -7
- package/kits/skills/aid-ability/SKILL.md +35 -6
- package/kits/skills/ec-service-proxy/SKILL.md +118 -0
- package/kits/skills/ec-trigger/SKILL.md +13 -5
- package/kits/skills/personal-assistant/SKILL.md +176 -0
- package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
- package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
- package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
- package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
- package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
- package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
- package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
- package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
- package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
- package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
- package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
- package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
- package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
- package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
- package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
- package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
- package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
- package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
- package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
- package/kits/templates/memory-consolidation/forget.md +19 -6
- package/kits/templates/memory-consolidation/notes.md +1 -1
- package/kits/templates/memory-consolidation/profile.md +2 -2
- package/kits/templates/memory-consolidation/promote.md +20 -3
- package/kits/templates/roles/member.json +8 -1
- package/kits/templates/session-capsule/recovery.md +5 -0
- package/kits/templates/session-capsule/renew.md +5 -0
- package/kits/templates/system-fragments/baseagent.md +2 -2
- package/kits/templates/system-fragments/bootstrap.md +6 -6
- package/kits/templates/system-fragments/channel.md +1 -1
- package/kits/templates/system-fragments/memory.md +4 -4
- package/package.json +7 -3
- package/dist/stats/billing.js +0 -215
|
@@ -9,7 +9,7 @@ import { relationFieldWriteOperation, resolveRoleFieldPermission, } from '../../
|
|
|
9
9
|
import { evaluateRoleOperationCapability } from '../auth/operation-authorizer.js';
|
|
10
10
|
import { listOperations } from '../auth/operation-catalog.js';
|
|
11
11
|
import { auditRoleMutation } from '../auth/authorization-audit.js';
|
|
12
|
-
import { formatPeerKey, parsePeerKey } from '../relation/peer-identity.js';
|
|
12
|
+
import { formatPeerKey, parsePeerKey, readAunPeerKind, resolveAunPeerKind } from '../relation/peer-identity.js';
|
|
13
13
|
import { agentDir, agentRoleConfig, agentRolesIndex, agentRelationConfig, agentRelationsDir, resolvePaths } from '../../paths.js';
|
|
14
14
|
import { atomicReadJson, atomicWrite } from '../../utils/atomic-write.js';
|
|
15
15
|
import { fileCache } from '../daemon-file-cache.js';
|
|
@@ -18,7 +18,7 @@ import { loadSchema } from '../../config/schema-registry.js';
|
|
|
18
18
|
import { rolePermissionFields, rolePermissionFieldOptions, rolePermissionFieldPatterns, validateRoleConfig, } from '../../config/role-schema.js';
|
|
19
19
|
import { groupInfo, groupList, groupDirectoryErrorCode } from '../../aun/group/index.js';
|
|
20
20
|
import { aidLookup, isValidAid } from '../../aun/aid/identity.js';
|
|
21
|
-
import {
|
|
21
|
+
import { resolveAunTargetKind } from '../../aun/group/identity.js';
|
|
22
22
|
import { readJsonFile, readLastJsonlLine, scanChatDirs, scanMetaFiles } from '../session/session-fs-store.js';
|
|
23
23
|
import { constrainResolvedModelForRole } from '../model/model-permission.js';
|
|
24
24
|
import { resolveRuntimePermissionMode, resolveRuntimeStringField } from '../role/runtime-policy.js';
|
|
@@ -50,7 +50,7 @@ export function roleMenuOperation(kind, args, value) {
|
|
|
50
50
|
if (kind === 'options')
|
|
51
51
|
return 'role.policy.read';
|
|
52
52
|
if (kind === 'query') {
|
|
53
|
-
return ['targets', 'assignments', 'target'].includes(String(args?.view))
|
|
53
|
+
return ['targets', 'assignments', 'target', 'member'].includes(String(args?.view))
|
|
54
54
|
? 'role.relation.read'
|
|
55
55
|
: 'role.policy.read';
|
|
56
56
|
}
|
|
@@ -151,6 +151,8 @@ export async function roleMenuQuery(context, args) {
|
|
|
151
151
|
return assignmentInventory(context, args, policyRevision);
|
|
152
152
|
if (view === 'target')
|
|
153
153
|
return targetSnapshot(context, args, policyRevision);
|
|
154
|
+
if (view === 'member')
|
|
155
|
+
return memberSnapshot(context, args, policyRevision);
|
|
154
156
|
if (view === 'targets')
|
|
155
157
|
return targetList(context, args);
|
|
156
158
|
throw roleError('NOT_SUPPORTED', 'The requested Role view is not supported', context.self, {
|
|
@@ -544,6 +546,42 @@ async function updateAssignment(context, args, value) {
|
|
|
544
546
|
const nextRevision = changed ? revision(normalized) : current?.revision ?? null;
|
|
545
547
|
return assignmentResponse(self, target, normalized, changed, nextRevision);
|
|
546
548
|
}
|
|
549
|
+
/**
|
|
550
|
+
* Apply an assignment that was approved out-of-band by the Agent owner through
|
|
551
|
+
* the role request workflow. The caller has already verified that the reviewer
|
|
552
|
+
* is the owner; this helper only re-applies the assignment invariants that must
|
|
553
|
+
* never be skipped (assignable role, owner protection, relation normalization).
|
|
554
|
+
*/
|
|
555
|
+
export async function applyApprovedRoleAssignment(input) {
|
|
556
|
+
const self = input.selfAid;
|
|
557
|
+
const target = normalizeTarget({ kind: 'private', peerAid: input.peerAid }, self);
|
|
558
|
+
const roleId = validateAssignableRole(input.roleId, self, 'roleId');
|
|
559
|
+
if (roleId === null) {
|
|
560
|
+
throw validationFailed(self, undefined, [{
|
|
561
|
+
field: 'roleId', code: 'INVALID_VALUE', message: 'roleId must be an existing assignable user role',
|
|
562
|
+
}]);
|
|
563
|
+
}
|
|
564
|
+
if (target.kind === 'private' && isStaticAgentOwner(self, target.peerAid)) {
|
|
565
|
+
throw roleError('NOT_ALLOWED', 'Owner assignments cannot be changed through relations', self, {
|
|
566
|
+
kind: 'owner_protected', targetAid: target.peerAid,
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
return withAgentMutation(self, async () => {
|
|
570
|
+
const current = readRelation(target.peerKey, self);
|
|
571
|
+
const relation = clone(current?.config ?? { $schema_version: currentVersion('relation-config') });
|
|
572
|
+
relation.targetKind = 'private';
|
|
573
|
+
relation.role = roleId;
|
|
574
|
+
const normalized = normalizeRelationForScene(relation, 'private');
|
|
575
|
+
const changed = stableStringify(current?.config ?? null) !== stableStringify(normalized);
|
|
576
|
+
if (changed)
|
|
577
|
+
write(ConfigTarget.Relation, normalized, { self, peerKey: target.peerKey });
|
|
578
|
+
return {
|
|
579
|
+
changed,
|
|
580
|
+
relationRevision: changed ? revision(normalized) : current?.revision ?? null,
|
|
581
|
+
roleId,
|
|
582
|
+
};
|
|
583
|
+
});
|
|
584
|
+
}
|
|
547
585
|
async function updateAdminAssignment(context, args, value) {
|
|
548
586
|
const self = context.self;
|
|
549
587
|
if (!isDaemonOwnerControl(context) && context.actorRole !== 'owner') {
|
|
@@ -777,7 +815,10 @@ async function assignmentInventory(context, args, policyRevision) {
|
|
|
777
815
|
}
|
|
778
816
|
async function targetSnapshot(context, args, policyRevision) {
|
|
779
817
|
const self = context.self;
|
|
780
|
-
const
|
|
818
|
+
const normalized = normalizeTarget(args?.target, self);
|
|
819
|
+
const target = context.fromControlChannel
|
|
820
|
+
? normalized
|
|
821
|
+
: await validateTargetExists(context, normalized, { allowAuthenticatedPrivateActor: true });
|
|
781
822
|
const relation = readRelation(target.peerKey, self);
|
|
782
823
|
const roleView = targetRoleView(self, target, relation?.config ?? null);
|
|
783
824
|
const override = target.kind === 'private'
|
|
@@ -796,6 +837,65 @@ async function targetSnapshot(context, args, policyRevision) {
|
|
|
796
837
|
relationConfig: relationConfigView(context, target, relation?.config ?? null),
|
|
797
838
|
};
|
|
798
839
|
}
|
|
840
|
+
function memberSnapshot(context, args, policyRevision) {
|
|
841
|
+
const self = context.self;
|
|
842
|
+
const groupId = stringArg(args?.groupId);
|
|
843
|
+
const peerAid = stringArg(args?.peerAid ?? args?.memberAid);
|
|
844
|
+
if (!groupId || !peerAid) {
|
|
845
|
+
throw validationFailed(self, undefined, [
|
|
846
|
+
...(!groupId ? [{ field: 'groupId', code: 'MISSING_FIELD', message: 'groupId is required' }] : []),
|
|
847
|
+
...(!peerAid ? [{ field: 'peerAid', code: 'MISSING_FIELD', message: 'peerAid is required' }] : []),
|
|
848
|
+
]);
|
|
849
|
+
}
|
|
850
|
+
if (groupId.length > 512 || !isValidAid(groupId)) {
|
|
851
|
+
throw invalidTargetValue(self, 'groupId');
|
|
852
|
+
}
|
|
853
|
+
if (peerAid.length > 512 || !isValidAid(peerAid))
|
|
854
|
+
throw invalidTargetValue(self, 'peerAid');
|
|
855
|
+
const peerType = stringArg(args?.peerType);
|
|
856
|
+
if (peerType.length > 128)
|
|
857
|
+
throw invalidTargetValue(self, 'peerType');
|
|
858
|
+
const groupTarget = { kind: 'group', groupId, peerKey: formatPeerKey('aun', groupId) };
|
|
859
|
+
const privateTarget = { kind: 'private', peerAid, peerKey: formatPeerKey('aun', peerAid) };
|
|
860
|
+
const detail = resolvePeerRoleDetail({
|
|
861
|
+
selfAid: self,
|
|
862
|
+
channelKey: `aun#${self}#main`,
|
|
863
|
+
channelType: 'aun',
|
|
864
|
+
chatType: 'group',
|
|
865
|
+
actorId: peerAid,
|
|
866
|
+
conversationId: groupId,
|
|
867
|
+
peerType: peerType || undefined,
|
|
868
|
+
});
|
|
869
|
+
const role = roleResult(detail.effectiveRole, detail.source, self);
|
|
870
|
+
const assignment = detail.source === 'relation-actor'
|
|
871
|
+
? explicitAssignment('group-member', privateTarget.peerKey, detail.effectiveRole, { groupId, peerId: peerAid })
|
|
872
|
+
: detail.source === 'relation-peer'
|
|
873
|
+
? explicitAssignment('group', groupTarget.peerKey, detail.effectiveRole, { groupId })
|
|
874
|
+
: undefined;
|
|
875
|
+
return {
|
|
876
|
+
$schema_version: ROLE_MENU_SCHEMA_VERSION,
|
|
877
|
+
self,
|
|
878
|
+
policyRevision,
|
|
879
|
+
groupId,
|
|
880
|
+
peerAid,
|
|
881
|
+
role,
|
|
882
|
+
effectiveRole: role,
|
|
883
|
+
source: detail.source,
|
|
884
|
+
...(assignment ? { assignment } : {}),
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
function explicitAssignment(scope, peerKey, role, ids) {
|
|
888
|
+
if (!role)
|
|
889
|
+
return undefined;
|
|
890
|
+
return {
|
|
891
|
+
scope,
|
|
892
|
+
peerKey,
|
|
893
|
+
role,
|
|
894
|
+
...(ids.peerId ? { peerId: ids.peerId } : {}),
|
|
895
|
+
...(ids.groupId ? { groupId: ids.groupId } : {}),
|
|
896
|
+
source: 'relation-config',
|
|
897
|
+
};
|
|
898
|
+
}
|
|
799
899
|
async function targetList(context, args) {
|
|
800
900
|
const self = context.self;
|
|
801
901
|
const targetType = stringArg(args?.targetType);
|
|
@@ -901,9 +1001,10 @@ function localKnownRelationTargets(self) {
|
|
|
901
1001
|
if (chat.channelType !== 'aun' || chat.selfAID !== self)
|
|
902
1002
|
continue;
|
|
903
1003
|
const active = readJsonFile(path.join(chat.dirPath, 'active.json'));
|
|
904
|
-
|
|
1004
|
+
const kind = chatTargetKind(self, chat);
|
|
1005
|
+
if (kind === 'group')
|
|
905
1006
|
known.groups.add(String(active?.metadata?.groupId || chat.channelId));
|
|
906
|
-
else
|
|
1007
|
+
else if (kind === 'private')
|
|
907
1008
|
known.privates.add(String(active?.metadata?.peerId || chat.channelId));
|
|
908
1009
|
}
|
|
909
1010
|
return known;
|
|
@@ -914,6 +1015,9 @@ async function validateTargetExists(context, target, options = {}) {
|
|
|
914
1015
|
&& target.kind === 'private'
|
|
915
1016
|
&& context.chatType === 'private'
|
|
916
1017
|
&& context.actorAid === target.peerAid) {
|
|
1018
|
+
if (readAunPeerKind(context.self, target.peerAid, { routeKind: 'private' }).kind !== 'private') {
|
|
1019
|
+
throw roleError('TARGET_TYPE_UNKNOWN', 'Authenticated peer type conflicts with stored evidence', context.self, { kind: 'target_type_unknown', target });
|
|
1020
|
+
}
|
|
917
1021
|
return target;
|
|
918
1022
|
}
|
|
919
1023
|
const directory = roleDirectory(context);
|
|
@@ -924,13 +1028,16 @@ async function validateTargetExists(context, target, options = {}) {
|
|
|
924
1028
|
kind: 'target_not_found', target,
|
|
925
1029
|
});
|
|
926
1030
|
}
|
|
927
|
-
const declaredType = lookup.content?.match(/^type:\s*["']?([^"'\r\n]+)["']?\s*$/mi)?.[1]?.trim().toLowerCase();
|
|
928
1031
|
const groupProbe = await directory.getGroup({ from: context.self, groupId: target.peerAid, required: ['member'] });
|
|
929
|
-
|
|
1032
|
+
const identity = await resolveAunPeerKind(context.self, target.peerAid, context.chatType === 'private' && context.actorAid === target.peerAid ? { routeKind: 'private' } : {});
|
|
1033
|
+
if (identity.kind === 'group' || (groupProbe.ok && groupProbe.found)) {
|
|
930
1034
|
throw roleError('INVALID_ARGUMENT', 'Private Role target resolves to a group', context.self, {
|
|
931
1035
|
kind: 'target_kind_mismatch', target,
|
|
932
1036
|
});
|
|
933
1037
|
}
|
|
1038
|
+
if (identity.kind !== 'private') {
|
|
1039
|
+
throw roleError('TARGET_TYPE_UNKNOWN', `Cannot establish private Role target type (${identity.reason})`, context.self, { kind: 'target_type_unknown', target });
|
|
1040
|
+
}
|
|
934
1041
|
return target;
|
|
935
1042
|
}
|
|
936
1043
|
const info = await directory.getGroup({ from: context.self, groupId: target.groupId, required: ['member', 'state'] });
|
|
@@ -947,6 +1054,9 @@ async function validateTargetExists(context, target, options = {}) {
|
|
|
947
1054
|
});
|
|
948
1055
|
}
|
|
949
1056
|
const canonicalGroupId = group.group_aid || group.group_id || target.groupId;
|
|
1057
|
+
if (readAunPeerKind(context.self, canonicalGroupId, { routeKind: 'group' }).kind !== 'group') {
|
|
1058
|
+
throw roleError('TARGET_TYPE_UNKNOWN', 'Joined group type conflicts with stored evidence', context.self, { kind: 'target_type_unknown', target });
|
|
1059
|
+
}
|
|
950
1060
|
return canonicalGroupId === target.groupId
|
|
951
1061
|
? target
|
|
952
1062
|
: { ...target, groupId: canonicalGroupId, peerKey: formatPeerKey('aun', canonicalGroupId) };
|
|
@@ -954,7 +1064,7 @@ async function validateTargetExists(context, target, options = {}) {
|
|
|
954
1064
|
function privateHistoryTargets(self) {
|
|
955
1065
|
const aggregate = new Map();
|
|
956
1066
|
for (const chat of scanChatDirs(resolvePaths().sessionsDir)) {
|
|
957
|
-
if (chat.channelType !== 'aun' || chat.selfAID !== self ||
|
|
1067
|
+
if (chat.channelType !== 'aun' || chat.selfAID !== self || chatTargetKind(self, chat) !== 'private')
|
|
958
1068
|
continue;
|
|
959
1069
|
const sessions = [];
|
|
960
1070
|
const active = readJsonFile(path.join(chat.dirPath, 'active.json'));
|
|
@@ -991,16 +1101,25 @@ function privateHistoryTargets(self) {
|
|
|
991
1101
|
};
|
|
992
1102
|
}).sort((a, b) => a.peerKey.localeCompare(b.peerKey));
|
|
993
1103
|
}
|
|
994
|
-
function
|
|
995
|
-
if (isExplicitGroupId(chat.channelId))
|
|
996
|
-
return true;
|
|
1104
|
+
function chatTargetKind(self, chat) {
|
|
997
1105
|
const active = readJsonFile(path.join(chat.dirPath, 'active.json'));
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1106
|
+
const sessions = active ? [active] : scanMetaFiles(chat.dirPath)
|
|
1107
|
+
.map(metaFile => readLastJsonlLine(path.join(chat.dirPath, metaFile))).filter(Boolean);
|
|
1108
|
+
let routeKind;
|
|
1109
|
+
for (const session of sessions) {
|
|
1110
|
+
const kind = resolveAunTargetKind({
|
|
1111
|
+
routeKind: session.chatType,
|
|
1112
|
+
targetKind: session.metadata?.groupId ? 'group' : undefined,
|
|
1113
|
+
});
|
|
1114
|
+
if (kind.reason === 'conflict' || kind.reason === 'invalid')
|
|
1115
|
+
return 'unknown';
|
|
1116
|
+
if (kind.kind !== 'unknown') {
|
|
1117
|
+
if (routeKind && routeKind !== kind.kind)
|
|
1118
|
+
return 'unknown';
|
|
1119
|
+
routeKind = kind.kind;
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
return readAunPeerKind(self, chat.channelId, { routeKind }).kind;
|
|
1004
1123
|
}
|
|
1005
1124
|
function assignmentResponse(self, target, config, changed, relationRevision) {
|
|
1006
1125
|
return {
|
|
@@ -1021,7 +1140,7 @@ function normalizeTarget(value, self) {
|
|
|
1021
1140
|
const peerAid = stringArg(value.peerAid);
|
|
1022
1141
|
if (!peerAid)
|
|
1023
1142
|
throw invalidTarget(self, 'target.peerAid');
|
|
1024
|
-
if (!isValidAid(peerAid)
|
|
1143
|
+
if (!isValidAid(peerAid))
|
|
1025
1144
|
throw invalidTargetValue(self, 'target.peerAid');
|
|
1026
1145
|
return { kind, peerAid, peerKey: formatPeerKey('aun', peerAid) };
|
|
1027
1146
|
}
|
|
@@ -1029,7 +1148,7 @@ function normalizeTarget(value, self) {
|
|
|
1029
1148
|
const groupId = stringArg(value.groupId);
|
|
1030
1149
|
if (!groupId)
|
|
1031
1150
|
throw invalidTarget(self, 'target.groupId');
|
|
1032
|
-
if (!isValidAid(groupId)
|
|
1151
|
+
if (!isValidAid(groupId))
|
|
1033
1152
|
throw invalidTargetValue(self, 'target.groupId');
|
|
1034
1153
|
return { kind, groupId, peerKey: formatPeerKey('aun', groupId) };
|
|
1035
1154
|
}
|
|
@@ -1339,7 +1458,7 @@ function listRelations(self, known = { groups: new Set(), privates: new Set() })
|
|
|
1339
1458
|
const config = read(ConfigTarget.Relation, { self, peerKey: entry.name }, { cache: false });
|
|
1340
1459
|
if (!config)
|
|
1341
1460
|
continue;
|
|
1342
|
-
const targetKind = relationTargetKind(config, parsed.channelId, known);
|
|
1461
|
+
const targetKind = relationTargetKind(self, config, parsed.channelId, known, parsed.channelType);
|
|
1343
1462
|
records.push({
|
|
1344
1463
|
peerKey: entry.name,
|
|
1345
1464
|
config,
|
|
@@ -1356,17 +1475,16 @@ function readRelation(peerKey, self) {
|
|
|
1356
1475
|
if (!config)
|
|
1357
1476
|
return null;
|
|
1358
1477
|
const parsed = parsePeerKey(peerKey);
|
|
1359
|
-
const targetKind = relationTargetKind(config, parsed.channelId);
|
|
1478
|
+
const targetKind = relationTargetKind(self, config, parsed.channelId, undefined, parsed.channelType);
|
|
1360
1479
|
return { peerKey, config, revision: revision(config), ...parsed, targetKind, isGroup: targetKind === 'group' };
|
|
1361
1480
|
}
|
|
1362
|
-
function relationTargetKind(config, channelId, known = { groups: new Set(), privates: new Set() }) {
|
|
1363
|
-
if (
|
|
1364
|
-
return config.targetKind;
|
|
1365
|
-
if (known.groups.has(channelId)
|
|
1366
|
-
return '
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
return 'unknown';
|
|
1481
|
+
function relationTargetKind(self, config, channelId, known = { groups: new Set(), privates: new Set() }, channelType = 'aun') {
|
|
1482
|
+
if (channelType !== 'aun')
|
|
1483
|
+
return resolveAunTargetKind({ targetKind: config.targetKind }).kind;
|
|
1484
|
+
if (known.groups.has(channelId) && known.privates.has(channelId))
|
|
1485
|
+
return 'unknown';
|
|
1486
|
+
const routeKind = known.groups.has(channelId) ? 'group' : known.privates.has(channelId) ? 'private' : undefined;
|
|
1487
|
+
return readAunPeerKind(self, channelId, { relation: config, routeKind }).kind;
|
|
1370
1488
|
}
|
|
1371
1489
|
function countRoleUsage(self, relations, roleId) {
|
|
1372
1490
|
const configuredDefaults = effectiveDefaultRoles(self);
|
|
@@ -47,22 +47,25 @@ const commands = ['/new', '/pwd', '/help', '/evolhelp', '/status', '/restart', '
|
|
|
47
47
|
const deprecatedCommands = ['/clear'];
|
|
48
48
|
commands.push('/diag');
|
|
49
49
|
const exactBoundaryCommands = new Set(['/pause', '/resume', '/stop', '/pair', '/diag']);
|
|
50
|
-
/** Parse
|
|
50
|
+
/** Parse fullaccess controls and one-shot prompts without command-prefix ambiguity. */
|
|
51
51
|
export function parseFullAccessCommand(content) {
|
|
52
52
|
const match = content.match(/^\s*(\/fa|\/fullaccess)(?=\s|$)([\s\S]*)$/);
|
|
53
53
|
if (!match)
|
|
54
54
|
return { matched: false };
|
|
55
|
+
const raw = match[2].trim();
|
|
56
|
+
const command = match[1];
|
|
57
|
+
if (raw === '')
|
|
58
|
+
return { matched: true, command, action: 'status', raw };
|
|
59
|
+
if (raw === 'on')
|
|
60
|
+
return { matched: true, command, action: 'on', raw };
|
|
61
|
+
if (raw === 'off')
|
|
62
|
+
return { matched: true, command, action: 'off', raw };
|
|
55
63
|
return {
|
|
56
64
|
matched: true,
|
|
57
|
-
command
|
|
58
|
-
action:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
? 'on'
|
|
62
|
-
: match[2].trim() === 'off'
|
|
63
|
-
? 'off'
|
|
64
|
-
: 'invalid',
|
|
65
|
-
raw: match[2].trim(),
|
|
65
|
+
command,
|
|
66
|
+
action: 'prompt',
|
|
67
|
+
prompt: raw,
|
|
68
|
+
raw,
|
|
66
69
|
};
|
|
67
70
|
}
|
|
68
71
|
// 命令别名映射
|