refactor: dedupe cli config cron and install flows

This commit is contained in:
Peter Steinberger
2026-03-02 19:48:38 +00:00
parent 9d30159fcd
commit b1c30f0ba9
80 changed files with 1379 additions and 2027 deletions

View File

@@ -50,11 +50,9 @@ describe("normalizePluginsConfig", () => {
});
describe("resolveEffectiveEnableState", () => {
it("enables bundled channels when channels.<id>.enabled=true", () => {
const normalized = normalizePluginsConfig({
enabled: true,
});
const state = resolveEffectiveEnableState({
function resolveBundledTelegramState(config: Parameters<typeof normalizePluginsConfig>[0]) {
const normalized = normalizePluginsConfig(config);
return resolveEffectiveEnableState({
id: "telegram",
origin: "bundled",
config: normalized,
@@ -66,11 +64,17 @@ describe("resolveEffectiveEnableState", () => {
},
},
});
}
it("enables bundled channels when channels.<id>.enabled=true", () => {
const state = resolveBundledTelegramState({
enabled: true,
});
expect(state).toEqual({ enabled: true });
});
it("keeps explicit plugin-level disable authoritative", () => {
const normalized = normalizePluginsConfig({
const state = resolveBundledTelegramState({
enabled: true,
entries: {
telegram: {
@@ -78,18 +82,6 @@ describe("resolveEffectiveEnableState", () => {
},
},
});
const state = resolveEffectiveEnableState({
id: "telegram",
origin: "bundled",
config: normalized,
rootConfig: {
channels: {
telegram: {
enabled: true,
},
},
},
});
expect(state).toEqual({ enabled: false, reason: "disabled in config" });
});
});

View File

@@ -7,6 +7,7 @@
*/
import { beforeEach, describe, expect, it } from "vitest";
import { createHookRunner } from "./hooks.js";
import { addTestHook, TEST_PLUGIN_AGENT_CTX } from "./hooks.test-helpers.js";
import { createEmptyPluginRegistry, type PluginRegistry } from "./registry.js";
import type { PluginHookBeforeAgentStartResult, PluginHookRegistration } from "./types.js";
@@ -16,21 +17,16 @@ function addBeforeAgentStartHook(
handler: () => PluginHookBeforeAgentStartResult | Promise<PluginHookBeforeAgentStartResult>,
priority?: number,
) {
registry.typedHooks.push({
addTestHook({
registry,
pluginId,
hookName: "before_agent_start",
handler,
handler: handler as PluginHookRegistration["handler"],
priority,
source: "test",
} as PluginHookRegistration);
});
}
const stubCtx = {
agentId: "test-agent",
sessionKey: "sk",
sessionId: "sid",
workspaceDir: "/tmp",
};
const stubCtx = TEST_PLUGIN_AGENT_CTX;
describe("before_agent_start hook merger", () => {
let registry: PluginRegistry;

View File

@@ -8,10 +8,10 @@
*/
import { beforeEach, describe, expect, it, vi } from "vitest";
import { createHookRunner } from "./hooks.js";
import { addTestHook, TEST_PLUGIN_AGENT_CTX } from "./hooks.test-helpers.js";
import { createEmptyPluginRegistry, type PluginRegistry } from "./registry.js";
import type {
PluginHookAgentContext,
PluginHookBeforeAgentStartResult,
PluginHookBeforeModelResolveEvent,
PluginHookBeforeModelResolveResult,
PluginHookBeforePromptBuildEvent,
@@ -28,13 +28,13 @@ function addBeforeModelResolveHook(
) => PluginHookBeforeModelResolveResult | Promise<PluginHookBeforeModelResolveResult>,
priority?: number,
) {
registry.typedHooks.push({
addTestHook({
registry,
pluginId,
hookName: "before_model_resolve",
handler,
handler: handler as PluginHookRegistration["handler"],
priority,
source: "test",
} as PluginHookRegistration);
});
}
function addBeforePromptBuildHook(
@@ -46,36 +46,16 @@ function addBeforePromptBuildHook(
) => PluginHookBeforePromptBuildResult | Promise<PluginHookBeforePromptBuildResult>,
priority?: number,
) {
registry.typedHooks.push({
addTestHook({
registry,
pluginId,
hookName: "before_prompt_build",
handler,
handler: handler as PluginHookRegistration["handler"],
priority,
source: "test",
} as PluginHookRegistration);
});
}
function addLegacyBeforeAgentStartHook(
registry: PluginRegistry,
pluginId: string,
handler: () => PluginHookBeforeAgentStartResult | Promise<PluginHookBeforeAgentStartResult>,
priority?: number,
) {
registry.typedHooks.push({
pluginId,
hookName: "before_agent_start",
handler,
priority,
source: "test",
} as PluginHookRegistration);
}
const stubCtx: PluginHookAgentContext = {
agentId: "test-agent",
sessionKey: "sk",
sessionId: "sid",
workspaceDir: "/tmp",
};
const stubCtx: PluginHookAgentContext = TEST_PLUGIN_AGENT_CTX;
describe("model override pipeline wiring", () => {
let registry: PluginRegistry;
@@ -109,10 +89,15 @@ describe("model override pipeline wiring", () => {
modelOverride: "llama3.3:8b",
providerOverride: "ollama",
}));
addLegacyBeforeAgentStartHook(registry, "legacy-hook", () => ({
modelOverride: "gpt-4o",
providerOverride: "openai",
}));
addTestHook({
registry,
pluginId: "legacy-hook",
hookName: "before_agent_start",
handler: (() => ({
modelOverride: "gpt-4o",
providerOverride: "openai",
})) as PluginHookRegistration["handler"],
});
const runner = createHookRunner(registry);
const explicit = await runner.runBeforeModelResolve({ prompt: "sensitive" }, stubCtx);
@@ -151,9 +136,14 @@ describe("model override pipeline wiring", () => {
addBeforePromptBuildHook(registry, "new-hook", () => ({
prependContext: "new context",
}));
addLegacyBeforeAgentStartHook(registry, "legacy-hook", () => ({
prependContext: "legacy context",
}));
addTestHook({
registry,
pluginId: "legacy-hook",
hookName: "before_agent_start",
handler: (() => ({
prependContext: "legacy context",
})) as PluginHookRegistration["handler"],
});
const runner = createHookRunner(registry);
const promptBuild = await runner.runBeforePromptBuild(
@@ -207,7 +197,12 @@ describe("model override pipeline wiring", () => {
addBeforeModelResolveHook(registry, "plugin-a", () => ({}));
addBeforePromptBuildHook(registry, "plugin-b", () => ({}));
addLegacyBeforeAgentStartHook(registry, "plugin-c", () => ({}));
addTestHook({
registry,
pluginId: "plugin-c",
hookName: "before_agent_start",
handler: (() => ({})) as PluginHookRegistration["handler"],
});
const runner2 = createHookRunner(registry);
expect(runner2.hasHooks("before_model_resolve")).toBe(true);

View File

@@ -1,6 +1,6 @@
import type { OpenClawConfig } from "../config/config.js";
import type { PluginInstallRecord } from "../config/types.plugins.js";
import type { NpmSpecResolution } from "../infra/install-source-utils.js";
import { buildNpmResolutionFields, type NpmSpecResolution } from "../infra/install-source-utils.js";
export type PluginInstallUpdate = PluginInstallRecord & { pluginId: string };
@@ -10,14 +10,7 @@ export function buildNpmResolutionInstallFields(
PluginInstallRecord,
"resolvedName" | "resolvedVersion" | "resolvedSpec" | "integrity" | "shasum" | "resolvedAt"
> {
return {
resolvedName: resolution?.name,
resolvedVersion: resolution?.version,
resolvedSpec: resolution?.resolvedSpec,
integrity: resolution?.integrity,
shasum: resolution?.shasum,
resolvedAt: resolution?.resolvedAt,
};
return buildNpmResolutionFields(resolution);
}
export function recordPluginInstall(

View File

@@ -570,8 +570,7 @@ export type PluginHookSubagentContext = {
export type PluginHookSubagentTargetKind = "subagent" | "acp";
// subagent_spawning hook
export type PluginHookSubagentSpawningEvent = {
type PluginHookSubagentSpawnBase = {
childSessionKey: string;
agentId: string;
label?: string;
@@ -585,6 +584,9 @@ export type PluginHookSubagentSpawningEvent = {
threadRequested: boolean;
};
// subagent_spawning hook
export type PluginHookSubagentSpawningEvent = PluginHookSubagentSpawnBase;
export type PluginHookSubagentSpawningResult =
| {
status: "ok";
@@ -620,19 +622,8 @@ export type PluginHookSubagentDeliveryTargetResult = {
};
// subagent_spawned hook
export type PluginHookSubagentSpawnedEvent = {
export type PluginHookSubagentSpawnedEvent = PluginHookSubagentSpawnBase & {
runId: string;
childSessionKey: string;
agentId: string;
label?: string;
mode: "run" | "session";
requester?: {
channel?: string;
accountId?: string;
to?: string;
threadId?: string | number;
};
threadRequested: boolean;
};
// subagent_ended hook