dsh-session-ops 0.2.1 → 0.2.3
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/README.md +1 -0
- package/README.zh.md +1 -0
- package/docs/DETAIL.md +2 -1
- package/docs/DETAIL.zh.md +2 -1
- package/lib/admin.js +9 -4
- package/lib/client.js +80 -3
- package/lib/move.js +124 -0
- package/lib/types/move.d.ts +27 -0
- package/lib/types/store/registry.d.ts +11 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,6 +9,7 @@ One package, one host-plugin row, two halves:
|
|
|
9
9
|
| --- | --- | --- |
|
|
10
10
|
| delete | filter by ungrouped / temp / archive / subagent, batch select, per-session guards; removes data from disk | HTTP `/session-admin/api/*`, model tool `session_admin`, right-pane "会话管理" tab, conversation-header trash icon, settings page "会话工具" |
|
|
11
11
|
| move | relocate the log, rewrite `header.cwd`, follow workspace membership; optional memory follow (off by default) | HTTP `/session-move/api/*`, model tool `session_move`, right-pane "会话归位" tab, session context menu |
|
|
12
|
+
| workspace | register an **existing absolute directory** as a workspace (idempotent: an already-registered directory is returned unchanged); never moves a session | HTTP /session-move/api/workspaceCreate, model tool workspace_create, 新建工作区… in the right-pane 会话归位 tab |
|
|
12
13
|
|
|
13
14
|
The session-storage primitives live in this package under `lib/store/` (project-directory key
|
|
14
15
|
codec, `session[.vN].jsonl[.zstd]` frame read/write, workspace registry, `$DSH_HOME` and file
|
package/README.zh.md
CHANGED
|
@@ -8,6 +8,7 @@ DeepSeek Harness(DSH)的会话运维插件:真删除已持久化的会话
|
|
|
8
8
|
| --- | --- | --- |
|
|
9
9
|
| 删除 | 按未分组、临时或失效目录、归档、子代理筛选;批量选择;逐条守卫;真删磁盘数据 | HTTP `/session-admin/api/*`、模型工具 `session_admin`、右栏「会话管理」页签、会话标题栏垃圾桶、设置页「会话工具」 |
|
|
10
10
|
| 搬迁 | 搬日志、改写 header 的 `cwd`、跟随工作区成员表;可选项目记忆跟随(默认关) | HTTP `/session-move/api/*`、模型工具 `session_move`、右栏「会话归位」页签、会话右键菜单 |
|
|
11
|
+
| 建工作区 | 把一个**已存在的绝对目录**登记成工作区(已登记则原样返回);只登记,不动任何会话 | HTTP /session-move/api/workspaceCreate、模型工具 workspace_create、右栏「会话归位」页签的「新建工作区…」 |
|
|
11
12
|
|
|
12
13
|
会话存储原语收在本包的 `lib/store/`:项目目录键编解码、`session[.vN].jsonl[.zstd]` 帧读写、工作区注册表、`$DSH_HOME` 与文件日志、HTTP 底座。两个半边共用同一份实现。
|
|
13
14
|
|
package/docs/DETAIL.md
CHANGED
|
@@ -9,7 +9,8 @@ between workspaces while keeping the registry consistent.
|
|
|
9
9
|
|
|
10
10
|
## Other entry points
|
|
11
11
|
- Session context menu: move / delete.
|
|
12
|
-
-
|
|
12
|
+
- 新建工作区… in the Move tab: pick an existing directory, register it as a workspace and select it as the move target.
|
|
13
|
+
- Model tools session_admin, session_move, workspace_create; host HTTP /session-admin/api, /session-move/api (including workspaceCreate).
|
|
13
14
|
|
|
14
15
|
## Shared storage primitives
|
|
15
16
|
|
package/docs/DETAIL.zh.md
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
## 其他入口
|
|
11
11
|
|
|
12
12
|
- 会话右键菜单:移动会话到工作区…、删除会话…
|
|
13
|
-
-
|
|
13
|
+
- 「会话归位」页签的「新建工作区…」:选一个已存在的目录,登记成工作区并直接选为搬迁目标。
|
|
14
|
+
- 模型工具 session_admin、session_move、workspace_create;宿主 HTTP /session-admin/api、/session-move/api(含 workspaceCreate)。
|
|
14
15
|
|
|
15
16
|
## 共享存储原语
|
|
16
17
|
|
package/lib/admin.js
CHANGED
|
@@ -658,11 +658,11 @@ const TOOL_PARAMETERS = {
|
|
|
658
658
|
},
|
|
659
659
|
dryRun: {
|
|
660
660
|
type: 'boolean',
|
|
661
|
-
description: 'Report what would be deleted without touching anything.',
|
|
661
|
+
description: 'Report what would be deleted without touching anything. Takes precedence over confirm: when true, nothing is removed even if confirm is also true.',
|
|
662
662
|
},
|
|
663
663
|
confirm: {
|
|
664
664
|
type: 'boolean',
|
|
665
|
-
description: 'Must be true for action="delete" to actually remove data.',
|
|
665
|
+
description: 'Must be true for action="delete" to actually remove data (and dryRun must not be true).',
|
|
666
666
|
},
|
|
667
667
|
limit: {
|
|
668
668
|
type: 'integer',
|
|
@@ -737,6 +737,7 @@ function buildTool(admin, config, log, holds) {
|
|
|
737
737
|
'Always start with action="list" plus a scope to see exactly what is in range, then call action="delete" with the SAME scope and confirm=true. ' +
|
|
738
738
|
'Scope values: all (every persisted session), ungrouped (exactly the rows the sidebar shows under Ungrouped — no workspace, and neither archived nor a subagent child), temp (sessions whose working directory is gone or under the OS temp dir), archived, subagent, orphan (no session log left, only a stale cache entry). ' +
|
|
739
739
|
'Sessions that belong to a workspace, are currently open/running, are archived, or are subagent children are REFUSED unless you pass the matching include* flag; report those refusals to the user instead of retrying blindly. ' +
|
|
740
|
+
'Pass dryRun=true to preview exactly what would be removed — dryRun takes precedence over confirm and never deletes anything. ' +
|
|
740
741
|
'Deletion is irreversible — there is no undo and no trash.',
|
|
741
742
|
parameters: TOOL_PARAMETERS,
|
|
742
743
|
output: {
|
|
@@ -772,7 +773,11 @@ function buildTool(admin, config, log, holds) {
|
|
|
772
773
|
.join(' | ')}`,
|
|
773
774
|
};
|
|
774
775
|
}
|
|
775
|
-
|
|
776
|
+
// `dryRun` 的语义是「绝不落盘」,优先级高于 `confirm`:`confirm=true` 只是
|
|
777
|
+
// 「允许真删」的前置条件,不能反过来把 dryRun 盖掉。2026-11-07 修:此前只在
|
|
778
|
+
// confirm !== true 时才走预演,confirm=true 时 dryRun 被静默忽略、直接真删。
|
|
779
|
+
const dryRun = args.dryRun === true || args.confirm !== true;
|
|
780
|
+
if (dryRun) {
|
|
776
781
|
// 不真删:把它们当作一次预演,把「确认后会发生什么」原样回给模型。
|
|
777
782
|
const payload = {
|
|
778
783
|
scope,
|
|
@@ -793,7 +798,7 @@ function buildTool(admin, config, log, holds) {
|
|
|
793
798
|
matched: value.results.length,
|
|
794
799
|
reclaimedBytes: value.reclaimed,
|
|
795
800
|
rejections: rejections.map((r) => ({ id: r.id, reason: r.reason })),
|
|
796
|
-
summary: `DRY RUN — confirm is not true
|
|
801
|
+
summary: `DRY RUN — nothing was deleted (${args.dryRun === true ? 'dryRun=true' : 'confirm is not true'}). ${value.results.length} session(s) in range, ${value.reclaimed} bytes would be reclaimed. ${rejections.length} would be refused (${summarizeReasons(rejections)}). Re-issue with dryRun=false and confirm=true to proceed.`,
|
|
797
802
|
};
|
|
798
803
|
}
|
|
799
804
|
const value = await api.delete({
|
package/lib/client.js
CHANGED
|
@@ -1410,10 +1410,13 @@
|
|
|
1410
1410
|
* 拖放面板。
|
|
1411
1411
|
* @param React - 外壳预置的 React。
|
|
1412
1412
|
* @param api - Host API 客户端。
|
|
1413
|
+
* @param workspaceTools - `{ pickDirectory, createWorkspaceAt }`:内核目录选择器与
|
|
1414
|
+
* 工作区登记(客户端服务优先,回落 Host 路由)。
|
|
1413
1415
|
* @returns 面板组件。
|
|
1414
1416
|
*/
|
|
1415
|
-
function createPanel(React, api) {
|
|
1417
|
+
function createPanel(React, api, workspaceTools) {
|
|
1416
1418
|
const h = React.createElement;
|
|
1419
|
+
const { pickDirectory, createWorkspaceAt } = workspaceTools;
|
|
1417
1420
|
return function SessionMovePanel(props) {
|
|
1418
1421
|
const fill = props.fill === true;
|
|
1419
1422
|
const useSessions = props.useSessions;
|
|
@@ -1429,6 +1432,7 @@
|
|
|
1429
1432
|
const [hover, setHover] = React.useState('');
|
|
1430
1433
|
const [outcome, setOutcome] = React.useState(null);
|
|
1431
1434
|
const [token, setToken] = React.useState(0);
|
|
1435
|
+
const [creating, setCreating] = React.useState(false);
|
|
1432
1436
|
// 右键菜单的一次性交接:面板一直开着时靠订阅推过来;这次才挂载时,初始版本号
|
|
1433
1437
|
// 会让下面的 effect 在挂载后立刻把槽里的请求取走。
|
|
1434
1438
|
const [requestVersion, setRequestVersion] = React.useState(moveRequest.version);
|
|
@@ -1518,6 +1522,35 @@
|
|
|
1518
1522
|
(busy ? ' 处理中…' : '')));
|
|
1519
1523
|
if (failure !== null)
|
|
1520
1524
|
children.push(h('div', { key: 'fail', style: S.bad }, `读取失败:${failure}`));
|
|
1525
|
+
/**
|
|
1526
|
+
* 把一个已存在的目录登记成工作区,并直接选为搬迁目标。
|
|
1527
|
+
*
|
|
1528
|
+
* 目录由内核的原生选择器挑(`uiWorkspace.pickDirectory()`);登记优先走外壳自己的
|
|
1529
|
+
* 客户端服务 `ctx.workspaces.create({ path })`——与内核「添加工作区」同一个 remote
|
|
1530
|
+
* 方法,页面刷新即生效;外壳没提供这个服务时回落到 Host 的
|
|
1531
|
+
* `/session-move/api/workspaceCreate`(与模型工具 `workspace_create` 同一份实现)。
|
|
1532
|
+
*/
|
|
1533
|
+
const createWorkspace = () => {
|
|
1534
|
+
if (creating)
|
|
1535
|
+
return;
|
|
1536
|
+
setCreating(true);
|
|
1537
|
+
setOutcome(null);
|
|
1538
|
+
Promise.resolve()
|
|
1539
|
+
.then(() => pickDirectory())
|
|
1540
|
+
.then((path) => {
|
|
1541
|
+
if (typeof path !== 'string' || path.length === 0)
|
|
1542
|
+
return undefined;
|
|
1543
|
+
return createWorkspaceAt(path);
|
|
1544
|
+
})
|
|
1545
|
+
.then((workspace) => {
|
|
1546
|
+
if (workspace === undefined || workspace === null)
|
|
1547
|
+
return;
|
|
1548
|
+
setTargetPick(String(workspace.id));
|
|
1549
|
+
setToken((current) => current + 1);
|
|
1550
|
+
setOutcome({ ok: true, created: true, report: { workspace } });
|
|
1551
|
+
}, (error) => setOutcome({ ok: false, error: String(error?.message ?? error) }))
|
|
1552
|
+
.then(() => setCreating(false));
|
|
1553
|
+
};
|
|
1521
1554
|
children.push(h('div', { key: 'bar', style: S.bar }, [
|
|
1522
1555
|
h('input', {
|
|
1523
1556
|
key: 'q',
|
|
@@ -1528,6 +1561,14 @@
|
|
|
1528
1561
|
onChange: (event) => setFilter(event.target.value),
|
|
1529
1562
|
}),
|
|
1530
1563
|
h('button', { key: 'r', type: 'button', style: busy ? { ...S.button, ...S.disabled } : S.button, disabled: busy, onClick: () => setToken((current) => current + 1) }, '刷新'),
|
|
1564
|
+
h('button', {
|
|
1565
|
+
key: 'nw',
|
|
1566
|
+
type: 'button',
|
|
1567
|
+
style: creating ? { ...S.button, ...S.disabled } : S.button,
|
|
1568
|
+
disabled: creating,
|
|
1569
|
+
onClick: createWorkspace,
|
|
1570
|
+
title: '把一个已存在的目录登记成工作区,并选为搬迁目标',
|
|
1571
|
+
}, creating ? '新建中…' : '新建工作区…'),
|
|
1531
1572
|
]));
|
|
1532
1573
|
const sessionOptions = [h('option', { key: 'none', value: '' }, '(未选中)')];
|
|
1533
1574
|
for (const row of rows) {
|
|
@@ -1670,7 +1711,9 @@
|
|
|
1670
1711
|
const ok = outcome.ok === true;
|
|
1671
1712
|
children.push(h('div', { key: 'out', style: S.result }, [
|
|
1672
1713
|
h('div', { key: 's', style: ok ? S.good : S.bad }, ok
|
|
1673
|
-
?
|
|
1714
|
+
? (outcome.created === true
|
|
1715
|
+
? `✔ 已登记工作区「${outcome.report?.workspace?.title ?? ''}」`
|
|
1716
|
+
: `${outcome.dryRun === true ? '✔ 预演完成' : '✔ 已搬迁'}${outcome.report?.noop === true ? '(无需搬迁)' : ''}`)
|
|
1674
1717
|
: `✘ ${String(outcome.error)}`),
|
|
1675
1718
|
h('pre', { key: 'd', style: S.pre }, JSON.stringify(outcome.report ?? outcome, null, 2)),
|
|
1676
1719
|
]));
|
|
@@ -1691,7 +1734,41 @@
|
|
|
1691
1734
|
const React = require('react');
|
|
1692
1735
|
function apply(ctx) {
|
|
1693
1736
|
const api = createApi();
|
|
1694
|
-
|
|
1737
|
+
// 目录选择器(内核服务,可选注入):面板里「新建工作区…」用它挑目录。
|
|
1738
|
+
let uiWorkspaceService;
|
|
1739
|
+
ctx.inject(['uiWorkspace'], (injected) => {
|
|
1740
|
+
uiWorkspaceService = injected.get('uiWorkspace');
|
|
1741
|
+
return () => {
|
|
1742
|
+
uiWorkspaceService = undefined;
|
|
1743
|
+
};
|
|
1744
|
+
});
|
|
1745
|
+
const pickDirectory = async () => {
|
|
1746
|
+
const service = uiWorkspaceService;
|
|
1747
|
+
if (service === undefined || typeof service.pickDirectory !== 'function')
|
|
1748
|
+
throw new Error('当前外壳没有提供目录选择器(uiWorkspace.pickDirectory)');
|
|
1749
|
+
return await service.pickDirectory();
|
|
1750
|
+
};
|
|
1751
|
+
/**
|
|
1752
|
+
* 登记工作区:优先客户端服务(页面刷新即生效),回落 Host 路由。
|
|
1753
|
+
* 两条路都返回 `{ id, title, path }`。
|
|
1754
|
+
*/
|
|
1755
|
+
const createWorkspaceAt = async (path) => {
|
|
1756
|
+
const spaces = ctx.workspaces;
|
|
1757
|
+
if (spaces !== undefined && typeof spaces.create === 'function') {
|
|
1758
|
+
const workspace = await spaces.create({ path });
|
|
1759
|
+
return {
|
|
1760
|
+
id: String(workspace?.workspaceId ?? workspace?.id ?? ''),
|
|
1761
|
+
title: String(workspace?.title ?? ''),
|
|
1762
|
+
path: String(workspace?.path ?? path),
|
|
1763
|
+
};
|
|
1764
|
+
}
|
|
1765
|
+
const value = await api.call('workspaceCreate', { path });
|
|
1766
|
+
const workspace = value !== null && typeof value === 'object' ? value.workspace : undefined;
|
|
1767
|
+
if (workspace === undefined || workspace === null)
|
|
1768
|
+
throw new Error('Host 没有返回工作区记录');
|
|
1769
|
+
return workspace;
|
|
1770
|
+
};
|
|
1771
|
+
const Panel = createPanel(React, api, { pickDirectory, createWorkspaceAt });
|
|
1695
1772
|
// 右侧面板服务:右键菜单要借它把搬迁页签打开(与删除半边同一套可选注入)。
|
|
1696
1773
|
let sidebarRight;
|
|
1697
1774
|
ctx.inject(['sidebarRight'], (injected) => {
|
package/lib/move.js
CHANGED
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
*/
|
|
28
28
|
import { statSync } from 'node:fs';
|
|
29
29
|
import { realpath } from 'node:fs/promises';
|
|
30
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
30
31
|
import { createApiHandler, readJsonBody } from './store/http.js';
|
|
31
32
|
import { dshHome } from './store/host.js';
|
|
32
33
|
import { SESSION_RUNNING_STATUS, accountedSessionIds, agentSessionStatus, archivedSessionIds, findWorkspace, redirectSessionWriters, residentSessionIds, sessionWriteHandles, workspaceOwningSession, } from './store/registry.js';
|
|
@@ -526,6 +527,126 @@ function buildTool(mover, config, log) {
|
|
|
526
527
|
},
|
|
527
528
|
};
|
|
528
529
|
}
|
|
530
|
+
/**
|
|
531
|
+
* 工作区实体的对外投影。
|
|
532
|
+
* @param workspace - 注册表实体。
|
|
533
|
+
* @returns 纯数据行。
|
|
534
|
+
*/
|
|
535
|
+
function workspaceRow(workspace) {
|
|
536
|
+
return {
|
|
537
|
+
id: String(workspace.id),
|
|
538
|
+
title: String(workspace.title),
|
|
539
|
+
path: String(workspace.path),
|
|
540
|
+
sessions: Array.isArray(workspace.sessionIds) ? workspace.sessionIds.length : 0,
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* 把一个**已存在的绝对目录**登记成工作区;已经登记过时原样返回那条记录。
|
|
545
|
+
*
|
|
546
|
+
* 与内核 `workspace/create` remote 方法同一套语义(`resolveByPath` → `create`),
|
|
547
|
+
* 只是 Host 侧直接调注册表服务,不经过页面:于是模型工具与右栏面板的「新建工作区…」
|
|
548
|
+
* 共用这一份实现。
|
|
549
|
+
*
|
|
550
|
+
* 拒绝的输入(与内核一致):相对路径、盘符相对路径(`C:foo`)、不存在的路径、文件。
|
|
551
|
+
*
|
|
552
|
+
* @param ctx - Host 上下文(需要 `workspaceRegistry`)。
|
|
553
|
+
* @param payload - `{ path, title? }`。
|
|
554
|
+
* @returns `{ created, workspace }`。
|
|
555
|
+
*/
|
|
556
|
+
export async function createOrResolveWorkspace(ctx, payload) {
|
|
557
|
+
const registry = ctx.workspaceRegistry;
|
|
558
|
+
if (registry === undefined || typeof registry.create !== 'function') {
|
|
559
|
+
throw new Error('Host 没有提供 workspaceRegistry.create,无法新建工作区');
|
|
560
|
+
}
|
|
561
|
+
const raw = typeof payload?.path === 'string' ? payload.path.trim() : '';
|
|
562
|
+
if (raw.length === 0)
|
|
563
|
+
throw new Error('缺少目录路径(path)');
|
|
564
|
+
if (!isAbsolute(raw))
|
|
565
|
+
throw new Error(`不是绝对路径:${raw}`);
|
|
566
|
+
const absolute = resolve(raw);
|
|
567
|
+
let stats;
|
|
568
|
+
try {
|
|
569
|
+
stats = statSync(absolute);
|
|
570
|
+
}
|
|
571
|
+
catch {
|
|
572
|
+
throw new Error(`目录不存在:${absolute}`);
|
|
573
|
+
}
|
|
574
|
+
if (!stats.isDirectory())
|
|
575
|
+
throw new Error(`不是目录:${absolute}`);
|
|
576
|
+
if (typeof registry.resolveByPath === 'function') {
|
|
577
|
+
const existing = await registry.resolveByPath(absolute);
|
|
578
|
+
if (existing !== undefined && existing !== null) {
|
|
579
|
+
return { created: false, workspace: workspaceRow(existing) };
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
const title = typeof payload?.title === 'string' && payload.title.trim().length > 0
|
|
583
|
+
? payload.title.trim()
|
|
584
|
+
: undefined;
|
|
585
|
+
const workspace = title === undefined ? await registry.create(absolute) : await registry.create(absolute, title);
|
|
586
|
+
return { created: true, workspace: workspaceRow(workspace) };
|
|
587
|
+
}
|
|
588
|
+
/** `workspace_create` 的输入 schema(真 JSON Schema,同 `session_move`)。 */
|
|
589
|
+
const WORKSPACE_TOOL_PARAMETERS = {
|
|
590
|
+
type: 'object',
|
|
591
|
+
additionalProperties: true,
|
|
592
|
+
properties: {
|
|
593
|
+
path: { type: 'string', description: '要登记为工作区的绝对目录路径(必须已存在;相对路径、不存在的路径、文件都会被拒绝)。' },
|
|
594
|
+
title: { type: 'string', description: '可选显示名;省略时内核用目录名。' },
|
|
595
|
+
},
|
|
596
|
+
required: ['path'],
|
|
597
|
+
};
|
|
598
|
+
/** `workspace_create` 的输出 schema。 */
|
|
599
|
+
const WORKSPACE_TOOL_OUTPUT = {
|
|
600
|
+
type: 'object',
|
|
601
|
+
additionalProperties: true,
|
|
602
|
+
required: ['ok', 'summary'],
|
|
603
|
+
properties: {
|
|
604
|
+
ok: { type: 'boolean', description: '调用本身是否成功。' },
|
|
605
|
+
summary: { type: 'string', description: '一句话结论。' },
|
|
606
|
+
created: { type: 'boolean', description: 'true = 新建;false = 该目录已有工作区,原样返回。' },
|
|
607
|
+
workspace: { type: 'object', additionalProperties: true, description: '工作区行(id / title / path / sessions)。' },
|
|
608
|
+
},
|
|
609
|
+
};
|
|
610
|
+
/** `workspace_create` 的注册体。 */
|
|
611
|
+
function buildWorkspaceTool(ctx, log) {
|
|
612
|
+
return {
|
|
613
|
+
name: 'workspace_create',
|
|
614
|
+
description: 'Register (or idempotently resolve) a DSH workspace over an existing absolute directory. ' +
|
|
615
|
+
'A workspace is the sidebar group that owns sessions; creating one never moves or touches any session. ' +
|
|
616
|
+
'Use it when a directory should become a workspace (for example before session_move files sessions into it), ' +
|
|
617
|
+
'then call session_move with action="move" and targetWorkspace set to the returned id or path. ' +
|
|
618
|
+
'An absolute path is required; relative paths, drive-relative paths (C:foo), missing paths and files are refused.',
|
|
619
|
+
parameters: WORKSPACE_TOOL_PARAMETERS,
|
|
620
|
+
output: {
|
|
621
|
+
schema: WORKSPACE_TOOL_OUTPUT,
|
|
622
|
+
render: (_args, value) => [{ type: 'text', text: value.summary }],
|
|
623
|
+
},
|
|
624
|
+
presentCall: (args) => ({
|
|
625
|
+
card: 'generic',
|
|
626
|
+
title: 'Create workspace',
|
|
627
|
+
kind: 'other',
|
|
628
|
+
rawInput: { path: args.path, title: args.title },
|
|
629
|
+
}),
|
|
630
|
+
async execute(args) {
|
|
631
|
+
try {
|
|
632
|
+
const result = await createOrResolveWorkspace(ctx, args);
|
|
633
|
+
const workspace = result.workspace;
|
|
634
|
+
log('info', `workspace_create: ${result.created ? 'created' : 'resolved'} ${workspace.id} path=${workspace.path}`);
|
|
635
|
+
return {
|
|
636
|
+
ok: true,
|
|
637
|
+
created: result.created,
|
|
638
|
+
workspace,
|
|
639
|
+
summary: result.created
|
|
640
|
+
? `Created workspace "${workspace.title}" at ${workspace.path} (id ${workspace.id}).`
|
|
641
|
+
: `Workspace "${workspace.title}" already covers ${workspace.path} (id ${workspace.id}); nothing was created.`,
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
catch (error) {
|
|
645
|
+
return { ok: false, summary: `workspace_create failed: ${messageOf(error)}` };
|
|
646
|
+
}
|
|
647
|
+
},
|
|
648
|
+
};
|
|
649
|
+
}
|
|
529
650
|
/**
|
|
530
651
|
* 挂载搬迁半边:路由 + 工具。
|
|
531
652
|
*
|
|
@@ -558,6 +679,8 @@ export function mountMove(ctx, config, log) {
|
|
|
558
679
|
list: async () => mover.list(),
|
|
559
680
|
/** 搬一条会话。 */
|
|
560
681
|
move: async (payload) => mover.move(payload),
|
|
682
|
+
/** 登记一个工作区(已登记则原样返回),供面板在没有客户端服务时回落。 */
|
|
683
|
+
workspaceCreate: async (payload) => createOrResolveWorkspace(ctx, payload),
|
|
561
684
|
/** 用 DSH 自己的读取器读回一条会话。 */
|
|
562
685
|
verify: async (payload) => mover.verify(String(payload.sessionId ?? '')),
|
|
563
686
|
/** 能力/诊断。 */
|
|
@@ -593,6 +716,7 @@ export function mountMove(ctx, config, log) {
|
|
|
593
716
|
}),
|
|
594
717
|
}), 'dsh-session-move: api route');
|
|
595
718
|
ctx.effect(() => ctx.tools.register(buildTool(mover, config, log)), 'dsh-session-move: session_move tool');
|
|
719
|
+
ctx.effect(() => ctx.tools.register(buildWorkspaceTool(ctx, log)), 'dsh-session-move: workspace_create tool');
|
|
596
720
|
}
|
|
597
721
|
// ---------------------------------------------------------------------------
|
|
598
722
|
// fork 子会话成员自愈
|
package/lib/types/move.d.ts
CHANGED
|
@@ -198,6 +198,33 @@ export interface MoveContext {
|
|
|
198
198
|
};
|
|
199
199
|
effect: (fn: () => unknown, label?: string) => unknown;
|
|
200
200
|
}
|
|
201
|
+
/** 工作区行(面板与工具共用的纯数据投影)。 */
|
|
202
|
+
export interface WorkspaceRow {
|
|
203
|
+
id: string;
|
|
204
|
+
title: string;
|
|
205
|
+
path: string;
|
|
206
|
+
sessions: number;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* 把一个**已存在的绝对目录**登记成工作区;已经登记过时原样返回那条记录。
|
|
210
|
+
*
|
|
211
|
+
* 与内核 `workspace/create` remote 方法同一套语义(`resolveByPath` → `create`),
|
|
212
|
+
* 只是 Host 侧直接调注册表服务,不经过页面:于是模型工具与右栏面板的「新建工作区…」
|
|
213
|
+
* 共用这一份实现。
|
|
214
|
+
*
|
|
215
|
+
* 拒绝的输入(与内核一致):相对路径、盘符相对路径(`C:foo`)、不存在的路径、文件。
|
|
216
|
+
*
|
|
217
|
+
* @param ctx - Host 上下文(需要 `workspaceRegistry`)。
|
|
218
|
+
* @param payload - `{ path, title? }`。
|
|
219
|
+
* @returns `{ created, workspace }`。
|
|
220
|
+
*/
|
|
221
|
+
export declare function createOrResolveWorkspace(ctx: MoveContext, payload: {
|
|
222
|
+
path?: unknown;
|
|
223
|
+
title?: unknown;
|
|
224
|
+
} | undefined): Promise<{
|
|
225
|
+
created: boolean;
|
|
226
|
+
workspace: WorkspaceRow;
|
|
227
|
+
}>;
|
|
201
228
|
/**
|
|
202
229
|
* 挂载搬迁半边:路由 + 工具。
|
|
203
230
|
*
|
|
@@ -68,6 +68,17 @@ export interface WorkspaceRegistryLike {
|
|
|
68
68
|
headers?: Map<string, Record<string, unknown>> | undefined;
|
|
69
69
|
unarchiveSession(sessionId: string): Promise<unknown>;
|
|
70
70
|
unpinSession(sessionId: string): Promise<unknown>;
|
|
71
|
+
/**
|
|
72
|
+
* 把一个**已存在的绝对目录**登记成工作区;同路径重复调用返回既有实体且不改标题。
|
|
73
|
+
* 内核 `@deepseek-ai/dsh-workspace` 的 `WorkspaceRegistry.create`。可选:取值时
|
|
74
|
+
* `typeof === 'function'` 判断,缺这个能力时 `workspace_create` 直接报错而不是崩。
|
|
75
|
+
*/
|
|
76
|
+
create?: (path: string, title?: string) => Promise<WorkspaceEntity>;
|
|
77
|
+
/**
|
|
78
|
+
* 按规范化(`realpath`)路径解析已有工作区;目录存在但没登记时返回 `undefined`,
|
|
79
|
+
* 路径不存在时 reject。内核的 `WorkspaceRegistry.resolveByPath`。
|
|
80
|
+
*/
|
|
81
|
+
resolveByPath?: (path: string) => Promise<WorkspaceEntity | undefined>;
|
|
71
82
|
}
|
|
72
83
|
/** 持久化写入句柄(`persistence.tracker.writers` 的值)。 */
|
|
73
84
|
export interface SessionWriteHandle {
|