evolcore 0.0.43-test.6 → 0.0.43-test.7
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 +48 -0
- package/bin/ecmsg.js +171 -54
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/codex/app-server-client.js +22 -0
- package/dist/agents/codex-runner.js +69 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/channels/aun.js +234 -21
- package/dist/cli/agent-create.js +2 -2
- package/dist/cli/daemon-commands.js +6 -66
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +35 -2
- package/dist/cli/events-command.js +73 -0
- package/dist/cli/index.js +31 -14
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/restart-monitor.js +45 -47
- package/dist/cli/services-command.js +111 -0
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +6 -2
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +0 -7
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/schema-migration.js +6 -1
- package/dist/config-store.js +2 -1
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +104 -10
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-catalog.js +20 -0
- package/dist/core/baseagent-loader.js +60 -130
- package/dist/core/channel-loader.js +10 -1
- package/dist/core/channel-runtime.js +4 -3
- package/dist/core/command/agent-control.js +1 -1
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/chatmode-config.js +2 -36
- package/dist/core/command/command-handler.js +53 -11
- package/dist/core/command/data-root-resolver.js +32 -23
- package/dist/core/command/eventcenter-menu.js +338 -0
- package/dist/core/command/menu-catalog.js +8 -0
- package/dist/core/command/menu-handler.js +198 -84
- package/dist/core/command/menu-protocol.js +60 -11
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/slash-gate.js +1 -1
- package/dist/core/command/slash-handler.js +34 -42
- package/dist/core/command/team-workspace-bootstrap.js +350 -0
- package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
- package/dist/core/command/team-workspace-initializer.js +2 -0
- package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
- package/dist/core/command/team-workspace-job-store.js +88 -0
- package/dist/core/command/team-workspace-management-service.js +2 -0
- package/dist/core/command/team-workspace-management-store.js +96 -0
- package/dist/core/command/team-workspace-management.js +265 -0
- package/dist/core/command/team-workspace-members-menu.js +88 -0
- package/dist/core/command/team-workspace-store.js +612 -0
- package/dist/core/command/team-workspace-team.js +193 -0
- package/dist/core/daemon-control.js +8 -5
- package/dist/core/daemon-lifecycle.js +132 -73
- package/dist/core/handoff/runtime.js +3 -3
- package/dist/core/invoke/executors/index.js +13 -0
- package/dist/core/invoke/executors/media.js +283 -0
- package/dist/core/invoke/executors/text.js +198 -0
- package/dist/core/invoke/invoke-service.js +157 -0
- package/dist/core/invoke/style-router.js +48 -0
- package/dist/core/invoke/types.js +19 -0
- package/dist/core/ipc-registration.js +46 -7
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +147 -17
- package/dist/core/message/im-renderer.js +28 -84
- package/dist/core/message/message-bridge.js +4 -0
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/response-engine.js +157 -54
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +43 -5
- package/dist/core/ownership/owner-resolver.js +7 -0
- package/dist/core/permission/ec-command-parser.js +3 -2
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +2 -3
- package/dist/core/task/task-recovery-service.js +13 -2
- package/dist/core/thread/command-parser.js +9 -2
- package/dist/core/thread/thread-operation.js +21 -2
- package/dist/core/thread/thread-route.js +13 -2
- package/dist/directory/owner-directory-admission.js +40 -53
- package/dist/directory/owner-directory-cache.js +89 -113
- package/dist/directory/owner-directory-query-operation.js +8 -10
- package/dist/eck/kit-renderer.js +7 -5
- package/dist/ecweb/basic-settings-service.js +1 -1
- package/dist/ecweb/message-context-service.js +0 -4
- package/dist/ecweb/runtime/lifecycle.js +6 -2
- package/dist/ecweb/runtime/supervisor.js +19 -4
- package/dist/event-center/admission-materializer.js +114 -0
- package/dist/event-center/bus-gate.js +136 -0
- package/dist/event-center/bus-host.js +290 -0
- package/dist/event-center/bus-resolver.js +120 -0
- package/dist/event-center/center-config.js +100 -0
- package/dist/event-center/client-factory.js +50 -0
- package/dist/event-center/daemon.js +45 -0
- package/dist/event-center/directory-source.js +53 -0
- package/dist/event-center/dispatcher.js +157 -0
- package/dist/event-center/event-log.js +110 -0
- package/dist/event-center/index-generator.js +63 -0
- package/dist/event-center/ipc-operation.js +308 -0
- package/dist/event-center/ledger.js +52 -0
- package/dist/event-center/pack-loader.js +202 -0
- package/dist/event-center/pack-manager.js +85 -0
- package/dist/event-center/registry.js +238 -0
- package/dist/event-center/runtime.js +641 -0
- package/dist/event-center/script-runner.js +356 -0
- package/dist/event-center/types.js +35 -0
- package/dist/event-center/validation.js +413 -0
- package/dist/index.js +285 -99
- package/dist/ipc.js +66 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +5 -1
- package/dist/proxy/service-supervisor.js +13 -4
- package/dist/response-system/engines/v1/index.js +0 -1
- package/dist/response-system/modes/single-session/index.js +1 -1
- package/dist/services/dispatcher.js +100 -0
- package/dist/services/idempotency.js +90 -0
- package/dist/services/identity.js +52 -0
- package/dist/services/index-generator.js +70 -0
- package/dist/services/index.js +449 -0
- package/dist/services/ipc-operation.js +458 -0
- package/dist/services/ledger.js +52 -0
- package/dist/services/message-log.js +112 -0
- package/dist/services/pack-manager.js +204 -0
- package/dist/services/reply.js +55 -0
- package/dist/services/router.js +95 -0
- package/dist/services/script-runner.js +422 -0
- package/dist/services/service-payload.js +70 -0
- package/dist/services/types.js +18 -0
- package/dist/services/validation.js +297 -0
- package/dist/trigger/application-service.js +18 -0
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/script-sandbox.js +118 -22
- package/dist/utils/cross-platform.js +24 -10
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/process-introspect.js +45 -9
- package/dist/utils/startup-trace.js +74 -37
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +7 -14
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +2 -0
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/event-center.md +207 -0
- package/kits/docs/evolcore/file-navigation.md +10 -264
- package/kits/docs/evolcore/fs.md +3 -2
- package/kits/docs/evolcore/group.md +1 -1
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-protocol.md +21 -0
- package/kits/docs/evolcore/msg.md +15 -3
- package/kits/docs/evolcore/provider.md +3 -1
- package/kits/docs/evolcore/response.md +5 -5
- package/kits/docs/evolcore/services.md +277 -0
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +41 -0
- package/kits/eck_manifest.json +26 -0
- package/kits/rules/02-navigation.md +10 -1
- package/kits/schemas/_meta.json +17 -6
- package/kits/schemas/agent-config.schema.19.json +5 -7
- package/kits/schemas/agent-config.schema.20.json +936 -0
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/skills/.switches.json +1 -5
- package/kits/skills/ability/SKILL.md +56 -0
- package/kits/skills/ability/references/calling.md +56 -0
- package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
- package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
- package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
- package/kits/skills/ec-agent-create/SKILL.md +0 -1
- package/kits/skills/ec-service-proxy/SKILL.md +34 -5
- package/kits/skills/personal-assistant/SKILL.md +6 -6
- package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
- package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
- package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
- package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
- package/kits/templates/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/reply.md +0 -5
- package/kits/templates/system-fragments/thread.md +10 -8
- package/package.json +3 -5
- package/dist/cli/pa-workspace-command.js +0 -225
- package/dist/core/command/pa-workspace-store.js +0 -468
- package/dist/core/relation/pa-team.js +0 -132
- package/kits/docs/evolcore/pa-workspace.md +0 -51
- package/kits/skills/aid-ability/SKILL.md +0 -244
- package/kits/skills/ec-ability/SKILL.md +0 -67
- package/kits/skills/ec-ability/references/workflows.md +0 -15
|
@@ -9,15 +9,14 @@ import * as platform from '../utils/cross-platform.js';
|
|
|
9
9
|
import { EventBus } from '../core/event-bus.js';
|
|
10
10
|
import { applyCachedPackageUpgrades, recordPackageUpgrade } from '../utils/package-version-info.js';
|
|
11
11
|
import { acknowledgeUpgradeRestart, readUpgradeJob, updateUpgradeJob } from '../utils/upgrade-jobs.js';
|
|
12
|
-
import { isValidAid } from '../aun/aid/
|
|
13
|
-
import { msgSend } from '../aun/msg/index.js';
|
|
12
|
+
import { isValidAid } from '../aun/aid/validation.js';
|
|
14
13
|
import { scanInstances, cleanupInstances, writeRestartMonitor, removeRestartMonitor, isRestartMonitorWinner, findOrphanProcesses, killOrphans, updateRestartMonitorPhase } from '../utils/instance-registry.js';
|
|
15
14
|
import { CHANNEL_LOGS_ENV, MAIN_PACKAGE_NAME, RESTART_REQUEST_ID_ENV } from '../product.js';
|
|
16
15
|
import { readRestartRequest, updateRestartRequest, removeRestartRequest, shouldSuppressRealRestart } from '../utils/restart-safety.js';
|
|
17
16
|
import { rotateStdoutLog } from '../utils/log-writer.js';
|
|
18
17
|
import { applyDataMigration, finalizeDataMigration, planDataMigration, verifyDataMigration, } from '../core/data-migration.js';
|
|
19
|
-
import { DAEMON_SHUTDOWN_TIMEOUT_MS, requestDaemonShutdown, stopCodexAppServerOrphans } from './daemon-
|
|
20
|
-
import {
|
|
18
|
+
import { DAEMON_SHUTDOWN_TIMEOUT_MS, requestDaemonShutdown, stopCodexAppServerOrphans } from './daemon-lifecycle-client.js';
|
|
19
|
+
import { getProcessStartTimeAsync, getProcessSnapshotAsync, invalidateProcessSnapshot, startTimeMatches } from '../utils/process-introspect.js';
|
|
21
20
|
import { DEFAULT_ECWEB_PORT, ecwebService, serviceRuntimeMode } from '../config/daemon-services.js';
|
|
22
21
|
import { stopEcwebForRestart } from '../ecweb/runtime/lifecycle.js';
|
|
23
22
|
import { StartupTracer, STARTUP_TRACE_ID_ENV } from '../utils/startup-trace.js';
|
|
@@ -101,10 +100,10 @@ function cleanEnv() {
|
|
|
101
100
|
delete process.env[key];
|
|
102
101
|
}
|
|
103
102
|
}
|
|
104
|
-
function isPidReused(pid, expectedStartedAt) {
|
|
103
|
+
async function isPidReused(pid, expectedStartedAt) {
|
|
105
104
|
if (expectedStartedAt === undefined)
|
|
106
105
|
return false;
|
|
107
|
-
const actualStartedAt =
|
|
106
|
+
const actualStartedAt = await getProcessStartTimeAsync(pid);
|
|
108
107
|
return actualStartedAt !== null && !startTimeMatches(expectedStartedAt, actualStartedAt);
|
|
109
108
|
}
|
|
110
109
|
function reportPidReused(pid, log) {
|
|
@@ -159,7 +158,7 @@ export async function cmdRestartMonitor() {
|
|
|
159
158
|
}
|
|
160
159
|
// 单实例保护:pre-check + post-write 自检(同 main 进程)
|
|
161
160
|
{
|
|
162
|
-
const pre = scanInstances();
|
|
161
|
+
const pre = scanInstances({ kind: 'restart-monitor', includeAidActivity: false });
|
|
163
162
|
const aliveOthers = pre.restartMonitors.filter(m => m.alive && m.record.pid !== process.pid);
|
|
164
163
|
if (aliveOthers.length > 0) {
|
|
165
164
|
log(`Another restart-monitor already running (PID: ${aliveOthers.map(m => m.record.pid).join(', ')}), exiting`);
|
|
@@ -202,7 +201,7 @@ export async function cmdRestartMonitor() {
|
|
|
202
201
|
const isServiceAlive = async () => {
|
|
203
202
|
if (!fs.existsSync(p.readySignal))
|
|
204
203
|
return false;
|
|
205
|
-
const s = scanInstances();
|
|
204
|
+
const s = scanInstances({ kind: 'main', includeAidActivity: false });
|
|
206
205
|
if (!s.mains.some(m => m.alive))
|
|
207
206
|
return false;
|
|
208
207
|
return true;
|
|
@@ -211,7 +210,7 @@ export async function cmdRestartMonitor() {
|
|
|
211
210
|
if (!hasCorrelatedRequest)
|
|
212
211
|
return;
|
|
213
212
|
const requesterPid = readRestartRequest(pendingFile, requestId)?.requesterPid;
|
|
214
|
-
const daemonPid = scanInstances().mains.find(item => item.alive && item.record.pid !== requesterPid)?.record.pid;
|
|
213
|
+
const daemonPid = scanInstances({ kind: 'main', includeAidActivity: false }).mains.find(item => item.alive && item.record.pid !== requesterPid)?.record.pid;
|
|
215
214
|
if (daemonPid && updateRestartRequest(pendingFile, requestId, { status: 'ready', daemonPid })) {
|
|
216
215
|
if (upgradeJob && !readUpgradeJob(upgradeJob.jobId)?.lifecycle)
|
|
217
216
|
updateUpgradeJob(upgradeJob.jobId, { lifecycle: { status: 'ready', at: new Date().toISOString() } });
|
|
@@ -226,6 +225,7 @@ export async function cmdRestartMonitor() {
|
|
|
226
225
|
const trace = new StartupTracer('restart-monitor', {
|
|
227
226
|
traceId: process.env[STARTUP_TRACE_ID_ENV] || undefined,
|
|
228
227
|
firstPhase: 'monitor.bootstrap',
|
|
228
|
+
initialPhase: 'running',
|
|
229
229
|
});
|
|
230
230
|
delete process.env[STARTUP_TRACE_ID_ENV];
|
|
231
231
|
trace.setMeta('operation', 'restart');
|
|
@@ -277,23 +277,25 @@ export async function cmdRestartMonitor() {
|
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
updateRestartMonitorPhase(process.pid, 'accepted');
|
|
280
|
-
trace.mark('monitor.stopDaemon');
|
|
280
|
+
trace.mark('monitor.stopDaemon', undefined, { initialPhase: 'running' });
|
|
281
281
|
log('Restart monitor accepted after migration preflight and monitor election');
|
|
282
282
|
if (upgradeJob) {
|
|
283
283
|
updateUpgradeJob(upgradeJob.jobId, { status: 'restart-started', success: true, phase: 'restart' }, '预检通过,已进入重启执行;不代表新进程已就绪');
|
|
284
|
-
await acknowledgeUpgradeRestart(upgradeJob.jobId);
|
|
284
|
+
await trace.waitForDependency(acknowledgeUpgradeRestart(upgradeJob.jobId), 'upgrade restart acknowledgement');
|
|
285
285
|
}
|
|
286
286
|
// Test daemons live in one temporary HOME per test, so the current HOME's
|
|
287
287
|
// instance registry cannot see them. Their strict environment markers make
|
|
288
288
|
// them safe to reap globally on every real restart. Keep one process-table
|
|
289
289
|
// snapshot for both orphan categories; each Windows CIM scan is expensive.
|
|
290
|
-
const
|
|
290
|
+
const beforeStopSnapshot = await trace.waitForDependency(getProcessSnapshotAsync({ fresh: true }), 'process inspection before shutdown');
|
|
291
|
+
let oldStatus = scanInstances({ includeAidActivity: false, processSnapshot: beforeStopSnapshot });
|
|
292
|
+
const orphanSnapshot = findOrphanProcesses(oldStatus, beforeStopSnapshot);
|
|
291
293
|
{
|
|
292
294
|
const leakedTestDaemons = orphanSnapshot.filter(o => o.confirmedTestDaemon);
|
|
293
295
|
if (leakedTestDaemons.length > 0) {
|
|
294
296
|
const killed = killOrphans(leakedTestDaemons);
|
|
295
297
|
log(`Cleaned ${killed.length} leaked test daemon(s): ${killed.join(', ')}`);
|
|
296
|
-
await sleep(500);
|
|
298
|
+
await trace.waitForDependency(sleep(500), 'test daemon exit');
|
|
297
299
|
}
|
|
298
300
|
}
|
|
299
301
|
// A stale instance record can disappear while the real Windows process is
|
|
@@ -312,17 +314,17 @@ export async function cmdRestartMonitor() {
|
|
|
312
314
|
const pids = runtimeOrphans.map(o => o.pid).join(', ');
|
|
313
315
|
log(`Stopping unregistered EvolCore process(es): ${pids}`);
|
|
314
316
|
const orphanPids = new Set(runtimeOrphans.map(orphan => orphan.pid));
|
|
315
|
-
const ping = await requestDaemonShutdown(p.socket, DAEMON_SHUTDOWN_TIMEOUT_MS, 'restart-monitor orphan cleanup', orphanPids);
|
|
317
|
+
const ping = await trace.waitForDependency(requestDaemonShutdown(p.socket, DAEMON_SHUTDOWN_TIMEOUT_MS, 'restart-monitor orphan cleanup', orphanPids), 'old daemon shutdown acknowledgement');
|
|
316
318
|
for (const orphan of runtimeOrphans) {
|
|
317
319
|
if (orphan.pid !== ping)
|
|
318
320
|
platform.killProcess(orphan.pid, false);
|
|
319
321
|
}
|
|
320
|
-
const exited = await Promise.all(runtimeOrphans.map(async (orphan) => {
|
|
322
|
+
const exited = await trace.waitForDependency(Promise.all(runtimeOrphans.map(async (orphan) => {
|
|
321
323
|
if (await platform.waitForProcessExit(orphan.pid, orphan.pid === ping ? 30_000 : 10_000))
|
|
322
324
|
return true;
|
|
323
325
|
platform.killProcess(orphan.pid, true);
|
|
324
326
|
return platform.waitForProcessExit(orphan.pid, 5_000);
|
|
325
|
-
}));
|
|
327
|
+
})), 'unregistered daemon exit');
|
|
326
328
|
if (exited.some(result => !result)) {
|
|
327
329
|
const message = `未登记的 EvolCore 进程仍未退出(PID: ${pids}),已停止重启以避免重复连接 AUN。`;
|
|
328
330
|
log(message);
|
|
@@ -330,15 +332,18 @@ export async function cmdRestartMonitor() {
|
|
|
330
332
|
process.exit(1);
|
|
331
333
|
}
|
|
332
334
|
cleanupInstances();
|
|
335
|
+
// Orphan shutdown can take seconds; do not reuse its pre-shutdown view of mains.
|
|
336
|
+
invalidateProcessSnapshot();
|
|
337
|
+
const snapshot = await trace.waitForDependency(getProcessSnapshotAsync({ fresh: true }), 'process inspection after orphan cleanup');
|
|
338
|
+
oldStatus = scanInstances({ includeAidActivity: false, processSnapshot: snapshot });
|
|
333
339
|
}
|
|
334
340
|
// 等待所有活 main 进程退出(可能不止一个)
|
|
335
|
-
const oldStatus = scanInstances();
|
|
336
341
|
const aliveMains = oldStatus.mains.filter(m => m.alive);
|
|
337
342
|
if (aliveMains.length > 0) {
|
|
338
343
|
const oldPids = aliveMains.map(m => m.record.pid);
|
|
339
344
|
const expectedStarts = new Map(aliveMains.map(m => [m.record.pid, m.record.startedAt]));
|
|
340
345
|
log(`Monitoring ${oldPids.length} main process(es): ${oldPids.join(', ')}`);
|
|
341
|
-
const gracefulPid = await requestDaemonShutdown(p.socket, DAEMON_SHUTDOWN_TIMEOUT_MS, 'restart-monitor', new Set(oldPids));
|
|
346
|
+
const gracefulPid = await trace.waitForDependency(requestDaemonShutdown(p.socket, DAEMON_SHUTDOWN_TIMEOUT_MS, 'restart-monitor', new Set(oldPids)), 'old daemon shutdown acknowledgement');
|
|
342
347
|
log(`Graceful shutdown request ${gracefulPid === null ? 'was not accepted' : `accepted by PID ${gracefulPid}`}`);
|
|
343
348
|
// 没有收到 IPC shutdown 确认的进程才走信号兜底
|
|
344
349
|
for (const pid of oldPids) {
|
|
@@ -352,27 +357,16 @@ export async function cmdRestartMonitor() {
|
|
|
352
357
|
}
|
|
353
358
|
}
|
|
354
359
|
}
|
|
355
|
-
const exited = await Promise.all(oldPids.map(async (oldPid) => {
|
|
360
|
+
const exited = await trace.waitForDependency(Promise.all(oldPids.map(async (oldPid) => {
|
|
356
361
|
const expectedStartedAt = expectedStarts.get(oldPid);
|
|
357
|
-
|
|
358
|
-
reportPidReused(oldPid, log);
|
|
359
|
-
return true;
|
|
360
|
-
}
|
|
362
|
+
// The phase snapshot verified the registered identity before requesting shutdown.
|
|
361
363
|
if (await platform.waitForProcessExit(oldPid, 30_000)) {
|
|
362
|
-
if (isPidReused(oldPid, expectedStartedAt)) {
|
|
363
|
-
reportPidReused(oldPid, log);
|
|
364
|
-
return true;
|
|
365
|
-
}
|
|
366
364
|
log(`Process ${oldPid} has exited`);
|
|
367
365
|
return true;
|
|
368
366
|
}
|
|
369
|
-
if (isPidReused(oldPid, expectedStartedAt)) {
|
|
370
|
-
reportPidReused(oldPid, log);
|
|
371
|
-
return true;
|
|
372
|
-
}
|
|
373
367
|
const state = platform.getProcessState(oldPid);
|
|
374
368
|
log(`ERROR: Process ${oldPid} still running after 30s${state ? ` (state=${state})` : ''}, force killing`);
|
|
375
|
-
if (isPidReused(oldPid, expectedStartedAt)) {
|
|
369
|
+
if (await isPidReused(oldPid, expectedStartedAt)) {
|
|
376
370
|
reportPidReused(oldPid, log);
|
|
377
371
|
return true;
|
|
378
372
|
}
|
|
@@ -380,7 +374,7 @@ export async function cmdRestartMonitor() {
|
|
|
380
374
|
log(`Forced termination for PID ${oldPid}: ${forcedKill ? 'accepted' : 'failed'}`);
|
|
381
375
|
const forced = await platform.waitForProcessExit(oldPid, 5_000);
|
|
382
376
|
log(`Forced termination wait for PID ${oldPid}: ${forced ? 'exited' : 'still running'}`);
|
|
383
|
-
if (isPidReused(oldPid, expectedStartedAt)) {
|
|
377
|
+
if (!forced && await isPidReused(oldPid, expectedStartedAt)) {
|
|
384
378
|
reportPidReused(oldPid, log);
|
|
385
379
|
return true;
|
|
386
380
|
}
|
|
@@ -389,7 +383,7 @@ export async function cmdRestartMonitor() {
|
|
|
389
383
|
log(`ERROR: Process ${oldPid} survived forced termination${finalState ? ` (state=${finalState})` : ''}`);
|
|
390
384
|
}
|
|
391
385
|
return forced;
|
|
392
|
-
}));
|
|
386
|
+
})), 'old daemon exit');
|
|
393
387
|
if (exited.some(result => !result)) {
|
|
394
388
|
log('❌ Existing daemon process could not be stopped; refusing to spawn a replacement');
|
|
395
389
|
await notifyDaemonOwners(p, '❌ 旧 EvolCore 进程未能退出,已停止重启,避免重复连接 AUN。', log);
|
|
@@ -407,8 +401,10 @@ export async function cmdRestartMonitor() {
|
|
|
407
401
|
// Shutdown changed the process table. A cached pre-shutdown snapshot can
|
|
408
402
|
// otherwise classify the exited daemon as an unregistered runtime process.
|
|
409
403
|
invalidateProcessSnapshot();
|
|
410
|
-
const
|
|
411
|
-
const
|
|
404
|
+
const afterStopSnapshot = await trace.waitForDependency(getProcessSnapshotAsync({ fresh: true }), 'process inspection after shutdown');
|
|
405
|
+
const remainingStatus = scanInstances({ includeAidActivity: false, processSnapshot: afterStopSnapshot });
|
|
406
|
+
const remaining = findOrphanProcesses(remainingStatus, afterStopSnapshot);
|
|
407
|
+
const remainingMains = remainingStatus.mains.filter(item => item.alive);
|
|
412
408
|
const remainingRuntime = remaining.filter(belongsToRuntime);
|
|
413
409
|
if (remainingMains.length || remainingRuntime.length) {
|
|
414
410
|
const pids = [...new Set([
|
|
@@ -437,7 +433,7 @@ export async function cmdRestartMonitor() {
|
|
|
437
433
|
try {
|
|
438
434
|
const service = ecwebService(loadDaemonConfig().services);
|
|
439
435
|
if (service?.enabled && serviceRuntimeMode(service) === 'managed') {
|
|
440
|
-
await stopEcwebForRestart(p, service.port ?? DEFAULT_ECWEB_PORT, log);
|
|
436
|
+
await trace.waitForDependency(stopEcwebForRestart(p, service.port ?? DEFAULT_ECWEB_PORT, log), 'ECWeb shutdown confirmation');
|
|
441
437
|
}
|
|
442
438
|
}
|
|
443
439
|
catch (error) {
|
|
@@ -1152,7 +1148,7 @@ async function spawnAndWaitReady(p, log, timeout, trace) {
|
|
|
1152
1148
|
});
|
|
1153
1149
|
const childPid = child.pid;
|
|
1154
1150
|
trace.setMeta('daemonPid', String(childPid));
|
|
1155
|
-
trace.mark('monitor.waitReady');
|
|
1151
|
+
trace.mark('monitor.waitReady', undefined, { initialPhase: 'running' });
|
|
1156
1152
|
if (foreground) {
|
|
1157
1153
|
foregroundDaemonExit = new Promise(resolve => {
|
|
1158
1154
|
child.once('error', () => resolve(1));
|
|
@@ -1164,15 +1160,16 @@ async function spawnAndWaitReady(p, log, timeout, trace) {
|
|
|
1164
1160
|
fs.closeSync(out);
|
|
1165
1161
|
fs.closeSync(err);
|
|
1166
1162
|
log(`Spawned new process PID: ${childPid}, waiting for ready signal...`);
|
|
1163
|
+
const isChildRunning = () => trace.waitForDependency(platform.isProcessRunningAsync(childPid), 'daemon process liveness');
|
|
1167
1164
|
// 轮询等待 ready.signal 出现
|
|
1168
1165
|
const start = Date.now();
|
|
1169
1166
|
while (Date.now() - start < timeout) {
|
|
1170
|
-
await sleep(500);
|
|
1167
|
+
await trace.waitForDependency(sleep(500), 'daemon ready.signal');
|
|
1171
1168
|
// 进程已退出则提前失败
|
|
1172
|
-
if (!
|
|
1169
|
+
if (!await isChildRunning()) {
|
|
1173
1170
|
log('Process exited before ready signal');
|
|
1174
1171
|
if (requireEcweb)
|
|
1175
|
-
await stopEcwebForRestart(p, ecwebPort, log);
|
|
1172
|
+
await trace.waitForDependency(stopEcwebForRestart(p, ecwebPort, log), 'ECWeb shutdown confirmation');
|
|
1176
1173
|
return false;
|
|
1177
1174
|
}
|
|
1178
1175
|
if (fs.existsSync(p.readySignal)) {
|
|
@@ -1181,8 +1178,8 @@ async function spawnAndWaitReady(p, log, timeout, trace) {
|
|
|
1181
1178
|
return true;
|
|
1182
1179
|
}
|
|
1183
1180
|
}
|
|
1184
|
-
const ping = await ipcQuery(p.socket, { type: 'ping' }, platform.isWindows ? 5_000 : 1_000);
|
|
1185
|
-
if (ping?.pong === true && ping.pid === childPid &&
|
|
1181
|
+
const ping = await trace.waitForDependency(ipcQuery(p.socket, { type: 'ping' }, platform.isWindows ? 5_000 : 1_000), 'daemon IPC ping response');
|
|
1182
|
+
if (ping?.pong === true && ping.pid === childPid && await isChildRunning()) {
|
|
1186
1183
|
log(`Daemon IPC is ready (PID: ${childPid}); startup finalization and managed services continue in background`);
|
|
1187
1184
|
trace.finish(true);
|
|
1188
1185
|
return true;
|
|
@@ -1190,18 +1187,18 @@ async function spawnAndWaitReady(p, log, timeout, trace) {
|
|
|
1190
1187
|
log(`Daemon ready signal not received within ${timeout / 1000}s and identified IPC is unavailable`);
|
|
1191
1188
|
// A timeout is still a live-process race: do not let self-heal spawn a
|
|
1192
1189
|
// replacement while the timed-out daemon owns the IPC endpoint or a port.
|
|
1193
|
-
if (
|
|
1190
|
+
if (await isChildRunning()) {
|
|
1194
1191
|
platform.killProcessOnly(childPid, false);
|
|
1195
|
-
if (!await platform.waitForProcessExit(childPid, 5_000)) {
|
|
1192
|
+
if (!await trace.waitForDependency(platform.waitForProcessExit(childPid, 5_000), 'timed out daemon exit')) {
|
|
1196
1193
|
log(`Process ${childPid} survived graceful termination, forcing kill`);
|
|
1197
1194
|
platform.killProcessOnly(childPid, true);
|
|
1198
|
-
if (!await platform.waitForProcessExit(childPid, 5_000)) {
|
|
1195
|
+
if (!await trace.waitForDependency(platform.waitForProcessExit(childPid, 5_000), 'forced daemon exit')) {
|
|
1199
1196
|
throw new Error(`Process ${childPid} survived forced termination; refusing rollback or duplicate startup`);
|
|
1200
1197
|
}
|
|
1201
1198
|
}
|
|
1202
1199
|
}
|
|
1203
1200
|
if (requireEcweb)
|
|
1204
|
-
await stopEcwebForRestart(p, ecwebPort, log);
|
|
1201
|
+
await trace.waitForDependency(stopEcwebForRestart(p, ecwebPort, log), 'ECWeb shutdown confirmation');
|
|
1205
1202
|
cleanupInstances();
|
|
1206
1203
|
return false;
|
|
1207
1204
|
}
|
|
@@ -1325,6 +1322,7 @@ async function notifyDaemonOwners(p, message, log) {
|
|
|
1325
1322
|
});
|
|
1326
1323
|
if (validOwners.length === 0)
|
|
1327
1324
|
return;
|
|
1325
|
+
const { msgSend } = await import('../aun/msg/index.js');
|
|
1328
1326
|
const text = formatDaemonOwnerNotice(p, message);
|
|
1329
1327
|
for (const owner of validOwners) {
|
|
1330
1328
|
try {
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ec services` CLI:服务路由运维与对端调用。
|
|
3
|
+
*
|
|
4
|
+
* 全部子命令都经 daemon IPC(`services.op`)执行,不在 CLI 侧建 AUN 连接:
|
|
5
|
+
* 请求登记与应答落盘都在 daemon 的 AunRequestRegistry 里,CLI 被杀也不丢结果。
|
|
6
|
+
*/
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import { ipcQuery } from '../ipc.js';
|
|
9
|
+
import { resolvePaths } from '../paths.js';
|
|
10
|
+
const HELP = `ec services — 服务路由运维
|
|
11
|
+
|
|
12
|
+
本机:
|
|
13
|
+
ec services status [<包名>] [--aid <aid>] [--format json] 每包状态
|
|
14
|
+
ec services types [--aid <aid>] 本 AID 可接的全部 services.* type
|
|
15
|
+
ec services ledger <包名> [--tail N] [--aid <aid>] 台账
|
|
16
|
+
ec services tail <包名> [--tail N] [--aid <aid>] 服务消息日志
|
|
17
|
+
ec services doctor [<包名>] [--aid <aid>] 诊断
|
|
18
|
+
ec services reload [<包名>] [--aid <aid>] 重载
|
|
19
|
+
ec services enable / disable [--aid <aid>] 总闸
|
|
20
|
+
|
|
21
|
+
对端:
|
|
22
|
+
ec services describe <aid> [--service <type>] 查对端可用服务
|
|
23
|
+
ec services schema <aid> <type> 查某个服务的请求 schema
|
|
24
|
+
ec services call <aid> <type> --data '<json>' [--timeout 30] [--encrypted] [--no-wait]
|
|
25
|
+
ec services call --request-id <id> --wait 查已发出的调用(--aid 指定本端)
|
|
26
|
+
|
|
27
|
+
服务调用是点对点、要结果、不丢的消息:结果由 daemon 落盘,CLI 被杀也不丢。`;
|
|
28
|
+
/** 这三个子命令的回包是「对端应答」,CLI 只打印正文。 */
|
|
29
|
+
const RELAY_COMMANDS = new Set(['call', 'describe', 'schema']);
|
|
30
|
+
function readControlToken() {
|
|
31
|
+
try {
|
|
32
|
+
return fs.readFileSync(resolvePaths().controlToken, 'utf8').trim() || undefined;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function queryServices(argv, timeoutMs = 20_000) {
|
|
39
|
+
const controlToken = readControlToken();
|
|
40
|
+
try {
|
|
41
|
+
const response = await ipcQuery(resolvePaths().socket, { type: 'services.op', argv, controlToken }, timeoutMs, { throwOnError: false });
|
|
42
|
+
if (!response || typeof response !== 'object')
|
|
43
|
+
return { transportError: 'invalid daemon response' };
|
|
44
|
+
return { response };
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return { transportError: error instanceof Error ? error.message : String(error) };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function printResult(result, json) {
|
|
51
|
+
if (json || (result && typeof result === 'object')) {
|
|
52
|
+
console.log(JSON.stringify(result, null, 2));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
console.log(String(result));
|
|
56
|
+
}
|
|
57
|
+
export async function runServicesCommand(argv) {
|
|
58
|
+
const args = [...argv];
|
|
59
|
+
const json = args.includes('--format') && args[args.indexOf('--format') + 1] === 'json';
|
|
60
|
+
if (args.length === 0 || args[0] === 'help' || args[0] === '--help') {
|
|
61
|
+
console.log(HELP);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// `call` 要等结果:IPC 超时必须覆盖调用预算,否则 CLI 先断而 daemon 还在等。
|
|
65
|
+
const callTimeoutMs = args[0] === 'call' ? readCallBudget(args) : undefined;
|
|
66
|
+
const query = await queryServices(args, callTimeoutMs);
|
|
67
|
+
if ('transportError' in query) {
|
|
68
|
+
console.error(`daemon 不可达:${query.transportError}`);
|
|
69
|
+
process.exitCode = 1;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const { response } = query;
|
|
73
|
+
if (!response.ok) {
|
|
74
|
+
const result = response.result && typeof response.result === 'object' ? response.result : undefined;
|
|
75
|
+
if (json)
|
|
76
|
+
console.log(JSON.stringify({ ok: false, code: response.code, error: response.error, ...(result ?? {}) }));
|
|
77
|
+
else
|
|
78
|
+
console.error(`${response.code ?? 'ERROR'}: ${response.error ?? 'unknown error'}`);
|
|
79
|
+
// 超时不重试:退出码 2 表示「可能已执行」。
|
|
80
|
+
process.exitCode = response.code === 'NO_RESULT' ? 2 : 1;
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
// 对端调用的成功输出是应答正文;--no-wait 时没有 response,回落到 request_id。
|
|
84
|
+
const result = response.result;
|
|
85
|
+
if (RELAY_COMMANDS.has(args[0] ?? '') && result && 'response' in result) {
|
|
86
|
+
printResult(result.response, json);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
printResult(result, json);
|
|
90
|
+
}
|
|
91
|
+
/** `--timeout` 预算 + 5s 余量,作为 IPC 等待上限。 */
|
|
92
|
+
function readCallBudget(args) {
|
|
93
|
+
const index = args.indexOf('--timeout');
|
|
94
|
+
const raw = index >= 0 ? args[index + 1] : undefined;
|
|
95
|
+
const parsed = raw === undefined ? 30_000 : parseTimeoutMs(raw);
|
|
96
|
+
return (parsed ?? 30_000) + 5_000;
|
|
97
|
+
}
|
|
98
|
+
function parseTimeoutMs(value) {
|
|
99
|
+
const trimmed = value.trim().toLowerCase();
|
|
100
|
+
const plain = Number(trimmed);
|
|
101
|
+
if (Number.isFinite(plain) && plain > 0)
|
|
102
|
+
return Math.round(plain * 1000);
|
|
103
|
+
const match = /^(\d+(?:\.\d+)?)(ms|s|m)$/.exec(trimmed);
|
|
104
|
+
if (!match)
|
|
105
|
+
return undefined;
|
|
106
|
+
const amount = Number(match[1]);
|
|
107
|
+
if (!Number.isFinite(amount) || amount <= 0)
|
|
108
|
+
return undefined;
|
|
109
|
+
const unit = match[2];
|
|
110
|
+
return Math.round(unit === 'ms' ? amount : unit === 'm' ? amount * 60_000 : amount * 1000);
|
|
111
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { authorizeLocalCommand } from './task-context.js';
|
|
3
|
+
import { agentWorkspaceDir } from '../paths.js';
|
|
4
|
+
import { readTeamWorkspaceNavigation, upsertTeamWorkspaceNavigation, removeTeamWorkspaceNavigation, updateTeamWorkspaceNavigation, } from '../core/command/team-workspace-store.js';
|
|
5
|
+
import { readTeamMembers, updateTeamMembers } from '../core/command/team-workspace-team.js';
|
|
6
|
+
import { TeamWorkspaceBootstrapService, TeamWorkspaceInitializer } from '../core/command/team-workspace-bootstrap.js';
|
|
7
|
+
const USAGE = `用法: ec team workspace init [--workspace <绝对路径>]
|
|
8
|
+
ec team navigation show
|
|
9
|
+
ec team navigation update --upsert-json <entries-json> [--expected-revision <n>]
|
|
10
|
+
ec team navigation update --remove-ids-json <ids-json> [--expected-revision <n>]
|
|
11
|
+
ec team navigation update --replace-json <entries-json> [--expected-revision <n>]
|
|
12
|
+
ec team members show
|
|
13
|
+
ec team members update --members-json <aids-json>
|
|
14
|
+
|
|
15
|
+
所有命令只输出 JSON;只允许当前 Agent Owner 的 AUN 私聊托管会话。`;
|
|
16
|
+
class TeamWorkspaceCommandError extends Error {
|
|
17
|
+
code;
|
|
18
|
+
constructor(code, message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.code = code;
|
|
21
|
+
this.name = 'TeamWorkspaceCommandError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function parseJsonFlag(args, flag) {
|
|
25
|
+
const index = args.indexOf(flag);
|
|
26
|
+
if (index < 0 || !args[index + 1])
|
|
27
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', `${flag} is required`);
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(args[index + 1]);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', `${flag} must contain valid JSON`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function assertFlags(args, allowed) {
|
|
36
|
+
const seen = new Set();
|
|
37
|
+
for (let index = 0; index < args.length; index += 2) {
|
|
38
|
+
const flag = args[index];
|
|
39
|
+
if (!allowed.includes(flag) || seen.has(flag) || !args[index + 1]) {
|
|
40
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', `Unexpected or duplicate argument: ${flag ?? ''}`);
|
|
41
|
+
}
|
|
42
|
+
seen.add(flag);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function expectedRevision(args, current) {
|
|
46
|
+
const index = args.indexOf('--expected-revision');
|
|
47
|
+
if (index < 0)
|
|
48
|
+
return current;
|
|
49
|
+
const raw = args[index + 1];
|
|
50
|
+
if (!raw || !/^\d+$/.test(raw))
|
|
51
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', '--expected-revision must be a non-negative integer');
|
|
52
|
+
const revision = Number(raw);
|
|
53
|
+
if (!Number.isSafeInteger(revision))
|
|
54
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', '--expected-revision must be a safe integer');
|
|
55
|
+
return revision;
|
|
56
|
+
}
|
|
57
|
+
function output(value) { process.stdout.write(`${JSON.stringify(value, null, 2)}\n`); }
|
|
58
|
+
function assertOwnerContext(context) {
|
|
59
|
+
if (context.channel !== 'aun' || context.chatType !== 'private' || context.peerRole !== 'owner' || !context.selfAid || !context.peerId) {
|
|
60
|
+
throw new TeamWorkspaceCommandError('NOT_ALLOWED', 'Team workspace commands require the current Agent Owner in an AUN private chat');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function initializeWorkspace(aid, ownerAid, suppliedPath) {
|
|
64
|
+
if (suppliedPath && !path.isAbsolute(suppliedPath))
|
|
65
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', '--workspace must be an absolute path');
|
|
66
|
+
const result = new TeamWorkspaceInitializer().initialize({ agentAid: aid, ownerAid }, suppliedPath ?? agentWorkspaceDir(aid), { allowExistingContent: !!suppliedPath });
|
|
67
|
+
return { workspaceId: result.state.workspaceId, navigationRevision: result.state.navigationRevision, rootPath: result.state.rootPath };
|
|
68
|
+
}
|
|
69
|
+
export async function cmdTeamWorkspace(rawArgs) {
|
|
70
|
+
if (rawArgs.length === 0 || rawArgs.includes('--help') || rawArgs.includes('-h')) {
|
|
71
|
+
console.log(USAGE);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const context = await authorizeLocalCommand(['team', ...rawArgs]);
|
|
76
|
+
assertOwnerContext(context);
|
|
77
|
+
if (rawArgs[0] === 'workspace' && rawArgs[1] === 'init') {
|
|
78
|
+
const pathIndex = rawArgs.indexOf('--workspace');
|
|
79
|
+
const workspace = pathIndex >= 0 ? rawArgs[pathIndex + 1] : undefined;
|
|
80
|
+
if (pathIndex >= 0 && (!workspace || rawArgs.length !== 4))
|
|
81
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', USAGE);
|
|
82
|
+
if (pathIndex < 0 && rawArgs.length !== 2)
|
|
83
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', USAGE);
|
|
84
|
+
if (!workspace)
|
|
85
|
+
new TeamWorkspaceBootstrapService().migrateLegacyDefault({ agentAid: context.selfAid, ownerAid: context.peerId });
|
|
86
|
+
output({ ok: true, ...initializeWorkspace(context.selfAid, context.peerId, workspace) });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (rawArgs[0] === 'navigation' && rawArgs[1] === 'show' && rawArgs.length === 2) {
|
|
90
|
+
new TeamWorkspaceBootstrapService().migrateLegacyDefault({ agentAid: context.selfAid, ownerAid: context.peerId });
|
|
91
|
+
output({ ok: true, ...readTeamWorkspaceNavigation(context.selfAid) });
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (rawArgs[0] === 'navigation' && rawArgs[1] === 'update') {
|
|
95
|
+
new TeamWorkspaceBootstrapService().migrateLegacyDefault({ agentAid: context.selfAid, ownerAid: context.peerId });
|
|
96
|
+
assertFlags(rawArgs.slice(2), ['--upsert-json', '--remove-ids-json', '--replace-json', '--expected-revision']);
|
|
97
|
+
const modes = ['--upsert-json', '--remove-ids-json', '--replace-json'].filter(flag => rawArgs.includes(flag));
|
|
98
|
+
if (modes.length !== 1)
|
|
99
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', 'Specify exactly one navigation update mode');
|
|
100
|
+
const navigation = readTeamWorkspaceNavigation(context.selfAid);
|
|
101
|
+
const revision = expectedRevision(rawArgs, navigation.navigationRevision);
|
|
102
|
+
const mode = modes[0];
|
|
103
|
+
const value = parseJsonFlag(rawArgs, mode);
|
|
104
|
+
let result;
|
|
105
|
+
if (mode === '--upsert-json')
|
|
106
|
+
result = upsertTeamWorkspaceNavigation(context.selfAid, revision, value);
|
|
107
|
+
else if (mode === '--remove-ids-json')
|
|
108
|
+
result = removeTeamWorkspaceNavigation(context.selfAid, revision, value);
|
|
109
|
+
else
|
|
110
|
+
result = updateTeamWorkspaceNavigation(context.selfAid, revision, value);
|
|
111
|
+
output({ ok: true, action: mode.slice(2, -5), ...result });
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (rawArgs[0] === 'members' && rawArgs[1] === 'show' && rawArgs.length === 2) {
|
|
115
|
+
output({ ok: true, aid: context.selfAid, members: readTeamMembers(context.selfAid) });
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (rawArgs[0] === 'members' && rawArgs[1] === 'update') {
|
|
119
|
+
assertFlags(rawArgs.slice(2), ['--members-json']);
|
|
120
|
+
if (rawArgs.length !== 4)
|
|
121
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', USAGE);
|
|
122
|
+
const members = parseJsonFlag(rawArgs, '--members-json');
|
|
123
|
+
const result = updateTeamMembers(context.selfAid, members);
|
|
124
|
+
output({ ok: true, aid: context.selfAid, ...result });
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', USAGE);
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
const source = error;
|
|
131
|
+
process.stderr.write(`${JSON.stringify({ ok: false, code: source.code ?? 'TEAM_WORKSPACE_FAILED', error: error instanceof Error ? error.message : String(error) })}\n`);
|
|
132
|
+
process.exitCode = 1;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -15,7 +15,7 @@ const HELP_TEXT = `
|
|
|
15
15
|
list <peer> 列出与某对端的所有话题
|
|
16
16
|
show <ref> 查看单个话题的元数据
|
|
17
17
|
history <ref> 读取话题历史消息
|
|
18
|
-
create <peer> --name
|
|
18
|
+
create <peer> --name 新建话题(对端类型按关系证据自动识别,--group/--private 可覆盖)
|
|
19
19
|
rename <ref> <名称> 修改话题名称(仅本端)
|
|
20
20
|
label <ref> <标签> 设置话题标签
|
|
21
21
|
status <ref> <状态> 更新话题业务状态
|
|
@@ -382,7 +382,11 @@ export async function runThreadCommand(args) {
|
|
|
382
382
|
}
|
|
383
383
|
const label = argValue(args, '--label');
|
|
384
384
|
const topicStatus = argValue(args, '--status');
|
|
385
|
-
|
|
385
|
+
// 对端类型:显式 --group / --private 优先;都不写时 daemon 侧按关系证据
|
|
386
|
+
// 推断(这里不能自行补值——daemon 会用 argv 重建请求,两者必须一致)。
|
|
387
|
+
const peerKind = hasFlag(args, '--group')
|
|
388
|
+
? 'group'
|
|
389
|
+
: hasFlag(args, '--private') ? 'private' : undefined;
|
|
386
390
|
const resp = await sendOp({ op: 'create', selfAid, peer, name, label, topicStatus, peerKind });
|
|
387
391
|
if (!resp.ok) {
|
|
388
392
|
console.error(`✗ ${resp.error}`);
|
package/dist/cli/watch-msg.js
CHANGED
|
@@ -302,7 +302,7 @@ function renderMessagesPanel(state, width, height) {
|
|
|
302
302
|
const isGroup = m.chatType === 'group';
|
|
303
303
|
const chatTag = isGroup ? `${MAGENTA}[群聊]${RST}` : '';
|
|
304
304
|
const encLabel = m.encrypt ? '密文' : '明文';
|
|
305
|
-
const modeLabel = m.chatmode === '
|
|
305
|
+
const modeLabel = m.chatmode === 'proactive' ? '自主' : '响应';
|
|
306
306
|
const metaTags = (m.encrypt != null || m.chatmode) ? `${MAGENTA}[${encLabel}|${modeLabel}]${RST}` : '';
|
|
307
307
|
// observer 插话:醒目标记,与对端真实消息区分
|
|
308
308
|
const injectTag = m.source === 'owner-inject' ? `${YELLOW}[插话]${RST}` : '';
|
|
@@ -328,9 +328,9 @@ export function parseConfigFieldValue(fieldPath, rawValue) {
|
|
|
328
328
|
? { ok: true, value: raw }
|
|
329
329
|
: { ok: false, reason: 'Config field chatmode.group is fixed to proactive' };
|
|
330
330
|
}
|
|
331
|
-
return raw === 'interactive' || raw === 'proactive'
|
|
331
|
+
return raw === 'interactive' || raw === 'proactive'
|
|
332
332
|
? { ok: true, value: raw }
|
|
333
|
-
: { ok: false, reason: `Config field ${fieldPath} must be interactive
|
|
333
|
+
: { ok: false, reason: `Config field ${fieldPath} must be interactive or proactive` };
|
|
334
334
|
case 'mention-mode':
|
|
335
335
|
return raw === 'disabled' || raw === 'mention-only' || raw === 'auto'
|
|
336
336
|
? { ok: true, value: raw }
|
|
@@ -978,10 +978,6 @@ export function write(target, value, sel, opts = {}) {
|
|
|
978
978
|
// 1. Schema 校验
|
|
979
979
|
if (!opts.skipValidate) {
|
|
980
980
|
validateOrThrow(schema, normalized, target);
|
|
981
|
-
if (target === ConfigTarget.Relation && normalized.chatmode?.private === 'paactive'
|
|
982
|
-
&& (!sel?.peerKey?.startsWith('aun#') || normalized.targetKind !== 'private')) {
|
|
983
|
-
throw new ConfigError('SCHEMA_INVALID', 'paactive only supports AUN private relations');
|
|
984
|
-
}
|
|
985
981
|
if (target === ConfigTarget.Defaults || target === ConfigTarget.Agent || target === ConfigTarget.Relation) {
|
|
986
982
|
const previous = atomicReadJson(file) ?? {};
|
|
987
983
|
const inherited = target === ConfigTarget.Defaults ? {}
|
|
@@ -1558,9 +1554,6 @@ export function normalizeDefaultsBehaviorCompat(defaults) {
|
|
|
1558
1554
|
if (!normalized.chatmode && (chatMode === 'interactive' || chatMode === 'proactive')) {
|
|
1559
1555
|
normalized.chatmode = { private: chatMode, group: 'proactive', nothuman: chatMode };
|
|
1560
1556
|
}
|
|
1561
|
-
else if (!normalized.chatmode && chatMode === 'paactive') {
|
|
1562
|
-
normalized.chatmode = { private: 'paactive', group: 'proactive', nothuman: 'proactive' };
|
|
1563
|
-
}
|
|
1564
1557
|
if (normalized.mentionMode === undefined && (config.mentionMode === 'disabled' || config.mentionMode === 'mention-only' || config.mentionMode === 'auto')) {
|
|
1565
1558
|
normalized.mentionMode = config.mentionMode;
|
|
1566
1559
|
}
|