dsh-content-search-ad 0.22.1 → 0.24.0
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 +23 -0
- package/client.js +138 -3
- package/index.js +64 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,6 +64,29 @@ is a subsequence, which turns the list into match-everything noise.
|
|
|
64
64
|
matches come last.
|
|
65
65
|
- **Recent searches** appear in the empty state; one click re-runs one.
|
|
66
66
|
|
|
67
|
+
## Two frames
|
|
68
|
+
|
|
69
|
+
The panel is split in two, and the lower frame never moves:
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
┌ search field + scope ─────────────────────┐
|
|
73
|
+
│ results │ ← search output, scrolls
|
|
74
|
+
├ This chat · 24 questions ──────────────────┤
|
|
75
|
+
│ the questions you asked, oldest first │ ← fixed list, scrolls on its own
|
|
76
|
+
│ … │
|
|
77
|
+
├──────────────────────────────── v0.24.0 ───┤
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
- The lower frame lists every question **you** asked in the current conversation
|
|
81
|
+
(injected context and tool output are filtered out by the message source). It
|
|
82
|
+
refreshes itself every few seconds, so a prompt you send shows up without
|
|
83
|
+
reopening the panel.
|
|
84
|
+
- Typing a query does **not** filter or reorder that list: matching rows are
|
|
85
|
+
highlighted in place, and clicking any row still jumps to it in the transcript.
|
|
86
|
+
- The running version is printed in the footer of both the list and the detail
|
|
87
|
+
view, so a build can be identified (and rolled back) without opening the
|
|
88
|
+
plugin's files.
|
|
89
|
+
|
|
67
90
|
## The detail view
|
|
68
91
|
|
|
69
92
|
```
|
package/client.js
CHANGED
|
@@ -18,6 +18,8 @@ window.__ModuleLoader__.load({
|
|
|
18
18
|
//#region contract
|
|
19
19
|
/** Locale namespace owned by this plugin. */
|
|
20
20
|
const NS = 'contentSearch'
|
|
21
|
+
/** Plugin version, shown in the panel so a running build can be identified. */
|
|
22
|
+
const PLUGIN_VERSION = '0.24.0'
|
|
21
23
|
/** Tab-type identity; the body slot registers under the same key. */
|
|
22
24
|
const TAB_ID = 'dsh-content-search-ad/panel'
|
|
23
25
|
/** Page kind opened by the guide card and the strip's add control. */
|
|
@@ -49,6 +51,7 @@ window.__ModuleLoader__.load({
|
|
|
49
51
|
'field.placeholder': 'Search the content of every conversation…',
|
|
50
52
|
'field.clear': 'Clear search',
|
|
51
53
|
'recent.title': 'Recent searches',
|
|
54
|
+
'questions.title': 'This chat · {n} questions',
|
|
52
55
|
'command.open': 'Search conversation content',
|
|
53
56
|
'hint.idle': 'Type a keyword to search every conversation body and title.',
|
|
54
57
|
'hint.shortcut': 'Press {keys} anywhere to open this panel.',
|
|
@@ -169,6 +172,29 @@ window.__ModuleLoader__.load({
|
|
|
169
172
|
return String(text === undefined || text === null ? '' : text).replace(/\s+/gu, ' ').trim()
|
|
170
173
|
}
|
|
171
174
|
|
|
175
|
+
/** Positive terms of a query, the same shape the Host parses. */
|
|
176
|
+
function queryTerms(raw) {
|
|
177
|
+
const text = String(raw === undefined || raw === null ? '' : raw)
|
|
178
|
+
const terms = []
|
|
179
|
+
const pattern = /(-?)"([^"]*)"|(-?)(\S+)/gu
|
|
180
|
+
let match = pattern.exec(text)
|
|
181
|
+
while (match !== null) {
|
|
182
|
+
const negative = (match[1] !== undefined ? match[1] : match[3]) === '-'
|
|
183
|
+
const value = String(match[2] !== undefined ? match[2] : match[4]).toLowerCase()
|
|
184
|
+
if (!negative && value.length > 0) terms.push(value)
|
|
185
|
+
match = pattern.exec(text)
|
|
186
|
+
}
|
|
187
|
+
return terms
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Whether every positive term of the query appears in the text. */
|
|
191
|
+
function matchesQuery(text, raw) {
|
|
192
|
+
const terms = queryTerms(raw)
|
|
193
|
+
if (terms.length === 0) return false
|
|
194
|
+
const haystack = normalize(text)
|
|
195
|
+
return terms.every((term) => haystack.includes(term))
|
|
196
|
+
}
|
|
197
|
+
|
|
172
198
|
/** Drop the ellipsis the Host puts around an excerpt. */
|
|
173
199
|
function trimEllipsis(text) {
|
|
174
200
|
return oneLine(text).replace(/^…+/u, '').replace(/…+$/u, '').trim()
|
|
@@ -765,7 +791,16 @@ window.__ModuleLoader__.load({
|
|
|
765
791
|
.dcs-count{flex:0 0 auto;padding:0 6px;border-radius:999px;background:var(--dsw-alias-interactive-bg-hover-accent,var(--dsw-alias-bg-layer-3));font-size:11px;line-height:17px;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-secondary)}
|
|
766
792
|
.dcs-row-snippet{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;font-size:12px;line-height:1.55;color:var(--dsw-alias-label-secondary);overflow-wrap:anywhere}
|
|
767
793
|
.dcs-row-meta{font-size:11px;color:var(--dsw-alias-label-tertiary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
768
|
-
.dcs-chevron{flex:0 0 auto;color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1}.dcs-
|
|
794
|
+
.dcs-chevron{flex:0 0 auto;color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1}.dcs-results{flex:1 1 auto;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:6px 6px 10px}
|
|
795
|
+
.dcs-chat{flex:0 0 auto;display:flex;flex-direction:column;max-height:42%;border-top:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1)}
|
|
796
|
+
.dcs-chat-head{flex:0 0 auto;margin:8px 10px 4px}
|
|
797
|
+
.dcs-chat-list{flex:1 1 auto;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:0 6px 8px;display:flex;flex-direction:column;gap:2px}
|
|
798
|
+
.dcs-question[data-hit="true"]{background:var(--dsw-alias-interactive-bg-hover-accent,var(--dsw-alias-bg-layer-3));color:var(--dsw-alias-label-primary);font-weight:600}
|
|
799
|
+
.dcs-version{flex:0 0 auto;font-variant-numeric:tabular-nums;opacity:.7}
|
|
800
|
+
.dcs-questions{display:flex;flex-direction:column;gap:2px;padding:0 6px 6px}
|
|
801
|
+
.dcs-question{width:100%;box-sizing:border-box;padding:6px 8px;border:0;border-radius:var(--dsw-radius-sm);background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;line-height:1.5;text-align:left;cursor:pointer;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;overflow-wrap:anywhere}
|
|
802
|
+
.dcs-question:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
|
|
803
|
+
.dcs-recent{display:flex;flex-wrap:wrap;gap:6px;padding:0 10px 4px}
|
|
769
804
|
.dcs-recent-chip{max-width:100%;padding:0 9px;height:24px;border:1px solid var(--dsw-alias-border-l2);border-radius:999px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
770
805
|
.dcs-recent-chip:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
|
|
771
806
|
.dcs-scope{display:flex;gap:2px;margin-top:8px;padding:2px;border-radius:var(--dsw-radius-sm);background:var(--dsw-alias-bg-layer-1)}
|
|
@@ -980,6 +1015,57 @@ window.__ModuleLoader__.load({
|
|
|
980
1015
|
}
|
|
981
1016
|
//#endregion
|
|
982
1017
|
|
|
1018
|
+
/**
|
|
1019
|
+
* The user's own messages in this conversation, for the "what did I ask"
|
|
1020
|
+
* list. The Host reads the log; the browser only renders the answer.
|
|
1021
|
+
*/
|
|
1022
|
+
async function fetchQuestions(sessionId, signal) {
|
|
1023
|
+
if (typeof sessionId !== 'string' || sessionId.length === 0) return { questions: [], count: 0 }
|
|
1024
|
+
const response = await fetch('/content-search/questions?focus=' + encodeURIComponent(sessionId), {
|
|
1025
|
+
signal,
|
|
1026
|
+
credentials: 'same-origin',
|
|
1027
|
+
headers: { accept: 'application/json' },
|
|
1028
|
+
})
|
|
1029
|
+
if (!response.ok) throw new Error('questions unavailable (HTTP ' + response.status + ')')
|
|
1030
|
+
const payload = await response.json()
|
|
1031
|
+
if (payload === null || typeof payload !== 'object' || payload.ok !== true) throw new Error('questions failed')
|
|
1032
|
+
const questions = Array.isArray(payload.questions) ? payload.questions : []
|
|
1033
|
+
return {
|
|
1034
|
+
count: typeof payload.count === 'number' ? payload.count : questions.length,
|
|
1035
|
+
questions: questions.map((question) => ({
|
|
1036
|
+
seq: question.seq,
|
|
1037
|
+
time: typeof question.time === 'number' ? question.time : 0,
|
|
1038
|
+
text: typeof question.text === 'string' ? question.text : '',
|
|
1039
|
+
anchor: typeof question.anchor === 'string' ? question.anchor : '',
|
|
1040
|
+
})),
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
/**
|
|
1045
|
+
* Center one question in the transcript, paging history to it when the
|
|
1046
|
+
* message is older than the loaded window.
|
|
1047
|
+
* @returns whether it was found immediately.
|
|
1048
|
+
*/
|
|
1049
|
+
function revealText(sessionId, anchor, seq) {
|
|
1050
|
+
if (typeof anchor !== 'string' || anchor.length < 4) return false
|
|
1051
|
+
ensureHighlightStyle()
|
|
1052
|
+
if (!highlightSupported()) return false
|
|
1053
|
+
const found = findAnchor(indexTranscript(true), anchor)
|
|
1054
|
+
if (found !== undefined) {
|
|
1055
|
+
CSS.highlights.set(ACTIVE_NAME, new Highlight(found.range))
|
|
1056
|
+
revealElement(found.element)
|
|
1057
|
+
return true
|
|
1058
|
+
}
|
|
1059
|
+
pageToHit(sessionId, seq).then((paged) => {
|
|
1060
|
+
if (!paged) return
|
|
1061
|
+
const retry = findAnchor(indexTranscript(true), anchor)
|
|
1062
|
+
if (retry === undefined) return
|
|
1063
|
+
CSS.highlights.set(ACTIVE_NAME, new Highlight(retry.range))
|
|
1064
|
+
revealElement(retry.element)
|
|
1065
|
+
}).catch(() => {})
|
|
1066
|
+
return false
|
|
1067
|
+
}
|
|
1068
|
+
|
|
983
1069
|
//#region component
|
|
984
1070
|
/**
|
|
985
1071
|
* Everything the panel needs to survive a tab remount: the sidebar is
|
|
@@ -1053,6 +1139,8 @@ window.__ModuleLoader__.load({
|
|
|
1053
1139
|
setScopeState(value)
|
|
1054
1140
|
}, [])
|
|
1055
1141
|
const [recent, setRecent] = React.useState(readRecent)
|
|
1142
|
+
const [questions, setQuestions] = React.useState([])
|
|
1143
|
+
const [questionCount, setQuestionCount] = React.useState(0)
|
|
1056
1144
|
|
|
1057
1145
|
const subscribeList = React.useCallback((notify) => {
|
|
1058
1146
|
const store = runtime === null ? undefined : runtime.sessions && runtime.sessions.list
|
|
@@ -1093,6 +1181,33 @@ window.__ModuleLoader__.load({
|
|
|
1093
1181
|
if (activeInput === inputRef.current) activeInput = null
|
|
1094
1182
|
}
|
|
1095
1183
|
}, [])
|
|
1184
|
+
// The "what did I ask" list belongs to the conversation this panel is on.
|
|
1185
|
+
React.useEffect(() => {
|
|
1186
|
+
if (typeof focusSessionId !== 'string' || focusSessionId.length === 0) return undefined
|
|
1187
|
+
const controller = new AbortController()
|
|
1188
|
+
fetchQuestions(focusSessionId, controller.signal).then((outcome) => {
|
|
1189
|
+
if (controller.signal.aborted) return
|
|
1190
|
+
setQuestions(outcome.questions)
|
|
1191
|
+
setQuestionCount(outcome.count)
|
|
1192
|
+
}).catch(() => {})
|
|
1193
|
+
return () => controller.abort()
|
|
1194
|
+
}, [focusSessionId])
|
|
1195
|
+
|
|
1196
|
+
// The question list is live: a new prompt the user sends shows up without
|
|
1197
|
+
// reopening the panel. Cheap enough — the Host reads the in-memory log.
|
|
1198
|
+
React.useEffect(() => {
|
|
1199
|
+
if (typeof focusSessionId !== 'string' || focusSessionId.length === 0) return undefined
|
|
1200
|
+
const timer = setInterval(() => {
|
|
1201
|
+
const controller = new AbortController()
|
|
1202
|
+
fetchQuestions(focusSessionId, controller.signal).then((outcome) => {
|
|
1203
|
+
if (controller.signal.aborted) return
|
|
1204
|
+
setQuestions((current) => (current.length === outcome.questions.length ? current : outcome.questions))
|
|
1205
|
+
setQuestionCount(outcome.count)
|
|
1206
|
+
}).catch(() => {})
|
|
1207
|
+
}, 8000)
|
|
1208
|
+
return () => clearInterval(timer)
|
|
1209
|
+
}, [focusSessionId])
|
|
1210
|
+
|
|
1096
1211
|
const trimmed = query.trim()
|
|
1097
1212
|
|
|
1098
1213
|
React.useEffect(() => {
|
|
@@ -1309,6 +1424,9 @@ window.__ModuleLoader__.load({
|
|
|
1309
1424
|
? h('p', { className: 'dcs-detail-status' }, t('detail.missing'))
|
|
1310
1425
|
: null,
|
|
1311
1426
|
),
|
|
1427
|
+
h('div', { className: 'dcs-foot' },
|
|
1428
|
+
h('span', { key: 'spacer' }, ''),
|
|
1429
|
+
h('span', { key: 'version', className: 'dcs-version' }, 'v' + PLUGIN_VERSION)),
|
|
1312
1430
|
)
|
|
1313
1431
|
}
|
|
1314
1432
|
|
|
@@ -1442,8 +1560,25 @@ window.__ModuleLoader__.load({
|
|
|
1442
1560
|
onClick: () => setScope(value),
|
|
1443
1561
|
}, t('scope.' + value)))),
|
|
1444
1562
|
),
|
|
1445
|
-
h('div', { className: 'dcs-
|
|
1446
|
-
|
|
1563
|
+
h('div', { className: 'dcs-results', role: 'listbox', 'aria-label': t('field.label') }, body),
|
|
1564
|
+
questions.length > 0
|
|
1565
|
+
? h('div', { className: 'dcs-chat' },
|
|
1566
|
+
h('p', { className: 'dcs-section dcs-chat-head' }, t('questions.title', { n: questionCount })),
|
|
1567
|
+
h('div', { className: 'dcs-chat-list' }, questions.map((question, index) => {
|
|
1568
|
+
const hit = trimmed.length > 0 && matchesQuery(question.text, query)
|
|
1569
|
+
return h('button', {
|
|
1570
|
+
key: String(question.seq) + ':' + index,
|
|
1571
|
+
type: 'button',
|
|
1572
|
+
className: 'dcs-question',
|
|
1573
|
+
'data-hit': hit ? 'true' : 'false',
|
|
1574
|
+
title: question.text,
|
|
1575
|
+
onClick: () => revealText(focusSessionId, question.anchor, question.seq),
|
|
1576
|
+
}, hit ? highlight(question.text, query, 'q' + index) : question.text)
|
|
1577
|
+
})))
|
|
1578
|
+
: null,
|
|
1579
|
+
h('div', { className: 'dcs-foot' },
|
|
1580
|
+
h('span', { key: 'hint' }, footer),
|
|
1581
|
+
h('span', { key: 'version', className: 'dcs-version' }, 'v' + PLUGIN_VERSION)),
|
|
1447
1582
|
)
|
|
1448
1583
|
}
|
|
1449
1584
|
//#endregion
|
package/index.js
CHANGED
|
@@ -64,7 +64,7 @@ const FUZZY_MAX_CHARS = 12
|
|
|
64
64
|
/** Shortest query, in code points, still worth a fuzzy pass. */
|
|
65
65
|
const FUZZY_MIN_CHARS = 4
|
|
66
66
|
|
|
67
|
-
const VERSION = '0.
|
|
67
|
+
const VERSION = '0.24.0'
|
|
68
68
|
|
|
69
69
|
//#region http helpers
|
|
70
70
|
function writeJson(res, status, value) {
|
|
@@ -569,6 +569,58 @@ async function scanCorpus(ctx, parsed, focusId, scope) {
|
|
|
569
569
|
}
|
|
570
570
|
//#endregion
|
|
571
571
|
|
|
572
|
+
//#region questions
|
|
573
|
+
/** How many user messages the panel lists for one conversation. */
|
|
574
|
+
const QUESTIONS_MAX = 200
|
|
575
|
+
/** Longest question text sent for display. */
|
|
576
|
+
const QUESTION_TEXT_CHARS = 220
|
|
577
|
+
/** Longest anchor sent for locating the question in the transcript. */
|
|
578
|
+
const QUESTION_ANCHOR_CHARS = 80
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* The user's own messages in one conversation, oldest first.
|
|
582
|
+
*
|
|
583
|
+
* This is the "what did I ask" list: only `user/message` events, only their
|
|
584
|
+
* text blocks, displayed as written and anchored for the transcript locator.
|
|
585
|
+
* @returns `{ questions, count }` for the panel.
|
|
586
|
+
*/
|
|
587
|
+
async function questionsFor(ctx, sessionId) {
|
|
588
|
+
const query = ctx.sessionQuery
|
|
589
|
+
const surface = await query.readSurface(sessionId)
|
|
590
|
+
const events = surface !== null && surface !== undefined && Array.isArray(surface.events) ? surface.events : []
|
|
591
|
+
const questions = []
|
|
592
|
+
for (const event of events) {
|
|
593
|
+
if (event === null || typeof event !== 'object' || event.type !== 'user/message') continue
|
|
594
|
+
const data = event.data === null || event.data === undefined ? {} : event.data
|
|
595
|
+
// Injected context also arrives as a user message; only the human `user`
|
|
596
|
+
// source counts as something the person actually asked.
|
|
597
|
+
const source = data.source === null || data.source === undefined ? {} : data.source
|
|
598
|
+
if (source.kind !== 'user') continue
|
|
599
|
+
const content = data.content
|
|
600
|
+
if (!Array.isArray(content)) continue
|
|
601
|
+
const parts = []
|
|
602
|
+
for (const block of content) {
|
|
603
|
+
if (block === null || typeof block !== 'object') continue
|
|
604
|
+
if (block.type !== 'text') continue
|
|
605
|
+
if (typeof block.text !== 'string' || block.text.length === 0) continue
|
|
606
|
+
parts.push(block.text)
|
|
607
|
+
}
|
|
608
|
+
if (parts.length === 0) continue
|
|
609
|
+
const raw = parts.join('\n').replace(/\s+/gu, ' ').trim()
|
|
610
|
+
if (raw.length === 0) continue
|
|
611
|
+
const plain = plainOf(parts.join('\n'))
|
|
612
|
+
questions.push({
|
|
613
|
+
seq: event.seq,
|
|
614
|
+
time: typeof event.time === 'number' ? event.time : 0,
|
|
615
|
+
text: raw.slice(0, QUESTION_TEXT_CHARS),
|
|
616
|
+
anchor: plain.slice(0, QUESTION_ANCHOR_CHARS),
|
|
617
|
+
})
|
|
618
|
+
}
|
|
619
|
+
const tail = questions.length > QUESTIONS_MAX ? questions.slice(-QUESTIONS_MAX) : questions
|
|
620
|
+
return { questions: tail, count: questions.length }
|
|
621
|
+
}
|
|
622
|
+
//#endregion
|
|
623
|
+
|
|
572
624
|
//#region handler
|
|
573
625
|
async function handleApi(req, res, ctx) {
|
|
574
626
|
if (!isTrustedRequest(req)) {
|
|
@@ -619,6 +671,17 @@ async function handleApi(req, res, ctx) {
|
|
|
619
671
|
return
|
|
620
672
|
}
|
|
621
673
|
|
|
674
|
+
if (route === '/questions' && req.method === 'GET') {
|
|
675
|
+
const focusId = url.searchParams.get('focus')
|
|
676
|
+
if (typeof focusId !== 'string' || focusId.length === 0) {
|
|
677
|
+
fail(res, 400, 'focus-required', 'the focus parameter is required')
|
|
678
|
+
return
|
|
679
|
+
}
|
|
680
|
+
const outcome = await questionsFor(ctx, focusId)
|
|
681
|
+
writeJson(res, 200, { ok: true, sessionId: focusId, ...outcome })
|
|
682
|
+
return
|
|
683
|
+
}
|
|
684
|
+
|
|
622
685
|
fail(res, 404, 'not-found', 'unknown route')
|
|
623
686
|
}
|
|
624
687
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-content-search-ad",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "DeepSeek Harness (DSH) plugin: full-text search over every conversation's prose from a right sidebar tab, with a jump-to-match detail view.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "zmq6931",
|