GCS-ZHN/mol4agent--packages-deepseek-harness ↗★ 2

@gcszhn/mol4agent-deepseekharness

DeepSeek Harness adapter: molecular document preview, agent-driven viewer commands, and PNG capture.

패키지
@gcszhn/mol4agent-deepseekharness
호환성
미검증
Harness peer 범위
>=0.2.2-rc.3 <0.3.0
Cordis peer 범위
^4.1.0
버전
0.1.0
라이선스
MIT
최근 업데이트
2026. 11. 15.

설치

$npx -p @deepseek-ai/dsh dsh plugin --profile web add 'github:GCS-ZHN/mol4agent#03379f204a8484248cdf098843821cba91f590cb&path:packages/deepseek-harness'

@gcszhn/mol4agent-deepseekharness

English | 中文

DeepSeek Harness (DSH) adapter for mol4agent: a right-sidebar molecular document preview that an agent can operate.

  • Structure: .pdb, .ent, .pdbqt, .pqr, .cif, .mmcif, .mcif, .bcif, .mol, .sdf, .sd, .mol2, .xyz, .gro open in Mol*'s official UI instead of plain text. Every claimed suffix also accepts a .gz variant (for example .pdb.gz, .cif.gz, .sdf.gz); the adapter decodes it before handing bytes to core. The previewer's Open with menu still offers code/plain text (bcif has no plain-text fallback because its bytes are binary).
  • Agent tools: mol_info, mol_interface, mol_open, mol_style, mol_select, mol_focus, mol_measure, mol_capture.
  • Agent-driven page: tool calls are folded into a durable session projection; the open page follows it and applies commands.
  • Auto-open: naming a new structure reveals its preview through a session-header bridge.
  • Screenshots: the page renders a PNG and delivers it back to the blocked tool call; a copy is saved under .mol4agent/captures/.

Architecture

flowchart TB
  subgraph Host["DSH Host"]
    Tools["mol_* tools"]
    Projection["session projection: mol4agent"]
    CaptureHub["CaptureHub"]
    CaptureCommand["/mol4agent_capture"]
    Prompt["system prompt section"]
  end

  subgraph Browser["DSH web client"]
    Definition["documentPreviews: mol4agent/molstar"]
    Body["MolBody: sidebar.right.tab.document"]
    Bridge["MolBridge: session header"]
    Viewer["Mol* official UI"]
    Cache["per-tab viewer cache (LRU 2)"]
  end

  Tools -->|"tool/call event"| Projection
  Projection -->|"useProjection('mol4agent')"| Body
  Bridge -->|"openResource(address)"| Definition
  Definition --> Body
  Body --> Viewer
  Body --> Cache
  Body -->|"commands.execute"| CaptureCommand
  CaptureCommand --> CaptureHub
  CaptureHub --> Tools

Boundary: all path handling lives here — suffix to MolFormat, workspace reads, authorization, sessions, projections, UI. @gcszhn/mol4agent-core only receives bytes plus an explicit format.

Agent tools

All tools are Host tools. Mutating tools are registered with isConcurrencySafe: () => false. The Host tool body validates arguments and reads files for summaries; the projection turns the recorded tool/call into viewer commands, so the page changes even if the tool card is scrolled away.

ToolParametersBehavior
mol_infopathSummarize chains, residues, atoms, ligands. Does not open a viewer or change the scene.
mol_interfacepath, chainsA, chainsB, cutoff?Find interface residues between two chain groups (default 8 Å, 0
}

- The image is attached to the tool result only when `imageCapable` is true;
  otherwise the text result reports the attachment and, when available, the saved
  path.
- `savedPath` is `/.mol4agent/captures/mol4agent--.png`.
- `diagnostics` carries the browser-side status/path/command counts and Mol* hierarchy diagnostics.

### Tool-call to command mapping

| Tool | Scene effect |
|---|---|
| `mol_open` | New `sceneKey`; commands `[represent, select?]` or `[represent, focus?]` |
| `mol_style` | Append `{ op: 'represent', style, target? }` |
| `mol_select` | Append `{ op: 'select', target, mode, focus? }` |
| `mol_focus` | Append `{ op: 'focus', target? }` |
| `mol_measure` | Append `{ op: 'measure', kind, targets }` |
| `mol_capture` | Add a pending capture entry; no viewer command |
| `mol_interface` | None; returns computed ranges only |
| `mol_info` | None |

## Session projection

The projection key is **`mol4agent`**. It is registered on the Host, folded from
session events, and exposed to the browser through the projection wire.

```ts
interface MolSessionState {
  revision: number
  cwd?: string
  tabs: Record
  active: string | null   // absolute path
  pending: Record
}
  • mol_open adds/replaces tabs[path] and sets active; each tab page has its own sceneKey and command list. mol_style/mol_select/mol_focus/ mol_measure fold into the tab argument (or active tab) and bump revision.
  • mol_capture adds a pending entry for the tab argument (or active tab) and bumps revision; the header bridge activates that tab so the capture can be delivered. Read-only tools (mol_info, mol_interface) and invalid selector/format arguments leave state unchanged. A file that fails to read can still create/switch a tab before the Host tool reports the error.
  • tool/result clears a matching pending capture and bumps revision; other results leave state unchanged.
  • Relative paths are resolved against cwd captured when the projection is initialized.
  • The projection is replayable: it stores paths and JSON commands, never bytes.
  • sceneKey changes when the agent opens that tab again. Only that tab reloads the structure (clearing old measurements/selection styles) and resets its applied-command cursor; other tabs are untouched.

The client selects tabs[path] for its own tab with props.useProjection('mol4agent'). It reads the file bytes separately through remote.workspaceFiles.readBytes, then calls @gcszhn/mol4agent-core with { data, format, label }.

Document preview

The client registers one preview implementation:

ctx.documentPreviews.register({
  id: 'mol4agent/molstar',
  extensions: PREVIEW_EXTENSIONS,
  binaryExtensions: ['bcif'],
  priority: 'extension',
  title: () => t('viewer'),
  loading: 'renderer',
  wrap: false,
})
  • priority: 'extension' makes it the default renderer for the claimed suffixes; code/plain text remain selectable via Open with.
  • The body is registered in the sidebar.right.tab.document slot, keyed by mol4agent/molstar.
  • wrap: false means the preview scrolls nothing above the viewer; Mol*'s own UI fills the body.

The body:

  1. parses the session path from the dsh-resource:// address;
  2. maps the suffix to a MolFormat (adapter-only logic);
  3. reads bytes through remote.workspaceFiles.readBytes;
  4. creates/reuses a Mol* viewer and calls load();
  5. follows the projection and applies new commands incrementally;
  6. captures and delivers PNGs when pending contains its call.

The header bridge is registered in conversation.session.header.utilities. It opens a resource when a tab is new or reopened, and activates the target tab when a capture is pending. Tabs that already existed when the session is opened are not auto-opened (the chip reopens the active one).

Screenshot loop

sequenceDiagram
  participant LLM
  participant Tool as mol_capture Host
  participant Hub as CaptureHub
  participant Page as MolBody Browser
  participant Viewer as Molstar

  LLM->>Tool: mol_capture
  Tool->>Hub: wait(session, callId, 20s)
  Page->>Page: projection.pending[callId]
  Page->>Viewer: capture({ width, height, transparent })
  Viewer-->>Page: PNG
  Page->>Tool: /mol4agent_capture callId + image attachment
  Tool->>Hub: deliver(session, callId)
  Hub-->>Tool: image ref
  Tool-->>LLM: image attachment / saved path

CaptureHub keys waiters by sessionId + callId; deliveries that arrive before the tool starts waiting are buffered for 30 s. The internal command is registered with input: { attachments: true } and recordInput: false.

Viewer behavior

  • Official Mol UI*: createPluginUI + DefaultPluginUISpec. The viewer is bundled into client.js; there is no lazy chunk.
  • Layout: chosen from the viewer container's aspect ratio, not the browser window. Tall containers use Mol*'s portrait layout, wide containers use landscape. The official control-panel set (top sequence, left State Tree/Home, right Structure Tools) starts closed (showControls: false); the viewport's sliders button toggles it open. Mol* renders these regions only while showControls is true.
  • Theme: the Mol* skin and canvas background follow DSH's theme/change event.
  • Tab scope: each document tab has its own viewer, cache, and projection scene. mol_open returns the tab page id (absolute path); pass tab to mol_style/mol_select/mol_focus/mol_measure/mol_capture to target that tab independently. Omitting tab uses the last-opened tab. Switching tabs preserves all viewer state; capture activates its target tab.
  • Tab cache: an unmounted preview parks its whole Mol* container in a hidden holder; remounting the same tab reattaches and resizes instead of re-reading the file. The two most recent tabs are kept; plugin unload disposes them.
  • Ligands stay visible: global cartoon uses Mol*'s polymer-and-ligand preset. When replacing a representation, core snapshots old representation refs and removes only those after the new ones exist.

Build

pnpm build
# or: pnpm --filter @gcszhn/mol4agent-core build && pnpm --filter @gcszhn/mol4agent-deepseekharness build

Produces:

  • lib/host.js — Host ESM; @deepseek-ai/* and node:* external.
  • lib/client.js — DSH lazy-CJS browser module, wrapped in window.__ModuleLoader__.load({ id, factory }); includes Mol* and the official UI CSS.

The build writes client/host through temporary files and atomic renames, so a page loading during a rebuild never reads a half-written bundle.

Install

The package is a DSH bundle. From this checkout:

cd /path/to/mol4agent
pnpm build
dsh plugin --profile desktop add link:"$PWD/packages/deepseek-harness"

dsh plugin forwards to pnpm in ~/.dsh/profiles/ . Ensure @gcszhn/mol4agent-deepseekharness is in that profile's dsh.profile.bundles (the DSH Plugin manager does this when installing/enabling a bundle), then restart DSH.

npm form (0.1.0, after publishing):

dsh plugin --profile desktop add @gcszhn/mol4agent-deepseekharness@0.1.0

The current Desktop desktop profile is installed via plugin_manager and enabled as @gcszhn/mol4agent-deepseekharness.

  • Host change: rebuild, then restart DSH (the Host loads lib/host.js at startup).
  • Client change: rebuild, then refresh the page; no restart is needed.
  • The package manifest contributes lib/host.js, lib/client.js, the locale dictionaries, icon, and cordis.patch.yml. The npm files allowlist excludes src/, AGENTS.md, and build scripts; prepack runs the build.

Limitations

  • BCIF can be rendered but mol_info cannot summarize it from raw bytes yet.
  • Gzip variants are decoded by the adapter; compressed or decompressed input over 64 MiB is rejected. The browser needs DecompressionStream for gzip previews.
  • Files are capped at 64 MiB, including a 64 MiB cap on gzip-decompressed output.
  • WebGL 2 is required for the 3D canvas.
  • mol_capture requires the structure preview to be open and times out after 20 s. A timeout produces no command row; a successful delivery leaves one internal mol4agent_capture command row.
  • mol_style without target changes the global representation; with target it adds a selection component. Labels are not exposed as a tool yet.
  • mol_interface currently parses PDB-like ATOM records (pdb/pdbqt/pqr) only; mmCIF/BCIF interface calculation is not implemented.
  • An 8 Å cutoff can produce a large interface (7CZD A/B: 91 residues); lower the cutoff or focus a single range for a cleaner figure.
  • A tab page id is the absolute path. Reopening the same path updates that tab (new sceneKey) rather than creating a second tab with the same DSH resource.
  • The tab cache keeps two viewers; closing a tab does not immediately free its cached viewer (it is evicted by the LRU or plugin unload).
  • The session bridge does not auto-open tabs that already existed when the session was restored; use the header chip.

Files

  • Host: src/host/{index,projection,tools,capture,commands,prompt,paths,interface}.ts
  • Client: src/client/{index,document,bridge}.tsx, src/client/{viewer-cache,locale,core-loader,address}.ts
  • Shared: src/{formats,state,selector}.ts
  • Package: package.json, cordis.patch.yml, locale/{en,zh}.json, icon.svg
  • Details: docs/DETAIL.md, Core API, Architecture

Chinese translation: README_zh.md.