dsh-skill-harbor 0.5.4 → 0.6.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.
@@ -1,169 +1,169 @@
1
- /**
2
- * 零依赖 frontmatter 解析。
3
- *
4
- * 不引 js-yaml:技能 frontmatter 的实际形态极窄(一层标量 + 少量布尔 + 两种块标量),
5
- * 而 yaml 全量解析器会带进 ~100KB 与大量边界语义(锚点/多文档/类型推断),
6
- * 我们只需要「读到正确字符串」。
7
- *
8
- * 支持:
9
- * - `key: value` 标量(去引号)
10
- * - `key: |` 字面块 / `key: >` 折叠块(含缩进剥离)
11
- * - `disable-model-invocation` / `user-invocable` 布尔:
12
- * true/false、1/0、yes/no、on/off(大小写不敏感)
13
- */
14
-
15
- /** 六种布尔写法的唯一收敛点。 */
16
- const BOOL_TRUE = new Set(['true', '1', 'yes', 'on'])
17
- const BOOL_FALSE = new Set(['false', '0', 'no', 'off'])
18
-
19
- /** 解析布尔;不是布尔写法返回 undefined(区别于 false)。 */
20
- export function parseBool(raw) {
21
- if (typeof raw !== 'string') return undefined
22
- const v = raw.trim().toLowerCase()
23
- if (BOOL_TRUE.has(v)) return true
24
- if (BOOL_FALSE.has(v)) return false
25
- return undefined
26
- }
27
-
28
- /** 去掉成对引号(单双),并还原常见转义。 */
29
- function unquote(raw) {
30
- const v = raw.trim()
31
- if (v.length >= 2) {
32
- const first = v[0]
33
- const last = v[v.length - 1]
34
- if ((first === '"' || first === "'") && first === last) {
35
- const inner = v.slice(1, -1)
36
- return first === '"' ? inner.replace(/\\"/g, '"').replace(/\\n/g, '\n') : inner.replace(/''/g, "'")
37
- }
38
- }
39
- return v
40
- }
41
-
42
- /**
43
- * 从 Markdown 文本中切出 frontmatter 原文与正文。
44
- * 只认文件最开头的 `---`(允许前置 BOM),与宿主一致。
45
- */
46
- export function splitFrontmatter(text) {
47
- const src = text.charCodeAt(0) === 0xfeff ? text.slice(1) : text
48
- if (!src.startsWith('---')) return { raw: null, body: src }
49
-
50
- // 找结束分隔行:独占一行的 --- 或 ...
51
- const lines = src.split(/\r?\n/)
52
- let end = -1
53
- for (let i = 1; i < lines.length; i += 1) {
54
- const line = lines[i]
55
- if (line === '---' || line === '...') {
56
- end = i
57
- break
58
- }
59
- }
60
- if (end === -1) return { raw: null, body: src }
61
-
62
- return {
63
- raw: lines.slice(1, end).join('\n'),
64
- body: lines.slice(end + 1).join('\n'),
65
- }
66
- }
67
-
68
- /**
69
- * 解析 frontmatter 原文为对象。
70
- * 值一律是 string 或 string[](块标量),布尔交给调用方用 parseBool 收敛,
71
- * 避免「看起来是字符串的 false」被当成真值。
72
- */
73
- export function parseFrontmatter(raw) {
74
- const out = Object.create(null)
75
- if (typeof raw !== 'string' || raw.trim() === '') return out
76
-
77
- const lines = raw.split(/\r?\n/)
78
- let i = 0
79
- while (i < lines.length) {
80
- const line = lines[i]
81
- if (line.trim() === '' || line.trimStart().startsWith('#')) {
82
- i += 1
83
- continue
84
- }
85
-
86
- const match = /^([A-Za-z0-9_.-]+):(.*)$/.exec(line)
87
- if (match === null) {
88
- i += 1
89
- continue
90
- }
91
-
92
- const key = match[1]
93
- const rest = match[2]
94
-
95
- // 块标量:`key: |` 或 `key: >`(可带修饰符)
96
- const blockMark = /^\s*([|>])[+-]?\s*$/.exec(rest)
97
- if (blockMark !== null) {
98
- const style = blockMark[1]
99
- const body = []
100
- i += 1
101
- while (i < lines.length) {
102
- const next = lines[i]
103
- if (next.trim() !== '' && !/^\s/.test(next)) break
104
- body.push(next)
105
- i += 1
106
- }
107
- // 去掉公共缩进
108
- const indents = body.filter(l => l.trim() !== '').map(l => l.match(/^\s*/)[0].length)
109
- const cut = indents.length > 0 ? Math.min(...indents) : 0
110
- const dedented = body.map(l => l.slice(cut))
111
- // 去掉尾部空行
112
- while (dedented.length > 0 && dedented[dedented.length - 1].trim() === '') dedented.pop()
113
- out[key] = style === '|' ? dedented.join('\n') : dedented.join(' ').replace(/\s+/g, ' ').trim()
114
- continue
115
- }
116
-
117
- // 普通标量
118
- const value = rest.trim()
119
- if (value !== '') {
120
- out[key] = unquote(value)
121
- i += 1
122
- continue
123
- }
124
-
125
- // 空值 → 可能是紧随其后的 `- item` 列表
126
- const items = []
127
- i += 1
128
- while (i < lines.length) {
129
- const next = lines[i]
130
- const item = /^\s*-\s+(.*)$/.exec(next)
131
- if (item === null) break
132
- items.push(unquote(item[1]))
133
- i += 1
134
- }
135
- out[key] = items.length > 0 ? items : ''
136
- }
137
-
138
- return out
139
- }
140
-
141
- /** 一站式:文本 → { data, body }。 */
142
- export function readSkillDocument(text) {
143
- const { raw, body } = splitFrontmatter(text)
144
- return { data: parseFrontmatter(raw), body, hasFrontmatter: raw !== null }
145
- }
146
-
147
- /**
148
- * 归一化成 SkillObservation 需要的三字段。
149
- * `whenToUse` 兼容 whenToUse / when_to_use 两种写法。
150
- */
151
- export function extractSkillMeta(text) {
152
- const { data, body } = readSkillDocument(text)
153
- const name = typeof data.name === 'string' ? data.name : ''
154
- const description = typeof data.description === 'string' ? data.description : ''
155
- const whenToUseRaw = data.whenToUse ?? data.when_to_use
156
- const whenToUse = typeof whenToUseRaw === 'string' && whenToUseRaw !== '' ? whenToUseRaw : undefined
157
-
158
- const disableRaw = data['disable-model-invocation']
159
- const userRaw = data['user-invocable']
160
-
161
- return {
162
- name,
163
- description,
164
- ...whenToUse === undefined ? {} : { whenToUse },
165
- disableModelInvocation: parseBool(disableRaw) ?? false,
166
- userInvocable: parseBool(userRaw) ?? true,
167
- body,
168
- }
169
- }
1
+ /**
2
+ * 零依赖 frontmatter 解析。
3
+ *
4
+ * 不引 js-yaml:技能 frontmatter 的实际形态极窄(一层标量 + 少量布尔 + 两种块标量),
5
+ * 而 yaml 全量解析器会带进 ~100KB 与大量边界语义(锚点/多文档/类型推断),
6
+ * 我们只需要「读到正确字符串」。
7
+ *
8
+ * 支持:
9
+ * - `key: value` 标量(去引号)
10
+ * - `key: |` 字面块 / `key: >` 折叠块(含缩进剥离)
11
+ * - `disable-model-invocation` / `user-invocable` 布尔:
12
+ * true/false、1/0、yes/no、on/off(大小写不敏感)
13
+ */
14
+
15
+ /** 六种布尔写法的唯一收敛点。 */
16
+ const BOOL_TRUE = new Set(['true', '1', 'yes', 'on'])
17
+ const BOOL_FALSE = new Set(['false', '0', 'no', 'off'])
18
+
19
+ /** 解析布尔;不是布尔写法返回 undefined(区别于 false)。 */
20
+ export function parseBool(raw) {
21
+ if (typeof raw !== 'string') return undefined
22
+ const v = raw.trim().toLowerCase()
23
+ if (BOOL_TRUE.has(v)) return true
24
+ if (BOOL_FALSE.has(v)) return false
25
+ return undefined
26
+ }
27
+
28
+ /** 去掉成对引号(单双),并还原常见转义。 */
29
+ function unquote(raw) {
30
+ const v = raw.trim()
31
+ if (v.length >= 2) {
32
+ const first = v[0]
33
+ const last = v[v.length - 1]
34
+ if ((first === '"' || first === "'") && first === last) {
35
+ const inner = v.slice(1, -1)
36
+ return first === '"' ? inner.replace(/\\"/g, '"').replace(/\\n/g, '\n') : inner.replace(/''/g, "'")
37
+ }
38
+ }
39
+ return v
40
+ }
41
+
42
+ /**
43
+ * 从 Markdown 文本中切出 frontmatter 原文与正文。
44
+ * 只认文件最开头的 `---`(允许前置 BOM),与宿主一致。
45
+ */
46
+ export function splitFrontmatter(text) {
47
+ const src = text.charCodeAt(0) === 0xfeff ? text.slice(1) : text
48
+ if (!src.startsWith('---')) return { raw: null, body: src }
49
+
50
+ // 找结束分隔行:独占一行的 --- 或 ...
51
+ const lines = src.split(/\r?\n/)
52
+ let end = -1
53
+ for (let i = 1; i < lines.length; i += 1) {
54
+ const line = lines[i]
55
+ if (line === '---' || line === '...') {
56
+ end = i
57
+ break
58
+ }
59
+ }
60
+ if (end === -1) return { raw: null, body: src }
61
+
62
+ return {
63
+ raw: lines.slice(1, end).join('\n'),
64
+ body: lines.slice(end + 1).join('\n'),
65
+ }
66
+ }
67
+
68
+ /**
69
+ * 解析 frontmatter 原文为对象。
70
+ * 值一律是 string 或 string[](块标量),布尔交给调用方用 parseBool 收敛,
71
+ * 避免「看起来是字符串的 false」被当成真值。
72
+ */
73
+ export function parseFrontmatter(raw) {
74
+ const out = Object.create(null)
75
+ if (typeof raw !== 'string' || raw.trim() === '') return out
76
+
77
+ const lines = raw.split(/\r?\n/)
78
+ let i = 0
79
+ while (i < lines.length) {
80
+ const line = lines[i]
81
+ if (line.trim() === '' || line.trimStart().startsWith('#')) {
82
+ i += 1
83
+ continue
84
+ }
85
+
86
+ const match = /^([A-Za-z0-9_.-]+):(.*)$/.exec(line)
87
+ if (match === null) {
88
+ i += 1
89
+ continue
90
+ }
91
+
92
+ const key = match[1]
93
+ const rest = match[2]
94
+
95
+ // 块标量:`key: |` 或 `key: >`(可带修饰符)
96
+ const blockMark = /^\s*([|>])[+-]?\s*$/.exec(rest)
97
+ if (blockMark !== null) {
98
+ const style = blockMark[1]
99
+ const body = []
100
+ i += 1
101
+ while (i < lines.length) {
102
+ const next = lines[i]
103
+ if (next.trim() !== '' && !/^\s/.test(next)) break
104
+ body.push(next)
105
+ i += 1
106
+ }
107
+ // 去掉公共缩进
108
+ const indents = body.filter(l => l.trim() !== '').map(l => l.match(/^\s*/)[0].length)
109
+ const cut = indents.length > 0 ? Math.min(...indents) : 0
110
+ const dedented = body.map(l => l.slice(cut))
111
+ // 去掉尾部空行
112
+ while (dedented.length > 0 && dedented[dedented.length - 1].trim() === '') dedented.pop()
113
+ out[key] = style === '|' ? dedented.join('\n') : dedented.join(' ').replace(/\s+/g, ' ').trim()
114
+ continue
115
+ }
116
+
117
+ // 普通标量
118
+ const value = rest.trim()
119
+ if (value !== '') {
120
+ out[key] = unquote(value)
121
+ i += 1
122
+ continue
123
+ }
124
+
125
+ // 空值 → 可能是紧随其后的 `- item` 列表
126
+ const items = []
127
+ i += 1
128
+ while (i < lines.length) {
129
+ const next = lines[i]
130
+ const item = /^\s*-\s+(.*)$/.exec(next)
131
+ if (item === null) break
132
+ items.push(unquote(item[1]))
133
+ i += 1
134
+ }
135
+ out[key] = items.length > 0 ? items : ''
136
+ }
137
+
138
+ return out
139
+ }
140
+
141
+ /** 一站式:文本 → { data, body }。 */
142
+ export function readSkillDocument(text) {
143
+ const { raw, body } = splitFrontmatter(text)
144
+ return { data: parseFrontmatter(raw), body, hasFrontmatter: raw !== null }
145
+ }
146
+
147
+ /**
148
+ * 归一化成 SkillObservation 需要的三字段。
149
+ * `whenToUse` 兼容 whenToUse / when_to_use 两种写法。
150
+ */
151
+ export function extractSkillMeta(text) {
152
+ const { data, body } = readSkillDocument(text)
153
+ const name = typeof data.name === 'string' ? data.name : ''
154
+ const description = typeof data.description === 'string' ? data.description : ''
155
+ const whenToUseRaw = data.whenToUse ?? data.when_to_use
156
+ const whenToUse = typeof whenToUseRaw === 'string' && whenToUseRaw !== '' ? whenToUseRaw : undefined
157
+
158
+ const disableRaw = data['disable-model-invocation']
159
+ const userRaw = data['user-invocable']
160
+
161
+ return {
162
+ name,
163
+ description,
164
+ ...whenToUse === undefined ? {} : { whenToUse },
165
+ disableModelInvocation: parseBool(disableRaw) ?? false,
166
+ userInvocable: parseBool(userRaw) ?? true,
167
+ body,
168
+ }
169
+ }
@@ -1,143 +1,143 @@
1
- /**
2
- * SkillObservation 组装 —— 证据层的核心。
3
- *
4
- * 三态 fileState(findings A4,采自 @linxin666,点名 issue #1842):
5
- * - `editable` 本面板扫盘解析到了 SKILL.md,携带写路由可信的 path
6
- * - `provider-file` 官方 registry 报了真实指令文件(SkillSummary.path),但本面板扫描没解析到
7
- * —— 文件存在,说「不存在」正是 #1842;但它不是写路由信任的路径,
8
- * 因此**不得提供任何写控件**
9
- * - `virtual` registry 压根没报指令文件,「无本地文件」才是准确说法
10
- */
11
- import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
12
- import { basename, join } from 'node:path'
13
-
14
- import { extractSkillMeta } from './frontmatter.js'
15
- import { filterExistingRoots } from './roots.js'
16
-
17
- /** 三态常量,避免散落字符串。 */
18
- export const FILE_STATE = Object.freeze({
19
- EDITABLE: 'editable',
20
- PROVIDER_FILE: 'provider-file',
21
- VIRTUAL: 'virtual',
22
- })
23
-
24
- /**
25
- * 在单个根下枚举技能:两种形态
26
- * - 目录包 `<root>/<name>/SKILL.md`
27
- * - 平铺 `<root>/<name>.md`
28
- * 符号链接**跳过**(不跟随,findings A5)。
29
- */
30
- export function scanRoot(root) {
31
- const found = []
32
- let entries
33
- try {
34
- entries = readdirSync(root.path, { withFileTypes: true })
35
- } catch {
36
- return found
37
- }
38
-
39
- for (const entry of entries) {
40
- if (entry.isSymbolicLink()) continue
41
-
42
- if (entry.isDirectory()) {
43
- const skillFile = join(root.path, entry.name, 'SKILL.md')
44
- if (safeIsFile(skillFile)) {
45
- found.push({ name: entry.name, path: skillFile, dir: join(root.path, entry.name) })
46
- }
47
- continue
48
- }
49
-
50
- if (entry.isFile() && entry.name.toLowerCase().endsWith('.md')) {
51
- // 平铺形态;SKILL.md 本身不算平铺技能(它属于目录包)
52
- const name = basename(entry.name, entry.name.slice(-3))
53
- found.push({ name, path: join(root.path, entry.name), dir: null })
54
- }
55
- }
56
- return found
57
- }
58
-
59
- function safeIsFile(path) {
60
- try {
61
- return statSync(path).isFile()
62
- } catch {
63
- return false
64
- }
65
- }
66
-
67
- /** 渐进披露第一层的字符数:name + description + whenToUse,不含正文。 */
68
- export function announcementChars(meta) {
69
- const parts = [meta.name ?? '', meta.description ?? '', meta.whenToUse ?? '']
70
- return parts.reduce((sum, part) => sum + [...part].length, 0)
71
- }
72
-
73
- /**
74
- * 扫描全部根,产出 SkillObservation[](尚未做遮蔽判定)。
75
- * registrySummaries 是官方 `ctx.skills.list()` 的结果,用于补齐 provider-file / virtual。
76
- */
77
- export function observeSkills({ roots, registrySummaries = [] }) {
78
- const observations = []
79
- const scanned = new Map() // name -> observation
80
-
81
- for (const root of filterExistingRoots(roots)) {
82
- for (const hit of scanRoot(root)) {
83
- let text
84
- try {
85
- text = readFileSync(hit.path, 'utf8')
86
- } catch {
87
- continue
88
- }
89
- const meta = extractSkillMeta(text)
90
- const name = meta.name !== '' ? meta.name : hit.name
91
-
92
- const observation = {
93
- name,
94
- description: meta.description,
95
- ...meta.whenToUse === undefined ? {} : { whenToUse: meta.whenToUse },
96
- source: root.source,
97
- rank: root.rank,
98
- path: hit.path,
99
- fileState: FILE_STATE.EDITABLE,
100
- modelInvocable: !meta.disableModelInvocation,
101
- announcementChars: announcementChars(meta),
102
- }
103
- observations.push(observation)
104
- if (!scanned.has(name)) scanned.set(name, observation)
105
- }
106
- }
107
-
108
- // 官方 registry 报了、我们没扫到的:区分 provider-file / virtual
109
- for (const summary of registrySummaries) {
110
- if (scanned.has(summary.name)) continue
111
- const hasPath = typeof summary.path === 'string' && summary.path !== ''
112
- observations.push({
113
- name: summary.name,
114
- description: summary.description ?? '',
115
- ...summary.whenToUse === undefined ? {} : { whenToUse: summary.whenToUse },
116
- source: typeof summary.source === 'string' ? summary.source : 'runtime',
117
- rank: typeof summary.rank === 'number' ? summary.rank : Number.MAX_SAFE_INTEGER,
118
- ...hasPath ? { path: summary.path } : {},
119
- fileState: hasPath ? FILE_STATE.PROVIDER_FILE : FILE_STATE.VIRTUAL,
120
- modelInvocable: summary.invocation?.model === true,
121
- announcementChars: announcementChars({
122
- name: summary.name,
123
- description: summary.description,
124
- whenToUse: summary.whenToUse,
125
- }),
126
- })
127
- }
128
-
129
- return observations
130
- }
131
-
132
- /**
133
- * 该条目是否允许写操作。
134
- * `provider-file` / `virtual` **一律不可写**(UI 层断言也依赖此谓词)。
135
- */
136
- export function isWritable(observation) {
137
- return observation.fileState === FILE_STATE.EDITABLE && typeof observation.path === 'string'
138
- }
139
-
140
- /** 路径是否存在(用于确认扫描结果未过期)。 */
141
- export function stillExists(observation) {
142
- return typeof observation.path === 'string' && existsSync(observation.path)
143
- }
1
+ /**
2
+ * SkillObservation 组装 —— 证据层的核心。
3
+ *
4
+ * 三态 fileState(findings A4,采自 @linxin666,点名 issue #1842):
5
+ * - `editable` 本面板扫盘解析到了 SKILL.md,携带写路由可信的 path
6
+ * - `provider-file` 官方 registry 报了真实指令文件(SkillSummary.path),但本面板扫描没解析到
7
+ * —— 文件存在,说「不存在」正是 #1842;但它不是写路由信任的路径,
8
+ * 因此**不得提供任何写控件**
9
+ * - `virtual` registry 压根没报指令文件,「无本地文件」才是准确说法
10
+ */
11
+ import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
12
+ import { basename, join } from 'node:path'
13
+
14
+ import { extractSkillMeta } from './frontmatter.js'
15
+ import { filterExistingRoots } from './roots.js'
16
+
17
+ /** 三态常量,避免散落字符串。 */
18
+ export const FILE_STATE = Object.freeze({
19
+ EDITABLE: 'editable',
20
+ PROVIDER_FILE: 'provider-file',
21
+ VIRTUAL: 'virtual',
22
+ })
23
+
24
+ /**
25
+ * 在单个根下枚举技能:两种形态
26
+ * - 目录包 `<root>/<name>/SKILL.md`
27
+ * - 平铺 `<root>/<name>.md`
28
+ * 符号链接**跳过**(不跟随,findings A5)。
29
+ */
30
+ export function scanRoot(root) {
31
+ const found = []
32
+ let entries
33
+ try {
34
+ entries = readdirSync(root.path, { withFileTypes: true })
35
+ } catch {
36
+ return found
37
+ }
38
+
39
+ for (const entry of entries) {
40
+ if (entry.isSymbolicLink()) continue
41
+
42
+ if (entry.isDirectory()) {
43
+ const skillFile = join(root.path, entry.name, 'SKILL.md')
44
+ if (safeIsFile(skillFile)) {
45
+ found.push({ name: entry.name, path: skillFile, dir: join(root.path, entry.name) })
46
+ }
47
+ continue
48
+ }
49
+
50
+ if (entry.isFile() && entry.name.toLowerCase().endsWith('.md')) {
51
+ // 平铺形态;SKILL.md 本身不算平铺技能(它属于目录包)
52
+ const name = basename(entry.name, entry.name.slice(-3))
53
+ found.push({ name, path: join(root.path, entry.name), dir: null })
54
+ }
55
+ }
56
+ return found
57
+ }
58
+
59
+ function safeIsFile(path) {
60
+ try {
61
+ return statSync(path).isFile()
62
+ } catch {
63
+ return false
64
+ }
65
+ }
66
+
67
+ /** 渐进披露第一层的字符数:name + description + whenToUse,不含正文。 */
68
+ export function announcementChars(meta) {
69
+ const parts = [meta.name ?? '', meta.description ?? '', meta.whenToUse ?? '']
70
+ return parts.reduce((sum, part) => sum + [...part].length, 0)
71
+ }
72
+
73
+ /**
74
+ * 扫描全部根,产出 SkillObservation[](尚未做遮蔽判定)。
75
+ * registrySummaries 是官方 `ctx.skills.list()` 的结果,用于补齐 provider-file / virtual。
76
+ */
77
+ export function observeSkills({ roots, registrySummaries = [] }) {
78
+ const observations = []
79
+ const scanned = new Map() // name -> observation
80
+
81
+ for (const root of filterExistingRoots(roots)) {
82
+ for (const hit of scanRoot(root)) {
83
+ let text
84
+ try {
85
+ text = readFileSync(hit.path, 'utf8')
86
+ } catch {
87
+ continue
88
+ }
89
+ const meta = extractSkillMeta(text)
90
+ const name = meta.name !== '' ? meta.name : hit.name
91
+
92
+ const observation = {
93
+ name,
94
+ description: meta.description,
95
+ ...meta.whenToUse === undefined ? {} : { whenToUse: meta.whenToUse },
96
+ source: root.source,
97
+ rank: root.rank,
98
+ path: hit.path,
99
+ fileState: FILE_STATE.EDITABLE,
100
+ modelInvocable: !meta.disableModelInvocation,
101
+ announcementChars: announcementChars(meta),
102
+ }
103
+ observations.push(observation)
104
+ if (!scanned.has(name)) scanned.set(name, observation)
105
+ }
106
+ }
107
+
108
+ // 官方 registry 报了、我们没扫到的:区分 provider-file / virtual
109
+ for (const summary of registrySummaries) {
110
+ if (scanned.has(summary.name)) continue
111
+ const hasPath = typeof summary.path === 'string' && summary.path !== ''
112
+ observations.push({
113
+ name: summary.name,
114
+ description: summary.description ?? '',
115
+ ...summary.whenToUse === undefined ? {} : { whenToUse: summary.whenToUse },
116
+ source: typeof summary.source === 'string' ? summary.source : 'runtime',
117
+ rank: typeof summary.rank === 'number' ? summary.rank : Number.MAX_SAFE_INTEGER,
118
+ ...hasPath ? { path: summary.path } : {},
119
+ fileState: hasPath ? FILE_STATE.PROVIDER_FILE : FILE_STATE.VIRTUAL,
120
+ modelInvocable: summary.invocation?.model === true,
121
+ announcementChars: announcementChars({
122
+ name: summary.name,
123
+ description: summary.description,
124
+ whenToUse: summary.whenToUse,
125
+ }),
126
+ })
127
+ }
128
+
129
+ return observations
130
+ }
131
+
132
+ /**
133
+ * 该条目是否允许写操作。
134
+ * `provider-file` / `virtual` **一律不可写**(UI 层断言也依赖此谓词)。
135
+ */
136
+ export function isWritable(observation) {
137
+ return observation.fileState === FILE_STATE.EDITABLE && typeof observation.path === 'string'
138
+ }
139
+
140
+ /** 路径是否存在(用于确认扫描结果未过期)。 */
141
+ export function stillExists(observation) {
142
+ return typeof observation.path === 'string' && existsSync(observation.path)
143
+ }