@mindexec/cli 0.2.164 → 0.2.165
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/package.json +1 -1
- package/server.js +62 -1
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -2045,6 +2045,7 @@ app.post('/api/auth/session', async (req, res) => {
|
|
|
2045
2045
|
const content = req.body?.content;
|
|
2046
2046
|
await writeStableAuthSessionPayload(content);
|
|
2047
2047
|
await wakeRemoteRegistryFollower('auth-session-saved');
|
|
2048
|
+
scheduleRemoteHostTargetRenewWake('auth-session-saved', { throttleMs: 0 });
|
|
2048
2049
|
res.json({
|
|
2049
2050
|
success: true
|
|
2050
2051
|
});
|
|
@@ -3351,6 +3352,7 @@ const REMOTE_AGENT_EARLY_EXIT_MS = 1200;
|
|
|
3351
3352
|
const REMOTE_AGENT_READY_TIMEOUT_MS = 5000;
|
|
3352
3353
|
const REMOTE_AGENT_DEFAULT_ENGINE = 'auto';
|
|
3353
3354
|
const REMOTE_AGENT_SYNC_REPORT_LOG_REPEAT_MS = 30000;
|
|
3355
|
+
const REMOTE_AGENT_SYNC_REPORT_WAKE_MS = Math.max(500, Number(process.env.MINDEXEC_REMOTE_AGENT_SYNC_REPORT_WAKE_MS || 1500) || 1500);
|
|
3354
3356
|
const REMOTE_AGENT_RACE_START_STAGGER_MS = Math.max(0, Number(process.env.MINDEXEC_REMOTE_AGENT_RACE_STAGGER_MS ?? 0) || 0);
|
|
3355
3357
|
const REMOTE_AGENT_MAX_PARALLEL_CANDIDATES = 6;
|
|
3356
3358
|
const REMOTE_AGENT_RECENT_MANAGER_CACHE_TTL_MS = 30 * 24 * 60 * 60 * 1000;
|
|
@@ -3376,6 +3378,7 @@ const REMOTE_HOST_TARGET_RENEW_MS = Math.max(
|
|
|
3376
3378
|
Math.floor(REMOTE_HOST_TARGET_LEASE_MS / 2),
|
|
3377
3379
|
Number(process.env.MINDEXEC_REMOTE_HOST_TARGET_RENEW_MS || 25000) || 25000));
|
|
3378
3380
|
const REMOTE_HOST_TARGET_RENEW_LOG_REPEAT_MS = 60000;
|
|
3381
|
+
const REMOTE_HOST_TARGET_WAKE_RENEW_MS = Math.max(3000, Number(process.env.MINDEXEC_REMOTE_HOST_TARGET_WAKE_RENEW_MS || 5000) || 5000);
|
|
3379
3382
|
const REMOTE_SYSTEM_RESUME_CHECK_MS = Math.max(1000, Number(process.env.MINDEXEC_REMOTE_RESUME_CHECK_MS || 5000) || 5000);
|
|
3380
3383
|
const REMOTE_SYSTEM_RESUME_DRIFT_MS = Math.max(
|
|
3381
3384
|
REMOTE_SYSTEM_RESUME_CHECK_MS + 5000,
|
|
@@ -3384,6 +3387,7 @@ let remoteAgentState = createRemoteAgentIdleState();
|
|
|
3384
3387
|
let remoteAgentSyncReportState = null;
|
|
3385
3388
|
let remoteAgentSyncReportLogKey = '';
|
|
3386
3389
|
let remoteAgentSyncReportLogAt = 0;
|
|
3390
|
+
let remoteAgentSyncReportWakeAt = 0;
|
|
3387
3391
|
let remoteAgentConnectPromise = null;
|
|
3388
3392
|
const remoteAgentIntentionalStopKeys = new Set();
|
|
3389
3393
|
const remoteAgentRecentSuccessfulManagers = new Map();
|
|
@@ -3409,6 +3413,7 @@ let remoteHostTargetRenewTimer = null;
|
|
|
3409
3413
|
let remoteHostTargetRenewInFlight = false;
|
|
3410
3414
|
let remoteHostTargetRenewLogKey = '';
|
|
3411
3415
|
let remoteHostTargetRenewLogAt = 0;
|
|
3416
|
+
let remoteHostTargetWakeRenewAt = 0;
|
|
3412
3417
|
let remoteSystemResumeTimer = null;
|
|
3413
3418
|
let remoteSystemResumeExpectedAt = 0;
|
|
3414
3419
|
let remoteSystemResumeInFlight = false;
|
|
@@ -5966,6 +5971,60 @@ async function wakeRemoteRegistryFollower(reason = 'wake') {
|
|
|
5966
5971
|
scheduleRemoteRegistryFollower(0, reason);
|
|
5967
5972
|
}
|
|
5968
5973
|
|
|
5974
|
+
function scheduleRemoteHostTargetRenewWake(reason = 'wake', options = {}) {
|
|
5975
|
+
if (!isLocalRemoteHostTargetActive()) {
|
|
5976
|
+
return false;
|
|
5977
|
+
}
|
|
5978
|
+
|
|
5979
|
+
const throttleMs = Math.max(0, Number(options.throttleMs ?? REMOTE_HOST_TARGET_WAKE_RENEW_MS) || 0);
|
|
5980
|
+
const now = Date.now();
|
|
5981
|
+
if (throttleMs > 0 && now - remoteHostTargetWakeRenewAt < throttleMs) {
|
|
5982
|
+
return false;
|
|
5983
|
+
}
|
|
5984
|
+
|
|
5985
|
+
remoteHostTargetWakeRenewAt = now;
|
|
5986
|
+
const wakeReason = safeRemoteAgentField(reason, 80) || 'wake';
|
|
5987
|
+
const timer = setTimeout(() => {
|
|
5988
|
+
runRemoteHostTargetRenewOnce(wakeReason, { takeover: options.takeover === true })
|
|
5989
|
+
.catch(error => {
|
|
5990
|
+
logWarn(
|
|
5991
|
+
'remote',
|
|
5992
|
+
`host target renew wake failed ${formatKeyValue('reason', wakeReason)} ${formatKeyValue('error', error?.message || String(error || ''))}`);
|
|
5993
|
+
});
|
|
5994
|
+
}, 0);
|
|
5995
|
+
timer?.unref?.();
|
|
5996
|
+
return true;
|
|
5997
|
+
}
|
|
5998
|
+
|
|
5999
|
+
function scheduleRemoteRegistryWakeFromSyncReport(report) {
|
|
6000
|
+
if (!report?.authenticated) {
|
|
6001
|
+
return {
|
|
6002
|
+
follower: false,
|
|
6003
|
+
hostRenew: false,
|
|
6004
|
+
reason: 'not-authenticated'
|
|
6005
|
+
};
|
|
6006
|
+
}
|
|
6007
|
+
|
|
6008
|
+
const now = Date.now();
|
|
6009
|
+
let follower = false;
|
|
6010
|
+
if (now - remoteAgentSyncReportWakeAt >= REMOTE_AGENT_SYNC_REPORT_WAKE_MS) {
|
|
6011
|
+
remoteAgentSyncReportWakeAt = now;
|
|
6012
|
+
follower = true;
|
|
6013
|
+
wakeRemoteRegistryFollower('agent-sync-report')
|
|
6014
|
+
.catch(error => {
|
|
6015
|
+
logWarn(
|
|
6016
|
+
'remote',
|
|
6017
|
+
`registry follower wake failed ${formatKeyValue('reason', 'agent-sync-report')} ${formatKeyValue('error', error?.message || String(error || ''))}`);
|
|
6018
|
+
});
|
|
6019
|
+
}
|
|
6020
|
+
|
|
6021
|
+
return {
|
|
6022
|
+
follower,
|
|
6023
|
+
hostRenew: scheduleRemoteHostTargetRenewWake('agent-sync-report'),
|
|
6024
|
+
reason: 'ok'
|
|
6025
|
+
};
|
|
6026
|
+
}
|
|
6027
|
+
|
|
5969
6028
|
async function runRemoteRegistryFollowerOnce(trigger = 'timer') {
|
|
5970
6029
|
if (!REMOTE_REGISTRY_FOLLOWER_ENABLED || remoteRegistryFollowerInFlight) {
|
|
5971
6030
|
return serializeRemoteRegistryFollowerState();
|
|
@@ -6112,6 +6171,7 @@ async function runRemoteRegistryFollowerOnce(trigger = 'timer') {
|
|
|
6112
6171
|
localHostTargetLeaseId: localHub.hostTargetLeaseId,
|
|
6113
6172
|
localHostTargetNodeId: localHub.hostTargetNodeId
|
|
6114
6173
|
});
|
|
6174
|
+
scheduleRemoteHostTargetRenewWake('local-monitor-is-host');
|
|
6115
6175
|
scheduleRemoteRegistryFollower(REMOTE_REGISTRY_FOLLOWER_POLL_MS, 'local-host');
|
|
6116
6176
|
return serializeRemoteRegistryFollowerState();
|
|
6117
6177
|
}
|
|
@@ -10931,7 +10991,8 @@ app.post('/api/remote/agent/sync-report', (req, res) => {
|
|
|
10931
10991
|
res.setHeader('Cache-Control', 'no-store');
|
|
10932
10992
|
const report = createRemoteAgentSyncReport(req.body || {});
|
|
10933
10993
|
rememberRemoteAgentSyncReport(report);
|
|
10934
|
-
|
|
10994
|
+
const wake = scheduleRemoteRegistryWakeFromSyncReport(report);
|
|
10995
|
+
res.json({ ok: true, report, wake });
|
|
10935
10996
|
});
|
|
10936
10997
|
|
|
10937
10998
|
app.post('/api/remote/agent/connect', async (req, res) => {
|