@mrrlin-dev/mcp 0.4.199 → 0.4.202
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/dist/bin.cjs +110 -51
- package/package.json +1 -1
package/dist/bin.cjs
CHANGED
|
@@ -69881,9 +69881,9 @@ function createMrrlinClient(config2) {
|
|
|
69881
69881
|
});
|
|
69882
69882
|
return executionRunResponseSchema.parse(body).data;
|
|
69883
69883
|
},
|
|
69884
|
-
async touchExecutionRunLease(projectSlug, runId, leaseId) {
|
|
69884
|
+
async touchExecutionRunLease(projectSlug, runId, leaseId, signal) {
|
|
69885
69885
|
try {
|
|
69886
|
-
const response = await request(`${projectPath(projectSlug)}/execution-runs/${encodeURIComponent(runId)}/touch-lease`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ leaseId }) });
|
|
69886
|
+
const response = await request(`${projectPath(projectSlug)}/execution-runs/${encodeURIComponent(runId)}/touch-lease`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ leaseId }), signal });
|
|
69887
69887
|
const data = compactExecutionTouchResponseSchema.parse(response).data;
|
|
69888
69888
|
if (data.projectSlug !== projectSlug || data.id !== runId || data.leaseId !== leaseId || data.executorBearer === void 0 !== (data.leaseRemainingMs === void 0)) {
|
|
69889
69889
|
throw new Error("Compact heartbeat returned a different execution lease");
|
|
@@ -69895,9 +69895,9 @@ function createMrrlinClient(config2) {
|
|
|
69895
69895
|
throw error51;
|
|
69896
69896
|
}
|
|
69897
69897
|
},
|
|
69898
|
-
async touchAsyncJobLease(projectSlug, jobId, leaseId) {
|
|
69898
|
+
async touchAsyncJobLease(projectSlug, jobId, leaseId, signal) {
|
|
69899
69899
|
try {
|
|
69900
|
-
const response = await request(`${projectPath(projectSlug)}/async-jobs/${encodeURIComponent(jobId)}/touch-lease`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ leaseId }) });
|
|
69900
|
+
const response = await request(`${projectPath(projectSlug)}/async-jobs/${encodeURIComponent(jobId)}/touch-lease`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ leaseId }), signal });
|
|
69901
69901
|
return compactAsyncTouchResponseSchema.parse(response).data.applied;
|
|
69902
69902
|
} catch (error51) {
|
|
69903
69903
|
if (error51 instanceof MrrlinApiError && error51.status === 409)
|
|
@@ -98006,13 +98006,23 @@ function createScopedTokenRefresh(options, lane = "refresh") {
|
|
|
98006
98006
|
const session = createScopedSession(options, lane);
|
|
98007
98007
|
return async (signal, absoluteDeadline) => (await session(signal, absoluteDeadline)).token;
|
|
98008
98008
|
}
|
|
98009
|
-
function createScopedHeartbeatFetch(options) {
|
|
98009
|
+
function createScopedHeartbeatFetch(options, mode = "full") {
|
|
98010
98010
|
const request = createScopedRequest(options, "heartbeat");
|
|
98011
98011
|
const origin = new URL(options.apiBaseUrl).origin;
|
|
98012
98012
|
return async (input, init) => {
|
|
98013
98013
|
if (typeof input !== "string" && !(input instanceof URL)) throw new Error("BRIDGE_HEARTBEAT_UNSUPPORTED_REQUEST");
|
|
98014
98014
|
const url2 = new URL(input);
|
|
98015
|
-
|
|
98015
|
+
const path40 = mode === "compact" ? /^\/projects\/([^/]+)\/(?:execution-runs|async-jobs)\/([^/]+)\/touch-lease$/u.exec(url2.pathname) : /^\/projects\/([^/]+)\/(?:execution-runs|async-jobs)\/([^/]+)\/touch$/u.exec(url2.pathname);
|
|
98016
|
+
const safeSegment = (segment) => {
|
|
98017
|
+
try {
|
|
98018
|
+
const value = decodeURIComponent(segment);
|
|
98019
|
+
return value !== "." && value !== ".." && !/[/\\\x00]/u.test(value);
|
|
98020
|
+
} catch {
|
|
98021
|
+
return false;
|
|
98022
|
+
}
|
|
98023
|
+
};
|
|
98024
|
+
const rawPath = typeof input === "string" ? /^https?:\/\/[^/?#\\]+(\/[^?#]*)$/iu.exec(input)?.[1] : void 0;
|
|
98025
|
+
if (url2.origin !== origin || url2.username || url2.password || url2.search || url2.hash || !path40 || mode === "compact" && (rawPath !== url2.pathname || !safeSegment(path40[1]) || !safeSegment(path40[2])) || init?.method !== "POST" || typeof init.body !== "string" || Buffer.byteLength(init.body) > 8192) {
|
|
98016
98026
|
throw new Error("BRIDGE_HEARTBEAT_UNSUPPORTED_REQUEST");
|
|
98017
98027
|
}
|
|
98018
98028
|
const result = await request(init.signal ?? void 0, { url: url2.href, body: init.body });
|
|
@@ -99249,7 +99259,7 @@ Do NOT derail the current task - if the operator has an in-flight question, answ
|
|
|
99249
99259
|
}
|
|
99250
99260
|
|
|
99251
99261
|
// src/_generated/version.ts
|
|
99252
|
-
var PKG_VERSION = "0.4.
|
|
99262
|
+
var PKG_VERSION = "0.4.202";
|
|
99253
99263
|
|
|
99254
99264
|
// src/bridge-allowed-origins.ts
|
|
99255
99265
|
var DEFAULT_DIRECTOR_BRIDGE_ALLOWED_ORIGINS = [
|
|
@@ -104421,6 +104431,9 @@ async function noteProjectFolderCreated(deps, projectSlug, taskId, folderPath) {
|
|
|
104421
104431
|
} catch {
|
|
104422
104432
|
}
|
|
104423
104433
|
}
|
|
104434
|
+
function touchConsumerExecutionLease(deps, projectSlug, runId, leaseId) {
|
|
104435
|
+
return deps.renewExecutionLease ? deps.renewExecutionLease(projectSlug, runId, leaseId, deps.activeLease?.watch.signal) : deps.client.touchExecutionRun(projectSlug, runId, leaseId);
|
|
104436
|
+
}
|
|
104424
104437
|
async function runHasLease(deps, projectSlug, runId, leaseId) {
|
|
104425
104438
|
try {
|
|
104426
104439
|
const run4 = await deps.client.getExecutionRun(projectSlug, runId);
|
|
@@ -104580,7 +104593,7 @@ async function driveTurn(deps, codex, projectSlug, runId, leaseId, threadId, inp
|
|
|
104580
104593
|
unsubEvent();
|
|
104581
104594
|
};
|
|
104582
104595
|
const touchTimer = deps.activeLease ? void 0 : setInterval(() => {
|
|
104583
|
-
void deps
|
|
104596
|
+
void touchConsumerExecutionLease(deps, projectSlug, runId, leaseId).catch(() => {
|
|
104584
104597
|
});
|
|
104585
104598
|
}, deps.touchIntervalMs);
|
|
104586
104599
|
touchTimer?.unref?.();
|
|
@@ -104716,7 +104729,7 @@ async function driveRun(deps, projectSlug, runId, shutdown) {
|
|
|
104716
104729
|
}
|
|
104717
104730
|
},
|
|
104718
104731
|
touch: async () => {
|
|
104719
|
-
const renewed = await client.touchExecutionRun(projectSlug, runId, leaseId);
|
|
104732
|
+
const renewed = deps.renewExecutionLease ? await deps.renewExecutionLease(projectSlug, runId, leaseId, watch.signal) : await client.touchExecutionRun(projectSlug, runId, leaseId);
|
|
104720
104733
|
if (renewed?.projectSlug !== projectSlug || renewed.id !== runId || renewed.leaseId !== leaseId || renewed.status !== "running") return null;
|
|
104721
104734
|
return renewed;
|
|
104722
104735
|
},
|
|
@@ -104855,7 +104868,15 @@ async function driveWatchedRun(deps, projectSlug, runId, claimed, leaseId, watch
|
|
|
104855
104868
|
}
|
|
104856
104869
|
});
|
|
104857
104870
|
try {
|
|
104858
|
-
|
|
104871
|
+
const renew = deps.renewExecutionLease;
|
|
104872
|
+
const renewExecutionLease = renew && (async (slug, id, lease) => {
|
|
104873
|
+
if (slug !== projectSlug || id !== runId || lease !== leaseId) throw new Error("Compact heartbeat claim mismatch");
|
|
104874
|
+
watch.assertActive();
|
|
104875
|
+
const result = await renew(slug, id, lease, watch.signal);
|
|
104876
|
+
watch.assertActive();
|
|
104877
|
+
return result;
|
|
104878
|
+
});
|
|
104879
|
+
await driveClaimedRun({ ...deps, client: guardedClient, activeLease, renewExecutionLease }, projectSlug, runId, claimed, leaseId);
|
|
104859
104880
|
} catch (error51) {
|
|
104860
104881
|
if (!watch.signal.aborted && !(executionFinished && error51 instanceof ExecutionLeaseError)) throw error51;
|
|
104861
104882
|
} finally {
|
|
@@ -106015,7 +106036,7 @@ ${coldClosureInstruction}` : workInstruction;
|
|
|
106015
106036
|
const deliveryTask = readiness.task;
|
|
106016
106037
|
const deliveryKey = deliveryLockKey(localCheckoutRealPath ?? checkout?.path ?? deliveryWorktree);
|
|
106017
106038
|
const deliveryHeartbeat = deps.activeLease ? void 0 : setInterval(() => {
|
|
106018
|
-
void deps
|
|
106039
|
+
void touchConsumerExecutionLease(deps, projectSlug, runId, leaseId).catch(() => {
|
|
106019
106040
|
});
|
|
106020
106041
|
}, deps.touchIntervalMs);
|
|
106021
106042
|
deliveryHeartbeat?.unref?.();
|
|
@@ -106649,7 +106670,7 @@ async function driveNonCodeRun(deps, projectSlug, runId, leaseId, task, domain2,
|
|
|
106649
106670
|
}
|
|
106650
106671
|
const runExec = deps.runDeliverableExec ?? ((input, provider) => runAgentExec(input, void 0, provider));
|
|
106651
106672
|
const touchTimer = deps.activeLease ? void 0 : setInterval(() => {
|
|
106652
|
-
void deps
|
|
106673
|
+
void touchConsumerExecutionLease(deps, projectSlug, runId, leaseId).catch(() => {
|
|
106653
106674
|
});
|
|
106654
106675
|
}, deps.touchIntervalMs);
|
|
106655
106676
|
touchTimer?.unref?.();
|
|
@@ -108164,8 +108185,11 @@ async function driveClaimableAsyncJob(deps, projectSlug, jobId, preClaimJob, sec
|
|
|
108164
108185
|
let nextHeartbeat = elapsed() + deps.touchIntervalMs;
|
|
108165
108186
|
const touchTimer = setInterval(() => {
|
|
108166
108187
|
if (!reportAction) {
|
|
108167
|
-
if (!shutdown?.aborted)
|
|
108168
|
-
|
|
108188
|
+
if (!shutdown?.aborted) {
|
|
108189
|
+
const renewal = deps.renewAsyncLease ? deps.renewAsyncLease(projectSlug, jobId, leaseId, shutdown) : deps.client.touchAsyncJob(projectSlug, jobId, leaseId);
|
|
108190
|
+
void renewal.catch(() => {
|
|
108191
|
+
});
|
|
108192
|
+
}
|
|
108169
108193
|
return;
|
|
108170
108194
|
}
|
|
108171
108195
|
if (!checkOwnership() || beginning || heartbeatPending || elapsed() < nextHeartbeat) return;
|
|
@@ -118859,6 +118883,14 @@ async function runStartupPruneSafely(prune2, log2) {
|
|
|
118859
118883
|
}
|
|
118860
118884
|
}
|
|
118861
118885
|
async function startDirectorBridge(startupDeps = {}) {
|
|
118886
|
+
const agentSecret = readAgentSecret();
|
|
118887
|
+
const scopedScheduler = process.env.MRRLIN_BRIDGE_SCOPED_SCHEDULER === "1";
|
|
118888
|
+
const compactFlag = process.env.MRRLIN_BRIDGE_COMPACT_HEARTBEAT?.trim().toLowerCase();
|
|
118889
|
+
if (compactFlag && !["0", "1", "false"].includes(compactFlag)) throw new Error("Invalid MRRLIN_BRIDGE_COMPACT_HEARTBEAT");
|
|
118890
|
+
const compactHeartbeat = compactFlag === "1";
|
|
118891
|
+
if (compactHeartbeat && (!agentSecret || !scopedScheduler)) {
|
|
118892
|
+
throw new Error("Compact heartbeat requires a durable agent credential and scoped scheduler");
|
|
118893
|
+
}
|
|
118862
118894
|
const signingProvider = buildBridgeSigningProvider();
|
|
118863
118895
|
const config2 = parseConfig();
|
|
118864
118896
|
const failureLog = createFailureLog();
|
|
@@ -118883,55 +118915,57 @@ async function startDirectorBridge(startupDeps = {}) {
|
|
|
118883
118915
|
};
|
|
118884
118916
|
const shutdownHolder = { fn: null };
|
|
118885
118917
|
const resumableCountHolder = { fn: null };
|
|
118886
|
-
const
|
|
118887
|
-
|
|
118888
|
-
|
|
118889
|
-
|
|
118890
|
-
|
|
118891
|
-
|
|
118892
|
-
|
|
118893
|
-
|
|
118894
|
-
|
|
118895
|
-
|
|
118896
|
-
|
|
118897
|
-
|
|
118898
|
-
|
|
118899
|
-
|
|
118918
|
+
const startBackgroundServices = () => {
|
|
118919
|
+
const { path: binPath, source: binPathSource } = resolveBinPath({
|
|
118920
|
+
argv1: process.argv[1] ?? ""
|
|
118921
|
+
});
|
|
118922
|
+
const selfUpdateHandle2 = startSelfUpdate({
|
|
118923
|
+
binPath,
|
|
118924
|
+
binPathSource,
|
|
118925
|
+
getActiveTurnCount: () => wrappedTurnLock.activeCount(),
|
|
118926
|
+
getResumableTurnCount: () => resumableCountHolder.fn?.() ?? 0,
|
|
118927
|
+
getIdleMs: () => Date.now() - lastTurnEndedAt,
|
|
118928
|
+
pkgVersion: PKG_VERSION,
|
|
118929
|
+
shutdown: () => {
|
|
118930
|
+
try {
|
|
118931
|
+
void shutdownHolder.fn?.();
|
|
118932
|
+
} catch (e) {
|
|
118933
|
+
process.stderr.write(
|
|
118934
|
+
`[mrrlin-mcp director-bridge] error self_update shutdown threw: ${String(
|
|
118935
|
+
e?.message ?? e
|
|
118936
|
+
)}
|
|
118937
|
+
`
|
|
118938
|
+
);
|
|
118939
|
+
}
|
|
118940
|
+
},
|
|
118941
|
+
log: (level, event, fields) => {
|
|
118942
|
+
const payload = fields ? ` ${JSON.stringify(fields)}` : "";
|
|
118900
118943
|
process.stderr.write(
|
|
118901
|
-
`[mrrlin-mcp director-bridge]
|
|
118902
|
-
e?.message ?? e
|
|
118903
|
-
)}
|
|
118944
|
+
`[mrrlin-mcp director-bridge] ${level} ${event}${payload}
|
|
118904
118945
|
`
|
|
118905
118946
|
);
|
|
118906
118947
|
}
|
|
118907
|
-
}
|
|
118908
|
-
|
|
118909
|
-
|
|
118910
|
-
|
|
118911
|
-
|
|
118912
|
-
`
|
|
118913
|
-
);
|
|
118948
|
+
});
|
|
118949
|
+
const codexProbeHandle2 = startCodexProbe();
|
|
118950
|
+
try {
|
|
118951
|
+
migrateRetiredApiBaseUrls();
|
|
118952
|
+
} catch {
|
|
118914
118953
|
}
|
|
118915
|
-
|
|
118916
|
-
|
|
118954
|
+
return { selfUpdateHandle: selfUpdateHandle2, codexProbeHandle: codexProbeHandle2 };
|
|
118955
|
+
};
|
|
118956
|
+
const legacyBackgroundServices = compactHeartbeat ? void 0 : startBackgroundServices();
|
|
118917
118957
|
const consumerState = {
|
|
118918
118958
|
inFlightRunIds: /* @__PURE__ */ new Set(),
|
|
118919
118959
|
lastClaimedRunId: null,
|
|
118920
118960
|
lastClaimAt: null
|
|
118921
118961
|
};
|
|
118922
118962
|
const health = createServiceHealth();
|
|
118923
|
-
try {
|
|
118924
|
-
migrateRetiredApiBaseUrls();
|
|
118925
|
-
} catch {
|
|
118926
|
-
}
|
|
118927
118963
|
const apiBaseUrl = readDirectorBridgeApiBaseUrl();
|
|
118928
118964
|
const envToken = process.env.MRRLIN_TOKEN?.trim() || void 0;
|
|
118929
|
-
const agentSecret = readAgentSecret();
|
|
118930
118965
|
let tokenProvider = null;
|
|
118931
118966
|
let tokenRefresher = null;
|
|
118932
118967
|
let schedulerGenerations;
|
|
118933
118968
|
let schedulerScope;
|
|
118934
|
-
const scopedScheduler = process.env.MRRLIN_BRIDGE_SCOPED_SCHEDULER === "1";
|
|
118935
118969
|
const ownedSdk = Boolean(agentSecret) && scopedScheduler && process.env.MRRLIN_BRIDGE_OWNED_SDK === "1";
|
|
118936
118970
|
const scopedRunRead = Boolean(agentSecret) && scopedScheduler && process.env.MRRLIN_BRIDGE_SCOPED_RUN_READ === "1";
|
|
118937
118971
|
const baseFetch = globalThis.fetch;
|
|
@@ -118960,8 +118994,12 @@ async function startDirectorBridge(startupDeps = {}) {
|
|
|
118960
118994
|
}) };
|
|
118961
118995
|
} catch {
|
|
118962
118996
|
schedulerScope?.dispose();
|
|
118963
|
-
|
|
118997
|
+
const disposal = schedulerGenerations?.dispose();
|
|
118964
118998
|
schedulerScope = void 0;
|
|
118999
|
+
if (compactHeartbeat) {
|
|
119000
|
+
await disposal;
|
|
119001
|
+
throw new Error("BRIDGE_COMPACT_HEARTBEAT_START_FAILED");
|
|
119002
|
+
}
|
|
118965
119003
|
refreshProvider = { getToken: async () => {
|
|
118966
119004
|
throw new Error("BRIDGE_REFRESH_START_FAILED");
|
|
118967
119005
|
} };
|
|
@@ -119045,6 +119083,9 @@ async function startDirectorBridge(startupDeps = {}) {
|
|
|
119045
119083
|
throw new Error("BRIDGE_RUN_READ_START_FAILED");
|
|
119046
119084
|
});
|
|
119047
119085
|
}
|
|
119086
|
+
const compactHeartbeatShutdown = compactHeartbeat ? new AbortController() : void 0;
|
|
119087
|
+
let renewExecutionLease;
|
|
119088
|
+
let renewAsyncLease;
|
|
119048
119089
|
if (tokenProvider && scopedScheduler) {
|
|
119049
119090
|
const heartbeat = schedulerScope && schedulerGenerations ? createMrrlinClient({ baseUrl: apiBaseUrl, fetch: createScopedHeartbeatFetch({
|
|
119050
119091
|
scope: schedulerScope,
|
|
@@ -119052,10 +119093,25 @@ async function startDirectorBridge(startupDeps = {}) {
|
|
|
119052
119093
|
apiBaseUrl,
|
|
119053
119094
|
tokenProvider,
|
|
119054
119095
|
timeoutMs: DEFAULT_OPERATION_TIMEOUT_MS
|
|
119055
|
-
}) }) : null;
|
|
119056
|
-
|
|
119057
|
-
|
|
119096
|
+
}, compactHeartbeat ? "compact" : "full") }) : null;
|
|
119097
|
+
if (compactHeartbeat) {
|
|
119098
|
+
if (!heartbeat?.touchExecutionRunLease || !heartbeat.touchAsyncJobLease) {
|
|
119099
|
+
tokenRefresher?.stop();
|
|
119100
|
+
schedulerScope?.dispose();
|
|
119101
|
+
await schedulerGenerations?.dispose();
|
|
119102
|
+
throw new Error("BRIDGE_COMPACT_HEARTBEAT_START_FAILED");
|
|
119103
|
+
}
|
|
119104
|
+
const lifetime = compactHeartbeatShutdown.signal;
|
|
119105
|
+
const execution = heartbeat.touchExecutionRunLease.bind(heartbeat);
|
|
119106
|
+
const asyncJob = heartbeat.touchAsyncJobLease.bind(heartbeat);
|
|
119107
|
+
renewExecutionLease = (slug, id, lease, signal) => execution(slug, id, lease, signal ? AbortSignal.any([signal, lifetime]) : lifetime);
|
|
119108
|
+
renewAsyncLease = (slug, id, lease, signal) => asyncJob(slug, id, lease, signal ? AbortSignal.any([signal, lifetime]) : lifetime);
|
|
119109
|
+
} else {
|
|
119110
|
+
client.touchExecutionRun = (projectSlug, runId, leaseId) => heartbeat ? heartbeat.touchExecutionRun(projectSlug, runId, leaseId) : Promise.reject(new Error("BRIDGE_HEARTBEAT_START_FAILED"));
|
|
119111
|
+
client.touchAsyncJob = (projectSlug, jobId, leaseId) => heartbeat ? heartbeat.touchAsyncJob(projectSlug, jobId, leaseId) : Promise.reject(new Error("BRIDGE_HEARTBEAT_START_FAILED"));
|
|
119112
|
+
}
|
|
119058
119113
|
}
|
|
119114
|
+
const { selfUpdateHandle, codexProbeHandle } = legacyBackgroundServices ?? startBackgroundServices();
|
|
119059
119115
|
const artifactsGc = startArtifactsGc(config2.stateDir);
|
|
119060
119116
|
const agentKeepalive = createAgentKeepalive({
|
|
119061
119117
|
acquire: (providerId) => resolveProvider(process.env, providerId).acquireWarm(),
|
|
@@ -119081,6 +119137,7 @@ async function startDirectorBridge(startupDeps = {}) {
|
|
|
119081
119137
|
});
|
|
119082
119138
|
const staleSeconds = readEnvInt("MRRLIN_DIRECTOR_BRIDGE_STALE_SECONDS", DEFAULT_STALE_SECONDS);
|
|
119083
119139
|
const consumerDeps = {
|
|
119140
|
+
renewExecutionLease,
|
|
119084
119141
|
client,
|
|
119085
119142
|
connectionStore,
|
|
119086
119143
|
stateDir: config2.stateDir,
|
|
@@ -119233,6 +119290,7 @@ async function startDirectorBridge(startupDeps = {}) {
|
|
|
119233
119290
|
const activeReports = /* @__PURE__ */ new Set();
|
|
119234
119291
|
const reportShutdown = reportDelivery ? new AbortController() : void 0;
|
|
119235
119292
|
const asyncConsumerDeps = {
|
|
119293
|
+
renewAsyncLease,
|
|
119236
119294
|
reportShutdown: reportShutdown?.signal,
|
|
119237
119295
|
onReportDrive: (drive) => {
|
|
119238
119296
|
activeReports.add(drive);
|
|
@@ -119913,8 +119971,9 @@ async function startDirectorBridge(startupDeps = {}) {
|
|
|
119913
119971
|
() => artifactsGc.stop()
|
|
119914
119972
|
],
|
|
119915
119973
|
shutdownCodex: () => codexServerManager.shutdown(),
|
|
119916
|
-
...progressExecution || reportDelivery ? { stopExecution: async () => {
|
|
119974
|
+
...progressExecution || reportDelivery || compactHeartbeat ? { stopExecution: async () => {
|
|
119917
119975
|
executionStopping = true;
|
|
119976
|
+
compactHeartbeatShutdown?.abort();
|
|
119918
119977
|
asyncShutdown?.abort();
|
|
119919
119978
|
reportShutdown?.abort();
|
|
119920
119979
|
for (const controller of activeDrives.keys()) controller.abort();
|