- E2Eテストのフィクスチャ、ヘルパー、スペックを追加 - mock/provider別のvitest設定を追加 - レビューエージェントのプロンプト改善 - TTY判定の共通化、list/confirmのnon-interactive対応 - eslint no-non-null-assertion を off に変更、未使用インポート削除
120 lines
3.5 KiB
TypeScript
120 lines
3.5 KiB
TypeScript
/**
|
|
* Path utilities for takt configuration
|
|
*
|
|
* This module provides pure path utilities without UI dependencies.
|
|
* For initialization with language selection, use initialization.ts.
|
|
*/
|
|
|
|
import { homedir } from 'node:os';
|
|
import { join, resolve } from 'node:path';
|
|
import { existsSync, mkdirSync } from 'node:fs';
|
|
import type { Language } from '../../core/models/index.js';
|
|
import { getLanguageResourcesDir } from '../resources/index.js';
|
|
|
|
/** Get takt global config directory (~/.takt or TAKT_CONFIG_DIR) */
|
|
export function getGlobalConfigDir(): string {
|
|
return process.env.TAKT_CONFIG_DIR || join(homedir(), '.takt');
|
|
}
|
|
|
|
/** Get takt global agents directory (~/.takt/agents) */
|
|
export function getGlobalAgentsDir(): string {
|
|
return join(getGlobalConfigDir(), 'agents');
|
|
}
|
|
|
|
/** Get takt global pieces directory (~/.takt/pieces) */
|
|
export function getGlobalPiecesDir(): string {
|
|
return join(getGlobalConfigDir(), 'pieces');
|
|
}
|
|
|
|
/** Get takt global logs directory */
|
|
export function getGlobalLogsDir(): string {
|
|
return join(getGlobalConfigDir(), 'logs');
|
|
}
|
|
|
|
/** Get takt global config file path */
|
|
export function getGlobalConfigPath(): string {
|
|
return join(getGlobalConfigDir(), 'config.yaml');
|
|
}
|
|
|
|
/** Get builtin pieces directory (resources/global/{lang}/pieces) */
|
|
export function getBuiltinPiecesDir(lang: Language): string {
|
|
return join(getLanguageResourcesDir(lang), 'pieces');
|
|
}
|
|
|
|
/** Get builtin agents directory (resources/global/{lang}/agents) */
|
|
export function getBuiltinAgentsDir(lang: Language): string {
|
|
return join(getLanguageResourcesDir(lang), 'agents');
|
|
}
|
|
|
|
/** Get project takt config directory (.takt in project) */
|
|
export function getProjectConfigDir(projectDir: string): string {
|
|
return join(resolve(projectDir), '.takt');
|
|
}
|
|
|
|
/** Get project config file path */
|
|
export function getProjectConfigPath(projectDir: string): string {
|
|
return join(getProjectConfigDir(projectDir), 'config.yaml');
|
|
}
|
|
|
|
/** Get project tasks directory */
|
|
export function getProjectTasksDir(projectDir: string): string {
|
|
return join(getProjectConfigDir(projectDir), 'tasks');
|
|
}
|
|
|
|
/** Get project completed tasks directory */
|
|
export function getProjectCompletedDir(projectDir: string): string {
|
|
return join(getProjectConfigDir(projectDir), 'completed');
|
|
}
|
|
|
|
/** Get project logs directory */
|
|
export function getProjectLogsDir(projectDir: string): string {
|
|
return join(getProjectConfigDir(projectDir), 'logs');
|
|
}
|
|
|
|
/** Ensure a directory exists, create if not */
|
|
export function ensureDir(dirPath: string): void {
|
|
if (!existsSync(dirPath)) {
|
|
mkdirSync(dirPath, { recursive: true });
|
|
}
|
|
}
|
|
|
|
/** Validate path is safe (no directory traversal) */
|
|
export function isPathSafe(basePath: string, targetPath: string): boolean {
|
|
const resolvedBase = resolve(basePath);
|
|
const resolvedTarget = resolve(targetPath);
|
|
return resolvedTarget.startsWith(resolvedBase);
|
|
}
|
|
|
|
// Re-export project config functions
|
|
export {
|
|
loadProjectConfig,
|
|
saveProjectConfig,
|
|
updateProjectConfig,
|
|
getCurrentPiece,
|
|
setCurrentPiece,
|
|
isVerboseMode,
|
|
type ProjectLocalConfig,
|
|
} from './project/projectConfig.js';
|
|
|
|
// Re-export session storage functions
|
|
export {
|
|
writeFileAtomic,
|
|
getInputHistoryPath,
|
|
MAX_INPUT_HISTORY,
|
|
loadInputHistory,
|
|
saveInputHistory,
|
|
addToInputHistory,
|
|
type AgentSessionData,
|
|
getAgentSessionsPath,
|
|
loadAgentSessions,
|
|
saveAgentSessions,
|
|
updateAgentSession,
|
|
clearAgentSessions,
|
|
// Worktree sessions
|
|
getWorktreeSessionsDir,
|
|
encodeWorktreePath,
|
|
getWorktreeSessionPath,
|
|
loadWorktreeSessions,
|
|
updateWorktreeSession,
|
|
} from './project/sessionStore.js';
|