mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 22:01:24 +00:00
fix: run BOOT.md for each configured agent at startup (#20569)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 9098a4cc64
Co-authored-by: mcaxtr <7562095+mcaxtr@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
@@ -9,7 +9,7 @@ const agentCommand = vi.fn();
|
||||
vi.mock("../commands/agent.js", () => ({ agentCommand }));
|
||||
|
||||
const { runBootOnce } = await import("./boot.js");
|
||||
const { resolveAgentIdFromSessionKey, resolveMainSessionKey } =
|
||||
const { resolveAgentIdFromSessionKey, resolveAgentMainSessionKey, resolveMainSessionKey } =
|
||||
await import("../config/sessions/main-session.js");
|
||||
const { resolveStorePath } = await import("../config/sessions/paths.js");
|
||||
const { loadSessionStore, saveSessionStore } = await import("../config/sessions/store.js");
|
||||
@@ -99,6 +99,24 @@ describe("runBootOnce", () => {
|
||||
await fs.rm(workspaceDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it("uses per-agent session key when agentId is provided", async () => {
|
||||
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-boot-"));
|
||||
await fs.writeFile(path.join(workspaceDir, "BOOT.md"), "Check status.", "utf-8");
|
||||
|
||||
agentCommand.mockResolvedValue(undefined);
|
||||
const cfg = {};
|
||||
const agentId = "ops";
|
||||
await expect(runBootOnce({ cfg, deps: makeDeps(), workspaceDir, agentId })).resolves.toEqual({
|
||||
status: "ran",
|
||||
});
|
||||
|
||||
expect(agentCommand).toHaveBeenCalledTimes(1);
|
||||
const perAgentCall = agentCommand.mock.calls[0]?.[0];
|
||||
expect(perAgentCall?.sessionKey).toBe(resolveAgentMainSessionKey({ cfg, agentId }));
|
||||
|
||||
await fs.rm(workspaceDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it("generates new session ID when no existing session exists", async () => {
|
||||
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-boot-"));
|
||||
const content = "Say hello when you wake up.";
|
||||
|
||||
@@ -7,6 +7,7 @@ import { agentCommand } from "../commands/agent.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import {
|
||||
resolveAgentIdFromSessionKey,
|
||||
resolveAgentMainSessionKey,
|
||||
resolveMainSessionKey,
|
||||
} from "../config/sessions/main-session.js";
|
||||
import { resolveStorePath } from "../config/sessions/paths.js";
|
||||
@@ -138,6 +139,7 @@ export async function runBootOnce(params: {
|
||||
cfg: OpenClawConfig;
|
||||
deps: CliDeps;
|
||||
workspaceDir: string;
|
||||
agentId?: string;
|
||||
}): Promise<BootRunResult> {
|
||||
const bootRuntime: RuntimeEnv = {
|
||||
log: () => {},
|
||||
@@ -157,7 +159,9 @@ export async function runBootOnce(params: {
|
||||
return { status: "skipped", reason: result.status };
|
||||
}
|
||||
|
||||
const sessionKey = resolveMainSessionKey(params.cfg);
|
||||
const sessionKey = params.agentId
|
||||
? resolveAgentMainSessionKey({ cfg: params.cfg, agentId: params.agentId })
|
||||
: resolveMainSessionKey(params.cfg);
|
||||
const message = buildBootPrompt(result.content ?? "");
|
||||
const sessionId = generateBootSessionId();
|
||||
const mappingSnapshot = snapshotMainSessionMapping({
|
||||
|
||||
Reference in New Issue
Block a user