dsh-linked-workspace 0.26.1 → 0.27.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.
package/lib/client.js CHANGED
@@ -2091,12 +2091,66 @@ function urlAttributeViolation(name, value, tagName) {
2091
2091
  // Complete attribute policy for the document preview. Inline styles are dropped
2092
2092
  // as well: `position:fixed; inset:0; z-index:99999` can cover the whole Harness
2093
2093
  // window, which turns a preview into a clickjacking / phishing surface without
2094
- // a single line of script.
2095
- function attributeViolation(name, value, tagName) {
2096
- if (String(name || '').toLowerCase() === 'style') return 'inline style';
2094
+ // a single line of script. Callers may opt in to `allowInlineStyle` for KaTeX
2095
+ // subtrees, where the style attribute is the layout (see katexStyleViolation).
2096
+ function attributeViolation(name, value, tagName, options) {
2097
+ if (String(name || '').toLowerCase() === 'style') {
2098
+ if (options && options.allowInlineStyle && katexStyleViolation(value) === '') return '';
2099
+ return 'inline style';
2100
+ }
2097
2101
  return urlAttributeViolation(name, value, tagName);
2098
2102
  }
2099
2103
 
2104
+ // KaTeX positions every glyph with an inline style — `height:1.2em` on a vlist,
2105
+ // `top:-0.5em` on its children, `vertical-align:-0.2em` on the base — so a
2106
+ // preview that drops them turns each formula into a pile of overlapping spans.
2107
+ // Only that shape is accepted, and only inside `.katex`: lengths, `position:
2108
+ // relative`, and a solid border. Anything that could escape the box
2109
+ // (absolute/fixed positioning, inset, z-index, transforms, url()) is refused.
2110
+ var KATEX_STYLE_PROPERTIES = {
2111
+ height: 'length',
2112
+ top: 'length',
2113
+ left: 'length',
2114
+ width: 'length',
2115
+ 'min-width': 'length',
2116
+ 'margin-left': 'length',
2117
+ 'margin-right': 'length',
2118
+ 'padding-left': 'length',
2119
+ 'vertical-align': 'length',
2120
+ 'border-width': 'length',
2121
+ 'border-bottom-width': 'length',
2122
+ 'border-style': 'keyword',
2123
+ position: 'keyword',
2124
+ };
2125
+
2126
+ var KATEX_LENGTH = /^-?(?:\d+\.?\d*|\.\d+)(?:em|ex|px|pt|rem|%)?$/;
2127
+ var KATEX_KEYWORDS = {
2128
+ 'border-style': /^(?:solid|dashed|dotted)$/,
2129
+ position: /^relative$/,
2130
+ };
2131
+
2132
+ function katexStyleViolation(value) {
2133
+ var text = normalizeUrlValue(value);
2134
+ if (text === '') return '';
2135
+ var declarations = text.split(';');
2136
+ for (var index = 0; index < declarations.length; index += 1) {
2137
+ var declaration = declarations[index].trim();
2138
+ if (declaration === '') continue;
2139
+ var colon = declaration.indexOf(':');
2140
+ if (colon < 0) return 'unsafe style';
2141
+ var property = declaration.slice(0, colon).trim().toLowerCase();
2142
+ var kind = KATEX_STYLE_PROPERTIES[property];
2143
+ if (!kind) return 'unsafe style';
2144
+ var value = declaration.slice(colon + 1).trim();
2145
+ if (kind === 'keyword') {
2146
+ if (!KATEX_KEYWORDS[property].test(value)) return 'unsafe style';
2147
+ } else if (!KATEX_LENGTH.test(value)) {
2148
+ return 'unsafe style';
2149
+ }
2150
+ }
2151
+ return '';
2152
+ }
2153
+
2100
2154
  var TREE_TAB_TYPE = 'dsh-linked-workspace';
2101
2155
  // Remote workspaces get their own page kind: the two modes show different
2102
2156
  // trees (local ⇄ remote pair vs. a plain remote root), so a session must be
@@ -2112,6 +2166,9 @@ function attributeViolation(name, value, tagName) {
2112
2166
  // but a full remote listing on a huge folder is expensive; 15 s keeps the
2113
2167
  // tree fresh without hammering the SSH channel.
2114
2168
  var REFRESH_MIN_INTERVAL_MS = 15000;
2169
+ // Long enough for a slow directory on a busy cluster, short enough that a
2170
+ // dead request does not stare back at the user forever.
2171
+ var TREE_LIST_TIMEOUT_MS = 20000;
2115
2172
  // HTML previews read the whole document (a plotly/figure page is one big
2116
2173
  // inlined script), so they ask the Host for the 8 MB read cap instead of
2117
2174
  // the editor's 2 MB one.
@@ -2273,6 +2330,26 @@ function attributeViolation(name, value, tagName) {
2273
2330
  return true;
2274
2331
  }
2275
2332
 
2333
+ // Chat artifacts live outside our tabs, so opening one has to travel
2334
+ // through the tab meta: the tab component reads revealPath on every render.
2335
+ function openTreeTabAt(ctx, options, scope) {
2336
+ var sidebar = sidebarService(ctx);
2337
+ if (!sidebar || typeof sidebar.openTab !== 'function') return false;
2338
+ var remoteOnly = options.kind === 'remote';
2339
+ var type = remoteOnly ? REMOTE_TREE_TAB_TYPE : TREE_TAB_TYPE;
2340
+ var t = makeT(readLocale(ctx));
2341
+ var meta = remoteOnly ? { remoteId: options.id } : { linkedId: options.id };
2342
+ meta.revealPath = options.relative || '';
2343
+ meta.revealSide = options.side === 'local' ? 'local' : 'remote';
2344
+ meta.revealAt = String(Date.now());
2345
+ try {
2346
+ sidebar.openTab({ type: type, id: type, title: t(remoteOnly ? 'remoteTabTitle' : 'tabTitle'), path: '/', meta: meta }, scope);
2347
+ return true;
2348
+ } catch (error) {
2349
+ return false;
2350
+ }
2351
+ }
2352
+
2276
2353
  var FILE_TAB_TYPE = 'dsh-linked-workspace:file';
2277
2354
  var FILE_SLOT_PREFIX = 'dsh-linked-workspace:file:';
2278
2355
  var FILE_SLOT_COUNT = 12;
@@ -2289,6 +2366,17 @@ function attributeViolation(name, value, tagName) {
2289
2366
 
2290
2367
  var ZH = {
2291
2368
  settingsNav: '联动工作区',
2369
+ revealSection: '最近产物打开位置',
2370
+ revealHint: '会话里点开会话产物(截图、图表、生成的文件)时,默认落到哪一侧。远程工作区只有远程侧。',
2371
+ revealSideRemote: '优先远程目录',
2372
+ revealSideLocal: '优先本地目录',
2373
+ locateArtifact: '定位最近产物',
2374
+ revealOutside: '这个文件不在任何联动/远程工作区目录里:{{path}}',
2375
+ revealOpenTree: '展开定位',
2376
+ artifactNone: '聊天里还没有可定位的产物',
2377
+ artifactNoSession: '当前会话不可用,无法定位产物',
2378
+ revealMissing: '找不到这个文件在工作区里的相对路径,已复制实际路径:{{path}}',
2379
+ revealCopied: '已复制远程路径:{{path}}',
2292
2380
  title: '联动&远程工作区',
2293
2381
  welcomeEyebrow: 'DSH-LINKED-WORKSPACE',
2294
2382
  welcomeTitle: '欢迎使用联动工作区插件',
@@ -2569,6 +2657,8 @@ function attributeViolation(name, value, tagName) {
2569
2657
  docPageOf: '第 {page} / {total} 页',
2570
2658
  docExportDone: '已导出 PDF:{path}',
2571
2659
  docPreviewFailed: '预览失败',
2660
+ previewTooLarge: '这个文件太大({{chars}} 字符,上限 {{limit}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
2661
+ previewTooLargeBytes: '这个文件太大({{bytes}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
2572
2662
  linkedTitle: '联动工作区',
2573
2663
  linkedHint: '本地目录与远端目录成对出现:DSH 会话在该本地目录中工作,并通过 linked_workspace 工具直接编辑远端文件。',
2574
2664
  localFlow: '本地目录',
@@ -2757,6 +2847,9 @@ function attributeViolation(name, value, tagName) {
2757
2847
  execAuditOpen: '打开审计日志',
2758
2848
  execSaved: '远端命令执行设置已保存',
2759
2849
  shortcutTitle: '常用快捷键',
2850
+ shortcutShow: '展开({{count}} 条)',
2851
+ shortcutHide: '收起',
2852
+ listTimedOut: '加载超时,点击重试',
2760
2853
  shortcutHint: '与 VS Code 类似的默认快捷键;macOS 上把 Ctrl 换成 ⌘。',
2761
2854
  shortcutSave: '保存当前文件',
2762
2855
  shortcutClose: '关闭当前文件',
@@ -2876,6 +2969,17 @@ function attributeViolation(name, value, tagName) {
2876
2969
 
2877
2970
  var EN = {
2878
2971
  settingsNav: 'Linked workspaces',
2972
+ revealSection: 'Where the last artifact opens',
2973
+ revealHint: 'Side used when a chat artifact (screenshot, chart, generated file) is opened from the conversation. Remote workspaces only have the remote side.',
2974
+ revealSideRemote: 'Prefer the remote tree',
2975
+ revealSideLocal: 'Prefer the local tree',
2976
+ locateArtifact: 'Locate last artifact',
2977
+ revealOutside: 'This file is not inside any linked or remote workspace directory: {{path}}',
2978
+ revealOpenTree: 'Reveal in the tree',
2979
+ artifactNone: 'No artifact to locate in this chat yet',
2980
+ artifactNoSession: 'This session is not available, so the artifact cannot be located',
2981
+ revealMissing: 'No workspace-relative path for this file; the real path was copied: {{path}}',
2982
+ revealCopied: 'Remote path copied: {{path}}',
2879
2983
  title: 'Linked & remote workspaces',
2880
2984
  welcomeEyebrow: 'DSH-LINKED-WORKSPACE',
2881
2985
  welcomeTitle: 'Welcome to the linked-workspaces plugin',
@@ -3156,6 +3260,8 @@ function attributeViolation(name, value, tagName) {
3156
3260
  docPageOf: 'Page {page} / {total}',
3157
3261
  docExportDone: 'Exported PDF: {path}',
3158
3262
  docPreviewFailed: 'Preview failed',
3263
+ previewTooLarge: 'Too large to preview ({{chars}} characters, the ceiling is {{limit}}). Read it in the editor, or download it and open it elsewhere.',
3264
+ previewTooLargeBytes: 'Too large to preview ({{bytes}}). Read it in the editor, or download it and open it elsewhere.',
3159
3265
  linkedTitle: 'Linked workspaces',
3160
3266
  linkedHint: 'A local folder paired with a remote folder: DSH sessions work in the local folder and edit remote files through the linked_workspace tool.',
3161
3267
  localFlow: 'Local folder',
@@ -3344,6 +3450,9 @@ function attributeViolation(name, value, tagName) {
3344
3450
  execAuditOpen: 'Open the audit log',
3345
3451
  execSaved: 'Remote-execution settings saved',
3346
3452
  shortcutTitle: 'Keyboard shortcuts',
3453
+ shortcutShow: 'Show ({{count}})',
3454
+ shortcutHide: 'Hide',
3455
+ listTimedOut: 'Taking too long — click to retry',
3347
3456
  shortcutHint: 'VS Code-like defaults; use ⌘ instead of Ctrl on macOS.',
3348
3457
  shortcutSave: 'Save the current file',
3349
3458
  shortcutClose: 'Close the current file',
@@ -3537,7 +3646,7 @@ function attributeViolation(name, value, tagName) {
3537
3646
  * Host methods the running DSH process does not have yet, the directory
3538
3647
  * pane says so instead of surfacing an unrelated error.
3539
3648
  */
3540
- var HOST_API_REVISION = 11;
3649
+ var HOST_API_REVISION = 14;
3541
3650
  var hostInfoProbe = null;
3542
3651
 
3543
3652
  function probeHostInfo() {
@@ -3668,20 +3777,35 @@ function attributeViolation(name, value, tagName) {
3668
3777
  return semicolons > commas ? ';' : ',';
3669
3778
  }
3670
3779
 
3780
+ // Returns `{ html, css }`. The stylesheet is handed back separately because
3781
+ // the HTML parser moves a <style> start tag into <head>, so it never reached
3782
+ // `body.innerHTML` — and KaTeX needs those rules: without them a formula
3783
+ // collapses into a pile of overlapping spans.
3671
3784
  function sanitizeDocumentHtml(html) {
3672
3785
  try {
3673
3786
  var parsed = new DOMParser().parseFromString(String(html || ''), 'text/html');
3674
- parsed.querySelectorAll('script,style,iframe,object,embed,link,meta,base,form').forEach(function (node) { node.remove(); });
3787
+ var css = '';
3788
+ // The renderer ships exactly one stylesheet, marked for this purpose;
3789
+ // anything else is removed like before.
3790
+ parsed.querySelectorAll('style').forEach(function (node) {
3791
+ if (node.getAttribute('data-rw-katex') === '1') css += node.textContent || '';
3792
+ node.remove();
3793
+ });
3794
+ parsed.querySelectorAll('script,iframe,object,embed,link,meta,base,form').forEach(function (node) { node.remove(); });
3675
3795
  parsed.querySelectorAll('*').forEach(function (element) {
3796
+ // KaTeX lays a formula out with inline lengths and nothing else, so
3797
+ // that shape survives inside `.katex` while the rest of the document
3798
+ // keeps the `position:fixed; inset:0` defence.
3799
+ var inFormula = typeof element.closest === 'function' && element.closest('.katex') !== null;
3676
3800
  Array.from(element.attributes).forEach(function (attribute) {
3677
- if (attributeViolation(attribute.name, attribute.value, element.tagName)) {
3801
+ if (attributeViolation(attribute.name, attribute.value, element.tagName, { allowInlineStyle: inFormula })) {
3678
3802
  element.removeAttribute(attribute.name);
3679
3803
  }
3680
3804
  });
3681
3805
  });
3682
- return parsed.body.innerHTML;
3806
+ return { html: parsed.body.innerHTML, css: css };
3683
3807
  } catch (error) {
3684
- return '';
3808
+ return { html: '', css: '' };
3685
3809
  }
3686
3810
  }
3687
3811
 
@@ -3745,7 +3869,7 @@ function attributeViolation(name, value, tagName) {
3745
3869
  };
3746
3870
 
3747
3871
  var runtimeSettings = {
3748
- value: { editorTheme: DEFAULT_THEME_ID, editorThemeFamily: DEFAULT_THEME_FAMILY, editorThemeMode: 'system', appThemeDark: false, fileOpenMode: 'editor', autoSave: false },
3872
+ value: { editorTheme: DEFAULT_THEME_ID, editorThemeFamily: DEFAULT_THEME_FAMILY, editorThemeMode: 'system', appThemeDark: false, fileOpenMode: 'editor', autoSave: false, revealSide: 'remote' },
3749
3873
  loaded: false,
3750
3874
  loading: null,
3751
3875
  listeners: new Set(),
@@ -3768,7 +3892,7 @@ function attributeViolation(name, value, tagName) {
3768
3892
  runtimeSettings.loading = null;
3769
3893
  var openMode = settings && (settings.fileOpenMode === 'system' || settings.fileOpenMode === 'copy') ? settings.fileOpenMode : 'editor';
3770
3894
  var mode = settings && (settings.editorThemeMode === 'light' || settings.editorThemeMode === 'dark') ? settings.editorThemeMode : 'system';
3771
- runtimeSettings.apply({ editorTheme: settings && settings.editorTheme ? settings.editorTheme : DEFAULT_THEME_ID, editorThemeFamily: themeFamilyFor(settings), editorThemeMode: mode, fileOpenMode: openMode, autoSave: Boolean(settings && settings.autoSave) });
3895
+ runtimeSettings.apply({ editorTheme: settings && settings.editorTheme ? settings.editorTheme : DEFAULT_THEME_ID, editorThemeFamily: themeFamilyFor(settings), editorThemeMode: mode, fileOpenMode: openMode, autoSave: Boolean(settings && settings.autoSave), revealSide: settings && settings.revealSide === 'local' ? 'local' : 'remote' });
3772
3896
  return runtimeSettings.value;
3773
3897
  }).catch(function () {
3774
3898
  runtimeSettings.loaded = true;
@@ -4191,6 +4315,8 @@ function attributeViolation(name, value, tagName) {
4191
4315
  '.rw-mode-card:hover{border-color:var(--dsw-alias-border-l3,rgba(127,127,127,.4))}',
4192
4316
  '.rw-mode-card.is-on{border-color:var(--dsw-alias-brand-primary);background:color-mix(in srgb,var(--dsw-alias-brand-primary) 9%,transparent)}',
4193
4317
  '.rw-mode-card.is-on .rw-mode-name{color:var(--dsw-alias-brand-primary)}',
4318
+ '.rw-btn.is-on{border-color:var(--dsw-alias-brand-primary);background:color-mix(in srgb,var(--dsw-alias-brand-primary) 10%,transparent);color:var(--dsw-alias-label-primary);font-weight:600}',
4319
+ '.rw-btn.is-on:hover{border-color:var(--dsw-alias-brand-primary)}',
4194
4320
  '.rw-mode-name{font-size:12px;font-weight:600;line-height:17px}',
4195
4321
  '.rw-mode-desc{font-size:10.5px;line-height:14px;color:var(--dsw-alias-label-tertiary)}',
4196
4322
  '.rw-ctx-menu{position:fixed;min-width:214px;max-height:min(70vh,520px);overflow:auto;padding:4px 0;border:1px solid var(--dsw-alias-border-l2);border-radius:7px;background:var(--dsw-alias-bg-overlay);box-shadow:0 12px 36px rgba(0,0,0,.3);z-index:71;font-size:12px;user-select:none}',
@@ -4835,6 +4961,13 @@ function attributeViolation(name, value, tagName) {
4835
4961
  h('path', { key: 'b', d: 'M11.2 2.2v3h-3M4.8 13.8v-3h3', stroke: 'currentColor', strokeWidth: 1.3, strokeLinecap: 'round', strokeLinejoin: 'round' }),
4836
4962
  ]);
4837
4963
  }
4964
+ function IconLocate(size) {
4965
+ return svg(size || 14, [
4966
+ h('circle', { key: 'a', cx: 8, cy: 8, r: 4.2, stroke: 'currentColor', strokeWidth: 1.3 }),
4967
+ h('path', { key: 'b', d: 'M8 1.4v2.6M8 12v2.6M1.4 8h2.6M12 8h2.6', stroke: 'currentColor', strokeWidth: 1.3, strokeLinecap: 'round' }),
4968
+ h('circle', { key: 'c', cx: 8, cy: 8, r: 0.9, fill: 'currentColor' }),
4969
+ ]);
4970
+ }
4838
4971
  function IconClock(size) {
4839
4972
  return svg(size || 14, [
4840
4973
  h('circle', { key: 'a', cx: 8, cy: 8, r: 5.8, stroke: 'currentColor', strokeWidth: 1.3 }),
@@ -6259,7 +6392,8 @@ function attributeViolation(name, value, tagName) {
6259
6392
  var entries = new Map();
6260
6393
  if (rememberedTree && Array.isArray(rememberedTree.entries)) {
6261
6394
  rememberedTree.entries.forEach(function (pair) {
6262
- if (pair && pair.length === 2) entries.set(pair[0], pair[1]);
6395
+ if (!pair || pair.length !== 2) return;
6396
+ entries.set(pair[0], Object.assign({}, pair[1] || {}, { loading: false, loadingMore: false }));
6263
6397
  });
6264
6398
  }
6265
6399
  return { entries: entries };
@@ -6268,9 +6402,15 @@ function attributeViolation(name, value, tagName) {
6268
6402
  var setCache = cacheState[1];
6269
6403
 
6270
6404
  useEffect(function () {
6405
+ // A record captured while its request was still in flight comes back
6406
+ // with `loading: true` and nothing will ever clear it (the request died
6407
+ // with the panel), so the tree would spin forever. Persist only what is
6408
+ // settled; the reload below refetches the rest.
6271
6409
  rememberPanel(props.memoryKey, {
6272
6410
  expanded: Array.from(expanded),
6273
- entries: Array.from(cache.entries.entries()),
6411
+ entries: Array.from(cache.entries.entries()).map(function (pair) {
6412
+ return [pair[0], Object.assign({}, pair[1] || {}, { loading: false, loadingMore: false })];
6413
+ }),
6274
6414
  });
6275
6415
  }, [expanded, cache]);
6276
6416
  var pending = useRef(new Set());
@@ -6371,6 +6511,15 @@ function attributeViolation(name, value, tagName) {
6371
6511
  });
6372
6512
  }
6373
6513
 
6514
+ // `load` refuses to re-ask while a path is pending, which is what keeps
6515
+ // duplicate requests down but also traps a request whose response never
6516
+ // arrived. The retry below drops the guard first.
6517
+ function retry(path) {
6518
+ pending.current.delete(path);
6519
+ lastRefreshAt.current.delete(path);
6520
+ load(path);
6521
+ }
6522
+
6374
6523
  function loadMore(path) {
6375
6524
  var record = cache.entries.get(path);
6376
6525
  if (!record || record.loadingMore || !record.hasMore) return;
@@ -6437,6 +6586,7 @@ function attributeViolation(name, value, tagName) {
6437
6586
  toggle: toggle,
6438
6587
  state: { entries: cache.entries },
6439
6588
  load: load,
6589
+ retry: retry,
6440
6590
  loadMore: loadMore,
6441
6591
  onSelect: props.onSelect,
6442
6592
  onPin: props.onPin,
@@ -6503,6 +6653,12 @@ function attributeViolation(name, value, tagName) {
6503
6653
  return h('div', { className: 'rw-linked-toolbar' },
6504
6654
  h('span', { className: 'rw-tree-toolbar-title' }, props.title || t('tabTitle')),
6505
6655
  h('div', { className: 'rw-actions', style: { marginLeft: 'auto', gap: 2 } },
6656
+ h('button', {
6657
+ type: 'button',
6658
+ className: 'rw-icon-btn',
6659
+ title: props.locateTitle || t('locateArtifact'),
6660
+ onClick: function () { if (props.onLocate) props.onLocate(); },
6661
+ }, IconLocate(14)),
6506
6662
  h('button', {
6507
6663
  type: 'button',
6508
6664
  className: 'rw-icon-btn',
@@ -7565,11 +7721,11 @@ function rememberShowHidden(value) {
7565
7721
  var stateRef = useState({
7566
7722
  loading: true, error: '', data: null, text: '', dirty: false, saving: false,
7567
7723
  preview: rememberedView ? rememberedView.preview === true : kind === 'markdown',
7568
- html: '', previewLoading: false,
7724
+ html: '', css: '', previewLoading: false,
7569
7725
  page: rememberedView ? Number(rememberedView.page) || 0 : 0,
7570
7726
  sheet: rememberedView ? Number(rememberedView.sheet) || 0 : 0,
7571
7727
  slide: rememberedView ? Number(rememberedView.slide) || 0 : 0,
7572
- updates: {}, pptxUpdates: {}, rotations: {}, deleted: {}, pdfLoading: false, notice: '',
7728
+ updates: {}, pptxUpdates: {}, rotations: {}, deleted: {}, pdfLoading: false, notice: '', warn: '',
7573
7729
  findOpen: false, findQuery: '', findIndex: 0,
7574
7730
  });
7575
7731
  var state = stateRef[0];
@@ -7582,13 +7738,29 @@ function rememberShowHidden(value) {
7582
7738
  setState(function (previous) { return Object.assign({}, previous, next); });
7583
7739
  }
7584
7740
 
7741
+ // D1: the Host refuses to render a document above its preview ceiling and
7742
+ // answers with a typed result; drop to the editor and say why.
7743
+ function applyPreviewResult(result) {
7744
+ if (result && result.kind === 'markdown-preview-too-large') {
7745
+ patch({
7746
+ preview: false, previewLoading: false, html: '', css: '',
7747
+ warn: result.bytes
7748
+ ? t('previewTooLargeBytes', { bytes: formatBytes(result.bytes) })
7749
+ : t('previewTooLarge', { chars: String(result.chars), limit: String(result.limit) }),
7750
+ });
7751
+ return;
7752
+ }
7753
+ var clean = sanitizeDocumentHtml(result.html);
7754
+ patch({ previewLoading: false, html: clean.html, css: clean.css });
7755
+ }
7756
+
7585
7757
  function params(extra) {
7586
7758
  var base = local ? { path: path } : Object.assign({ path: path }, scopeParams(scope));
7587
7759
  return Object.assign(base, extra || {});
7588
7760
  }
7589
7761
 
7590
7762
  function load() {
7591
- patch({ loading: true, error: '', notice: '' });
7763
+ patch({ loading: true, error: '', notice: '', warn: '' });
7592
7764
  apiCall('docs.read', params()).then(function (result) {
7593
7765
  var remembered = recallView(viewKey);
7594
7766
  patch({
@@ -7635,7 +7807,7 @@ function rememberShowHidden(value) {
7635
7807
  if (state.loading || !state.preview || kind !== 'markdown' || state.html || state.previewLoading) return;
7636
7808
  patch({ previewLoading: true });
7637
7809
  apiCall('docs.mdPreview', params({ text: state.text })).then(function (result) {
7638
- patch({ previewLoading: false, html: sanitizeDocumentHtml(result.html) });
7810
+ applyPreviewResult(result);
7639
7811
  }).catch(function (error) {
7640
7812
  patch({ previewLoading: false, error: messageOf(error, t, locale) });
7641
7813
  });
@@ -7749,10 +7921,10 @@ function rememberShowHidden(value) {
7749
7921
 
7750
7922
  function showPreview() {
7751
7923
  var next = !state.preview;
7752
- patch({ preview: next, previewLoading: next && !state.html });
7924
+ patch({ preview: next, previewLoading: next && !state.html, warn: '' });
7753
7925
  if (!next || state.html) return;
7754
7926
  apiCall('docs.mdPreview', params({ text: state.text })).then(function (result) {
7755
- patch({ previewLoading: false, html: sanitizeDocumentHtml(result.html) });
7927
+ applyPreviewResult(result);
7756
7928
  }).catch(function (error) {
7757
7929
  patch({ previewLoading: false, error: messageOf(error, t, locale) });
7758
7930
  });
@@ -7848,6 +8020,7 @@ function rememberShowHidden(value) {
7848
8020
  body = state.preview
7849
8021
  ? h('div', { className: 'rw-doc-body', ref: docBodyRef, onScroll: rememberScroll },
7850
8022
  state.previewLoading ? h('div', { className: 'rw-editor-message' }, Spinner(14), t('loading')) : null,
8023
+ state.html ? h('style', { 'data-rw-katex': '1', dangerouslySetInnerHTML: { __html: state.css || '' } }) : null,
7851
8024
  state.html ? h('div', { ref: docPreviewRef, className: 'rw-doc-preview', onScroll: rememberScroll, dangerouslySetInnerHTML: { __html: state.html } }) : null)
7852
8025
  : h('div', { className: 'rw-doc-body', ref: docBodyRef, onScroll: rememberScroll },
7853
8026
  state.findOpen ? h('div', { className: 'rw-find-bar rw-doc-find' },
@@ -7967,6 +8140,7 @@ function rememberShowHidden(value) {
7967
8140
  return h('div', { className: 'rw-doc' }, toolbar,
7968
8141
  state.notice ? h('div', { style: { padding: '6px 10px 0' } }, h(Banner, { kind: 'success' }, state.notice)) : null,
7969
8142
  state.error ? h('div', { style: { padding: '6px 10px 0' } }, h(Banner, { kind: 'error' }, state.error)) : null,
8143
+ state.warn ? h('div', { style: { padding: '6px 10px 0' } }, h(Banner, { kind: 'warn', onClose: function () { patch({ warn: '' }); } }, state.warn)) : null,
7970
8144
  body,
7971
8145
  h('div', { className: 'rw-doc-status' },
7972
8146
  h('span', null, kind.toUpperCase()),
@@ -8172,10 +8346,24 @@ function rememberShowHidden(value) {
8172
8346
  if (!exists) setSelectedKey(sources[0].key);
8173
8347
  }, [sources.length, selectedKey]);
8174
8348
 
8349
+ // Reveal a chat artifact: the tab meta carries the workspace-relative
8350
+ // path, and every new reveal bumps revealAt so repeats still fire.
8351
+ var revealedRef = useRef('');
8352
+ useEffect(function () {
8353
+ var wanted = tabMeta.revealPath ? String(tabMeta.revealPath) : '';
8354
+ if (!wanted || !selected) return;
8355
+ var stamp = String(tabMeta.revealAt || '') + ':' + wanted;
8356
+ if (revealedRef.current === stamp) return;
8357
+ revealedRef.current = stamp;
8358
+ var side = tabMeta.revealSide === 'local' && !remoteOnly ? 'local' : 'remote';
8359
+ openInternalFile(side, wanted, { pinned: true });
8360
+ }, [tabMeta.revealPath, tabMeta.revealAt, tabMeta.revealSide, selected && selected.key]);
8361
+
8175
8362
  var scopeRef = selected ? sourceScopeOf(selected) : null;
8176
8363
 
8177
- // Free space on the remote volume (F2): fetched once per workspace and
8178
- // refreshed when the tree is refreshed. Cheap enough to keep on screen.
8364
+ // Free space on the remote volume: fetched once per workspace and again
8365
+ // whenever the tree refreshes (`version` bumps inside refreshTree()), so
8366
+ // the number does not go stale while the panel stays open (D4).
8179
8367
  var diskState = useState(null);
8180
8368
  var disk = diskState[0];
8181
8369
  var setDisk = diskState[1];
@@ -8188,7 +8376,7 @@ function rememberShowHidden(value) {
8188
8376
  if (alive) setDisk(result && result.disk ? result.disk : null);
8189
8377
  }).catch(function () { if (alive) setDisk(null); });
8190
8378
  return function () { alive = false; };
8191
- }, [diskHostId, diskPath]);
8379
+ }, [diskHostId, diskPath, version]);
8192
8380
 
8193
8381
  // autoPush is host-side and silent, so surface it here: the per-workspace
8194
8382
  // switch state (0.24.0) plus the newest push from the transfer history.
@@ -8373,6 +8561,15 @@ function rememberShowHidden(value) {
8373
8561
  });
8374
8562
  }
8375
8563
 
8564
+ function activeTabSessionId() {
8565
+ try {
8566
+ var snapshot = typeof sidebar.getSnapshot === 'function' ? sidebar.getSnapshot() : null;
8567
+ return snapshot && snapshot.sessionId ? String(snapshot.sessionId) : '';
8568
+ } catch (error) {
8569
+ return '';
8570
+ }
8571
+ }
8572
+
8376
8573
  function openTerminal(side, atPath) {
8377
8574
  if (!selected) return;
8378
8575
  if (side === 'local' && selected.kind !== 'linked') {
@@ -9822,6 +10019,17 @@ function rememberShowHidden(value) {
9822
10019
  directoryOpen: directoryOpen,
9823
10020
  onToggleDirectory: function () { setDirectoryOpen(!directoryOpen); },
9824
10021
  onOpenTerminal: openTerminal,
10022
+ onLocate: function () {
10023
+ locateLastArtifact({
10024
+ ctx: ctx,
10025
+ t: t,
10026
+ locale: locale,
10027
+ settings: settings,
10028
+ showNotice: showNotice,
10029
+ sessionId: props.sessionId || activeTabSessionId(),
10030
+ data: data.data || {},
10031
+ });
10032
+ },
9825
10033
  localEnabled: !remoteOnly && selected.kind === 'linked',
9826
10034
  showHidden: showHidden,
9827
10035
  onToggleHidden: function () {
@@ -10043,15 +10251,26 @@ function rememberShowHidden(value) {
10043
10251
  ? { kind: 'remote', id: meta.remoteId }
10044
10252
  : { kind: 'workspace', id: meta.workspaceId };
10045
10253
  var filePath = tab && tab.path ? tab.path : '';
10046
- return h('div', { className: 'rw-editor-pane' },
10047
- h(RemoteFileEditor, {
10048
- ctx: ctx, t: t, locale: locale,
10049
- scope: scope,
10050
- path: filePath,
10051
- visible: props.visible !== false,
10052
- tabId: tab ? tab.id : undefined,
10053
- sessionId: props.scope ? props.scope.sessionId : undefined,
10054
- }));
10254
+ var visible = props.visible !== false;
10255
+ // D2: this tab used to be a plain code editor only, so the same Markdown
10256
+ // opened here (placeholder paths, references) had no preview while the
10257
+ // very same file opened in the directory panel did. Mirror that dispatch.
10258
+ var docKind = documentKindOf(filePath);
10259
+ var pane = docKind === 'image'
10260
+ ? h(ImagePreview, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false })
10261
+ : docKind === 'html'
10262
+ ? h(HtmlPreview, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false })
10263
+ : docKind && docKind !== 'csv'
10264
+ ? h(DocumentPane, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false, visible: visible })
10265
+ : h(RemoteFileEditor, {
10266
+ ctx: ctx, t: t, locale: locale,
10267
+ scope: scope,
10268
+ path: filePath,
10269
+ visible: visible,
10270
+ tabId: tab ? tab.id : undefined,
10271
+ sessionId: props.scope ? props.scope.sessionId : undefined,
10272
+ });
10273
+ return h('div', { className: 'rw-editor-pane' }, pane);
10055
10274
  }
10056
10275
 
10057
10276
  // ── tree ───────────────────────────────────────────────────────────────
@@ -10111,8 +10330,19 @@ function rememberShowHidden(value) {
10111
10330
  });
10112
10331
  // Hovering over a collapsed folder during a drag expands it after a short
10113
10332
  // delay, so dropping into a nested folder does not require two passes.
10333
+ // A listing that never settles (dropped socket, aborted request) has to
10334
+ // stop looking like progress at some point.
10335
+ var stalledState = useState(false);
10336
+ var stalled = stalledState[0];
10337
+ var setStalled = stalledState[1];
10114
10338
  var dragOpenTimer = useRef(null);
10115
10339
 
10340
+ useEffect(function () {
10341
+ if (!entry.loading) { setStalled(false); return undefined; }
10342
+ var timer = setTimeout(function () { setStalled(true); }, TREE_LIST_TIMEOUT_MS);
10343
+ return function () { clearTimeout(timer); };
10344
+ }, [entry.loading, path]);
10345
+
10116
10346
  useEffect(function () {
10117
10347
  return function () {
10118
10348
  if (dragOpenTimer.current) clearTimeout(dragOpenTimer.current);
@@ -10120,12 +10350,25 @@ function rememberShowHidden(value) {
10120
10350
  }, []);
10121
10351
 
10122
10352
  useEffect(function () {
10123
- if (isOpen && !entry.loading && !entry.loaded && !entry.error) props.load(path);
10124
- }, [isOpen]);
10353
+ // `load` is guarded per path, so asking again while a request is in
10354
+ // flight costs nothing; doing it whenever the record is unsettled also
10355
+ // heals one restored from panel memory still flagged as loading.
10356
+ if (isOpen && !entry.loaded && !entry.error) props.load(path);
10357
+ }, [isOpen, entry.loading, entry.loaded, entry.error]);
10125
10358
 
10126
10359
  var children = [];
10127
10360
  if (isOpen) {
10128
- if (entry.loading) children.push(h('div', { key: 'loading', className: 'rw-row-msg' }, Spinner(12), t('loading')));
10361
+ if (entry.loading) {
10362
+ children.push(stalled
10363
+ ? h('button', {
10364
+ key: 'loading',
10365
+ type: 'button',
10366
+ className: 'rw-row-msg',
10367
+ style: { width: '100%', border: 0, background: 'transparent', cursor: 'pointer', textAlign: 'left' },
10368
+ onClick: function () { setStalled(false); props.retry(path); },
10369
+ }, IconAlert(12), t('listTimedOut'))
10370
+ : h('div', { key: 'loading', className: 'rw-row-msg' }, Spinner(12), t('loading')));
10371
+ }
10129
10372
  else if (entry.error) children.push(h('button', {
10130
10373
  key: 'error',
10131
10374
  type: 'button',
@@ -10149,6 +10392,7 @@ function rememberShowHidden(value) {
10149
10392
  toggle: toggle,
10150
10393
  state: state,
10151
10394
  load: props.load,
10395
+ retry: props.retry,
10152
10396
  loadMore: props.loadMore,
10153
10397
  onSelect: onSelect,
10154
10398
  onPin: onPin,
@@ -10365,6 +10609,11 @@ function rememberShowHidden(value) {
10365
10609
  });
10366
10610
  }
10367
10611
 
10612
+ function retry(path) {
10613
+ pending.current.delete(path);
10614
+ load(path);
10615
+ }
10616
+
10368
10617
  function loadMore(path) {
10369
10618
  var record = cache.entries.get(path);
10370
10619
  if (!record || record.loadingMore || !record.hasMore) return;
@@ -10409,7 +10658,7 @@ function rememberShowHidden(value) {
10409
10658
  return next;
10410
10659
  });
10411
10660
  var record = cache.entries.get(root);
10412
- if (!record || (!record.loaded && !record.loading && !record.error)) load(root);
10661
+ if (!record || (!record.loaded && !record.error)) load(root);
10413
10662
  }, [open]);
10414
10663
 
10415
10664
  return h('div', { className: 'rw-tree-ws' },
@@ -10448,6 +10697,7 @@ function rememberShowHidden(value) {
10448
10697
  toggle: toggle,
10449
10698
  state: { entries: cache.entries },
10450
10699
  load: load,
10700
+ retry: retry,
10451
10701
  loadMore: loadMore,
10452
10702
  onSelect: props.onSelect,
10453
10703
  selectedPath: props.selectedPath,
@@ -11634,6 +11884,11 @@ function rememberShowHidden(value) {
11634
11884
  var state = useState({ saving: false, message: null });
11635
11885
  var local = state[0];
11636
11886
  var setLocal = state[1];
11887
+ // The key list is reference material: folded until asked for, like the
11888
+ // second-layer lists below it.
11889
+ var shortcutOpenState = useState(false);
11890
+ var shortcutsOpen = shortcutOpenState[0];
11891
+ var setShortcutsOpen = shortcutOpenState[1];
11637
11892
  var shortcuts = [
11638
11893
  ['Ctrl+S', t('shortcutSave')],
11639
11894
  ['Ctrl+W', t('shortcutClose')],
@@ -11667,14 +11922,22 @@ function rememberShowHidden(value) {
11667
11922
  local.saving ? Spinner(12) : null),
11668
11923
  h('div', { className: 'rw-group-head', style: { marginTop: 14 } },
11669
11924
  h('span', { className: 'rw-group-title' }, t('shortcutTitle')),
11670
- h('span', { className: 'rw-group-hint' }, t('shortcutHint'))),
11671
- h('div', { className: 'rw-shortcut-grid' },
11672
- shortcuts.map(function (item) {
11673
- return h('div', { key: item[0], className: 'rw-shortcut-row' },
11674
- h('kbd', { className: 'rw-kbd' }, item[0]),
11675
- h('span', null, item[1]));
11676
- })),
11677
- h('div', { className: 'rw-group-hint', style: { marginTop: 8 } }, t('shortcutWebNote')),
11925
+ h('button', {
11926
+ type: 'button',
11927
+ className: 'rw-btn rw-btn-ghost rw-btn-sm',
11928
+ onClick: function () { setShortcutsOpen(function (open) { return !open; }); },
11929
+ }, t(shortcutsOpen ? 'shortcutHide' : 'shortcutShow', { count: String(shortcuts.length) }))),
11930
+ shortcutsOpen
11931
+ ? h('div', null,
11932
+ h('div', { className: 'rw-group-hint', style: { marginTop: 4 } }, t('shortcutHint')),
11933
+ h('div', { className: 'rw-shortcut-grid' },
11934
+ shortcuts.map(function (item) {
11935
+ return h('div', { key: item[0], className: 'rw-shortcut-row' },
11936
+ h('kbd', { className: 'rw-kbd' }, item[0]),
11937
+ h('span', null, item[1]));
11938
+ })),
11939
+ h('div', { className: 'rw-group-hint', style: { marginTop: 8 } }, t('shortcutWebNote')))
11940
+ : null,
11678
11941
  local.message
11679
11942
  ? h(Banner, {
11680
11943
  kind: local.message.kind === 'success' ? 'success' : 'error',
@@ -11700,7 +11963,10 @@ function rememberShowHidden(value) {
11700
11963
  });
11701
11964
  var local = state[0];
11702
11965
  var setLocal = state[1];
11703
- // The second-layer list is long and rarely touched: start collapsed.
11966
+ // Both lists are long and rarely touched: start collapsed.
11967
+ var hostListState = useState(false);
11968
+ var hostsOpen = hostListState[0];
11969
+ var setHostsOpen = hostListState[1];
11704
11970
  var workspaceListState = useState(false);
11705
11971
  var workspacesOpen = workspaceListState[0];
11706
11972
  var setWorkspacesOpen = workspaceListState[1];
@@ -11812,23 +12078,36 @@ function rememberShowHidden(value) {
11812
12078
  if (local.execEnabled) {
11813
12079
  children.push(h('div', { className: 'rw-group-hint', style: { marginTop: 8, color: 'rgb(210,153,34)' } }, t('execWarn')));
11814
12080
  children.push(h('div', { className: 'rw-group-head', style: { marginTop: 12 } },
11815
- h('span', { className: 'rw-group-title' }, t('execHostsTitle'))));
11816
- children.push(hosts.length === 0
11817
- ? h('div', { className: 'rw-hint' }, t('execHostsEmpty'))
11818
- : h('div', { className: 'rw-exec-list' }, hosts.map(function (host) {
11819
- var checked = local.execHostIds.indexOf(host.id) >= 0;
11820
- return h('label', { key: host.id, className: 'rw-exec-item' },
11821
- h('input', {
11822
- type: 'checkbox',
11823
- checked: checked,
11824
- onChange: function (event) {
11825
- var on = event.currentTarget.checked;
11826
- save({ execHostIds: withId(local.execHostIds, host.id, on) }, t('execSaved'));
11827
- },
11828
- }),
11829
- h('span', { className: 'rw-exec-name' }, host.name || host.host || host.id),
11830
- h('span', { className: 'rw-exec-meta' }, (host.username ? host.username + '@' : '') + (host.host || '') + (host.port ? ':' + host.port : '')));
11831
- })));
12081
+ h('span', { className: 'rw-group-title' }, t('execHostsTitle')),
12082
+ h('button', {
12083
+ type: 'button',
12084
+ className: 'rw-btn rw-btn-ghost rw-btn-sm',
12085
+ onClick: function () { setHostsOpen(function (open) { return !open; }); },
12086
+ }, t(hostsOpen ? 'execWorkspacesHide' : 'execWorkspacesShow', { count: String(local.execHostIds.length) }))));
12087
+ if (hostsOpen) {
12088
+ children.push(hosts.length === 0
12089
+ ? h('div', { className: 'rw-hint' }, t('execHostsEmpty'))
12090
+ : h('div', { className: 'rw-exec-list' }, hosts.map(function (host) {
12091
+ var checked = local.execHostIds.indexOf(host.id) >= 0;
12092
+ return h('label', { key: host.id, className: 'rw-exec-item' },
12093
+ h('input', {
12094
+ type: 'checkbox',
12095
+ checked: checked,
12096
+ onChange: function (event) {
12097
+ var on = event.currentTarget.checked;
12098
+ save({ execHostIds: withId(local.execHostIds, host.id, on) }, t('execSaved'));
12099
+ },
12100
+ }),
12101
+ h('span', { className: 'rw-exec-name' }, host.name || host.host || host.id),
12102
+ h('span', { className: 'rw-exec-meta' }, (host.username ? host.username + '@' : '') + (host.host || '') + (host.port ? ':' + host.port : '')));
12103
+ })));
12104
+ } else {
12105
+ var pickedNames = hosts.filter(function (host) {
12106
+ return local.execHostIds.indexOf(host.id) >= 0;
12107
+ }).map(function (host) { return host.name || host.host || host.id; });
12108
+ children.push(h('div', { className: 'rw-group-hint', style: { marginTop: 4 } },
12109
+ pickedNames.length === 0 ? t('execHostsEmpty') : pickedNames.join('、')));
12110
+ }
11832
12111
  var picked = local.execWorkspaceIds;
11833
12112
  children.push(h('div', { className: 'rw-group-head', style: { marginTop: 12 } },
11834
12113
  h('span', { className: 'rw-group-title' }, t('execWorkspacesTitle')),
@@ -12375,6 +12654,135 @@ function rememberShowHidden(value) {
12375
12654
  return h('div', { className: 'rw-group' }, children);
12376
12655
  }
12377
12656
 
12657
+ // ── chat artifacts: open them in our own tree ───────────────────────────
12658
+ // DSH hands every file chip, deliverable card and file tool row the same
12659
+ // context-menu target: { kind: 'file', value: { sessionId, path } }. That is
12660
+ // the only place the original path survives, so the reveal action lives here.
12661
+
12662
+ function workspaceRelativePath(source, filePath) {
12663
+ var path = String(filePath || '');
12664
+ if (!path || !source) return '';
12665
+ if (source.kind === 'remote') {
12666
+ var remoteRoot = String(source.remotePath || '');
12667
+ if (remoteRoot && (path === remoteRoot || path.indexOf(remoteRoot + '/') === 0)) {
12668
+ return path.slice(remoteRoot.length).replace(/^\/+/, '');
12669
+ }
12670
+ return '';
12671
+ }
12672
+ var posixPath = path.split('\\').join('/');
12673
+ var localRoot = String(source.localPath || '').split('\\').join('/');
12674
+ if (localRoot && (posixPath.toLowerCase() === localRoot.toLowerCase() || posixPath.toLowerCase().indexOf((localRoot + '/').toLowerCase()) === 0)) {
12675
+ return posixPath.slice(localRoot.length).replace(/^\/+/, '');
12676
+ }
12677
+ var linkedRemote = String(source.remotePath || '');
12678
+ if (linkedRemote && (path === linkedRemote || path.indexOf(linkedRemote + '/') === 0)) {
12679
+ return path.slice(linkedRemote.length).replace(/^\/+/, '');
12680
+ }
12681
+ return '';
12682
+ }
12683
+
12684
+ function remoteAbsolutePath(source, relative) {
12685
+ var root = String(source.remotePath || '').replace(/\/+$/, '');
12686
+ var rel = String(relative || '').replace(/^\/+/, '');
12687
+ if (!root) return rel;
12688
+ return rel ? root + '/' + rel : root;
12689
+ }
12690
+
12691
+ function localAbsolutePath(source, relative) {
12692
+ var root = String(source.localPath || '').replace(/[\\/]+$/, '');
12693
+ var rel = String(relative || '').replace(/^[\\/]+/, '');
12694
+ return rel ? root + '\\' + rel.replace(/\//g, '\\') : root;
12695
+ }
12696
+
12697
+ function revealCandidates(data) {
12698
+ var out = [];
12699
+ (data.links || []).forEach(function (item) {
12700
+ out.push({ kind: 'linked', id: item.id, name: item.name, localPath: item.localPath, remotePath: item.remotePath, status: item.status });
12701
+ });
12702
+ (data.remotes || []).forEach(function (item) {
12703
+ out.push({ kind: 'remote', id: item.id, name: item.name, localPath: null, remotePath: item.remotePath, status: item.status });
12704
+ });
12705
+ return out;
12706
+ }
12707
+
12708
+ function locateLastArtifact(options) {
12709
+ var ctx = options.ctx;
12710
+ var t = options.t;
12711
+ var locale = options.locale;
12712
+ var settings = options.settings;
12713
+ var showNotice = options.showNotice;
12714
+ var sessionId = String(options.sessionId || '');
12715
+ if (!sessionId) {
12716
+ showNotice('error', t('artifactNoSession'));
12717
+ return;
12718
+ }
12719
+ apiCall('linked.lastArtifact', { sessionId: sessionId }).then(function (result) {
12720
+ var artifact = result && result.artifact ? result.artifact : null;
12721
+ if (!artifact || !artifact.path) {
12722
+ showNotice('info', t('artifactNone'));
12723
+ return;
12724
+ }
12725
+ var filePath = String(artifact.path);
12726
+ var candidates = revealCandidates(options.data || {});
12727
+ var hit = null;
12728
+ for (var index = 0; index < candidates.length; index += 1) {
12729
+ var relative = workspaceRelativePath(candidates[index], filePath);
12730
+ if (relative) { hit = { source: candidates[index], relative: relative }; break; }
12731
+ }
12732
+ if (!hit) {
12733
+ copyPathToClipboard(filePath);
12734
+ showNotice('warn', t('revealOutside', { path: filePath }));
12735
+ return;
12736
+ }
12737
+ var side = settings.revealSide === 'local' && hit.source.kind === 'linked' ? 'local' : 'remote';
12738
+ var opened = openTreeTabAt(ctx, { kind: hit.source.kind, id: hit.source.id, relative: hit.relative, side: side }, sessionId);
12739
+ if (!opened) showNotice('error', t('revealMissing'));
12740
+ }).catch(function (error) {
12741
+ showNotice('error', messageOf(error, t, locale));
12742
+ });
12743
+ }
12744
+
12745
+ function RevealSettingsGroup(props) {
12746
+ var t = props.t;
12747
+ var settings = useRuntimeSettings();
12748
+ var state = useState({ saving: false, message: null });
12749
+ var local = state[0];
12750
+ var setLocal = state[1];
12751
+ var current = settings.revealSide === 'local' ? 'local' : 'remote';
12752
+
12753
+ function choose(side) {
12754
+ if (local.saving || side === current) return;
12755
+ setLocal({ saving: true, message: null });
12756
+ apiCall('settings.update', { revealSide: side }).then(function () {
12757
+ runtimeSettings.apply({ revealSide: side });
12758
+ bus.emit();
12759
+ setLocal({ saving: false, message: null });
12760
+ }).catch(function (error) {
12761
+ setLocal({ saving: false, message: { kind: 'error', text: messageOf(error, t, props.locale) } });
12762
+ });
12763
+ }
12764
+
12765
+ return h('div', { className: 'rw-group' },
12766
+ h('div', { className: 'rw-group-head' },
12767
+ h('span', { className: 'rw-group-title' }, t('revealSection')),
12768
+ h('span', { className: 'rw-group-hint' }, t('revealHint'))),
12769
+ h('div', { className: 'rw-setting-row' },
12770
+ h('button', {
12771
+ type: 'button',
12772
+ className: 'rw-btn rw-btn-sm' + (current === 'remote' ? ' is-on' : ''),
12773
+ onClick: function () { choose('remote'); },
12774
+ 'aria-pressed': current === 'remote',
12775
+ }, t('revealSideRemote')),
12776
+ h('button', {
12777
+ type: 'button',
12778
+ className: 'rw-btn rw-btn-sm' + (current === 'local' ? ' is-on' : ''),
12779
+ onClick: function () { choose('local'); },
12780
+ 'aria-pressed': current === 'local',
12781
+ }, t('revealSideLocal')),
12782
+ local.saving ? Spinner(12) : null),
12783
+ local.message ? h(Banner, { kind: local.message.kind === 'error' ? 'error' : 'success' }, local.message.text) : null);
12784
+ }
12785
+
12378
12786
  function ConnectionsPage(props) {
12379
12787
  var ctx = props.ctx;
12380
12788
  var locale = useLocale(ctx);
@@ -12435,6 +12843,7 @@ function rememberShowHidden(value) {
12435
12843
  !sidebarAvailable ? h(Banner, { kind: 'warn' }, t('needsSidebar')) : null,
12436
12844
  h(ThemeGroup, { t: t, locale: locale }),
12437
12845
  h(EditorSettingsGroup, { t: t, locale: locale }),
12846
+ h(RevealSettingsGroup, { t: t, locale: locale }),
12438
12847
  h(ExecSettingsGroup, {
12439
12848
  t: t,
12440
12849
  locale: locale,
@@ -12692,6 +13101,120 @@ function rememberShowHidden(value) {
12692
13101
  }, 'dsh-linked-workspace: @ reference source');
12693
13102
  }
12694
13103
 
13104
+ // ── placeholder hand-over ─────────────────────────────────────────────
13105
+
13106
+ // A remote workspace's session cwd is an EMPTY local placeholder: the files
13107
+ // only exist on the SSH host. So a relative link in the chat ("docs/plan.md")
13108
+ // is resolved against the placeholder and the native editor tries to read it
13109
+ // from the local disk, where it can never exist — the user gets a "file not
13110
+ // found" page for a file that is right there on the remote machine.
13111
+ //
13112
+ // Whenever the sidebar opens a tab bound to a path under
13113
+ // "remote-placeholders/<uuid>/", reopen that same file in our own remote tab
13114
+ // (which reads AND writes over SSH) and drop the broken one. Only the
13115
+ // placeholder prefix is claimed, so ordinary local files are untouched, and
13116
+ // our own tabs carry the resolved remote path — never a placeholder — so the
13117
+ // hand-over cannot repeat itself.
13118
+ var PLACEHOLDER_PATH = /[\\/]remote-placeholders[\\/]([^\\/]+)([\\/].*)$/i;
13119
+
13120
+ function installPlaceholderHandover(ctx) {
13121
+ var sidebar = sidebarService(ctx);
13122
+ if (!sidebar || typeof sidebar.nativePathTabs !== 'function' || typeof sidebar.subscribeState !== 'function') return;
13123
+ var handled = new Set();
13124
+ var known = null;
13125
+ var knownAt = 0;
13126
+ var scanning = false;
13127
+
13128
+ // The list is asked for at most once every 30 s, and once more (uncached)
13129
+ // when a placeholder path matches nothing — a workspace created while the
13130
+ // page is open then works without a reload.
13131
+ function remoteWorkspaces(fresh) {
13132
+ if (!fresh && known && Date.now() - knownAt < 30000) return Promise.resolve(known);
13133
+ return apiCall('remote_workspaces.list').then(function (result) {
13134
+ known = (result && result.workspaces) || [];
13135
+ knownAt = Date.now();
13136
+ return known;
13137
+ }).catch(function () { return []; });
13138
+ }
13139
+
13140
+ function placeholderOwnerOf(list, normalized) {
13141
+ for (var index = 0; index < list.length; index += 1) {
13142
+ var placeholder = String(list[index].placeholderPath || '').replace(/\\/g, '/').replace(/\/+$/, '');
13143
+ if (placeholder !== '' && normalized.indexOf(placeholder + '/') === 0) return list[index];
13144
+ }
13145
+ return null;
13146
+ }
13147
+
13148
+ function openOnRemote(owner, relative, scope, tab) {
13149
+ var remotePath = String(owner.remotePath || '').replace(/\/+$/, '') + '/' + relative;
13150
+ var source = { kind: 'remote', id: owner.id, name: owner.name };
13151
+ if (!openRemoteFileTab(sidebar, scope, source, remotePath)) return;
13152
+ try { sidebar.closeTab(tab.id, scope); } catch (error) { /* the page is gone already */ }
13153
+ }
13154
+
13155
+ function handOver(tab) {
13156
+ var normalized = String(tab && tab.path ? tab.path : '').replace(/\\/g, '/');
13157
+ var match = PLACEHOLDER_PATH.exec(normalized);
13158
+ if (!match) return;
13159
+ var relative = String(match[2] || '').replace(/^\/+/, '');
13160
+ // Directories and extension-less names are not ours to render.
13161
+ if (relative === '' || /\/$/.test(relative) || !/\.[^./]+$/.test(relative)) return;
13162
+ var key = String(tab.sessionId || '') + '|' + String(tab.id || '');
13163
+ if (handled.has(key)) return;
13164
+ // Tab ids are recycled, so the set only has to outlive the pass that
13165
+ // closed the page — keeping it bounded is enough.
13166
+ if (handled.size > 200) handled.clear();
13167
+ handled.add(key);
13168
+ var scope = { sessionId: tab.sessionId };
13169
+ if (tab.cwd) scope.cwd = tab.cwd;
13170
+ remoteWorkspaces(false).then(function (list) {
13171
+ var owner = placeholderOwnerOf(list, normalized);
13172
+ if (owner) return openOnRemote(owner, relative, scope, tab);
13173
+ return remoteWorkspaces(true).then(function (fresh) {
13174
+ var again = placeholderOwnerOf(fresh, normalized);
13175
+ if (again) openOnRemote(again, relative, scope, tab);
13176
+ });
13177
+ });
13178
+ }
13179
+
13180
+ function scan() {
13181
+ if (scanning) return;
13182
+ // F1: a hidden window cannot be looking at a file, so do not poll for
13183
+ // nothing — the visibility handler below catches up on return.
13184
+ if (typeof document !== 'undefined' && document.visibilityState === 'hidden') return;
13185
+ scanning = true;
13186
+ try {
13187
+ var tabs = sidebar.nativePathTabs() || [];
13188
+ for (var index = 0; index < tabs.length; index += 1) handOver(tabs[index]);
13189
+ } catch (error) {
13190
+ /* a sidebar without path tabs simply never hands over */
13191
+ } finally {
13192
+ scanning = false;
13193
+ }
13194
+ }
13195
+
13196
+ scan();
13197
+ // Native right-column tabs live in the sidebar's own adapter and never
13198
+ // reach the shared store, so `subscribeState` stays silent when one opens
13199
+ // — the interval is what actually catches them. It only runs the prefix
13200
+ // test, so a tick costs nothing when nothing is open.
13201
+ ctx.effect(function () {
13202
+ var stop = sidebar.subscribeState(scan);
13203
+ var timer = setInterval(scan, 2000);
13204
+ // A hand-over skipped while the window was hidden has to happen as soon
13205
+ // as it is back, otherwise the click looks like it did nothing.
13206
+ function onVisibility() {
13207
+ if (typeof document !== 'undefined' && document.visibilityState === 'visible') scan();
13208
+ }
13209
+ if (typeof document !== 'undefined') document.addEventListener('visibilitychange', onVisibility);
13210
+ return function () {
13211
+ try { stop(); } catch (error) { /* already disposed */ }
13212
+ clearInterval(timer);
13213
+ if (typeof document !== 'undefined') document.removeEventListener('visibilitychange', onVisibility);
13214
+ };
13215
+ }, 'dsh-linked-workspace: placeholder hand-over');
13216
+ }
13217
+
12695
13218
  // ── apply ──────────────────────────────────────────────────────────────
12696
13219
 
12697
13220
  // `sessions` is a core client service (the sidebar shell injects it too):
@@ -12702,6 +13225,7 @@ function rememberShowHidden(value) {
12702
13225
  function apply(ctx) {
12703
13226
  ctx.effect(installStyles, 'dsh-linked-workspace: styles');
12704
13227
  installReferenceTriggers(ctx);
13228
+ installPlaceholderHandover(ctx);
12705
13229
  ctx.effect(function () {
12706
13230
  var lastDark = null;
12707
13231
  var sync = function () {