dsh-ws-recency 0.30.0 → 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/README.md +8 -3
- package/client.js +1069 -105
- package/index.js +155 -11
- 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
|
|
@@ -578,7 +578,28 @@ export function aggregateSession(events) {
|
|
|
578
578
|
const end = Math.min(totalSteps, start + size);
|
|
579
579
|
let sum = 0;
|
|
580
580
|
for (let index = start; index < end; index += 1) sum += steps[index].input + steps[index].cacheRead;
|
|
581
|
-
|
|
581
|
+
/* What entered during this bucket: the biggest block that first appears
|
|
582
|
+
between these steps. The panel says "step 58 grew 33K" - this is the
|
|
583
|
+
content behind that number. The host is the only side that sees every
|
|
584
|
+
block (the payload carries the top 15), so the attribution is done here
|
|
585
|
+
and each curve point only carries one small label. */
|
|
586
|
+
let entered = null;
|
|
587
|
+
for (const block of blocks) {
|
|
588
|
+
if (block.entry < start || block.entry >= end) continue;
|
|
589
|
+
if (entered === null || block.tokens > entered.tokens) entered = block;
|
|
590
|
+
}
|
|
591
|
+
series.push({
|
|
592
|
+
step: start + 1,
|
|
593
|
+
context: Math.round(sum / (end - start)),
|
|
594
|
+
entered: entered === null
|
|
595
|
+
? null
|
|
596
|
+
: {
|
|
597
|
+
kind: entered.kind,
|
|
598
|
+
name: entered.name,
|
|
599
|
+
detail: typeof entered.detail === "string" ? entered.detail.slice(0, 80) : "",
|
|
600
|
+
tokens: entered.tokens,
|
|
601
|
+
},
|
|
602
|
+
});
|
|
582
603
|
}
|
|
583
604
|
}
|
|
584
605
|
summary.amplified = {
|
|
@@ -642,7 +663,7 @@ async function readSessionEvents(ctx, sessionId) {
|
|
|
642
663
|
* pending, which is what the panel shows as "still indexing".
|
|
643
664
|
* ------------------------------------------------------------------------- */
|
|
644
665
|
|
|
645
|
-
const SEARCH_INDEX_VERSION =
|
|
666
|
+
const SEARCH_INDEX_VERSION = 4;
|
|
646
667
|
/** Longer messages are cut for the cache: snippets never need the tail. */
|
|
647
668
|
const SEARCH_MESSAGE_CAP = 200000;
|
|
648
669
|
const SEARCH_PER_SESSION = 3;
|
|
@@ -731,8 +752,12 @@ function extractSearchMessages(events) {
|
|
|
731
752
|
if (text === "") continue;
|
|
732
753
|
if (text.length > SEARCH_MESSAGE_CAP) text = text.slice(0, SEARCH_MESSAGE_CAP);
|
|
733
754
|
const declared = Number(data.turn);
|
|
755
|
+
const declaredStep = Number(data.step);
|
|
734
756
|
messages.push({
|
|
735
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,
|
|
736
761
|
seq: Number.isSafeInteger(Number(event.seq)) ? Number(event.seq) : 0,
|
|
737
762
|
at: Number.isFinite(Number(event.time)) ? Number(event.time) : 0,
|
|
738
763
|
role: event.type === "user/message" ? "user" : "assistant",
|
|
@@ -742,6 +767,93 @@ function extractSearchMessages(events) {
|
|
|
742
767
|
return messages;
|
|
743
768
|
}
|
|
744
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
|
+
|
|
745
857
|
function searchSnippet(text, needle) {
|
|
746
858
|
const haystack = text.toLowerCase();
|
|
747
859
|
const index = needle === "" ? -1 : haystack.indexOf(needle);
|
|
@@ -810,33 +922,56 @@ export async function searchSessions(ctx, query, options = {}) {
|
|
|
810
922
|
}
|
|
811
923
|
decoded += 1;
|
|
812
924
|
let messages = [];
|
|
925
|
+
let title = "";
|
|
813
926
|
try {
|
|
814
|
-
|
|
927
|
+
const events = await readSessionEvents(ctx, session.id);
|
|
928
|
+
messages = extractSearchMessages(events);
|
|
929
|
+
title = titleFromEvents(events);
|
|
815
930
|
} catch {
|
|
816
931
|
messages = [];
|
|
817
932
|
}
|
|
818
|
-
await writeSearchCache(directory, session.id, { v: SEARCH_INDEX_VERSION, key, messages });
|
|
819
|
-
cached = { key, messages };
|
|
933
|
+
await writeSearchCache(directory, session.id, { v: SEARCH_INDEX_VERSION, key, messages, title });
|
|
934
|
+
cached = { key, messages, title };
|
|
820
935
|
}
|
|
821
936
|
|
|
822
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
|
+
}
|
|
823
946
|
for (const message of cached.messages) {
|
|
824
947
|
if (message === null || typeof message !== "object" || typeof message.text !== "string") continue;
|
|
825
948
|
const haystack = message.text.toLowerCase();
|
|
826
949
|
if (!terms.every((term) => haystack.indexOf(term) !== -1)) continue;
|
|
827
950
|
const { snippet, lead, tail } = searchSnippet(message.text, terms[0]);
|
|
828
|
-
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() : "";
|
|
829
954
|
const cwd = normalizedPath(session.header.cwd);
|
|
830
955
|
hits.push({
|
|
831
956
|
sessionId: session.id,
|
|
832
|
-
title:
|
|
957
|
+
title: headerTitle !== "" ? headerTitle : (cachedTitle !== "" ? cachedTitle : titleFromMessages(cached.messages, session.id)),
|
|
833
958
|
workspace: workspaceByPath.get(cwd) ?? "",
|
|
834
959
|
cwd: typeof session.header.cwd === "string" ? session.header.cwd : "",
|
|
835
960
|
turn: message.turn,
|
|
961
|
+
step: message.step === undefined ? null : message.step,
|
|
836
962
|
seq: message.seq,
|
|
837
963
|
at: message.at,
|
|
838
964
|
role: message.role,
|
|
839
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,
|
|
840
975
|
lead: lead === true,
|
|
841
976
|
tail: tail === true,
|
|
842
977
|
});
|
|
@@ -1636,6 +1771,8 @@ function checkpointValue(record, key) {
|
|
|
1636
1771
|
*
|
|
1637
1772
|
* A title is written right after the first prompt, so the first page of the log
|
|
1638
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.
|
|
1639
1776
|
*/
|
|
1640
1777
|
async function titleFromLog(ctx, sessionId) {
|
|
1641
1778
|
let handle;
|
|
@@ -1647,11 +1784,18 @@ async function titleFromLog(ctx, sessionId) {
|
|
|
1647
1784
|
try {
|
|
1648
1785
|
const slice = await handle.read(0, 60);
|
|
1649
1786
|
const events = slice !== null && slice !== undefined && Array.isArray(slice.events) ? slice.events : [];
|
|
1787
|
+
let provider = "";
|
|
1788
|
+
let fallback = "";
|
|
1650
1789
|
for (const event of events) {
|
|
1651
1790
|
if (event?.type !== "session/title") continue;
|
|
1652
|
-
const
|
|
1653
|
-
|
|
1654
|
-
|
|
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;
|
|
1655
1799
|
for (const event of events) {
|
|
1656
1800
|
if (event?.type !== "user/message") continue;
|
|
1657
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",
|