dsh-ws-recency 0.22.0 → 0.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +3 -1
  2. package/client.js +100 -35
  3. package/index.js +1 -1
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -133,6 +133,8 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
133
133
 
134
134
  细节想改不用在这里改——新会话的输入框里直接调更顺手。轮询最多 5 分钟自动收起。
135
135
 
136
+ 两处发送都是模拟 Enter:当前会话里先写入、等 250ms 再按回车,并按需再补两次(共 3 次);草稿会话在 14 秒内重试。始终送不出去时文本仍留在输入框,手动回车即可。
137
+
136
138
  ## 设置
137
139
 
138
140
  **设置 → 通用**:
@@ -169,7 +171,7 @@ dsh plugin --profile <profile> add github:chyxhtc/dsh-ws-recency
169
171
  或固定版本的预构建包:
170
172
 
171
173
  ```powershell
172
- dsh plugin --profile <profile> add https://github.com/chyxhtc/dsh-ws-recency/releases/download/v0.22.0/dsh-ws-recency-0.22.0.tgz
174
+ dsh plugin --profile <profile> add https://github.com/chyxhtc/dsh-ws-recency/releases/download/v0.23.1/dsh-ws-recency-0.23.1.tgz
173
175
  ```
174
176
 
175
177
  装完把 `dsh-ws-recency` 加进 `~/.hypers-work/profiles/<profile>/package.json` 的 `dsh.profile.bundles`,重启应用。
package/client.js CHANGED
@@ -1971,59 +1971,123 @@
1971
1971
  });
1972
1972
  }
1973
1973
 
1974
- /** Write text into the composer and send it, if the editor is reachable. */
1975
- function sendToSession(text) {
1976
- if (typeof document === "undefined" || typeof text !== "string" || text === "") return false;
1974
+ /** Enter is the only submit path the composer exposes to a plugin. */
1975
+ function pressEnter(editor) {
1976
+ try {
1977
+ var event = new window.KeyboardEvent("keydown", {
1978
+ key: "Enter",
1979
+ code: "Enter",
1980
+ keyCode: 13,
1981
+ which: 13,
1982
+ bubbles: true,
1983
+ cancelable: true,
1984
+ });
1985
+ editor.dispatchEvent(event);
1986
+ return true;
1987
+ } catch (error) {
1988
+ return false;
1989
+ }
1990
+ }
1991
+
1992
+ /** The composer of the open conversation, if it is on screen. */
1993
+ function composerEditor() {
1994
+ if (typeof document === "undefined") return null;
1977
1995
  var seat = typeof document.querySelector === "function" ? document.querySelector("[data-composer-seat]") : null;
1978
- if (seat === null || seat === undefined) return false;
1996
+ if (seat === null || seat === undefined) return null;
1979
1997
  var editor = null;
1980
1998
  try { editor = seat.querySelector('[contenteditable="true"]'); } catch (error) { editor = null; }
1981
1999
  if (editor === null || editor === undefined) {
1982
2000
  try { editor = seat.querySelector("textarea"); } catch (error) { editor = null; }
1983
2001
  }
1984
- if (editor === null || editor === undefined) return false;
2002
+ return editor === undefined ? null : editor;
2003
+ }
2004
+
2005
+ function editorText(editor) {
2006
+ if (editor === null || editor === undefined) return "";
2007
+ if (editor.tagName === "TEXTAREA" || editor.tagName === "INPUT") return typeof editor.value === "string" ? editor.value : "";
2008
+ return typeof editor.textContent === "string" ? editor.textContent : "";
2009
+ }
2010
+
2011
+ /**
2012
+ * Send the handoff in the Session that was just opened.
2013
+ *
2014
+ * The draft initialises asynchronously: poll until the composer actually holds
2015
+ * the note, press Enter once, then stop. If it never shows up (slow render,
2016
+ * another draft kept) the text simply stays there for a manual Enter.
2017
+ */
2018
+ function autoSendDraft(marker) {
2019
+ if (typeof window === "undefined") return;
2020
+ var tries = 0;
2021
+ function step() {
2022
+ tries += 1;
2023
+ var editor = composerEditor();
2024
+ if (editor !== null) {
2025
+ var text = editorText(editor);
2026
+ if (text.indexOf(marker) !== -1) {
2027
+ try { if (typeof editor.focus === "function") editor.focus(); } catch (error) { /* focus is best effort */ }
2028
+ pressEnter(editor);
2029
+ return;
2030
+ }
2031
+ }
2032
+ if (tries < 40) window.setTimeout(step, 350);
2033
+ }
2034
+ window.setTimeout(step, 400);
2035
+ }
2036
+
2037
+ /** Put text into an editor without losing the framework's own input event. */
2038
+ function writeIntoEditor(editor, text) {
1985
2039
  try {
1986
2040
  if (typeof editor.focus === "function") editor.focus();
1987
2041
  if (editor.tagName === "TEXTAREA" || editor.tagName === "INPUT") {
1988
2042
  editor.value = text;
1989
2043
  editor.dispatchEvent(new window.Event("input", { bubbles: true }));
1990
- } else {
1991
- var selection = typeof window.getSelection === "function" ? window.getSelection() : null;
1992
- if (selection !== null && typeof document.createRange === "function") {
1993
- var range = document.createRange();
1994
- range.selectNodeContents(editor);
1995
- range.collapse(false);
1996
- selection.removeAllRanges();
1997
- selection.addRange(range);
1998
- }
1999
- if (typeof document.execCommand !== "function" || !document.execCommand("insertText", false, text)) {
2000
- editor.textContent = text;
2001
- editor.dispatchEvent(new window.Event("input", { bubbles: true }));
2002
- }
2044
+ return true;
2003
2045
  }
2004
- /* Enter is the only submit path the composer exposes to a plugin. If it
2005
- does not take, the card says so and the user presses it themselves. */
2006
- var sent = false;
2007
- try {
2008
- var event = new window.KeyboardEvent("keydown", {
2009
- key: "Enter",
2010
- code: "Enter",
2011
- keyCode: 13,
2012
- which: 13,
2013
- bubbles: true,
2014
- cancelable: true,
2015
- });
2016
- editor.dispatchEvent(event);
2017
- sent = true;
2018
- } catch (error) {
2019
- sent = false;
2046
+ var selection = typeof window.getSelection === "function" ? window.getSelection() : null;
2047
+ if (selection !== null && typeof document.createRange === "function") {
2048
+ var range = document.createRange();
2049
+ range.selectNodeContents(editor);
2050
+ range.collapse(false);
2051
+ selection.removeAllRanges();
2052
+ selection.addRange(range);
2020
2053
  }
2021
- return sent;
2054
+ if (typeof document.execCommand === "function" && document.execCommand("insertText", false, text)) return true;
2055
+ editor.textContent = text;
2056
+ editor.dispatchEvent(new window.Event("input", { bubbles: true }));
2057
+ return true;
2022
2058
  } catch (error) {
2023
2059
  return false;
2024
2060
  }
2025
2061
  }
2026
2062
 
2063
+ /**
2064
+ * Press Enter until the text actually leaves the composer.
2065
+ *
2066
+ * The editor commits an inserted text and a synthetic Enter in different
2067
+ * frames: pressing Enter in the same tick as the insert is swallowed, which
2068
+ * is why the instruction used to sit in the box until the user pressed it.
2069
+ * Wait a beat, then press again only while the text is still there.
2070
+ */
2071
+ function armEnter(editor, attempt) {
2072
+ if (typeof window === "undefined") return;
2073
+ window.setTimeout(function () {
2074
+ if (composerEditor() !== editor) return;
2075
+ if (editorText(editor).trim() === "") return;
2076
+ pressEnter(editor);
2077
+ if (attempt < 2) armEnter(editor, attempt + 1);
2078
+ }, attempt === 0 ? 250 : 800);
2079
+ }
2080
+
2081
+ /** Write text into the composer and send it, if the editor is reachable. */
2082
+ function sendToSession(text) {
2083
+ if (typeof document === "undefined" || typeof text !== "string" || text === "") return false;
2084
+ var editor = composerEditor();
2085
+ if (editor === null || editor === undefined) return false;
2086
+ if (!writeIntoEditor(editor, text)) return false;
2087
+ armEnter(editor, 0);
2088
+ return true;
2089
+ }
2090
+
2027
2091
  function stopHandoffPolling() {
2028
2092
  if (handoffTimer !== null && typeof window.clearTimeout === "function") window.clearTimeout(handoffTimer);
2029
2093
  handoffTimer = null;
@@ -2109,6 +2173,7 @@
2109
2173
  try {
2110
2174
  service.startSession(workspaceId, { prompt: prompt, whenDraftExists: "replace" });
2111
2175
  resetHandoff();
2176
+ autoSendDraft(t("handoff.preamble").slice(0, 12));
2112
2177
  return;
2113
2178
  } catch (error) {
2114
2179
  /* fall through */
package/index.js CHANGED
@@ -32,7 +32,7 @@ import { dirname, join } from "node:path";
32
32
  export const name = "ws-recency";
33
33
 
34
34
  /** Version marker reported by the health route. */
35
- export const HOST_VERSION = "0.22.0";
35
+ export const HOST_VERSION = "0.23.1";
36
36
 
37
37
  /**
38
38
  * Exact routes the client half calls. Registered on the bare web server, so they
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ws-recency",
3
- "version": "0.22.0",
3
+ "version": "0.23.1",
4
4
  "description": "Sidebar session management for DeepSeek Harness: workspace groups sorted by latest activity, stale history folded, a global pinned section, follow-up marks, session delete into a recoverable trash, archived sessions managed from that same trash panel, per-session token statistics with an argument/result split and an option to count tool arguments as the agent's writing, and moving a session to another workspace.",
5
5
  "license": "MIT",
6
6
  "author": "chyxhtc",