dsh-requirement-dev-workbench 4.5.4 → 4.5.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 (4) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dsh/index.js +3475 -3018
  3. package/lib/client.js +338 -28
  4. package/package.json +65 -65
package/lib/client.js CHANGED
@@ -13,7 +13,7 @@ window.__ModuleLoader__.load({
13
13
  const { useCallback, useEffect, useMemo, useRef, useState } = React
14
14
 
15
15
  const API = '/api/requirement-dev-workbench'
16
- const WORKBENCH_VERSION = '4.5.4'
16
+ const WORKBENCH_VERSION = '4.5.8'
17
17
  const STYLE_ID = 'rdw-business-panel-styles'
18
18
 
19
19
  const CSS = `
@@ -294,6 +294,24 @@ window.__ModuleLoader__.load({
294
294
  return payload
295
295
  }
296
296
 
297
+ /**
298
+ * 工作台设置变了,通知同一窗口里的其它组件。
299
+ *
300
+ * 「对话输入框的 + 专家」和工作台是同一个 bundle 里的两个独立组件实例:
301
+ * 在工作台里选了专家,输入框那个入口的按钮和面板并不知道,会一直显示旧角色,
302
+ * 直到它自己重新读一次。这里用一个自定义事件把它们串起来(同窗口、不需宿主支持)。
303
+ */
304
+ const SETTINGS_EVENT = 'rdw:settings-changed'
305
+ function notifySettingsChanged(patch) {
306
+ try {
307
+ if (typeof window === 'undefined' || typeof window.dispatchEvent !== 'function') return
308
+ if (typeof CustomEvent !== 'function') return
309
+ window.dispatchEvent(new CustomEvent(SETTINGS_EVENT, { detail: patch ?? {} }))
310
+ } catch {
311
+ /* 只是通知,失败不影响保存本身 */
312
+ }
313
+ }
314
+
297
315
  /**
298
316
  * 界面自检上报(best-effort,失败不影响用):把详情分栏的真实几何报给本机服务端,
299
317
  * 排障时直接读 GET /ui/metrics 就能看到「内容区多宽、拖拽条在不在、按了几次」。
@@ -1021,7 +1039,7 @@ window.__ModuleLoader__.load({
1021
1039
  return `这张表当前 0 条${noun}(已成功读取,表内暂无记录)`
1022
1040
  }
1023
1041
 
1024
- function TableModule({ state, reloadState, uiWorkspace, table, view, saveView, runs, handOff, onUpdateRun, onOpenTable, onAddModule, expertData, reloadExperts }) {
1042
+ function TableModule({ state, reloadState, uiWorkspace, table, view, saveView, runs, handOff, onUpdateRun, onOpenTable, onAddModule, expertData, reloadExperts, settingsOnly = false, onCloseSettings, onSavedSettings }) {
1025
1043
  const [data, setData] = useState({ configured: false, items: [] })
1026
1044
  const [schema, setSchema] = useState(null)
1027
1045
  const [loading, setLoading] = useState(false)
@@ -1389,7 +1407,9 @@ window.__ModuleLoader__.load({
1389
1407
  setToast('')
1390
1408
  try {
1391
1409
  await api('/settings', { method: 'POST', body: JSON.stringify(patch) })
1410
+ notifySettingsChanged(patch)
1392
1411
  await reloadState()
1412
+ await onSavedSettings?.(patch)
1393
1413
  setToast('已保存')
1394
1414
  setShowSettings(false)
1395
1415
  load()
@@ -1424,6 +1444,7 @@ window.__ModuleLoader__.load({
1424
1444
 
1425
1445
  /** 回写飞书一律先弹页面确认,确认后才真的写。 */
1426
1446
  const askWriteBack = (recordId, status, field, title) => {
1447
+ if (table?.readOnly) return
1427
1448
  const type = (schemaFields ?? []).find((entry) => entry.name === field)?.type ?? ''
1428
1449
  setPendingWrite({ recordId, status, field: field || groupField, fieldType: type, title: title || '', kind: 'status' })
1429
1450
  setFailure(null)
@@ -1436,7 +1457,7 @@ window.__ModuleLoader__.load({
1436
1457
  try {
1437
1458
  await api('/requirement/status', {
1438
1459
  method: 'POST',
1439
- body: JSON.stringify({ recordId: pending.recordId, status: pending.status, field: pending.field, fieldType: pending.fieldType }),
1460
+ body: JSON.stringify({ tableKey, recordId: pending.recordId, status: pending.status, field: pending.field, fieldType: pending.fieldType }),
1440
1461
  })
1441
1462
  setToast(`已把「${pending.field}」回写为「${pending.status}」`)
1442
1463
  } catch (error) {
@@ -1501,10 +1522,11 @@ window.__ModuleLoader__.load({
1501
1522
  const settingsView = h(SettingsView, {
1502
1523
  settings,
1503
1524
  sources,
1525
+ failure: failure?.message,
1504
1526
  larkCli: state?.larkCli,
1505
1527
  chooseDirectory,
1506
1528
  onReloadSources: loadSources,
1507
- onCancel: () => setShowSettings(false),
1529
+ onCancel: onCloseSettings ?? (() => setShowSettings(false)),
1508
1530
  onSave: saveSettings,
1509
1531
  })
1510
1532
  // 设置页是「提前 return」的独立分支:目录选择弹窗必须挂在这一层,
@@ -1872,7 +1894,7 @@ window.__ModuleLoader__.load({
1872
1894
  instruction,
1873
1895
  setInstruction,
1874
1896
  copyInstruction,
1875
- writeBack,
1897
+ writeBack: table?.readOnly ? null : writeBack,
1876
1898
  chooseDirectory,
1877
1899
  runs: itemRuns,
1878
1900
  onUpdateRun,
@@ -2088,7 +2110,15 @@ window.__ModuleLoader__.load({
2088
2110
  )
2089
2111
  }
2090
2112
 
2091
- function SettingsView({ settings, sources, onCancel, onSave, larkCli, chooseDirectory, onReloadSources }) {
2113
+ function SettingsView({ settings, sources, failure, onCancel, onSave, larkCli, chooseDirectory, onReloadSources }) {
2114
+ const [remoteSource, setRemoteSource] = useState(null)
2115
+ useEffect(() => {
2116
+ let live = true
2117
+ api('/project-source')
2118
+ .then((result) => { if (live) setRemoteSource(result) })
2119
+ .catch(() => { if (live) setRemoteSource(null) })
2120
+ return () => { live = false }
2121
+ }, [])
2092
2122
  const [link, setLink] = useState(settings.baseToken ? `${settings.baseToken} ${settings.tableId}` : '')
2093
2123
  const [tableId, setTableId] = useState(settings.tableId ?? '')
2094
2124
  const [projectDir, setProjectDir] = useState(settings.projectDir ?? '')
@@ -2117,14 +2147,14 @@ window.__ModuleLoader__.load({
2117
2147
  h(Field, { label: '项目目录(绝对路径)', value: projectDir, placeholder: 'D:\\workspace\\your-project', onChange: setProjectDir }),
2118
2148
  h('div', { className: 'rdw-toolbar', style: { marginTop: 6 } }, h('button', { className: 'rdw-btn', onClick: chooseRoot, disabled: !chooseDirectory }, '用系统目录选择器挑选')),
2119
2149
  h('div', { className: 'rdw-note' }, '选好项目后,「技能与规范」会扫描它的 skill;如果项目里已经有需求源配置,会自动认出来。'),
2120
- h('div', { className: 'rdw-note' }, '口径:项目里的 .requirement-sources.json / .dev-task-sources.json 优先,这里填的坐标只在项目没有配置时生效。'),
2150
+ h('div', { className: 'rdw-note' }, '优先读取项目根目录的 sino-skill-config.json,未配置的类别仍可使用旧的独立配置文件。'),
2121
2151
  // v4.5.3:选到「没有需求源配置」的目录时(比如换成了另一个工程),以前只会在原地打转,
2122
2152
  // 看起来像「保存后没返回」。现在明确说清楚为什么看板读不到表,并给两条出路。
2123
2153
  sources && !detected.length
2124
2154
  ? h(
2125
2155
  'div',
2126
2156
  { className: 'rdw-note', style: { marginTop: 6, color: 'var(--dsw-alias-label-danger,#ff6b6b)' } },
2127
- '这个目录里没有 .requirement-sources.json / .dev-task-sources.json:看板读不到任何飞书表。把项目目录改回有配置的工程,或在下面第 2 块手动填表坐标再保存。',
2157
+ '没有检测到项目需求源(sino-skill-config.json 或 .requirement-sources.json)。要读取需求表,可配置项目需求源,或在下面手动填写表格链接。',
2128
2158
  )
2129
2159
  : null,
2130
2160
  ),
@@ -2132,6 +2162,7 @@ window.__ModuleLoader__.load({
2132
2162
  'div',
2133
2163
  { className: 'rdw-card', style: { marginTop: 12 } },
2134
2164
  h('h3', null, '2. 需求来源'),
2165
+ failure ? h('div', { className: 'rdw-error', role: 'alert' }, failure) : null,
2135
2166
  detected.length
2136
2167
  ? h(
2137
2168
  'div',
@@ -2151,14 +2182,32 @@ window.__ModuleLoader__.load({
2151
2182
  ),
2152
2183
  ),
2153
2184
  )
2154
- : h('div', { className: 'rdw-note' }, '项目里没有 .requirement-sources.json,下面手动填表格地址也可以。'),
2185
+ : h('div', { className: 'rdw-note' }, '项目没有可选的需求源。'),
2155
2186
  h(Field, {
2156
- label: '多维表格链接或 base_token(手动填写,选项目配置时可留空)',
2187
+ label: '多维表格链接或 base_token(手动填写,选项目配置时也可留空)',
2157
2188
  value: link,
2158
2189
  placeholder: 'https://xxx.feishu.cn/base/xxxx?table=tblxxxx',
2159
2190
  onChange: setLink,
2160
2191
  }),
2161
- h(Field, { label: '表名或 table_id', value: tableId, placeholder: '需求池 或 tblxxxx', onChange: setTableId }),
2192
+ remoteSource ? h(
2193
+ 'div',
2194
+ { style: { marginBottom: 8 } },
2195
+ h('div', { className: 'rdw-note' }, remoteSource.baseUrl ? `项目已保存的链接:${remoteSource.baseUrl}` : '还没有为这个项目单独保存链接。填好后点「保存并拉取需求」会写入本项目的 sino-skill-config.json。'),
2196
+ remoteSource.baseUrl
2197
+ ? h('button', {
2198
+ className: 'rdw-btn',
2199
+ onClick: async () => {
2200
+ try {
2201
+ await api('/project-source', { method: 'POST', body: JSON.stringify({ baseUrl: '', projectDir }) })
2202
+ await onSave({ projectDir: remoteSource.projectDir ?? projectDir })
2203
+ } catch (error) {
2204
+ setFailure(error.message)
2205
+ }
2206
+ },
2207
+ }, '清除本项目链接')
2208
+ : null,
2209
+ ) : null,
2210
+ h(Field, { label: '表名或 table_id(链接里已含 table 时可留空)', value: tableId, placeholder: 'tblxxxx', onChange: setTableId }),
2162
2211
  h('div', { className: 'rdw-note' }, `读取身份:${larkCli ? `lark-cli 就绪(${larkCli})` : 'lark-cli 未找到'} · 本工作台不保存飞书凭证。`),
2163
2212
  ),
2164
2213
  h(
@@ -2227,7 +2276,157 @@ window.__ModuleLoader__.load({
2227
2276
  }
2228
2277
 
2229
2278
  /**
2279
+ * 模块数据来源:每个模块自己一份飞书表链接。
2280
+ *
2281
+ * 以前只有一个「表格设置」,改一次链接所有模块都跟着变;现在链接挂在模块上(存 view.json),
2282
+ * 改这个模块只影响这个模块。留空即回到「跟着项目配置走」。
2283
+ */
2284
+ function ModuleSourceDialog({ moduleKey, moduleTitle, data, onClose, onSaved }) {
2285
+ const [link, setLink] = useState('')
2286
+ const [failure, setFailure] = useState('')
2287
+ const [busy, setBusy] = useState(false)
2288
+ const [notice, setNotice] = useState('')
2289
+ const [test, setTest] = useState(null)
2290
+ const [testing, setTesting] = useState(false)
2291
+ const [moduleDir, setModuleDir] = useState('')
2292
+ const [titleField, setTitleField] = useState('')
2293
+ const [rawField, setRawField] = useState('')
2294
+ const [optionNames, setOptionNames] = useState([])
2295
+ const loaded = data !== null
2296
+ useEffect(() => {
2297
+ if (!loaded) return
2298
+ setLink(String(data?.baseUrl ?? ''))
2299
+ setModuleDir(String(data?.ownProjectDir ?? ''))
2300
+ setTitleField(String(data?.fields?.title ?? ''))
2301
+ setRawField(String(data?.fields?.rawRequirement ?? ''))
2302
+ setTest(null)
2303
+ setFailure('')
2304
+ }, [loaded, data?.baseUrl, data?.moduleKey])
2305
+ useEffect(() => {
2306
+ if (!moduleKey) return
2307
+ let live = true
2308
+ api(`/fields?t=${encodeURIComponent(moduleKey)}`)
2309
+ .then((result) => { if (live) setOptionNames(Array.isArray(result?.names) ? result.names : []) })
2310
+ .catch(() => { if (live) setOptionNames([]) })
2311
+ return () => { live = false }
2312
+ }, [moduleKey, loaded])
2313
+ const save = async (baseUrl) => {
2314
+ setBusy(true)
2315
+ setFailure('')
2316
+ try {
2317
+ const fields = {}
2318
+ if (titleField.trim()) fields.title = titleField.trim()
2319
+ if (rawField.trim()) fields.rawRequirement = rawField.trim()
2320
+ await api('/module-source', { method: 'POST', body: JSON.stringify({ moduleKey, baseUrl, projectDir: moduleDir.trim(), fields: Object.keys(fields).length ? fields : null }) })
2321
+ setNotice(baseUrl ? '已保存到这个模块' : '已恢复为跟随项目配置')
2322
+ if (typeof onSaved === 'function') await onSaved()
2323
+ onClose()
2324
+ } catch (error) {
2325
+ setFailure(error.message)
2326
+ } finally {
2327
+ setBusy(false)
2328
+ }
2329
+ }
2330
+ const probe = async () => {
2331
+ setTesting(true)
2332
+ setTest(null)
2333
+ try {
2334
+ const result = await api(`/records?table=${encodeURIComponent(`module:${moduleKey}`)}&fresh=1`)
2335
+ setTest(
2336
+ result?.error
2337
+ ? { ok: false, text: `${result.error}${result.detail ? `:${String(result.detail).slice(0, 200)}` : ''}` }
2338
+ : { ok: true, text: `读到 ${result?.count ?? result?.items?.length ?? 0} 条记录(${result?.table?.tableId ?? ''})` },
2339
+ )
2340
+ } catch (error) {
2341
+ setTest({ ok: false, text: error.message })
2342
+ } finally {
2343
+ setTesting(false)
2344
+ }
2345
+ }
2346
+ return h(
2347
+ 'div',
2348
+ { className: 'rdw-mask', role: 'presentation', onClick: onClose },
2349
+ h(
2350
+ 'div',
2351
+ {
2352
+ className: 'rdw-modal',
2353
+ role: 'dialog',
2354
+ 'aria-modal': 'true',
2355
+ 'aria-label': `模块数据来源:${moduleTitle}`,
2356
+ style: { width: 'min(560px,94vw)' },
2357
+ onClick: (event) => event.stopPropagation(),
2358
+ },
2359
+ h(
2360
+ 'div',
2361
+ { className: 'rdw-modal-head' },
2362
+ h('strong', null, `数据来源 · ${moduleTitle}`),
2363
+ h('span', { className: 'rdw-grow' }),
2364
+ h('button', { className: 'rdw-btn', onClick: onClose }, '关闭'),
2365
+ ),
2366
+ !loaded
2367
+ ? h('div', { className: 'rdw-note' }, data?.error ? `读取失败:${data.error}` : '读取中…')
2368
+ : h(
2369
+ 'div',
2370
+ null,
2371
+ h('div', { className: 'rdw-note', style: { marginBottom: 8 } },
2372
+ '这个链接只属于当前模块:别的模块、别的项目都不会跟着变。留空则跟随「项目配置」(sino-skill-config.json)。'),
2373
+ h(Field, {
2374
+ label: '这个模块的多维表格链接',
2375
+ value: link,
2376
+ placeholder: 'https://xxx.feishu.cn/base/xxxx?table=tblxxxx',
2377
+ onChange: (value) => {
2378
+ setLink(value)
2379
+ setTest(null)
2380
+ },
2381
+ }),
2382
+ h(Field, {
2383
+ label: '这个模块的项目目录(留空 = 跟随当前项目)',
2384
+ value: moduleDir,
2385
+ placeholder: data.projectDir || 'D:\\workspace\\your-project',
2386
+ onChange: setModuleDir,
2387
+ }),
2388
+ h('div', { className: 'rdw-note' },
2389
+ `读取身份:${data.identity || 'bot'}${data.readOnly ? ' · 只读' : ''} · 同一个工作台里每个模块各存各的链接与目录,互不牵动。`),
2390
+ loaded && data?.resolved
2391
+ ? h('div', { className: 'rdw-note' }, `当前实际读取:${data.resolved.tableId}${data.resolved.label ? `(${data.resolved.label})` : ''}`)
2392
+ : h('div', { className: 'rdw-note' }, '当前跟随项目配置。'),
2393
+ h('div', { className: 'rdw-note', style: { marginTop: 10 } },
2394
+ '字段映射(可选):手填「标题」与「原始需求」的真实列名,模块就按这两列显示。'),
2395
+ h(Field, {
2396
+ label: '标题字段(默认按 页面/标题 自动认)',
2397
+ value: titleField,
2398
+ placeholder: '页面',
2399
+ onChange: setTitleField,
2400
+ }),
2401
+ h(Field, {
2402
+ label: '原始需求字段(详情里展示的那一列)',
2403
+ value: rawField,
2404
+ placeholder: '需求|方案|问题',
2405
+ onChange: setRawField,
2406
+ }),
2407
+ optionNames.length
2408
+ ? h('div', { className: 'rdw-note' }, `这张表已有的列:${optionNames.slice(0, 24).join('、')}`)
2409
+ : null,
2410
+ failure ? h('div', { className: 'rdw-error', role: 'alert', style: { marginTop: 8 } }, failure) : null,
2411
+ notice ? h('div', { className: 'rdw-note', style: { marginTop: 8 } }, notice) : null,
2412
+ test ? h('div', { className: 'rdw-note', style: { marginTop: 8, color: test.ok ? undefined : 'var(--dsw-alias-label-danger,#ff6b6b)' } }, test.text) : null,
2413
+ h(
2414
+ 'div',
2415
+ { className: 'rdw-toolbar', style: { marginTop: 12 } },
2416
+ h('button', { className: 'rdw-btn primary', disabled: busy, onClick: () => save(link.trim()) }, busy ? '保存中…' : '保存到这个模块'),
2417
+ h('button', { className: 'rdw-btn', disabled: busy || !link.trim(), onClick: () => save('') }, '改为跟随项目'),
2418
+ h('span', { className: 'rdw-grow' }),
2419
+ h('button', { className: 'rdw-btn', disabled: testing || !link.trim(), onClick: probe }, testing ? '读取中…' : '先试着读一次'),
2420
+ ),
2421
+ ),
2422
+ ),
2423
+ )
2424
+ }
2425
+
2426
+ /**
2427
+ /**
2230
2428
  * 更新日志弹窗:左栏底部「vX.Y.Z · 更新日志」点开。
2429
+ *
2231
2430
  * 内容来自包内 CHANGELOG.md(走 /changelog 接口解析成 sections),
2232
2431
  * 只读不写;当前版本那一段标「当前版本」并默认展开在顶部。
2233
2432
  */
@@ -2387,12 +2586,12 @@ window.__ModuleLoader__.load({
2387
2586
  h(
2388
2587
  'div',
2389
2588
  { style: { marginTop: 14 } },
2390
- h('div', { className: 'rdw-note' }, '回写飞书状态(可选)'),
2391
- h(
2589
+ h('div', { className: 'rdw-note' }, writeBack ? '回写飞书状态(可选)' : '飞书来源:只读'),
2590
+ writeBack ? h(
2392
2591
  'div',
2393
2592
  { className: 'rdw-toolbar', style: { marginTop: 6 } },
2394
2593
  ...statuses.map((status) => h('button', { key: status, className: 'rdw-btn', onClick: () => writeBack(status) }, status)),
2395
- ),
2594
+ ) : null,
2396
2595
  ),
2397
2596
  h(
2398
2597
  'div',
@@ -2809,6 +3008,7 @@ window.__ModuleLoader__.load({
2809
3008
 
2810
3009
  const pick = async (value) => {
2811
3010
  await api('/settings', { method: 'POST', body: JSON.stringify({ expert: value }) })
3011
+ notifySettingsChanged({ expert: value })
2812
3012
  setToast(value ? '已选中:以后交付给 AI 会自动带上这个角色' : '已改为「不用专家」')
2813
3013
  if (reloadState) await reloadState()
2814
3014
  if (reloadExperts) await reloadExperts()
@@ -4767,6 +4967,21 @@ window.__ModuleLoader__.load({
4767
4967
  setChangelog({ found: false, sections: [], error: error.message })
4768
4968
  }
4769
4969
  }, [changelog])
4970
+ // 「模块数据来源」对话框:每个模块各自一份,openSource 时读该模块当前绑定的表。
4971
+ const [sourceFor, setSourceFor] = useState('')
4972
+ const [sourceDialog, setSourceDialog] = useState(null)
4973
+ const reloadSources = useCallback(async (moduleKey) => {
4974
+ try {
4975
+ setSourceDialog(await api(`/module-source?module=${encodeURIComponent(moduleKey)}`))
4976
+ } catch (error) {
4977
+ setSourceDialog({ error: error.message, moduleKey })
4978
+ }
4979
+ }, [])
4980
+ useEffect(() => {
4981
+ if (!sourceFor) return
4982
+ setSourceDialog(null)
4983
+ void reloadSources(sourceFor)
4984
+ }, [sourceFor, reloadSources])
4770
4985
  const renameModule = useCallback(
4771
4986
  async (key, title) => {
4772
4987
  const trimmed = String(title ?? '').trim()
@@ -4850,7 +5065,12 @@ window.__ModuleLoader__.load({
4850
5065
  { kind: 'experts', id: 'experts', glyph: '🎓', label: '专家与专家团' },
4851
5066
  ]
4852
5067
  for (const module of view?.modules?.length ? view.modules : defaultModules(tables)) {
4853
- const table = tables.find((entry) => entry.key === module.tableKey)
5068
+ // 模块自带的表用模块 key 当表 key(服务端 /fields、/records 都按它精确取),
5069
+ // 否则原来配的那张项目表被换掉后,模块会去借别的表甚至找不到表。
5070
+ const ownSource = module.source ? module.sourceResolved ?? module.source : null
5071
+ const table = (ownSource
5072
+ ? { key: module.key, label: ownSource.label || ownSource.tableName || module.title, kind: ownSource.readOnly ? 'task' : 'requirement', own: true }
5073
+ : null) ?? tables.find((entry) => entry.key === module.tableKey)
4854
5074
  list.push({
4855
5075
  kind: 'table',
4856
5076
  id: module.key,
@@ -5065,6 +5285,22 @@ window.__ModuleLoader__.load({
5065
5285
  '✎',
5066
5286
  )
5067
5287
  : null,
5288
+ entry.kind === 'table' && renamingId !== entry.id
5289
+ ? h(
5290
+ 'button',
5291
+ {
5292
+ className: 'rdw-mod-edit',
5293
+ title: `设置这个模块的飞书表格:${entry.label}`,
5294
+ 'aria-label': `设置数据来源:${entry.label}`,
5295
+ onClick: (event) => {
5296
+ event.stopPropagation()
5297
+ setSourceFor(entry.id)
5298
+ setActive(entry.id)
5299
+ },
5300
+ },
5301
+ '🔗',
5302
+ )
5303
+ : null,
5068
5304
  ),
5069
5305
  ),
5070
5306
  h(
@@ -5139,9 +5375,18 @@ window.__ModuleLoader__.load({
5139
5375
  : h(TableModule, {
5140
5376
  // key 里带上「配置好了没」:从设置页回到内容区时重建一次,
5141
5377
  // 宽度测量才挂得到新出现的容器上(否则窄内容区的详情让位不会生效)。
5142
- key: `${activeEntry?.id}:${state?.configured ? 'ready' : 'setup'}`,
5378
+ key: `${activeEntry?.id}:${state?.configured ? 'ready' : 'setup'}:${state?.settings?.projectDir ?? ''}`,
5143
5379
  state,
5144
5380
  reloadState,
5381
+ settingsOnly: activeEntry?.kind === 'settings',
5382
+ onCloseSettings: activeEntry?.kind === 'settings' ? () => setActive('overview') : undefined,
5383
+ onSavedSettings: async (patch) => {
5384
+ await reloadTables()
5385
+ if (Object.hasOwn(patch, 'baseInput')) {
5386
+ if (activeEntry?.kind === 'settings') setActive('overview')
5387
+ await loadOverview(true)
5388
+ }
5389
+ },
5145
5390
  uiWorkspace,
5146
5391
  table: activeEntry?.table,
5147
5392
  view: sliceForTable(view, activeEntry?.module?.tableKey ?? ''),
@@ -5169,6 +5414,23 @@ window.__ModuleLoader__.load({
5169
5414
  showConversation ? (frameActive && conversation ? conversation : h('div', { className: 'rdw-note', style: { padding: 12 } }, '宿主没有提供对话区;可以改成用左侧原来的对话窗口。')) : null,
5170
5415
  ),
5171
5416
  changelogOpen ? h(ChangelogDialog, { data: changelog, current: WORKBENCH_VERSION, onClose: () => setChangelogOpen(false) }) : null,
5417
+ sourceFor
5418
+ ? h(ModuleSourceDialog, {
5419
+ key: sourceFor,
5420
+ moduleKey: sourceFor,
5421
+ moduleTitle: railModules.find((entry) => entry.id === sourceFor)?.label ?? sourceFor,
5422
+ data: sourceDialog,
5423
+ onClose: () => {
5424
+ setSourceFor('')
5425
+ setSourceDialog(null)
5426
+ },
5427
+ onSaved: async () => {
5428
+ await reloadTables()
5429
+ await reloadView()
5430
+ await loadOverview(true)
5431
+ },
5432
+ })
5433
+ : null,
5172
5434
  ])
5173
5435
  }
5174
5436
 
@@ -5185,10 +5447,14 @@ window.__ModuleLoader__.load({
5185
5447
  * 这里的 ctx.slots 用嵌套 inject + try/catch 拿:宿主没提供 slots 时工作台本体照常可用。
5186
5448
  */
5187
5449
  function ExpertComposerEntry(props) {
5450
+ // 输入框入口可独立挂载,不能依赖用户先打开 BusinessPanel 才加载样式。
5451
+ ensureStyles()
5188
5452
  const [open, setOpen] = useState(false)
5189
5453
  const [data, setData] = useState(null)
5190
5454
  const [failure, setFailure] = useState('')
5191
5455
  const [status, setStatus] = useState('')
5456
+ // 读取状态放在状态序列最后(前面的下标被自测注入依赖,别插在中间)
5457
+ const [loading, setLoading] = useState(false)
5192
5458
  const rootRef = useRef(null)
5193
5459
  const inputActions = props?.inputActions
5194
5460
  const sessionId = props?.sessionId
@@ -5209,6 +5475,36 @@ window.__ModuleLoader__.load({
5209
5475
  // eslint-disable-next-line react-hooks/exhaustive-deps
5210
5476
  }, [sessionId])
5211
5477
 
5478
+ // v4.5.5:挂载就先读一次专家。以前只在「点开面板」时才读,第一次点开必然是空列表,
5479
+ // 面板就先画出「还没有专家……」——看起来就是「第一次打开展示不对」,等几百毫秒才变对。
5480
+ useEffect(() => {
5481
+ void load({ force: true })
5482
+ return undefined
5483
+ // eslint-disable-next-line react-hooks/exhaustive-deps
5484
+ }, [])
5485
+
5486
+ // 工作台里换了专家/专家团(同一个窗口的自定义事件):按钮上的角色要立刻跟着变。
5487
+ useEffect(() => {
5488
+ if (typeof window === 'undefined' || typeof window.addEventListener !== 'function') return undefined
5489
+ const onChanged = () => {
5490
+ void load({ force: true })
5491
+ }
5492
+ window.addEventListener(SETTINGS_EVENT, onChanged)
5493
+ return () => window.removeEventListener(SETTINGS_EVENT, onChanged)
5494
+ // eslint-disable-next-line react-hooks/exhaustive-deps
5495
+ }, [])
5496
+
5497
+ // 切回窗口时补一次(换了项目目录、或在别处改了设置,回来就是新的)
5498
+ useEffect(() => {
5499
+ if (typeof window === 'undefined' || typeof window.addEventListener !== 'function') return undefined
5500
+ const onFocus = () => {
5501
+ void load({ force: true })
5502
+ }
5503
+ window.addEventListener('focus', onFocus)
5504
+ return () => window.removeEventListener('focus', onFocus)
5505
+ // eslint-disable-next-line react-hooks/exhaustive-deps
5506
+ }, [])
5507
+
5212
5508
  // 点别处 / 按 Esc 收起面板
5213
5509
  useEffect(() => {
5214
5510
  if (!open || typeof document === 'undefined') return undefined
@@ -5226,10 +5522,14 @@ window.__ModuleLoader__.load({
5226
5522
  }
5227
5523
  }, [open])
5228
5524
 
5229
- const load = async () => {
5525
+ const load = async (options) => {
5526
+ const force = options?.force === true
5230
5527
  setStatus('')
5231
5528
  reportSession()
5232
- if (data) return data
5529
+ // v4.5.5:不再「读过一次就永久缓存」——宿主的对话输入框条目是常驻的,
5530
+ // 缓存住的话,工作台里换了专家、或项目目录变了,这里永远显示旧的。
5531
+ if (data && !force) return data
5532
+ setLoading(true)
5233
5533
  try {
5234
5534
  const next = await api('/experts')
5235
5535
  setData(next)
@@ -5237,6 +5537,8 @@ window.__ModuleLoader__.load({
5237
5537
  } catch (error) {
5238
5538
  setFailure(`读到专家列表失败:${error.message}`)
5239
5539
  return null
5540
+ } finally {
5541
+ setLoading(false)
5240
5542
  }
5241
5543
  }
5242
5544
 
@@ -5247,7 +5549,8 @@ window.__ModuleLoader__.load({
5247
5549
  }
5248
5550
  setFailure('')
5249
5551
  setOpen(true)
5250
- await load()
5552
+ // 每次打开都重读一次:已有列表照旧先显示(不闪空白),读到新的再换。
5553
+ await load({ force: true })
5251
5554
  }
5252
5555
 
5253
5556
  /**
@@ -5263,6 +5566,7 @@ window.__ModuleLoader__.load({
5263
5566
  const label = isNone ? '普通交付' : pick?.displayName || pick?.name || pick?.agentId || pick?.id || '专家'
5264
5567
  try {
5265
5568
  await api('/settings', { method: 'POST', body: JSON.stringify({ expert: value }) })
5569
+ notifySettingsChanged({ expert: value })
5266
5570
  } catch (error) {
5267
5571
  setFailure(`记下这个选择失败:${error.message}`)
5268
5572
  return
@@ -5270,7 +5574,7 @@ window.__ModuleLoader__.load({
5270
5574
  if (isNone) {
5271
5575
  setStatus('已改为「不用专家(普通交付)」:这轮按工作台默认的开发指令来')
5272
5576
  setOpen(false)
5273
- await load()
5577
+ await load({ force: true })
5274
5578
  return
5275
5579
  }
5276
5580
  const text = expertOpenerText(pick)
@@ -5285,7 +5589,7 @@ window.__ModuleLoader__.load({
5285
5589
  if (inserted) {
5286
5590
  setStatus(`已把《${label}》的开场白写进输入框,接着补一句你的需求就能开工`)
5287
5591
  setOpen(false)
5288
- await load()
5592
+ await load({ force: true })
5289
5593
  return
5290
5594
  }
5291
5595
  // 编辑器没接住(或宿主没给 inputActions):退回复制,结果不丢。
@@ -5296,7 +5600,7 @@ window.__ModuleLoader__.load({
5296
5600
  setStatus(`编辑器没接住,剪贴板也不可用,请手动复制:${text}`)
5297
5601
  }
5298
5602
  setOpen(false)
5299
- await load()
5603
+ await load({ force: true })
5300
5604
  }
5301
5605
 
5302
5606
  const selected = String((data?.selected ?? '') || '')
@@ -5370,11 +5674,17 @@ window.__ModuleLoader__.load({
5370
5674
  ),
5371
5675
  experts.length || teams.length
5372
5676
  ? null
5373
- : h(
5374
- 'div',
5375
- { className: 'rdw-expert-option-note', style: { padding: '6px 8px' } },
5376
- '还没有专家。在「AI Native 工作台 · 专家与专家团」里点「+ 新建专家」写一位,回到这里刷新即可。',
5377
- ),
5677
+ : loading || !data
5678
+ ? h(
5679
+ 'div',
5680
+ { className: 'rdw-expert-option-note', style: { padding: '6px 8px' } },
5681
+ '正在读取专家与专家团…',
5682
+ )
5683
+ : h(
5684
+ 'div',
5685
+ { className: 'rdw-expert-option-note', style: { padding: '6px 8px' } },
5686
+ '还没有专家。在「AI Native 工作台 · 专家与专家团」里点「+ 新建专家」写一位,回到这里刷新即可。',
5687
+ ),
5378
5688
  ),
5379
5689
  status ? h('div', { className: 'rdw-expert-pop-foot' }, status) : null,
5380
5690
  failure ? h('div', { className: 'rdw-expert-pop-foot is-error' }, failure) : null,
@@ -5551,7 +5861,7 @@ window.__ModuleLoader__.load({
5551
5861
  // Desktop 上有它就优先用(apply 里按需检测),没有就走原生 main 面板。
5552
5862
  inject: [],
5553
5863
  // 自测钩子:给 test/smoke.mjs 直接跑组件函数体与纯函数用;宿主只读 apply/inject,多余的键会被忽略。
5554
- __components: { BusinessPanel, TableModule, OverviewModule, ModuleDialog, DetailView, ChangelogDialog, ViewConfigPanel, SettingsView, SkillsModule, DevModule, ExpertsModule, ExpertComposerEntry, FlowModule, DocsModule, DirectoryPickerDialog },
5864
+ __components: { BusinessPanel, TableModule, OverviewModule, ModuleDialog, ModuleSourceDialog, DetailView, ChangelogDialog, ViewConfigPanel, SettingsView, SkillsModule, DevModule, ExpertsModule, ExpertComposerEntry, FlowModule, DocsModule, DirectoryPickerDialog },
5555
5865
  __pure: {
5556
5866
  summarizeBuckets,
5557
5867
  runBadge,