@blueking/bkui-knowledge 0.0.1-beta.6 → 0.0.1-beta.8

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 (28) hide show
  1. package/README.md +32 -0
  2. package/bin/bkui-knowledge.js +60 -1
  3. package/knowledge/manifest.json +10 -1
  4. package/knowledge/skills/bkui-quick-start/SKILL.md +21 -37
  5. package/knowledge/skills/bkui-quick-start/references/components-list.md +17 -0
  6. package/knowledge/skills/bkui-quick-start/references/skills-index.md +26 -0
  7. package/knowledge/skills/external/vue-skills/LICENSE +21 -0
  8. package/knowledge/skills/external/vue-skills/README.md +69 -0
  9. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/SKILL.md +42 -0
  10. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/codeactions-save-performance.md +79 -0
  11. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/data-attributes-config.md +74 -0
  12. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/deep-watch-numeric.md +102 -0
  13. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/define-model-update-event.md +79 -0
  14. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/duplicate-plugin-detection.md +102 -0
  15. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/fallthrough-attributes.md +63 -0
  16. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/hmr-vue-ssr.md +124 -0
  17. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/module-resolution-bundler.md +81 -0
  18. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/pinia-store-mocking.md +159 -0
  19. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/script-setup-jsdoc.md +85 -0
  20. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/strict-css-modules.md +68 -0
  21. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/unplugin-auto-import-conflicts.md +97 -0
  22. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/volar-3-breaking-changes.md +66 -0
  23. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/vue-directive-comments.md +73 -0
  24. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/vue-router-typed-params.md +81 -0
  25. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/vue-tsc-strict-templates.md +69 -0
  26. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/with-defaults-union-types.md +102 -0
  27. package/package.json +1 -1
  28. package/server/mcp-core.js +38 -8
@@ -0,0 +1,68 @@
1
+ ---
2
+ title: Enable Strict CSS Modules Type Checking
3
+ impact: MEDIUM
4
+ impactDescription: catches typos in CSS module class names at compile time
5
+ type: capability
6
+ tags: strictCssModules, vueCompilerOptions, css-modules, style-module
7
+ ---
8
+
9
+ # Enable Strict CSS Modules Type Checking
10
+
11
+ **Impact: MEDIUM** - catches typos in CSS module class names at compile time
12
+
13
+ When using CSS modules with `<style module>`, Vue doesn't validate class names by default. Enable `strictCssModules` to catch typos and undefined classes.
14
+
15
+ ## Problem
16
+
17
+ CSS module class name errors go undetected:
18
+
19
+ ```vue
20
+ <script setup lang="ts">
21
+ // No error for typo in class name
22
+ </script>
23
+
24
+ <template>
25
+ <div :class="$style.buttn">Click me</div>
26
+ </template>
27
+
28
+ <style module>
29
+ .button {
30
+ background: blue;
31
+ }
32
+ </style>
33
+ ```
34
+
35
+ The typo `buttn` instead of `button` silently fails at runtime.
36
+
37
+ ## Solution
38
+
39
+ Enable `strictCssModules` in your tsconfig:
40
+
41
+ ```json
42
+ // tsconfig.json or tsconfig.app.json
43
+ {
44
+ "vueCompilerOptions": {
45
+ "strictCssModules": true
46
+ }
47
+ }
48
+ ```
49
+
50
+ Now `$style.buttn` will show a type error because `buttn` doesn't exist in the CSS module.
51
+
52
+ ## What Gets Checked
53
+
54
+ | Access | With strictCssModules |
55
+ |--------|----------------------|
56
+ | `$style.validClass` | OK |
57
+ | `$style.typo` | Error: Property 'typo' does not exist |
58
+ | `$style['dynamic']` | OK (dynamic access not checked) |
59
+
60
+ ## Limitations
61
+
62
+ - Only checks static property access (`$style.className`)
63
+ - Dynamic access (`$style[variable]`) is not validated
64
+ - Only works with `<style module>`, not external CSS files
65
+
66
+ ## Reference
67
+
68
+ - [Vue Language Tools Wiki - Vue Compiler Options](https://github.com/vuejs/language-tools/wiki/Vue-Compiler-Options)
@@ -0,0 +1,97 @@
1
+ ---
2
+ title: unplugin-vue-components and unplugin-auto-import Type Conflicts
3
+ impact: HIGH
4
+ impactDescription: fixes component types resolving as any when using both plugins
5
+ type: capability
6
+ tags: unplugin-vue-components, unplugin-auto-import, types, any, dts
7
+ ---
8
+
9
+ # unplugin-vue-components and unplugin-auto-import Type Conflicts
10
+
11
+ **Impact: HIGH** - fixes component types resolving as any when using both plugins
12
+
13
+ Installing both `unplugin-vue-components` and `unplugin-auto-import` can cause component types to resolve as `any`. The generated `.d.ts` files conflict with each other.
14
+
15
+ ## Symptoms
16
+
17
+ - Components typed as `any` instead of proper component types
18
+ - No autocomplete for component props
19
+ - No type errors for invalid props
20
+ - Types work when using only one plugin but break with both
21
+
22
+ ## Root Cause
23
+
24
+ Both plugins generate declaration files (`components.d.ts` and `auto-imports.d.ts`) that can have conflicting declarations. TypeScript declaration merging fails silently.
25
+
26
+ ## Fix
27
+
28
+ **Step 1: Ensure both .d.ts files are in tsconfig include**
29
+ ```json
30
+ {
31
+ "include": [
32
+ "src/**/*.ts",
33
+ "src/**/*.vue",
34
+ "components.d.ts",
35
+ "auto-imports.d.ts"
36
+ ]
37
+ }
38
+ ```
39
+
40
+ **Step 2: Set explicit, different dts paths**
41
+ ```typescript
42
+ // vite.config.ts
43
+ import Components from 'unplugin-vue-components/vite'
44
+ import AutoImport from 'unplugin-auto-import/vite'
45
+
46
+ export default defineConfig({
47
+ plugins: [
48
+ Components({
49
+ dts: 'src/types/components.d.ts' // Explicit unique path
50
+ }),
51
+ AutoImport({
52
+ dts: 'src/types/auto-imports.d.ts' // Explicit unique path
53
+ })
54
+ ]
55
+ })
56
+ ```
57
+
58
+ **Step 3: Regenerate type files**
59
+ ```bash
60
+ # Delete existing .d.ts files
61
+ rm components.d.ts auto-imports.d.ts
62
+
63
+ # Restart dev server to regenerate
64
+ npm run dev
65
+ ```
66
+
67
+ **Step 4: Verify no duplicate declarations**
68
+
69
+ Check that the same component isn't declared in both files.
70
+
71
+ ## Plugin Order Matters
72
+
73
+ Configure Components plugin AFTER AutoImport:
74
+ ```typescript
75
+ plugins: [
76
+ AutoImport({ /* ... */ }),
77
+ Components({ /* ... */ }) // Must come after AutoImport
78
+ ]
79
+ ```
80
+
81
+ ## Common Mistake: Duplicate Imports
82
+
83
+ Don't configure the same import in both plugins:
84
+ ```typescript
85
+ // Wrong - Vue imported in both
86
+ AutoImport({
87
+ imports: ['vue']
88
+ })
89
+ Components({
90
+ resolvers: [/* includes Vue components */]
91
+ })
92
+ ```
93
+
94
+ ## Reference
95
+
96
+ - [unplugin-vue-components#640](https://github.com/unplugin/unplugin-vue-components/issues/640)
97
+ - [unplugin-auto-import docs](https://github.com/unplugin/unplugin-auto-import)
@@ -0,0 +1,66 @@
1
+ ---
2
+ title: Volar 3.0 Breaking Changes
3
+ impact: HIGH
4
+ impactDescription: fixes editor integration after Volar/vue-language-server upgrade
5
+ type: capability
6
+ tags: volar, vue-language-server, neovim, vscode, ide, ts_ls, vtsls
7
+ ---
8
+
9
+ # Volar 3.0 Breaking Changes
10
+
11
+ **Impact: HIGH** - fixes editor integration after Volar/vue-language-server upgrade
12
+
13
+ Volar 3.0 (vue-language-server 3.x) introduced breaking changes to the language server protocol. Editors configured for Volar 2.x will break with errors like "vue_ls doesn't work with ts_ls.. it expects vtsls".
14
+
15
+ ## Symptoms
16
+
17
+ - `vue_ls doesn't work with ts_ls`
18
+ - TypeScript features stop working in Vue files
19
+ - No autocomplete, type hints, or error highlighting
20
+ - Editor shows "Language server initialization failed"
21
+
22
+ ## Fix by Editor
23
+
24
+ ### VSCode
25
+
26
+ Update the "Vue - Official" extension to latest version. It manages the language server automatically.
27
+
28
+ ### NeoVim (nvim-lspconfig)
29
+
30
+ **Option 1: Use vtsls instead of ts_ls**
31
+ ```lua
32
+ -- Replace ts_ls/tsserver with vtsls
33
+ require('lspconfig').vtsls.setup({})
34
+ require('lspconfig').volar.setup({})
35
+ ```
36
+
37
+ **Option 2: Downgrade vue-language-server**
38
+ ```bash
39
+ npm install -g @vue/language-server@2.1.10
40
+ ```
41
+
42
+ ### JetBrains IDEs
43
+
44
+ Update to latest Vue plugin. If issues persist, disable and re-enable the Vue plugin.
45
+
46
+ ## What Changed in 3.0
47
+
48
+ | Feature | Volar 2.x | Volar 3.0 |
49
+ |---------|-----------|-----------|
50
+ | Package name | volar | vue_ls |
51
+ | TypeScript integration | ts_ls/tsserver | vtsls required |
52
+ | Hybrid mode | Optional | Default |
53
+
54
+ ## Workaround: Stay on 2.x
55
+
56
+ If upgrading is not possible:
57
+ ```bash
58
+ npm install -g @vue/language-server@^2.0.0
59
+ ```
60
+
61
+ Pin in your project's package.json to prevent accidental upgrades.
62
+
63
+ ## Reference
64
+
65
+ - [vuejs/language-tools#5598](https://github.com/vuejs/language-tools/issues/5598)
66
+ - [NeoVim Vue Setup Guide](https://dev.to/danwalsh/solved-vue-3-typescript-inlay-hint-support-in-neovim-53ej)
@@ -0,0 +1,73 @@
1
+ ---
2
+ title: Vue Template Directive Comments
3
+ impact: HIGH
4
+ impactDescription: enables fine-grained control over template type checking
5
+ type: capability
6
+ tags: vue-directive, vue-ignore, vue-expect-error, vue-skip, template, type-checking
7
+ ---
8
+
9
+ # Vue Template Directive Comments
10
+
11
+ **Impact: HIGH** - enables fine-grained control over template type checking
12
+
13
+ Vue Language Tools supports special directive comments to control type checking behavior in templates.
14
+
15
+ ## Available Directives
16
+
17
+ ### @vue-ignore
18
+
19
+ Suppress type errors for the next line:
20
+
21
+ ```vue
22
+ <template>
23
+ <!-- @vue-ignore -->
24
+ <Component :prop="valueWithTypeError" />
25
+ </template>
26
+ ```
27
+
28
+ ### @vue-expect-error
29
+
30
+ Assert that the next line should have a type error (useful for testing):
31
+
32
+ ```vue
33
+ <template>
34
+ <!-- @vue-expect-error -->
35
+ <Component :invalid-prop="value" />
36
+ </template>
37
+ ```
38
+
39
+ ### @vue-skip
40
+
41
+ Skip type checking for an entire block:
42
+
43
+ ```vue
44
+ <template>
45
+ <!-- @vue-skip -->
46
+ <div>
47
+ <!-- Everything in here is not type-checked -->
48
+ <LegacyComponent :any="props" :go="here" />
49
+ </div>
50
+ </template>
51
+ ```
52
+
53
+ ### @vue-generic
54
+
55
+ Declare template-level generic types:
56
+
57
+ ```vue
58
+ <template>
59
+ <!-- @vue-generic {T extends string} -->
60
+ <GenericList :items="items as T[]" />
61
+ </template>
62
+ ```
63
+
64
+ ## Use Cases
65
+
66
+ - Migrating legacy components with incomplete types
67
+ - Working with third-party components that have incorrect type definitions
68
+ - Temporarily suppressing errors during refactoring
69
+ - Testing that certain patterns produce expected type errors
70
+
71
+ ## Reference
72
+
73
+ - [Vue Language Tools Wiki - Directive Comments](https://github.com/vuejs/language-tools/wiki/Directive-Comments)
@@ -0,0 +1,81 @@
1
+ ---
2
+ title: Vue Router useRoute Params Union Type Narrowing
3
+ impact: MEDIUM
4
+ impactDescription: fixes "Property does not exist" errors with typed route params
5
+ type: capability
6
+ tags: vue-router, useRoute, unplugin-vue-router, typed-routes, params
7
+ ---
8
+
9
+ # Vue Router useRoute Params Union Type Narrowing
10
+
11
+ **Impact: MEDIUM** - fixes "Property does not exist" errors with typed route params
12
+
13
+ With `unplugin-vue-router` typed routes, `route.params` becomes a union of ALL page param types. TypeScript cannot narrow `Record<never, never> | { id: string }` properly, causing "Property 'id' does not exist" errors even on the correct page.
14
+
15
+ ## Symptoms
16
+
17
+ - "Property 'id' does not exist on type 'RouteParams'"
18
+ - `route.params.id` shows as `string | undefined` everywhere
19
+ - Union type of all route params instead of specific route
20
+ - Type narrowing with `if (route.name === 'users-id')` doesn't work
21
+
22
+ ## Root Cause
23
+
24
+ `unplugin-vue-router` generates a union type of all possible route params. TypeScript's control flow analysis can't narrow this union based on route name checks.
25
+
26
+ ## Fix
27
+
28
+ **Option 1: Pass route name to useRoute (recommended)**
29
+ ```typescript
30
+ // pages/users/[id].vue
31
+ import { useRoute } from 'vue-router/auto'
32
+
33
+ // Specify the route path for proper typing
34
+ const route = useRoute('/users/[id]')
35
+
36
+ // Now properly typed as { id: string }
37
+ console.log(route.params.id) // string, not string | undefined
38
+ ```
39
+
40
+ **Option 2: Type assertion with specific route**
41
+ ```typescript
42
+ import { useRoute } from 'vue-router'
43
+ import type { RouteLocationNormalized } from 'vue-router/auto-routes'
44
+
45
+ const route = useRoute() as RouteLocationNormalized<'/users/[id]'>
46
+ route.params.id // Properly typed
47
+ ```
48
+
49
+ **Option 3: Define route-specific param type**
50
+ ```typescript
51
+ // In your page component
52
+ interface UserRouteParams {
53
+ id: string
54
+ }
55
+
56
+ const route = useRoute()
57
+ const { id } = route.params as UserRouteParams
58
+ ```
59
+
60
+ ## Required tsconfig Setting
61
+
62
+ Ensure `moduleResolution: "bundler"` for unplugin-vue-router:
63
+ ```json
64
+ {
65
+ "compilerOptions": {
66
+ "moduleResolution": "bundler"
67
+ }
68
+ }
69
+ ```
70
+
71
+ ## Caveat: Route Name Format
72
+
73
+ The route name matches the file path pattern:
74
+ - `pages/users/[id].vue` → `/users/[id]`
75
+ - `pages/posts/[slug]/comments.vue` → `/posts/[slug]/comments`
76
+
77
+ ## Reference
78
+
79
+ - [unplugin-vue-router#337](https://github.com/posva/unplugin-vue-router/issues/337)
80
+ - [unplugin-vue-router#176](https://github.com/posva/unplugin-vue-router/discussions/176)
81
+ - [unplugin-vue-router TypeScript docs](https://uvr.esm.is/guide/typescript.html)
@@ -0,0 +1,69 @@
1
+ ---
2
+ title: Enable Strict Template Checking
3
+ impact: HIGH
4
+ impactDescription: catches undefined components and props at compile time
5
+ type: capability
6
+ tags: vue-tsc, typescript, type-checking, templates, vueCompilerOptions
7
+ ---
8
+
9
+ # Enable Strict Template Checking
10
+
11
+ **Impact: HIGH** - catches undefined components and props at compile time
12
+
13
+ By default, vue-tsc does not report errors for undefined components in templates. Enable `strictTemplates` to catch these issues during type checking.
14
+
15
+ ## Which tsconfig?
16
+
17
+ Add `vueCompilerOptions` to the tsconfig that includes Vue source files. In projects with multiple tsconfigs (like those created with `create-vue`), this is typically `tsconfig.app.json`, not the root `tsconfig.json` or `tsconfig.node.json`.
18
+
19
+ **Incorrect (missing strict checking):**
20
+
21
+ ```json
22
+ {
23
+ "compilerOptions": {
24
+ "strict": true
25
+ }
26
+ // vueCompilerOptions not configured - undefined components won't error
27
+ }
28
+ ```
29
+
30
+ **Correct (strict template checking enabled):**
31
+
32
+ ```json
33
+ {
34
+ "compilerOptions": {
35
+ "strict": true
36
+ },
37
+ "vueCompilerOptions": {
38
+ "strictTemplates": true
39
+ }
40
+ }
41
+ ```
42
+
43
+ ## Available Options
44
+
45
+ | Option | Default | Effect |
46
+ |--------|---------|--------|
47
+ | `strictTemplates` | `false` | Enables all checkUnknown* options below |
48
+ | `checkUnknownComponents` | `false` | Error on undefined/unregistered components |
49
+ | `checkUnknownProps` | `false` | Error on props not declared in component definition |
50
+ | `checkUnknownEvents` | `false` | Error on events not declared via `defineEmits` |
51
+ | `checkUnknownDirectives` | `false` | Error on unregistered custom directives |
52
+
53
+ ## Granular Control
54
+
55
+ If `strictTemplates` is too strict, enable individual checks:
56
+
57
+ ```json
58
+ {
59
+ "vueCompilerOptions": {
60
+ "checkUnknownComponents": true,
61
+ "checkUnknownProps": false
62
+ }
63
+ }
64
+ ```
65
+
66
+ ## Reference
67
+
68
+ - [Vue Compiler Options](https://github.com/vuejs/language-tools/wiki/Vue-Compiler-Options)
69
+ - [Vite Vue+TS Template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-vue-ts)
@@ -0,0 +1,102 @@
1
+ ---
2
+ title: withDefaults Incorrect Default with Union Types
3
+ impact: MEDIUM
4
+ impactDescription: fixes incorrect default value behavior with union type props
5
+ type: capability
6
+ tags: withDefaults, defineProps, union-types, defaults, vue-3.5
7
+ ---
8
+
9
+ # withDefaults Incorrect Default with Union Types
10
+
11
+ **Impact: MEDIUM** - fixes spurious "Missing required prop" warning with union type props
12
+
13
+ Using `withDefaults` with union types like `false | string` may produce a Vue runtime warning "Missing required prop" even when a default is provided. The runtime value IS applied correctly, but the warning can be confusing.
14
+
15
+ ## Symptoms
16
+
17
+ - Vue warns "Missing required prop" despite default being set
18
+ - Warning appears only with union types like `false | string`
19
+ - TypeScript types are correct
20
+ - Runtime value IS correct (the default is applied)
21
+
22
+ ## Problematic Pattern
23
+
24
+ ```typescript
25
+ // This produces a spurious warning (but works at runtime)
26
+ interface Props {
27
+ value: false | string // Union type
28
+ }
29
+
30
+ const props = withDefaults(defineProps<Props>(), {
31
+ value: 'default' // Runtime value IS correct, but Vue warns about missing prop
32
+ })
33
+ ```
34
+
35
+ ## Fix
36
+
37
+ **Option 1: Use Reactive Props Destructure (Vue 3.5+)**
38
+ ```vue
39
+ <script setup lang="ts">
40
+ interface Props {
41
+ value: false | string
42
+ }
43
+
44
+ // Preferred in Vue 3.5+
45
+ const { value = 'default' } = defineProps<Props>()
46
+ </script>
47
+ ```
48
+
49
+ **Option 2: Use runtime declaration**
50
+ ```vue
51
+ <script setup lang="ts">
52
+ const props = defineProps({
53
+ value: {
54
+ type: [Boolean, String] as PropType<false | string>,
55
+ default: 'default'
56
+ }
57
+ })
58
+ </script>
59
+ ```
60
+
61
+ **Option 3: Split into separate props**
62
+ ```typescript
63
+ interface Props {
64
+ enabled: boolean
65
+ customValue?: string
66
+ }
67
+
68
+ const props = withDefaults(defineProps<Props>(), {
69
+ enabled: false,
70
+ customValue: 'default'
71
+ })
72
+ ```
73
+
74
+ ## Why Reactive Props Destructure Works
75
+
76
+ Vue 3.5's Reactive Props Destructure handles default values at the destructuring level, bypassing the type inference issues with `withDefaults`.
77
+
78
+ ```typescript
79
+ // The default is applied during destructuring, not type inference
80
+ const { prop = 'default' } = defineProps<{ prop?: string }>()
81
+ ```
82
+
83
+ ## Enable Reactive Props Destructure
84
+
85
+ This is enabled by default in Vue 3.5+. For older versions:
86
+ ```javascript
87
+ // vite.config.js
88
+ export default {
89
+ plugins: [
90
+ vue({
91
+ script: {
92
+ propsDestructure: true
93
+ }
94
+ })
95
+ ]
96
+ }
97
+ ```
98
+
99
+ ## Reference
100
+
101
+ - [vuejs/core#12897](https://github.com/vuejs/core/issues/12897)
102
+ - [Reactive Props Destructure RFC](https://github.com/vuejs/rfcs/discussions/502)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueking/bkui-knowledge",
3
- "version": "0.0.1-beta.6",
3
+ "version": "0.0.1-beta.8",
4
4
  "description": "蓝鲸前端知识库 MCP 服务 - 自动同步 skills,支持 Cursor/CodeBuddy",
5
5
  "main": "server/mcp-core.js",
6
6
  "bin": {
@@ -105,6 +105,22 @@ const TOOLS = [
105
105
  type: "object",
106
106
  properties: {}
107
107
  }
108
+ },
109
+
110
+ // L3 工具: 获取资源文件 (绕过 Cursor FetchMcpResource bug)
111
+ {
112
+ name: "get_resource",
113
+ description: "获取 skill 或 example 资源文件内容。URI 格式: skill://skillId/subDir/path 或 example://componentId/exampleName。用于获取布局模板、代码示例等资源。",
114
+ inputSchema: {
115
+ type: "object",
116
+ properties: {
117
+ uri: {
118
+ type: "string",
119
+ description: "资源 URI,如: skill://bkui-builder/assets/layouts/admin-layout-dark.vue, example://table/basic"
120
+ }
121
+ },
122
+ required: ["uri"]
123
+ }
108
124
  }
109
125
  ];
110
126
 
@@ -153,8 +169,9 @@ function buildResources() {
153
169
  if (manifest.skills && manifest.skills.items) {
154
170
  const skillsBasePath = path.join(KNOWLEDGE_DIR, manifest.skills.base_path);
155
171
  manifest.skills.items.forEach(skill => {
156
- const skillDir = path.join(skillsBasePath, skill.id);
157
- ['scripts', 'references', 'assets'].forEach(subDir => {
172
+ // 使用 skill.path 推断目录(支持外部 skill
173
+ const skillDir = path.join(skillsBasePath, path.dirname(skill.path));
174
+ ['scripts', 'references', 'assets', 'rules'].forEach(subDir => {
158
175
  const subDirPath = path.join(skillDir, subDir);
159
176
  if (fs.existsSync(subDirPath)) {
160
177
  scanSkillDir(subDirPath, '').forEach(filePath => {
@@ -275,7 +292,7 @@ const Handlers = {
275
292
 
276
293
  // 检查 skill 目录下的附属资源,生成 skill:// URIs
277
294
  const skillDir = path.dirname(filePath);
278
- const subDirs = ['scripts', 'references', 'assets'];
295
+ const subDirs = ['scripts', 'references', 'assets', 'rules'];
279
296
  const availableResources = [];
280
297
 
281
298
  subDirs.forEach(dir => {
@@ -447,6 +464,17 @@ ${recommendedIds.map(id => {
447
464
  return { content: [{ type: "text", text: result }] };
448
465
  },
449
466
 
467
+ // L3: 获取资源文件 (绕过 Cursor FetchMcpResource bug)
468
+ async get_resource({ uri }) {
469
+ const result = await readResource(uri);
470
+ // readResource 返回 { content: string } 或 { contents: [{ text }] }
471
+ const text = result.content || (result.contents && result.contents[0] && result.contents[0].text);
472
+ if (!text) {
473
+ throw new Error(`Resource not found or empty: ${uri}`);
474
+ }
475
+ return { content: [{ type: "text", text }] };
476
+ },
477
+
450
478
  // Prompt 处理
451
479
  async get_prompt({ name }) {
452
480
  if (name === "BKUI-EXPERT") {
@@ -551,8 +579,8 @@ async function handleExampleResource(uri) {
551
579
  throw new Error(`Example '${exampleName}' not found for ${componentId}. Available: ${compExamples.examples.map(e => e.name).join(', ')}`);
552
580
  }
553
581
 
554
- // 读取示例文件
555
- const examplePath = path.join(ROOT_DIR, manifest.componentExamples.base_path, example.file);
582
+ // 读取示例文件 (base_path 相对于 KNOWLEDGE_DIR)
583
+ const examplePath = path.join(KNOWLEDGE_DIR, manifest.componentExamples.base_path, example.file);
556
584
  if (!fs.existsSync(examplePath)) {
557
585
  throw new Error(`Example file not found: ${example.file}`);
558
586
  }
@@ -573,8 +601,8 @@ async function handleSkillResource(uri) {
573
601
 
574
602
  const [, skillId, subDir, filePath] = match;
575
603
 
576
- if (!['scripts', 'references', 'assets'].includes(subDir)) {
577
- throw new Error(`Invalid skill subDir: ${subDir}. Must be scripts, references, or assets`);
604
+ if (!['scripts', 'references', 'assets', 'rules'].includes(subDir)) {
605
+ throw new Error(`Invalid skill subDir: ${subDir}. Must be scripts, references, assets, or rules`);
578
606
  }
579
607
 
580
608
  const manifest = loadManifest();
@@ -583,7 +611,9 @@ async function handleSkillResource(uri) {
583
611
  throw new Error(`Skill not found: ${skillId}`);
584
612
  }
585
613
 
586
- const fullPath = path.join(KNOWLEDGE_DIR, manifest.skills.base_path, skillId, subDir, filePath);
614
+ // 使用 skill.path 推断目录(支持外部 skill)
615
+ const skillDir = path.dirname(skill.path);
616
+ const fullPath = path.join(KNOWLEDGE_DIR, manifest.skills.base_path, skillDir, subDir, filePath);
587
617
  if (!fs.existsSync(fullPath)) {
588
618
  throw new Error(`Skill resource not found: ${subDir}/${filePath}`);
589
619
  }