GCS-ZHN/mol4agent--packages-deepseek-harness ↗★ 2
@gcszhn/mol4agent-deepseekharness
DeepSeek Harness adapter: molecular document preview, agent-driven viewer commands, and PNG capture.
安裝
npx -p @deepseek-ai/dsh dsh plugin --profile web add 'github:GCS-ZHN/mol4agent#03379f204a8484248cdf098843821cba91f590cb&path:packages/deepseek-harness'說明文件
閱讀完整 README ↗@gcszhn/mol4agent-deepseekharness
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,.groopen in Mol*'s official UI instead of plain text. Every claimed suffix also accepts a.gzvariant (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 (bcifhas 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.
| Tool | Parameters | Behavior |
|---|---|---|
mol_info | path | Summarize chains, residues, atoms, ligands. Does not open a viewer or change the scene. |
mol_interface | path, 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_openadds/replacestabs[path]and setsactive; each tab page has its ownsceneKeyand command list.mol_style/mol_select/mol_focus/mol_measurefold into thetabargument (or active tab) and bumprevision.mol_captureadds a pending entry for thetabargument (or active tab) and bumpsrevision; 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/resultclears a matching pending capture and bumpsrevision; other results leave state unchanged.- Relative paths are resolved against
cwdcaptured when the projection is initialized. - The projection is replayable: it stores paths and JSON commands, never bytes.
sceneKeychanges 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.documentslot, keyed bymol4agent/molstar. wrap: falsemeans the preview scrolls nothing above the viewer; Mol*'s own UI fills the body.
The body:
- parses the session path from the
dsh-resource://address; - maps the suffix to a
MolFormat(adapter-only logic); - reads bytes through
remote.workspaceFiles.readBytes; - creates/reuses a Mol* viewer and calls
load(); - follows the projection and applies new commands incrementally;
- captures and delivers PNGs when
pendingcontains 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 intoclient.js; there is no lazy chunk. - Layout: chosen from the viewer container's aspect ratio, not the browser
window. Tall containers use Mol*'s
portraitlayout, wide containers uselandscape. 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 whileshowControlsis true. - Theme: the Mol* skin and canvas background follow DSH's
theme/changeevent. - Tab scope: each document tab has its own viewer, cache, and projection
scene.
mol_openreturns the tab page id (absolute path); passtabtomol_style/mol_select/mol_focus/mol_measure/mol_captureto target that tab independently. Omittingtabuses 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
cartoonuses Mol*'spolymer-and-ligandpreset. 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/*andnode:*external.lib/client.js— DSH lazy-CJS browser module, wrapped inwindow.__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.jsat 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, andcordis.patch.yml. The npmfilesallowlist excludessrc/,AGENTS.md, and build scripts;prepackruns the build.
Limitations
- BCIF can be rendered but
mol_infocannot 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
DecompressionStreamfor 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_capturerequires the structure preview to be open and times out after 20 s. A timeout produces no command row; a successful delivery leaves one internalmol4agent_capturecommand row.mol_stylewithouttargetchanges the global representation; withtargetit adds a selection component. Labels are not exposed as a tool yet.mol_interfacecurrently 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.