@mindexec/cli 0.2.204 → 0.2.205
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 +82 -1
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -3771,6 +3771,24 @@ function isRemoteAgentOutputReconnectSignal(text) {
|
|
|
3771
3771
|
}
|
|
3772
3772
|
|
|
3773
3773
|
function rememberRemoteAgentSyncReport(report) {
|
|
3774
|
+
if (report?.authenticated !== true
|
|
3775
|
+
&& isRemoteAgentRegistryOwned()
|
|
3776
|
+
&& isRemoteAgentProcessRunning()
|
|
3777
|
+
&& /^(registry-auth-pending-agent-kept|registry-not-authenticated-agent-kept|session-expired-agent-kept)$/i.test(String(report.reason || ''))) {
|
|
3778
|
+
const now = Date.now();
|
|
3779
|
+
const key = `ignored-unauth|${report.reason || ''}|${remoteAgentState.manager || ''}|${remoteAgentState.leaseId || ''}`;
|
|
3780
|
+
if (key !== remoteAgentSyncReportLogKey
|
|
3781
|
+
|| now - remoteAgentSyncReportLogAt >= REMOTE_AGENT_SYNC_REPORT_LOG_REPEAT_MS) {
|
|
3782
|
+
remoteAgentSyncReportLogKey = key;
|
|
3783
|
+
remoteAgentSyncReportLogAt = now;
|
|
3784
|
+
logEvent(
|
|
3785
|
+
'remote',
|
|
3786
|
+
`registry sync ignored stale unauth report ${formatKeyValue('reason', report.reason || '-')} ${formatKeyValue('target', remoteAgentState.manager || '-')} ${formatKeyValue('auth', 'kept')}`,
|
|
3787
|
+
'remote');
|
|
3788
|
+
}
|
|
3789
|
+
return false;
|
|
3790
|
+
}
|
|
3791
|
+
|
|
3774
3792
|
remoteAgentSyncReportState = report;
|
|
3775
3793
|
const reason = report.reason || report.error || (report.ok ? 'ok' : 'failed');
|
|
3776
3794
|
const status = report.connected
|
|
@@ -3807,6 +3825,7 @@ function rememberRemoteAgentSyncReport(report) {
|
|
|
3807
3825
|
'remote',
|
|
3808
3826
|
`registry sync ${status} ${formatKeyValue('reason', reason)} ${formatKeyValue('target', report.targetEndpoint || '-')} ${formatKeyValue('auth', report.authenticated ? 'yes' : 'no')}`,
|
|
3809
3827
|
'remote');
|
|
3828
|
+
return true;
|
|
3810
3829
|
}
|
|
3811
3830
|
|
|
3812
3831
|
function appendRemoteAgentOutput(stream, chunk, stateConnectionKey = '') {
|
|
@@ -5841,6 +5860,28 @@ async function readFreshSupabaseSessionForRegistry(config, reason = 'registry')
|
|
|
5841
5860
|
}
|
|
5842
5861
|
}
|
|
5843
5862
|
|
|
5863
|
+
async function refreshSupabaseSessionAfterRegistryAuthFailure(config, trigger = 'registry-auth-failure') {
|
|
5864
|
+
if (!config?.url || !config?.key) {
|
|
5865
|
+
return {
|
|
5866
|
+
ok: false,
|
|
5867
|
+
reason: 'supabase-config-missing'
|
|
5868
|
+
};
|
|
5869
|
+
}
|
|
5870
|
+
|
|
5871
|
+
const sessionPayload = await readStableAuthSessionPayload();
|
|
5872
|
+
if (!sessionPayload.found) {
|
|
5873
|
+
return {
|
|
5874
|
+
ok: false,
|
|
5875
|
+
reason: 'registry-not-authenticated'
|
|
5876
|
+
};
|
|
5877
|
+
}
|
|
5878
|
+
|
|
5879
|
+
return await refreshSupabaseSessionForRegistry(
|
|
5880
|
+
config,
|
|
5881
|
+
sessionPayload,
|
|
5882
|
+
`registry-auth-failure-${safeRemoteAgentField(trigger || 'timer', 80)}`);
|
|
5883
|
+
}
|
|
5884
|
+
|
|
5844
5885
|
function readRegistryTargetField(target, ...keys) {
|
|
5845
5886
|
for (const key of keys) {
|
|
5846
5887
|
const value = target?.[key];
|
|
@@ -6595,8 +6636,9 @@ async function runRemoteRegistryFollowerOnce(trigger = 'timer') {
|
|
|
6595
6636
|
|
|
6596
6637
|
remoteRegistryFollowerInFlight = true;
|
|
6597
6638
|
const attemptedAt = new Date().toISOString();
|
|
6639
|
+
let config = null;
|
|
6598
6640
|
try {
|
|
6599
|
-
|
|
6641
|
+
config = readSupabaseRuntimeConfig();
|
|
6600
6642
|
if (!config.url || !config.key) {
|
|
6601
6643
|
closeRemoteRegistryRealtime('supabase-config-missing');
|
|
6602
6644
|
updateRemoteRegistryFollowerState({
|
|
@@ -6968,6 +7010,45 @@ async function runRemoteRegistryFollowerOnce(trigger = 'timer') {
|
|
|
6968
7010
|
return serializeRemoteRegistryFollowerState();
|
|
6969
7011
|
} catch (error) {
|
|
6970
7012
|
const transientAuth = error?.statusCode === 401 || error?.statusCode === 403;
|
|
7013
|
+
if (transientAuth) {
|
|
7014
|
+
const agentKept = isRemoteAgentRegistryOwned() && isRemoteAgentProcessRunning();
|
|
7015
|
+
const keptManager = agentKept ? safeRemoteAgentField(remoteAgentState.manager, 160) : '';
|
|
7016
|
+
const keptCandidates = agentKept ? normalizeRemoteManagerEndpointList(remoteAgentState.managerCandidates, remoteAgentState.manager) : [];
|
|
7017
|
+
const refreshed = await refreshSupabaseSessionAfterRegistryAuthFailure(config, trigger).catch(refreshError => ({
|
|
7018
|
+
ok: false,
|
|
7019
|
+
reason: refreshError?.message || String(refreshError || 'auth-refresh-failed')
|
|
7020
|
+
}));
|
|
7021
|
+
|
|
7022
|
+
if (refreshed?.ok === true && refreshed.session) {
|
|
7023
|
+
updateRemoteRegistryFollowerState({
|
|
7024
|
+
status: 'auth-refreshed',
|
|
7025
|
+
reason: agentKept ? 'registry-auth-refreshed-agent-kept' : 'registry-auth-refreshed',
|
|
7026
|
+
authenticated: true,
|
|
7027
|
+
lastAttemptAt: attemptedAt,
|
|
7028
|
+
lastError: '',
|
|
7029
|
+
targetEndpoint: keptManager,
|
|
7030
|
+
targetEndpointCandidates: keptCandidates,
|
|
7031
|
+
targetLeaseId: agentKept ? safeRemoteAgentField(remoteAgentState.leaseId, 128) : '',
|
|
7032
|
+
targetNodeId: agentKept ? safeRemoteAgentField(remoteAgentState.nodeId, 128) : '',
|
|
7033
|
+
agentKept
|
|
7034
|
+
});
|
|
7035
|
+
await reportRemoteRegistryFollowerSync({
|
|
7036
|
+
ok: true,
|
|
7037
|
+
skipped: true,
|
|
7038
|
+
reason: agentKept ? 'registry-auth-refreshed-agent-kept' : 'registry-auth-refreshed',
|
|
7039
|
+
trigger,
|
|
7040
|
+
authenticated: true,
|
|
7041
|
+
targetEndpoint: keptManager,
|
|
7042
|
+
targetEndpointCandidates: keptCandidates,
|
|
7043
|
+
targetLeaseId: agentKept ? remoteAgentState.leaseId : '',
|
|
7044
|
+
targetNodeId: agentKept ? remoteAgentState.nodeId : '',
|
|
7045
|
+
agentKept
|
|
7046
|
+
});
|
|
7047
|
+
scheduleRemoteRegistryFollower(0, 'auth-refreshed');
|
|
7048
|
+
return serializeRemoteRegistryFollowerState();
|
|
7049
|
+
}
|
|
7050
|
+
}
|
|
7051
|
+
|
|
6971
7052
|
updateRemoteRegistryFollowerState({
|
|
6972
7053
|
status: transientAuth ? 'auth-pending' : 'error',
|
|
6973
7054
|
reason: transientAuth ? 'registry-auth-pending' : 'registry-sync-failed',
|