dsh-ris-ide 1.8.1 → 1.8.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.
Files changed (50) hide show
  1. package/README.md +2 -2
  2. package/lib/client.js +569 -98
  3. package/lib/debug/vendor/README.md +14 -0
  4. package/lib/debug/vendor/jdwp/client.js +9 -4
  5. package/lib/debug/vendor/src/jdwp/client.ts +12 -5
  6. package/lib/index.js +963 -64
  7. package/lib/redirector.js +76 -4
  8. package/lib/risd/lifecycle.js +54 -10
  9. package/lib/risd/ping.js +136 -17
  10. package/lib/risd/server.js +424 -22
  11. package/lib/risd/ui.js +218 -129
  12. package/lib/risd-client.js +4 -1
  13. package/lib/startup.js +27 -7
  14. package/package.json +2 -2
  15. package/test/client-viewer.test.mjs +268 -93
  16. package/test/clipboard.test.mjs +259 -0
  17. package/test/debug-engine.test.mjs +3 -1
  18. package/test/dsh-origin.test.mjs +4 -11
  19. package/test/dsh-window-refresh.test.mjs +166 -1
  20. package/test/harness.test.mjs +1 -1
  21. package/test/helpers/cmd.mjs +29 -0
  22. package/test/helpers/tgz.mjs +71 -0
  23. package/test/host-search.test.mjs +18 -11
  24. package/test/host-tail.test.mjs +190 -25
  25. package/test/proxy-route.test.mjs +61 -0
  26. package/test/proxy-window.test.mjs +5 -0
  27. package/test/proxy.test.mjs +40 -11
  28. package/test/proxybridge-bundle.test.mjs +1 -59
  29. package/test/redirector-bundle.test.mjs +21 -67
  30. package/test/redirector.test.mjs +71 -4
  31. package/test/risd-api.test.mjs +83 -29
  32. package/test/risd-bridge-degrade.test.mjs +3 -29
  33. package/test/risd-cli-home.test.mjs +41 -4
  34. package/test/risd-engine.test.mjs +13 -50
  35. package/test/risd-entry.test.mjs +0 -37
  36. package/test/risd-follow-start.test.mjs +102 -0
  37. package/test/risd-git.test.mjs +7 -5
  38. package/test/risd-handoff.test.mjs +6 -50
  39. package/test/risd-helpers.mjs +150 -3
  40. package/test/risd-host-p2.test.mjs +2 -30
  41. package/test/risd-lifecycle.test.mjs +203 -33
  42. package/test/risd-ping.test.mjs +77 -1
  43. package/test/risd-programs.test.mjs +4 -34
  44. package/test/risd-review-p2.test.mjs +0 -13
  45. package/test/risd-shutdown.test.mjs +5 -38
  46. package/test/risd-teardown.test.mjs +8 -27
  47. package/test/risd-ui.test.mjs +205 -14
  48. package/test/risd-write.test.mjs +2 -1
  49. package/test/startup-reconcile.test.mjs +44 -8
  50. package/test/proxy-restart.test.mjs +0 -39
package/lib/client.js CHANGED
@@ -286,6 +286,43 @@ window.__ModuleLoader__.load({
286
286
  }
287
287
  }
288
288
 
289
+ /**
290
+ * Where the host last answered that ONE session's workspace is.
291
+ *
292
+ * `knownWorkspaceCwd()` is a single slot shared by every document on this
293
+ * origin — the dsh page, the IDE in a risd-ui tab, a standalone window — so it
294
+ * names whichever panel talked to the host LAST. Reading it as "my workspace"
295
+ * is what made the sidebar console follow an IDE workspace switch made
296
+ * somewhere else (and the other way round). Per-session keys keep each panel
297
+ * on the workspace its own session belongs to (m04873).
298
+ */
299
+ var SESSION_CWD_PREFIX = 'dsh-ris-ide:cwd:'
300
+
301
+ /**
302
+ * Remember the workspace of one session (absolute paths only).
303
+ * @param {string} value - absolute workspace path.
304
+ * @param {string} sessionId - the session the answer belongs to.
305
+ */
306
+ function rememberSessionCwd(value, sessionId) {
307
+ if (typeof value !== 'string' || value === '' || value[0] !== '/') return
308
+ if (typeof sessionId !== 'string' || sessionId === '') return
309
+ try { window.localStorage.setItem(SESSION_CWD_PREFIX + sessionId, value) } catch { /* private mode */ }
310
+ }
311
+
312
+ /**
313
+ * @param {string|undefined} sessionId - the session to look up.
314
+ * @returns {string|undefined} that session's remembered workspace.
315
+ */
316
+ function knownSessionCwd(sessionId) {
317
+ if (typeof sessionId !== 'string' || sessionId === '') return undefined
318
+ try {
319
+ var value = window.localStorage.getItem(SESSION_CWD_PREFIX + sessionId)
320
+ return typeof value === 'string' && value[0] === '/' ? value : undefined
321
+ } catch {
322
+ return undefined
323
+ }
324
+ }
325
+
289
326
  /**
290
327
  * A scope with a usable `cwd`, falling back to the remembered workspace.
291
328
  * @param {{sessionId?: string, cwd?: string}|undefined} scope - caller scope.
@@ -296,6 +333,58 @@ window.__ModuleLoader__.load({
296
333
  return knownWorkspaceCwd()
297
334
  }
298
335
 
336
+ /** How the page answers "which (session, workspace) is on screen right now". */
337
+ var liveScopeResolver = null
338
+
339
+ /**
340
+ * Register (or clear) the page's freshest tree scope.
341
+ *
342
+ * The panel that OWNS the tree is the only one that can answer this: it re-reads
343
+ * the sidebar's live Session marker and the session store on every change. `fsOp`
344
+ * consults it once after the host refuses a mutation as `outside-workspace`.
345
+ * @param {Function|null} resolver - returns `{sessionId, cwd}`, or null to clear.
346
+ */
347
+ function setLiveScopeResolver(resolver) {
348
+ liveScopeResolver = typeof resolver === 'function' ? resolver : null
349
+ }
350
+
351
+ /** @returns {{sessionId?: string, cwd?: string}|undefined} the freshest scope. */
352
+ function liveScope() {
353
+ if (liveScopeResolver === null) return undefined
354
+ try {
355
+ var scope = liveScopeResolver()
356
+ return scope !== null && typeof scope === 'object' ? scope : undefined
357
+ } catch {
358
+ return undefined
359
+ }
360
+ }
361
+
362
+ /**
363
+ * Which Session the host considers LIVE for the workspace a scope names.
364
+ *
365
+ * Read-only probe (`/windows?cwd=`); the host answers with `liveSessionFor(cwd)`,
366
+ * i.e. the Session whose header cwd owns that tree. A window that kept the
367
+ * Session it was booted on gets the right answer here after a workspace switch.
368
+ * @param {{sessionId?: string, cwd?: string}} scope - the scope that just failed.
369
+ * @returns {Promise<string|undefined>} a live session id, or undefined.
370
+ */
371
+ async function liveSessionOfScope(scope) {
372
+ var cwd = scopeCwd(scope)
373
+ if (typeof cwd !== 'string' || cwd === '') return undefined
374
+ try {
375
+ var url = routeUrl('dsh-ris-ide/windows')
376
+ url.searchParams.set('cwd', cwd)
377
+ var response = await fetch(url.href, { headers: { accept: 'application/json' } })
378
+ var parsed = await response.json().catch(function () { return null })
379
+ if (parsed === null || parsed === undefined || parsed.ok !== true) return undefined
380
+ var session = parsed.session
381
+ var id = session !== null && typeof session === 'object' ? session.id : undefined
382
+ return typeof id === 'string' && id !== '' ? id : undefined
383
+ } catch {
384
+ return undefined
385
+ }
386
+ }
387
+
299
388
  /**
300
389
  * The workspace of ONE session, read through the slot's standard `useSessions`
301
390
  * hook.
@@ -1232,22 +1321,9 @@ window.__ModuleLoader__.load({
1232
1321
  return Math.min(Math.max(120, value), 720)
1233
1322
  }
1234
1323
 
1235
- /**
1236
- * Storage key of the compact panel's maximized section ('' | 'console' | 'log').
1237
- * Machine-wide on purpose, same as COMPACT_UI_KEY above.
1238
- */
1239
- var COMPACT_MAX_KEY = 'dsh-ris-ide:ui:compact-max'
1240
-
1241
- /**
1242
- * Which compact section is maximized: 'console', 'log', or '' for the split
1243
- * view. A stale/garbage value degrades to the split view, never to a blank
1244
- * panel (same tolerance as the saved height).
1245
- * @returns {string}
1246
- */
1247
- function readCompactMax() {
1248
- var raw = readPref(COMPACT_MAX_KEY, '')
1249
- return raw === 'console' || raw === 'log' ? raw : ''
1250
- }
1324
+ // The compact panel's maximised section is NOT remembered (m00584): a ⤢ was
1325
+ // persisted machine-wide and every later panel open showed one section only,
1326
+ // with nothing on screen saying why the other one was gone.
1251
1327
 
1252
1328
  /** Clamp a font size read from storage into the supported range. */
1253
1329
  /** The IDE-wide content font size: 10–18px in 0.5 steps (A−/A+ control). */
@@ -2195,7 +2271,13 @@ window.__ModuleLoader__.load({
2195
2271
  // poll timer far more often than once a second.
2196
2272
  var sessionId = scope ? scope.sessionId : undefined
2197
2273
  var cwd = scope ? scope.cwd : undefined
2198
- if (typeof cwd !== 'string' || cwd === '') cwd = knownWorkspaceCwd()
2274
+ // Same rule as the console: a log pane follows ITS scope, never another
2275
+ // document's remembered workspace (m04873).
2276
+ if (typeof cwd !== 'string' || cwd === '') {
2277
+ var scopedCwd = knownSessionCwd(sessionId)
2278
+ cwd = typeof scopedCwd === 'string' && scopedCwd !== '' ? scopedCwd
2279
+ : (typeof sessionId === 'string' && sessionId !== '' ? undefined : knownWorkspaceCwd())
2280
+ }
2199
2281
  var [view, setView] = useState(function () { return stateFromPayload(props.customData) })
2200
2282
  // These controls live in the LOG PANE'S TITLE BAR inside the IDE, so the
2201
2283
  // workbench passes them down (value + change callback) and the viewer body
@@ -5556,6 +5638,13 @@ window.__ModuleLoader__.load({
5556
5638
  try {
5557
5639
  var payload = await fsClipboardState(scope)
5558
5640
  if (payload === null || payload === undefined || payload.ok !== true) return null
5641
+ // The host re-checks the ORIGINALS of the last tree copies: a source that
5642
+ // vanished after Ctrl+C is reported here, with its still-intact staged copy.
5643
+ if (Array.isArray(payload.warnings)) {
5644
+ for (var warningIndex = 0; warningIndex < payload.warnings.length; warningIndex += 1) {
5645
+ if (typeof payload.warnings[warningIndex] === 'string') notify(payload.warnings[warningIndex])
5646
+ }
5647
+ }
5559
5648
  return {
5560
5649
  files: Array.isArray(payload.files) ? payload.files : [],
5561
5650
  text: typeof payload.text === 'string' ? payload.text : '',
@@ -6239,7 +6328,7 @@ window.__ModuleLoader__.load({
6239
6328
  var flyout = menuSub === null
6240
6329
  ? null
6241
6330
  : h('div', {
6242
- key: 'new-flyout', 'data-tree-submenu-panel': 'new',
6331
+ key: 'new-flyout', 'data-tree-submenu-panel': 'new', 'data-ris-ide-menu': '1',
6243
6332
  style: Object.assign({}, S.tabMenu, {
6244
6333
  position: 'absolute', left: menuSub.left, top: menuSub.top, zIndex: 901, minWidth: 150,
6245
6334
  maxHeight: 320, overflowY: 'auto',
@@ -6256,6 +6345,7 @@ window.__ModuleLoader__.load({
6256
6345
  return h('div', {
6257
6346
  style: Object.assign({}, S.tabMenu, { left: treeMenu.x, top: treeMenu.y, position: 'fixed', zIndex: 900, minWidth: 150 }),
6258
6347
  'data-tree-menu': '1',
6348
+ 'data-ris-ide-menu': '1',
6259
6349
  onMouseDown: function (event) { event.stopPropagation() },
6260
6350
  onMouseLeave: function () { setMenuSub(null) },
6261
6351
  }, items, flyout)
@@ -6690,10 +6780,13 @@ window.__ModuleLoader__.load({
6690
6780
  }
6691
6781
 
6692
6782
  /**
6693
- * The saved layout of one IDE tab: `{ui:{maximized,section}, sizes, font,
6694
- * theme, files, file}`. Persisted per tab + WORKSPACE under
6783
+ * The saved layout of one IDE tab: `{ui:{collapsed,section}, sizes, font,
6784
+ * files, file}`. Persisted per tab + WORKSPACE under
6695
6785
  * `dsh-ris-ide:ui:<key>@<cwd>` (m13444).
6696
6786
  *
6787
+ * `ui.maximized` is deliberately NOT part of this shape any more (m00584): a
6788
+ * blob written by an older build may still carry it and is ignored on read.
6789
+ *
6697
6790
  * Pre-m13444 keys had no workspace suffix. Migration is one-shot: the tab's
6698
6791
  * own legacy key (`…:<key>` without `@…`) is adopted ONCE and deleted, so the
6699
6792
  * next workspace does not inherit the same open tabs again (C review P1-2).
@@ -6816,22 +6909,54 @@ window.__ModuleLoader__.load({
6816
6909
  }
6817
6910
 
6818
6911
  /**
6819
- * Per-notice dismissal state: a notice stays closed until its SIGNATURE changes
6820
- * (a new message, or the same one after the state moved on).
6912
+ * Which notice kinds the user closed, and at which signature: a notice stays
6913
+ * closed until its SIGNATURE changes (a new message, or the same one after the
6914
+ * state moved on).
6915
+ *
6916
+ * This lives at MODULE scope rather than in component state (m00388): the same
6917
+ * panel can be mounted more than once at the same moment — the DSH sidebar
6918
+ * keeps a hidden copy beside the visible one, and `keepMounted` keeps a copy
6919
+ * alive across tab switches — so a ✕ that only touched the clicked instance
6920
+ * left the other one rendering the notice again ("点 X 关不掉"). Every mounted
6921
+ * instance subscribes and re-renders together.
6922
+ */
6923
+ var NOTICE_DISMISSALS = {}
6924
+ var NOTICE_DISMISSAL_LISTENERS = []
6925
+ /**
6926
+ * Whether a notice of `kind` with `signature` should still be shown.
6927
+ * @param {string} kind - notice kind (also `data-notice`).
6928
+ * @param {string} signature - the message identity this kind currently carries.
6929
+ * @returns {boolean} true while the user has not closed exactly this one.
6930
+ */
6931
+ function noticeIsOpen(kind, signature) {
6932
+ return NOTICE_DISMISSALS[kind] !== signature
6933
+ }
6934
+ /**
6935
+ * Close one notice for EVERY mounted panel (and every later mount).
6936
+ * @param {string} kind - notice kind.
6937
+ * @param {string} signature - the message identity being closed.
6938
+ */
6939
+ function dismissNotice(kind, signature) {
6940
+ if (NOTICE_DISMISSALS[kind] === signature) return
6941
+ NOTICE_DISMISSALS[kind] = signature
6942
+ NOTICE_DISMISSAL_LISTENERS.slice().forEach(function (listener) { listener() })
6943
+ }
6944
+ /**
6945
+ * Subscribe one mounted panel to the shared dismissal table.
6821
6946
  * @returns {{isOpen: function(string, string): boolean, dismiss: function(string, string): void}}
6822
6947
  */
6823
6948
  function useDismissedNotices() {
6824
- var [dismissed, setDismissed] = useState(function () { return {} })
6949
+ var [, setVersion] = useState(0)
6950
+ useEffect(function () {
6951
+ var listener = function () { setVersion(function (value) { return value + 1 }) }
6952
+ NOTICE_DISMISSAL_LISTENERS.push(listener)
6953
+ return function () {
6954
+ NOTICE_DISMISSAL_LISTENERS = NOTICE_DISMISSAL_LISTENERS.filter(function (item) { return item !== listener })
6955
+ }
6956
+ }, [])
6825
6957
  return {
6826
- isOpen: function (kind, signature) { return dismissed[kind] !== signature },
6827
- dismiss: function (kind, signature) {
6828
- setDismissed(function (prev) {
6829
- if (prev[kind] === signature) return prev
6830
- var next = Object.assign({}, prev)
6831
- next[kind] = signature
6832
- return next
6833
- })
6834
- },
6958
+ isOpen: function (kind, signature) { return noticeIsOpen(kind, signature) },
6959
+ dismiss: function (kind, signature) { dismissNotice(kind, signature) },
6835
6960
  }
6836
6961
  }
6837
6962
 
@@ -6916,6 +7041,18 @@ window.__ModuleLoader__.load({
6916
7041
  // (Chromium < 111): without it the hover rule would be dropped entirely.
6917
7042
  + '{background:rgba(0,0,0,0.05);background:color-mix(in srgb, currentColor 7%, transparent)}'
6918
7043
 
7044
+ /**
7045
+ * Context-menu row hover: the same faint grey tint the tree rows use, under the
7046
+ * pointer over any menu this panel draws (file tree, tab strip, editor gutter).
7047
+ *
7048
+ * `!important` because `S.tabMenuItem` pins `background: transparent` as an
7049
+ * INLINE style — a stylesheet rule loses to inline without it. Disabled rows
7050
+ * (paste with an empty clipboard) keep their flat look.
7051
+ */
7052
+ var MENU_HOVER_CSS = '[data-workbench="ris-ide"] [data-ris-ide-menu] button:hover:not(:disabled)'
7053
+ // Same color-mix fallback ordering as the tree rows above.
7054
+ + '{background:rgba(0,0,0,0.05) !important;background:color-mix(in srgb, currentColor 7%, transparent) !important}'
7055
+
6919
7056
  /**
6920
7057
  * The editor's find panel, restyled to belong to the IDE (user口径: 美化一下
6921
7058
  * 编辑器的搜索面板,风格和整体不一致). CodeMirror ships a 2018-looking strip:
@@ -7473,14 +7610,16 @@ window.__ModuleLoader__.load({
7473
7610
  var [consoleBulk, setConsoleBulk] = useState(null)
7474
7611
  var consoleBulkRef = useRef(false)
7475
7612
  var [ui, setUi] = useState(function () {
7476
- // First ever open of an IDE tab (no saved layout, real browser): start with
7477
- // the SOURCE pane maximised so the editor gets the whole area, and let the
7478
- // normal persistence save that state — every later open restores whatever
7479
- // the user left (including "not maximised"). SSR has no localStorage, so
7480
- // tests/previews keep the plain 2x2 grid.
7481
- var firstOpen = savedUi === null && typeof localStorage !== 'undefined'
7482
- var base = { section: 'breakpoints', collapsed: false, threadId: undefined, frameIndex: 0, note: undefined, busy: false, maximized: firstOpen ? 'editor' : null }
7483
- return savedUi !== null && typeof savedUi.ui === 'object' ? Object.assign(base, savedUi.ui) : base
7613
+ // Every open starts on the plain 2x2 grid: maximise mode (⤢) is NEVER
7614
+ // persisted nor defaulted (m00584 — a remembered "editor" made the IDE
7615
+ // open looking like it had only an editor, with no hint that a pane was
7616
+ // maximised). Only the collapsed section is restored from the saved blob.
7617
+ var base = { section: 'breakpoints', collapsed: false, threadId: undefined, frameIndex: 0, note: undefined, busy: false, maximized: null }
7618
+ if (savedUi !== null && typeof savedUi.ui === 'object') {
7619
+ if (savedUi.ui.collapsed === true) base.collapsed = true
7620
+ if (typeof savedUi.ui.section === 'string' && savedUi.ui.section !== '') base.section = savedUi.ui.section
7621
+ }
7622
+ return base
7484
7623
  })
7485
7624
  /** The three user-draggable pane sizes (px). */
7486
7625
  var [sizes, setSizes] = useState(function () {
@@ -7803,6 +7942,8 @@ var [ui, setUi] = useState(function () {
7803
7942
  var forceEditPathsRef = useRef(new Set())
7804
7943
  var [savingPath, setSavingPath] = useState(undefined)
7805
7944
  var [pendingClose, setPendingClose] = useState(undefined)
7945
+ /** A "reload from disk" waiting for a decision when the tab is dirty. */
7946
+ var [pendingReload, setPendingReload] = useState(undefined)
7806
7947
  /** Bulk close waiting for a decision: `{keepActive, victims, dirty}`. */
7807
7948
  var [pendingBulk, setPendingBulk] = useState(undefined)
7808
7949
  /** Files opened recently (newest first), shown under the open tabs. */
@@ -8194,13 +8335,26 @@ var [ui, setUi] = useState(function () {
8194
8335
  setTimeout(function () { Object.keys(docsRef.current).forEach(function (path) { ensureDocRef.current(path) }) }, 0)
8195
8336
  })
8196
8337
 
8197
- /** Load one document (idempotent): media kinds need no read at all. */
8198
- function ensureDoc(path) {
8338
+ /**
8339
+ * Load one document (idempotent): media kinds need no read at all.
8340
+ * @param {string} path - absolute file path.
8341
+ * @param {boolean} [force] - re-read a path that is already loaded (the tab
8342
+ * strip's 重新加载 button); the CALLER drops the draft first, so a reload
8343
+ * never merges an unsaved buffer into what came back from disk.
8344
+ */
8345
+ function ensureDoc(path, force) {
8199
8346
  if (typeof path !== 'string' || path === '') return
8200
- if (docs[path] !== undefined) return
8347
+ if (force !== true && docs[path] !== undefined) return
8201
8348
  if (isPdfPath(path) || isImagePath(path)) {
8202
8349
  var kind = isPdfPath(path) ? 'pdf' : 'image'
8203
- setDocs(function (prev) { if (prev[path] !== undefined) return prev; var next = Object.assign({}, prev); next[path] = { kind: kind }; return next })
8350
+ // `at` makes the reassignment a real change, so the cache-busting media
8351
+ // URL is rebuilt and the browser reads the file again.
8352
+ setDocs(function (prev) {
8353
+ if (prev[path] !== undefined && force !== true) return prev
8354
+ var next = Object.assign({}, prev)
8355
+ next[path] = { kind: kind, at: force === true ? Date.now() : 0 }
8356
+ return next
8357
+ })
8204
8358
  return
8205
8359
  }
8206
8360
  var cancelled = { current: false }
@@ -8505,6 +8659,26 @@ var [ui, setUi] = useState(function () {
8505
8659
  if (isDirty(path)) setPendingClose(path)
8506
8660
  else closePath(path)
8507
8661
  }
8662
+ /**
8663
+ * Re-read ONE tab from disk (the tab strip's 重新加载 button, m00388).
8664
+ *
8665
+ * "Reload" means *what is on disk now*: the draft is dropped first, never
8666
+ * merged. Media tabs get a fresh cache-busting URL (`ensureDoc(…, true)`);
8667
+ * text tabs get a brand-new document, which the CodeMirror host applies
8668
+ * through its `props.text` effect.
8669
+ * @param {string} path - absolute file path.
8670
+ */
8671
+ function reloadPath(path) {
8672
+ if (typeof path !== 'string' || path === '') return
8673
+ forgetDoc(path)
8674
+ ensureDoc(path, true)
8675
+ }
8676
+ /** 重新加载: ask first when the tab holds unsaved edits. */
8677
+ function requestReload(path) {
8678
+ if (typeof path !== 'string' || path === '') return
8679
+ if (isDirty(path)) setPendingReload(path)
8680
+ else reloadPath(path)
8681
+ }
8508
8682
  /** Disk text for a document: restore the file's original line endings. */
8509
8683
  function docTextForDisk(doc) {
8510
8684
  if (doc === undefined || doc === null) return ''
@@ -9278,12 +9452,15 @@ var [ui, setUi] = useState(function () {
9278
9452
  ensureDoc(openFile)
9279
9453
  }, [openFile, sessionId, reloadTick])
9280
9454
 
9281
- /** Remember open files, the active one and the layout. */
9455
+ /** Remember open files, the active one and the layout (maximise mode never). */
9282
9456
  useEffect(function () {
9283
9457
  try {
9284
9458
  if (typeof localStorage === 'undefined') return
9285
9459
  localStorage.setItem(storageKey, JSON.stringify({
9286
- ui: { collapsed: ui.collapsed, maximized: ui.maximized, section: ui.section },
9460
+ // No `maximized`: which pane is full-screened is a transient view
9461
+ // state, not a preference (m00584) — a restored ⤢ hid three panes and
9462
+ // looked like the IDE only had an editor.
9463
+ ui: { collapsed: ui.collapsed, section: ui.section },
9287
9464
  files: openFiles,
9288
9465
  file: openFile,
9289
9466
  recent: recentFiles,
@@ -9291,7 +9468,7 @@ var [ui, setUi] = useState(function () {
9291
9468
  font: uiFont,
9292
9469
  }))
9293
9470
  } catch (error) { /* private mode / quota: layout memory is best-effort */ }
9294
- }, [ui.collapsed, ui.maximized, ui.section, openFiles, openFile, recentFiles, sizes.left, sizes.leftBottom, sizes.rightBottom, sizes.debugWidth, uiFont])
9471
+ }, [ui.collapsed, ui.section, openFiles, openFile, recentFiles, sizes.left, sizes.leftBottom, sizes.rightBottom, sizes.debugWidth, uiFont])
9295
9472
 
9296
9473
  /**
9297
9474
  * Ctrl/Cmd+W closes the active source tab (asking when dirty); Ctrl/Cmd+F4
@@ -10246,12 +10423,27 @@ var [ui, setUi] = useState(function () {
10246
10423
  }, '×'))
10247
10424
  })),
10248
10425
  h('button', { type: 'button', style: S.tabPage, 'data-tab-page': 'next', title: '下一页页签', onClick: function () { pageTabs(1) } }, '▶'),
10249
- h('button', {
10250
- type: 'button', style: S.tabPage, 'data-action': 'diff',
10251
- title: openFile === '' ? '先打开一个文件' : '与磁盘版本对比:看这一版到底改了哪几行(有未保存修改时可用)',
10252
- disabled: openFile === '' || isDirty(openFile) !== true,
10253
- onClick: function () { setDiffPath(diffPath === openFile ? null : openFile) },
10254
- }, '±'),
10426
+ // ± (compare with disk) and ⟳ (reload from disk) ask the SAME question,
10427
+ // "how does my buffer relate to the file?", and only one of them is ever
10428
+ // useful: a dirty buffer can only be compared, a clean one can only be
10429
+ // reloaded (there is nothing left to throw away). So they swap, sharing
10430
+ // one slot in the strip (m00808) instead of leaving a dead ± behind.
10431
+ // `openFile` starts as `undefined` (not ''), so test for "a real path",
10432
+ // not for an empty string — otherwise ⟳ looks enabled with no tab open.
10433
+ isDirty(openFile) === true
10434
+ ? h('button', {
10435
+ type: 'button', style: S.tabPage, 'data-action': 'diff',
10436
+ title: '与磁盘版本对比:看这一版到底改了哪几行(' + fileBaseName(openFile) + ')',
10437
+ onClick: function () { setDiffPath(diffPath === openFile ? null : openFile) },
10438
+ }, '±')
10439
+ : h('button', {
10440
+ type: 'button', style: S.tabPage, 'data-action': 'reload-file',
10441
+ title: typeof openFile === 'string' && openFile !== ''
10442
+ ? '重新加载 ' + fileBaseName(openFile) + ':丢掉当前缓冲区,重新从磁盘读取(有未保存修改时这个位置变成 ± 对比)'
10443
+ : '先打开一个文件(缓冲区没有未保存修改时,这个位置是重新加载)',
10444
+ disabled: typeof openFile !== 'string' || openFile === '',
10445
+ onClick: function () { requestReload(openFile) },
10446
+ }, '⟳'),
10255
10447
  testRunTarget(openFile, cwd) === null
10256
10448
  ? null
10257
10449
  : h('button', {
@@ -10335,6 +10527,34 @@ var [ui, setUi] = useState(function () {
10335
10527
  onClick: function () { setPendingBulk(undefined) },
10336
10528
  }, '×'))
10337
10529
  : null
10530
+ var reloadPrompt = pendingReload !== undefined
10531
+ ? h('div', { style: Object.assign({}, S.notice, { display: 'flex', alignItems: 'center', gap: 6 }), 'data-reload-prompt': '1' },
10532
+ h('span', { style: { flex: '1 1 auto', minWidth: 0 } }, '「' + fileBaseName(pendingReload) + '」有未保存的修改,重新加载会丢掉它们:'),
10533
+ h('button', {
10534
+ type: 'button', style: S.button, 'data-action': 'save-reload', title: '保存当前修改,再从磁盘重新读取',
10535
+ onClick: function () {
10536
+ var target = pendingReload
10537
+ setPendingReload(undefined)
10538
+ void savePath(target).then(function (ok) { if (ok) reloadPath(target) })
10539
+ },
10540
+ }, '保存并重载'),
10541
+ h('button', {
10542
+ type: 'button', style: S.buttonOff, 'data-action': 'discard-reload', title: '丢掉未保存的修改,按磁盘上的版本重新加载',
10543
+ onClick: function () {
10544
+ var target = pendingReload
10545
+ setPendingReload(undefined)
10546
+ reloadPath(target)
10547
+ },
10548
+ }, '丢弃重载'),
10549
+ h('button', {
10550
+ type: 'button', style: S.buttonOff, 'data-action': 'cancel-reload', title: '保持当前缓冲区不动',
10551
+ onClick: function () { setPendingReload(undefined) },
10552
+ }, '取消'),
10553
+ h('button', {
10554
+ type: 'button', style: Object.assign({}, S.buttonOff, { padding: '0 4px' }), 'data-notice-close': 'reload-prompt', title: '关闭提示(保持当前缓冲区)',
10555
+ onClick: function () { setPendingReload(undefined) },
10556
+ }, '×'))
10557
+ : null
10338
10558
  var body = openFiles.length === 0
10339
10559
  ? h('div', { style: S.idePlaceholder, 'data-no-file': '1' }, '在左侧选择一个文件:打开即可编辑,Ctrl/Cmd+S 保存')
10340
10560
  : openFiles.map(filePane)
@@ -10347,6 +10567,7 @@ var [ui, setUi] = useState(function () {
10347
10567
  overflowY: 'auto', zIndex: 945,
10348
10568
  }),
10349
10569
  'data-tabs-menu': '1',
10570
+ 'data-ris-ide-menu': '1',
10350
10571
  onMouseDown: function (event) { event.stopPropagation() },
10351
10572
  },
10352
10573
  menuRows.length === 0 ? h('span', { style: Object.assign({}, S.meta, { display: 'block', padding: '4px 10px' }) }, '还没有打开过文件')
@@ -10457,6 +10678,7 @@ var [ui, setUi] = useState(function () {
10457
10678
  tabsMenu,
10458
10679
  prompt,
10459
10680
  bulkPrompt,
10681
+ reloadPrompt,
10460
10682
  h('div', { style: S.filePanes },
10461
10683
  // The editor is NEVER swapped out: hiding it behind an overlay keeps
10462
10684
  // the CodeMirror instance (and its undo history) alive, so closing the
@@ -10838,7 +11060,7 @@ var [ui, setUi] = useState(function () {
10838
11060
  if (paneConfig !== null && typeof paneConfig.generate === 'function') {
10839
11061
  consoleConfigActions.push(button('⚙', function () { paneConfig.generate() }, { key: 'config-generate', icon: true, height: 20, action: 'config-generate', title: paneConfig.exists === true ? '更新配置:按当前扫描结果同步 .dsh-ris-ide/config.json(保留你改过的字段)' : '生成配置:把扫描到的程序写成 .dsh-ris-ide/config.json' }))
10840
11062
  }
10841
- paneActions.push(button('⟲', resetLayout, { key: 'layout-reset', icon: true, height: 20, action: 'layout-reset', title: '还原布局尺寸:左列 300px、调试区 300px、两个下层 260px(不改变最大化状态)' }))
11063
+ paneActions.push(button('▦', resetLayout, { key: 'layout-reset', icon: true, height: 20, action: 'layout-reset', title: '还原布局尺寸:左列 300px、调试区 300px、两个下层 260px(不改变最大化状态;管尺寸不管内容)' }))
10842
11064
 
10843
11065
  /** Load the visual debug settings from the host (⚙ opens on a fresh read). */
10844
11066
  async function refreshDebugSettings() {
@@ -10953,7 +11175,7 @@ var [ui, setUi] = useState(function () {
10953
11175
  },
10954
11176
  // The sidebar's CodeMirror theme pins 13px, so the embedded viewer needs
10955
11177
  // this rule, not inheritance, to follow A−/A+.
10956
- h('style', { key: 'ide-font' }, viewerFontCss(uiFont) + viewerThemeCss(pageDark) + DEBUG_LINE_CSS + PREVIEW_CSS + SELECTION_CSS + SCROLLBAR_CSS + SEARCH_PANEL_CSS + TOAST_CSS + PROGRAM_LOADING_CSS + TREE_HOVER_CSS),
11178
+ h('style', { key: 'ide-font' }, viewerFontCss(uiFont) + viewerThemeCss(pageDark) + DEBUG_LINE_CSS + PREVIEW_CSS + SELECTION_CSS + SCROLLBAR_CSS + SEARCH_PANEL_CSS + TOAST_CSS + PROGRAM_LOADING_CSS + TREE_HOVER_CSS + MENU_HOVER_CSS),
10957
11179
  (function () {
10958
11180
  var panes = {
10959
11181
  tree: h(IdeTree, {
@@ -11310,6 +11532,7 @@ var [ui, setUi] = useState(function () {
11310
11532
  editorMenu === null ? null : h('div', {
11311
11533
  style: Object.assign({}, S.tabMenu, { left: editorMenu.x, top: editorMenu.y, position: 'fixed', zIndex: 950, minWidth: 200 }),
11312
11534
  'data-editor-menu': '1',
11535
+ 'data-ris-ide-menu': '1',
11313
11536
  onMouseDown: function (event) { event.stopPropagation() },
11314
11537
  }, (editorMenu.items || []).map(function (item, index) {
11315
11538
  if (item.separator === true) {
@@ -11399,6 +11622,7 @@ var [ui, setUi] = useState(function () {
11399
11622
  tabMenu === null ? null : h('div', {
11400
11623
  style: Object.assign({}, S.tabMenu, { left: tabMenu.x, top: tabMenu.y }),
11401
11624
  'data-tab-menu': tabMenu.kind,
11625
+ 'data-ris-ide-menu': '1',
11402
11626
  onMouseDown: function (event) { event.stopPropagation() },
11403
11627
  },
11404
11628
  h('button', { type: 'button', style: S.tabMenuItem, 'data-action': 'ctx-close-others', onClick: function () { closeOtherTabsOf(); closeTabMenu() } }, '关闭其他'),
@@ -11720,6 +11944,12 @@ var [ui, setUi] = useState(function () {
11720
11944
  var session = payload.session !== null && payload.session !== undefined ? payload.session : null
11721
11945
  var live = session !== null ? session.id : undefined
11722
11946
  if (typeof live !== 'string' || live === '' || live === sessionId) return
11947
+ // This window is pinned to the workspace in its URL: a hello that
11948
+ // resolved to a DIFFERENT workspace belongs to another dsh window, and
11949
+ // following it is how the embedded IDE's console used to jump to
11950
+ // whatever workspace dsh had just switched to (m04873).
11951
+ if (typeof props.cwd === 'string' && props.cwd !== '' &&
11952
+ typeof payload.root === 'string' && payload.root !== '' && payload.root !== props.cwd) return
11723
11953
  var mine = payload.windowSession !== null && payload.windowSession !== undefined ? payload.windowSession : null
11724
11954
  // Still live: this window belongs to a session that exists, so the
11725
11955
  // newer session in the same workspace is a DIFFERENT thread — leave it.
@@ -12611,22 +12841,57 @@ var [ui, setUi] = useState(function () {
12611
12841
  */
12612
12842
  async function fsOp(action, scope, payload) {
12613
12843
  var url = routeUrl('dsh-ris-ide/fs/' + action)
12614
- var response = await fetch(url.href, {
12615
- method: 'POST',
12616
- headers: { 'content-type': 'application/json' },
12617
- body: JSON.stringify(Object.assign({
12618
- sessionId: scope.sessionId,
12619
- }, typeof scope.cwd === 'string' && scope.cwd !== '' ? { cwd: scope.cwd } : {}, payload)),
12620
- })
12621
- var parsed = await response.json().catch(function () { return null })
12622
- if (!response.ok || parsed === null || parsed.ok !== true) {
12844
+ /**
12845
+ * POST one body for one scope and normalize the host's answer: the payload on
12846
+ * success, an `Error` (carrying the host's machine `code`) on failure. A return
12847
+ * instead of a throw lets `fsOp` retry exactly once.
12848
+ * @param {{sessionId?: string, cwd?: string}} active - the scope to send.
12849
+ * @returns {Promise<object|Error>} host payload or the failure.
12850
+ */
12851
+ async function send(active) {
12852
+ var response = await fetch(url.href, {
12853
+ method: 'POST',
12854
+ headers: { 'content-type': 'application/json' },
12855
+ body: JSON.stringify(Object.assign({
12856
+ sessionId: active.sessionId,
12857
+ }, typeof active.cwd === 'string' && active.cwd !== '' ? { cwd: active.cwd } : {}, payload)),
12858
+ })
12859
+ var parsed = await response.json().catch(function () { return null })
12860
+ if (response.ok && parsed !== null && parsed.ok === true) return parsed
12623
12861
  var failure = new Error(parsed !== null && parsed.message !== undefined ? parsed.message : 'HTTP ' + response.status)
12624
12862
  // The paste flow branches on `exists` to offer 改名/覆盖: keep the host's
12625
12863
  // machine code on the error instead of flattening it into a message.
12626
12864
  failure.code = parsed !== null && typeof parsed.code === 'string' ? parsed.code : ''
12627
- throw failure
12865
+ return failure
12628
12866
  }
12629
- return parsed
12867
+ var first = await send(scope)
12868
+ if (!(first instanceof Error)) return first
12869
+ /**
12870
+ * `outside-workspace` is the ONE failure the page can heal without the user:
12871
+ * it means the host fenced this request against a different workspace than the
12872
+ * tree on screen. After a workspace switch the panel/window can still carry the
12873
+ * previous Session (the standalone window keeps the Session it booted on), and
12874
+ * every mutation then died with 「后台任务出错:不能对工作区之外的路径执行新建文件夹」
12875
+ * (m00220). Re-read the live pair once — the page's own live scope first, else
12876
+ * the host's live Session for this workspace — and retry silently.
12877
+ */
12878
+ if (first.code === 'outside-workspace') {
12879
+ var next = null
12880
+ var fresh = liveScope()
12881
+ if (fresh !== undefined && typeof fresh.sessionId === 'string' && fresh.sessionId !== '' && fresh.sessionId !== scope.sessionId) {
12882
+ next = { sessionId: fresh.sessionId, cwd: typeof fresh.cwd === 'string' && fresh.cwd !== '' ? fresh.cwd : scope.cwd }
12883
+ }
12884
+ if (next === null) {
12885
+ var alive = await liveSessionOfScope(scope)
12886
+ if (alive !== undefined && alive !== scope.sessionId) next = { sessionId: alive, cwd: scope.cwd }
12887
+ }
12888
+ if (next !== null) {
12889
+ var retried = await send(next)
12890
+ if (!(retried instanceof Error)) return retried
12891
+ throw retried
12892
+ }
12893
+ }
12894
+ throw first
12630
12895
  }
12631
12896
  function fsMkdir(scope, path) { return fsOp('mkdir', scope, { path: path }) }
12632
12897
  function fsCreateFile(scope, path, content) { return fsOp('create', scope, { path: path, content: content === undefined ? '' : content }) }
@@ -13499,6 +13764,49 @@ var [ui, setUi] = useState(function () {
13499
13764
  openIdeTab(ctx)
13500
13765
  }
13501
13766
 
13767
+ /**
13768
+ * Resolve the URL "open in browser" should use for one program.
13769
+ *
13770
+ * The host decides: the dev-server URL the program printed into its log, or —
13771
+ * when dsh-ris-yds is installed and the workspace is a yds project — yds'
13772
+ * injecting proxy, which also attaches a YYCToken to the page's gateway calls.
13773
+ * @param {object} program - one row from the programs panel.
13774
+ * @param {{sessionId: string, cwd?: string}} scope - owning session.
13775
+ * @returns {Promise<{ok: boolean, url?: string, message?: string, code?: string}>}
13776
+ */
13777
+ async function requestOpenTarget(program, scope) {
13778
+ var query = new URLSearchParams()
13779
+ query.set('sessionId', scope.sessionId)
13780
+ if (typeof scope.cwd === 'string' && scope.cwd !== '') query.set('cwd', scope.cwd)
13781
+ if (typeof program.id === 'string' && program.id !== '') query.set('id', program.id)
13782
+ var response = await fetch(routeUrl('dsh-ris-ide/open-target?' + query.toString()).href, { headers: { accept: 'application/json' } })
13783
+ var parsed = await response.json().catch(function () { return null })
13784
+ if (parsed !== null && typeof parsed === 'object') return parsed
13785
+ return { ok: false, code: 'http', message: 'HTTP ' + response.status }
13786
+ }
13787
+
13788
+ /**
13789
+ * Is the workspace a yds project? The console asks dsh-ris-yds, so a bare
13790
+ * workspace never sees yds wording and the row cannot promise a token it will
13791
+ * not get. A missing plugin (404) is "not a yds project", never an error.
13792
+ * @param {{sessionId: string, cwd?: string}} scope - owning session.
13793
+ * @returns {Promise<boolean>} whether dsh-ris-yds found a `yds.*` project here.
13794
+ */
13795
+ async function requestYdsProject(scope) {
13796
+ var workspace = typeof scope.cwd === 'string' ? scope.cwd : ''
13797
+ if (workspace === '') return false
13798
+ try {
13799
+ var query = new URLSearchParams()
13800
+ query.set('workspace', workspace)
13801
+ var response = await fetch(routeUrl('dsh-ris-yds/probe?' + query.toString()).href, { headers: { accept: 'application/json' } })
13802
+ if (!response.ok) return false
13803
+ var parsed = await response.json()
13804
+ return parsed !== null && typeof parsed === 'object' && parsed.yds === true
13805
+ } catch (error) {
13806
+ return false
13807
+ }
13808
+ }
13809
+
13502
13810
  /**
13503
13811
  * Ask the host to start one discovered program.
13504
13812
  *
@@ -13786,15 +14094,67 @@ var [ui, setUi] = useState(function () {
13786
14094
  // can still name the PREVIOUS session, so the store's value wins when the
13787
14095
  // slot hands us `useSessions`.
13788
14096
  var storeCwd = sessionWorkspaceCwd(props ? props.useSessions : undefined, sessionId)
13789
- if (typeof storeCwd === 'string' && storeCwd !== '') cwd = storeCwd
13790
- // A stale session id must not blank the panel: the host still accepts a cwd.
13791
- if (typeof cwd !== 'string' || cwd === '') cwd = knownWorkspaceCwd()
14097
+ // A workspace we are SURE about: the session store's answer, or what the host
14098
+ // answered for this same session earlier. Anything else (a prop inherited from
14099
+ // a retained tab, the origin-wide last-cwd slot) is a guess, and a guess must
14100
+ // never override the host's own session → workspace resolution (m04873).
14101
+ var cwdKnown = false
14102
+ if (typeof storeCwd === 'string' && storeCwd !== '') {
14103
+ cwd = storeCwd
14104
+ cwdKnown = true
14105
+ } else {
14106
+ var sessionCwd = knownSessionCwd(sessionId)
14107
+ if (typeof sessionCwd === 'string' && sessionCwd !== '') {
14108
+ cwd = sessionCwd
14109
+ cwdKnown = true
14110
+ }
14111
+ }
14112
+ /**
14113
+ * Publish the freshest (Session, workspace) pair to `fsOp`'s one-shot retry.
14114
+ * A mutation refused as `outside-workspace` means the host fenced it against a
14115
+ * workspace other than the tree on screen; the retry asks THIS closure (which
14116
+ * re-reads the sidebar's live marker and the session store) instead of guessing.
14117
+ */
14118
+ useEffect(function () {
14119
+ setLiveScopeResolver(function () {
14120
+ var live = liveSidebarSessionId()
14121
+ var nextSessionId = typeof live === 'string' && live !== '' ? live : sessionId
14122
+ var nextCwd = sessionWorkspaceCwd(props ? props.useSessions : undefined, nextSessionId)
14123
+ if (typeof nextCwd !== 'string' || nextCwd === '') nextCwd = cwd
14124
+ return { sessionId: nextSessionId, cwd: nextCwd }
14125
+ })
14126
+ return function () { setLiveScopeResolver(null) }
14127
+ }, [sessionId, cwd])
13792
14128
  // Selections and the followed log belong to the workspace they were made in,
13793
14129
  // so a Session switch drops them instead of showing another project's log.
13794
14130
  var sessionIdentity = typeof sessionId === 'string' ? sessionId : ''
13795
14131
  useEffect(function () {
13796
14132
  setCompactPick(undefined)
13797
14133
  setActive(undefined)
14134
+ // The console rows and the tree root are workspace data as well: until the
14135
+ // first scan of the NEW scope lands, show "scanning" instead of the previous
14136
+ // workspace's rows. A stale row also feeds a stale absolute log path into
14137
+ // the compact LogTail, which then reads the old project's log under the new
14138
+ // session id ("new scope + old path").
14139
+ setState(function (prev) {
14140
+ if (prev.loading === true && prev.programs.length === 0 && prev.root === undefined) return prev
14141
+ return { loading: true, programs: [], root: undefined, dir: undefined, config: undefined, error: undefined, note: prev.note }
14142
+ })
14143
+ }, [sessionIdentity, cwd])
14144
+ // A workspace switch opens a blank DSH session, and a sidebar layout is stored
14145
+ // per session — so the blank one has no IDE tab and the panel would sit on an
14146
+ // empty pane. Put the tab back on the new session. Capability-checked: hosts
14147
+ // without the right-Sidebar service keep working (nothing happens).
14148
+ useEffect(function () {
14149
+ if (sessionIdentity === '' || props.compact !== true) return
14150
+ var sidebar = props.clientCtx !== null && props.clientCtx !== undefined ? props.clientCtx.sidebarRight : undefined
14151
+ if (sidebar === undefined || sidebar === null || typeof sidebar.openTab !== 'function') return
14152
+ try {
14153
+ sidebar.openTab(IDE_TAB_KIND)
14154
+ } catch (error) {
14155
+ // A host that refuses the tab kind must not break the switch itself.
14156
+ void error
14157
+ }
13798
14158
  }, [sessionIdentity])
13799
14159
  /** Warm the compact ⧉'s address; a fresh cache makes the click synchronous. */
13800
14160
  function warmCompactRisd() {
@@ -13822,7 +14182,8 @@ var [ui, setUi] = useState(function () {
13822
14182
  // Which of the two compact sections owns the panel ('' = split view). The
13823
14183
  // sidebar is too narrow for the IDE's 2x2 maximize, but "最大化这一段" is
13824
14184
  // still useful when reading a long log or a long program list.
13825
- var [compactMax, setCompactMax] = useState(readCompactMax)
14185
+ /** Which compact section is expanded ('console' | 'log' | ''): view state only, starts split. */
14186
+ var [compactMax, setCompactMax] = useState('')
13826
14187
  // The compact log pane's "follow the tail" switch. LogTail defaults to
13827
14188
  // following, but the sidebar view had no control for it — the IDE title bar
13828
14189
  // owned that button, so the compact header needs its own.
@@ -13857,11 +14218,28 @@ var [ui, setUi] = useState(function () {
13857
14218
  }, [state.note])
13858
14219
 
13859
14220
  var [busyId, setBusyId] = useState(undefined)
14221
+ // Which row's 🌐 is in flight: a second click while the host resolves the URL
14222
+ // would open two tabs at the same address.
14223
+ var [busySiteId, setBusySiteId] = useState(undefined)
14224
+ // "Open in browser" is a frontend-only affordance; only a yds project may
14225
+ // mention the token (m04354: a backend row has no page to open, and a plain
14226
+ // workspace must never read yds wording).
14227
+ var [ydsProject, setYdsProject] = useState(false)
14228
+ useEffect(function () {
14229
+ var alive = true
14230
+ requestYdsProject({ sessionId: sessionId, cwd: cwd }).then(function (found) {
14231
+ if (alive) setYdsProject(found === true)
14232
+ })
14233
+ return function () { alive = false }
14234
+ }, [cwd, props.visible])
13860
14235
  /** The compact ⧉ is opening the page: disable it and show progress. */
13861
14236
  var [openingIde, setOpeningIde] = useState(false)
13862
14237
  /** Which action `busyId` is running, for the row mask's wording. */
13863
14238
  var [busyKind, setBusyKind] = useState('')
13864
- var busyRef = useRef(false)
14239
+ // Which (session, workspace) scope the in-flight scan belongs to. A switch
14240
+ // must be able to start a scan of the NEW scope even while the OLD one is
14241
+ // still in flight, and the late answer of the old one must not be rendered.
14242
+ var busyScopeRef = useRef('')
13865
14243
  /** A start-all/stop-all pass in flight: `{kind, index, total}` or null. */
13866
14244
  var [bulk, setBulk] = useState(null)
13867
14245
  /**
@@ -13879,16 +14257,32 @@ var [ui, setUi] = useState(function () {
13879
14257
  var panelDismissals = useDismissedNotices()
13880
14258
 
13881
14259
  var refresh = React.useCallback(async function (force) {
13882
- if (typeof sessionId !== 'string' || sessionId === '' || busyRef.current) return
13883
- busyRef.current = true
14260
+ if (typeof sessionId !== 'string' || sessionId === '') return
14261
+ var scope = sessionId + '|' + (typeof cwd === 'string' ? cwd : '')
14262
+ if (busyScopeRef.current === scope) return
14263
+ busyScopeRef.current = scope
13884
14264
  try {
13885
14265
  var url = routeUrl('dsh-ris-ide/programs')
13886
14266
  url.searchParams.set('sessionId', sessionId)
13887
- if (typeof cwd === 'string' && cwd !== '') url.searchParams.set('cwd', cwd)
14267
+ // Only a CERTAIN workspace may steer the host: a guessed cwd (a retained
14268
+ // prop, the origin-wide last-cwd slot) is exactly how one panel used to
14269
+ // drag another panel's console to its own workspace. Without it the host
14270
+ // resolves the workspace from the session header, which is the truth.
14271
+ if (cwdKnown === true && typeof cwd === 'string' && cwd !== '') url.searchParams.set('cwd', cwd)
13888
14272
  if (force === true) url.searchParams.set('refresh', '1')
13889
14273
  var response = await fetch(url.href, { headers: { accept: 'application/json' } })
13890
14274
  var payload = await response.json().catch(function () { return undefined })
13891
- if (payload !== undefined && payload !== null) rememberWorkspaceCwd(payload.root)
14275
+ // The user switched workspace while this request was on the wire: its
14276
+ // rows belong to the previous scope, so drop them instead of rendering
14277
+ // them under the new session id.
14278
+ if (busyScopeRef.current !== scope) return
14279
+ if (payload !== undefined && payload !== null) {
14280
+ // Remember the answer twice: under this session (what a panel of this
14281
+ // session may reuse) and in the origin-wide slot (the default workspace
14282
+ // when a window is opened without a session).
14283
+ rememberSessionCwd(payload.root, sessionId)
14284
+ rememberWorkspaceCwd(payload.root)
14285
+ }
13892
14286
  if (!response.ok || payload === undefined || payload.ok !== true) {
13893
14287
  setState(function (prev) {
13894
14288
  return Object.assign({}, prev, {
@@ -13912,9 +14306,9 @@ var [ui, setUi] = useState(function () {
13912
14306
  } catch (error) {
13913
14307
  setState(function (prev) { return Object.assign({}, prev, { loading: false, error: messageOf(error) }) })
13914
14308
  } finally {
13915
- busyRef.current = false
14309
+ if (busyScopeRef.current === scope) busyScopeRef.current = ''
13916
14310
  }
13917
- }, [sessionId, cwd])
14311
+ }, [sessionId, cwd, cwdKnown])
13918
14312
 
13919
14313
  // After a `dsh web` restart the console keeps its error row ("扫描失败…")
13920
14314
  // until something re-reads. The stream reopening IS that signal.
@@ -14075,6 +14469,53 @@ var [ui, setUi] = useState(function () {
14075
14469
  })
14076
14470
  }
14077
14471
 
14472
+ /**
14473
+ * Open one program in the user's own browser (🌐).
14474
+ *
14475
+ * A browser page cannot add headers to the tab it opens, so the token work
14476
+ * lives on the host side (dsh-ris-yds' proxy) and this only asks where to go.
14477
+ */
14478
+ function openSite(program) {
14479
+ if (busySiteId !== undefined) return
14480
+ setBusySiteId(program.id)
14481
+ requestOpenTarget(program, { sessionId: sessionId, cwd: cwd }).then(function (result) {
14482
+ setBusySiteId(undefined)
14483
+ if (result.ok !== true) {
14484
+ setState(function (prev) {
14485
+ return Object.assign({}, prev, { note: result.message || '这个程序还没有可打开的地址:先启动它' })
14486
+ })
14487
+ return
14488
+ }
14489
+ // yds started its own private browser (extension + CDP): nothing to open here.
14490
+ if (result.mode === 'debug') {
14491
+ setState(function (prev) {
14492
+ return Object.assign({}, prev, {
14493
+ note: result.pid !== undefined
14494
+ ? '已在专用调试浏览器打开(pid ' + result.pid + ',DevTools 127.0.0.1:' + result.port + ')'
14495
+ : '已在专用调试浏览器打开',
14496
+ })
14497
+ })
14498
+ return
14499
+ }
14500
+ var handle = null
14501
+ try {
14502
+ handle = window.open(String(result.url), 'dsh-ris-ide-site-' + String(program.id).replace(/[^A-Za-z0-9_-]/g, '-'))
14503
+ } catch (error) {
14504
+ handle = null
14505
+ }
14506
+ if (handle === null) {
14507
+ setState(function (prev) {
14508
+ return Object.assign({}, prev, { note: '浏览器拦截了新窗口:允许本站弹窗后再点一次 🌐' })
14509
+ })
14510
+ }
14511
+ }).catch(function (error) {
14512
+ setBusySiteId(undefined)
14513
+ setState(function (prev) {
14514
+ return Object.assign({}, prev, { note: '打开失败:' + messageOf(error) })
14515
+ })
14516
+ })
14517
+ }
14518
+
14078
14519
  /** Write or update the user-editable config from a scan. */
14079
14520
  function generateConfigFile(mode) {
14080
14521
  if (busyId !== undefined) return
@@ -14148,13 +14589,10 @@ var [ui, setUi] = useState(function () {
14148
14589
  text: '已按扫描结果自动生成配置 ' + path + '(可编辑,保存后生效)',
14149
14590
  })
14150
14591
  }
14151
- if (config.status === 'updated') {
14152
- items.push({
14153
- kind: 'config-updated',
14154
- signature: 'updated',
14155
- text: '配置已与工作区同步(新增程序已补、失效条目已删;你改过的字段保留)',
14156
- })
14157
- }
14592
+ // m03291: the automatic-sync row (status 'updated') is NOT shown any
14593
+ // more — it was pure noise after every workspace switch, and the sync
14594
+ // itself is silent anyway. The drift notice below is the actionable
14595
+ // one and stays; the compact panel dropped its own copy too.
14158
14596
  var drift = config.drift
14159
14597
  if (drift !== undefined && drift !== null && drift.stale === true) {
14160
14598
  items.push({
@@ -14246,11 +14684,11 @@ var [ui, setUi] = useState(function () {
14246
14684
  }
14247
14685
 
14248
14686
  /** Drag the hairline above the log pane; the height is remembered on release. */
14249
- /** Maximize one compact section (console | log); the other one is parked. */
14687
+ /** Maximize one compact section (console | log); the other one is parked.
14688
+ * Deliberately NOT written to storage: reopening the panel always shows
14689
+ * the split view (m00584). */
14250
14690
  function toggleCompactMax(section) {
14251
- var next = compactMax === section ? '' : section
14252
- writePref(COMPACT_MAX_KEY, next)
14253
- setCompactMax(next)
14691
+ setCompactMax(compactMax === section ? '' : section)
14254
14692
  }
14255
14693
 
14256
14694
  function dragLogPane(event) {
@@ -14357,6 +14795,21 @@ var [ui, setUi] = useState(function () {
14357
14795
  onClick: function (event) { event.stopPropagation(); void act('restart', program) },
14358
14796
  }, busy ? '…' : '⟳')
14359
14797
  : null,
14798
+ // Open the page the program serves, in the user's own browser. The URL
14799
+ // (and the token, for a yds project) is resolved by the host: a page
14800
+ // cannot add headers to a tab it opens itself.
14801
+ startable && program.kind === 'frontend'
14802
+ ? h('button', {
14803
+ type: 'button', style: busySiteId === program.id ? S.paneIconOff : S.paneIcon, disabled: busySiteId === program.id,
14804
+ 'data-action': 'open-site',
14805
+ title: '在系统浏览器打开 ' + program.name + ' 的页面'
14806
+ + (ydsProject ? '(yds 项目:请求自动带上登录 token,免登录)' : ''),
14807
+ onClick: function (event) {
14808
+ event.stopPropagation()
14809
+ openSite(program)
14810
+ },
14811
+ }, busySiteId === program.id ? '…' : '🌐')
14812
+ : null,
14360
14813
  program.kind === 'spring'
14361
14814
  ? h('button', {
14362
14815
  type: 'button', style: S.debugIcon, 'data-action': 'debug-window',
@@ -14562,8 +15015,10 @@ var [ui, setUi] = useState(function () {
14562
15015
  // A different file is a different viewer: remount it, exactly like
14563
15016
  // the IDE's log pane (`key: activePath`). Without the key the pane
14564
15017
  // kept the previous file's text while the title bar already showed
14565
- // the new program, so a pick looked like it did nothing.
14566
- key: logPath,
15018
+ // the new program, so a pick looked like it did nothing. A new
15019
+ // (session, workspace) scope is a different viewer even when the
15020
+ // path string happens to be equal.
15021
+ key: sessionIdentity + '|' + (typeof cwd === 'string' ? cwd : '') + '|' + logPath,
14567
15022
  scope: { sessionId: sessionId, cwd: cwd },
14568
15023
  path: logPath,
14569
15024
  // One source of truth for the follow switch, exactly like the IDE:
@@ -14670,6 +15125,15 @@ var [ui, setUi] = useState(function () {
14670
15125
  onClick: function () { openWorkbench(program, true) },
14671
15126
  }, '调试')
14672
15127
  : null,
15128
+ program.kind === 'frontend'
15129
+ ? h('button', {
15130
+ type: 'button', style: busySiteId === program.id ? S.paneIconOff : S.buttonOff, 'data-action': 'open-site',
15131
+ disabled: busySiteId === program.id,
15132
+ title: '在系统浏览器打开 ' + program.name + ' 的页面'
15133
+ + (ydsProject ? '(yds 项目:请求自动带上登录 token,免登录)' : ''),
15134
+ onClick: function (event) { event.stopPropagation(); openSite(program) },
15135
+ }, busySiteId === program.id ? '…' : '🌐')
15136
+ : null,
14673
15137
  h('button', {
14674
15138
  type: 'button', style: S.button, 'data-action': 'enter',
14675
15139
  title: '进入 IDE:文件树 / 源码(行号断点)/ 调试 / 实时日志',
@@ -14713,12 +15177,6 @@ var [ui, setUi] = useState(function () {
14713
15177
  styles: S, kind: 'config-generated', signature: 'generated:' + String(state.config.path), onDismiss: panelDismissals.dismiss,
14714
15178
  }, '已按扫描结果自动生成配置 ' + state.config.path + '(可编辑,保存后生效)')
14715
15179
  : null,
14716
- state.config !== undefined && state.config !== null && state.config.status === 'updated'
14717
- && panelDismissals.isOpen('config-updated', 'updated')
14718
- ? h(ClosableNotice, {
14719
- styles: S, kind: 'config-updated', signature: 'updated', onDismiss: panelDismissals.dismiss,
14720
- }, '配置已与工作区同步(新增程序已补、失效条目已删;你改过的字段保留)')
14721
- : null,
14722
15180
  state.config !== undefined && state.config !== null && state.config.drift !== undefined
14723
15181
  && state.config.drift !== null && state.config.drift.stale === true
14724
15182
  && panelDismissals.isOpen('drift', driftSignature(state.config.drift))
@@ -14768,6 +15226,13 @@ var [ui, setUi] = useState(function () {
14768
15226
  RisIdeWindowAction: RisIdeWindowAction,
14769
15227
  /** The header button's cwd source: the session store, never the remembered one. */
14770
15228
  sessionWorkspaceCwd: sessionWorkspaceCwd,
15229
+ // Per-session workspace memory: what keeps the console and a log pane on
15230
+ // THEIR workspace while other documents on the same origin remember another.
15231
+ rememberSessionCwd: rememberSessionCwd,
15232
+ knownSessionCwd: knownSessionCwd,
15233
+ SESSION_CWD_PREFIX: SESSION_CWD_PREFIX,
15234
+ rememberWorkspaceCwd: rememberWorkspaceCwd,
15235
+ knownWorkspaceCwd: knownWorkspaceCwd,
14771
15236
  openStandaloneWindow: openStandaloneWindow,
14772
15237
  mountStandalone: mountStandalone,
14773
15238
  StandaloneWindow: StandaloneWindow,
@@ -14800,8 +15265,6 @@ var [ui, setUi] = useState(function () {
14800
15265
  COMPACT_PANE_DEFAULT: COMPACT_PANE_DEFAULT,
14801
15266
  COMPACT_UI_KEY: COMPACT_UI_KEY,
14802
15267
  CompactLogHead: CompactLogHead,
14803
- COMPACT_MAX_KEY: COMPACT_MAX_KEY,
14804
- readCompactMax: readCompactMax,
14805
15268
  readCompactPaneHeight: readCompactPaneHeight,
14806
15269
  requestDebug: requestDebug,
14807
15270
  requestDebugs: requestDebugs,
@@ -14853,6 +15316,14 @@ var [ui, setUi] = useState(function () {
14853
15316
  debugSnapshotSuspended: debugSnapshotSuspended,
14854
15317
  debugSuspendedThreadId: debugSuspendedThreadId,
14855
15318
  readSavedUi: readSavedUi,
15319
+ // Notice dismissals are shared module state (m00388): the ✕ has to stick for
15320
+ // every mounted copy of the panel, so the table itself is the test seam.
15321
+ noticeIsOpen: noticeIsOpen,
15322
+ dismissNotice: dismissNotice,
15323
+ __resetNoticeDismissals: function () {
15324
+ NOTICE_DISMISSALS = {}
15325
+ NOTICE_DISMISSAL_LISTENERS.forEach(function (listener) { listener() })
15326
+ },
14856
15327
  treeLabel: treeLabel,
14857
15328
  childEntryFor: childEntryFor,
14858
15329
  pathWithin: pathWithin,