feat(web): extend workspace lib with profile discovery and state dir resolution

This commit is contained in:
kumarabhirup 2026-03-02 18:32:53 -08:00
parent b45ac0166a
commit ba1a66d222
No known key found for this signature in database
GPG Key ID: DB7CA2289CAB0167
2 changed files with 18 additions and 3 deletions

View File

@ -915,6 +915,16 @@ describe("workspace utilities", () => {
expect(isSystemFile("sub/workspace_context.yaml")).toBe(false);
});
it("returns true for IDENTITY.md at root", async () => {
const { isSystemFile } = await importWorkspace();
expect(isSystemFile("IDENTITY.md")).toBe(true);
});
it("returns false for IDENTITY.md in subdirectory", async () => {
const { isSystemFile } = await importWorkspace();
expect(isSystemFile("sub/IDENTITY.md")).toBe(false);
});
it("returns false for regular files", async () => {
const { isSystemFile } = await importWorkspace();
expect(isSystemFile("readme.md")).toBe(false);

View File

@ -297,8 +297,8 @@ export function discoverProfiles(): DiscoveredProfile[] {
* - named profile: ~/.openclaw-<profile>
* - OPENCLAW_STATE_DIR override wins for all profiles
*/
export function resolveOpenClawStateDir(): string {
const profile = getEffectiveProfile();
export function resolveOpenClawStateDir(profileOverride?: string | null): string {
const profile = normalizeProfileName(profileOverride ?? getEffectiveProfile());
migrateLegacyProfileStorage(profile);
return resolveProfileStateDir(profile);
}
@ -325,11 +325,15 @@ export function resolveWorkspaceRoot(): string | null {
const normalizedProfile = normalizeProfileName(profile);
const stateDir = resolveProfileStateDir(profile);
const registryPath = getRegisteredWorkspacePath(profile);
const legacyWorkspaceFallback =
normalizedProfile
? join(resolveLegacySharedStateDir(), `workspace-${normalizedProfile}`)
: null;
const candidates = [
process.env.OPENCLAW_WORKSPACE,
registryPath,
join(stateDir, "workspace"),
normalizedProfile ? join(resolveLegacySharedStateDir(), `workspace-${normalizedProfile}`) : null,
legacyWorkspaceFallback,
].filter(Boolean) as string[];
for (const dir of candidates) {
@ -1009,6 +1013,7 @@ const ALWAYS_SYSTEM_PATTERNS = [
const ROOT_ONLY_SYSTEM_PATTERNS = [
/^workspace\.duckdb/,
/^workspace_context\.yaml$/,
/^IDENTITY\.md$/,
];
/** Check if a workspace-relative path refers to a protected system file. */