evolcore 0.0.46 → 0.0.48
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 +93 -0
- package/bin/ec-build.mjs +86 -0
- package/dist/agent-template/jobs.js +12 -4
- package/dist/agent-template/runtime.js +139 -39
- package/dist/agent-template/service.js +66 -13
- package/dist/agents/baseagent.js +60 -20
- package/dist/agents/claude-runner.js +43 -18
- package/dist/agents/codex/app-server-client.js +32 -23
- package/dist/agents/codex-runner.js +31 -16
- package/dist/agents/ecagent-runner.js +7 -4
- package/dist/agents/gemini-runner.js +5 -2
- package/dist/agents/runner-types.js +5 -21
- package/dist/aun/aid/agentmd.js +5 -1
- package/dist/aun/group/fs-download.js +1 -1
- package/dist/aun/service-proxy.js +4 -2
- package/dist/build-identity.json +1 -0
- package/dist/channels/aun.js +100 -32
- package/dist/channels/daemon.js +10 -26
- package/dist/cli/aun-commands.js +86 -51
- package/dist/cli/code-stats.js +19 -8
- package/dist/cli/command-log.js +1 -1
- package/dist/cli/daemon-commands.js +65 -76
- package/dist/cli/daemon-lifecycle-client.js +17 -3
- package/dist/cli/directory.js +7 -1
- package/dist/cli/ecmsg-gateway.js +5 -2
- package/dist/cli/index.js +2 -8
- package/dist/cli/init-channel.js +6 -8
- package/dist/cli/init.js +74 -46
- package/dist/cli/invoke-command.js +1 -1
- package/dist/cli/provider-command.js +74 -13
- package/dist/cli/restart-monitor.js +104 -28
- package/dist/cli/role.js +61 -17
- package/dist/cli/stats.js +3 -3
- package/dist/cli/task-context.js +83 -15
- package/dist/cli/thread-command.js +16 -51
- package/dist/cli/upgrade-command.js +4 -2
- package/dist/config/boot-log.js +3 -9
- package/dist/config/builtin-roles.js +5 -7
- package/dist/config/config-manager.js +31 -23
- package/dist/config/daemon-services.js +30 -3
- package/dist/config/gateway-config.js +2 -2
- package/dist/config/invoke-ipc-service.js +6 -4
- package/dist/config/peer-bind-code.js +3 -4
- package/dist/config/peer-book-store.js +59 -218
- package/dist/config/peer-book.js +26 -27
- package/dist/config/peer-role-resolver.js +16 -1
- package/dist/config/provider-identity-migration.js +161 -6
- package/dist/config/provider-ipc-service.js +56 -11
- package/dist/config/provider-menu-request.js +24 -5
- package/dist/config/provider-templates.js +127 -0
- package/dist/config/providers-config.js +59 -8
- package/dist/config/providers-management.js +467 -49
- package/dist/config/role-command-service.js +248 -1
- package/dist/config/schema-migration.js +228 -20
- package/dist/config/schema-registry.js +6 -2
- package/dist/core/agent-application-service.js +6 -1
- package/dist/core/agent-runtime.js +10 -5
- package/dist/core/auth/agent-delegation.js +10 -4
- package/dist/core/auth/auth-gateway.js +2 -1
- package/dist/core/auth/delegation-authorization.js +3 -0
- package/dist/core/auth/delegation-diagnostics.js +56 -15
- package/dist/core/auth/operation-authorizer.js +26 -1
- package/dist/core/auth/operation-catalog.js +28 -64
- package/dist/core/capability/providers/codex-capability-provider.js +7 -8
- package/dist/core/channel-loader.js +18 -0
- package/dist/core/command/agent-control.js +32 -0
- package/dist/core/command/command-handler.js +81 -85
- package/dist/core/command/menu-catalog.js +1 -0
- package/dist/core/command/menu-handler.js +65 -153
- package/dist/core/command/menu-protocol.js +7 -1
- package/dist/core/command/provider-menu.js +13 -3
- package/dist/core/command/role-menu.js +47 -23
- package/dist/core/command/slash-handler.js +30 -49
- package/dist/core/command/team-workspace-items.js +81 -12
- package/dist/core/command/team-workspace-team.js +9 -71
- package/dist/core/command/topic-slash.js +9 -30
- package/dist/core/daemon-bootstrap.js +19 -10
- package/dist/core/daemon-control.js +8 -10
- package/dist/core/daemon-lifecycle.js +50 -40
- package/dist/core/evolagent-registry.js +22 -3
- package/dist/core/file-integrity/store.js +2 -0
- package/dist/core/handoff/runtime.js +37 -1
- package/dist/core/host-snapshot.js +9 -4
- package/dist/core/inference/text-inference.js +3 -1
- package/dist/core/initialization/service.js +31 -8
- package/dist/core/interaction-router.js +3 -0
- package/dist/core/invoke/executors/text.js +72 -19
- package/dist/core/ipc-registration.js +6 -4
- package/dist/core/memory/consolidation.js +6 -6
- package/dist/core/message/aun-ipc-sender.js +165 -55
- package/dist/core/message/im-renderer.js +1 -1
- package/dist/core/message/message-bridge.js +51 -334
- package/dist/core/message/message-log.js +5 -0
- package/dist/core/message/message-queue.js +22 -0
- package/dist/core/message/message-utils.js +8 -0
- package/dist/core/message/response-engine.js +429 -116
- package/dist/core/message/send-routing.js +5 -1
- package/dist/core/model/catalog-service.js +31 -11
- package/dist/core/model/model-capabilities.js +22 -4
- package/dist/core/model/model-catalog.js +1 -0
- package/dist/core/ownership/owner-resolver.js +355 -60
- package/dist/core/permission/protected-paths.js +6 -6
- package/dist/core/relation/peer-identity.js +28 -2
- package/dist/core/relation/same-owner-proof.js +81 -111
- package/dist/core/session/adapters/claude-session-file-adapter.js +1 -1
- package/dist/core/session/adapters/codex-session-file-adapter.js +96 -15
- package/dist/core/session/session-file-health.js +49 -14
- package/dist/core/session/session-fs-store.js +91 -35
- package/dist/core/session/session-manager.js +68 -24
- package/dist/core/session/session-mapper.js +14 -34
- package/dist/core/session/session-transcript.js +5 -1
- package/dist/core/task/task-activity-store.js +84 -0
- package/dist/core/task/task-image-resources.js +1 -1
- package/dist/core/task/task-recovery-service.js +12 -0
- package/dist/core/thread/command-parser.js +7 -12
- package/dist/core/thread/thread-context-storage.js +3 -2
- package/dist/core/thread/thread-operation.js +2 -13
- package/dist/core/thread/thread-service.js +15 -46
- package/dist/directory/owner-directory-admission.js +1 -1
- package/dist/directory/owner-directory-cache.js +45 -28
- package/dist/directory/owner-directory-markdown.js +13 -1
- package/dist/directory/owner-directory-query-operation.js +29 -3
- package/dist/directory/owner-directory-remarks.js +11 -3
- package/dist/eck/message-renderer.js +84 -24
- package/dist/ecweb/basic-settings-service.js +3 -1
- package/dist/ecweb/message-context-service.js +1 -1
- package/dist/ecweb/pairing.js +4 -3
- package/dist/ecweb/providers-service.js +26 -1
- package/dist/ecweb/runtime/lifecycle.js +82 -23
- package/dist/ecweb/runtime/proxy-access.js +74 -0
- package/dist/ecweb/runtime/supervisor.js +6 -17
- package/dist/event-center/registry.js +13 -2
- package/dist/event-center/runtime.js +103 -11
- package/dist/event-center/script-runner.js +5 -5
- package/dist/index.js +129 -93
- package/dist/ipc.js +15 -3
- package/dist/outputs/events.js +62 -0
- package/dist/outputs/protocol.js +102 -0
- package/dist/outputs/service.js +279 -0
- package/dist/paths.js +3 -0
- package/dist/proxy/manager.js +43 -13
- package/dist/services/index.js +89 -4
- package/dist/services/ipc-operation.js +4 -15
- package/dist/services/pack-manager.js +12 -1
- package/dist/services/router.js +21 -6
- package/dist/services/script-runner.js +5 -4
- package/dist/services/validation.js +1 -1
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +19 -0
- package/dist/stats/index.js +1 -1
- package/dist/stats/{price-resolver.js → model-resolver.js} +305 -24
- package/dist/stats/normalizer.js +2 -0
- package/dist/stats/query.js +35 -27
- package/dist/stats/role-budget.js +5 -2
- package/dist/stats/writer.js +10 -6
- package/dist/trigger/audit.js +7 -0
- package/dist/trigger/authorization.js +105 -11
- package/dist/trigger/feedback.js +10 -0
- package/dist/trigger/history.js +37 -11
- package/dist/trigger/ipc-service.js +12 -1
- package/dist/trigger/manager.js +1 -0
- package/dist/trigger/scheduler.js +11 -5
- package/dist/trigger/script-executor.js +2 -1
- package/dist/trigger/script-sandbox.js +9 -3
- package/dist/trigger/state.js +7 -0
- package/dist/trigger/validation.js +22 -0
- package/dist/utils/aid-bind.js +155 -18
- package/dist/utils/atomic-write.js +3 -3
- package/dist/utils/cross-platform.js +97 -31
- package/dist/utils/error-dict.json +94 -4
- package/dist/utils/error-utils.js +40 -4
- package/dist/utils/evolcore-version.js +36 -65
- package/dist/utils/instance-registry.js +61 -0
- package/dist/utils/msg-diag.js +1 -0
- package/dist/utils/process-introspect.js +158 -8
- package/dist/utils/process-tree.js +50 -2
- package/dist/utils/upgrade-jobs.js +4 -4
- package/dist/utils/windows-shell-trust.js +2 -0
- package/dist/workbench/protocol.js +80 -0
- package/dist/workbench/service.js +359 -0
- package/ecagent/dist/types.d.ts +6 -2
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +2 -2
- package/kits/docs/evolcore/aid.md +3 -1
- package/kits/docs/evolcore/config.md +12 -0
- package/kits/docs/evolcore/directory.md +22 -3
- package/kits/docs/evolcore/ecweb-lifecycle.md +15 -0
- package/kits/docs/evolcore/model.md +10 -0
- package/kits/docs/evolcore/peer.md +19 -65
- package/kits/docs/evolcore/provider.md +133 -5
- package/kits/docs/evolcore/role.md +80 -0
- package/kits/docs/evolcore/services.md +6 -6
- package/kits/docs/evolcore/team-workspace.md +1 -1
- package/kits/docs/evolcore/thread-chain.md +14 -15
- package/kits/docs/evolcore/tool-authorization.md +5 -0
- package/kits/docs/evolcore/trigger.md +10 -0
- package/kits/eck_message_manifest.json +12 -0
- package/kits/provider-templates.json +1213 -0
- package/kits/rules/04-relation.md +3 -3
- package/kits/schemas/_meta.json +14 -2
- package/kits/schemas/contact-book.schema.4.json +52 -0
- package/kits/schemas/providers.schema.3.json +200 -0
- package/kits/skills/.switches.json +4 -0
- package/kits/skills/ability/references/calling.md +1 -1
- package/kits/skills/ec-group/SKILL.md +2 -2
- package/kits/skills/ec-identity/SKILL.md +19 -72
- package/kits/skills/ec-provider/SKILL.md +221 -0
- package/kits/skills/ec-provider/scripts/check-model.mjs +80 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/skills/thread-ops/SKILL.md +34 -21
- package/kits/templates/message-fragments/group-batch-item.md +1 -1
- package/kits/templates/message-fragments/group-batch.md +1 -1
- package/kits/templates/message-fragments/inject-default.md +1 -1
- package/kits/templates/message-fragments/interrupt-insert.md +1 -0
- package/kits/templates/message-fragments/item-group.md +1 -1
- package/kits/templates/message-fragments/item-private.md +1 -1
- package/kits/templates/message-fragments/thread-context.md +1 -1
- package/kits/templates/message-fragments/trigger-session.md +1 -1
- package/kits/templates/message-fragments/trigger-thread-check.md +1 -1
- package/kits/templates/roles/admin.json +2 -19
- package/kits/templates/roles/member.json +0 -3
- package/kits/templates/system-fragments/baseagent.md +6 -0
- package/kits/templates/system-fragments/commands.md +3 -3
- package/kits/templates/system-fragments/managed-runtime.md +1 -1
- package/kits/templates/system-fragments/relation.md +1 -1
- package/kits/templates/system-fragments/thread.md +6 -5
- package/package.json +6 -4
- package/scripts/agent-template/inspect.mjs +4 -1
- package/scripts/agent-template/shared/common.mjs +2 -3
- package/scripts/agent-template/shared/template-contract.mjs +2 -1
- package/scripts/agent-template/shared/template-package.mjs +9 -2
- package/scripts/agent-template/shared/template-runtime.mjs +20 -5
- package/scripts/agent-template/team-pack.mjs +6 -3
- package/dist/cli/peer.js +0 -127
- package/dist/config/peer-operation-service.js +0 -132
- package/dist/config/peer-request-service.js +0 -532
- package/dist/core/command/connect-menu.js +0 -624
|
@@ -38,7 +38,7 @@ import { normalizePermissionMode as normalizePermissionModeContract, PUBLIC_PERM
|
|
|
38
38
|
import { isManagementRole } from '../../config/builtin-roles.js';
|
|
39
39
|
import { isSystemControlChannel } from '../system-channels.js';
|
|
40
40
|
import { launchMonitorAndConfirm, resolveMonitorLaunch, cleanupMonitorStage, isProcessRunning } from '../../utils/cross-platform.js';
|
|
41
|
-
import {
|
|
41
|
+
import { hasLiveRestartMonitor } from '../../utils/instance-registry.js';
|
|
42
42
|
import { guardIdleCommand, guardGroupSlashCommand, guardKnownCommand, guardRoleCommand, guardThreadCommand, isRecognizedSlashCommand, normalizeSlashContent, parseFullAccessCommand, probeSessionActivity, } from './slash-gate.js';
|
|
43
43
|
import { MAX_AUN_ATTACHMENT_SIZE } from '../../aun/msg/upload.js';
|
|
44
44
|
import { DEFAULT_SESSION_LOOP_SECONDS, MAX_SESSION_LOOP_PROMPT_LENGTH, MAX_SESSION_LOOP_SECONDS, MIN_SESSION_LOOP_SECONDS, refreshSessionLoopTarget, resolveCurrentSessionLoopTarget, resolveSessionLoopTarget, sessionLoopPayload, validateIdleSeconds, writeSessionLoopConfig, } from '../session/session-idle-monitor.js';
|
|
@@ -302,43 +302,26 @@ function getAgentBusyCount(handler, aid, excludeSessionKey) {
|
|
|
302
302
|
}
|
|
303
303
|
async function getGitWorkingDirInfo(projectPath) {
|
|
304
304
|
try {
|
|
305
|
-
const {
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
})
|
|
305
|
+
const { execFile } = await import('child_process');
|
|
306
|
+
const git = (args) => new Promise((resolve, reject) => {
|
|
307
|
+
const child = execFile('git', args, {
|
|
308
|
+
cwd: projectPath, encoding: 'utf8', timeout: 1000,
|
|
309
|
+
windowsHide: process.platform === 'win32',
|
|
310
|
+
}, (error, stdout) => error ? reject(error) : resolve(stdout));
|
|
311
|
+
child.stdin?.end();
|
|
312
|
+
});
|
|
313
|
+
const isInsideWorkTree = (await git(['rev-parse', '--is-inside-work-tree'])).trim();
|
|
313
314
|
if (isInsideWorkTree !== 'true')
|
|
314
315
|
return null;
|
|
315
316
|
// 获取分支名
|
|
316
|
-
let branch =
|
|
317
|
-
cwd: projectPath,
|
|
318
|
-
encoding: 'utf8',
|
|
319
|
-
timeout: 1000,
|
|
320
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
321
|
-
windowsHide: process.platform === 'win32',
|
|
322
|
-
}).trim();
|
|
317
|
+
let branch = (await git(['branch', '--show-current'])).trim();
|
|
323
318
|
if (!branch) {
|
|
324
|
-
branch =
|
|
325
|
-
cwd: projectPath,
|
|
326
|
-
encoding: 'utf8',
|
|
327
|
-
timeout: 1000,
|
|
328
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
329
|
-
windowsHide: process.platform === 'win32',
|
|
330
|
-
}).trim();
|
|
319
|
+
branch = (await git(['rev-parse', '--abbrev-ref', 'HEAD'])).trim();
|
|
331
320
|
}
|
|
332
321
|
if (!branch)
|
|
333
322
|
return null;
|
|
334
323
|
// 检查文件状态
|
|
335
|
-
const statusOutput =
|
|
336
|
-
cwd: projectPath,
|
|
337
|
-
encoding: 'utf8',
|
|
338
|
-
timeout: 1000,
|
|
339
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
340
|
-
windowsHide: process.platform === 'win32',
|
|
341
|
-
});
|
|
324
|
+
const statusOutput = await git(['--no-optional-locks', 'status', '--porcelain']);
|
|
342
325
|
// 解析文件状态统计
|
|
343
326
|
const stats = { modified: 0, added: 0, deleted: 0, untracked: 0 };
|
|
344
327
|
const lines = statusOutput.trim().split('\n').filter(Boolean);
|
|
@@ -380,13 +363,7 @@ async function getGitWorkingDirInfo(projectPath) {
|
|
|
380
363
|
}
|
|
381
364
|
// 获取 ahead/behind 信息
|
|
382
365
|
try {
|
|
383
|
-
const revOutput =
|
|
384
|
-
cwd: projectPath,
|
|
385
|
-
timeout: 1000,
|
|
386
|
-
encoding: 'utf8',
|
|
387
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
388
|
-
windowsHide: process.platform === 'win32',
|
|
389
|
-
});
|
|
366
|
+
const revOutput = await git(['rev-list', '--left-right', '--count', '@{upstream}...HEAD']);
|
|
390
367
|
const revParts = revOutput.trim().split(/\s+/);
|
|
391
368
|
if (revParts.length === 2) {
|
|
392
369
|
const behind = parseInt(revParts[0], 10) || 0;
|
|
@@ -2609,7 +2586,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
2609
2586
|
return { kind: 'command.error', text: `❌ 当前 Agent (${currentSessionAgent.name}) 不支持 /compact` };
|
|
2610
2587
|
}
|
|
2611
2588
|
if (sendMessage) {
|
|
2612
|
-
const text = '
|
|
2589
|
+
const text = '正在压缩会话上下文...';
|
|
2613
2590
|
await sendMessage(channelId, text, this.getReplyContext(session), {
|
|
2614
2591
|
kind: 'system.notice',
|
|
2615
2592
|
text,
|
|
@@ -2681,7 +2658,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
2681
2658
|
if (compactResult === true || compactResult?.ok === true) {
|
|
2682
2659
|
return {
|
|
2683
2660
|
kind: 'system.notice',
|
|
2684
|
-
text: '
|
|
2661
|
+
text: '会话压缩完成',
|
|
2685
2662
|
subtype: 'session.compacted',
|
|
2686
2663
|
};
|
|
2687
2664
|
}
|
|
@@ -3256,19 +3233,17 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
3256
3233
|
const controlDir = daemonControlDir();
|
|
3257
3234
|
fs.mkdirSync(controlDir, { recursive: true });
|
|
3258
3235
|
const pendingFile = path.join(controlDir, 'restart-pending.json');
|
|
3259
|
-
if (
|
|
3236
|
+
if (await hasLiveRestartMonitor()
|
|
3260
3237
|
|| !createRestartRequest(pendingFile, restartInfo, isProcessRunning)) {
|
|
3261
3238
|
if (monitorEntry.stageDir)
|
|
3262
3239
|
cleanupMonitorStage(monitorEntry.stageDir);
|
|
3263
3240
|
return { code: 'RESTART_PENDING_CONFIRMATION', reason: '已有重启请求正在处理', requestId: restartInfo.requestId };
|
|
3264
3241
|
}
|
|
3265
|
-
const confirmation = await launchMonitorAndConfirm([...monitorEntry.args, 'restart-monitor', autoUpgrade ? '--apply-package-upgrades' : '--skip-package-upgrades'], { EVOLCORE_HOME: resolvePaths().root, ...monitorEntry.env, [RESTART_REQUEST_ID_ENV]: restartInfo.requestId }, pid =>
|
|
3266
|
-
&& m.record.requestId === restartInfo.requestId && m.record.phase === 'accepted'), pid => scanInstances().restartMonitors.some(m => m.alive && m.record.pid !== pid
|
|
3267
|
-
&& m.record.requestId === restartInfo.requestId && m.record.phase === 'accepted'), {
|
|
3242
|
+
const confirmation = await launchMonitorAndConfirm([...monitorEntry.args, 'restart-monitor', autoUpgrade ? '--apply-package-upgrades' : '--skip-package-upgrades'], { EVOLCORE_HOME: resolvePaths().root, ...monitorEntry.env, [RESTART_REQUEST_ID_ENV]: restartInfo.requestId }, pid => hasLiveRestartMonitor({ pid, requestId: restartInfo.requestId, phase: 'accepted' }), pid => hasLiveRestartMonitor({ excludePid: pid, requestId: restartInfo.requestId, phase: 'accepted' }), {
|
|
3268
3243
|
requestId: restartInfo.requestId,
|
|
3269
3244
|
logFilePath: path.join(resolvePaths().logs, `restart-launch-${restartInfo.requestId}.log`),
|
|
3270
3245
|
onSpawn: pid => { updateRestartRequest(pendingFile, restartInfo.requestId, { launcherPid: pid }); },
|
|
3271
|
-
isPendingInRegistry: () =>
|
|
3246
|
+
isPendingInRegistry: () => hasLiveRestartMonitor({ requestId: restartInfo.requestId }),
|
|
3272
3247
|
});
|
|
3273
3248
|
if (!confirmation.ok) {
|
|
3274
3249
|
if (confirmation.pending) {
|
|
@@ -3824,10 +3799,14 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
3824
3799
|
if (!targetSession) {
|
|
3825
3800
|
return { kind: 'command.error', text: `❌ 会话不存在: ${sessionName}\n使用 /s 查看可用会话` };
|
|
3826
3801
|
}
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3802
|
+
// Context is presentation only: finish the switch before asynchronous I/O
|
|
3803
|
+
// so it cannot widen the idle-check-to-session-replacement window.
|
|
3804
|
+
const readLastInput = async () => {
|
|
3805
|
+
const lastInput = targetSession.agentSessionId
|
|
3806
|
+
? await this.sessionManager.readSessionLastUserMessage(targetSession.projectPath, targetSession.agentSessionId, targetSession.baseagent, targetSession.selfAID)
|
|
3807
|
+
: null;
|
|
3808
|
+
return { lastInput, lastInputLine: lastInput ? `\n 最后输入: "${lastInput}"` : '' };
|
|
3809
|
+
};
|
|
3831
3810
|
if (!session) {
|
|
3832
3811
|
const switched = await this.sessionManager.switchToSession(channel, channelId, targetSession.id);
|
|
3833
3812
|
if (!switched) {
|
|
@@ -3835,6 +3814,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
3835
3814
|
}
|
|
3836
3815
|
if (this.shouldSuppressCardTriggerResult(source, channel))
|
|
3837
3816
|
return null;
|
|
3817
|
+
const { lastInputLine } = await readLastInput();
|
|
3838
3818
|
return { kind: 'command.result', text: `✓ 已切换到会话: ${displaySessionTitle(targetSession.name, sessionName)}\n 项目: ${path.basename(targetSession.projectPath)}${lastInputLine}` };
|
|
3839
3819
|
}
|
|
3840
3820
|
if (targetSession.id === session.id) {
|
|
@@ -3852,9 +3832,10 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
3852
3832
|
return { kind: 'command.error', text: `❌ 切换会话失败` };
|
|
3853
3833
|
}
|
|
3854
3834
|
this.eventBus.publish({ type: 'session:switched', sessionId: targetSession.id, fromSessionId: session.id, toSessionId: targetSession.id });
|
|
3855
|
-
const continueHint = lastInput ? '\n 将继续之前的对话历史' : '\n 当前会话未有发言';
|
|
3856
3835
|
if (this.shouldSuppressCardTriggerResult(source, channel))
|
|
3857
3836
|
return null;
|
|
3837
|
+
const { lastInput, lastInputLine } = await readLastInput();
|
|
3838
|
+
const continueHint = lastInput ? '\n 将继续之前的对话历史' : '\n 当前会话未有发言';
|
|
3858
3839
|
return { kind: 'command.result', text: `✓ 已切换到会话: ${displaySessionTitle(targetSession.name, sessionName)}${continueHint}${lastInputLine}` };
|
|
3859
3840
|
}
|
|
3860
3841
|
// /rename 或 /name 命令:重命名当前会话
|
|
@@ -105,9 +105,18 @@ async function preview(realPath, size) {
|
|
|
105
105
|
/** Derived private cache. No Skill files, workspace content or directory layouts are modified. */
|
|
106
106
|
export class TeamWorkspaceItemsIndex {
|
|
107
107
|
store;
|
|
108
|
+
cacheNamespace;
|
|
109
|
+
idleMs;
|
|
108
110
|
indexes = new Map();
|
|
109
|
-
|
|
111
|
+
listeners = new Set();
|
|
112
|
+
constructor(store = teamWorkspaceStore, cacheNamespace = 'team-workspace-items-v1', idleMs = IDLE_MS) {
|
|
110
113
|
this.store = store;
|
|
114
|
+
this.cacheNamespace = cacheNamespace;
|
|
115
|
+
this.idleMs = idleMs;
|
|
116
|
+
}
|
|
117
|
+
onCommitted(listener) {
|
|
118
|
+
this.listeners.add(listener);
|
|
119
|
+
return () => { this.listeners.delete(listener); };
|
|
111
120
|
}
|
|
112
121
|
warm(agentAid, state) {
|
|
113
122
|
// Navigation must not wait for cache JSON parsing or filesystem discovery.
|
|
@@ -134,6 +143,11 @@ export class TeamWorkspaceItemsIndex {
|
|
|
134
143
|
}
|
|
135
144
|
}
|
|
136
145
|
async query(agentAid, state, args) {
|
|
146
|
+
const { indexState: _indexState, watcherHealthy: _watcherHealthy, ...response } = await this.queryFiltered(agentAid, state, args);
|
|
147
|
+
return response;
|
|
148
|
+
}
|
|
149
|
+
/** Fixed-output queries share the bounded scanner, preview queue and path checks. */
|
|
150
|
+
async queryFiltered(agentAid, state, args, predicate = () => true, nonBlocking = false) {
|
|
137
151
|
validateTeamWorkspaceItemsArgs(args);
|
|
138
152
|
this.assertCurrent(agentAid, state);
|
|
139
153
|
const requestedPath = args.path;
|
|
@@ -141,13 +155,31 @@ export class TeamWorkspaceItemsIndex {
|
|
|
141
155
|
throw new DataRootError('FORBIDDEN', 'Path is not published in Team navigation');
|
|
142
156
|
this.store.resolvePath(state, requestedPath);
|
|
143
157
|
const index = this.get(agentAid, state);
|
|
158
|
+
if (index.watchDegraded) {
|
|
159
|
+
// A failed watcher is retried only on a legal read, never by a scan timer.
|
|
160
|
+
index.watchRestart ??= Promise.all((index.watchers ?? []).map(w => w.close())).then(() => {
|
|
161
|
+
if (index.closed)
|
|
162
|
+
return;
|
|
163
|
+
index.watchDegraded = false;
|
|
164
|
+
this.observe(index);
|
|
165
|
+
}).finally(() => { index.watchRestart = undefined; });
|
|
166
|
+
await index.watchRestart;
|
|
167
|
+
}
|
|
168
|
+
if (nonBlocking && index.scannedAt === 0) {
|
|
169
|
+
void this.refresh(index).catch(() => { index.rescan = true; });
|
|
170
|
+
return {
|
|
171
|
+
indexRevision: index.revision, items: [], total: 0,
|
|
172
|
+
nextOffset: null, hasMore: false, truncated: false, indexState: 'building',
|
|
173
|
+
watcherHealthy: index.watchReady === true && !index.watchDegraded,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
144
176
|
await this.refresh(index);
|
|
145
177
|
this.assertCurrent(agentAid, state);
|
|
146
178
|
if (args.indexRevision !== undefined && args.indexRevision !== index.revision) {
|
|
147
179
|
throw new DataRootError('INDEX_CHANGED', 'Team workspace items changed; restart pagination');
|
|
148
180
|
}
|
|
149
181
|
const snapshotRevision = index.revision;
|
|
150
|
-
const matching = index.sorted.filter(item => within(requestedPath, item.path));
|
|
182
|
+
const matching = index.sorted.filter(item => within(requestedPath, item.path) && predicate(item));
|
|
151
183
|
const offset = Number(args.offset ?? 0);
|
|
152
184
|
const limit = Number(args.limit ?? 20);
|
|
153
185
|
const window = matching.slice(offset, offset + limit);
|
|
@@ -181,6 +213,8 @@ export class TeamWorkspaceItemsIndex {
|
|
|
181
213
|
indexRevision: index.revision, path: requestedPath, offset,
|
|
182
214
|
total: matching.length, nextOffset: next < matching.length ? next : null,
|
|
183
215
|
hasMore: next < matching.length, truncated: index.truncated,
|
|
216
|
+
indexState: 'ready',
|
|
217
|
+
watcherHealthy: index.watchReady === true && !index.watchDegraded,
|
|
184
218
|
items: window.map(({ signature: _signature, realPath: _realPath, previewLoaded: _loaded, ...item }) => item),
|
|
185
219
|
};
|
|
186
220
|
// JSON escaping and long logical paths also consume transport space. A page
|
|
@@ -229,12 +263,14 @@ export class TeamWorkspaceItemsIndex {
|
|
|
229
263
|
this.observe(index);
|
|
230
264
|
}
|
|
231
265
|
clearTimeout(index.idle);
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
this.indexes.
|
|
236
|
-
|
|
237
|
-
|
|
266
|
+
if (this.idleMs > 0) {
|
|
267
|
+
index.idle = setTimeout(() => {
|
|
268
|
+
this.release(index);
|
|
269
|
+
if (this.indexes.get(agentAid) === index)
|
|
270
|
+
this.indexes.delete(agentAid);
|
|
271
|
+
}, this.idleMs);
|
|
272
|
+
index.idle.unref();
|
|
273
|
+
}
|
|
238
274
|
// Bound watcher count even on a host with many PAs.
|
|
239
275
|
if (this.indexes.size > 16) {
|
|
240
276
|
const oldest = [...this.indexes.values()].find(candidate => candidate !== index && !candidate.pending);
|
|
@@ -245,7 +281,10 @@ export class TeamWorkspaceItemsIndex {
|
|
|
245
281
|
}
|
|
246
282
|
return index;
|
|
247
283
|
}
|
|
248
|
-
cachePath(index) {
|
|
284
|
+
cachePath(index) {
|
|
285
|
+
const safeNamespace = this.cacheNamespace.replace(/[^A-Za-z0-9._-]/g, '-');
|
|
286
|
+
return path.join(agentDataDir(index.agentAid), `${safeNamespace}.json`);
|
|
287
|
+
}
|
|
249
288
|
persist(index) {
|
|
250
289
|
if (index.closed || this.indexes.get(index.agentAid) !== index)
|
|
251
290
|
return;
|
|
@@ -311,6 +350,9 @@ export class TeamWorkspaceItemsIndex {
|
|
|
311
350
|
{ root: workspaceRoot, output: false },
|
|
312
351
|
...(outputRoot && outputRoot !== workspaceRoot ? [{ root: outputRoot, output: true }] : []),
|
|
313
352
|
];
|
|
353
|
+
index.watchReady = false;
|
|
354
|
+
const generation = index.watchGeneration = (index.watchGeneration ?? 0) + 1;
|
|
355
|
+
let pendingReady = roots.length;
|
|
314
356
|
index.watchers = roots.map(({ root, output }) => {
|
|
315
357
|
const allowed = index.state.entries.filter(entry => entry.availability !== 'unavailable'
|
|
316
358
|
&& (output ? entry.path === 'output' || entry.path.startsWith('output/') : !outputRoot || entry.path !== 'output' && !entry.path.startsWith('output/')));
|
|
@@ -326,7 +368,7 @@ export class TeamWorkspaceItemsIndex {
|
|
|
326
368
|
},
|
|
327
369
|
});
|
|
328
370
|
watcher.on('all', (event, absolute) => {
|
|
329
|
-
if (index.closed)
|
|
371
|
+
if (index.closed || index.watchGeneration !== generation)
|
|
330
372
|
return;
|
|
331
373
|
const relative = path.relative(root, absolute).split(path.sep).join('/');
|
|
332
374
|
const logical = logicalPath(relative);
|
|
@@ -338,8 +380,27 @@ export class TeamWorkspaceItemsIndex {
|
|
|
338
380
|
index.timer = setTimeout(() => { void this.refresh(index).catch(() => { index.rescan = true; }); }, 75);
|
|
339
381
|
index.timer.unref();
|
|
340
382
|
});
|
|
341
|
-
watcher.on('ready', () => {
|
|
342
|
-
|
|
383
|
+
watcher.on('ready', () => {
|
|
384
|
+
if (index.closed || index.watchDegraded || index.watchGeneration !== generation)
|
|
385
|
+
return;
|
|
386
|
+
if (--pendingReady === 0)
|
|
387
|
+
index.watchReady = true;
|
|
388
|
+
index.rescan = true;
|
|
389
|
+
void this.refresh(index).catch(() => { index.rescan = true; });
|
|
390
|
+
});
|
|
391
|
+
watcher.on('error', () => {
|
|
392
|
+
if (index.closed || index.watchDegraded || index.watchGeneration !== generation)
|
|
393
|
+
return;
|
|
394
|
+
index.watchDegraded = true;
|
|
395
|
+
index.watchReady = false;
|
|
396
|
+
index.rescan = true;
|
|
397
|
+
for (const listener of this.listeners) {
|
|
398
|
+
try {
|
|
399
|
+
listener(index.agentAid, index.revision, index.sorted, index.truncated, false);
|
|
400
|
+
}
|
|
401
|
+
catch { /* observers never block reads */ }
|
|
402
|
+
}
|
|
403
|
+
});
|
|
343
404
|
return watcher;
|
|
344
405
|
});
|
|
345
406
|
}
|
|
@@ -480,6 +541,14 @@ export class TeamWorkspaceItemsIndex {
|
|
|
480
541
|
index.revision = crypto.randomBytes(12).toString('hex');
|
|
481
542
|
if (changed || full)
|
|
482
543
|
this.persist(index);
|
|
544
|
+
if (changed || full && index.scannedAt !== 0) {
|
|
545
|
+
for (const listener of this.listeners) {
|
|
546
|
+
try {
|
|
547
|
+
listener(index.agentAid, index.revision, index.sorted, index.truncated, index.watchReady === true && !index.watchDegraded);
|
|
548
|
+
}
|
|
549
|
+
catch { /* observers never block reads */ }
|
|
550
|
+
}
|
|
551
|
+
}
|
|
483
552
|
}
|
|
484
553
|
release(index) {
|
|
485
554
|
index.closed = true;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { isValidAid } from '../../aun/aid/validation.js';
|
|
3
3
|
import { ConfigTarget, mutateConfig, read } from '../../config/config-manager.js';
|
|
4
|
-
import { getPeerSnapshot, isAcceptedPeer } from '../../config/peer-book.js';
|
|
5
4
|
import { readOwnerDirectoryMembership, refreshDirectoryMarkdown } from '../../directory/owner-directory-admission.js';
|
|
6
5
|
import { MY_AGENT_TEAM_LIMIT } from '../../directory/owner-directory-markdown.js';
|
|
7
6
|
import { entryOwnerAid } from '../../directory/owner-directory-scope.js';
|
|
8
|
-
import { readAunPeerKind } from '../relation/peer-identity.js';
|
|
9
7
|
export class TeamWorkspaceTeamError extends Error {
|
|
10
8
|
code;
|
|
11
9
|
data;
|
|
@@ -36,30 +34,12 @@ export function normalizeTeamMemberAids(value, selfAid) {
|
|
|
36
34
|
throw new TeamWorkspaceTeamError('INVALID_ARGUMENT', 'team cannot contain its own Agent AID');
|
|
37
35
|
return members;
|
|
38
36
|
}
|
|
39
|
-
function contactSnapshot(selfAid) {
|
|
40
|
-
try {
|
|
41
|
-
return getPeerSnapshot(selfAid);
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
throw new TeamWorkspaceTeamError('CONTACT_BOOK_INVALID', 'The current Agent contact book is unavailable');
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function assertPeerContacts(selfAid, members) {
|
|
48
|
-
const snapshot = contactSnapshot(selfAid);
|
|
49
|
-
for (const aid of members) {
|
|
50
|
-
if (readAunPeerKind(selfAid, aid).kind !== 'private' || !snapshot.contacts.has(aid) || !isAcceptedPeer(selfAid, aid)) {
|
|
51
|
-
throw new TeamWorkspaceTeamError('TEAM_MEMBER_NOT_CONTACT', `Team member must be an active private Agent contact: ${aid}`, { memberAid: aid });
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
37
|
function assertActiveContacts(selfAid, members) {
|
|
56
38
|
for (const aid of members) {
|
|
57
39
|
const membership = readOwnerDirectoryMembership(selfAid, aid);
|
|
58
|
-
//
|
|
59
|
-
// Keep the established peer-book admission path usable in that case.
|
|
40
|
+
// Team eligibility requires the Owner directory; peer state is not a fallback.
|
|
60
41
|
if (membership === undefined) {
|
|
61
|
-
|
|
62
|
-
return;
|
|
42
|
+
throw new TeamWorkspaceTeamError('CONTACT_DIRECTORY_UNAVAILABLE', 'Owner directory is not configured');
|
|
63
43
|
}
|
|
64
44
|
// Directory unavailable
|
|
65
45
|
if (membership.category === 'unavailable') {
|
|
@@ -103,61 +83,19 @@ export function readTeamMembersState(selfAid) {
|
|
|
103
83
|
}
|
|
104
84
|
/** Keep stale contacts visible to the Owner so they can be removed. */
|
|
105
85
|
export function readTeamMemberDetails(selfAid, members) {
|
|
106
|
-
// Keep the legacy/local contact-book view when no Owner directory is configured.
|
|
107
|
-
if (members.some(aid => readOwnerDirectoryMembership(selfAid, aid) === undefined)) {
|
|
108
|
-
const snapshot = contactSnapshot(selfAid);
|
|
109
|
-
return members.map(aid => {
|
|
110
|
-
const contact = snapshot.contacts.get(aid);
|
|
111
|
-
const contactStatus = contact ? contact.status ?? 'active' : 'missing';
|
|
112
|
-
const reason = !contact ? 'NOT_A_CONTACT'
|
|
113
|
-
: contactStatus !== 'active' ? 'CONTACT_NOT_ACTIVE'
|
|
114
|
-
: readAunPeerKind(selfAid, aid).kind !== 'private' ? 'NOT_PRIVATE_CONTACT' : undefined;
|
|
115
|
-
return {
|
|
116
|
-
aid,
|
|
117
|
-
...(contact?.displayName ? { displayName: contact.displayName } : {}),
|
|
118
|
-
contactStatus,
|
|
119
|
-
availability: reason ? 'unavailable' : 'available',
|
|
120
|
-
...(reason ? { reason } : {}),
|
|
121
|
-
};
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
86
|
return members.map(aid => {
|
|
125
87
|
const membership = readOwnerDirectoryMembership(selfAid, aid);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return {
|
|
129
|
-
aid,
|
|
130
|
-
contactStatus: 'unavailable',
|
|
131
|
-
availability: 'unavailable',
|
|
132
|
-
reason: 'OWNER_DIRECTORY_UNAVAILABLE',
|
|
133
|
-
};
|
|
88
|
+
if (!membership || membership.category === 'unavailable') {
|
|
89
|
+
return { aid, contactStatus: 'unavailable', availability: 'unavailable', reason: 'OWNER_DIRECTORY_UNAVAILABLE' };
|
|
134
90
|
}
|
|
135
|
-
// Not found in directory
|
|
136
91
|
if (membership.category === 'not_found') {
|
|
137
|
-
return {
|
|
138
|
-
aid,
|
|
139
|
-
contactStatus: 'missing',
|
|
140
|
-
availability: 'unavailable',
|
|
141
|
-
reason: 'NOT_IN_OWNER_DIRECTORY',
|
|
142
|
-
};
|
|
92
|
+
return { aid, contactStatus: 'missing', availability: 'unavailable', reason: 'NOT_IN_OWNER_DIRECTORY' };
|
|
143
93
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
aid,
|
|
148
|
-
displayName: membership.entry?.name,
|
|
149
|
-
contactStatus: membership.blocked ? 'missing' : 'unavailable',
|
|
150
|
-
availability: 'unavailable',
|
|
151
|
-
reason: membership.blocked ? 'NOT_IN_OWNER_DIRECTORY' : 'NOT_AGENT_TYPE',
|
|
152
|
-
};
|
|
94
|
+
if (membership.blocked || !['agent', 'human', 'assistant'].includes(membership.category)) {
|
|
95
|
+
return { aid, contactStatus: 'unavailable', availability: 'unavailable',
|
|
96
|
+
reason: membership.blocked ? 'NOT_IN_OWNER_DIRECTORY' : 'NOT_AGENT_TYPE' };
|
|
153
97
|
}
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
aid,
|
|
157
|
-
displayName: membership.entry?.name,
|
|
158
|
-
contactStatus: 'active',
|
|
159
|
-
availability: 'available',
|
|
160
|
-
};
|
|
98
|
+
return { aid, displayName: membership.entry?.name, contactStatus: 'active', availability: 'available' };
|
|
161
99
|
});
|
|
162
100
|
}
|
|
163
101
|
export function readTeamMembers(selfAid) {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* 权限(沿用 /memory 的两级模型):
|
|
5
5
|
* - 只读(list / show / history / summary show / summary log / peers):
|
|
6
6
|
* 私聊所有角色可看;群聊仅 admin+ 可看
|
|
7
|
-
* - 写(create / rename /
|
|
7
|
+
* - 写(create / rename / status / delete / summary set / summary clear):
|
|
8
8
|
* 仅 admin+(群聊同样要求 admin,且只能操作本群关系)
|
|
9
9
|
* - rebuild-index:仅 admin+,且默认只报告不写盘(--write 才落盘)
|
|
10
10
|
*
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import { ThreadService, ThreadServiceError } from '../thread/thread-service.js';
|
|
16
16
|
import { isTopicThreadId } from '../thread/topic-id.js';
|
|
17
17
|
import { parseTimeArg, TIME_ARG_FORMATS } from '../../cli/cli-argv.js';
|
|
18
|
-
const TOPIC_STATUSES = ['
|
|
18
|
+
const TOPIC_STATUSES = ['active', 'closed', 'archived'];
|
|
19
19
|
const USAGE = [
|
|
20
20
|
'用法(更名与总结默认作用于当前话题,无需手写 ref):',
|
|
21
21
|
' /thread rename <新名称> 重命名当前话题',
|
|
@@ -26,15 +26,14 @@ const USAGE = [
|
|
|
26
26
|
'',
|
|
27
27
|
' /thread 当前对端的话题列表(等价 /thread list)',
|
|
28
28
|
' /thread list all 本节点所有对端的话题列表',
|
|
29
|
-
' /thread list [ref] [--status <s>] [--
|
|
29
|
+
' /thread list [ref] [--status <s>] [--page <n>]',
|
|
30
30
|
' /thread peers 列出有话题记录的所有对端',
|
|
31
31
|
' /thread show [ref] 查看话题元数据',
|
|
32
32
|
' /thread history [ref] [--limit <n>] [--after <ts>] [--before <ts>]',
|
|
33
33
|
' 读取话题历史消息(--after 上次 summary 的 coveredThroughTs 读增量)',
|
|
34
34
|
'',
|
|
35
|
-
' /thread create <名称> [--
|
|
36
|
-
' /thread
|
|
37
|
-
' /thread status [ref] <状态> 更新话题业务状态',
|
|
35
|
+
' /thread create <名称> [--status <s>] 新建话题',
|
|
36
|
+
' /thread status [ref] <状态> 更新话题状态(active|closed|archived)',
|
|
38
37
|
' /thread delete [ref] 删除话题(session 文件移入 _trash)',
|
|
39
38
|
' /thread rebuild-index [--write] 检查/重建话题索引',
|
|
40
39
|
'',
|
|
@@ -80,7 +79,7 @@ export function topicHelpEntries(ctx) {
|
|
|
80
79
|
out.push({ command: '/thread', aliases: ['/thread list'], description: '当前对端的话题列表', category, roles }, { command: '/thread list all', description: '本节点所有对端的话题列表', category, roles }, { command: '/thread peers', description: '有话题记录的所有对端', category, roles }, { command: '/thread show', description: '查看话题元数据', args: '[ref]', category, roles }, { command: '/thread history', description: '读取话题历史消息', args: '[ref] [--limit <n>]', category, roles });
|
|
81
80
|
// 第三档:其余写操作与索引维护
|
|
82
81
|
if (write) {
|
|
83
|
-
out.push({ command: '/thread create', description: '新建话题', args: '<名称> [--
|
|
82
|
+
out.push({ command: '/thread create', description: '新建话题', args: '<名称> [--status <s>]', category, roles }, { command: '/thread status', description: '更新话题状态', args: '[ref] <状态>', category, roles }, { command: '/thread delete', description: '删除话题', args: '[ref]', category, roles }, { command: '/thread rebuild-index', description: '检查话题索引健康状态', category, roles });
|
|
84
83
|
}
|
|
85
84
|
out.push({ command: '/thread help', description: '全部子命令说明', category, roles });
|
|
86
85
|
return out;
|
|
@@ -133,11 +132,10 @@ function truncate(s, n) {
|
|
|
133
132
|
}
|
|
134
133
|
function formatThreadLine(t, currentThreadId) {
|
|
135
134
|
const mark = currentThreadId && t.threadId === currentThreadId ? ' ←当前' : '';
|
|
136
|
-
//
|
|
135
|
+
// 标题只放标题本身;状态单独成字段,不与标题拼接
|
|
137
136
|
const bits = [
|
|
138
137
|
t.name,
|
|
139
|
-
t.
|
|
140
|
-
t.topicStatus ? `状态:${t.topicStatus}` : '',
|
|
138
|
+
t.topicStatus && t.topicStatus !== 'active' ? `状态:${t.topicStatus}` : '',
|
|
141
139
|
formatTime(t.lastActiveAt),
|
|
142
140
|
t.lastMsgSnippet ? truncate(t.lastMsgSnippet, 30) : '',
|
|
143
141
|
].filter(Boolean);
|
|
@@ -256,7 +254,6 @@ export async function handleTopicSlash(ctx) {
|
|
|
256
254
|
`session: ${t.sessionId}`,
|
|
257
255
|
`对端: ${t.peer}(${t.peerKind === 'group' ? '群' : '私聊'})`,
|
|
258
256
|
`状态: ${t.topicStatus}`,
|
|
259
|
-
`标签: ${t.label ?? '(无)'}`,
|
|
260
257
|
`创建: ${formatTime(t.createdAt)} 最近活跃: ${formatTime(t.lastActiveAt)}`,
|
|
261
258
|
`消息: ${t.msgTotal ?? 0} 条(24h 内 ${t.msg24h ?? 0} 条)`,
|
|
262
259
|
];
|
|
@@ -302,7 +299,7 @@ export async function handleTopicSlash(ctx) {
|
|
|
302
299
|
if (sub === 'create') {
|
|
303
300
|
const name = positional[0];
|
|
304
301
|
if (!name)
|
|
305
|
-
return error('用法: /thread create <名称> [--
|
|
302
|
+
return error('用法: /thread create <名称> [--status <状态>]');
|
|
306
303
|
if (!ctx.peerKey)
|
|
307
304
|
return error('当前会话没有关系上下文,无法新建话题');
|
|
308
305
|
const status = flags.status !== undefined ? needStatus(flags.status) : undefined;
|
|
@@ -315,7 +312,6 @@ export async function handleTopicSlash(ctx) {
|
|
|
315
312
|
peer: ctx.peerKey,
|
|
316
313
|
peerKind: ctx.chatType === 'group' ? 'group' : 'private',
|
|
317
314
|
name,
|
|
318
|
-
...(typeof flags.label === 'string' ? { label: flags.label } : {}),
|
|
319
315
|
...(status ? { topicStatus: status } : {}),
|
|
320
316
|
});
|
|
321
317
|
return result(`✅ 已创建话题: ${created.name}\nref: ${created.threadId}`);
|
|
@@ -333,21 +329,6 @@ export async function handleTopicSlash(ctx) {
|
|
|
333
329
|
const r = await service.renameThread({ selfAid: ctx.selfAid, peer: target.peer, threadId: target.threadId, name });
|
|
334
330
|
return result(r.changed ? `✅ 已重命名为 ${r.name}` : `话题名称已是 ${r.name}`);
|
|
335
331
|
}
|
|
336
|
-
if (sub === 'label') {
|
|
337
|
-
const ref = refSource(positional, flags);
|
|
338
|
-
const target = resolveRef(ref, ctx, service);
|
|
339
|
-
if (isPayload(target))
|
|
340
|
-
return target;
|
|
341
|
-
if (!target.threadId)
|
|
342
|
-
return error('不能标记主会话;请指定 <peer>/<threadId>');
|
|
343
|
-
const clear = flags.clear === true;
|
|
344
|
-
const labelArg = stripRefArg(positional, ref).join(' ').trim();
|
|
345
|
-
if (!clear && !labelArg)
|
|
346
|
-
return error('用法: /thread label <标签> 或 /thread label --clear');
|
|
347
|
-
const label = clear ? null : labelArg;
|
|
348
|
-
await service.labelThread({ selfAid: ctx.selfAid, peer: target.peer, threadId: target.threadId, label });
|
|
349
|
-
return result(clear ? '✅ 已清除标签' : `✅ 已设置标签: ${label}`);
|
|
350
|
-
}
|
|
351
332
|
if (sub === 'status') {
|
|
352
333
|
const ref = refSource(positional, flags);
|
|
353
334
|
const target = resolveRef(ref, ctx, service);
|
|
@@ -416,8 +397,6 @@ async function listThreads(ctx, service, positional, flags) {
|
|
|
416
397
|
selfAid: ctx.selfAid,
|
|
417
398
|
...(peer ? { peer } : {}),
|
|
418
399
|
...(status ? { status } : {}),
|
|
419
|
-
...(typeof flags.label === 'string' ? { label: flags.label } : {}),
|
|
420
|
-
...(flags.unlabeled === true ? { unlabeled: true } : {}),
|
|
421
400
|
...(flags.sort === 'created' ? { sort: 'created' } : {}),
|
|
422
401
|
page: Number.isFinite(page) && page > 0 ? page : 1,
|
|
423
402
|
limit: Number.isFinite(limit) && limit > 0 ? limit : 10,
|
|
@@ -13,13 +13,16 @@ import { controlReplyContext } from './message/outbound.js';
|
|
|
13
13
|
import { TriggerDefinitionManager } from '../trigger/manager.js';
|
|
14
14
|
import { seedUpgradeCheckTrigger } from '../trigger/system-definitions.js';
|
|
15
15
|
import { ownerResolver } from './ownership/owner-resolver.js';
|
|
16
|
+
import { ecwebInitializationService } from './initialization/service.js';
|
|
17
|
+
import { readServiceProxySnapshot, ServiceProxyManager } from '../proxy/manager.js';
|
|
16
18
|
export function detectAvailableBaseagents() {
|
|
17
19
|
// 与 init/ECWeb 的探测保持同一判据;claude 在这里也走内置二进制,
|
|
18
20
|
// 不再只看 PATH——否则 daemon 会对外声明一个实际跑不起来的 baseagent。
|
|
19
21
|
return detectBaseagentDetails().filter(item => item.detected).map(item => item.id);
|
|
20
22
|
}
|
|
21
|
-
export async function runBindBootstrapDaemon(daemonCfg) {
|
|
23
|
+
export async function runBindBootstrapDaemon(daemonCfg, ecwebSupervisor) {
|
|
22
24
|
logger.warn('[daemon-bootstrap] starting control AID + IPC only');
|
|
25
|
+
ecwebInitializationService.setRuntimeControlAid(daemonCfg.aid);
|
|
23
26
|
const bootstrapControlAid = daemonCfg.aid || '__daemon__';
|
|
24
27
|
try {
|
|
25
28
|
seedUpgradeCheckTrigger(new TriggerDefinitionManager(bootstrapControlAid), {
|
|
@@ -35,6 +38,7 @@ export async function runBindBootstrapDaemon(daemonCfg) {
|
|
|
35
38
|
receiverAid: daemonCfg.aid,
|
|
36
39
|
getAvailableBaseagents: detectAvailableBaseagents,
|
|
37
40
|
getUptimeSeconds: () => Math.floor(process.uptime()),
|
|
41
|
+
handleAppBindRequest: (payload, senderAid, encrypted) => ecwebInitializationService.handleAppBindRequest(payload, senderAid, encrypted),
|
|
38
42
|
});
|
|
39
43
|
bindService.startCleanup();
|
|
40
44
|
ownerResolver.setDaemonAid(daemonCfg.aid);
|
|
@@ -55,13 +59,8 @@ export async function runBindBootstrapDaemon(daemonCfg) {
|
|
|
55
59
|
aunTrace: daemonCfg.debug?.aunTrace,
|
|
56
60
|
aunSdkLog: daemonCfg.debug?.aunSdkLog,
|
|
57
61
|
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
logger.info(`✓ 控制 AID 已连接: ${daemonCfg.aid}`);
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
logger.warn(`控制 AID 首连失败(后台自动重连,不影响 bootstrap IPC): ${error?.message || error}`);
|
|
64
|
-
}
|
|
62
|
+
const serviceManager = new ServiceProxyManager({ providerAid: daemonCfg.aid, controlChannel, ecwebSupervisor });
|
|
63
|
+
await serviceManager.start();
|
|
65
64
|
controlChannel.onMessage(async (opts) => {
|
|
66
65
|
const text = (opts.content || '').trim();
|
|
67
66
|
let parsed = null;
|
|
@@ -71,11 +70,18 @@ export async function runBindBootstrapDaemon(daemonCfg) {
|
|
|
71
70
|
catch {
|
|
72
71
|
parsed = null;
|
|
73
72
|
}
|
|
74
|
-
const response = parsed ? await bindService.handleRequest(parsed, opts.peerId) : null;
|
|
73
|
+
const response = parsed ? await bindService.handleRequest(parsed, opts.peerId, opts.encrypted === true) : null;
|
|
75
74
|
if (response) {
|
|
76
|
-
await controlChannel.
|
|
75
|
+
await controlChannel.sendStructuredOrThrow(opts.channelId, response, controlReplyContext(opts));
|
|
77
76
|
}
|
|
78
77
|
});
|
|
78
|
+
try {
|
|
79
|
+
await controlChannel.connect();
|
|
80
|
+
logger.info(`✓ 控制 AID 已连接: ${daemonCfg.aid}`);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
logger.warn(`控制 AID 首连失败(后台自动重连,不影响 bootstrap IPC): ${error?.message || error}`);
|
|
84
|
+
}
|
|
79
85
|
const controlToken = crypto.randomBytes(32).toString('base64url');
|
|
80
86
|
fs.mkdirSync(path.dirname(resolvePaths().controlToken), { recursive: true });
|
|
81
87
|
fs.writeFileSync(resolvePaths().controlToken, controlToken, { mode: 0o600 });
|
|
@@ -89,6 +95,7 @@ export async function runBindBootstrapDaemon(daemonCfg) {
|
|
|
89
95
|
channels: {},
|
|
90
96
|
channelsByType: {},
|
|
91
97
|
queue: { pending: 0, processing: 0 },
|
|
98
|
+
serviceProxy: readServiceProxySnapshot(serviceManager.transportSnapshot()),
|
|
92
99
|
controlAid: (() => {
|
|
93
100
|
const aidState = controlChannel?.getAidState();
|
|
94
101
|
return {
|
|
@@ -135,6 +142,8 @@ export async function runBindBootstrapDaemon(daemonCfg) {
|
|
|
135
142
|
}
|
|
136
143
|
catch { }
|
|
137
144
|
bindService.stopCleanup();
|
|
145
|
+
await serviceManager.stop();
|
|
146
|
+
await ecwebSupervisor?.stop();
|
|
138
147
|
if (controlChannel) {
|
|
139
148
|
try {
|
|
140
149
|
await controlChannel.disconnect();
|