dsh-lmw-plugin 1.0.2 → 1.0.5
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/client.js +340 -2
- package/index.js +138 -0
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -133,6 +133,17 @@ window.__ModuleLoader__.load({
|
|
|
133
133
|
'import.blocked.title': 'Not addable ({n})',
|
|
134
134
|
'import.none': 'No addable sessions.',
|
|
135
135
|
'import.count': '{n} sessions',
|
|
136
|
+
'sort.footer': 'Sort workspaces',
|
|
137
|
+
'sort.title': 'Sort workspaces',
|
|
138
|
+
'sort.hint': 'Reorders the sidebar groups; the order is saved for this profile.',
|
|
139
|
+
'sort.byPath': 'By path name',
|
|
140
|
+
'sort.byName': 'By workspace name',
|
|
141
|
+
'sort.byActivity': 'By session activity',
|
|
142
|
+
'sort.applying': 'Reordering…',
|
|
143
|
+
'sort.manual': 'Manual (no auto sort)',
|
|
144
|
+
'offline.workspace': 'Workspace directory is missing (its drive may be unplugged)',
|
|
145
|
+
'offline.session': 'The workspace directory of this session is missing (its drive may be unplugged)',
|
|
146
|
+
'offline.input': 'This workspace directory is missing, so input is disabled',
|
|
136
147
|
},
|
|
137
148
|
zh: {
|
|
138
149
|
'footer.label': '会话分配检查',
|
|
@@ -234,6 +245,17 @@ window.__ModuleLoader__.load({
|
|
|
234
245
|
'import.blocked.title': '不可添加的会话({n})',
|
|
235
246
|
'import.none': '没有可添加的会话。',
|
|
236
247
|
'import.count': '{n} 个会话',
|
|
248
|
+
'sort.footer': '工作区排序',
|
|
249
|
+
'sort.title': '工作区排序',
|
|
250
|
+
'sort.hint': '调整侧栏工作区分组的顺序,顺序会保存到当前 profile。',
|
|
251
|
+
'sort.byPath': '按路径名',
|
|
252
|
+
'sort.byName': '按工作区名',
|
|
253
|
+
'sort.byActivity': '按会话活跃度',
|
|
254
|
+
'sort.applying': '正在调整…',
|
|
255
|
+
'sort.manual': '手动(不自动排序)',
|
|
256
|
+
'offline.workspace': '工作区目录不存在(可能所在磁盘已拔出)',
|
|
257
|
+
'offline.session': '该会话所属工作区目录不存在(可能所在磁盘已拔出)',
|
|
258
|
+
'offline.input': '该会话所属工作区目录不存在,无法输入',
|
|
237
259
|
},
|
|
238
260
|
}
|
|
239
261
|
|
|
@@ -1076,7 +1098,7 @@ window.__ModuleLoader__.load({
|
|
|
1076
1098
|
|
|
1077
1099
|
/** One footer seat holding the three actions stacked, so labels stay readable. */
|
|
1078
1100
|
function FooterActionsPanel(props) {
|
|
1079
|
-
const { wide, store, importStore } = props
|
|
1101
|
+
const { wide, store, importStore, sortStore } = props
|
|
1080
1102
|
const tr = makeT(props.translate ?? props.t)
|
|
1081
1103
|
const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot)
|
|
1082
1104
|
const importSnapshot = useSyncExternalStore(importStore.subscribe, importStore.getSnapshot)
|
|
@@ -1114,6 +1136,13 @@ window.__ModuleLoader__.load({
|
|
|
1114
1136
|
expanded: importSnapshot.dialogOpen === true,
|
|
1115
1137
|
onClick: () => importStore.toggle(),
|
|
1116
1138
|
}),
|
|
1139
|
+
h(FootRow, {
|
|
1140
|
+
wide,
|
|
1141
|
+
glyph: SORT_GLYPH,
|
|
1142
|
+
label: tr('sort.footer'),
|
|
1143
|
+
aria: tr('sort.title'),
|
|
1144
|
+
onClick: () => sortStore.toggle(),
|
|
1145
|
+
}),
|
|
1117
1146
|
)
|
|
1118
1147
|
}
|
|
1119
1148
|
|
|
@@ -1551,6 +1580,288 @@ window.__ModuleLoader__.load({
|
|
|
1551
1580
|
)
|
|
1552
1581
|
}
|
|
1553
1582
|
|
|
1583
|
+
/* ------------------------------------------------------------------ */
|
|
1584
|
+
/* Workspace sort and offline guard */
|
|
1585
|
+
/* ------------------------------------------------------------------ */
|
|
1586
|
+
|
|
1587
|
+
const SORT_GLYPH = h(
|
|
1588
|
+
'svg',
|
|
1589
|
+
{ width: 16, height: 16, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': 'true', focusable: 'false' },
|
|
1590
|
+
h('path', { d: 'M3 4.5h10M3 8h7M3 11.5h4', stroke: 'currentColor', 'stroke-width': 1.5, 'stroke-linecap': 'round' }),
|
|
1591
|
+
)
|
|
1592
|
+
|
|
1593
|
+
const SORT_STORAGE_KEY = 'lmw.workspaceSortMode'
|
|
1594
|
+
const SORT_MODES = ['path', 'title', 'activity']
|
|
1595
|
+
|
|
1596
|
+
function readStoredSortMode() {
|
|
1597
|
+
try {
|
|
1598
|
+
const mode = window.localStorage.getItem(SORT_STORAGE_KEY)
|
|
1599
|
+
return SORT_MODES.includes(mode) ? mode : null
|
|
1600
|
+
} catch {
|
|
1601
|
+
return null
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
function createSortStore() {
|
|
1606
|
+
let snapshot = { open: false, busy: false, error: null, mode: readStoredSortMode() }
|
|
1607
|
+
const listeners = new Set()
|
|
1608
|
+
const publish = (patch) => {
|
|
1609
|
+
snapshot = { ...snapshot, ...patch }
|
|
1610
|
+
for (const listener of [...listeners]) {
|
|
1611
|
+
try {
|
|
1612
|
+
listener()
|
|
1613
|
+
} catch (error) {
|
|
1614
|
+
console.error('[lmw-plugin] sort listener failed:', error)
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
const apply = async (mode) => {
|
|
1619
|
+
if (snapshot.busy) return
|
|
1620
|
+
if (mode === 'manual') {
|
|
1621
|
+
try {
|
|
1622
|
+
window.localStorage.removeItem(SORT_STORAGE_KEY)
|
|
1623
|
+
} catch {
|
|
1624
|
+
// A browser that refuses storage simply forgets the preference.
|
|
1625
|
+
}
|
|
1626
|
+
publish({ mode: null, open: false, error: null })
|
|
1627
|
+
return
|
|
1628
|
+
}
|
|
1629
|
+
publish({ busy: true, error: null })
|
|
1630
|
+
try {
|
|
1631
|
+
await requestJson('POST', 'workspaces/sort', { mode })
|
|
1632
|
+
try {
|
|
1633
|
+
window.localStorage.setItem(SORT_STORAGE_KEY, mode)
|
|
1634
|
+
} catch {
|
|
1635
|
+
// A browser that refuses storage simply forgets the preference.
|
|
1636
|
+
}
|
|
1637
|
+
publish({ busy: false, open: false, mode })
|
|
1638
|
+
} catch (error) {
|
|
1639
|
+
publish({ busy: false, error: messageOf(error) })
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
/** Re-apply the remembered mode at startup and after a page reload. */
|
|
1643
|
+
const autoApply = async () => {
|
|
1644
|
+
const mode = snapshot.mode
|
|
1645
|
+
if (mode === null) return
|
|
1646
|
+
try {
|
|
1647
|
+
await requestJson('POST', 'workspaces/sort', { mode })
|
|
1648
|
+
} catch (error) {
|
|
1649
|
+
console.error('[lmw-plugin] applying the remembered workspace sort failed:', error)
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
return {
|
|
1653
|
+
getSnapshot: () => snapshot,
|
|
1654
|
+
subscribe: (listener) => {
|
|
1655
|
+
listeners.add(listener)
|
|
1656
|
+
return () => listeners.delete(listener)
|
|
1657
|
+
},
|
|
1658
|
+
open: () => publish({ open: true, error: null }),
|
|
1659
|
+
close: () => publish({ open: false, error: null }),
|
|
1660
|
+
toggle: () => publish({ open: !snapshot.open, error: null }),
|
|
1661
|
+
apply,
|
|
1662
|
+
autoApply,
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
/** Always-mounted guard: mark Workspaces whose directory vanished and block them. */
|
|
1667
|
+
function WorkspaceOfflineGuard(props) {
|
|
1668
|
+
const tr = makeT(props.translate ?? props.t)
|
|
1669
|
+
useEffect(() => {
|
|
1670
|
+
document.body.setAttribute('data-lmw-guard', JSON.stringify({ mounted: true }))
|
|
1671
|
+
let statuses = { workspaces: {}, sessions: {} }
|
|
1672
|
+
let disposed = false
|
|
1673
|
+
let timer = 0
|
|
1674
|
+
|
|
1675
|
+
const mark = () => {
|
|
1676
|
+
try {
|
|
1677
|
+
for (const row of document.querySelectorAll('[data-row-key^="workspace:"]')) {
|
|
1678
|
+
const id = row.getAttribute('data-row-key').slice('workspace:'.length)
|
|
1679
|
+
const missing = statuses.workspaces[id] === true
|
|
1680
|
+
row.toggleAttribute('data-lmw-offline', missing)
|
|
1681
|
+
if (missing) {
|
|
1682
|
+
row.setAttribute('title', tr('offline.workspace'))
|
|
1683
|
+
row.setAttribute('aria-disabled', 'true')
|
|
1684
|
+
} else {
|
|
1685
|
+
row.removeAttribute('title')
|
|
1686
|
+
row.removeAttribute('aria-disabled')
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
for (const row of document.querySelectorAll('[data-row-key^="session:"]')) {
|
|
1690
|
+
const id = row.getAttribute('data-row-key').slice('session:'.length)
|
|
1691
|
+
const missing = statuses.sessions[id] === true
|
|
1692
|
+
row.toggleAttribute('data-lmw-offline', missing)
|
|
1693
|
+
if (missing) {
|
|
1694
|
+
row.setAttribute('title', tr('offline.session'))
|
|
1695
|
+
row.setAttribute('aria-disabled', 'true')
|
|
1696
|
+
} else {
|
|
1697
|
+
row.removeAttribute('title')
|
|
1698
|
+
row.removeAttribute('aria-disabled')
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
const selected = document.querySelector('[data-row-key^="session:"][aria-selected="true"]')
|
|
1702
|
+
const sessionId = selected?.getAttribute('data-row-key')?.slice('session:'.length)
|
|
1703
|
+
const offlineActive = sessionId !== undefined && statuses.sessions[sessionId] === true
|
|
1704
|
+
const composer = document.querySelector('[data-lmw-composer]')
|
|
1705
|
+
?? document.querySelector('[contenteditable="true"]')
|
|
1706
|
+
if (composer !== null) {
|
|
1707
|
+
composer.setAttribute('data-lmw-composer', '')
|
|
1708
|
+
composer.toggleAttribute('data-lmw-offline-composer', offlineActive)
|
|
1709
|
+
if (offlineActive) {
|
|
1710
|
+
composer.setAttribute('title', tr('offline.input'))
|
|
1711
|
+
composer.setAttribute('aria-disabled', 'true')
|
|
1712
|
+
} else {
|
|
1713
|
+
composer.removeAttribute('title')
|
|
1714
|
+
composer.removeAttribute('aria-disabled')
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
} catch (error) {
|
|
1718
|
+
console.error('[lmw-plugin] offline marking failed:', error)
|
|
1719
|
+
document.body.setAttribute('data-lmw-guard', JSON.stringify({ markError: messageOf(error) }))
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
const schedule = () => {
|
|
1724
|
+
if (timer !== 0) return
|
|
1725
|
+
timer = window.setTimeout(() => {
|
|
1726
|
+
timer = 0
|
|
1727
|
+
mark()
|
|
1728
|
+
}, 120)
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
const load = async () => {
|
|
1732
|
+
try {
|
|
1733
|
+
const data = await requestJson('GET', 'workspaces/status')
|
|
1734
|
+
const workspaces = {}
|
|
1735
|
+
const sessions = {}
|
|
1736
|
+
for (const workspace of data.workspaces ?? []) {
|
|
1737
|
+
workspaces[workspace.id] = workspace.missing === true
|
|
1738
|
+
for (const sid of workspace.sessionIds ?? []) sessions[sid] = workspace.missing === true
|
|
1739
|
+
}
|
|
1740
|
+
if (!disposed) {
|
|
1741
|
+
statuses = { workspaces, sessions }
|
|
1742
|
+
mark()
|
|
1743
|
+
document.body.setAttribute('data-lmw-guard', JSON.stringify({
|
|
1744
|
+
loaded: true,
|
|
1745
|
+
workspaces: Object.keys(workspaces).length,
|
|
1746
|
+
missing: Object.values(workspaces).filter(Boolean).length,
|
|
1747
|
+
rows: document.querySelectorAll('[data-row-key^="workspace:"]').length,
|
|
1748
|
+
offline: document.querySelectorAll('[data-lmw-offline]').length,
|
|
1749
|
+
}))
|
|
1750
|
+
}
|
|
1751
|
+
} catch (error) {
|
|
1752
|
+
if (!disposed) {
|
|
1753
|
+
document.body.setAttribute('data-lmw-guard', JSON.stringify({ loaded: false, error: messageOf(error) }))
|
|
1754
|
+
}
|
|
1755
|
+
console.error('[lmw-plugin] workspace status failed:', error)
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
const blockRow = (event) => {
|
|
1760
|
+
const row = event.target instanceof Element ? event.target.closest('[data-lmw-offline]') : null
|
|
1761
|
+
if (row === null) return
|
|
1762
|
+
event.preventDefault()
|
|
1763
|
+
event.stopPropagation()
|
|
1764
|
+
}
|
|
1765
|
+
const blockInput = (event) => {
|
|
1766
|
+
const target = event.target instanceof Element ? event.target : null
|
|
1767
|
+
if (target === null || target.closest('[data-lmw-offline-composer]') === null) return
|
|
1768
|
+
event.preventDefault()
|
|
1769
|
+
event.stopPropagation()
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
const observer = new MutationObserver(schedule)
|
|
1773
|
+
observer.observe(document.body, { childList: true, subtree: true })
|
|
1774
|
+
document.addEventListener('click', blockRow, true)
|
|
1775
|
+
document.addEventListener('keydown', blockRow, true)
|
|
1776
|
+
for (const type of ['keydown', 'beforeinput', 'paste', 'drop']) document.addEventListener(type, blockInput, true)
|
|
1777
|
+
const interval = window.setInterval(() => { void load() }, 20000)
|
|
1778
|
+
// Mark first: a broken optional subscription must never keep the guard
|
|
1779
|
+
// from running at all.
|
|
1780
|
+
void load()
|
|
1781
|
+
let unsubscribe = () => {}
|
|
1782
|
+
try {
|
|
1783
|
+
const list = workspaces?.list
|
|
1784
|
+
if (list !== undefined && typeof list.subscribe === 'function') {
|
|
1785
|
+
unsubscribe = list.subscribe(() => {
|
|
1786
|
+
schedule()
|
|
1787
|
+
void load()
|
|
1788
|
+
}) ?? (() => {})
|
|
1789
|
+
}
|
|
1790
|
+
} catch (error) {
|
|
1791
|
+
console.error('[lmw-plugin] workspace list subscription failed:', error)
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
return () => {
|
|
1795
|
+
disposed = true
|
|
1796
|
+
observer.disconnect()
|
|
1797
|
+
unsubscribe()
|
|
1798
|
+
window.clearInterval(interval)
|
|
1799
|
+
document.removeEventListener('click', blockRow, true)
|
|
1800
|
+
document.removeEventListener('keydown', blockRow, true)
|
|
1801
|
+
for (const type of ['keydown', 'beforeinput', 'paste', 'drop']) document.removeEventListener(type, blockInput, true)
|
|
1802
|
+
if (timer !== 0) window.clearTimeout(timer)
|
|
1803
|
+
for (const row of document.querySelectorAll('[data-lmw-offline]')) {
|
|
1804
|
+
row.removeAttribute('data-lmw-offline')
|
|
1805
|
+
row.removeAttribute('aria-disabled')
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
}, [workspaces, tr])
|
|
1809
|
+
return null
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
function SortDialog(props) {
|
|
1813
|
+
const { store } = props
|
|
1814
|
+
const tr = makeT(props.translate ?? props.t)
|
|
1815
|
+
const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot)
|
|
1816
|
+
const dialogRef = useRef(null)
|
|
1817
|
+
useEffect(() => {
|
|
1818
|
+
if (!snapshot.open) return undefined
|
|
1819
|
+
const onKeyDown = (event) => {
|
|
1820
|
+
if (event.key !== 'Escape') return
|
|
1821
|
+
event.stopPropagation()
|
|
1822
|
+
store.close()
|
|
1823
|
+
}
|
|
1824
|
+
document.addEventListener('keydown', onKeyDown, true)
|
|
1825
|
+
const timer = window.setTimeout(() => dialogRef.current?.querySelector('button')?.focus(), 30)
|
|
1826
|
+
return () => {
|
|
1827
|
+
document.removeEventListener('keydown', onKeyDown, true)
|
|
1828
|
+
window.clearTimeout(timer)
|
|
1829
|
+
}
|
|
1830
|
+
}, [snapshot.open, store])
|
|
1831
|
+
if (!snapshot.open) return null
|
|
1832
|
+
const option = (mode, label) => {
|
|
1833
|
+
const active = (snapshot.mode ?? 'manual') === mode
|
|
1834
|
+
return h('button', {
|
|
1835
|
+
type: 'button',
|
|
1836
|
+
className: active ? 'lmw-button lmw-sort-option lmw-sort-active' : 'lmw-button lmw-sort-option',
|
|
1837
|
+
disabled: snapshot.busy,
|
|
1838
|
+
'aria-pressed': active ? 'true' : 'false',
|
|
1839
|
+
onClick: () => { void store.apply(mode) },
|
|
1840
|
+
}, label, active ? h('span', { className: 'lmw-sort-check', 'aria-hidden': 'true' }, '✓') : null)
|
|
1841
|
+
}
|
|
1842
|
+
return h('div', {
|
|
1843
|
+
className: 'lmw-backdrop',
|
|
1844
|
+
onMouseDown: (event) => { if (event.target === event.currentTarget) store.close() },
|
|
1845
|
+
},
|
|
1846
|
+
h('section', { ref: dialogRef, className: 'lmw-dialog lmw-dialog-sm', role: 'dialog', 'aria-modal': 'true', 'aria-label': tr('sort.title') },
|
|
1847
|
+
h('header', { className: 'lmw-header' },
|
|
1848
|
+
h('div', { className: 'lmw-header-text' },
|
|
1849
|
+
h('div', { className: 'lmw-title' }, tr('sort.title')),
|
|
1850
|
+
h('div', { className: 'lmw-subtitle' }, tr('sort.hint'))),
|
|
1851
|
+
h('button', { type: 'button', className: 'lmw-close', 'aria-label': tr('dialog.close'), onClick: () => store.close() },
|
|
1852
|
+
h('svg', { width: 14, height: 14, viewBox: '0 0 14 14', 'aria-hidden': 'true' },
|
|
1853
|
+
h('path', { d: 'M3 3l8 8M11 3l-8 8', stroke: 'currentColor', 'stroke-width': 1.6, 'stroke-linecap': 'round' })))),
|
|
1854
|
+
h('div', { className: 'lmw-body lmw-sort-body' },
|
|
1855
|
+
snapshot.error !== null ? h('p', { className: 'lmw-error' }, snapshot.error) : null,
|
|
1856
|
+
option('path', tr('sort.byPath')),
|
|
1857
|
+
option('title', tr('sort.byName')),
|
|
1858
|
+
option('activity', tr('sort.byActivity')),
|
|
1859
|
+
option('manual', tr('sort.manual')),
|
|
1860
|
+
snapshot.busy ? h('p', { className: 'lmw-note lmw-note-flush' }, tr('sort.applying')) : null),
|
|
1861
|
+
h('div', { className: 'lmw-footbar' },
|
|
1862
|
+
h('button', { type: 'button', className: 'lmw-button', onClick: () => store.close() }, tr('dialog.close')))))
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1554
1865
|
/* ------------------------------------------------------------------ */
|
|
1555
1866
|
/* Workspace path subtitle decorator */
|
|
1556
1867
|
/* ------------------------------------------------------------------ */
|
|
@@ -1698,6 +2009,14 @@ window.__ModuleLoader__.load({
|
|
|
1698
2009
|
'.lmw-confirm-text{margin:0;font-size:12.5px;line-height:18px;color:var(--dsw-alias-label-secondary);overflow-wrap:anywhere}',
|
|
1699
2010
|
'.lmw-confirm-actions{display:flex;justify-content:flex-end;gap:8px;flex-wrap:wrap}',
|
|
1700
2011
|
'.lmw-body-fixed{display:flex;flex-direction:column;overflow:hidden}',
|
|
2012
|
+
'.lmw-dialog-sm{width:min(440px,100%)}',
|
|
2013
|
+
'.lmw-sort-body{display:flex;flex-direction:column;gap:8px}',
|
|
2014
|
+
'.lmw-sort-option{justify-content:flex-start;width:100%}',
|
|
2015
|
+
'.lmw-sort-active{color:var(--dsw-alias-brand-primary);border-color:color-mix(in srgb,var(--dsw-alias-brand-primary) 45%,var(--dsw-alias-border-l2))}',
|
|
2016
|
+
'.lmw-sort-check{margin-left:auto;font-size:12px}',
|
|
2017
|
+
'[data-lmw-offline]{opacity:.45;filter:grayscale(1);cursor:not-allowed!important}',
|
|
2018
|
+
'[data-lmw-offline] *{cursor:not-allowed!important}',
|
|
2019
|
+
'[data-lmw-offline-composer]{opacity:.55;cursor:not-allowed!important}',
|
|
1701
2020
|
'.lmw-import-body{display:flex;flex-direction:column;flex:1;min-height:0;gap:10px}',
|
|
1702
2021
|
'.lmw-import-top{display:flex;flex-direction:column;gap:8px;flex:none;min-width:0}',
|
|
1703
2022
|
'.lmw-import-scroll{flex:1;min-height:0;overflow-y:auto;padding-right:2px}',
|
|
@@ -1759,13 +2078,16 @@ window.__ModuleLoader__.load({
|
|
|
1759
2078
|
},
|
|
1760
2079
|
refreshSessions: refreshSessionList,
|
|
1761
2080
|
})
|
|
2081
|
+
const sortStore = createSortStore()
|
|
2082
|
+
// Re-apply the remembered arrangement at startup and after a page reload.
|
|
2083
|
+
void sortStore.autoApply()
|
|
1762
2084
|
|
|
1763
2085
|
ctx.slots.inject('sidebar.footer.action', () => ctx.slots.register({
|
|
1764
2086
|
name: 'sidebar.footer.action',
|
|
1765
2087
|
id: 'lmw-footer',
|
|
1766
2088
|
order: 250,
|
|
1767
2089
|
locale: NS,
|
|
1768
|
-
inject: () => ({ store, importStore, translate: t }),
|
|
2090
|
+
inject: () => ({ store, importStore, sortStore, translate: t }),
|
|
1769
2091
|
}, FooterActionsPanel))
|
|
1770
2092
|
|
|
1771
2093
|
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
@@ -1790,6 +2112,22 @@ window.__ModuleLoader__.load({
|
|
|
1790
2112
|
}),
|
|
1791
2113
|
}, ImportDialog))
|
|
1792
2114
|
|
|
2115
|
+
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
2116
|
+
name: 'shell.overlay',
|
|
2117
|
+
id: 'lmw-sort-dialog',
|
|
2118
|
+
order: 620,
|
|
2119
|
+
locale: NS,
|
|
2120
|
+
inject: () => ({ store: sortStore, translate: t }),
|
|
2121
|
+
}, SortDialog))
|
|
2122
|
+
|
|
2123
|
+
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
2124
|
+
name: 'shell.overlay',
|
|
2125
|
+
id: 'lmw-workspace-offline',
|
|
2126
|
+
order: 920,
|
|
2127
|
+
locale: NS,
|
|
2128
|
+
inject: () => ({ workspaces: ctx.workspaces, translate: t }),
|
|
2129
|
+
}, WorkspaceOfflineGuard))
|
|
2130
|
+
|
|
1793
2131
|
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
1794
2132
|
name: 'shell.overlay',
|
|
1795
2133
|
id: 'lmw-workspace-path',
|
package/index.js
CHANGED
|
@@ -35,6 +35,8 @@ const ASSIGN_PATH = '/lmw-plugin/assign'
|
|
|
35
35
|
const SKILLS_PATH = '/lmw-plugin/skills'
|
|
36
36
|
const IMPORT_SCAN_PATH = '/lmw-plugin/import/scan'
|
|
37
37
|
const IMPORT_APPLY_PATH = '/lmw-plugin/import/apply'
|
|
38
|
+
const WORKSPACE_STATUS_PATH = '/lmw-plugin/workspaces/status'
|
|
39
|
+
const WORKSPACE_SORT_PATH = '/lmw-plugin/workspaces/sort'
|
|
38
40
|
const MAX_BODY_BYTES = 64 * 1024
|
|
39
41
|
/** One canonical DSH generation filename: `session.v4.jsonl.zstd` (or plain JSONL). */
|
|
40
42
|
const SESSION_FILE_NAME = /^session(?:\.v\d+)?\.jsonl(?:\.zstd)?$/
|
|
@@ -914,6 +916,92 @@ async function scanImportSource(ctx, settings, rawPath) {
|
|
|
914
916
|
}
|
|
915
917
|
}
|
|
916
918
|
|
|
919
|
+
/** Report each Workspace's directory state; sessions of a missing directory are offline. */
|
|
920
|
+
async function collectWorkspaceStatus(ctx) {
|
|
921
|
+
const rows = []
|
|
922
|
+
for (const workspace of ctx.workspaceRegistry.list()) {
|
|
923
|
+
let missing = false
|
|
924
|
+
try {
|
|
925
|
+
missing = typeof workspace.status === 'function'
|
|
926
|
+
? (await workspace.status()) === 'missing-dir'
|
|
927
|
+
: !(await isDirectory(workspace.path))
|
|
928
|
+
} catch {
|
|
929
|
+
missing = !(await isDirectory(workspace.path))
|
|
930
|
+
}
|
|
931
|
+
rows.push({
|
|
932
|
+
id: String(workspace.id),
|
|
933
|
+
path: workspace.path,
|
|
934
|
+
title: workspace.title,
|
|
935
|
+
missing,
|
|
936
|
+
sessionIds: (workspace.sessionIds ?? []).map(String),
|
|
937
|
+
})
|
|
938
|
+
}
|
|
939
|
+
return rows
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
/** Latest Session-log activity per Workspace, used by the activity sort. */
|
|
943
|
+
async function workspaceActivity(ctx) {
|
|
944
|
+
let snapshots = []
|
|
945
|
+
try {
|
|
946
|
+
snapshots = await ctx.sessionPersistence.list()
|
|
947
|
+
} catch {
|
|
948
|
+
return new Map()
|
|
949
|
+
}
|
|
950
|
+
const sessionTime = new Map()
|
|
951
|
+
for (const snapshot of snapshots) {
|
|
952
|
+
const id = String(snapshot.header.id)
|
|
953
|
+
let time = typeof snapshot.header.createdAt === 'number' ? snapshot.header.createdAt : 0
|
|
954
|
+
const path = snapshot.location?.path
|
|
955
|
+
if (typeof path === 'string') {
|
|
956
|
+
try {
|
|
957
|
+
time = Math.max(time, (await stat(path)).mtimeMs)
|
|
958
|
+
} catch {
|
|
959
|
+
// A missing log keeps its header time.
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
sessionTime.set(id, time)
|
|
963
|
+
}
|
|
964
|
+
const activity = new Map()
|
|
965
|
+
for (const workspace of ctx.workspaceRegistry.list()) {
|
|
966
|
+
let latest = 0
|
|
967
|
+
for (const id of workspace.sessionIds ?? []) latest = Math.max(latest, sessionTime.get(String(id)) ?? 0)
|
|
968
|
+
if (latest === 0) {
|
|
969
|
+
const updated = Date.parse(workspace.updatedAt ?? '')
|
|
970
|
+
if (Number.isFinite(updated)) latest = updated
|
|
971
|
+
}
|
|
972
|
+
activity.set(String(workspace.id), latest)
|
|
973
|
+
}
|
|
974
|
+
return activity
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
/** Order workspaces by path, title, or latest session activity, then persist via insertBefore. */
|
|
978
|
+
async function sortWorkspaceOrder(ctx, mode) {
|
|
979
|
+
const workspaces = ctx.workspaceRegistry.list()
|
|
980
|
+
const activity = mode === 'activity' ? await workspaceActivity(ctx) : undefined
|
|
981
|
+
const compare = (left, right) => {
|
|
982
|
+
if (mode === 'activity') {
|
|
983
|
+
const a = activity?.get(String(left.id)) ?? 0
|
|
984
|
+
const b = activity?.get(String(right.id)) ?? 0
|
|
985
|
+
if (a !== b) return b - a
|
|
986
|
+
return left.path.localeCompare(right.path)
|
|
987
|
+
}
|
|
988
|
+
if (mode === 'title') {
|
|
989
|
+
const a = (left.title ?? '').toLowerCase()
|
|
990
|
+
const b = (right.title ?? '').toLowerCase()
|
|
991
|
+
if (a !== b) return a < b ? -1 : 1
|
|
992
|
+
}
|
|
993
|
+
return left.path.localeCompare(right.path)
|
|
994
|
+
}
|
|
995
|
+
const ordered = [...workspaces].sort(compare)
|
|
996
|
+
let anchor
|
|
997
|
+
for (let index = ordered.length - 1; index >= 0; index -= 1) {
|
|
998
|
+
const id = ordered[index].id
|
|
999
|
+
await ctx.workspaceRegistry.insertBefore(id, anchor)
|
|
1000
|
+
anchor = id
|
|
1001
|
+
}
|
|
1002
|
+
return ordered.map((workspace) => ({ id: String(workspace.id), path: workspace.path, title: workspace.title }))
|
|
1003
|
+
}
|
|
1004
|
+
|
|
917
1005
|
/** Fold and persist one session's projection cache (fail-soft). */
|
|
918
1006
|
async function warmOneSession(ctx, id, settings) {
|
|
919
1007
|
const cache = typeof ctx.get === 'function' ? ctx.get('sessionProjectionCache') : undefined
|
|
@@ -1212,4 +1300,54 @@ export function apply(ctx, config) {
|
|
|
1212
1300
|
}
|
|
1213
1301
|
},
|
|
1214
1302
|
}), `lmw-plugin: POST ${IMPORT_APPLY_PATH}`)
|
|
1303
|
+
|
|
1304
|
+
ctx.effect(() => ctx.webServer.register({
|
|
1305
|
+
kind: 'exact',
|
|
1306
|
+
path: WORKSPACE_STATUS_PATH,
|
|
1307
|
+
handler: async (req, res) => {
|
|
1308
|
+
if (rejected(req, res)) return
|
|
1309
|
+
if (req.method !== 'GET') {
|
|
1310
|
+
sendMethodNotAllowed(res, 'GET')
|
|
1311
|
+
return
|
|
1312
|
+
}
|
|
1313
|
+
try {
|
|
1314
|
+
const workspaces = await collectWorkspaceStatus(ctx)
|
|
1315
|
+
sendJson(res, 200, { ok: true, workspaces, generatedAt: new Date().toISOString() })
|
|
1316
|
+
} catch (error) {
|
|
1317
|
+
internalFailure(res, error, 'workspace status')
|
|
1318
|
+
}
|
|
1319
|
+
},
|
|
1320
|
+
}), `lmw-plugin: GET ${WORKSPACE_STATUS_PATH}`)
|
|
1321
|
+
|
|
1322
|
+
ctx.effect(() => ctx.webServer.register({
|
|
1323
|
+
kind: 'exact',
|
|
1324
|
+
path: WORKSPACE_SORT_PATH,
|
|
1325
|
+
handler: async (req, res) => {
|
|
1326
|
+
if (rejected(req, res)) return
|
|
1327
|
+
if (req.method !== 'POST') {
|
|
1328
|
+
sendMethodNotAllowed(res, 'POST')
|
|
1329
|
+
return
|
|
1330
|
+
}
|
|
1331
|
+
if (!isJsonRequest(req)) {
|
|
1332
|
+
sendJson(res, 415, { ok: false, error: { code: 'unsupported-media-type', message: 'content-type must be application/json' } })
|
|
1333
|
+
return
|
|
1334
|
+
}
|
|
1335
|
+
const body = await readJsonBody(req)
|
|
1336
|
+
if (!body.ok) {
|
|
1337
|
+
sendJson(res, body.status, { ok: false, error: { code: 'bad-body', message: 'the request body was rejected' } })
|
|
1338
|
+
return
|
|
1339
|
+
}
|
|
1340
|
+
const mode = body.value?.mode
|
|
1341
|
+
if (mode !== 'path' && mode !== 'title' && mode !== 'activity') {
|
|
1342
|
+
sendJson(res, 400, { ok: false, error: { code: 'unsupported-mode', message: 'mode must be path, title, or activity' } })
|
|
1343
|
+
return
|
|
1344
|
+
}
|
|
1345
|
+
try {
|
|
1346
|
+
const order = await sortWorkspaceOrder(ctx, mode)
|
|
1347
|
+
sendJson(res, 200, { ok: true, mode, order })
|
|
1348
|
+
} catch (error) {
|
|
1349
|
+
internalFailure(res, error, 'workspace sort')
|
|
1350
|
+
}
|
|
1351
|
+
},
|
|
1352
|
+
}), `lmw-plugin: POST ${WORKSPACE_SORT_PATH}`)
|
|
1215
1353
|
}
|