evolcore 0.0.43-test.3 → 0.0.43-test.5
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 +82 -0
- package/bin/ecmsg.js +492 -0
- package/bin/install-codex-managed-hooks.mjs +130 -8
- package/dist/ability/application-service.js +37 -0
- package/dist/ability/resources.js +28 -0
- package/dist/ability/runtime.js +6 -1
- package/dist/agents/claude-runner.js +7 -5
- package/dist/agents/codex/app-server-client.js +0 -12
- package/dist/agents/codex-runner.js +12 -54
- package/dist/agents/ecagent-runner.js +130 -35
- package/dist/aun/aid/agentmd.js +56 -12
- package/dist/aun/aid/control-aid.js +15 -0
- package/dist/aun/aid/identity.js +8 -0
- package/dist/aun/aid/ownership-operation.js +12 -3
- package/dist/aun/menu/client.js +8 -7
- package/dist/aun/menu/index.js +1 -1
- package/dist/aun/menu/transport.js +8 -5
- package/dist/aun/service-proxy.js +3 -0
- package/dist/channels/aun.js +56 -22
- package/dist/channels/daemon.js +12 -4
- package/dist/cli/agent-command.js +5 -0
- package/dist/cli/agent-create.js +32 -8
- package/dist/cli/agent.js +9 -3
- package/dist/cli/aid-bind-command.js +3 -0
- package/dist/cli/aun-commands.js +12 -5
- package/dist/cli/code-stats.js +451 -213
- package/dist/cli/ctl-command.js +1 -3
- package/dist/cli/daemon-commands.js +42 -21
- package/dist/cli/directory.js +7 -8
- package/dist/cli/ecmsg-gateway.js +204 -0
- package/dist/cli/getmeta-command.js +2 -1
- package/dist/cli/index.js +6 -0
- package/dist/cli/init.js +58 -18
- package/dist/cli/provider-command.js +82 -5
- package/dist/cli/restart-monitor.js +11 -19
- package/dist/cli/stats.js +8 -1
- package/dist/cli/task-context.js +3 -0
- package/dist/cli/trigger-command.js +20 -14
- package/dist/config/boot-log.js +23 -2
- package/dist/config/config-field-policy.js +2 -0
- package/dist/config/config-manager.js +13 -17
- package/dist/config/daemon-services.js +1 -0
- package/dist/config/peer-role-resolver.js +6 -6
- package/dist/config/provider-identity-migration.js +202 -0
- package/dist/config/provider-identity.js +37 -0
- package/dist/config/provider-ipc-service.js +40 -3
- package/dist/config/provider-local-sync.js +153 -0
- package/dist/config/providers-config.js +32 -4
- package/dist/config/providers-management.js +144 -68
- package/dist/config/providers.js +4 -1
- package/dist/config/role-schema.js +3 -3
- package/dist/config/schema-migration.js +188 -3
- package/dist/core/agent-application-service.js +11 -0
- package/dist/core/agent-ipc-registration.js +2 -0
- package/dist/core/agent-runtime.js +45 -11
- package/dist/core/auth/auth-gateway.js +8 -6
- package/dist/core/auth/delegation-diagnostics.js +6 -2
- package/dist/core/auth/operation-authorizer.js +5 -2
- package/dist/core/auth/operation-catalog.js +6 -4
- package/dist/core/baseagent-loader.js +11 -3
- package/dist/core/bootstrap-service.js +8 -0
- package/dist/core/channel-loader.js +61 -23
- package/dist/core/command/agent-control.js +4 -1
- package/dist/core/command/chatmode-config.js +46 -0
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +16 -20
- package/dist/core/command/daemon-diagnostics.js +2 -1
- package/dist/core/command/menu-catalog.js +1 -1
- package/dist/core/command/menu-handler.js +16 -16
- package/dist/core/command/menu-protocol.js +4 -2
- package/dist/core/command/provider-menu.js +4 -2
- package/dist/core/command/role-menu.js +2 -2
- package/dist/core/command/slash-handler.js +56 -42
- package/dist/core/daemon-lifecycle.js +35 -17
- package/dist/core/event-catalog.js +19 -0
- package/dist/core/evolagent-registry.js +3 -0
- package/dist/core/handoff/runtime.js +9 -3
- package/dist/core/initialization/service.js +4 -3
- package/dist/core/ipc-registration.js +6 -0
- package/dist/core/message/aun-ipc-sender.js +81 -3
- package/dist/core/message/im-renderer.js +24 -19
- package/dist/core/message/message-admission.js +13 -2
- package/dist/core/message/response-engine.js +40 -41
- package/dist/core/message/send-options.js +40 -0
- package/dist/core/message/send-routing.js +310 -0
- package/dist/core/model/model-capabilities.js +37 -0
- package/dist/core/model/model-catalog.js +6 -2
- package/dist/core/ownership/owner-resolver.js +117 -14
- package/dist/core/permission/ec-command-parser.js +195 -27
- package/dist/core/permission/readonly-shell-query.js +66 -7
- package/dist/core/permission/tool-error-code.js +13 -1
- package/dist/core/permission/tool-policy.js +74 -20
- package/dist/core/plugin-lifecycle.js +6 -2
- package/dist/core/relation/pa-team.js +7 -2
- package/dist/core/relation/same-owner-proof.js +131 -0
- package/dist/core/session/session-idle-monitor.js +94 -16
- package/dist/core/session/session-manager.js +69 -16
- package/dist/core/thread/thread-route.js +5 -2
- package/dist/directory/owner-directory-cache.js +690 -99
- package/dist/directory/owner-directory-markdown.js +146 -36
- package/dist/directory/owner-directory-query-operation.js +7 -9
- package/dist/directory/owner-directory-scope.js +12 -0
- package/dist/directory/owner-directory-search.js +5 -1
- package/dist/directory/owner-directory-store.js +28 -0
- package/dist/ecweb/basic-settings-service.js +15 -1
- package/dist/ecweb/message-context-service.js +2 -2
- package/dist/ecweb/providers-service.js +3 -1
- package/dist/ecweb/runtime/lifecycle.js +38 -5
- package/dist/ecweb/runtime/supervisor.js +157 -49
- package/dist/index.js +202 -38
- package/dist/paths.js +2 -1
- package/dist/proxy/manager.js +2 -0
- package/dist/proxy/service-supervisor.js +379 -143
- package/dist/response-system/engines/v1/proactive-flow.js +4 -0
- package/dist/trigger/application-service.js +1 -0
- package/dist/trigger/audit.js +3 -2
- package/dist/trigger/authorization.js +2 -3
- package/dist/trigger/event-source.js +4 -0
- package/dist/trigger/feedback.js +26 -2
- package/dist/trigger/history.js +4 -3
- package/dist/trigger/ipc-service.js +24 -19
- package/dist/trigger/manager.js +3 -5
- package/dist/trigger/parser.js +4 -21
- package/dist/trigger/patch.js +3 -15
- package/dist/trigger/scheduler.js +48 -13
- package/dist/trigger/system-definitions.js +2 -2
- package/dist/trigger/validation.js +4 -13
- package/dist/utils/autostart.js +2 -2
- package/dist/utils/cross-platform.js +36 -8
- package/dist/utils/error-utils.js +8 -0
- package/dist/utils/macos-autostart.js +31 -0
- package/dist/utils/model-prices.jsonl +15 -8
- package/dist/utils/process-introspect.js +21 -1
- package/dist/utils/public-suffix.js +5811 -0
- package/dist/utils/startup-trace.js +7 -1
- package/dist/utils/windows-autostart.js +42 -7
- package/ecagent/dist/harness/compaction/branch-summarization.js +1 -1
- package/ecagent/dist/harness/compaction/compaction.js +4 -4
- package/ecagent/dist/harness/env/nodejs.js +46 -2
- package/kits/docs/aun/ABILITY_CALLING.md +3 -3
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/channels/feishu.md +2 -2
- package/kits/docs/context-assembly.md +20 -4
- package/kits/docs/evolcore/INDEX.md +3 -2
- package/kits/docs/evolcore/agent.md +2 -2
- package/kits/docs/evolcore/aid.md +8 -2
- package/kits/docs/evolcore/ctl.md +13 -4
- package/kits/docs/evolcore/directory.md +48 -15
- package/kits/docs/evolcore/file-navigation.md +63 -49
- package/kits/docs/evolcore/group.md +6 -6
- package/kits/docs/evolcore/memory-consolidation.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +33 -3
- package/kits/docs/evolcore/model.md +5 -3
- package/kits/docs/evolcore/msg.md +28 -27
- package/kits/docs/evolcore/provider.md +39 -5
- package/kits/docs/evolcore/response.md +3 -1
- package/kits/docs/evolcore/thread-chain.md +12 -14
- package/kits/docs/evolcore/tool-authorization.md +21 -1
- package/kits/docs/evolcore/trigger.md +12 -9
- package/kits/docs/identity/ROLE_DETAIL.md +1 -1
- package/kits/docs/prompt-loading-architecture.md +30 -20
- package/kits/eck_manifest.auxiliary.json +5 -5
- package/kits/eck_manifest.json +28 -49
- package/kits/eck_manifest.memory.json +18 -18
- package/kits/rules/01-overview.md +43 -45
- package/kits/rules/02-navigation.md +44 -53
- package/kits/rules/03-identity.md +21 -25
- package/kits/rules/04-relation.md +23 -33
- package/kits/rules/05-venue.md +24 -25
- package/kits/rules/06-channel.md +3 -3
- package/kits/schemas/_meta.json +20 -27
- package/kits/schemas/agent-config.schema.19.json +10 -6
- package/kits/schemas/providers.schema.2.json +74 -0
- package/kits/schemas/relation-config.schema.12.json +2 -2
- package/kits/schemas/role-config.schema.2.json +5 -5
- package/kits/schemas/role-registry.schema.1.json +1 -1
- package/kits/skills/ec-agent-create/SKILL.md +1 -0
- package/kits/skills/ec-service-proxy/SKILL.md +3 -0
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/ec-trigger/references/examples.md +1 -1
- package/kits/templates/system-fragments/channel.md +5 -5
- package/kits/templates/system-fragments/commands.md +3 -2
- package/kits/templates/system-fragments/directory-contacts.md +10 -3
- package/kits/templates/system-fragments/identity.md +0 -1
- package/kits/templates/system-fragments/personal-assistant.md +22 -3
- package/kits/templates/system-fragments/reply.md +47 -28
- package/kits/templates/system-fragments/session.md +2 -9
- package/kits/templates/system-fragments/thread.md +5 -5
- package/package.json +17 -13
- package/kits/schemas/agent-config.schema.20.json +0 -925
- package/kits/schemas/relation-config.schema.13.json +0 -289
- package/kits/schemas/role-config.schema.3.json +0 -1038
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { getRunnerCatalog, catalogEfforts, assertCatalogSelectable, } from '../core/model/model-catalog.js';
|
|
1
|
+
import { getRunnerCatalog, catalogEfforts, assertCatalogSelectable, resolveCatalogModel, } from '../core/model/model-catalog.js';
|
|
2
2
|
// Ecagent/OpenAI API 不认识 Claude Code SDK 的窗口后缀,必须传入基础模型 ID。
|
|
3
3
|
import { stripContextWindowSuffix } from '../core/model/context-window-suffix.js';
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import { assertOwnershipAuthorization } from '../core/ownership/owner-resolver.js';
|
|
6
6
|
import path from 'path';
|
|
7
|
-
import { AgentHarness, JsonlSessionRepo, NodeExecutionEnv, } from '../../ecagent/dist/node.js';
|
|
7
|
+
import { AgentHarness, DEFAULT_COMPACTION_SETTINGS, estimateContextTokens, JsonlSessionRepo, NodeExecutionEnv, } from '../../ecagent/dist/node.js';
|
|
8
8
|
import { Type, createModels, createProvider, } from '../../ecagent/dist/runtime/index.js';
|
|
9
9
|
import { AssistantMessageEventStream } from '../../ecagent/dist/runtime/utils/event-stream.js';
|
|
10
10
|
import { DEFAULT_PERMISSION_MODE } from '../types.js';
|
|
11
11
|
import { agentSessionsDir, resolveRoot } from '../paths.js';
|
|
12
|
+
import { isValidAid } from '../aun/aid/identity.js';
|
|
13
|
+
import { getExistingRelationAttachmentDirs } from '../core/permission/protected-paths.js';
|
|
12
14
|
import { requestDangerousCommandPermission } from '../core/permission/approval-gateway.js';
|
|
13
15
|
import { normalizeExecutionPermissionMode, normalizePermissionMode } from '../core/permission/mode.js';
|
|
14
16
|
import { checkBashDescription, checkDangerousCommand, checkReadonly, evaluateToolPreflight } from '../core/permission/tool-policy.js';
|
|
@@ -20,10 +22,11 @@ import { auditToolPreflightDenial } from '../core/auth/authorization-audit.js';
|
|
|
20
22
|
import { resolveEcagentConfig, resolveRuntimeBaseagentModelSelection } from './baseagent.js';
|
|
21
23
|
import { resolveProviderServiceForBaseagent } from '../config/providers.js';
|
|
22
24
|
import { buildModelRequestHeaders } from './request-identity.js';
|
|
23
|
-
import { getGatewayPricing as getSharedGatewayPricing
|
|
25
|
+
import { getGatewayPricing as getSharedGatewayPricing } from '../stats/price-resolver.js';
|
|
26
|
+
import { resolveAutoCompactWindow, resolveModelCapabilities } from '../core/model/model-capabilities.js';
|
|
24
27
|
import { appendRequestPath } from './request-identity.js';
|
|
25
28
|
import { getManagedTaskTempDir } from '../cli/task-context.js';
|
|
26
|
-
import { unsettledInterruptError, withInterruptDeadline, hasTrustedFullAccessContext, isOneMillionContextModel
|
|
29
|
+
import { unsettledInterruptError, withInterruptDeadline, hasTrustedFullAccessContext, isOneMillionContextModel } from './runner-types.js';
|
|
27
30
|
const PROVIDER_ID = 'evolcore-gateway';
|
|
28
31
|
const DEFAULT_SYSTEM_PROMPT = `You are ecagent, the coding agent built into EvolCore.
|
|
29
32
|
Work directly in the current project. Inspect relevant files before changing them, keep edits scoped, and verify the result.
|
|
@@ -33,6 +36,7 @@ const MAX_TOOL_OUTPUT = 200_000;
|
|
|
33
36
|
const MAX_SCAN_FILES = 5_000;
|
|
34
37
|
const MAX_SEARCH_RESULTS = 500;
|
|
35
38
|
const DEFAULT_BASH_TIMEOUT_MS = 120_000;
|
|
39
|
+
const INVALID_TOOL_ARGUMENTS_MARKER = '__evolcoreInvalidToolArguments';
|
|
36
40
|
class AsyncEventQueue {
|
|
37
41
|
values = [];
|
|
38
42
|
waiters = [];
|
|
@@ -252,7 +256,10 @@ function createOpenAiTransport(config) {
|
|
|
252
256
|
onAbort();
|
|
253
257
|
else
|
|
254
258
|
options?.signal?.addEventListener('abort', onAbort, { once: true });
|
|
255
|
-
const
|
|
259
|
+
const requestType = options?.metadata?.requestType;
|
|
260
|
+
const timeout = requestType === 'compaction' || requestType === 'branch_summary'
|
|
261
|
+
? undefined
|
|
262
|
+
: setTimeout(() => controller.abort(new Error(`Gateway request timed out after ${config.timeoutMs}ms`)), config.timeoutMs);
|
|
256
263
|
try {
|
|
257
264
|
controller.signal.throwIfAborted();
|
|
258
265
|
let payload = {
|
|
@@ -317,7 +324,8 @@ function createOpenAiTransport(config) {
|
|
|
317
324
|
}
|
|
318
325
|
}
|
|
319
326
|
finally {
|
|
320
|
-
|
|
327
|
+
if (timeout)
|
|
328
|
+
clearTimeout(timeout);
|
|
321
329
|
options?.signal?.removeEventListener('abort', onAbort);
|
|
322
330
|
}
|
|
323
331
|
if (retryScheduled) {
|
|
@@ -363,7 +371,7 @@ async function consumeOpenAiStream(output, body, model) {
|
|
|
363
371
|
args = call.arguments.trim() ? JSON.parse(call.arguments) : {};
|
|
364
372
|
}
|
|
365
373
|
catch {
|
|
366
|
-
|
|
374
|
+
args = { [INVALID_TOOL_ARGUMENTS_MARKER]: true };
|
|
367
375
|
}
|
|
368
376
|
const toolCall = { type: 'toolCall', id: call.id, name: call.name, arguments: args };
|
|
369
377
|
message.content[call.contentIndex] = toolCall;
|
|
@@ -456,13 +464,8 @@ async function consumeOpenAiStream(output, body, model) {
|
|
|
456
464
|
}
|
|
457
465
|
throw new Error('[network] Gateway stream ended without a terminal event');
|
|
458
466
|
}
|
|
459
|
-
function createModel(
|
|
460
|
-
const modelId = stripContextWindowSuffix(
|
|
461
|
-
const isClaude = modelId.toLowerCase().startsWith('claude-');
|
|
462
|
-
const fallback = isClaude
|
|
463
|
-
? { context_window: isOneMillionContextModel(id) ? 1_000_000 : 200_000, max_output_tokens: 8_192 }
|
|
464
|
-
: { context_window: isOneMillionContextModel(id) ? 1_000_000 : 128_000, max_output_tokens: 16_384 };
|
|
465
|
-
const spec = resolveModelSpec(resolveRoot(), id, undefined, fallback);
|
|
467
|
+
function createModel(capabilities, baseUrl) {
|
|
468
|
+
const modelId = stripContextWindowSuffix(capabilities.model);
|
|
466
469
|
return {
|
|
467
470
|
id: modelId,
|
|
468
471
|
name: modelId,
|
|
@@ -472,8 +475,10 @@ function createModel(id, baseUrl) {
|
|
|
472
475
|
reasoning: true,
|
|
473
476
|
input: ['text', 'image'],
|
|
474
477
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
475
|
-
contextWindow:
|
|
476
|
-
maxTokens:
|
|
478
|
+
contextWindow: capabilities.contextWindow,
|
|
479
|
+
maxTokens: capabilities.maxOutputTokens,
|
|
480
|
+
capabilities,
|
|
481
|
+
autoCompactWindow: resolveAutoCompactWindow(capabilities.contextWindow, capabilities.maxOutputTokens, DEFAULT_COMPACTION_SETTINGS.reserveTokens),
|
|
477
482
|
compat: {
|
|
478
483
|
maxTokensField: 'max_tokens',
|
|
479
484
|
supportsUsageInStreaming: true,
|
|
@@ -494,7 +499,12 @@ function isWithin(root, candidate) {
|
|
|
494
499
|
function isWithinAny(candidate, roots) {
|
|
495
500
|
return roots.some(root => isWithin(path.resolve(root), candidate));
|
|
496
501
|
}
|
|
497
|
-
|
|
502
|
+
function getEcagentAttachmentReadRoots(selfAid) {
|
|
503
|
+
return selfAid && isValidAid(selfAid)
|
|
504
|
+
? getExistingRelationAttachmentDirs(resolveRoot(), { selfAid })
|
|
505
|
+
: [];
|
|
506
|
+
}
|
|
507
|
+
export function resolveEcagentToolPath(projectPath, candidate, forWrite = false, bootstrapAgentMdPath, fullaccess = false, personalSoulDir, sessionGrants, selfAid) {
|
|
498
508
|
const root = fs.realpathSync(projectPath);
|
|
499
509
|
const resolved = path.resolve(root, candidate || '.');
|
|
500
510
|
const allowedBootstrapFile = bootstrapAgentMdPath
|
|
@@ -511,7 +521,10 @@ export function resolveEcagentToolPath(projectPath, candidate, forWrite = false,
|
|
|
511
521
|
.some(file => path.resolve(file) === resolved);
|
|
512
522
|
const sessionReads = !forWrite && isWithinAny(resolved, sessionGrants?.readRoots ?? []);
|
|
513
523
|
const isSessionTarget = sessionReads || sessionWrites;
|
|
514
|
-
|
|
524
|
+
const attachmentReadRoot = !forWrite && !sessionGrants
|
|
525
|
+
? getEcagentAttachmentReadRoots(selfAid).find(directory => isWithin(directory, resolved))
|
|
526
|
+
: undefined;
|
|
527
|
+
if (!fullaccess && !isWithin(root, resolved) && !isManagedIdentityFile && !isSessionTarget && !attachmentReadRoot) {
|
|
515
528
|
throw new Error(`Path is outside the project: ${candidate}`);
|
|
516
529
|
}
|
|
517
530
|
if (isManagedIdentityFile) {
|
|
@@ -542,6 +555,16 @@ export function resolveEcagentToolPath(projectPath, candidate, forWrite = false,
|
|
|
542
555
|
}
|
|
543
556
|
// 可写文件尚未创建时,以父目录的真实路径为准;已存在时以文件自身的真实路径为准。
|
|
544
557
|
const canonicalSelf = fs.existsSync(resolved) ? fs.realpathSync(resolved) : canonical;
|
|
558
|
+
if (attachmentReadRoot) {
|
|
559
|
+
const canonicalAttachmentRoot = fs.realpathSync(attachmentReadRoot);
|
|
560
|
+
if (!isWithin(attachmentReadRoot, canonicalAttachmentRoot)
|
|
561
|
+
|| !isWithin(canonicalAttachmentRoot, attachmentReadRoot)
|
|
562
|
+
|| !isWithin(canonicalAttachmentRoot, canonical)
|
|
563
|
+
|| !isWithin(canonicalAttachmentRoot, canonicalSelf)) {
|
|
564
|
+
throw new Error(`Path resolves outside its attachment root: ${candidate}`);
|
|
565
|
+
}
|
|
566
|
+
return resolved;
|
|
567
|
+
}
|
|
545
568
|
if (isSessionTarget) {
|
|
546
569
|
const grantedRoots = [
|
|
547
570
|
...(sessionReads ? sessionGrants?.readRoots ?? [] : []),
|
|
@@ -613,16 +636,16 @@ async function walkFiles(root, signal) {
|
|
|
613
636
|
function textResult(text, details = {}) {
|
|
614
637
|
return { content: [{ type: 'text', text: truncate(text) }], details };
|
|
615
638
|
}
|
|
616
|
-
function createTools(env, projectPath, runtimeEnv, bootstrapAgentMdPath, fullaccess = false, personalSoulDir, sessionGrants) {
|
|
639
|
+
function createTools(env, projectPath, runtimeEnv, bootstrapAgentMdPath, fullaccess = false, personalSoulDir, sessionGrants, selfAid) {
|
|
617
640
|
const read = {
|
|
618
|
-
name: 'Read', label: 'Read', description: 'Read a UTF-8 text file from the project.',
|
|
641
|
+
name: 'Read', label: 'Read', description: 'Read a UTF-8 text file from the project or this Agent\'s incoming attachments.',
|
|
619
642
|
parameters: Type.Object({
|
|
620
643
|
file_path: Type.String(),
|
|
621
644
|
offset: Type.Optional(Type.Number({ minimum: 1 })),
|
|
622
645
|
limit: Type.Optional(Type.Number({ minimum: 1 })),
|
|
623
646
|
}),
|
|
624
647
|
async execute(_id, params, signal) {
|
|
625
|
-
const file = resolveEcagentToolPath(projectPath, params.file_path, false, bootstrapAgentMdPath, fullaccess, personalSoulDir, sessionGrants);
|
|
648
|
+
const file = resolveEcagentToolPath(projectPath, params.file_path, false, bootstrapAgentMdPath, fullaccess, personalSoulDir, sessionGrants, selfAid);
|
|
626
649
|
const stat = await fs.promises.stat(file);
|
|
627
650
|
if (stat.size > MAX_READ_BYTES)
|
|
628
651
|
throw new Error(`File exceeds ${MAX_READ_BYTES} byte read limit`);
|
|
@@ -636,10 +659,10 @@ function createTools(env, projectPath, runtimeEnv, bootstrapAgentMdPath, fullacc
|
|
|
636
659
|
},
|
|
637
660
|
};
|
|
638
661
|
const glob = {
|
|
639
|
-
name: 'Glob', label: 'Glob', description: 'Find
|
|
662
|
+
name: 'Glob', label: 'Glob', description: 'Find files matching a glob pattern in the project or this Agent\'s incoming attachments.',
|
|
640
663
|
parameters: Type.Object({ pattern: Type.String(), path: Type.Optional(Type.String()) }),
|
|
641
664
|
async execute(_id, params, signal) {
|
|
642
|
-
const root = resolveEcagentToolPath(projectPath, params.path ?? '.', false, undefined, fullaccess, undefined, sessionGrants);
|
|
665
|
+
const root = resolveEcagentToolPath(projectPath, params.path ?? '.', false, undefined, fullaccess, undefined, sessionGrants, selfAid);
|
|
643
666
|
const matcher = globRegex(params.pattern.replaceAll('\\', '/'));
|
|
644
667
|
const files = (await walkFiles(root, signal))
|
|
645
668
|
.map(file => path.relative(root, file).replaceAll(path.sep, '/'))
|
|
@@ -649,13 +672,13 @@ function createTools(env, projectPath, runtimeEnv, bootstrapAgentMdPath, fullacc
|
|
|
649
672
|
},
|
|
650
673
|
};
|
|
651
674
|
const grep = {
|
|
652
|
-
name: 'Grep', label: 'Grep', description: 'Search text files in the project.',
|
|
675
|
+
name: 'Grep', label: 'Grep', description: 'Search text files in the project or this Agent\'s incoming attachments.',
|
|
653
676
|
parameters: Type.Object({
|
|
654
677
|
pattern: Type.String(), path: Type.Optional(Type.String()), glob: Type.Optional(Type.String()),
|
|
655
678
|
case_insensitive: Type.Optional(Type.Boolean()), literal: Type.Optional(Type.Boolean()),
|
|
656
679
|
}),
|
|
657
680
|
async execute(_id, params, signal) {
|
|
658
|
-
const root = resolveEcagentToolPath(projectPath, params.path ?? '.', false, undefined, fullaccess, undefined, sessionGrants);
|
|
681
|
+
const root = resolveEcagentToolPath(projectPath, params.path ?? '.', false, undefined, fullaccess, undefined, sessionGrants, selfAid);
|
|
659
682
|
const files = (await fs.promises.stat(root)).isFile() ? [root] : await walkFiles(root, signal);
|
|
660
683
|
const fileMatcher = params.glob ? globRegex(params.glob.replaceAll('\\', '/')) : undefined;
|
|
661
684
|
const flags = params.case_insensitive ? 'i' : '';
|
|
@@ -738,7 +761,16 @@ function createTools(env, projectPath, runtimeEnv, bootstrapAgentMdPath, fullacc
|
|
|
738
761
|
return textResult(combined || `Command exited with ${result.value.exitCode}`, { exitCode: result.value.exitCode });
|
|
739
762
|
},
|
|
740
763
|
};
|
|
741
|
-
|
|
764
|
+
const tools = [read, glob, grep, write, edit, bash];
|
|
765
|
+
return tools.map((tool) => ({
|
|
766
|
+
...tool,
|
|
767
|
+
prepareArguments(args) {
|
|
768
|
+
if (args && typeof args === 'object' && args[INVALID_TOOL_ARGUMENTS_MARKER] === true) {
|
|
769
|
+
throw new Error(`The model returned malformed JSON arguments for ${tool.name}; no command was executed. Return valid JSON arguments and try again.`);
|
|
770
|
+
}
|
|
771
|
+
return tool.prepareArguments ? tool.prepareArguments(args) : args;
|
|
772
|
+
},
|
|
773
|
+
}));
|
|
742
774
|
}
|
|
743
775
|
function extractToolResult(result) {
|
|
744
776
|
const content = Array.isArray(result?.content) ? result.content : [];
|
|
@@ -746,6 +778,8 @@ function extractToolResult(result) {
|
|
|
746
778
|
}
|
|
747
779
|
function errorType(message) {
|
|
748
780
|
const normalized = message.toLowerCase();
|
|
781
|
+
if (normalized.includes('summarization failed') || normalized.includes('turn prefix summarization failed'))
|
|
782
|
+
return ErrorType.COMPACTION_FAILED;
|
|
749
783
|
if (normalized.includes('invalid jsonl session file') || normalized.includes('session file'))
|
|
750
784
|
return ErrorType.SESSION_UNAVAILABLE;
|
|
751
785
|
if (normalized.includes('[auth]') || normalized.includes('401') || normalized.includes('403'))
|
|
@@ -829,6 +863,7 @@ export class EcagentRunner {
|
|
|
829
863
|
throw new Error(`Provider ${providerId} has no API key`);
|
|
830
864
|
return {
|
|
831
865
|
...this.config,
|
|
866
|
+
providerId,
|
|
832
867
|
apiKey: provider.apiKey,
|
|
833
868
|
baseUrl: provider.baseUrl,
|
|
834
869
|
headers: buildModelRequestHeaders({
|
|
@@ -852,7 +887,24 @@ export class EcagentRunner {
|
|
|
852
887
|
];
|
|
853
888
|
}
|
|
854
889
|
getModelCatalog() {
|
|
855
|
-
return getRunnerCatalog('ecagent', this.agentAid, this.
|
|
890
|
+
return getRunnerCatalog('ecagent', this.agentAid, this.currentProviderConfig());
|
|
891
|
+
}
|
|
892
|
+
async resolveRunModel(modelId, connection) {
|
|
893
|
+
const catalog = await getRunnerCatalog('ecagent', undefined, connection);
|
|
894
|
+
assertCatalogSelectable(catalog);
|
|
895
|
+
const canonicalModel = resolveCatalogModel(catalog, modelId);
|
|
896
|
+
const isClaude = stripContextWindowSuffix(canonicalModel).toLowerCase().startsWith('claude-');
|
|
897
|
+
const capabilities = resolveModelCapabilities(resolveRoot(), modelId, {
|
|
898
|
+
catalog,
|
|
899
|
+
fallbackContextWindow: isOneMillionContextModel(canonicalModel) ? 1_000_000 : isClaude ? 200_000 : 128_000,
|
|
900
|
+
fallbackMaxOutputTokens: isClaude ? 8192 : 16384,
|
|
901
|
+
});
|
|
902
|
+
const model = createModel(capabilities, connection.baseUrl);
|
|
903
|
+
logger.info('[EcagentRunner] Resolved model capabilities', {
|
|
904
|
+
...capabilities, autoCompactWindow: model.autoCompactWindow,
|
|
905
|
+
providerId: connection.providerId, catalogSource: catalog?.source, catalogFreshness: catalog?.freshness,
|
|
906
|
+
});
|
|
907
|
+
return model;
|
|
856
908
|
}
|
|
857
909
|
async listModels() {
|
|
858
910
|
const catalog = await this.getModelCatalog();
|
|
@@ -957,6 +1009,8 @@ export class EcagentRunner {
|
|
|
957
1009
|
startedAt: Date.now(), text: '', textBlocks: new Map(), numTurns: 0, usage: {}, modelCalls: [],
|
|
958
1010
|
};
|
|
959
1011
|
let completeSent = false;
|
|
1012
|
+
let compactHeartbeatTimer;
|
|
1013
|
+
let compactStartedAt;
|
|
960
1014
|
try {
|
|
961
1015
|
const connection = this.currentProviderConfig(request.modelOverride?.provider);
|
|
962
1016
|
await fs.promises.mkdir(request.projectPath, { recursive: true });
|
|
@@ -982,7 +1036,15 @@ export class EcagentRunner {
|
|
|
982
1036
|
if (fullaccess && !hasTrustedFullAccessContext(this.permissionContexts.get(request.sessionId))) {
|
|
983
1037
|
throw new Error('Ecagent fullaccess requires a trusted per-call execution authorization');
|
|
984
1038
|
}
|
|
985
|
-
const model =
|
|
1039
|
+
const model = await this.resolveRunModel(modelId, connection);
|
|
1040
|
+
if (lifecycle.cancelled)
|
|
1041
|
+
throw new Error('ecagent run interrupted');
|
|
1042
|
+
if (model.capabilities.contextWindowSource === 'safe-fallback') {
|
|
1043
|
+
queue.push({
|
|
1044
|
+
type: 'notice', severity: 'warn', subtype: 'model_context_fallback',
|
|
1045
|
+
message: '未取得模型上下文参数,暂按保守窗口 ' + model.contextWindow + ' tokens 运行;这不代表模型官方上限。',
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
986
1048
|
const nodeEnv = new NodeExecutionEnv({ cwd: request.projectPath, shellEnv: { ...process.env, ...request.runtimeEnv, EVOLCORE_SESSION_ID: request.sessionId, EVOLCORE_HOME: resolveRoot() } });
|
|
987
1049
|
const models = createModels();
|
|
988
1050
|
const transport = createOpenAiTransport(connection);
|
|
@@ -1004,8 +1066,8 @@ export class EcagentRunner {
|
|
|
1004
1066
|
models,
|
|
1005
1067
|
model,
|
|
1006
1068
|
thinkingLevel: normalizeThinkingLevel(effort),
|
|
1007
|
-
autoCompactWindow:
|
|
1008
|
-
tools: createTools(nodeEnv, request.projectPath, request.runtimeEnv, request.modelOverride?.bootstrapAgentMdPath, fullaccess, request.modelOverride?.personalSoulDir, this.permissionContexts.get(request.sessionId)?.systemSessionGrants),
|
|
1069
|
+
autoCompactWindow: model.autoCompactWindow,
|
|
1070
|
+
tools: createTools(nodeEnv, request.projectPath, request.runtimeEnv, request.modelOverride?.bootstrapAgentMdPath, fullaccess, request.modelOverride?.personalSoulDir, this.permissionContexts.get(request.sessionId)?.systemSessionGrants, this.permissionContexts.get(request.sessionId)?.systemSessionCheck ? undefined : this.agentAid),
|
|
1009
1071
|
systemPrompt: [DEFAULT_SYSTEM_PROMPT, request.systemPromptAppend].filter(Boolean).join('\n\n'),
|
|
1010
1072
|
streamOptions: {
|
|
1011
1073
|
timeoutMs: connection.timeoutMs,
|
|
@@ -1016,6 +1078,10 @@ export class EcagentRunner {
|
|
|
1016
1078
|
runtime.harness = harness;
|
|
1017
1079
|
harness.on('session_before_compact', () => {
|
|
1018
1080
|
this.onCompactStart?.(request.sessionId);
|
|
1081
|
+
compactStartedAt = Date.now();
|
|
1082
|
+
compactHeartbeatTimer ??= setInterval(() => {
|
|
1083
|
+
queue.push({ type: 'heartbeat', source: 'compaction', turn: stats.numTurns + 1 });
|
|
1084
|
+
}, 30_000);
|
|
1019
1085
|
return undefined;
|
|
1020
1086
|
});
|
|
1021
1087
|
if (this.pendingInterrupts.get(request.sessionId) === queue) {
|
|
@@ -1057,7 +1123,27 @@ export class EcagentRunner {
|
|
|
1057
1123
|
return messages ? { messages } : undefined;
|
|
1058
1124
|
});
|
|
1059
1125
|
let inputAccepted = false;
|
|
1060
|
-
const unsubscribe = harness.subscribe(event => {
|
|
1126
|
+
const unsubscribe = harness.subscribe(async (event) => {
|
|
1127
|
+
if (event.type === 'session_compact') {
|
|
1128
|
+
if (compactHeartbeatTimer)
|
|
1129
|
+
clearInterval(compactHeartbeatTimer);
|
|
1130
|
+
compactHeartbeatTimer = undefined;
|
|
1131
|
+
const durationMs = compactStartedAt === undefined ? undefined : Date.now() - compactStartedAt;
|
|
1132
|
+
compactStartedAt = undefined;
|
|
1133
|
+
try {
|
|
1134
|
+
const context = await runtime.session.buildContext();
|
|
1135
|
+
queue.push({
|
|
1136
|
+
type: 'compact',
|
|
1137
|
+
preTokens: event.compactionEntry.tokensBefore,
|
|
1138
|
+
postTokens: estimateContextTokens(context.messages).tokens,
|
|
1139
|
+
durationMs,
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
catch (error) {
|
|
1143
|
+
logger.warn(`[EcagentRunner] Could not measure compacted context: ${error instanceof Error ? error.message : String(error)}`);
|
|
1144
|
+
queue.push({ type: 'compact', preTokens: event.compactionEntry.tokensBefore, durationMs });
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1061
1147
|
if (event.type === 'tool_execution_start' || event.type === 'tool_execution_end') {
|
|
1062
1148
|
logger.info('[EcagentRunner] Tool lifecycle', {
|
|
1063
1149
|
sessionId: request.sessionId, taskId: request.modelOverride?.turn?.taskId,
|
|
@@ -1149,6 +1235,8 @@ export class EcagentRunner {
|
|
|
1149
1235
|
completeSent = true;
|
|
1150
1236
|
}
|
|
1151
1237
|
finally {
|
|
1238
|
+
if (compactHeartbeatTimer)
|
|
1239
|
+
clearInterval(compactHeartbeatTimer);
|
|
1152
1240
|
if (!completeSent)
|
|
1153
1241
|
queue.push({ type: 'complete', isError: true, terminalReason: 'error', durationMs: Date.now() - stats.startedAt });
|
|
1154
1242
|
if (this.activeStreams.get(request.sessionId) === queue) {
|
|
@@ -1339,7 +1427,8 @@ export class EcagentRunner {
|
|
|
1339
1427
|
return {
|
|
1340
1428
|
totalTokens, maxTokens: model.contextWindow,
|
|
1341
1429
|
percentage: model.contextWindow > 0 ? totalTokens / model.contextWindow * 100 : 0,
|
|
1342
|
-
autoCompactTokens:
|
|
1430
|
+
autoCompactTokens: model.autoCompactWindow,
|
|
1431
|
+
contextWindowSource: model.capabilities.contextWindowSource,
|
|
1343
1432
|
model: model.id, effort,
|
|
1344
1433
|
};
|
|
1345
1434
|
}
|
|
@@ -1454,8 +1543,14 @@ export class EcagentRunner {
|
|
|
1454
1543
|
return {};
|
|
1455
1544
|
const checkedInput = preflight.input;
|
|
1456
1545
|
if (mode === 'readonly') {
|
|
1546
|
+
const attachmentReadRoots = ['Read', 'Glob', 'Grep'].includes(toolName)
|
|
1547
|
+
? getEcagentAttachmentReadRoots(permissionContext?.selfAid)
|
|
1548
|
+
: [];
|
|
1457
1549
|
const decision = checkReadonly(toolName, checkedInput, projectPath, {
|
|
1458
|
-
sessionId, managedTempDir: permissionContext?.managedTempDir,
|
|
1550
|
+
sessionId, managedTempDir: permissionContext?.managedTempDir,
|
|
1551
|
+
grantedReadRoots: [...(permissionContext?.grantedReadRoots ?? []), ...attachmentReadRoots],
|
|
1552
|
+
channel: permissionContext?.channel, peerId: permissionContext?.userId, role: permissionContext?.role,
|
|
1553
|
+
selfAid: permissionContext?.selfAid,
|
|
1459
1554
|
allowReadonlySourceDiagnostics: permissionContext?.allowReadonlySourceDiagnostics === true,
|
|
1460
1555
|
});
|
|
1461
1556
|
if (decision.behavior === 'deny') {
|
|
@@ -1582,8 +1677,8 @@ export class EcagentRunner {
|
|
|
1582
1677
|
const compactEffort = modelOverride?.effortMode === 'model_default'
|
|
1583
1678
|
? undefined
|
|
1584
1679
|
: modelOverride?.effort ?? this.effort;
|
|
1585
|
-
const connection = this.currentProviderConfig();
|
|
1586
|
-
const model =
|
|
1680
|
+
const connection = this.currentProviderConfig(modelOverride?.provider);
|
|
1681
|
+
const model = await this.resolveRunModel(compactModel, connection);
|
|
1587
1682
|
const env = new NodeExecutionEnv({ cwd: runtime.projectPath });
|
|
1588
1683
|
const models = createModels();
|
|
1589
1684
|
const transport = createOpenAiTransport(connection);
|
package/dist/aun/aid/agentmd.js
CHANGED
|
@@ -147,9 +147,6 @@ async function withAgentMdWriteLock(key, operation) {
|
|
|
147
147
|
agentMdWriteLocks.delete(key);
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
-
// A process can host agents that deliberately use different AUN keystore
|
|
151
|
-
// roots. Keep their display-name state separate so one root cannot shadow the
|
|
152
|
-
// other with a same-named AID.
|
|
153
150
|
const displayNameCache = new Map();
|
|
154
151
|
const displayNamePending = new Map();
|
|
155
152
|
const displayNameRevision = new Map();
|
|
@@ -180,18 +177,34 @@ function displayNameKey(aid, aunPath) {
|
|
|
180
177
|
const root = path.resolve(aunPath ?? resolveRoot());
|
|
181
178
|
return `${root}\u0000${aid.toLowerCase()}`;
|
|
182
179
|
}
|
|
180
|
+
/** agent.md 的廉价指纹;文件不存在时返回 null。 */
|
|
181
|
+
function agentMdStamp(aid, aunPath) {
|
|
182
|
+
try {
|
|
183
|
+
const st = fs.statSync(agentMdPath(aid, aunPath));
|
|
184
|
+
return `${st.mtimeMs}:${st.size}`;
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
183
190
|
function readLocalAgentDisplayName(aid, aunPath) {
|
|
191
|
+
// 先取指纹再读内容:并发写入时只会让下一次多读一遍,不会留下过期条目。
|
|
192
|
+
const stamp = agentMdStamp(aid, aunPath);
|
|
184
193
|
try {
|
|
185
|
-
return parseAgentDisplayName(fs.readFileSync(agentMdPath(aid, aunPath), 'utf-8'));
|
|
194
|
+
return { name: parseAgentDisplayName(fs.readFileSync(agentMdPath(aid, aunPath), 'utf-8')), stamp };
|
|
186
195
|
}
|
|
187
196
|
catch {
|
|
188
|
-
return undefined;
|
|
197
|
+
return { name: undefined, stamp: null };
|
|
189
198
|
}
|
|
190
199
|
}
|
|
191
200
|
/**
|
|
192
201
|
* Resolve an agent.md display name without blocking on the network.
|
|
193
202
|
* Local content is returned immediately; a missing value starts one shared
|
|
194
203
|
* background refresh and remains undefined until a later lookup.
|
|
204
|
+
*
|
|
205
|
+
* The cache is validated against agent.md's mtime+size on every lookup, so a
|
|
206
|
+
* rename written by any path (CLI, App, peer sync) is visible on the next read
|
|
207
|
+
* instead of waiting for a process-level invalidate hook or a daemon restart.
|
|
195
208
|
*/
|
|
196
209
|
export function resolveAgentDisplayName(aid, opts) {
|
|
197
210
|
const normalizedAid = normalizeAid(aid);
|
|
@@ -200,13 +213,19 @@ export function resolveAgentDisplayName(aid, opts) {
|
|
|
200
213
|
const aunPath = resolveAgentMdAunPath(opts);
|
|
201
214
|
const key = displayNameKey(normalizedAid, aunPath);
|
|
202
215
|
const cached = displayNameCache.get(key);
|
|
203
|
-
if (cached)
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
216
|
+
if (cached) {
|
|
217
|
+
// 指纹未知(当初 stat 不到)或此刻 stat 不到文件时,沿用缓存,避免反复回源。
|
|
218
|
+
const current = cached.stamp === null ? null : agentMdStamp(normalizedAid, aunPath);
|
|
219
|
+
if (current === null || current === cached.stamp)
|
|
220
|
+
return cached.name;
|
|
221
|
+
displayNameCache.delete(key);
|
|
209
222
|
}
|
|
223
|
+
const local = readLocalAgentDisplayName(normalizedAid, aunPath);
|
|
224
|
+
if (local.name) {
|
|
225
|
+
displayNameCache.set(key, { name: local.name, stamp: local.stamp });
|
|
226
|
+
return local.name;
|
|
227
|
+
}
|
|
228
|
+
displayNameCache.delete(key);
|
|
210
229
|
void refreshAgentDisplayName(normalizedAid, opts);
|
|
211
230
|
return undefined;
|
|
212
231
|
}
|
|
@@ -228,7 +247,7 @@ export function refreshAgentDisplayName(aid, opts) {
|
|
|
228
247
|
if ((displayNameRevision.get(key) ?? 0) !== revision)
|
|
229
248
|
return undefined;
|
|
230
249
|
if (name)
|
|
231
|
-
displayNameCache.set(key, name);
|
|
250
|
+
displayNameCache.set(key, { name, stamp: agentMdStamp(normalizedAid, aunPath) });
|
|
232
251
|
return name;
|
|
233
252
|
})
|
|
234
253
|
.catch(() => undefined)
|
|
@@ -686,6 +705,31 @@ export async function agentmdGet(aid, opts) {
|
|
|
686
705
|
catch { /* ignore */ }
|
|
687
706
|
}
|
|
688
707
|
}
|
|
708
|
+
/** Ordinary Agent ownership targets require a freshly verified human card. */
|
|
709
|
+
export async function assertHumanAgentOwner(ownerAid, opts = {}) {
|
|
710
|
+
let card;
|
|
711
|
+
try {
|
|
712
|
+
card = await agentmdGet(ownerAid, { ...opts, withVerification: true, remoteOnly: true });
|
|
713
|
+
}
|
|
714
|
+
catch (cause) {
|
|
715
|
+
throw Object.assign(new Error(`Cannot verify the Owner identity for ${ownerAid}`), {
|
|
716
|
+
code: 'OWNER_IDENTITY_UNAVAILABLE', cause,
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
const frontmatter = card.content.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/)?.[1];
|
|
720
|
+
const document = parseDocument(frontmatter ?? '');
|
|
721
|
+
const fields = document.errors.length === 0 ? document.toJS() : undefined;
|
|
722
|
+
if (card.verification.status !== 'verified' || document.errors.length > 0
|
|
723
|
+
|| !fields || typeof fields !== 'object' || Array.isArray(fields) || fields.aid !== ownerAid
|
|
724
|
+
|| typeof fields.type !== 'string' || !fields.type.trim()) {
|
|
725
|
+
throw Object.assign(new Error(`Cannot verify the Owner identity for ${ownerAid}`), {
|
|
726
|
+
code: 'OWNER_IDENTITY_UNAVAILABLE',
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
if (fields.type !== 'human') {
|
|
730
|
+
throw Object.assign(new Error('An Agent Owner must have type human'), { code: 'INVALID_OWNER' });
|
|
731
|
+
}
|
|
732
|
+
}
|
|
689
733
|
/** Check an existing identity before Agent creation can overwrite its signed card. */
|
|
690
734
|
export async function assertAgentIdentityReusable(aid, opts = {}) {
|
|
691
735
|
let card;
|
|
@@ -14,6 +14,21 @@ import { agentmdPutInitializationProfile, buildInitialAgentMd, invalidateAgentDi
|
|
|
14
14
|
import { logger, logOwnershipEvent } from '../../utils/logger.js';
|
|
15
15
|
const MAX_ATTEMPTS = 5;
|
|
16
16
|
export { DEFAULT_AID_DOMAIN } from './domain.js';
|
|
17
|
+
export function hasLocalControlIdentity(aid, root = resolvePaths().root) {
|
|
18
|
+
if (!isValidAid(aid))
|
|
19
|
+
return false;
|
|
20
|
+
return [['private', 'key.json'], ['public', 'cert.pem']].every(parts => {
|
|
21
|
+
try {
|
|
22
|
+
return fs.statSync(path.join(root, 'AIDs', aid, ...parts)).isFile();
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export function missingControlIdentityMessage(aid) {
|
|
30
|
+
return `控制 AID ${aid} 的本地证书或私钥缺失。重装 npm 包不能恢复身份;请从可信备份恢复该 AID 的证书和私钥,或明确选择卸载菜单的“完全清除”后重新安装(会删除所有 AIDs、配置与数据)。未自动重新生成 AID。`;
|
|
31
|
+
}
|
|
17
32
|
/** Human-facing platform label used in the control AID's agent.md name. */
|
|
18
33
|
export function controlHostPlatformLabel(platform = process.platform) {
|
|
19
34
|
switch (String(platform).trim().toLowerCase()) {
|
package/dist/aun/aid/identity.js
CHANGED
|
@@ -252,6 +252,10 @@ export async function aidEnsureOwnerBinding(client, aid, ownerAid) {
|
|
|
252
252
|
code: current.code || 'OWNER_BIND_STATE_UNAVAILABLE',
|
|
253
253
|
});
|
|
254
254
|
}
|
|
255
|
+
if (client.getType() === 'agent') {
|
|
256
|
+
const { assertHumanAgentOwner } = await import('./agentmd.js');
|
|
257
|
+
await assertHumanAgentOwner(owner);
|
|
258
|
+
}
|
|
255
259
|
const binding = await client.bindOwneraid(owner);
|
|
256
260
|
if (binding.status === 'error' || binding.status === 'rejected' || binding.status === 'stopped') {
|
|
257
261
|
throw Object.assign(new Error(binding.reason || `Owner binding ${binding.status}`), {
|
|
@@ -336,6 +340,10 @@ export async function aidCreate(aid, opts) {
|
|
|
336
340
|
// 新注册流程:AIDStore.register → downloadCaRoot → load → authenticate
|
|
337
341
|
const store = await getAidStore({ slotId: SLOT.cli, aunPath });
|
|
338
342
|
try {
|
|
343
|
+
if ((opts?.type ?? 'agent') === 'agent' && opts?.owner?.trim()) {
|
|
344
|
+
const { assertHumanAgentOwner } = await import('./agentmd.js');
|
|
345
|
+
await assertHumanAgentOwner(opts.owner.trim(), { aunPath, store });
|
|
346
|
+
}
|
|
339
347
|
const regResult = await store.register(aid, {
|
|
340
348
|
type: opts?.type ?? 'agent',
|
|
341
349
|
...(opts?.owner?.trim() ? { owner: opts.owner.trim() } : {}),
|
|
@@ -17,13 +17,17 @@ export function parseOwnershipCommand(argv) {
|
|
|
17
17
|
if (!args[0] || !args[1] || !['bind', 'transfer'].includes(args[0])) {
|
|
18
18
|
throw new OwnershipError('INVALID_ARGUMENT', `Use ${MAIN_CLI_BIN} aid bind <ownerAid>, transfer <subAid> <newOwnerAid>, status, accept, or reject`);
|
|
19
19
|
}
|
|
20
|
-
const action = args[0] === '
|
|
21
|
-
: [
|
|
20
|
+
const action = args[0] === 'bind' && args[1] === 'reject' && args[2] === '--reset' ? 'reset-rejection'
|
|
21
|
+
: args[0] === 'transfer' ? 'transfer'
|
|
22
|
+
: ['status', 'accept', 'reject'].includes(args[1]) ? args[1] : 'bind';
|
|
22
23
|
if (action === 'bind' && !isValidAid(args[1]))
|
|
23
24
|
throw new OwnershipError('INVALID_AID', 'A valid owner AID is required');
|
|
24
25
|
if (action === 'transfer' && (!isValidAid(args[1]) || !isValidAid(args[2] ?? ''))) {
|
|
25
26
|
throw new OwnershipError('INVALID_AID', 'Valid sub and new owner AIDs are required');
|
|
26
27
|
}
|
|
28
|
+
if (action === 'reset-rejection' && !isValidAid(args[3] ?? '')) {
|
|
29
|
+
throw new OwnershipError('INVALID_AID', 'A valid owner AID is required to reset a rejection');
|
|
30
|
+
}
|
|
27
31
|
if ((action === 'accept' || action === 'reject') && !OWNERSHIP_OPERATION_ID.test(args[2] ?? '')) {
|
|
28
32
|
throw new OwnershipError('INVALID_OPERATION', 'A valid ownership operation ID is required');
|
|
29
33
|
}
|
|
@@ -31,7 +35,7 @@ export function parseOwnershipCommand(argv) {
|
|
|
31
35
|
let reason;
|
|
32
36
|
let refresh = false;
|
|
33
37
|
let formatSeen = false;
|
|
34
|
-
const positionalEnd = action === 'bind' || action === 'status' ? 2 : 3;
|
|
38
|
+
const positionalEnd = action === 'reset-rejection' ? 4 : action === 'bind' || action === 'status' ? 2 : 3;
|
|
35
39
|
for (let index = positionalEnd; index < args.length;) {
|
|
36
40
|
const flag = args[index];
|
|
37
41
|
if (flag === '--refresh' && action === 'status' && !refresh) {
|
|
@@ -57,6 +61,8 @@ export function parseOwnershipCommand(argv) {
|
|
|
57
61
|
}
|
|
58
62
|
if (action === 'status')
|
|
59
63
|
return { action, subjectAid, ...(refresh ? { refresh } : {}) };
|
|
64
|
+
if (action === 'reset-rejection')
|
|
65
|
+
return { action, subjectAid, ownerAid: args[3] };
|
|
60
66
|
if (action === 'transfer')
|
|
61
67
|
return { action, subAid: args[1], newOwnerAid: args[2], subjectAid };
|
|
62
68
|
if (action === 'accept')
|
|
@@ -72,6 +78,9 @@ export async function executeOwnershipCommand(command, defaultSubjectAid) {
|
|
|
72
78
|
if (command.action === 'status') {
|
|
73
79
|
return ownerResolver.status(subjectAid, { force: command.refresh === true });
|
|
74
80
|
}
|
|
81
|
+
if (command.action === 'reset-rejection') {
|
|
82
|
+
return ownerResolver.resetRejectedOwnerBinding(subjectAid, command.ownerAid);
|
|
83
|
+
}
|
|
75
84
|
if (command.action === 'accept' || command.action === 'reject') {
|
|
76
85
|
return ownerResolver.decide(subjectAid, command.operationId, command.action, command.action === 'reject' ? command.reason : undefined);
|
|
77
86
|
}
|
package/dist/aun/menu/client.js
CHANGED
|
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import crypto from 'node:crypto';
|
|
4
4
|
import { createShortConnection } from '../rpc/client.js';
|
|
5
|
-
import { MENU_MESSAGE_TTL_SECONDS } from './transport.js';
|
|
5
|
+
import { MENU_MESSAGE_CLASS, MENU_MESSAGE_TTL_SECONDS } from './transport.js';
|
|
6
6
|
import { SLOT } from '../aid/store.js';
|
|
7
7
|
import { isValidAid } from '../aid/validation.js';
|
|
8
8
|
import { resolveRoot } from '../../paths.js';
|
|
@@ -125,7 +125,7 @@ export class ManagedMenuClient {
|
|
|
125
125
|
});
|
|
126
126
|
const sent = this.send({
|
|
127
127
|
to: options.targetAid, payload: request, encrypt: true,
|
|
128
|
-
ttl: MENU_MESSAGE_TTL_SECONDS, protected_headers: headers,
|
|
128
|
+
message_class: MENU_MESSAGE_CLASS, ttl: MENU_MESSAGE_TTL_SECONDS, protected_headers: headers,
|
|
129
129
|
}, options.beforeSend)
|
|
130
130
|
.then(result => {
|
|
131
131
|
if (!(result?.message_id ?? result?.message?.message_id))
|
|
@@ -276,7 +276,7 @@ async function pollResponse(conn, targetAid, requestId, timeoutMs, initialAfterS
|
|
|
276
276
|
const deadline = Date.now() + timeoutMs;
|
|
277
277
|
let afterSeq = initialAfterSeq;
|
|
278
278
|
while (Date.now() < deadline) {
|
|
279
|
-
const result = await callClient(conn, 'message.pull', { after_seq: afterSeq, limit: PULL_LIMIT });
|
|
279
|
+
const result = await callClient(conn, 'message.pull', { message_class: MENU_MESSAGE_CLASS, after_seq: afterSeq, limit: PULL_LIMIT });
|
|
280
280
|
const messages = Array.isArray(result?.messages) ? result.messages : [];
|
|
281
281
|
let maxSeq = afterSeq;
|
|
282
282
|
for (const message of messages) {
|
|
@@ -290,7 +290,7 @@ async function pollResponse(conn, targetAid, requestId, timeoutMs, initialAfterS
|
|
|
290
290
|
if (response && messageFrom === targetAid && response.id === requestId) {
|
|
291
291
|
if (Number.isSafeInteger(maxSeq) && maxSeq > afterSeq) {
|
|
292
292
|
try {
|
|
293
|
-
await callClient(conn, 'message.ack', { seq: maxSeq });
|
|
293
|
+
await callClient(conn, 'message.ack', { message_class: MENU_MESSAGE_CLASS, seq: maxSeq });
|
|
294
294
|
}
|
|
295
295
|
catch (error) {
|
|
296
296
|
throw new MenuClientError('ACK_FAILED', error?.message ?? String(error));
|
|
@@ -302,7 +302,7 @@ async function pollResponse(conn, targetAid, requestId, timeoutMs, initialAfterS
|
|
|
302
302
|
if (Number.isSafeInteger(maxSeq) && maxSeq > afterSeq) {
|
|
303
303
|
afterSeq = maxSeq;
|
|
304
304
|
try {
|
|
305
|
-
await callClient(conn, 'message.ack', { seq: afterSeq });
|
|
305
|
+
await callClient(conn, 'message.ack', { message_class: MENU_MESSAGE_CLASS, seq: afterSeq });
|
|
306
306
|
}
|
|
307
307
|
catch (error) {
|
|
308
308
|
throw new MenuClientError('ACK_FAILED', error?.message ?? String(error));
|
|
@@ -316,7 +316,7 @@ async function pollResponse(conn, targetAid, requestId, timeoutMs, initialAfterS
|
|
|
316
316
|
async function drainBaseline(conn) {
|
|
317
317
|
let afterSeq = 0;
|
|
318
318
|
for (let page = 0; page < 200; page += 1) {
|
|
319
|
-
const result = await callClient(conn, 'message.pull', { after_seq: afterSeq, limit: PULL_LIMIT });
|
|
319
|
+
const result = await callClient(conn, 'message.pull', { message_class: MENU_MESSAGE_CLASS, after_seq: afterSeq, limit: PULL_LIMIT });
|
|
320
320
|
const messages = Array.isArray(result?.messages) ? result.messages : [];
|
|
321
321
|
let maxSeq = Math.max(afterSeq, Number(result?.server_ack_seq) || 0);
|
|
322
322
|
for (const message of messages) {
|
|
@@ -326,7 +326,7 @@ async function drainBaseline(conn) {
|
|
|
326
326
|
}
|
|
327
327
|
if (maxSeq > afterSeq) {
|
|
328
328
|
try {
|
|
329
|
-
await callClient(conn, 'message.ack', { seq: maxSeq });
|
|
329
|
+
await callClient(conn, 'message.ack', { message_class: MENU_MESSAGE_CLASS, seq: maxSeq });
|
|
330
330
|
}
|
|
331
331
|
catch (error) {
|
|
332
332
|
throw new MenuClientError('ACK_FAILED', error?.message ?? String(error));
|
|
@@ -363,6 +363,7 @@ async function sendOnce(options, request, timeoutMs) {
|
|
|
363
363
|
to: options.targetAid,
|
|
364
364
|
payload: request,
|
|
365
365
|
encrypt,
|
|
366
|
+
message_class: MENU_MESSAGE_CLASS,
|
|
366
367
|
ttl: MENU_MESSAGE_TTL_SECONDS,
|
|
367
368
|
...(encrypt ? { protected_headers: headers } : {}),
|
|
368
369
|
});
|
package/dist/aun/menu/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { ManagedMenuClient, MenuClientError, executeMenuClientRequest } from './client.js';
|
|
2
|
-
export { MENU_MESSAGE_TTL_SECONDS, MENU_VOLATILE_SDK_VERSION, menuSenderDeviceId, menuTransportParams, supportsMenuVolatileTransport, } from './transport.js';
|
|
2
|
+
export { MENU_MESSAGE_TTL_SECONDS, MENU_MESSAGE_CLASS, MENU_VOLATILE_SDK_VERSION, menuSenderDeviceId, menuTransportParams, supportsMenuVolatileTransport, } from './transport.js';
|