@xsok/dsh-enhanced 0.2.2-5 → 0.2.2-7
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/CHANGELOG.md +33 -0
- package/client.js +497 -93
- package/host/engine/index.js +12 -1
- package/host/engine/sessions.js +18 -1
- package/host/engine/workspace.js +32 -0
- package/host/envcheck.js +3 -2
- package/host/search.js +75 -7
- package/index.js +2 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
版本号前三位对应主程序版本,最后一段是插件自身的发布序号。
|
|
4
4
|
|
|
5
|
+
## 0.2.2-7
|
|
6
|
+
|
|
7
|
+
### 改进
|
|
8
|
+
|
|
9
|
+
- **会话搜索**:每条匹配前显示时间(今日/昨日/周几/日期,跨年带年份)。
|
|
10
|
+
- **搜索悬停预览**:输入后需移动鼠标,悬停 1 秒出现;跟随鼠标右侧,位于目标行上/下方,内容超长时内部滚动,当前命中高亮。
|
|
11
|
+
- **点击跳转与高亮**:已加载内容定位到关键词本身并高亮 10 秒;未加载的更早历史只提示,不再翻页。
|
|
12
|
+
- **提示样式**:挂到 body 的固定横幅,深色卡片,使之更醒目。
|
|
13
|
+
|
|
14
|
+
### 修复
|
|
15
|
+
|
|
16
|
+
- 云端已移动且内容更新时,本机同步会用旧内容反向覆盖并删除云端新副本;改为始终按事件数判定方向。
|
|
17
|
+
|
|
18
|
+
## 0.2.2-6
|
|
19
|
+
|
|
20
|
+
### 改进
|
|
21
|
+
|
|
22
|
+
- 同步日志展开时隐藏“上次同步”摘要,避免与列表首行重复。
|
|
23
|
+
- 环境检测显示的插件版本改为读取 `package.json`,与发布版本保持一致。
|
|
24
|
+
|
|
25
|
+
### 修复
|
|
26
|
+
|
|
27
|
+
- 会话移动后同步不生效:旧工作区目录残留同一会话,云端出现两份。
|
|
28
|
+
- 工作区合并按会话 cwd 去重,一个会话不再挂在两个工作区。
|
|
29
|
+
- 推送阶段清理同一会话的重复副本,避免每次同步都推送一次。
|
|
30
|
+
|
|
31
|
+
## 0.2.2-5
|
|
32
|
+
|
|
33
|
+
### 改进
|
|
34
|
+
|
|
35
|
+
- 包元数据补充 `repository`、`homepage`、`bugs`,npm 页面可直接跳转 GitHub 仓库。
|
|
36
|
+
- 发布流程迁移到 GitHub Actions:推送 tag 后自动发布,使用 OIDC 可信发布并附带 provenance 证明。
|
|
37
|
+
|
|
5
38
|
## 0.2.2-4
|
|
6
39
|
|
|
7
40
|
### 改进
|
package/client.js
CHANGED
|
@@ -468,14 +468,28 @@ window.__ModuleLoader__.load({
|
|
|
468
468
|
font:inherit;font-weight:600;padding:6px 10px;border-radius:8px;cursor:pointer;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
469
469
|
.dshe-group-title:hover{background:var(--dsw-alias-bg-layer-2,rgba(0,0,0,.05))}
|
|
470
470
|
.dshe-group-meta{color:var(--dsw-alias-label-secondary,#8a919c);font-weight:400;font-size:11px;margin-left:8px}
|
|
471
|
-
.dshe-match{display:flex;gap:
|
|
471
|
+
.dshe-match{display:flex;gap:6px;width:100%;text-align:left;border:0;background:transparent;color:var(--dsw-alias-label-secondary,#4b5563);
|
|
472
472
|
font:inherit;padding:5px 10px 5px 18px;border-radius:8px;cursor:pointer;line-height:18px}
|
|
473
473
|
.dshe-match:hover,.dshe-match[data-active="true"]{background:var(--dsw-alias-bg-layer-2,rgba(0,0,0,.06))}
|
|
474
474
|
.dshe-role{flex:none;font-size:11px;padding:0 6px;border-radius:6px;background:var(--dsw-alias-bg-layer-2,rgba(0,0,0,.05));
|
|
475
475
|
color:var(--dsw-alias-label-secondary,#6b7280);height:18px;line-height:18px}
|
|
476
476
|
.dshe-snippet{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--dsw-alias-label-primary,#2b2f36)}
|
|
477
|
+
.dshe-group-title{display:flex;align-items:center;gap:6px}
|
|
478
|
+
.dshe-group-caret{flex:none;width:12px;color:var(--dsw-alias-label-secondary,#8a919c);font-size:11px}
|
|
479
|
+
.dshe-group-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
480
|
+
.dshe-group-meta{flex:none;margin-left:0}
|
|
481
|
+
.dshe-match-time{flex:none;min-width:0;color:var(--dsw-alias-label-secondary,#8a919c);font-size:11px;font-variant-numeric:tabular-nums;white-space:nowrap}
|
|
477
482
|
.dshe-mark{background:color-mix(in srgb,var(--dsw-alias-brand-primary,#3b6ef5) 26%,transparent);color:inherit;border-radius:3px;padding:0 1px}
|
|
478
483
|
.dshe-section{display:flex;flex-direction:column;gap:14px;width:100%;font-size:13px}
|
|
484
|
+
.dshe-match-time[data-tier="1"]{min-width:52px}
|
|
485
|
+
.dshe-match-time[data-tier="2"]{min-width:60px}
|
|
486
|
+
.dshe-match-time[data-tier="3"]{min-width:88px}
|
|
487
|
+
.dshe-preview{position:fixed;z-index:2147482000;max-width:min(560px,46vw);max-height:46vh;overflow:auto;
|
|
488
|
+
background:var(--dsw-alias-bg-overlay,#fff);color:var(--dsw-alias-label-primary,#1b1d22);
|
|
489
|
+
border:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.12));border-radius:10px;padding:10px 12px;
|
|
490
|
+
font-size:12px;line-height:1.6;white-space:pre-wrap;word-break:break-word;box-shadow:0 12px 32px rgba(0,0,0,.18)}
|
|
491
|
+
.dshe-mark-current{background:#ffd76a;color:#1b1d22;border-radius:3px;box-shadow:0 0 0 2px rgba(255,193,7,.5)}
|
|
492
|
+
::highlight(dshe-flash){background-color:#ffe27a;color:#1b1d22;border-radius:3px}
|
|
479
493
|
.dshe-section-title{margin:0;font-size:15px;font-weight:600;color:var(--dsw-alias-label-primary,#1b1d22)}
|
|
480
494
|
.dshe-subsection-title{margin:4px 0 0;font-size:13px;font-weight:600;color:var(--dsw-alias-label-primary,#1b1d22);
|
|
481
495
|
padding-top:10px;border-top:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.08))}
|
|
@@ -625,7 +639,7 @@ window.__ModuleLoader__.load({
|
|
|
625
639
|
toast(kind, text) {
|
|
626
640
|
if (toastTimer !== null) clearTimeout(toastTimer);
|
|
627
641
|
store.set({ toast: { kind, text, id: Date.now() } });
|
|
628
|
-
toastTimer = setTimeout(() => store.set({ toast: null }), kind === 'error' ?
|
|
642
|
+
toastTimer = setTimeout(() => store.set({ toast: null }), kind === 'error' ? 5000 : 3000);
|
|
629
643
|
},
|
|
630
644
|
async init() {
|
|
631
645
|
try {
|
|
@@ -1250,6 +1264,44 @@ window.__ModuleLoader__.load({
|
|
|
1250
1264
|
}, h('span', {}));
|
|
1251
1265
|
}
|
|
1252
1266
|
|
|
1267
|
+
/**
|
|
1268
|
+
* Compact stamp for one search hit: 今日 10:11 / 昨日 10:11 / 周三 12:11 /
|
|
1269
|
+
* 11-02 11:12 / 2025-12-31 08:44.
|
|
1270
|
+
*/
|
|
1271
|
+
function formatMatchTime(value) {
|
|
1272
|
+
const ms = Number(value);
|
|
1273
|
+
if (!Number.isFinite(ms) || ms <= 0) return '';
|
|
1274
|
+
const date = new Date(ms);
|
|
1275
|
+
const now = new Date();
|
|
1276
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
1277
|
+
const clock = `${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
1278
|
+
const dayStart = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
|
|
1279
|
+
const days = Math.round((dayStart(now) - dayStart(date)) / 86400000);
|
|
1280
|
+
if (days === 0) return `今日 ${clock}`;
|
|
1281
|
+
if (days === 1) return `昨日 ${clock}`;
|
|
1282
|
+
const monday = (d) => {
|
|
1283
|
+
const start = new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
|
1284
|
+
start.setDate(start.getDate() - ((start.getDay() + 6) % 7));
|
|
1285
|
+
return start.getTime();
|
|
1286
|
+
};
|
|
1287
|
+
if (monday(date) === monday(now)) {
|
|
1288
|
+
const names = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
|
|
1289
|
+
return `${names[(date.getDay() + 6) % 7]} ${clock}`;
|
|
1290
|
+
}
|
|
1291
|
+
if (date.getFullYear() === now.getFullYear()) {
|
|
1292
|
+
return `${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${clock}`;
|
|
1293
|
+
}
|
|
1294
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${clock}`;
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
/** Width class for a match stamp: 1 = 今日/昨日/周X, 2 = MM-DD, 3 = YYYY-MM-DD. */
|
|
1298
|
+
function timeTier(text) {
|
|
1299
|
+
if (typeof text !== 'string' || text === '') return 1;
|
|
1300
|
+
if (/^(今日|昨日|周[一二三四五六日])/u.test(text)) return 1;
|
|
1301
|
+
if (/^\d{2}-\d{2} /u.test(text)) return 2;
|
|
1302
|
+
return 3;
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1253
1305
|
function formatSize(bytes) {
|
|
1254
1306
|
const value = Number(bytes) || 0;
|
|
1255
1307
|
if (value < 1024) return `${String(value)} B`;
|
|
@@ -1263,6 +1315,28 @@ window.__ModuleLoader__.load({
|
|
|
1263
1315
|
return new Date(time).toLocaleString();
|
|
1264
1316
|
}
|
|
1265
1317
|
|
|
1318
|
+
/** Highlight every hit; the one at focusIndex also gets the current style. */
|
|
1319
|
+
function highlightFocus(text, query, focusIndex) {
|
|
1320
|
+
const needle = typeof query === 'string' ? query.trim() : '';
|
|
1321
|
+
if (needle === '') return text;
|
|
1322
|
+
const lower = text.toLowerCase();
|
|
1323
|
+
const target = needle.toLowerCase();
|
|
1324
|
+
const parts = [];
|
|
1325
|
+
let from = 0;
|
|
1326
|
+
let key = 0;
|
|
1327
|
+
let index = lower.indexOf(target);
|
|
1328
|
+
while (index >= 0) {
|
|
1329
|
+
if (index > from) parts.push(text.slice(from, index));
|
|
1330
|
+
const current = Number(focusIndex) === index;
|
|
1331
|
+
parts.push(h('mark', { className: current ? 'dshe-mark dshe-mark-current' : 'dshe-mark', key: `f${String(key)}` }, text.slice(index, index + target.length)));
|
|
1332
|
+
key += 1;
|
|
1333
|
+
from = index + target.length;
|
|
1334
|
+
index = lower.indexOf(target, from);
|
|
1335
|
+
}
|
|
1336
|
+
if (from < text.length) parts.push(text.slice(from));
|
|
1337
|
+
return parts;
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1266
1340
|
function highlight(text, query) {
|
|
1267
1341
|
const needle = typeof query === 'string' ? query.trim() : '';
|
|
1268
1342
|
if (needle === '') return text;
|
|
@@ -1614,12 +1688,106 @@ const displayName = (value) => {
|
|
|
1614
1688
|
return Math.max(0, Math.round(bottom));
|
|
1615
1689
|
}
|
|
1616
1690
|
|
|
1691
|
+
|
|
1692
|
+
|
|
1617
1693
|
function SearchOverlay() {
|
|
1618
1694
|
const state = useStore();
|
|
1619
1695
|
const search = state.search;
|
|
1620
1696
|
const inputRef = React.useRef(null);
|
|
1621
1697
|
const resultsRef = React.useRef(null);
|
|
1622
1698
|
const [active, setActive] = React.useState(0);
|
|
1699
|
+
const [expanded, setExpanded] = React.useState(null);
|
|
1700
|
+
const [preview, setPreview] = React.useState(null);
|
|
1701
|
+
|
|
1702
|
+
// The card lives on document.body: inside the dialog an animated ancestor would
|
|
1703
|
+
// turn position:fixed into a local coordinate system and clip it.
|
|
1704
|
+
React.useEffect(() => {
|
|
1705
|
+
const existing = document.getElementById('dshe-preview-el');
|
|
1706
|
+
if (existing !== null) existing.remove();
|
|
1707
|
+
if (preview === null) return;
|
|
1708
|
+
|
|
1709
|
+
const node = document.createElement('div');
|
|
1710
|
+
node.id = 'dshe-preview-el';
|
|
1711
|
+
node.className = 'dshe-preview';
|
|
1712
|
+
node.style.cssText = [
|
|
1713
|
+
'position:fixed',
|
|
1714
|
+
'z-index:2147482000',
|
|
1715
|
+
'box-sizing:border-box',
|
|
1716
|
+
'overflow:auto',
|
|
1717
|
+
'width:' + String(preview.width) + 'px',
|
|
1718
|
+
'left:' + String(preview.left) + 'px',
|
|
1719
|
+
'max-height:' + String(preview.maxHeight ?? 320) + 'px',
|
|
1720
|
+
preview.bottom !== null && preview.bottom !== undefined
|
|
1721
|
+
? 'bottom:' + String(preview.bottom) + 'px'
|
|
1722
|
+
: 'top:' + String(Math.max(12, preview.top ?? 12)) + 'px',
|
|
1723
|
+
].join(';');
|
|
1724
|
+
|
|
1725
|
+
const needle = search.query.trim().toLowerCase();
|
|
1726
|
+
const text = String(preview.text ?? '');
|
|
1727
|
+
if (needle === '') {
|
|
1728
|
+
node.textContent = text;
|
|
1729
|
+
} else {
|
|
1730
|
+
let from = 0;
|
|
1731
|
+
let at = text.toLowerCase().indexOf(needle);
|
|
1732
|
+
while (at >= 0) {
|
|
1733
|
+
if (at > from) node.appendChild(document.createTextNode(text.slice(from, at)));
|
|
1734
|
+
const mark = document.createElement('mark');
|
|
1735
|
+
mark.className = at === preview.hit ? 'dshe-mark dshe-mark-current' : 'dshe-mark';
|
|
1736
|
+
mark.textContent = text.slice(at, at + needle.length);
|
|
1737
|
+
node.appendChild(mark);
|
|
1738
|
+
from = at + needle.length;
|
|
1739
|
+
at = text.toLowerCase().indexOf(needle, from);
|
|
1740
|
+
}
|
|
1741
|
+
if (from < text.length) node.appendChild(document.createTextNode(text.slice(from)));
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
node.addEventListener('mouseenter', () => {
|
|
1745
|
+
if (previewTimer.current !== null) window.clearTimeout(previewTimer.current);
|
|
1746
|
+
});
|
|
1747
|
+
node.addEventListener('mouseleave', () => {
|
|
1748
|
+
if (previewTimer.current !== null) window.clearTimeout(previewTimer.current);
|
|
1749
|
+
previewTimer.current = window.setTimeout(() => setPreview(null), 160);
|
|
1750
|
+
});
|
|
1751
|
+
document.body.appendChild(node);
|
|
1752
|
+
|
|
1753
|
+
// Keep it inside the window, then centre the focused hit.
|
|
1754
|
+
const rect = node.getBoundingClientRect();
|
|
1755
|
+
if (rect.bottom > window.innerHeight - 12) {
|
|
1756
|
+
node.style.top = 'auto';
|
|
1757
|
+
node.style.bottom = String(Math.max(12, Math.round(window.innerHeight - rect.top - (window.innerHeight - 24 - rect.height)))) + 'px';
|
|
1758
|
+
}
|
|
1759
|
+
const mark = node.querySelector('.dshe-mark-current');
|
|
1760
|
+
if (mark !== null) {
|
|
1761
|
+
const box = node.getBoundingClientRect();
|
|
1762
|
+
const markRect = mark.getBoundingClientRect();
|
|
1763
|
+
node.scrollTop += markRect.top - box.top - node.clientHeight / 2 + markRect.height / 2;
|
|
1764
|
+
}
|
|
1765
|
+
}, [preview, search.query]);
|
|
1766
|
+
|
|
1767
|
+
const previewRef = React.useRef(null);
|
|
1768
|
+
const previewTimer = React.useRef(null);
|
|
1769
|
+
const previewGate = React.useRef(true);
|
|
1770
|
+
const previewHover = React.useRef(null);
|
|
1771
|
+
const previewPointer = React.useRef({ x: 0, y: 0 });
|
|
1772
|
+
|
|
1773
|
+
React.useEffect(() => {
|
|
1774
|
+
// Typing hides the preview; it may only reappear after the pointer moves.
|
|
1775
|
+
previewGate.current = true;
|
|
1776
|
+
if (previewHover.current !== null) {
|
|
1777
|
+
window.clearTimeout(previewHover.current);
|
|
1778
|
+
previewHover.current = null;
|
|
1779
|
+
}
|
|
1780
|
+
setPreview(null);
|
|
1781
|
+
}, [search.query]);
|
|
1782
|
+
|
|
1783
|
+
React.useEffect(() => {
|
|
1784
|
+
const onMove = (event) => {
|
|
1785
|
+
previewGate.current = false;
|
|
1786
|
+
previewPointer.current = { x: event.clientX, y: event.clientY };
|
|
1787
|
+
};
|
|
1788
|
+
window.addEventListener('mousemove', onMove, { passive: true });
|
|
1789
|
+
return () => window.removeEventListener('mousemove', onMove);
|
|
1790
|
+
}, []);
|
|
1623
1791
|
|
|
1624
1792
|
React.useEffect(() => {
|
|
1625
1793
|
if (search.open !== true) return undefined;
|
|
@@ -1648,26 +1816,29 @@ const displayName = (value) => {
|
|
|
1648
1816
|
}, [search.open]);
|
|
1649
1817
|
|
|
1650
1818
|
const flat = React.useMemo(() => {
|
|
1651
|
-
const
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1819
|
+
const groups = search.groups ?? [];
|
|
1820
|
+
const target = expanded === null ? groups[0] : groups.find((group) => group.sessionId === expanded);
|
|
1821
|
+
return (target?.matches ?? []).map((match) => ({ group: target, match }));
|
|
1822
|
+
}, [search.groups, expanded]);
|
|
1823
|
+
|
|
1824
|
+
const groups = search.groups ?? [];
|
|
1825
|
+
const totalMatches = React.useMemo(
|
|
1826
|
+
() => groups.reduce((sum, group) => sum + (group.matches ?? []).length, 0),
|
|
1827
|
+
[search.groups],
|
|
1828
|
+
);
|
|
1657
1829
|
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
let cursor = 0;
|
|
1661
|
-
for (const group of search.groups ?? []) {
|
|
1662
|
-
map.set(group.sessionId, cursor);
|
|
1663
|
-
cursor += (group.matches ?? []).length;
|
|
1664
|
-
}
|
|
1665
|
-
return map;
|
|
1830
|
+
React.useEffect(() => {
|
|
1831
|
+
setExpanded((groups[0]?.sessionId) ?? null);
|
|
1666
1832
|
}, [search.groups]);
|
|
1667
1833
|
|
|
1668
1834
|
React.useEffect(() => {
|
|
1669
1835
|
setActive(0);
|
|
1670
|
-
}, [
|
|
1836
|
+
}, [expanded]);
|
|
1837
|
+
|
|
1838
|
+
React.useEffect(() => {
|
|
1839
|
+
setPreview(null);
|
|
1840
|
+
}, [search.open, search.groups]);
|
|
1841
|
+
|
|
1671
1842
|
|
|
1672
1843
|
React.useEffect(() => {
|
|
1673
1844
|
if (active >= flat.length) setActive(flat.length === 0 ? 0 : flat.length - 1);
|
|
@@ -1710,11 +1881,11 @@ const displayName = (value) => {
|
|
|
1710
1881
|
}
|
|
1711
1882
|
};
|
|
1712
1883
|
|
|
1713
|
-
const totalMatches = flat.length;
|
|
1714
1884
|
const meta = search.status === 'done'
|
|
1715
1885
|
? runtime.t('search.meta', { count: (search.groups ?? []).length, matches: totalMatches })
|
|
1716
1886
|
: '';
|
|
1717
1887
|
|
|
1888
|
+
|
|
1718
1889
|
const panel = h('div', { className: 'dshe-overlay dshe-overlay-top', role: 'presentation', style: { top: `${String(captionHeight())}px` } },
|
|
1719
1890
|
h('div', { className: 'dshe-backdrop', 'aria-hidden': 'true', onClick: () => runtime.store.closeSearch() }),
|
|
1720
1891
|
h('div', {
|
|
@@ -1748,27 +1919,70 @@ const displayName = (value) => {
|
|
|
1748
1919
|
search.status === 'idle' ? h('div', { className: 'dshe-status' }, runtime.t('search.hint')) : null,
|
|
1749
1920
|
search.status === 'done' && totalMatches === 0 ? h('div', { className: 'dshe-status' }, runtime.t('search.empty')) : null,
|
|
1750
1921
|
search.status === 'done'
|
|
1751
|
-
?
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
title: group.title,
|
|
1756
|
-
onClick: () => open(group.sessionId),
|
|
1757
|
-
}, group.title, h('span', { className: 'dshe-group-meta' }, (group.matches ?? []).length + '')),
|
|
1758
|
-
(group.matches ?? []).map((match, index) => {
|
|
1759
|
-
const rowIndex = (offsets.get(group.sessionId) ?? 0) + index;
|
|
1760
|
-
return h('button', {
|
|
1922
|
+
? groups.map((group) => {
|
|
1923
|
+
const isOpen = group.sessionId === expanded;
|
|
1924
|
+
return h('div', { className: 'dshe-group', key: group.sessionId },
|
|
1925
|
+
h('button', {
|
|
1761
1926
|
type: 'button',
|
|
1762
|
-
className: 'dshe-
|
|
1763
|
-
|
|
1764
|
-
'
|
|
1765
|
-
onClick: () =>
|
|
1927
|
+
className: 'dshe-group-title',
|
|
1928
|
+
title: group.title,
|
|
1929
|
+
'aria-expanded': isOpen ? 'true' : 'false',
|
|
1930
|
+
onClick: () => setExpanded(isOpen ? null : group.sessionId),
|
|
1766
1931
|
},
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
)
|
|
1770
|
-
|
|
1771
|
-
|
|
1932
|
+
h('span', { className: 'dshe-group-caret' }, isOpen ? '▾' : '▸'),
|
|
1933
|
+
h('span', { className: 'dshe-group-name' }, group.title),
|
|
1934
|
+
h('span', { className: 'dshe-group-meta' }, (group.matches ?? []).length + '')),
|
|
1935
|
+
isOpen
|
|
1936
|
+
? (group.matches ?? []).map((match, index) => h('button', {
|
|
1937
|
+
type: 'button',
|
|
1938
|
+
className: 'dshe-match',
|
|
1939
|
+
onMouseEnter: (event) => {
|
|
1940
|
+
if (previewHover.current !== null) window.clearTimeout(previewHover.current);
|
|
1941
|
+
if (previewGate.current === true) return;
|
|
1942
|
+
const row = event.currentTarget;
|
|
1943
|
+
if (event.clientX !== undefined) previewPointer.current = { x: event.clientX, y: event.clientY };
|
|
1944
|
+
previewHover.current = window.setTimeout(() => {
|
|
1945
|
+
previewHover.current = null;
|
|
1946
|
+
const rect = row.getBoundingClientRect();
|
|
1947
|
+
const dialog = row.closest('.dshe-search');
|
|
1948
|
+
const box = dialog === null ? null : dialog.getBoundingClientRect();
|
|
1949
|
+
const width = box === null ? 420 : Math.min(460, Math.round(box.width * 0.62));
|
|
1950
|
+
const pointer = previewPointer.current;
|
|
1951
|
+
const left = Math.max(12, Math.min(Math.round(pointer.x + 16), window.innerWidth - width - 12));
|
|
1952
|
+
const spaceBelow = Math.round(window.innerHeight - rect.bottom - 12);
|
|
1953
|
+
const spaceAbove = Math.round(rect.top - 12);
|
|
1954
|
+
// Pick whichever side has more room, so a row near the bottom opens upwards.
|
|
1955
|
+
const goAbove = spaceAbove > spaceBelow;
|
|
1956
|
+
if (goAbove) {
|
|
1957
|
+
const bottom = Math.max(12, Math.round(window.innerHeight - (rect.top - 6)));
|
|
1958
|
+
const maxHeight = Math.max(160, Math.min(Math.round(window.innerHeight * 0.7), spaceAbove - 6));
|
|
1959
|
+
setPreview({ text: match.preview || match.snippet || '', hit: match.previewHit ?? -1, left, width, maxHeight, top: null, bottom });
|
|
1960
|
+
} else {
|
|
1961
|
+
const top = Math.round(rect.bottom + 6);
|
|
1962
|
+
const maxHeight = Math.max(160, Math.min(Math.round(window.innerHeight * 0.7), spaceBelow - 6));
|
|
1963
|
+
setPreview({ text: match.preview || match.snippet || '', hit: match.previewHit ?? -1, left, width, maxHeight, top, bottom: null });
|
|
1964
|
+
}
|
|
1965
|
+
}, 1000);
|
|
1966
|
+
},
|
|
1967
|
+
onMouseLeave: () => {
|
|
1968
|
+
if (previewHover.current !== null) {
|
|
1969
|
+
window.clearTimeout(previewHover.current);
|
|
1970
|
+
previewHover.current = null;
|
|
1971
|
+
}
|
|
1972
|
+
if (previewTimer.current !== null) window.clearTimeout(previewTimer.current);
|
|
1973
|
+
previewTimer.current = window.setTimeout(() => setPreview(null), 160);
|
|
1974
|
+
},
|
|
1975
|
+
key: `${group.sessionId}-${String(match.seq ?? 'title')}-${String(index)}`,
|
|
1976
|
+
'data-active': index === active ? 'true' : 'false',
|
|
1977
|
+
onClick: () => open(group.sessionId, match),
|
|
1978
|
+
},
|
|
1979
|
+
h('span', { className: 'dshe-match-time', 'data-tier': String(timeTier(formatMatchTime(match.time))) }, formatMatchTime(match.time)),
|
|
1980
|
+
h('span', { className: 'dshe-role' }, runtime.t(`role.${match.role ?? 'body'}`)),
|
|
1981
|
+
h('span', { className: 'dshe-snippet' }, highlight(match.snippet ?? '', search.query)),
|
|
1982
|
+
))
|
|
1983
|
+
: null,
|
|
1984
|
+
);
|
|
1985
|
+
})
|
|
1772
1986
|
: null,
|
|
1773
1987
|
),
|
|
1774
1988
|
),
|
|
@@ -2131,7 +2345,7 @@ const displayName = (value) => {
|
|
|
2131
2345
|
onClick: () => runtime.store.openRestart(),
|
|
2132
2346
|
}, runtime.t('restart.button')),
|
|
2133
2347
|
),
|
|
2134
|
-
h('button', {
|
|
2348
|
+
state.sync.showLog === true ? null : h('button', {
|
|
2135
2349
|
type: 'button',
|
|
2136
2350
|
className: 'dshe-row-desc dshe-log-toggle',
|
|
2137
2351
|
title: runtime.t('sync.logToggle'),
|
|
@@ -2534,62 +2748,249 @@ const displayName = (value) => {
|
|
|
2534
2748
|
console.warn('[dsh-enhanced] refreshing the workspace failed:', error);
|
|
2535
2749
|
}
|
|
2536
2750
|
};
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2751
|
+
/**
|
|
2752
|
+
* Scroll to the start of one turn.
|
|
2753
|
+
*
|
|
2754
|
+
* Text-level precision inside a turn is not reliable: the same sentence can
|
|
2755
|
+
* appear in the prompt and in the reply, and markdown rendering shifts the
|
|
2756
|
+
* offsets. Landing on the turn boundary is predictable.
|
|
2757
|
+
*/
|
|
2758
|
+
/** Normalise for a loose containment check: markdown noise and spaces out. */
|
|
2759
|
+
const looseText = (value) => String(value ?? '').replace(/[\s`*_#>~\[\]()…⋯]/gu, '').toLowerCase();
|
|
2760
|
+
|
|
2761
|
+
/** Keep only letters and digits: markdown markers differ between log and UI. */
|
|
2762
|
+
const bareText = (value) => String(value ?? '').replace(/[^\p{L}\p{N}]/gu, '').toLowerCase();
|
|
2763
|
+
|
|
2764
|
+
/** Wrap every occurrence of the query inside the given nodes, then undo it later. */
|
|
2765
|
+
/**
|
|
2766
|
+
* Highlight every occurrence inside the given nodes with the CSS Highlight API.
|
|
2767
|
+
*
|
|
2768
|
+
* Ranges leave the DOM untouched, so a later render cannot break the markup,
|
|
2769
|
+
* and the ten-second timer starts only after the target page is on screen.
|
|
2770
|
+
*/
|
|
2771
|
+
let releaseFlash = null;
|
|
2772
|
+
const highlightMatches = (nodes, query) => {
|
|
2773
|
+
if (releaseFlash !== null) {
|
|
2774
|
+
releaseFlash();
|
|
2775
|
+
releaseFlash = null;
|
|
2776
|
+
}
|
|
2777
|
+
const needle = typeof query === 'string' ? query.trim() : '';
|
|
2778
|
+
if (needle === '' || nodes.length === 0) return;
|
|
2779
|
+
if (typeof CSS === 'undefined' || CSS.highlights === undefined || typeof Highlight === 'undefined') return;
|
|
2780
|
+
const lowerNeedle = needle.toLowerCase();
|
|
2781
|
+
const ranges = [];
|
|
2782
|
+
for (const node of nodes.slice(0, 8)) {
|
|
2783
|
+
const walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT, {
|
|
2784
|
+
acceptNode: (textNode) => (textNode.nodeValue ?? '').toLowerCase().includes(lowerNeedle)
|
|
2785
|
+
? NodeFilter.FILTER_ACCEPT
|
|
2786
|
+
: NodeFilter.FILTER_SKIP,
|
|
2787
|
+
});
|
|
2788
|
+
while (walker.nextNode() !== null) {
|
|
2789
|
+
const textNode = walker.currentNode;
|
|
2790
|
+
const value = textNode.nodeValue ?? '';
|
|
2791
|
+
const lower = value.toLowerCase();
|
|
2792
|
+
let from = 0;
|
|
2793
|
+
let at = lower.indexOf(lowerNeedle);
|
|
2794
|
+
while (at >= 0) {
|
|
2795
|
+
const range = document.createRange();
|
|
2796
|
+
range.setStart(textNode, at);
|
|
2797
|
+
range.setEnd(textNode, at + needle.length);
|
|
2798
|
+
ranges.push(range);
|
|
2799
|
+
from = at + needle.length;
|
|
2800
|
+
at = lower.indexOf(lowerNeedle, from);
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
if (ranges.length === 0) return;
|
|
2805
|
+
CSS.highlights.set('dshe-flash', new Highlight(...ranges));
|
|
2806
|
+
const timer = window.setTimeout(() => {
|
|
2807
|
+
CSS.highlights.delete('dshe-flash');
|
|
2808
|
+
releaseFlash = null;
|
|
2809
|
+
}, 10_000);
|
|
2810
|
+
releaseFlash = () => {
|
|
2811
|
+
window.clearTimeout(timer);
|
|
2812
|
+
CSS.highlights.delete('dshe-flash');
|
|
2813
|
+
};
|
|
2814
|
+
};
|
|
2815
|
+
|
|
2816
|
+
|
|
2817
|
+
/**
|
|
2818
|
+
* Scroll to the turn a hit belongs to and flash the matched text for ten seconds.
|
|
2819
|
+
*
|
|
2820
|
+
* The event seq keys the rendered node ("13:input-message…"), so that is the
|
|
2821
|
+
* primary anchor. Assistant nodes are keyed by turn instead, and the stored
|
|
2822
|
+
* turn can be off by one across the host/UI numbering, so neighbouring turns
|
|
2823
|
+
* are tried and the one whose own text contains the hit wins.
|
|
2824
|
+
*/
|
|
2825
|
+
/**
|
|
2826
|
+
* Fixed-position banner for jump feedback.
|
|
2827
|
+
*
|
|
2828
|
+
* It does not depend on React or the toast store and always lands at a
|
|
2829
|
+
* constant place in the window, so nothing can push it off-screen.
|
|
2830
|
+
*/
|
|
2831
|
+
const showJumpNotice = (text, ms) => {
|
|
2832
|
+
try {
|
|
2833
|
+
const existing = document.getElementById('dshe-jump-notice');
|
|
2834
|
+
if (existing !== null) existing.remove();
|
|
2835
|
+
const node = document.createElement('div');
|
|
2836
|
+
node.id = 'dshe-jump-notice';
|
|
2837
|
+
node.textContent = String(text ?? '');
|
|
2838
|
+
node.style.cssText = [
|
|
2839
|
+
'position:fixed',
|
|
2840
|
+
'z-index:2147483002',
|
|
2841
|
+
'top:44px',
|
|
2842
|
+
'left:50%',
|
|
2843
|
+
'transform:translateX(-50%)',
|
|
2844
|
+
'pointer-events:auto',
|
|
2845
|
+
'background:rgba(24,26,30,.96)',
|
|
2846
|
+
'color:#fff',
|
|
2847
|
+
'border:1px solid rgba(255,255,255,.18)',
|
|
2848
|
+
'border-radius:14px',
|
|
2849
|
+
'padding:16px 26px',
|
|
2850
|
+
'font-size:16px',
|
|
2851
|
+
'font-weight:500',
|
|
2852
|
+
'line-height:1.55',
|
|
2853
|
+
'box-shadow:0 24px 60px rgba(0,0,0,.38)',
|
|
2854
|
+
'max-width:70vw',
|
|
2855
|
+
'text-align:center',
|
|
2856
|
+
'cursor:pointer',
|
|
2857
|
+
].join(';');
|
|
2858
|
+
node.addEventListener('click', () => node.remove());
|
|
2859
|
+
document.body.appendChild(node);
|
|
2860
|
+
window.setTimeout(() => node.remove(), typeof ms === 'number' ? ms : 5000);
|
|
2861
|
+
} catch (error) {
|
|
2862
|
+
console.warn('[dsh-enhanced] notice failed:', error);
|
|
2863
|
+
}
|
|
2864
|
+
};
|
|
2540
2865
|
|
|
2866
|
+
/**
|
|
2867
|
+
* Locate one hit inside the mounted transcript.
|
|
2868
|
+
*
|
|
2869
|
+
* Only rendered rows can be found: a hit that lives in older history is
|
|
2870
|
+
* reported instead of being searched for where it cannot exist.
|
|
2871
|
+
*/
|
|
2541
2872
|
runtime.jumpToAnchor = (options) => {
|
|
2542
|
-
const
|
|
2543
|
-
const
|
|
2544
|
-
const
|
|
2545
|
-
const
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2873
|
+
const query = typeof options?.query === 'string' ? options.query : '';
|
|
2874
|
+
const previewText = typeof options?.preview === 'string' ? options.preview : '';
|
|
2875
|
+
const previewHit = Number.isInteger(options?.previewHit) ? options.previewHit : -1;
|
|
2876
|
+
const probe = bareText(options?.snippet ?? '').slice(0, 40);
|
|
2877
|
+
const anchorText = previewText !== '' && previewHit >= 0
|
|
2878
|
+
? bareText(previewText.slice(Math.max(0, previewHit - 60), previewHit + 60))
|
|
2879
|
+
: '';
|
|
2880
|
+
const kinds = options?.role === 'user'
|
|
2881
|
+
? ['user', 'steering']
|
|
2882
|
+
: (options?.role === 'assistant'
|
|
2883
|
+
? ['assistant-step', 'turn-tail']
|
|
2884
|
+
: (options?.role === 'tool' ? ['tool-call'] : null));
|
|
2885
|
+
|
|
2886
|
+
let settled = false;
|
|
2887
|
+
let tries = 0;
|
|
2888
|
+
|
|
2889
|
+
const finish = (row) => {
|
|
2890
|
+
settled = true;
|
|
2891
|
+
scrollToKeyword(row, query);
|
|
2892
|
+
highlightMatches([row], query);
|
|
2893
|
+
showJumpNotice('已定位到匹配位置', 2000);
|
|
2894
|
+
};
|
|
2895
|
+
|
|
2896
|
+
/** Scroll the transcript so one occurrence of the keyword is centred. */
|
|
2897
|
+
const scrollToKeyword = (row, queryText) => {
|
|
2898
|
+
const needle = String(queryText ?? '').trim().toLowerCase();
|
|
2899
|
+
if (needle === '') {
|
|
2900
|
+
row.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
|
2901
|
+
return;
|
|
2552
2902
|
}
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
?
|
|
2562
|
-
:
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2903
|
+
let scroller = row.parentElement;
|
|
2904
|
+
while (scroller !== null && scroller !== document.body) {
|
|
2905
|
+
const style = window.getComputedStyle(scroller);
|
|
2906
|
+
if ((style.overflowY === 'auto' || style.overflowY === 'scroll') && scroller.scrollHeight > scroller.clientHeight) break;
|
|
2907
|
+
scroller = scroller.parentElement;
|
|
2908
|
+
}
|
|
2909
|
+
const walker = document.createTreeWalker(row, NodeFilter.SHOW_TEXT, {
|
|
2910
|
+
acceptNode: (textNode) => (textNode.nodeValue ?? '').toLowerCase().includes(needle)
|
|
2911
|
+
? NodeFilter.FILTER_ACCEPT
|
|
2912
|
+
: NodeFilter.FILTER_SKIP,
|
|
2913
|
+
});
|
|
2914
|
+
while (walker.nextNode() !== null) {
|
|
2915
|
+
const textNode = walker.currentNode;
|
|
2916
|
+
const value = textNode.nodeValue ?? '';
|
|
2917
|
+
const at = value.toLowerCase().indexOf(needle);
|
|
2918
|
+
if (at < 0) continue;
|
|
2919
|
+
if (scroller === null) break;
|
|
2920
|
+
const range = document.createRange();
|
|
2921
|
+
range.setStart(textNode, at);
|
|
2922
|
+
range.setEnd(textNode, at + needle.length);
|
|
2923
|
+
const rect = range.getBoundingClientRect();
|
|
2924
|
+
const box = scroller.getBoundingClientRect();
|
|
2925
|
+
if (rect.height > 0) {
|
|
2926
|
+
scroller.scrollTop += rect.top - box.top - box.height / 2 + rect.height / 2;
|
|
2927
|
+
return;
|
|
2574
2928
|
}
|
|
2575
2929
|
}
|
|
2576
|
-
|
|
2577
|
-
|
|
2930
|
+
row.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
|
2931
|
+
};
|
|
2932
|
+
|
|
2933
|
+
/** Row that carries most of the excerpt, or null. */
|
|
2934
|
+
const pickRow = (rows) => {
|
|
2935
|
+
const chunks = anchorText === ''
|
|
2936
|
+
? []
|
|
2937
|
+
: (() => {
|
|
2938
|
+
const size = Math.max(10, Math.floor(anchorText.length / 3));
|
|
2939
|
+
const parts = [];
|
|
2940
|
+
for (let i = 0; i + size <= anchorText.length; i += size) parts.push(anchorText.slice(i, i + size));
|
|
2941
|
+
return parts;
|
|
2942
|
+
})();
|
|
2943
|
+
const needed = Math.max(2, Math.ceil(chunks.length * 0.6));
|
|
2944
|
+
for (const row of rows) {
|
|
2945
|
+
const text = bareText(row.textContent);
|
|
2946
|
+
if (query !== '' && !text.includes(bareText(query))) continue;
|
|
2947
|
+
if (chunks.length > 0 && chunks.filter((part) => text.includes(part)).length >= needed) return row;
|
|
2948
|
+
if (probe.length >= 24 && text.includes(probe)) return row;
|
|
2949
|
+
}
|
|
2950
|
+
return null;
|
|
2578
2951
|
};
|
|
2579
|
-
window.setTimeout(tick, 60);
|
|
2580
|
-
};
|
|
2581
2952
|
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2953
|
+
const attempt = () => {
|
|
2954
|
+
if (settled === true) return;
|
|
2955
|
+
tries += 1;
|
|
2585
2956
|
try {
|
|
2586
|
-
const
|
|
2587
|
-
|
|
2957
|
+
const flows = Array.from(document.querySelectorAll('[data-chat-flow]'))
|
|
2958
|
+
.filter((node) => node.querySelector('[data-chat-flow-key]') !== null);
|
|
2959
|
+
for (const flow of flows) {
|
|
2960
|
+
let rows = Array.from(flow.querySelectorAll('[data-chat-flow-key]'));
|
|
2961
|
+
if (kinds !== null) {
|
|
2962
|
+
const byKind = rows.filter((row) => kinds.includes(row.getAttribute('data-chat-flow-kind') ?? ''));
|
|
2963
|
+
if (byKind.length > 0) rows = byKind;
|
|
2964
|
+
}
|
|
2965
|
+
const hit = pickRow(rows);
|
|
2966
|
+
if (hit !== null) {
|
|
2967
|
+
finish(hit);
|
|
2968
|
+
return;
|
|
2969
|
+
}
|
|
2970
|
+
}
|
|
2588
2971
|
} catch (error) {
|
|
2589
|
-
console.warn('[dsh-enhanced]
|
|
2972
|
+
console.warn('[dsh-enhanced] locate failed:', error);
|
|
2590
2973
|
}
|
|
2591
|
-
|
|
2592
|
-
|
|
2974
|
+
if (tries >= 8) {
|
|
2975
|
+
settled = true;
|
|
2976
|
+
showJumpNotice('该命中在更早的会话中,已打开会话但未自动定位', 5000);
|
|
2977
|
+
return;
|
|
2978
|
+
}
|
|
2979
|
+
window.setTimeout(attempt, 350);
|
|
2980
|
+
};
|
|
2981
|
+
attempt();
|
|
2982
|
+
};
|
|
2983
|
+
|
|
2984
|
+
runtime.focusMatch = (sessionId, match, query) => {
|
|
2985
|
+
// The hit already names its session, and only mounted rows can be located,
|
|
2986
|
+
// so the click navigates by text alone.
|
|
2987
|
+
runtime.jumpToAnchor({
|
|
2988
|
+
role: match?.role,
|
|
2989
|
+
snippet: match?.snippet,
|
|
2990
|
+
preview: match?.preview,
|
|
2991
|
+
previewHit: match?.previewHit,
|
|
2992
|
+
query,
|
|
2993
|
+
});
|
|
2593
2994
|
};
|
|
2594
2995
|
runtime.rpc = async (action, payload, signal) => {
|
|
2595
2996
|
const url = new URL('api/dsh-enhanced/rpc', document.baseURI);
|
|
@@ -2647,11 +3048,13 @@ const displayName = (value) => {
|
|
|
2647
3048
|
return () => window.removeEventListener('keydown', onKeyDown, true);
|
|
2648
3049
|
}, 'dsh-enhanced: restart shortcut');
|
|
2649
3050
|
|
|
3051
|
+
|
|
3052
|
+
|
|
2650
3053
|
ctx.effect(() => {
|
|
2651
3054
|
// Prefetch distance from the top of the loaded history, in pixels.
|
|
2652
|
-
const PREFETCH_PX =
|
|
3055
|
+
const PREFETCH_PX = 600;
|
|
2653
3056
|
// Do not stack requests closer than this, so one flick loads one page.
|
|
2654
|
-
const MIN_GAP_MS =
|
|
3057
|
+
const MIN_GAP_MS = 600;
|
|
2655
3058
|
let cachedScroller = null;
|
|
2656
3059
|
let loading = null;
|
|
2657
3060
|
let scheduled = null;
|
|
@@ -2682,12 +3085,13 @@ const displayName = (value) => {
|
|
|
2682
3085
|
};
|
|
2683
3086
|
|
|
2684
3087
|
const findOlderButton = () => {
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
const
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
3088
|
+
const candidates = Array.from(document.querySelectorAll('button, [role="button"], a, [data-load-older]'));
|
|
3089
|
+
for (const node of candidates) {
|
|
3090
|
+
const label = (node.textContent ?? '').trim();
|
|
3091
|
+
if (label === 'Load earlier' || label.startsWith('加载更早')) return node;
|
|
3092
|
+
if (node.hasAttribute('data-load-older')) return node;
|
|
3093
|
+
const className = [String(node.className ?? ''), String(node.parentElement?.className ?? '')].join(' ');
|
|
3094
|
+
if (/(?:^|[_\s-])older(?:[_\s-]|$)/iu.test(className)) return node;
|
|
2691
3095
|
}
|
|
2692
3096
|
return null;
|
|
2693
3097
|
};
|
|
@@ -2736,7 +3140,7 @@ const displayName = (value) => {
|
|
|
2736
3140
|
if (grown > 0 && !moved) scroller.scrollTop = before.top + grown;
|
|
2737
3141
|
loading = null;
|
|
2738
3142
|
// Chain straight into the next page while the reader is still near the top.
|
|
2739
|
-
schedule(
|
|
3143
|
+
schedule(400);
|
|
2740
3144
|
};
|
|
2741
3145
|
window.setTimeout(settle, 100);
|
|
2742
3146
|
};
|
package/host/engine/index.js
CHANGED
|
@@ -10,7 +10,8 @@ import { promises as fsp } from 'node:fs';
|
|
|
10
10
|
import { randomUUID } from 'node:crypto';
|
|
11
11
|
import path from 'node:path';
|
|
12
12
|
import { syncSessions } from './sessions.js';
|
|
13
|
-
import { scanSessionGroups } from './scan.js';
|
|
13
|
+
import { scanSessionGroups, scanSessions } from './scan.js';
|
|
14
|
+
import { readSessionFile } from './session.js';
|
|
14
15
|
import { loadPathMap, resolveLocalPath } from './paths.js';
|
|
15
16
|
import { mergeWorkspaceFiles } from './workspace.js';
|
|
16
17
|
import { pruneArchiveEvents, syncArchiveState, writeArchiveEvents } from './archive.js';
|
|
@@ -195,6 +196,16 @@ async function runSyncJsInner(deps) {
|
|
|
195
196
|
sharedFile: path.join(sharedConfig, 'storages', 'workspace.json'),
|
|
196
197
|
tombstones,
|
|
197
198
|
resolvePath: async (value) => (await resolveCwd(value)).path,
|
|
199
|
+
// Lazy session lookup: only paid when a merge finds duplicate memberships.
|
|
200
|
+
sessionCwd: async (id) => {
|
|
201
|
+
const found = (await scanSessions(path.join(dshHome, 'sessions'))).get(id);
|
|
202
|
+
if (found === undefined) return null;
|
|
203
|
+
try {
|
|
204
|
+
return (await readSessionFile(found.file)).header.cwd ?? null;
|
|
205
|
+
} catch {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
},
|
|
198
209
|
isDirectory,
|
|
199
210
|
stateDir,
|
|
200
211
|
machineId,
|
package/host/engine/sessions.js
CHANGED
|
@@ -262,6 +262,12 @@ export async function syncSessions(deps) {
|
|
|
262
262
|
continue;
|
|
263
263
|
}
|
|
264
264
|
const sharedEntry = shared.get(id);
|
|
265
|
+
// A session under another workspace folder was moved: the folder says nothing
|
|
266
|
+
// about which copy is newer, so the event count still decides. Treating the
|
|
267
|
+
// local folder as authoritative pushed a stale copy back over a newer share
|
|
268
|
+
// and undid the move.
|
|
269
|
+
const relocated = sharedEntry !== undefined
|
|
270
|
+
&& path.basename(path.dirname(entry.file)) !== path.basename(path.dirname(sharedEntry.file));
|
|
265
271
|
// Append-only logs: the one holding more events is the newer one. Upload and
|
|
266
272
|
// download timestamps are meaningless here because each transfer rewrites them.
|
|
267
273
|
if (sharedEntry !== undefined) {
|
|
@@ -269,6 +275,8 @@ export async function syncSessions(deps) {
|
|
|
269
275
|
const sharedSeq = await lastContentSeq(sharedEntry.file);
|
|
270
276
|
if (sharedSeq >= 0 && localSeq >= 0) {
|
|
271
277
|
if (sharedSeq >= localSeq) {
|
|
278
|
+
// The share is as new or newer — including a moved session it already
|
|
279
|
+
// holds; the pull pass below brings it over and drops the local copy.
|
|
272
280
|
skipped += 1;
|
|
273
281
|
continue;
|
|
274
282
|
}
|
|
@@ -278,7 +286,16 @@ export async function syncSessions(deps) {
|
|
|
278
286
|
}
|
|
279
287
|
}
|
|
280
288
|
try {
|
|
281
|
-
if (apply)
|
|
289
|
+
if (apply) {
|
|
290
|
+
const written = await copySessionTo(entry, sharedRoot);
|
|
291
|
+
// A moved session can still exist under its previous project key in the
|
|
292
|
+
// share; leaving it makes every later run look like a push.
|
|
293
|
+
if (relocated && sharedEntry !== undefined) {
|
|
294
|
+
await fsp.rm(sharedEntry.dir, { recursive: true, force: true }).catch(() => {});
|
|
295
|
+
shared.delete(id);
|
|
296
|
+
}
|
|
297
|
+
await dropOtherCopies(sharedRoot, id, path.dirname(written));
|
|
298
|
+
}
|
|
282
299
|
pushed += 1;
|
|
283
300
|
if (pushedIds.length < 300) pushedIds.push(id);
|
|
284
301
|
} catch (error) {
|
package/host/engine/workspace.js
CHANGED
|
@@ -61,6 +61,7 @@ export async function mergeWorkspaceDocuments(localDoc, sharedDoc, options = {})
|
|
|
61
61
|
stateDir = null,
|
|
62
62
|
machineId = null,
|
|
63
63
|
apply = true,
|
|
64
|
+
sessionCwd = null,
|
|
64
65
|
} = options;
|
|
65
66
|
|
|
66
67
|
// Workspace deletions used to be silent: the other machine's document still
|
|
@@ -145,6 +146,37 @@ export async function mergeWorkspaceDocuments(localDoc, sharedDoc, options = {})
|
|
|
145
146
|
else missing.push({ title: entry.title, path: entry.path });
|
|
146
147
|
}
|
|
147
148
|
|
|
149
|
+
// A session belongs to one workspace only. Older merges unioned membership, so a
|
|
150
|
+
// moved session stayed listed under its previous workspace; resolve the real one
|
|
151
|
+
// from the session header and drop the rest.
|
|
152
|
+
if (typeof sessionCwd === 'function') {
|
|
153
|
+
const owners = new Map();
|
|
154
|
+
for (const [uuid, record] of Object.entries(shared)) {
|
|
155
|
+
for (const id of record.sessionIds) {
|
|
156
|
+
const list = owners.get(id) ?? [];
|
|
157
|
+
list.push(uuid);
|
|
158
|
+
owners.set(id, list);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
for (const [id, uuids] of owners) {
|
|
162
|
+
if (uuids.length < 2) continue;
|
|
163
|
+
let cwd = null;
|
|
164
|
+
try {
|
|
165
|
+
cwd = await sessionCwd(id);
|
|
166
|
+
} catch {
|
|
167
|
+
cwd = null;
|
|
168
|
+
}
|
|
169
|
+
const normalized = typeof cwd === 'string' && cwd !== '' ? await resolvePath(cwd) : null;
|
|
170
|
+
const keep = normalized === null
|
|
171
|
+
? uuids[0]
|
|
172
|
+
: (uuids.find((uuid) => shared[uuid]?.path === normalized) ?? uuids[0]);
|
|
173
|
+
for (const uuid of uuids) {
|
|
174
|
+
if (uuid === keep) continue;
|
|
175
|
+
shared[uuid].sessionIds = shared[uuid].sessionIds.filter((value) => value !== id);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
148
180
|
const archived = [];
|
|
149
181
|
const pinned = [];
|
|
150
182
|
let initialized = false;
|
package/host/envcheck.js
CHANGED
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
* A failed check never throws; it is reported so the user can export a report.
|
|
7
7
|
*/
|
|
8
8
|
import { promises as fsp } from 'node:fs';
|
|
9
|
+
import { pluginVersion } from './version.js';
|
|
9
10
|
import path from 'node:path';
|
|
10
11
|
import os from 'node:os';
|
|
11
12
|
import zlib from 'node:zlib';
|
|
12
13
|
import { scanFrames } from './engine/zstd.js';
|
|
13
14
|
import { scanSessions, projectKey } from './engine/scan.js';
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
|
|
16
17
|
|
|
17
18
|
async function readJson(file) {
|
|
18
19
|
try {
|
|
@@ -227,7 +228,7 @@ export async function runEnvironmentCheck(deps) {
|
|
|
227
228
|
return {
|
|
228
229
|
ok: failed.length === 0,
|
|
229
230
|
checkedAt: new Date().toISOString(),
|
|
230
|
-
pluginVersion:
|
|
231
|
+
pluginVersion: pluginVersion(),
|
|
231
232
|
appVersion: version.version,
|
|
232
233
|
appVersionSource: version.source,
|
|
233
234
|
checks,
|
package/host/search.js
CHANGED
|
@@ -13,17 +13,58 @@ const MAX_SEGMENT_CHARS = 24000;
|
|
|
13
13
|
const MAX_MATCHES_PER_SESSION = Number.POSITIVE_INFINITY;
|
|
14
14
|
const MAX_TOTAL_MATCHES = 500;
|
|
15
15
|
const CONTEXT_CHARS = 42;
|
|
16
|
+
// The hover preview needs a readable passage, not just one line around the hit.
|
|
17
|
+
const PREVIEW_CHARS = 420;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Wrappers the app injects into a message but never shows in the conversation.
|
|
21
|
+
* Matching inside them would surface hits the reader cannot see on screen.
|
|
22
|
+
*/
|
|
23
|
+
const HIDDEN_WRAPPERS = ['system-reminder', 'available_skills', 'compacted-summary'];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* User-message sources the transcript actually renders. Everything else the log
|
|
27
|
+
* stores as a `user/message` is model-facing context: runtime snapshots, time
|
|
28
|
+
* stamps, skill catalogs, model switches, approval notes, background-job
|
|
29
|
+
* notices, and compaction checkpoints. Those never appear in the conversation,
|
|
30
|
+
* so indexing them would return hits the reader cannot see.
|
|
31
|
+
*/
|
|
32
|
+
const VISIBLE_USER_SOURCES = new Set(['user', 'user-question-reply']);
|
|
33
|
+
|
|
34
|
+
/** True when a stored user message is one the transcript shows. */
|
|
35
|
+
function isVisibleUserMessage(message) {
|
|
36
|
+
const source = message?.source;
|
|
37
|
+
// Logs written before sources existed have no marker; keep them searchable.
|
|
38
|
+
if (source === null || typeof source !== 'object') return true;
|
|
39
|
+
return VISIBLE_USER_SOURCES.has(source.kind);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Drop hidden wrapper blocks (and stray closing tags) from one text block. */
|
|
43
|
+
function stripHidden(text) {
|
|
44
|
+
let out = text;
|
|
45
|
+
// Only a leading wrapper is model-facing context. A wrapper quoted inside
|
|
46
|
+
// prose or a fenced code block is visible content and stays searchable.
|
|
47
|
+
for (const tag of HIDDEN_WRAPPERS) {
|
|
48
|
+
const leading = new RegExp(`^\\s*<${tag}>[\\s\\S]*?</${tag}>`, 'iu');
|
|
49
|
+
while (leading.test(out)) out = out.replace(leading, ' ');
|
|
50
|
+
}
|
|
51
|
+
// A block that is only a closing tag belongs to a wrapper split across blocks.
|
|
52
|
+
if (/^<\/[a-z-]+>$/iu.test(out.trim())) return '';
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
16
55
|
|
|
17
56
|
/** Text blocks of one message, tolerating every message shape the log stores. */
|
|
18
57
|
function messageText(message) {
|
|
19
58
|
if (message === null || typeof message !== 'object') return '';
|
|
20
59
|
const content = message.content;
|
|
21
|
-
if (typeof content === 'string') return content.trim();
|
|
60
|
+
if (typeof content === 'string') return stripHidden(content).trim();
|
|
22
61
|
if (!Array.isArray(content)) return '';
|
|
23
62
|
const parts = [];
|
|
24
63
|
for (const block of content) {
|
|
25
64
|
if (block === null || typeof block !== 'object') continue;
|
|
26
|
-
if (block.type
|
|
65
|
+
if (block.type !== 'text' || typeof block.text !== 'string') continue;
|
|
66
|
+
const text = stripHidden(block.text);
|
|
67
|
+
if (text.trim() !== '') parts.push(text);
|
|
27
68
|
}
|
|
28
69
|
return parts.join('\n').trim();
|
|
29
70
|
}
|
|
@@ -39,20 +80,23 @@ function buildDocument(sessionId, header, events) {
|
|
|
39
80
|
let title = '';
|
|
40
81
|
let updatedAt = typeof header.createdAt === 'number' ? header.createdAt : 0;
|
|
41
82
|
let firstUserText = '';
|
|
83
|
+
let turn = 0;
|
|
42
84
|
for (const event of events) {
|
|
85
|
+
if (event.type === 'turn/start' && typeof event.data?.turn === 'number') turn = event.data.turn;
|
|
43
86
|
if (typeof event.time === 'number' && event.time > updatedAt) updatedAt = event.time;
|
|
44
87
|
if (event.type === 'user/message') {
|
|
88
|
+
if (!isVisibleUserMessage(event.data)) continue;
|
|
45
89
|
const text = messageText(event.data);
|
|
46
90
|
if (text !== '') {
|
|
47
91
|
if (firstUserText === '') firstUserText = text;
|
|
48
|
-
segments.push({ seq: event.seq, role: 'user', text: clip(text) });
|
|
92
|
+
segments.push({ seq: event.seq, role: 'user', text: clip(text), time: event.time, turn });
|
|
49
93
|
}
|
|
50
94
|
} else if (event.type === 'assistant/message') {
|
|
51
95
|
const text = messageText(event.data?.message);
|
|
52
|
-
if (text !== '') segments.push({ seq: event.seq, role: 'assistant', text: clip(text) });
|
|
96
|
+
if (text !== '') segments.push({ seq: event.seq, role: 'assistant', text: clip(text), time: event.time, turn });
|
|
53
97
|
} else if (event.type === 'tool/result') {
|
|
54
98
|
const text = messageText(event.data?.message);
|
|
55
|
-
if (text !== '') segments.push({ seq: event.seq, role: 'tool', text: clip(text) });
|
|
99
|
+
if (text !== '') segments.push({ seq: event.seq, role: 'tool', text: clip(text), time: event.time, turn });
|
|
56
100
|
} else if (event.type === 'session/title') {
|
|
57
101
|
const value = event.data?.title;
|
|
58
102
|
if (typeof value === 'string' && value.trim() !== '') title = value.trim();
|
|
@@ -72,6 +116,7 @@ async function readDocument(persistence, sessionId, header, signal) {
|
|
|
72
116
|
}
|
|
73
117
|
}
|
|
74
118
|
|
|
119
|
+
/** The excerpt around one hit plus the offset of that hit inside it. */
|
|
75
120
|
function snippetAround(text, index, length) {
|
|
76
121
|
const start = Math.max(0, index - CONTEXT_CHARS);
|
|
77
122
|
const end = Math.min(text.length, index + length + CONTEXT_CHARS);
|
|
@@ -80,12 +125,23 @@ function snippetAround(text, index, length) {
|
|
|
80
125
|
return `${prefix}${text.slice(start, end)}${suffix}`;
|
|
81
126
|
}
|
|
82
127
|
|
|
128
|
+
function previewAround(text, index, length) {
|
|
129
|
+
const start = Math.max(0, index - PREVIEW_CHARS);
|
|
130
|
+
const end = Math.min(text.length, index + length + PREVIEW_CHARS);
|
|
131
|
+
const prefix = start > 0 ? '…' : '';
|
|
132
|
+
const suffix = end < text.length ? '…' : '';
|
|
133
|
+
return {
|
|
134
|
+
text: `${prefix}${text.slice(start, end)}${suffix}`,
|
|
135
|
+
hit: index - start + prefix.length,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
83
139
|
/** One document's matches, capped per session. */
|
|
84
140
|
function matchDocument(document, needle, settings, budget) {
|
|
85
141
|
const matches = [];
|
|
86
142
|
if (settings.matchTitle === true && document.title !== '') {
|
|
87
143
|
if (document.title.toLowerCase().includes(needle)) {
|
|
88
|
-
matches.push({ kind: 'title', role: 'title', snippet: document.title, at: document.title.toLowerCase().indexOf(needle) });
|
|
144
|
+
matches.push({ kind: 'title', role: 'title', snippet: document.title, preview: document.title, previewHit: 0, at: document.title.toLowerCase().indexOf(needle), time: document.updatedAt });
|
|
89
145
|
budget.total += 1;
|
|
90
146
|
}
|
|
91
147
|
}
|
|
@@ -100,17 +156,24 @@ function matchDocument(document, needle, settings, budget) {
|
|
|
100
156
|
while (matches.length < MAX_MATCHES_PER_SESSION && budget.total < MAX_TOTAL_MATCHES) {
|
|
101
157
|
const at = haystack.indexOf(needle, from);
|
|
102
158
|
if (at < 0) break;
|
|
159
|
+
const preview = previewAround(segment.text, at, needle.length);
|
|
103
160
|
matches.push({
|
|
104
161
|
kind: 'body',
|
|
105
162
|
role: segment.role,
|
|
106
163
|
seq: segment.seq,
|
|
164
|
+
turn: segment.turn,
|
|
107
165
|
snippet: snippetAround(segment.text, at, needle.length),
|
|
166
|
+
preview: preview.text,
|
|
167
|
+
previewHit: preview.hit,
|
|
108
168
|
at,
|
|
169
|
+
time: segment.time,
|
|
109
170
|
});
|
|
110
171
|
budget.total += 1;
|
|
111
172
|
from = at + needle.length;
|
|
112
173
|
}
|
|
113
174
|
}
|
|
175
|
+
// Newest first inside one session; rows without a timestamp sink to the end.
|
|
176
|
+
matches.sort((left, right) => (Number(right.time) || 0) - (Number(left.time) || 0));
|
|
114
177
|
return matches;
|
|
115
178
|
}
|
|
116
179
|
|
|
@@ -165,7 +228,12 @@ export function createSearch(options) {
|
|
|
165
228
|
}
|
|
166
229
|
// Drop cache rows whose session log no longer exists.
|
|
167
230
|
for (const id of cache.keys()) if (!seen.has(id)) cache.delete(id);
|
|
168
|
-
|
|
231
|
+
// Newest hit first: a session with a fresh match outranks one whose file is newer.
|
|
232
|
+
const newestHit = (group) => (group.matches ?? []).reduce(
|
|
233
|
+
(max, match) => Math.max(max, Number(match.time) || 0),
|
|
234
|
+
0,
|
|
235
|
+
);
|
|
236
|
+
groups.sort((a, b) => newestHit(b) - newestHit(a) || b.updatedAt - a.updatedAt);
|
|
169
237
|
return {
|
|
170
238
|
groups,
|
|
171
239
|
scanned: snapshotList.length,
|
package/index.js
CHANGED
|
@@ -26,6 +26,7 @@ import path from 'node:path';
|
|
|
26
26
|
import { appendFile } from 'node:fs/promises';
|
|
27
27
|
import { createSearch } from './host/search.js';
|
|
28
28
|
import { restartApplication } from './host/restart.js';
|
|
29
|
+
import { pluginVersion } from './host/version.js';
|
|
29
30
|
import { inspectOverride, overwriteCloud, overwriteLocal } from './host/overwrite.js';
|
|
30
31
|
import { moveCandidates, moveSession, readAllEvents } from './host/move.js';
|
|
31
32
|
import { inspectSyncTarget, readSyncHistory, readSyncState, recordOverwrite, resolveSyncTarget, runSync } from './host/sync.js';
|
|
@@ -216,7 +217,7 @@ export function apply(ctx, config = {}) {
|
|
|
216
217
|
const record = await readEnvRecord(paths);
|
|
217
218
|
return {
|
|
218
219
|
appVersion: current.version,
|
|
219
|
-
pluginVersion:
|
|
220
|
+
pluginVersion: pluginVersion(),
|
|
220
221
|
lastAppVersion: record.lastAppVersion ?? null,
|
|
221
222
|
changed: current.version !== null && record.lastAppVersion !== undefined && record.lastAppVersion !== current.version,
|
|
222
223
|
};
|