fix: derive canvas root from workspace dir when not explicitly configured

When canvasHost.root is not set, use <workspace>/canvas instead of
hardcoded ~/clawd/canvas, so the canvas directory respects the
agents.defaults.workspace setting.
This commit is contained in:
sanool 2026-01-29 22:09:14 +00:00
parent 4583f88626
commit bfc4e5fe1d
3 changed files with 5 additions and 2 deletions

View File

@ -36,7 +36,7 @@ export type DiscoveryConfig = {
export type CanvasHostConfig = {
enabled?: boolean;
/** Directory to serve (default: ~/clawd/canvas). */
/** Directory to serve (default: <workspace>/canvas, e.g. ~/clawd/canvas). */
root?: string;
/** HTTP port to listen on (default: 18793). */
port?: number;

View File

@ -1,4 +1,5 @@
import type { Server as HttpServer } from "node:http";
import path from "node:path";
import { WebSocketServer } from "ws";
import { CANVAS_HOST_PATH } from "../canvas-host/a2ui.js";
import { type CanvasHostHandler, createCanvasHostHandler } from "../canvas-host/server.js";
@ -37,6 +38,7 @@ export async function createGatewayRuntimeState(params: {
deps: CliDeps;
canvasRuntime: RuntimeEnv;
canvasHostEnabled: boolean;
defaultWorkspaceDir: string;
allowCanvasHostInTests?: boolean;
logCanvas: { info: (msg: string) => void; warn: (msg: string) => void };
log: { info: (msg: string) => void; warn: (msg: string) => void };
@ -75,7 +77,7 @@ export async function createGatewayRuntimeState(params: {
try {
const handler = await createCanvasHostHandler({
runtime: params.canvasRuntime,
rootDir: params.cfg.canvasHost?.root,
rootDir: params.cfg.canvasHost?.root ?? path.join(params.defaultWorkspaceDir, "canvas"),
basePath: CANVAS_HOST_PATH,
allowInTests: params.allowCanvasHostInTests,
liveReload: params.cfg.canvasHost?.liveReload,

View File

@ -301,6 +301,7 @@ export async function startGatewayServer(
deps,
canvasRuntime,
canvasHostEnabled,
defaultWorkspaceDir,
allowCanvasHostInTests: opts.allowCanvasHostInTests,
logCanvas,
log,