feat(coding-agent): configurable app name and config dir for forks (#95)

- Add piConfig to package.json for app name and config directory
- Consolidate paths.ts into config.ts with clearer naming
- Fix Bun binary detection (changed from %7EBUN to $bunfs)
- Update all hardcoded paths to use config.ts exports
- getThemesDir() for built-in themes, getCustomThemesDir() for user themes
This commit is contained in:
Mario Zechner 2025-12-03 16:18:59 +01:00
parent 9d5fe1fe85
commit e82fb0fc83
17 changed files with 241 additions and 167 deletions

View file

@ -1,6 +1,5 @@
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
import { homedir } from "os";
import { join } from "path";
import { getAgentDir, getOAuthPath } from "../config.js";
export interface OAuthCredentials {
type: "oauth";
@ -13,19 +12,11 @@ interface OAuthStorageFormat {
[provider: string]: OAuthCredentials;
}
/**
* Get path to oauth.json
*/
function getOAuthFilePath(): string {
const configDir = join(homedir(), ".pi", "agent");
return join(configDir, "oauth.json");
}
/**
* Ensure the config directory exists
*/
function ensureConfigDir(): void {
const configDir = join(homedir(), ".pi", "agent");
const configDir = getAgentDir();
if (!existsSync(configDir)) {
mkdirSync(configDir, { recursive: true, mode: 0o700 });
}
@ -35,7 +26,7 @@ function ensureConfigDir(): void {
* Load all OAuth credentials from oauth.json
*/
function loadStorage(): OAuthStorageFormat {
const filePath = getOAuthFilePath();
const filePath = getOAuthPath();
if (!existsSync(filePath)) {
return {};
}
@ -54,7 +45,7 @@ function loadStorage(): OAuthStorageFormat {
*/
function saveStorage(storage: OAuthStorageFormat): void {
ensureConfigDir();
const filePath = getOAuthFilePath();
const filePath = getOAuthPath();
writeFileSync(filePath, JSON.stringify(storage, null, 2), "utf-8");
// Set permissions to owner read/write only
chmodSync(filePath, 0o600);