dsh-lmw-plugin 1.0.2 → 1.0.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/client.js +314 -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,262 @@ 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
|
+
let statuses = { workspaces: {}, sessions: {} }
|
|
1671
|
+
let disposed = false
|
|
1672
|
+
let timer = 0
|
|
1673
|
+
|
|
1674
|
+
const mark = () => {
|
|
1675
|
+
for (const row of document.querySelectorAll('[data-row-key^="workspace:"]')) {
|
|
1676
|
+
const id = row.getAttribute('data-row-key').slice('workspace:'.length)
|
|
1677
|
+
const missing = statuses.workspaces[id] === true
|
|
1678
|
+
row.toggleAttribute('data-lmw-offline', missing)
|
|
1679
|
+
if (missing) {
|
|
1680
|
+
row.setAttribute('title', tr('offline.workspace'))
|
|
1681
|
+
row.setAttribute('aria-disabled', 'true')
|
|
1682
|
+
} else {
|
|
1683
|
+
row.removeAttribute('title')
|
|
1684
|
+
row.removeAttribute('aria-disabled')
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
for (const row of document.querySelectorAll('[data-row-key^="session:"]')) {
|
|
1688
|
+
const id = row.getAttribute('data-row-key').slice('session:'.length)
|
|
1689
|
+
const missing = statuses.sessions[id] === true
|
|
1690
|
+
row.toggleAttribute('data-lmw-offline', missing)
|
|
1691
|
+
if (missing) {
|
|
1692
|
+
row.setAttribute('title', tr('offline.session'))
|
|
1693
|
+
row.setAttribute('aria-disabled', 'true')
|
|
1694
|
+
} else {
|
|
1695
|
+
row.removeAttribute('title')
|
|
1696
|
+
row.removeAttribute('aria-disabled')
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
const selected = document.querySelector('[data-row-key^="session:"][aria-selected="true"]')
|
|
1700
|
+
const sessionId = selected?.getAttribute('data-row-key')?.slice('session:'.length)
|
|
1701
|
+
const offlineActive = sessionId !== undefined && statuses.sessions[sessionId] === true
|
|
1702
|
+
const composer = document.querySelector('[data-lmw-composer]')
|
|
1703
|
+
?? document.querySelector('[contenteditable="true"]')
|
|
1704
|
+
if (composer !== null) {
|
|
1705
|
+
composer.setAttribute('data-lmw-composer', '')
|
|
1706
|
+
composer.toggleAttribute('data-lmw-offline-composer', offlineActive)
|
|
1707
|
+
if (offlineActive) {
|
|
1708
|
+
composer.setAttribute('title', tr('offline.input'))
|
|
1709
|
+
composer.setAttribute('aria-disabled', 'true')
|
|
1710
|
+
} else {
|
|
1711
|
+
composer.removeAttribute('title')
|
|
1712
|
+
composer.removeAttribute('aria-disabled')
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
const schedule = () => {
|
|
1718
|
+
if (timer !== 0) return
|
|
1719
|
+
timer = window.setTimeout(() => {
|
|
1720
|
+
timer = 0
|
|
1721
|
+
mark()
|
|
1722
|
+
}, 120)
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
const load = async () => {
|
|
1726
|
+
try {
|
|
1727
|
+
const data = await requestJson('GET', 'workspaces/status')
|
|
1728
|
+
const workspaces = {}
|
|
1729
|
+
const sessions = {}
|
|
1730
|
+
for (const workspace of data.workspaces ?? []) {
|
|
1731
|
+
workspaces[workspace.id] = workspace.missing === true
|
|
1732
|
+
for (const sid of workspace.sessionIds ?? []) sessions[sid] = workspace.missing === true
|
|
1733
|
+
}
|
|
1734
|
+
if (!disposed) {
|
|
1735
|
+
statuses = { workspaces, sessions }
|
|
1736
|
+
mark()
|
|
1737
|
+
}
|
|
1738
|
+
} catch (error) {
|
|
1739
|
+
console.error('[lmw-plugin] workspace status failed:', error)
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
const blockRow = (event) => {
|
|
1744
|
+
const row = event.target instanceof Element ? event.target.closest('[data-lmw-offline]') : null
|
|
1745
|
+
if (row === null) return
|
|
1746
|
+
event.preventDefault()
|
|
1747
|
+
event.stopPropagation()
|
|
1748
|
+
}
|
|
1749
|
+
const blockInput = (event) => {
|
|
1750
|
+
const target = event.target instanceof Element ? event.target : null
|
|
1751
|
+
if (target === null || target.closest('[data-lmw-offline-composer]') === null) return
|
|
1752
|
+
event.preventDefault()
|
|
1753
|
+
event.stopPropagation()
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1756
|
+
const observer = new MutationObserver(schedule)
|
|
1757
|
+
observer.observe(document.body, { childList: true, subtree: true })
|
|
1758
|
+
const unsubscribe = workspaces.list.subscribe(() => {
|
|
1759
|
+
schedule()
|
|
1760
|
+
void load()
|
|
1761
|
+
})
|
|
1762
|
+
document.addEventListener('click', blockRow, true)
|
|
1763
|
+
document.addEventListener('keydown', blockRow, true)
|
|
1764
|
+
for (const type of ['keydown', 'beforeinput', 'paste', 'drop']) document.addEventListener(type, blockInput, true)
|
|
1765
|
+
const interval = window.setInterval(() => { void load() }, 20000)
|
|
1766
|
+
void load()
|
|
1767
|
+
|
|
1768
|
+
return () => {
|
|
1769
|
+
disposed = true
|
|
1770
|
+
observer.disconnect()
|
|
1771
|
+
unsubscribe()
|
|
1772
|
+
window.clearInterval(interval)
|
|
1773
|
+
document.removeEventListener('click', blockRow, true)
|
|
1774
|
+
document.removeEventListener('keydown', blockRow, true)
|
|
1775
|
+
for (const type of ['keydown', 'beforeinput', 'paste', 'drop']) document.removeEventListener(type, blockInput, true)
|
|
1776
|
+
if (timer !== 0) window.clearTimeout(timer)
|
|
1777
|
+
for (const row of document.querySelectorAll('[data-lmw-offline]')) {
|
|
1778
|
+
row.removeAttribute('data-lmw-offline')
|
|
1779
|
+
row.removeAttribute('aria-disabled')
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
}, [workspaces, tr])
|
|
1783
|
+
return null
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
function SortDialog(props) {
|
|
1787
|
+
const { store } = props
|
|
1788
|
+
const tr = makeT(props.translate ?? props.t)
|
|
1789
|
+
const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot)
|
|
1790
|
+
const dialogRef = useRef(null)
|
|
1791
|
+
useEffect(() => {
|
|
1792
|
+
if (!snapshot.open) return undefined
|
|
1793
|
+
const onKeyDown = (event) => {
|
|
1794
|
+
if (event.key !== 'Escape') return
|
|
1795
|
+
event.stopPropagation()
|
|
1796
|
+
store.close()
|
|
1797
|
+
}
|
|
1798
|
+
document.addEventListener('keydown', onKeyDown, true)
|
|
1799
|
+
const timer = window.setTimeout(() => dialogRef.current?.querySelector('button')?.focus(), 30)
|
|
1800
|
+
return () => {
|
|
1801
|
+
document.removeEventListener('keydown', onKeyDown, true)
|
|
1802
|
+
window.clearTimeout(timer)
|
|
1803
|
+
}
|
|
1804
|
+
}, [snapshot.open, store])
|
|
1805
|
+
if (!snapshot.open) return null
|
|
1806
|
+
const option = (mode, label) => {
|
|
1807
|
+
const active = (snapshot.mode ?? 'manual') === mode
|
|
1808
|
+
return h('button', {
|
|
1809
|
+
type: 'button',
|
|
1810
|
+
className: active ? 'lmw-button lmw-sort-option lmw-sort-active' : 'lmw-button lmw-sort-option',
|
|
1811
|
+
disabled: snapshot.busy,
|
|
1812
|
+
'aria-pressed': active ? 'true' : 'false',
|
|
1813
|
+
onClick: () => { void store.apply(mode) },
|
|
1814
|
+
}, label, active ? h('span', { className: 'lmw-sort-check', 'aria-hidden': 'true' }, '✓') : null)
|
|
1815
|
+
}
|
|
1816
|
+
return h('div', {
|
|
1817
|
+
className: 'lmw-backdrop',
|
|
1818
|
+
onMouseDown: (event) => { if (event.target === event.currentTarget) store.close() },
|
|
1819
|
+
},
|
|
1820
|
+
h('section', { ref: dialogRef, className: 'lmw-dialog lmw-dialog-sm', role: 'dialog', 'aria-modal': 'true', 'aria-label': tr('sort.title') },
|
|
1821
|
+
h('header', { className: 'lmw-header' },
|
|
1822
|
+
h('div', { className: 'lmw-header-text' },
|
|
1823
|
+
h('div', { className: 'lmw-title' }, tr('sort.title')),
|
|
1824
|
+
h('div', { className: 'lmw-subtitle' }, tr('sort.hint'))),
|
|
1825
|
+
h('button', { type: 'button', className: 'lmw-close', 'aria-label': tr('dialog.close'), onClick: () => store.close() },
|
|
1826
|
+
h('svg', { width: 14, height: 14, viewBox: '0 0 14 14', 'aria-hidden': 'true' },
|
|
1827
|
+
h('path', { d: 'M3 3l8 8M11 3l-8 8', stroke: 'currentColor', 'stroke-width': 1.6, 'stroke-linecap': 'round' })))),
|
|
1828
|
+
h('div', { className: 'lmw-body lmw-sort-body' },
|
|
1829
|
+
snapshot.error !== null ? h('p', { className: 'lmw-error' }, snapshot.error) : null,
|
|
1830
|
+
option('path', tr('sort.byPath')),
|
|
1831
|
+
option('title', tr('sort.byName')),
|
|
1832
|
+
option('activity', tr('sort.byActivity')),
|
|
1833
|
+
option('manual', tr('sort.manual')),
|
|
1834
|
+
snapshot.busy ? h('p', { className: 'lmw-note lmw-note-flush' }, tr('sort.applying')) : null),
|
|
1835
|
+
h('div', { className: 'lmw-footbar' },
|
|
1836
|
+
h('button', { type: 'button', className: 'lmw-button', onClick: () => store.close() }, tr('dialog.close')))))
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1554
1839
|
/* ------------------------------------------------------------------ */
|
|
1555
1840
|
/* Workspace path subtitle decorator */
|
|
1556
1841
|
/* ------------------------------------------------------------------ */
|
|
@@ -1698,6 +1983,14 @@ window.__ModuleLoader__.load({
|
|
|
1698
1983
|
'.lmw-confirm-text{margin:0;font-size:12.5px;line-height:18px;color:var(--dsw-alias-label-secondary);overflow-wrap:anywhere}',
|
|
1699
1984
|
'.lmw-confirm-actions{display:flex;justify-content:flex-end;gap:8px;flex-wrap:wrap}',
|
|
1700
1985
|
'.lmw-body-fixed{display:flex;flex-direction:column;overflow:hidden}',
|
|
1986
|
+
'.lmw-dialog-sm{width:min(440px,100%)}',
|
|
1987
|
+
'.lmw-sort-body{display:flex;flex-direction:column;gap:8px}',
|
|
1988
|
+
'.lmw-sort-option{justify-content:flex-start;width:100%}',
|
|
1989
|
+
'.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))}',
|
|
1990
|
+
'.lmw-sort-check{margin-left:auto;font-size:12px}',
|
|
1991
|
+
'[data-lmw-offline]{opacity:.45;filter:grayscale(1);cursor:not-allowed!important}',
|
|
1992
|
+
'[data-lmw-offline] *{cursor:not-allowed!important}',
|
|
1993
|
+
'[data-lmw-offline-composer]{opacity:.55;cursor:not-allowed!important}',
|
|
1701
1994
|
'.lmw-import-body{display:flex;flex-direction:column;flex:1;min-height:0;gap:10px}',
|
|
1702
1995
|
'.lmw-import-top{display:flex;flex-direction:column;gap:8px;flex:none;min-width:0}',
|
|
1703
1996
|
'.lmw-import-scroll{flex:1;min-height:0;overflow-y:auto;padding-right:2px}',
|
|
@@ -1759,13 +2052,16 @@ window.__ModuleLoader__.load({
|
|
|
1759
2052
|
},
|
|
1760
2053
|
refreshSessions: refreshSessionList,
|
|
1761
2054
|
})
|
|
2055
|
+
const sortStore = createSortStore()
|
|
2056
|
+
// Re-apply the remembered arrangement at startup and after a page reload.
|
|
2057
|
+
void sortStore.autoApply()
|
|
1762
2058
|
|
|
1763
2059
|
ctx.slots.inject('sidebar.footer.action', () => ctx.slots.register({
|
|
1764
2060
|
name: 'sidebar.footer.action',
|
|
1765
2061
|
id: 'lmw-footer',
|
|
1766
2062
|
order: 250,
|
|
1767
2063
|
locale: NS,
|
|
1768
|
-
inject: () => ({ store, importStore, translate: t }),
|
|
2064
|
+
inject: () => ({ store, importStore, sortStore, translate: t }),
|
|
1769
2065
|
}, FooterActionsPanel))
|
|
1770
2066
|
|
|
1771
2067
|
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
@@ -1790,6 +2086,22 @@ window.__ModuleLoader__.load({
|
|
|
1790
2086
|
}),
|
|
1791
2087
|
}, ImportDialog))
|
|
1792
2088
|
|
|
2089
|
+
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
2090
|
+
name: 'shell.overlay',
|
|
2091
|
+
id: 'lmw-sort-dialog',
|
|
2092
|
+
order: 620,
|
|
2093
|
+
locale: NS,
|
|
2094
|
+
inject: () => ({ store: sortStore, translate: t }),
|
|
2095
|
+
}, SortDialog))
|
|
2096
|
+
|
|
2097
|
+
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
2098
|
+
name: 'shell.overlay',
|
|
2099
|
+
id: 'lmw-workspace-offline',
|
|
2100
|
+
order: 920,
|
|
2101
|
+
locale: NS,
|
|
2102
|
+
inject: () => ({ workspaces: ctx.workspaces, translate: t }),
|
|
2103
|
+
}, WorkspaceOfflineGuard))
|
|
2104
|
+
|
|
1793
2105
|
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
1794
2106
|
name: 'shell.overlay',
|
|
1795
2107
|
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
|
}
|