find tmux

This commit is contained in:
Chris Lettieri 2026-02-24 21:20:27 -05:00
parent 55465575aa
commit 3b49d555fe
4 changed files with 40 additions and 3 deletions

View file

@ -94,7 +94,8 @@ export class TaskDispatchService {
const contextContent = await this.assembleContext(file, taskId);
const contextFilePath = await this.writeContextFile(taskId, contextContent);
await this.createTmuxSession(tmux, sessionName, agentConfig, contextFilePath);
const workingDir = this.getWorkingDir(file);
await this.createTmuxSession(tmux, sessionName, agentConfig, contextFilePath, workingDir);
await this.openTerminal(sessionName);
}
} catch (error) {
@ -227,6 +228,22 @@ export class TaskDispatchService {
return taskId ? String(taskId) : null;
}
/**
* Resolve the working directory for a task session.
* Priority: `repo` frontmatter defaultWorkingDir setting home dir.
*/
private getWorkingDir(file: TFile): string {
const cache = this.app.metadataCache.getFileCache(file);
const fm = cache?.frontmatter;
const repo = fm?.['repo'];
if (repo && typeof repo === 'string') return repo;
const defaultDir = this.settings.taskDispatch.defaultWorkingDir;
if (defaultDir) return defaultDir;
return process.env.HOME ?? '/tmp';
}
private async assembleContext(file: TFile, taskId: string): Promise<string> {
// Read note body and strip frontmatter
const rawContent = await this.app.vault.read(file);
@ -297,9 +314,10 @@ export class TaskDispatchService {
tmux: string,
sessionName: string,
agentConfig: AgentConfig,
contextFilePath: string
contextFilePath: string,
workingDir: string
): Promise<void> {
await execAsync(`${tmux} new-session -d -s ${this.shellEscape(sessionName)}`);
await execAsync(`${tmux} new-session -d -s ${this.shellEscape(sessionName)} -c ${this.shellEscape(workingDir)}`);
const agentCommand = `${agentConfig.command} ${agentConfig.contextFlag} ${this.shellEscape(contextFilePath)}`;
await execAsync(

View file

@ -59,6 +59,7 @@ export const DEFAULT_SETTINGS: OpenAugiSettings = {
taskDispatch: {
terminalApp: 'iterm2',
tmuxPath: '',
defaultWorkingDir: '',
agents: [
{
id: 'claude-code',

View file

@ -12,6 +12,7 @@ export type TerminalApp = 'iterm2' | 'terminal-app';
export interface TaskDispatchSettings {
terminalApp: TerminalApp;
tmuxPath: string; // absolute path to tmux binary; empty = auto-detect
defaultWorkingDir: string; // directory Claude launches in; overridden by `repo` frontmatter
agents: AgentConfig[];
defaultAgent: string;
contextTempDir: string;

View file

@ -399,6 +399,23 @@ export class OpenAugiSettingTab extends PluginSettingTab {
})
);
new Setting(containerEl)
.setName('Default working directory')
.setDesc('Directory the agent launches in. Override per-task with `repo` in frontmatter.')
.addText(text => {
text
.setPlaceholder('~/projects')
.setValue(this.plugin.settings.taskDispatch.defaultWorkingDir);
text.inputEl.addEventListener('blur', async () => {
const value = text.getValue().trim();
if (value !== this.plugin.settings.taskDispatch.defaultWorkingDir) {
this.plugin.settings.taskDispatch.defaultWorkingDir = value;
await this.plugin.saveSettings();
}
});
return text;
});
new Setting(containerEl)
.setName('Default agent')
.setDesc('Agent to use when task note does not specify one')