Agent Preset Text Takeover Plugin

Introduction

In DSH, the names and descriptions of Agent presets come from the built-in dictionary or the Host roster. When different text needs to be displayed across languages, different presets, or specific workspaces, the traditional approach is to modify the preset declaration or create multiple presets. This breaks the declaration consistency of presets and makes it difficult to adjust without changing the source code.

This plugin takes over the text of Agent presets at the display layer, applying rules based on language, preset, and runtime conditions, without modifying the preset declaration itself.

What This Is

hluica/dsh-agent-preset-text is a workflow plugin that takes over the names and descriptions of built-in and custom Agent presets at the Harness display layer. It uses a rule engine to match conditions by language, preset, current text, enabled plugins, and workspace path, then appends, replaces, or rewrites text. Disabling the plugin immediately restores the original text.

Core Features

Scope of Interception

The plugin takes over text in the following locations:

  • Settings → Agent Presets: preset card name, description, full hover tooltip text, “View Configuration” dialog title, help button aria text
  • New Task screen preset chip dropdown: the name and description of each item
  • Preset label next to the session title: display name and title tooltip
  • Settings → Plugins → Plugin list: preset switcher and preset group display names

Interception Mechanism

The plugin handles built-in and custom presets separately:

  • Built-in presets: modifies locale dictionary values; rules apply per language; by default only the “description” field is changed, and the name requires explicit selection
  • Custom presets: wraps the roster read path and selects display text based on the current UI language; custom presets have no native multilingual text

Rule Engine

The rule document is document.json, using a versioned JSON structure:

{
  "version": 1,
  "enabled": true,
  "rules": [
    {
      "id": "zh-standard-description",
      "when": {
        "locales": ["zh"],
        "presets": ["standard"],
        "fields": ["description"],
        "text": { "mode": "glob", "pattern": "处理代码、文件和资料*" },
        "plugin": { "id": "dsh-custom-css", "state": "enabled" },
        "workspace": "**/coding-workspace"
      },
      "then": { "op": "append", "text": "\n(本机补充:优先用 bash)" }
    }
  ]
}

when Condition Fields

Field Value Default Meaning
version 1 Required Document version; unknown versions invalidate the entire document
enabled boolean true Global switch; when false, no rules take effect
when.locales string or string[] "*" Language id; "*" means all languages
when.presets string or string[] "*" Preset id (built-in: standard, ptc, minimal, cordis; custom presets use the roster row id)
when.fields name / description / * (array allowed) description Name or description
when.key string — Directly specifies the dictionary key in settings.agentPreset
when.text { mode, pattern, flags? } No restriction Matches against the current working text: exact / glob / regex
when.plugin string or { id, state } No restriction state is enabled (default) / active / absent
when.workspace string (path glob) No restriction Matches the current workspace path

then Operation Fields

Field Value Default Meaning
then.op prepend / append / replace / rewrite Required Prepend / append / replace by match / full rewrite
then.text template string Required Operation text
then.find { mode, pattern, flags? } — Find pattern for replace; when omitted, equivalent to rewrite
then.count all / first all Replacement count for replace

then.text Placeholders

Placeholder Meaning
{preset} Preset id; empty string when the target is not a built-in preset field
{field} name or description
{locale} Language id of the current dictionary entry
{original} Original text captured at installation
{current} Working text before this rule executes
{{ / }} Literal curly braces

Using the Settings Page

In DSH, navigate to Settings → Agent Preset Text (immediately after the official “Agent Presets”).

  1. Status bar displays the interception status, current language, number of active rules, current workspace, plugin list, and external override count:
    - Active: the settings.agentPreset dictionary has been found and is in operation
    - Waiting for Agent Preset plugin: the dictionary has not yet been registered
    - Unavailable: the current DSH locale service does not expose an overridable dictionary object

  2. Language tabs switch the language to view/edit (built-in uses the languages actually present in the dictionary; when the dictionary is unavailable, it falls back to the UI language catalog)

  3. Preset cards display two groups — built-in presets and custom presets. Each row shows “Name” and “Description” with both the original text and the effective text. When they differ, a “Modified” badge is shown. Click “Edit Rules” to open the rule editor for that string

  4. Rule editor — edit the operation, text, find pattern, and conditions. Saving immediately writes back to the Host’s document.json and takes effect without a restart

  5. Full document — directly edit document.json; a saved page will pick up changes within seconds

Rule Document

The rule document is stored in a dedicated file under the DSH data directory (default: ~/.dsh/dsh-agent-preset-text/document.json; or $DSH_HOME/dsh-agent-preset-text/document.json when $DSH_HOME is set). It is the plugin’s own state, not part of cordis.patch.yml, and will not be overwritten by the profile save process.

  • Can be manually edited with any editor at any time; a saved page will pick up changes within seconds
  • The settings page displays the actual storage path; saving is disabled if the initial read fails
  • If the file does not exist, the plugin creates {"version":1,"enabled":true,"rules":[]} on startup; an existing file will never be auto-modified

How It Works

The plugin determines text sources per row in the presetDisplayText() function of DSH 0.2.2:

  • Built-in presets: client locale namespace settings.agentPreset, mapped to eight keys: preset{Standard,Ptc,Minimal,Cordis}{Name,Description}
  • Custom presets: the name / description fields carried by the Host roster row

The plugin overrides the locale dictionary for built-in presets and wraps the roster read path for custom presets. The settings page, dropdown, title label, and plugin list page all go through the same folding function, so this plugin has two interception paths.

Use Cases

  • Displaying different text for different languages under the same preset
  • Adjusting preset descriptions based on workspace path
  • Displaying different text based on the state of enabled plugins
  • Batch-modifying preset descriptions without modifying the preset declaration

Notes

The plugin runs with the current DSH process permissions. Review the source code and license before installation. Rules are applied in document order; a later rule sees the result of the preceding one, and when.text matches against the current working text.

Conclusion

This plugin takes over Agent preset text at the display layer, using a rule engine to apply text based on language, preset, and runtime conditions, without modifying the preset declaration itself. It is suitable for scenarios requiring different text in multilingual environments or under specific conditions.

  • Plugin directory page: https://www.skillhub.cn/plugins/hluica/dsh-agent-preset-text
  • GitHub repository: https://github.com/hluica/dsh-agent-preset-text
羽毛球分组比赛记分
小程序二维码

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

Xiaoye