mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-15 20:03:11 +00:00
Integrate OpenHandoff factory workspace (#212)
This commit is contained in:
parent
3d9476ed0b
commit
bf282199b5
251 changed files with 42824 additions and 692 deletions
45
factory/packages/cli/src/task-editor.ts
Normal file
45
factory/packages/cli/src/task-editor.ts
Normal 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 });
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue