Integrate OpenHandoff factory workspace (#212)

This commit is contained in:
Nathan Flurry 2026-03-09 14:00:20 -07:00 committed by GitHub
parent 3d9476ed0b
commit bf282199b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
251 changed files with 42824 additions and 692 deletions

View file

@ -0,0 +1,45 @@
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { spawnSync } from "node:child_process";
const DEFAULT_EDITOR_TEMPLATE = [
"# Enter handoff task details below.",
"# Lines starting with # are ignored.",
""
].join("\n");
export function sanitizeEditorTask(input: string): string {
return input
.split(/\r?\n/)
.filter((line) => !line.trim().startsWith("#"))
.join("\n")
.trim();
}
export function openEditorForTask(): string {
const editor = process.env.VISUAL?.trim() || process.env.EDITOR?.trim() || "vi";
const tempDir = mkdtempSync(join(tmpdir(), "hf-task-"));
const taskPath = join(tempDir, "task.md");
try {
writeFileSync(taskPath, DEFAULT_EDITOR_TEMPLATE, "utf8");
const result = spawnSync(editor, [taskPath], { stdio: "inherit" });
if (result.error) {
throw result.error;
}
if ((result.status ?? 1) !== 0) {
throw new Error(`Editor exited with status ${result.status ?? "unknown"}`);
}
const raw = readFileSync(taskPath, "utf8");
const task = sanitizeEditorTask(raw);
if (!task) {
throw new Error("Missing handoff task text");
}
return task;
} finally {
rmSync(tempDir, { recursive: true, force: true });
}
}