evolcore 0.0.40 → 0.0.41-test.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +94 -1
- package/bin/codex-managed-hook.mjs +11 -0
- package/bin/ec-safe-output.js +11 -1
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/baseagent.js +20 -43
- package/dist/agents/claude-runner.js +197 -197
- package/dist/agents/codex-runner.js +535 -259
- package/dist/agents/ecagent-runner.js +31 -12
- package/dist/agents/gemini-runner.js +27 -7
- package/dist/agents/runner-types.js +11 -3
- package/dist/aun/ability-device-routing.js +26 -0
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/group/fs-download.js +39 -0
- package/dist/aun/group/identity.js +36 -13
- package/dist/aun/group/operations.js +5 -0
- package/dist/aun/msg/managed-operation.js +72 -11
- package/dist/aun/msg/p2p.js +32 -7
- package/dist/aun/service-proxy.js +36 -12
- package/dist/aun/storage/download.js +30 -0
- package/dist/aun/storage/index.js +14 -6
- package/dist/channels/aun.js +367 -24
- package/dist/channels/daemon.js +39 -5
- package/dist/cli/agent-command.js +2 -0
- package/dist/cli/agent-create.js +98 -19
- package/dist/cli/agent.js +10 -3
- package/dist/cli/aun-commands.js +85 -41
- package/dist/cli/daemon-commands.js +678 -688
- package/dist/cli/fs-command.js +64 -2
- package/dist/cli/index.js +48 -4
- package/dist/cli/managed-command-guard.js +4 -0
- package/dist/cli/model.js +40 -40
- package/dist/cli/proxy-command.js +92 -0
- package/dist/cli/restart-monitor.js +17 -0
- package/dist/cli/role.js +85 -0
- package/dist/cli/session-command.js +128 -13
- package/dist/cli/stats.js +60 -4
- package/dist/cli/trigger-command.js +2 -2
- package/dist/config/access-policy.js +8 -1
- package/dist/config/boot-log.js +38 -1
- package/dist/config/config-field-policy.js +5 -32
- package/dist/config/config-manager.js +46 -39
- package/dist/config/config-operation-service.js +8 -11
- package/dist/config/contact-book-store.js +47 -21
- package/dist/config/contact-book.js +18 -12
- package/dist/config/contact-operation-service.js +3 -4
- package/dist/config/contact-request-service.js +11 -0
- package/dist/config/daemon-services.js +11 -0
- package/dist/config/gateway-config.js +89 -595
- package/dist/config/peer-role-resolver.js +15 -11
- package/dist/config/providers-config.js +12 -7
- package/dist/config/providers-import.js +3 -21
- package/dist/config/resolved-config-op.js +3 -0
- package/dist/config/role-command-service.js +166 -0
- package/dist/config/role-request-service.js +193 -0
- package/dist/config/schema-migration.js +686 -25
- package/dist/config-store.js +79 -3
- package/dist/contracts/ecweb-instance.js +41 -0
- package/dist/contracts/ecweb-service-protocol.js +3 -1
- package/dist/core/agent-application-service.js +11 -1
- package/dist/core/agent-ipc-registration.js +4 -0
- package/dist/core/agent-runtime.js +1 -1
- package/dist/core/auth/agent-delegation.js +82 -6
- package/dist/core/auth/auth-gateway.js +1 -1
- package/dist/core/auth/authorization-audit.js +37 -9
- package/dist/core/auth/delegation-authorization.js +3 -1
- package/dist/core/auth/operation-authorizer.js +15 -0
- package/dist/core/auth/operation-catalog.js +39 -6
- package/dist/core/command/agent-control.js +94 -19
- package/dist/core/command/agent-storage-menu.js +5 -3
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +105 -145
- package/dist/core/command/connect-menu.js +31 -2
- package/dist/core/command/data-root-resolver.js +5 -4
- package/dist/core/command/memory-slash.js +16 -8
- package/dist/core/command/menu-catalog.js +6 -6
- package/dist/core/command/menu-handler.js +87 -163
- package/dist/core/command/menu-protocol.js +9 -2
- package/dist/core/command/role-menu.js +148 -30
- package/dist/core/command/slash-gate.js +13 -10
- package/dist/core/command/slash-handler.js +157 -352
- package/dist/core/daemon-control.js +8 -14
- package/dist/core/event-catalog.js +15 -0
- package/dist/core/evolagent-registry.js +4 -4
- package/dist/core/evolagent.js +2 -2
- package/dist/core/inference/text-inference.js +31 -40
- package/dist/core/ipc-registration.js +24 -3
- package/dist/core/memory/consolidation-context.js +51 -5
- package/dist/core/memory/consolidation-ops-records.js +1 -1
- package/dist/core/memory/consolidation-trigger.js +190 -190
- package/dist/core/memory/consolidation.js +316 -29
- package/dist/core/memory/forget-log.js +96 -0
- package/dist/core/memory/index-manager.js +27 -5
- package/dist/core/memory/memory-admin.js +45 -5
- package/dist/core/memory/memory-writer.js +163 -18
- package/dist/core/memory/relation-idle-monitor.js +119 -58
- package/dist/core/memory/relation-sweep.js +44 -39
- package/dist/core/message/aun-ipc-sender.js +34 -7
- package/dist/core/message/aun-request-registry.js +97 -3
- package/dist/core/message/im-renderer.js +11 -4
- package/dist/core/message/message-admission.js +97 -8
- package/dist/core/message/message-bridge.js +71 -24
- package/dist/core/message/message-log.js +55 -0
- package/dist/core/message/message-queue.js +5 -5
- package/dist/core/message/response-engine.js +387 -144
- package/dist/core/model/catalog-service.js +4 -2
- package/dist/core/model/config-scope.js +24 -64
- package/dist/core/model/field-scope.js +1 -1
- package/dist/core/model/model-catalog.js +37 -47
- package/dist/core/model/model-diagnostics.js +4 -3
- package/dist/core/model/model-fallback.js +10 -7
- package/dist/core/model/model-permission.js +3 -2
- package/dist/core/ownership/owner-resolver.js +25 -23
- package/dist/core/permission/ec-command-parser.js +138 -5
- package/dist/core/permission/sandbox-runtime.js +18 -1
- package/dist/core/permission/tool-policy.js +42 -10
- package/dist/core/relation/peer-identity.js +64 -1
- package/dist/core/role/runtime-policy.js +72 -13
- package/dist/core/session/session-capsule.js +197 -0
- package/dist/core/session/session-idle-monitor.js +1 -1
- package/dist/core/session/session-manager.js +168 -14
- package/dist/core/session/session-mapper.js +2 -0
- package/dist/core/session/session-renew.js +3 -3
- package/dist/core/skill/index-generator.js +15 -5
- package/dist/core/system-session/memory.js +6 -1
- package/dist/core/thread/thread-service.js +19 -6
- package/dist/directory/owner-directory-admission.js +95 -0
- package/dist/directory/owner-directory-authorization.js +309 -0
- package/dist/directory/owner-directory-cache.js +635 -0
- package/dist/eck/kit-renderer.js +2 -2
- package/dist/ecweb/basic-settings-service.js +33 -40
- package/dist/ecweb/message-context-service.js +110 -0
- package/dist/index.js +79 -17
- package/dist/ipc.js +189 -17
- package/dist/paths.js +4 -0
- package/dist/proxy/command.js +122 -0
- package/dist/proxy/ipc-service.js +68 -0
- package/dist/proxy/manager.js +485 -0
- package/dist/proxy/service-supervisor.js +603 -0
- package/dist/response-system/engines/v1/proactive-flow.js +16 -6
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +15 -0
- package/dist/stats/index.js +2 -2
- package/dist/stats/price-resolver.js +304 -5
- package/dist/stats/query.js +82 -3
- package/dist/stats/writer.js +38 -5
- package/dist/trigger/feedback.js +18 -7
- package/dist/trigger/manager.js +20 -3
- package/dist/trigger/parser.js +6 -3
- package/dist/trigger/patch.js +1 -1
- package/dist/trigger/system-definitions.js +43 -7
- package/dist/trigger/validation.js +13 -5
- package/dist/utils/cross-platform.js +14 -0
- package/dist/utils/ecweb-supervisor.js +258 -83
- package/dist/utils/error-utils.js +16 -2
- package/dist/utils/logger.js +24 -5
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +5 -3
- package/dist/utils/upgrade-jobs.js +45 -5
- package/kits/docs/INDEX.md +1 -1
- package/kits/docs/aun/ABILITY_CALLING.md +20 -2
- package/kits/docs/channels/aun.md +9 -0
- package/kits/docs/evolcore/INDEX.md +2 -1
- package/kits/docs/evolcore/agent-create.md +3 -2
- package/kits/docs/evolcore/agent.md +1 -1
- package/kits/docs/evolcore/config.md +18 -7
- package/kits/docs/evolcore/contact.md +3 -0
- package/kits/docs/evolcore/event.md +1 -0
- package/kits/docs/evolcore/fs.md +16 -0
- package/kits/docs/evolcore/memory-architecture.md +2 -2
- package/kits/docs/evolcore/memory-consolidation.md +32 -8
- package/kits/docs/evolcore/memory.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +36 -0
- package/kits/docs/evolcore/model.md +23 -20
- package/kits/docs/evolcore/msg.md +21 -8
- package/kits/docs/evolcore/session.md +14 -0
- package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
- package/kits/schemas/_meta.json +37 -4
- package/kits/schemas/agent-config.schema.13.json +23 -3
- package/kits/schemas/agent-config.schema.16.json +891 -0
- package/kits/schemas/daemon.schema.9.json +366 -0
- package/kits/schemas/defaults.schema.5.json +406 -127
- package/kits/schemas/relation-config.schema.11.json +260 -0
- package/kits/schemas/role-config.schema.1.json +7 -7
- package/kits/skills/.switches.json +3 -7
- package/kits/skills/aid-ability/SKILL.md +35 -6
- package/kits/skills/ec-service-proxy/SKILL.md +118 -0
- package/kits/skills/ec-trigger/SKILL.md +13 -5
- package/kits/skills/personal-assistant/SKILL.md +176 -0
- package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
- package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
- package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
- package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
- package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
- package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
- package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
- package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
- package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
- package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
- package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
- package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
- package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
- package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
- package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
- package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
- package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
- package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
- package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
- package/kits/templates/memory-consolidation/forget.md +19 -6
- package/kits/templates/memory-consolidation/notes.md +1 -1
- package/kits/templates/memory-consolidation/profile.md +2 -2
- package/kits/templates/memory-consolidation/promote.md +20 -3
- package/kits/templates/roles/member.json +8 -1
- package/kits/templates/session-capsule/recovery.md +5 -0
- package/kits/templates/session-capsule/renew.md +5 -0
- package/kits/templates/system-fragments/baseagent.md +2 -2
- package/kits/templates/system-fragments/bootstrap.md +6 -6
- package/kits/templates/system-fragments/channel.md +1 -1
- package/kits/templates/system-fragments/memory.md +4 -4
- package/package.json +7 -3
- package/dist/stats/billing.js +0 -215
package/dist/channels/daemon.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { appendExpireEntry, recordNextLaunchCleanup, cleanupPreviousByKind, runExpireCleanup, cleanupSessionRecord, } from '../core/background-session/session-cleanup.js';
|
|
2
2
|
import { ExecutionTimeoutError } from '../utils/error-utils.js';
|
|
3
|
+
import { logger } from '../utils/logger.js';
|
|
3
4
|
import { normalizeExecutionMode } from '../trigger/validation.js';
|
|
4
5
|
import { resolvePeerRoleDetail } from '../config/peer-role-resolver.js';
|
|
5
6
|
import { assertSystemSessionLaunchable } from '../core/system-session/registry.js';
|
|
6
7
|
import { sessionTopicThreadId } from '../core/thread/topic-id.js';
|
|
7
8
|
const DEFAULT_WATCHDOG_MS = 11 * 60 * 1000;
|
|
9
|
+
const EXPIRE_CLEANUP_INTERVAL_MS = 60 * 60 * 1000;
|
|
8
10
|
export class DaemonChannel {
|
|
9
11
|
sessionManager;
|
|
10
12
|
messageQueue;
|
|
@@ -23,15 +25,27 @@ export class DaemonChannel {
|
|
|
23
25
|
bgPending = new Map();
|
|
24
26
|
watchdogMs;
|
|
25
27
|
totalExecutionMs;
|
|
28
|
+
expireCleanupTimer;
|
|
26
29
|
constructor(sessionManager, messageQueue, opts = {}) {
|
|
27
30
|
this.sessionManager = sessionManager;
|
|
28
31
|
this.messageQueue = messageQueue;
|
|
29
32
|
this.watchdogMs = normalizeWatchdogMs(opts.watchdogMs);
|
|
30
33
|
this.totalExecutionMs = normalizeTotalExecutionMs(opts.totalExecutionMs);
|
|
34
|
+
// expire 扫描不能只挂在 converse / bg-session 启动上:script 与 target_session 类 trigger
|
|
35
|
+
// 不走 converse,记忆整理走 on_next_launch,实际几乎没有调用方,到期登记会一直不被消费。
|
|
36
|
+
// 启动时扫一次,之后每小时一次。
|
|
37
|
+
this.runExpireCleanupSafely();
|
|
38
|
+
this.expireCleanupTimer = setInterval(() => this.runExpireCleanupSafely(), EXPIRE_CLEANUP_INTERVAL_MS);
|
|
39
|
+
this.expireCleanupTimer.unref?.();
|
|
40
|
+
}
|
|
41
|
+
runExpireCleanupSafely() {
|
|
42
|
+
void runExpireCleanup(this.sessionManager).catch((e) => {
|
|
43
|
+
logger.warn(`[DaemonChannel] expire 清理失败: ${e?.message}`);
|
|
44
|
+
});
|
|
31
45
|
}
|
|
32
46
|
async converse(prompt, ctx) {
|
|
33
47
|
// 启动前跑一次 expire 扫描(成本低,只读少量小文件)
|
|
34
|
-
|
|
48
|
+
this.runExpireCleanupSafely();
|
|
35
49
|
const runId = ctx.runId;
|
|
36
50
|
const pendingId = ctx.attemptId ?? runId;
|
|
37
51
|
const messageId = pendingId;
|
|
@@ -187,11 +201,11 @@ export class DaemonChannel {
|
|
|
187
201
|
slot.acc.files.push({ path: payload.filePath, name: payload.fileName });
|
|
188
202
|
break;
|
|
189
203
|
case 'result.error':
|
|
190
|
-
slot.acc.error = { reason: payload.reason, text: payload.text, recoverable: payload.recoverable };
|
|
204
|
+
slot.acc.error = { reason: payload.reason, subtype: payload.subtype, text: payload.text, raw: payload.raw, recoverable: payload.recoverable };
|
|
191
205
|
this.finish(runId, 'error', { errorType: payload.reason ?? 'result_error' });
|
|
192
206
|
break;
|
|
193
207
|
case 'system.error':
|
|
194
|
-
slot.acc.error = { reason: payload.subtype, text: payload.text, recoverable: payload.recoverable };
|
|
208
|
+
slot.acc.error = { reason: payload.reason ?? payload.subtype, subtype: payload.subtype, text: payload.text, raw: payload.raw, recoverable: payload.recoverable };
|
|
195
209
|
this.finish(runId, 'error', { errorType: payload.subtype });
|
|
196
210
|
break;
|
|
197
211
|
case 'status.progress':
|
|
@@ -221,8 +235,10 @@ export class DaemonChannel {
|
|
|
221
235
|
case 'status.error':
|
|
222
236
|
if (payload.metadata?.message) {
|
|
223
237
|
slot.acc.error = {
|
|
224
|
-
reason: payload.metadata.errorType ?? 'status_error',
|
|
238
|
+
reason: payload.metadata.reason ?? payload.metadata.errorType ?? 'status_error',
|
|
239
|
+
subtype: payload.metadata.errorType,
|
|
225
240
|
text: payload.metadata.message,
|
|
241
|
+
raw: payload.metadata.raw,
|
|
226
242
|
recoverable: payload.metadata.recoverable,
|
|
227
243
|
};
|
|
228
244
|
}
|
|
@@ -236,6 +252,16 @@ export class DaemonChannel {
|
|
|
236
252
|
this.finish(runId, 'interrupted', payload.metadata);
|
|
237
253
|
break;
|
|
238
254
|
case 'status.timeout':
|
|
255
|
+
slot.acc.error = {
|
|
256
|
+
reason: payload.metadata?.reason ?? payload.metadata?.errorType ?? 'timeout',
|
|
257
|
+
subtype: payload.metadata?.errorType,
|
|
258
|
+
text: payload.metadata?.message
|
|
259
|
+
?? (payload.metadata?.idleSec
|
|
260
|
+
? `任务超时(${payload.metadata.idleSec}秒无响应),已自动中断`
|
|
261
|
+
: '任务超时,已自动中断'),
|
|
262
|
+
recoverable: payload.metadata?.recoverable,
|
|
263
|
+
raw: payload.metadata?.raw,
|
|
264
|
+
};
|
|
239
265
|
this.finish(runId, 'timeout', payload.metadata);
|
|
240
266
|
break;
|
|
241
267
|
}
|
|
@@ -424,9 +450,13 @@ export class DaemonChannel {
|
|
|
424
450
|
slot.acc.error = {
|
|
425
451
|
reason: 'daemon_watchdog_timeout',
|
|
426
452
|
text: `daemon conversation watchdog timed out after ${this.watchdogMs}ms`,
|
|
453
|
+
recoverable: true,
|
|
427
454
|
};
|
|
428
|
-
if (!this.claimTerminal(slot, '
|
|
455
|
+
if (!this.claimTerminal(slot, 'timeout', {
|
|
429
456
|
errorType: 'daemon_watchdog_timeout',
|
|
457
|
+
reason: 'daemon_watchdog_timeout',
|
|
458
|
+
message: slot.acc.error.text,
|
|
459
|
+
recoverable: true,
|
|
430
460
|
watchdogMs: this.watchdogMs,
|
|
431
461
|
}))
|
|
432
462
|
return;
|
|
@@ -448,9 +478,13 @@ export class DaemonChannel {
|
|
|
448
478
|
slot.acc.error = {
|
|
449
479
|
reason: 'daemon_total_execution_timeout',
|
|
450
480
|
text: `daemon conversation exceeded total execution limit of ${totalExecutionMs}ms`,
|
|
481
|
+
recoverable: true,
|
|
451
482
|
};
|
|
452
483
|
if (!this.claimTerminal(slot, 'timeout', {
|
|
453
484
|
errorType: 'daemon_total_execution_timeout',
|
|
485
|
+
reason: 'daemon_total_execution_timeout',
|
|
486
|
+
message: slot.acc.error.text,
|
|
487
|
+
recoverable: true,
|
|
454
488
|
totalExecutionMs,
|
|
455
489
|
}))
|
|
456
490
|
return;
|
|
@@ -82,6 +82,8 @@ function printAgentNewHelp() {
|
|
|
82
82
|
--project <path> 默认: 当前目录
|
|
83
83
|
--baseagent <claude|codex|gemini|ecagent>
|
|
84
84
|
默认: defaults 配置,否则检测本机可用基座
|
|
85
|
+
--model <id> 初始化可选;须在主机当前基座的可见模型目录中
|
|
86
|
+
--effort <level> 初始化可选;需同时指定 model,auto 使用默认强度
|
|
85
87
|
--owner <aid> 必填;初始协议 Owner 绑定意图
|
|
86
88
|
--name <display-name> 初始化必填;Bootstrap 默认取项目名称
|
|
87
89
|
--description <text> 初始化必填;Bootstrap 默认取项目描述
|
package/dist/cli/agent-create.js
CHANGED
|
@@ -22,6 +22,7 @@ import { uploadAvatarFile, uploadAvatarUrl } from '../utils/avatar-upload.js';
|
|
|
22
22
|
import { readTaskRuntimeContextFromEnv } from './task-context.js';
|
|
23
23
|
import { logger } from '../utils/logger.js';
|
|
24
24
|
import { creationOwnershipBinding } from '../core/ownership/owner-resolver.js';
|
|
25
|
+
import { getCatalog, resolveCatalogModel, catalogEfforts, assertCatalogSelectable } from '../core/model/model-catalog.js';
|
|
25
26
|
/** Select the creation lifecycle independently of --non-interactive. */
|
|
26
27
|
export function resolveAgentCreateMode(args) {
|
|
27
28
|
if (args.includes('--initialize') && args.includes('--bootstrap')) {
|
|
@@ -697,23 +698,32 @@ export function initializationPath(aid) {
|
|
|
697
698
|
return path.join(agentDataDir(aid), 'initialization.json');
|
|
698
699
|
}
|
|
699
700
|
export function initializationFingerprint(plan) {
|
|
700
|
-
|
|
701
|
+
const values = [
|
|
701
702
|
plan.aid, plan.project, plan.baseagent, plan.ownerAid, plan.name,
|
|
702
703
|
plan.description, plan.type, plan.tags, plan.persona ?? null,
|
|
703
704
|
plan.avatarFile ?? null, plan.avatarUrl ?? null,
|
|
704
|
-
|
|
705
|
+
...(plan.model !== undefined || plan.effort !== undefined
|
|
706
|
+
? [{ model: plan.model ?? null, effort: plan.effort ?? null }]
|
|
707
|
+
: []),
|
|
708
|
+
];
|
|
709
|
+
return createHash('sha256').update(JSON.stringify(values)).digest('hex');
|
|
705
710
|
}
|
|
706
711
|
export function readInitialization(aid) {
|
|
707
712
|
const file = initializationPath(aid);
|
|
708
713
|
if (!fs.existsSync(file))
|
|
709
714
|
return null;
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
||
|
|
713
|
-
|
|
714
|
-
|
|
715
|
+
try {
|
|
716
|
+
const record = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
717
|
+
if (record.version !== 1 || record.plan?.aid !== aid || !/^init-[a-f0-9]{24}$/.test(record.operationId)
|
|
718
|
+
|| !['in_progress', 'failed', 'complete', 'cancelled'].includes(record.status)
|
|
719
|
+
|| initializationFingerprint(record.plan) !== record.fingerprint) {
|
|
720
|
+
failure('INITIALIZE_STATE_INVALID');
|
|
721
|
+
}
|
|
722
|
+
return record;
|
|
723
|
+
}
|
|
724
|
+
catch {
|
|
725
|
+
failure('INITIALIZE_STATE_INVALID');
|
|
715
726
|
}
|
|
716
|
-
return record;
|
|
717
727
|
}
|
|
718
728
|
export function saveInitialization(record) {
|
|
719
729
|
const file = initializationPath(record.plan.aid);
|
|
@@ -734,8 +744,8 @@ export function initializationSummary(aid) {
|
|
|
734
744
|
return {
|
|
735
745
|
mode: 'supplied', operationId: r.operationId, fingerprint: r.fingerprint,
|
|
736
746
|
status: r.status, phase: r.phase, complete: r.status === 'complete',
|
|
737
|
-
code: r.code, error: r.error, retryable: r.status === 'failed',
|
|
738
|
-
nextStep: r.status === 'failed' ? `ec agent initialize ${aid} --resume` :
|
|
747
|
+
code: r.code ?? null, error: r.error ?? null, retryable: r.status === 'failed',
|
|
748
|
+
nextStep: r.status === 'failed' ? `ec agent initialize ${aid} --resume` : null,
|
|
739
749
|
agentmd: { published: r.published === true, verified: r.verified === true },
|
|
740
750
|
persona: { provided: r.plan.persona !== undefined },
|
|
741
751
|
avatar: { requested: r.plan.avatarFile !== undefined || r.plan.avatarUrl !== undefined, uploaded: r.avatarUploaded === true },
|
|
@@ -743,7 +753,10 @@ export function initializationSummary(aid) {
|
|
|
743
753
|
};
|
|
744
754
|
}
|
|
745
755
|
catch {
|
|
746
|
-
return {
|
|
756
|
+
return {
|
|
757
|
+
mode: 'supplied', status: 'failed', phase: 'unknown', complete: false,
|
|
758
|
+
code: 'INITIALIZE_STATE_INVALID', error: 'Initialization state is invalid', retryable: false,
|
|
759
|
+
};
|
|
747
760
|
}
|
|
748
761
|
}
|
|
749
762
|
/** Persistent guard also covers a removed/tampered config marker. */
|
|
@@ -767,13 +780,21 @@ function failure(code, error = code) {
|
|
|
767
780
|
throw Object.assign(new Error(error), { code });
|
|
768
781
|
}
|
|
769
782
|
export function validateInitializationPlan(plan) {
|
|
770
|
-
if (
|
|
783
|
+
if (typeof plan.name !== 'string' || !plan.name.trim()
|
|
784
|
+
|| typeof plan.description !== 'string' || !plan.description.trim()
|
|
785
|
+
|| !Array.isArray(plan.tags) || typeof plan.ownerAid !== 'string' || !plan.ownerAid.trim()) {
|
|
771
786
|
failure('INITIALIZE_FIELDS_REQUIRED', 'Explicit name, description, tags and one Owner AID are required');
|
|
772
787
|
}
|
|
773
788
|
if (!isValidAid(plan.ownerAid))
|
|
774
789
|
failure('INVALID_ARGS', 'Owner must be a valid AID');
|
|
775
790
|
if (plan.type !== 'agent')
|
|
776
791
|
failure('INVALID_ARGS', 'Initialized targets must have type=agent');
|
|
792
|
+
if (plan.model !== undefined && (typeof plan.model !== 'string' || !plan.model.trim() || plan.model.length > 512)) {
|
|
793
|
+
failure('INVALID_ARGS', 'model must be a non-empty string of at most 512 characters');
|
|
794
|
+
}
|
|
795
|
+
if (plan.effort !== undefined && (typeof plan.effort !== 'string' || !plan.effort.trim() || plan.effort.length > 64)) {
|
|
796
|
+
failure('INVALID_ARGS', 'effort must be a non-empty string of at most 64 characters');
|
|
797
|
+
}
|
|
777
798
|
if (plan.avatarFile !== undefined && plan.avatarUrl !== undefined)
|
|
778
799
|
failure('INVALID_ARGS', 'avatar-file and avatar-url are mutually exclusive');
|
|
779
800
|
const error = validateAgentCreatePlan({
|
|
@@ -782,8 +803,9 @@ export function validateInitializationPlan(plan) {
|
|
|
782
803
|
});
|
|
783
804
|
if (error)
|
|
784
805
|
failure('INVALID_ARGS', error);
|
|
785
|
-
if (!path.isAbsolute(plan.project))
|
|
806
|
+
if (typeof plan.project !== 'string' || !path.isAbsolute(plan.project)) {
|
|
786
807
|
failure('INVALID_ARGS', 'project must be an absolute path');
|
|
808
|
+
}
|
|
787
809
|
if (fs.existsSync(plan.project) && !fs.statSync(plan.project).isDirectory())
|
|
788
810
|
failure('INVALID_ARGS', 'project is not a directory');
|
|
789
811
|
const card = validateAgentMdFrontmatter(buildInitialAgentMd(plan), plan.aid);
|
|
@@ -797,6 +819,44 @@ export function validateInitializationPlan(plan) {
|
|
|
797
819
|
failure('INVALID_ARGS', personaError);
|
|
798
820
|
}
|
|
799
821
|
}
|
|
822
|
+
export async function validateInitializationModelArgs(args) {
|
|
823
|
+
const plan = args.plan && typeof args.plan === 'object' && !Array.isArray(args.plan) ? args.plan : args;
|
|
824
|
+
const modelValue = plan.model ?? args.model;
|
|
825
|
+
const effortValue = plan.effort ?? args.effort;
|
|
826
|
+
if (modelValue !== undefined && typeof modelValue !== 'string') {
|
|
827
|
+
return { error: 'model 必须是字符串', code: 'INVALID_ARGS' };
|
|
828
|
+
}
|
|
829
|
+
if (effortValue !== undefined && typeof effortValue !== 'string') {
|
|
830
|
+
return { error: 'effort 必须是字符串', code: 'INVALID_ARGS' };
|
|
831
|
+
}
|
|
832
|
+
const model = typeof modelValue === 'string' ? modelValue.trim() : '';
|
|
833
|
+
const effort = typeof effortValue === 'string' ? effortValue.trim() : '';
|
|
834
|
+
if (!model && (!effort || effort === 'auto'))
|
|
835
|
+
return undefined;
|
|
836
|
+
if (!model && effort && effort !== 'auto') {
|
|
837
|
+
return { error: '设置 effort 时必须同时指定 model', code: 'INVALID_ARGS' };
|
|
838
|
+
}
|
|
839
|
+
const baseagentValue = plan.baseagent ?? args.baseagent;
|
|
840
|
+
const baseagent = typeof baseagentValue === 'string' ? baseagentValue.trim() : '';
|
|
841
|
+
if (!baseagent)
|
|
842
|
+
return { error: '指定 model/effort 时必须提供 baseagent', code: 'INVALID_ARGS' };
|
|
843
|
+
try {
|
|
844
|
+
const catalog = await getCatalog(undefined, baseagent);
|
|
845
|
+
assertCatalogSelectable(catalog);
|
|
846
|
+
const modelIds = catalog.models.map(entry => entry.id);
|
|
847
|
+
const resolvedModel = resolveCatalogModel(catalog, model);
|
|
848
|
+
if (!modelIds.includes(model) && !modelIds.includes(resolvedModel)) {
|
|
849
|
+
return { error: `模型不在当前主机 ${baseagent} 的可见目录中: ${model}`, code: 'INVALID_ARGS' };
|
|
850
|
+
}
|
|
851
|
+
if (effort && effort !== 'auto' && !catalogEfforts(catalog, resolvedModel, baseagent).includes(effort)) {
|
|
852
|
+
return { error: `模型 ${model} 不支持推理强度: ${effort}`, code: 'INVALID_ARGS' };
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
catch (error) {
|
|
856
|
+
return { error: error instanceof Error ? error.message : String(error), code: 'MODEL_UNAVAILABLE' };
|
|
857
|
+
}
|
|
858
|
+
return undefined;
|
|
859
|
+
}
|
|
800
860
|
function cardHash(content) {
|
|
801
861
|
return createHash('sha256').update(content).digest('hex');
|
|
802
862
|
}
|
|
@@ -859,6 +919,8 @@ export class AgentInitializationService {
|
|
|
859
919
|
resume(aid, actor) {
|
|
860
920
|
if (this.deps.authorize && !this.deps.authorize(actor))
|
|
861
921
|
failure('NOT_ALLOWED');
|
|
922
|
+
if (!isValidAid(aid))
|
|
923
|
+
failure('INVALID_ARGS', 'Invalid initialization AID');
|
|
862
924
|
const r = readInitialization(aid);
|
|
863
925
|
if (!r)
|
|
864
926
|
failure('NOT_FOUND');
|
|
@@ -952,8 +1014,11 @@ export class AgentInitializationService {
|
|
|
952
1014
|
const config = loadAgent(r.plan.aid);
|
|
953
1015
|
if (r.configSaved && (!config || config.enabled === false))
|
|
954
1016
|
failure('INITIALIZE_TARGET_CHANGED');
|
|
1017
|
+
const baseagentConfig = config?.baseagents?.[r.plan.baseagent];
|
|
955
1018
|
if (config && (config.initialization?.operationId !== r.operationId
|
|
956
|
-
|| config.active_baseagent !== r.plan.baseagent || config.projects?.defaultPath !== r.plan.project
|
|
1019
|
+
|| config.active_baseagent !== r.plan.baseagent || config.projects?.defaultPath !== r.plan.project
|
|
1020
|
+
|| baseagentConfig?.model !== r.plan.model
|
|
1021
|
+
|| baseagentConfig?.effort !== r.plan.effort)) {
|
|
957
1022
|
failure('INITIALIZE_TARGET_CHANGED');
|
|
958
1023
|
}
|
|
959
1024
|
}
|
|
@@ -973,7 +1038,12 @@ export class AgentInitializationService {
|
|
|
973
1038
|
$schema_version: CONFIG_SCHEMA_VERSION, aid: p.aid, enabled: true, lifecycle: 'created',
|
|
974
1039
|
initialization: { mode: 'supplied', operationId: r.operationId }, channels: [],
|
|
975
1040
|
projects: { defaultPath: p.project }, active_baseagent: p.baseagent,
|
|
976
|
-
baseagents: {
|
|
1041
|
+
baseagents: {
|
|
1042
|
+
[p.baseagent]: {
|
|
1043
|
+
...(p.model ? { model: p.model } : {}),
|
|
1044
|
+
...(p.effort ? { effort: p.effort } : {}),
|
|
1045
|
+
},
|
|
1046
|
+
}, chatmode: { private: 'interactive', group: 'proactive', nothuman: 'proactive' },
|
|
977
1047
|
});
|
|
978
1048
|
}
|
|
979
1049
|
r.configSaved = true;
|
|
@@ -1100,7 +1170,7 @@ export class AgentInitializationService {
|
|
|
1100
1170
|
}
|
|
1101
1171
|
}
|
|
1102
1172
|
/** Called only after the IPC adapter has validated the local control token. */
|
|
1103
|
-
export function executeLocalInitializationCommand(service, command) {
|
|
1173
|
+
export async function executeLocalInitializationCommand(service, command) {
|
|
1104
1174
|
try {
|
|
1105
1175
|
if (!Array.isArray(command.argv) || command.argv.some(value => typeof value !== 'string')) {
|
|
1106
1176
|
return { ok: false, code: 'INVALID_ARGS', error: 'argv required' };
|
|
@@ -1115,7 +1185,11 @@ export function executeLocalInitializationCommand(service, command) {
|
|
|
1115
1185
|
return { ok: false, code: 'NOT_FOUND', error: 'No initialization record' };
|
|
1116
1186
|
return service.resume(parsed.aid, record.actor);
|
|
1117
1187
|
}
|
|
1118
|
-
|
|
1188
|
+
const plan = resolveInitializationPlan(argv);
|
|
1189
|
+
const modelError = await validateInitializationModelArgs(plan);
|
|
1190
|
+
if (modelError)
|
|
1191
|
+
return { ok: false, ...modelError };
|
|
1192
|
+
return service.start(plan, 'local-control', parsed.dryRun);
|
|
1119
1193
|
}
|
|
1120
1194
|
catch (error) {
|
|
1121
1195
|
return {
|
|
@@ -1134,7 +1208,7 @@ export function parseInitializationArgs(args) {
|
|
|
1134
1208
|
throw new Error('--bootstrap cannot initialize an agent');
|
|
1135
1209
|
const booleans = new Set(resume ? ['--resume'] : ['--initialize', '--non-interactive', '--dry-run']);
|
|
1136
1210
|
const strings = new Set(resume ? ['--wait', '--format'] : [
|
|
1137
|
-
'--project', '--baseagent', '--owner', '--name', '--description', '--tags', '--type', '--avatar-file', '--avatar-url',
|
|
1211
|
+
'--project', '--baseagent', '--model', '--effort', '--owner', '--name', '--description', '--tags', '--type', '--avatar-file', '--avatar-url',
|
|
1138
1212
|
'--persona-file', '--persona-text', '--wait', '--format',
|
|
1139
1213
|
]);
|
|
1140
1214
|
const seen = new Set();
|
|
@@ -1187,8 +1261,13 @@ export function resolveInitializationPlan(args, context) {
|
|
|
1187
1261
|
avatarFile: v['--avatar-file'], avatarUrl: v['--avatar-url'],
|
|
1188
1262
|
name: v['--name'], description: v['--description'], tags: parseAgentTags(v['--tags']), type: v['--type'],
|
|
1189
1263
|
}, context?.projectCwd);
|
|
1264
|
+
const model = v['--model']?.trim();
|
|
1265
|
+
const effort = v['--effort']?.trim();
|
|
1190
1266
|
return {
|
|
1191
|
-
aid: p.aid, project: p.project, baseagent: p.baseagent ?? '',
|
|
1267
|
+
aid: p.aid, project: p.project, baseagent: p.baseagent ?? '',
|
|
1268
|
+
...(model ? { model } : {}),
|
|
1269
|
+
...(effort && effort !== 'auto' ? { effort } : {}),
|
|
1270
|
+
ownerAid: p.owner ?? '',
|
|
1192
1271
|
name: p.name, description: p.description, tags: p.tags, type: p.type,
|
|
1193
1272
|
...(persona !== undefined ? { persona } : {}),
|
|
1194
1273
|
...(v['--avatar-file'] !== undefined ? { avatarFile: v['--avatar-file'] } : {}),
|
package/dist/cli/agent.js
CHANGED
|
@@ -167,14 +167,16 @@ export async function agentShow(aid) {
|
|
|
167
167
|
if (!agent) {
|
|
168
168
|
const init = initializationSummary(aid);
|
|
169
169
|
if (init) {
|
|
170
|
+
const lifecycle = loadAgent(aid)?.lifecycle ?? null;
|
|
170
171
|
return {
|
|
171
172
|
ok: true,
|
|
172
173
|
aid,
|
|
173
174
|
status: 'initializing',
|
|
174
|
-
lifecycle
|
|
175
|
+
lifecycle,
|
|
175
176
|
identity: { name: null, description: null },
|
|
176
177
|
config: { baseagent: null, model: null, effort: null, chatmode: null, channels: [] },
|
|
177
178
|
connection: null,
|
|
179
|
+
usable: false,
|
|
178
180
|
sessions: { active: 0, last_activity: null },
|
|
179
181
|
paths: {
|
|
180
182
|
config: toPosix(path.join(p.agentsDir, aid, 'config.json')),
|
|
@@ -207,11 +209,13 @@ export async function agentShow(aid) {
|
|
|
207
209
|
}
|
|
208
210
|
const identity = readAgentMdIdentity(aid);
|
|
209
211
|
const agentMdPath = getAgentMdPath(aid);
|
|
212
|
+
const lifecycle = loadAgent(aid)?.lifecycle ?? null;
|
|
213
|
+
const initializationState = initializationSummary(aid);
|
|
210
214
|
return {
|
|
211
215
|
ok: true,
|
|
212
216
|
aid,
|
|
213
217
|
status: agentInfo.status || 'unknown',
|
|
214
|
-
lifecycle
|
|
218
|
+
lifecycle,
|
|
215
219
|
identity,
|
|
216
220
|
config: {
|
|
217
221
|
baseagent: agentInfo.baseagent || null,
|
|
@@ -221,6 +225,10 @@ export async function agentShow(aid) {
|
|
|
221
225
|
channels: agentInfo.channels || [],
|
|
222
226
|
},
|
|
223
227
|
connection: connectionInfo,
|
|
228
|
+
...(initializationState ? {
|
|
229
|
+
initialization: initializationState,
|
|
230
|
+
usable: initializationState.complete === true && lifecycle === 'active' && connectionInfo?.status === 'connected',
|
|
231
|
+
} : {}),
|
|
224
232
|
sessions: {
|
|
225
233
|
active: agentInfo.activeSessions || 0,
|
|
226
234
|
last_activity: agentInfo.lastActivity ? new Date(agentInfo.lastActivity).toISOString() : null,
|
|
@@ -231,7 +239,6 @@ export async function agentShow(aid) {
|
|
|
231
239
|
project: toPosix(agentInfo.projectPath || null),
|
|
232
240
|
data: toPosix(path.join(p.agentsDir, aid, 'data')),
|
|
233
241
|
},
|
|
234
|
-
...(initializationSummary(aid) ? { initialization: initializationSummary(aid) } : {}),
|
|
235
242
|
...(stale ? { stale: true } : {}),
|
|
236
243
|
};
|
|
237
244
|
}
|