Skip to main content
1

dsh-prompt-history-lite

16bh/dsh-prompt-history-lite

Composer helpers for DeepSeek Harness: Up on an empty input recalls the last message you sent, the sparkle button rewrites the draft into a structured prompt with the session model, and a template panel inserts reusable prompts at the caret without sending.

Install

dsh plugin --profile web add github:16bh/dsh-prompt-history-lite

README

dsh-prompt-history-lite

A deliberately small prompt helper for the DeepSeek Harness composer: recall your last message, rewrite a draft into a structured prompt, drop in a reusable template — three everyday things and nothing else.

The three actions in the composer action row

The community plugin dsh-prompt-history does much more than this, and it keeps a lot of machinery resident in the composer, which shows up as typing lag. This plugin re-implements the three parts that get used every day and drops the rest: no clipboard history, no inline autocomplete, no ghost text, no feedback panel.

What it does

1. ↑ on an empty composer recalls your last message

Typing nothing, press ↑ and the most recent message you sent in this session appears in the composer. Press ↑ again to walk back through older messages, ↓ to walk forward, and ↓ past the newest one restores the draft you started with. Esc leaves browsing at any time. Nothing is ever sent automatically.

The history is read from the session on the host the first time you press ↑, then kept for that browsing pass only — it is dropped as soon as you edit the draft or send.

2. ✨ rewrites the draft into a structured prompt

The ✨ button in the composer action row sends the current draft to the session's own model and shows the result next to the original:

Original and rewritten draft side by side

  • The rewrite targets role and goal, context and constraints, executable steps, output format, acceptance criteria, and edge cases — and only the sections the draft actually needs, aiming for roughly 1–3× the original length instead of padding every heading.
  • You get apply, copy, retry and close. Applying replaces the draft and offers one undo; nothing is written into the composer until you say so, and a result that arrives after you have kept typing is discarded rather than overwriting your text.
  • The call is streamed, so text appears as it is generated, and it is cancelled when you close the panel.
  • The draft is sent inside <draft>…</draft> and treated as data, not as instructions.

3. 📋 reusable prompt templates

The 📋 button opens a panel of templates. Clicking a row inserts its body at the caret, without sending and without replacing what you have already written.

Template panel

Five starting templates ship built in — code review, explain code, write tests, find edge cases, refactor suggestions — and you can add, edit and delete your own. Deleting offers an undo. Drag a row by the grip on its left to reorder the list; the order is saved to the file.

The templates live in ~/.dsh/prompt-history-lite/templates.json, a plain JSON array on the host, and that file is the only source of truth. The prompt_templates agent tool reads and writes the same file, so you can also ask the model to add, rewrite or prune templates for you, and the panel shows the change the next time you open it. The five starting templates are served only while the file does not exist; once anything has been saved — including an empty list — the file wins and deleted templates stay deleted. Templates from the old localStorage store are migrated into the file the first time the panel opens, and the old key is removed once the write succeeds.

The panel follows the host theme, light or dark:

Template panel in dark mode

4. select text in the conversation, insert it without copying

Select any settled message text in the conversation and the host's selection surface appears above the composer with two buttons:

  • Insert writes the selection into the composer at the caret as plain, editable text — no clipboard involved, one undo step.
  • Quote inserts it as a quote chip that becomes a Markdown blockquote when sent.

The host owns the selection rules, placement, and dismissal (outside click, Escape, new selection); the plugin only decides to show the surface and what the buttons do. Only text that the host already treats as selectable participates — displayed user messages and settled assistant text; tool output, streamed text and injected context do not.

Settings

Settings → Prompt history lite has two switches, both on by default: prompt enhancement and prompt templates. ↑ recall has no switch; it is the reason the plugin exists.

Install

dsh plugin --profile <your profile> add github:16bh/dsh-prompt-history-lite

From a local checkout, point the profile at the directory with link::

git clone https://github.com/16bh/dsh-prompt-history-lite.git
dsh plugin --profile <your profile> add link:$PWD/dsh-prompt-history-lite

The browser half is picked up on page reload; the host half registers its four routes at startup, so restart DSH once after installing.

Implementation notes

  • No build step. Plain ESM, no bundler, no dependencies. index.js is the host half, client.js the browser half, loaded through the host's module loader.
  • Four routes, all under /api/prompt-history-lite/: history (the session's sent messages), enhance (one-shot), enhance/stream (NDJSON, one frame per line) and templates (GET/PUT the template store as a whole). Requests are admitted through the host connection service, the same check the host applies to its own API.
  • History is computed on demand. The host folds the session's events into a list of sent message bodies when asked, instead of watching the DOM or subscribing to every event on the client.
  • One resident listener. A single captured keydown on document, removed on unmount, handles ↑/↓/Esc and only while the composer is empty. No MutationObserver, no timers, no polling, no selectionchange/scroll/resize handlers.
  • The model route follows the session. The enhancement runs on whatever provider, model and reasoning effort the current session resolved to, at the lowest reasoning effort the model offers — rewriting is generation, not deliberation.
  • Panels are plain DOM. The client loader hands the plugin React, and React owns the two buttons in the action row; the panels and the toast are built with document.createElement and mounted next to document.body, which keeps them out of the composer's re-render path.
  • Colours come from host theme tokens (--dsw-alias-*), so light and dark mode both follow the host without a hard-coded palette.
  • Templates have a single source of truth: ~/.dsh/prompt-history-lite/templates.json, at most 200 entries, 8000 characters per body. Writes go to a temp file and are renamed into place; the panel and the prompt_templates tool share one serialized read-modify-write chain, so they cannot overwrite each other. localStorage is only a fallback for hosts without the route, and the place the old templates are migrated from.

Development

node --check index.js
node --check client.js
node --test test/host.test.mjs

The tests cover the host-side helpers: event folding, history extraction, request admission, length limits and the NDJSON framing.

License

MIT. The idea for the plugin comes from dsh-prompt-history; no code is copied from it — this is a smaller implementation written from scratch.


中文说明

给 DeepSeek Harness 输入框用的轻量提示词工具,只保留三件每天都会用的事:召回上一条消息、把草稿改写成结构化提示词、插入常用模板。

输入框动作行的三个入口

社区插件 dsh-prompt-history 功能更全,但它在输入框旁边常驻了不少东西(全局事件、观察器、定时器),表现出来就是打字卡顿。这个插件只重写了最常用的三块,其余一概不做:没有剪贴板历史、没有行内补全、没有 ghost 文字、没有反馈面板。

功能

一、空输入时按 ↑ 召回上一条消息

输入框为空时按 ↑,本会话最近一条发过的消息出现在草稿里;继续 ↑ 往前翻,↓ 往回退,退过最新一条之后恢复你原本的草稿;Esc 随时退出浏览。整个过程不会发送任何东西。

历史是第一次按 ↑ 时从宿主侧现算一次,只在这一次浏览里复用;一旦你改动草稿或发送,缓存即失效。

二、✨ 把草稿改写成结构化提示词

点输入框动作行的 ✨,当前草稿会交给当前会话使用的模型改写,结果和原文并排显示:

原文与改写对照

  • 改写覆盖角色与目标、上下文与约束、可执行步骤、输出格式、验收标准、边界情况,并且只写草稿真正需要的小节,目标长度约为原文 1–3 倍,不硬凑标题。
  • 面板提供应用 / 复制 / 重试 / 关闭。应用会写入草稿并给一次撤销;在你点应用之前不会动草稿,改写结果回来时如果你已经继续打字,它会丢弃结果而不是覆盖你新写的内容。
  • 调用是流式的,字出着就显示;关掉面板会中断在途请求。
  • 草稿包在 <draft>…</draft> 里发送,按数据处理,不按指令处理。

三、📋 常用提示词模板

点 📋 打开模板面板,点一行就把正文按光标位置插进草稿——不发送,也不覆盖你已经写的内容。

模板面板

装好就有 5 条起步模板(代码审查 / 解释代码 / 写测试 / 找边界情况 / 重构建议),可以自己新增、编辑、删除,删除有撤销。鼠标移到行上,左边会出现拖动把手,按住拖动即可调整顺序,顺序会写进文件。

模板存在宿主上的 ~/.dsh/prompt-history-lite/templates.json(一个纯 JSON 数组),这份文件是唯一数据源。agent 工具 prompt_templates 读写的是同一个文件,所以也可以直接让模型帮你加、改、删模板,下次打开面板就能看到。只有文件还不存在时才给 5 条起步模板;一旦保存过(哪怕保存的是空列表)就以文件为准,删掉的模板不会自己长回来。老版本存在 localStorage 里的模板会在第一次打开面板时自动迁移到文件里,写成功后再删掉旧 key。

面板跟随宿主深浅色主题:

深色主题下的模板面板

四、选中会话里的文字,不用复制直接进输入框

在会话里选中一段已经落定的文字,输入框上方的选区浮层会出现两个按钮:

  • 插入:把选中的文字按光标位置写进输入框,是可编辑的纯文本、可撤销,不经过系统剪贴板。
  • 引用:以引用块的形式放进输入框,发送时是 Markdown 引用。

选区判定、浮层定位和关闭(外部点击、Escape、重新选择)都由宿主负责,插件只决定显不显示浮层、按钮做什么。只有宿主本来就认定为可选的文字参与:已展示的用户消息、已完成的 assistant 文本;工具输出、流式文本和注入上下文不参与。

设置

设置页「提示词历史 Lite」有两个开关,默认都开:提示词增强、提示词模板。↑ 召回没有开关,它就是本插件存在的理由。

安装

dsh plugin --profile <你的 profile> add github:16bh/dsh-prompt-history-lite

本地目录用 link::

git clone https://github.com/16bh/dsh-prompt-history-lite.git
dsh plugin --profile <你的 profile> add link:$PWD/dsh-prompt-history-lite

前端半区刷新页面即生效;宿主半区在启动时注册四条路由,装完重启一次 DSH。

实现要点

  • 无构建:纯 ESM,无打包器、无依赖。index.js 是宿主半区,client.js 是浏览器半区,走宿主的模块加载器。
  • 四条路由,都在 /api/prompt-history-lite/ 下:history(本会话发过的消息)、enhance(一次性)、enhance/stream(NDJSON,一行一帧)、templates(GET/PUT 整表读写模板库)。请求走宿主连接服务的准入校验。
  • 历史按需计算:宿主在你按 ↑ 时才折叠会话事件,客户端不监听 DOM、不订阅事件流。
  • 只有一个常驻监听:document 捕获阶段的一个 keydown,卸载时移除,只在草稿为空时接管 ↑/↓/Esc。没有 MutationObserver、没有定时器、没有轮询、没有 selectionchange/scroll/resize。
  • 模型跟随会话:用当前会话解析到的 provider / model,并把推理强度降到该模型最省的一档——改写是生成,不是思考。
  • 面板用原生 DOM:动作行的两个按钮是 React 组件,面板和 toast 用 document.createElement 挂到 document.body 旁边,不进入输入框的重渲染链路。
  • 配色全走宿主主题令牌(--dsw-alias-*),深浅色都不写死颜色。
  • 模板只有一个数据源:~/.dsh/prompt-history-lite/templates.json,最多 200 条,单条正文上限 8000 字。写入先落临时文件再 rename;面板和 prompt_templates 工具共用同一条串行读改写链,不会互相覆盖。localStorage 只作为没有该路由的老宿主的兜底,以及老数据的迁移来源。

开发

node --check index.js
node --check client.js
node --test test/host.test.mjs

测试覆盖宿主侧的纯函数:事件折叠、历史提取、请求准入、长度上限、NDJSON 分帧。

许可

MIT。插件思路来自 dsh-prompt-history,未复制其代码,本实现是重写的更小版本。

Related plugins