dshgo-session-admin 0.0.0-stage → 0.1.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 parofufu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,65 @@
1
- # Temporary Holding Version
1
+ # dshgo-session-admin
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ English | [简体中文](#简体中文)
4
+
5
+ List and permanently delete DSH sessions on the local engine — the same effect as
6
+ long-pressing a conversation in the app and choosing "永久删除".
7
+
8
+ Two tools:
9
+
10
+ - `session_list` — returns `{ total, returned, sessions: [{ sessionId, title, createdAt, cwd }] }`.
11
+ Use it to reconcile what is actually in the store before/after a batch import.
12
+ - `session_delete` — accepts `sessionId` or `sessionIds` (batch) and returns
13
+ `{ deleted, deletedIds, failed: [{ sessionId, reason }] }`. It deletes only the
14
+ session log and its subagent tree; workspace files are untouched. Unknown ids are
15
+ reported in `failed` (never silently ignored), and a session that still has a live
16
+ agent is rejected with a reason.
17
+
18
+ Deletion runs through the engine's own lifecycle seam
19
+ (`sessionPersistence.dshGoDeletion.delete`), so tombstones, subagent cascade and
20
+ artifact cleanup behave exactly like the app's delete action.
21
+
22
+ ## Install
23
+
24
+ ```sh
25
+ dsh plugin add dshgo-session-admin
26
+ ```
27
+
28
+ On HarmonyOS, install it from the plugin manager with the registry spec
29
+ `dshgo-session-admin@0.1.0` (or `latest`). Local `.tgz` packages are rejected with
30
+ `OHOS_PLUGIN_UNSUPPORTED` on HarmonyOS.
31
+
32
+ ## License
33
+
34
+ MIT
35
+
36
+ ---
37
+
38
+ ## 简体中文
39
+
40
+ 在**本机引擎**里列出会话、永久删除会话——效果等同 App 里长按会话 ›「永久删除」。
41
+
42
+ 两个工具:
43
+
44
+ - `session_list`:返回 `{ total, returned, sessions: [{ sessionId, title, createdAt, cwd }] }`,
45
+ 用于批量重导前后核对「库里到底还有哪些会话」。
46
+ - `session_delete`:接受 `sessionId` 或批量 `sessionIds`,返回
47
+ `{ deleted, deletedIds, failed: [{ sessionId, reason }] }`。**只删会话记录与其子代理会话树,
48
+ 不动工作区文件**;删除不存在的 id 会出现在 `failed` 并给出原因(不会静默成功);
49
+ 仍有活跃 agent 的会话会被拒绝并说明原因。
50
+
51
+ 删除走引擎自己的生命周期接口 `sessionPersistence.dshGoDeletion.delete`,
52
+ 墓碑、子会话级联、产物清理与 App 内删除行为一致。
53
+
54
+ ### 安装
55
+
56
+ ```sh
57
+ dsh plugin add dshgo-session-admin
58
+ ```
59
+
60
+ 鸿蒙手机上请在插件管理器里用 registry spec 安装:`dshgo-session-admin@0.1.0`(或 `latest`)。
61
+ 鸿蒙本机不接受本地 `.tgz` 包(会报 `OHOS_PLUGIN_UNSUPPORTED`)。
62
+
63
+ ### 许可
64
+
65
+ MIT
@@ -0,0 +1,6 @@
1
+ # dsh bundle patch: inserts this plugin into a profile's layer stack.
2
+ # `name` is the published package name, so the same file works after
3
+ # `dsh plugin add dshgo-session-admin`.
4
+ - insert:
5
+ - id: dshgo-session-admin
6
+ name: 'dshgo-session-admin'
package/lib/plugin.js ADDED
@@ -0,0 +1,235 @@
1
+ // dshgo-session-admin — list and permanently delete sessions on the local DSH engine.
2
+ //
3
+ // Only node builtins are imported: the profile loader loads this plugin from an
4
+ // arbitrary absolute path whose module resolution does not cover @deepseek-ai/*.
5
+ //
6
+ // Deletion goes through the engine's own lifecycle seam
7
+ // (`sessionPersistence.dshGoDeletion.delete`), which fences the session, removes
8
+ // its subagent tree, writes the tombstone and deletes only session artifacts —
9
+ // the workspace is never touched.
10
+
11
+ const PLUGIN_NAME = 'dshgo-session-admin'
12
+ const LIST_TOOL = 'session_list'
13
+ const DELETE_TOOL = 'session_delete'
14
+
15
+ function str(value) {
16
+ return typeof value === 'string' ? value : ''
17
+ }
18
+
19
+ function num(value) {
20
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined
21
+ }
22
+
23
+ function lastTitle(events) {
24
+ if (!Array.isArray(events)) return ''
25
+ for (let index = events.length - 1; index >= 0; index -= 1) {
26
+ const event = events[index]
27
+ if (event?.type !== 'session/title') continue
28
+ const title = str(event?.data?.title) || str(event?.data?.name)
29
+ if (title.length > 0) return title
30
+ }
31
+ return ''
32
+ }
33
+
34
+ async function readTitle(persistence, sessionId) {
35
+ if (typeof persistence.requireStoredLog !== 'function') return ''
36
+ try {
37
+ const log = await persistence.requireStoredLog(sessionId)
38
+ return lastTitle(log?.events)
39
+ } catch {
40
+ return ''
41
+ }
42
+ }
43
+
44
+ const listParameters = {
45
+ type: 'object',
46
+ properties: {
47
+ limit: { type: 'number', description: '最多返回多少条,默认 500,上限 2000' },
48
+ includeSubagents: { type: 'boolean', description: '是否包含子代理会话,默认 false' },
49
+ withTitles: { type: 'boolean', description: '是否读取每个会话的标题(较慢,默认 true)' },
50
+ },
51
+ additionalProperties: false,
52
+ }
53
+
54
+ const listOutputSchema = {
55
+ type: 'object',
56
+ properties: {
57
+ total: { type: 'number' },
58
+ returned: { type: 'number' },
59
+ sessions: {
60
+ type: 'array',
61
+ items: {
62
+ type: 'object',
63
+ properties: {
64
+ sessionId: { type: 'string' },
65
+ title: { type: 'string' },
66
+ createdAt: { type: 'number' },
67
+ cwd: { type: 'string' },
68
+ sizeBytes: { type: 'number' },
69
+ },
70
+ required: ['sessionId'],
71
+ additionalProperties: false,
72
+ },
73
+ },
74
+ },
75
+ required: ['total', 'returned', 'sessions'],
76
+ additionalProperties: false,
77
+ }
78
+
79
+ async function runList(args, exec, ctx) {
80
+ const persistence = ctx.get('sessionPersistence')
81
+ if (persistence === undefined || persistence === null) {
82
+ throw new Error('当前引擎没有 sessionPersistence 服务,无法列出会话')
83
+ }
84
+ const limit = typeof args.limit === 'number' && args.limit > 0 ? Math.min(Math.floor(args.limit), 2000) : 500
85
+ const includeSubagents = args.includeSubagents === true
86
+ const withTitles = args.withTitles !== false
87
+ const snapshots = await persistence.list()
88
+ const visible = snapshots.filter((snapshot) => includeSubagents || snapshot?.header?.origin !== 'subagent')
89
+ const sessions = []
90
+ for (const snapshot of visible) {
91
+ const header = snapshot?.header ?? {}
92
+ const sessionId = str(header.id)
93
+ if (sessionId.length === 0) continue
94
+ const title = withTitles ? await readTitle(persistence, sessionId) : ''
95
+ sessions.push({
96
+ sessionId,
97
+ title,
98
+ ...(header.createdAt === undefined ? {} : { createdAt: header.createdAt }),
99
+ ...(str(header.cwd).length > 0 ? { cwd: str(header.cwd) } : {}),
100
+ ...(snapshot.sizeBytes === undefined ? {} : { sizeBytes: snapshot.sizeBytes }),
101
+ })
102
+ }
103
+ sessions.sort((left, right) => (right.createdAt ?? 0) - (left.createdAt ?? 0))
104
+ const returned = sessions.slice(0, limit)
105
+ return { total: sessions.length, returned: returned.length, sessions: returned }
106
+ }
107
+
108
+ const deleteParameters = {
109
+ type: 'object',
110
+ properties: {
111
+ sessionId: { type: 'string', description: '要删除的单个会话 id(session-…)' },
112
+ sessionIds: {
113
+ type: 'array',
114
+ items: { type: 'string' },
115
+ description: '要批量删除的会话 id 列表;与 sessionId 二选一或同时给',
116
+ },
117
+ },
118
+ additionalProperties: false,
119
+ }
120
+
121
+ const deleteOutputSchema = {
122
+ type: 'object',
123
+ properties: {
124
+ deleted: { type: 'number' },
125
+ deletedIds: { type: 'array', items: { type: 'string' } },
126
+ failed: {
127
+ type: 'array',
128
+ items: {
129
+ type: 'object',
130
+ properties: {
131
+ sessionId: { type: 'string' },
132
+ reason: { type: 'string' },
133
+ },
134
+ required: ['sessionId', 'reason'],
135
+ additionalProperties: false,
136
+ },
137
+ },
138
+ },
139
+ required: ['deleted', 'failed'],
140
+ additionalProperties: false,
141
+ }
142
+
143
+ async function runDelete(args, exec, ctx) {
144
+ const persistence = ctx.get('sessionPersistence')
145
+ if (persistence === undefined || persistence === null) {
146
+ throw new Error('当前引擎没有 sessionPersistence 服务,无法删除会话')
147
+ }
148
+ const seam = persistence.dshGoDeletion
149
+ if (seam === undefined || seam === null || typeof seam.delete !== 'function') {
150
+ throw new Error('当前引擎没有暴露会话删除接口(sessionPersistence.dshGoDeletion),请升级 dsh-Go')
151
+ }
152
+ const wanted = []
153
+ const single = str(args.sessionId).trim()
154
+ if (single.length > 0) wanted.push(single)
155
+ if (Array.isArray(args.sessionIds)) {
156
+ for (const item of args.sessionIds) {
157
+ const id = str(item).trim()
158
+ if (id.length > 0) wanted.push(id)
159
+ }
160
+ }
161
+ const unique = [...new Set(wanted)]
162
+ if (unique.length === 0) throw new Error('需要 sessionId 或 sessionIds')
163
+
164
+ const deletedIds = []
165
+ const failed = []
166
+ for (const sessionId of unique) {
167
+ try {
168
+ // The seam fences the id, disposes an idle live agent, cascades subagent
169
+ // children, tombstones the artifact and only removes session files.
170
+ await seam.delete(sessionId, {})
171
+ deletedIds.push(sessionId)
172
+ } catch (error) {
173
+ const code = str(error?.code)
174
+ const message = str(error?.message) || String(error)
175
+ failed.push({ sessionId, reason: code.length > 0 ? `${code}: ${message}` : message })
176
+ }
177
+ }
178
+ return { deleted: deletedIds.length, deletedIds, failed }
179
+ }
180
+
181
+ function renderList(value) {
182
+ const lines = [`共 ${value.total} 个会话,返回 ${value.returned} 个`]
183
+ for (const session of value.sessions ?? []) {
184
+ const when = session.createdAt === undefined ? '' : new Date(session.createdAt).toISOString().slice(0, 16).replace('T', ' ')
185
+ lines.push(`- ${session.sessionId} ${session.title || '(无标题)'} ${when}`)
186
+ }
187
+ return lines.join('\n')
188
+ }
189
+
190
+ function renderDelete(value) {
191
+ const lines = [`已删除 ${value.deleted} 个会话`]
192
+ for (const id of value.deletedIds ?? []) lines.push(`✔ ${id}`)
193
+ for (const item of value.failed ?? []) lines.push(`✘ ${item.sessionId}:${item.reason}`)
194
+ return lines.join('\n')
195
+ }
196
+
197
+ export function apply(ctx) {
198
+ ctx.tools.register({
199
+ name: LIST_TOOL,
200
+ description: [
201
+ '列出本机引擎里的会话(id、标题、创建时间),用于核对库里到底有哪些会话。',
202
+ '默认不含子代理会话;withTitles=false 可跳过标题读取(更快)。',
203
+ ].join(' '),
204
+ parameters: listParameters,
205
+ output: {
206
+ schema: listOutputSchema,
207
+ render: (_args, value) => [{ type: 'text', text: renderList(value) }],
208
+ },
209
+ presentCall: () => ({ card: 'generic', title: '会话列表', kind: 'read' }),
210
+ async execute(args, exec) {
211
+ return runList(args, exec, ctx)
212
+ },
213
+ })
214
+
215
+ ctx.tools.register({
216
+ name: DELETE_TOOL,
217
+ description: [
218
+ '把会话从本机引擎永久删除(等同 App 里长按 › 永久删除):只删会话记录与其子代理会话树,不动工作区文件。',
219
+ '支持单个 sessionId 或批量 sessionIds;删除不存在的 id 会出现在 failed 里并给出原因。',
220
+ '正在运行(有活跃 agent/未完成输入)的会话会被拒绝,请先结束它。',
221
+ ].join(' '),
222
+ parameters: deleteParameters,
223
+ output: {
224
+ schema: deleteOutputSchema,
225
+ render: (_args, value) => [{ type: 'text', text: renderDelete(value) }],
226
+ },
227
+ presentCall: (args) => ({ card: 'generic', title: '删除会话', kind: 'write', rawInput: str(args.sessionId) }),
228
+ async execute(args, exec) {
229
+ return runDelete(args, exec, ctx)
230
+ },
231
+ })
232
+ }
233
+
234
+ export const name = PLUGIN_NAME
235
+ export const inject = ['tools', 'sessions', 'sessionPersistence']
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "dshgo-session-admin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "List and permanently delete DSH sessions on the device. · 在本机引擎里列出会话、永久删除会话(只删会话记录,不动工作区文件)。",
5
+ "type": "module",
6
+ "main": "./lib/plugin.js",
7
+ "exports": {
8
+ ".": "./lib/plugin.js",
9
+ "./cordis.patch.yml": "./cordis.patch.yml",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "lib",
14
+ "cordis.patch.yml",
15
+ "README.md",
16
+ "LICENSE"
17
+ ],
18
+ "engines": {
19
+ "node": ">=22.18",
20
+ "dsh": ">=0.2.0"
21
+ },
22
+ "keywords": [
23
+ "deepseek",
24
+ "harness",
25
+ "dsh",
26
+ "dsh-plugin",
27
+ "session",
28
+ "delete",
29
+ "session-management"
30
+ ],
31
+ "license": "MIT",
32
+ "dsh": {
33
+ "bundle": {
34
+ "patch": "./cordis.patch.yml"
35
+ }
36
+ },
37
+ "dshGo": {
38
+ "v": 1,
39
+ "title": {
40
+ "zh": "会话管理(列出/删除)",
41
+ "en": "Session Admin (list/delete)"
42
+ },
43
+ "contributes": {}
44
+ },
45
+ "publishConfig": {
46
+ "registry": "https://registry.npmjs.org/"
47
+ }
48
+ }