dsh-comfyui-panel
界面增强 活跃维护

dsh-comfyui-panel

Natsubrei/dsh-comfyui-panel

提供真正的 ComfyUI 编辑器内嵌面板,按会话隔离工作流与节点,支持面板内直接管理 ComfyUI 实例、拖拽编排、实时预览与出图调试,免去窗口切换。

0
Stars 标星
0
Forks 分支
0
Watchers 关注
0
Open Issues
JavaScript
主要语言
MIT
开源协议
389 KB
仓库大小
1 个月前
最后推送
一键安装扩展 / 插件指令
dsh plugin --profile web add github:Natsubrei/dsh-comfyui-panel
git clone https://github.com/Natsubrei/dsh-comfyui-panel.git
git clone git@github.com:Natsubrei/dsh-comfyui-panel.git
README.md main

dsh-comfyui-panel

test
license

ComfyUI inside the DeepSeek Harness Web UI: the real editor in a right-side
panel, a workflow the model can read and edit, and runs the model can start.

Install

From the plugin market (recommended). In DSH, open Settings → Plugins →
Discover → Add index source
and paste:

https://raw.githubusercontent.com/Natsubrei/dsh-comfyui-panel/main/market/index.json

The ComfyUI Panel card installs the bundle; the index pins one exact commit
per version, so an install always matches a tested release. The same index is
what the plugin_market tool reads, so an agent can list it, show versions, and
install without a browser.

With the agent or the CLI. The market hands install_bundle an install spec
of the form git+https://github.com/Natsubrei/dsh-comfyui-panel.git#<commit>;
that is also the spec to paste yourself:

dsh plugin --profile <name> add 'git+https://github.com/Natsubrei/dsh-comfyui-panel.git'

dsh plugin links or installs the package and appends it to the profile's
bundle list. Restart DSH if the profile was already running; clients need a hard
refresh after a bundle change.

From npm once the package is published:

dsh plugin --profile <name> add dsh-comfyui-panel

Then configure the upstream if it is not 127.0.0.1:8188, and
read on for the panel itself.

What it does

  • Serves the real ComfyUI frontend under the DSH origin at /comfyui/
    through an authenticated reverse proxy (HTTP + WebSocket).
  • Adds a ComfyUI tab to the right sidebar. The tab is session-scoped and
    can be used full-screen; it loads /comfyui/ in a same-origin iframe, so
    third-party nodes keep their own UI.
  • Bridges the iframe editor to the Host: once window.comfyAPI.app.app is
    available, the panel periodically serializes the UI workflow, builds a
    semantic projection from the live nodes (ids, class types, widget names and
    values, input sources, selection), asks app.graphToPrompt() for the API
    prompt, and POSTs all three to /api/comfyui/state.
  • Subscribes to the embedded editor's own event bus (app.api, a DOM
    EventTarget) and forwards a compact event stream (queue status,
    execution_start, executing, progress, executed, execution_success /
    execution_error / execution_interrupted) to /api/comfyui/events, so the
    Host sees runs without polling. ComfyUI addresses those events to the socket
    that queued the prompt, so the panel relays the editor's connection instead of
    opening one of its own.
  • Registers seven model tools on the Agent context of each session that has a
    synced workflow
    . Other sessions see no ComfyUI tools:
    • comfyui_status — upstream reachability, panel connection, workflow
      summary, persistence backend, supervisor state, and the latest run.
    • comfyui_graph_read — the semantic projection: per node id, type,
      title, mode, widgets (name -> value), and inputs
      (name -> "<sourceNodeId>:<slot>"). layout=true returns the canvas boxes
      plus an overlap verdict, full=true the raw UI workflow and API prompt.
    • comfyui_run — submit the synced API prompt and return the prompt_id;
      optionally wait for history.
    • comfyui_progress — panel events (current node, step progress, errors),
      the run record, and a live /queue snapshot.
    • comfyui_edit — add, remove, move, and reconnect nodes and set widget
      values inside the open panel through a Host → panel command channel. One
      batch is applied in order and answers with the node and link counts it left
      behind, so a half-applied edit is visible in the result.
    • comfyui_screenshot — serialize the panel's editor canvas to a PNG on
      disk and return the path; open it with read_image to see the graph the
      user sees.
    • comfyui_node_info — cached /object_info lookup for class types and
      input names.
  • Adds one runtime-context digest line to those sessions, e.g.
    ComfyUI: rev 14 · 9 nodes · 9 links · selected 7 · panel open.
  • Persists each session's workflow, API prompt, and projection through
    ctx.storageDomain (domain dsh_comfyui), so a Host restart does not lose
    the graph. Storage failures degrade to memory without blocking the bridge.
  • Manages the ComfyUI process from the panel. The Server section starts,
    stops, and restarts ComfyUI, remembers the checkout directory, and can start
    it together with DSH. It adopts an already-running server instead of
    launching a duplicate. No profile configuration is required.

Configuration

The bundle's own patch, cordis.patch.yml:

- insert:
    - id: dsh-comfyui-panel
      name: dsh-comfyui-panel
      config:
        upstream: http://127.0.0.1:8188
        prefix: /comfyui

Override the row in your profile's cordis.patch.yml by the same id to change
upstream or prefix; a patch replaces the row's whole config, so repeat
every key you keep.

prefix is the same-origin path the panel is served from; upstream is the
ComfyUI server. Both must agree with the panel's hard-coded /comfyui/.

Process management needs no configuration: open the panel's Server section,
point it at the ComfyUI directory (the folder with main.py; a common location
is detected automatically), and press Start. The command is derived from
that directory (<dir>/.venv/bin/python, else python3) and the arguments from
the configured upstream port, so the panel cannot run arbitrary commands. The
directory and the Start with DSH flag are stored in the plugin's own
dsh_comfyui domain, not in the DSH profile.

For advanced setups, the plugin row still accepts a supervise block that
takes precedence at start-up:

        supervise:
          enabled: true
          command: /opt/ComfyUI/.venv/bin/python
          args: [main.py, --listen, 127.0.0.1, --port, '8188']
          cwd: /opt/ComfyUI
          restartDelayMs: 5000
          maxRestarts: 5
          probeIntervalMs: 20000
          startTimeoutMs: 120000
          logPath: /var/log/comfyui/comfyui.log

cwd is required when that block is enabled; a missing value fails the plugin
load instead of silently never starting ComfyUI. command defaults to
python3, args to main.py --listen 127.0.0.1. An upstream that already
answers /system_stats is adopted (state: external) rather than duplicated.
Unloading the plugin stops only a process it started.

Requirements

  • A running ComfyUI whose frontend is the standard comfyui-frontend-package
    build (relative ./assets/..., api_base derived from the path).
  • The DSH Web profile with storage + storage-json + storage-domain
    mounted (the default profile has them). Without them, workflows stay in
    memory.
  • The panel relies on the same-origin iframe and on
    window.comfyAPI.app.app, a legacy compatibility shim exposed by the
    ComfyUI frontend, not a stable public API. Pin the ComfyUI frontend version
    for anything beyond this milestone. What the plugin actually uses — and how
    to re-derive it after an upgrade — is in
    docs/comfyui-bridge.md; the panel was last verified
    against frontend 1.57.1.

Try it without ComfyUI

A mock upstream is included so the proxy/iframe/bridge can be tested without
torch:

node test/mock-comfyui.mjs

Then open the ComfyUI tab in a session and wait for Connected. The
mock page exposes a one-node workflow. comfyui_run should return p1. Stop
the mock before starting a real ComfyUI on port 8188.

Run the checks with:

npm install       # once: typescript and @types/node for the type check
npm run typecheck # checkJs over the plugin, the tests and the scripts
npm test          # checks, host smoke, editor ops, hygiene, market index
npm run contract  # real DSH runtime, needs ../deepseek-harness
npm run ui        # live panel in a headless browser, needs a running dsh web
npm run shot -- workflow.json   # render a workflow file to a PNG

npm test covers the proxy, redirect, asset caching, the workflow and event
bridges, session-scoped tools and digest, the projection fallback, persistence
across two Host instances, the edit round-trip, the panel-managed
start/stop/restart of a real child process, and the supervisor's adoption path.
It prints host smoke test passed. npm run contract mounts the plugin next to
the real Cordis context, ToolRuntime, SystemPrompt, and
HostConnectionService, so an invalid Fetch path or a tool schema the registry
rejects fails locally instead of at install time. npm test and
npm run typecheck are what the pre-commit hook runs; see
AGENTS.md for reload and logging steps.

npm run ui is the browser check: it opens the GUI in a headless Chromium, puts
the panel in a throwaway session, and asserts the panel's observable behaviour —
the editor boots, the counters describe the graph on screen, zooming is not an
edit, a widget edit bumps the revision once, editor events reach the bar, the
Host learned the editor's socket id, and Fit frames the graph. It needs an
installed Chromium-family browser but installs nothing; see
test/ui/README.md. npm test also scans the tree and the
whole history for machine-specific paths, so a stray home directory fails
before it ships.

npm run shot -- workflow.json renders a workflow file to a PNG without a DSH
session: it loads the graph into a real ComfyUI frontend, frames it the way the
editor does, writes the image, and prints the boxes that overlap or sit closer
than 16 pixels (exit code 2 when any do). Use it to judge a layout file, or
comfyui_screenshot for the graph already open in a panel.

Current limits

  • Edits require the ComfyUI panel to be open in the same session; the command
    channel is a long-poll and the panel applies operations inside the iframe.
  • comfyui_edit does not validate graph semantics; a bad edit is rejected
    when ComfyUI converts the graph to a prompt.
  • Sync is polling-based (about once per second while the tab is visible).
  • A session that never opened the panel shows no ComfyUI tools. After a Host
    restart a persisted session gets them back; a brand-new session gets them on
    its first panel sync.
  • save/cancel of a run are not exposed yet; comfyui_run only queues.
  • The panel is an iframe, so it does not inherit DSH theme tokens; this is a
    deliberate exception for UI-workflow fidelity and third-party node UIs.
  • Execution events are relayed from the editor's own bus, so progress and errors
    exist only while the panel is mounted; a run started before the panel opened
    shows its queue entry but no step progress.
  • A ComfyUI the plugin only adopted stays running when the plugin unloads: it did
    not start that process, and after a reload it cannot tell its own survivor from
    a server you launched by hand. Stop it from the panel first if you want it
    gone; a child the plugin spawned is stopped on unload.
  • The process manager cannot distinguish a hung ComfyUI from one doing a long
    generation that stops answering /system_stats; health restarts should be
    tuned per workload.
  • An upstream the plugin cannot adopt — a pid it cannot name, or one running
    from a different directory — stays external: the plugin never stops it and
    the panel hides Stop/Restart. One it can adopt gets those buttons, but keeps
    running when the plugin unloads (previous bullet).

Design notes

  • The UI workflow stays canonical. The API prompt is derived by the real
    graphToPrompt(); the projection is a read-only view built from the same
    nodes, so the model never sees a second, lossy graph representation as truth.
  • State lives in the plugin. Workflows survive restarts through a domain KV
    record (sessionId -> { workflow, prompt, semantic, revision }), capped at
    the 20 most recently updated sessions. The model only sees the projection and
    its own edit results.
  • revision tracks edits, not the viewport. The frontend serializes
    extra.ds (zoom/pan) into every workflow, so the Host strips it before
    comparing and storing: scrolling, zooming, or resizing the panel does not
    change rev, while real edits still advance it.
  • Tools follow the session. Registration happens on agent.ctx, so an
    agent-scoped tool list and prompt context decide visibility; unregistering
    happens through the same effect chain when the plugin unloads.
  • No core or ComfyUI changes. The proxy, the iframe reach into
    comfyAPI.app.app, and the command channel are the whole integration.