mirror of https://github.com/openclaw/openclaw.git
refactor: lazy load cron cli runtime
This commit is contained in:
parent
7a9ad3820e
commit
88b1c00b39
|
|
@ -0,0 +1,2 @@
|
|||
export { runCliAgent } from "./cli-runner.js";
|
||||
export { getCliSessionId, setCliSessionId } from "./cli-session.js";
|
||||
|
|
@ -58,12 +58,10 @@ const normalizeModelSelectionMock = vi.fn((value: unknown) =>
|
|||
typeof value === "string" ? value.trim() || undefined : undefined,
|
||||
);
|
||||
const lookupContextTokensMock = vi.fn().mockReturnValue(128000);
|
||||
const resolveCronStyleNowMock = vi
|
||||
.fn()
|
||||
.mockReturnValue({
|
||||
formattedTime: "2026-02-10 12:00",
|
||||
timeLine: "Current time: 2026-02-10 12:00 UTC",
|
||||
});
|
||||
const resolveCronStyleNowMock = vi.fn().mockReturnValue({
|
||||
formattedTime: "2026-02-10 12:00",
|
||||
timeLine: "Current time: 2026-02-10 12:00 UTC",
|
||||
});
|
||||
const resolveAgentTimeoutMsMock = vi.fn().mockReturnValue(60_000);
|
||||
const deriveSessionTotalTokensMock = vi.fn().mockReturnValue(30);
|
||||
const hasNonzeroUsageMock = vi.fn().mockReturnValue(false);
|
||||
|
|
@ -84,6 +82,12 @@ const resolveBootstrapWarningSignaturesSeenMock = vi.fn().mockReturnValue([]);
|
|||
const resolveFastModeStateMock = vi.fn().mockReturnValue({ enabled: false });
|
||||
const resolveNestedAgentLaneMock = vi.fn((lane: string | undefined) => lane);
|
||||
|
||||
vi.mock("../../agents/cli-runner.runtime.js", () => ({
|
||||
runCliAgent: runCliAgentMock,
|
||||
getCliSessionId: getCliSessionIdMock,
|
||||
setCliSessionId: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("./run.runtime.js", () => ({
|
||||
DEFAULT_CONTEXT_TOKENS: 128000,
|
||||
DEFAULT_MODEL: "gpt-4",
|
||||
|
|
@ -96,14 +100,13 @@ vi.mock("./run.runtime.js", () => ({
|
|||
detectSuspiciousPatterns: detectSuspiciousPatternsMock,
|
||||
ensureAgentWorkspace: ensureAgentWorkspaceMock,
|
||||
estimateUsageCost: estimateUsageCostMock,
|
||||
getCliSessionId: getCliSessionIdMock,
|
||||
listDescendantRunsForRequester: listDescendantRunsForRequesterMock,
|
||||
getModelRefStatus: getModelRefStatusMock,
|
||||
getRemoteSkillEligibility: vi.fn().mockReturnValue({}),
|
||||
getSkillsSnapshotVersion: getSkillsSnapshotVersionMock,
|
||||
hasNonzeroUsage: hasNonzeroUsageMock,
|
||||
isCliProvider: isCliProviderMock,
|
||||
isExternalHookSession: isExternalHookSessionMock,
|
||||
listDescendantRunsForRequester: listDescendantRunsForRequesterMock,
|
||||
loadModelCatalog: loadModelCatalogMock,
|
||||
logWarn: (...args: unknown[]) => logWarnMock(...args),
|
||||
lookupContextTokens: lookupContextTokensMock,
|
||||
|
|
@ -132,10 +135,8 @@ vi.mock("./run.runtime.js", () => ({
|
|||
resolveSessionAuthProfileOverride: resolveSessionAuthProfileOverrideMock,
|
||||
resolveSessionTranscriptPath: resolveSessionTranscriptPathMock,
|
||||
resolveThinkingDefault: resolveThinkingDefaultMock,
|
||||
runCliAgent: runCliAgentMock,
|
||||
runEmbeddedPiAgent: runEmbeddedPiAgentMock,
|
||||
runWithModelFallback: runWithModelFallbackMock,
|
||||
setCliSessionId: vi.fn(),
|
||||
setSessionRuntimeModel: setSessionRuntimeModelMock,
|
||||
supportsXHighThinking: supportsXHighThinkingMock,
|
||||
updateSessionStore: updateSessionStoreMock,
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import {
|
|||
detectSuspiciousPatterns,
|
||||
ensureAgentWorkspace,
|
||||
estimateUsageCost,
|
||||
getCliSessionId,
|
||||
hasNonzeroUsage,
|
||||
isCliProvider,
|
||||
isExternalHookSession,
|
||||
|
|
@ -52,10 +51,8 @@ import {
|
|||
resolveSessionAuthProfileOverride,
|
||||
resolveSessionTranscriptPath,
|
||||
resolveThinkingDefault,
|
||||
runCliAgent,
|
||||
runEmbeddedPiAgent,
|
||||
runWithModelFallback,
|
||||
setCliSessionId,
|
||||
setSessionRuntimeModel,
|
||||
supportsXHighThinking,
|
||||
updateSessionStore,
|
||||
|
|
@ -166,6 +163,10 @@ function appendCronDeliveryInstruction(params: {
|
|||
return `${params.commandBody}\n\nReturn your summary as plain text; it will be delivered automatically. If the task explicitly calls for messaging a specific external recipient, note who/where it should go instead of sending it yourself.`.trim();
|
||||
}
|
||||
|
||||
async function loadCliRunnerRuntime() {
|
||||
return await import("../../agents/cli-runner.runtime.js");
|
||||
}
|
||||
|
||||
export async function runCronIsolatedAgentTurn(params: {
|
||||
cfg: OpenClawConfig;
|
||||
deps: CliDeps;
|
||||
|
|
@ -492,6 +493,7 @@ export async function runCronIsolatedAgentTurn(params: {
|
|||
const bootstrapPromptWarningSignature =
|
||||
bootstrapPromptWarningSignaturesSeen[bootstrapPromptWarningSignaturesSeen.length - 1];
|
||||
if (isCliProvider(providerOverride, cfgWithAgentDefaults)) {
|
||||
const { getCliSessionId, runCliAgent } = await loadCliRunnerRuntime();
|
||||
// Fresh isolated cron sessions must not reuse a stored CLI session ID.
|
||||
// Passing an existing ID activates the resume watchdog profile
|
||||
// (noOutputTimeoutRatio 0.3, maxMs 180 s) instead of the fresh profile
|
||||
|
|
@ -712,6 +714,7 @@ export async function runCronIsolatedAgentTurn(params: {
|
|||
if (isCliProvider(providerUsed, cfgWithAgentDefaults)) {
|
||||
const cliSessionId = finalRunResult.meta?.agentMeta?.sessionId?.trim();
|
||||
if (cliSessionId) {
|
||||
const { setCliSessionId } = await loadCliRunnerRuntime();
|
||||
setCliSessionId(cronSession.sessionEntry, providerUsed, cliSessionId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue