evolcore 0.0.43-test.5 → 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 +95 -0
- package/bin/ecmsg.js +281 -81
- package/dist/agents/baseagent-availability.js +20 -5
- package/dist/agents/baseagent.js +2 -2
- package/dist/agents/claude-runner.js +19 -4
- package/dist/agents/codex/app-server-client.js +36 -3
- package/dist/agents/codex-runner.js +75 -8
- package/dist/aun/group/invite-service.js +3 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/aun/service-proxy.js +18 -6
- package/dist/channels/aun.js +306 -30
- package/dist/cli/agent-create.js +18 -8
- package/dist/cli/aun-commands.js +9 -1
- package/dist/cli/daemon-commands.js +34 -65
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +38 -3
- package/dist/cli/events-command.js +73 -0
- package/dist/cli/index.js +31 -14
- package/dist/cli/init.js +75 -0
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/provider-command.js +1 -1
- package/dist/cli/restart-monitor.js +67 -50
- package/dist/cli/services-command.js +111 -0
- package/dist/cli/task-context.js +38 -1
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +6 -2
- package/dist/cli/watch-logs.js +6 -4
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/boot-log.js +6 -4
- package/dist/config/builtin-roles.js +2 -2
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +1 -8
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/peer-role-resolver.js +1 -1
- package/dist/config/provider-identity-migration.js +92 -17
- package/dist/config/provider-local-sync.js +2 -0
- package/dist/config/providers-config.js +13 -0
- package/dist/config/providers-management.js +100 -10
- package/dist/config/role-service.js +8 -8
- package/dist/config/role-store.js +22 -22
- package/dist/config/schema-migration.js +86 -88
- package/dist/config/snapshot.js +70 -41
- package/dist/config-store.js +2 -1
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +146 -15
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-catalog.js +20 -0
- package/dist/core/baseagent-loader.js +75 -42
- package/dist/core/channel-loader.js +45 -13
- package/dist/core/channel-runtime.js +116 -45
- 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 +58 -16
- 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 +206 -87
- package/dist/core/command/menu-protocol.js +142 -22
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/role-menu.js +27 -15
- 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 +45 -15
- package/dist/core/daemon-lifecycle.js +478 -75
- package/dist/core/handoff/dispatcher.js +9 -3
- package/dist/core/handoff/runtime.js +130 -42
- package/dist/core/handoff/store.js +190 -2
- package/dist/core/handoff/types.js +5 -0
- package/dist/core/initialization/service.js +4 -4
- 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 +51 -11
- package/dist/core/lifecycle-notice.js +10 -4
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +149 -19
- package/dist/core/message/im-renderer.js +28 -84
- package/dist/core/message/message-bridge.js +57 -4
- package/dist/core/message/message-queue.js +46 -4
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/pending-hints.js +4 -10
- package/dist/core/message/response-engine.js +163 -52
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +55 -7
- package/dist/core/ownership/owner-resolver.js +8 -0
- package/dist/core/permission/ec-command-parser.js +14 -3
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +24 -0
- package/dist/core/session/adapters/codex-session-file-adapter.js +80 -0
- package/dist/core/session/adapters/ecagent-session-file-adapter.js +22 -0
- package/dist/core/session/adapters/gemini-session-file-adapter.js +39 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +163 -3
- package/dist/core/session/session-idle-monitor.js +9 -1
- package/dist/core/session/session-manager.js +36 -2
- 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 +42 -30
- package/dist/directory/owner-directory-cache.js +143 -126
- package/dist/directory/owner-directory-query-operation.js +9 -8
- 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 +14 -8
- package/dist/ecweb/runtime/supervisor.js +62 -30
- 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 +751 -268
- package/dist/ipc.js +66 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +43 -18
- package/dist/proxy/service-supervisor.js +78 -35
- 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 +21 -1
- package/dist/trigger/audit.js +19 -4
- package/dist/trigger/authorization.js +14 -5
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/history.js +176 -7
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/manager.js +1 -3
- package/dist/trigger/scheduler.js +78 -5
- package/dist/trigger/script-sandbox.js +118 -22
- package/dist/utils/cross-platform.js +175 -13
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/host-info.js +11 -8
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/npm-ops.js +48 -0
- package/dist/utils/process-introspect.js +109 -10
- package/dist/utils/startup-trace.js +222 -44
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +10 -17
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +5 -2
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/ctl.md +2 -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 +2 -2
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +21 -0
- package/kits/docs/evolcore/msg.md +27 -8
- package/kits/docs/evolcore/provider.md +23 -3
- 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 +45 -7
- package/kits/eck_message_manifest.json +3 -3
- package/kits/rules/02-navigation.md +10 -1
- package/kits/rules/06-channel.md +5 -6
- 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/daemon.schema.1.json +5 -0
- package/kits/schemas/daemon.schema.2.json +5 -0
- package/kits/schemas/daemon.schema.3.json +2 -1
- package/kits/schemas/daemon.schema.4.json +2 -1
- package/kits/schemas/daemon.schema.5.json +2 -1
- package/kits/schemas/daemon.schema.6.json +1 -1
- package/kits/schemas/daemon.schema.7.json +1 -1
- package/kits/schemas/daemon.schema.8.json +2 -1
- package/kits/schemas/daemon.schema.9.json +2 -1
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/schemas/role-registry.schema.1.json +2 -2
- package/kits/schemas/single-session.schema.1.json +1 -1
- package/kits/schemas/single-session.schema.2.json +1 -1
- package/kits/schemas/single-session.schema.3.json +1 -1
- 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-group/SKILL.md +8 -5
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-service-proxy/SKILL.md +34 -5
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- 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/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +9 -7
- package/kits/templates/system-fragments/reply.md +2 -6
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +11 -9
- package/package.json +5 -6
- 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
|
@@ -5,9 +5,11 @@ import { execFileSync, execFile, spawn, spawnSync } from 'child_process';
|
|
|
5
5
|
import { promisify, TextDecoder } from 'util';
|
|
6
6
|
import fs from 'fs';
|
|
7
7
|
import { getProcessStartTime, parseCimDate } from './process-introspect.js';
|
|
8
|
-
import { resolveTrustedWindowsCmdPath } from './windows-shell-trust.js';
|
|
8
|
+
import { resolveTrustedWindowsCmdPath, resolveTrustedWindowsCmdPathAsync } from './windows-shell-trust.js';
|
|
9
9
|
const execFileAsync = promisify(execFile);
|
|
10
10
|
const CLI_PROBE_FAILURE_BACKOFF_MS = 5_000;
|
|
11
|
+
export const CODEX_CLI_PROBE_TIMEOUT_MS = 9_000;
|
|
12
|
+
export const CODEX_CLI_PROBE_RETRY_TIMEOUT_MS = 15_000;
|
|
11
13
|
const CLI_PROBE_PACKAGES = {
|
|
12
14
|
codex: '@openai/codex',
|
|
13
15
|
claude: '@anthropic-ai/claude-code',
|
|
@@ -184,20 +186,61 @@ export function invalidateCliProbes() {
|
|
|
184
186
|
cliProbeCache.clear();
|
|
185
187
|
}
|
|
186
188
|
function cliProbeTimeouts(command, options) {
|
|
187
|
-
return options.timeouts?.length ? options.timeouts : command === 'codex'
|
|
189
|
+
return options.timeouts?.length ? options.timeouts : command === 'codex'
|
|
190
|
+
? [CODEX_CLI_PROBE_TIMEOUT_MS, CODEX_CLI_PROBE_RETRY_TIMEOUT_MS] : [3_000];
|
|
188
191
|
}
|
|
189
|
-
|
|
192
|
+
/** The stock npm shim adds cmd + node before Codex, outside a reliable Windows timeout. */
|
|
193
|
+
function codexProbeExecutable(executable) {
|
|
194
|
+
if (!isWindows || !/\.(?:cmd|bat)$/i.test(executable))
|
|
195
|
+
return executable;
|
|
196
|
+
try {
|
|
197
|
+
const shim = fs.readFileSync(executable, 'utf8');
|
|
198
|
+
// Preserve custom launchers. Only the stock npm entry for this installation
|
|
199
|
+
// may be shortened for read-only --version/app-server --help probes.
|
|
200
|
+
if (!/^@ECHO off\r?\nGOTO start\r?\n/i.test(shim)
|
|
201
|
+
|| !shim.includes('%dp0%\\node_modules\\@openai\\codex\\bin\\codex.js'))
|
|
202
|
+
return executable;
|
|
203
|
+
const packageFile = path.join(path.dirname(executable), 'node_modules', '@openai', 'codex', 'package.json');
|
|
204
|
+
const manifest = JSON.parse(fs.readFileSync(packageFile, 'utf8'));
|
|
205
|
+
if (manifest.name !== '@openai/codex' || manifest.bin?.codex !== 'bin/codex.js')
|
|
206
|
+
return executable;
|
|
207
|
+
const arch = process.arch === 'x64' ? 'x86_64' : process.arch === 'arm64' ? 'aarch64' : null;
|
|
208
|
+
if (!arch)
|
|
209
|
+
return executable;
|
|
210
|
+
let vendorRoot;
|
|
211
|
+
try {
|
|
212
|
+
const platformFile = createRequire(packageFile).resolve(`@openai/codex-win32-${process.arch}/package.json`);
|
|
213
|
+
vendorRoot = path.join(path.dirname(platformFile), 'vendor');
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
vendorRoot = path.join(path.dirname(packageFile), 'vendor');
|
|
217
|
+
}
|
|
218
|
+
const binary = path.join(vendorRoot, `${arch}-pc-windows-msvc`, 'bin', 'codex.exe');
|
|
219
|
+
if (fs.statSync(binary).isFile())
|
|
220
|
+
return binary;
|
|
221
|
+
}
|
|
222
|
+
catch { /* Incomplete or non-npm installations retain their configured entrypoint. */ }
|
|
223
|
+
return executable;
|
|
224
|
+
}
|
|
225
|
+
function resolveCliProbe(command, args, options) {
|
|
190
226
|
const executable = options.executable ?? resolveProbePath(command);
|
|
191
227
|
if (!executable)
|
|
192
228
|
throw Object.assign(new Error(`${command} CLI not found`), { code: 'ENOENT' });
|
|
193
|
-
const
|
|
229
|
+
const probeExecutable = command === 'codex'
|
|
230
|
+
&& (args.length === 1 && args[0] === '--version'
|
|
231
|
+
|| args.length === 2 && args[0] === 'app-server' && args[1] === '--help')
|
|
232
|
+
? codexProbeExecutable(executable) : executable;
|
|
233
|
+
return { executable, probeExecutable };
|
|
234
|
+
}
|
|
235
|
+
function prepareCliProbe(command, args, options = {}, resolved = resolveCliProbe(command, args, options), resolveWindowsCmd) {
|
|
236
|
+
const launchCommand = buildCliLaunchCommand(resolved.probeExecutable, args, { resolveWindowsCmd });
|
|
194
237
|
const launch = launchCommand;
|
|
195
|
-
const identity = `${probeInstallationIdentity(command, executable)}|${cliFileIdentity(launch.launcherPath)}`;
|
|
238
|
+
const identity = `${probeInstallationIdentity(command, resolved.executable)}|${cliFileIdentity(launch.launcherPath)}`;
|
|
196
239
|
const key = JSON.stringify([command, args]);
|
|
197
240
|
let entry = cliProbeCache.get(key);
|
|
198
241
|
if (!entry || entry.identity !== identity || (entry.retryAt !== undefined && Date.now() >= entry.retryAt)
|
|
199
242
|
|| (entry.output !== undefined && options.validateOutput && !options.validateOutput(entry.output))) {
|
|
200
|
-
entry = { identity };
|
|
243
|
+
entry = { identity, launcherPath: launch.launcherPath };
|
|
201
244
|
cliProbeCache.set(key, entry);
|
|
202
245
|
}
|
|
203
246
|
return {
|
|
@@ -250,7 +293,13 @@ export function probeCliSync(command, args, options = {}) {
|
|
|
250
293
|
throw new Error('CLI probe exhausted');
|
|
251
294
|
}
|
|
252
295
|
export async function probeCli(command, args, options = {}) {
|
|
253
|
-
const
|
|
296
|
+
const resolved = resolveCliProbe(command, args, options);
|
|
297
|
+
let resolveWindowsCmd;
|
|
298
|
+
if (isWindows && /\.(?:cmd|bat)$/i.test(resolved.probeExecutable)) {
|
|
299
|
+
const trustedCmd = await resolveTrustedWindowsCmdPathAsync();
|
|
300
|
+
resolveWindowsCmd = () => trustedCmd;
|
|
301
|
+
}
|
|
302
|
+
const request = prepareCliProbe(command, args, options, resolved, resolveWindowsCmd);
|
|
254
303
|
if (request.entry.output !== undefined)
|
|
255
304
|
return request.entry.output;
|
|
256
305
|
if (request.entry.error !== undefined)
|
|
@@ -312,9 +361,14 @@ export async function probeCli(command, args, options = {}) {
|
|
|
312
361
|
/** Non-blocking version lookup used by status menus. */
|
|
313
362
|
export function cachedCliVersion(command) {
|
|
314
363
|
try {
|
|
315
|
-
const
|
|
316
|
-
if (
|
|
364
|
+
const executable = resolveProbePath(command);
|
|
365
|
+
if (!executable)
|
|
366
|
+
return null;
|
|
367
|
+
const entry = cliProbeCache.get(JSON.stringify([command, ['--version']]));
|
|
368
|
+
if (entry?.output !== undefined
|
|
369
|
+
&& entry.identity === `${probeInstallationIdentity(command, executable)}|${cliFileIdentity(entry.launcherPath)}`) {
|
|
317
370
|
return entry.output.match(/\b\d+\.\d+\.\d+(?:[-+][\w.-]+)?/)?.[0] ?? null;
|
|
371
|
+
}
|
|
318
372
|
void probeCli(command, ['--version']).catch(() => { });
|
|
319
373
|
}
|
|
320
374
|
catch { /* Missing CLI. */ }
|
|
@@ -731,6 +785,42 @@ export function isProcessRunning(pid) {
|
|
|
731
785
|
return e.code === 'EPERM';
|
|
732
786
|
}
|
|
733
787
|
}
|
|
788
|
+
const processLivenessQueries = new Map();
|
|
789
|
+
/** Share concurrent Windows probes, but never cache liveness across checks. */
|
|
790
|
+
export async function isProcessRunningAsync(pid) {
|
|
791
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
792
|
+
return false;
|
|
793
|
+
if (!isWindows)
|
|
794
|
+
return isProcessRunning(pid);
|
|
795
|
+
const pending = processLivenessQueries.get(pid);
|
|
796
|
+
if (pending)
|
|
797
|
+
return pending;
|
|
798
|
+
const query = (async () => {
|
|
799
|
+
try {
|
|
800
|
+
const { stdout } = await execFileAsync('tasklist', ['/FI', `PID eq ${pid}`, '/FO', 'CSV', '/NH'], {
|
|
801
|
+
encoding: 'utf8', timeout: 3000, windowsHide: true,
|
|
802
|
+
});
|
|
803
|
+
if (new RegExp(`,"${pid}",`, 'i').test(stdout))
|
|
804
|
+
return true;
|
|
805
|
+
}
|
|
806
|
+
catch { /* Retain the conservative native fallback on query failure. */ }
|
|
807
|
+
try {
|
|
808
|
+
process.kill(pid, 0);
|
|
809
|
+
return true;
|
|
810
|
+
}
|
|
811
|
+
catch (error) {
|
|
812
|
+
return error.code === 'EPERM';
|
|
813
|
+
}
|
|
814
|
+
})();
|
|
815
|
+
processLivenessQueries.set(pid, query);
|
|
816
|
+
try {
|
|
817
|
+
return await query;
|
|
818
|
+
}
|
|
819
|
+
finally {
|
|
820
|
+
if (processLivenessQueries.get(pid) === query)
|
|
821
|
+
processLivenessQueries.delete(pid);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
734
824
|
function isWindowsProcessRunning(pid) {
|
|
735
825
|
try {
|
|
736
826
|
const result = spawnSync('tasklist', ['/FI', `PID eq ${pid}`, '/FO', 'CSV', '/NH'], { encoding: 'utf-8', timeout: 3000, stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true });
|
|
@@ -833,11 +923,11 @@ export function killProcessTree(pid, force = false) {
|
|
|
833
923
|
export async function waitForProcessExit(pid, timeoutMs = 10_000, intervalMs = 250) {
|
|
834
924
|
const deadline = Date.now() + timeoutMs;
|
|
835
925
|
while (Date.now() < deadline) {
|
|
836
|
-
if (!
|
|
926
|
+
if (!await isProcessRunningAsync(pid))
|
|
837
927
|
return true;
|
|
838
928
|
await new Promise(resolve => setTimeout(resolve, intervalMs));
|
|
839
929
|
}
|
|
840
|
-
return !
|
|
930
|
+
return !await isProcessRunningAsync(pid);
|
|
841
931
|
}
|
|
842
932
|
/**
|
|
843
933
|
* Cross-platform process search by command line pattern.
|
|
@@ -909,7 +999,7 @@ export function findProcessByPort(port) {
|
|
|
909
999
|
const pids = new Set();
|
|
910
1000
|
try {
|
|
911
1001
|
if (isWindows) {
|
|
912
|
-
const result = spawnSync('netstat', ['-ano', '-p', 'TCP'], { encoding: 'utf-8', windowsHide: true });
|
|
1002
|
+
const result = spawnSync('netstat', ['-ano', '-p', 'TCP'], { encoding: 'utf-8', windowsHide: true, timeout: 3000 });
|
|
913
1003
|
const output = result.stdout || '';
|
|
914
1004
|
for (const line of output.split('\n')) {
|
|
915
1005
|
// 形如: TCP 0.0.0.0:42705 0.0.0.0:0 LISTENING 23004
|
|
@@ -924,7 +1014,7 @@ export function findProcessByPort(port) {
|
|
|
924
1014
|
}
|
|
925
1015
|
}
|
|
926
1016
|
else {
|
|
927
|
-
const output = execFileSync('lsof', ['-ti', `tcp:${port}`, '-sTCP:LISTEN'], { encoding: 'utf-8' }).trim();
|
|
1017
|
+
const output = execFileSync('lsof', ['-ti', `tcp:${port}`, '-sTCP:LISTEN'], { encoding: 'utf-8', timeout: 3000 }).trim();
|
|
928
1018
|
for (const line of output.split('\n')) {
|
|
929
1019
|
const pid = parseInt(line.trim(), 10);
|
|
930
1020
|
if (pid && pid !== process.pid)
|
|
@@ -935,6 +1025,55 @@ export function findProcessByPort(port) {
|
|
|
935
1025
|
catch { /* netstat/lsof missing or no match */ }
|
|
936
1026
|
return [...pids];
|
|
937
1027
|
}
|
|
1028
|
+
let tcpListenersQuery;
|
|
1029
|
+
/**
|
|
1030
|
+
* Share concurrent Windows port scans, without retaining stale ownership data.
|
|
1031
|
+
* Missing optional lsof yields no known PIDs; callers must still bind/probe the service.
|
|
1032
|
+
*/
|
|
1033
|
+
export async function findProcessByPortAsync(port) {
|
|
1034
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535)
|
|
1035
|
+
throw new Error('Invalid TCP port');
|
|
1036
|
+
let output;
|
|
1037
|
+
if (isWindows) {
|
|
1038
|
+
const query = tcpListenersQuery ??= execFileAsync('netstat', ['-ano', '-p', 'TCP'], {
|
|
1039
|
+
encoding: 'utf8', windowsHide: true, timeout: 3000, maxBuffer: 4 * 1024 * 1024,
|
|
1040
|
+
}).then(result => result.stdout);
|
|
1041
|
+
try {
|
|
1042
|
+
output = (await query) ?? '';
|
|
1043
|
+
}
|
|
1044
|
+
finally {
|
|
1045
|
+
if (tcpListenersQuery === query)
|
|
1046
|
+
tcpListenersQuery = undefined;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
else {
|
|
1050
|
+
try {
|
|
1051
|
+
output = ((await execFileAsync('lsof', ['-ti', `tcp:${port}`, '-sTCP:LISTEN'], {
|
|
1052
|
+
encoding: 'utf8', timeout: 3000,
|
|
1053
|
+
})).stdout ?? '');
|
|
1054
|
+
}
|
|
1055
|
+
catch (error) {
|
|
1056
|
+
const detail = error;
|
|
1057
|
+
// lsof is optional on Unix, as in the synchronous port lookup.
|
|
1058
|
+
if (detail.code === 'ENOENT')
|
|
1059
|
+
return [];
|
|
1060
|
+
// lsof uses exit 1, with no output, to report an empty selection.
|
|
1061
|
+
if (detail.code === 1 && !detail.stdout?.trim() && !detail.stderr?.trim())
|
|
1062
|
+
return [];
|
|
1063
|
+
throw error;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
const pids = new Set();
|
|
1067
|
+
for (const line of output.split('\n')) {
|
|
1068
|
+
const match = isWindows ? line.match(/:(\d+)\s+\S+\s+LISTENING\s+(\d+)/i) : null;
|
|
1069
|
+
if (isWindows && (!match || Number(match[1]) !== port))
|
|
1070
|
+
continue;
|
|
1071
|
+
const pid = Number(isWindows ? match[2] : line.trim());
|
|
1072
|
+
if (Number.isInteger(pid) && pid > 0 && pid !== process.pid)
|
|
1073
|
+
pids.add(pid);
|
|
1074
|
+
}
|
|
1075
|
+
return [...pids];
|
|
1076
|
+
}
|
|
938
1077
|
export function getProcessInfo(pid) {
|
|
939
1078
|
try {
|
|
940
1079
|
if (isWindows) {
|
|
@@ -1014,6 +1153,29 @@ function parseDateString(value) {
|
|
|
1014
1153
|
* Cross-platform command existence check.
|
|
1015
1154
|
*/
|
|
1016
1155
|
const _commandExistsCache = new Map();
|
|
1156
|
+
const commandExistsPending = new Map();
|
|
1157
|
+
/** Daemon inventory probes must not block IPC on where/which. */
|
|
1158
|
+
export async function commandExistsAsync(cmd) {
|
|
1159
|
+
const cached = _commandExistsCache.get(cmd);
|
|
1160
|
+
if (cached !== undefined)
|
|
1161
|
+
return cached;
|
|
1162
|
+
const existing = commandExistsPending.get(cmd);
|
|
1163
|
+
if (existing)
|
|
1164
|
+
return existing;
|
|
1165
|
+
const pending = execFileAsync(isWindows ? 'where.exe' : 'which', [cmd], {
|
|
1166
|
+
encoding: 'utf8', windowsHide: true, timeout: 3_000,
|
|
1167
|
+
}).then(() => true, () => false);
|
|
1168
|
+
commandExistsPending.set(cmd, pending);
|
|
1169
|
+
try {
|
|
1170
|
+
const exists = await pending;
|
|
1171
|
+
_commandExistsCache.set(cmd, exists);
|
|
1172
|
+
return exists;
|
|
1173
|
+
}
|
|
1174
|
+
finally {
|
|
1175
|
+
if (commandExistsPending.get(cmd) === pending)
|
|
1176
|
+
commandExistsPending.delete(cmd);
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1017
1179
|
export function commandExists(cmd) {
|
|
1018
1180
|
const cached = _commandExistsCache.get(cmd);
|
|
1019
1181
|
if (cached !== undefined)
|
|
@@ -189,39 +189,81 @@ export function readBuildIdentity(distDir, version) {
|
|
|
189
189
|
...(version ? { version } : {}),
|
|
190
190
|
};
|
|
191
191
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const runtimeEntry = fileURLToPath(entryUrl);
|
|
195
|
-
const diskDistDir = path.join(packageRoot, 'dist');
|
|
196
|
-
const runtimeIsDist = path.resolve(path.dirname(runtimeEntry)) === path.resolve(diskDistDir);
|
|
197
|
-
const runtimeBuildIdentity = readBuildIdentity(runtimeIsDist ? path.dirname(runtimeEntry) : diskDistDir, readInstalledEvolcoreVersion());
|
|
198
|
-
const diskDistId = runtimeBuildIdentity.id;
|
|
199
|
-
if (!runtimeIsDist)
|
|
200
|
-
runtimeBuildIdentity.id = null;
|
|
201
|
-
const isLinked = fs.existsSync(path.join(packageRoot, '.git'));
|
|
202
|
-
const directoryType = runtimeIsDist ? (isLinked ? '开发仓/dist' : '安装路径/dist') : '源码(tsx)';
|
|
203
|
-
const scanDir = runtimeIsDist ? path.join(packageRoot, 'dist') : path.join(packageRoot, 'src');
|
|
192
|
+
/** Keep the same content hash as computeBuildId without blocking the event loop. */
|
|
193
|
+
async function readBuildTreeAsync(root, hashFiles = true) {
|
|
204
194
|
let latestMtime = 0;
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
195
|
+
try {
|
|
196
|
+
const files = [];
|
|
197
|
+
const collect = async (directory) => {
|
|
198
|
+
const entries = await fs.promises.readdir(directory, { withFileTypes: true });
|
|
199
|
+
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
200
|
+
if (!hashFiles && entry.name === 'node_modules')
|
|
209
201
|
continue;
|
|
210
202
|
const full = path.join(directory, entry.name);
|
|
211
|
-
if (entry.isDirectory())
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
203
|
+
if (entry.isDirectory())
|
|
204
|
+
await collect(full);
|
|
205
|
+
else if (entry.isFile())
|
|
206
|
+
files.push(full);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
await collect(root);
|
|
210
|
+
const hash = crypto.createHash('sha256');
|
|
211
|
+
for (let offset = 0; offset < files.length; offset += 8) {
|
|
212
|
+
const batch = await Promise.all(files.slice(offset, offset + 8).map(async (file) => {
|
|
213
|
+
const [content, stat] = await Promise.all([
|
|
214
|
+
hashFiles ? fs.promises.readFile(file) : undefined,
|
|
215
|
+
/\.(js|ts)$/.test(file) ? fs.promises.stat(file) : undefined,
|
|
216
|
+
]);
|
|
217
|
+
return { file, content, stat };
|
|
218
|
+
}));
|
|
219
|
+
for (const { file, content, stat } of batch) {
|
|
220
|
+
if (stat)
|
|
221
|
+
latestMtime = Math.max(latestMtime, stat.mtimeMs);
|
|
222
|
+
if (content) {
|
|
223
|
+
hash.update(path.relative(root, file).replaceAll(path.sep, '/'));
|
|
224
|
+
hash.update('\0');
|
|
225
|
+
hash.update(content);
|
|
226
|
+
hash.update('\0');
|
|
219
227
|
}
|
|
220
228
|
}
|
|
221
229
|
}
|
|
222
|
-
|
|
230
|
+
return { id: hashFiles ? `sha256:${hash.digest('hex').slice(0, 24)}` : null, latestMtime };
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
return { id: null, latestMtime };
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/** Cheap initial status; the full build identity is published after hashing. */
|
|
237
|
+
export function createEvolcoreStartupDiagnostics(entryUrl) {
|
|
238
|
+
const packageRoot = getPackageRoot();
|
|
239
|
+
const runtimeEntry = fileURLToPath(entryUrl);
|
|
240
|
+
const diskDistDir = path.join(packageRoot, 'dist');
|
|
241
|
+
const runtimeIsDist = path.resolve(path.dirname(runtimeEntry)) === path.resolve(diskDistDir);
|
|
242
|
+
return {
|
|
243
|
+
state: 'pending', runtimeIsDist, diskDistDir, diskDistId: null,
|
|
244
|
+
runtimeBuildIdentity: { id: null, entry: path.join(diskDistDir, 'index.js'), version: readInstalledEvolcoreVersion() },
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
export async function reportEvolcoreStartup(entryUrl, report, diagnostics = createEvolcoreStartupDiagnostics(entryUrl)) {
|
|
248
|
+
const packageRoot = getPackageRoot();
|
|
249
|
+
const { runtimeIsDist, diskDistDir } = diagnostics;
|
|
250
|
+
const [dist, source] = await Promise.all([
|
|
251
|
+
readBuildTreeAsync(diskDistDir),
|
|
252
|
+
runtimeIsDist ? undefined : readBuildTreeAsync(path.join(packageRoot, 'src'), false),
|
|
253
|
+
]);
|
|
254
|
+
const diskDistId = dist.id;
|
|
255
|
+
const runtimeBuildIdentity = {
|
|
256
|
+
id: runtimeIsDist ? diskDistId : null,
|
|
257
|
+
entry: path.join(diskDistDir, 'index.js'),
|
|
258
|
+
version: readInstalledEvolcoreVersion(),
|
|
223
259
|
};
|
|
224
|
-
|
|
260
|
+
// Publish both IDs together. Pending/failed reads must never claim a match.
|
|
261
|
+
Object.assign(diagnostics, {
|
|
262
|
+
state: diskDistId === null ? 'unavailable' : 'ready', runtimeBuildIdentity, diskDistId,
|
|
263
|
+
});
|
|
264
|
+
const isLinked = fs.existsSync(path.join(packageRoot, '.git'));
|
|
265
|
+
const directoryType = runtimeIsDist ? (isLinked ? '开发仓/dist' : '安装路径/dist') : '源码(tsx)';
|
|
266
|
+
const latestMtime = source?.latestMtime ?? dist.latestMtime;
|
|
225
267
|
let version = '?';
|
|
226
268
|
try {
|
|
227
269
|
version = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf-8')).version;
|
|
@@ -240,5 +282,5 @@ export function reportEvolcoreStartup(entryUrl, report) {
|
|
|
240
282
|
console.error(`[EvolCore] 运行 build ID: ${runtimeIsDist ? (runtimeBuildIdentity.id ?? '?') : 'source'}`);
|
|
241
283
|
console.error(`[EvolCore] 磁盘 dist build ID: ${diskBuildId ?? '?'}`);
|
|
242
284
|
report(`[Build] runtimeMode=${runtimeIsDist ? 'dist' : 'source'} runtimeBuildId=${runtimeBuildIdentity.id ?? 'source'} diskDistBuildId=${diskBuildId ?? 'unknown'} match=${runtimeIsDist && runtimeBuildIdentity.id !== null && runtimeBuildIdentity.id === diskBuildId}`);
|
|
243
|
-
return
|
|
285
|
+
return diagnostics;
|
|
244
286
|
}
|
package/dist/utils/host-info.js
CHANGED
|
@@ -17,7 +17,7 @@ import { execFile } from 'node:child_process';
|
|
|
17
17
|
import { readSystemMemoryUsage } from './system-memory.js';
|
|
18
18
|
import { getPackageRoot } from '../paths.js';
|
|
19
19
|
import { WEB_PACKAGE_NAME } from '../product.js';
|
|
20
|
-
import {
|
|
20
|
+
import { probeCli, resolveProbePath } from './cross-platform.js';
|
|
21
21
|
function readJsonVersion(filePath) {
|
|
22
22
|
try {
|
|
23
23
|
const pkg = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
@@ -195,8 +195,8 @@ function runExec(command, args, timeoutMs, windowsVerbatimArguments = false) {
|
|
|
195
195
|
* 按 PATH 探测一个 CLI 的版本。
|
|
196
196
|
*
|
|
197
197
|
* 不能直接 execFile('claude'):Windows 上 npm 装的是 claude.cmd,Node 25 对 .cmd
|
|
198
|
-
* 直接 spawn 会报 EINVAL
|
|
199
|
-
*
|
|
198
|
+
* 直接 spawn 会报 EINVAL。复用 baseagent 的探测缓存和在途请求,保留原生
|
|
199
|
+
* Codex 入口探测及 .cmd 经受信任 cmd.exe 转发的规则。
|
|
200
200
|
*/
|
|
201
201
|
async function probeCliVersion(command, args, timeoutMs) {
|
|
202
202
|
try {
|
|
@@ -207,9 +207,10 @@ async function probeCliVersion(command, args, timeoutMs) {
|
|
|
207
207
|
const raw = await runExec(command, args, timeoutMs);
|
|
208
208
|
return raw.ok ? firstVersionLine(raw.stdout) : null;
|
|
209
209
|
}
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
210
|
+
const output = await probeCli(command, args, {
|
|
211
|
+
executable, timeouts: [timeoutMs], validateOutput: value => firstVersionLine(value) !== null,
|
|
212
|
+
});
|
|
213
|
+
return firstVersionLine(output);
|
|
213
214
|
}
|
|
214
215
|
catch {
|
|
215
216
|
return null;
|
|
@@ -299,8 +300,10 @@ async function probeBundledClaudeVersion() {
|
|
|
299
300
|
const executable = resolveBundledClaudeExecutable();
|
|
300
301
|
if (!executable)
|
|
301
302
|
return null;
|
|
302
|
-
const
|
|
303
|
-
|
|
303
|
+
const output = await probeCli('bundled-claude', ['--version'], {
|
|
304
|
+
executable, timeouts: [8000], validateOutput: value => firstVersionLine(value) !== null,
|
|
305
|
+
});
|
|
306
|
+
return firstVersionLine(output);
|
|
304
307
|
}
|
|
305
308
|
catch {
|
|
306
309
|
return null;
|
|
@@ -33,14 +33,14 @@ function safeParseJson(filePath) {
|
|
|
33
33
|
return null;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
function lazySnapshot() {
|
|
37
|
-
let cached = null;
|
|
36
|
+
function lazySnapshot(initial) {
|
|
37
|
+
let cached = initial ?? null;
|
|
38
38
|
return {
|
|
39
39
|
get() {
|
|
40
40
|
cached ??= getProcessSnapshot();
|
|
41
41
|
return cached;
|
|
42
42
|
},
|
|
43
|
-
|
|
43
|
+
provided: () => initial !== undefined,
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
@@ -56,6 +56,12 @@ function isAlive(pid, recordedStartedAt, snapshot) {
|
|
|
56
56
|
const actual = getProcessStartTime(pid);
|
|
57
57
|
return actual === null ? true : startTimeMatches(recordedStartedAt, actual);
|
|
58
58
|
}
|
|
59
|
+
// A caller-scoped snapshot already covers this phase; avoid one tasklist per record.
|
|
60
|
+
if (snapshot.provided()) {
|
|
61
|
+
const verdict = snapshotProcessState(snapshot.get(), pid, recordedStartedAt);
|
|
62
|
+
if (verdict !== 'unknown')
|
|
63
|
+
return verdict === 'alive';
|
|
64
|
+
}
|
|
59
65
|
// 廉价前置探测:不存在就直接判定为死,省掉整张进程表。
|
|
60
66
|
if (!isProcessRunning(pid))
|
|
61
67
|
return false;
|
|
@@ -115,7 +121,7 @@ export function removeMain(pid) {
|
|
|
115
121
|
* @returns 当前进程是否赢家。false 表示应该让出(删自己的 record + exit)。
|
|
116
122
|
*/
|
|
117
123
|
export function isMainWinner() {
|
|
118
|
-
const status = scanInstances();
|
|
124
|
+
const status = scanInstances({ kind: 'main', includeAidActivity: false });
|
|
119
125
|
const aliveMains = status.mains.filter(m => m.alive);
|
|
120
126
|
if (aliveMains.length <= 1)
|
|
121
127
|
return { winner: true };
|
|
@@ -173,7 +179,7 @@ export function removeRestartMonitor(pid) {
|
|
|
173
179
|
* Post-write 自检:与 isMainWinner 同语义,用于 restart-monitor。
|
|
174
180
|
*/
|
|
175
181
|
export function isRestartMonitorWinner() {
|
|
176
|
-
const status = scanInstances();
|
|
182
|
+
const status = scanInstances({ kind: 'restart-monitor', includeAidActivity: false });
|
|
177
183
|
const alive = status.restartMonitors.filter(m => m.alive);
|
|
178
184
|
if (alive.length <= 1)
|
|
179
185
|
return { winner: true };
|
|
@@ -243,10 +249,10 @@ export function readAidLastActivity(pid) {
|
|
|
243
249
|
*
|
|
244
250
|
* 损坏的 JSON 文件直接删除。aid-*.jsonl 在 scan 时不解析,由调用方按需读取。
|
|
245
251
|
*/
|
|
246
|
-
export function scanInstances() {
|
|
252
|
+
export function scanInstances(options = {}) {
|
|
247
253
|
// 惰性快照:每条记录先做廉价的单 pid 存活探测,只有确实活着才需要整张进程表。
|
|
248
254
|
// 启动路径上绝大多数时候目录里只有本进程的记录或已死记录,这样可省掉约 0.45s。
|
|
249
|
-
const snapshot = lazySnapshot();
|
|
255
|
+
const snapshot = lazySnapshot(options.processSnapshot);
|
|
250
256
|
const status = {
|
|
251
257
|
mains: [],
|
|
252
258
|
restartMonitors: [],
|
|
@@ -264,12 +270,12 @@ export function scanInstances() {
|
|
|
264
270
|
}
|
|
265
271
|
for (const file of files) {
|
|
266
272
|
const filePath = path.join(dir, file);
|
|
267
|
-
if (file.startsWith('main-') && file.endsWith('.json')) {
|
|
273
|
+
if (file.startsWith('main-') && file.endsWith('.json') && options.kind !== 'restart-monitor') {
|
|
268
274
|
const record = safeParseJson(filePath);
|
|
269
275
|
if (record && record.pid && record.startedAt) {
|
|
270
276
|
const alive = isAlive(record.pid, record.startedAt, snapshot);
|
|
271
277
|
status.mains.push({ record, alive });
|
|
272
|
-
if (alive) {
|
|
278
|
+
if (alive && options.includeAidActivity !== false) {
|
|
273
279
|
// 合并所有活 main 的 AID 活动记录(按 ts 取最新)
|
|
274
280
|
for (const [aid, info] of readAidLastActivity(record.pid)) {
|
|
275
281
|
const prev = status.aidLastActivity.get(aid);
|
|
@@ -286,7 +292,7 @@ export function scanInstances() {
|
|
|
286
292
|
catch { }
|
|
287
293
|
}
|
|
288
294
|
}
|
|
289
|
-
else if (file.startsWith('restart-monitor-') && file.endsWith('.json')) {
|
|
295
|
+
else if (file.startsWith('restart-monitor-') && file.endsWith('.json') && options.kind !== 'main') {
|
|
290
296
|
const record = safeParseJson(filePath);
|
|
291
297
|
if (record && record.pid && record.startedAt) {
|
|
292
298
|
const alive = isAlive(record.pid, record.startedAt, snapshot);
|
|
@@ -428,7 +434,7 @@ export function isEvolCoreMainCommand(cmdline, packageRoot = getPackageRoot()) {
|
|
|
428
434
|
*
|
|
429
435
|
* 不会主动 kill——清理由调用方决定。
|
|
430
436
|
*/
|
|
431
|
-
export function findOrphanProcesses(status = scanInstances()) {
|
|
437
|
+
export function findOrphanProcesses(status = scanInstances({ includeAidActivity: false }), snapshot = getProcessSnapshot()) {
|
|
432
438
|
// 1. 已登记 PID(自己 HOME 下的 main + 自己进程)。调用方刚扫过登记簿时可直接传入,
|
|
433
439
|
// Windows 上每次 scanInstances 都要为活实例跑一遍 CIM 查询。
|
|
434
440
|
const known = new Set([process.pid]);
|
|
@@ -449,8 +455,8 @@ export function findOrphanProcesses(status = scanInstances()) {
|
|
|
449
455
|
// 所以先用快照里的命令行过滤,只对真正的 EvolCore 入口做后续探测。
|
|
450
456
|
// 优先用启动期已经采过的进程快照:它同样带命令行,省掉这里再拉一次全表 CIM。
|
|
451
457
|
// 快照不可用(非 Windows、或 CIM 查询失败)时回退到主动枚举。
|
|
452
|
-
|
|
453
|
-
const candidates = snapshot.complete
|
|
458
|
+
// Linux identity snapshots do not contain command lines; retain native enumeration.
|
|
459
|
+
const candidates = snapshot.complete && isWindows
|
|
454
460
|
? [...snapshot.commandLines.entries()]
|
|
455
461
|
.filter(([pid]) => pid !== process.pid)
|
|
456
462
|
.map(([pid, commandLine]) => ({ pid, commandLine }))
|
package/dist/utils/npm-ops.js
CHANGED
|
@@ -334,6 +334,9 @@ export function getLocalVersion() {
|
|
|
334
334
|
* 未安装或查询失败返回 null。
|
|
335
335
|
*/
|
|
336
336
|
export function resolveGlobalPkg(pkgName) {
|
|
337
|
+
const local = resolveBundledPkg(pkgName);
|
|
338
|
+
if (local)
|
|
339
|
+
return local;
|
|
337
340
|
try {
|
|
338
341
|
const npm = resolveNpmInvocation();
|
|
339
342
|
const globalRoot = execFileSync(npm.command, [...npm.argsPrefix, 'root', '-g'], {
|
|
@@ -356,6 +359,51 @@ export function resolveGlobalPkg(pkgName) {
|
|
|
356
359
|
catch { /* not found */ }
|
|
357
360
|
return null;
|
|
358
361
|
}
|
|
362
|
+
function resolveBundledPkg(pkgName) {
|
|
363
|
+
if (pkgName !== WEB_PACKAGE_NAME)
|
|
364
|
+
return null;
|
|
365
|
+
const candidates = [
|
|
366
|
+
...(isLinkedInstall() ? [path.join(getPackageRoot(), 'ecweb', 'package.json')] : []),
|
|
367
|
+
path.join(targetPackageRoot(), 'node_modules', ...pkgName.split('/'), 'package.json'),
|
|
368
|
+
];
|
|
369
|
+
for (const file of candidates) {
|
|
370
|
+
try {
|
|
371
|
+
const pkg = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
372
|
+
if (pkg.name === pkgName && typeof pkg.version === 'string')
|
|
373
|
+
return { version: pkg.version, path: file };
|
|
374
|
+
}
|
|
375
|
+
catch { /* Try the next installation layout. */ }
|
|
376
|
+
}
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
/** Runtime callers must not block IPC and CLI probe callbacks while locating npm packages. */
|
|
380
|
+
export async function resolveGlobalPkgAsync(pkgName) {
|
|
381
|
+
const local = resolveBundledPkg(pkgName);
|
|
382
|
+
if (local)
|
|
383
|
+
return local;
|
|
384
|
+
try {
|
|
385
|
+
const npm = resolveNpmInvocation();
|
|
386
|
+
const { stdout } = await execFileAsync(npm.command, [...npm.argsPrefix, 'root', '-g'], {
|
|
387
|
+
encoding: 'utf8', timeout: 10_000, windowsHide: true,
|
|
388
|
+
});
|
|
389
|
+
const globalRoot = stdout.trim();
|
|
390
|
+
const candidates = [
|
|
391
|
+
...(pkgName === WEB_PACKAGE_NAME
|
|
392
|
+
? [path.join(globalRoot, MAIN_PACKAGE_NAME, 'node_modules', ...pkgName.split('/'), 'package.json')] : []),
|
|
393
|
+
path.join(globalRoot, ...pkgName.split('/'), 'package.json'),
|
|
394
|
+
];
|
|
395
|
+
for (const file of candidates) {
|
|
396
|
+
try {
|
|
397
|
+
const pkg = JSON.parse(await fs.promises.readFile(file, 'utf8'));
|
|
398
|
+
if (pkg.name === pkgName && typeof pkg.version === 'string')
|
|
399
|
+
return { version: pkg.version, path: file };
|
|
400
|
+
}
|
|
401
|
+
catch { /* Try the next installation layout. */ }
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
catch { /* npm unavailable or package not installed. */ }
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
359
407
|
/**
|
|
360
408
|
* 查询 npm registry 上指定包的最新版本。
|
|
361
409
|
* 使用 HTTP fetch 直接查 registry API,不依赖 npm CLI。
|