dsh-session-ops 0.2.9 → 0.2.10
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/cordis.patch.yml +1 -0
- package/lib/admin.js +15 -3
- package/lib/client.js +62 -13
- package/lib/engine.js +10 -1
- package/lib/move.js +48 -24
- package/lib/store/frames.js +26 -5
- package/lib/store/registry.js +9 -6
- package/lib/types/store/registry.d.ts +1 -0
- package/package.json +4 -5
package/cordis.patch.yml
CHANGED
package/lib/admin.js
CHANGED
|
@@ -526,6 +526,11 @@ export function isTrustedRequest(req, allowHosts = []) {
|
|
|
526
526
|
const authority = parseAuthority(rawHost);
|
|
527
527
|
if (authority === undefined)
|
|
528
528
|
return false;
|
|
529
|
+
const remote = req.socket?.remoteAddress;
|
|
530
|
+
if (typeof remote === 'string' && remote.length > 0) {
|
|
531
|
+
if (!isLoopback(remote) && !isAllowedAuthority(authority, allowHosts))
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
529
534
|
if (!isLoopback(authority.hostname) && !isAllowedAuthority(authority, allowHosts))
|
|
530
535
|
return false;
|
|
531
536
|
if (req.headers?.['sec-fetch-site'] === 'cross-site')
|
|
@@ -535,7 +540,7 @@ export function isTrustedRequest(req, allowHosts = []) {
|
|
|
535
540
|
return true;
|
|
536
541
|
try {
|
|
537
542
|
// 头可能是数组(重复头);`URL` 的入参本来就是字符串,这里按原语义做一次 ToString。
|
|
538
|
-
return new URL(String(origin)).
|
|
543
|
+
return new URL(String(origin)).host.toLowerCase() === authority.host.toLowerCase();
|
|
539
544
|
}
|
|
540
545
|
catch {
|
|
541
546
|
return false;
|
|
@@ -829,11 +834,10 @@ function buildApi(admin, config, log, holds, health) {
|
|
|
829
834
|
},
|
|
830
835
|
/** 删除:先按范围解析出目标集合,再逐条过守卫。 */
|
|
831
836
|
async delete(payload) {
|
|
832
|
-
const records = admin.scan();
|
|
833
837
|
const explicit = Array.isArray(payload?.sessionIds) ? payload.sessionIds : null;
|
|
834
838
|
const targets = explicit !== null
|
|
835
839
|
? explicit
|
|
836
|
-
: admin.select(
|
|
840
|
+
: admin.select(admin.scan(), payload).map((record) => record.id);
|
|
837
841
|
if (targets.length === 0)
|
|
838
842
|
return { removed: 0, reclaimed: 0, results: [], pruned: [] };
|
|
839
843
|
const result = await admin.remove(targets, {
|
|
@@ -1029,6 +1033,13 @@ function buildTool(admin, config, log, holds, health) {
|
|
|
1029
1033
|
.join(' | ')}`,
|
|
1030
1034
|
};
|
|
1031
1035
|
}
|
|
1036
|
+
if (args.action !== 'delete') {
|
|
1037
|
+
return {
|
|
1038
|
+
ok: false,
|
|
1039
|
+
error: `Unsupported action: ${String(args.action ?? '')}`,
|
|
1040
|
+
summary: `Unsupported action "${String(args.action ?? '')}". Expected "list" or "delete".`,
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1032
1043
|
// `dryRun` 的语义是「绝不落盘」,优先级高于 `confirm`:`confirm=true` 只是
|
|
1033
1044
|
// 「允许真删」的前置条件,不能反过来把 dryRun 盖掉。2026-11-07 修:此前只在
|
|
1034
1045
|
// confirm !== true 时才走预演,confirm=true 时 dryRun 被静默忽略、直接真删。
|
|
@@ -1044,6 +1055,7 @@ function buildTool(admin, config, log, holds, health) {
|
|
|
1044
1055
|
includeWorkspace: args.includeWorkspace === true,
|
|
1045
1056
|
includeArchived: args.includeArchived === true,
|
|
1046
1057
|
includeSubagent: args.includeSubagent === true,
|
|
1058
|
+
callerSessionId,
|
|
1047
1059
|
};
|
|
1048
1060
|
const value = await api.delete(payload);
|
|
1049
1061
|
const rejections = value.results.filter((r) => r.status === 'skipped');
|
package/lib/client.js
CHANGED
|
@@ -242,6 +242,8 @@
|
|
|
242
242
|
return;
|
|
243
243
|
if (typeof event.preventDefault === 'function')
|
|
244
244
|
event.preventDefault();
|
|
245
|
+
if (typeof event.stopPropagation === 'function')
|
|
246
|
+
event.stopPropagation();
|
|
245
247
|
finish(false);
|
|
246
248
|
}
|
|
247
249
|
dismiss.addEventListener('click', onDismiss);
|
|
@@ -256,8 +258,8 @@
|
|
|
256
258
|
card.appendChild(bar);
|
|
257
259
|
overlay.appendChild(card);
|
|
258
260
|
document.body.appendChild(overlay);
|
|
259
|
-
if (typeof
|
|
260
|
-
|
|
261
|
+
if (typeof dismiss.focus === 'function')
|
|
262
|
+
dismiss.focus();
|
|
261
263
|
});
|
|
262
264
|
}
|
|
263
265
|
/** 时间戳 → `MM-DD HH:mm`。 */
|
|
@@ -537,14 +539,18 @@
|
|
|
537
539
|
}, [sessionId]);
|
|
538
540
|
const entry = health.entryOf(sessionId);
|
|
539
541
|
const [openState, setOpenState] = React.useState({ kind: 'idle', message: '' });
|
|
542
|
+
React.useEffect(() => {
|
|
543
|
+
setOpenState({ kind: 'idle', message: '' });
|
|
544
|
+
}, [sessionId]);
|
|
540
545
|
// 失败/读取中只给「重试」;有数据时给「打开目录」——刷新按钮对只读面板没有意义。
|
|
541
546
|
const retryButton = h('button', { type: 'button', style: S.button, onClick: () => void health.refresh(sessionId) }, '重试');
|
|
542
547
|
const openButton = h('button', {
|
|
543
548
|
type: 'button',
|
|
544
549
|
style: S.button,
|
|
545
550
|
onClick: () => {
|
|
551
|
+
const targetId = sessionId;
|
|
546
552
|
setOpenState({ kind: 'opening', message: '' });
|
|
547
|
-
void health.openDir(
|
|
553
|
+
void health.openDir(targetId).then((result) => {
|
|
548
554
|
if (result?.ok === true)
|
|
549
555
|
setOpenState({ kind: 'opened', message: '已在文件管理器中打开' });
|
|
550
556
|
else
|
|
@@ -613,8 +619,13 @@
|
|
|
613
619
|
refresh,
|
|
614
620
|
start() {
|
|
615
621
|
void refresh();
|
|
616
|
-
if (state.timer === undefined)
|
|
617
|
-
state.timer = setInterval(() =>
|
|
622
|
+
if (state.timer === undefined) {
|
|
623
|
+
state.timer = setInterval(() => {
|
|
624
|
+
if (typeof document !== 'undefined' && document.hidden)
|
|
625
|
+
return;
|
|
626
|
+
void refresh();
|
|
627
|
+
}, 120_000);
|
|
628
|
+
}
|
|
618
629
|
},
|
|
619
630
|
stop() {
|
|
620
631
|
if (state.timer !== undefined) {
|
|
@@ -677,7 +688,9 @@
|
|
|
677
688
|
const [failure, setFailure] = React.useState(undefined);
|
|
678
689
|
const [result, setResult] = React.useState(undefined);
|
|
679
690
|
const [showAll, setShowAll] = React.useState(false);
|
|
691
|
+
const loadSeqRef = React.useRef(0);
|
|
680
692
|
const load = React.useCallback(async () => {
|
|
693
|
+
const seq = ++loadSeqRef.current;
|
|
681
694
|
setBusy(true);
|
|
682
695
|
setFailure(undefined);
|
|
683
696
|
try {
|
|
@@ -687,19 +700,31 @@
|
|
|
687
700
|
cwdPrefix: cwdPrefix === '' ? undefined : cwdPrefix,
|
|
688
701
|
limit: 2000,
|
|
689
702
|
});
|
|
703
|
+
if (seq !== loadSeqRef.current)
|
|
704
|
+
return;
|
|
690
705
|
setData(value);
|
|
691
706
|
setSelected(new Set());
|
|
692
707
|
}
|
|
693
708
|
catch (error) {
|
|
709
|
+
if (seq !== loadSeqRef.current)
|
|
710
|
+
return;
|
|
694
711
|
setFailure(String(error?.message ?? error));
|
|
695
712
|
}
|
|
696
713
|
finally {
|
|
697
|
-
|
|
714
|
+
if (seq === loadSeqRef.current)
|
|
715
|
+
setBusy(false);
|
|
698
716
|
}
|
|
699
717
|
}, [scope, search, cwdPrefix]);
|
|
718
|
+
const firstLoadRef = React.useRef(true);
|
|
700
719
|
React.useEffect(() => {
|
|
701
|
-
|
|
702
|
-
|
|
720
|
+
if (firstLoadRef.current) {
|
|
721
|
+
firstLoadRef.current = false;
|
|
722
|
+
void load();
|
|
723
|
+
return undefined;
|
|
724
|
+
}
|
|
725
|
+
const timer = setTimeout(() => void load(), search === '' ? 0 : 250);
|
|
726
|
+
return () => clearTimeout(timer);
|
|
727
|
+
}, [load, search]);
|
|
703
728
|
const rows = data?.sessions ?? [];
|
|
704
729
|
const visible = showAll ? rows : rows.slice(0, 200);
|
|
705
730
|
function toggle(id) {
|
|
@@ -1220,8 +1245,16 @@
|
|
|
1220
1245
|
// 注册项的 `inject` 把共享表单的 `{ state, mutate }` 作为 `form` 传进来;命名空间
|
|
1221
1246
|
// 不是「Host 在服务的设置命名空间」时快照是 undefined(见 dsh-client-ui-settings
|
|
1222
1247
|
// 的 ConfigFormController 与 dsh-client-ui-plugin-manager 的 formFor)。
|
|
1248
|
+
const [, setRevisionTick] = React.useState(0);
|
|
1223
1249
|
const form = props.form;
|
|
1224
|
-
|
|
1250
|
+
React.useEffect(() => {
|
|
1251
|
+
if (typeof form?.subscribe !== 'function')
|
|
1252
|
+
return undefined;
|
|
1253
|
+
return form.subscribe(() => setRevisionTick((n) => n + 1));
|
|
1254
|
+
}, [form]);
|
|
1255
|
+
const snapshot = form !== undefined && form !== null
|
|
1256
|
+
? (typeof form.getState === 'function' ? form.getState() : form.state)
|
|
1257
|
+
: undefined;
|
|
1225
1258
|
const writable = snapshot !== undefined && snapshot.writable !== false;
|
|
1226
1259
|
if (props.view === 'summary')
|
|
1227
1260
|
return h('span', null, SUMMARY);
|
|
@@ -1394,7 +1427,9 @@
|
|
|
1394
1427
|
// 因为要等一次请求才知道开关,所以注册是异步的;请求失败时按「不渲染」处理
|
|
1395
1428
|
// (安全的那一侧),而不是把按钮露出来。
|
|
1396
1429
|
let headerButtonDispose;
|
|
1430
|
+
let headerButtonDisposed = false;
|
|
1397
1431
|
ctx.effect(() => () => {
|
|
1432
|
+
headerButtonDisposed = true;
|
|
1398
1433
|
try {
|
|
1399
1434
|
headerButtonDispose?.();
|
|
1400
1435
|
}
|
|
@@ -1405,7 +1440,7 @@
|
|
|
1405
1440
|
void api
|
|
1406
1441
|
.call('config', {})
|
|
1407
1442
|
.then((config) => {
|
|
1408
|
-
if (config?.headerDeleteButton !== true)
|
|
1443
|
+
if (headerButtonDisposed || config?.headerDeleteButton !== true)
|
|
1409
1444
|
return;
|
|
1410
1445
|
headerButtonDispose = ctx.slots.inject('conversation.session.header.utilities', () => ctx.slots.register({
|
|
1411
1446
|
name: 'conversation.session.header.utilities',
|
|
@@ -1553,6 +1588,10 @@
|
|
|
1553
1588
|
inject: () => ({
|
|
1554
1589
|
form: {
|
|
1555
1590
|
state: configForm.getSnapshot(),
|
|
1591
|
+
getState: () => configForm.getSnapshot(),
|
|
1592
|
+
subscribe: typeof configForm.subscribe === 'function'
|
|
1593
|
+
? (listener) => configForm.subscribe(listener)
|
|
1594
|
+
: undefined,
|
|
1556
1595
|
mutate: (ops, revision) => configForm.mutate(ops, revision),
|
|
1557
1596
|
},
|
|
1558
1597
|
}),
|
|
@@ -1886,13 +1925,23 @@
|
|
|
1886
1925
|
* 工作区登记(客户端服务优先,回落 Host 路由)。
|
|
1887
1926
|
* @returns 面板组件。
|
|
1888
1927
|
*/
|
|
1889
|
-
function createPanel(React, api, workspaceTools) {
|
|
1928
|
+
function createPanel(React, api, workspaceTools, sessionsList) {
|
|
1890
1929
|
const h = React.createElement;
|
|
1891
1930
|
const { pickDirectory, createWorkspaceAt } = workspaceTools;
|
|
1892
1931
|
return function SessionMovePanel(props) {
|
|
1893
1932
|
const fill = props.fill === true;
|
|
1894
1933
|
const useSessions = props.useSessions;
|
|
1895
|
-
const
|
|
1934
|
+
const storeFromHook = typeof useSessions === 'function' ? useSessions((snapshot) => snapshot) : undefined;
|
|
1935
|
+
const [fallbackStore, setFallbackStore] = React.useState(() => typeof useSessions !== 'function' && typeof sessionsList?.getSnapshot === 'function'
|
|
1936
|
+
? sessionsList.getSnapshot()
|
|
1937
|
+
: undefined);
|
|
1938
|
+
React.useEffect(() => {
|
|
1939
|
+
if (typeof useSessions === 'function' || typeof sessionsList?.subscribe !== 'function')
|
|
1940
|
+
return undefined;
|
|
1941
|
+
setFallbackStore(sessionsList.getSnapshot?.());
|
|
1942
|
+
return sessionsList.subscribe(() => setFallbackStore(sessionsList.getSnapshot?.()));
|
|
1943
|
+
}, [useSessions]);
|
|
1944
|
+
const store = storeFromHook ?? fallbackStore;
|
|
1896
1945
|
const byId = store !== undefined && store !== null ? store.byId : undefined;
|
|
1897
1946
|
const [snapshot, setSnapshot] = React.useState(null);
|
|
1898
1947
|
const [failure, setFailure] = React.useState(null);
|
|
@@ -2240,7 +2289,7 @@
|
|
|
2240
2289
|
throw new Error('Host 没有返回工作区记录');
|
|
2241
2290
|
return workspace;
|
|
2242
2291
|
};
|
|
2243
|
-
const Panel = createPanel(React, api, { pickDirectory, createWorkspaceAt });
|
|
2292
|
+
const Panel = createPanel(React, api, { pickDirectory, createWorkspaceAt }, ctx.sessions?.list);
|
|
2244
2293
|
// 右侧面板服务:右键菜单要借它把搬迁页签打开(与删除半边同一套可选注入)。
|
|
2245
2294
|
let sidebarRight;
|
|
2246
2295
|
ctx.inject(['sidebarRight'], (injected) => {
|
package/lib/engine.js
CHANGED
|
@@ -154,7 +154,16 @@ export function applyPlan(plan) {
|
|
|
154
154
|
const parkedPath = plan.sourcePath + PARKED_SUFFIX;
|
|
155
155
|
writeDurable(tmpPath, plan.buffer);
|
|
156
156
|
renameSync(plan.sourcePath, parkedPath);
|
|
157
|
-
|
|
157
|
+
try {
|
|
158
|
+
renameSync(tmpPath, plan.targetPath);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
try {
|
|
162
|
+
renameSync(parkedPath, plan.sourcePath);
|
|
163
|
+
}
|
|
164
|
+
catch { }
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
158
167
|
rmSync(parkedPath, { force: true });
|
|
159
168
|
// 0.2.2 起每个会话目录里有 `session.lock`(POSIX flock,写入句柄整个生命周期持有;
|
|
160
169
|
// 内核约定这个文件永不删除、靠稳定 inode 判断归属)。搬迁必须把它一起搬过去:
|
package/lib/move.js
CHANGED
|
@@ -86,16 +86,15 @@ export function isTrustedRequest(req, allowHosts) {
|
|
|
86
86
|
const host = String(req.headers?.host ?? '');
|
|
87
87
|
if (!fromLoopback && !(Array.isArray(allowHosts) && allowHosts.includes(host)))
|
|
88
88
|
return false;
|
|
89
|
-
// 3) 带了 Origin 就必须与请求的 authority
|
|
89
|
+
// 3) 带了 Origin 就必须与请求的 authority 同源(包含端口)。
|
|
90
90
|
const origin = req?.headers?.origin;
|
|
91
91
|
if (origin === undefined)
|
|
92
92
|
return true;
|
|
93
|
-
|
|
94
|
-
if (hostname === undefined)
|
|
93
|
+
if (host.length === 0)
|
|
95
94
|
return false;
|
|
96
95
|
try {
|
|
97
96
|
// 头可能是数组(重复头);`URL` 的入参本来就是字符串,这里按原语义做一次 ToString。
|
|
98
|
-
return new URL(String(origin)).
|
|
97
|
+
return new URL(String(origin)).host.toLowerCase() === host.toLowerCase();
|
|
99
98
|
}
|
|
100
99
|
catch {
|
|
101
100
|
return false;
|
|
@@ -106,7 +105,6 @@ function createMover(ctx, config, log) {
|
|
|
106
105
|
const persistence = ctx.sessionPersistence;
|
|
107
106
|
const registry = ctx.workspaceRegistry;
|
|
108
107
|
const sessionStore = ctx.get('sessions');
|
|
109
|
-
const agents = ctx.get('agents');
|
|
110
108
|
const rootOf = () => {
|
|
111
109
|
if (typeof config.root === 'string' && config.root.length > 0)
|
|
112
110
|
return config.root;
|
|
@@ -119,7 +117,7 @@ function createMover(ctx, config, log) {
|
|
|
119
117
|
// 下面这几个查询都来自 `lib/store/registry.js`(与删除半边共用一份):
|
|
120
118
|
// 服务挂在哪、id 怎么比、状态叫什么,规则只写在一个地方。
|
|
121
119
|
const residentIds = () => residentSessionIds(sessionStore);
|
|
122
|
-
const runningOf = (id) => agentSessionStatus(agents, id);
|
|
120
|
+
const runningOf = (id) => agentSessionStatus(ctx.get('agents'), id);
|
|
123
121
|
const writersOf = () => sessionWriteHandles(persistence);
|
|
124
122
|
const ownerOf = (sessionId) => workspaceOwningSession(registry.list(), sessionId);
|
|
125
123
|
const resolveWorkspace = (key) => findWorkspace(registry.list(), key);
|
|
@@ -334,25 +332,40 @@ function createMover(ctx, config, log) {
|
|
|
334
332
|
report.dryRunOnly = true;
|
|
335
333
|
return report;
|
|
336
334
|
}
|
|
337
|
-
// 1)
|
|
335
|
+
// 1) 落盘前先 flush 活跃写入句柄,免得 applyPlan 删掉源目录后 flush 撞上 ENOENT。
|
|
336
|
+
const writers = writersOf();
|
|
337
|
+
const preHandle = writers?.get(sessionId);
|
|
338
|
+
let preFlushError;
|
|
339
|
+
if (preHandle !== undefined && preHandle !== null && typeof preHandle.flush === 'function') {
|
|
340
|
+
try {
|
|
341
|
+
await preHandle.flush();
|
|
342
|
+
}
|
|
343
|
+
catch (error) {
|
|
344
|
+
preFlushError = messageOf(error);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
// 2) 落盘:日志搬家 + header cwd 改写。
|
|
338
348
|
const storage = applyPlan(plan);
|
|
339
349
|
report.storage = storage;
|
|
340
350
|
if (storage.ok !== true) {
|
|
341
351
|
throw new Error(`the log was moved to ${plan.targetPath} but the rewritten header did not verify: ${JSON.stringify(storage.verifiedHeader)}`);
|
|
342
352
|
}
|
|
343
|
-
//
|
|
353
|
+
// 3) 内存态:让"以后继续写"落到新位置。
|
|
344
354
|
// 写入句柄每次 append 都从自己的 header 重新推 logPath(appendLines → logPath(meta.cwd)),
|
|
345
355
|
// 所以改写 handle.header 就够了;会话对象自身的 header 也同步,供工具解析 cwd;
|
|
346
356
|
// 注册表里的头部缓存也要一起改。三处都在 `lib/store/registry.js`。
|
|
347
357
|
const redirect = await redirectSessionWriters({
|
|
348
|
-
writers
|
|
358
|
+
writers,
|
|
349
359
|
sessions: sessionStore,
|
|
350
360
|
registry,
|
|
351
361
|
sessionId,
|
|
352
362
|
cwd: targetPath,
|
|
363
|
+
skipFlush: true,
|
|
353
364
|
});
|
|
354
365
|
const live = redirect.liveSession;
|
|
355
|
-
if (
|
|
366
|
+
if (preFlushError !== undefined)
|
|
367
|
+
report.handleFlushError = preFlushError;
|
|
368
|
+
else if (redirect.flushError !== undefined)
|
|
356
369
|
report.handleFlushError = redirect.flushError;
|
|
357
370
|
if (redirect.writeHandleRedirected)
|
|
358
371
|
report.writeHandleRedirected = true;
|
|
@@ -904,23 +917,34 @@ export async function sweepForkChildrenOnBoot(ctx, config = {}, log = () => { },
|
|
|
904
917
|
report.skipped = 'listing-failed';
|
|
905
918
|
return report;
|
|
906
919
|
}
|
|
907
|
-
|
|
920
|
+
const forkSnapshots = (Array.isArray(snapshots) ? snapshots : []).filter((snapshot) => {
|
|
908
921
|
const header = snapshot?.header;
|
|
909
922
|
const sessionId = String(header?.id ?? snapshot?.id ?? '');
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
+
return sessionId.length > 0 && isForkChild(header);
|
|
924
|
+
});
|
|
925
|
+
report.checked = forkSnapshots.length;
|
|
926
|
+
const failed = new Set();
|
|
927
|
+
for (let pass = 0; pass < 5; pass += 1) {
|
|
928
|
+
let progress = false;
|
|
929
|
+
for (const snapshot of forkSnapshots) {
|
|
930
|
+
const header = snapshot?.header;
|
|
931
|
+
const sessionId = String(header?.id ?? snapshot?.id ?? '');
|
|
932
|
+
if (failed.has(sessionId) || repairer.ownerOf(sessionId) !== undefined)
|
|
933
|
+
continue;
|
|
934
|
+
try {
|
|
935
|
+
await repairer.repair(sessionId, header, 'boot-sweep');
|
|
936
|
+
if (repairer.ownerOf(sessionId) !== undefined) {
|
|
937
|
+
report.attached += 1;
|
|
938
|
+
progress = true;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
catch (error) {
|
|
942
|
+
failed.add(sessionId);
|
|
943
|
+
log('warn', `membership sweep: ${sessionId} failed: ${messageOf(error)}`);
|
|
944
|
+
}
|
|
923
945
|
}
|
|
946
|
+
if (!progress)
|
|
947
|
+
break;
|
|
924
948
|
}
|
|
925
949
|
if (report.attached > 0)
|
|
926
950
|
log('info', `membership sweep: re-attached ${report.attached} of ${report.checked} fork child(ren) that had lost workspace accounting`);
|
package/lib/store/frames.js
CHANGED
|
@@ -176,11 +176,27 @@ export function readSessionHeader(dir, cache = new Map()) {
|
|
|
176
176
|
let header;
|
|
177
177
|
try {
|
|
178
178
|
const raw = readFileSync(path);
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
179
|
+
let text;
|
|
180
|
+
if (log.name.endsWith('.zstd')) {
|
|
181
|
+
if (zstdDecompress !== undefined) {
|
|
182
|
+
const scan = scanZstdFrames(raw);
|
|
183
|
+
if (scan.frames.length > 0) {
|
|
184
|
+
try {
|
|
185
|
+
const first = scan.frames[0];
|
|
186
|
+
text = zstdDecompress(raw.subarray(first.start, first.end)).toString('utf8');
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
text = undefined;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (text === undefined) {
|
|
193
|
+
text = zstdDecompress(raw).toString('utf8');
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
text = raw.toString('utf8');
|
|
199
|
+
}
|
|
184
200
|
if (text !== undefined) {
|
|
185
201
|
const end = text.indexOf('\n');
|
|
186
202
|
header = JSON.parse(end === -1 ? text : text.slice(0, end));
|
|
@@ -189,6 +205,11 @@ export function readSessionHeader(dir, cache = new Map()) {
|
|
|
189
205
|
catch {
|
|
190
206
|
header = undefined;
|
|
191
207
|
}
|
|
208
|
+
if (cache.size >= 2000) {
|
|
209
|
+
const oldest = cache.keys().next().value;
|
|
210
|
+
if (oldest !== undefined)
|
|
211
|
+
cache.delete(oldest);
|
|
212
|
+
}
|
|
192
213
|
cache.set(key, header);
|
|
193
214
|
return header;
|
|
194
215
|
}
|
package/lib/store/registry.js
CHANGED
|
@@ -159,7 +159,8 @@ export function findWorkspace(workspaces, key) {
|
|
|
159
159
|
export async function releaseSessionEverywhere(registry, sessionId) {
|
|
160
160
|
const detached = [];
|
|
161
161
|
for (const workspace of registry.list()) {
|
|
162
|
-
|
|
162
|
+
const ids = accountedSessionIds(workspace) ?? workspace.sessionIds;
|
|
163
|
+
if (!ids.includes(sessionId))
|
|
163
164
|
continue;
|
|
164
165
|
await workspace.detachSession(sessionId);
|
|
165
166
|
detached.push(String(workspace.id));
|
|
@@ -208,11 +209,13 @@ export async function redirectSessionWriters(options) {
|
|
|
208
209
|
};
|
|
209
210
|
const handle = writers === undefined ? undefined : writers.get(sessionId);
|
|
210
211
|
if (handle !== undefined && handle !== null && typeof handle.header === 'object') {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
212
|
+
if (options.skipFlush !== true && typeof handle.flush === 'function') {
|
|
213
|
+
try {
|
|
214
|
+
await handle.flush();
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
outcome.flushError = messageOf(error);
|
|
218
|
+
}
|
|
216
219
|
}
|
|
217
220
|
handle.header = { ...handle.header, cwd };
|
|
218
221
|
outcome.writeHandleRedirected = true;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-ops",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"description": "Session operations for DeepSeek Harness: really delete persisted sessions (ungrouped/temp/archive/subagent filters, running-session guards) and move sessions between workspaces (log relocation, header.cwd rewrite, workspace registry follow). Ships the shared session-store primitives (project-directory keys, jsonl.zstd frames, workspace registry, host/HTTP plumbing) as lib/store. One host entry with two HTTP prefixes and
|
|
8
|
+
"description": "Session operations for DeepSeek Harness: really delete persisted sessions (ungrouped/temp/archive/subagent filters, running-session guards) and move sessions between workspaces (log relocation, header.cwd rewrite, workspace registry follow). Ships the shared session-store primitives (project-directory keys, jsonl.zstd frames, workspace registry, host/HTTP plumbing) as lib/store. One host entry with two HTTP prefixes and three model tools, one browser bundle with two right-pane tabs and a merged config card.",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"dsh",
|
|
11
11
|
"dsh-plugin",
|
|
@@ -34,6 +34,8 @@
|
|
|
34
34
|
"types": "./lib/types/store/index.d.ts",
|
|
35
35
|
"default": "./lib/store/index.js"
|
|
36
36
|
},
|
|
37
|
+
"./locale/*.json": "./locale/*.json",
|
|
38
|
+
"./icon": "./icon.svg",
|
|
37
39
|
"./package.json": "./package.json"
|
|
38
40
|
},
|
|
39
41
|
"files": [
|
|
@@ -56,9 +58,6 @@
|
|
|
56
58
|
"node": ">=24",
|
|
57
59
|
"dsh": "^0.2.1-rc.2 || ^0.2.2-alpha.2 || ^0.2.3-alpha.1"
|
|
58
60
|
},
|
|
59
|
-
"dependencies": {
|
|
60
|
-
"@deepseek-ai/schemastery": "^3.18.5 || ^3.18.6-alpha.1"
|
|
61
|
-
},
|
|
62
61
|
"peerDependencies": {
|
|
63
62
|
"@deepseek-ai/schemastery": "^3.18.5 || ^3.18.6-alpha.1"
|
|
64
63
|
},
|