dsh-max-compact
Agent 与会话 活跃维护

dsh-max-compact

20genesis14-sys/dsh-max-compact

提供 mc_discover 懒加载工具面,按需暴露工具以压缩模型输入;支持部署级提示层与人格影子,并可用代理预设组合器拼装运行配置,适配 0.2.x。

1
Stars 标星
0
Forks 分支
1
Watchers 关注
0
Open Issues
JavaScript
主要语言
MIT
开源协议
99 KB
仓库大小
1 个月前
最后推送
一键安装扩展 / 插件指令
dsh plugin --profile web add github:20genesis14-sys/dsh-max-compact
git clone https://github.com/20genesis14-sys/dsh-max-compact.git
git clone git@github.com:20genesis14-sys/dsh-max-compact.git
README.md main

dsh-max-compact

Compact model input for DeepSeek Harness (DSH >= 0.2): shrink what the model
sees — tool definitions, prompt sections, preset compositions — without
shrinking what the deployment can do.

Five mechanisms, one plugin — all config-gated (ponytail ships an opt-out
lite default; everything else is inert until configured):

  1. Lazy tool surface. Most tools hide behind mc_discover: the model sees
    a small resident surface (fs + shell + messaging) and activates anything
    else on demand — the dsh-ops discovery pattern, generalized to every
    plugin's tools, not just one catalog.
  2. Editable prompt layer + persona shadow. A trailing system-prompt
    section the deployment owns — inline text, an external prompt.md-style
    file (re-read every step, mtime-cached), or named profiles — plus a
    per-agent deployment:persona-prefix override that shadows whatever the
    preset's persona row declared, without touching the preset.
  3. Preset composer. agentPresets.list() shows the whole roster —
    official, foreign, managed. readDocument + register clone any preset
    under a new id with per-row disabled toggles (the dsh-custom-mode
    capability, but for all presets, since foreign declarations are
    read-only but clonable).
  4. Managed prompt sections. /mc section pins hide/shadow/trim rules to
    named prompt sections, scoped per agent (all | subagents | preset
    ids); the assemble waterfall applies them every step, independent of the
    lazy switch.
  5. Ponytail minimal-code mode. A baseline-frozen maxcompact:ponytail
    section renders per session while /mc pt switches ride as tagged
    <system-reminder> messages — the prompt prefix never re-hashes.
    Vendored review/audit/debt skills ride the host's skills.registerProvider
    seam.

Everything is capability-probed: a missing seam disables the feature with an
honest /mc status line, never a crash.

Install

npm install dsh-max-compact
# or straight from GitHub:
npm install github:20genesis14-sys/dsh-max-compact
# or add the plugin directory to the profile's plugin list

The bundle mounts one global row (id: max-compact) — intentionally not
inside a preset, so every mechanism covers every agent and every preset,
including foreign ones. With the default config only ponytail's lite
baseline is active (everything else is inert); ponytailDefault: off or
/mc pt default off silences it too.

Commands

/mc                                    # status: seams, lazy stats, layer, persona, presets
/mc lazy on|off                        # enable/disable the compact surface
/mc lazy keep|hide|default <tool>      # adjust the resident/lazy policy
/mc lazy release <tool> | reset        # re-mask activated tool(s) on this session
/mc lazy list                          # hidden vs activated for this session
/mc sections                           # last assembled system-prompt sections (chars each)
/mc prompt                             # show the active layer
/mc prompt set <text...>               # inline layer text
/mc prompt file <path|off>             # external prompt file (re-read each step)
/mc prompt clear                       # drop the layer from the prompt
/mc prompt profile save|use|rm|list    # named layer profiles
/mc persona set <text...> | off        # per-agent persona shadow
/mc persona scope all|subagents|<id>   # limit the shadow to delegated/selected agents
/mc prompt scope all|subagents|<id>    # limit the prompt layer the same way
/mc section                            # managed sections list
/mc section diet                       # apply the whole recommended set at once
/mc section hide <name>[,<name>…] [scope]  # drop section(s) (waterfall, scoped)
/mc section set <name> <text...>       # shadow: replace text in agent's own scope
/mc section trim <name> <keep…>        # keep only lines containing a substring
/mc section scope <name> all|subagents|<id>[,<id>…]  # retarget managed rules
/mc section off <name>|all [mode] [scope]  # release rule(s) — original returns
/mc presets                            # roster: foreign + managed, incl. broken
/mc preset show <id>                   # row tree with [disabled]/[group] flags
/mc preset clone <src> <newId> [name]  # clone any preset -> managed
/mc preset toggle <id> <row> [on|off]  # flip a row's disabled flag, re-register
/mc preset rm <id>                     # unmount + forget a managed preset
/mc pt                                 # ponytail status: baseline, effective, seams
/mc pt lite|full|ultra|off             # switch THIS session (reminder, no cache miss)
/mc pt default <mode>                  # persist the baseline for new sessions
/mc pt skills                          # vendored skills served to the model catalog

/mc output also lands on an expanded transcript card plus a floating result
panel (the bundled client/ web half), so it stays visible on a fresh
session's hero screen.

Bundled skills (skills/ dir, vendored MIT from @wenaixi/dsh-ponytail):
ponytail-review (diff review for over-engineering), ponytail-audit
(whole-repo), ponytail-debt (ponytail:-marker ledger). The model calls
the skill tool by name, or you invoke a skill directly.

stop ponytail or normal mode as a whole message also flips the session off.

In-session the model gets mc_discover:

mc_discover({query: "web"})  ->  "Selected web_search, web_fetch. They become
callable on the next model step; nothing was executed."

How it works

Lazy surface (lib/dsh/lazy-tools.js, lib/core/lazy-catalog.js)

  • agent.ctx.tools.register puts mc_discover in the agent's own layer —
    restrictions never cover own-layer registrations, so the activation path
    can never mask itself. Its disposer lives in ownLifts, separate from the
    restrict masks that reconcile lifts on every recompute.
  • agent.ctx.tools.restrict({deny}) masks the lazy set per agent. Reconcile
    follows the official-tool-hiding discipline: a public-surface snapshot
    diff guards against publication feedback loops, all masks lift before
    recompute, a failed plan hides nothing, and deny narrows on scope-local
    or unknown names (restrict throws naming the offender — that tool is
    honestly reported as unmaskable rather than silently kept).
  • Activations queue into pending and commit at the next step boundary
    (agent/pre-step, session/event step/end as fallback) — republishing
    mid-step would invalidate the in-flight request's tool list. Activated
    tools stay visible for the agent's lifetime (/mc lazy release <tool> or
    reset re-masks them).
  • A global ctx.tools.guard(exec => …) keyed on exec.agent denies
    hidden-tool executions even from conversation history; activation lifts
    the denial automatically.
  • Keep beats hide, hide beats default-lazy; run_code + own tools are
    never hidden (reserved transport + own-layer registrations throw in
    restrict).
  • While lazy is on, a maxcompact:lazy-hint section (order 10501) tells the
    model how many tools are hidden and to call mc_discover; it renders
    empty — drops out — once nothing is masked.

Section hygiene (lib/dsh/lazy-prompt.js)

One global system-prompt/assemble listener (context.scope = the
assembling agent) drops sections that document currently-masked tools —
tools:workflow and friends stop burning tokens while their tool is lazy.
The waterfall cannot rewrite a complete section (the host restores it);
that limit is documented, not worked around. /mc sections inspects the
last assembly.

Managed sections (lib/core/managed-sections.js, lib/dsh/section-shadow.js)

Three modes pinned per named section, independent of the lazy switch:

  • hide — the waterfall drops the section for matching agents. The only
    mode that works on agent-scoped contributions (shadows would collide in
    the same layer).
  • shadow — same-name section registered in the agent's own scope
    replaces the original (deeper layer wins by name, the host's own persona
    mechanism). Order self-heals: the waterfall records the original's
    position and the shadow re-registers there once seen.
  • trim — lines containing a keep-substring survive; the only mode safe
    for dynamic sections (tier-routing shows live tier labels — a static
    shadow would freeze stale values, so set refuses the NO_SHADOW list).

Scopes follow matchesScope: all (default) | subagents | preset ids.
Agents without session.meta (older hosts) match only all. Multiple
rules may target the same name — hide wins over shadow for a matching
agent, so "shadow for all + hide for subagents" compresses parents and
drops the section for children. A trim whose patterns match nothing
leaves the original text — a mistyped rule must degrade to "unchanged",
never to "silently deleted". Rules persist in the settings document and
lift instantly on /mc section off.

Prompt layer (lib/core/prompt-layer.js, lib/dsh/files.js)

Section maxcompact:layer (order 10500, after deployment:persona-prefix
and suffix) resolves each assembly: file > active profile > inline. Files
are re-read every step through an mtime/size cache — external edits land on
the next model call with no reload.

Persona shadow (lib/dsh/persona.js)

deployment:persona-prefix (order 0) registered in the agent's own
scope shadows the preset's persona row — same-name sections shadow across
layers (duplicate names only collide within one layer). Off by default;
/mc persona set/off refreshes every live agent.

Ponytail minimal-code mode (lib/core/ponytail.js, lib/dsh/ponytail.js)

One global maxcompact:ponytail section (order 50) renders ONLY the baseline
locked at agent/created — mid-session /mc pt switches never re-hash the
prompt prefix. Mode changes travel as one tagged <system-reminder> user
message appended on the agent/pre-step waterfall (a retry replaces it by
tag). stop ponytail / normal mode as a whole message flips the session
off. Default resolution: PONYTAIL_DEFAULT_MODE env → ponytailDefault
field → lite. The vendored skills/ catalog registers through
skills.registerProvider; maxcompact:ponytail is denylisted from managed
sections (NO_MANAGE).

Preset composer (lib/core/presets.js, lib/dsh/preset-registry.js)

  • agentPresets.list() — every declared preset incl. broken diagnostics.
  • readDocument(id) — the full composition YAML, parsed with a !!js →
    {__jsExpr} schema so host-evaluated predicates survive cloning verbatim.
  • Clone registers under a new id (foreign declarations are never
    touched); group/isolate structure is preserved so service rows keep
    their realms; relative ./x.mjs specifiers become absolute file:// URLs.
  • Toggle = disabled: true on the row + dispose/re-register (duplicate ids
    throw — disposal first). New sessions pick up the new revision; running
    sessions keep their retained generation.
    That's the platform's
    revision-retention design, not a limitation of this plugin.
  • Managed specs persist through the volatile managedPresets field and the
    settings document (ns max-compact) — clones survive restarts.

Config

All fields are volatile (WebUI-editable, persisted via the settings
document):

Field Default Meaning
lazyEnabled false Master switch for the compact surface
lazyKeep [] Extra tool names to keep resident
lazyHide [] Tool names forced lazy (beats keep)
lazyHideSections [] Section names filtered from assemblies while lazy is on
customPrompt '' Inline layer text
customPromptFile '' External prompt file path
promptProfiles {} {name: text} named layers
activePromptProfile '' Selected profile
customPersona '' Persona shadow text
layerPresets [] Layer scope: [] all, [':subagent'] delegates only, preset ids
personaPresets [] Persona scope, same vocabulary
managedSections [] [{name, mode, text?, keep?, scope?}] hide/shadow/trim rules; several rules may target one name under different scopes (hide wins over shadow)
managedPresets [] Cloned preset specs
ponytailDefault unset Ponytail baseline for new sessions — PONYTAIL_DEFAULT_MODE env wins; falls back to lite

Honest limitations

  • Preview APIs. agentPresets, tools.restrict/guard,
    system-prompt/assemble are preview surfaces — all probed; missing seams
    degrade features, never crash.
  • Global rows can still add tools. Profile-global plugins mount on top
    of any preset — no preset or mask fences their own-layer additions, so
    /mc lazy list reports what the host actually shows, not an ideal count.
  • Foreign presets are read-only. readDocument is "for viewing only" —
    clone under a new id to customize; the original is never edited in place.
  • complete sections can't be rewritten by the assemble waterfall —
    including a complete persona. The persona shadow uses a named prefix
    section instead, which layering does shadow.
  • Shadows freeze static text. Sections resolving live state per step
    (tier-routing's tier labels) belong to trim, not set — the
    NO_SHADOW denylist enforces it. Agent-scoped contributions (registered
    per-agent by the host, e.g. context:file-reference) collide with a
    shadow in the same layer — use hide for those.
  • Revision retention. Preset toggles affect new sessions; running
    sessions keep the generation they mounted.

Development

npm test           # 88 tests — pure core + mocked-ctx smoke
npm run check      # node --check every lib file
npm run pack:check # npm pack --dry-run

lib/core/ is pure logic (no DSH imports, no I/O); lib/dsh/ is the only
place that knows DSH exists; lib/index.js wires the two. Per-agent state
lives in WeakMaps keyed on agent objects — never session-id strings.