evolcore 0.0.47 → 0.0.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +90 -1
- package/bin/ec-build.mjs +86 -0
- package/dist/agent-template/jobs.js +12 -4
- package/dist/agent-template/runtime.js +143 -40
- package/dist/agent-template/service.js +66 -13
- package/dist/agents/baseagent.js +60 -20
- package/dist/agents/claude-runner.js +34 -17
- package/dist/agents/codex-runner.js +36 -17
- package/dist/agents/ecagent-runner.js +7 -4
- package/dist/agents/gemini-runner.js +5 -2
- package/dist/agents/runner-types.js +5 -21
- package/dist/aun/aid/agentmd.js +5 -1
- package/dist/aun/msg/p2p.js +2 -1
- package/dist/aun/service-proxy.js +4 -2
- package/dist/build-identity.json +1 -0
- package/dist/channels/aun.js +722 -295
- package/dist/channels/daemon.js +9 -25
- package/dist/cli/aun-commands.js +86 -51
- package/dist/cli/code-stats.js +19 -8
- package/dist/cli/command-log.js +1 -1
- package/dist/cli/daemon-commands.js +44 -43
- package/dist/cli/directory.js +13 -2
- package/dist/cli/ecmsg-gateway.js +5 -2
- package/dist/cli/index.js +9 -9
- package/dist/cli/init-channel.js +4 -6
- package/dist/cli/init.js +72 -50
- package/dist/cli/invoke-command.js +1 -1
- package/dist/cli/managed-command-guard.js +2 -0
- package/dist/cli/model.js +20 -5
- package/dist/cli/provider-command.js +74 -13
- package/dist/cli/quota.js +89 -0
- package/dist/cli/role.js +62 -17
- package/dist/cli/services-command.js +1 -0
- package/dist/cli/stats.js +3 -3
- package/dist/cli/team-workspace-command.js +56 -2
- package/dist/cli/thread-command.js +16 -51
- package/dist/config/boot-log.js +3 -9
- package/dist/config/builtin-roles.js +5 -7
- package/dist/config/config-field-policy.js +71 -1
- package/dist/config/config-manager.js +13 -7
- package/dist/config/daemon-services.js +30 -3
- package/dist/config/gateway-config.js +2 -2
- package/dist/config/invoke-ipc-service.js +6 -4
- package/dist/config/peer-bind-code.js +3 -4
- package/dist/config/peer-book-store.js +62 -229
- package/dist/config/peer-book.js +26 -27
- package/dist/config/peer-role-resolver.js +16 -1
- package/dist/config/provider-identity-migration.js +4 -1
- package/dist/config/provider-ipc-service.js +56 -11
- package/dist/config/provider-menu-request.js +24 -5
- package/dist/config/provider-templates.js +127 -0
- package/dist/config/providers-config.js +67 -12
- package/dist/config/providers-management.js +477 -51
- package/dist/config/resolved-config-op.js +3 -2
- package/dist/config/role-command-service.js +248 -1
- package/dist/config/schema-migration.js +105 -4
- package/dist/core/agent-application-service.js +6 -1
- package/dist/core/agent-runtime.js +4 -0
- package/dist/core/auth/agent-delegation.js +2 -1
- package/dist/core/auth/auth-gateway.js +2 -1
- package/dist/core/auth/delegation-authorization.js +36 -26
- package/dist/core/auth/operation-authorizer.js +25 -0
- package/dist/core/auth/operation-catalog.js +37 -64
- package/dist/core/capability/providers/codex-capability-provider.js +7 -8
- package/dist/core/channel-loader.js +18 -0
- package/dist/core/command/agent-control.js +32 -0
- package/dist/core/command/cli-intent-parser.js +13 -0
- package/dist/core/command/command-handler.js +126 -87
- package/dist/core/command/menu-catalog.js +1 -0
- package/dist/core/command/menu-handler.js +67 -150
- package/dist/core/command/menu-protocol.js +31 -1
- package/dist/core/command/provider-menu.js +13 -3
- package/dist/core/command/remote-shell.js +565 -0
- package/dist/core/command/role-menu.js +47 -23
- package/dist/core/command/slash-handler.js +26 -43
- package/dist/core/command/team-workspace-items.js +81 -12
- package/dist/core/command/team-workspace-team.js +9 -71
- package/dist/core/command/topic-slash.js +9 -30
- package/dist/core/daemon-bootstrap.js +8 -1
- package/dist/core/daemon-control.js +64 -8
- package/dist/core/daemon-lifecycle.js +16 -2
- package/dist/core/evolagent-registry.js +20 -3
- package/dist/core/file-integrity/store.js +2 -0
- package/dist/core/handoff/runtime.js +37 -1
- package/dist/core/inference/text-inference.js +3 -1
- package/dist/core/initialization/service.js +11 -6
- package/dist/core/interaction-router.js +3 -0
- package/dist/core/invoke/executors/text.js +72 -19
- package/dist/core/ipc-registration.js +3 -1
- package/dist/core/message/aun-ipc-sender.js +279 -107
- package/dist/core/message/contact-admission.js +91 -6
- package/dist/core/message/contact-pending-inbound.js +113 -0
- package/dist/core/message/contact-thread-approval.js +212 -0
- package/dist/core/message/im-renderer.js +41 -2
- package/dist/core/message/message-admission.js +5 -39
- package/dist/core/message/message-bridge.js +140 -370
- package/dist/core/message/message-log.js +29 -0
- package/dist/core/message/message-queue.js +119 -15
- package/dist/core/message/message-utils.js +8 -0
- package/dist/core/message/response-engine.js +580 -134
- package/dist/core/message/send-routing.js +5 -1
- package/dist/core/model/catalog-service.js +31 -11
- package/dist/core/model/config-scope.js +6 -14
- package/dist/core/model/model-capabilities.js +22 -4
- package/dist/core/model/model-catalog.js +1 -0
- package/dist/core/model/model-diagnostics.js +19 -0
- package/dist/core/model/model-fallback.js +13 -2
- package/dist/core/ownership/owner-resolver.js +328 -50
- package/dist/core/pack-auth.js +3 -0
- package/dist/core/pack-install.js +1 -1
- package/dist/core/permission/ec-command-parser.js +106 -19
- package/dist/core/permission/protected-paths.js +6 -6
- package/dist/core/permission/services-path-acl.js +451 -0
- package/dist/core/permission/tool-policy.js +5 -1
- package/dist/core/relation/peer-identity.js +36 -1
- package/dist/core/relation/same-owner-proof.js +81 -112
- package/dist/core/session/adapters/codex-session-file-adapter.js +96 -15
- package/dist/core/session/session-file-health.js +13 -7
- package/dist/core/session/session-fs-store.js +91 -35
- package/dist/core/session/session-manager.js +68 -24
- package/dist/core/session/session-mapper.js +14 -34
- package/dist/core/session/session-transcript.js +5 -1
- package/dist/core/task/task-activity-store.js +84 -0
- package/dist/core/task/task-recovery-service.js +13 -0
- package/dist/core/thread/command-parser.js +7 -12
- package/dist/core/thread/thread-context-storage.js +3 -2
- package/dist/core/thread/thread-operation.js +2 -13
- package/dist/core/thread/thread-service.js +15 -46
- package/dist/core/thread/topic-id.js +15 -0
- package/dist/directory/owner-directory-admission.js +12 -9
- package/dist/directory/owner-directory-cache.js +64 -28
- package/dist/directory/owner-directory-markdown.js +14 -2
- package/dist/directory/owner-directory-policy.js +5 -30
- package/dist/directory/owner-directory-query-operation.js +29 -3
- package/dist/directory/owner-directory-remarks.js +11 -3
- package/dist/directory/owner-directory-request-operation.js +5 -2
- package/dist/eck/kit-renderer.js +1 -1
- package/dist/eck/message-renderer.js +112 -29
- package/dist/ecweb/basic-settings-service.js +3 -1
- package/dist/ecweb/message-context-service.js +1 -1
- package/dist/ecweb/pairing.js +4 -3
- package/dist/ecweb/providers-service.js +26 -1
- package/dist/ecweb/runtime/lifecycle.js +18 -8
- package/dist/ecweb/runtime/proxy-access.js +74 -0
- package/dist/ecweb/runtime/supervisor.js +36 -6
- package/dist/event-center/center-config.js +9 -5
- package/dist/event-center/dispatcher.js +10 -1
- package/dist/event-center/ipc-operation.js +19 -0
- package/dist/event-center/registry.js +29 -3
- package/dist/event-center/runtime.js +106 -11
- package/dist/event-center/script-runner.js +5 -5
- package/dist/index.js +96 -59
- package/dist/ipc.js +38 -3
- package/dist/outputs/authorization.js +16 -0
- package/dist/outputs/cards.js +336 -0
- package/dist/outputs/events.js +63 -0
- package/dist/outputs/protocol.js +103 -0
- package/dist/outputs/service.js +266 -0
- package/dist/paths.js +3 -0
- package/dist/proxy/manager.js +43 -13
- package/dist/services/index.js +114 -5
- package/dist/services/ipc-operation.js +88 -15
- package/dist/services/pack-manager.js +13 -1
- package/dist/services/router.js +21 -6
- package/dist/services/script-runner.js +5 -4
- package/dist/services/service-payload.js +13 -7
- package/dist/services/validation.js +1 -1
- package/dist/stats/budget.js +2 -2
- package/dist/stats/db.js +19 -0
- package/dist/stats/index.js +1 -1
- package/dist/stats/{price-resolver.js → model-resolver.js} +304 -23
- package/dist/stats/normalizer.js +2 -0
- package/dist/stats/query.js +35 -27
- package/dist/stats/quota-query.js +95 -0
- package/dist/stats/role-budget.js +5 -2
- package/dist/stats/writer.js +10 -6
- package/dist/trigger/audit.js +7 -0
- package/dist/trigger/authorization.js +105 -11
- package/dist/trigger/feedback.js +10 -0
- package/dist/trigger/history.js +37 -11
- package/dist/trigger/ipc-service.js +12 -1
- package/dist/trigger/manager.js +1 -0
- package/dist/trigger/scheduler.js +7 -5
- package/dist/trigger/script-executor.js +2 -1
- package/dist/trigger/script-sandbox.js +21 -3
- package/dist/trigger/validation.js +22 -0
- package/dist/utils/atomic-write.js +22 -8
- package/dist/utils/cross-platform.js +73 -26
- package/dist/utils/error-dict.json +94 -4
- package/dist/utils/error-utils.js +27 -4
- package/dist/utils/evolcore-version.js +36 -65
- package/dist/utils/host-info.js +100 -1
- package/dist/utils/msg-diag.js +1 -0
- package/dist/utils/npm-ops.js +43 -8
- package/dist/utils/process-introspect.js +12 -7
- package/dist/utils/process-tree.js +50 -2
- package/dist/utils/windows-shell-trust.js +2 -0
- package/dist/workbench/protocol.js +80 -0
- package/dist/workbench/service.js +359 -0
- package/ecagent/dist/types.d.ts +6 -2
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +4 -2
- package/kits/docs/evolcore/aid.md +25 -0
- package/kits/docs/evolcore/config.md +16 -1
- package/kits/docs/evolcore/directory.md +30 -12
- package/kits/docs/evolcore/ecweb-lifecycle.md +15 -0
- package/kits/docs/evolcore/model.md +10 -0
- package/kits/docs/evolcore/msg.md +9 -0
- package/kits/docs/evolcore/peer.md +19 -65
- package/kits/docs/evolcore/provider.md +124 -4
- package/kits/docs/evolcore/quota.md +54 -0
- package/kits/docs/evolcore/role.md +83 -0
- package/kits/docs/evolcore/services.md +6 -6
- package/kits/docs/evolcore/stats.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +1 -1
- package/kits/docs/evolcore/thread-chain.md +14 -15
- package/kits/docs/evolcore/tool-authorization.md +5 -0
- package/kits/docs/evolcore/trigger.md +12 -0
- package/kits/eck_message_manifest.json +12 -0
- package/kits/provider-templates.json +1213 -0
- package/kits/rules/04-relation.md +3 -3
- package/kits/schemas/_meta.json +14 -2
- package/kits/schemas/agent-config.schema.20.json +24 -0
- package/kits/schemas/contact-book.schema.4.json +52 -0
- package/kits/schemas/providers.schema.3.json +200 -0
- package/kits/skills/.switches.json +8 -0
- package/kits/skills/ability/references/calling.md +1 -1
- package/kits/skills/agent-output-cards/SKILL.md +57 -0
- package/kits/skills/ec-group/SKILL.md +2 -2
- package/kits/skills/ec-identity/SKILL.md +19 -72
- package/kits/skills/ec-provider/SKILL.md +270 -0
- package/kits/skills/ec-provider/scripts/check-model.mjs +80 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/skills/thread-ops/SKILL.md +34 -21
- package/kits/templates/message-fragments/group-batch-item.md +1 -1
- package/kits/templates/message-fragments/group-batch.md +1 -1
- package/kits/templates/message-fragments/inject-default.md +1 -1
- package/kits/templates/message-fragments/interrupt-insert.md +1 -0
- package/kits/templates/message-fragments/item-group.md +1 -1
- package/kits/templates/message-fragments/item-private.md +1 -1
- package/kits/templates/message-fragments/thread-context.md +1 -1
- package/kits/templates/message-fragments/trigger-session.md +1 -1
- package/kits/templates/message-fragments/trigger-thread-check.md +1 -1
- package/kits/templates/roles/admin.json +2 -19
- package/kits/templates/roles/member.json +0 -3
- package/kits/templates/roles/visitor.json +1 -0
- package/kits/templates/system-fragments/baseagent.md +6 -0
- package/kits/templates/system-fragments/commands.md +4 -3
- package/kits/templates/system-fragments/directory-contacts.md +3 -4
- package/kits/templates/system-fragments/managed-runtime.md +1 -1
- package/kits/templates/system-fragments/relation.md +1 -1
- package/kits/templates/system-fragments/thread.md +7 -5
- package/kits/templates/system-fragments/venue.md +11 -0
- package/package.json +6 -4
- package/scripts/agent-template/inspect.mjs +50 -11
- package/scripts/agent-template/shared/common.mjs +11 -6
- package/scripts/agent-template/shared/team-schema.json +6 -4
- package/scripts/agent-template/shared/template-contract.mjs +62 -11
- package/scripts/agent-template/shared/template-package.mjs +189 -21
- package/scripts/agent-template/shared/template-runtime.mjs +54 -6
- package/scripts/agent-template/shared/template.mjs +2 -2
- package/scripts/agent-template/team-pack.mjs +52 -14
- package/dist/cli/peer.js +0 -127
- package/dist/config/peer-operation-service.js +0 -132
- package/dist/config/peer-request-service.js +0 -532
- package/dist/core/command/connect-menu.js +0 -624
package/dist/cli/peer.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { resolvePaths } from '../paths.js';
|
|
2
|
-
import { loadAllAgents } from '../config-store.js';
|
|
3
|
-
import { executeResolvedPeerCommand, resolvePeerCommand, } from '../config/peer-operation-service.js';
|
|
4
|
-
import { daemonUnavailableMessage, queryDaemon } from './help.js';
|
|
5
|
-
import { AGENT_DELEGATION_TOKEN_ENV, readDelegationCredential } from '../core/auth/agent-delegation.js';
|
|
6
|
-
import { getArgValue, isHelpFlag, wantsHelp } from './help.js';
|
|
7
|
-
export async function cmdPeer(args) {
|
|
8
|
-
if (args.length === 0 || isHelpFlag(args[0]) || wantsHelp(args)) {
|
|
9
|
-
printHelp();
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
const json = getArgValue(args, '--format') === 'json';
|
|
13
|
-
if (process.env.EVOLCORE_SESSION_ID) {
|
|
14
|
-
try {
|
|
15
|
-
const result = await runManaged(args, json);
|
|
16
|
-
output(result, json);
|
|
17
|
-
}
|
|
18
|
-
catch (err) {
|
|
19
|
-
console.error(`❌ ${err.message ?? String(err)}`);
|
|
20
|
-
process.exitCode = 1;
|
|
21
|
-
}
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
if (!args.includes('--self') && isListCommand(args) && !process.env.EVOLCORE_SELF_AID?.trim()) {
|
|
25
|
-
output(await executeAggregateList(args), json);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const resolved = resolvePeerCommand(withDefaultSelf(args));
|
|
29
|
-
if (!resolved.ok) {
|
|
30
|
-
const message = resolved.code === 'INVALID_SELF' && !args.includes('--self')
|
|
31
|
-
? `${resolved.reason}; multiple local Agents are configured, add --self <agent-aid>`
|
|
32
|
-
: resolved.reason;
|
|
33
|
-
fail(message, resolved.code);
|
|
34
|
-
}
|
|
35
|
-
const result = await executeResolvedPeerCommand(resolved.command);
|
|
36
|
-
if (!result.ok)
|
|
37
|
-
fail(result.error, result.code, result.data);
|
|
38
|
-
output(result, json);
|
|
39
|
-
}
|
|
40
|
-
function output(value, json) {
|
|
41
|
-
if (json)
|
|
42
|
-
console.log(JSON.stringify(value));
|
|
43
|
-
else
|
|
44
|
-
console.log(JSON.stringify(value, null, 2));
|
|
45
|
-
}
|
|
46
|
-
async function runManaged(args, json) {
|
|
47
|
-
const sessionId = process.env.EVOLCORE_SESSION_ID;
|
|
48
|
-
const delegationToken = readDelegationCredential();
|
|
49
|
-
if (!delegationToken)
|
|
50
|
-
fail(`${AGENT_DELEGATION_TOKEN_ENV} is not set for the active task`, 'DELEGATION_REQUIRED');
|
|
51
|
-
const { response, transportError } = await queryDaemon(resolvePaths().socket, {
|
|
52
|
-
type: 'peer.op',
|
|
53
|
-
argv: ['peer', ...args],
|
|
54
|
-
sessionId,
|
|
55
|
-
delegationToken,
|
|
56
|
-
}, 10_000);
|
|
57
|
-
if (!response) {
|
|
58
|
-
fail(daemonUnavailableMessage(transportError, 'Unable to connect to the evolcore daemon'), 'DAEMON_UNAVAILABLE');
|
|
59
|
-
}
|
|
60
|
-
if (!response.ok || !response.result) {
|
|
61
|
-
fail(response.error || 'contact operation failed', response.code || 'CONTACT_AUTH_FAILED', response.data);
|
|
62
|
-
}
|
|
63
|
-
return response.result;
|
|
64
|
-
}
|
|
65
|
-
function fail(message, code = 'INVALID_ARGUMENT', data) {
|
|
66
|
-
const error = new Error(message);
|
|
67
|
-
error.code = code;
|
|
68
|
-
if (data !== undefined)
|
|
69
|
-
error.data = data;
|
|
70
|
-
throw error;
|
|
71
|
-
}
|
|
72
|
-
function printHelp() {
|
|
73
|
-
console.log(`用法:
|
|
74
|
-
ec peer block <primaryId> --self <agent-aid>
|
|
75
|
-
ec peer unblock <primaryId> --self <agent-aid>
|
|
76
|
-
ec peer list --blocked [--self <agent-aid>]
|
|
77
|
-
ec peer list --all [--self <agent-aid>]
|
|
78
|
-
|
|
79
|
-
Options:
|
|
80
|
-
--self <agent-aid> 本端 agent AID;省略时从当前运行环境推断
|
|
81
|
-
--blocked 仅列出已拉黑的对端
|
|
82
|
-
--all 列出所有已登记的对端身份
|
|
83
|
-
--format json 输出 JSON
|
|
84
|
-
--help, -h 显示帮助
|
|
85
|
-
|
|
86
|
-
添加联系人、审批联系人申请由 Evol App 名录流程处理。
|
|
87
|
-
发起 app-v1 加好友申请:ec directory request <target-aid> --self <agent-aid> [--note <申请介绍>]。`);
|
|
88
|
-
}
|
|
89
|
-
function withDefaultSelf(args) {
|
|
90
|
-
if (args.includes('--self'))
|
|
91
|
-
return args;
|
|
92
|
-
const selfAid = resolveStandaloneSelfAid();
|
|
93
|
-
return selfAid ? [...args, '--self', selfAid] : args;
|
|
94
|
-
}
|
|
95
|
-
function isListCommand(args) {
|
|
96
|
-
return args[0] === 'list';
|
|
97
|
-
}
|
|
98
|
-
async function executeAggregateList(args) {
|
|
99
|
-
const agents = loadAllAgents().agents.map(agent => agent.aid).filter(Boolean).sort();
|
|
100
|
-
const results = [];
|
|
101
|
-
for (const aid of agents) {
|
|
102
|
-
const resolved = resolvePeerCommand([...args, '--self', aid]);
|
|
103
|
-
if (!resolved.ok)
|
|
104
|
-
fail(resolved.reason, resolved.code);
|
|
105
|
-
const result = await executeResolvedPeerCommand(resolved.command);
|
|
106
|
-
if (!result.ok)
|
|
107
|
-
fail(result.error, result.code, result.data);
|
|
108
|
-
results.push(result);
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
ok: true,
|
|
112
|
-
operation: 'list',
|
|
113
|
-
filter: args.includes('--blocked') ? 'blocked' : 'all',
|
|
114
|
-
scope: 'all-agents',
|
|
115
|
-
agents: results,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
/** Resolve the local Agent identity for standalone CLI commands. */
|
|
119
|
-
export function resolveStandaloneSelfAid() {
|
|
120
|
-
const runtimeAid = process.env.EVOLCORE_SELF_AID?.trim();
|
|
121
|
-
if (runtimeAid)
|
|
122
|
-
return runtimeAid;
|
|
123
|
-
const agents = loadAllAgents().agents
|
|
124
|
-
.map(agent => agent.aid)
|
|
125
|
-
.filter(Boolean);
|
|
126
|
-
return agents.length === 1 ? agents[0] : undefined;
|
|
127
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import { isValidAid } from '../aun/aid/validation.js';
|
|
3
|
-
import { agentConfig } from '../paths.js';
|
|
4
|
-
import { getPeerSnapshot, resolvePeerView } from './peer-book.js';
|
|
5
|
-
import { PeerMutationError } from './peer-book-store.js';
|
|
6
|
-
import { mutatePeerWithOperation } from './peer-request-service.js';
|
|
7
|
-
/**
|
|
8
|
-
* `ec peer` 命令面。
|
|
9
|
-
*
|
|
10
|
-
* 只保留本 Agent 能自主决定的两件事:查看已有对端身份、拉黑/解除拉黑。
|
|
11
|
-
* 添加联系人、审批联系人申请都归 Owner——Owner 在其名录里直接维护,
|
|
12
|
-
* Agent 侧不再有自助入口,也不再持有 pending 状态机。
|
|
13
|
-
*/
|
|
14
|
-
export function resolvePeerCommand(argv) {
|
|
15
|
-
const args = argv[0] === 'peer' ? argv.slice(1) : [...argv];
|
|
16
|
-
const selfAid = String(argValue(args, '--self') || '').trim();
|
|
17
|
-
if (!isValidAid(selfAid))
|
|
18
|
-
return invalid('INVALID_SELF', '--self must be a valid Agent AID');
|
|
19
|
-
const positional = stripOptions(args);
|
|
20
|
-
const [command, subcommand, ...extra] = positional;
|
|
21
|
-
if (extra.length > 0)
|
|
22
|
-
return invalid('INVALID_ARGUMENT', `Unexpected peer arguments: ${extra.join(' ')}`);
|
|
23
|
-
if (command === 'list') {
|
|
24
|
-
if (subcommand !== undefined) {
|
|
25
|
-
return invalid('INVALID_ARGUMENT', 'peer list does not accept a positional argument');
|
|
26
|
-
}
|
|
27
|
-
const filter = args.includes('--blocked')
|
|
28
|
-
? 'blocked'
|
|
29
|
-
: args.includes('--all') ? 'all' : undefined;
|
|
30
|
-
if (!filter)
|
|
31
|
-
return invalid('INVALID_ARGUMENT', 'peer list requires --blocked or --all');
|
|
32
|
-
return {
|
|
33
|
-
ok: true,
|
|
34
|
-
command: { kind: 'list', operationId: 'peer.read', selfAid, filter, canonicalArgv: canonicalArgv(argv) },
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
if (command === 'block' || command === 'unblock') {
|
|
38
|
-
if (!isValidAid(subcommand || '')) {
|
|
39
|
-
return invalid('INVALID_AID', 'primaryId must be a valid individual AID');
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
ok: true,
|
|
43
|
-
command: {
|
|
44
|
-
kind: 'set-blocked',
|
|
45
|
-
operationId: 'peer.block',
|
|
46
|
-
selfAid,
|
|
47
|
-
primaryId: subcommand,
|
|
48
|
-
blocked: command === 'block',
|
|
49
|
-
canonicalArgv: canonicalArgv(argv),
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
return invalid('UNKNOWN_COMMAND', `Unknown peer command: ${positional.join(' ')}`);
|
|
54
|
-
}
|
|
55
|
-
export async function executeResolvedPeerCommand(command, actor = 'local-cli') {
|
|
56
|
-
if (!fs.existsSync(agentConfig(command.selfAid))) {
|
|
57
|
-
return { ok: false, code: 'AGENT_NOT_FOUND', error: `Agent does not exist: ${command.selfAid}` };
|
|
58
|
-
}
|
|
59
|
-
try {
|
|
60
|
-
if (command.kind === 'list') {
|
|
61
|
-
const snapshot = getPeerSnapshot(command.selfAid);
|
|
62
|
-
const ids = command.filter === 'blocked'
|
|
63
|
-
? [...snapshot.blockedIndex]
|
|
64
|
-
: [...snapshot.contacts.keys()];
|
|
65
|
-
const items = ids.sort().map(id => resolvePeerView(command.selfAid, id));
|
|
66
|
-
return {
|
|
67
|
-
ok: true,
|
|
68
|
-
operation: 'list',
|
|
69
|
-
selfAid: command.selfAid,
|
|
70
|
-
filter: command.filter,
|
|
71
|
-
peerRevision: snapshot.peerRevision,
|
|
72
|
-
items,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
if (command.kind === 'set-blocked') {
|
|
76
|
-
if (!getPeerSnapshot(command.selfAid).contacts.has(command.primaryId)) {
|
|
77
|
-
return { ok: false, code: 'NOT_FOUND', error: `Peer was not found: ${command.primaryId}` };
|
|
78
|
-
}
|
|
79
|
-
const result = await mutatePeerWithOperation({
|
|
80
|
-
selfAid: command.selfAid,
|
|
81
|
-
actorId: actor,
|
|
82
|
-
operation: command.blocked ? 'block' : 'unblock',
|
|
83
|
-
primaryId: command.primaryId,
|
|
84
|
-
mutation: {
|
|
85
|
-
type: 'set-status',
|
|
86
|
-
primaryId: command.primaryId,
|
|
87
|
-
status: command.blocked ? 'blocked' : 'active',
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
return {
|
|
91
|
-
ok: true,
|
|
92
|
-
operation: 'set-blocked',
|
|
93
|
-
selfAid: command.selfAid,
|
|
94
|
-
primaryId: command.primaryId,
|
|
95
|
-
blocked: command.blocked,
|
|
96
|
-
changed: result.changed,
|
|
97
|
-
peerRevision: result.peerRevision,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
return { ok: false, code: 'PEER_OPERATION_FAILED', error: 'Unsupported peer operation' };
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
if (error instanceof PeerMutationError) {
|
|
104
|
-
return { ok: false, code: error.code, error: error.message, ...(error.data ? { data: error.data } : {}) };
|
|
105
|
-
}
|
|
106
|
-
return { ok: false, code: 'PEER_OPERATION_FAILED', error: error instanceof Error ? error.message : String(error) };
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
function argValue(args, flag) {
|
|
110
|
-
const index = args.indexOf(flag);
|
|
111
|
-
return index >= 0 ? args[index + 1] : undefined;
|
|
112
|
-
}
|
|
113
|
-
function stripOptions(args) {
|
|
114
|
-
const result = [];
|
|
115
|
-
for (let index = 0; index < args.length; index += 1) {
|
|
116
|
-
const arg = args[index];
|
|
117
|
-
if (arg === '--self' || arg === '--format') {
|
|
118
|
-
index += 1;
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
if (arg === '--blocked' || arg === '--all')
|
|
122
|
-
continue;
|
|
123
|
-
result.push(arg);
|
|
124
|
-
}
|
|
125
|
-
return result;
|
|
126
|
-
}
|
|
127
|
-
function canonicalArgv(argv) {
|
|
128
|
-
return argv[0] === 'peer' ? [...argv] : ['peer', ...argv];
|
|
129
|
-
}
|
|
130
|
-
function invalid(code, reason) {
|
|
131
|
-
return { ok: false, code, reason };
|
|
132
|
-
}
|