evolcore 0.0.31 → 0.0.33
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 +35 -0
- package/bin/install-codex-managed-hooks.mjs +124 -37
- package/dist/agents/claude-runner.js +29 -2
- package/dist/agents/codex/app-server-client.js +3 -0
- package/dist/agents/codex/diagnostics.js +76 -44
- package/dist/agents/codex-runner.js +51 -24
- package/dist/agents/ecagent-runner.js +9 -13
- package/dist/agents/gemini-runner.js +4 -0
- package/dist/aun/aid/store.js +0 -81
- package/dist/aun/group/fs-download.js +1 -10
- package/dist/aun/group/operations.js +0 -1
- package/dist/aun/msg/history.js +1 -0
- package/dist/aun/msg/managed-operation.js +130 -32
- package/dist/aun/msg/p2p.js +0 -1
- package/dist/aun/outbox.js +50 -1
- package/dist/aun/service-proxy.js +12 -18
- package/dist/aun/storage/index.js +29 -0
- package/dist/channels/aun.js +38 -137
- package/dist/channels/daemon.js +257 -2
- package/dist/cli/agent-command.js +64 -31
- package/dist/cli/agent-create.js +43 -24
- package/dist/cli/agent.js +16 -70
- package/dist/cli/aun-commands.js +512 -32
- package/dist/cli/contact.js +8 -2
- package/dist/cli/ctl-command.js +1 -2
- package/dist/cli/daemon-commands.js +82 -13
- package/dist/cli/debug-mode.js +154 -0
- package/dist/cli/diag.js +2 -2
- package/dist/cli/handoff-command.js +18 -5
- package/dist/cli/index.js +81 -64
- package/dist/cli/init.js +2 -2
- package/dist/cli/managed-command-guard.js +5 -0
- package/dist/cli/memory-command.js +93 -12
- package/dist/cli/model.js +14 -138
- package/dist/cli/queue-command.js +51 -0
- package/dist/cli/response.js +5 -54
- package/dist/cli/session-command.js +194 -0
- package/dist/cli/skill-command.js +85 -3
- package/dist/cli/stats.js +10 -4
- package/dist/cli/task-command.js +1 -0
- package/dist/cli/task-context.js +16 -0
- package/dist/cli/thread-command.js +620 -0
- package/dist/cli/trigger-command.js +76 -50
- package/dist/config/builtin-roles.js +9 -7
- package/dist/config/config-field-policy.js +2 -3
- package/dist/config/config-manager.js +7 -2
- package/dist/config/resolved-config-op.js +3 -0
- package/dist/config-store.js +15 -0
- package/dist/core/agent-ipc-registration.js +65 -22
- package/dist/core/auth/agent-delegation.js +42 -2
- package/dist/core/auth/debug-context.js +139 -0
- package/dist/core/auth/delegation-authorization.js +1 -0
- package/dist/core/auth/operation-authorizer.js +24 -1
- package/dist/core/auth/operation-catalog.js +44 -3
- package/dist/core/background-session/session-cleanup.js +212 -0
- package/dist/core/background-session/types.js +10 -0
- package/dist/core/bootstrap-messages.js +1 -1
- package/dist/core/bootstrap-service.js +6 -3
- package/dist/core/command/command-handler.js +224 -45
- package/dist/core/command/diag-service.js +5 -1
- package/dist/core/command/memory-slash.js +6 -2
- package/dist/core/command/menu-catalog.js +48 -1
- package/dist/core/command/menu-handler.js +92 -16
- package/dist/core/command/menu-protocol.js +24 -1
- package/dist/core/command/skill-slash.js +322 -0
- package/dist/core/command/slash-gate.js +6 -4
- package/dist/core/command/slash-handler.js +193 -13
- package/dist/core/command/topic-slash.js +528 -0
- package/dist/core/evolagent-registry.js +20 -5
- package/dist/core/handoff/ipc-registration.js +38 -0
- package/dist/core/handoff/runtime.js +5 -11
- package/dist/core/handoff/store.js +5 -0
- package/dist/core/ipc-registration.js +210 -9
- package/dist/core/memory/consolidation-context.js +49 -16
- package/dist/core/memory/consolidation-ops-records.js +35 -0
- package/dist/core/memory/consolidation-queue-format.js +21 -0
- package/dist/core/memory/consolidation.js +174 -180
- package/dist/core/message/aun-ipc-sender.js +207 -8
- package/dist/core/message/im-renderer.js +149 -6
- package/dist/core/message/message-bridge.js +13 -3
- package/dist/core/message/message-log.js +1 -0
- package/dist/core/message/message-queue.js +131 -3
- package/dist/core/message/peer-mode.js +6 -1
- package/dist/core/message/response-engine.js +379 -69
- package/dist/core/message/subtask-tool-projection.js +140 -0
- package/dist/core/model/catalog-service.js +17 -12
- package/dist/core/permission/ec-command-parser.js +126 -7
- package/dist/core/permission/sandbox-runtime.js +14 -1
- package/dist/core/session/session-idle-monitor.js +249 -22
- package/dist/core/session/session-manager.js +54 -9
- package/dist/core/skill/command-parser.js +13 -0
- package/dist/core/skill/index-generator.js +4 -1
- package/dist/core/skill/startup.js +41 -0
- package/dist/core/skill/switch-resolver.js +55 -29
- package/dist/core/task/task-recovery-service.js +2 -0
- package/dist/core/task/task-resume-operation.js +11 -0
- package/dist/core/thread/command-parser.js +125 -0
- package/dist/core/thread/index.js +1 -0
- package/dist/core/thread/ipc-operation.js +95 -0
- package/dist/core/thread/thread-context-storage.js +131 -0
- package/dist/core/thread/thread-operation.js +258 -0
- package/dist/core/thread/thread-route.js +33 -0
- package/dist/core/thread/thread-service.js +777 -0
- package/dist/core/thread/types.js +1 -0
- package/dist/eck/message-renderer.js +35 -0
- package/dist/index.js +10 -7
- package/dist/ipc.js +234 -17
- package/dist/paths.js +23 -0
- package/dist/response-system/engines/v1/proactive-flow.js +169 -80
- package/dist/trigger/authorization.js +59 -29
- package/dist/trigger/feedback.js +7 -1
- package/dist/trigger/ipc-service.js +49 -35
- package/dist/trigger/parser.js +63 -1
- package/dist/trigger/script-sandbox.js +58 -77
- package/dist/trigger/validation.js +14 -0
- package/dist/utils/error-utils.js +22 -1
- package/kits/docs/AUTHORING.md +1 -1
- package/kits/docs/channels/aun.md +8 -0
- package/kits/docs/context-assembly.md +1 -0
- package/kits/docs/evolcore/INDEX.md +3 -2
- package/kits/docs/evolcore/agent-create.md +39 -28
- package/kits/docs/evolcore/agent.md +19 -4
- package/kits/docs/evolcore/ec-capabilities.md +4 -0
- package/kits/docs/evolcore/group-collaboration.md +3 -5
- package/kits/docs/evolcore/group.md +3 -4
- package/kits/docs/evolcore/memory-consolidation.md +1 -1
- package/kits/docs/evolcore/menu-exec-schema-commands.md +2 -2
- package/kits/docs/evolcore/menu-protocol.md +7 -0
- package/kits/docs/evolcore/msg.md +5 -8
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/thread-chain.md +267 -0
- package/kits/docs/evolcore/trigger.md +2 -2
- package/kits/docs/prompt-loading-architecture.md +1 -0
- package/kits/eck_manifest.json +61 -26
- package/kits/eck_message_manifest.json +169 -10
- package/kits/rules/01-overview.md +0 -9
- package/kits/rules/05-venue.md +1 -1
- package/kits/rules/06-channel.md +7 -1
- package/kits/rules/07-memory-and-thread.md +202 -0
- package/kits/schemas/relation-config.schema.9.json +18 -3
- package/kits/schemas/role-config.schema.1.json +6 -6
- package/kits/schemas/single-session.schema.1.json +6 -6
- package/kits/schemas/single-session.schema.2.json +6 -6
- package/kits/schemas/single-session.schema.3.json +6 -6
- package/kits/skills/.switches.json +12 -1
- package/kits/skills/ec-group/SKILL.md +234 -0
- package/kits/skills/ec-skill/SKILL.md +10 -1
- package/kits/skills/ec-skill/scripts/cli.mjs +15 -1
- package/kits/skills/scrapling-article-fetch/SKILL.md +128 -0
- package/kits/skills/scrapling-article-fetch/scripts/check_python_env.py +54 -0
- package/kits/skills/scrapling-article-fetch/scripts/render_markdown_reply.py +35 -0
- package/kits/skills/scrapling-article-fetch/scripts/run_pipeline.sh +16 -0
- package/kits/skills/scrapling-article-fetch/scripts/scrapling_fetch.py +344 -0
- package/kits/skills/thread-ops/SKILL.md +492 -0
- package/kits/skills/wechat-article-media-download/SKILL.md +65 -0
- package/kits/skills/wechat-article-media-download/scripts/download.py +163 -0
- package/kits/skills/wechat-article-reader/SKILL.md +97 -0
- package/kits/skills/wechat-article-reader/scripts/fetch.mjs +256 -0
- package/kits/templates/bootstrap-welcome.md +7 -7
- package/kits/templates/memory-consolidation/forget.md +5 -0
- package/kits/templates/memory-consolidation/generalize.md +5 -0
- package/kits/templates/memory-consolidation/profile.md +5 -0
- package/kits/templates/memory-consolidation/promote.md +5 -0
- package/kits/templates/message-fragments/item.md +2 -1
- package/kits/templates/message-fragments/thread-context.md +6 -0
- package/kits/templates/message-fragments/trigger-session.md +2 -0
- package/kits/templates/message-fragments/trigger-thread-check.md +2 -0
- package/kits/templates/roles/member.json +2 -0
- package/kits/templates/roles/visitor.json +2 -0
- package/kits/templates/system-fragments/bootstrap.md +66 -72
- package/kits/templates/system-fragments/channel.md +3 -6
- package/kits/templates/system-fragments/commands.md +2 -1
- package/kits/templates/system-fragments/managed-runtime.md +15 -0
- package/kits/templates/system-fragments/reply.md +3 -2
- package/kits/templates/system-fragments/session.md +5 -14
- package/package.json +3 -1
- package/kits/docs/evolcore/group-fs.md +0 -17
- package/kits/docs/venues/aun-group.md +0 -45
- package/kits/docs/venues/group.md +0 -43
package/dist/cli/model.js
CHANGED
|
@@ -19,10 +19,8 @@ import { resolvePaths } from '../paths.js';
|
|
|
19
19
|
import { ipcQuery } from '../ipc.js';
|
|
20
20
|
import { parsePeerKey } from '../core/relation/peer-identity.js';
|
|
21
21
|
import { resolvePeerRoleDetail } from '../config/peer-role-resolver.js';
|
|
22
|
-
import { getFieldPermission } from '../config/roles.js';
|
|
23
22
|
import { AGENT_DELEGATION_TOKEN_ENV, readDelegationCredential } from '../core/auth/agent-delegation.js';
|
|
24
23
|
import { formatModelCheck, runModelCheck } from '../core/model/model-diagnostics.js';
|
|
25
|
-
import { validateRuntimeStringFieldOverride } from '../core/role/runtime-policy.js';
|
|
26
24
|
const ALL_EFFORTS = ['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max', 'auto'];
|
|
27
25
|
const SCOPE_LABEL = {
|
|
28
26
|
global: '全局', agent: 'agent级', role: '角色级', relation: '关系级',
|
|
@@ -45,29 +43,21 @@ function fail(formatJson, code, message, data) {
|
|
|
45
43
|
}
|
|
46
44
|
process.exit(1);
|
|
47
45
|
}
|
|
48
|
-
function
|
|
49
|
-
void args;
|
|
50
|
-
return !!process.env.EVOLCORE_SESSION_ID;
|
|
51
|
-
}
|
|
52
|
-
function isManagedTargetedWriteEnv(args) {
|
|
53
|
-
return !!process.env.EVOLCORE_SESSION_ID
|
|
54
|
-
&& !isManagedSessionEnv(args);
|
|
55
|
-
}
|
|
56
|
-
async function runCtlCommand(cmd, formatJson, timeoutMs = 10_000) {
|
|
46
|
+
async function runManagedCliOperation(args, formatJson, timeoutMs = 10_000) {
|
|
57
47
|
const sessionId = process.env.EVOLCORE_SESSION_ID;
|
|
58
48
|
if (!sessionId)
|
|
59
49
|
fail(formatJson, 'NO_SESSION', 'EVOLCORE_SESSION_ID 未设置');
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
50
|
+
const delegationToken = readDelegationCredential();
|
|
51
|
+
if (!delegationToken)
|
|
52
|
+
fail(formatJson, 'DELEGATION_REQUIRED', `${AGENT_DELEGATION_TOKEN_ENV} 未设置`);
|
|
53
|
+
const response = await ipcQuery(resolvePaths().socket, {
|
|
54
|
+
type: 'ctl', argv: args, sessionId, delegationToken,
|
|
65
55
|
}, timeoutMs);
|
|
66
|
-
if (!
|
|
56
|
+
if (!response)
|
|
67
57
|
fail(formatJson, 'DAEMON_UNAVAILABLE', '无法连接 evolcore 服务');
|
|
68
|
-
if (!
|
|
69
|
-
fail(formatJson, 'CTL_FAILED',
|
|
70
|
-
|
|
58
|
+
if (!response.ok)
|
|
59
|
+
fail(formatJson, response.code || 'CTL_FAILED', response.error || '命令执行失败');
|
|
60
|
+
printCtlResult({ text: response.result || '', data: response.data }, formatJson);
|
|
71
61
|
}
|
|
72
62
|
function printCtlResult(result, formatJson) {
|
|
73
63
|
if (formatJson) {
|
|
@@ -76,56 +66,6 @@ function printCtlResult(result, formatJson) {
|
|
|
76
66
|
}
|
|
77
67
|
console.log(result.text);
|
|
78
68
|
}
|
|
79
|
-
async function runManagedConfigOperation(args, formatJson) {
|
|
80
|
-
const sessionId = process.env.EVOLCORE_SESSION_ID;
|
|
81
|
-
if (!sessionId)
|
|
82
|
-
fail(formatJson, 'NO_SESSION', 'EVOLCORE_SESSION_ID 未设置');
|
|
83
|
-
const delegationToken = readDelegationCredential();
|
|
84
|
-
if (!delegationToken) {
|
|
85
|
-
fail(formatJson, 'DELEGATION_REQUIRED', `${AGENT_DELEGATION_TOKEN_ENV} 未设置`);
|
|
86
|
-
}
|
|
87
|
-
let response;
|
|
88
|
-
try {
|
|
89
|
-
response = await ipcQuery(resolvePaths().socket, {
|
|
90
|
-
type: 'config.op',
|
|
91
|
-
argv: ['config', ...args],
|
|
92
|
-
sessionId,
|
|
93
|
-
delegationToken,
|
|
94
|
-
}, 10_000);
|
|
95
|
-
}
|
|
96
|
-
catch {
|
|
97
|
-
response = null;
|
|
98
|
-
}
|
|
99
|
-
if (!response)
|
|
100
|
-
fail(formatJson, 'DAEMON_UNAVAILABLE', '无法连接 evolcore 服务');
|
|
101
|
-
if (!response.ok || !response.result?.ok) {
|
|
102
|
-
fail(formatJson, response.code || 'CONFIG_AUTH_FAILED', response.error || 'config 操作失败', response.data);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
function configSelectorArgs(sel) {
|
|
106
|
-
const args = ['--self', sel.self];
|
|
107
|
-
if (sel.peerKey)
|
|
108
|
-
args.push('--peer', sel.peerKey);
|
|
109
|
-
return args;
|
|
110
|
-
}
|
|
111
|
-
async function setManagedModelField(sel, field, value, formatJson) {
|
|
112
|
-
const subcommand = value === null ? ['unset', field] : ['set', field, value];
|
|
113
|
-
await runManagedConfigOperation([...subcommand, ...configSelectorArgs(sel)], formatJson);
|
|
114
|
-
}
|
|
115
|
-
function preflightManagedFieldOverride(sel, role, field, value, formatJson) {
|
|
116
|
-
if (!role)
|
|
117
|
-
return;
|
|
118
|
-
const policy = getFieldPermission(role, field, sel.self);
|
|
119
|
-
if (policy?.allowOverride === false) {
|
|
120
|
-
fail(formatJson, 'ROLE_OVERRIDE_DISABLED', `Role ${role} cannot override ${field}`);
|
|
121
|
-
}
|
|
122
|
-
if (value === null)
|
|
123
|
-
return;
|
|
124
|
-
const decision = validateRuntimeStringFieldOverride({ selfAid: sel.self, role, field, value });
|
|
125
|
-
if (!decision.ok) {
|
|
126
|
-
fail(formatJson, decision.code || 'ROLE_VALUE_NOT_ALLOWED', decision.message || `Value ${value} is not allowed for ${field}`);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
69
|
/**
|
|
130
70
|
* 解析 --self / --peer 为作用域选择器。
|
|
131
71
|
*/
|
|
@@ -286,11 +226,6 @@ async function cmdList(args, formatJson) {
|
|
|
286
226
|
console.log(HELP);
|
|
287
227
|
return;
|
|
288
228
|
}
|
|
289
|
-
if (isManagedSessionEnv(args)) {
|
|
290
|
-
const out = await runCtlCommand('/model list', formatJson);
|
|
291
|
-
printCtlResult(out, formatJson);
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
229
|
const sel = parseSelector(args, formatJson);
|
|
295
230
|
const role = explicitOrDerivedRole(args, sel);
|
|
296
231
|
const effectiveSel = selectorWithRole(sel, role);
|
|
@@ -337,11 +272,6 @@ async function cmdCurrent(args, formatJson) {
|
|
|
337
272
|
console.log(HELP);
|
|
338
273
|
return;
|
|
339
274
|
}
|
|
340
|
-
if (isManagedSessionEnv(args)) {
|
|
341
|
-
const out = await runCtlCommand('/model current', formatJson);
|
|
342
|
-
printCtlResult(out, formatJson);
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
275
|
const sel = parseSelector(args, formatJson);
|
|
346
276
|
const ba = activeBaseagent(sel.self);
|
|
347
277
|
const role = explicitOrDerivedRole(args, sel);
|
|
@@ -372,11 +302,6 @@ async function cmdInfo(args, formatJson) {
|
|
|
372
302
|
const modelId = args[1] && !args[1].startsWith('--') ? args[1] : undefined;
|
|
373
303
|
if (!modelId)
|
|
374
304
|
fail(formatJson, 'MISSING_MODEL_ID', 'info 需要 <model-id>');
|
|
375
|
-
if (isManagedSessionEnv(args)) {
|
|
376
|
-
const out = await runCtlCommand(`/model info ${modelId}`, formatJson);
|
|
377
|
-
printCtlResult(out, formatJson);
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
305
|
const sel = parseSelector(args, formatJson);
|
|
381
306
|
const self = getArgValue(args, '--self');
|
|
382
307
|
const info = await getModelInfo(modelId, self);
|
|
@@ -424,12 +349,6 @@ async function cmdUse(args, formatJson) {
|
|
|
424
349
|
const modelId = args[1] && !args[1].startsWith('--') ? args[1] : undefined;
|
|
425
350
|
if (!modelId)
|
|
426
351
|
fail(formatJson, 'MISSING_MODEL_ID', 'use 需要 <model-id>');
|
|
427
|
-
if (isManagedSessionEnv(args)) {
|
|
428
|
-
const effort = getArgValue(args, '--effort');
|
|
429
|
-
const out = await runCtlCommand(`/model ${modelId}${effort ? ` ${effort}` : ''}`, formatJson);
|
|
430
|
-
printCtlResult(out, formatJson);
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
352
|
const sel = parseSelector(args, formatJson);
|
|
434
353
|
const role = explicitOrDerivedRole(args, sel);
|
|
435
354
|
const scope = determineWriteScope(sel, formatJson);
|
|
@@ -457,19 +376,6 @@ async function cmdUse(args, formatJson) {
|
|
|
457
376
|
fail(formatJson, 'INVALID_EFFORT', `当前模型目录未声明支持推理强度: ${effort}`);
|
|
458
377
|
}
|
|
459
378
|
const effortVal = effort === 'auto' ? null : (effort ?? undefined);
|
|
460
|
-
if (isManagedTargetedWriteEnv(args)) {
|
|
461
|
-
if (effortVal !== undefined) {
|
|
462
|
-
const effortKey = 'effort';
|
|
463
|
-
preflightManagedFieldOverride(sel, role, `baseagents.${ba}.${effortKey}`, effortVal, formatJson);
|
|
464
|
-
}
|
|
465
|
-
await setManagedModelField(sel, `baseagents.${ba}.model`, modelId, formatJson);
|
|
466
|
-
if (effortVal !== undefined) {
|
|
467
|
-
const effortKey = 'effort';
|
|
468
|
-
await setManagedModelField(sel, `baseagents.${ba}.${effortKey}`, effortVal, formatJson);
|
|
469
|
-
}
|
|
470
|
-
describeWrite(scope, sel, modelId, effort ?? null, formatJson);
|
|
471
|
-
return;
|
|
472
|
-
}
|
|
473
379
|
try {
|
|
474
380
|
writeScope(scope, sel, ba, { model: modelId, effort: effortVal });
|
|
475
381
|
}
|
|
@@ -491,11 +397,6 @@ async function cmdEffort(args, formatJson) {
|
|
|
491
397
|
if (!ALL_EFFORTS.includes(level)) {
|
|
492
398
|
fail(formatJson, 'INVALID_EFFORT', `无效推理强度: ${level}(${ALL_EFFORTS.join('/')})`);
|
|
493
399
|
}
|
|
494
|
-
if (isManagedSessionEnv(args)) {
|
|
495
|
-
const out = await runCtlCommand(`/effort ${level}`, formatJson);
|
|
496
|
-
printCtlResult(out, formatJson);
|
|
497
|
-
return;
|
|
498
|
-
}
|
|
499
400
|
const sel = parseSelector(args, formatJson);
|
|
500
401
|
const scope = determineWriteScope(sel, formatJson);
|
|
501
402
|
const ba = activeBaseagent(sel.self);
|
|
@@ -507,13 +408,6 @@ async function cmdEffort(args, formatJson) {
|
|
|
507
408
|
if (!model || !catalogEfforts(cat, model, ba).includes(val))
|
|
508
409
|
fail(formatJson, 'INVALID_EFFORT', `当前模型目录未声明支持推理强度: ${val}`);
|
|
509
410
|
}
|
|
510
|
-
if (isManagedTargetedWriteEnv(args)) {
|
|
511
|
-
const effortKey = 'effort';
|
|
512
|
-
preflightManagedFieldOverride(sel, explicitOrDerivedRole(args, sel), `baseagents.${ba}.${effortKey}`, val, formatJson);
|
|
513
|
-
await setManagedModelField(sel, `baseagents.${ba}.${effortKey}`, val, formatJson);
|
|
514
|
-
describeWrite(scope, sel, null, level, formatJson);
|
|
515
|
-
return;
|
|
516
|
-
}
|
|
517
411
|
try {
|
|
518
412
|
writeScope(scope, sel, ba, { effort: val });
|
|
519
413
|
}
|
|
@@ -529,26 +423,9 @@ async function cmdReset(args, formatJson) {
|
|
|
529
423
|
console.log(HELP);
|
|
530
424
|
return;
|
|
531
425
|
}
|
|
532
|
-
if (isManagedSessionEnv(args)) {
|
|
533
|
-
const out = await runCtlCommand('/model reset', formatJson);
|
|
534
|
-
printCtlResult(out, formatJson);
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
426
|
const sel = parseSelector(args, formatJson);
|
|
538
427
|
const scope = determineWriteScope(sel, formatJson);
|
|
539
428
|
const ba = activeBaseagent(sel.self);
|
|
540
|
-
if (isManagedTargetedWriteEnv(args)) {
|
|
541
|
-
const effortKey = 'effort';
|
|
542
|
-
const role = explicitOrDerivedRole(args, sel);
|
|
543
|
-
preflightManagedFieldOverride(sel, role, `baseagents.${ba}.model`, null, formatJson);
|
|
544
|
-
preflightManagedFieldOverride(sel, role, `baseagents.${ba}.${effortKey}`, null, formatJson);
|
|
545
|
-
await setManagedModelField(sel, `baseagents.${ba}.model`, null, formatJson);
|
|
546
|
-
await setManagedModelField(sel, `baseagents.${ba}.${effortKey}`, null, formatJson);
|
|
547
|
-
emit(formatJson, {
|
|
548
|
-
ok: true, scope, self: sel.self ?? null, peerKey: sel.peerKey ?? null,
|
|
549
|
-
}, () => `✓ 已清除 ${SCOPE_LABEL[scope]} 设置,回落上一级(该范围所有会话下条消息生效)`);
|
|
550
|
-
return;
|
|
551
|
-
}
|
|
552
429
|
try {
|
|
553
430
|
clearScope(scope, sel, ba);
|
|
554
431
|
}
|
|
@@ -568,11 +445,6 @@ async function cmdCheck(args, formatJson) {
|
|
|
568
445
|
console.log(HELP);
|
|
569
446
|
return;
|
|
570
447
|
}
|
|
571
|
-
if (isManagedSessionEnv(args)) {
|
|
572
|
-
const out = await runCtlCommand('/model check', formatJson, 60_000);
|
|
573
|
-
printCtlResult(out, formatJson);
|
|
574
|
-
return;
|
|
575
|
-
}
|
|
576
448
|
const sel = parseSelector(args, formatJson);
|
|
577
449
|
const role = explicitOrDerivedRole(args, sel);
|
|
578
450
|
const ba = activeBaseagent(sel.self);
|
|
@@ -609,5 +481,9 @@ export async function cmdModel(args) {
|
|
|
609
481
|
&& (getArgValue(args, '--self') || getArgValue(args, '--peer') || getArgValue(args, '--role'))) {
|
|
610
482
|
fail(formatJson, 'NOT_ALLOWED', 'Managed model commands cannot select --self, --peer, or --role; they always use the authenticated current relation');
|
|
611
483
|
}
|
|
484
|
+
if (process.env.EVOLCORE_SESSION_ID) {
|
|
485
|
+
await runManagedCliOperation(['model', ...args], formatJson, sub === 'check' ? 60_000 : 10_000);
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
612
488
|
await dispatch(sub, args, formatJson);
|
|
613
489
|
}
|
|
@@ -2,7 +2,9 @@ import { resolvePaths } from '../paths.js';
|
|
|
2
2
|
import { ipcQuery } from '../ipc.js';
|
|
3
3
|
import { readDelegationCredential } from '../core/auth/agent-delegation.js';
|
|
4
4
|
import { getArgValue, isHelpFlag, wantsHelp } from './help.js';
|
|
5
|
+
import { canonicalizeEvolcoreCommandArgv } from '../core/permission/ec-command-parser.js';
|
|
5
6
|
export async function cmdQueue(args) {
|
|
7
|
+
args = canonicalizeEvolcoreCommandArgv(['ec', 'queue', ...args]).slice(2);
|
|
6
8
|
if (args.length === 0 || isHelpFlag(args[0]) || wantsHelp(args)) {
|
|
7
9
|
console.log(`用法: ec queue --agent <aid> [选项]
|
|
8
10
|
|
|
@@ -91,6 +93,7 @@ JSON 时间字段:
|
|
|
91
93
|
const managed = process.env.EVOLCORE_SESSION_ID;
|
|
92
94
|
const result = await ipcQuery(socketPath, managed ? {
|
|
93
95
|
type: 'queue.op',
|
|
96
|
+
argv: ['queue', ...args],
|
|
94
97
|
agent,
|
|
95
98
|
action,
|
|
96
99
|
messageId: cancelMsgId,
|
|
@@ -147,6 +150,54 @@ function parseQueueTime(value, flag) {
|
|
|
147
150
|
}
|
|
148
151
|
return parsed;
|
|
149
152
|
}
|
|
153
|
+
export function parseQueueOperationArgv(argv) {
|
|
154
|
+
if (argv[0] !== 'queue')
|
|
155
|
+
throw new Error('Expected a queue command');
|
|
156
|
+
const flags = new Map();
|
|
157
|
+
const booleanFlags = new Set(['--clear', '--interrupt', '--showid', '--full']);
|
|
158
|
+
const valueFlags = new Set(['--agent', '--cancel', '--sessionkey', '--after', '--before', '--format']);
|
|
159
|
+
for (let index = 1; index < argv.length; index++) {
|
|
160
|
+
const flag = argv[index];
|
|
161
|
+
if (booleanFlags.has(flag)) {
|
|
162
|
+
flags.set(flag, 'true');
|
|
163
|
+
}
|
|
164
|
+
else if (valueFlags.has(flag) && argv[index + 1] && !argv[index + 1].startsWith('--')) {
|
|
165
|
+
if (!flags.has(flag))
|
|
166
|
+
flags.set(flag, argv[index + 1]);
|
|
167
|
+
index++;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
throw new Error(`Invalid queue option: ${flag}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const agent = flags.get('--agent');
|
|
174
|
+
if (!agent)
|
|
175
|
+
throw new Error('--agent is required');
|
|
176
|
+
if (flags.has('--format') && flags.get('--format') !== 'json')
|
|
177
|
+
throw new Error('--format only supports json');
|
|
178
|
+
if (['--clear', '--cancel', '--interrupt'].filter(flag => flags.has(flag)).length > 1)
|
|
179
|
+
throw new Error('Queue actions are mutually exclusive');
|
|
180
|
+
const time = (flag) => {
|
|
181
|
+
const value = flags.get(flag);
|
|
182
|
+
if (value === undefined)
|
|
183
|
+
return undefined;
|
|
184
|
+
const parsed = /^\d+$/.test(value) ? Number(value) : Date.parse(value);
|
|
185
|
+
if (!Number.isFinite(parsed))
|
|
186
|
+
throw new Error(`Invalid ${flag}`);
|
|
187
|
+
return parsed;
|
|
188
|
+
};
|
|
189
|
+
const after = time('--after');
|
|
190
|
+
const before = time('--before');
|
|
191
|
+
if (after !== undefined && before !== undefined && after >= before)
|
|
192
|
+
throw new Error('--after must precede --before');
|
|
193
|
+
if (flags.has('--interrupt') && !flags.get('--sessionkey'))
|
|
194
|
+
throw new Error('--interrupt requires --sessionkey');
|
|
195
|
+
return {
|
|
196
|
+
agent,
|
|
197
|
+
action: flags.has('--clear') ? 'clear' : flags.has('--cancel') ? 'cancel' : flags.has('--interrupt') ? 'interrupt' : undefined,
|
|
198
|
+
messageId: flags.get('--cancel'), sessionKey: flags.get('--sessionkey'), after, before,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
150
201
|
function renderQueueItemsCli(items, showId, full, aid) {
|
|
151
202
|
const lines = [`${aid} — 队列 (${items.length} 条)`, ''];
|
|
152
203
|
if (items.length === 0) {
|
package/dist/cli/response.js
CHANGED
|
@@ -57,7 +57,7 @@ function fail(formatJson, code, message) {
|
|
|
57
57
|
}
|
|
58
58
|
process.exit(1);
|
|
59
59
|
}
|
|
60
|
-
async function
|
|
60
|
+
async function runManagedResponse(args, formatJson) {
|
|
61
61
|
const sessionId = process.env.EVOLCORE_SESSION_ID;
|
|
62
62
|
const delegationToken = readDelegationCredential();
|
|
63
63
|
if (!sessionId)
|
|
@@ -65,62 +65,13 @@ async function managedConfig(fieldArgs, formatJson) {
|
|
|
65
65
|
if (!delegationToken)
|
|
66
66
|
fail(formatJson, 'DELEGATION_REQUIRED', `${AGENT_DELEGATION_TOKEN_ENV} is not set`);
|
|
67
67
|
const response = await ipcQuery(resolvePaths().socket, {
|
|
68
|
-
type: '
|
|
69
|
-
argv: ['config', ...fieldArgs],
|
|
70
|
-
sessionId,
|
|
71
|
-
delegationToken,
|
|
68
|
+
type: 'ctl', argv: ['response', ...args], sessionId, delegationToken,
|
|
72
69
|
}, 10_000);
|
|
73
70
|
if (!response)
|
|
74
71
|
fail(formatJson, 'DAEMON_UNAVAILABLE', 'Unable to connect to the evolcore daemon');
|
|
75
|
-
if (!response.ok
|
|
76
|
-
fail(formatJson, response.code || '
|
|
77
|
-
}
|
|
78
|
-
return response.result;
|
|
79
|
-
}
|
|
80
|
-
async function runManagedResponse(args, formatJson) {
|
|
81
|
-
if (getArgValue(args, '--self') || getArgValue(args, '--peer')) {
|
|
82
|
-
fail(formatJson, 'NOT_ALLOWED', 'Managed response commands always use the authenticated current relation');
|
|
83
|
-
}
|
|
84
|
-
const sub = args[0];
|
|
85
|
-
if (sub === 'set') {
|
|
86
|
-
const id = args[1];
|
|
87
|
-
if (!id)
|
|
88
|
-
fail(formatJson, 'MISSING_ID', 'set requires a mode id');
|
|
89
|
-
if (!buildRegistry().has(id))
|
|
90
|
-
fail(formatJson, 'UNKNOWN_MODE', `Unknown mode: ${id}`);
|
|
91
|
-
await managedConfig(['set', RESPONSE_MODE_FIELD, id], formatJson);
|
|
92
|
-
return emit(formatJson, { ok: true, scope: 'relation', mode: id }, () => `✓ 已设置响应模式为 ${id}(作用域: relation)`);
|
|
93
|
-
}
|
|
94
|
-
if (sub === 'reset') {
|
|
95
|
-
await managedConfig(['unset', RESPONSE_MODE_FIELD], formatJson);
|
|
96
|
-
return emit(formatJson, { ok: true, scope: 'relation' }, () => '✓ 已清除当前关系的响应模式设置');
|
|
97
|
-
}
|
|
98
|
-
if (sub === 'current') {
|
|
99
|
-
const modeResult = await managedConfig(['get', RESPONSE_MODE_FIELD], formatJson);
|
|
100
|
-
const paramsResult = await managedConfig(['get', RESPONSE_MODE_PARAMS_FIELD], formatJson);
|
|
101
|
-
const configuredMode = typeof modeResult.value === 'string' ? modeResult.value : undefined;
|
|
102
|
-
const mode = configuredMode ?? buildRegistry().getPreferredId();
|
|
103
|
-
return emit(formatJson, {
|
|
104
|
-
ok: true,
|
|
105
|
-
scope: 'relation',
|
|
106
|
-
responseMode: mode ?? null,
|
|
107
|
-
source: configuredMode ? 'config' : 'preferred',
|
|
108
|
-
sourceTarget: modeResult.source?.target ?? null,
|
|
109
|
-
responseModeParams: paramsResult.value ?? null,
|
|
110
|
-
}, () => `当前响应模式: ${mode ?? '(无)'}`);
|
|
111
|
-
}
|
|
112
|
-
if (sub === 'config') {
|
|
113
|
-
if (args[1] === 'set') {
|
|
114
|
-
fail(formatJson, 'NOT_ALLOWED', 'responseModeParams cannot be modified as an opaque object from a managed task');
|
|
115
|
-
}
|
|
116
|
-
const result = await managedConfig(['get', RESPONSE_MODE_PARAMS_FIELD], formatJson);
|
|
117
|
-
const params = result.value ?? {};
|
|
118
|
-
const modeId = args[1] && !args[1].startsWith('--') ? args[1] : undefined;
|
|
119
|
-
if (modeId)
|
|
120
|
-
return emit(formatJson, { ok: true, mode: modeId, config: params[modeId] ?? {} }, () => `${modeId} 配置: ${JSON.stringify(params[modeId] ?? {}, null, 2)}`);
|
|
121
|
-
return emit(formatJson, { ok: true, responseModeParams: params }, () => `所有模式配置: ${JSON.stringify(params, null, 2)}`);
|
|
122
|
-
}
|
|
123
|
-
fail(formatJson, 'NOT_ALLOWED', `response ${sub} is not available in a managed task`);
|
|
72
|
+
if (!response.ok)
|
|
73
|
+
fail(formatJson, response.code || 'CTL_FAILED', response.error || 'response operation failed');
|
|
74
|
+
emit(formatJson, response.data ?? { ok: true, result: response.result }, () => response.result || 'ok');
|
|
124
75
|
}
|
|
125
76
|
/** 解析 --self / --peer 为作用域选择器 */
|
|
126
77
|
function parseSelector(args, formatJson) {
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { resolvePaths, resolveRoot } from '../paths.js';
|
|
4
|
+
import { scanChatDirs, readLastJsonlLine, } from '../core/session/session-fs-store.js';
|
|
5
|
+
const HELP_TEXT = `
|
|
6
|
+
ec session <command> [options]
|
|
7
|
+
|
|
8
|
+
本地会话文件查询(不经过 daemon,直接读 $EVOLCORE_HOME/agents/ 下的 session 存档)。
|
|
9
|
+
|
|
10
|
+
命令:
|
|
11
|
+
find <sessionId> 按 ec 会话 id(meta_YYYYMMDD_<ts>)定位 session 文件,
|
|
12
|
+
输出 agentSessionId 与所在位置等元数据
|
|
13
|
+
help 显示本帮助
|
|
14
|
+
|
|
15
|
+
选项:
|
|
16
|
+
--format json 以 JSON 格式输出(默认按人类可读格式)
|
|
17
|
+
|
|
18
|
+
说明:
|
|
19
|
+
meta_<ts> 这个 id 只含时间戳,不含路径信息。物理布局是
|
|
20
|
+
agents/<selfAid>/sessions/<channelSessionKey>/,主会话的 meta 文件在目录根,
|
|
21
|
+
话题会话的在 _threads/ 子目录。find 通过文件名扫描全量 chat 目录定位,
|
|
22
|
+
同一 id 理论上可命中多处(不同 agent/对端),全部列出。
|
|
23
|
+
`.trim();
|
|
24
|
+
function argValue(args, flag) {
|
|
25
|
+
const i = args.indexOf(flag);
|
|
26
|
+
return i >= 0 ? args[i + 1] : undefined;
|
|
27
|
+
}
|
|
28
|
+
function hasFlag(args, flag) {
|
|
29
|
+
return args.includes(flag);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 在单个 chat 目录中查找指定 meta 文件名。
|
|
33
|
+
* 主会话 meta 位于目录根;话题会话 meta 位于 _threads/ 下。
|
|
34
|
+
*/
|
|
35
|
+
function findMetaInChatDir(chatDir, metaFileName) {
|
|
36
|
+
const hits = [];
|
|
37
|
+
for (const dir of [chatDir, path.join(chatDir, '_threads')]) {
|
|
38
|
+
try {
|
|
39
|
+
const entries = fs.readdirSync(dir);
|
|
40
|
+
if (entries.includes(metaFileName))
|
|
41
|
+
hits.push(path.join(dir, metaFileName));
|
|
42
|
+
}
|
|
43
|
+
catch { /* 目录不存在,跳过 */ }
|
|
44
|
+
}
|
|
45
|
+
return hits;
|
|
46
|
+
}
|
|
47
|
+
/** 在 _trash 中查找(话题删除后 session 文件移入 _trash)。 */
|
|
48
|
+
function findMetaInTrash(chatDir, metaFileName) {
|
|
49
|
+
const trashDir = path.join(chatDir, '_trash');
|
|
50
|
+
const hits = [];
|
|
51
|
+
try {
|
|
52
|
+
for (const entry of fs.readdirSync(trashDir)) {
|
|
53
|
+
if (entry === metaFileName || entry === `${metaFileName}.jsonl`) {
|
|
54
|
+
hits.push(path.join(trashDir, entry));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch { /* 目录不存在,跳过 */ }
|
|
59
|
+
return hits;
|
|
60
|
+
}
|
|
61
|
+
async function cmdFind(args) {
|
|
62
|
+
const jsonFormat = hasFlag(args, '--format') && argValue(args, '--format') === 'json'
|
|
63
|
+
|| hasFlag(args, '--json');
|
|
64
|
+
// 位置参数已在调用处剥掉子命令,第一个非 flag 参数即 sessionId
|
|
65
|
+
const rawId = args.find(a => !a.startsWith('-'));
|
|
66
|
+
if (!rawId) {
|
|
67
|
+
console.error('用法: ec session find <sessionId> [--format json]');
|
|
68
|
+
process.exitCode = 1;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
// 允许传入带或不带 .jsonl 后缀的 id
|
|
72
|
+
const sessionId = rawId.endsWith('.jsonl') ? rawId.slice(0, -'.jsonl'.length) : rawId;
|
|
73
|
+
if (!sessionId.startsWith('meta_')) {
|
|
74
|
+
console.error(`✗ ec 会话 id 应以 meta_ 开头(如 meta_20261012_1791789158257),收到: ${rawId}`);
|
|
75
|
+
process.exitCode = 1;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const metaFileName = `${sessionId}.jsonl`;
|
|
79
|
+
const p = resolvePaths();
|
|
80
|
+
const chatDirs = scanChatDirs(p.sessionsDir);
|
|
81
|
+
const found = [];
|
|
82
|
+
for (const chat of chatDirs) {
|
|
83
|
+
const locations = [
|
|
84
|
+
...findMetaInChatDir(chat.dirPath, metaFileName),
|
|
85
|
+
...findMetaInTrash(chat.dirPath, metaFileName),
|
|
86
|
+
];
|
|
87
|
+
for (const metaFile of locations) {
|
|
88
|
+
const meta = readLastJsonlLine(metaFile);
|
|
89
|
+
if (!meta)
|
|
90
|
+
continue;
|
|
91
|
+
found.push({
|
|
92
|
+
sessionId: meta.id || sessionId,
|
|
93
|
+
metaFile,
|
|
94
|
+
sessionKey: meta.sessionKey,
|
|
95
|
+
agentSessionId: meta.agentSessionId ?? null,
|
|
96
|
+
baseagent: meta.baseagent ?? null,
|
|
97
|
+
threadId: meta.threadId ?? null,
|
|
98
|
+
name: meta.name ?? null,
|
|
99
|
+
chatType: meta.chatType ?? null,
|
|
100
|
+
channelId: meta.channelId ?? chat.channelId,
|
|
101
|
+
selfAID: chat.selfAID,
|
|
102
|
+
projectPath: meta.projectPath ?? null,
|
|
103
|
+
updatedAt: meta.updatedAt,
|
|
104
|
+
updatedAtStr: meta.updatedAtStr,
|
|
105
|
+
createdAtStr: meta.createdAtStr,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// 兜底:active.json 的 id 字段也可能匹配(active 是 meta 的最新版快照)
|
|
110
|
+
if (found.length === 0) {
|
|
111
|
+
for (const chat of chatDirs) {
|
|
112
|
+
const activeFile = path.join(chat.dirPath, 'active.json');
|
|
113
|
+
const active = readJsonFileSafe(activeFile);
|
|
114
|
+
if (active && active.id === sessionId) {
|
|
115
|
+
found.push({
|
|
116
|
+
sessionId,
|
|
117
|
+
metaFile: activeFile,
|
|
118
|
+
sessionKey: active.sessionKey,
|
|
119
|
+
agentSessionId: active.agentSessionId ?? null,
|
|
120
|
+
baseagent: active.baseagent ?? null,
|
|
121
|
+
threadId: active.threadId ?? null,
|
|
122
|
+
name: active.name ?? null,
|
|
123
|
+
chatType: active.chatType ?? null,
|
|
124
|
+
channelId: active.channelId ?? chat.channelId,
|
|
125
|
+
selfAID: chat.selfAID,
|
|
126
|
+
projectPath: active.projectPath ?? null,
|
|
127
|
+
updatedAt: active.updatedAt,
|
|
128
|
+
updatedAtStr: active.updatedAtStr,
|
|
129
|
+
createdAtStr: active.createdAtStr,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (found.length === 0) {
|
|
135
|
+
if (jsonFormat) {
|
|
136
|
+
console.log(JSON.stringify({ ok: false, sessionId, found: [] }, null, 2));
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
console.error(`✗ 未找到会话 ${sessionId}(已扫描 ${resolveRoot()} 下 ${chatDirs.length} 个 chat 目录)`);
|
|
140
|
+
}
|
|
141
|
+
process.exitCode = 1;
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (jsonFormat) {
|
|
145
|
+
console.log(JSON.stringify({ ok: true, sessionId, found }, null, 2));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
for (const f of found) {
|
|
149
|
+
console.log(`ec 会话 id: ${f.sessionId}`);
|
|
150
|
+
console.log(` agentSessionId: ${f.agentSessionId ?? '(空)'}`);
|
|
151
|
+
console.log(` baseagent: ${f.baseagent ?? '(未知)'}`);
|
|
152
|
+
console.log(` threadId: ${f.threadId ? f.threadId : '(主会话)'}`);
|
|
153
|
+
if (f.name)
|
|
154
|
+
console.log(` 名称: ${f.name}`);
|
|
155
|
+
if (f.chatType)
|
|
156
|
+
console.log(` 类型: ${f.chatType === 'group' ? '群聊' : '单聊'}`);
|
|
157
|
+
console.log(` 对端: ${f.channelId ?? ''}`);
|
|
158
|
+
console.log(` 本端 AID: ${f.selfAID ?? ''}`);
|
|
159
|
+
if (f.projectPath)
|
|
160
|
+
console.log(` 项目: ${f.projectPath}`);
|
|
161
|
+
if (f.updatedAtStr)
|
|
162
|
+
console.log(` 最近更新: ${f.updatedAtStr}`);
|
|
163
|
+
console.log(` meta 文件: ${f.metaFile}`);
|
|
164
|
+
if (f.metaFile.includes('_trash'))
|
|
165
|
+
console.log(` ⚠ 该话题已删除(文件在 _trash 中)`);
|
|
166
|
+
console.log('');
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// readJsonFile 在 session-fs-store 中未导出别名导入成本高,这里本地实现同语义
|
|
170
|
+
function readJsonFileSafe(filePath) {
|
|
171
|
+
try {
|
|
172
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
173
|
+
return JSON.parse(content);
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
export async function runSessionCommand(args) {
|
|
180
|
+
const sub = args[0];
|
|
181
|
+
if (!sub || sub === 'help' || hasFlag(args, '--help') || hasFlag(args, '-h')) {
|
|
182
|
+
console.log(HELP_TEXT);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
switch (sub) {
|
|
186
|
+
case 'find':
|
|
187
|
+
await cmdFind(args.slice(1));
|
|
188
|
+
break;
|
|
189
|
+
default:
|
|
190
|
+
console.error(`✗ 未知子命令: ${sub}`);
|
|
191
|
+
console.log(HELP_TEXT);
|
|
192
|
+
process.exitCode = 1;
|
|
193
|
+
}
|
|
194
|
+
}
|