Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/shared/task-output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { log } from "./logger";

export const INLINE_OUTPUT_MAX_CHARS = 15000;

export function getTaskOutputsDir(): string {
const dir = join(tmpdir(), "opencode-task-outputs");
if (!existsSync(dir)) {
try {
mkdirSync(dir, { recursive: true });
} catch (error) {
log(`[task-output] Failed to create output directory: ${error}`);
}
}
return dir;
}

export function saveOutputToFile(
toolName: string,
id: string,
content: string,
): string | null {
try {
const outputDir = getTaskOutputsDir();
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
const filename = `${toolName}_${id}_${timestamp}.md`;
const filePath = join(outputDir, filename);
writeFileSync(filePath, content, "utf-8");
return filePath;
} catch (error) {
log(`[task-output] Failed to save output to file: ${error}`);
return null;
}
}

export function truncateText(text: string, maxLength: number): string {
if (text.length <= maxLength) return text;
return text.slice(0, maxLength) + "...";
}
Loading