Add CAD Factory observation dashboard
This commit is contained in:
1 parent
43fdc8e1b0
commit
a6e63ae91d
14 files changed
+940
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import { Plugin } from "@opencode/plugin"
|
||||
import { execFile } from "node:child_process"
|
||||
import { join } from "node:path"
|
||||
import { promisify } from "node:util"
|
||||
|
||||
const run = promisify(execFile)
|
||||
|
||||
export default Plugin.define({
|
||||
id: "cad-dashboard",
|
||||
async setup(ctx) {
|
||||
await ctx.tool.transform((editor) => {
|
||||
editor.namespace({ name: "cad_dashboard", description: "Локальная панель CAD Factory" })
|
||||
editor.add({
|
||||
name: "ensure",
|
||||
description: "Запускает или находит панель наблюдения для текущего CAD-проекта. Возвращает локальную ссылку, не открывая браузер.",
|
||||
options: { namespace: "cad_dashboard", codemode: true },
|
||||
input: { type: "object", properties: {}, additionalProperties: false },
|
||||
async execute(_, context) {
|
||||
await ctx.permission.assert({
|
||||
sessionID: context.sessionID,
|
||||
agent: context.agent,
|
||||
source: { type: "tool", messageID: context.messageID, id: context.id },
|
||||
action: "cad_dashboard",
|
||||
resources: ["ensure"],
|
||||
save: ["ensure"],
|
||||
})
|
||||
const root = ctx.location.directory
|
||||
try {
|
||||
const { stdout } = await run("python3", [
|
||||
"-I", join(root, "dashboard", "serve.py"), "--ensure", "--root", root,
|
||||
], { cwd: root, signal: context.signal, timeout: 15_000, maxBuffer: 8192 })
|
||||
return { content: stdout.trim() }
|
||||
} catch (error) {
|
||||
if (context.signal.aborted) throw error
|
||||
return { content: "Панель не удалось запустить. Из корня проекта можно попробовать вручную: python3 dashboard/serve.py" }
|
||||
}
|
||||
},
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
Reference in new issue
Block a user