dsh-ris-ide 1.8.2 → 1.8.4

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
@@ -269,10 +269,17 @@ window.__ModuleLoader__.load({
269
269
  * `sessionId` can go stale and the host then answers every route with 400.
270
270
  * The host accepts an absolute `cwd` from the client, which is enough to keep
271
271
  * the panel working across a session switch or a `dsh web` restart.
272
+ *
273
+ * ONLY the DSH page writes this slot. The standalone window and the IDE inside
274
+ * the risd-ui tab are separate surfaces with their own workspace in the URL:
275
+ * letting them overwrite the slot made the DSH console open the workspace the
276
+ * embedded IDE happened to switch to (m00173-3). They keep using their own
277
+ * (session, cwd) scope and the per-session keys.
272
278
  * @param {string} value - absolute workspace path.
273
279
  */
274
280
  function rememberWorkspaceCwd(value) {
275
281
  if (typeof value !== 'string' || value === '' || value[0] !== '/') return
282
+ if (typeof window !== 'undefined' && window.__dshRisIdeWindow === true) return
276
283
  try { window.localStorage.setItem(WORKSPACE_CWD_KEY, value) } catch { /* private mode */ }
277
284
  }
278
285
 
@@ -286,6 +293,43 @@ window.__ModuleLoader__.load({
286
293
  }
287
294
  }
288
295
 
296
+ /**
297
+ * Where the host last answered that ONE session's workspace is.
298
+ *
299
+ * `knownWorkspaceCwd()` is a single slot shared by every document on this
300
+ * origin — the dsh page, the IDE in a risd-ui tab, a standalone window — so it
301
+ * names whichever panel talked to the host LAST. Reading it as "my workspace"
302
+ * is what made the sidebar console follow an IDE workspace switch made
303
+ * somewhere else (and the other way round). Per-session keys keep each panel
304
+ * on the workspace its own session belongs to (m04873).
305
+ */
306
+ var SESSION_CWD_PREFIX = 'dsh-ris-ide:cwd:'
307
+
308
+ /**
309
+ * Remember the workspace of one session (absolute paths only).
310
+ * @param {string} value - absolute workspace path.
311
+ * @param {string} sessionId - the session the answer belongs to.
312
+ */
313
+ function rememberSessionCwd(value, sessionId) {
314
+ if (typeof value !== 'string' || value === '' || value[0] !== '/') return
315
+ if (typeof sessionId !== 'string' || sessionId === '') return
316
+ try { window.localStorage.setItem(SESSION_CWD_PREFIX + sessionId, value) } catch { /* private mode */ }
317
+ }
318
+
319
+ /**
320
+ * @param {string|undefined} sessionId - the session to look up.
321
+ * @returns {string|undefined} that session's remembered workspace.
322
+ */
323
+ function knownSessionCwd(sessionId) {
324
+ if (typeof sessionId !== 'string' || sessionId === '') return undefined
325
+ try {
326
+ var value = window.localStorage.getItem(SESSION_CWD_PREFIX + sessionId)
327
+ return typeof value === 'string' && value[0] === '/' ? value : undefined
328
+ } catch {
329
+ return undefined
330
+ }
331
+ }
332
+
289
333
  /**
290
334
  * A scope with a usable `cwd`, falling back to the remembered workspace.
291
335
  * @param {{sessionId?: string, cwd?: string}|undefined} scope - caller scope.
@@ -449,16 +493,27 @@ window.__ModuleLoader__.load({
449
493
  * event (same origin, fires in every other window) carries the selected log
450
494
  * path, so starting a program from the console also moves the IDE window's log
451
495
  * pane immediately instead of only when the debug session attaches ~40s later.
496
+ *
497
+ * The broadcast is SCOPED by (sessionId, cwd): two views of two different
498
+ * workspaces must stay independent — a start made in workspace B never moves
499
+ * the console that is showing workspace A (m00173-3).
452
500
  */
453
501
  var LOG_FOCUS_KEY = 'dsh-ris-ide:log-focus'
454
502
 
455
503
  /**
456
504
  * @param {string} logPath - the log the user should now be watching.
505
+ * @param {string} [sessionId] - the session the log belongs to.
506
+ * @param {string} [cwd] - the workspace the log belongs to.
457
507
  */
458
- function broadcastLogFocus(logPath) {
508
+ function broadcastLogFocus(logPath, sessionId, cwd) {
459
509
  if (typeof logPath !== 'string' || logPath === '') return
460
510
  try {
461
- window.localStorage.setItem(LOG_FOCUS_KEY, JSON.stringify({ path: logPath, at: Date.now() }))
511
+ window.localStorage.setItem(LOG_FOCUS_KEY, JSON.stringify({
512
+ path: logPath,
513
+ sessionId: typeof sessionId === 'string' ? sessionId : '',
514
+ cwd: typeof cwd === 'string' ? cwd : '',
515
+ at: Date.now(),
516
+ }))
462
517
  } catch { /* private mode / quota: the broadcast is best-effort */ }
463
518
  }
464
519
 
@@ -521,6 +576,48 @@ window.__ModuleLoader__.load({
521
576
  return true
522
577
  }
523
578
 
579
+ /** Normalised workspace path, for comparing two panels' scopes. */
580
+ function risScopeCwd(value) {
581
+ if (typeof value !== 'string' || value === '') return ''
582
+ return value.replace(/[\\/]+$/, '').replace(/\\/g, '/').toLowerCase()
583
+ }
584
+
585
+ /**
586
+ * Does this subscriber belong to the (Session, workspace) the socket carries?
587
+ *
588
+ * ONE socket has ONE scope, but DSH keeps a `keepMounted` panel body alive
589
+ * across Session switches, so the subscriber set can hold panels from several
590
+ * workspaces at once. The scope used to be picked from whichever panel
591
+ * subscribed first, and every frame was then handed to every subscriber of the
592
+ * topic: the console of workspace A painted B's rows (and after a few switches
593
+ * "内容窜"), because `programs` frames carry a `root` that the handler stored
594
+ * unexamined. Frames for another scope are NOT delivered here — that panel
595
+ * falls back to polling its own scope.
596
+ *
597
+ * A subscriber that names neither a session nor a workspace (the `opens` /
598
+ * `debugs` watchers) is connection-wide and matches every socket.
599
+ *
600
+ * @param {object} sub - the subscription.
601
+ * @param {string} sessionId - session the socket was opened for.
602
+ * @param {string} cwd - workspace the socket was opened for.
603
+ * @returns {boolean} whether the sub may receive this socket's frames.
604
+ */
605
+ function risScopeMatches(sub, sessionId, cwd) {
606
+ var subSession = typeof sub.sessionId === 'string' ? sub.sessionId : ''
607
+ var subCwd = risScopeCwd(sub.cwd)
608
+ var socketSession = typeof sessionId === 'string' ? sessionId : ''
609
+ var socketCwd = risScopeCwd(cwd)
610
+ if (subSession !== '' && socketSession !== '' && subSession !== socketSession) return false
611
+ if (subCwd !== '' && socketCwd !== '' && subCwd !== socketCwd) return false
612
+ return true
613
+ }
614
+
615
+ /** The session the right sidebar is showing RIGHT NOW (document-wide, visible marker only). */
616
+ function liveSidebarSessionOfDocument() {
617
+ var live = liveSidebarSessionId()
618
+ return typeof live === 'string' && live !== '' ? live : ''
619
+ }
620
+
524
621
  /** Subscribe an object `{topics, sessionId?, cwd?, handlers, onOpen?}` to the hub. */
525
622
  function risStreamHub() {
526
623
  if (RIS_STREAM_HUB !== null) return RIS_STREAM_HUB
@@ -529,6 +626,9 @@ window.__ModuleLoader__.load({
529
626
  var signature = ''
530
627
  /** The tail path the CURRENT connection carries ('' when none). */
531
628
  var servedTail = ''
629
+ /** The scope the CURRENT connection carries ('' = unknown / connection-wide). */
630
+ var servedSession = ''
631
+ var servedCwd = ''
532
632
  var rebuildTimer = null
533
633
  var retryTimer = null
534
634
  var retryDelay = 3000
@@ -574,20 +674,33 @@ window.__ModuleLoader__.load({
574
674
  return
575
675
  }
576
676
  var topics = []
577
- var sessionId
578
- var cwd
579
677
  var tail
580
678
  var tailBytes
581
679
  var debugPath
680
+ var firstSession
681
+ var firstCwd
682
+ var activeSession
683
+ var activeCwd
582
684
  subscribers.forEach(function (sub) {
583
685
  ;(sub.topics || []).forEach(function (topic) { if (topics.indexOf(topic) === -1) topics.push(topic) })
584
- if (sessionId === undefined && typeof sub.sessionId === 'string' && sub.sessionId !== '') sessionId = sub.sessionId
585
- if (cwd === undefined && typeof sub.cwd === 'string' && sub.cwd !== '') cwd = sub.cwd
586
- if (cwd === undefined) cwd = knownWorkspaceCwd()
686
+ var subSession = typeof sub.sessionId === 'string' ? sub.sessionId : ''
687
+ var subCwd = typeof sub.cwd === 'string' ? sub.cwd : ''
688
+ if (firstSession === undefined && subSession !== '') firstSession = subSession
689
+ if (firstCwd === undefined && subCwd !== '') firstCwd = subCwd
690
+ // The panel the user is looking at owns the socket. A kept-mounted panel
691
+ // from a previous Session just holds its subscription and polls instead
692
+ // of dragging the connection (and every other panel) to its own scope.
693
+ if (sub.active === true) {
694
+ if (activeSession === undefined && subSession !== '') activeSession = subSession
695
+ if (activeCwd === undefined && subCwd !== '') activeCwd = subCwd
696
+ }
587
697
  if (tail === undefined && typeof sub.tail === 'string' && sub.tail !== '') tail = sub.tail
588
698
  if (tailBytes === undefined && typeof sub.tailBytes === 'number' && sub.tailBytes > 0) tailBytes = sub.tailBytes
589
699
  if (debugPath === undefined && typeof sub.debugPath === 'string' && sub.debugPath !== '') debugPath = sub.debugPath
590
700
  })
701
+ var sessionId = activeSession !== undefined ? activeSession : firstSession
702
+ var cwd = activeCwd !== undefined ? activeCwd : firstCwd
703
+ if (cwd === undefined) cwd = knownWorkspaceCwd()
591
704
  topics.sort()
592
705
  var next = topics.join(',') + '|' + [sessionId || '', cwd || '', tail || '', tailBytes || '', debugPath || ''].join('|')
593
706
  if (source !== null && next === signature) {
@@ -601,6 +714,8 @@ window.__ModuleLoader__.load({
601
714
  closeSource()
602
715
  signature = next
603
716
  servedTail = tail || ''
717
+ servedSession = typeof sessionId === 'string' ? sessionId : ''
718
+ servedCwd = typeof cwd === 'string' ? cwd : ''
604
719
  var url = routeUrl('dsh-ris-ide/stream')
605
720
  url.searchParams.set('topics', topics.join(','))
606
721
  if (sessionId !== undefined) url.searchParams.set('sessionId', sessionId)
@@ -653,6 +768,11 @@ window.__ModuleLoader__.load({
653
768
  var payload
654
769
  try { payload = JSON.parse(event.data) } catch { return }
655
770
  subscribers.forEach(function (sub) {
771
+ // Frames belong to the socket's ONE scope. `stream-error` is a
772
+ // connection-wide report, everything else must match the subscriber's
773
+ // own (session, workspace) — a kept-mounted panel from another Session
774
+ // polls its scope instead of painting this one's rows.
775
+ if (topic !== 'stream-error' && !risScopeMatches(sub, servedSession, servedCwd)) return
656
776
  // A frame does not always belong to its own topic (tail bytes arrive
657
777
  // as `append`): risFrameWanted owns that mapping.
658
778
  if (!risFrameWanted(sub.topics, topic, sub.tail, servedTail)) return
@@ -662,10 +782,17 @@ window.__ModuleLoader__.load({
662
782
  })
663
783
  })
664
784
  }
665
- /** Tell subscribers the connection is up, and WHICH tail it carries. */
785
+ /** Tell subscribers the connection is up, WHICH tail it carries and WHICH scope. */
666
786
  function notifyOpen() {
667
787
  subscribers.forEach(function (sub) {
668
- if (typeof sub.onOpen === 'function') sub.onOpen({ tail: servedTail })
788
+ if (typeof sub.onOpen !== 'function') return
789
+ sub.onOpen({
790
+ tail: servedTail,
791
+ sessionId: servedSession,
792
+ cwd: servedCwd,
793
+ // This panel's scope is not the one on the wire: it must poll, not wait.
794
+ scopeMismatch: !risScopeMatches(sub, servedSession, servedCwd),
795
+ })
669
796
  })
670
797
  }
671
798
  function scheduleRetry() {
@@ -2234,7 +2361,13 @@ window.__ModuleLoader__.load({
2234
2361
  // poll timer far more often than once a second.
2235
2362
  var sessionId = scope ? scope.sessionId : undefined
2236
2363
  var cwd = scope ? scope.cwd : undefined
2237
- if (typeof cwd !== 'string' || cwd === '') cwd = knownWorkspaceCwd()
2364
+ // Same rule as the console: a log pane follows ITS scope, never another
2365
+ // document's remembered workspace (m04873).
2366
+ if (typeof cwd !== 'string' || cwd === '') {
2367
+ var scopedCwd = knownSessionCwd(sessionId)
2368
+ cwd = typeof scopedCwd === 'string' && scopedCwd !== '' ? scopedCwd
2369
+ : (typeof sessionId === 'string' && sessionId !== '' ? undefined : knownWorkspaceCwd())
2370
+ }
2238
2371
  var [view, setView] = useState(function () { return stateFromPayload(props.customData) })
2239
2372
  // These controls live in the LOG PANE'S TITLE BAR inside the IDE, so the
2240
2373
  // workbench passes them down (value + change callback) and the viewer body
@@ -2398,11 +2531,14 @@ window.__ModuleLoader__.load({
2398
2531
  onOpen: function (info) {
2399
2532
  failures = 0
2400
2533
  // The panel shares ONE streaming socket and that socket carries ONE
2401
- // tail path. When the host bound it to another file (another log viewer
2402
- // mounted first), this pane would never see its own file on the stream
2403
- // — poll `/tail` for it instead of waiting forever.
2534
+ // tail path AND one (Session, workspace). When the host bound it to
2535
+ // another file or another workspace (another pane mounted first, or a
2536
+ // kept panel from an older Session still holds the connection), this
2537
+ // pane would never see its own file on the stream — poll `/tail` for it
2538
+ // instead of waiting forever.
2404
2539
  var served = info !== null && info !== undefined && typeof info.tail === 'string' ? info.tail : ''
2405
- setStreamOk(served === '' || served === path)
2540
+ var mismatch = info !== null && info !== undefined && info.scopeMismatch === true
2541
+ setStreamOk(mismatch !== true && (served === '' || served === path))
2406
2542
  },
2407
2543
  onError: function (readyState) {
2408
2544
  failures += 1
@@ -7539,6 +7675,14 @@ window.__ModuleLoader__.load({
7539
7675
  var openProgram = props !== null && props !== undefined && props.openProgram !== null && typeof props.openProgram === 'object' ? props.openProgram : null
7540
7676
  var openLogPath = openProgram !== null && typeof openProgram.logPath === 'string' ? openProgram.logPath : ''
7541
7677
  var visible = props ? props.visible !== false : true
7678
+ /**
7679
+ * The console's 🌐 button. The URL/token work lives in the OWNING panel
7680
+ * (`ProgramsPanel.openSite`) because this component never scans: it only
7681
+ * knows the `programs` array it is handed (m04354/m03945).
7682
+ */
7683
+ var onOpenSite = typeof props.onOpenSite === 'function' ? props.onOpenSite : null
7684
+ var siteBusyId = typeof props.siteBusyId === 'string' ? props.siteBusyId : undefined
7685
+ var ydsProject = props.ydsProject === true
7542
7686
  /** The workspace search box (Ctrl+Alt+F / F3 target outside the editor). */
7543
7687
  var searchInputRef = useRef(null)
7544
7688
  /** The panel root: the boundary of "inside the IDE" for the shortcut shield. */
@@ -7946,6 +8090,14 @@ var [ui, setUi] = useState(function () {
7946
8090
  if (event.key !== LOG_FOCUS_KEY || typeof event.newValue !== 'string' || event.newValue === '') return
7947
8091
  var parsed
7948
8092
  try { parsed = JSON.parse(event.newValue) } catch (error) { return }
8093
+ // The broadcast is scoped: a start made in another workspace must not
8094
+ // move THIS window's log pane (two surfaces, two Sessions — m00173-3).
8095
+ var mineSession = typeof sessionId === 'string' ? sessionId : ''
8096
+ var mineCwd = risScopeCwd(typeof cwd === 'string' ? cwd : '')
8097
+ var theirSession = parsed !== null && typeof parsed.sessionId === 'string' ? parsed.sessionId : ''
8098
+ var theirCwd = risScopeCwd(parsed !== null && typeof parsed.cwd === 'string' ? parsed.cwd : '')
8099
+ if (mineSession !== '' && theirSession !== '' && mineSession !== theirSession) return
8100
+ if (mineCwd !== '' && theirCwd !== '' && mineCwd !== theirCwd) return
7949
8101
  var path = parsed !== null && typeof parsed.path === 'string' ? parsed.path : ''
7950
8102
  if (path === '') return
7951
8103
  var found
@@ -8788,7 +8940,7 @@ var [ui, setUi] = useState(function () {
8788
8940
  // Watch this program's log while it starts: mvn compile is quiet, so the
8789
8941
  // view has to switch at click time, not after the spawn settles.
8790
8942
  selectProgram(program)
8791
- broadcastLogFocus(program.logPath)
8943
+ broadcastLogFocus(program.logPath, sessionId, cwd)
8792
8944
  var logPath = typeof program.logPath === 'string' ? program.logPath : ''
8793
8945
  // Same first-output watch as the debug path. Without it the pane can sit on
8794
8946
  // the wrapper's marker/command line forever: a start's output arrives as
@@ -8831,7 +8983,7 @@ var [ui, setUi] = useState(function () {
8831
8983
  /** Restart one program: the host stops it (pidfile released) then starts it. */
8832
8984
  async function consoleRestart(program) {
8833
8985
  selectProgram(program)
8834
- broadcastLogFocus(program.logPath)
8986
+ broadcastLogFocus(program.logPath, sessionId, cwd)
8835
8987
  var logPath = typeof program.logPath === 'string' ? program.logPath : ''
8836
8988
  var baseline = logPath === '' ? undefined : await logSizeOf(logPath)
8837
8989
  statusNote('正在重启 ' + program.name + '…', 0)
@@ -8885,7 +9037,7 @@ var [ui, setUi] = useState(function () {
8885
9037
  setConsoleBusyKind(kind)
8886
9038
  if (kind === 'start') {
8887
9039
  selectProgram(targets[index])
8888
- broadcastLogFocus(targets[index].logPath)
9040
+ broadcastLogFocus(targets[index].logPath, sessionId, cwd)
8889
9041
  }
8890
9042
  try {
8891
9043
  var result = kind === 'start'
@@ -8909,7 +9061,7 @@ var [ui, setUi] = useState(function () {
8909
9061
  }
8910
9062
  async function consoleDebug(program) {
8911
9063
  selectProgram(program)
8912
- broadcastLogFocus(program.logPath)
9064
+ broadcastLogFocus(program.logPath, sessionId, cwd)
8913
9065
  sourcePathRef.current = {}
8914
9066
  setDbg(function () { return { attached: false, port: null, suspended: false, suspendedThreads: [], currentThreadId: null, seq: 0, events: [], breakpoints: globalBreakpointsSnapshot(), threads: [], frames: [], variables: [], missingSource: null, lastError: null } })
8915
9067
  setUi(function (prev) { return Object.assign({}, prev, { busy: true, note: '正在以调试模式重启 ' + program.name + '(Spring 约 40–55s)…' }) })
@@ -9187,7 +9339,7 @@ var [ui, setUi] = useState(function () {
9187
9339
  setActivePath(logPath)
9188
9340
  activePathRef.current = logPath
9189
9341
  }
9190
- broadcastLogFocus(logPath)
9342
+ broadcastLogFocus(logPath, sessionId, cwd)
9191
9343
  }
9192
9344
  var baseline = logPath === '' ? undefined : await logSizeOf(logPath)
9193
9345
  setUi(function (prev) { return Object.assign({}, prev, { busy: true, note: '正在以调试模式重启(Spring 约 40–55s)…' }) })
@@ -10698,6 +10850,19 @@ var [ui, setUi] = useState(function () {
10698
10850
  alive ? button(stopGlyph(11), function (event) { event.stopPropagation(); void consoleStop(program) }, { icon: true, width: 25, stop: true, action: 'console-stop', title: '停止 ' + program.name }) : null,
10699
10851
  // ⟳ shares ▶'s green: both (re)start the program, only ■ is red.
10700
10852
  startable ? button('⟳', function (event) { event.stopPropagation(); void consoleRestart(program) }, { icon: true, width: 25, start: true, action: 'console-restart', title: '重启 ' + program.name }) : null,
10853
+ // The IDE console has the same 🌐 as the sidebar console (m03945):
10854
+ // only a frontend serves a page, and only the owning panel can ask
10855
+ // the host where that page is (m04354).
10856
+ program.kind === 'frontend'
10857
+ ? button(siteBusyId === program.id ? '…' : '🌐', function (event) {
10858
+ event.stopPropagation()
10859
+ if (onOpenSite !== null) onOpenSite(program)
10860
+ }, {
10861
+ icon: true, width: 25, off: true, disabled: siteBusyId === program.id, action: 'console-open-site',
10862
+ title: '在系统浏览器打开 ' + program.name + ' 的页面'
10863
+ + (ydsProject ? '(yds 项目:请求自动带上登录 token,免登录)' : ''),
10864
+ })
10865
+ : null,
10701
10866
  program.kind === 'spring' ? button(ideBadgeIcon('bug', 'play', 13), function (event) { event.stopPropagation(); void consoleDebug(program) }, { icon: true, width: 25, debug: true, off: ui.busy, action: 'console-debug', title: '调试 ' + program.name }) : null,
10702
10867
  busy
10703
10868
  ? h('div', {
@@ -11901,6 +12066,12 @@ var [ui, setUi] = useState(function () {
11901
12066
  var session = payload.session !== null && payload.session !== undefined ? payload.session : null
11902
12067
  var live = session !== null ? session.id : undefined
11903
12068
  if (typeof live !== 'string' || live === '' || live === sessionId) return
12069
+ // This window is pinned to the workspace in its URL: a hello that
12070
+ // resolved to a DIFFERENT workspace belongs to another dsh window, and
12071
+ // following it is how the embedded IDE's console used to jump to
12072
+ // whatever workspace dsh had just switched to (m04873).
12073
+ if (typeof props.cwd === 'string' && props.cwd !== '' &&
12074
+ typeof payload.root === 'string' && payload.root !== '' && payload.root !== props.cwd) return
11904
12075
  var mine = payload.windowSession !== null && payload.windowSession !== undefined ? payload.windowSession : null
11905
12076
  // Still live: this window belongs to a session that exists, so the
11906
12077
  // newer session in the same workspace is a DIFFERENT thread — leave it.
@@ -13715,6 +13886,49 @@ var [ui, setUi] = useState(function () {
13715
13886
  openIdeTab(ctx)
13716
13887
  }
13717
13888
 
13889
+ /**
13890
+ * Resolve the URL "open in browser" should use for one program.
13891
+ *
13892
+ * The host decides: the dev-server URL the program printed into its log, or —
13893
+ * when dsh-ris-yds is installed and the workspace is a yds project — yds'
13894
+ * injecting proxy, which also attaches a YYCToken to the page's gateway calls.
13895
+ * @param {object} program - one row from the programs panel.
13896
+ * @param {{sessionId: string, cwd?: string}} scope - owning session.
13897
+ * @returns {Promise<{ok: boolean, url?: string, message?: string, code?: string}>}
13898
+ */
13899
+ async function requestOpenTarget(program, scope) {
13900
+ var query = new URLSearchParams()
13901
+ query.set('sessionId', scope.sessionId)
13902
+ if (typeof scope.cwd === 'string' && scope.cwd !== '') query.set('cwd', scope.cwd)
13903
+ if (typeof program.id === 'string' && program.id !== '') query.set('id', program.id)
13904
+ var response = await fetch(routeUrl('dsh-ris-ide/open-target?' + query.toString()).href, { headers: { accept: 'application/json' } })
13905
+ var parsed = await response.json().catch(function () { return null })
13906
+ if (parsed !== null && typeof parsed === 'object') return parsed
13907
+ return { ok: false, code: 'http', message: 'HTTP ' + response.status }
13908
+ }
13909
+
13910
+ /**
13911
+ * Is the workspace a yds project? The console asks dsh-ris-yds, so a bare
13912
+ * workspace never sees yds wording and the row cannot promise a token it will
13913
+ * not get. A missing plugin (404) is "not a yds project", never an error.
13914
+ * @param {{sessionId: string, cwd?: string}} scope - owning session.
13915
+ * @returns {Promise<boolean>} whether dsh-ris-yds found a `yds.*` project here.
13916
+ */
13917
+ async function requestYdsProject(scope) {
13918
+ var workspace = typeof scope.cwd === 'string' ? scope.cwd : ''
13919
+ if (workspace === '') return false
13920
+ try {
13921
+ var query = new URLSearchParams()
13922
+ query.set('workspace', workspace)
13923
+ var response = await fetch(routeUrl('dsh-ris-yds/probe?' + query.toString()).href, { headers: { accept: 'application/json' } })
13924
+ if (!response.ok) return false
13925
+ var parsed = await response.json()
13926
+ return parsed !== null && typeof parsed === 'object' && parsed.yds === true
13927
+ } catch (error) {
13928
+ return false
13929
+ }
13930
+ }
13931
+
13718
13932
  /**
13719
13933
  * Ask the host to start one discovered program.
13720
13934
  *
@@ -14002,9 +14216,21 @@ var [ui, setUi] = useState(function () {
14002
14216
  // can still name the PREVIOUS session, so the store's value wins when the
14003
14217
  // slot hands us `useSessions`.
14004
14218
  var storeCwd = sessionWorkspaceCwd(props ? props.useSessions : undefined, sessionId)
14005
- if (typeof storeCwd === 'string' && storeCwd !== '') cwd = storeCwd
14006
- // A stale session id must not blank the panel: the host still accepts a cwd.
14007
- if (typeof cwd !== 'string' || cwd === '') cwd = knownWorkspaceCwd()
14219
+ // A workspace we are SURE about: the session store's answer, or what the host
14220
+ // answered for this same session earlier. Anything else (a prop inherited from
14221
+ // a retained tab, the origin-wide last-cwd slot) is a guess, and a guess must
14222
+ // never override the host's own session → workspace resolution (m04873).
14223
+ var cwdKnown = false
14224
+ if (typeof storeCwd === 'string' && storeCwd !== '') {
14225
+ cwd = storeCwd
14226
+ cwdKnown = true
14227
+ } else {
14228
+ var sessionCwd = knownSessionCwd(sessionId)
14229
+ if (typeof sessionCwd === 'string' && sessionCwd !== '') {
14230
+ cwd = sessionCwd
14231
+ cwdKnown = true
14232
+ }
14233
+ }
14008
14234
  /**
14009
14235
  * Publish the freshest (Session, workspace) pair to `fsOp`'s one-shot retry.
14010
14236
  * A mutation refused as `outside-workspace` means the host fenced it against a
@@ -14027,7 +14253,22 @@ var [ui, setUi] = useState(function () {
14027
14253
  useEffect(function () {
14028
14254
  setCompactPick(undefined)
14029
14255
  setActive(undefined)
14030
- }, [sessionIdentity])
14256
+ // The console rows and the tree root are workspace data as well: until the
14257
+ // first scan of the NEW scope lands, show "scanning" instead of the previous
14258
+ // workspace's rows. A stale row also feeds a stale absolute log path into
14259
+ // the compact LogTail, which then reads the old project's log under the new
14260
+ // session id ("new scope + old path").
14261
+ setState(function (prev) {
14262
+ if (prev.loading === true && prev.programs.length === 0 && prev.root === undefined) return prev
14263
+ return { loading: true, programs: [], root: undefined, dir: undefined, config: undefined, error: undefined, note: prev.note }
14264
+ })
14265
+ }, [sessionIdentity, cwd])
14266
+ // NOTE: this panel must NOT open its own sidebar tab. `openTab()` expands the
14267
+ // sidebar column (a session starts collapsed and empty by design), so doing
14268
+ // it on every session change is what made the console pop open by itself at
14269
+ // the start of a session. The tab is opened by user actions only
14270
+ // (`openIdeTab` from the header/⧉/log routes); a session with no layout yet
14271
+ // simply keeps the panel closed until the user asks for it.
14031
14272
  /** Warm the compact ⧉'s address; a fresh cache makes the click synchronous. */
14032
14273
  function warmCompactRisd() {
14033
14274
  if (typeof sessionId !== 'string' || sessionId === '') return
@@ -14090,11 +14331,28 @@ var [ui, setUi] = useState(function () {
14090
14331
  }, [state.note])
14091
14332
 
14092
14333
  var [busyId, setBusyId] = useState(undefined)
14334
+ // Which row's 🌐 is in flight: a second click while the host resolves the URL
14335
+ // would open two tabs at the same address.
14336
+ var [busySiteId, setBusySiteId] = useState(undefined)
14337
+ // "Open in browser" is a frontend-only affordance; only a yds project may
14338
+ // mention the token (m04354: a backend row has no page to open, and a plain
14339
+ // workspace must never read yds wording).
14340
+ var [ydsProject, setYdsProject] = useState(false)
14341
+ useEffect(function () {
14342
+ var alive = true
14343
+ requestYdsProject({ sessionId: sessionId, cwd: cwd }).then(function (found) {
14344
+ if (alive) setYdsProject(found === true)
14345
+ })
14346
+ return function () { alive = false }
14347
+ }, [cwd, props.visible])
14093
14348
  /** The compact ⧉ is opening the page: disable it and show progress. */
14094
14349
  var [openingIde, setOpeningIde] = useState(false)
14095
14350
  /** Which action `busyId` is running, for the row mask's wording. */
14096
14351
  var [busyKind, setBusyKind] = useState('')
14097
- var busyRef = useRef(false)
14352
+ // Which (session, workspace) scope the in-flight scan belongs to. A switch
14353
+ // must be able to start a scan of the NEW scope even while the OLD one is
14354
+ // still in flight, and the late answer of the old one must not be rendered.
14355
+ var busyScopeRef = useRef('')
14098
14356
  /** A start-all/stop-all pass in flight: `{kind, index, total}` or null. */
14099
14357
  var [bulk, setBulk] = useState(null)
14100
14358
  /**
@@ -14112,16 +14370,32 @@ var [ui, setUi] = useState(function () {
14112
14370
  var panelDismissals = useDismissedNotices()
14113
14371
 
14114
14372
  var refresh = React.useCallback(async function (force) {
14115
- if (typeof sessionId !== 'string' || sessionId === '' || busyRef.current) return
14116
- busyRef.current = true
14373
+ if (typeof sessionId !== 'string' || sessionId === '') return
14374
+ var scope = sessionId + '|' + (typeof cwd === 'string' ? cwd : '')
14375
+ if (busyScopeRef.current === scope) return
14376
+ busyScopeRef.current = scope
14117
14377
  try {
14118
14378
  var url = routeUrl('dsh-ris-ide/programs')
14119
14379
  url.searchParams.set('sessionId', sessionId)
14120
- if (typeof cwd === 'string' && cwd !== '') url.searchParams.set('cwd', cwd)
14380
+ // Only a CERTAIN workspace may steer the host: a guessed cwd (a retained
14381
+ // prop, the origin-wide last-cwd slot) is exactly how one panel used to
14382
+ // drag another panel's console to its own workspace. Without it the host
14383
+ // resolves the workspace from the session header, which is the truth.
14384
+ if (cwdKnown === true && typeof cwd === 'string' && cwd !== '') url.searchParams.set('cwd', cwd)
14121
14385
  if (force === true) url.searchParams.set('refresh', '1')
14122
14386
  var response = await fetch(url.href, { headers: { accept: 'application/json' } })
14123
14387
  var payload = await response.json().catch(function () { return undefined })
14124
- if (payload !== undefined && payload !== null) rememberWorkspaceCwd(payload.root)
14388
+ // The user switched workspace while this request was on the wire: its
14389
+ // rows belong to the previous scope, so drop them instead of rendering
14390
+ // them under the new session id.
14391
+ if (busyScopeRef.current !== scope) return
14392
+ if (payload !== undefined && payload !== null) {
14393
+ // Remember the answer twice: under this session (what a panel of this
14394
+ // session may reuse) and in the origin-wide slot (the default workspace
14395
+ // when a window is opened without a session).
14396
+ rememberSessionCwd(payload.root, sessionId)
14397
+ rememberWorkspaceCwd(payload.root)
14398
+ }
14125
14399
  if (!response.ok || payload === undefined || payload.ok !== true) {
14126
14400
  setState(function (prev) {
14127
14401
  return Object.assign({}, prev, {
@@ -14145,9 +14419,9 @@ var [ui, setUi] = useState(function () {
14145
14419
  } catch (error) {
14146
14420
  setState(function (prev) { return Object.assign({}, prev, { loading: false, error: messageOf(error) }) })
14147
14421
  } finally {
14148
- busyRef.current = false
14422
+ if (busyScopeRef.current === scope) busyScopeRef.current = ''
14149
14423
  }
14150
- }, [sessionId, cwd])
14424
+ }, [sessionId, cwd, cwdKnown])
14151
14425
 
14152
14426
  // After a `dsh web` restart the console keeps its error row ("扫描失败…")
14153
14427
  // until something re-reads. The stream reopening IS that signal.
@@ -14163,9 +14437,17 @@ var [ui, setUi] = useState(function () {
14163
14437
  topics: ['programs'],
14164
14438
  sessionId: sessionId,
14165
14439
  cwd: typeof cwd === 'string' ? cwd : undefined,
14166
- onOpen: function () {
14440
+ // The shared socket serves ONE scope: the console the user is looking at.
14441
+ // A kept-mounted body of another Session stays subscribed but must not
14442
+ // pull the connection (and every panel) to its own workspace.
14443
+ active: typeof sessionId === 'string' && sessionId !== '' && sessionId === liveSidebarSessionOfDocument(),
14444
+ onOpen: function (info) {
14167
14445
  failures = 0
14168
- setStreamOk(true)
14446
+ // The socket carries another panel's scope: poll our own instead of
14447
+ // sitting on rows that will never arrive.
14448
+ var mismatch = info !== null && info !== undefined && info.scopeMismatch === true
14449
+ setStreamOk(mismatch !== true)
14450
+ if (mismatch === true) void refresh(false)
14169
14451
  },
14170
14452
  onError: function (readyState) {
14171
14453
  failures += 1
@@ -14173,6 +14455,15 @@ var [ui, setUi] = useState(function () {
14173
14455
  },
14174
14456
  handlers: {
14175
14457
  programs: function (payload) {
14458
+ // Defence in depth: a frame naming another workspace must never paint
14459
+ // this session's console (the hub already filters by scope, but this
14460
+ // handler is where the rows and the tree root are stored).
14461
+ if (cwdKnown === true && typeof cwd === 'string' && cwd !== '' &&
14462
+ payload !== null && payload !== undefined && typeof payload.root === 'string' && payload.root !== '' &&
14463
+ risScopeCwd(payload.root) !== risScopeCwd(cwd)) {
14464
+ void refresh(false)
14465
+ return
14466
+ }
14176
14467
  setState(function (prev) {
14177
14468
  return {
14178
14469
  loading: false,
@@ -14240,7 +14531,7 @@ var [ui, setUi] = useState(function () {
14240
14531
  setBusyKind(kind)
14241
14532
  if (kind === 'start') {
14242
14533
  setActive(targets[index])
14243
- broadcastLogFocus(targets[index].logPath)
14534
+ broadcastLogFocus(targets[index].logPath, sessionId, cwd)
14244
14535
  }
14245
14536
  var scopeArg = { sessionId: sessionId, cwd: cwd }
14246
14537
  var result
@@ -14277,7 +14568,7 @@ var [ui, setUi] = useState(function () {
14277
14568
  // Show this program's log from the first moment: the start call waits for
14278
14569
  // a pidfile (up to START_WAIT_MS), and Maven compile is silent. The same
14279
14570
  // event moves the standalone IDE window's log pane right away.
14280
- if (boots) { setActive(program); broadcastLogFocus(program.logPath); setCompactLogNonce(function (value) { return value + 1 }) }
14571
+ if (boots) { setActive(program); broadcastLogFocus(program.logPath, sessionId, cwd); setCompactLogNonce(function (value) { return value + 1 }) }
14281
14572
  var scopeArg = { sessionId: sessionId, cwd: cwd }
14282
14573
  var task = kind === 'stop'
14283
14574
  ? requestStop(program.logPath, scopeArg)
@@ -14308,6 +14599,53 @@ var [ui, setUi] = useState(function () {
14308
14599
  })
14309
14600
  }
14310
14601
 
14602
+ /**
14603
+ * Open one program in the user's own browser (🌐).
14604
+ *
14605
+ * A browser page cannot add headers to the tab it opens, so the token work
14606
+ * lives on the host side (dsh-ris-yds' proxy) and this only asks where to go.
14607
+ */
14608
+ function openSite(program) {
14609
+ if (busySiteId !== undefined) return
14610
+ setBusySiteId(program.id)
14611
+ requestOpenTarget(program, { sessionId: sessionId, cwd: cwd }).then(function (result) {
14612
+ setBusySiteId(undefined)
14613
+ if (result.ok !== true) {
14614
+ setState(function (prev) {
14615
+ return Object.assign({}, prev, { note: result.message || '这个程序还没有可打开的地址:先启动它' })
14616
+ })
14617
+ return
14618
+ }
14619
+ // yds started its own private browser (extension + CDP): nothing to open here.
14620
+ if (result.mode === 'debug') {
14621
+ setState(function (prev) {
14622
+ return Object.assign({}, prev, {
14623
+ note: result.pid !== undefined
14624
+ ? '已在专用调试浏览器打开(pid ' + result.pid + ',DevTools 127.0.0.1:' + result.port + ')'
14625
+ : '已在专用调试浏览器打开',
14626
+ })
14627
+ })
14628
+ return
14629
+ }
14630
+ var handle = null
14631
+ try {
14632
+ handle = window.open(String(result.url), 'dsh-ris-ide-site-' + String(program.id).replace(/[^A-Za-z0-9_-]/g, '-'))
14633
+ } catch (error) {
14634
+ handle = null
14635
+ }
14636
+ if (handle === null) {
14637
+ setState(function (prev) {
14638
+ return Object.assign({}, prev, { note: '浏览器拦截了新窗口:允许本站弹窗后再点一次 🌐' })
14639
+ })
14640
+ }
14641
+ }).catch(function (error) {
14642
+ setBusySiteId(undefined)
14643
+ setState(function (prev) {
14644
+ return Object.assign({}, prev, { note: '打开失败:' + messageOf(error) })
14645
+ })
14646
+ })
14647
+ }
14648
+
14311
14649
  /** Write or update the user-editable config from a scan. */
14312
14650
  function generateConfigFile(mode) {
14313
14651
  if (busyId !== undefined) return
@@ -14381,13 +14719,10 @@ var [ui, setUi] = useState(function () {
14381
14719
  text: '已按扫描结果自动生成配置 ' + path + '(可编辑,保存后生效)',
14382
14720
  })
14383
14721
  }
14384
- if (config.status === 'updated') {
14385
- items.push({
14386
- kind: 'config-updated',
14387
- signature: 'updated',
14388
- text: '配置已与工作区同步(新增程序已补、失效条目已删;你改过的字段保留)',
14389
- })
14390
- }
14722
+ // m03291: the automatic-sync row (status 'updated') is NOT shown any
14723
+ // more — it was pure noise after every workspace switch, and the sync
14724
+ // itself is silent anyway. The drift notice below is the actionable
14725
+ // one and stays; the compact panel dropped its own copy too.
14391
14726
  var drift = config.drift
14392
14727
  if (drift !== undefined && drift !== null && drift.stale === true) {
14393
14728
  items.push({
@@ -14590,6 +14925,21 @@ var [ui, setUi] = useState(function () {
14590
14925
  onClick: function (event) { event.stopPropagation(); void act('restart', program) },
14591
14926
  }, busy ? '…' : '⟳')
14592
14927
  : null,
14928
+ // Open the page the program serves, in the user's own browser. The URL
14929
+ // (and the token, for a yds project) is resolved by the host: a page
14930
+ // cannot add headers to a tab it opens itself.
14931
+ startable && program.kind === 'frontend'
14932
+ ? h('button', {
14933
+ type: 'button', style: busySiteId === program.id ? S.paneIconOff : S.paneIcon, disabled: busySiteId === program.id,
14934
+ 'data-action': 'open-site',
14935
+ title: '在系统浏览器打开 ' + program.name + ' 的页面'
14936
+ + (ydsProject ? '(yds 项目:请求自动带上登录 token,免登录)' : ''),
14937
+ onClick: function (event) {
14938
+ event.stopPropagation()
14939
+ openSite(program)
14940
+ },
14941
+ }, busySiteId === program.id ? '…' : '🌐')
14942
+ : null,
14593
14943
  program.kind === 'spring'
14594
14944
  ? h('button', {
14595
14945
  type: 'button', style: S.debugIcon, 'data-action': 'debug-window',
@@ -14795,8 +15145,10 @@ var [ui, setUi] = useState(function () {
14795
15145
  // A different file is a different viewer: remount it, exactly like
14796
15146
  // the IDE's log pane (`key: activePath`). Without the key the pane
14797
15147
  // kept the previous file's text while the title bar already showed
14798
- // the new program, so a pick looked like it did nothing.
14799
- key: logPath,
15148
+ // the new program, so a pick looked like it did nothing. A new
15149
+ // (session, workspace) scope is a different viewer even when the
15150
+ // path string happens to be equal.
15151
+ key: sessionIdentity + '|' + (typeof cwd === 'string' ? cwd : '') + '|' + logPath,
14800
15152
  scope: { sessionId: sessionId, cwd: cwd },
14801
15153
  path: logPath,
14802
15154
  // One source of truth for the follow switch, exactly like the IDE:
@@ -14845,6 +15197,12 @@ var [ui, setUi] = useState(function () {
14845
15197
  // The row the window was opened on (sidebar 🐞): seeds the log pane and
14846
15198
  // turns on auto-debug. `null` = plain workspace window.
14847
15199
  openProgram: active !== null && active !== undefined && typeof active === 'object' ? active : null,
15200
+ // The IDE console renders the same 🌐 as the sidebar rows: the URL/token
15201
+ // resolution and the "one tab at a time" guard stay HERE (this panel owns
15202
+ // the fetch and the note bar), the workbench only draws the button.
15203
+ onOpenSite: openSite,
15204
+ siteBusyId: busySiteId,
15205
+ ydsProject: ydsProject,
14848
15206
  tab: {
14849
15207
  id: PROGRAM_TAB_ID,
14850
15208
  type: PROGRAM_TAB_ID,
@@ -14903,6 +15261,15 @@ var [ui, setUi] = useState(function () {
14903
15261
  onClick: function () { openWorkbench(program, true) },
14904
15262
  }, '调试')
14905
15263
  : null,
15264
+ program.kind === 'frontend'
15265
+ ? h('button', {
15266
+ type: 'button', style: busySiteId === program.id ? S.paneIconOff : S.buttonOff, 'data-action': 'open-site',
15267
+ disabled: busySiteId === program.id,
15268
+ title: '在系统浏览器打开 ' + program.name + ' 的页面'
15269
+ + (ydsProject ? '(yds 项目:请求自动带上登录 token,免登录)' : ''),
15270
+ onClick: function (event) { event.stopPropagation(); openSite(program) },
15271
+ }, busySiteId === program.id ? '…' : '🌐')
15272
+ : null,
14906
15273
  h('button', {
14907
15274
  type: 'button', style: S.button, 'data-action': 'enter',
14908
15275
  title: '进入 IDE:文件树 / 源码(行号断点)/ 调试 / 实时日志',
@@ -14946,12 +15313,6 @@ var [ui, setUi] = useState(function () {
14946
15313
  styles: S, kind: 'config-generated', signature: 'generated:' + String(state.config.path), onDismiss: panelDismissals.dismiss,
14947
15314
  }, '已按扫描结果自动生成配置 ' + state.config.path + '(可编辑,保存后生效)')
14948
15315
  : null,
14949
- state.config !== undefined && state.config !== null && state.config.status === 'updated'
14950
- && panelDismissals.isOpen('config-updated', 'updated')
14951
- ? h(ClosableNotice, {
14952
- styles: S, kind: 'config-updated', signature: 'updated', onDismiss: panelDismissals.dismiss,
14953
- }, '配置已与工作区同步(新增程序已补、失效条目已删;你改过的字段保留)')
14954
- : null,
14955
15316
  state.config !== undefined && state.config !== null && state.config.drift !== undefined
14956
15317
  && state.config.drift !== null && state.config.drift.stale === true
14957
15318
  && panelDismissals.isOpen('drift', driftSignature(state.config.drift))
@@ -15001,6 +15362,13 @@ var [ui, setUi] = useState(function () {
15001
15362
  RisIdeWindowAction: RisIdeWindowAction,
15002
15363
  /** The header button's cwd source: the session store, never the remembered one. */
15003
15364
  sessionWorkspaceCwd: sessionWorkspaceCwd,
15365
+ // Per-session workspace memory: what keeps the console and a log pane on
15366
+ // THEIR workspace while other documents on the same origin remember another.
15367
+ rememberSessionCwd: rememberSessionCwd,
15368
+ knownSessionCwd: knownSessionCwd,
15369
+ SESSION_CWD_PREFIX: SESSION_CWD_PREFIX,
15370
+ rememberWorkspaceCwd: rememberWorkspaceCwd,
15371
+ knownWorkspaceCwd: knownWorkspaceCwd,
15004
15372
  openStandaloneWindow: openStandaloneWindow,
15005
15373
  mountStandalone: mountStandalone,
15006
15374
  StandaloneWindow: StandaloneWindow,