@openspecui/search 5.0.0 → 6.0.0-beta.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/dist/index.d.mts +114 -2
- package/dist/index.mjs +4 -2
- package/dist/node.d.mts +1 -1
- package/dist/node.mjs +1 -1
- package/dist/types-BrBOVcVY.d.mts +68 -0
- package/dist/{worker-source-D2akmNhf.mjs → worker-source-wZNAgstZ.mjs} +41 -3
- package/package.json +1 -1
- package/dist/types-DOR38nFt.d.mts +0 -41
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { a as SearchIndexDocument, i as
|
|
1
|
+
import { a as SearchDocumentKind, c as SearchIndexDocument, i as SearchDocument, l as SearchProvider, n as ProjectSearchHit, o as SearchHit, r as ProjectSearchScope, s as SearchIndex, t as ProjectSearchDocument, u as SearchQuery } from "./types-BrBOVcVY.mjs";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
4
|
//#region src/engine.d.ts
|
|
5
|
+
|
|
5
6
|
declare function normalizeText(input: string): string;
|
|
6
7
|
declare function splitTerms(query: string): string[];
|
|
7
8
|
declare function buildSearchIndex(docs: SearchDocument[]): SearchIndex;
|
|
@@ -10,9 +11,12 @@ declare function searchIndex(index: SearchIndex, query: SearchQuery): SearchHit[
|
|
|
10
11
|
//#endregion
|
|
11
12
|
//#region src/protocol.d.ts
|
|
12
13
|
declare const SearchDocumentKindSchema: z.ZodString;
|
|
14
|
+
/** The source scopes supported by one project workspace's Search surface. */
|
|
15
|
+
declare const ProjectSearchScopeSchema: z.ZodEnum<["active-root", "referenced-specs"]>;
|
|
13
16
|
declare const SearchDocumentSchema: z.ZodObject<{
|
|
14
17
|
id: z.ZodString;
|
|
15
18
|
kind: z.ZodString;
|
|
19
|
+
scope: z.ZodOptional<z.ZodEnum<["active-root", "referenced-specs"]>>;
|
|
16
20
|
title: z.ZodString;
|
|
17
21
|
href: z.ZodString;
|
|
18
22
|
path: z.ZodString;
|
|
@@ -26,6 +30,7 @@ declare const SearchDocumentSchema: z.ZodObject<{
|
|
|
26
30
|
path: string;
|
|
27
31
|
content: string;
|
|
28
32
|
updatedAt: number;
|
|
33
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
29
34
|
}, {
|
|
30
35
|
id: string;
|
|
31
36
|
kind: string;
|
|
@@ -34,18 +39,99 @@ declare const SearchDocumentSchema: z.ZodObject<{
|
|
|
34
39
|
path: string;
|
|
35
40
|
content: string;
|
|
36
41
|
updatedAt: number;
|
|
42
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
43
|
+
}>;
|
|
44
|
+
/** Runtime validator for a source-attributed project Search document. */
|
|
45
|
+
declare const ProjectSearchDocumentSchema: z.ZodObject<{
|
|
46
|
+
id: z.ZodString;
|
|
47
|
+
kind: z.ZodString;
|
|
48
|
+
title: z.ZodString;
|
|
49
|
+
href: z.ZodString;
|
|
50
|
+
path: z.ZodString;
|
|
51
|
+
content: z.ZodString;
|
|
52
|
+
updatedAt: z.ZodNumber;
|
|
53
|
+
} & {
|
|
54
|
+
scope: z.ZodEnum<["active-root", "referenced-specs"]>;
|
|
55
|
+
}, "strip", z.ZodTypeAny, {
|
|
56
|
+
id: string;
|
|
57
|
+
kind: string;
|
|
58
|
+
scope: "active-root" | "referenced-specs";
|
|
59
|
+
title: string;
|
|
60
|
+
href: string;
|
|
61
|
+
path: string;
|
|
62
|
+
content: string;
|
|
63
|
+
updatedAt: number;
|
|
64
|
+
}, {
|
|
65
|
+
id: string;
|
|
66
|
+
kind: string;
|
|
67
|
+
scope: "active-root" | "referenced-specs";
|
|
68
|
+
title: string;
|
|
69
|
+
href: string;
|
|
70
|
+
path: string;
|
|
71
|
+
content: string;
|
|
72
|
+
updatedAt: number;
|
|
37
73
|
}>;
|
|
38
74
|
declare const SearchQuerySchema: z.ZodObject<{
|
|
39
75
|
query: z.ZodString;
|
|
76
|
+
scope: z.ZodOptional<z.ZodEnum<["active-root", "referenced-specs"]>>;
|
|
40
77
|
limit: z.ZodOptional<z.ZodNumber>;
|
|
41
78
|
}, "strip", z.ZodTypeAny, {
|
|
42
79
|
query: string;
|
|
80
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
43
81
|
limit?: number | undefined;
|
|
44
82
|
}, {
|
|
45
83
|
query: string;
|
|
84
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
85
|
+
limit?: number | undefined;
|
|
86
|
+
}>;
|
|
87
|
+
/** A project Search request normalized to the writable Planning-root source by default. */
|
|
88
|
+
declare const ProjectSearchQuerySchema: z.ZodObject<{
|
|
89
|
+
query: z.ZodString;
|
|
90
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
91
|
+
} & {
|
|
92
|
+
scope: z.ZodDefault<z.ZodEnum<["active-root", "referenced-specs"]>>;
|
|
93
|
+
}, "strip", z.ZodTypeAny, {
|
|
94
|
+
scope: "active-root" | "referenced-specs";
|
|
95
|
+
query: string;
|
|
96
|
+
limit?: number | undefined;
|
|
97
|
+
}, {
|
|
98
|
+
query: string;
|
|
99
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
46
100
|
limit?: number | undefined;
|
|
47
101
|
}>;
|
|
48
102
|
declare const SearchHitSchema: z.ZodObject<{
|
|
103
|
+
documentId: z.ZodString;
|
|
104
|
+
kind: z.ZodString;
|
|
105
|
+
scope: z.ZodOptional<z.ZodEnum<["active-root", "referenced-specs"]>>;
|
|
106
|
+
title: z.ZodString;
|
|
107
|
+
href: z.ZodString;
|
|
108
|
+
path: z.ZodString;
|
|
109
|
+
score: z.ZodNumber;
|
|
110
|
+
snippet: z.ZodString;
|
|
111
|
+
updatedAt: z.ZodNumber;
|
|
112
|
+
}, "strip", z.ZodTypeAny, {
|
|
113
|
+
kind: string;
|
|
114
|
+
title: string;
|
|
115
|
+
href: string;
|
|
116
|
+
path: string;
|
|
117
|
+
updatedAt: number;
|
|
118
|
+
documentId: string;
|
|
119
|
+
score: number;
|
|
120
|
+
snippet: string;
|
|
121
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
122
|
+
}, {
|
|
123
|
+
kind: string;
|
|
124
|
+
title: string;
|
|
125
|
+
href: string;
|
|
126
|
+
path: string;
|
|
127
|
+
updatedAt: number;
|
|
128
|
+
documentId: string;
|
|
129
|
+
score: number;
|
|
130
|
+
snippet: string;
|
|
131
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
132
|
+
}>;
|
|
133
|
+
/** Runtime validator for a source-attributed project Search result. */
|
|
134
|
+
declare const ProjectSearchHitSchema: z.ZodObject<{
|
|
49
135
|
documentId: z.ZodString;
|
|
50
136
|
kind: z.ZodString;
|
|
51
137
|
title: z.ZodString;
|
|
@@ -54,8 +140,11 @@ declare const SearchHitSchema: z.ZodObject<{
|
|
|
54
140
|
score: z.ZodNumber;
|
|
55
141
|
snippet: z.ZodString;
|
|
56
142
|
updatedAt: z.ZodNumber;
|
|
143
|
+
} & {
|
|
144
|
+
scope: z.ZodEnum<["active-root", "referenced-specs"]>;
|
|
57
145
|
}, "strip", z.ZodTypeAny, {
|
|
58
146
|
kind: string;
|
|
147
|
+
scope: "active-root" | "referenced-specs";
|
|
59
148
|
title: string;
|
|
60
149
|
href: string;
|
|
61
150
|
path: string;
|
|
@@ -65,6 +154,7 @@ declare const SearchHitSchema: z.ZodObject<{
|
|
|
65
154
|
snippet: string;
|
|
66
155
|
}, {
|
|
67
156
|
kind: string;
|
|
157
|
+
scope: "active-root" | "referenced-specs";
|
|
68
158
|
title: string;
|
|
69
159
|
href: string;
|
|
70
160
|
path: string;
|
|
@@ -73,12 +163,15 @@ declare const SearchHitSchema: z.ZodObject<{
|
|
|
73
163
|
score: number;
|
|
74
164
|
snippet: string;
|
|
75
165
|
}>;
|
|
166
|
+
/** Validate project hits and reject provenance that differs from the selected source. */
|
|
167
|
+
declare function parseProjectSearchHits(input: unknown, expectedScope: ProjectSearchScope): ProjectSearchHit[];
|
|
76
168
|
declare const SearchWorkerRequestSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
77
169
|
id: z.ZodString;
|
|
78
170
|
type: z.ZodLiteral<"init">;
|
|
79
171
|
docs: z.ZodArray<z.ZodObject<{
|
|
80
172
|
id: z.ZodString;
|
|
81
173
|
kind: z.ZodString;
|
|
174
|
+
scope: z.ZodOptional<z.ZodEnum<["active-root", "referenced-specs"]>>;
|
|
82
175
|
title: z.ZodString;
|
|
83
176
|
href: z.ZodString;
|
|
84
177
|
path: z.ZodString;
|
|
@@ -92,6 +185,7 @@ declare const SearchWorkerRequestSchema: z.ZodDiscriminatedUnion<"type", [z.ZodO
|
|
|
92
185
|
path: string;
|
|
93
186
|
content: string;
|
|
94
187
|
updatedAt: number;
|
|
188
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
95
189
|
}, {
|
|
96
190
|
id: string;
|
|
97
191
|
kind: string;
|
|
@@ -100,6 +194,7 @@ declare const SearchWorkerRequestSchema: z.ZodDiscriminatedUnion<"type", [z.ZodO
|
|
|
100
194
|
path: string;
|
|
101
195
|
content: string;
|
|
102
196
|
updatedAt: number;
|
|
197
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
103
198
|
}>, "many">;
|
|
104
199
|
}, "strip", z.ZodTypeAny, {
|
|
105
200
|
id: string;
|
|
@@ -112,6 +207,7 @@ declare const SearchWorkerRequestSchema: z.ZodDiscriminatedUnion<"type", [z.ZodO
|
|
|
112
207
|
path: string;
|
|
113
208
|
content: string;
|
|
114
209
|
updatedAt: number;
|
|
210
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
115
211
|
}[];
|
|
116
212
|
}, {
|
|
117
213
|
id: string;
|
|
@@ -124,6 +220,7 @@ declare const SearchWorkerRequestSchema: z.ZodDiscriminatedUnion<"type", [z.ZodO
|
|
|
124
220
|
path: string;
|
|
125
221
|
content: string;
|
|
126
222
|
updatedAt: number;
|
|
223
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
127
224
|
}[];
|
|
128
225
|
}>, z.ZodObject<{
|
|
129
226
|
id: z.ZodString;
|
|
@@ -131,6 +228,7 @@ declare const SearchWorkerRequestSchema: z.ZodDiscriminatedUnion<"type", [z.ZodO
|
|
|
131
228
|
docs: z.ZodArray<z.ZodObject<{
|
|
132
229
|
id: z.ZodString;
|
|
133
230
|
kind: z.ZodString;
|
|
231
|
+
scope: z.ZodOptional<z.ZodEnum<["active-root", "referenced-specs"]>>;
|
|
134
232
|
title: z.ZodString;
|
|
135
233
|
href: z.ZodString;
|
|
136
234
|
path: z.ZodString;
|
|
@@ -144,6 +242,7 @@ declare const SearchWorkerRequestSchema: z.ZodDiscriminatedUnion<"type", [z.ZodO
|
|
|
144
242
|
path: string;
|
|
145
243
|
content: string;
|
|
146
244
|
updatedAt: number;
|
|
245
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
147
246
|
}, {
|
|
148
247
|
id: string;
|
|
149
248
|
kind: string;
|
|
@@ -152,6 +251,7 @@ declare const SearchWorkerRequestSchema: z.ZodDiscriminatedUnion<"type", [z.ZodO
|
|
|
152
251
|
path: string;
|
|
153
252
|
content: string;
|
|
154
253
|
updatedAt: number;
|
|
254
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
155
255
|
}>, "many">;
|
|
156
256
|
}, "strip", z.ZodTypeAny, {
|
|
157
257
|
id: string;
|
|
@@ -164,6 +264,7 @@ declare const SearchWorkerRequestSchema: z.ZodDiscriminatedUnion<"type", [z.ZodO
|
|
|
164
264
|
path: string;
|
|
165
265
|
content: string;
|
|
166
266
|
updatedAt: number;
|
|
267
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
167
268
|
}[];
|
|
168
269
|
}, {
|
|
169
270
|
id: string;
|
|
@@ -176,18 +277,22 @@ declare const SearchWorkerRequestSchema: z.ZodDiscriminatedUnion<"type", [z.ZodO
|
|
|
176
277
|
path: string;
|
|
177
278
|
content: string;
|
|
178
279
|
updatedAt: number;
|
|
280
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
179
281
|
}[];
|
|
180
282
|
}>, z.ZodObject<{
|
|
181
283
|
id: z.ZodString;
|
|
182
284
|
type: z.ZodLiteral<"search">;
|
|
183
285
|
query: z.ZodObject<{
|
|
184
286
|
query: z.ZodString;
|
|
287
|
+
scope: z.ZodOptional<z.ZodEnum<["active-root", "referenced-specs"]>>;
|
|
185
288
|
limit: z.ZodOptional<z.ZodNumber>;
|
|
186
289
|
}, "strip", z.ZodTypeAny, {
|
|
187
290
|
query: string;
|
|
291
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
188
292
|
limit?: number | undefined;
|
|
189
293
|
}, {
|
|
190
294
|
query: string;
|
|
295
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
191
296
|
limit?: number | undefined;
|
|
192
297
|
}>;
|
|
193
298
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -195,6 +300,7 @@ declare const SearchWorkerRequestSchema: z.ZodDiscriminatedUnion<"type", [z.ZodO
|
|
|
195
300
|
type: "search";
|
|
196
301
|
query: {
|
|
197
302
|
query: string;
|
|
303
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
198
304
|
limit?: number | undefined;
|
|
199
305
|
};
|
|
200
306
|
}, {
|
|
@@ -202,6 +308,7 @@ declare const SearchWorkerRequestSchema: z.ZodDiscriminatedUnion<"type", [z.ZodO
|
|
|
202
308
|
type: "search";
|
|
203
309
|
query: {
|
|
204
310
|
query: string;
|
|
311
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
205
312
|
limit?: number | undefined;
|
|
206
313
|
};
|
|
207
314
|
}>, z.ZodObject<{
|
|
@@ -229,6 +336,7 @@ declare const SearchWorkerResponseSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
|
|
|
229
336
|
hits: z.ZodArray<z.ZodObject<{
|
|
230
337
|
documentId: z.ZodString;
|
|
231
338
|
kind: z.ZodString;
|
|
339
|
+
scope: z.ZodOptional<z.ZodEnum<["active-root", "referenced-specs"]>>;
|
|
232
340
|
title: z.ZodString;
|
|
233
341
|
href: z.ZodString;
|
|
234
342
|
path: z.ZodString;
|
|
@@ -244,6 +352,7 @@ declare const SearchWorkerResponseSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
|
|
|
244
352
|
documentId: string;
|
|
245
353
|
score: number;
|
|
246
354
|
snippet: string;
|
|
355
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
247
356
|
}, {
|
|
248
357
|
kind: string;
|
|
249
358
|
title: string;
|
|
@@ -253,6 +362,7 @@ declare const SearchWorkerResponseSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
|
|
|
253
362
|
documentId: string;
|
|
254
363
|
score: number;
|
|
255
364
|
snippet: string;
|
|
365
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
256
366
|
}>, "many">;
|
|
257
367
|
}, "strip", z.ZodTypeAny, {
|
|
258
368
|
id: string;
|
|
@@ -266,6 +376,7 @@ declare const SearchWorkerResponseSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
|
|
|
266
376
|
documentId: string;
|
|
267
377
|
score: number;
|
|
268
378
|
snippet: string;
|
|
379
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
269
380
|
}[];
|
|
270
381
|
}, {
|
|
271
382
|
id: string;
|
|
@@ -279,6 +390,7 @@ declare const SearchWorkerResponseSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
|
|
|
279
390
|
documentId: string;
|
|
280
391
|
score: number;
|
|
281
392
|
snippet: string;
|
|
393
|
+
scope?: "active-root" | "referenced-specs" | undefined;
|
|
282
394
|
}[];
|
|
283
395
|
}>, z.ZodObject<{
|
|
284
396
|
id: z.ZodString;
|
|
@@ -313,4 +425,4 @@ declare class WebWorkerSearchProvider implements SearchProvider {
|
|
|
313
425
|
private failPending;
|
|
314
426
|
}
|
|
315
427
|
//#endregion
|
|
316
|
-
export { type SearchDocument, type SearchDocumentInput, type SearchDocumentKind, SearchDocumentKindSchema, SearchDocumentSchema, type SearchHit, type SearchHitOutput, SearchHitSchema, type SearchIndex, type SearchIndexDocument, type SearchProvider, type SearchQuery, type SearchQueryInput, SearchQuerySchema, type SearchWorkerRequest, SearchWorkerRequestSchema, type SearchWorkerResponse, SearchWorkerResponseSchema, WebWorkerSearchProvider, buildSearchIndex, createSnippet, normalizeText, searchIndex, splitTerms };
|
|
428
|
+
export { type ProjectSearchDocument, ProjectSearchDocumentSchema, type ProjectSearchHit, ProjectSearchHitSchema, ProjectSearchQuerySchema, type ProjectSearchScope, ProjectSearchScopeSchema, type SearchDocument, type SearchDocumentInput, type SearchDocumentKind, SearchDocumentKindSchema, SearchDocumentSchema, type SearchHit, type SearchHitOutput, SearchHitSchema, type SearchIndex, type SearchIndexDocument, type SearchProvider, type SearchQuery, type SearchQueryInput, SearchQuerySchema, type SearchWorkerRequest, SearchWorkerRequestSchema, type SearchWorkerResponse, SearchWorkerResponseSchema, WebWorkerSearchProvider, buildSearchIndex, createSnippet, normalizeText, parseProjectSearchHits, searchIndex, splitTerms };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as ProjectSearchQuerySchema, c as SearchDocumentSchema, d as SearchWorkerRequestSchema, f as SearchWorkerResponseSchema, i as ProjectSearchHitSchema, l as SearchHitSchema, n as buildWebWorkerSource, o as ProjectSearchScopeSchema, p as parseProjectSearchHits, r as ProjectSearchDocumentSchema, s as SearchDocumentKindSchema, u as SearchQuerySchema } from "./worker-source-wZNAgstZ.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/engine.ts
|
|
4
4
|
const DEFAULT_LIMIT = 50;
|
|
@@ -62,10 +62,12 @@ function searchIndex(index, query) {
|
|
|
62
62
|
if (terms.length === 0) return [];
|
|
63
63
|
const hits = [];
|
|
64
64
|
for (const doc of index.documents) {
|
|
65
|
+
if (query.scope !== void 0 && doc.scope !== query.scope) continue;
|
|
65
66
|
if (!isDocumentMatch(doc, terms)) continue;
|
|
66
67
|
hits.push({
|
|
67
68
|
documentId: doc.id,
|
|
68
69
|
kind: doc.kind,
|
|
70
|
+
...doc.scope === void 0 ? {} : { scope: doc.scope },
|
|
69
71
|
title: doc.title,
|
|
70
72
|
href: doc.href,
|
|
71
73
|
path: doc.path,
|
|
@@ -178,4 +180,4 @@ var WebWorkerSearchProvider = class {
|
|
|
178
180
|
};
|
|
179
181
|
|
|
180
182
|
//#endregion
|
|
181
|
-
export { SearchDocumentKindSchema, SearchDocumentSchema, SearchHitSchema, SearchQuerySchema, SearchWorkerRequestSchema, SearchWorkerResponseSchema, WebWorkerSearchProvider, buildSearchIndex, createSnippet, normalizeText, searchIndex, splitTerms };
|
|
183
|
+
export { ProjectSearchDocumentSchema, ProjectSearchHitSchema, ProjectSearchQuerySchema, ProjectSearchScopeSchema, SearchDocumentKindSchema, SearchDocumentSchema, SearchHitSchema, SearchQuerySchema, SearchWorkerRequestSchema, SearchWorkerResponseSchema, WebWorkerSearchProvider, buildSearchIndex, createSnippet, normalizeText, parseProjectSearchHits, searchIndex, splitTerms };
|
package/dist/node.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as SearchDocument, l as SearchProvider, o as SearchHit, u as SearchQuery } from "./types-BrBOVcVY.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/node-worker-provider.d.ts
|
|
4
4
|
declare class NodeWorkerSearchProvider implements SearchProvider {
|
package/dist/node.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as SearchWorkerResponseSchema, l as SearchHitSchema, t as buildNodeWorkerSource } from "./worker-source-wZNAgstZ.mjs";
|
|
2
2
|
import { Worker } from "node:worker_threads";
|
|
3
3
|
|
|
4
4
|
//#region src/node-worker-provider.ts
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Orthogonal intents (updated 2026-07-18 Asia/Shanghai):
|
|
4
|
+
* 1. Define framework-neutral Search documents, queries, hits, indexes, and providers.
|
|
5
|
+
* 2. Keep scope optional for generic consumers and exact for project Search documents and hits.
|
|
6
|
+
*
|
|
7
|
+
* Original request (2026-07-15): "Referenced Specs are navigable and searchable but visibly read-only."
|
|
8
|
+
* Derived requirement (2026-07-18): Checkpoint 6.10 scopes Search to the active root or direct Referenced Specs.
|
|
9
|
+
*/
|
|
10
|
+
type SearchDocumentKind = string;
|
|
11
|
+
/** The two objective document sources exposed by project Search. */
|
|
12
|
+
type ProjectSearchScope = 'active-root' | 'referenced-specs';
|
|
13
|
+
/** A normalized document accepted by the shared Search index. */
|
|
14
|
+
interface SearchDocument {
|
|
15
|
+
id: string;
|
|
16
|
+
kind: SearchDocumentKind;
|
|
17
|
+
scope?: ProjectSearchScope;
|
|
18
|
+
title: string;
|
|
19
|
+
href: string;
|
|
20
|
+
path: string;
|
|
21
|
+
content: string;
|
|
22
|
+
updatedAt: number;
|
|
23
|
+
}
|
|
24
|
+
/** A project Search document whose source provenance is always explicit. */
|
|
25
|
+
interface ProjectSearchDocument extends SearchDocument {
|
|
26
|
+
scope: ProjectSearchScope;
|
|
27
|
+
}
|
|
28
|
+
/** A shared Search request; project consumers may select one source scope. */
|
|
29
|
+
interface SearchQuery {
|
|
30
|
+
query: string;
|
|
31
|
+
scope?: ProjectSearchScope;
|
|
32
|
+
limit?: number;
|
|
33
|
+
}
|
|
34
|
+
/** A Search result with the source scope preserved when supplied by the document. */
|
|
35
|
+
interface SearchHit {
|
|
36
|
+
documentId: string;
|
|
37
|
+
kind: SearchDocumentKind;
|
|
38
|
+
scope?: ProjectSearchScope;
|
|
39
|
+
title: string;
|
|
40
|
+
href: string;
|
|
41
|
+
path: string;
|
|
42
|
+
score: number;
|
|
43
|
+
snippet: string;
|
|
44
|
+
updatedAt: number;
|
|
45
|
+
}
|
|
46
|
+
/** A project Search result whose source provenance is always explicit. */
|
|
47
|
+
interface ProjectSearchHit extends SearchHit {
|
|
48
|
+
scope: ProjectSearchScope;
|
|
49
|
+
}
|
|
50
|
+
/** An asynchronous provider for a replaceable Search document collection. */
|
|
51
|
+
interface SearchProvider {
|
|
52
|
+
init(docs: SearchDocument[]): Promise<void>;
|
|
53
|
+
replaceAll(docs: SearchDocument[]): Promise<void>;
|
|
54
|
+
search(query: SearchQuery): Promise<SearchHit[]>;
|
|
55
|
+
dispose(): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
/** A Search document enriched with engine-private normalized fields. */
|
|
58
|
+
interface SearchIndexDocument extends SearchDocument {
|
|
59
|
+
normalizedTitle: string;
|
|
60
|
+
normalizedPath: string;
|
|
61
|
+
normalizedContent: string;
|
|
62
|
+
}
|
|
63
|
+
/** The immutable collection searched by the synchronous engine. */
|
|
64
|
+
interface SearchIndex {
|
|
65
|
+
documents: SearchIndexDocument[];
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { SearchDocumentKind as a, SearchIndexDocument as c, SearchDocument as i, SearchProvider as l, ProjectSearchHit as n, SearchHit as o, ProjectSearchScope as r, SearchIndex as s, ProjectSearchDocument as t, SearchQuery as u };
|
|
@@ -1,23 +1,40 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
|
|
3
3
|
//#region src/protocol.ts
|
|
4
|
+
/**
|
|
5
|
+
* Orthogonal intents (updated 2026-07-18 Asia/Shanghai):
|
|
6
|
+
* 1. Validate Search document, query, hit, and worker message boundaries.
|
|
7
|
+
* 2. Define the defaulted project Search source contract.
|
|
8
|
+
*
|
|
9
|
+
* Original request (2026-07-15): "Referenced Specs are navigable and searchable but visibly read-only."
|
|
10
|
+
* Derived requirement (2026-07-18): Checkpoint 6.10 scopes Search to the active root or direct Referenced Specs.
|
|
11
|
+
*/
|
|
4
12
|
const SearchDocumentKindSchema = z.string().min(1);
|
|
13
|
+
/** The source scopes supported by one project workspace's Search surface. */
|
|
14
|
+
const ProjectSearchScopeSchema = z.enum(["active-root", "referenced-specs"]);
|
|
5
15
|
const SearchDocumentSchema = z.object({
|
|
6
16
|
id: z.string(),
|
|
7
17
|
kind: SearchDocumentKindSchema,
|
|
18
|
+
scope: ProjectSearchScopeSchema.optional(),
|
|
8
19
|
title: z.string(),
|
|
9
20
|
href: z.string(),
|
|
10
21
|
path: z.string(),
|
|
11
22
|
content: z.string(),
|
|
12
23
|
updatedAt: z.number()
|
|
13
24
|
});
|
|
25
|
+
/** Runtime validator for a source-attributed project Search document. */
|
|
26
|
+
const ProjectSearchDocumentSchema = SearchDocumentSchema.extend({ scope: ProjectSearchScopeSchema });
|
|
14
27
|
const SearchQuerySchema = z.object({
|
|
15
28
|
query: z.string(),
|
|
29
|
+
scope: ProjectSearchScopeSchema.optional(),
|
|
16
30
|
limit: z.number().int().positive().optional()
|
|
17
31
|
});
|
|
32
|
+
/** A project Search request normalized to the writable Planning-root source by default. */
|
|
33
|
+
const ProjectSearchQuerySchema = SearchQuerySchema.extend({ scope: ProjectSearchScopeSchema.default("active-root") });
|
|
18
34
|
const SearchHitSchema = z.object({
|
|
19
35
|
documentId: z.string(),
|
|
20
36
|
kind: SearchDocumentKindSchema,
|
|
37
|
+
scope: ProjectSearchScopeSchema.optional(),
|
|
21
38
|
title: z.string(),
|
|
22
39
|
href: z.string(),
|
|
23
40
|
path: z.string(),
|
|
@@ -25,6 +42,15 @@ const SearchHitSchema = z.object({
|
|
|
25
42
|
snippet: z.string(),
|
|
26
43
|
updatedAt: z.number()
|
|
27
44
|
});
|
|
45
|
+
/** Runtime validator for a source-attributed project Search result. */
|
|
46
|
+
const ProjectSearchHitSchema = SearchHitSchema.extend({ scope: ProjectSearchScopeSchema });
|
|
47
|
+
/** Validate project hits and reject provenance that differs from the selected source. */
|
|
48
|
+
function parseProjectSearchHits(input, expectedScope) {
|
|
49
|
+
const hits = ProjectSearchHitSchema.array().parse(input);
|
|
50
|
+
const mismatchedHit = hits.find((hit) => hit.scope !== expectedScope);
|
|
51
|
+
if (mismatchedHit) throw new Error(`Project Search hit "${mismatchedHit.documentId}" has scope "${mismatchedHit.scope}"; expected "${expectedScope}".`);
|
|
52
|
+
return hits;
|
|
53
|
+
}
|
|
28
54
|
const SearchWorkerRequestSchema = z.discriminatedUnion("type", [
|
|
29
55
|
z.object({
|
|
30
56
|
id: z.string(),
|
|
@@ -65,6 +91,14 @@ const SearchWorkerResponseSchema = z.discriminatedUnion("type", [
|
|
|
65
91
|
|
|
66
92
|
//#endregion
|
|
67
93
|
//#region src/worker-source.ts
|
|
94
|
+
/**
|
|
95
|
+
* Orthogonal intents (updated 2026-07-18 Asia/Shanghai):
|
|
96
|
+
* 1. Generate equivalent browser and Node Search worker runtimes.
|
|
97
|
+
* 2. Preserve source filtering and provenance without runtime package imports.
|
|
98
|
+
*
|
|
99
|
+
* Original request (2026-07-15): "Referenced Specs are navigable and searchable but visibly read-only."
|
|
100
|
+
* Derived requirement (2026-07-18): Checkpoint 6.10 scopes Search to the active root or direct Referenced Specs.
|
|
101
|
+
*/
|
|
68
102
|
const sharedRuntimeSource = String.raw`
|
|
69
103
|
const DEFAULT_LIMIT = 50;
|
|
70
104
|
const MAX_LIMIT = 200;
|
|
@@ -88,6 +122,7 @@ function toSearchIndexDocument(doc) {
|
|
|
88
122
|
return {
|
|
89
123
|
id: doc.id,
|
|
90
124
|
kind: doc.kind,
|
|
125
|
+
scope: doc.scope,
|
|
91
126
|
title: doc.title,
|
|
92
127
|
href: doc.href,
|
|
93
128
|
path: doc.path,
|
|
@@ -169,9 +204,10 @@ function searchIndex(index, query) {
|
|
|
169
204
|
const hits = [];
|
|
170
205
|
|
|
171
206
|
for (const doc of index.documents) {
|
|
207
|
+
if (query && query.scope !== undefined && doc.scope !== query.scope) continue;
|
|
172
208
|
if (!isDocumentMatch(doc, terms)) continue;
|
|
173
209
|
|
|
174
|
-
|
|
210
|
+
const hit = {
|
|
175
211
|
documentId: doc.id,
|
|
176
212
|
kind: doc.kind,
|
|
177
213
|
title: doc.title,
|
|
@@ -180,7 +216,9 @@ function searchIndex(index, query) {
|
|
|
180
216
|
score: scoreDocument(doc, terms),
|
|
181
217
|
snippet: createSnippet(doc.content, terms),
|
|
182
218
|
updatedAt: doc.updatedAt,
|
|
183
|
-
}
|
|
219
|
+
};
|
|
220
|
+
if (doc.scope !== undefined) hit.scope = doc.scope;
|
|
221
|
+
hits.push(hit);
|
|
184
222
|
}
|
|
185
223
|
|
|
186
224
|
hits.sort((a, b) => {
|
|
@@ -229,4 +267,4 @@ function buildNodeWorkerSource() {
|
|
|
229
267
|
}
|
|
230
268
|
|
|
231
269
|
//#endregion
|
|
232
|
-
export {
|
|
270
|
+
export { ProjectSearchQuerySchema as a, SearchDocumentSchema as c, SearchWorkerRequestSchema as d, SearchWorkerResponseSchema as f, ProjectSearchHitSchema as i, SearchHitSchema as l, buildWebWorkerSource as n, ProjectSearchScopeSchema as o, parseProjectSearchHits as p, ProjectSearchDocumentSchema as r, SearchDocumentKindSchema as s, buildNodeWorkerSource as t, SearchQuerySchema as u };
|
package/package.json
CHANGED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
//#region src/types.d.ts
|
|
2
|
-
type SearchDocumentKind = string;
|
|
3
|
-
interface SearchDocument {
|
|
4
|
-
id: string;
|
|
5
|
-
kind: SearchDocumentKind;
|
|
6
|
-
title: string;
|
|
7
|
-
href: string;
|
|
8
|
-
path: string;
|
|
9
|
-
content: string;
|
|
10
|
-
updatedAt: number;
|
|
11
|
-
}
|
|
12
|
-
interface SearchQuery {
|
|
13
|
-
query: string;
|
|
14
|
-
limit?: number;
|
|
15
|
-
}
|
|
16
|
-
interface SearchHit {
|
|
17
|
-
documentId: string;
|
|
18
|
-
kind: SearchDocumentKind;
|
|
19
|
-
title: string;
|
|
20
|
-
href: string;
|
|
21
|
-
path: string;
|
|
22
|
-
score: number;
|
|
23
|
-
snippet: string;
|
|
24
|
-
updatedAt: number;
|
|
25
|
-
}
|
|
26
|
-
interface SearchProvider {
|
|
27
|
-
init(docs: SearchDocument[]): Promise<void>;
|
|
28
|
-
replaceAll(docs: SearchDocument[]): Promise<void>;
|
|
29
|
-
search(query: SearchQuery): Promise<SearchHit[]>;
|
|
30
|
-
dispose(): Promise<void>;
|
|
31
|
-
}
|
|
32
|
-
interface SearchIndexDocument extends SearchDocument {
|
|
33
|
-
normalizedTitle: string;
|
|
34
|
-
normalizedPath: string;
|
|
35
|
-
normalizedContent: string;
|
|
36
|
-
}
|
|
37
|
-
interface SearchIndex {
|
|
38
|
-
documents: SearchIndexDocument[];
|
|
39
|
-
}
|
|
40
|
-
//#endregion
|
|
41
|
-
export { SearchIndexDocument as a, SearchIndex as i, SearchDocumentKind as n, SearchProvider as o, SearchHit as r, SearchQuery as s, SearchDocument as t };
|