import { join, resolve, sep } from "node:path"; import { z } from "zod"; import { getAppsDir } from "../../apps/app-store.js"; import { RiskLevel } from "../../permissions/types.js"; import { enqueuePkbIndexJob } from "../../plugins/defaults/memory/v1/jobs/embed-pkb-file.js"; import { getLogger } from "../../util/logger.js"; import { getWorkspaceDir } from "../../util/platform.js"; import { FileSystemOps } from "../shared/filesystem/file-ops-service.js"; import { formatWriteSummary } from "../shared/filesystem/format-diff.js"; import { sandboxPolicyWithHostFallback } from "../shared/filesystem/path-policy.js"; import { invalidToolInputResult, toToolInputSchema, } from "../shared/zod-tool-schema.js"; import type { ToolContext, ToolDefinition, ToolExecutionResult, } from "../types.js"; const logger = getLogger("file-write"); /** * Detects an attempt to write a self-contained interactive HTML document — * the signature of a "visualization" / "artifact" the model should be * building as a real app via the app-builder skill, not dumping as a loose * file. We deliberately trip ONLY on standalone docs with a substantial * INLINE script (the data + rendering live in the file). app-builder's own * scaffold writes a thin shell whose only script is an external module * (`