@dsh-gis/dsh-opengis-skill 0.4.0 → 0.5.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +53 -8
  3. package/adaptations/brutile.md +19 -6
  4. package/adaptations/cesiumjs.md +14 -5
  5. package/adaptations/common.md +49 -20
  6. package/adaptations/deck-gl.md +19 -6
  7. package/adaptations/duckdb-spatial.md +20 -6
  8. package/adaptations/gdal-api.md +24 -6
  9. package/adaptations/gdal.md +22 -6
  10. package/adaptations/geolibre.md +20 -6
  11. package/adaptations/geometry-api-java.md +14 -6
  12. package/adaptations/geometry-api-net.md +17 -6
  13. package/adaptations/geonode.md +17 -6
  14. package/adaptations/geopandas.md +21 -6
  15. package/adaptations/geopipe-agent.md +21 -6
  16. package/adaptations/geos.md +21 -6
  17. package/adaptations/geoserver-cloud.md +17 -6
  18. package/adaptations/geoserver-rest-api.md +17 -6
  19. package/adaptations/geoserver.md +18 -6
  20. package/adaptations/geotools.md +19 -6
  21. package/adaptations/grass-gis.md +24 -6
  22. package/adaptations/jts.md +18 -6
  23. package/adaptations/kepler-gl.md +18 -5
  24. package/adaptations/leaflet.md +25 -6
  25. package/adaptations/mapbox-gl-js.md +23 -6
  26. package/adaptations/maplibre-gl-js.md +18 -6
  27. package/adaptations/maplibre-native.md +17 -6
  28. package/adaptations/mapserver.md +22 -6
  29. package/adaptations/mapsui.md +22 -6
  30. package/adaptations/nettopologysuite.md +19 -6
  31. package/adaptations/opendronemap.md +19 -6
  32. package/adaptations/opengis-all.md +16 -5
  33. package/adaptations/opengis-daf.md +16 -5
  34. package/adaptations/opengis-utils-for-java.md +20 -6
  35. package/adaptations/opengis-utils-for-net.md +23 -6
  36. package/adaptations/openlayers.md +20 -6
  37. package/adaptations/pdal.md +26 -6
  38. package/adaptations/postgis.md +20 -6
  39. package/adaptations/proj.md +20 -6
  40. package/adaptations/projnet4geoapi.md +21 -6
  41. package/adaptations/pyqgis.md +18 -6
  42. package/adaptations/qgis-process.md +21 -6
  43. package/adaptations/qgis-server.md +18 -6
  44. package/adaptations/shapely.md +22 -6
  45. package/adaptations/sharpmap.md +19 -6
  46. package/adaptations/spatialite.md +23 -6
  47. package/adaptations/stac-cog-titiler.md +21 -6
  48. package/adaptations/whitebox-tools.md +19 -6
  49. package/lib/adaptations.d.ts +9 -0
  50. package/lib/adaptations.js +64 -0
  51. package/lib/index.d.ts +13 -9
  52. package/lib/index.js +32 -12
  53. package/lib/taxonomy.d.ts +41 -0
  54. package/lib/taxonomy.js +332 -0
  55. package/package.json +3 -2
package/lib/index.js CHANGED
@@ -11,6 +11,16 @@
11
11
  * guidance lives outside them: "adaptations/<skill>.md" plus the shared
12
12
  * "adaptations/common.md" are appended when a skill is loaded.
13
13
  *
14
+ * Three catalog layers stay outside the vendored snapshot on purpose:
15
+ *
16
+ * - "lib/taxonomy.js" maps each skill to coarse groups and to the Chinese
17
+ * trigger phrases a request actually uses, and the provider exposes both on
18
+ * the candidate metadata.
19
+ * - The plugin config ("groups", "skills", "exclude") trims the catalog per
20
+ * bundle configuration, so a browser-map session never pays for the server
21
+ * and database skills.
22
+ * - Loading appends the DSH guidance, so the upstream body stays byte-identical.
23
+ *
14
24
  * @module @dsh-gis/dsh-opengis-skill
15
25
  */
16
26
 
@@ -19,6 +29,7 @@ import { fileURLToPath } from "node:url";
19
29
  import { composeSkillContent, readAdaptation, readCommon } from "./adaptations.js";
20
30
  import { readSkillCatalog, resourceBaseOf } from "./catalog.js";
21
31
  import { parseSkillFile } from "./skill-file.js";
32
+ import { groupsOf, keywordsOf, normalizeSelection, selectSkills } from "./taxonomy.js";
22
33
 
23
34
  /** Provider name registered on "ctx.skills" (the runtime name "runtime" is reserved). */
24
35
  const PROVIDER_NAME = "opengis";
@@ -71,18 +82,23 @@ function sharedGuidance() {
71
82
  }
72
83
 
73
84
  /**
74
- * Build the candidate metadata from the parsed upstream frontmatter.
85
+ * Build the candidate metadata from the upstream frontmatter plus the local
86
+ * taxonomy.
75
87
  *
76
88
  * "category" is omitted when upstream does not declare one, so consumers never
77
- * see an explicit undefined; "tags" is always an array so a consumer can map
78
- * over it without a guard.
89
+ * see an explicit undefined; "tags", "groups" and "keywords" are always arrays
90
+ * so a consumer can map over them without a guard. "groups" and "keywords" are
91
+ * local additions: upstream carries neither, and a host that does not know them
92
+ * simply ignores the keys.
79
93
  *
80
- * @param metadata - the parsed frontmatter metadata, when the skill has any.
94
+ * @param skill - the parsed catalog entry.
81
95
  * @returns the metadata object carried on the candidate.
82
96
  */
83
- function candidateMetadata(metadata) {
84
- const tags = Array.isArray(metadata?.tags) ? metadata.tags : [];
85
- return metadata?.category === undefined ? { tags } : { category: metadata.category, tags };
97
+ function candidateMetadata(skill) {
98
+ const tags = Array.isArray(skill.metadata?.tags) ? skill.metadata.tags : [];
99
+ const metadata = { tags, groups: groupsOf(skill.name), keywords: keywordsOf(skill.name) };
100
+ if (skill.metadata?.category !== undefined) metadata.category = skill.metadata.category;
101
+ return metadata;
86
102
  }
87
103
 
88
104
  /**
@@ -107,11 +123,15 @@ function loadSkills() {
107
123
  * so plugin unload removes the provider without an extra "ctx.effect" wrapper.
108
124
  *
109
125
  * @param ctx - Cordis context carrying the skill registry.
126
+ * @param config - optional plugin config: "groups" (string[]), "skills"
127
+ * (string[] allow list) and "exclude" (string[] deny list). Unknown names are
128
+ * rejected so a typo cannot silently return the wrong catalog.
110
129
  */
111
- function apply(ctx) {
130
+ function apply(ctx, config) {
112
131
  const skills = loadSkills();
113
- const byName = new Map(skills.map((skill) => [skill.name, skill]));
114
- const candidates = skills.map((skill) => ({
132
+ const visible = selectSkills(skills, normalizeSelection(config, skills));
133
+ const byName = new Map(visible.map((skill) => [skill.name, skill]));
134
+ const candidates = visible.map((skill) => ({
115
135
  name: skill.name,
116
136
  description: skill.description,
117
137
  invocation: { ...INVOCATION },
@@ -124,7 +144,7 @@ function apply(ctx) {
124
144
  // The registry keeps upstream routing metadata on the candidate only;
125
145
  // a definition is a summary and must not carry it. Absent values are
126
146
  // omitted rather than emitted as undefined keys.
127
- metadata: candidateMetadata(skill.metadata)
147
+ metadata: candidateMetadata(skill)
128
148
  }));
129
149
  const provider = {
130
150
  name: PROVIDER_NAME,
@@ -161,4 +181,4 @@ function apply(ctx) {
161
181
  ctx.skills.registerProvider(() => provider);
162
182
  }
163
183
 
164
- export { apply, inject, name };
184
+ export { apply, inject, name };
@@ -0,0 +1,41 @@
1
+ /** The coarse groups a plugin config may select from. */
2
+ export declare const GROUP_IDS: readonly string[];
3
+
4
+ /** One-line description of every group. */
5
+ export declare const GROUP_DESCRIPTIONS: Readonly<Record<string, string>>;
6
+
7
+ /** The groups one skill belongs to. */
8
+ export declare function groupsOf(name: string): string[];
9
+
10
+ /** The trigger keywords of one skill. */
11
+ export declare function keywordsOf(name: string): string[];
12
+
13
+ /** One routing score for one skill. */
14
+ export interface OpenGisRoutingScore {
15
+ /** Kebab-case skill name. */
16
+ name: string;
17
+ /** Weighted hits: 3 per keyword match, 1 per description token match. */
18
+ score: number;
19
+ }
20
+
21
+ /** Score every catalog entry against one lowercased request. */
22
+ export declare function keywordScores(skills: readonly { name: string; description?: string }[], query: string): OpenGisRoutingScore[];
23
+
24
+ /** Report taxonomy entries that disagree with the catalog. */
25
+ export declare function taxonomyProblems(names: readonly string[]): string[];
26
+
27
+ /** The normalized plugin selection. */
28
+ export interface OpenGisSkillSelection {
29
+ /** Groups to union; ignored when "only" is non-empty. */
30
+ groups: string[];
31
+ /** Explicit skill allow list; wins over "groups". */
32
+ only: string[];
33
+ /** Skill deny list, applied last. */
34
+ exclude: string[];
35
+ }
36
+
37
+ /** Validate and normalize the raw plugin config. */
38
+ export declare function normalizeSelection(config: unknown, skills: readonly { name: string }[]): OpenGisSkillSelection;
39
+
40
+ /** Apply one selection to the catalog, keeping the catalog order. */
41
+ export declare function selectSkills<T extends { name: string }>(skills: readonly T[], selection: OpenGisSkillSelection): T[];
@@ -0,0 +1,332 @@
1
+ /**
2
+ * Catalog taxonomy for the bundled GIS skills: the groups a session can filter
3
+ * on and the local trigger keywords that make an English description reachable
4
+ * from a Chinese request.
5
+ *
6
+ * Upstream frontmatter stays the single source of truth for *what* a skill
7
+ * covers. This module only carries two things the vendored snapshot cannot
8
+ * express without breaking byte-identity with the upstream git blob:
9
+ *
10
+ * - "GROUPS" a coarse, deployment-shaped partition. A session that only builds
11
+ * browser maps can hide the GeoServer and PostGIS skills without editing the
12
+ * package, which keeps the session catalog small.
13
+ * - "KEYWORDS" short phrases, mostly Chinese, that a user actually types. The
14
+ * upstream descriptions are English "Use when ..." sentences, so a Chinese
15
+ * request reaches the right skill only through the model's own translation.
16
+ * Keywords remove that hop: the provider exposes them on the candidate
17
+ * metadata and the routing test scores candidate matches against them.
18
+ *
19
+ * Keywords are matched as substrings, so they must be short and phrased the way
20
+ * a request phrases them ("点云滤波", not "滤波处理能力"). Overlap between two
21
+ * skills is expected and allowed; discrimination comes from the number of hits.
22
+ *
23
+ * @module @dsh-gis/dsh-opengis-skill/taxonomy
24
+ */
25
+
26
+ /** The coarse groups a plugin config may select from. */
27
+ export const GROUP_IDS = Object.freeze([
28
+ "desktop",
29
+ "server",
30
+ "data",
31
+ "geometry",
32
+ "web",
33
+ "dotnet",
34
+ "java",
35
+ "pipeline",
36
+ "meta"
37
+ ]);
38
+
39
+ /** One-line description of every group, used in diagnostics and docs. */
40
+ export const GROUP_DESCRIPTIONS = Object.freeze({
41
+ desktop: "QGIS 桌面与桌面端应用",
42
+ server: "服务端发布、目录与 OGC 服务",
43
+ data: "数据读写、栅格与矢量处理、空间数据库",
44
+ geometry: "几何算法与几何库",
45
+ web: "Web / 3D 前端可视化与地图控件",
46
+ dotnet: ".NET 技术栈专用的 GIS 库",
47
+ java: "Java 技术栈专用的 GIS 库",
48
+ pipeline: "流程编排、自动化管线与无人机重建",
49
+ meta: "跨技能的索引与流程总览"
50
+ });
51
+
52
+ /**
53
+ * Group membership per skill. A skill may belong to several groups; filtering
54
+ * unions the selected groups.
55
+ */
56
+ const SKILL_GROUPS = Object.freeze({
57
+ brutile: ["web", "dotnet"],
58
+ cesiumjs: ["web"],
59
+ "deck-gl": ["web"],
60
+ "duckdb-spatial": ["data"],
61
+ gdal: ["data"],
62
+ "gdal-api": ["data"],
63
+ geolibre: ["desktop", "web"],
64
+ "geometry-api-java": ["geometry", "java"],
65
+ "geometry-api-net": ["geometry", "dotnet"],
66
+ geonode: ["server"],
67
+ geopandas: ["data"],
68
+ "geopipe-agent": ["pipeline"],
69
+ geos: ["geometry"],
70
+ geoserver: ["server"],
71
+ "geoserver-cloud": ["server"],
72
+ "geoserver-rest-api": ["server"],
73
+ geotools: ["geometry", "java"],
74
+ "grass-gis": ["data"],
75
+ jts: ["geometry", "java"],
76
+ "kepler-gl": ["web"],
77
+ leaflet: ["web"],
78
+ "mapbox-gl-js": ["web"],
79
+ "maplibre-gl-js": ["web"],
80
+ "maplibre-native": ["web"],
81
+ mapserver: ["server"],
82
+ mapsui: ["dotnet"],
83
+ nettopologysuite: ["geometry", "dotnet"],
84
+ opendronemap: ["pipeline"],
85
+ "opengis-all": ["meta"],
86
+ "opengis-daf": ["pipeline"],
87
+ "opengis-utils-for-java": ["geometry", "java"],
88
+ "opengis-utils-for-net": ["geometry", "dotnet"],
89
+ openlayers: ["web"],
90
+ pdal: ["data"],
91
+ postgis: ["data"],
92
+ proj: ["data"],
93
+ projnet4geoapi: ["geometry", "dotnet"],
94
+ pyqgis: ["desktop"],
95
+ "qgis-process": ["desktop"],
96
+ "qgis-server": ["server"],
97
+ shapely: ["geometry"],
98
+ sharpmap: ["dotnet"],
99
+ spatialite: ["data"],
100
+ "stac-cog-titiler": ["data", "server"],
101
+ "whitebox-tools": ["data"]
102
+ });
103
+
104
+ /**
105
+ * Trigger phrases per skill, in the wording a request uses. English product
106
+ * names and acronyms are included where a Chinese request would keep them.
107
+ */
108
+ const SKILL_KEYWORDS = Object.freeze({
109
+ brutile: ["瓦片", "底图", "切片方案", "MBTiles", "离线地图"],
110
+ cesiumjs: ["三维地球", "3D Tiles", "倾斜摄影", "CZML", "模型贴地"],
111
+ "deck-gl": ["大数据可视化", "六边形聚合", "WebGL 图层", "轨迹热力"],
112
+ "duckdb-spatial": ["DuckDB", "Parquet", "列式分析", "空间函数"],
113
+ gdal: ["格式转换", "重投影", "镶嵌", "栅格裁剪", "重采样", "COG"],
114
+ "gdal-api": ["GDAL 绑定", "Python 绑定", "驱动注册", "异常处理"],
115
+ geolibre: ["GeoLibre", "桌面应用", "本地项目"],
116
+ "geometry-api-java": ["Esri 几何", "GeometryEngine", "Java 几何"],
117
+ "geometry-api-net": ["Esri 几何", "反序列化几何", "WKB", "GeoJSON 转几何"],
118
+ geonode: ["GeoNode", "元数据", "数据目录"],
119
+ geopandas: ["GeoDataFrame", "空间连接", "叠加分析", "出图"],
120
+ "geopipe-agent": ["GeoPipeAgent", "YAML 流程", "管线编排"],
121
+ geos: ["GEOS", "拓扑异常", "叠加失败", "C 接口"],
122
+ geoserver: ["GeoServer", "WMS", "WFS", "图层发布", "样式配置"],
123
+ "geoserver-cloud": ["微服务", "集群部署", "Kubernetes"],
124
+ "geoserver-rest-api": ["REST 发布", "批量建图层", "自动化发布"],
125
+ geotools: ["GeoTools", "要素读取", "渲染出图"],
126
+ "grass-gis": ["GRASS", "区域设置", "流域分析", "栅格代数"],
127
+ jts: ["JTS", "空间关系判断", "精度问题"],
128
+ "kepler-gl": ["Kepler.gl", "时空可视化", "出行轨迹"],
129
+ leaflet: ["Leaflet", "网页地图", "标记弹窗"],
130
+ "mapbox-gl-js": ["Mapbox", "样式表达式", "矢量瓦片渲染", "三维建筑"],
131
+ "maplibre-gl-js": ["MapLibre", "免密钥", "地形夸张"],
132
+ "maplibre-native": ["移动端地图", "离线地图包", "Android 地图"],
133
+ mapserver: ["MapServer", "mapfile", "地图服务发布"],
134
+ mapsui: ["Mapsui", "WPF 地图", "MAUI 地图"],
135
+ nettopologysuite: ["NetTopologySuite", "NTS", "EF Core 空间"],
136
+ opendronemap: ["无人机", "正射影像", "三维重建", "空三"],
137
+ "opengis-all": ["全流程", "技术选型", "链路串联"],
138
+ "opengis-daf": ["OpenGisDAF", "JSON 计划", "DAG 执行"],
139
+ "opengis-utils-for-java": ["OGU4J", "CGCS2000", "拓扑校验"],
140
+ "opengis-utils-for-net": ["OguLayerUtil", "格式互转", "GBK 乱码"],
141
+ openlayers: ["OpenLayers", "前端地图", "绘制编辑"],
142
+ pdal: ["点云滤波", "LAS", "地面分类", "PDAL"],
143
+ postgis: ["PostGIS", "空间数据库", "空间索引", "几何字段"],
144
+ proj: ["PROJ", "坐标转换", "投影参数", "EPSG"],
145
+ projnet4geoapi: ["ProjNet", "坐标转换", "EPSG 解析"],
146
+ pyqgis: ["PyQGIS", "QGIS 脚本", "图层自动化"],
147
+ "qgis-process": ["qgis_process", "命令行算法", "无界面运行"],
148
+ "qgis-server": ["QGIS Server", "fcgi", "服务参数调优"],
149
+ shapely: ["Shapely", "缓冲区", "相交判断", "有效性修复"],
150
+ sharpmap: ["SharpMap", "WinForms 地图", "专题渲染"],
151
+ spatialite: ["SpatiaLite", "SQLite", "空间 SQL"],
152
+ "stac-cog-titiler": ["STAC", "TiTiler", "动态切片", "影像编目", "云优化影像"],
153
+ "whitebox-tools": ["WhiteboxTools", "洼地填充", "汇流累积", "地形指数"]
154
+ });
155
+
156
+ /**
157
+ * Score every catalog entry against one lowercased request.
158
+ *
159
+ * Two signals, both taken from what the provider actually exposes:
160
+ *
161
+ * - A keyword hit is worth three points, because the keywords are written in
162
+ * request wording and are the strongest evidence available.
163
+ * - A Latin token of the description is worth one point. Product names and
164
+ * acronyms (GDAL, PostGIS, MapLibre) survive a Chinese request untouched, so
165
+ * they separate neighbouring skills the keywords alone cannot.
166
+ *
167
+ * Description tokens shorter than three characters and pure numbers are
168
+ * ignored: they match too much and carry no routing signal.
169
+ *
170
+ * @param skills - the catalog entries; a description is optional but improves
171
+ * scoring when present.
172
+ * @param query - the request text, already lowercased.
173
+ * @returns one { name, score } entry per skill, in catalog order.
174
+ */
175
+ export function keywordScores(skills, query) {
176
+ return skills.map((skill) => {
177
+ let score = 0;
178
+ for (const keyword of keywordsOf(skill.name)) {
179
+ if (query.includes(keyword.toLowerCase())) score += 3;
180
+ }
181
+ for (const token of descriptionTokens(skill.description)) {
182
+ if (query.includes(token)) score += 1;
183
+ }
184
+ return { name: skill.name, score };
185
+ });
186
+ }
187
+
188
+ /**
189
+ * Extract the Latin tokens of one description.
190
+ *
191
+ * Short tokens and pure numbers are dropped: they match too much ("use", "id")
192
+ * or carry no routing signal, and a two-character token would fire on every
193
+ * version string in a request.
194
+ *
195
+ * @param description - the upstream description, when known.
196
+ * @returns the lowercased tokens, deduplicated.
197
+ */
198
+ function descriptionTokens(description) {
199
+ if (typeof description !== "string") return [];
200
+ const tokens = new Set();
201
+ for (const match of description.toLowerCase().matchAll(/[a-z][a-z0-9+#.-]{2,}/gu)) {
202
+ if (/^\d+$/u.test(match[0])) continue;
203
+ tokens.add(match[0]);
204
+ }
205
+ return [...tokens];
206
+ }
207
+
208
+ /**
209
+ * The groups one skill belongs to.
210
+ *
211
+ * @param name - kebab-case skill name.
212
+ * @returns the group ids, empty when the taxonomy has no entry.
213
+ */
214
+ export function groupsOf(name) {
215
+ const groups = SKILL_GROUPS[name];
216
+ return groups === undefined ? [] : [...groups];
217
+ }
218
+
219
+ /**
220
+ * The trigger keywords of one skill.
221
+ *
222
+ * @param name - kebab-case skill name.
223
+ * @returns the keywords, empty when the taxonomy has no entry.
224
+ */
225
+ export function keywordsOf(name) {
226
+ const keywords = SKILL_KEYWORDS[name];
227
+ return keywords === undefined ? [] : [...keywords];
228
+ }
229
+
230
+ /**
231
+ * Report every skill the taxonomy does not describe, and every key it describes
232
+ * that the catalog does not ship.
233
+ *
234
+ * @param names - the catalog skill names.
235
+ * @returns human-readable problems, empty when the taxonomy matches the catalog.
236
+ */
237
+ export function taxonomyProblems(names) {
238
+ const problems = [];
239
+ const catalog = new Set(names);
240
+ for (const name of names) {
241
+ if (groupsOf(name).length === 0) problems.push("lib/taxonomy.js: \"" + name + "\" has no group; add it to SKILL_GROUPS");
242
+ if (keywordsOf(name).length < 3) problems.push("lib/taxonomy.js: \"" + name + "\" has fewer than 3 keywords; add trigger phrases to SKILL_KEYWORDS");
243
+ }
244
+ for (const name of Object.keys(SKILL_GROUPS)) {
245
+ if (!catalog.has(name)) problems.push("lib/taxonomy.js: SKILL_GROUPS names \"" + name + "\", which is not a bundled skill");
246
+ for (const group of SKILL_GROUPS[name]) {
247
+ if (!GROUP_IDS.includes(group)) problems.push("lib/taxonomy.js: \"" + name + "\" lists unknown group \"" + group + "\"");
248
+ }
249
+ }
250
+ for (const name of Object.keys(SKILL_KEYWORDS)) {
251
+ if (!catalog.has(name)) problems.push("lib/taxonomy.js: SKILL_KEYWORDS names \"" + name + "\", which is not a bundled skill");
252
+ const seen = new Set();
253
+ for (const keyword of SKILL_KEYWORDS[name]) {
254
+ if (keyword.trim().length === 0) problems.push("lib/taxonomy.js: \"" + name + "\" carries an empty keyword");
255
+ if (seen.has(keyword)) problems.push("lib/taxonomy.js: \"" + name + "\" repeats the keyword \"" + keyword + "\"");
256
+ seen.add(keyword);
257
+ }
258
+ }
259
+ for (const group of GROUP_IDS) {
260
+ if (!Object.values(SKILL_GROUPS).some((groups) => groups.includes(group))) problems.push("lib/taxonomy.js: group \"" + group + "\" has no members");
261
+ }
262
+ return problems;
263
+ }
264
+
265
+ /**
266
+ * Read one optional string list from the plugin config.
267
+ *
268
+ * @param config - the raw plugin config, possibly undefined.
269
+ * @param key - the field to read.
270
+ * @returns the list, empty when the field is absent.
271
+ * @throws when the field is present but is not an array of non-empty strings.
272
+ */
273
+ function readList(config, key) {
274
+ const value = config?.[key];
275
+ if (value === undefined) return [];
276
+ if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string" || entry.length === 0)) {
277
+ throw new Error('opengis-skill: plugin config field "' + key + '" must be an array of non-empty strings');
278
+ }
279
+ return [...value];
280
+ }
281
+
282
+ /**
283
+ * Validate and normalize the plugin config into a selection.
284
+ *
285
+ * The three fields compose as: "skills" wins over "groups" when both are given,
286
+ * and "exclude" is always applied last. Unknown group ids and unknown skill
287
+ * names are rejected instead of being silently ignored, because a typo in a
288
+ * filter silently returns the wrong catalog.
289
+ *
290
+ * @param config - the raw plugin config, possibly undefined.
291
+ * @param skills - the catalog entries the plugin loaded.
292
+ * @returns the normalized selection.
293
+ * @throws when a field is malformed or names an unknown group or skill.
294
+ */
295
+ export function normalizeSelection(config, skills) {
296
+ const available = new Set(skills.map((skill) => skill.name));
297
+ const groups = readList(config, "groups");
298
+ const only = readList(config, "skills");
299
+ const exclude = readList(config, "exclude");
300
+ for (const group of groups) {
301
+ if (!GROUP_IDS.includes(group)) {
302
+ throw new Error('opengis-skill: unknown group "' + group + '"; valid groups are ' + GROUP_IDS.join(", "));
303
+ }
304
+ }
305
+ for (const name of [...only, ...exclude]) {
306
+ if (!available.has(name)) throw new Error('opengis-skill: unknown skill "' + name + '" in the plugin config; the catalog ships ' + skills.length + " skills");
307
+ }
308
+ return { groups, only, exclude };
309
+ }
310
+
311
+ /**
312
+ * Apply one selection to the catalog, keeping the catalog order.
313
+ *
314
+ * @param skills - the catalog entries the plugin loaded.
315
+ * @param selection - the normalized selection.
316
+ * @returns the visible catalog entries.
317
+ * @throws when the selection hides every skill.
318
+ */
319
+ export function selectSkills(skills, selection) {
320
+ const wanted = new Set(selection.only);
321
+ const excluded = new Set(selection.exclude);
322
+ const selected = skills.filter((skill) => {
323
+ if (excluded.has(skill.name)) return false;
324
+ if (wanted.size > 0) return wanted.has(skill.name);
325
+ if (selection.groups.length === 0) return true;
326
+ return groupsOf(skill.name).some((group) => selection.groups.includes(group));
327
+ });
328
+ if (selected.length === 0) {
329
+ throw new Error("opengis-skill: the plugin config selects no skill; widen \"groups\" or drop \"exclude\"");
330
+ }
331
+ return selected;
332
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-gis/dsh-opengis-skill",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "OpenGIS skill pack for DeepSeek Harness: the 45 gis/ skills from opengis-skills, vendored byte-for-byte and loaded on demand, plus a DeepSeek Harness execution layer (tool mapping, background jobs, verification, consent, upstream routing metadata) appended at load time.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -47,8 +47,9 @@
47
47
  "sync:check": "node scripts/sync-opengis-skills.mjs --check",
48
48
  "validate": "node scripts/validate-skills.mjs",
49
49
  "check:adaptations": "node scripts/check-adaptations.mjs",
50
+ "check:citations": "node scripts/check-citations.mjs",
50
51
  "test": "node --test",
51
- "check": "npm run validate && npm test",
52
+ "check": "npm run validate && npm run check:citations && npm test",
52
53
  "prepublishOnly": "npm run check"
53
54
  },
54
55
  "repository": {