mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-31 01:36:53 +00:00
feat(tui): infer workspace agent when launching TUI (#39591)
Merged via squash.
Prepared head SHA: 23533e24c4
Co-authored-by: arceus77-7 <261276524+arceus77-7@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
@@ -13,6 +15,8 @@ import {
|
||||
resolveAgentModelPrimary,
|
||||
resolveRunModelFallbacksOverride,
|
||||
resolveAgentWorkspaceDir,
|
||||
resolveAgentIdByWorkspacePath,
|
||||
resolveAgentIdsByWorkspacePath,
|
||||
} from "./agent-scope.js";
|
||||
|
||||
afterEach(() => {
|
||||
@@ -428,3 +432,92 @@ describe("resolveAgentConfig", () => {
|
||||
expect(agentDir).toBe(path.join(path.resolve(home), ".openclaw", "agents", "main", "agent"));
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveAgentIdByWorkspacePath", () => {
|
||||
it("returns the most specific workspace match for a directory", () => {
|
||||
const workspaceRoot = `/tmp/openclaw-agent-scope-${Date.now()}-root`;
|
||||
const opsWorkspace = `${workspaceRoot}/projects/ops`;
|
||||
const cfg: OpenClawConfig = {
|
||||
agents: {
|
||||
list: [
|
||||
{ id: "main", workspace: workspaceRoot },
|
||||
{ id: "ops", workspace: opsWorkspace },
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
expect(resolveAgentIdByWorkspacePath(cfg, `${opsWorkspace}/src`)).toBe("ops");
|
||||
});
|
||||
|
||||
it("returns undefined when directory has no matching workspace", () => {
|
||||
const workspaceRoot = `/tmp/openclaw-agent-scope-${Date.now()}-root`;
|
||||
const cfg: OpenClawConfig = {
|
||||
agents: {
|
||||
list: [
|
||||
{ id: "main", workspace: workspaceRoot },
|
||||
{ id: "ops", workspace: `${workspaceRoot}-ops` },
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
expect(
|
||||
resolveAgentIdByWorkspacePath(cfg, `/tmp/openclaw-agent-scope-${Date.now()}-unrelated`),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("matches workspace paths through symlink aliases", () => {
|
||||
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-agent-scope-"));
|
||||
const realWorkspaceRoot = path.join(tempRoot, "real-root");
|
||||
const realOpsWorkspace = path.join(realWorkspaceRoot, "projects", "ops");
|
||||
const aliasWorkspaceRoot = path.join(tempRoot, "alias-root");
|
||||
try {
|
||||
fs.mkdirSync(path.join(realOpsWorkspace, "src"), { recursive: true });
|
||||
fs.symlinkSync(
|
||||
realWorkspaceRoot,
|
||||
aliasWorkspaceRoot,
|
||||
process.platform === "win32" ? "junction" : "dir",
|
||||
);
|
||||
|
||||
const cfg: OpenClawConfig = {
|
||||
agents: {
|
||||
list: [
|
||||
{ id: "main", workspace: realWorkspaceRoot },
|
||||
{ id: "ops", workspace: realOpsWorkspace },
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
expect(
|
||||
resolveAgentIdByWorkspacePath(cfg, path.join(aliasWorkspaceRoot, "projects", "ops")),
|
||||
).toBe("ops");
|
||||
expect(
|
||||
resolveAgentIdByWorkspacePath(cfg, path.join(aliasWorkspaceRoot, "projects", "ops", "src")),
|
||||
).toBe("ops");
|
||||
} finally {
|
||||
fs.rmSync(tempRoot, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveAgentIdsByWorkspacePath", () => {
|
||||
it("returns matching workspaces ordered by specificity", () => {
|
||||
const workspaceRoot = `/tmp/openclaw-agent-scope-${Date.now()}-root`;
|
||||
const opsWorkspace = `${workspaceRoot}/projects/ops`;
|
||||
const opsDevWorkspace = `${opsWorkspace}/dev`;
|
||||
const cfg: OpenClawConfig = {
|
||||
agents: {
|
||||
list: [
|
||||
{ id: "main", workspace: workspaceRoot },
|
||||
{ id: "ops", workspace: opsWorkspace },
|
||||
{ id: "ops-dev", workspace: opsDevWorkspace },
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
expect(resolveAgentIdsByWorkspacePath(cfg, `${opsDevWorkspace}/pkg`)).toEqual([
|
||||
"ops-dev",
|
||||
"ops",
|
||||
"main",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user