dsh-kubejs: Customize Installed DSH Plugins with a Script Package

In the DeepSeek Harness (DSH) plugin ecosystem, modifying existing plugins typically means directly editing their source code, which introduces risks such as modifications being lost after version updates or broken changes crashing startup. dsh-kubejs introduces KubeJS’s core paradigm: decoupling modification logic into standalone script packages, applying scripts to installed plugins through declarative configuration without touching plugin source code.

Core Features

dsh-kubejs itself is an ordinary DSH plugin responsible for loading scripts; scripts reside in a separate directory, fully isolated from plugin code.

Separation of Modifier and Modification

Scripts are centralized in an independent directory, completely isolated from plugin code. Plugin updates or reinstallation will not lose modifications. Modification logic is exported via activate(api) and acts on existing entities.

Target Plugin Dependency Management

Scripts are packaged per target plugin, with dependencies declared in manifest.json. If the target plugin is not installed or the version mismatches, the entire package is disabled with an alarm—never failing silently.

Configuration Override Ledger

Configuration is written via api.config.override, with all changes recorded in the managed block of cordis.patch.yml, supporting precise removal. Writing to different paths on the same plugin instance across multiple calls is additive rather than overwriting.

Five API Primitives

Scripts obtain five primitives through activate(api):

  • api.on(event, handler): Event hooks (actually attached to the host cordis events).
  • api.slot(id, props, Component): Register UI components to client slots.
  • api.config.override(path, value): Configuration override.
  • api.service.wrap(name, wrapper): Service wrapping (onion model).
  • api.fetch.wrap(matcher, handler): Global fetch interception (onion model).

Management Panel and Toolset

Provides a management panel to browse script package status, mismatch red flags, execution status, and the configuration ledger. Also provides four dedicated tools: kubejs_inspect, kubejs_write_script, kubejs_reload, kubejs_check.

Installation

In the DSH Desktop “Plugins” panel, enter either of the following addresses to install:

github:YuMo-233/dsh-kubejs

Or fill in the repository address directly: https://github.com/YuMo-233/dsh-kubejs. The official installer will automatically complete package fetching, bundles registration, and cordis.patch.yml registration. Restart after installation.

Typical Usage

Event Hooks

export function activate(api) {
    // Observe only: returning undefined means full pass-through, never interfering with DSH
    api.on('agent/pre-step', (payload) => {
        api.log.debug('Current step:', payload.step);
    });

    // Modify decisions: always await next() first to get the host's built-in decision, then spread it
    api.on('agent/pre-step', async (payload, next) => {
        const decision = await next();          // { kind: 'enter', messages: [...] }
        return { ...decision, delayHint: 800 };
    });
}

fetch Interception

export function activate(api) {
    api.fetch.wrap({ urlIncludes: '/v1/chat/completions' }, async (request, next, helpers) => {
        // Replace "whole-request timeout" with an idle watchdog that times out only when no bytes flow
        const idle = helpers.createIdleSignal({ firstByteMs: 60_000, idleMs: 300_000, upstream: request.signal });
        request.init.signal = idle.signal;

        const res = await next();                          // Returning undefined means the framework sends it
        return helpers.wrapResponseBody(res, idle.pulse, idle.dispose);
    });
}

Hot Reload

kubejs_reload takes effect immediately (no restart needed), used for modifying event hooks, configuration overrides, or fetch interception rules.

Usage Notes

Hooks and Decisions

  • If you don’t own the decision, return undefined (pass-through); don’t fabricate objects—fabricating will override the host’s built-in decision fields.
  • If you want to modify, await next() first, then spread its return value.
  • Hooks are async; handlers can be async; slow handlers will delay events.
  • api.ctx provides full pass-through (for reading or modifying scenarios), but to create new things, write a standalone plugin.

Script Constraints

  • Scripts cannot create new access points (provide new services/register new tools/new routes).
  • Client scripts cannot use import/export (only require() allowed).
  • manifest.json cannot have a BOM (will cause parsing failure).
  • Scripts must use ESM to export activate (writing as CJS will fail silently).
  • Marker lines must be comments starting with # (written in cordis.patch.yml).

Value Summary

dsh-kubejs allows developers to customize installed plugins through standalone script packages without modifying plugin source code. This paradigm solves problems caused by directly editing plugins: modifications lost during version updates, broken changes crashing startup, and scattered modifications that are difficult to audit. Scripts are packaged per target plugin, combined with a configuration override ledger and hot reload mechanism, providing safe, rollback-capable modification capabilities.

For more information or to obtain the source code, visit the GitHub repository.

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

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

Xiaoye