evolcore 0.0.41-test.2 → 0.0.42-test.0
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 +38 -2
- package/bin/codex-managed-hook.mjs +9 -5
- package/dist/agents/baseagent.js +156 -16
- package/dist/agents/claude-runner.js +10 -3
- package/dist/agents/codex/catalog.js +8 -4
- package/dist/agents/codex-runner.js +236 -59
- package/dist/agents/ecagent-runner.js +82 -13
- package/dist/aun/aid/agentmd.js +106 -27
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/aid/control-aid.js +65 -13
- package/dist/aun/aid/identity.js +70 -4
- package/dist/aun/aid/index.js +2 -2
- package/dist/aun/service-proxy.js +25 -1
- package/dist/channels/aun.js +242 -209
- package/dist/channels/dingtalk.js +1 -1
- package/dist/channels/feishu.js +1 -1
- package/dist/channels/qqbot.js +1 -1
- package/dist/channels/wechat.js +1 -1
- package/dist/channels/wecom.js +1 -1
- package/dist/cli/agent-command.js +183 -3
- package/dist/cli/agent-create.js +92 -86
- package/dist/cli/agent.js +136 -1
- package/dist/cli/aun-commands.js +137 -35
- package/dist/cli/bench.js +8 -2
- package/dist/cli/command-log.js +1 -1
- package/dist/cli/daemon-commands.js +235 -51
- package/dist/cli/debug-mode.js +1 -1
- package/dist/cli/directory.js +170 -0
- package/dist/cli/index.js +40 -30
- package/dist/cli/init-channel.js +4 -4
- package/dist/cli/init.js +47 -32
- package/dist/cli/managed-command-guard.js +4 -1
- package/dist/cli/model.js +27 -18
- package/dist/cli/pa-workspace-command.js +191 -0
- package/dist/cli/{contact.js → peer.js} +19 -25
- package/dist/cli/restart-monitor.js +11 -4
- package/dist/cli/thread-command.js +47 -18
- package/dist/cli/version.js +18 -18
- package/dist/config/access-policy.js +29 -12
- package/dist/config/boot-log.js +65 -10
- package/dist/config/builtin-roles.js +2 -4
- package/dist/config/config-field-policy.js +3 -0
- package/dist/config/config-manager.js +28 -20
- package/dist/config/{contact-bind-code.js → peer-bind-code.js} +6 -6
- package/dist/config/{contact-book-store.js → peer-book-store.js} +75 -75
- package/dist/config/{contact-book-v2-startup.js → peer-book-v2-startup.js} +2 -2
- package/dist/config/{contact-book.js → peer-book.js} +47 -47
- package/dist/config/peer-operation-service.js +132 -0
- package/dist/config/{contact-request-service.js → peer-request-service.js} +90 -90
- package/dist/config/peer-role-resolver.js +3 -3
- package/dist/config/providers-config.js +17 -8
- package/dist/config/providers.js +1 -1
- package/dist/config/schema-migration.js +336 -39
- package/dist/core/agent-application-service.js +8 -2
- package/dist/core/agent-create-status.js +4 -5
- package/dist/core/agent-ipc-registration.js +5 -4
- package/dist/core/agent-runtime.js +30 -17
- package/dist/core/auth/operation-authorizer.js +0 -24
- package/dist/core/auth/operation-catalog.js +4 -20
- package/dist/core/baseagent-loader.js +27 -3
- package/dist/core/bootstrap-service.js +5 -22
- package/dist/core/capability/capability-manager.js +52 -35
- package/dist/core/channel-loader.js +43 -2
- package/dist/core/channel-runtime.js +2 -2
- package/dist/core/command/agent-control.js +54 -18
- package/dist/core/command/command-handler.js +92 -72
- package/dist/core/command/connect-menu.js +35 -42
- package/dist/core/command/daemon-diagnostics.js +41 -5
- package/dist/core/command/data-root-error.js +10 -0
- package/dist/core/command/data-root-resolver.js +53 -13
- package/dist/core/command/menu-catalog.js +1 -0
- package/dist/core/command/menu-handler.js +163 -65
- package/dist/core/command/menu-protocol.js +52 -0
- package/dist/core/command/pa-workspace-calendar.js +223 -0
- package/dist/core/command/pa-workspace-store.js +459 -0
- package/dist/core/command/role-menu.js +2 -2
- package/dist/core/command/slash-gate.js +1 -1
- package/dist/core/command/slash-handler.js +57 -41
- package/dist/core/daemon-lifecycle.js +90 -31
- package/dist/core/evolagent.js +6 -10
- package/dist/core/handoff/runtime.js +11 -4
- package/dist/core/host-snapshot.js +208 -0
- package/dist/core/initialization/service.js +152 -20
- package/dist/core/ipc-registration.js +33 -4
- package/dist/core/memory/batch-meta.js +27 -0
- package/dist/core/memory/consolidation-ops-records.js +44 -1
- package/dist/core/memory/consolidation.js +169 -27
- package/dist/core/message/aun-ipc-sender.js +2 -8
- package/dist/core/message/im-renderer.js +56 -3
- package/dist/core/message/message-admission.js +121 -124
- package/dist/core/message/message-bridge.js +38 -54
- package/dist/core/message/message-queue.js +7 -0
- package/dist/core/message/outbound.js +34 -9
- package/dist/core/message/response-engine.js +154 -73
- package/dist/core/model/catalog-service.js +1 -1
- package/dist/core/model/config-scope.js +2 -2
- package/dist/core/model/model-catalog.js +5 -4
- package/dist/core/model/model-diagnostics.js +6 -5
- package/dist/core/model/model-fallback.js +3 -6
- package/dist/core/model/model-permission.js +1 -1
- package/dist/core/ownership/owner-resolver.js +9 -9
- package/dist/core/permission/approval-gateway.js +1 -1
- package/dist/core/permission/ec-command-parser.js +2 -2
- package/dist/core/permission/tool-canonical.js +96 -46
- package/dist/core/permission/tool-error-code.js +41 -0
- package/dist/core/permission/tool-policy.js +71 -47
- package/dist/core/role/runtime-policy.js +1 -1
- package/dist/core/session/session-idle-monitor.js +10 -0
- package/dist/core/session/session-manager.js +2 -4
- package/dist/core/session/session-title.js +36 -8
- package/dist/core/system-session/memory.js +2 -7
- package/dist/core/thread/command-parser.js +6 -2
- package/dist/core/thread/ipc-operation.js +51 -36
- package/dist/core/thread/thread-operation.js +29 -61
- package/dist/core/thread/thread-service.js +57 -13
- package/dist/directory/canonical-digest.js +54 -0
- package/dist/directory/owner-directory-admission.js +114 -43
- package/dist/directory/owner-directory-agentmd-sync.js +89 -0
- package/dist/directory/owner-directory-cache.js +847 -459
- package/dist/directory/owner-directory-markdown.js +272 -0
- package/dist/directory/owner-directory-query-operation.js +195 -0
- package/dist/directory/owner-directory-remark-operation.js +147 -0
- package/dist/directory/owner-directory-remarks.js +145 -0
- package/dist/directory/owner-directory-scope.js +55 -0
- package/dist/directory/owner-directory-search.js +148 -0
- package/dist/directory/owner-directory-store.js +227 -0
- package/dist/eck/kit-renderer.js +1 -0
- package/dist/ecweb/basic-settings-service.js +4 -1
- package/dist/ecweb/message-context-service.js +13 -9
- package/dist/index.js +195 -37
- package/dist/ipc.js +86 -22
- package/dist/paths.js +11 -8
- package/dist/product.js +2 -0
- package/dist/proxy/manager.js +13 -2
- package/dist/proxy/service-supervisor.js +8 -1
- package/dist/trigger/history.js +23 -0
- package/dist/trigger/scheduler.js +3 -0
- package/dist/utils/atomic-write.js +21 -0
- package/dist/utils/cross-platform.js +35 -0
- package/dist/utils/ecweb-supervisor.js +42 -0
- package/dist/utils/error-utils.js +2 -1
- package/dist/utils/evolcore-version.js +19 -0
- package/dist/utils/host-info.js +242 -5
- package/dist/utils/instance-registry.js +28 -6
- package/dist/utils/logger.js +59 -14
- package/dist/utils/machine-info.js +46 -0
- package/dist/utils/process-introspect.js +166 -2
- package/dist/utils/startup-trace.js +245 -0
- package/ecagent/dist/agent-loop.js +27 -13
- package/ecagent/dist/harness/agent-harness.js +3 -3
- package/ecagent/dist/harness/types.d.ts +1 -0
- package/ecagent/dist/types.d.ts +1 -0
- package/kits/docs/INDEX.md +1 -1
- package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +72 -0
- package/kits/docs/evolcore/INDEX.md +3 -2
- package/kits/docs/evolcore/agent-create.md +17 -27
- package/kits/docs/evolcore/agent.md +4 -1
- package/kits/docs/evolcore/aid.md +3 -1
- package/kits/docs/evolcore/config.md +16 -5
- package/kits/docs/evolcore/ctl.md +9 -0
- package/kits/docs/evolcore/ec-capabilities.md +19 -0
- package/kits/docs/evolcore/memory-consolidation-batches.md +79 -5
- package/kits/docs/evolcore/menu-exec-schema-commands.md +2 -1
- package/kits/docs/evolcore/menu-protocol.md +1 -0
- package/kits/docs/evolcore/model.md +13 -4
- package/kits/docs/evolcore/msg.md +1 -1
- package/kits/docs/evolcore/pa-workspace.md +51 -0
- package/kits/docs/evolcore/peer.md +73 -0
- package/kits/docs/evolcore/thread-chain.md +4 -1
- package/kits/eck_manifest.json +21 -0
- package/kits/rules/06-channel.md +1 -1
- package/kits/schemas/_meta.json +12 -1
- package/kits/schemas/agent-config.schema.16.json +6 -0
- package/kits/schemas/agent-config.schema.17.json +897 -0
- package/kits/schemas/daemon.schema.9.json +8 -1
- package/kits/skills/ec-agent-create/SKILL.md +2 -2
- package/kits/skills/ec-identity/SKILL.md +45 -27
- package/kits/skills/ec-service-proxy/SKILL.md +7 -2
- package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +4 -5
- package/kits/skills/thread-ops/SKILL.md +11 -11
- package/kits/templates/bootstrap-welcome.md +3 -15
- package/kits/templates/message-fragments/item.md +1 -1
- package/kits/templates/system-fragments/bootstrap.md +24 -23
- package/kits/templates/system-fragments/commands.md +12 -5
- package/kits/templates/system-fragments/thread.md +18 -3
- package/package.json +6 -4
- package/dist/config/contact-operation-service.js +0 -235
- package/dist/directory/owner-directory-authorization.js +0 -309
- package/kits/docs/evolcore/contact.md +0 -78
- /package/dist/config/{contact-alias.js → peer-alias.js} +0 -0
|
@@ -2,37 +2,37 @@ import crypto from 'crypto';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { isValidAid } from '../aun/aid/validation.js';
|
|
4
4
|
import { recordAunPeerRoute, resolveAunPeerKind } from '../core/relation/peer-identity.js';
|
|
5
|
-
import {
|
|
5
|
+
import { agentPeerOperations } from '../paths.js';
|
|
6
6
|
import { listStaticAgentAdmins, listStaticAgentOwners } from './peer-role-resolver.js';
|
|
7
7
|
import { listAgentOwners } from './access-policy.js';
|
|
8
|
-
import {
|
|
9
|
-
export const
|
|
10
|
-
export const
|
|
11
|
-
export const
|
|
12
|
-
export const
|
|
13
|
-
export const
|
|
14
|
-
export const
|
|
15
|
-
export const
|
|
16
|
-
export async function
|
|
8
|
+
import { PeerMutationError, mutatePeerBookPrepared, } from './peer-book-store.js';
|
|
9
|
+
export const PEER_REQUEST_TTL_MS = 20 * 60 * 1000;
|
|
10
|
+
export const PEER_REQUEST_WINDOW_MS = 60 * 60 * 1000;
|
|
11
|
+
export const PEER_REQUEST_MAX_PER_WINDOW = 3;
|
|
12
|
+
export const PEER_REQUEST_MAX_PENDING = 100;
|
|
13
|
+
export const PEER_REQUEST_MAX_RETAINED = 1000;
|
|
14
|
+
export const PEER_REQUEST_NOTE_MAX_LENGTH = 500;
|
|
15
|
+
export const PEER_REQUEST_ID_MAX_LENGTH = 128;
|
|
16
|
+
export async function mutatePeerWithOperation(input) {
|
|
17
17
|
const at = new Date(input.now ?? Date.now()).toISOString();
|
|
18
|
-
const logFile =
|
|
19
|
-
const result = await
|
|
20
|
-
if (input.expectedContactRevision !== undefined && input.expectedContactRevision !==
|
|
21
|
-
throw new
|
|
18
|
+
const logFile = agentPeerOperations(input.selfAid);
|
|
19
|
+
const result = await mutatePeerBookPrepared(input.selfAid, ({ peerRevision }) => {
|
|
20
|
+
if (input.expectedContactRevision !== undefined && input.expectedContactRevision !== peerRevision) {
|
|
21
|
+
throw new PeerMutationError('CONFLICT', 'Contact book changed since it was read', {
|
|
22
22
|
expectedContactRevision: input.expectedContactRevision,
|
|
23
|
-
|
|
23
|
+
peerRevision,
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
return {
|
|
27
27
|
mutation: input.mutation,
|
|
28
28
|
actor: input.actorId,
|
|
29
29
|
value: undefined,
|
|
30
|
-
beforeCommit: ({
|
|
30
|
+
beforeCommit: ({ peerRevision: nextRevision }) => operationLogChange(logFile, [operationRecord({
|
|
31
31
|
at,
|
|
32
32
|
op: input.operation,
|
|
33
33
|
primaryId: input.primaryId,
|
|
34
34
|
actorId: input.actorId,
|
|
35
|
-
|
|
35
|
+
peerRevision: nextRevision,
|
|
36
36
|
})]),
|
|
37
37
|
};
|
|
38
38
|
});
|
|
@@ -44,27 +44,27 @@ export async function mutateContactWithOperation(input) {
|
|
|
44
44
|
* Existing pending/declined entries are intentionally promoted here, while a
|
|
45
45
|
* blocked entry remains a hard stop and must be explicitly unblocked first.
|
|
46
46
|
*/
|
|
47
|
-
export async function
|
|
47
|
+
export async function addPeer(input) {
|
|
48
48
|
const primaryId = String(input.primaryId || '').trim();
|
|
49
49
|
if (!isValidAid(primaryId)) {
|
|
50
|
-
throw new
|
|
50
|
+
throw new PeerMutationError('INVALID_AID', `Invalid contact AID: ${primaryId}`);
|
|
51
51
|
}
|
|
52
52
|
const identity = await resolveAunPeerKind(input.selfAid, primaryId);
|
|
53
53
|
if (identity.kind !== 'private') {
|
|
54
|
-
throw new
|
|
54
|
+
throw new PeerMutationError(identity.kind === 'group' ? 'INVALID_AID' : 'CONTACT_TYPE_UNKNOWN', identity.kind === 'group' ? `Contact Book does not support group AID: ${primaryId}`
|
|
55
55
|
: `Cannot establish private contact type (${identity.reason}): ${primaryId}`);
|
|
56
56
|
}
|
|
57
57
|
const at = new Date(input.now ?? Date.now()).toISOString();
|
|
58
|
-
const logFile =
|
|
59
|
-
const result = await
|
|
60
|
-
if (input.expectedContactRevision !== undefined && input.expectedContactRevision !==
|
|
61
|
-
throw new
|
|
58
|
+
const logFile = agentPeerOperations(input.selfAid);
|
|
59
|
+
const result = await mutatePeerBookPrepared(input.selfAid, ({ contact, peerRevision }) => {
|
|
60
|
+
if (input.expectedContactRevision !== undefined && input.expectedContactRevision !== peerRevision) {
|
|
61
|
+
throw new PeerMutationError('CONFLICT', 'Contact book changed since it was read', {
|
|
62
62
|
expectedContactRevision: input.expectedContactRevision,
|
|
63
|
-
|
|
63
|
+
peerRevision,
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
if (contact.contacts[primaryId]?.status === 'blocked') {
|
|
67
|
-
throw new
|
|
67
|
+
throw new PeerMutationError('CONTACT_BLOCKED', `Contact is blocked: ${primaryId}`);
|
|
68
68
|
}
|
|
69
69
|
const mutations = [
|
|
70
70
|
{ type: 'set-status', primaryId, status: 'active' },
|
|
@@ -76,58 +76,58 @@ export async function addContact(input) {
|
|
|
76
76
|
mutation: mutations.length === 1 ? mutations[0] : { type: 'batch', mutations },
|
|
77
77
|
actor: input.actorId,
|
|
78
78
|
value: undefined,
|
|
79
|
-
beforeCommit: ({
|
|
79
|
+
beforeCommit: ({ peerRevision: nextRevision }) => operationLogChange(logFile, [operationRecord({
|
|
80
80
|
at,
|
|
81
81
|
op: 'manual-add',
|
|
82
82
|
primaryId,
|
|
83
83
|
actorId: input.actorId,
|
|
84
|
-
|
|
84
|
+
peerRevision: nextRevision,
|
|
85
85
|
})]),
|
|
86
86
|
};
|
|
87
87
|
});
|
|
88
88
|
const { value: _value, ...mutationResult } = result;
|
|
89
89
|
return mutationResult;
|
|
90
90
|
}
|
|
91
|
-
export async function
|
|
91
|
+
export async function submitPeerRequest(input) {
|
|
92
92
|
const applicantAid = String(input.applicantAid || '').trim();
|
|
93
93
|
const owners = listAgentOwners(input.selfAid);
|
|
94
94
|
if (!isValidAid(applicantAid)) {
|
|
95
|
-
return { code: 'invalid-applicant',
|
|
95
|
+
return { code: 'invalid-applicant', peerRevision: '' };
|
|
96
96
|
}
|
|
97
97
|
if (owners.includes(applicantAid)) {
|
|
98
|
-
return { code: 'owner',
|
|
98
|
+
return { code: 'owner', peerRevision: '' };
|
|
99
99
|
}
|
|
100
100
|
if (owners.length === 0) {
|
|
101
|
-
return { code: 'no-owner',
|
|
101
|
+
return { code: 'no-owner', peerRevision: '' };
|
|
102
102
|
}
|
|
103
103
|
const identity = input.routeKind
|
|
104
104
|
? recordAunPeerRoute(input.selfAid, applicantAid, input.routeKind)
|
|
105
105
|
: await resolveAunPeerKind(input.selfAid, applicantAid);
|
|
106
106
|
if (identity.kind !== 'private')
|
|
107
|
-
return { code: 'invalid-applicant',
|
|
107
|
+
return { code: 'invalid-applicant', peerRevision: '' };
|
|
108
108
|
const note = normalizeNote(input.note);
|
|
109
109
|
if (note === null) {
|
|
110
|
-
return { code: 'invalid-note',
|
|
110
|
+
return { code: 'invalid-note', peerRevision: '' };
|
|
111
111
|
}
|
|
112
112
|
const nowMs = input.now ?? Date.now();
|
|
113
113
|
const nowIso = new Date(nowMs).toISOString();
|
|
114
|
-
const logFile =
|
|
115
|
-
const result = await
|
|
114
|
+
const logFile = agentPeerOperations(input.selfAid);
|
|
115
|
+
const result = await mutatePeerBookPrepared(input.selfAid, ({ contact }) => {
|
|
116
116
|
const expiration = collectExpiredMutations(contact, nowMs);
|
|
117
117
|
const effectiveEntry = effectiveEntryAfterExpirations(contact.contacts[applicantAid], nowMs);
|
|
118
118
|
if (effectiveEntry?.status === 'blocked') {
|
|
119
|
-
return preparedWithExpirations(expiration, { code: 'blocked',
|
|
119
|
+
return preparedWithExpirations(expiration, { code: 'blocked', peerRevision: '' }, logFile);
|
|
120
120
|
}
|
|
121
121
|
if (effectiveEntry && (effectiveEntry.status === undefined || effectiveEntry.status === 'active')) {
|
|
122
|
-
return preparedWithExpirations(expiration, { code: 'already-contact',
|
|
122
|
+
return preparedWithExpirations(expiration, { code: 'already-contact', peerRevision: '' }, logFile);
|
|
123
123
|
}
|
|
124
124
|
const operations = readOperationLog(logFile);
|
|
125
|
-
const windowStart = nowMs -
|
|
125
|
+
const windowStart = nowMs - PEER_REQUEST_WINDOW_MS;
|
|
126
126
|
const recentCount = operations.filter(record => (record.primaryId === applicantAid
|
|
127
127
|
&& (record.op === 'request' || record.op === 'resubmit')
|
|
128
128
|
&& Date.parse(record.at) > windowStart
|
|
129
129
|
&& Date.parse(record.at) <= nowMs)).length;
|
|
130
|
-
if (recentCount >=
|
|
130
|
+
if (recentCount >= PEER_REQUEST_MAX_PER_WINDOW) {
|
|
131
131
|
return preparedWithExpirations(expiration, {
|
|
132
132
|
code: 'rate-limited',
|
|
133
133
|
...(effectiveEntry?.status === 'pending' && effectiveEntry.pendingRequest
|
|
@@ -137,24 +137,24 @@ export async function submitContactRequest(input) {
|
|
|
137
137
|
expiresAt: effectiveEntry.pendingRequest.expiresAt,
|
|
138
138
|
}
|
|
139
139
|
: {}),
|
|
140
|
-
|
|
140
|
+
peerRevision: '',
|
|
141
141
|
}, logFile);
|
|
142
142
|
}
|
|
143
143
|
const counts = countRequestRecordsAfterExpirations(contact, nowMs);
|
|
144
144
|
const isExistingPending = effectiveEntry?.status === 'pending';
|
|
145
|
-
if (!isExistingPending && (counts.pending >=
|
|
146
|
-
|| counts.retained >=
|
|
147
|
-
return preparedWithExpirations(expiration, { code: 'capacity',
|
|
145
|
+
if (!isExistingPending && (counts.pending >= PEER_REQUEST_MAX_PENDING
|
|
146
|
+
|| counts.retained >= PEER_REQUEST_MAX_RETAINED)) {
|
|
147
|
+
return preparedWithExpirations(expiration, { code: 'capacity', peerRevision: '' }, logFile);
|
|
148
148
|
}
|
|
149
149
|
const requestId = `creq_${crypto.randomUUID().replace(/-/g, '')}`;
|
|
150
|
-
const expiresAt = new Date(nowMs +
|
|
150
|
+
const expiresAt = new Date(nowMs + PEER_REQUEST_TTL_MS).toISOString();
|
|
151
151
|
const op = isExistingPending ? 'resubmit' : 'request';
|
|
152
152
|
const value = {
|
|
153
153
|
code: isExistingPending ? 'resubmitted' : 'submitted',
|
|
154
154
|
requestId,
|
|
155
155
|
submittedAt: nowIso,
|
|
156
156
|
expiresAt,
|
|
157
|
-
|
|
157
|
+
peerRevision: '',
|
|
158
158
|
};
|
|
159
159
|
const mutations = [
|
|
160
160
|
...expiration.mutations,
|
|
@@ -168,8 +168,8 @@ export async function submitContactRequest(input) {
|
|
|
168
168
|
mutation: { type: 'batch', mutations },
|
|
169
169
|
actor: applicantAid,
|
|
170
170
|
value,
|
|
171
|
-
beforeCommit: ({
|
|
172
|
-
...expiration.events.map(event => ({ ...event,
|
|
171
|
+
beforeCommit: ({ peerRevision }) => operationLogChange(logFile, [
|
|
172
|
+
...expiration.events.map(event => ({ ...event, peerRevision })),
|
|
173
173
|
operationRecord({
|
|
174
174
|
at: nowIso,
|
|
175
175
|
op,
|
|
@@ -178,19 +178,19 @@ export async function submitContactRequest(input) {
|
|
|
178
178
|
expiresAt,
|
|
179
179
|
sourceChannelKey: input.sourceChannelKey,
|
|
180
180
|
...(note ? { note } : {}),
|
|
181
|
-
|
|
181
|
+
peerRevision,
|
|
182
182
|
}),
|
|
183
183
|
]),
|
|
184
184
|
};
|
|
185
185
|
});
|
|
186
|
-
return { ...result.value,
|
|
186
|
+
return { ...result.value, peerRevision: result.peerRevision };
|
|
187
187
|
}
|
|
188
|
-
export async function
|
|
188
|
+
export async function reviewPeerRequest(input) {
|
|
189
189
|
const nowMs = input.now ?? Date.now();
|
|
190
190
|
const nowIso = new Date(nowMs).toISOString();
|
|
191
|
-
const logFile =
|
|
191
|
+
const logFile = agentPeerOperations(input.selfAid);
|
|
192
192
|
try {
|
|
193
|
-
const result = await
|
|
193
|
+
const result = await mutatePeerBookPrepared(input.selfAid, ({ contact, peerRevision }) => {
|
|
194
194
|
const owners = listStaticAgentOwners(input.selfAid, { fresh: true });
|
|
195
195
|
const admins = listStaticAgentAdmins(input.selfAid, { fresh: true });
|
|
196
196
|
const selectedManager = input.reviewerRole === undefined
|
|
@@ -200,14 +200,14 @@ export async function reviewContactRequest(input) {
|
|
|
200
200
|
&& ((input.reviewerRole === 'admin' && admins.includes(input.actorId))
|
|
201
201
|
|| (input.reviewerRole === 'owner' && owners.includes(input.actorId)));
|
|
202
202
|
if (!selectedManager && !managementReviewer) {
|
|
203
|
-
return preparedNoop({ code: 'forbidden',
|
|
203
|
+
return preparedNoop({ code: 'forbidden', peerRevision });
|
|
204
204
|
}
|
|
205
|
-
if (
|
|
206
|
-
return preparedNoop({ code: 'revision-conflict',
|
|
205
|
+
if (peerRevision !== input.expectedContactRevision) {
|
|
206
|
+
return preparedNoop({ code: 'revision-conflict', peerRevision });
|
|
207
207
|
}
|
|
208
208
|
const entry = contact.contacts[input.primaryId];
|
|
209
209
|
if (!entry || entry.status !== 'pending' || entry.pendingRequest?.id !== input.requestId) {
|
|
210
|
-
return preparedNoop({ code: 'request-stale',
|
|
210
|
+
return preparedNoop({ code: 'request-stale', peerRevision });
|
|
211
211
|
}
|
|
212
212
|
const requestMetadata = {
|
|
213
213
|
requestId: entry.pendingRequest.id,
|
|
@@ -223,13 +223,13 @@ export async function reviewContactRequest(input) {
|
|
|
223
223
|
return {
|
|
224
224
|
mutation,
|
|
225
225
|
actor: input.actorId,
|
|
226
|
-
value: { code: 'request-expired',
|
|
227
|
-
beforeCommit: ({
|
|
226
|
+
value: { code: 'request-expired', peerRevision, ...requestMetadata },
|
|
227
|
+
beforeCommit: ({ peerRevision: nextRevision }) => operationLogChange(logFile, [operationRecord({
|
|
228
228
|
at: nowIso,
|
|
229
229
|
op: 'expire',
|
|
230
230
|
primaryId: input.primaryId,
|
|
231
231
|
requestId: input.requestId,
|
|
232
|
-
|
|
232
|
+
peerRevision: nextRevision,
|
|
233
233
|
})]),
|
|
234
234
|
};
|
|
235
235
|
}
|
|
@@ -247,30 +247,30 @@ export async function reviewContactRequest(input) {
|
|
|
247
247
|
now: nowIso,
|
|
248
248
|
},
|
|
249
249
|
actor: input.actorId,
|
|
250
|
-
value: { code,
|
|
251
|
-
beforeCommit: ({
|
|
250
|
+
value: { code, peerRevision, ...requestMetadata },
|
|
251
|
+
beforeCommit: ({ peerRevision: nextRevision }) => operationLogChange(logFile, [operationRecord({
|
|
252
252
|
at: nowIso,
|
|
253
253
|
op: input.decision === 'approve' ? 'approve' : input.decision === 'reject' ? 'reject' : 'block',
|
|
254
254
|
primaryId: input.primaryId,
|
|
255
255
|
requestId: input.requestId,
|
|
256
256
|
actorId: input.actorId,
|
|
257
|
-
|
|
257
|
+
peerRevision: nextRevision,
|
|
258
258
|
})]),
|
|
259
259
|
};
|
|
260
260
|
});
|
|
261
|
-
return { ...result.value,
|
|
261
|
+
return { ...result.value, peerRevision: result.peerRevision };
|
|
262
262
|
}
|
|
263
263
|
catch (error) {
|
|
264
|
-
if (error instanceof
|
|
265
|
-
return { code: 'request-expired',
|
|
264
|
+
if (error instanceof PeerMutationError && error.code === 'REQUEST_EXPIRED') {
|
|
265
|
+
return { code: 'request-expired', peerRevision: input.expectedContactRevision };
|
|
266
266
|
}
|
|
267
267
|
throw error;
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
|
-
export async function
|
|
270
|
+
export async function expirePendingPeerRequests(selfAid, now = Date.now()) {
|
|
271
271
|
const nowIso = new Date(now).toISOString();
|
|
272
|
-
const logFile =
|
|
273
|
-
const result = await
|
|
272
|
+
const logFile = agentPeerOperations(selfAid);
|
|
273
|
+
const result = await mutatePeerBookPrepared(selfAid, ({ contact }) => {
|
|
274
274
|
const expiration = collectExpiredMutations(contact, now);
|
|
275
275
|
if (expiration.mutations.length === 0)
|
|
276
276
|
return preparedNoop(0);
|
|
@@ -278,26 +278,26 @@ export async function expirePendingContactRequests(selfAid, now = Date.now()) {
|
|
|
278
278
|
mutation: { type: 'batch', mutations: expiration.mutations },
|
|
279
279
|
actor: 'contact-request-expiry',
|
|
280
280
|
value: expiration.mutations.length,
|
|
281
|
-
beforeCommit: ({
|
|
281
|
+
beforeCommit: ({ peerRevision }) => operationLogChange(logFile, expiration.events.map(event => ({ ...event, peerRevision }))),
|
|
282
282
|
};
|
|
283
283
|
});
|
|
284
284
|
return result.value;
|
|
285
285
|
}
|
|
286
|
-
export async function
|
|
287
|
-
await
|
|
288
|
-
const result = await
|
|
286
|
+
export async function listPendingPeerRequests(selfAid, now = Date.now()) {
|
|
287
|
+
await expirePendingPeerRequests(selfAid, now);
|
|
288
|
+
const result = await mutatePeerBookPrepared(selfAid, ({ contact, peerRevision }) => preparedNoop(Object.entries(contact.contacts)
|
|
289
289
|
.filter(([, entry]) => entry.status === 'pending' && entry.pendingRequest)
|
|
290
290
|
.map(([primaryId, entry]) => ({
|
|
291
291
|
primaryId,
|
|
292
292
|
requestId: entry.pendingRequest.id,
|
|
293
293
|
submittedAt: entry.pendingRequest.submittedAt,
|
|
294
294
|
expiresAt: entry.pendingRequest.expiresAt,
|
|
295
|
-
|
|
295
|
+
peerRevision,
|
|
296
296
|
}))));
|
|
297
297
|
return result.value;
|
|
298
298
|
}
|
|
299
299
|
/** Return only the authenticated applicant's own admission/request state. */
|
|
300
|
-
export async function
|
|
300
|
+
export async function queryOwnPeerRequestStatus(input) {
|
|
301
301
|
const applicantAid = String(input.applicantAid || '').trim();
|
|
302
302
|
if (!isValidAid(applicantAid))
|
|
303
303
|
return protocolResult('NOT_ALLOWED');
|
|
@@ -307,12 +307,12 @@ export async function queryOwnContactRequestStatus(input) {
|
|
|
307
307
|
return protocolResult('NOT_ALLOWED');
|
|
308
308
|
const requestedRequestId = rawRequestId?.trim();
|
|
309
309
|
if (requestedRequestId !== undefined
|
|
310
|
-
&& (!requestedRequestId || requestedRequestId.length >
|
|
310
|
+
&& (!requestedRequestId || requestedRequestId.length > PEER_REQUEST_ID_MAX_LENGTH)) {
|
|
311
311
|
return protocolResult('NOT_ALLOWED');
|
|
312
312
|
}
|
|
313
313
|
const owners = listAgentOwners(input.selfAid);
|
|
314
|
-
const result = await
|
|
315
|
-
const logFile =
|
|
314
|
+
const result = await mutatePeerBookPrepared(input.selfAid, ({ contact }) => {
|
|
315
|
+
const logFile = agentPeerOperations(input.selfAid);
|
|
316
316
|
const expiration = collectExpiredMutations(contact, now);
|
|
317
317
|
const entry = effectiveEntryAfterExpirations(contact.contacts[applicantAid], now);
|
|
318
318
|
const operations = readOperationLog(logFile).filter(record => record.primaryId === applicantAid);
|
|
@@ -361,12 +361,12 @@ export async function queryOwnContactRequestStatus(input) {
|
|
|
361
361
|
mutation: { type: 'batch', mutations: expiration.mutations },
|
|
362
362
|
actor: 'contact-request-expiry',
|
|
363
363
|
value,
|
|
364
|
-
beforeCommit: ({
|
|
364
|
+
beforeCommit: ({ peerRevision }) => operationLogChange(logFile, expiration.events.map(event => ({ ...event, peerRevision }))),
|
|
365
365
|
};
|
|
366
366
|
});
|
|
367
367
|
return result.value;
|
|
368
368
|
}
|
|
369
|
-
export function
|
|
369
|
+
export function peerRequestSubmissionProtocolResult(result) {
|
|
370
370
|
const metadata = { requestId: result.requestId, expiresAt: result.expiresAt };
|
|
371
371
|
switch (result.code) {
|
|
372
372
|
case 'submitted':
|
|
@@ -381,14 +381,14 @@ export function contactRequestSubmissionProtocolResult(result) {
|
|
|
381
381
|
return protocolResult('NOT_ALLOWED', metadata);
|
|
382
382
|
}
|
|
383
383
|
}
|
|
384
|
-
export function
|
|
385
|
-
const records = readOperationLog(
|
|
384
|
+
export function findPeerRequestNote(selfAid, requestId) {
|
|
385
|
+
const records = readOperationLog(agentPeerOperations(selfAid));
|
|
386
386
|
return [...records].reverse().find(record => (record.requestId === requestId
|
|
387
387
|
&& (record.op === 'request' || record.op === 'resubmit')))?.note;
|
|
388
388
|
}
|
|
389
389
|
function normalizeNote(value) {
|
|
390
390
|
const note = String(value ?? '').trim();
|
|
391
|
-
if (note.length >
|
|
391
|
+
if (note.length > PEER_REQUEST_NOTE_MAX_LENGTH)
|
|
392
392
|
return null;
|
|
393
393
|
return note;
|
|
394
394
|
}
|
|
@@ -400,7 +400,7 @@ function requestMetadataFor(operations, requestId) {
|
|
|
400
400
|
return {
|
|
401
401
|
requestId,
|
|
402
402
|
expiresAt: submitted?.expiresAt
|
|
403
|
-
?? (Number.isFinite(submittedAt) ? new Date(submittedAt +
|
|
403
|
+
?? (Number.isFinite(submittedAt) ? new Date(submittedAt + PEER_REQUEST_TTL_MS).toISOString() : undefined),
|
|
404
404
|
};
|
|
405
405
|
}
|
|
406
406
|
function protocolResult(status, metadata = {}) {
|
|
@@ -429,7 +429,7 @@ function collectExpiredMutations(book, now) {
|
|
|
429
429
|
op: 'expire',
|
|
430
430
|
primaryId,
|
|
431
431
|
requestId: entry.pendingRequest.id,
|
|
432
|
-
|
|
432
|
+
peerRevision: '',
|
|
433
433
|
}));
|
|
434
434
|
}
|
|
435
435
|
return { mutations, events };
|
|
@@ -459,7 +459,7 @@ function preparedWithExpirations(expiration, value, logFile) {
|
|
|
459
459
|
mutation: { type: 'batch', mutations: expiration.mutations },
|
|
460
460
|
actor: 'contact-request-expiry',
|
|
461
461
|
value,
|
|
462
|
-
beforeCommit: ({
|
|
462
|
+
beforeCommit: ({ peerRevision }) => operationLogChange(logFile, expiration.events.map(event => ({ ...event, peerRevision }))),
|
|
463
463
|
};
|
|
464
464
|
}
|
|
465
465
|
function preparedNoop(value) {
|
|
@@ -473,7 +473,7 @@ function readOperationLog(file) {
|
|
|
473
473
|
catch (error) {
|
|
474
474
|
if (error?.code === 'ENOENT')
|
|
475
475
|
return [];
|
|
476
|
-
throw new
|
|
476
|
+
throw new PeerMutationError('CONTACT_OPERATION_LOG_INVALID', `Cannot read contact operation log: ${error instanceof Error ? error.message : String(error)}`);
|
|
477
477
|
}
|
|
478
478
|
const records = [];
|
|
479
479
|
for (const [index, line] of raw.split('\n').entries()) {
|
|
@@ -489,13 +489,13 @@ function readOperationLog(file) {
|
|
|
489
489
|
|| (record.expiresAt !== undefined && (!isValidIsoDate(record.expiresAt)))
|
|
490
490
|
|| (record.actorId !== undefined && typeof record.actorId !== 'string')
|
|
491
491
|
|| (record.sourceChannelKey !== undefined && typeof record.sourceChannelKey !== 'string')
|
|
492
|
-
|| (record.note !== undefined && (typeof record.note !== 'string' || record.note.length >
|
|
493
|
-
|| typeof record.
|
|
492
|
+
|| (record.note !== undefined && (typeof record.note !== 'string' || record.note.length > PEER_REQUEST_NOTE_MAX_LENGTH))
|
|
493
|
+
|| typeof record.peerRevision !== 'string')
|
|
494
494
|
throw new Error('invalid record');
|
|
495
495
|
records.push(record);
|
|
496
496
|
}
|
|
497
497
|
catch (error) {
|
|
498
|
-
throw new
|
|
498
|
+
throw new PeerMutationError('CONTACT_OPERATION_LOG_INVALID', `Invalid contact operation log record at line ${index + 1}: ${error instanceof Error ? error.message : String(error)}`);
|
|
499
499
|
}
|
|
500
500
|
}
|
|
501
501
|
return records;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import crypto from 'crypto';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import { agentConfig,
|
|
4
|
+
import { agentConfig, agentPeerConfig, agentRelationsDir } from '../paths.js';
|
|
5
5
|
import { formatPeerKey, parsePeerKey, readAunPeerKind } from '../core/relation/peer-identity.js';
|
|
6
6
|
import { hasTrustedPrincipal } from '../core/auth/authenticated-actor.js';
|
|
7
7
|
import { ConfigTarget, read } from './config-manager.js';
|
|
8
8
|
import { isManagementRole } from './builtin-roles.js';
|
|
9
9
|
import { getRoleDefinition, getRoleRank, normalizeDefaultRole, roleExists } from './roles.js';
|
|
10
10
|
import { getStoredRoleRegistry, roleRegistryExists } from './role-store.js';
|
|
11
|
-
import { resolvePrincipal } from './
|
|
11
|
+
import { resolvePrincipal } from './peer-book.js';
|
|
12
12
|
import { configuredOwnerList } from './owner-config.js';
|
|
13
13
|
import { tryParseChannelKey } from '../core/channel-loader.js';
|
|
14
14
|
import { isValidAid } from '../aun/aid/validation.js';
|
|
@@ -58,7 +58,7 @@ export function getFirstStaticAgentOwner(aid) {
|
|
|
58
58
|
}
|
|
59
59
|
/** Revision for security-sensitive owner/contact/relation authorization inputs. */
|
|
60
60
|
export function authorizationConfigRevision(aid) {
|
|
61
|
-
const fingerprints = [ownerResolver.revision(aid), fileRevision(agentConfig(aid)), fileRevision(
|
|
61
|
+
const fingerprints = [ownerResolver.revision(aid), fileRevision(agentConfig(aid)), fileRevision(agentPeerConfig(aid))];
|
|
62
62
|
const relations = agentRelationsDir(aid);
|
|
63
63
|
try {
|
|
64
64
|
for (const entry of fs.readdirSync(relations, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
@@ -47,14 +47,20 @@ export function providerServiceTypeForPurpose(purpose) {
|
|
|
47
47
|
return purpose === 'auxiliary' ? 'text' : purpose;
|
|
48
48
|
}
|
|
49
49
|
export function providerServiceTypesForBaseagent(baseagent) {
|
|
50
|
+
if (baseagent === 'ecagent')
|
|
51
|
+
return ['ecagent', 'text'];
|
|
50
52
|
return ['claude', 'codex', 'gemini'].includes(baseagent)
|
|
51
53
|
? [baseagent]
|
|
52
54
|
: [...new Set(['text', baseagent])];
|
|
53
55
|
}
|
|
54
|
-
export function providerServiceTypeForBaseagent(baseagent) {
|
|
55
|
-
|
|
56
|
+
export function providerServiceTypeForBaseagent(baseagent, provider) {
|
|
57
|
+
if (baseagent === 'ecagent') {
|
|
58
|
+
return provider?.services && !Object.hasOwn(provider.services, 'ecagent') && Object.hasOwn(provider.services, 'text')
|
|
59
|
+
? 'text' : 'ecagent';
|
|
60
|
+
}
|
|
61
|
+
return ['openclaw', 'hermes'].includes(baseagent) ? 'text' : baseagent;
|
|
56
62
|
}
|
|
57
|
-
function resolveProviderServiceTypeForBaseagent(baseagent, selectedServiceType) {
|
|
63
|
+
function resolveProviderServiceTypeForBaseagent(baseagent, selectedServiceType, provider) {
|
|
58
64
|
assertSafeRegistrySegment(baseagent, 'baseagent');
|
|
59
65
|
if (selectedServiceType !== undefined) {
|
|
60
66
|
assertSafeRegistrySegment(selectedServiceType, 'provider service type');
|
|
@@ -63,7 +69,7 @@ function resolveProviderServiceTypeForBaseagent(baseagent, selectedServiceType)
|
|
|
63
69
|
}
|
|
64
70
|
return selectedServiceType;
|
|
65
71
|
}
|
|
66
|
-
return providerServiceTypeForBaseagent(baseagent);
|
|
72
|
+
return providerServiceTypeForBaseagent(baseagent, provider);
|
|
67
73
|
}
|
|
68
74
|
const FIXED_STYLES = {
|
|
69
75
|
claude: 'claude',
|
|
@@ -280,15 +286,18 @@ export function resolveProviderService(providerId, serviceType, config) {
|
|
|
280
286
|
};
|
|
281
287
|
}
|
|
282
288
|
export function resolveProviderServiceForBaseagent(providerId, baseagent, preferredServiceType, config) {
|
|
283
|
-
const
|
|
289
|
+
const provider = Object.hasOwn(config.providers, providerId) ? config.providers[providerId] : undefined;
|
|
290
|
+
const serviceType = resolveProviderServiceTypeForBaseagent(baseagent, preferredServiceType, provider);
|
|
284
291
|
return resolveProviderService(providerId, serviceType, config);
|
|
285
292
|
}
|
|
286
|
-
export function resolveProviderModelOverrides(providerId, serviceType, config) {
|
|
293
|
+
export function resolveProviderModelOverrides(providerId, serviceType, config, baseagent) {
|
|
287
294
|
assertSafeRegistrySegment(providerId, 'provider id');
|
|
288
295
|
assertSafeRegistrySegment(serviceType, 'service type');
|
|
289
296
|
const provider = Object.hasOwn(config.providers, providerId) ? config.providers[providerId] : undefined;
|
|
290
297
|
if (!provider)
|
|
291
298
|
throw new Error(`Provider not found: ${providerId}`);
|
|
299
|
+
if (baseagent)
|
|
300
|
+
serviceType = providerServiceTypeForBaseagent(baseagent, provider);
|
|
292
301
|
const service = provider.services && Object.hasOwn(provider.services, serviceType) ? provider.services[serviceType] : undefined;
|
|
293
302
|
if (!service)
|
|
294
303
|
throw new Error(`Provider ${providerId} has no service: ${serviceType}`);
|
|
@@ -328,7 +337,7 @@ export function assertProviderSelectionWrite(next, previous, inherited, resolveM
|
|
|
328
337
|
if (changed) {
|
|
329
338
|
const serviceType = providerServiceTypeForBaseagent(baseagent);
|
|
330
339
|
if (selection.provider !== undefined) {
|
|
331
|
-
const modelOverrides = resolveModelOverrides(selection.provider, serviceType);
|
|
340
|
+
const modelOverrides = resolveModelOverrides(selection.provider, serviceType, baseagent);
|
|
332
341
|
if (selection.model && modelOverrides[selection.model]?.enabled === false) {
|
|
333
342
|
throw new Error(`Model ${selection.model} is disabled for provider ${selection.provider}`);
|
|
334
343
|
}
|
|
@@ -337,7 +346,7 @@ export function assertProviderSelectionWrite(next, previous, inherited, resolveM
|
|
|
337
346
|
const providerId = candidate?.provider ?? selection.provider;
|
|
338
347
|
if (!providerId || typeof candidate?.model !== 'string')
|
|
339
348
|
continue;
|
|
340
|
-
const modelOverrides = resolveModelOverrides(providerId, serviceType);
|
|
349
|
+
const modelOverrides = resolveModelOverrides(providerId, serviceType, baseagent);
|
|
341
350
|
if (modelOverrides[candidate.model]?.enabled === false) {
|
|
342
351
|
throw new Error(`Model ${candidate.model} is disabled for provider ${providerId}`);
|
|
343
352
|
}
|
package/dist/config/providers.js
CHANGED
|
@@ -18,5 +18,5 @@ export function resolveServiceSelection(selections, serviceType) {
|
|
|
18
18
|
return resolveSelection(selections, serviceType, resolveProviderService);
|
|
19
19
|
}
|
|
20
20
|
export function assertProviderSelectionWrite(next, previous = {}, inherited = {}) {
|
|
21
|
-
validateSelectionWrite(next, previous, inherited, (providerId, serviceType) => resolveModelOverrides(providerId, serviceType, readProvidersFile()));
|
|
21
|
+
validateSelectionWrite(next, previous, inherited, (providerId, serviceType, baseagent) => resolveModelOverrides(providerId, serviceType, readProvidersFile(), baseagent));
|
|
22
22
|
}
|