diff --git a/extensions/goritech-media.ts b/extensions/goritech-media.ts index 2e7dab7..ded2e35 100644 --- a/extensions/goritech-media.ts +++ b/extensions/goritech-media.ts @@ -166,8 +166,11 @@ async function runVideoJob(requestId: string): Promise { // File helpers // --------------------------------------------------------------------------- +// Session-scoped output directory override (set via /gori-output) +let sessionOutputDir: string | undefined; + function outputDir(cwd: string): string { - const dir = process.env.GORITECHES_OUTPUT_DIR ?? path.join(cwd, "goritech-media"); + const dir = sessionOutputDir ?? process.env.GORITECHES_OUTPUT_DIR ?? path.join(cwd, "goritech-media"); fs.mkdirSync(dir, { recursive: true }); return dir; } @@ -503,6 +506,34 @@ export default function goritechMedia(pi: ExtensionAPI) { }, }); + // ----------------------------------------------------------------------- + // /gori-output [dir]: set or show output directory for this session + // ----------------------------------------------------------------------- + pi.registerCommand("gori-output", { + description: "Set or show output directory (usage: /gori-output [dir], empty to reset, no args to show)", + handler: async (args, ctx) => { + const dir = args.trim(); + if (!dir) { + const current = sessionOutputDir ?? process.env.GORITECHES_OUTPUT_DIR ?? path.join(ctx.cwd ?? process.cwd(), "goritech-media"); + ctx.ui.notify(`Output dir: ${current}${sessionOutputDir ? " (session override)" : ""}\nUsage: /gori-output to set, /gori-output reset to clear`, "info"); + return; + } + if (dir === "reset") { + sessionOutputDir = undefined; + ctx.ui.notify("Output dir reset to default (/goritech-media or GORITECHES_OUTPUT_DIR env)", "info"); + return; + } + const abs = path.resolve(ctx.cwd ?? process.cwd(), dir); + try { + fs.mkdirSync(abs, { recursive: true }); + sessionOutputDir = abs; + ctx.ui.notify(`Output dir set to: ${abs} (this session only)`, "info"); + } catch (err: any) { + ctx.ui.notify(`Failed to set output dir: ${err?.message ?? err}`, "error"); + } + }, + }); + // ----------------------------------------------------------------------- // /gori-media command: quick smoke test + usage // ----------------------------------------------------------------------- @@ -526,9 +557,10 @@ export default function goritechMedia(pi: ExtensionAPI) { `API key: ${keySource}`, `Image model: ${IMAGE_MODEL}`, `Video model: ${VIDEO_MODEL}`, - `Output dir: ${process.env.GORITECHES_OUTPUT_DIR ?? "/goritech-media"}`, + `Output dir: ${sessionOutputDir ?? process.env.GORITECHES_OUTPUT_DIR ?? "/goritech-media"}${sessionOutputDir ? " (session)" : ""}`, ``, `Tools: generate_image, edit_image, generate_video (model-callable)`, + `Commands: /gori-output [dir], /gori-fetch , /gori-media`, ].join("\n"), "info", );