CodeBridge: Orchestration Tools Using JavaScript/TypeScript in DSH Standard Mode

Preface

DSH defaults to the “tool calling” step: the model retrieves the parameters for one tool at a time, returns the result to the dialogue, and then decides on the next step. Single-step read/write is fine, but tasks like “circular pagination processing”, “filter a batch of results first then aggregate”, or “conditional branching chained with multiple calls” will cause the number of round trips to expand rapidly, and intermediate results need to be repeatedly fed into the context.

CodeBridge addresses this issue by adding a code execution entry point to the standard mode, allowing the model to write JavaScript/TypeScript in a single call. It chains multiple tools and controls flow via tools.*, then returns the required results to the model. The original native tools can still be called directly, and they coexist.

Below is an introduction to this plugin. CodeBridge is maintained by MUKAPP, the repository is MUKAPP/dsh-codebridge, and it belongs to the workflow plugin category. The current version is 0.1.1, compatible with DSH 0.2.2-rc.1 and Node.js >=24.9.0, with the MIT license.

What it can do

The capabilities listed in the official README are categorized by usage:

  • In-session state: By default, variables, functions, imports, and intermediate results are retained within the same session. Subsequent calls can directly reuse them without wrapping them in a function.
  • Chain tools with code: Supports conditional judgment, loops, result filtering, and aggregation to reduce model round trips.
  • Query structure before calling: Search for currently visible tools by name or description, then retrieve parameters and return schema as needed; it can also be used for read-only environment diagnostics.
  • Optional restart recovery: When enabled, it automatically saves supported top-level JSON data variables. After a restart, variables are restored by their original names without re-running historical code.
  • Large output recovery: After successfully saving the full text, the display is shortened, the valid JSON is preserved, and a location to retrieve it is provided.
  • Inherit current permissions: Every sub-call goes through the DSH tool pipeline, retaining visibility checks, approvals, cancellations, and call logs.
  • Coexist with PTC Plus: Uses a dedicated official Node runtime codebridge-runtime with namespace isolation from the public runtime.

It is worth noting that the README explicitly states that the tool schema for standard mode is still retained, and CodeBridge does not promise a fixed token saving ratio.

Installation and Activation

Enter the GitHub address in DSH’s “Plugins → Add Plugin”:

https://github.com/MUKAPP/dsh-codebridge.git

The installation process will compile the plugin from source; the repository’s prepare and prepack scripts compile the Host and Web clients. If the manager prompts that the build script is pending approval, check the repository’s build scripts first before deciding whether to allow. After installation, enable or restart DSH as prompted by the manager; refreshing the browser page will not reload the Host plugin.

The command line method can install it to a specific profile. Below is an example using web:

dsh plugin --profile web add https://github.com/MUKAPP/dsh-codebridge.git

Note that installation affects all sessions using that profile. The plugin currently only declares support for DSH 0.2.2-rc.1; other versions require adaptation first, and compatibility cannot be achieved by ignoring version checks.

When upgrading, the entire dsh-codebridge bundle needs to be reloaded to update the tools and dedicated runtime to persistent mode. When uninstalling, close or remove the entire bundle and wait for session resource release.

Two Tools

The plugin provides two tools:

Tool Parameters Purpose
codebridge_exec code, description, optional timeoutMs, maxInlineBytes Execute code and return logs and results
codebridge_tools names or query, optional detail, offset, limit, diagnostics Search summary, query full structure, or read-only diagnostics

code is the TypeScript REPL source code, supporting top-level await and the last expression. The tool name and return structure are based on the current session’s query result; what is obtained in the code is the tool’s canonical JSON, which may differ from the text displayed by native tools. If a sub-tool fails, it will throw a catchable ToolCallError, containing name, toolName, and message.

Typical Usage: Query, Then Call, Then Orchestrate

When the tool name is unknown, let the model first call codebridge_tools to search by description:

{ "query": "文件", "limit": 20 }

The search is case-insensitive and matches substrings after stripping leading and trailing whitespace. query: "" can browse all visible tools. By default, only the name and description are returned, without attaching parameters and return structures. Results are sorted by name, total is the total match count, and nextOffset is returned if there are subsequent pages. limit defaults to 20, ranging from 1–100, and offset defaults to 0.

After finding the target, use the exact name to query the full structure:

{ "names": ["working_directory"] }

A names query returns the name, description, full parameters, and output by default; unavailable names appear in unavailable. After confirming the parameters, you can call codebridge_exec:

{
  "description": "读取当前工作目录",
  "code": "const directory = await tools.working_directory({}); directory",
  "timeoutMs": 10000
}

Within the same session, bindings can be reused across calls. The first call prepares data and functions:

const values = [12, 8, 5]
function total() { return values.reduce((sum, value) => sum + value, 0) }
total()

The next call can directly continue using them:

values.filter(value => value >= 8).map(value => value * 2)

By default, session state is only retained within the current process. When “Restore on Restart” is enabled, the plugin additionally saves supported top-level JSON data variables; after a process restart, it restores from the most recent snapshot; functions, modules, and handles are not restored. File writes, network requests, and other external side effects will not be rolled back due to code failure.

Settings

Adjust two switches in “Settings → Plugins → CodeBridge”; the settings take effect immediately upon saving; the configuration belongs to the current profile, and sessions using that profile share the settings.

Setting Config Key Default Behavior
Retain Session State retainSessionState Enabled Reuse Node REPL in the same session; when disabled, the next call releases the old environment and executes in a new environment
Restore on Restart restoreOnRestart Disabled Must be enabled together with session retention; saves and restores supported top-level JSON data variables

The restore function only tracks top-level const, let, var declarations (including destructuring) and supports limited numbers, strings, booleans, null, and plain JSON arrays/data objects. Functions, class instances, Promises, handles, getters, Proxies, circular references, nested scope properties, and new properties on globalThis are not in the scope of recovery. The maximum limit for a full record of each snapshot is 1 MiB. Recovery only injects data; it does not re-run the original code.

Runtime limits are adjusted in codebridge-runtime:

Config Default Meaning
executionMode persistent-in-memory Keeps a Node REPL per session; optional JSON data snapshot recovery
timeoutMs 120000 Default execution timeout in milliseconds
maxTimeoutMs 600000 Upper limit of the single timeout parameter in milliseconds
maxOutputBytes 67108864 Combined output limit for logs and results, 64 MiB

CodeBridge requires the runtime to remain persistent-in-memory and programFormat: "repl". If manually changed back to per-call, codebridge_tools({ diagnostics: true }) will report that the configuration is not ready, and code execution will also explicitly be rejected to avoid mistakenly handing the REPL trailing expression to the function body runtime.

Execution Rules and Notes

Be aware of several hard constraints when reading and using:

  • Serial Sub-calls: Submitting multiple Promises does not imply parallelism. All asynchronous tool calls must be awaited; unfinished calls at the end of the program will be cancelled and waited for cleanup. timeoutMs does not include cleanup work.
  • Adhere to Scope: You can only call tools visible to the current proxy. There is no entry point for recursive calls to CodeBridge or run_code, and the code tool itself has no privilege elevation parameters.
  • Sandbox Inherits Host: Node file, network, and subprocess operations are constrained by the actual host policy. The Windows backend may report partial and cannot be treated as complete isolation.
  • Large Output: maxInlineBytes defaults to 32768 (32 KiB), ranging from 1024–262144. When over budget, the plugin uses the host’s mounted spillStore to save the full JSON and displays a preview of the beginning and end; the preview text may omit parts in the middle of the JSON and cannot be parsed as complete JSON.
  • Diagnostics are not security proofs: diagnostics returns statuses like stateRetention, stateRecovery, configurationReady, but configurationReady only indicates that no issues were found during configuration checks and does not prove complete sandbox isolation. If the runtime is missing, the entire bundle should be restored, and simply enabling the public Node runtime separately may be ineffective.

It is recommended to read the repository source code and build scripts before installation to ensure the license and permissions comply with the constraints of your environment. The plugin runs with the current DSH process permissions and has no independent privilege escalation channel.

Directory and Source Code

  • Community Plugin Directory: https://www.skillhub.cn/plugins/MUKAPP/dsh-codebridge
  • GitHub: https://github.com/MUKAPP/dsh-codebridge

It should be noted that the community directory is an independent site with no official affiliation to DeepSeek/Huansuan, nor does it equate to the official app store.

CodeBridge converges “multi-step tool orchestration” into a single code call, maintains state within the same session, and retains the host’s native pipeline for permissions. It is suitable for scenarios where pagination, filtering, and aggregation are needed within standard mode; if it is just single-step read/write, calling native tools directly is more convenient.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye