dsh-remote-plugin 0.7.6 → 0.8.0-rc.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.
@@ -0,0 +1,275 @@
1
+ /* Shared, dependency-free subagent browser. Only explicit disclosure reads a new level. */
2
+ (function (root) {
3
+ 'use strict'
4
+ let view = null, page = null, pageBody = null, pageTitle = null
5
+ const memories = new Map()
6
+ const text = (cn, en) => String(root.I18N?.lang || 'zh').startsWith('en') ? en : cn
7
+ function node(tag, label, cls) {
8
+ const el = document.createElement(tag)
9
+ if (label !== undefined) el.textContent = label
10
+ if (cls) el.className = cls
11
+ return el
12
+ }
13
+ function button(label, action, cls, key) {
14
+ const el = node('button', label, cls)
15
+ el.type = 'button'
16
+ if (key) el.dataset.subFocus = key
17
+ el.addEventListener('click', action)
18
+ return el
19
+ }
20
+ const valid = v => view === v && !v.paused && v.options.valid()
21
+ const modeLabel = mode => mode === 'one-shot' ? text('单次任务', 'One-shot task') : mode === 'continuable' ? text('可续接任务', 'Continuable task') : text('模式未知', 'Unknown mode')
22
+ const activityLabel = activity => activity === 'running' ? text('运行中', 'Running') : activity === 'waiting' ? text('等待中', 'Waiting') : activity === 'inactive' ? text('未运行', 'Inactive') : text('状态未知', 'Unknown status')
23
+ function reasonLabel(reason) {
24
+ if (reason === 'migration-required') return text('请先在 DSH 中打开原会话完成迁移,再刷新目录', 'Open the source session in DSH to complete migration, then refresh the catalog')
25
+ if (reason === 'external') return text('这是外部代理任务,请在 DSH 中查看', 'This is an external-agent task. View it in DSH')
26
+ return ({ unsupported: text('当前版本无法识别此任务类型', 'This task type is not supported by the current version'), unavailable: text('记录暂时无法读取,可刷新重试', 'Record unavailable. Refresh to try again'), corrupt: text('任务信息不一致,暂不能打开', 'Task information is inconsistent. This record cannot be opened'), cycle: text('目录关系重复或形成循环', 'The catalog contains a repeated or circular relationship') })[reason] || text('此目录项暂时不可用', 'This catalog entry is unavailable')
27
+ }
28
+ function status(entry, diagnostic) {
29
+ const value = diagnostic ? 'diagnostic' : ['running', 'waiting', 'inactive'].includes(entry.activity) ? entry.activity : 'unknown'
30
+ const el = node('span', diagnostic ? text('目录异常', 'Catalog issue') : activityLabel(value), 'subtree-badge')
31
+ el.dataset.activity = value
32
+ return el
33
+ }
34
+ function model(v) {
35
+ const rootItem = { key: 'root', id: v.id, label: v.options.title || v.id, parent: null, depth: 0, entry: { activity: v.options.activity }, children: [] }
36
+ const byKey = new Map([['root', rootItem]])
37
+ let count = 0, running = 0, issues = 0, limited = false
38
+ function visit(parent, ancestors) {
39
+ const cached = v.cache.get(parent.id)
40
+ for (const entry of cached?.value?.entries || []) {
41
+ if (byKey.size > 300) { limited = true; break }
42
+ const diagnostic = entry.kind === 'diagnostic' || !entry.id || ancestors.has(entry.id)
43
+ const item = { key: parent.key + '/' + (entry.id ? encodeURIComponent(entry.id) : 'unknown-' + parent.children.length), id: entry.id || '', label: entry.label || entry.id?.slice(0, 12) || text('异常条目', 'Catalog issue'), entry, parent, depth: parent.depth + 1, diagnostic, reason: ancestors.has(entry.id) ? 'cycle' : entry.reason, children: [] }
44
+ byKey.set(item.key, item); parent.children.push(item)
45
+ if (diagnostic) issues++
46
+ else {
47
+ count++; if (entry.activity === 'running') running++
48
+ if (item.depth < 16) visit(item, new Set([...ancestors, item.id]))
49
+ else if (entry.hasChildren !== false) limited = true
50
+ }
51
+ }
52
+ }
53
+ visit(rootItem, new Set([v.id]))
54
+ return { rootItem, byKey, count, running, issues, limited }
55
+ }
56
+ async function read(v, id, force = false) {
57
+ if (!valid(v)) return
58
+ const previous = v.cache.get(id)
59
+ if (previous?.loading || (!force && (previous?.value || previous?.error))) return
60
+ const item = { ...previous, loading: true, error: '' }
61
+ v.cache.set(id, item); paint(v)
62
+ try {
63
+ const value = await v.options.read(id)
64
+ if (!valid(v)) { v.cache.delete(id); return }
65
+ if (!Array.isArray(value?.entries)) throw new Error(text('未能读取子代理目录', 'Subagent catalog unavailable'))
66
+ item.value = value; item.updatedAt = Date.now()
67
+ const ancestors = new Set([v.id, id])
68
+ let parent = [...model(v).byKey.values()].find(item => !item.diagnostic && item.id === id)
69
+ for (; parent; parent = parent.parent) ancestors.add(parent.id)
70
+ for (const entry of value.entries) if (entry.kind !== 'diagnostic' && entry.id && !ancestors.has(entry.id)) v.options.remember(entry, id)
71
+ } catch (error) {
72
+ if (!valid(v)) { v.cache.delete(id); return }
73
+ item.error = String(error.message || error)
74
+ } finally { item.loading = false; if (valid(v)) paint(v) }
75
+ }
76
+ async function refresh(v) {
77
+ if (!valid(v) || v.refreshing) return
78
+ v.refreshing = true; paint(v)
79
+ const seen = new Set()
80
+ async function visit(id, depth) {
81
+ if (!valid(v) || seen.has(id) || seen.size >= 300 || depth > 16) return
82
+ seen.add(id); await read(v, id, true)
83
+ if (!valid(v) || !v.expanded.has(id)) return
84
+ for (const entry of v.cache.get(id)?.value?.entries || []) {
85
+ if (entry.kind !== 'diagnostic' && entry.id && v.expanded.has(entry.id)) await visit(entry.id, depth + 1)
86
+ }
87
+ }
88
+ try { await visit(v.id, 0) } finally { v.refreshing = false; if (valid(v)) paint(v) }
89
+ }
90
+ function shell(v) {
91
+ const el = v.el = node('section', undefined, 'subtree')
92
+ const toolbar = node('div', undefined, 'subtree-toolbar')
93
+ const search = v.search = node('input', undefined, 'subtree-search')
94
+ search.type = 'search'; search.placeholder = text('查找已读取的名称或 ID', 'Find a loaded name or ID')
95
+ search.setAttribute('aria-label', search.placeholder)
96
+ search.addEventListener('input', () => { v.query = search.value; paint(v) })
97
+ const filters = node('div', undefined, 'subtree-filters')
98
+ filters.setAttribute('aria-label', text('按状态筛选', 'Filter by status'))
99
+ v.filters = []
100
+ for (const [key, label] of [['all', text('全部', 'All')], ['running', text('运行中', 'Running')], ['diagnostic', text('异常', 'Issues')]]) {
101
+ const b = button(label, () => { v.filter = key; paint(v) }, '', 'filter:' + key)
102
+ filters.append(b); v.filters.push([key, b])
103
+ }
104
+ toolbar.append(search, filters)
105
+ const actions = node('div', undefined, 'subtree-toolbar-actions')
106
+ const collapse = button(text('收起分支', 'Collapse branches'), () => { v.expanded.clear(); v.expanded.add(v.id); paint(v) }, 'subtree-quiet', 'collapse')
107
+ v.collapseButton = collapse
108
+ const refreshButton = v.refreshButton = button(text('刷新', 'Refresh'), () => void refresh(v), 'subtree-quiet', 'refresh')
109
+ actions.append(collapse, refreshButton); toolbar.append(actions)
110
+ v.summary = node('div', undefined, 'subtree-summary'); v.summary.setAttribute('role', 'status')
111
+ const layout = node('div', undefined, 'subtree-layout')
112
+ v.tree = node('div', undefined, 'subtree-outline'); v.tree.setAttribute('aria-label', text('子代理层级', 'Subagent hierarchy'))
113
+ v.detail = node('aside', undefined, 'subtree-detail'); v.detail.setAttribute('aria-label', text('所选节点详情', 'Selected node details'))
114
+ layout.append(v.tree, v.detail); el.append(toolbar, v.summary, layout)
115
+ }
116
+ function select(v, item) {
117
+ v.selected = item.key; paint(v)
118
+ if (root.matchMedia?.('(max-width:800px)').matches) v.detail.scrollIntoView({ behavior: root.matchMedia('(prefers-reduced-motion:reduce)').matches ? 'auto' : 'smooth', block: 'start' })
119
+ v.detailTitle?.focus({ preventScroll: true })
120
+ }
121
+ function details(v, item, outsideFilter) {
122
+ const box = v.detail; box.replaceChildren()
123
+ box.append(button(text('↑ 返回层级', '↑ Back to hierarchy'), () => {
124
+ const card = v.cards.get(item.key) || v.cards.get('root')
125
+ card?.scrollIntoView({ block: 'center' }); card?.focus({ preventScroll: true })
126
+ }, 'subtree-parent subtree-back-to-tree', 'back-to-tree'))
127
+ box.append(node('div', text('节点详情', 'Node details'), 'subtree-eyebrow'))
128
+ const title = v.detailTitle = node('h3', item.label); title.tabIndex = -1; box.append(title)
129
+ if (outsideFilter) box.append(node('p', text('此选中节点不在当前筛选结果中。', 'This selected node is outside the current filter.'), 'subtree-note'))
130
+ const badges = node('div', undefined, 'subtree-detail-badges')
131
+ if (item.key === 'root') badges.append(node('span', text('当前会话', 'Current session'), 'subtree-kind'))
132
+ else badges.append(node('span', item.diagnostic ? text('不可打开', 'Unavailable') : modeLabel(item.entry.mode), 'subtree-kind'))
133
+ badges.append(status(item.entry, item.diagnostic)); box.append(badges)
134
+ const path = []; for (let p = item; p; p = p.parent) path.unshift(p.label)
135
+ box.append(node('div', text('所在分支', 'Branch'), 'subtree-field-label'), node('p', path.join(' › '), 'subtree-path'))
136
+ if (item.parent) {
137
+ box.append(node('div', text('直接父会话', 'Direct parent'), 'subtree-field-label'))
138
+ box.append(button(item.parent.label, () => select(v, item.parent), 'subtree-parent', 'parent:' + item.key))
139
+ }
140
+ box.append(node('div', text('会话 ID', 'Session ID'), 'subtree-field-label'), node('code', item.id || '—', 'subtree-id'))
141
+ if (item.diagnostic) {
142
+ box.append(node('p', reasonLabel(item.reason), 'subtree-notice'))
143
+ if (item.reason) box.append(node('code', item.reason, 'subtree-reason'))
144
+ box.append(button(text('刷新目录', 'Refresh catalog'), () => void read(v, item.parent.id, true), 'subtree-action', 'retry-detail')); return
145
+ }
146
+ const cached = v.cache.get(item.id)
147
+ if (cached?.value) box.append(node('p', text(`已读取 ${item.children.filter(c => !c.diagnostic).length} 个直接子代理`, `${item.children.filter(c => !c.diagnostic).length} direct subagents loaded`), 'subtree-note'))
148
+ else if (item.entry.hasChildren !== false && item.key !== 'root') box.append(node('p', text('展开节点前的箭头,读取下一层任务。', 'Expand the node arrow to load the next level.'), 'subtree-note'))
149
+ const actions = node('div', undefined, 'subtree-detail-actions')
150
+ actions.append(button(item.key === 'root' ? text('返回当前对话', 'Back to current chat') : text('打开只读记录 ↗', 'Open read-only record ↗'), () => {
151
+ if (!valid(v)) return
152
+ root.DshSubagents.close(); if (item.parent) void v.options.open(item.entry, item.parent.id)
153
+ }, 'subtree-action subtree-primary', 'open:' + item.key))
154
+ const parentCatalog = item.parent && v.cache.get(item.parent.id)?.value
155
+ if (item.entry.mode === 'continuable' && item.entry.activity === 'running' && parentCatalog?.parentAvailable !== false) {
156
+ actions.append(button(text('中断任务', 'Interrupt task'), () => { if (valid(v)) void v.options.interrupt(item.id, item.parent.id) }, 'subtree-action subtree-danger', 'interrupt:' + item.key))
157
+ }
158
+ box.append(actions, node('p', item.parent ? text('打开记录后,返回会进入它的直接父会话。', 'From a record, Back opens its direct parent session.') : text('选择树中的子代理,查看任务详情。', 'Select a subagent in the tree to inspect its details.'), 'subtree-note'))
159
+ }
160
+ function paint(v) {
161
+ if (!valid(v)) return
162
+ const focused = document.activeElement?.dataset?.subFocus
163
+ const m = model(v), query = v.query.trim().toLocaleLowerCase(), filtering = !!query || v.filter !== 'all'
164
+ const matches = new Set()
165
+ function match(item) {
166
+ const own = (!query || `${item.label} ${item.id}`.toLocaleLowerCase().includes(query)) && (v.filter === 'all' || (v.filter === 'diagnostic' ? item.diagnostic : !item.diagnostic && item.entry.activity === 'running'))
167
+ const descendant = item.children.map(match).some(Boolean)
168
+ if (own || descendant) matches.add(item.key)
169
+ return own || descendant
170
+ }
171
+ m.rootItem.children.forEach(match)
172
+ v.refreshButton.disabled = !!v.refreshing; v.refreshButton.textContent = v.refreshing ? text('刷新中…', 'Refreshing…') : text('刷新', 'Refresh')
173
+ v.collapseButton.disabled = filtering
174
+ v.collapseButton.title = filtering ? text('清除筛选后可收起分支', 'Clear filters to collapse branches') : ''
175
+ for (const [key, b] of v.filters) b.setAttribute('aria-pressed', String(key === v.filter))
176
+ const labels = [text(`已读取 ${m.count} 个子代理`, `${m.count} subagents loaded`), text(`${m.running} 个运行中`, `${m.running} running`), text(`${m.issues} 个目录异常`, `${m.issues} catalog issues`)]
177
+ if (v.summarySignature !== labels.join('|')) {
178
+ v.summarySignature = labels.join('|'); v.summary.replaceChildren()
179
+ for (const label of labels) v.summary.append(node('span', label))
180
+ }
181
+ v.tree.replaceChildren()
182
+ v.cards = new Map()
183
+ function feedback(parent, list) {
184
+ const cached = v.cache.get(parent.id)
185
+ if (cached?.error) {
186
+ const warning = node('li', undefined, 'subtree-feedback subtree-warning')
187
+ warning.append(node('strong', cached.value ? text('刷新失败,保留上次目录', 'Refresh failed. Showing the last catalog') : text('暂时无法读取目录', 'Catalog unavailable')), node('p', cached.error))
188
+ warning.append(button(text('重试', 'Retry'), () => void read(v, parent.id, true), 'subtree-action', 'retry:' + parent.key)); list.append(warning)
189
+ }
190
+ if (cached?.loading) list.append(node('li', text('正在读取这一层…', 'Loading this level…'), 'subtree-feedback'))
191
+ if (cached?.value && !cached.value.entries.length && !cached.error) {
192
+ const empty = node('li', undefined, 'subtree-feedback')
193
+ empty.append(node('strong', text('暂无子代理', 'No subagents')), node('p', text('此会话还没有子代理记录。产生新任务后可刷新查看。', 'This session has no subagent records yet. Refresh after new tasks are created.'))); list.append(empty)
194
+ }
195
+ }
196
+ function row(item) {
197
+ const li = node('li'), line = node('div', undefined, 'subtree-row')
198
+ const cached = v.cache.get(item.id), expanded = v.expanded.has(item.id)
199
+ const canExpand = !item.diagnostic && item.depth < 16 && (cached?.value ? cached.value.entries.length > 0 : item.key === 'root' || item.entry.hasChildren !== false)
200
+ if (canExpand) {
201
+ const toggle = button(expanded ? '⌄' : '›', () => {
202
+ if (expanded) v.expanded.delete(item.id)
203
+ else { v.expanded.add(item.id); void read(v, item.id) }
204
+ paint(v)
205
+ }, 'subtree-disclosure', 'toggle:' + item.key)
206
+ toggle.setAttribute('aria-expanded', String(expanded)); toggle.setAttribute('aria-label', (expanded ? text('收起 ', 'Collapse ') : text('展开 ', 'Expand ')) + item.label); line.append(toggle)
207
+ } else line.append(node('span', '·', 'subtree-leaf'))
208
+ const card = button(undefined, () => select(v, item), 'subtree-node', 'select:' + item.key)
209
+ v.cards.set(item.key, card)
210
+ card.setAttribute('aria-pressed', String(item.key === v.selected)); card.title = item.id
211
+ const head = node('span', undefined, 'subtree-node-head'); head.append(node('strong', item.label), status(item.entry, item.diagnostic))
212
+ const meta = node('span', undefined, 'subtree-node-meta')
213
+ meta.append(node('span', item.key === 'root' ? text('当前会话 · 树的起点', 'Current session · Tree root') : item.diagnostic ? reasonLabel(item.reason) : modeLabel(item.entry.mode)))
214
+ if (item.depth >= 4) meta.append(node('span', text(`第 ${item.depth} 层`, `Level ${item.depth}`), 'subtree-depth'))
215
+ if (!item.diagnostic && cached?.value && item.children.length) meta.append(node('span', text(`${item.children.length} 个下级条目`, `${item.children.length} child entries`)))
216
+ card.append(head, meta); line.append(card); li.append(line)
217
+ if (!item.diagnostic && (expanded || filtering)) {
218
+ const list = node('ul', undefined, 'subtree-list')
219
+ for (const child of item.children) if (!filtering || matches.has(child.key)) list.append(row(child))
220
+ if (!filtering || cached?.loading || cached?.error) feedback(item, list)
221
+ if (list.children.length) li.append(list)
222
+ }
223
+ return li
224
+ }
225
+ const treeList = node('ul', undefined, 'subtree-list subtree-root-list'); treeList.append(row(m.rootItem)); v.tree.append(treeList)
226
+ if (filtering && v.cache.get(v.id)?.value && !v.cache.get(v.id)?.loading && !m.rootItem.children.some(c => matches.has(c.key))) {
227
+ const empty = node('div', undefined, 'subtree-feedback')
228
+ empty.append(node('strong', text('已读取目录中没有匹配项', 'No matches in the loaded catalog')), node('p', text('筛选仅检查已读取的节点,不会自动加载其他分支。', 'Filters only inspect loaded nodes and do not load other branches.')))
229
+ empty.append(button(text('清除筛选', 'Clear filters'), () => { v.query = ''; v.search.value = ''; v.filter = 'all'; paint(v) }, 'subtree-action', 'clear')); v.tree.append(empty)
230
+ }
231
+ if (m.limited) v.tree.append(node('p', text('目录较大,打开子代理记录可继续查看更深层。', 'Open a child record to explore more of this large catalog.'), 'subtree-note'))
232
+ const selected = m.byKey.get(v.selected) || m.rootItem
233
+ v.selected = selected.key; details(v, selected, filtering && selected.key !== 'root' && !matches.has(selected.key))
234
+ if (focused) for (const el of v.el.querySelectorAll('[data-sub-focus]')) if (el.dataset.subFocus === focused) el.focus({ preventScroll: true })
235
+ }
236
+ root.DshSubagents = {
237
+ configure(entry, options) {
238
+ if (!entry) return
239
+ entry.onclick = () => { if (options.valid()) root.DshSubagents.show(options) }
240
+ if (page?.open) { if (view?.id === options.sessionId) root.DshSubagents.mount(pageBody, options); else root.DshSubagents.close() }
241
+ },
242
+ show(options) {
243
+ if (!options.valid()) return
244
+ if (!page) {
245
+ page = node('dialog', undefined, 'subagent-page'); page.id = 'subagent-page'; page.setAttribute('aria-labelledby', 'subagent-page-title')
246
+ const head = node('header', undefined, 'subagent-page-head')
247
+ const back = button(text('‹ 返回对话', '‹ Back to chat'), () => root.DshSubagents.close(), 'subagent-page-back')
248
+ const titleBlock = node('div', undefined, 'subagent-page-heading'); titleBlock.append(node('span', text('会话 / 子代理', 'Conversation / Subagents'), 'subtree-eyebrow'))
249
+ pageTitle = node('h2'); pageTitle.id = 'subagent-page-title'; titleBlock.append(pageTitle); head.append(back, titleBlock)
250
+ pageBody = node('div', undefined, 'subagent-page-content'); page.append(head, pageBody)
251
+ page.addEventListener('close', () => { if (view?.options.valid()) view.options.onClose?.(); root.DshSubagents.pause() }); document.body.append(page)
252
+ }
253
+ pageTitle.textContent = options.title || options.sessionId
254
+ if (!page.open) { page.showModal(); options.onShow?.() }
255
+ if (!view || view.id !== options.sessionId || !view.options.valid()) {
256
+ const expanded = memories.get(options.sessionId) || new Set(); expanded.add(options.sessionId); memories.set(options.sessionId, expanded)
257
+ }
258
+ pageBody.replaceChildren(); root.DshSubagents.mount(pageBody, options)
259
+ },
260
+ close() { if (page?.open) { page.close(); root.DshSubagents.pause() } },
261
+ mount(target, options) {
262
+ if (!target || !options.valid()) return
263
+ if (!view || view.id !== options.sessionId || !view.options.valid()) {
264
+ if (view) memories.set(view.id, view.expanded)
265
+ if (memories.size > 20) memories.delete(memories.keys().next().value)
266
+ view = { id: options.sessionId, options, expanded: memories.get(options.sessionId) || new Set([options.sessionId]), cache: new Map(), paused: false, query: '', filter: 'all', selected: 'root' }; shell(view)
267
+ }
268
+ view.options = options; view.paused = false; target.append(view.el); paint(view)
269
+ const cached = view.cache.get(view.id)
270
+ if (cached?.value && Date.now() - cached.updatedAt >= 10000) void refresh(view); else void read(view, view.id)
271
+ },
272
+ pause() { if (view) view.paused = true },
273
+ reset() { root.DshSubagents.close(); view = null; memories.clear() },
274
+ }
275
+ })(window)
@@ -1,9 +1,9 @@
1
1
  {
2
- "version": "0.7.6",
2
+ "version": "0.8.0-rc.3",
3
3
  "apkUrl": "dsh-remote.apk",
4
- "sha256": "33e85026a3b95f341ade14b1ee97db9ac2dea97a4ef3f55976be86e7a2655e1d",
5
- "releasedAt": "2026-10-15T04:38:27.277Z",
6
- "notes": "修复长提问占满会话导致无法回答,支持点击摘要卡片并在独立滚动弹窗中选择;补齐 Android 后台审批与提问通知、请求去重及会话跳转;支持普通相对路径聊天文件下载,并反馈系统下载完成或失败原因。",
4
+ "sha256": "cda79a6d4c43bac042b6b47bbdd141c3f7c6e0ac20c7a455b9fe204d32822908",
5
+ "releasedAt": "2026-10-17T12:41:14.228Z",
6
+ "notes": "0.8.0 开发者预览 rc.3:适配 DSH 0.2.1,新增独立子代理树形页面,统一二级设置界面;精简思考与工具调用展示并保留展开状态;支持重新下载同版本补丁安装包并校验 SHA-256;修复审批展示、公告与返回导航等测试反馈;峰谷提醒交由 dsh-cost-meter 管理,停用 Remote 独立提醒服务。",
7
7
  "history": [
8
8
  {
9
9
  "version": "0.7.6",
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "0.7.6"
2
+ "version": "0.8.0-rc.3"
3
3
  }