dsh-lmw-plugin 0.0.0-stage → 1.0.2
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/LICENSE +21 -0
- package/README.md +36 -2
- package/client.js +1806 -0
- package/cordis.patch.yml +5 -0
- package/icon.svg +5 -0
- package/index.js +1215 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +54 -4
- package/src/scan.js +153 -0
package/locale/en.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "LMW-DSH basics",
|
|
4
|
+
"description": "Adds the basic session-assignment and workspace-information features DSH lacks. The \"Check session assignment\" button at the bottom of the left sidebar runs the session check only. \"Import sessions\" copies DSH sessions from another directory: it validates the session format, compares each one with the local corpus (new sessions are addable; identical sessions are replaceable when the source file is larger or newer, with a yellow warning when only one holds), replaces identical sessions in place after a backup (the session must be closed and its id/cwd must match), and assigns workspaces plus warms titles for new sessions. Starting DSH runs the full check automatically: the dialog has two clearly separated panels, \"Session assignment\" and \"Skills directory\"; a missing skills directory is offered as a checkbox and an existing one shows its path with a green check. \"Confirm and run\" asks confirm/cancel and then executes every checked item at once. Each workspace name also gets a wrapping subtitle with its full directory path. Reads session headers and the workspace registry only; writes workspace records, session attachment, $DSH_HOME/skills only after confirmation, and imported session files only after confirmation; never edits existing session logs. Sessions whose recorded directory no longer exists cannot be assigned; sessions without a cwd and subagent sessions are skipped; archived sessions are listed with a badge; new workspaces land at the top of the sidebar order. Set config { autoOpenOnStartup: false } to stop the automatic dialog; warmTitleCache and importMaxFiles are configurable too. The path subtitle decorates the shipped workspace row; if a future DSH release changes that markup the subtitle silently stops and nothing else is affected."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/zh.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "LMW-DSH基础功能",
|
|
4
|
+
"description": "给 DSH 补齐会话分配与工作区信息的基础功能。左栏底部「会话分配检查」按钮只做会话检查:列出没有工作区的会话、按会话目录分组、目录与单个会话都可勾选(默认全选),确认后按 DSH 自身方式创建或复用工作区并挂载会话,不检查 skill 目录。左栏「导入会话」可把其它目录中的 DSH 会话复制进来:先校验会话格式,再与本机现有会话逐个对比——新会话直接列为可添加,相同会话按「文件更大或修改时间更新」判断为可替换,只满足其一时给出黄色警告;确认后相同会话直接替换(需未打开且 id/cwd 一致,自动备份),新会话自动分配工作区并预热标题。开启 DSH 时自动运行完整检查:弹窗分成「会话分配」和「Skill 目录」两个明确分区,Skill 目录缺失时以勾选方式询问是否创建(默认勾选),已存在时显示路径与绿色对号;右下角「确认执行」会先弹出确认/取消,确认后一次性执行所有勾选项。每个工作区名下方还会显示一行可自动换行的完整目录路径。只读取会话头与工作区注册表;写入范围仅限工作区记录、会话挂载、经你确认后创建 $DSH_HOME/skills,以及经你确认后导入的会话文件;不改动已有会话日志。会话记录的目录已不存在时无法分配(DSH 会校验路径),没有 cwd 的会话、子代理会话会被跳过,已归档会话带标记列出,新建工作区按 DSH 默认行为出现在侧栏顶部。在 patch 里设置 config { autoOpenOnStartup: false } 可关闭启动自动弹窗;warmTitleCache、importMaxFiles 等也可配置。工作区路径副标题是在官方行结构上做的装饰;将来 DSH 改版若改变该结构,副标题会静默失效,其余功能不受影响。"
|
|
5
|
+
}
|
|
6
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-lmw-plugin",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Session assignment, session import, and workspace path subtitles for DeepSeek Harness",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "李默闻 (Li Mowen)",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"dsh",
|
|
10
|
+
"deepseek-harness",
|
|
11
|
+
"plugin",
|
|
12
|
+
"sessions",
|
|
13
|
+
"workspaces",
|
|
14
|
+
"session-import"
|
|
15
|
+
],
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/Bemo12/dsh-lmw-plugin.git"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/Bemo12/dsh-lmw-plugin#readme",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/Bemo12/dsh-lmw-plugin/issues"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"dsh": ">=0.2.2-rc.5 <0.3.0"
|
|
26
|
+
},
|
|
27
|
+
"exports": {
|
|
28
|
+
".": "./index.js",
|
|
29
|
+
"./client": "./client.js",
|
|
30
|
+
"./locale/*.json": "./locale/*.json",
|
|
31
|
+
"./icon": "./icon.svg"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"index.js",
|
|
35
|
+
"src",
|
|
36
|
+
"client.js",
|
|
37
|
+
"cordis.patch.yml",
|
|
38
|
+
"locale/*.json",
|
|
39
|
+
"README.md",
|
|
40
|
+
"icon.svg"
|
|
41
|
+
],
|
|
42
|
+
"dsh": {
|
|
43
|
+
"bundle": {
|
|
44
|
+
"patch": "./cordis.patch.yml"
|
|
45
|
+
},
|
|
46
|
+
"client": {
|
|
47
|
+
"platform": "web",
|
|
48
|
+
"immediately": true,
|
|
49
|
+
"inject": [
|
|
50
|
+
"@deepseek-ai/dsh-api-workspace-controller",
|
|
51
|
+
"@deepseek-ai/dsh-client-ui-sidebar",
|
|
52
|
+
"@deepseek-ai/dsh-client-ui-layout"
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/scan.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure scan and assignment planning for the lmw-plugin bundle.
|
|
3
|
+
*
|
|
4
|
+
* Nothing in this module touches Node APIs, the Cordis Context, or the
|
|
5
|
+
* filesystem, so the Host half and the unit test share one implementation of
|
|
6
|
+
* "which stored Sessions are unassigned" and "which cwd owns each selection".
|
|
7
|
+
*
|
|
8
|
+
* @module @local/lmw-plugin/src/scan
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Default eligibility options for a scan. */
|
|
12
|
+
export const SCAN_DEFAULTS = Object.freeze({
|
|
13
|
+
includeSubagentSessions: false,
|
|
14
|
+
titleLimit: 200,
|
|
15
|
+
maxSessions: 2000,
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Collect every Session id already accounted for by a Workspace projection.
|
|
20
|
+
* @param {readonly { sessionIds?: readonly string[] }[]} workspaces - registry rows.
|
|
21
|
+
* @returns {Set<string>} assigned Session ids.
|
|
22
|
+
*/
|
|
23
|
+
export function assignedSessionIds(workspaces) {
|
|
24
|
+
const assigned = new Set()
|
|
25
|
+
for (const workspace of workspaces ?? []) {
|
|
26
|
+
const ids = workspace?.sessionIds
|
|
27
|
+
if (!ids) continue
|
|
28
|
+
for (const id of ids) assigned.add(String(id))
|
|
29
|
+
}
|
|
30
|
+
return assigned
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Group unassigned stored Sessions by their recorded cwd.
|
|
35
|
+
*
|
|
36
|
+
* A record qualifies when its header carries a `cwd`, the id is not accounted
|
|
37
|
+
* for by a Workspace, the Session is not a subagent child, and its stored log
|
|
38
|
+
* is readable in the current format.
|
|
39
|
+
*
|
|
40
|
+
* @param {readonly { header?: Record<string, unknown>, formatStatus?: string }[]} records - `sessionQuery.listSessions()` rows.
|
|
41
|
+
* @param {ReadonlySet<string>} assigned - ids owned by some Workspace.
|
|
42
|
+
* @param {{ includeSubagentSessions?: boolean }} [options] - eligibility switches.
|
|
43
|
+
* @returns {{
|
|
44
|
+
* groups: { cwd: string, sessions: { id: string, title: string, createdAt: number, origin: string }[] }[],
|
|
45
|
+
* total: number,
|
|
46
|
+
* unassignable: { noCwd: number, subagent: number, legacyFormat: number },
|
|
47
|
+
* }}
|
|
48
|
+
*/
|
|
49
|
+
export function collectUnassigned(records, assigned, options = {}) {
|
|
50
|
+
const includeSubagent = options.includeSubagentSessions === true
|
|
51
|
+
/** @type {Map<string, { cwd: string, sessions: { id: string, title: string, createdAt: number, origin: string }[] }>} */
|
|
52
|
+
const groups = new Map()
|
|
53
|
+
const unassignable = { noCwd: 0, subagent: 0, legacyFormat: 0 }
|
|
54
|
+
let total = 0
|
|
55
|
+
for (const record of records ?? []) {
|
|
56
|
+
const header = record?.header
|
|
57
|
+
if (!header || typeof header.id !== 'string' || header.id.length === 0) continue
|
|
58
|
+
if (assigned.has(header.id)) continue
|
|
59
|
+
if (typeof header.cwd !== 'string' || header.cwd.length === 0) {
|
|
60
|
+
unassignable.noCwd += 1
|
|
61
|
+
continue
|
|
62
|
+
}
|
|
63
|
+
if (header.origin === 'subagent' && !includeSubagent) {
|
|
64
|
+
unassignable.subagent += 1
|
|
65
|
+
continue
|
|
66
|
+
}
|
|
67
|
+
if (record.formatStatus === 'migration-required') {
|
|
68
|
+
unassignable.legacyFormat += 1
|
|
69
|
+
continue
|
|
70
|
+
}
|
|
71
|
+
let group = groups.get(header.cwd)
|
|
72
|
+
if (group === undefined) {
|
|
73
|
+
group = { cwd: header.cwd, sessions: [] }
|
|
74
|
+
groups.set(header.cwd, group)
|
|
75
|
+
}
|
|
76
|
+
group.sessions.push({
|
|
77
|
+
id: header.id,
|
|
78
|
+
title: '',
|
|
79
|
+
createdAt: typeof header.createdAt === 'number' ? header.createdAt : 0,
|
|
80
|
+
origin: typeof header.origin === 'string' ? header.origin : 'user',
|
|
81
|
+
})
|
|
82
|
+
total += 1
|
|
83
|
+
}
|
|
84
|
+
const ordered = [...groups.values()]
|
|
85
|
+
.map((group) => ({
|
|
86
|
+
cwd: group.cwd,
|
|
87
|
+
sessions: group.sessions.sort((left, right) =>
|
|
88
|
+
right.createdAt - left.createdAt || left.id.localeCompare(right.id)),
|
|
89
|
+
}))
|
|
90
|
+
.sort((left, right) => left.cwd.localeCompare(right.cwd))
|
|
91
|
+
return { groups: ordered, total, unassignable }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Split requested Session ids into cwd work lists and the reasons some cannot
|
|
96
|
+
* be planned: ids a Workspace already owns, and ids the scan cannot place.
|
|
97
|
+
*
|
|
98
|
+
* @param {readonly { header?: Record<string, unknown>, formatStatus?: string }[]} records - fresh `listSessions()` rows.
|
|
99
|
+
* @param {ReadonlySet<string>} assigned - ids owned by some Workspace.
|
|
100
|
+
* @param {readonly string[]} requestedIds - ids submitted by the caller.
|
|
101
|
+
* @param {{ includeSubagentSessions?: boolean }} [options] - eligibility switches.
|
|
102
|
+
* @returns {{
|
|
103
|
+
* byCwd: Map<string, string[]>,
|
|
104
|
+
* alreadyAssigned: string[],
|
|
105
|
+
* unknown: string[],
|
|
106
|
+
* }}
|
|
107
|
+
*/
|
|
108
|
+
export function planAssignment(records, assigned, requestedIds, options = {}) {
|
|
109
|
+
const wanted = [...new Set((requestedIds ?? []).map((id) => String(id)))]
|
|
110
|
+
const scan = collectUnassigned(records, assigned, options)
|
|
111
|
+
/** @type {Map<string, string>} */
|
|
112
|
+
const cwdOf = new Map()
|
|
113
|
+
for (const group of scan.groups) {
|
|
114
|
+
for (const session of group.sessions) cwdOf.set(session.id, group.cwd)
|
|
115
|
+
}
|
|
116
|
+
/** @type {Map<string, string[]>} */
|
|
117
|
+
const byCwd = new Map()
|
|
118
|
+
const alreadyAssigned = wanted.filter((id) => assigned.has(id))
|
|
119
|
+
const unknown = []
|
|
120
|
+
for (const id of wanted) {
|
|
121
|
+
if (assigned.has(id)) continue
|
|
122
|
+
const cwd = cwdOf.get(id)
|
|
123
|
+
if (cwd === undefined) {
|
|
124
|
+
unknown.push(id)
|
|
125
|
+
continue
|
|
126
|
+
}
|
|
127
|
+
const list = byCwd.get(cwd)
|
|
128
|
+
if (list === undefined) byCwd.set(cwd, [id])
|
|
129
|
+
else list.push(id)
|
|
130
|
+
}
|
|
131
|
+
return { byCwd, alreadyAssigned, unknown }
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Normalize a submitted id list: strings only, trimmed, deduplicated, bounded.
|
|
136
|
+
* @param {unknown} value - request body field.
|
|
137
|
+
* @param {number} limit - maximum accepted ids.
|
|
138
|
+
* @returns {string[]} accepted ids.
|
|
139
|
+
*/
|
|
140
|
+
export function normalizeRequestedIds(value, limit = 2000) {
|
|
141
|
+
if (!Array.isArray(value)) return []
|
|
142
|
+
const ids = []
|
|
143
|
+
const seen = new Set()
|
|
144
|
+
for (const entry of value) {
|
|
145
|
+
if (typeof entry !== 'string') continue
|
|
146
|
+
const id = entry.trim()
|
|
147
|
+
if (id.length === 0 || seen.has(id)) continue
|
|
148
|
+
seen.add(id)
|
|
149
|
+
ids.push(id)
|
|
150
|
+
if (ids.length >= limit) break
|
|
151
|
+
}
|
|
152
|
+
return ids
|
|
153
|
+
}
|