mirror of
https://github.com/penpot/penpot.git
synced 2026-09-24 21:06:14 +00:00
* ⬆️ Update devenv dependencies Update Node.js, OpenCode, clj-kondo, Babashka, Pixi, GitHub CLI, uv, and Serena to their current stable releases. AI-assisted-by: gpt-5.6-sol * ⬆️ Update devenv to Java 27 Use Zulu JDK 27 in the development image for compatibility testing. Update the official checksums for both supported architectures. AI-assisted-by: gpt-5.6-sol * 🐳 Replace MinIO with RustFS in devenv Run RustFS as the development S3 service and wait for its health check. Install a pinned AWS CLI with checksums and use it to create the bucket idempotently from each backend entry point. Keep the old MinIO volume untouched and use a new RustFS volume. AI-assisted-by: gpt-5.6-sol * 🐳 Replace MailCatcher with persistent Mailpit Run Mailpit as the devenv SMTP sink while preserving mailer:1025 and the localhost:1080 UI. Store its SQLite inbox in a named volume and wait for the readiness endpoint before starting runtime containers. Bind the web UI to loopback so development emails stay local. AI-assisted-by: gpt-5.6-sol * ⬆️ Update Node.js to 24.21.0 Align the host NVM version with the Node.js version used by devenv. AI-assisted-by: gpt-5.6-sol * ⬆️ Update devenv to PostgreSQL 18.6 Run PostgreSQL 18 with its versioned volume layout and a TCP readiness check that ignores the temporary initialization server. Install the matching client, create penpot_nexus, and preserve the old PostgreSQL 16 volume for rollback or logical migration. AI-assisted-by: gpt-5.6-sol * 🐳 Expose RustFS ports in devenv Publish the RustFS S3 API and management console on localhost port 9000 and 9001. Keep both bindings on loopback so object storage is not exposed to the local network. AI-assisted-by: gpt-5.6-sol * 🐳 Install standalone pnpm in devenv Install pnpm 12.5.0 from architecture-specific release archives and verify their published checksums. Remove the Corepack setup while allowing pnpm to honor the project packageManager pins. AI-assisted-by: gpt-5.6-sol * 🔥 Remove corepack, use system pnpm everywhere Corepack is gone from Node 25+, so every `corepack enable` call fails. pnpm now ships as a system binary (devenv, CI runners and Docker images install it directly) and auto-downloads the version pinned in `packageManager` on mismatch. Scripts, workflows and Dockerfiles call `pnpm` straight away; the three deploy workflows use a single `pnpm/setup@v2` step; and the new `scripts/sync-pnpm-version` stamps all 35 `packageManager` fields from the system pnpm, replacing the `corepack use` sweep. AI-assisted-by: muse-spark-1.3-contributor * 🐛 Fix exporter watch missing render-wasm build step The exporter watch compiled CLJS requiring the generated src/app/wasm/shared.js, which only render-wasm/build export produces. Without it shadow-cljs failed with a cryptic missing ./shared.js dependency. Run build:wasm before watching, as the frontend watch:app and exporter scripts/build already do. AI-assisted-by: muse-spark-1.3-contributor * 🔧 Add opencode V2 support and adapt plugins Register the penpot tools for both opencode V1 (server()) and V2 (setup() with JSON Schema inputs) from a single dependency-free plugin file, sharing the psql and paren-repair runners between both paths. Install the opencode2 binary side-by-side with V1 in the devenv image and document the dual registration in the paren-repair and psql memories. AI-assisted-by: muse-spark-1.3-contributor * ⬆️ Update pnpm and opencode
245 lines
6.6 KiB
JavaScript
245 lines
6.6 KiB
JavaScript
// Penpot opencode plugin: custom tools for Penpot development.
|
|
//
|
|
// Dual V1 + V2 implementation from a single file:
|
|
// - OpenCode V1 (>= 1.18.29) calls the default export's `server()` and uses
|
|
// the returned `tool` map (built with the `tool()` helper from
|
|
// `@opencode-ai/plugin`).
|
|
// - OpenCode V2 reads the default export's `id` and `setup()` and ignores
|
|
// `server()`. Tools are registered via `ctx.tool.transform()` with JSON
|
|
// Schema inputs, and `execute` returns `{ content }`.
|
|
// See https://opencode.ai/v2/docs/build/plugins/migrate-v1
|
|
//
|
|
// NOTE: the V2 side intentionally does NOT
|
|
// `import { Plugin } from "@opencode/plugin"`. At runtime `Plugin.define` is
|
|
// the identity function, so a plain `{ id, setup }` object is equivalent, and
|
|
// skipping the import keeps this plugin dependency-free
|
|
// (`.opencode/package.json` is gitignored, so a new dependency declared there
|
|
// would not travel with this file).
|
|
|
|
import { tool } from "@opencode-ai/plugin"
|
|
import path from "path"
|
|
import { spawn } from "child_process"
|
|
|
|
function runCommand(command, args, options = {}) {
|
|
const {
|
|
cwd,
|
|
env,
|
|
stdin,
|
|
closeStdin = false,
|
|
successMessage = "Command executed successfully",
|
|
} = options
|
|
|
|
return new Promise((resolve) => {
|
|
let stdout = ""
|
|
let stderr = ""
|
|
|
|
const proc = spawn(command, args, { cwd, env })
|
|
|
|
proc.stdout.on("data", (data) => {
|
|
stdout += data.toString()
|
|
})
|
|
|
|
proc.stderr.on("data", (data) => {
|
|
stderr += data.toString()
|
|
})
|
|
|
|
proc.on("error", (error) => {
|
|
resolve(`Error: ${error.message}`)
|
|
})
|
|
|
|
proc.on("close", (exitCode) => {
|
|
const output =
|
|
exitCode === 0
|
|
? stdout.trim() || successMessage
|
|
: `Error (exit ${exitCode}): ${
|
|
(stderr || stdout).trim() || "No error output"
|
|
}`
|
|
resolve(output)
|
|
})
|
|
|
|
// Close stdin so the child cannot wait on it indefinitely. `psql -c`
|
|
// never reads stdin, so only the paren-repair pipe mode needs this, but
|
|
// closing it unconditionally is harmless there.
|
|
if (stdin !== undefined) {
|
|
proc.stdin.end(stdin)
|
|
} else if (closeStdin) {
|
|
proc.stdin.end()
|
|
}
|
|
})
|
|
}
|
|
|
|
function executePsql(sql, useTestDb, cwd) {
|
|
const host = process.env.PENPOT_DB_HOST || "postgres"
|
|
const user = process.env.PENPOT_DB_USER || "penpot"
|
|
const db = useTestDb
|
|
? "penpot_test"
|
|
: process.env.PENPOT_DB_NAME || "penpot"
|
|
const password = process.env.PENPOT_DB_PASSWORD || "penpot"
|
|
|
|
const psqlArgs = ["-h", host, "-U", user, "-d", db, "-c", sql]
|
|
|
|
return runCommand("psql", psqlArgs, {
|
|
cwd,
|
|
env: { ...process.env, PGPASSWORD: password },
|
|
successMessage: "Query executed successfully",
|
|
})
|
|
}
|
|
|
|
function executeParenRepair({ files, code }, directory) {
|
|
const script = path.join(directory, "scripts/paren-repair")
|
|
|
|
const fileList = files
|
|
? files
|
|
.split(",")
|
|
.map((file) => file.trim())
|
|
.filter(Boolean)
|
|
: []
|
|
|
|
const childArgs =
|
|
fileList.length > 0 ? [script, ...fileList] : [script]
|
|
|
|
return runCommand("bb", childArgs, {
|
|
cwd: directory,
|
|
stdin: code,
|
|
closeStdin: true,
|
|
successMessage: "No changes needed",
|
|
})
|
|
}
|
|
|
|
// --- V1 tool definitions (OpenCode V1 calls `server()` below) ---
|
|
|
|
const penpotPsqlTool = tool({
|
|
description:
|
|
"Execute a SQL command against the Penpot database. Uses the defaults from scripts/psql.",
|
|
|
|
args: {
|
|
sql: tool.schema
|
|
.string()
|
|
.describe("SQL command to execute"),
|
|
|
|
test: tool.schema
|
|
.boolean()
|
|
.describe("Use the penpot_test database")
|
|
.optional(),
|
|
},
|
|
|
|
async execute(args, context) {
|
|
return executePsql(args.sql, args.test === true, context.worktree)
|
|
},
|
|
})
|
|
|
|
const parenRepairTool = tool({
|
|
description:
|
|
"Fix mismatched parentheses/braces in Clojure files (.clj, .cljs, .cljc) then reformat with cljfmt.",
|
|
|
|
args: {
|
|
// A string is used instead of an array so OpenCode displays it
|
|
// in the generic tool invocation.
|
|
files: tool.schema
|
|
.string()
|
|
.describe(
|
|
"Comma-separated file paths to fix, for example: frontend/src/app/config.cljs, backend/src/core.clj",
|
|
)
|
|
.optional(),
|
|
|
|
code: tool.schema
|
|
.string()
|
|
.describe("Code string to fix via stdin")
|
|
.optional(),
|
|
},
|
|
|
|
async execute(args, context) {
|
|
return executeParenRepair(args, context.worktree)
|
|
},
|
|
})
|
|
|
|
async function server() {
|
|
return {
|
|
tool: {
|
|
"paren-repair": parenRepairTool,
|
|
"penpot-psql": penpotPsqlTool,
|
|
},
|
|
}
|
|
}
|
|
|
|
// --- V2 setup (OpenCode V2 calls `setup()` and ignores `server()`) ---
|
|
|
|
const penpotPsqlInputSchema = {
|
|
type: "object",
|
|
properties: {
|
|
sql: {
|
|
type: "string",
|
|
description: "SQL command to execute",
|
|
},
|
|
test: {
|
|
type: "boolean",
|
|
description: "Use the penpot_test database",
|
|
},
|
|
},
|
|
required: ["sql"],
|
|
additionalProperties: false,
|
|
}
|
|
|
|
const parenRepairInputSchema = {
|
|
type: "object",
|
|
properties: {
|
|
// A string is used instead of an array so OpenCode displays it
|
|
// in the generic tool invocation.
|
|
files: {
|
|
type: "string",
|
|
description:
|
|
"Comma-separated file paths to fix, for example: frontend/src/app/config.cljs, backend/src/core.clj",
|
|
},
|
|
code: {
|
|
type: "string",
|
|
description: "Code string to fix via stdin",
|
|
},
|
|
},
|
|
additionalProperties: false,
|
|
}
|
|
|
|
async function setup(ctx) {
|
|
// Plugin instance location. This is not the location of every session the
|
|
// tools may run for, but it is the closest V2 equivalent of the V1
|
|
// per-execution `context.worktree` (the repo checkout the plugin loaded
|
|
// from), which is what both tools need as cwd / script base.
|
|
const directory =
|
|
ctx.location.directory ?? ctx.location.project?.canonical
|
|
|
|
// Keep this callback synchronous: transforms are replayable state edits.
|
|
// The async work happens later, inside each tool's `execute`.
|
|
await ctx.tool.transform((editor) => {
|
|
editor.add({
|
|
name: "penpot-psql",
|
|
description:
|
|
"Execute a SQL command against the Penpot database. Uses the defaults from scripts/psql.",
|
|
input: penpotPsqlInputSchema,
|
|
async execute(input) {
|
|
const content = await executePsql(
|
|
input.sql,
|
|
input.test === true,
|
|
directory,
|
|
)
|
|
return { content }
|
|
},
|
|
})
|
|
|
|
editor.add({
|
|
name: "paren-repair",
|
|
description:
|
|
"Fix mismatched parentheses/braces in Clojure files (.clj, .cljs, .cljc) then reformat with cljfmt.",
|
|
input: parenRepairInputSchema,
|
|
async execute(input) {
|
|
const content = await executeParenRepair(input, directory)
|
|
return { content }
|
|
},
|
|
})
|
|
})
|
|
}
|
|
|
|
export default {
|
|
id: "penpot",
|
|
setup,
|
|
server,
|
|
}
|