Edit photos by describing the change, on your own GPU. A free, open-source alternative to Nano Banana and ChatGPT image editing: photos stay on your computer, no daily limit. One installer for Windows, Mac and Linux sets up the best open model (Qwen-Image 2.1). MCP server for AI agents.
TypeScript ai-photo-editorcomfyui-alternativegenerative-fillimage-editingimage-generationinpaintinglinuxlocal-aimacosmcpmcp-servernano-banana-alternativeofflinephoto-editorprivacyqwen-imageqwen-image-2-1stable-diffusion-cppvulkanwindows
macos installer build fix
Gabriele Lozupone9f1194c00e4e
diff --git a/mcp/src/paths.ts b/mcp/src/paths.tsindex 08053ca..aa86179 100644--- a/mcp/src/paths.ts+++ b/mcp/src/paths.ts@@ -1,12 +1,17 @@// Path policy for MCP clients. An agent may only read images from — and write images// to — the project folder (MCP working directory), the app's output folder, and any// folders listed in QLS_MCP_ALLOWED_DIRS (semicolon separated). The service validates-// again on its side (UNC/device paths, traversal, no overwrite).+// again on its side (UNC/device paths, traversal, no overwrite). Windows paths compare+// case-insensitively and get the drive/stream/reserved-name checks; on macOS `\` is still+// read as a separator, so agents sending Windows-style relative paths behave the same.import fs from "node:fs";import path from "node:path";-const p = path.win32;+const WIN = process.platform === "win32";+const p = WIN ? path.win32 : path.posix;+const SEP = p.sep;+const fold = (x: string) => (WIN ? x.toLowerCase() : x);export const INPUT_EXT = [".png", ".jpg", ".jpeg", ".webp", ".bmp", ".gif", ".tif", ".tiff", ".heic", ".heif"];export const OUTPUT_EXT = [".png", ".jpg", ".jpeg", ".webp"];@@ -34,9 +39,9 @@ function realish(target: string): string {}export function isWithin(target: string, root: string): boolean {- const t = realish(p.resolve(target)).toLowerCase();- const r = realish(p.resolve(root)).toLowerCase().replace(/\\+$/, "");- return t === r || t.startsWith(r + "\\");+ const t = fold(realish(p.resolve(target)));+ const r = fold(realish(p.resolve(root))).replace(/[\\/]+$/, "");+ return t === r || t.startsWith(r + SEP);}/** Lexical checks shared by inputs and outputs; returns an absolute normalized path. */@@ -45,6 +50,7 @@ export function normalize(raw: string, cwd: string): string {if (!s) throw new PathError("The path is empty.");if (/[\u0000-\u001f]/.test(s)) throw new PathError("The path contains invalid characters.");if (s.startsWith("\\\\") || s.startsWith("//")) throw new PathError("Network and device paths are not allowed.");+ if (!WIN) return p.resolve(cwd, s.replace(/\\/g, "/"));if (/^[a-zA-Z]:(?![\\/])/.test(s)) throw new PathError("Drive-relative paths (like C:file.png) are not allowed.");const abs = p.resolve(cwd, s.replace(/\//g, "\\"));const parts = abs.slice(3).split("\\");diff --git a/mcp/src/service.ts b/mcp/src/service.tsindex 350bf4d..033ae79 100644--- a/mcp/src/service.ts+++ b/mcp/src/service.ts@@ -3,8 +3,12 @@import { spawn } from "node:child_process";import fs from "node:fs";+import os from "node:os";import path from "node:path";+const WIN = process.platform === "win32";+const SERVICE_EXE = WIN ? "kokon-service.exe" : "kokon-service";+export interface ServiceInfo {port: number;token: string;@@ -25,7 +29,10 @@ export class ServiceError extends Error {export function dataDir(): string {if (process.env.QLS_DATA_DIR) return process.env.QLS_DATA_DIR;- const base = process.env.LOCALAPPDATA ?? path.join(process.env.USERPROFILE ?? "C:\\", "AppData", "Local");+ // Same folder as the service's dirs::data_local_dir().+ const base = WIN+ ? (process.env.LOCALAPPDATA ?? path.join(process.env.USERPROFILE ?? "C:\\", "AppData", "Local"))+ : path.join(os.homedir(), "Library", "Application Support");// The service moves the folder of the app's old name (QwenLocalStudio) to KokonData on its// first start; until then the old one is read.const [next, old] = [path.join(base, "KokonData"), path.join(base, "QwenLocalStudio")];@@ -50,15 +57,20 @@ async function ping(port: number): Promise<boolean> {}export function findServiceExe(): string | null {- const local = process.env.LOCALAPPDATA ?? "";+ const installed = WIN+ ? [+ path.join(process.env.LOCALAPPDATA ?? "", "Kokon", SERVICE_EXE),+ path.join(process.env.ProgramFiles ?? "C:\\Program Files", "Kokon", SERVICE_EXE),+ ]+ : [path.join("/Applications", "Kokon.app", "Contents", "MacOS", SERVICE_EXE), path.join(os.homedir(), "Applications", "Kokon.app", "Contents", "MacOS", SERVICE_EXE)];const candidates = [process.env.QLS_SERVICE_EXE,- path.join(path.dirname(process.execPath), "kokon-service.exe"),- path.join(local, "Kokon", "kokon-service.exe"),- path.join(process.env.ProgramFiles ?? "C:\\Program Files", "Kokon", "kokon-service.exe"),+ // Next to kokon-mcp (Windows install folder, Kokon.app/Contents/MacOS)+ path.join(path.dirname(process.execPath), SERVICE_EXE),+ ...installed,// Development checkout (mcp/build -> target/...)- path.resolve(__dirname, "..", "..", "target", "release", "kokon-service.exe"),- path.resolve(__dirname, "..", "..", "target", "debug", "kokon-service.exe"),+ path.resolve(__dirname, "..", "..", "target", "release", SERVICE_EXE),+ path.resolve(__dirname, "..", "..", "target", "debug", SERVICE_EXE),];for (const c of candidates) {if (c && fs.existsSync(c)) return c;@@ -88,9 +100,9 @@ export class ServiceClient {const exe = findServiceExe();if (!exe) {throw new ServiceError(- "Kokon is not installed (kokon-service.exe not found).",+ `Kokon is not installed (${SERVICE_EXE} not found).`,"not_installed",- "Install Kokon, or set QLS_SERVICE_EXE to the path of kokon-service.exe.",+ `Install Kokon, or set QLS_SERVICE_EXE to the path of ${SERVICE_EXE}.`,);}// Detached: the service outlives this MCP process and exits on its own when idle.diff --git a/mcp/test/paths.test.ts b/mcp/test/paths.test.tsindex dd4940e..6930978 100644--- a/mcp/test/paths.test.ts+++ b/mcp/test/paths.test.ts@@ -13,9 +13,13 @@ const outside = path.join(tmp, "proj2");fs.mkdirSync(outside);fs.writeFileSync(path.join(outside, "x.png"), "x");const roots = [proj];+const WIN = process.platform === "win32";describe("normalize", () => {- it.each([["\\\\server\\share\\a.png"], ["\\\\?\\C:\\a.png"], ["//server/a.png"], ["C:\\a.png:ads"], ["C:\\x\\CON.png"], ["C:rel.png"], [""], ["a\u0000b"]])("rejects %s", (p) => {+ it.each([["\\\\server\\share\\a.png"], ["\\\\?\\C:\\a.png"], ["//server/a.png"], [""], ["a\u0000b"]])("rejects %s", (p) => {+ expect(() => normalize(p, proj)).toThrow(PathError);+ });+ it.runIf(WIN).each([["C:\\a.png:ads"], ["C:\\x\\CON.png"], ["C:rel.png"]])("rejects %s (Windows)", (p) => {expect(() => normalize(p, proj)).toThrow(PathError);});it("resolves relative paths against the project", () => {diff --git a/mcp/test/protocol.test.ts b/mcp/test/protocol.test.tsindex bad156b..4aef115 100644--- a/mcp/test/protocol.test.ts+++ b/mcp/test/protocol.test.ts@@ -8,12 +8,18 @@ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"import { afterAll, beforeAll, describe, expect, it } from "vitest";const root = path.resolve(__dirname, "..", "..");+const serviceExe = process.platform === "win32" ? "kokon-service.exe" : "kokon-service";+// The most recently built service (debug or release), so a stale build is not tested.+const serviceBuild = ["debug", "release"]+ .map((b) => path.join(root, "target", b, serviceExe))+ .filter((p) => fs.existsSync(p))+ .sort((a, b) => fs.statSync(b).mtimeMs - fs.statSync(a).mtimeMs)[0];const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "qls-mcp-proto-"));const env = {...process.env,QLS_DATA_DIR: path.join(tmp, "data"),QLS_CONFIG_DIR: path.join(tmp, "config"),- QLS_SERVICE_EXE: path.join(root, "target", "debug", "kokon-service.exe"),+ QLS_SERVICE_EXE: serviceBuild ?? path.join(root, "target", "debug", serviceExe),} as Record<string, string>;delete env.CLAUDE_PROJECT_DIR;fs.mkdirSync(env.QLS_CONFIG_DIR, { recursive: true });@@ -67,7 +73,7 @@ describe("MCP protocol", () => {const ok = await client.callTool({ name: "get_image_info", arguments: { image_path: "dot.png" } });expect(ok.isError).toBe(false);expect(ok.structuredContent).toMatchObject({ width: 1, height: 1, file_type: "png" });- const bad = await client.callTool({ name: "get_image_info", arguments: { image_path: "C:\\Windows\\System32\\cmd.png" } });+ const bad = await client.callTool({ name: "get_image_info", arguments: { image_path: path.join(os.tmpdir(), "cmd.png") } });expect(bad.isError).toBe(true);expect((bad.structuredContent as { error: { code: string } }).error.code).toBe("invalid_path");}, 60_000);diff --git a/scripts/build-release-mac.sh b/scripts/build-release-mac.shindex f6720c2..b066e41 100755--- a/scripts/build-release-mac.sh+++ b/scripts/build-release-mac.sh@@ -17,18 +17,17 @@ echo "1/5 Packages"npm ci --no-audit --no-fund(cd mcp && npm ci --no-audit --no-fund)-echo "2/5 Tests (Rust core + frontend + MCP)"+echo "2/5 Tests (Rust core + frontend)"cargo test -p qls-core --release --quietnpx vitest run-(cd mcp && npx vitest run)echo "3/5 kokon-service (release)"cargo build -p qls-service --releasemkdir -p src-tauri/binariescp target/release/kokon-service "src-tauri/binaries/kokon-service-$TRIPLE"-echo "4/5 kokon-mcp"-(cd mcp && npm run build:exe)+echo "4/5 kokon-mcp + MCP tests (they drive the bundle and the service built above)"+(cd mcp && npm run build:exe && npx vitest run)echo "5/5 Kokon.app + disk image (signed for the in-app updater)"# Updates are verified against the public key in tauri.conf.json. Copy the private key from