dsh-ws-recency 0.30.1 → 0.30.2
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.
- package/client.js +944 -51
- package/index.js +133 -10
- package/package.json +1 -1
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.30.
|
|
35
|
+
export const HOST_VERSION = "0.30.2";
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Exact routes the client half calls. Registered on the bare web server, so they
|
|
@@ -663,7 +663,7 @@ async function readSessionEvents(ctx, sessionId) {
|
|
|
663
663
|
* pending, which is what the panel shows as "still indexing".
|
|
664
664
|
* ------------------------------------------------------------------------- */
|
|
665
665
|
|
|
666
|
-
const SEARCH_INDEX_VERSION =
|
|
666
|
+
const SEARCH_INDEX_VERSION = 4;
|
|
667
667
|
/** Longer messages are cut for the cache: snippets never need the tail. */
|
|
668
668
|
const SEARCH_MESSAGE_CAP = 200000;
|
|
669
669
|
const SEARCH_PER_SESSION = 3;
|
|
@@ -752,8 +752,12 @@ function extractSearchMessages(events) {
|
|
|
752
752
|
if (text === "") continue;
|
|
753
753
|
if (text.length > SEARCH_MESSAGE_CAP) text = text.slice(0, SEARCH_MESSAGE_CAP);
|
|
754
754
|
const declared = Number(data.turn);
|
|
755
|
+
const declaredStep = Number(data.step);
|
|
755
756
|
messages.push({
|
|
756
757
|
turn: Number.isSafeInteger(declared) ? declared : turn,
|
|
758
|
+
/* Assistant messages carry their step inside the turn; user messages do not
|
|
759
|
+
(they arrive before the turn's steps), so the step stays null there. */
|
|
760
|
+
step: Number.isSafeInteger(declaredStep) ? declaredStep : null,
|
|
757
761
|
seq: Number.isSafeInteger(Number(event.seq)) ? Number(event.seq) : 0,
|
|
758
762
|
at: Number.isFinite(Number(event.time)) ? Number(event.time) : 0,
|
|
759
763
|
role: event.type === "user/message" ? "user" : "assistant",
|
|
@@ -763,6 +767,93 @@ function extractSearchMessages(events) {
|
|
|
763
767
|
return messages;
|
|
764
768
|
}
|
|
765
769
|
|
|
770
|
+
/**
|
|
771
|
+
* The session's own title, read from the events already in hand.
|
|
772
|
+
*
|
|
773
|
+
* A session writes the title twice: a fallback that is just the first prompt's
|
|
774
|
+
* prefix, then the real one from the title provider. The first one is not the
|
|
775
|
+
* name shown in the sidebar, so the provider title wins and the fallback is only
|
|
776
|
+
* used when the provider never answered.
|
|
777
|
+
*/
|
|
778
|
+
function titleFromEvents(events) {
|
|
779
|
+
let provider = "";
|
|
780
|
+
let fallback = "";
|
|
781
|
+
let firstPrompt = "";
|
|
782
|
+
for (const event of events) {
|
|
783
|
+
if (event === null || typeof event !== "object") continue;
|
|
784
|
+
if (event.type === "session/title") {
|
|
785
|
+
const raw = typeof event.data === "string" ? event.data : event.data?.title;
|
|
786
|
+
const value = typeof raw === "string" ? raw.trim() : "";
|
|
787
|
+
if (value === "") continue;
|
|
788
|
+
if (event.data?.source?.kind === "fallback") fallback = value;
|
|
789
|
+
else provider = value;
|
|
790
|
+
continue;
|
|
791
|
+
}
|
|
792
|
+
if (firstPrompt === "" && event.type === "user/message") {
|
|
793
|
+
const text = conversationText(event.data?.message?.content ?? event.data?.content).trim();
|
|
794
|
+
const first = text.split("\n")[0].trim();
|
|
795
|
+
if (first !== "") firstPrompt = first.slice(0, 120);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
if (provider !== "") return provider;
|
|
799
|
+
if (fallback !== "") return fallback;
|
|
800
|
+
return firstPrompt;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* Fragments of the message to find again in the rendered transcript.
|
|
805
|
+
*
|
|
806
|
+
* The conversation view exposes no per-turn DOM anchor, so a jump locates what
|
|
807
|
+
* to scroll to by its text - and the log's text is markdown while the DOM's is
|
|
808
|
+
* not. `**bold**`, backticks, table pipes and heading marks all disappear when
|
|
809
|
+
* the message renders, so the raw window would never match. Several candidates
|
|
810
|
+
* are returned because a match can sit inside bold, inside a table cell, or at
|
|
811
|
+
* the start of a line the renderer rewrites.
|
|
812
|
+
*/
|
|
813
|
+
function searchSeeks(text, needle) {
|
|
814
|
+
const stripped = text
|
|
815
|
+
.replace(/```[\s\S]*?```/g, " ")
|
|
816
|
+
.replace(/^\s{0,6}#{1,6}\s+/gm, "")
|
|
817
|
+
.replace(/^\s{0,6}>\s?/gm, "")
|
|
818
|
+
.replace(/^\s{0,6}(?:[-*+]|\d+\.)\s+/gm, "")
|
|
819
|
+
.replace(/\*\*|__|`/g, "")
|
|
820
|
+
.replace(/\|/g, " ")
|
|
821
|
+
.replace(/\s+/g, " ")
|
|
822
|
+
.trim();
|
|
823
|
+
const index = needle === "" ? -1 : stripped.toLowerCase().indexOf(needle);
|
|
824
|
+
const out = [];
|
|
825
|
+
const push = (from) => {
|
|
826
|
+
const body = stripped.slice(Math.max(0, from), Math.max(0, from) + 70).trim();
|
|
827
|
+
if (body.length >= 8 && out.indexOf(body) === -1) out.push(body);
|
|
828
|
+
};
|
|
829
|
+
if (index >= 0) {
|
|
830
|
+
push(index);
|
|
831
|
+
push(index - 30);
|
|
832
|
+
}
|
|
833
|
+
push(0);
|
|
834
|
+
return out.slice(0, 3);
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* A window of the message around the match.
|
|
839
|
+
*
|
|
840
|
+
* Jumping into a long session makes the chat mount a large page of history, and
|
|
841
|
+
* that is slow; the panel can show the neighbourhood of a hit on its own. The
|
|
842
|
+
* window is collapsed to single spaces and capped because it crosses the IPC
|
|
843
|
+
* boundary for every hit.
|
|
844
|
+
*/
|
|
845
|
+
function searchContext(text, needle, radius) {
|
|
846
|
+
const span = Number.isFinite(radius) ? radius : 420;
|
|
847
|
+
const flat = text.replace(/\s+/g, " ");
|
|
848
|
+
const index = needle === "" ? -1 : flat.toLowerCase().indexOf(needle);
|
|
849
|
+
if (index < 0) return flat.slice(0, span * 2).trim();
|
|
850
|
+
const from = Math.max(0, index - span);
|
|
851
|
+
const to = Math.min(flat.length, index + needle.length + span);
|
|
852
|
+
const head = from > 0 ? "\u2026" : "";
|
|
853
|
+
const tail = to < flat.length ? "\u2026" : "";
|
|
854
|
+
return head + flat.slice(from, to).trim() + tail;
|
|
855
|
+
}
|
|
856
|
+
|
|
766
857
|
function searchSnippet(text, needle) {
|
|
767
858
|
const haystack = text.toLowerCase();
|
|
768
859
|
const index = needle === "" ? -1 : haystack.indexOf(needle);
|
|
@@ -831,33 +922,56 @@ export async function searchSessions(ctx, query, options = {}) {
|
|
|
831
922
|
}
|
|
832
923
|
decoded += 1;
|
|
833
924
|
let messages = [];
|
|
925
|
+
let title = "";
|
|
834
926
|
try {
|
|
835
|
-
|
|
927
|
+
const events = await readSessionEvents(ctx, session.id);
|
|
928
|
+
messages = extractSearchMessages(events);
|
|
929
|
+
title = titleFromEvents(events);
|
|
836
930
|
} catch {
|
|
837
931
|
messages = [];
|
|
838
932
|
}
|
|
839
|
-
await writeSearchCache(directory, session.id, { v: SEARCH_INDEX_VERSION, key, messages });
|
|
840
|
-
cached = { key, messages };
|
|
933
|
+
await writeSearchCache(directory, session.id, { v: SEARCH_INDEX_VERSION, key, messages, title });
|
|
934
|
+
cached = { key, messages, title };
|
|
841
935
|
}
|
|
842
936
|
|
|
843
937
|
let found = 0;
|
|
938
|
+
/* How far down the transcript the last turn sits: the client uses it to jump
|
|
939
|
+
to an approximate scroll position before it looks for the text. */
|
|
940
|
+
let maxTurn = 0;
|
|
941
|
+
for (const message of cached.messages) {
|
|
942
|
+
if (message !== null && typeof message === "object" && Number.isFinite(Number(message.turn))) {
|
|
943
|
+
if (Number(message.turn) > maxTurn) maxTurn = Number(message.turn);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
844
946
|
for (const message of cached.messages) {
|
|
845
947
|
if (message === null || typeof message !== "object" || typeof message.text !== "string") continue;
|
|
846
948
|
const haystack = message.text.toLowerCase();
|
|
847
949
|
if (!terms.every((term) => haystack.indexOf(term) !== -1)) continue;
|
|
848
950
|
const { snippet, lead, tail } = searchSnippet(message.text, terms[0]);
|
|
849
|
-
const
|
|
951
|
+
const seeks = searchSeeks(message.text, terms[0]);
|
|
952
|
+
const headerTitle = typeof session.header.title === "string" ? session.header.title.trim() : "";
|
|
953
|
+
const cachedTitle = typeof cached.title === "string" ? cached.title.trim() : "";
|
|
850
954
|
const cwd = normalizedPath(session.header.cwd);
|
|
851
955
|
hits.push({
|
|
852
956
|
sessionId: session.id,
|
|
853
|
-
title:
|
|
957
|
+
title: headerTitle !== "" ? headerTitle : (cachedTitle !== "" ? cachedTitle : titleFromMessages(cached.messages, session.id)),
|
|
854
958
|
workspace: workspaceByPath.get(cwd) ?? "",
|
|
855
959
|
cwd: typeof session.header.cwd === "string" ? session.header.cwd : "",
|
|
856
960
|
turn: message.turn,
|
|
961
|
+
step: message.step === undefined ? null : message.step,
|
|
857
962
|
seq: message.seq,
|
|
858
963
|
at: message.at,
|
|
859
964
|
role: message.role,
|
|
860
965
|
snippet,
|
|
966
|
+
/* A piece of the message to find again in the rendered transcript: the
|
|
967
|
+
chat exposes no per-turn DOM anchor, so the client locates the text. */
|
|
968
|
+
seek: seeks.length > 0 ? seeks[0] : "",
|
|
969
|
+
seeks,
|
|
970
|
+
/* The matched neighbourhood, so reading a hit never needs the chat. */
|
|
971
|
+
context: searchContext(message.text, terms[0]),
|
|
972
|
+
/* How many turns the session has, so the client can scroll to a rough
|
|
973
|
+
position before looking for the text. */
|
|
974
|
+
turns: maxTurn,
|
|
861
975
|
lead: lead === true,
|
|
862
976
|
tail: tail === true,
|
|
863
977
|
});
|
|
@@ -1657,6 +1771,8 @@ function checkpointValue(record, key) {
|
|
|
1657
1771
|
*
|
|
1658
1772
|
* A title is written right after the first prompt, so the first page of the log
|
|
1659
1773
|
* is enough - and reading one page is far cheaper than folding the whole Log.
|
|
1774
|
+
* The page holds both the prefix fallback and the provider's title; the provider
|
|
1775
|
+
* one is the name the sidebar shows, so it wins.
|
|
1660
1776
|
*/
|
|
1661
1777
|
async function titleFromLog(ctx, sessionId) {
|
|
1662
1778
|
let handle;
|
|
@@ -1668,11 +1784,18 @@ async function titleFromLog(ctx, sessionId) {
|
|
|
1668
1784
|
try {
|
|
1669
1785
|
const slice = await handle.read(0, 60);
|
|
1670
1786
|
const events = slice !== null && slice !== undefined && Array.isArray(slice.events) ? slice.events : [];
|
|
1787
|
+
let provider = "";
|
|
1788
|
+
let fallback = "";
|
|
1671
1789
|
for (const event of events) {
|
|
1672
1790
|
if (event?.type !== "session/title") continue;
|
|
1673
|
-
const
|
|
1674
|
-
|
|
1675
|
-
|
|
1791
|
+
const raw = typeof event.data === "string" ? event.data : event.data?.title;
|
|
1792
|
+
const value = typeof raw === "string" ? raw.trim() : "";
|
|
1793
|
+
if (value === "") continue;
|
|
1794
|
+
if (event.data?.source?.kind === "fallback") fallback = value;
|
|
1795
|
+
else provider = value;
|
|
1796
|
+
}
|
|
1797
|
+
if (provider !== "") return provider;
|
|
1798
|
+
if (fallback !== "") return fallback;
|
|
1676
1799
|
for (const event of events) {
|
|
1677
1800
|
if (event?.type !== "user/message") continue;
|
|
1678
1801
|
const line = blockText(event.data?.content).split("\n")[0].trim();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ws-recency",
|
|
3
|
-
"version": "0.30.
|
|
3
|
+
"version": "0.30.2",
|
|
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, moving a session to another workspace, and a literal content search that jumps to the turn a word was said in.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "chyxhtc",
|