@lizimin/dsh-session-search 0.0.0-stage → 1.3.7

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.
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: local-session-search
3
+ name: '@lizimin/dsh-session-search'
@@ -0,0 +1,6 @@
1
+ url: https://github.com/Ziminli/dsh-session-search
2
+ name: Ziminli/dsh-session-search
3
+ category: session
4
+ description:
5
+ en: 'Search stored DSH conversation text across all or selected workspaces and sessions, with exact, regular-expression, typo-tolerant or word-internal subsequence matching.'
6
+ zh: '在所有或指定工作区、会话中搜索已存储的 DSH 对话文本,支持精确、正则表达式、拼写容错及词内子序列匹配。'
package/icon.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><rect x="3" y="3" width="58" height="58" rx="15" fill="#3174ef"/><path d="M17 17h23M17 25h13M17 33h9" stroke="#fff" stroke-width="4" stroke-linecap="round"/><circle cx="36" cy="37" r="11" fill="none" stroke="#fff" stroke-width="4"/><path d="m44 45 8 8" stroke="#fff" stroke-width="5" stroke-linecap="round"/></svg>
package/index.js ADDED
@@ -0,0 +1,111 @@
1
+ import {search, highlightText} from './search.js';
2
+ import {createSettingsOperation, readSettingsBody} from './settings.js';
3
+ export {Config} from './settings.js';
4
+ export const inject = ['sessionQuery', 'sessionController', 'workspaceController', 'connection', 'webServer', 'tools', 'configEditor'];
5
+ const MAX_HIGHLIGHT_BODY_BYTES = 2 * 1024 * 1024;
6
+ async function readHighlightBody(req) {
7
+ const declared = req.headers['content-length'];
8
+ if (declared !== undefined && (!/^\d+$/u.test(declared) || Number(declared) > MAX_HIGHLIGHT_BODY_BYTES)) throw new Error('Highlight body exceeds 2 MiB or has invalid Content-Length');
9
+ let size = 0;
10
+ const chunks = [];
11
+ // Do not destroy IncomingMessage (and its socket) on an oversized body:
12
+ // the handler still owes the caller an honest JSON 400 response.
13
+ for await (const chunk of req.iterator({destroyOnReturn: false})) {
14
+ size += Buffer.byteLength(chunk);
15
+ if (size > MAX_HIGHLIGHT_BODY_BYTES) throw new Error('Highlight body exceeds 2 MiB');
16
+ chunks.push(Buffer.from(chunk));
17
+ }
18
+ try {return JSON.parse(Buffer.concat(chunks).toString('utf8'));} catch {throw new Error('Invalid highlight JSON');}
19
+ }
20
+ export function apply(ctx, config) {
21
+ const operation = (input, signal) => search(ctx, input, signal);
22
+ const settings = createSettingsOperation(ctx, config);
23
+ ctx.effect(() => ctx.provide('localSessionSearch', {search: operation, settings}));
24
+ ctx.effect(() => ctx.webServer.register({kind: 'exact', path: '/api/local-session-search-settings', async handler(req, res) {
25
+ res.setHeader('Cache-Control', 'no-store');
26
+ res.setHeader('Content-Type', 'application/json; charset=utf-8');
27
+ res.setHeader('X-Content-Type-Options', 'nosniff');
28
+ const admission = ctx.connection.admit({headers: req.headers});
29
+ if ('rejection' in admission) {res.writeHead(admission.rejection); res.end(JSON.stringify({error: 'Authentication required'})); return;}
30
+ if (admission.peer.principal.kind !== 'owner') {res.writeHead(403); res.end(JSON.stringify({error: 'Owner access required'})); return;}
31
+ if (!['GET', 'POST'].includes(req.method)) {res.setHeader('Allow', 'GET, POST'); res.writeHead(405); res.end(JSON.stringify({error: 'GET or POST required'})); return;}
32
+ if (req.method === 'POST' && !/^application\/json(?:\s*;|$)/i.test(req.headers['content-type'] || '')) {res.writeHead(415); res.end(JSON.stringify({error: 'JSON content type required'})); return;}
33
+ try {
34
+ const result = await settings(req.method === 'POST' ? await readSettingsBody(req) : undefined);
35
+ if (!res.destroyed) {res.writeHead(200); res.end(JSON.stringify(result));}
36
+ } catch (error) {
37
+ if (!res.destroyed) {res.writeHead(400); res.end(JSON.stringify({error: error instanceof Error ? error.message : String(error)}));}
38
+ }
39
+ }}));
40
+ ctx.effect(() => ctx.tools.register({
41
+ name: 'session_search_settings',
42
+ description: 'Read or save the profile-wide Session Search timing preference. Live searches as you type; submit waits for Enter or Search.',
43
+ parameters: {type: 'object', properties: {searchMode: {type: 'string', enum: ['live', 'submit'], description: 'Omit to read. Set to save this timing mode in plugin settings.'}}, additionalProperties: false},
44
+ output: {schema: {type: 'object'}, render: (_args, value) => [{type: 'text', text: JSON.stringify(value)}]},
45
+ isConcurrencySafe: input => input.searchMode === undefined,
46
+ async execute(input) {return settings(input.searchMode === undefined ? undefined : input);}
47
+ }));
48
+ ctx.effect(() => ctx.webServer.register({kind: 'exact', path: '/api/local-session-search-highlight', async handler(req, res) {
49
+ res.setHeader('Cache-Control', 'no-store');
50
+ res.setHeader('Content-Type', 'application/json; charset=utf-8');
51
+ res.setHeader('X-Content-Type-Options', 'nosniff');
52
+ const admission = ctx.connection.admit({headers: req.headers});
53
+ if ('rejection' in admission) {res.writeHead(admission.rejection); res.end(JSON.stringify({error: 'Authentication required'})); return;}
54
+ if (admission.peer.principal.kind !== 'owner') {res.writeHead(403); res.end(JSON.stringify({error: 'Owner access required'})); return;}
55
+ if (req.method !== 'POST') {res.setHeader('Allow', 'POST'); res.writeHead(405); res.end(JSON.stringify({error: 'POST required'})); return;}
56
+ if (!/^application\/json(?:\s*;|$)/i.test(req.headers['content-type'] || '')) {res.writeHead(415); res.end(JSON.stringify({error: 'JSON content type required'})); return;}
57
+ try {
58
+ const input = await readHighlightBody(req);
59
+ if (res.destroyed) return;
60
+ const result = highlightText(input);
61
+ if (!res.destroyed) {res.writeHead(200); res.end(JSON.stringify(result));}
62
+ } catch (error) {
63
+ if (!res.destroyed) {res.writeHead(400); res.end(JSON.stringify({error: error instanceof Error ? error.message : String(error), ...(error?.code ? {code: error.code} : {})}));}
64
+ }
65
+ }}));
66
+ ctx.effect(() => ctx.webServer.register({kind: 'exact', path: '/api/local-session-search', async handler(req, res) {
67
+ const admission = ctx.connection.admit({headers: req.headers});
68
+ res.setHeader('Cache-Control', 'no-store');
69
+ res.setHeader('Content-Type', 'application/json; charset=utf-8');
70
+ res.setHeader('X-Content-Type-Options', 'nosniff');
71
+ if ('rejection' in admission) {res.writeHead(admission.rejection); res.end(JSON.stringify({error: 'Authentication required'})); return;}
72
+ if (admission.peer.principal.kind !== 'owner') {res.writeHead(403); res.end(JSON.stringify({error: 'Owner access required'})); return;}
73
+ if (req.method !== 'GET') {res.setHeader('Allow', 'GET'); res.writeHead(405); res.end(JSON.stringify({error: 'GET required'})); return;}
74
+ const controller = new AbortController();
75
+ const cancel = () => controller.abort();
76
+ res.once('close', cancel);
77
+ try {
78
+ const url = new URL(req.url, 'http://localhost');
79
+ const result = await operation(Object.fromEntries(url.searchParams), controller.signal);
80
+ if (!res.destroyed) {res.writeHead(200); res.end(JSON.stringify(result));}
81
+ } catch (error) {
82
+ if (!res.destroyed) {res.writeHead(400); res.end(JSON.stringify({error: error instanceof Error ? error.message : String(error), ...(error?.code ? {code: error.code} : {})}));}
83
+ } finally {res.off('close', cancel);}
84
+ }}));
85
+ ctx.effect(() => ctx.tools.register({
86
+ name: 'search_session_text',
87
+ description: 'Search DSH history: every matching reply/event with snippets and UTF-16 ranges, or complete per-session match counts. Results are paged. Read-only.',
88
+ parameters: {type: 'object', properties: {
89
+ action: {type: 'string', enum: ['search', 'sessions', 'groups'], description: 'Default search: matching replies/events. groups: session rows with complete event counts (total=groups, totalMatches=events). sessions: catalog without text matching.'},
90
+ query: {type: 'string', description: 'Required for search/groups, 1–1024 characters. Default: escaped literal substring with flexible whitespace. Regex mode: JavaScript Unicode pattern source, no /delimiters/ or trailing flags. Invalid or timed-out expressions fail the entire search.'},
91
+ sessionId: {type: 'string', description: 'Legacy single conversation ID; cannot combine with nonempty sessionIds.'},
92
+ sessionIds: {type: 'array', items: {type: 'string'}, maxItems: 1000, description: 'Search any of these conversation IDs, intersected with workspace scope. Empty/omitted means all. Do not combine with sessionId.'},
93
+ workspaceIds: {type: 'array', items: {type: 'string'}, maxItems: 200, description: 'Search any of these workspace IDs; empty/omitted means all. Use __ungrouped__ for unregistered workspaces. Discover IDs via action sessions. Do not combine with workspaceId.'},
94
+ after: {type: 'integer', description: 'Inclusive message timestamp lower bound, Unix epoch milliseconds. Missing timestamps are excluded when bounded.'},
95
+ before: {type: 'integer', description: 'Exclusive message timestamp upper bound, Unix epoch milliseconds; must exceed after. Applies before matching/grouping, not to session activity.'},
96
+ workspaceId: {type: 'string', description: 'Restrict to this workspace ID; omit for all workspaces. Discover IDs from action sessions → workspaces. Use __ungrouped__ for sessions without a registered workspace. A selected session must belong to this workspace.'},
97
+ includeSubagents: {type: 'boolean', description: 'Include subagent conversations. Default false.'},
98
+ includeArchived: {type: 'boolean', description: 'Include archived conversations. Default false.'},
99
+ matchCase: {type: 'boolean', description: 'Match case exactly. Default false (Unicode case-insensitive).'},
100
+ wholeWord: {type: 'boolean', description: 'Require no adjacent Unicode letter, number or underscore around the complete match. Default false; combines with exact, regex or fuzzy modes.'},
101
+ useRegex: {type: 'boolean', description: 'Interpret query as a JavaScript Unicode regular expression instead of literal text. Default false; incompatible with fuzzy modes.'},
102
+ fuzzy: {type: 'string', enum: ['off', 'typo', 'subsequence'], description: 'Default off: exact text. typo: whole words within 0 edits for 1–3 characters, 1 for 4–7, 2 for 8+; includes adjacent transpositions. subsequence: ordered characters within each word (candidate length ≤4×query-word length+8). Fuzzy phrases keep words contiguous/in order, punctuation literal, whitespace flexible; max 128 Unicode characters / 16 words. Compatible with matchCase/wholeWord, not useRegex.'},
103
+ content: {type: 'string', enum: ['final', 'all'], description: 'Default final: text of the last assistant reply in each completed turn. all: also inputs, intermediate outputs, tool text and stored reasoning.'},
104
+ order: {type: 'string', enum: ['newest', 'oldest'], description: 'Default newest. Search sorts matching messages; groups sorts each session by its newest/oldest matching message, then ID. Catalog uses latest user activity.'},
105
+ cursor: {type: 'string', description: 'nextCursor from the previous page with identical action, query, scope and flags; changed history requires restarting search.'}
106
+ }, additionalProperties: false},
107
+ output: {schema: {type: 'object'}, render: (_args, value) => [{type: 'text', text: JSON.stringify(value)}]},
108
+ isConcurrencySafe: () => true,
109
+ async execute(input, exec) {return operation(input, exec.signal);}
110
+ }));
111
+ }
package/locale/en.json ADDED
@@ -0,0 +1 @@
1
+ {"meta":{"title":"Session Search","description":"Search stored DSH conversation text across all or selected workspaces and sessions, with exact, regular-expression, typo-tolerant or word-internal subsequence matching. Open with Ctrl+F or ⌘F."}}
package/locale/zh.json ADDED
@@ -0,0 +1 @@
1
+ {"meta":{"title":"会话搜索","description":"在所有或指定工作区、会话中搜索已存储的 DSH 对话文本,支持精确、正则表达式、拼写容错及词内子序列匹配。使用 Ctrl+F 或 ⌘F 打开。"}}
package/package.json CHANGED
@@ -1,6 +1,68 @@
1
1
  {
2
2
  "name": "@lizimin/dsh-session-search",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.3.7",
4
+ "description": "Search stored DSH conversation text across all or selected workspaces and sessions, with exact, regular-expression, typo-tolerant or word-internal subsequence matching.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Zimin Li",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/Ziminli/dsh-session-search.git"
11
+ },
12
+ "homepage": "https://github.com/Ziminli/dsh-session-search#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/Ziminli/dsh-session-search/issues"
15
+ },
16
+ "keywords": [
17
+ "dsh-plugin",
18
+ "dsh",
19
+ "session-search",
20
+ "conversation-search"
21
+ ],
22
+ "engines": {
23
+ "node": ">=22"
24
+ },
25
+ "exports": {
26
+ ".": "./index.js",
27
+ "./client": "./client.js",
28
+ "./locale/*.json": "./locale/*.json",
29
+ "./icon": "./icon.svg"
30
+ },
31
+ "files": [
32
+ "index.js",
33
+ "settings.js",
34
+ "search.js",
35
+ "session-catalog.js",
36
+ "client.js",
37
+ "cordis.patch.yml",
38
+ "locale/en.json",
39
+ "locale/zh.json",
40
+ "icon.svg",
41
+ "README.md",
42
+ "README.zh-CN.md",
43
+ "CHANGELOG.md",
44
+ "docs/community-listing.yml",
45
+ "LICENSE"
46
+ ],
47
+ "scripts": {
48
+ "check": "node tools/check.mjs",
49
+ "test": "node --test search.test.js fuzzy.test.js filters.test.js settings.test.js client-logic.test.js highlight.test.js"
50
+ },
51
+ "dsh": {
52
+ "bundle": {
53
+ "patch": "./cordis.patch.yml"
54
+ },
55
+ "client": {
56
+ "platform": "web",
57
+ "immediately": true,
58
+ "inject": [
59
+ "@deepseek-ai/dsh-client-ui-conversation",
60
+ "@deepseek-ai/dsh-client-ui-plugin-manager"
61
+ ]
62
+ }
63
+ },
64
+ "publishConfig": {
65
+ "access": "public",
66
+ "registry": "https://registry.npmjs.org/"
67
+ }
68
+ }