@cheemsup/dsh-plugin-console 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,60 @@
1
+ /**
2
+ * 会话日志里 `user/message.source.kind` → 产出它的包。
3
+ *
4
+ * 这是**推断**,不是注册表事实:宿主没有把「这条消息由谁注入」登记在任何
5
+ * 公开接口上,只能按已知的来源类型映射回包名。禁用预演用它回答「哪些运行时
6
+ * 消息可能不再注入」,因此调用方必须把结果标成「推断」。
7
+ *
8
+ * 抽成独立模块而不是留在 `session-influence.js`:那边会拖进整个会话日志读取
9
+ * 链路,而禁用预演只需要这张静态表。
10
+ * @module dsh-plugin-console/host/injection-owners
11
+ */
12
+
13
+ /** source.kind → 产出它的包。没有映射的 kind 留空,由调用方标「未知」。 */
14
+ export const MESSAGE_INJECTION_OWNERS = {
15
+ 'runtime-context': ['@deepseek-ai/dsh-agent-loop'],
16
+ 'time-context': ['@deepseek-ai/dsh-time-context'],
17
+ 'skill-catalog': ['@deepseek-ai/dsh-tool-skill'],
18
+ 'agent-message': ['@deepseek-ai/dsh-subagent'],
19
+ 'subagent-settled': ['@deepseek-ai/dsh-subagent'],
20
+ }
21
+
22
+ /** source.kind 的中文说明;界面只展示这个说法。 */
23
+ export const MESSAGE_INJECTION_LABELS = {
24
+ 'runtime-context': '运行时上下文',
25
+ 'time-context': '时间上下文',
26
+ 'skill-catalog': 'skill 目录',
27
+ 'agent-message': '子 Agent 消息',
28
+ 'subagent-settled': '子 Agent 结束消息',
29
+ }
30
+
31
+ /** 去掉 scope 与子路径,得到裸包名。 */
32
+ function bareName(name) {
33
+ if (typeof name !== 'string') return ''
34
+ const parts = name.split('/')
35
+ return name.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0]
36
+ }
37
+
38
+ /**
39
+ * 一个条目可能负责的注入类型。
40
+ *
41
+ * 同时用包名与模块名匹配:Loader 行给的是模块说明符,包名是它的裸名;
42
+ * 子路径模块(`@scope/pkg/lib/x`)也归到同一包。
43
+ * @param {string | null | undefined} packageName - 条目包名。
44
+ * @param {string | null | undefined} moduleName - 条目模块说明符。
45
+ * @returns {Array<{sourceKind: string, label: string, owners: string[]}>} 匹配到的注入类型。
46
+ */
47
+ export function injectionKindsOf(packageName, moduleName) {
48
+ const candidates = new Set([bareName(packageName), bareName(moduleName)].filter((name) => name !== ''))
49
+ if (candidates.size === 0) return []
50
+ const rows = []
51
+ for (const [sourceKind, owners] of Object.entries(MESSAGE_INJECTION_OWNERS)) {
52
+ if (!owners.some((owner) => candidates.has(owner))) continue
53
+ rows.push({
54
+ sourceKind,
55
+ label: MESSAGE_INJECTION_LABELS[sourceKind] ?? sourceKind,
56
+ owners: [...owners],
57
+ })
58
+ }
59
+ return rows
60
+ }
@@ -0,0 +1,554 @@
1
+ /**
2
+ * patch 文件的 config 子树扫描与有限 YAML 解析。
3
+ *
4
+ * 为什么不直接用完整 YAML:本插件零依赖,而这里要回答的问题很窄——
5
+ * 「某一层给这一行声明了哪些 config 键、值是什么」。因此只实现 DSH 组合
6
+ * 文件实际出现的块式写法;遇到块标量、锚点、跨行流式值这类不支持的构造,
7
+ * 保留原文并标记 `parsed:false`,**不猜一个看起来合理的值**。
8
+ *
9
+ * 与 `patch-scan.js` 的分工:那边只回答「被谁、改了哪些顶层键」,是快照的
10
+ * 轻量事实;这里回答「改成了什么」,只在禁用预演按需读取一个目标行。
11
+ * 两套扫描器独立演进,`verify-patch-config.mjs` 用同一份样例断言 id、类型与
12
+ * 顶层键名一致,防止语义悄悄分叉。
13
+ * @module dsh-plugin-console/host/patch-config
14
+ */
15
+
16
+ /** 单个 patch 文件最多扫描的行数;超出只保留已读到的行。 */
17
+ const MAX_LINES = 2000
18
+ /** 单个标量的展示上限;超出截断并给行标 truncated。 */
19
+ const MAX_VALUE_TEXT = 2000
20
+ /** config 的最大嵌套深度。 */
21
+ const MAX_DEPTH = 8
22
+ /** 单个 config 子树的节点上限。 */
23
+ const MAX_NODES = 2000
24
+
25
+ /** 解析失败:patch 里出现了本页刻意不支持的写法。 */
26
+ class PatchParseError extends Error {}
27
+
28
+ /**
29
+ * 去掉行尾注释。
30
+ *
31
+ * 只在引号外、且 `#` 前面是空白时截断——`url: a#b` 里的 `#` 是值的一部分。
32
+ * @param {string} raw - 原始行。
33
+ * @returns {string} 去掉注释后的行。
34
+ */
35
+ function stripComment(raw) {
36
+ let quote = null
37
+ for (let index = 0; index < raw.length; index++) {
38
+ const char = raw[index]
39
+ if (quote !== null) {
40
+ if (char === '\\' && quote === '"') {
41
+ index++
42
+ continue
43
+ }
44
+ if (char === quote) quote = null
45
+ continue
46
+ }
47
+ if (char === '"' || char === "'") {
48
+ quote = char
49
+ continue
50
+ }
51
+ if (char === '#' && (index === 0 || /\s/.test(raw[index - 1]))) return raw.slice(0, index)
52
+ }
53
+ return raw
54
+ }
55
+
56
+ /** 去掉键两端的引号;只处理 patch 里常见的写法。 */
57
+ function unquoteKey(text) {
58
+ const trimmed = text.trim()
59
+ if (trimmed.length >= 2 && trimmed.startsWith('"') && trimmed.endsWith('"')) {
60
+ return trimmed.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\')
61
+ }
62
+ if (trimmed.length >= 2 && trimmed.startsWith("'") && trimmed.endsWith("'")) {
63
+ return trimmed.slice(1, -1).replace(/''/g, "'")
64
+ }
65
+ return trimmed
66
+ }
67
+
68
+ /**
69
+ * 切出 `key: value`。
70
+ *
71
+ * 分隔符是引号外的第一个 `:`,且它后面必须是空白或行尾——否则
72
+ * `url: https://x` 会被从协议名处切开。
73
+ * @param {string} text - 已去掉注释的正文(不含列表前缀)。
74
+ * @returns {{key: string, rest: string} | null} 键与剩余文本。
75
+ */
76
+ function splitKey(text) {
77
+ let quote = null
78
+ for (let index = 0; index < text.length; index++) {
79
+ const char = text[index]
80
+ if (quote !== null) {
81
+ if (char === '\\' && quote === '"') {
82
+ index++
83
+ continue
84
+ }
85
+ if (char === quote) quote = null
86
+ continue
87
+ }
88
+ if (char === '"' || char === "'") {
89
+ quote = char
90
+ continue
91
+ }
92
+ if (char !== ':') continue
93
+ const rest = text.slice(index + 1)
94
+ if (rest !== '' && !/^\s/.test(rest)) continue
95
+ const key = unquoteKey(text.slice(0, index))
96
+ if (key === '') return null
97
+ return { key, rest: rest.trim() }
98
+ }
99
+ return null
100
+ }
101
+
102
+ /**
103
+ * 解析一个标量文本。
104
+ *
105
+ * 引号、布尔、null 与数字按 YAML 的常见语义;其余原样当字符串。
106
+ * @param {string} text - 标量文本。
107
+ * @returns {unknown} 解析结果。
108
+ */
109
+ function parseScalarToken(text) {
110
+ const value = text.trim()
111
+ if (value === '' ) return null
112
+ if (value.startsWith('"')) {
113
+ if (!value.endsWith('"') || value.length < 2) throw new PatchParseError('双引号未闭合')
114
+ return value.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\')
115
+ }
116
+ if (value.startsWith("'")) {
117
+ if (!value.endsWith("'") || value.length < 2) throw new PatchParseError('单引号未闭合')
118
+ return value.slice(1, -1).replace(/''/g, "'")
119
+ }
120
+ if (/^(null|~)$/i.test(value)) return null
121
+ if (/^true$/i.test(value)) return true
122
+ if (/^false$/i.test(value)) return false
123
+ if (/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/.test(value)) return Number(value)
124
+ return value
125
+ }
126
+
127
+ /**
128
+ * 解析流式值 `[a, b]` / `{a: b}`。
129
+ *
130
+ * 只支持单行、可嵌套的写法;跨行流式值属于不支持的构造。
131
+ * @param {string} text - 以 `[` 或 `{` 开头的文本。
132
+ * @param {number} line - 行号,用于错误信息。
133
+ * @returns {unknown} 解析结果。
134
+ */
135
+ function parseFlow(text, line) {
136
+ let index = 0
137
+ const fail = (why) => {
138
+ throw new PatchParseError(`第 ${line} 行的流式值无法解析:${why}`)
139
+ }
140
+ const skip = () => {
141
+ while (index < text.length && /\s/.test(text[index])) index++
142
+ }
143
+
144
+ /** 读一个带引号的字符串。 */
145
+ const readQuoted = () => {
146
+ const quote = text[index]
147
+ let out = ''
148
+ index++
149
+ while (index < text.length) {
150
+ const char = text[index]
151
+ if (char === '\\' && quote === '"') {
152
+ out += text[index + 1] ?? ''
153
+ index += 2
154
+ continue
155
+ }
156
+ if (char === quote) {
157
+ if (quote === "'" && text[index + 1] === "'") {
158
+ out += "'"
159
+ index += 2
160
+ continue
161
+ }
162
+ index++
163
+ return out
164
+ }
165
+ out += char
166
+ index++
167
+ }
168
+ fail('引号未闭合')
169
+ return ''
170
+ }
171
+
172
+ /** 流式 map 的键:允许引号,也允许到 `:` 为止的裸键。 */
173
+ const readKey = () => {
174
+ skip()
175
+ if (text[index] === '"' || text[index] === "'") return readQuoted()
176
+ const start = index
177
+ while (index < text.length && text[index] !== ':') index++
178
+ const key = text.slice(start, index).trim()
179
+ if (key === '') fail('缺少键名')
180
+ return key
181
+ }
182
+
183
+ const readNode = (depth) => {
184
+ if (depth > MAX_DEPTH) fail('嵌套过深')
185
+ skip()
186
+ const char = text[index]
187
+ if (char === '[') {
188
+ index++
189
+ const list = []
190
+ skip()
191
+ if (text[index] === ']') {
192
+ index++
193
+ return list
194
+ }
195
+ while (true) {
196
+ list.push(readNode(depth + 1))
197
+ skip()
198
+ if (text[index] === ',') {
199
+ index++
200
+ skip()
201
+ if (text[index] === ']') {
202
+ index++
203
+ return list
204
+ }
205
+ continue
206
+ }
207
+ if (text[index] === ']') {
208
+ index++
209
+ return list
210
+ }
211
+ fail('缺少 ]')
212
+ }
213
+ }
214
+ if (char === '{') {
215
+ index++
216
+ const map = {}
217
+ skip()
218
+ if (text[index] === '}') {
219
+ index++
220
+ return map
221
+ }
222
+ while (true) {
223
+ const key = readKey()
224
+ skip()
225
+ if (text[index] !== ':') fail('缺少 :')
226
+ index++
227
+ map[key] = readNode(depth + 1)
228
+ skip()
229
+ if (text[index] === ',') {
230
+ index++
231
+ skip()
232
+ if (text[index] === '}') {
233
+ index++
234
+ return map
235
+ }
236
+ continue
237
+ }
238
+ if (text[index] === '}') {
239
+ index++
240
+ return map
241
+ }
242
+ fail('缺少 }')
243
+ }
244
+ }
245
+ if (char === '"' || char === "'") return readQuoted()
246
+ const start = index
247
+ while (index < text.length && !',]}'.includes(text[index])) index++
248
+ return parseScalarToken(text.slice(start, index))
249
+ }
250
+
251
+ const value = readNode(1)
252
+ skip()
253
+ if (index !== text.length) fail('值后面还有多余内容')
254
+ return value
255
+ }
256
+
257
+ /**
258
+ * 解析一个值文本;不支持的构造直接抛错,由调用方整行降级。
259
+ * @param {string} text - 值文本。
260
+ * @param {number} line - 行号。
261
+ * @param {object} state - 截断/节点计数状态。
262
+ * @returns {unknown} 解析结果。
263
+ */
264
+ function parseValueText(text, line, state) {
265
+ const value = text.trim()
266
+ if (value === '') return null
267
+ if (/^[|>]/.test(value)) throw new PatchParseError(`第 ${line} 行使用了块标量,本页只保留原文`)
268
+ if (/^[&*!]/.test(value)) throw new PatchParseError(`第 ${line} 行使用了锚点、别名或标签,本页只保留原文`)
269
+ if (value.startsWith('[') || value.startsWith('{')) {
270
+ state.nodes++
271
+ if (state.nodes > MAX_NODES) throw new PatchParseError('config 节点过多,已截断')
272
+ return parseFlow(value, line)
273
+ }
274
+ return clipScalar(parseScalarToken(value), state)
275
+ }
276
+
277
+ /** 超长标量截断;只影响展示与比较,解析结果仍然是字符串。 */
278
+ function clipScalar(value, state) {
279
+ if (typeof value !== 'string' || value.length <= MAX_VALUE_TEXT) return value
280
+ state.truncated = true
281
+ return `${value.slice(0, MAX_VALUE_TEXT)}…(已截断,共 ${value.length} 字符)`
282
+ }
283
+
284
+ /**
285
+ * 解析一块缩进文本。
286
+ * @param {Array<{indent: number, text: string, line: number}>} lines - 块内行。
287
+ * @param {number} start - 起始下标。
288
+ * @param {number} indent - 该块的首行缩进。
289
+ * @param {number} depth - 当前深度。
290
+ * @param {object} state - 截断/节点计数状态。
291
+ * @returns {[unknown, number]} 解析值与该块之后的下标。
292
+ */
293
+ function parseBlock(lines, start, indent, depth, state) {
294
+ if (depth > MAX_DEPTH) throw new PatchParseError('config 嵌套过深')
295
+ const first = lines[start]
296
+ if (first.text === '-' || first.text.startsWith('- ')) {
297
+ return parseSequence(lines, start, indent, depth, state)
298
+ }
299
+ return parseMapping(lines, start, indent, depth, state)
300
+ }
301
+
302
+ /** 解析一个块式 map。 */
303
+ function parseMapping(lines, start, indent, depth, state) {
304
+ const map = {}
305
+ let index = start
306
+ while (index < lines.length) {
307
+ const line = lines[index]
308
+ if (line.indent < indent) break
309
+ if (line.indent > indent) throw new PatchParseError(`第 ${line.line} 行的缩进无法归入上一级`)
310
+ if (line.text === '-' || line.text.startsWith('- ')) break
311
+ const kv = splitKey(line.text)
312
+ if (kv === null) throw new PatchParseError(`第 ${line.line} 行不是键值对`)
313
+ state.nodes++
314
+ if (state.nodes > MAX_NODES) throw new PatchParseError('config 节点过多,已截断')
315
+ if (kv.rest === '') {
316
+ if (index + 1 < lines.length && lines[index + 1].indent > indent) {
317
+ const [child, next] = parseBlock(lines, index + 1, lines[index + 1].indent, depth + 1, state)
318
+ map[kv.key] = child
319
+ index = next
320
+ } else {
321
+ map[kv.key] = null
322
+ index++
323
+ }
324
+ continue
325
+ }
326
+ map[kv.key] = parseValueText(kv.rest, line.line, state)
327
+ index++
328
+ if (index < lines.length && lines[index].indent > indent) {
329
+ throw new PatchParseError(`第 ${lines[index].line} 行:标量后面还有子行`)
330
+ }
331
+ }
332
+ return [map, index]
333
+ }
334
+
335
+ /** 解析一个块式序列;序列项可以是标量或 map。 */
336
+ function parseSequence(lines, start, indent, depth, state) {
337
+ const list = []
338
+ let index = start
339
+ while (index < lines.length) {
340
+ const line = lines[index]
341
+ if (line.indent < indent) break
342
+ if (line.indent > indent) throw new PatchParseError(`第 ${line.line} 行的缩进无法归入上一级`)
343
+ if (!(line.text === '-' || line.text.startsWith('- '))) break
344
+ state.nodes++
345
+ if (state.nodes > MAX_NODES) throw new PatchParseError('config 节点过多,已截断')
346
+ const body = line.text === '-' ? '' : line.text.slice(2).trim()
347
+ if (body === '') {
348
+ if (index + 1 < lines.length && lines[index + 1].indent > indent) {
349
+ const [child, next] = parseBlock(lines, index + 1, lines[index + 1].indent, depth + 1, state)
350
+ list.push(child)
351
+ index = next
352
+ } else {
353
+ list.push(null)
354
+ index++
355
+ }
356
+ continue
357
+ }
358
+ const kv = splitKey(body)
359
+ if (kv === null) {
360
+ list.push(parseValueText(body, line.line, state))
361
+ index++
362
+ continue
363
+ }
364
+ const item = {}
365
+ index++
366
+ if (kv.rest === '') {
367
+ if (index < lines.length && lines[index].indent > indent) {
368
+ const [child, next] = parseBlock(lines, index, lines[index].indent, depth + 1, state)
369
+ item[kv.key] = child
370
+ index = next
371
+ } else {
372
+ item[kv.key] = null
373
+ }
374
+ } else {
375
+ item[kv.key] = parseValueText(kv.rest, line.line, state)
376
+ }
377
+ if (index < lines.length && lines[index].indent > indent) {
378
+ const [rest, next] = parseMapping(lines, index, lines[index].indent, depth + 1, state)
379
+ Object.assign(item, rest)
380
+ index = next
381
+ }
382
+ list.push(item)
383
+ }
384
+ return [list, index]
385
+ }
386
+
387
+ /** 从 config 块里按首层缩进抓键名;解析失败时用它回答「声明了哪些键」。 */
388
+ function topLevelKeys(lines, indent) {
389
+ const keys = []
390
+ for (const line of lines) {
391
+ if (line.indent !== indent) continue
392
+ const kv = splitKey(line.text)
393
+ if (kv !== null && !keys.includes(kv.key)) keys.push(kv.key)
394
+ }
395
+ return keys
396
+ }
397
+
398
+ /**
399
+ * 扫描一个 patch 文件的 config 子树。
400
+ *
401
+ * 每个 `- id:` 出现一次就是一条记录;同一 id 在一个文件里出现多次时保留
402
+ * 各自的 occurrence,不做合并——合并是「生效值」的事,覆盖链需要看到每一层。
403
+ * @param {string} text - patch 文件内容。
404
+ * @returns {{rows: Array<object>, diagnostics: string[]}} config 行与文件级诊断。
405
+ */
406
+ export function scanPatchConfig(text) {
407
+ const rawLines = String(text).split(/\r?\n/)
408
+ const diagnostics = []
409
+ if (rawLines.length > MAX_LINES) {
410
+ diagnostics.push(`文件超过 ${MAX_LINES} 行,只扫描前 ${MAX_LINES} 行`)
411
+ }
412
+ const lines = rawLines.slice(0, MAX_LINES)
413
+ /** @type {Array<object>} */
414
+ const rows = []
415
+ const occurrences = new Map()
416
+ let inserting = false
417
+ let current = null
418
+
419
+ /** 开始一条新行记录。 */
420
+ const startRow = (id, kind, line) => {
421
+ const occurrence = (occurrences.get(id) ?? 0) + 1
422
+ occurrences.set(id, occurrence)
423
+ const row = {
424
+ id,
425
+ kind,
426
+ line,
427
+ occurrence,
428
+ keys: [],
429
+ hasConfig: false,
430
+ configKeys: [],
431
+ configRaw: '',
432
+ parsed: true,
433
+ truncated: false,
434
+ }
435
+ rows.push(row)
436
+ return { row, keyIndent: null }
437
+ }
438
+
439
+ for (let index = 0; index < lines.length; index++) {
440
+ const raw = lines[index]
441
+ if (/^\s*\t/.test(raw)) diagnostics.push(`第 ${index + 1} 行含 tab 缩进;本页按原文逐行识别,可能漏键`)
442
+ const cleaned = stripComment(raw)
443
+ if (!cleaned.trim()) continue
444
+ const indent = cleaned.length - cleaned.trimStart().length
445
+ const body = cleaned.trim()
446
+
447
+ if (indent === 0) {
448
+ current = null
449
+ if (/^-?\s*insert\s*:/.test(body)) {
450
+ inserting = true
451
+ continue
452
+ }
453
+ const match = body.match(/^-\s*id\s*:\s*(.+)$/)
454
+ if (match !== null) {
455
+ inserting = false
456
+ current = startRow(unquoteKey(match[1]), 'override', index + 1)
457
+ current.keyIndent = indent + 2
458
+ }
459
+ continue
460
+ }
461
+
462
+ const idMatch = body.match(/^-\s*id\s*:\s*(.+)$/)
463
+ if (idMatch !== null && inserting) {
464
+ current = startRow(unquoteKey(idMatch[1]), 'insert', index + 1)
465
+ current.keyIndent = indent + 2
466
+ continue
467
+ }
468
+ if (idMatch !== null) {
469
+ current = null
470
+ continue
471
+ }
472
+ if (current === null) continue
473
+ current.keyIndent ??= indent
474
+ if (indent < current.keyIndent) {
475
+ current = null
476
+ continue
477
+ }
478
+ if (indent !== current.keyIndent) continue
479
+
480
+ const kv = splitKey(body)
481
+ if (kv === null || kv.key === 'id') continue
482
+ if (!current.row.keys.includes(kv.key)) current.row.keys.push(kv.key)
483
+ if (kv.key !== 'config') continue
484
+
485
+ current.row.hasConfig = true
486
+ // `config: {...}` 与 `config:` 两种写法都要认;后者收集子块。
487
+ if (kv.rest !== '') {
488
+ current.row.configRaw = kv.rest
489
+ const state = { nodes: 0, truncated: false }
490
+ try {
491
+ current.row.config = parseValueText(kv.rest, index + 1, state)
492
+ current.row.configKeys = current.row.config !== null && typeof current.row.config === 'object' && !Array.isArray(current.row.config)
493
+ ? Object.keys(current.row.config)
494
+ : []
495
+ current.row.truncated = state.truncated
496
+ } catch (cause) {
497
+ current.row.parsed = false
498
+ current.row.reason = cause instanceof Error ? cause.message : String(cause)
499
+ }
500
+ continue
501
+ }
502
+
503
+ const blockLines = []
504
+ const rawBlock = []
505
+ let next = index + 1
506
+ for (; next < lines.length; next++) {
507
+ const nested = stripComment(lines[next])
508
+ if (!nested.trim()) {
509
+ rawBlock.push(lines[next])
510
+ continue
511
+ }
512
+ const nestedIndent = nested.length - nested.trimStart().length
513
+ if (nestedIndent <= current.keyIndent) break
514
+ blockLines.push({ indent: nestedIndent, text: nested.trim(), line: next + 1 })
515
+ rawBlock.push(lines[next])
516
+ }
517
+ index = next - 1
518
+ current.row.configRaw = rawBlock.join('\n').trim()
519
+ if (blockLines.length === 0) {
520
+ current.row.config = {}
521
+ current.row.configKeys = []
522
+ current.row.emptyConfig = true
523
+ continue
524
+ }
525
+ const state = { nodes: 0, truncated: false }
526
+ const firstIndent = blockLines[0].indent
527
+ try {
528
+ const [config, after] = parseBlock(blockLines, 0, firstIndent, 1, state)
529
+ if (after < blockLines.length) throw new PatchParseError(`第 ${blockLines[after].line} 行无法归入 config 子树`)
530
+ current.row.config = config
531
+ current.row.configKeys = config !== null && typeof config === 'object' && !Array.isArray(config) ? Object.keys(config) : []
532
+ current.row.truncated = state.truncated
533
+ } catch (cause) {
534
+ current.row.parsed = false
535
+ current.row.reason = cause instanceof Error ? cause.message : String(cause)
536
+ current.row.configKeys = topLevelKeys(blockLines, firstIndent)
537
+ }
538
+ }
539
+
540
+ return { rows, diagnostics }
541
+ }
542
+
543
+ /**
544
+ * 解析一个独立的 YAML 值文本。
545
+ *
546
+ * 只给测试与流式值使用;不承诺完整 YAML 语义,不支持的构造会抛错。
547
+ * @param {string} text - 值文本。
548
+ * @returns {unknown} 解析结果。
549
+ */
550
+ export function parseYamlValue(text) {
551
+ const cleaned = stripComment(String(text)).trim()
552
+ if (cleaned === '') return null
553
+ return parseValueText(cleaned, 0, { nodes: 0, truncated: false })
554
+ }