evolcore 0.0.40 → 0.0.41-test.1
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 +94 -1
- package/bin/codex-managed-hook.mjs +11 -0
- package/bin/ec-safe-output.js +11 -1
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/baseagent.js +20 -43
- package/dist/agents/claude-runner.js +197 -197
- package/dist/agents/codex-runner.js +535 -259
- package/dist/agents/ecagent-runner.js +31 -12
- package/dist/agents/gemini-runner.js +27 -7
- package/dist/agents/runner-types.js +11 -3
- package/dist/aun/ability-device-routing.js +26 -0
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/group/fs-download.js +39 -0
- package/dist/aun/group/identity.js +36 -13
- package/dist/aun/group/operations.js +5 -0
- package/dist/aun/msg/managed-operation.js +72 -11
- package/dist/aun/msg/p2p.js +32 -7
- package/dist/aun/service-proxy.js +36 -12
- package/dist/aun/storage/download.js +30 -0
- package/dist/aun/storage/index.js +14 -6
- package/dist/channels/aun.js +367 -24
- package/dist/channels/daemon.js +39 -5
- package/dist/cli/agent-command.js +2 -0
- package/dist/cli/agent-create.js +98 -19
- package/dist/cli/agent.js +10 -3
- package/dist/cli/aun-commands.js +85 -41
- package/dist/cli/daemon-commands.js +678 -688
- package/dist/cli/fs-command.js +64 -2
- package/dist/cli/index.js +48 -4
- package/dist/cli/managed-command-guard.js +4 -0
- package/dist/cli/model.js +40 -40
- package/dist/cli/proxy-command.js +92 -0
- package/dist/cli/restart-monitor.js +17 -0
- package/dist/cli/role.js +85 -0
- package/dist/cli/session-command.js +128 -13
- package/dist/cli/stats.js +60 -4
- package/dist/cli/trigger-command.js +2 -2
- package/dist/config/access-policy.js +8 -1
- package/dist/config/boot-log.js +38 -1
- package/dist/config/config-field-policy.js +5 -32
- package/dist/config/config-manager.js +46 -39
- package/dist/config/config-operation-service.js +8 -11
- package/dist/config/contact-book-store.js +47 -21
- package/dist/config/contact-book.js +18 -12
- package/dist/config/contact-operation-service.js +3 -4
- package/dist/config/contact-request-service.js +11 -0
- package/dist/config/daemon-services.js +11 -0
- package/dist/config/gateway-config.js +89 -595
- package/dist/config/peer-role-resolver.js +15 -11
- package/dist/config/providers-config.js +12 -7
- package/dist/config/providers-import.js +3 -21
- package/dist/config/resolved-config-op.js +3 -0
- package/dist/config/role-command-service.js +166 -0
- package/dist/config/role-request-service.js +193 -0
- package/dist/config/schema-migration.js +686 -25
- package/dist/config-store.js +79 -3
- package/dist/contracts/ecweb-instance.js +41 -0
- package/dist/contracts/ecweb-service-protocol.js +3 -1
- package/dist/core/agent-application-service.js +11 -1
- package/dist/core/agent-ipc-registration.js +4 -0
- package/dist/core/agent-runtime.js +1 -1
- package/dist/core/auth/agent-delegation.js +82 -6
- package/dist/core/auth/auth-gateway.js +1 -1
- package/dist/core/auth/authorization-audit.js +37 -9
- package/dist/core/auth/delegation-authorization.js +3 -1
- package/dist/core/auth/operation-authorizer.js +15 -0
- package/dist/core/auth/operation-catalog.js +39 -6
- package/dist/core/command/agent-control.js +94 -19
- package/dist/core/command/agent-storage-menu.js +5 -3
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +105 -145
- package/dist/core/command/connect-menu.js +31 -2
- package/dist/core/command/data-root-resolver.js +5 -4
- package/dist/core/command/memory-slash.js +16 -8
- package/dist/core/command/menu-catalog.js +6 -6
- package/dist/core/command/menu-handler.js +87 -163
- package/dist/core/command/menu-protocol.js +9 -2
- package/dist/core/command/role-menu.js +148 -30
- package/dist/core/command/slash-gate.js +13 -10
- package/dist/core/command/slash-handler.js +157 -352
- package/dist/core/daemon-control.js +8 -14
- package/dist/core/event-catalog.js +15 -0
- package/dist/core/evolagent-registry.js +4 -4
- package/dist/core/evolagent.js +2 -2
- package/dist/core/inference/text-inference.js +31 -40
- package/dist/core/ipc-registration.js +24 -3
- package/dist/core/memory/consolidation-context.js +51 -5
- package/dist/core/memory/consolidation-ops-records.js +1 -1
- package/dist/core/memory/consolidation-trigger.js +190 -190
- package/dist/core/memory/consolidation.js +316 -29
- package/dist/core/memory/forget-log.js +96 -0
- package/dist/core/memory/index-manager.js +27 -5
- package/dist/core/memory/memory-admin.js +45 -5
- package/dist/core/memory/memory-writer.js +163 -18
- package/dist/core/memory/relation-idle-monitor.js +119 -58
- package/dist/core/memory/relation-sweep.js +44 -39
- package/dist/core/message/aun-ipc-sender.js +34 -7
- package/dist/core/message/aun-request-registry.js +97 -3
- package/dist/core/message/im-renderer.js +11 -4
- package/dist/core/message/message-admission.js +97 -8
- package/dist/core/message/message-bridge.js +71 -24
- package/dist/core/message/message-log.js +55 -0
- package/dist/core/message/message-queue.js +5 -5
- package/dist/core/message/response-engine.js +387 -144
- package/dist/core/model/catalog-service.js +4 -2
- package/dist/core/model/config-scope.js +24 -64
- package/dist/core/model/field-scope.js +1 -1
- package/dist/core/model/model-catalog.js +37 -47
- package/dist/core/model/model-diagnostics.js +4 -3
- package/dist/core/model/model-fallback.js +10 -7
- package/dist/core/model/model-permission.js +3 -2
- package/dist/core/ownership/owner-resolver.js +25 -23
- package/dist/core/permission/ec-command-parser.js +138 -5
- package/dist/core/permission/sandbox-runtime.js +18 -1
- package/dist/core/permission/tool-policy.js +42 -10
- package/dist/core/relation/peer-identity.js +64 -1
- package/dist/core/role/runtime-policy.js +72 -13
- package/dist/core/session/session-capsule.js +197 -0
- package/dist/core/session/session-idle-monitor.js +1 -1
- package/dist/core/session/session-manager.js +168 -14
- package/dist/core/session/session-mapper.js +2 -0
- package/dist/core/session/session-renew.js +3 -3
- package/dist/core/skill/index-generator.js +15 -5
- package/dist/core/system-session/memory.js +6 -1
- package/dist/core/thread/thread-service.js +19 -6
- package/dist/directory/owner-directory-admission.js +95 -0
- package/dist/directory/owner-directory-authorization.js +309 -0
- package/dist/directory/owner-directory-cache.js +635 -0
- package/dist/eck/kit-renderer.js +2 -2
- package/dist/ecweb/basic-settings-service.js +33 -40
- package/dist/ecweb/message-context-service.js +110 -0
- package/dist/index.js +79 -17
- package/dist/ipc.js +189 -17
- package/dist/paths.js +4 -0
- package/dist/proxy/command.js +122 -0
- package/dist/proxy/ipc-service.js +68 -0
- package/dist/proxy/manager.js +485 -0
- package/dist/proxy/service-supervisor.js +603 -0
- package/dist/response-system/engines/v1/proactive-flow.js +16 -6
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +15 -0
- package/dist/stats/index.js +2 -2
- package/dist/stats/price-resolver.js +304 -5
- package/dist/stats/query.js +82 -3
- package/dist/stats/writer.js +38 -5
- package/dist/trigger/feedback.js +18 -7
- package/dist/trigger/manager.js +20 -3
- package/dist/trigger/parser.js +6 -3
- package/dist/trigger/patch.js +1 -1
- package/dist/trigger/system-definitions.js +43 -7
- package/dist/trigger/validation.js +13 -5
- package/dist/utils/cross-platform.js +14 -0
- package/dist/utils/ecweb-supervisor.js +258 -83
- package/dist/utils/error-utils.js +16 -2
- package/dist/utils/logger.js +24 -5
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +5 -3
- package/dist/utils/upgrade-jobs.js +45 -5
- package/kits/docs/INDEX.md +1 -1
- package/kits/docs/aun/ABILITY_CALLING.md +20 -2
- package/kits/docs/channels/aun.md +9 -0
- package/kits/docs/evolcore/INDEX.md +2 -1
- package/kits/docs/evolcore/agent-create.md +3 -2
- package/kits/docs/evolcore/agent.md +1 -1
- package/kits/docs/evolcore/config.md +18 -7
- package/kits/docs/evolcore/contact.md +3 -0
- package/kits/docs/evolcore/event.md +1 -0
- package/kits/docs/evolcore/fs.md +16 -0
- package/kits/docs/evolcore/memory-architecture.md +2 -2
- package/kits/docs/evolcore/memory-consolidation.md +32 -8
- package/kits/docs/evolcore/memory.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +36 -0
- package/kits/docs/evolcore/model.md +23 -20
- package/kits/docs/evolcore/msg.md +21 -8
- package/kits/docs/evolcore/session.md +14 -0
- package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
- package/kits/schemas/_meta.json +37 -4
- package/kits/schemas/agent-config.schema.13.json +23 -3
- package/kits/schemas/agent-config.schema.16.json +891 -0
- package/kits/schemas/daemon.schema.9.json +366 -0
- package/kits/schemas/defaults.schema.5.json +406 -127
- package/kits/schemas/relation-config.schema.11.json +260 -0
- package/kits/schemas/role-config.schema.1.json +7 -7
- package/kits/skills/.switches.json +3 -7
- package/kits/skills/aid-ability/SKILL.md +35 -6
- package/kits/skills/ec-service-proxy/SKILL.md +118 -0
- package/kits/skills/ec-trigger/SKILL.md +13 -5
- package/kits/skills/personal-assistant/SKILL.md +176 -0
- package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
- package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
- package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
- package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
- package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
- package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
- package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
- package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
- package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
- package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
- package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
- package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
- package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
- package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
- package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
- package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
- package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
- package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
- package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
- package/kits/templates/memory-consolidation/forget.md +19 -6
- package/kits/templates/memory-consolidation/notes.md +1 -1
- package/kits/templates/memory-consolidation/profile.md +2 -2
- package/kits/templates/memory-consolidation/promote.md +20 -3
- package/kits/templates/roles/member.json +8 -1
- package/kits/templates/session-capsule/recovery.md +5 -0
- package/kits/templates/session-capsule/renew.md +5 -0
- package/kits/templates/system-fragments/baseagent.md +2 -2
- package/kits/templates/system-fragments/bootstrap.md +6 -6
- package/kits/templates/system-fragments/channel.md +1 -1
- package/kits/templates/system-fragments/memory.md +4 -4
- package/package.json +7 -3
- package/dist/stats/billing.js +0 -215
|
@@ -34,7 +34,7 @@ export function seedUpgradeCheckTrigger(manager, owner) {
|
|
|
34
34
|
script: {
|
|
35
35
|
path: scriptName,
|
|
36
36
|
runtime: 'node',
|
|
37
|
-
timeoutMs: 60_000,
|
|
37
|
+
timeoutMs: 6 * 60_000,
|
|
38
38
|
},
|
|
39
39
|
permissionMode: 'bypass',
|
|
40
40
|
onError: 'fail',
|
|
@@ -47,7 +47,7 @@ export function seedUpgradeCheckTrigger(manager, owner) {
|
|
|
47
47
|
concurrency: 'forbid',
|
|
48
48
|
missedPolicy: 'run_once',
|
|
49
49
|
retry: {
|
|
50
|
-
maxAttempts:
|
|
50
|
+
maxAttempts: 1,
|
|
51
51
|
backoffMs: 30_000,
|
|
52
52
|
},
|
|
53
53
|
},
|
|
@@ -58,15 +58,51 @@ export function seedUpgradeCheckTrigger(manager, owner) {
|
|
|
58
58
|
const packageRoot = getPackageRoot();
|
|
59
59
|
fs.writeFileSync(scriptPath, `#!/usr/bin/env node
|
|
60
60
|
const { pathToFileURL } = require('node:url');
|
|
61
|
-
const
|
|
61
|
+
const { randomUUID } = require('node:crypto');
|
|
62
|
+
const packageRoot = ${JSON.stringify(packageRoot)};
|
|
63
|
+
const load = file => import(pathToFileURL(require('node:path').join(packageRoot, 'dist', file)).href);
|
|
62
64
|
async function main() {
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
const [versions, npm, config, upgrades, product] = await Promise.all([
|
|
66
|
+
load('utils/package-version-info.js'), load('utils/npm-ops.js'), load('config-store.js'),
|
|
67
|
+
load('utils/upgrade-jobs.js'), load('product.js'),
|
|
68
|
+
]);
|
|
69
|
+
const selection = await npm.resolveUpgradeRegistry();
|
|
70
|
+
const results = await versions.refreshManagedPackageVersions(undefined, { source: 'daily-check', selection });
|
|
71
|
+
const checkedAt = new Date().toISOString();
|
|
72
|
+
// Query stable separately so it never replaces the latest/test cache.
|
|
73
|
+
const linked = npm.isLinkedInstall();
|
|
74
|
+
const stable = linked ? null : await npm.queryPackageVersion(product.MAIN_PACKAGE_NAME, selection, undefined, 'stable');
|
|
75
|
+
let upgrade;
|
|
76
|
+
if (stable && config.loadDaemonConfig().upgrade?.autoOnStart !== false) {
|
|
77
|
+
const currentVersion = npm.getLocalVersion();
|
|
78
|
+
if (npm.comparePackageVersions(currentVersion, stable.version) < 0) {
|
|
79
|
+
const target = {
|
|
80
|
+
packageName: product.MAIN_PACKAGE_NAME, currentVersion, currentVersionObservedAt: checkedAt,
|
|
81
|
+
latestVersion: stable.version, checkedAt, registry: stable.registry, distTag: 'stable',
|
|
82
|
+
npmConfig: stable.npmConfig, lastAttemptStatus: 'ok', lastAttemptAt: checkedAt,
|
|
83
|
+
};
|
|
84
|
+
const started = await upgrades.startUpgradeJob(randomUUID(), '__upgrade-check', { stableTarget: target });
|
|
85
|
+
upgrade = started.job;
|
|
86
|
+
// Wait for the watchdog handoff before the script exits. The watchdog
|
|
87
|
+
// allows the result to be recorded before it shuts down the daemon.
|
|
88
|
+
while (['accepted', 'running'].includes(upgrade.status)) {
|
|
89
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
90
|
+
upgrade = upgrades.readUpgradeJob(upgrade.jobId);
|
|
91
|
+
if (!upgrade) throw new Error('Stable upgrade job disappeared');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const failed = results.some(result => result.status === 'unavailable') || (!linked && !stable)
|
|
96
|
+
|| (upgrade && ['failed', 'timeout'].includes(upgrade.status));
|
|
66
97
|
process.stdout.write(JSON.stringify({
|
|
67
98
|
outcome: failed ? 'error' : 'success',
|
|
68
|
-
text:
|
|
99
|
+
text: [
|
|
100
|
+
...results.map(result => result.packageName + ': ' + result.status),
|
|
101
|
+
product.MAIN_PACKAGE_NAME + '@stable: ' + (stable?.version || (linked ? 'skipped (development install)' : 'unavailable')),
|
|
102
|
+
...(upgrade ? ['stable upgrade: ' + upgrade.status + ' (' + upgrade.jobId + ')'] : []),
|
|
103
|
+
].join('; '),
|
|
69
104
|
files: [],
|
|
105
|
+
meta: { stableVersion: stable?.version || null, ...(upgrade ? { upgradeJobId: upgrade.jobId } : {}) },
|
|
70
106
|
}));
|
|
71
107
|
}
|
|
72
108
|
main().catch(() => {
|
|
@@ -252,7 +252,9 @@ function normalizeV3Phase2(raw, opts) {
|
|
|
252
252
|
source: normalizeSource(raw.source),
|
|
253
253
|
execution: normalizeExecution(raw.execution, { id }),
|
|
254
254
|
feedback: normalizeFeedback(raw.feedback, agentAid),
|
|
255
|
-
reliability: normalizeReliability(raw.reliability
|
|
255
|
+
reliability: normalizeReliability(raw.reliability, {
|
|
256
|
+
allowLegacyZeroRetryAttempts: opts.allowLegacyZeroRetryAttempts === true,
|
|
257
|
+
}),
|
|
256
258
|
limits: normalizeLimits(raw.limits),
|
|
257
259
|
};
|
|
258
260
|
// T10: labels 字典原样保留,只做类型校验(如果存在必须是 Record<string, string>)
|
|
@@ -650,9 +652,9 @@ function inferSessionKind(threadId, rawSession, label) {
|
|
|
650
652
|
}
|
|
651
653
|
return inferred;
|
|
652
654
|
}
|
|
653
|
-
function normalizeReliability(value) {
|
|
655
|
+
function normalizeReliability(value, opts = {}) {
|
|
654
656
|
if (value === undefined) {
|
|
655
|
-
return { concurrency: 'forbid', missedPolicy: 'run_once', retry: { maxAttempts:
|
|
657
|
+
return { concurrency: 'forbid', missedPolicy: 'run_once', retry: { maxAttempts: 1, backoffMs: 30_000 } };
|
|
656
658
|
}
|
|
657
659
|
if (!isObject(value))
|
|
658
660
|
throw new Error('reliability must be an object');
|
|
@@ -666,10 +668,16 @@ function normalizeReliability(value) {
|
|
|
666
668
|
throw new Error('reliability.missedPolicy is invalid');
|
|
667
669
|
}
|
|
668
670
|
const retryRaw = isObject(raw.retry) ? raw.retry : {};
|
|
669
|
-
|
|
671
|
+
let maxAttempts = optionalNumber(retryRaw.maxAttempts) ?? 1;
|
|
670
672
|
const backoffMs = optionalNumber(retryRaw.backoffMs) ?? 30_000;
|
|
671
673
|
if (!Number.isInteger(maxAttempts) || maxAttempts < 0 || maxAttempts > 20) {
|
|
672
|
-
throw new Error('reliability.retry.maxAttempts must be an integer between
|
|
674
|
+
throw new Error('reliability.retry.maxAttempts must be an integer between 1 and 20');
|
|
675
|
+
}
|
|
676
|
+
if (maxAttempts === 0) {
|
|
677
|
+
if (!opts.allowLegacyZeroRetryAttempts) {
|
|
678
|
+
throw new Error('reliability.retry.maxAttempts must be at least 1');
|
|
679
|
+
}
|
|
680
|
+
maxAttempts = 1;
|
|
673
681
|
}
|
|
674
682
|
if (!Number.isFinite(backoffMs) || backoffMs < 0) {
|
|
675
683
|
throw new Error('reliability.retry.backoffMs must be a non-negative number');
|
|
@@ -723,6 +723,20 @@ export function killProcess(pid, force = false) {
|
|
|
723
723
|
return !isProcessRunning(pid);
|
|
724
724
|
}
|
|
725
725
|
}
|
|
726
|
+
/** Terminate a detached process group where supported, falling back to one PID. */
|
|
727
|
+
export function killProcessTree(pid, force = false) {
|
|
728
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
729
|
+
return false;
|
|
730
|
+
if (isWindows)
|
|
731
|
+
return killProcess(pid, force);
|
|
732
|
+
try {
|
|
733
|
+
process.kill(-pid, force ? 'SIGKILL' : 'SIGTERM');
|
|
734
|
+
return true;
|
|
735
|
+
}
|
|
736
|
+
catch {
|
|
737
|
+
return killProcess(pid, force);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
726
740
|
/** Wait until a process has really disappeared from the host process table. */
|
|
727
741
|
export async function waitForProcessExit(pid, timeoutMs = 10_000, intervalMs = 250) {
|
|
728
742
|
const deadline = Date.now() + timeoutMs;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { spawn } from 'child_process';
|
|
4
|
-
import {
|
|
4
|
+
import { isDevMode, resolvePaths } from '../paths.js';
|
|
5
|
+
import { SERVICE_HEALTH_INTERVALS, SERVICE_RESTART_BACKOFF_MS, SERVICE_RESTART_MAX_ATTEMPTS, SERVICE_RESTART_WINDOW_MS, } from '../config/daemon-services.js';
|
|
5
6
|
import { WEB_PACKAGE_NAME } from '../product.js';
|
|
6
7
|
import { resolveGlobalPkg } from './npm-ops.js';
|
|
7
8
|
import { ecwebVersionRequirementError, resolveEcwebLaunchCommand } from './ecweb-utils.js';
|
|
8
9
|
import * as platform from './cross-platform.js';
|
|
9
|
-
import { getProcessStartTime } from './process-introspect.js';
|
|
10
|
+
import { getProcessStartTime, startTimeMatches } from './process-introspect.js';
|
|
11
|
+
import { matchesEcwebInstanceHealth, parseEcwebInstanceRecord } from '../contracts/ecweb-instance.js';
|
|
10
12
|
const INSTANCE_FILE_RE = /^(?:ecweb|watch-web)-\d+\.json$/;
|
|
11
13
|
function sleep(ms) {
|
|
12
14
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
@@ -37,17 +39,9 @@ function readEntries() {
|
|
|
37
39
|
continue;
|
|
38
40
|
const filePath = path.join(dir, file);
|
|
39
41
|
try {
|
|
40
|
-
const
|
|
41
|
-
if (
|
|
42
|
-
entries.push({
|
|
43
|
-
filePath,
|
|
44
|
-
record: {
|
|
45
|
-
pid: value.pid,
|
|
46
|
-
port: Number.isInteger(value.port) ? value.port : 42705,
|
|
47
|
-
...(typeof value.startedAt === 'number' ? { startedAt: value.startedAt } : {}),
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
}
|
|
42
|
+
const record = parseEcwebInstanceRecord(JSON.parse(fs.readFileSync(filePath, 'utf8')), resolvePaths().root, file);
|
|
43
|
+
if (record)
|
|
44
|
+
entries.push({ filePath, record });
|
|
51
45
|
}
|
|
52
46
|
catch {
|
|
53
47
|
// A partially-written instance file is ignored until the next check.
|
|
@@ -67,17 +61,14 @@ function removeEntriesForPid(pid) {
|
|
|
67
61
|
removeEntry(entry);
|
|
68
62
|
}
|
|
69
63
|
}
|
|
70
|
-
async function probe(
|
|
64
|
+
async function probe(record) {
|
|
71
65
|
try {
|
|
72
|
-
const response = await fetch(`http://127.0.0.1:${port}/api/health`, {
|
|
66
|
+
const response = await fetch(`http://127.0.0.1:${record.port}/api/health`, {
|
|
73
67
|
signal: AbortSignal.timeout(1500),
|
|
74
68
|
});
|
|
75
69
|
if (!response.ok)
|
|
76
70
|
return false;
|
|
77
|
-
|
|
78
|
-
return health.ok === true
|
|
79
|
-
&& health.service === 'ecweb'
|
|
80
|
-
&& health.daemonProtocolCompatible === true;
|
|
71
|
+
return matchesEcwebInstanceHealth(await response.json(), record);
|
|
81
72
|
}
|
|
82
73
|
catch {
|
|
83
74
|
return false;
|
|
@@ -93,15 +84,29 @@ async function probe(port) {
|
|
|
93
84
|
*/
|
|
94
85
|
export function createEcwebSupervisor(options) {
|
|
95
86
|
const failureThreshold = Math.max(1, options.failureThreshold ?? 3);
|
|
96
|
-
|
|
87
|
+
let desiredPort = options.port;
|
|
88
|
+
let desiredEnabled = options.enabled ?? true;
|
|
89
|
+
let runtimeMode = options.runtimeMode ?? 'managed';
|
|
90
|
+
let restartConfig = options.restart;
|
|
97
91
|
let active = null;
|
|
98
92
|
let child = null;
|
|
99
93
|
let logFd = null;
|
|
100
94
|
let timer = null;
|
|
101
95
|
let failureCount = 0;
|
|
96
|
+
let healthy = false;
|
|
102
97
|
let startInFlight = null;
|
|
103
98
|
let childStartedAt = 0;
|
|
104
99
|
let stopping = false;
|
|
100
|
+
let checkInFlight = null;
|
|
101
|
+
let startup = null;
|
|
102
|
+
let restartInFlight = null;
|
|
103
|
+
let recoveryTimer = null;
|
|
104
|
+
let recoveryAttempts = [];
|
|
105
|
+
let recoveryExhausted = false;
|
|
106
|
+
let intentionalStop = false;
|
|
107
|
+
let launchRequested = false;
|
|
108
|
+
let hasBeenReady = false;
|
|
109
|
+
let configureQueue = Promise.resolve();
|
|
105
110
|
const logFile = path.join(resolvePaths().logs, 'ecweb-daemon.log');
|
|
106
111
|
const setActiveFromEntry = (entry, owned) => {
|
|
107
112
|
active = {
|
|
@@ -120,7 +125,15 @@ export function createEcwebSupervisor(options) {
|
|
|
120
125
|
removeEntry(entry);
|
|
121
126
|
continue;
|
|
122
127
|
}
|
|
123
|
-
|
|
128
|
+
const actual = getProcessStartTime(entry.record.pid);
|
|
129
|
+
if (actual !== null && entry.record.startedAt !== undefined
|
|
130
|
+
&& (entry.record.schemaVersion === 1 ? Math.abs(actual - entry.record.startedAt) >= 2000 : actual - entry.record.startedAt > 2000)) {
|
|
131
|
+
removeEntry(entry);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (entry.record.port !== desiredPort)
|
|
135
|
+
continue;
|
|
136
|
+
if (await probe(entry.record))
|
|
124
137
|
return entry;
|
|
125
138
|
}
|
|
126
139
|
return null;
|
|
@@ -133,7 +146,7 @@ export function createEcwebSupervisor(options) {
|
|
|
133
146
|
return found;
|
|
134
147
|
if (Date.now() >= deadline)
|
|
135
148
|
break;
|
|
136
|
-
await sleep(
|
|
149
|
+
await sleep(SERVICE_HEALTH_INTERVALS.http.startup);
|
|
137
150
|
} while (!stopping);
|
|
138
151
|
return null;
|
|
139
152
|
};
|
|
@@ -147,6 +160,7 @@ export function createEcwebSupervisor(options) {
|
|
|
147
160
|
logFd = null;
|
|
148
161
|
};
|
|
149
162
|
const killActive = async () => {
|
|
163
|
+
intentionalStop = true;
|
|
150
164
|
const current = active;
|
|
151
165
|
if (!current) {
|
|
152
166
|
// During the short window between spawn() and ECWeb writing its
|
|
@@ -160,15 +174,15 @@ export function createEcwebSupervisor(options) {
|
|
|
160
174
|
catch { }
|
|
161
175
|
await platform.waitForProcessExit(pendingPid, 5000);
|
|
162
176
|
}
|
|
177
|
+
child = null;
|
|
178
|
+
healthy = false;
|
|
163
179
|
return;
|
|
164
180
|
}
|
|
165
181
|
const actual = getProcessStartTime(current.pid);
|
|
166
182
|
// Never kill a reused PID. `startedAt` was captured from the live process
|
|
167
183
|
// when it was adopted/spawned, so this remains safe even for legacy records
|
|
168
184
|
// whose on-disk timestamp used a different clock.
|
|
169
|
-
const sameProcess = current.startedAt !== null && actual
|
|
170
|
-
? current.startedAt === actual
|
|
171
|
-
: false;
|
|
185
|
+
const sameProcess = current.startedAt !== null && startTimeMatches(current.startedAt, actual);
|
|
172
186
|
if (sameProcess && platform.isProcessRunning(current.pid)) {
|
|
173
187
|
try {
|
|
174
188
|
platform.killProcess(current.pid, true);
|
|
@@ -178,12 +192,16 @@ export function createEcwebSupervisor(options) {
|
|
|
178
192
|
}
|
|
179
193
|
removeEntriesForPid(current.pid);
|
|
180
194
|
active = null;
|
|
195
|
+
child = null;
|
|
196
|
+
healthy = false;
|
|
181
197
|
};
|
|
182
198
|
const spawnEcweb = async () => {
|
|
199
|
+
intentionalStop = false;
|
|
200
|
+
hasBeenReady = false;
|
|
183
201
|
const root = resolvePaths().root;
|
|
184
202
|
const localEntry = path.join(root, 'ecweb', 'dist', 'index.js');
|
|
185
203
|
const globalPkg = resolveGlobalPkg(WEB_PACKAGE_NAME);
|
|
186
|
-
let launch = resolveEcwebLaunchCommand(['--home', root, '--port', String(
|
|
204
|
+
let launch = resolveEcwebLaunchCommand(['--home', root, '--port', String(desiredPort)], {
|
|
187
205
|
installedPkg: globalPkg,
|
|
188
206
|
});
|
|
189
207
|
let cwd = root;
|
|
@@ -194,7 +212,7 @@ export function createEcwebSupervisor(options) {
|
|
|
194
212
|
if (!launch && isDevMode() && fs.existsSync(localEntry)) {
|
|
195
213
|
launch = {
|
|
196
214
|
command: process.execPath,
|
|
197
|
-
args: [localEntry, '--home', root, '--port', String(
|
|
215
|
+
args: [localEntry, '--home', root, '--port', String(desiredPort)],
|
|
198
216
|
entry: localEntry,
|
|
199
217
|
source: 'package-bin',
|
|
200
218
|
};
|
|
@@ -206,11 +224,15 @@ export function createEcwebSupervisor(options) {
|
|
|
206
224
|
}
|
|
207
225
|
if (!launch) {
|
|
208
226
|
options.logger.warn('ECWeb 启动入口不存在,请重新安装包含匹配 ECWeb 的 EvolCore 版本。');
|
|
227
|
+
failureCount = failureThreshold;
|
|
228
|
+
scheduleRecovery();
|
|
209
229
|
return;
|
|
210
230
|
}
|
|
211
231
|
const versionError = ecwebVersionRequirementError(version);
|
|
212
232
|
if (versionError) {
|
|
213
233
|
options.logger.error(`ECWeb 未启动: ${versionError}`);
|
|
234
|
+
failureCount = failureThreshold;
|
|
235
|
+
scheduleRecovery();
|
|
214
236
|
return;
|
|
215
237
|
}
|
|
216
238
|
fs.mkdirSync(resolvePaths().logs, { recursive: true });
|
|
@@ -227,14 +249,9 @@ export function createEcwebSupervisor(options) {
|
|
|
227
249
|
detached: true,
|
|
228
250
|
stdio: ['ignore', childLogFd, childLogFd],
|
|
229
251
|
windowsHide: platform.isWindows,
|
|
230
|
-
// Keep the runtime home and package root aligned with this daemon.
|
|
231
|
-
// The service protocol is the runtime boundary; package-root pinning
|
|
232
|
-
// remains useful for development-only compatibility code and static
|
|
233
|
-
// asset resolution.
|
|
234
252
|
env: {
|
|
235
253
|
...process.env,
|
|
236
254
|
EVOLCORE_HOME: root,
|
|
237
|
-
EVOLCORE_PACKAGE_ROOT: getPackageRoot(),
|
|
238
255
|
EVOLCORE_ECWEB_SUPERVISED: '1',
|
|
239
256
|
},
|
|
240
257
|
});
|
|
@@ -242,6 +259,8 @@ export function createEcwebSupervisor(options) {
|
|
|
242
259
|
catch (error) {
|
|
243
260
|
closeLogStream();
|
|
244
261
|
options.logger.error(`ECWeb 子进程创建失败: ${error?.message || error}`);
|
|
262
|
+
failureCount = failureThreshold;
|
|
263
|
+
scheduleRecovery();
|
|
245
264
|
return;
|
|
246
265
|
}
|
|
247
266
|
closeLogStream();
|
|
@@ -249,16 +268,23 @@ export function createEcwebSupervisor(options) {
|
|
|
249
268
|
childStartedAt = Date.now();
|
|
250
269
|
spawned.once('error', (error) => {
|
|
251
270
|
options.logger.error(`ECWeb 子进程创建失败: ${error.message}`);
|
|
271
|
+
if (child !== spawned || intentionalStop || stopping)
|
|
272
|
+
return;
|
|
273
|
+
failureCount = failureThreshold;
|
|
274
|
+
scheduleRecovery();
|
|
252
275
|
});
|
|
253
276
|
spawned.once('exit', (code, signal) => {
|
|
254
277
|
options.logger.warn(`ECWeb 进程退出 (PID: ${spawned.pid ?? 'unknown'}, code=${code ?? 'null'}, signal=${signal ?? 'null'})`);
|
|
255
278
|
if (child === spawned) {
|
|
256
279
|
child = null;
|
|
257
280
|
childStartedAt = 0;
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
281
|
+
healthy = false;
|
|
282
|
+
if (!stopping && !intentionalStop) {
|
|
283
|
+
if (active?.pid === spawned.pid)
|
|
284
|
+
active = null;
|
|
285
|
+
failureCount = failureThreshold;
|
|
286
|
+
scheduleRecovery();
|
|
287
|
+
}
|
|
262
288
|
}
|
|
263
289
|
closeLogStream();
|
|
264
290
|
});
|
|
@@ -275,79 +301,228 @@ export function createEcwebSupervisor(options) {
|
|
|
275
301
|
// latency while ServiceProxy continues to wait for the instance file.
|
|
276
302
|
};
|
|
277
303
|
const ensureRunning = async () => {
|
|
278
|
-
if (stopping || startInFlight)
|
|
304
|
+
if (stopping || !desiredEnabled || runtimeMode !== 'managed' || startInFlight)
|
|
279
305
|
return;
|
|
280
|
-
//
|
|
281
|
-
//
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
if (
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
if (healthy) {
|
|
290
|
-
const changed = !active || active.pid !== healthy.record.pid || active.port !== healthy.record.port;
|
|
291
|
-
setActiveFromEntry(healthy, active?.pid === healthy.record.pid ? active.owned : false);
|
|
306
|
+
// Allow the child to bind and publish its instance record before treating
|
|
307
|
+
// it as crashed. Daemon readiness is not required for HTTP liveness.
|
|
308
|
+
const instance = await findHealthyInstance();
|
|
309
|
+
healthy = instance !== null;
|
|
310
|
+
if (instance) {
|
|
311
|
+
launchRequested = false;
|
|
312
|
+
cancelRecovery();
|
|
313
|
+
const changed = !active || active.pid !== instance.record.pid || active.port !== instance.record.port;
|
|
314
|
+
setActiveFromEntry(instance, active?.pid === instance.record.pid ? active.owned : false);
|
|
292
315
|
failureCount = 0;
|
|
316
|
+
hasBeenReady = true;
|
|
293
317
|
if (changed)
|
|
294
|
-
options.logger.info(`✓ ECWeb supervisor 接管现有实例 (PID: ${
|
|
318
|
+
options.logger.info(`✓ ECWeb supervisor 接管现有实例 (PID: ${instance.record.pid}, 端口: ${instance.record.port})`);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (!launchRequested && !hasBeenReady && child?.pid && platform.isProcessRunning(child.pid)
|
|
322
|
+
&& Date.now() - childStartedAt < 45_000)
|
|
323
|
+
return;
|
|
324
|
+
if (launchRequested) {
|
|
325
|
+
launchRequested = false;
|
|
326
|
+
startInFlight = (async () => {
|
|
327
|
+
await killActive();
|
|
328
|
+
await spawnEcweb();
|
|
329
|
+
})().finally(() => { startInFlight = null; });
|
|
330
|
+
await startInFlight;
|
|
295
331
|
return;
|
|
296
332
|
}
|
|
297
333
|
failureCount += 1;
|
|
298
334
|
if (failureCount < failureThreshold)
|
|
299
335
|
return;
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
if (
|
|
304
|
-
|
|
305
|
-
|
|
336
|
+
scheduleRecovery();
|
|
337
|
+
};
|
|
338
|
+
const check = () => {
|
|
339
|
+
if (checkInFlight)
|
|
340
|
+
return checkInFlight;
|
|
341
|
+
checkInFlight = ensureRunning().finally(() => { checkInFlight = null; });
|
|
342
|
+
return checkInFlight;
|
|
343
|
+
};
|
|
344
|
+
const cancelRecovery = () => {
|
|
345
|
+
if (recoveryTimer)
|
|
346
|
+
clearTimeout(recoveryTimer);
|
|
347
|
+
recoveryTimer = null;
|
|
348
|
+
};
|
|
349
|
+
const scheduleRecovery = () => {
|
|
350
|
+
if (stopping || intentionalStop || !desiredEnabled || runtimeMode !== 'managed'
|
|
351
|
+
|| restartConfig?.enabled === false || recoveryTimer || recoveryExhausted)
|
|
352
|
+
return;
|
|
353
|
+
const now = Date.now();
|
|
354
|
+
recoveryAttempts = recoveryAttempts.filter(timestamp => now - timestamp <= SERVICE_RESTART_WINDOW_MS);
|
|
355
|
+
if (recoveryAttempts.length >= SERVICE_RESTART_MAX_ATTEMPTS) {
|
|
356
|
+
recoveryExhausted = true;
|
|
357
|
+
options.logger.error('ECWeb 自动恢复已达到 15 分钟内 3 次上限,请修复后 reset-failure');
|
|
306
358
|
return;
|
|
307
359
|
}
|
|
308
|
-
|
|
360
|
+
recoveryAttempts.push(now);
|
|
361
|
+
const delay = (restartConfig?.backoffMs ?? SERVICE_RESTART_BACKOFF_MS) * (2 ** (recoveryAttempts.length - 1));
|
|
362
|
+
recoveryTimer = setTimeout(() => {
|
|
363
|
+
recoveryTimer = null;
|
|
364
|
+
if (stopping || !desiredEnabled || runtimeMode !== 'managed' || restartConfig?.enabled === false)
|
|
365
|
+
return;
|
|
366
|
+
launchRequested = true;
|
|
367
|
+
void check().catch(error => options.logger.error('ECWeb 自动恢复失败: ' + String(error)));
|
|
368
|
+
}, delay);
|
|
369
|
+
recoveryTimer.unref?.();
|
|
370
|
+
};
|
|
371
|
+
const restart = async () => {
|
|
372
|
+
if (runtimeMode !== 'managed')
|
|
373
|
+
throw Object.assign(new Error('ECWeb is external'), { code: 'EXTERNAL_SERVICE_UNMANAGED' });
|
|
374
|
+
if (!desiredEnabled || stopping)
|
|
375
|
+
throw Object.assign(new Error('ECWeb is disabled'), { code: 'SERVICE_NOT_ENABLED' });
|
|
376
|
+
if (restartInFlight)
|
|
377
|
+
return restartInFlight;
|
|
378
|
+
restartInFlight = (async () => {
|
|
379
|
+
cancelRecovery();
|
|
380
|
+
if (checkInFlight)
|
|
381
|
+
await checkInFlight.catch(() => { });
|
|
382
|
+
if (startInFlight)
|
|
383
|
+
await startInFlight.catch(() => { });
|
|
309
384
|
await killActive();
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
385
|
+
failureCount = failureThreshold;
|
|
386
|
+
launchRequested = true;
|
|
387
|
+
await check();
|
|
388
|
+
})().finally(() => { restartInFlight = null; });
|
|
389
|
+
return restartInFlight;
|
|
390
|
+
};
|
|
391
|
+
const scheduleCheck = () => {
|
|
392
|
+
if (stopping)
|
|
393
|
+
return;
|
|
394
|
+
const interval = active || hasBeenReady ? SERVICE_HEALTH_INTERVALS.http.running : SERVICE_HEALTH_INTERVALS.http.startup;
|
|
395
|
+
timer = setTimeout(() => {
|
|
396
|
+
timer = null;
|
|
397
|
+
void check().catch((error) => {
|
|
398
|
+
options.logger.error(`ECWeb watchdog 检查失败: ${error?.message || error}`);
|
|
399
|
+
}).finally(scheduleCheck);
|
|
400
|
+
}, desiredEnabled && runtimeMode === 'managed' ? interval : SERVICE_HEALTH_INTERVALS.http.running);
|
|
401
|
+
timer.unref?.();
|
|
402
|
+
};
|
|
403
|
+
const start = async () => {
|
|
404
|
+
if (stopping)
|
|
405
|
+
return;
|
|
406
|
+
if (!desiredEnabled || runtimeMode !== 'managed') {
|
|
407
|
+
scheduleCheck();
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
// Give an independently started ECWeb time to publish its instance record.
|
|
411
|
+
const existing = await waitForHealthyInstance(1_500);
|
|
412
|
+
if (stopping)
|
|
413
|
+
return;
|
|
414
|
+
if (existing) {
|
|
415
|
+
healthy = true;
|
|
416
|
+
hasBeenReady = true;
|
|
417
|
+
setActiveFromEntry(existing, false);
|
|
418
|
+
options.logger.info(`✓ ECWeb supervisor 接管现有实例 (PID: ${existing.record.pid}, 端口: ${existing.record.port})`);
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
failureCount = failureThreshold;
|
|
422
|
+
launchRequested = true;
|
|
423
|
+
await check();
|
|
424
|
+
}
|
|
425
|
+
if (stopping)
|
|
426
|
+
return;
|
|
427
|
+
scheduleCheck();
|
|
428
|
+
};
|
|
429
|
+
const configure = async (config) => {
|
|
430
|
+
if (stopping)
|
|
431
|
+
return;
|
|
432
|
+
const portChanged = config.port !== desiredPort;
|
|
433
|
+
const enabledChanged = config.enabled !== desiredEnabled;
|
|
434
|
+
const nextMode = config.runtimeMode ?? 'managed';
|
|
435
|
+
const modeChanged = nextMode !== runtimeMode;
|
|
436
|
+
const recoveryChanged = JSON.stringify(config.restart) !== JSON.stringify(restartConfig);
|
|
437
|
+
desiredEnabled = config.enabled;
|
|
438
|
+
desiredPort = config.port;
|
|
439
|
+
runtimeMode = nextMode;
|
|
440
|
+
restartConfig = config.restart;
|
|
441
|
+
if (!enabledChanged && !portChanged && !modeChanged && !recoveryChanged)
|
|
442
|
+
return;
|
|
443
|
+
cancelRecovery();
|
|
444
|
+
if (checkInFlight)
|
|
445
|
+
await checkInFlight.catch(() => { });
|
|
446
|
+
if (startInFlight)
|
|
447
|
+
await startInFlight.catch(() => { });
|
|
448
|
+
if (restartInFlight)
|
|
449
|
+
await restartInFlight.catch(() => { });
|
|
450
|
+
if (stopping)
|
|
451
|
+
return;
|
|
452
|
+
if (runtimeMode === 'external') {
|
|
453
|
+
child?.removeAllListeners();
|
|
454
|
+
child = null;
|
|
455
|
+
active = null;
|
|
456
|
+
healthy = false;
|
|
457
|
+
}
|
|
458
|
+
else if (enabledChanged || portChanged || modeChanged) {
|
|
459
|
+
await killActive();
|
|
460
|
+
recoveryAttempts = [];
|
|
461
|
+
recoveryExhausted = false;
|
|
462
|
+
failureCount = desiredEnabled ? failureThreshold : 0;
|
|
463
|
+
launchRequested = desiredEnabled;
|
|
464
|
+
if (desiredEnabled && !stopping)
|
|
465
|
+
await check();
|
|
466
|
+
}
|
|
467
|
+
else if (restartConfig?.enabled !== false && !healthy && failureCount >= failureThreshold) {
|
|
468
|
+
intentionalStop = false;
|
|
469
|
+
scheduleRecovery();
|
|
470
|
+
}
|
|
471
|
+
if (timer)
|
|
472
|
+
clearTimeout(timer);
|
|
473
|
+
timer = null;
|
|
474
|
+
scheduleCheck();
|
|
314
475
|
};
|
|
315
476
|
return {
|
|
316
|
-
|
|
317
|
-
if (
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
477
|
+
start() {
|
|
478
|
+
if (!startup)
|
|
479
|
+
startup = start();
|
|
480
|
+
return startup;
|
|
481
|
+
},
|
|
482
|
+
configure(config) {
|
|
483
|
+
configureQueue = configureQueue.then(() => configure(config), () => configure(config));
|
|
484
|
+
return configureQueue;
|
|
485
|
+
},
|
|
486
|
+
restart,
|
|
487
|
+
async resetFailure() {
|
|
488
|
+
recoveryAttempts = [];
|
|
489
|
+
recoveryExhausted = false;
|
|
490
|
+
if (!healthy)
|
|
491
|
+
await restart();
|
|
492
|
+
},
|
|
493
|
+
status() {
|
|
494
|
+
const running = active && platform.isProcessRunning(active.pid);
|
|
495
|
+
const ready = running && healthy && active.port === desiredPort;
|
|
496
|
+
return {
|
|
497
|
+
enabled: desiredEnabled,
|
|
498
|
+
port: desiredPort,
|
|
499
|
+
state: !desiredEnabled ? 'disabled' : ready ? 'ready' : failureCount >= failureThreshold ? 'failed' : 'starting',
|
|
500
|
+
...(running ? { pid: active.pid } : {}),
|
|
501
|
+
};
|
|
336
502
|
},
|
|
337
503
|
async stop() {
|
|
338
504
|
if (stopping)
|
|
339
505
|
return;
|
|
340
506
|
stopping = true;
|
|
507
|
+
cancelRecovery();
|
|
341
508
|
if (timer)
|
|
342
|
-
|
|
509
|
+
clearTimeout(timer);
|
|
343
510
|
timer = null;
|
|
511
|
+
if (startup)
|
|
512
|
+
await startup.catch(() => { });
|
|
513
|
+
if (checkInFlight)
|
|
514
|
+
await checkInFlight.catch(() => { });
|
|
515
|
+
if (restartInFlight)
|
|
516
|
+
await restartInFlight.catch(() => { });
|
|
517
|
+
await configureQueue.catch(() => { });
|
|
344
518
|
if (startInFlight) {
|
|
345
519
|
try {
|
|
346
520
|
await startInFlight;
|
|
347
521
|
}
|
|
348
522
|
catch { }
|
|
349
523
|
}
|
|
350
|
-
|
|
524
|
+
if (runtimeMode === 'managed')
|
|
525
|
+
await killActive();
|
|
351
526
|
if (child) {
|
|
352
527
|
try {
|
|
353
528
|
child.removeAllListeners();
|