initial commit
This commit is contained in:
44
src/runner.ts
Normal file
44
src/runner.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
export function createTmuxSingleRunner(deps: {
|
||||
assertInsideTmux(): void;
|
||||
getCurrentWindowId: () => Promise<string>;
|
||||
createArtifacts: (cwd: string, meta: Record<string, unknown>) => Promise<any>;
|
||||
buildWrapperCommand: (metaPath: string) => string;
|
||||
createPane: (input: { windowId: string; cwd: string; command: string }) => Promise<string>;
|
||||
monitorRun: (input: { eventsPath: string; resultPath: string; onEvent?: (event: any) => void }) => Promise<any>;
|
||||
killPane: (paneId: string) => Promise<void>;
|
||||
}) {
|
||||
return async function runSingleTask(input: {
|
||||
cwd: string;
|
||||
meta: Record<string, unknown>;
|
||||
onEvent?: (event: any) => void;
|
||||
}) {
|
||||
deps.assertInsideTmux();
|
||||
|
||||
const artifacts = await deps.createArtifacts(input.cwd, input.meta);
|
||||
const windowId = await deps.getCurrentWindowId();
|
||||
const command = deps.buildWrapperCommand(artifacts.metaPath);
|
||||
const paneId = await deps.createPane({ windowId, cwd: input.cwd, command });
|
||||
|
||||
try {
|
||||
const result = await deps.monitorRun({
|
||||
eventsPath: artifacts.eventsPath,
|
||||
resultPath: artifacts.resultPath,
|
||||
onEvent: input.onEvent,
|
||||
});
|
||||
|
||||
return {
|
||||
...result,
|
||||
runId: result.runId ?? artifacts.runId,
|
||||
paneId,
|
||||
windowId,
|
||||
sessionPath: result.sessionPath ?? artifacts.sessionPath,
|
||||
stdoutPath: result.stdoutPath ?? artifacts.stdoutPath,
|
||||
stderrPath: result.stderrPath ?? artifacts.stderrPath,
|
||||
resultPath: artifacts.resultPath,
|
||||
eventsPath: artifacts.eventsPath,
|
||||
};
|
||||
} finally {
|
||||
await deps.killPane(paneId);
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user