evolcore 0.0.45 → 0.0.47
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 +113 -0
- package/bin/ecmsg.js +33 -23
- package/dist/ability/application-service.js +1 -2
- package/dist/ability/package.js +28 -0
- package/dist/agent-template/jobs.js +158 -36
- package/dist/agent-template/runtime.js +401 -34
- package/dist/agent-template/service.js +764 -369
- package/dist/agent-template/tool-runner.js +35 -17
- package/dist/agent-template/types.js +7 -4
- package/dist/agents/baseagent.js +10 -9
- package/dist/agents/claude-runner.js +22 -6
- package/dist/agents/codex/app-server-client.js +34 -27
- package/dist/agents/codex/diagnostics.js +18 -1
- package/dist/agents/codex-runner.js +3 -1
- package/dist/agents/ecagent-runner.js +3 -1
- package/dist/agents/gemini-runner.js +2 -1
- package/dist/aun/group/fs-download.js +1 -1
- package/dist/aun/menu/client.js +142 -182
- package/dist/aun/rpc/client.js +33 -17
- package/dist/aun/service-proxy.js +6 -23
- package/dist/channels/aun.js +675 -120
- package/dist/channels/daemon.js +1 -1
- package/dist/cli/agent-create.js +37 -10
- package/dist/cli/agent-template.js +105 -84
- package/dist/cli/agent.js +31 -18
- package/dist/cli/daemon-commands.js +42 -56
- package/dist/cli/daemon-lifecycle-client.js +55 -19
- package/dist/cli/directory.js +12 -4
- package/dist/cli/ecmsg-gateway.js +5 -2
- package/dist/cli/events-command.js +2 -1
- package/dist/cli/init-channel.js +2 -2
- package/dist/cli/init.js +57 -21
- package/dist/cli/integrity-command.js +2 -0
- package/dist/cli/managed-command-guard.js +20 -1
- package/dist/cli/menu-client.js +7 -5
- package/dist/cli/restart-monitor.js +135 -46
- package/dist/cli/services-command.js +28 -5
- package/dist/cli/task-context.js +83 -15
- package/dist/cli/upgrade-command.js +4 -2
- package/dist/config/config-field-policy.js +24 -0
- package/dist/config/config-manager.js +49 -19
- package/dist/config/peer-book-store.js +167 -127
- package/dist/config/peer-role-resolver.js +24 -4
- package/dist/config/provider-identity-migration.js +158 -6
- package/dist/config/provider-identity.js +10 -4
- package/dist/config/provider-ipc-service.js +10 -2
- package/dist/config/provider-local-sync.js +2 -2
- package/dist/config/providers-config.js +95 -10
- package/dist/config/providers-import.js +4 -6
- package/dist/config/providers.js +14 -3
- package/dist/config/role-store.js +1 -1
- package/dist/config/schema-migration.js +123 -16
- package/dist/config/schema-registry.js +6 -2
- package/dist/config-store.js +9 -1
- package/dist/core/agent-application-service.js +56 -29
- package/dist/core/agent-create-status.js +3 -1
- package/dist/core/agent-creation-claim.js +1 -0
- package/dist/core/agent-ipc-registration.js +2 -2
- package/dist/core/agent-reload-coordinator.js +38 -1
- package/dist/core/agent-runtime.js +91 -43
- package/dist/core/auth/agent-delegation.js +13 -3
- package/dist/core/auth/delegation-diagnostics.js +56 -15
- package/dist/core/auth/operation-authorizer.js +2 -2
- package/dist/core/auth/operation-catalog.js +3 -3
- package/dist/core/bootstrap-service.js +3 -0
- package/dist/core/capability/capability-manager.js +3 -1
- package/dist/core/channel-loader.js +29 -3
- package/dist/core/channel-runtime.js +1 -1
- package/dist/core/command/agent-control.js +6 -5
- package/dist/core/command/agent-template-menu.js +32 -97
- package/dist/core/command/eventcenter-menu.js +61 -13
- package/dist/core/command/menu-catalog.js +11 -4
- package/dist/core/command/menu-handler.js +39 -12
- package/dist/core/command/menu-protocol.js +8 -16
- package/dist/core/command/skill-slash.js +6 -2
- package/dist/core/command/slash-handler.js +4 -6
- package/dist/core/command/team-workspace-bootstrap.js +1 -2
- package/dist/core/command/team-workspace-management-store.js +83 -0
- package/dist/core/command/team-workspace-management.js +1 -2
- package/dist/core/command/team-workspace-team.js +26 -3
- package/dist/core/daemon-bootstrap.js +11 -9
- package/dist/core/daemon-control.js +4 -7
- package/dist/core/daemon-lifecycle.js +189 -143
- package/dist/core/evolagent-registry.js +50 -2
- package/dist/core/evolagent.js +2 -1
- package/dist/core/file-integrity/read.js +9 -16
- package/dist/core/file-integrity/store.js +94 -34
- package/dist/core/handoff/dispatcher.js +33 -7
- package/dist/core/handoff/runtime.js +8 -0
- package/dist/core/host-snapshot.js +9 -4
- package/dist/core/inference/text-inference.js +12 -2
- package/dist/core/initialization/service.js +22 -4
- package/dist/core/invoke/invoke-service.js +24 -3
- package/dist/core/ipc-registration.js +7 -3
- package/dist/core/memory/consolidation.js +6 -6
- package/dist/core/message/aun-ipc-sender.js +109 -7
- package/dist/core/message/contact-admission.js +6 -2
- package/dist/core/message/message-bridge.js +13 -0
- package/dist/core/message/message-queue.js +131 -30
- package/dist/core/message/pending-hints.js +8 -0
- package/dist/core/message/response-engine.js +48 -2
- package/dist/core/message/send-routing.js +3 -12
- package/dist/core/model/catalog-service.js +13 -0
- package/dist/core/model/model-catalog.js +57 -18
- package/dist/core/ownership/owner-resolver.js +27 -10
- package/dist/core/pack-auth.js +163 -31
- package/dist/core/pack-install.js +42 -1
- package/dist/{services/ledger.js → core/pack-ledger.js} +17 -6
- package/dist/core/permission/ec-command-parser.js +3 -1
- package/dist/core/permission/shell-environment.js +23 -0
- package/dist/core/rate-window.js +6 -1
- package/dist/core/relation/peer-identity.js +5 -1
- package/dist/core/relation/same-owner-proof.js +2 -1
- package/dist/core/session/adapters/claude-session-file-adapter.js +1 -1
- package/dist/core/session/session-file-health.js +36 -7
- package/dist/core/session/session-idle-monitor.js +0 -1
- package/dist/core/session/session-manager.js +14 -0
- package/dist/core/session/session-title.js +26 -6
- package/dist/core/skill/index-generator.js +3 -4
- package/dist/core/task/task-image-resources.js +1 -1
- package/dist/core/thread/thread-service.js +0 -1
- package/dist/core/thread/topic-id.js +8 -0
- package/dist/directory/owner-directory-admission.js +17 -0
- package/dist/directory/owner-directory-cache.js +3 -1
- package/dist/directory/owner-directory-markdown.js +145 -23
- package/dist/directory/owner-directory-policy.js +23 -0
- package/dist/directory/owner-directory-query-operation.js +20 -6
- package/dist/directory/owner-directory-search.js +47 -0
- package/dist/eck/message-renderer.js +171 -32
- package/dist/ecweb/basic-settings-service.js +7 -3
- package/dist/ecweb/providers-service.js +17 -10
- package/dist/ecweb/runtime/lifecycle.js +65 -16
- package/dist/ecweb/runtime/supervisor.js +79 -50
- package/dist/event-center/admission-materializer.js +1 -1
- package/dist/event-center/bus-gate.js +48 -4
- package/dist/event-center/bus-host.js +3 -3
- package/dist/event-center/center-config.js +57 -28
- package/dist/event-center/dispatcher.js +8 -0
- package/dist/event-center/event-log.js +69 -27
- package/dist/event-center/index-generator.js +6 -1
- package/dist/event-center/ipc-operation.js +66 -25
- package/dist/event-center/pack-loader.js +12 -55
- package/dist/event-center/pack-manager.js +5 -3
- package/dist/event-center/registry.js +48 -52
- package/dist/event-center/runtime.js +219 -81
- package/dist/event-center/script-runner.js +18 -7
- package/dist/event-center/types.js +9 -1
- package/dist/event-center/validation.js +33 -4
- package/dist/index.js +132 -75
- package/dist/ipc.js +35 -8
- package/dist/product.js +1 -0
- package/dist/proxy/manager.js +52 -11
- package/dist/proxy/service-supervisor.js +265 -67
- package/dist/services/dispatcher.js +26 -3
- package/dist/services/idempotency.js +128 -0
- package/dist/services/identity.js +3 -27
- package/dist/services/index-generator.js +5 -1
- package/dist/services/index.js +244 -45
- package/dist/services/ipc-operation.js +164 -20
- package/dist/services/pack-manager.js +37 -9
- package/dist/services/router.js +100 -31
- package/dist/services/script-runner.js +15 -4
- package/dist/services/service-payload.js +50 -2
- package/dist/services/validation.js +107 -3
- package/dist/trigger/scheduler.js +18 -4
- package/dist/trigger/script-sandbox.js +39 -2
- package/dist/trigger/state.js +7 -0
- package/dist/utils/aid-bind.js +155 -18
- package/dist/utils/atomic-write.js +3 -3
- package/dist/utils/cross-platform.js +59 -16
- package/dist/utils/error-utils.js +26 -1
- package/dist/utils/instance-registry.js +94 -35
- package/dist/utils/process-introspect.js +187 -27
- package/dist/utils/project-path.js +47 -3
- package/dist/utils/upgrade-jobs.js +4 -4
- package/dist/utils/windows-shell-trust.js +174 -68
- package/kits/docs/context-assembly.md +3 -3
- package/kits/docs/evolcore/agent.md +28 -10
- package/kits/docs/evolcore/aid.md +3 -1
- package/kits/docs/evolcore/config.md +22 -0
- package/kits/docs/evolcore/directory.md +46 -12
- package/kits/docs/evolcore/event-center.md +6 -6
- package/kits/docs/evolcore/group-collaboration.md +1 -1
- package/kits/docs/evolcore/menu-client.md +7 -5
- package/kits/docs/evolcore/menu-protocol.md +5 -3
- package/kits/docs/evolcore/msg.md +10 -3
- package/kits/docs/evolcore/provider.md +17 -5
- package/kits/docs/evolcore/services.md +145 -12
- package/kits/docs/evolcore/thread-chain.md +17 -9
- package/kits/docs/prompt-loading-architecture.md +4 -4
- package/kits/eck_message_manifest.json +46 -3
- package/kits/rules/04-relation.md +10 -2
- package/kits/rules/06-channel.md +2 -1
- package/kits/schemas/providers.schema.2.json +1 -0
- package/kits/skills/ec-group/SKILL.md +4 -0
- package/kits/skills/ec-skill/scripts/cli.mjs +1 -1
- package/kits/skills/ec-skill/scripts/skill.mjs +13 -2
- package/kits/skills/thread-ops/SKILL.md +8 -5
- package/kits/templates/message-fragments/group-batch-item.md +3 -0
- package/kits/templates/message-fragments/group-batch.md +1 -0
- package/kits/templates/message-fragments/item-group.md +4 -0
- package/kits/templates/message-fragments/item-private.md +4 -0
- package/kits/templates/message-fragments/thread-context.md +1 -1
- package/kits/templates/system-fragments/commands.md +5 -5
- package/kits/templates/system-fragments/managed-runtime.md +1 -1
- package/kits/templates/system-fragments/relation.md +11 -7
- package/package.json +3 -2
- package/scripts/agent-template/index.mjs +9 -4
- package/scripts/agent-template/inspect.mjs +16 -9
- package/scripts/agent-template/shared/plan.mjs +3 -33
- package/scripts/agent-template/shared/template-contract.mjs +186 -3
- package/scripts/agent-template/shared/template-package.mjs +119 -10
- package/scripts/agent-template/shared/template-runtime.mjs +49 -6
- package/scripts/agent-template/shared/template.mjs +5 -5
- package/scripts/agent-template/team-pack.mjs +245 -0
- package/scripts/agent-template/team-preview.mjs +111 -0
- package/scripts/aid-batch/identity-batch.mjs +143 -0
- package/dist/ability/versions.js +0 -32
- package/dist/aun/model-headers.js +0 -17
- package/dist/channels/builtin-plugins.js +0 -19
- package/dist/core/command/team-workspace-initializer.js +0 -2
- package/dist/core/command/team-workspace-job-store.js +0 -88
- package/dist/core/command/team-workspace-management-service.js +0 -2
- package/dist/core/contact-bind-registry.js +0 -27
- package/dist/event-center/ledger.js +0 -52
- package/dist/services/reply.js +0 -55
- package/kits/templates/message-fragments/item.md +0 -3
- package/scripts/agent-template/pack.mjs +0 -169
|
@@ -5,7 +5,8 @@ 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 {
|
|
8
|
+
import { requireTrustedWindowsCmdPath, requireTrustedWindowsCmdPathAsync, WindowsShellTrustError, } from './windows-shell-trust.js';
|
|
9
|
+
import { logger } from './logger.js';
|
|
9
10
|
const execFileAsync = promisify(execFile);
|
|
10
11
|
const CLI_PROBE_FAILURE_BACKOFF_MS = 5_000;
|
|
11
12
|
export const CODEX_CLI_PROBE_TIMEOUT_MS = 9_000;
|
|
@@ -63,6 +64,14 @@ function escapeWindowsCmdArgument(value) {
|
|
|
63
64
|
escaped = `"${escaped}"`;
|
|
64
65
|
return escaped.replace(WINDOWS_CMD_META_RE, '^$1');
|
|
65
66
|
}
|
|
67
|
+
function failWindowsCliLaunch(error, executable) {
|
|
68
|
+
if (error instanceof WindowsShellTrustError) {
|
|
69
|
+
logger.warn(`[WindowsShellTrust] ${JSON.stringify({
|
|
70
|
+
code: error.code, reason: error.reason, executable, message: error.message, ...error.diagnostics,
|
|
71
|
+
})}`);
|
|
72
|
+
}
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
66
75
|
/** Build one argv-based CLI launch without consulting the parent terminal. */
|
|
67
76
|
export function buildCliLaunchCommand(executable, args, options = {}) {
|
|
68
77
|
const windows = options.isWindows ?? isWindows;
|
|
@@ -77,13 +86,16 @@ export function buildCliLaunchCommand(executable, args, options = {}) {
|
|
|
77
86
|
launcherPath: executable,
|
|
78
87
|
};
|
|
79
88
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
let launcherPath;
|
|
90
|
+
try {
|
|
91
|
+
const resolved = (options.resolveWindowsCmd ?? requireTrustedWindowsCmdPath)(options.comSpec);
|
|
92
|
+
if (!resolved) {
|
|
93
|
+
throw new WindowsShellTrustError('CMD_UNAVAILABLE', '系统 cmd 解析器未返回可用路径', { executable });
|
|
94
|
+
}
|
|
95
|
+
launcherPath = resolved;
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
return failWindowsCliLaunch(error, executable);
|
|
87
99
|
}
|
|
88
100
|
const shellCommand = [
|
|
89
101
|
escapeWindowsCmdCommand(executable),
|
|
@@ -296,7 +308,13 @@ export async function probeCli(command, args, options = {}) {
|
|
|
296
308
|
const resolved = resolveCliProbe(command, args, options);
|
|
297
309
|
let resolveWindowsCmd;
|
|
298
310
|
if (isWindows && /\.(?:cmd|bat)$/i.test(resolved.probeExecutable)) {
|
|
299
|
-
|
|
311
|
+
let trustedCmd;
|
|
312
|
+
try {
|
|
313
|
+
trustedCmd = await requireTrustedWindowsCmdPathAsync();
|
|
314
|
+
}
|
|
315
|
+
catch (error) {
|
|
316
|
+
return failWindowsCliLaunch(error, resolved.probeExecutable);
|
|
317
|
+
}
|
|
300
318
|
resolveWindowsCmd = () => trustedCmd;
|
|
301
319
|
}
|
|
302
320
|
const request = prepareCliProbe(command, args, options, resolved, resolveWindowsCmd);
|
|
@@ -488,21 +506,21 @@ export async function launchMonitorAndConfirm(args, env, isAliveInRegistry, hasO
|
|
|
488
506
|
catch (error) {
|
|
489
507
|
diagnostic(`Spawn callback failed: ${error.message}`);
|
|
490
508
|
}
|
|
491
|
-
const accepted = () => isAliveInRegistry(childPid) || hasOtherLiveMonitor(childPid);
|
|
509
|
+
const accepted = async () => await isAliveInRegistry(childPid) || await hasOtherLiveMonitor(childPid);
|
|
492
510
|
const deadline = Date.now() + (options.timeoutMs ?? 15_000);
|
|
493
511
|
while (Date.now() < deadline) {
|
|
494
512
|
await new Promise(resolve => setTimeout(resolve, 300));
|
|
495
|
-
if (accepted())
|
|
513
|
+
if (await accepted())
|
|
496
514
|
return finish({ ok: true, pid: childPid });
|
|
497
515
|
if (spawnError)
|
|
498
516
|
return finish({ ok: false, pid: childPid, reason: spawnError });
|
|
499
|
-
if (exited && !options.isPendingInRegistry?.()) {
|
|
517
|
+
if (exited && !await options.isPendingInRegistry?.()) {
|
|
500
518
|
return finish({ ok: false, pid: childPid, reason: `进程已退出,exit=${exitCode}, signal=${exitSignal ?? 'none'}` });
|
|
501
519
|
}
|
|
502
520
|
}
|
|
503
|
-
if (accepted())
|
|
521
|
+
if (await accepted())
|
|
504
522
|
return finish({ ok: true, pid: childPid });
|
|
505
|
-
if ((!exited &&
|
|
523
|
+
if ((!exited && await isProcessRunningAsync(childPid)) || await options.isPendingInRegistry?.()) {
|
|
506
524
|
return finish({
|
|
507
525
|
ok: false,
|
|
508
526
|
pid: childPid,
|
|
@@ -520,10 +538,10 @@ export async function launchMonitorAndConfirm(args, env, isAliveInRegistry, hasO
|
|
|
520
538
|
* in a checkout: `npm install -g` swaps the whole package directory, and the
|
|
521
539
|
* monitor has ~170 lazy `await import()` sites, so a module it has not loaded
|
|
522
540
|
* yet would come from the new version while the rest is still the old one.
|
|
523
|
-
* Staging `dist/`, `bin
|
|
541
|
+
* Staging `dist/`, `bin/`, `kits/` and runtime scripts keeps package-owned code and runtime
|
|
524
542
|
* schemas on one version.
|
|
525
543
|
*
|
|
526
|
-
* `dist/`, `bin/`, `kits
|
|
544
|
+
* `dist/`, `bin/`, `kits/`, runtime scripts and `package.json` are copied. `node_modules` is
|
|
527
545
|
* linked, because copying it is hundreds of MB. The link degrades in steps so
|
|
528
546
|
* that no platform is left without a path forward:
|
|
529
547
|
*
|
|
@@ -562,6 +580,12 @@ export function prepareMonitorStage(packageRoot, stageParent) {
|
|
|
562
580
|
const kitsSource = path.join(packageRoot, 'kits');
|
|
563
581
|
if (fs.existsSync(kitsSource))
|
|
564
582
|
fs.cpSync(kitsSource, path.join(stageDir, 'kits'), { recursive: true });
|
|
583
|
+
for (const name of ['agent-template', 'aid-batch']) {
|
|
584
|
+
const scriptsSource = path.join(packageRoot, 'scripts', name);
|
|
585
|
+
if (fs.existsSync(scriptsSource)) {
|
|
586
|
+
fs.cpSync(scriptsSource, path.join(stageDir, 'scripts', name), { recursive: true });
|
|
587
|
+
}
|
|
588
|
+
}
|
|
565
589
|
const pkgJson = path.join(packageRoot, 'package.json');
|
|
566
590
|
if (fs.existsSync(pkgJson))
|
|
567
591
|
fs.copyFileSync(pkgJson, path.join(stageDir, 'package.json'));
|
|
@@ -870,6 +894,25 @@ export function killProcess(pid, force = false) {
|
|
|
870
894
|
return !isProcessRunning(pid);
|
|
871
895
|
}
|
|
872
896
|
}
|
|
897
|
+
/** Same process-tree termination as killProcess, without blocking Windows I/O. */
|
|
898
|
+
export async function killProcessAsync(pid, force = false) {
|
|
899
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
900
|
+
return false;
|
|
901
|
+
if (!isWindows)
|
|
902
|
+
return killProcess(pid, force);
|
|
903
|
+
try {
|
|
904
|
+
const args = ['/PID', String(pid), '/T'];
|
|
905
|
+
if (force)
|
|
906
|
+
args.push('/F');
|
|
907
|
+
await execFileAsync('taskkill', args, {
|
|
908
|
+
encoding: 'utf-8', timeout: 10_000, windowsHide: true,
|
|
909
|
+
});
|
|
910
|
+
return true;
|
|
911
|
+
}
|
|
912
|
+
catch {
|
|
913
|
+
return !await isProcessRunningAsync(pid);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
873
916
|
/**
|
|
874
917
|
* Terminate exactly one process, without recursively terminating its children.
|
|
875
918
|
*
|
|
@@ -2,6 +2,7 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { getPackageRoot, resolvePaths } from '../paths.js';
|
|
4
4
|
import { logger } from './logger.js';
|
|
5
|
+
import { isWindowsShellTrustError } from './windows-shell-trust.js';
|
|
5
6
|
import { CODEX_SANDBOX_USER_NAMESPACE_DISABLED_BY_APPARMOR, CODEX_SANDBOX_USER_NAMESPACE_UNAVAILABLE, isClaudeSandboxDependencyFailure, isCodexSandboxUserNamespaceFailure, isSandboxInitializationFailure, } from '../core/permission/sandbox-runtime.js';
|
|
6
7
|
/** A deadline imposed by an outer executor, handled by the ordinary task timeout path. */
|
|
7
8
|
export class ExecutionTimeoutError extends Error {
|
|
@@ -102,6 +103,7 @@ export var ErrorType;
|
|
|
102
103
|
ErrorType["COMPACTION_FAILED"] = "compaction_failed";
|
|
103
104
|
ErrorType["MODEL_UNAVAILABLE"] = "model_unavailable";
|
|
104
105
|
ErrorType["SESSION_UNAVAILABLE"] = "session_unavailable";
|
|
106
|
+
ErrorType["SESSION_RUNTIME_UNAVAILABLE"] = "session_runtime_unavailable";
|
|
105
107
|
ErrorType["SANDBOX_INITIALIZATION_FAILED"] = "sandbox_initialization_failed";
|
|
106
108
|
ErrorType["SANDBOX_DEPENDENCIES_MISSING"] = "sandbox_dependencies_missing";
|
|
107
109
|
ErrorType["CODEX_SANDBOX_USER_NAMESPACE_UNAVAILABLE"] = "codex_sandbox_userns_unavailable";
|
|
@@ -113,7 +115,8 @@ export var ErrorType;
|
|
|
113
115
|
})(ErrorType || (ErrorType = {}));
|
|
114
116
|
const POLICY_REJECTION_PATTERN = /invalid prompt[\s\S]{0,240}flagged as potentially violating our usage policy|prompt was flagged as potentially violating our usage policy/i;
|
|
115
117
|
export function isPolicyRejectedError(error) {
|
|
116
|
-
|
|
118
|
+
const raw = getErrorRawText(error) ?? '';
|
|
119
|
+
return /Provider model policy rejected:/u.test(raw) || POLICY_REJECTION_PATTERN.test(raw);
|
|
117
120
|
}
|
|
118
121
|
export function getErrorRawText(error, seen = new Set()) {
|
|
119
122
|
if (typeof error === 'string') {
|
|
@@ -464,7 +467,15 @@ const GATEWAY_REQUEST_TIMEOUT_PATTERN = /\bgateway request timed out\b/i;
|
|
|
464
467
|
function hasRetryableHttpStatus(text) {
|
|
465
468
|
return RETRYABLE_HTTP_STATUS_PATTERN.test(text);
|
|
466
469
|
}
|
|
470
|
+
function isSessionRuntimeError(error) {
|
|
471
|
+
return error?.code === 'SESSION_RUNTIME_UNAVAILABLE'
|
|
472
|
+
|| String(error?.message ?? error ?? '').startsWith('SESSION_RUNTIME_UNAVAILABLE:');
|
|
473
|
+
}
|
|
467
474
|
export function classifyError(error) {
|
|
475
|
+
if (isSessionRuntimeError(error))
|
|
476
|
+
return ErrorType.SESSION_RUNTIME_UNAVAILABLE;
|
|
477
|
+
if (isWindowsShellTrustError(error))
|
|
478
|
+
return ErrorType.UNKNOWN;
|
|
468
479
|
if (isUnattendedInputRequired(error))
|
|
469
480
|
return ErrorType.INPUT_REQUIRED;
|
|
470
481
|
if (error?.code === 'RUNNER_INTERRUPT_UNCONFIRMED')
|
|
@@ -548,6 +559,10 @@ export function classifyError(error) {
|
|
|
548
559
|
* 注意:401 认证错误不可重试(API Key 无效不会因重试恢复)
|
|
549
560
|
*/
|
|
550
561
|
export function isRetryableError(error) {
|
|
562
|
+
if (isSessionRuntimeError(error))
|
|
563
|
+
return false;
|
|
564
|
+
if (isWindowsShellTrustError(error))
|
|
565
|
+
return false;
|
|
551
566
|
if (isUnattendedInputRequired(error))
|
|
552
567
|
return false;
|
|
553
568
|
if (error?.code === 'RUNNER_INTERRUPT_UNCONFIRMED')
|
|
@@ -611,6 +626,16 @@ function sandboxInitializationErrorMessage(error, prefix) {
|
|
|
611
626
|
return `${prefix}执行沙箱启动失败(sandbox_initialization_failed),当前操作未执行;请查看原始诊断并运行 ec diagnose 排查`;
|
|
612
627
|
}
|
|
613
628
|
export function getErrorMessage(error, terminalReason, includeEmoji = true) {
|
|
629
|
+
if (isSessionRuntimeError(error)) {
|
|
630
|
+
const message = typeof error === 'string' ? error : error.message ?? error.code;
|
|
631
|
+
return `${includeEmoji ? '❌ ' : ''}会话临时目录准备或安全校验失败,本轮未继续执行。${message}。请检查对应阶段的目录权限或超时原因;不会退回共享临时目录。`;
|
|
632
|
+
}
|
|
633
|
+
if (isWindowsShellTrustError(error)) {
|
|
634
|
+
return `${includeEmoji ? '❌ ' : ''}${resolveErrorMessage(error)}`;
|
|
635
|
+
}
|
|
636
|
+
if (/Provider model policy rejected:/u.test(getErrorRawText(error) ?? '')) {
|
|
637
|
+
return `${includeEmoji ? '⚠️ ' : ''}模型未获 Provider 策略允许,请检查对应服务类型的模型名单;不会自动换模型。`;
|
|
638
|
+
}
|
|
614
639
|
if (isUnattendedInputRequired(error)) {
|
|
615
640
|
return `${includeEmoji ? '⚠️ ' : ''}${UNATTENDED_INPUT_REQUIRED_MESSAGE}`;
|
|
616
641
|
}
|
|
@@ -12,8 +12,8 @@ import fs from 'fs';
|
|
|
12
12
|
import path from 'path';
|
|
13
13
|
import { spawnSync } from 'child_process';
|
|
14
14
|
import { getPackageRoot, resolvePaths, isDevMode } from '../paths.js';
|
|
15
|
-
import { isProcessRunning, killProcess, isWindows, findProcessesWithCommandLine, decodeWindowsOutput } from './cross-platform.js';
|
|
16
|
-
import { getProcessSnapshot, getProcessStartTime, snapshotProcessState, startTimeMatches, } from './process-introspect.js';
|
|
15
|
+
import { isProcessRunning, isProcessRunningAsync, killProcess, waitForProcessExit, isWindows, findProcessesWithCommandLine, decodeWindowsOutput } from './cross-platform.js';
|
|
16
|
+
import { getProcessSnapshot, getProcessStartTime, getProcessStartTimeAsync, snapshotProcessState, startTimeMatches, } from './process-introspect.js';
|
|
17
17
|
import { isConfirmedLeakedTestDaemon, runtimeHomeFromEnv } from './restart-safety.js';
|
|
18
18
|
import { atomicWriteJson } from './atomic-write.js';
|
|
19
19
|
// ── Helpers ──
|
|
@@ -308,9 +308,71 @@ export function scanInstances(options = {}) {
|
|
|
308
308
|
}
|
|
309
309
|
return status;
|
|
310
310
|
}
|
|
311
|
+
/** Observe the IPC target only; the restart monitor still owns election and cleanup. */
|
|
312
|
+
export async function hasLiveMain(pid) {
|
|
313
|
+
if (!Number.isSafeInteger(pid) || pid <= 0)
|
|
314
|
+
return false;
|
|
315
|
+
let record;
|
|
316
|
+
try {
|
|
317
|
+
record = JSON.parse(await fs.promises.readFile(path.join(instanceDir(), mainFileName(pid)), 'utf8'));
|
|
318
|
+
}
|
|
319
|
+
catch (error) {
|
|
320
|
+
if (error instanceof SyntaxError || error.code === 'ENOENT')
|
|
321
|
+
return false;
|
|
322
|
+
throw error;
|
|
323
|
+
}
|
|
324
|
+
if (record?.pid !== pid || !Number.isFinite(record.startedAt) || record.startedAt <= 0)
|
|
325
|
+
return false;
|
|
326
|
+
// A fresh identity lookup already confirms liveness after the OS query.
|
|
327
|
+
// Fall back conservatively only when the creation time is unavailable.
|
|
328
|
+
const actual = await getProcessStartTimeAsync(pid, { fresh: true });
|
|
329
|
+
return actual !== null ? startTimeMatches(record.startedAt, actual) : await isProcessRunningAsync(pid);
|
|
330
|
+
}
|
|
331
|
+
/** Read-only launch observation; never block the daemon's shutdown IPC with a full process scan. */
|
|
332
|
+
export async function hasLiveRestartMonitor(options = {}) {
|
|
333
|
+
const directory = instanceDir();
|
|
334
|
+
let files;
|
|
335
|
+
try {
|
|
336
|
+
files = await fs.promises.readdir(directory);
|
|
337
|
+
}
|
|
338
|
+
catch (error) {
|
|
339
|
+
if (error.code === 'ENOENT')
|
|
340
|
+
return false;
|
|
341
|
+
throw error;
|
|
342
|
+
}
|
|
343
|
+
for (const file of files) {
|
|
344
|
+
const match = /^restart-monitor-(\d+)\.json$/.exec(file);
|
|
345
|
+
if (!match)
|
|
346
|
+
continue;
|
|
347
|
+
const pid = Number(match[1]);
|
|
348
|
+
if (!Number.isSafeInteger(pid) || pid <= 0 || pid === options.excludePid
|
|
349
|
+
|| (options.pid !== undefined && pid !== options.pid))
|
|
350
|
+
continue;
|
|
351
|
+
let record;
|
|
352
|
+
try {
|
|
353
|
+
record = JSON.parse(await fs.promises.readFile(path.join(directory, file), 'utf8'));
|
|
354
|
+
}
|
|
355
|
+
catch (error) {
|
|
356
|
+
if (error instanceof SyntaxError || error.code === 'ENOENT')
|
|
357
|
+
continue;
|
|
358
|
+
throw error;
|
|
359
|
+
}
|
|
360
|
+
if (record?.pid !== pid || !Number.isFinite(record.startedAt) || record.startedAt <= 0
|
|
361
|
+
|| (options.requestId !== undefined && record.requestId !== options.requestId)
|
|
362
|
+
|| (options.phase !== undefined && record.phase !== options.phase))
|
|
363
|
+
continue;
|
|
364
|
+
if (!await isProcessRunningAsync(pid))
|
|
365
|
+
continue;
|
|
366
|
+
const actual = await getProcessStartTimeAsync(pid, { fresh: true });
|
|
367
|
+
if (actual !== null ? startTimeMatches(record.startedAt, actual) : await isProcessRunningAsync(pid))
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
return false;
|
|
371
|
+
}
|
|
311
372
|
/**
|
|
312
373
|
* 清理所有非自己 PID 的残留文件。仍活着的旧实例进程会被 SIGKILL。
|
|
313
|
-
*
|
|
374
|
+
* 发送终止信号前重新核验身份;无法核验或终止失败时保留登记供后续处理。
|
|
375
|
+
* 返回终止命令成功的 PID 列表。
|
|
314
376
|
*/
|
|
315
377
|
export function cleanupInstances() {
|
|
316
378
|
const dir = instanceDir();
|
|
@@ -326,33 +388,18 @@ export function cleanupInstances() {
|
|
|
326
388
|
const killed = [];
|
|
327
389
|
for (const file of files) {
|
|
328
390
|
const filePath = path.join(dir, file);
|
|
329
|
-
if (file.startsWith('main-') && file.endsWith('.json')) {
|
|
391
|
+
if ((file.startsWith('main-') || file.startsWith('restart-monitor-')) && file.endsWith('.json')) {
|
|
330
392
|
const record = safeParseJson(filePath);
|
|
331
393
|
if (record?.pid) {
|
|
332
394
|
if (record.pid === process.pid)
|
|
333
395
|
continue;
|
|
334
396
|
if (isProcessRunning(record.pid)) {
|
|
335
|
-
const actual = getProcessStartTime(record.pid);
|
|
397
|
+
const actual = getProcessStartTime(record.pid, { fresh: true });
|
|
398
|
+
if (actual === null && isProcessRunning(record.pid))
|
|
399
|
+
continue;
|
|
336
400
|
if (startTimeMatches(record.startedAt, actual)) {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
try {
|
|
343
|
-
fs.unlinkSync(filePath);
|
|
344
|
-
}
|
|
345
|
-
catch { }
|
|
346
|
-
}
|
|
347
|
-
else if (file.startsWith('restart-monitor-') && file.endsWith('.json')) {
|
|
348
|
-
const record = safeParseJson(filePath);
|
|
349
|
-
if (record?.pid) {
|
|
350
|
-
if (record.pid === process.pid)
|
|
351
|
-
continue;
|
|
352
|
-
if (isProcessRunning(record.pid)) {
|
|
353
|
-
const actual = getProcessStartTime(record.pid);
|
|
354
|
-
if (startTimeMatches(record.startedAt, actual)) {
|
|
355
|
-
killPid(record.pid);
|
|
401
|
+
if (!killProcess(record.pid, true))
|
|
402
|
+
continue;
|
|
356
403
|
killed.push(record.pid);
|
|
357
404
|
}
|
|
358
405
|
}
|
|
@@ -389,10 +436,6 @@ export function removeAll(pid) {
|
|
|
389
436
|
removeMain(target);
|
|
390
437
|
removeAidLog(target);
|
|
391
438
|
}
|
|
392
|
-
// ── Internal ──
|
|
393
|
-
function killPid(pid) {
|
|
394
|
-
killProcess(pid, true);
|
|
395
|
-
}
|
|
396
439
|
function normalizeProcessPath(value) {
|
|
397
440
|
return value.replace(/[\\/]+/g, '/').toLowerCase();
|
|
398
441
|
}
|
|
@@ -470,13 +513,16 @@ export function findOrphanProcesses(status = scanInstances({ includeAidActivity:
|
|
|
470
513
|
// 快照完整时它本身就是存活进程表,不需要再逐 pid 拉 tasklist。
|
|
471
514
|
if (!snapshot.complete && !isProcessRunning(pid))
|
|
472
515
|
continue;
|
|
473
|
-
|
|
516
|
+
// Bind command evidence to a captured identity before later signalling.
|
|
517
|
+
const startedAt = snapshot.startedAt.get(pid) ?? getProcessStartTime(pid, { fresh: true }) ?? undefined;
|
|
518
|
+
const cmdline = snapshot.startedAt.has(pid) && commandLine ? commandLine : readCmdline(pid);
|
|
474
519
|
// 二次验证:入口必须是当前 EvolCore 包的 dist/index.js。
|
|
475
520
|
if (!isEvolCoreMainCommand(cmdline))
|
|
476
521
|
continue;
|
|
477
522
|
const processEnv = readProcessEnvironment(pid);
|
|
478
523
|
orphans.push({
|
|
479
524
|
pid,
|
|
525
|
+
startedAt,
|
|
480
526
|
evolcoreHome: processEnv ? runtimeHomeFromEnv(processEnv) : null,
|
|
481
527
|
cmdline,
|
|
482
528
|
confirmedTestDaemon: processEnv ? isConfirmedLeakedTestDaemon(processEnv) : false,
|
|
@@ -485,18 +531,31 @@ export function findOrphanProcesses(status = scanInstances({ includeAidActivity:
|
|
|
485
531
|
return orphans;
|
|
486
532
|
}
|
|
487
533
|
/**
|
|
488
|
-
* SIGKILL
|
|
534
|
+
* SIGKILL 已核验身份的孤儿 PID,只返回确认原进程已退出的 PID。
|
|
489
535
|
*/
|
|
490
|
-
export function killOrphans(orphans) {
|
|
491
|
-
const
|
|
536
|
+
export async function killOrphans(orphans) {
|
|
537
|
+
const confirmations = [];
|
|
492
538
|
for (const o of orphans) {
|
|
493
539
|
try {
|
|
494
|
-
|
|
495
|
-
|
|
540
|
+
const expectedStartedAt = o.startedAt;
|
|
541
|
+
if (expectedStartedAt === undefined)
|
|
542
|
+
continue;
|
|
543
|
+
if (!startTimeMatches(expectedStartedAt, await getProcessStartTimeAsync(o.pid, { fresh: true })))
|
|
544
|
+
continue;
|
|
545
|
+
if (!killProcess(o.pid, true))
|
|
546
|
+
continue;
|
|
547
|
+
// Keep identity probes sequential, but overlap independent exit waits.
|
|
548
|
+
confirmations.push(waitForProcessExit(o.pid, 2000).then(async (exited) => {
|
|
549
|
+
if (exited || !await isProcessRunningAsync(o.pid))
|
|
550
|
+
return o.pid;
|
|
551
|
+
const currentStartedAt = await getProcessStartTimeAsync(o.pid, { fresh: true });
|
|
552
|
+
// PID reuse proves the original exited; never signal the replacement.
|
|
553
|
+
return currentStartedAt !== null && !startTimeMatches(expectedStartedAt, currentStartedAt) ? o.pid : null;
|
|
554
|
+
}).catch(() => null));
|
|
496
555
|
}
|
|
497
556
|
catch { }
|
|
498
557
|
}
|
|
499
|
-
return
|
|
558
|
+
return (await Promise.all(confirmations)).filter((pid) => pid !== null);
|
|
500
559
|
}
|
|
501
560
|
function readCmdline(pid) {
|
|
502
561
|
if (isWindows) {
|