mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-21 22:01:49 +00:00
Integrate OpenHandoff factory workspace (#212)
This commit is contained in:
parent
3d9476ed0b
commit
bf282199b5
251 changed files with 42824 additions and 692 deletions
22
factory/packages/backend/src/config/backend.ts
Normal file
22
factory/packages/backend/src/config/backend.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { dirname } from "node:path";
|
||||
import { homedir } from "node:os";
|
||||
import * as toml from "@iarna/toml";
|
||||
import { ConfigSchema, type AppConfig } from "@openhandoff/shared";
|
||||
|
||||
export const CONFIG_PATH = `${homedir()}/.config/openhandoff/config.toml`;
|
||||
|
||||
export function loadConfig(path = CONFIG_PATH): AppConfig {
|
||||
if (!existsSync(path)) {
|
||||
return ConfigSchema.parse({});
|
||||
}
|
||||
|
||||
const raw = readFileSync(path, "utf8");
|
||||
const parsed = toml.parse(raw) as unknown;
|
||||
return ConfigSchema.parse(parsed);
|
||||
}
|
||||
|
||||
export function saveConfig(config: AppConfig, path = CONFIG_PATH): void {
|
||||
mkdirSync(dirname(path), { recursive: true });
|
||||
writeFileSync(path, toml.stringify(config), "utf8");
|
||||
}
|
||||
13
factory/packages/backend/src/config/workspace.ts
Normal file
13
factory/packages/backend/src/config/workspace.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import type { AppConfig } from "@openhandoff/shared";
|
||||
|
||||
export function defaultWorkspace(config: AppConfig): string {
|
||||
const ws = config.workspace.default.trim();
|
||||
return ws.length > 0 ? ws : "default";
|
||||
}
|
||||
|
||||
export function resolveWorkspace(flagWorkspace: string | undefined, config: AppConfig): string {
|
||||
if (flagWorkspace && flagWorkspace.trim().length > 0) {
|
||||
return flagWorkspace.trim();
|
||||
}
|
||||
return defaultWorkspace(config);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue