Pular para o conteúdo principal
L

dsh-clear-command

liufeicc/dsh-clear-command

Adds a /clear command that clears one conversation's model-visible context while keeping the session itself.

Instalar

dsh plugin --profile web add github:liufeicc/dsh-clear-command

README

English | 中文

dsh-clear-command

Local DSH bundle: a /clear command that empties one conversation's model context while keeping the session itself.

What it adds

  • One Host row that registers the global command clear, so /clear appears in every composed command surface (Web composer slash menu, CLI) for every session.

Behaviour

  • /clear clears the conversation's model-visible history: the agent no longer sees any earlier message, and its next request starts from the system prompt plus one marker line.
  • The session is untouched: same session id, title, workspace membership, sidebar position, and a complete durable log. This is a clear, not a delete, and not a new session.
  • The clear is one positional surface replacement written into the session log — the mechanism /compact uses — so it survives reloads and replays deterministically.
  • Because the Web transcript is derived from append-origin log events, the earlier messages remain readable on screen and in the log; only what the model sees is emptied.
  • /clear runs on the agent's idle phase (runMaintenance, the same reservation manual compaction uses): while a turn, a queued wake, or another maintenance task owns the agent, the command reports that and changes nothing.
  • The invocation is recorded in the session log as the ordinary command/run / command/done pair, so the result appears as a command row in the transcript.

Notes and limits

  • The leading system/message surface node is preserved, because it is the agent's instructions; everything after it is shadowed.
  • The marker line is English ([Earlier conversation cleared by the user; …]) because it enters the model's context, while the command's own user-facing copy is Simplified Chinese, matching the bundle's shipped UI language.
  • Nothing here touches archived sessions, other sessions, or their files.

Files

  • index.js — the whole plugin: command registration plus the surface replacement.
  • cordis.patch.yml — inserts the single Host row.
  • locale/{en,zh}.json — Plugin Manager display metadata.
  • icon.svg — Plugin Manager artwork.
  • test/clear-contract.mjs — offline contract test. It replays a real session log (zstdcat a ~/.dsh/sessions/**/session.v*.jsonl.zstd) into a detached Session, applies exactly the range and append index.js performs, and prints the resulting surface and derived model messages: node test/clear-contract.mjs <log.jsonl.zstd>.

Development

The profile links this directory (link: in the profile's package.json). Host code is loaded by the Loader, so a change needs the row to be reloaded (profile restart), unlike the client half of dsh-split-workspaces, which dsh-client-hmr reloads on edit.

License

This project is released under the MIT License — see LICENSE for the full text.

Plugins relacionados