dsh-ide-window 0.4.2 → 0.4.3

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.
package/AGENTS.md CHANGED
@@ -274,6 +274,7 @@ tail -f /tmp/dsh-ide-test/logs/dsh-ide-window.log # 自测实例
274
274
  - 文件树右键 Java/Kotlin 文件 → 解析 `@TableName` 发 `openTable`;编辑器符号右键 → Mapper 方法发 `openSql`(`@Select` 等注解优先,其次按 namespace 在 XML 里找 statement,动态 SQL 会带注释提示原文粘贴);
275
275
  - MyBatis 动态 SQL 会先转成可执行 SQL:`<foreach>` 展开 3 条默认值、`#{}`/`${}` 按方法签名里的参数类型填默认值(数字 `1`、字符串 `'demo'`、日期时间),SQL 头部注释列出默认参数;XML 的 `<if>/<where>/<set>/<trim>/<choose>` 会展开成静态 SQL。仍不自动执行,用户在数据窗口里改值后自己跑。
276
276
  - **`<include refid="..."/>` 会展开再拼**(`test/data-bridge.mjs` 有用例):同文件 `<sql id>`、跨命名空间的片段、嵌套 include、include 自带的 `<property>` 都解析;解析不到的 refid 在 SQL 里留 `/* include not found: x */` 并在头部注释列出,条件被吃光后剩下的空 `WHERE` 直接去掉——绝不给数据窗口一段 `WHERE` 后面直接 `ORDER BY` 的语法错误 SQL。
277
+ - **标签属性里的 `>` 不算标签结束**(踩过,用户截图:SQL 中间多出一行 `0">`):`<if test="billStatusList != null and billStatusList.size() > 0">` 这种写法遍地都是,用 `[^>]*>` 匹配开标签会在属性质里的 `>` 处截断,剩下的 ` 0">` 被当成 SQL。所以所有开标签(if/when/otherwise/where/set/trim/foreach/include 的 property/bind/sql/select/兜底清理)一律用引号感知的 `IDE_DATA_WINDOW_TAG_ATTRS`(`(?:"[^"]*"|'[^']*'|[^>"'])*`)拼正则,别再手写 `[^>]*>`
277
278
  - 本插件只解析、不执行 SQL;定位库、只读校验都在数据窗口与它的 Host 里。
278
279
 
279
280
  ### 4.4 与对话联动
@@ -333,6 +334,7 @@ tail -f /tmp/dsh-ide-test/logs/dsh-ide-window.log # 自测实例
333
334
  - `@` 两节:**文件与文件夹**(`workspaceFiles.list(sessionId, dir)`,`'.'` 是根、其余相对路径、条目只有 `{name,type}`)+ **对话**(按标题过滤其他会话,选中即切换悬浮卡的会话)
334
335
  - ↑/↓ 选、Enter/Tab 选中、Esc 关,目录**下钻**成 `@dir/`、文件变引用 chip、技能插入 `/<名字> `。菜单绝对定位在输入框上方(`.iw-float-input` 必须是 `position: relative`)
335
336
  - **浮层挂在触发器上**:会话列表从标题 ▾ 向下、权限与模型从各自 chip 向上。菜单曾是卡片的 flex 子节点,于是点模型菜单会跑到卡片顶部——现在 `useLayoutEffect` 按触发器与卡片的 rect 算出 `left/top` 或 `right/bottom`,再用内联样式粘上去(卡片可缩放,写死偏移会漂)。`useLayoutEffect` 要记得在 `build.mjs` 的解构里导出
337
+ - **会话模式(Agent 预设)也显示在输入区底行**:`mode` chip 放在权限 pill 与思考/模型 chip 之间,只展示不切换(切换仍在 DSH 里做)。值读 `session.projections` 的 `agentPreset` 投影(字符串;`projections.get` / `faceOf().getSnapshot()` / 会话快照三条兜底),订阅 `faceOf('agentPreset').subscribe` 跟着变;名字优先用预设自己的 `name`(自定义模式),内置预设(`standard/ptc/minimal/cordis`)借 DSH 自己的 `settings.agentPreset` 命名空间文案(`ctx.locale.bind('settings.agentPreset')` 的 `preset*Name`),拿不到再用本插件 `floatMode*` 兜底,最后才显示 id。预设列表来自 `ctx.remote.agentPresets.list()` 的 `value.presets`
336
338
  - **输入区 = DSH 的 composer**:一个 16px 圆角容器(内边距 `10px 10px 8px 14px`),里面是无边框 textarea(占位文案同 DSH)与底行 `+(圆形)/ 权限 pill(锁+文字+⌄)/ 空隙 / 思考等级 / 模型 chip / 圆形发送键(↑,运行中变 ■)`;引用是蓝色 chip,粘贴图片走剪贴板 `image/*`(≤4 张、单张 8 MB),发送 `prompt([image…, {text: refs + 正文}])`
337
339
  - **跟随当前会话(`floatFollow`,默认开,持久化)**:`ideFloatTargetSession(state)` 决定卡片展示哪个会话——跟随用 `state.sessionId`;关掉后用卡片自己的 `state.floatSessionId`(只本次进程有效),DSH 里怎么切都不动。卡片标题菜单里点会话:跟随时照旧 `openSession()`,不跟随时只 `store.setFloatSessionId()`(不动面板);不跟随时菜单顶部有「不跟随当前会话 · 在下面手动切换」提示。卡片里点「+ 新建会话」用 `pinnedAdoptRef` 收养新会话,避免不跟随时新建完还停在旧会话。重新打开跟随会清掉钉子
338
340
  - **表头**:`▾` 标题 **居中、16px、最多 20 个字**(超出加省略号,悬停给完整标题 + 工作区路径),标题颜色按**工作区**取色相(`ideFloatWorkspaceHue(path)` → `--iw-float-hue`,再和正文主色 `color-mix` 混,浅色/深色都压得住对比度);右侧 `+` 与 `–`/`×` 放在绝对定位的 `.iw-float-head-right` 里,标题才会在整条表头里真正居中
package/CHANGELOG.md CHANGED
@@ -6,6 +6,17 @@
6
6
  升级方式:DSH →「插件」→ 打开插件的「版本」区 →「检查更新」,或直接卸载后重新安装。
7
7
  (`link:` 本地安装不参与版本检查,拉取仓库即可。)
8
8
 
9
+ ## [0.4.3] — 2026-11-26
10
+
11
+ ### 新增
12
+
13
+ - **悬浮框显示当前会话的模式**:输入区底行(权限、思考、模型之间)新增模式 chip,值和 DSH 表头一致(标准模式 / PTC / 精简 / Cordis,自定义预设显示自己的名字),在 DSH 里换模式卡片立刻跟着变。
14
+
15
+ ### 修复
16
+
17
+ - **Mapper SQL 里多出一行 `0">`**:`<if test="list.size() > 0">` 这种属性里带 `>` 的标签,被当成在 `>` 处结束,剩下的 ` 0">` 落到 SQL 中间(在数据窗口里执行就报语法错误)。现在所有标签都按引号感知解析,属性里的 `>` 不再算标签结尾。
18
+ - **卡片里图片加载失败只剩一枚裂图标**:消息里的 `![](/tmp/xxx.jpg)` 如果文件已不存在,之前显示成裂图标 + 替代文字,看着像卡片坏了。现在换成一行「图片无法加载 · 文件名」,悬停显示完整路径;粘贴的附件图读取失败时同样给这行提示,不再永远停在灰色骨架。
19
+
9
20
  ## [0.4.2] — 2026-11-25
10
21
 
11
22
  ### 新增
package/client.js CHANGED
@@ -406,6 +406,12 @@ window.__ModuleLoader__.load({
406
406
  "floatAttachReference": "Reference the open file",
407
407
  "floatNeedsFile": "Open a file first",
408
408
  "floatPermission": "Permission",
409
+ "floatMode": "Mode",
410
+ "floatImageMissing": "Image unavailable",
411
+ "floatModeStandard": "Standard mode",
412
+ "floatModePtc": "PTC mode",
413
+ "floatModeMinimal": "Minimal mode",
414
+ "floatModeCordis": "Cordis mode",
409
415
  "floatPermissionReadOnly": "Read only",
410
416
  "floatPermissionWorkspace": "Workspace write",
411
417
  "floatPermissionFull": "Full access",
@@ -858,6 +864,12 @@ window.__ModuleLoader__.load({
858
864
  "floatAttachReference": "引用当前文件",
859
865
  "floatNeedsFile": "先打开一个文件",
860
866
  "floatPermission": "权限",
867
+ "floatMode": "模式",
868
+ "floatImageMissing": "图片无法加载",
869
+ "floatModeStandard": "标准模式",
870
+ "floatModePtc": "PTC 模式",
871
+ "floatModeMinimal": "精简模式",
872
+ "floatModeCordis": "Cordis 模式",
861
873
  "floatPermissionReadOnly": "仅可查看",
862
874
  "floatPermissionWorkspace": "工作区内修改",
863
875
  "floatPermissionFull": "完全权限",
@@ -2682,6 +2694,19 @@ html.iw-select-code .iw-code .iw-vision {
2682
2694
  var(--dsw-alias-label-primary, currentColor)
2683
2695
  );
2684
2696
  }
2697
+ .iw-float-mode {
2698
+ flex: 0 0 auto;
2699
+ max-width: 132px;
2700
+ overflow: hidden;
2701
+ text-overflow: ellipsis;
2702
+ white-space: nowrap;
2703
+ padding: 1px 7px;
2704
+ border-radius: var(--dsw-radius-sm, 6px);
2705
+ background: var(--dsw-alias-bg-layer-3, rgba(128, 128, 128, 0.12));
2706
+ color: var(--dsw-alias-label-secondary, inherit);
2707
+ font-size: 12.5px;
2708
+ line-height: 18px;
2709
+ }
2685
2710
  .iw-float-older {
2686
2711
  flex: 0 0 auto;
2687
2712
  padding: 2px 0 6px;
@@ -3002,6 +3027,38 @@ html.iw-select-code .iw-code .iw-vision {
3002
3027
  border-radius: 6px;
3003
3028
  border: 0.5px solid var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.1));
3004
3029
  }
3030
+ /* 图片文件不在了:一行说明,别只留一枚裂图标。 */
3031
+ .iw-float-img-missing {
3032
+ display: inline-flex;
3033
+ align-items: center;
3034
+ max-width: 100%;
3035
+ padding: 4px 10px;
3036
+ margin: 6px 0;
3037
+ border-radius: var(--dsw-radius-sm, 6px);
3038
+ background: var(--dsw-alias-bg-layer-3, rgba(128, 128, 128, 0.12));
3039
+ color: var(--dsw-alias-label-tertiary, inherit);
3040
+ font-size: 12.5px;
3041
+ line-height: 18px;
3042
+ overflow: hidden;
3043
+ text-overflow: ellipsis;
3044
+ white-space: nowrap;
3045
+ }
3046
+ .iw-float-pic-missing {
3047
+ display: flex;
3048
+ align-items: center;
3049
+ justify-content: center;
3050
+ max-width: 220px;
3051
+ min-height: 40px;
3052
+ padding: 6px 12px;
3053
+ border-radius: 8px;
3054
+ background: var(--dsw-alias-bg-layer-3, rgba(128, 128, 128, 0.12));
3055
+ color: var(--dsw-alias-label-tertiary, inherit);
3056
+ font-size: 12.5px;
3057
+ line-height: 18px;
3058
+ overflow: hidden;
3059
+ text-overflow: ellipsis;
3060
+ white-space: nowrap;
3061
+ }
3005
3062
  .iw-float-filelist { display: flex; flex-direction: column; gap: 4px; }
3006
3063
  .iw-float-file {
3007
3064
  display: flex;
@@ -13656,6 +13713,14 @@ function IdeScreenshotEditor({ store, tr, onInsert, onCopy, onOpenSettings, onCl
13656
13713
  const IDE_DATA_WINDOW_KEY = '__DSH_DATA_WINDOW_BRIDGE__'
13657
13714
  const IDE_DATA_WINDOW_REQUEST = 'dsh-data-window:request'
13658
13715
  const IDE_DATA_WINDOW_RESPONSE = 'dsh-data-window:response'
13716
+ /**
13717
+ * 一个标签的属性区,引号里的 `>` 不算标签结束。
13718
+ *
13719
+ * `<if test="billStatusList != null and billStatusList.size() > 0">` 这种写法到处都是;
13720
+ * 用 `[^>]*>` 会在第一个 `>` 处截断,把剩下的 ` 0">` 当成 SQL 留在语句里。
13721
+ */
13722
+ const IDE_DATA_WINDOW_TAG_ATTRS = String.raw`(?:"[^"]*"|'[^']*'|[^>"'])*`
13723
+
13659
13724
  const IDE_DATA_WINDOW_ACK_MS = 2000
13660
13725
 
13661
13726
  /** Whether the data window plugin is installed and active in this page. */
@@ -13844,7 +13909,10 @@ const IDE_DATA_WINDOW_INCLUDE_DEPTH = 8
13844
13909
  */
13845
13910
  function ideDataWindowSqlFragments(text) {
13846
13911
  const fragments = {}
13847
- const pattern = /<sql\b[^>]*\bid\s*=\s*["']([^"']+)["'][^>]*>([\s\S]*?)<\/\s*sql\s*>/gi
13912
+ const pattern = new RegExp(
13913
+ `<sql\\b${IDE_DATA_WINDOW_TAG_ATTRS}\\bid\\s*=\\s*["']([^"']+)["']${IDE_DATA_WINDOW_TAG_ATTRS}>([\\s\\S]*?)<\\/\\s*sql\\s*>`,
13914
+ 'gi',
13915
+ )
13848
13916
  let match
13849
13917
  while ((match = pattern.exec(String(text ?? ''))) !== null) {
13850
13918
  fragments[match[1]] = match[2]
@@ -13910,7 +13978,7 @@ function ideDataWindowIncludes(body) {
13910
13978
  /** `<include>` 里 `<property name=... value=.../>` 提供的占位符值。 */
13911
13979
  function ideDataWindowIncludeProps(body) {
13912
13980
  const props = {}
13913
- for (const match of String(body ?? '').matchAll(/<property\b[^>]*\/?\s*>/gi)) {
13981
+ for (const match of String(body ?? '').matchAll(new RegExp(`<property\\b${IDE_DATA_WINDOW_TAG_ATTRS}\\/?\\s*>`, 'gi'))) {
13914
13982
  const attrs = ideDataWindowXmlAttrs(match[0])
13915
13983
  if (attrs.name !== undefined && attrs.value !== undefined) props[attrs.name] = attrs.value
13916
13984
  }
@@ -13987,7 +14055,7 @@ async function ideDataWindowXmlSql(root, fqcn, symbol) {
13987
14055
  const text = await ideDataWindowReadFile(root, path)
13988
14056
  if (text === '') return null
13989
14057
  const pattern = new RegExp(
13990
- `<\\s*(select|insert|update|delete)\\b[^>]*\\bid\\s*=\\s*["']${ideDataWindowEscape(symbol)}["'][^>]*>([\\s\\S]*?)<\\s*/\\s*\\1\\s*>`,
14058
+ `<\\s*(select|insert|update|delete)\\b${IDE_DATA_WINDOW_TAG_ATTRS}\\bid\\s*=\\s*["']${ideDataWindowEscape(symbol)}["']${IDE_DATA_WINDOW_TAG_ATTRS}>([\\s\\S]*?)<\\s*/\\s*\\1\\s*>`,
13991
14059
  'i',
13992
14060
  )
13993
14061
  const match = pattern.exec(text)
@@ -14069,7 +14137,7 @@ function ideDataWindowValueFor(expr, params, index, item) {
14069
14137
  /** Expand `<foreach>` into three default rows so the SQL can run as-is. */
14070
14138
  function ideDataWindowExpandForeach(sql, params) {
14071
14139
  let result = String(sql ?? '')
14072
- const pattern = /<foreach\b([^>]*)>([\s\S]*?)<\/foreach>/i
14140
+ const pattern = new RegExp(`<foreach\\b(${IDE_DATA_WINDOW_TAG_ATTRS})>([\\s\\S]*?)<\\/foreach>`, 'i')
14073
14141
  let match
14074
14142
  while ((match = pattern.exec(result)) !== null) {
14075
14143
  const attrs = ideDataWindowXmlAttrs(match[1])
@@ -14095,19 +14163,20 @@ function ideDataWindowStripTags(sql) {
14095
14163
  let result = String(sql ?? '')
14096
14164
  // CDATA 里是原样 SQL,先去壳,否则会被下面「未知标签」那条清理连内容一起吞掉。
14097
14165
  result = result.replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, '$1')
14098
- result = result.replace(/<\s*script\b[^>]*>/gi, '').replace(/<\s*\/\s*script\s*>/gi, '')
14099
- result = result.replace(/<choose\b[^>]*>([\s\S]*?)<\/choose>/gi, (whole, body) => {
14100
- const when = /<when\b[^>]*>([\s\S]*?)<\/when>/i.exec(body)
14101
- const otherwise = /<otherwise\b[^>]*>([\s\S]*?)<\/otherwise>/i.exec(body)
14166
+ const open = (tag) => new RegExp(`<\\s*${tag}\\b${IDE_DATA_WINDOW_TAG_ATTRS}>`, 'gi')
14167
+ result = result.replace(open('script'), '').replace(/<\s*\/\s*script\s*>/gi, '')
14168
+ result = result.replace(new RegExp(`<choose\\b${IDE_DATA_WINDOW_TAG_ATTRS}>([\\s\\S]*?)<\\/choose>`, 'gi'), (whole, body) => {
14169
+ const when = new RegExp(`<when\\b${IDE_DATA_WINDOW_TAG_ATTRS}>([\\s\\S]*?)<\\/when>`, 'i').exec(body)
14170
+ const otherwise = new RegExp(`<otherwise\\b${IDE_DATA_WINDOW_TAG_ATTRS}>([\\s\\S]*?)<\\/otherwise>`, 'i').exec(body)
14102
14171
  return when !== null ? when[1] : otherwise !== null ? otherwise[1] : ''
14103
14172
  })
14104
- result = result.replace(/<where\b[^>]*>([\s\S]*?)<\/where>/gi, (whole, body) => (
14173
+ result = result.replace(new RegExp(`<where\\b${IDE_DATA_WINDOW_TAG_ATTRS}>([\\s\\S]*?)<\\/where>`, 'gi'), (whole, body) => (
14105
14174
  ` WHERE ${body.replace(/^\s*(and|or)\b/i, '')} `
14106
14175
  ))
14107
- result = result.replace(/<set\b[^>]*>([\s\S]*?)<\/set>/gi, (whole, body) => (
14176
+ result = result.replace(new RegExp(`<set\\b${IDE_DATA_WINDOW_TAG_ATTRS}>([\\s\\S]*?)<\\/set>`, 'gi'), (whole, body) => (
14108
14177
  ` SET ${body.replace(/,\s*$/, '')} `
14109
14178
  ))
14110
- result = result.replace(/<trim\b([^>]*)>([\s\S]*?)<\/trim>/gi, (whole, attrText, body) => {
14179
+ result = result.replace(new RegExp(`<trim\\b(${IDE_DATA_WINDOW_TAG_ATTRS})>([\\s\\S]*?)<\\/trim>`, 'gi'), (whole, attrText, body) => {
14111
14180
  const attrs = ideDataWindowXmlAttrs(attrText)
14112
14181
  let inner = body
14113
14182
  for (const prefix of String(attrs.prefixOverrides ?? '').split('|')) {
@@ -14121,14 +14190,14 @@ function ideDataWindowStripTags(sql) {
14121
14190
  return `${String(attrs.prefix ?? '').trim()} ${inner} ${String(attrs.suffix ?? '').trim()}`
14122
14191
  })
14123
14192
  for (const tag of ['if', 'when', 'otherwise']) {
14124
- const pattern = new RegExp(`<\\s*${tag}\\b[^>]*>([\\s\\S]*?)<\\s*/\\s*${tag}\\s*>`, 'gi')
14193
+ const pattern = new RegExp(`<\\s*${tag}\\b${IDE_DATA_WINDOW_TAG_ATTRS}>([\\s\\S]*?)<\\s*/\\s*${tag}\\s*>`, 'gi')
14125
14194
  result = result.replace(pattern, '$1')
14126
14195
  }
14127
- result = result.replace(/<bind\b[^>]*\/?\s*>/gi, '')
14196
+ result = result.replace(new RegExp(`<bind\\b${IDE_DATA_WINDOW_TAG_ATTRS}\\/?\\s*>`, 'gi'), '')
14128
14197
  // Anything left (foreach and include are already expanded) is an unsupported tag: drop it.
14129
14198
  // 只认「XML 形状」的标签(字母或 `!` 开头):`a &lt; 5` 解出来是比较运算符,
14130
14199
  // 按 `<[^>]+>` 删会把 `<` 到后面某个 `>` 之间的真实 SQL 一起吞掉。
14131
- result = result.replace(/<\/?[A-Za-z!][^>]*>/g, '')
14200
+ result = result.replace(new RegExp(`<\\/?[A-Za-z!]${IDE_DATA_WINDOW_TAG_ATTRS}>`, 'g'), '')
14132
14201
  // `<where>` may have wrapped its leading AND/OR inside a stripped `<if>`.
14133
14202
  result = result.replace(/\bWHERE\s+(AND|OR)\b/gi, 'WHERE')
14134
14203
  // 条件被动态标签或解析失败的 include 吃光后只剩一个 WHERE,留着就是语法错误。
@@ -14395,6 +14464,23 @@ function ideFloatTargetSession(state) {
14395
14464
  return pinned !== '' ? pinned : panel
14396
14465
  }
14397
14466
 
14467
+ /** 会话的模式:`agentPreset` 投影的值(字符串或 `{currentValue}`,没配置就是空)。 */
14468
+ function ideFloatPresetId(value) {
14469
+ if (typeof value === 'string') return value
14470
+ if (value !== null && typeof value === 'object' && typeof value.currentValue === 'string') return value.currentValue
14471
+ return ''
14472
+ }
14473
+
14474
+ /** 模式的名字:自定义预设用自己的名字,内置预设交给调用方翻译,最后兜底 id。 */
14475
+ function ideFloatPresetName(presets, id, translate) {
14476
+ if (typeof id !== 'string' || id === '') return ''
14477
+ const entry = Array.isArray(presets) ? presets.find((item) => item?.id === id) : undefined
14478
+ const named = typeof entry?.name === 'string' ? entry.name.trim() : ''
14479
+ if (named !== '') return named
14480
+ const text = typeof translate === 'function' ? translate(id) : ''
14481
+ return typeof text === 'string' && text !== '' ? text : id
14482
+ }
14483
+
14398
14484
  /** 表头标题最多 `limit` 个字,超出用省略号——再长就分不清是哪个会话了。 */
14399
14485
  function ideFloatTitleText(text, limit = IDE_FLOAT_TITLE_CHARS) {
14400
14486
  const value = String(text ?? '').trim()
@@ -14545,7 +14631,12 @@ function ideFloatRow(row, tr, io) {
14545
14631
  const body = row.text === '' ? null : h(IdeFloatMarkdown, { key: 'text', text: row.text, tr })
14546
14632
  const pics = row.images === undefined || row.images.length === 0 ? null : h('div', { key: 'pics', className: 'iw-float-pics' }, row.images.map((image, index) => {
14547
14633
  const url = pictures[image.attachmentId] ?? ''
14548
- if (url === '') return h('div', { key: `pic${index}`, className: 'iw-float-pic iw-float-pic-wait' })
14634
+ // 还没读到用骨架,读失败用一行提示(`''` 是「试过了、失败」的标记)。
14635
+ if (url === '') {
14636
+ return Object.prototype.hasOwnProperty.call(picturesRef.current, image.attachmentId)
14637
+ ? h('div', { key: `pic${index}`, className: 'iw-float-pic iw-float-pic-missing' }, `${tr('floatImageMissing')}${image.name === undefined ? '' : ` · ${image.name}`}`)
14638
+ : h('div', { key: `pic${index}`, className: 'iw-float-pic iw-float-pic-wait' })
14639
+ }
14549
14640
  return h('img', {
14550
14641
  key: `pic${index}`,
14551
14642
  className: 'iw-float-pic',
@@ -15741,8 +15832,38 @@ function ideFloatFileUrl(path) {
15741
15832
  }
15742
15833
  }
15743
15834
 
15835
+ /**
15836
+ * 一张 markdown 图:加载不出来就换成一行提示。
15837
+ *
15838
+ * 助手有时会写 `![说明](/tmp/xxx.jpg)` 指向已经不存在的文件(临时截图被清理了),
15839
+ * 浏览器只会给一枚裂图标 + alt 文字,看着像卡片坏了。这里显式说明「图片无法加载」
15840
+ * 并带上文件名,悬停给完整路径。
15841
+ */
15842
+ function IdeFloatImage(props) {
15843
+ // 一个 props 参数、不解构:测试里的 grabSource 按花括号配平取函数体,
15844
+ // 解构里的 `{ ... }` 会被当成函数结尾。
15845
+ const src = props?.src
15846
+ const alt = props?.alt
15847
+ const path = props?.path
15848
+ const tr = props?.tr
15849
+ const [failed, setFailed] = useState(false)
15850
+ if (failed === true) {
15851
+ const name = String(path ?? '').split(/[\\/]/).pop() || String(alt ?? '')
15852
+ return h('span', {
15853
+ className: 'iw-float-img-missing',
15854
+ title: path === undefined ? name : String(path),
15855
+ }, name === '' ? tr('floatImageMissing') : `${tr('floatImageMissing')} · ${name}`)
15856
+ }
15857
+ return h('img', {
15858
+ className: 'iw-float-md-img',
15859
+ src,
15860
+ alt,
15861
+ onError: () => setFailed(true),
15862
+ })
15863
+ }
15864
+
15744
15865
  /** One inline markdown run: code, bold, emphasis, strike, links, images, autolinks. */
15745
- function ideFloatInline(text, prefix = '') {
15866
+ function ideFloatInline(text, prefix = '', tr) {
15746
15867
  const nodes = []
15747
15868
  const pattern = new RegExp([
15748
15869
  '`+[^`]*`+', // inline code, any number of backticks
@@ -15781,7 +15902,14 @@ function ideFloatInline(text, prefix = '') {
15781
15902
  const localImage = image === null ? '' : ideFloatFileUrl(image[2])
15782
15903
  const src = localImage !== '' ? localImage : image === null ? '' : ideFloatSafeUrl(image[2], true)
15783
15904
  if (src === '') pushText(image === null ? token : image[1])
15784
- else nodes.push(h('img', { key, className: 'iw-float-md-img', src, alt: image[1] }))
15905
+ else nodes.push(h(IdeFloatImage, {
15906
+ key,
15907
+ src,
15908
+ alt: image[1],
15909
+ // 本地路径的图才可能「文件没了」;网络图加载失败也给同一句提示。
15910
+ path: image[2],
15911
+ tr: typeof tr === 'function' ? tr : (key) => key,
15912
+ }))
15785
15913
  } else if (token.startsWith('[')) {
15786
15914
  const link = /^\[([^\]]+)\]\(([^)]+)\)$/.exec(token)
15787
15915
  const localLink = link === null ? '' : ideFloatFileUrl(link[2])
@@ -16031,19 +16159,19 @@ function IdeFloatMarkdown({ text, tr }) {
16031
16159
  return h('div', { className: 'iw-float-md' }, blocks.map((block, index) => {
16032
16160
  const key = `b${index}`
16033
16161
  if (block.type === 'code') return h(IdeFloatCodeBlock, { key, code: block.text, lang: block.lang, tr })
16034
- if (block.type === 'heading') return h('div', { key, className: `iw-float-md-h iw-float-md-h${block.level}` }, ideFloatInline(block.text, key))
16162
+ if (block.type === 'heading') return h('div', { key, className: `iw-float-md-h iw-float-md-h${block.level}` }, ideFloatInline(block.text, key, tr))
16035
16163
  if (block.type === 'hr') return h('div', { key, className: 'iw-float-md-hr' })
16036
- if (block.type === 'quote') return h('blockquote', { key, className: 'iw-float-md-quote' }, ideFloatInline(block.text, key))
16164
+ if (block.type === 'quote') return h('blockquote', { key, className: 'iw-float-md-quote' }, ideFloatInline(block.text, key, tr))
16037
16165
  if (block.type === 'table') {
16038
16166
  return h('div', { key, className: 'iw-float-md-tablewrap' }, h('table', { key: 't', className: 'iw-float-md-table' }, [
16039
16167
  h('thead', { key: 'head' }, h('tr', { key: 'row' }, block.head.map((cell, column) => h('th', {
16040
16168
  key: `c${column}`,
16041
16169
  className: cellClass(block.align[column]),
16042
- }, ideFloatInline(cell, `${key}h${column}`))))),
16170
+ }, ideFloatInline(cell, `${key}h${column}`, tr))))),
16043
16171
  h('tbody', { key: 'body' }, block.rows.map((row, rowIndex) => h('tr', { key: `r${rowIndex}` }, block.head.map((_, column) => h('td', {
16044
16172
  key: `c${column}`,
16045
16173
  className: cellClass(block.align[column]),
16046
- }, ideFloatInline(row[column] ?? '', `${key}r${rowIndex}c${column}`)))))),
16174
+ }, ideFloatInline(row[column] ?? '', `${key}r${rowIndex}c${column}`, tr)))))),
16047
16175
  ]))
16048
16176
  }
16049
16177
  if (block.type === 'ul' || block.type === 'ol') {
@@ -16057,10 +16185,10 @@ function IdeFloatMarkdown({ text, tr }) {
16057
16185
  item.task === null || item.task === undefined
16058
16186
  ? null
16059
16187
  : h('span', { key: 'check', className: 'iw-float-md-check' }, item.task === true ? '☑' : '☐'),
16060
- ...ideFloatInline(item.text.replace(/\n/g, ' '), `${key}l${itemIndex}`),
16188
+ ...ideFloatInline(item.text.replace(/\n/g, ' '), `${key}l${itemIndex}`, tr),
16061
16189
  ])))
16062
16190
  }
16063
- return h('p', { key, className: 'iw-float-md-p' }, ideFloatInline(block.text, key))
16191
+ return h('p', { key, className: 'iw-float-md-p' }, ideFloatInline(block.text, key, tr))
16064
16192
  }))
16065
16193
  }
16066
16194
 
@@ -16070,7 +16198,7 @@ function IdeFloatMarkdown({ text, tr }) {
16070
16198
  * @param props.sessions - the Client `sessions` service (retention + prompt).
16071
16199
  * @param props.modelDirectories - the model directory service the composer uses.
16072
16200
  */
16073
- function IdeFloatingAsk({ store, sessions, modelDirectories, translate, openSession, startSession, useWorkspaces, openInWorkspace, goToChat, composeText, commandList, workspaceList, skillList }) {
16201
+ function IdeFloatingAsk({ store, sessions, modelDirectories, translate, openSession, startSession, useWorkspaces, openInWorkspace, goToChat, composeText, commandList, workspaceList, skillList, modeList, modeLabel }) {
16074
16202
  const tr = typeof translate === 'function' ? translate : (key) => key
16075
16203
  const state = useSyncExternalStore(store.subscribe, store.getState, store.getState)
16076
16204
  const [binding, setBinding] = useState(null)
@@ -16082,6 +16210,9 @@ function IdeFloatingAsk({ store, sessions, modelDirectories, translate, openSess
16082
16210
  // 「+ 新建会话」之后,不跟随时把卡片收养到新会话上(只认卡片自己发起的创建)。
16083
16211
  const pinnedAdoptRef = useRef(false)
16084
16212
  const [olderBusy, setOlderBusy] = useState(false)
16213
+ // 会话的模式(Agent 预设):DSH 表头显示的就是它,卡片只展示不改。
16214
+ const [presetId, setPresetId] = useState('')
16215
+ const [presets, setPresets] = useState([])
16085
16216
  // 卡片默认只画最后 200 行;用户主动往回翻时按步长放宽,别让补进来的行被裁掉。
16086
16217
  const [rowLimit, setRowLimit] = useState(IDE_FLOAT_MESSAGES)
16087
16218
  // 滚到顶 = 用户想看历史:整段对话铺开,直到发消息或切会话才回到「本轮状态板」。
@@ -16157,6 +16288,8 @@ function IdeFloatingAsk({ store, sessions, modelDirectories, translate, openSess
16157
16288
  code: result?.error?.code ?? 'unknown',
16158
16289
  message: result?.error?.message ?? '',
16159
16290
  })
16291
+ // 读不出来就别留一个永远转圈的骨架:标成失败,渲染成「图片无法加载」。
16292
+ setPictures((current) => (current[image.attachmentId] !== undefined ? current : { ...current, [image.attachmentId]: '' }))
16160
16293
  return
16161
16294
  }
16162
16295
  const data = result.value?.data
@@ -16184,6 +16317,44 @@ function IdeFloatingAsk({ store, sessions, modelDirectories, translate, openSess
16184
16317
  stickRef.current = true
16185
16318
  }, [state.floatOpen])
16186
16319
 
16320
+ // 会话的模式:投影一变就跟着变(在 DSH 里换模式,卡片立刻同步)。
16321
+ useEffect(() => {
16322
+ if (binding === null) {
16323
+ setPresetId('')
16324
+ return undefined
16325
+ }
16326
+ const projections = binding.session?.projections
16327
+ if (projections === undefined || projections === null) return undefined
16328
+ const face = typeof projections.faceOf === 'function' ? projections.faceOf('agentPreset') : undefined
16329
+ const read = () => {
16330
+ const direct = typeof projections.get === 'function' ? projections.get('agentPreset') : undefined
16331
+ const fromFace = typeof face?.getSnapshot === 'function' ? face.getSnapshot() : undefined
16332
+ const fromSession = typeof binding.session?.getSnapshot === 'function'
16333
+ ? binding.session.getSnapshot()?.projectionValues?.agentPreset
16334
+ : undefined
16335
+ setPresetId(ideFloatPresetId(direct) || ideFloatPresetId(fromFace) || ideFloatPresetId(fromSession))
16336
+ }
16337
+ read()
16338
+ const off = typeof face?.subscribe === 'function' ? face.subscribe(read) : projections.subscribeAny?.(read)
16339
+ return () => {
16340
+ if (typeof off === 'function') off()
16341
+ }
16342
+ }, [binding])
16343
+
16344
+ // 预设列表只为「自定义模式」的名字;拿不到就只显示内置模式的名字。
16345
+ useEffect(() => {
16346
+ if (typeof modeList !== 'function') return undefined
16347
+ let cancelled = false
16348
+ Promise.resolve(modeList())
16349
+ .then((result) => {
16350
+ if (cancelled) return
16351
+ if (Array.isArray(result?.value)) setPresets(result.value)
16352
+ else if (result?.error !== undefined) ideLogRecord('warn', 'float', 'presets failed', String(result.error))
16353
+ })
16354
+ .catch((error) => { if (cancelled !== true) ideLogRecord('warn', 'float', 'presets failed', error?.message ?? String(error)) })
16355
+ return () => { cancelled = true }
16356
+ }, [modeList])
16357
+
16187
16358
  // 不跟随时,第一次进入就把面板当前会话钉住;之后 DSH 里怎么切都不动。
16188
16359
  useEffect(() => {
16189
16360
  if (state.floatFollow !== false) return
@@ -17655,6 +17826,11 @@ function IdeFloatingAsk({ store, sessions, modelDirectories, translate, openSess
17655
17826
  h('span', { key: 't', className: 'iw-float-perm-text' }, ideFloatPermissionLabel(permission, tr)),
17656
17827
  h(IdeChevronDownIcon, { key: 'c', size: 12 }),
17657
17828
  ]),
17829
+ presetId === '' ? null : h('span', {
17830
+ key: 'mode',
17831
+ className: 'iw-float-mode',
17832
+ title: `${tr('floatMode')}: ${ideFloatPresetName(presets, presetId, modeLabel)}`,
17833
+ }, ideFloatPresetName(presets, presetId, modeLabel)),
17658
17834
  h('span', { key: 'gap', className: 'iw-float-gap' }),
17659
17835
  efforts.length === 0 ? null : h('button', {
17660
17836
  key: 'effort',
@@ -17811,6 +17987,16 @@ function apply(ctx) {
17811
17987
  void error
17812
17988
  }
17813
17989
  const translate = ideMakeTranslator(ctx, bound)
17990
+ // 会话模式的标签:内置预设(standard/ptc/minimal/cordis)没有 name,文案在 DSH
17991
+ // 自己的 `settings.agentPreset` 命名空间里。借它的文案,和表头显示的一致。
17992
+ let presetText
17993
+ try {
17994
+ presetText = ctx.locale !== undefined && typeof ctx.locale.bind === 'function'
17995
+ ? ctx.locale.bind('settings.agentPreset')
17996
+ : undefined
17997
+ } catch (error) {
17998
+ void error
17999
+ }
17814
18000
 
17815
18001
  /**
17816
18002
  * The palette's command list.
@@ -18950,6 +19136,30 @@ function apply(ctx) {
18950
19136
  return { error: String(error?.message ?? error) }
18951
19137
  }
18952
19138
  },
19139
+ // 会话的模式 = Agent 预设;卡片只展示,切换仍在 DSH 里做。
19140
+ modeList: async () => {
19141
+ try {
19142
+ const result = await ctx.remote.agentPresets.list()
19143
+ if (result?.ok === false) return { error: result.error?.message ?? result.error?.code ?? 'failed' }
19144
+ const presets = result?.value?.presets
19145
+ return { value: Array.isArray(presets) ? presets : [] }
19146
+ } catch (error) {
19147
+ return { error: String(error?.message ?? error) }
19148
+ }
19149
+ },
19150
+ /** 内置预设的中文/英文名;返回空串表示「不是内置预设」,交给调用方兜底。 */
19151
+ modeLabel: (id) => {
19152
+ const builtin = { standard: 'Standard', ptc: 'Ptc', minimal: 'Minimal', cordis: 'Cordis' }[id]
19153
+ if (builtin === undefined) return ''
19154
+ const key = `preset${builtin}Name`
19155
+ try {
19156
+ const text = typeof presetText === 'function' ? presetText(key) : undefined
19157
+ if (typeof text === 'string' && text.trim() !== '' && text !== key) return text
19158
+ } catch (error) {
19159
+ void error
19160
+ }
19161
+ return translate(`floatMode${builtin}`)
19162
+ },
18953
19163
  workspaceList: async (sessionId, path) => {
18954
19164
  try {
18955
19165
  const result = await ctx.remote.workspaceFiles.list(sessionId, path)
package/locale/en.json CHANGED
@@ -400,6 +400,12 @@
400
400
  "floatAttachReference": "Reference the open file",
401
401
  "floatNeedsFile": "Open a file first",
402
402
  "floatPermission": "Permission",
403
+ "floatMode": "Mode",
404
+ "floatImageMissing": "Image unavailable",
405
+ "floatModeStandard": "Standard mode",
406
+ "floatModePtc": "PTC mode",
407
+ "floatModeMinimal": "Minimal mode",
408
+ "floatModeCordis": "Cordis mode",
403
409
  "floatPermissionReadOnly": "Read only",
404
410
  "floatPermissionWorkspace": "Workspace write",
405
411
  "floatPermissionFull": "Full access",
package/locale/zh.json CHANGED
@@ -400,6 +400,12 @@
400
400
  "floatAttachReference": "引用当前文件",
401
401
  "floatNeedsFile": "先打开一个文件",
402
402
  "floatPermission": "权限",
403
+ "floatMode": "模式",
404
+ "floatImageMissing": "图片无法加载",
405
+ "floatModeStandard": "标准模式",
406
+ "floatModePtc": "PTC 模式",
407
+ "floatModeMinimal": "精简模式",
408
+ "floatModeCordis": "Cordis 模式",
403
409
  "floatPermissionReadOnly": "仅可查看",
404
410
  "floatPermissionWorkspace": "工作区内修改",
405
411
  "floatPermissionFull": "完全权限",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ide-window",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "IDEA-style code workspace for DeepSeek Harness: a centre panel with a workspace file tree, editor tabs and live-updating source, while the left navigation column hides.",
5
5
  "type": "module",
6
6
  "icon": "icon.svg",