@bnviking/dsh-bnv-workspace 0.0.0-stage → 0.4.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.
@@ -0,0 +1,5 @@
1
+ # Bundle patch: one Host row for the permanent-delete command; the browser half
2
+ # is declared by package.json `dsh.client`.
3
+ - insert:
4
+ - id: bnv-workspace
5
+ name: '@bnviking/dsh-bnv-workspace'
package/icon.svg ADDED
@@ -0,0 +1,6 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="Sidebar names and permanent delete">
2
+ <rect width="64" height="64" rx="14" fill="#247bbf"/>
3
+ <text x="13" y="41" font-family="Segoe UI, Arial, sans-serif" font-size="27" font-weight="600" fill="#ffffff">A</text>
4
+ <path d="M35 25h15M39.5 25v-3.2h5V25M37 25l1.3 19h9.4L49 25M41.8 30v9.5M45.7 30v9.5"
5
+ fill="none" stroke="#ffffff" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/>
6
+ </svg>
package/index.js ADDED
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Host half: one human command that erases a chat, or a project and every chat
3
+ * inside it, from disk. No DSH seam deletes stored session files, so this
4
+ * plugin removes the session-owned directory and then forgets every durable
5
+ * reference to the erased ids (workspace account, pin, archive).
6
+ *
7
+ * The Client passes its active language as the last argument, because Host
8
+ * command results are plain text and the Client shows them verbatim.
9
+ */
10
+ import { rm } from 'node:fs/promises'
11
+ import { descendantsOf, safeSessionArtifact } from './safety.js'
12
+
13
+ export const name = 'bnv-workspace'
14
+ export const inject = ['commands', 'sessions', 'sessionPersistence', 'workspaceRegistry']
15
+
16
+ const SAFE_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,199}$/
17
+ const PLAIN_ID = /^[A-Za-z0-9_-]{1,160}$/
18
+
19
+ const TEXT = {
20
+ en: {
21
+ usage: 'Usage: /bnv-delete session <id> | project <id>',
22
+ projectMissing: 'Project not found.',
23
+ openOne: 'This chat is open right now. Switch to another chat and try again.',
24
+ openMany: count => `An open chat is part of this deletion (${count}). Switch to another chat and try again.`,
25
+ chatDone: erased => `Chat deleted permanently: ${erased} log${erased === 1 ? '' : 's'} erased.`,
26
+ projectDone: (title, chats, erased) => `Project “${title}” deleted permanently: ${chats} chat${chats === 1 ? '' : 's'} erased, ${erased} log${erased === 1 ? '' : 's'}. The project folder on disk was left untouched.`,
27
+ },
28
+ ru: {
29
+ usage: 'Использование: /bnv-delete session <id> | project <id>',
30
+ projectMissing: 'Проект не найден.',
31
+ openOne: 'Этот чат сейчас открыт. Переключитесь на другой чат и повторите удаление.',
32
+ openMany: count => `Среди удаляемых есть открытый чат (${count}). Переключитесь на другой чат и повторите.`,
33
+ chatDone: erased => `Чат удалён навсегда: стёрто журналов — ${erased}.`,
34
+ projectDone: (title, chats, erased) => `Проект «${title}» удалён навсегда: стёрто чатов — ${chats}, журналов — ${erased}. Папка проекта на диске не тронута.`,
35
+ },
36
+ }
37
+
38
+ /** @param {import('@deepseek-ai/cordis').Context} ctx */
39
+ export function apply(ctx) {
40
+ ctx.effect(() => ctx.commands.register({
41
+ name: 'bnv-delete',
42
+ description: 'Permanently delete a chat or a project with every chat inside',
43
+ recordInput: false,
44
+ input: { hint: 'session <id> | project <id>' },
45
+ handler: invocation => run(ctx, invocation.rawInput),
46
+ }), 'bnv-workspace: permanent delete command')
47
+ }
48
+
49
+ /** @param {string} rawInput */
50
+ async function run(ctx, rawInput) {
51
+ const [verb, id, language] = String(rawInput ?? '').trim().split(/\s+/)
52
+ const text = language === 'ru' ? TEXT.ru : TEXT.en
53
+ if (verb === undefined || id === undefined || !SAFE_ID.test(id)) return fail(text.usage)
54
+ if (verb === 'session') return eraseChat(ctx, id, text)
55
+ if (verb === 'project') return eraseProject(ctx, id, text)
56
+ return fail(text.usage)
57
+ }
58
+
59
+ async function eraseChat(ctx, id, text) {
60
+ try {
61
+ const snapshots = await storedSessions(ctx)
62
+ const ids = [id, ...descendantsOf(snapshots, id)]
63
+ const open = ids.filter(candidate => ctx.sessions.get(candidate) !== undefined)
64
+ if (open.length > 0) return fail(openMessage(text, open.length))
65
+ // Detach before the log disappears: workspace membership is derived from
66
+ // the stored header, so a deleted session could keep a dangling id.
67
+ await forgetReferences(ctx, ids)
68
+ const erased = await eraseAll(ctx, ids)
69
+ for (const candidate of ids) ctx.emit('api-session/removed', candidate)
70
+ return ok(text.chatDone(erased))
71
+ } catch (error) {
72
+ return fail(messageOf(error))
73
+ }
74
+ }
75
+
76
+ async function eraseProject(ctx, id, text) {
77
+ try {
78
+ const registry = ctx.workspaceRegistry
79
+ const workspace = registry.get(id)
80
+ if (workspace === undefined) return fail(text.projectMissing)
81
+ const snapshots = await storedSessions(ctx)
82
+ const ids = new Set()
83
+ for (const root of workspace.sessionIds) {
84
+ ids.add(root)
85
+ for (const descendant of descendantsOf(snapshots, root)) ids.add(descendant)
86
+ }
87
+ const targets = [...ids]
88
+ const open = targets.filter(candidate => ctx.sessions.get(candidate) !== undefined)
89
+ if (open.length > 0) return fail(openMessage(text, open.length))
90
+ for (const candidate of targets) {
91
+ await registry.unpinSession(candidate)
92
+ await registry.unarchiveSession(candidate)
93
+ }
94
+ for (const workspaceRow of registry.list()) {
95
+ const members = new Set(workspaceRow.sessionIds)
96
+ for (const candidate of targets) {
97
+ if (members.has(candidate)) await workspaceRow.detachSession(candidate)
98
+ }
99
+ }
100
+ const erased = await eraseAll(ctx, targets)
101
+ await registry.delete(id)
102
+ for (const candidate of targets) ctx.emit('api-session/removed', candidate)
103
+ return ok(text.projectDone(workspace.title, targets.length, erased))
104
+ } catch (error) {
105
+ return fail(messageOf(error))
106
+ }
107
+ }
108
+
109
+ async function storedSessions(ctx) {
110
+ const snapshots = await ctx.sessionPersistence.list()
111
+ return new Map(snapshots.map(snapshot => [snapshot.header.id, snapshot]))
112
+ }
113
+
114
+ async function eraseAll(ctx, ids) {
115
+ let erased = 0
116
+ for (const id of ids) {
117
+ if (!PLAIN_ID.test(id)) continue
118
+ const snapshot = await ctx.sessionPersistence.stat(id)
119
+ const dir = safeSessionArtifact(snapshot?.location?.path)
120
+ if (dir === null) continue
121
+ await rm(dir, { recursive: true, force: true })
122
+ erased += 1
123
+ }
124
+ return erased
125
+ }
126
+
127
+ async function forgetReferences(ctx, ids) {
128
+ const registry = ctx.workspaceRegistry
129
+ for (const id of ids) {
130
+ await registry.unpinSession(id)
131
+ await registry.unarchiveSession(id)
132
+ }
133
+ for (const workspace of registry.list()) {
134
+ const members = new Set(workspace.sessionIds)
135
+ for (const id of ids) {
136
+ if (members.has(id)) await workspace.detachSession(id)
137
+ }
138
+ }
139
+ }
140
+
141
+ function openMessage(text, count) {
142
+ return count === 1 ? text.openOne : text.openMany(count)
143
+ }
144
+
145
+ function ok(text) {
146
+ return { kind: 'success', text }
147
+ }
148
+
149
+ function fail(text) {
150
+ return { kind: 'error', text }
151
+ }
152
+
153
+ function messageOf(error) {
154
+ return error instanceof Error ? error.message : String(error)
155
+ }
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Sidebar names and permanent delete",
4
+ "description": "Restyle chat and project names in the workspace sidebar, and permanently erase chats or projects together with every chat inside them."
5
+ }
6
+ }
package/locale/ru.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Имена в сайдбаре и удаление навсегда",
4
+ "description": "Настраивает шрифт, цвет, толщину и регистр названий чатов и проектов в боковой панели и безвозвратно удаляет чаты или проекты вместе со всеми чатами внутри."
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@bnviking/dsh-bnv-workspace",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.4.0",
4
+ "description": "Name styling, per-row icons, and permanent chat/project deletion for the DeepSeek Harness workspace sidebar.",
5
+ "license": "MIT",
6
+ "author": "BNViking",
7
+ "keywords": ["dsh", "deepseek-harness", "plugin", "sidebar", "workspace"],
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/BNViking/dsh-bnv-workspace.git"
11
+ },
12
+ "homepage": "https://github.com/BNViking/dsh-bnv-workspace#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/BNViking/dsh-bnv-workspace/issues"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "type": "module",
20
+ "exports": {
21
+ ".": "./index.js",
22
+ "./client": "./client.js",
23
+ "./locale/*.json": "./locale/*.json",
24
+ "./icon": "./icon.svg"
25
+ },
26
+ "files": [
27
+ "index.js",
28
+ "client.js",
29
+ "safety.js",
30
+ "cordis.patch.yml",
31
+ "locale/*.json",
32
+ "README.md",
33
+ "icon.svg"
34
+ ],
35
+ "dsh": {
36
+ "bundle": { "patch": "./cordis.patch.yml" },
37
+ "client": {
38
+ "platform": "web",
39
+ "immediately": true,
40
+ "inject": [
41
+ "@deepseek-ai/dsh-client-ui-workspace",
42
+ "@deepseek-ai/dsh-client-ui-context-menu"
43
+ ]
44
+ }
45
+ }
46
+ }
package/safety.js ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Pure helpers for permanent deletion: which stored file may be erased, and
3
+ * which persisted sessions hang below one session. Kept separate from the
4
+ * command so they can be checked without a Harness process.
5
+ */
6
+ import { basename, dirname, resolve } from 'node:path'
7
+
8
+ const SESSION_FILE = /^session(?:\.v\d+)?\.jsonl(?:\.zstd)?$/
9
+ const SESSION_DIR = /^session-[A-Za-z0-9._-]{1,180}$/
10
+
11
+ /**
12
+ * The session-owned directory to erase, or null when the path is not exactly
13
+ * one file inside a session directory (`<root>/<project>/<session>/session*.jsonl*`).
14
+ * @param {string} file - absolute stored log path.
15
+ * @returns {string | null} the directory to remove.
16
+ */
17
+ export function safeSessionArtifact(file) {
18
+ if (typeof file !== 'string' || file.length === 0) return null
19
+ if (!SESSION_FILE.test(basename(file))) return null
20
+ const dir = resolve(dirname(file))
21
+ if (!SESSION_DIR.test(basename(dir))) return null
22
+ return dir
23
+ }
24
+
25
+ /**
26
+ * Every stored session below one root, breadth-first, excluding the root.
27
+ * @param {Map<string, { header: { id: string, parentSession?: string } }>} byId - every stored snapshot by id.
28
+ * @param {string} rootId - the session whose descendants to collect.
29
+ * @returns {string[]} descendant ids.
30
+ */
31
+ export function descendantsOf(byId, rootId) {
32
+ const children = new Map()
33
+ for (const snapshot of byId.values()) {
34
+ const parent = snapshot.header.parentSession
35
+ if (parent === undefined) continue
36
+ const list = children.get(parent)
37
+ if (list === undefined) children.set(parent, [snapshot.header.id])
38
+ else list.push(snapshot.header.id)
39
+ }
40
+ const out = []
41
+ const stack = [...(children.get(rootId) ?? [])]
42
+ while (stack.length > 0) {
43
+ const id = stack.pop()
44
+ out.push(id)
45
+ stack.push(...(children.get(id) ?? []))
46
+ }
47
+ return out
48
+ }