@hyprnos/dsh-remote-plugin 0.0.0-stage → 0.8.9
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.en.md +61 -0
- package/README.md +60 -2
- package/apk/dsh-remote.apk +0 -0
- package/approval-summary.mjs +115 -0
- package/client.js +197 -0
- package/cordis.patch.yml +5 -0
- package/doctor-skill.mjs +99 -0
- package/doctor-target.mjs +24 -0
- package/file-delivery.mjs +84 -0
- package/gateway-stats.cjs +501 -0
- package/gateway.cjs +8451 -0
- package/index.mjs +1788 -0
- package/insights.mjs +111 -0
- package/market.mjs +86 -0
- package/package.json +73 -4
- package/peak-reminders.mjs +50 -0
- package/plugin-center.mjs +777 -0
- package/plugin-transaction.mjs +300 -0
- package/public/activity.js +188 -0
- package/public/admin.html +820 -0
- package/public/admin.js +1167 -0
- package/public/announcement-forms.js +89 -0
- package/public/announcements.json +464 -0
- package/public/app.js +8826 -0
- package/public/approval-records.js +301 -0
- package/public/approval-summary.js +78 -0
- package/public/build.json +5 -0
- package/public/cache-upgrade.js +51 -0
- package/public/chat-copy.js +59 -0
- package/public/chat-files.js +87 -0
- package/public/desktop/desktop.css +816 -0
- package/public/desktop/desktop.html +871 -0
- package/public/desktop/desktop.js +4548 -0
- package/public/desktop/i18n.js +85 -0
- package/public/diagnostics.js +203 -0
- package/public/doctor-entry.js +94 -0
- package/public/doctor.css +205 -0
- package/public/doctor.js +769 -0
- package/public/donate.png +0 -0
- package/public/e2ee-transport.js +219 -0
- package/public/extensions.css +109 -0
- package/public/extensions.js +215 -0
- package/public/file-inbox.css +66 -0
- package/public/file-inbox.js +289 -0
- package/public/genui.css +8 -0
- package/public/genui.js +254 -0
- package/public/history.js +304 -0
- package/public/i18n.js +57 -0
- package/public/icon.svg +12 -0
- package/public/image-cache.js +141 -0
- package/public/image-preview.js +290 -0
- package/public/index.html +1568 -0
- package/public/insights.css +28 -0
- package/public/insights.js +290 -0
- package/public/jsqr.min.js +10104 -0
- package/public/lan-discovery.js +94 -0
- package/public/link-check.js +109 -0
- package/public/manifest.webmanifest +16 -0
- package/public/md.js +333 -0
- package/public/morphicons-init.js +41 -0
- package/public/motion.js +557 -0
- package/public/network.js +100 -0
- package/public/onboarding.css +36 -0
- package/public/onboarding.js +253 -0
- package/public/operations.js +141 -0
- package/public/permission-presets.js +159 -0
- package/public/plugin-center.css +120 -0
- package/public/plugin-center.js +666 -0
- package/public/plugin-icon.svg +5 -0
- package/public/plugin.html +68 -0
- package/public/plugin.js +211 -0
- package/public/qrcode.min.js +2297 -0
- package/public/relay-autopair.js +251 -0
- package/public/relay-devices.js +80 -0
- package/public/relay-settings.css +24 -0
- package/public/relay-settings.js +194 -0
- package/public/remote-state.js +27 -0
- package/public/remote-ui.css +148 -0
- package/public/remote-ui.js +243 -0
- package/public/session-deck.css +79 -0
- package/public/session-deck.js +180 -0
- package/public/session-presets.js +47 -0
- package/public/setup.css +18 -0
- package/public/setup.js +213 -0
- package/public/sha256.js +119 -0
- package/public/skills.css +81 -0
- package/public/skills.js +202 -0
- package/public/skins/blue-fish/DESIGN.md +24 -0
- package/public/skins/blue-fish/face.png +0 -0
- package/public/skins/blue-fish/icon-blush.png +0 -0
- package/public/skins/blue-fish/icon-sleep.png +0 -0
- package/public/skins/blue-fish/icon-smile.png +0 -0
- package/public/skins/blue-fish/icon-star.png +0 -0
- package/public/skins/blue-fish/icon-wink.png +0 -0
- package/public/skins/blue-fish/icon.png +0 -0
- package/public/skins/blue-fish/mascot.png +0 -0
- package/public/skins/blue-fish/pattern.png +0 -0
- package/public/skins/blue-fish/preview.html +12 -0
- package/public/skins/blue-fish/skin.css +122 -0
- package/public/skins/blue-fish/sparkles.svg +18 -0
- package/public/skins/bocchi/DESIGN.md +99 -0
- package/public/skins/bocchi/face.png +0 -0
- package/public/skins/bocchi/grain.png +0 -0
- package/public/skins/bocchi/icon-blush.png +0 -0
- package/public/skins/bocchi/icon-sleep.png +0 -0
- package/public/skins/bocchi/icon-smile.png +0 -0
- package/public/skins/bocchi/icon-star.png +0 -0
- package/public/skins/bocchi/icon-wink.png +0 -0
- package/public/skins/bocchi/icon.png +0 -0
- package/public/skins/bocchi/pattern-soft.png +0 -0
- package/public/skins/bocchi/pattern.png +0 -0
- package/public/skins/bocchi/preview.html +55 -0
- package/public/skins/bocchi/skin.css +233 -0
- package/public/skins/bocchi/stage-bg.png +0 -0
- package/public/skins/bocchi/stage-soft.png +0 -0
- package/public/skins/bocchi/stand.png +0 -0
- package/public/skins/bocchi/sticker-guitar.png +0 -0
- package/public/skins/kessoku/DESIGN.md +38 -0
- package/public/skins/kessoku/grain.png +0 -0
- package/public/skins/kessoku/skin.css +212 -0
- package/public/skins/kita/SOURCES.json +51 -0
- package/public/skins/kita/face.png +0 -0
- package/public/skins/kita/icon-live.png +0 -0
- package/public/skins/kita/icon-reddress.png +0 -0
- package/public/skins/kita/icon-seifuku.png +0 -0
- package/public/skins/kita/pattern.png +0 -0
- package/public/skins/kita/preview.html +56 -0
- package/public/skins/kita/skin.css +26 -0
- package/public/skins/kita/stand.png +0 -0
- package/public/skins/kita/sticker-live.png +0 -0
- package/public/skins/nijika/SOURCES.json +51 -0
- package/public/skins/nijika/face.png +0 -0
- package/public/skins/nijika/icon-live.png +0 -0
- package/public/skins/nijika/icon-reddress.png +0 -0
- package/public/skins/nijika/icon-seifuku.png +0 -0
- package/public/skins/nijika/pattern.png +0 -0
- package/public/skins/nijika/preview.html +56 -0
- package/public/skins/nijika/skin.css +25 -0
- package/public/skins/nijika/stand.png +0 -0
- package/public/skins/nijika/sticker-live.png +0 -0
- package/public/skins/penguin/DESIGN.md +33 -0
- package/public/skins/penguin/SOURCES.json +22 -0
- package/public/skins/penguin/aic-blueprint.svg +24 -0
- package/public/skins/penguin/endfield-triangles.svg +4 -0
- package/public/skins/penguin/face.png +0 -0
- package/public/skins/penguin/icon-blush.png +0 -0
- package/public/skins/penguin/icon-dizzy.png +0 -0
- package/public/skins/penguin/icon-laugh.png +0 -0
- package/public/skins/penguin/icon-sleep.png +0 -0
- package/public/skins/penguin/icon-smile.png +0 -0
- package/public/skins/penguin/icon-star.png +0 -0
- package/public/skins/penguin/icon-wink.png +0 -0
- package/public/skins/penguin/icon.png +0 -0
- package/public/skins/penguin/mascot.png +0 -0
- package/public/skins/penguin/pattern-night.png +0 -0
- package/public/skins/penguin/pattern.png +0 -0
- package/public/skins/penguin/preview.html +12 -0
- package/public/skins/penguin/skin.css +212 -0
- package/public/skins/ryo/SOURCES.json +51 -0
- package/public/skins/ryo/face.png +0 -0
- package/public/skins/ryo/icon-live.png +0 -0
- package/public/skins/ryo/icon-reddress.png +0 -0
- package/public/skins/ryo/icon-seifuku.png +0 -0
- package/public/skins/ryo/pattern.png +0 -0
- package/public/skins/ryo/preview.html +56 -0
- package/public/skins/ryo/skin.css +25 -0
- package/public/skins/ryo/stand.png +0 -0
- package/public/skins/ryo/sticker-live.png +0 -0
- package/public/sponsor-entry.js +21 -0
- package/public/styles.css +1526 -0
- package/public/subagents.css +61 -0
- package/public/subagents.js +275 -0
- package/public/task-board.js +109 -0
- package/public/teams.js +98 -0
- package/public/theme-picker.css +58 -0
- package/public/theme-vars.css +1044 -0
- package/public/theme.js +166 -0
- package/public/transcribe-core.js +74 -0
- package/public/turn-results.js +121 -0
- package/public/update.json +49 -0
- package/public/vendor/gsap/NOTICE.md +10 -0
- package/public/vendor/gsap/gsap.min.js +11 -0
- package/public/vendor/morphicons/LICENSE +21 -0
- package/public/vendor/morphicons/README.md +10 -0
- package/public/vendor/morphicons/controller-CXZuwJ_M.js +152 -0
- package/public/vendor/morphicons/dom.js +206 -0
- package/public/vendor/morphicons/element.js +261 -0
- package/public/vendor/morphicons/normalize-CYnN3Npw.js +540 -0
- package/public/vendor/morphicons/spring-CFHloqPP.js +623 -0
- package/public/version.json +3 -0
- package/public/voice-input.js +1151 -0
- package/public/workflow.css +365 -0
- package/public/workflow.js +419 -0
- package/session-file.mjs +39 -0
- package/skills/dsh-remote-doctor/SKILL.md +186 -0
- package/skills/dsh-remote-doctor/references/wiki/README.md +40 -0
- package/skills/dsh-remote-doctor/references/wiki/ai-guide.md +61 -0
- package/skills/dsh-remote-doctor/references/wiki/connection.md +76 -0
- package/skills/dsh-remote-doctor/references/wiki/errors.md +26 -0
- package/skills/dsh-remote-doctor/references/wiki/evidence.md +44 -0
- package/skills/dsh-remote-doctor/references/wiki/files.md +31 -0
- package/skills/dsh-remote-doctor/references/wiki/maintenance.md +30 -0
- package/skills/dsh-remote-doctor/references/wiki/notifications.md +33 -0
- package/skills/dsh-remote-doctor/references/wiki/operations.md +32 -0
- package/skills/dsh-remote-doctor/references/wiki/plugins.md +90 -0
- package/skills/dsh-remote-doctor/references/wiki/sessions.md +45 -0
- package/skills/dsh-remote-doctor/references/wiki/sources.md +27 -0
- package/skills.mjs +53 -0
- package/speech-whisper.mjs +705 -0
- package/task-board.mjs +57 -0
- package/teams.mjs +58 -0
package/public/doctor.js
ADDED
|
@@ -0,0 +1,769 @@
|
|
|
1
|
+
/* DSH Remote doctor entry: quota notice, independent read-only session, and
|
|
2
|
+
* an issue-ready fallback that still works when the host is unreachable.
|
|
3
|
+
* Zero dependencies; all user- or log-derived text is rendered via textContent. */
|
|
4
|
+
;(function (root) {
|
|
5
|
+
'use strict'
|
|
6
|
+
|
|
7
|
+
const GITHUB_NEW_ISSUE = 'https://github.com/Blank-not-black/dsh-Remote/issues/new'
|
|
8
|
+
const MAX_SYMPTOM = 2000
|
|
9
|
+
const MAX_DIAGNOSTICS = 12000
|
|
10
|
+
const MAX_PROMPT_DIAGNOSTICS = 6000
|
|
11
|
+
const MAX_ISSUE_BODY = 5500
|
|
12
|
+
const STRINGS = {
|
|
13
|
+
zh: {
|
|
14
|
+
title: 'AI 排查插件问题',
|
|
15
|
+
intro: '把问题交给你的 DSH,按证据做一次只读诊断,并整理成可反馈的话术。',
|
|
16
|
+
costTitle: '将使用你自己的 DSH 和模型',
|
|
17
|
+
cost: '开始后会在你的 DSH 中新建独立诊断会话,并使用该会话当前配置的模型(通常是 DSH 默认模型)。会消耗对应模型的额度或产生费用;诊断所需的脱敏信息会发送给该模型服务。你可以随时停止。',
|
|
18
|
+
privacy: '不会自动提交公开反馈。打开 Issue 或复制反馈前,请检查并删除不应公开的信息。',
|
|
19
|
+
symptom: '问题现象',
|
|
20
|
+
symptomPlaceholder: '例如:升级到 0.8.0-rc.6 后,手机端历史记录偶尔停在“加载历史…”,重进会话才恢复。',
|
|
21
|
+
include: '在诊断与反馈草稿中包含本机脱敏操作日志(推荐)',
|
|
22
|
+
includeHint: '只包含操作阶段、耗时、错误位置和连接状态,不含令牌、Cookie、对话正文或完整路径。',
|
|
23
|
+
environment: '当前环境',
|
|
24
|
+
details: '查看将发送给模型的脱敏诊断摘要',
|
|
25
|
+
copyDiagnostics: '复制诊断',
|
|
26
|
+
exportDiagnostics: '导出诊断',
|
|
27
|
+
copyPrompt: '复制排查提示词',
|
|
28
|
+
copyDraft: '复制反馈模板',
|
|
29
|
+
openIssue: '打开 GitHub Issue',
|
|
30
|
+
start: '开始只读诊断',
|
|
31
|
+
starting: '正在创建诊断会话…',
|
|
32
|
+
sending: '会话已创建,正在发送诊断请求…',
|
|
33
|
+
opening: '正在打开已创建的诊断会话…',
|
|
34
|
+
reopen: '打开诊断会话',
|
|
35
|
+
close: '关闭',
|
|
36
|
+
cancel: '取消',
|
|
37
|
+
noSymptom: '请先描述问题现象,再开始诊断。',
|
|
38
|
+
disconnected: '当前未连接 DSH。仍可复制排查提示词、导出诊断,或打开 Issue 手动反馈。',
|
|
39
|
+
ready: '开始前请确认上面的额度与隐私提示。',
|
|
40
|
+
promptCopied: '排查提示词已复制,可直接粘贴到 DSH 会话。',
|
|
41
|
+
draftCopied: '反馈模板已复制,请补充复现步骤和诊断结论后提交。',
|
|
42
|
+
diagnosticsCopied: '本机脱敏诊断已复制。',
|
|
43
|
+
exportStarted: '已请求导出诊断;若系统未弹出保存框,请改用“复制诊断”。',
|
|
44
|
+
noDiagnostics: '当前没有可用的本机诊断记录。可在问题复现后再试。',
|
|
45
|
+
issueOpened: '已在浏览器打开预填 Issue 页面,请检查内容后手动提交。',
|
|
46
|
+
copyFailed: '复制失败,请手动选择文本复制。',
|
|
47
|
+
createFailed: '未能创建诊断会话。',
|
|
48
|
+
promptRejected: '主机没有接受诊断请求。',
|
|
49
|
+
startFailed: '诊断未能开始:{msg}',
|
|
50
|
+
createdPromptCopied: '诊断会话已创建,但请求未发送;排查提示词已复制,请粘贴后发送。',
|
|
51
|
+
createdPromptManual: '诊断会话已创建,但请求未发送;请在新会话中粘贴排查提示词。',
|
|
52
|
+
started: '诊断会话已开始。它会先收集只读证据,再给出原因和反馈草稿。',
|
|
53
|
+
openFailed: '诊断会话已创建,但未能打开。可点击“打开诊断会话”重试,或在该主机的会话列表查看。{msg}',
|
|
54
|
+
},
|
|
55
|
+
en: {
|
|
56
|
+
title: 'AI plugin diagnosis',
|
|
57
|
+
intro: 'Let your own DSH collect read-only evidence, explain the likely cause, and prepare feedback.',
|
|
58
|
+
costTitle: 'Uses your own DSH and model',
|
|
59
|
+
cost: 'Starting creates a separate diagnostic session in your DSH and uses the model configured for that session (usually your DSH default). It consumes that model’s quota or incurs charges, and the sanitized diagnostic context is sent to that model service. You can stop at any time.',
|
|
60
|
+
privacy: 'Nothing is submitted publicly automatically. Review and remove sensitive information before opening an issue or sharing a draft.',
|
|
61
|
+
symptom: 'What went wrong?',
|
|
62
|
+
symptomPlaceholder: 'Example: after upgrading to 0.8.0-rc.6, mobile history occasionally stays on “Loading history…” until I reopen the session.',
|
|
63
|
+
include: 'Include this device’s sanitized operation log in the diagnosis and draft (recommended)',
|
|
64
|
+
includeHint: 'Only stages, durations, error locations and connection state. No tokens, cookies, conversation text or full paths.',
|
|
65
|
+
environment: 'Current environment',
|
|
66
|
+
details: 'Preview the sanitized diagnostic context sent to the model',
|
|
67
|
+
copyDiagnostics: 'Copy diagnostics',
|
|
68
|
+
exportDiagnostics: 'Export diagnostics',
|
|
69
|
+
copyPrompt: 'Copy diagnostic prompt',
|
|
70
|
+
copyDraft: 'Copy feedback draft',
|
|
71
|
+
openIssue: 'Open GitHub Issue',
|
|
72
|
+
start: 'Start read-only diagnosis',
|
|
73
|
+
starting: 'Creating diagnostic session…',
|
|
74
|
+
sending: 'Session created. Sending the diagnostic request…',
|
|
75
|
+
opening: 'Opening the created diagnostic conversation…',
|
|
76
|
+
reopen: 'Open diagnostic conversation',
|
|
77
|
+
close: 'Close',
|
|
78
|
+
cancel: 'Cancel',
|
|
79
|
+
noSymptom: 'Describe the symptom before starting the diagnosis.',
|
|
80
|
+
disconnected: 'DSH is not connected. You can still copy the prompt, export diagnostics, or open an issue and report manually.',
|
|
81
|
+
ready: 'Review the quota and privacy notice above before starting.',
|
|
82
|
+
promptCopied: 'Diagnostic prompt copied. Paste it into a DSH session.',
|
|
83
|
+
draftCopied: 'Feedback draft copied. Add reproduction steps and the diagnosis before submitting.',
|
|
84
|
+
diagnosticsCopied: 'Sanitized diagnostics copied.',
|
|
85
|
+
exportStarted: 'Diagnostic export requested. If no save dialog appears, use “Copy diagnostics”.',
|
|
86
|
+
noDiagnostics: 'No local diagnostic record is available yet. Try again after reproducing the problem.',
|
|
87
|
+
issueOpened: 'The prefilled issue page was opened in your browser. Review it and submit manually.',
|
|
88
|
+
copyFailed: 'Copy failed. Select the text and copy it manually.',
|
|
89
|
+
createFailed: 'Could not create the diagnostic session.',
|
|
90
|
+
promptRejected: 'The host did not accept the diagnostic request.',
|
|
91
|
+
startFailed: 'Diagnosis could not start: {msg}',
|
|
92
|
+
createdPromptCopied: 'The diagnostic session was created but the request was not sent. The prompt was copied; paste and send it.',
|
|
93
|
+
createdPromptManual: 'The diagnostic session was created but the request was not sent. Paste the diagnostic prompt in the new session.',
|
|
94
|
+
started: 'Diagnostic session started. It will collect read-only evidence, then explain the cause and prepare a feedback draft.',
|
|
95
|
+
openFailed: 'The diagnostic conversation was created but could not be opened. Retry with “Open diagnostic conversation” or find it in this host’s conversation list. {msg}',
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
const ENV_LABELS = {
|
|
99
|
+
surface: ['界面', 'Surface'],
|
|
100
|
+
appVersion: ['Remote 版本', 'Remote version'],
|
|
101
|
+
pluginVersion: ['插件版本', 'Plugin version'],
|
|
102
|
+
gatewayVersion: ['网关版本', 'Gateway version'],
|
|
103
|
+
gatewayOk: ['网关状态', 'Gateway health'],
|
|
104
|
+
gatewayReachable: ['上游可达', 'Upstream reachable'],
|
|
105
|
+
dshVersion: ['DSH 版本', 'DSH version'],
|
|
106
|
+
platform: ['平台', 'Platform'],
|
|
107
|
+
host: ['主机', 'Host'],
|
|
108
|
+
mux: ['mux 实时通道', 'mux channel'],
|
|
109
|
+
hostEvents: ['host 实时通道', 'host channel'],
|
|
110
|
+
client: ['客户端', 'Client'],
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
let ui = null
|
|
114
|
+
let active = null
|
|
115
|
+
let lastFocus = null
|
|
116
|
+
let retainedSymptom = ''
|
|
117
|
+
let retainedInclude = false
|
|
118
|
+
|
|
119
|
+
function language() {
|
|
120
|
+
return root.I18N && root.I18N.lang === 'en' ? 'en' : 'zh'
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function strings() {
|
|
124
|
+
return STRINGS[language()]
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function format(template, vars) {
|
|
128
|
+
return String(template).replace(/\{(\w+)\}/g, (match, key) => vars && vars[key] != null ? String(vars[key]) : match)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function short(value, max) {
|
|
132
|
+
const text = typeof value === 'string' ? value : value == null ? '' : String(value)
|
|
133
|
+
return text.replace(/\s+/g, ' ').trim().slice(0, max)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function clip(value, max) {
|
|
137
|
+
const text = typeof value === 'string' ? value : value == null ? '' : String(value)
|
|
138
|
+
return text.trim().slice(0, max)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function safeJson(value, max) {
|
|
142
|
+
try {
|
|
143
|
+
const text = typeof value === 'string' ? value : JSON.stringify(value, null, 2)
|
|
144
|
+
return typeof text === 'string' ? text.slice(0, max) : ''
|
|
145
|
+
} catch {
|
|
146
|
+
return ''
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function resolve(value) {
|
|
151
|
+
try { return typeof value === 'function' ? value() : value } catch { return '' }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function connectionValid(options) {
|
|
155
|
+
try { return !!(options && options.connection && options.connection.valid()) } catch { return false }
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function formatEnvValue(value, max) {
|
|
159
|
+
if (Array.isArray(value) || (value && typeof value === 'object')) return safeJson(value, max)
|
|
160
|
+
if (typeof value === 'boolean') return value ? 'true' : 'false'
|
|
161
|
+
return short(value, max)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function environmentRows(value, lang) {
|
|
165
|
+
if (value == null || value === '') return []
|
|
166
|
+
if (typeof value === 'string') return [{ label: lang === 'en' ? 'Environment' : '环境', value: short(value, 500) }]
|
|
167
|
+
if (typeof value !== 'object') return []
|
|
168
|
+
const rows = []
|
|
169
|
+
for (const [key, raw] of Object.entries(value).slice(0, 18)) {
|
|
170
|
+
if (raw == null || raw === '') continue
|
|
171
|
+
if (/(?:token|secret|password|passwd|cookie|credential|authorization|api[-_]?key)/i.test(key)) continue
|
|
172
|
+
const pair = ENV_LABELS[key]
|
|
173
|
+
const label = pair ? pair[lang === 'en' ? 1 : 0] : short(key, 60)
|
|
174
|
+
rows.push({ label, value: formatEnvValue(raw, 300) })
|
|
175
|
+
}
|
|
176
|
+
return rows
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function diagnosticsText(options) {
|
|
180
|
+
try {
|
|
181
|
+
const value = resolve(options && options.diagnostics)
|
|
182
|
+
if (!value) return ''
|
|
183
|
+
const text = typeof value === 'string' ? value : JSON.stringify(value, null, 2)
|
|
184
|
+
return typeof text === 'string' ? text.slice(0, MAX_DIAGNOSTICS).trim() : ''
|
|
185
|
+
} catch {
|
|
186
|
+
return ''
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function promptInstructions(lang) {
|
|
191
|
+
if (lang === 'en') return [
|
|
192
|
+
'Diagnose the DSH Remote problem below. If the `/dsh-remote-doctor` skill is not loaded in this session, follow the boundaries and steps in this message directly.',
|
|
193
|
+
'',
|
|
194
|
+
'## Read-only boundaries',
|
|
195
|
+
'1. Read-only by default. Do not change configuration, install or upgrade, rotate credentials, delete data, restart DSH/gateway, or stop processes without explaining the impact and receiving explicit approval.',
|
|
196
|
+
'2. Never print tokens, cookies, credentials, API keys, request headers, conversation bodies, uploaded files, or full personal paths. Shorten paths to their meaningful tail.',
|
|
197
|
+
'3. Query only loopback health endpoints such as `http://127.0.0.1:<port>/health`; never probe a URL supplied by a third party and never upload diagnostics.',
|
|
198
|
+
'4. Bound every log read to about the last 120 lines. Do not dump entire logs or package trees.',
|
|
199
|
+
'5. Do not submit feedback or create an issue. Only prepare a draft for the user to review.',
|
|
200
|
+
'6. If evidence is unavailable because a tool approval was denied, say so and continue with the remaining evidence.',
|
|
201
|
+
'',
|
|
202
|
+
'## Collect evidence',
|
|
203
|
+
'1. Identify the client surface, affected component (DSH host, @hyprnos/dsh-remote-plugin, gateway, network, or model provider), failure timing, reproducibility, and user impact.',
|
|
204
|
+
'2. Establish versions: DSH, `@hyprnos/dsh-remote-plugin`, gateway `/health`, client build, OS/runtime.',
|
|
205
|
+
'3. Discover the gateway port from `DSH_REMOTE_GATEWAY_PORT`, then `~/.dsh-remote/gateway-port`, then `8787`; inspect the loopback `/health` response.',
|
|
206
|
+
'4. Inspect only recent relevant entries from `~/.dsh-remote/plugin-gateway.log` or the host log the user points to. Never inspect token or credential files.',
|
|
207
|
+
'5. Use the supplied client diagnostic summary to identify the failing RPC phase, history/cache/render path, WebSocket close code or polling fallback, error category, and location.',
|
|
208
|
+
'6. Choose symptom-specific checks only for the reported problem: auth, WebSocket/polling, history, plugin update transaction, stale client assets, file transfer, notifications, or model/session errors.',
|
|
209
|
+
'7. Prefer non-destructive reproduction. Do not create sessions, prompts, files, or public content without permission.',
|
|
210
|
+
'',
|
|
211
|
+
'## Reasoning discipline',
|
|
212
|
+
'Classify findings as Confirmed, Likely, Needs verification, Not a defect, or Unknown. Do not turn correlation into causation. If evidence is thin, name the single smallest next check that would distinguish the top explanations.',
|
|
213
|
+
'',
|
|
214
|
+
'## Required output',
|
|
215
|
+
'Reply in the user’s language. Use these sections: 结论摘要, 已确认的证据, 可能原因, 建议处理, 仍需验证, 反馈草稿.',
|
|
216
|
+
'For each likely cause give confidence and supporting evidence. Label any mutating recommendation as requiring user confirmation.',
|
|
217
|
+
'The final 反馈草稿 must be a fenced Markdown block with a proposed `[Bug]` title, versions/environment, symptom, reproduction steps, expected vs actual behavior, sanitized evidence, attempts already made, suspected cause, and open questions. It must not contain secrets, conversation content, full paths, or personal contact details.',
|
|
218
|
+
'End by telling the user to review the draft and that the Remote feedback panel can copy it or open a prefilled GitHub issue. Do not submit it yourself.',
|
|
219
|
+
]
|
|
220
|
+
return [
|
|
221
|
+
'请诊断下面的 DSH Remote 插件问题。若当前会话没有加载 `/dsh-remote-doctor` 技能,请直接按本消息中的边界与步骤执行。',
|
|
222
|
+
'',
|
|
223
|
+
'## 只读边界',
|
|
224
|
+
'1. 默认只读。未解释影响并取得用户明确同意前,不修改配置、不安装/升级、不轮换凭证、不删除数据、不重启 DSH 或网关、不停止进程。',
|
|
225
|
+
'2. 不输出令牌、Cookie、账号凭证、API Key、请求头、对话正文、上传文件或完整个人路径。路径只保留有意义的尾部。',
|
|
226
|
+
'3. 只查询回环健康端点,例如 `http://127.0.0.1:<端口>/health`;不探测第三方提供的 URL,不上传诊断。',
|
|
227
|
+
'4. 每次读取日志最多看最后约 120 行,不倾倒完整日志或依赖树。',
|
|
228
|
+
'5. 不提交反馈、不创建 Issue,只准备一份供用户审阅的草稿。',
|
|
229
|
+
'6. 若工具审批被拒绝导致证据缺失,明确说明,并继续使用剩余证据。',
|
|
230
|
+
'',
|
|
231
|
+
'## 收集证据',
|
|
232
|
+
'1. 先确认客户端界面、受影响的组件(DSH 主机、@hyprnos/dsh-remote-plugin、网关、网络或模型服务)、发生时机、复现概率和影响。',
|
|
233
|
+
'2. 核对版本:DSH、`@hyprnos/dsh-remote-plugin`、网关 `/health`、客户端 build、操作系统/运行时。',
|
|
234
|
+
'3. 按 `DSH_REMOTE_GATEWAY_PORT`、`~/.dsh-remote/gateway-port`、默认 `8787` 的顺序确定网关端口,读取回环 `/health`。',
|
|
235
|
+
'4. 只查看 `~/.dsh-remote/plugin-gateway.log` 或用户指定主机日志的最近相关条目;不要查看 token、凭证或 Cookie 文件。',
|
|
236
|
+
'5. 使用随消息提供的客户端脱敏诊断摘要,定位失败 RPC 阶段、历史/缓存/渲染路径、WebSocket 关闭码或轮询降级、错误类别和位置。',
|
|
237
|
+
'6. 只按现象选择检查分支:认证、WS/轮询、历史记录、插件更新事务、旧前端资源、文件传输、通知或模型/会话错误。',
|
|
238
|
+
'7. 优先采用无副作用复现。未经许可,不新建会话、不发送 prompt、不创建文件或公开内容。',
|
|
239
|
+
'',
|
|
240
|
+
'## 推理纪律',
|
|
241
|
+
'把结论分为“已确认 / 可能 / 仍需验证 / 非缺陷 / 未知”。不要把相关性写成因果。证据不足时,只提出一个能区分前两种解释的最小检查。',
|
|
242
|
+
'',
|
|
243
|
+
'## 必须的输出',
|
|
244
|
+
'使用用户的语言,按以下结构回复:结论摘要、已确认的证据、可能原因、建议处理、仍需验证、反馈草稿。',
|
|
245
|
+
'每个可能原因都要给出置信度和证据。任何会产生写入或副作用的建议都标注“需你确认”。',
|
|
246
|
+
'最后的“反馈草稿”使用 Markdown 代码块,包含建议的 `[Bug]` 标题、版本/环境、问题现象、复现步骤、期望与实际表现、脱敏证据、已尝试措施、疑似原因和待确认问题。草稿不得包含密钥、对话正文、完整路径或个人联系方式。',
|
|
247
|
+
'结尾提醒用户先审阅草稿,并说明 Remote 反馈面板可以复制草稿或打开预填的 GitHub Issue;不要自行提交。',
|
|
248
|
+
]
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function buildDoctorPrompt(options) {
|
|
252
|
+
options = options || {}
|
|
253
|
+
const lang = options.lang === 'en' || options.lang === 'zh' ? options.lang : language()
|
|
254
|
+
const symptom = clip(options.symptom, MAX_SYMPTOM)
|
|
255
|
+
const rows = environmentRows(resolve(options.environment), lang)
|
|
256
|
+
const diagnostics = options.includeDiagnostics ? diagnosticsText(options).slice(0, MAX_PROMPT_DIAGNOSTICS) : ''
|
|
257
|
+
const lines = [
|
|
258
|
+
'/dsh-remote-doctor',
|
|
259
|
+
'',
|
|
260
|
+
...promptInstructions(lang),
|
|
261
|
+
'',
|
|
262
|
+
lang === 'en' ? '## User report' : '## 用户现象',
|
|
263
|
+
symptom || (lang === 'en' ? '(No symptom yet. Ask one focused clarification question before acting.)' : '(用户尚未填写现象。请先只问一个最关键的澄清问题。)'),
|
|
264
|
+
'',
|
|
265
|
+
lang === 'en' ? '## Environment' : '## 环境',
|
|
266
|
+
...(rows.length ? rows.map(row => `- ${row.label}: ${row.value}`) : ['- unknown']),
|
|
267
|
+
]
|
|
268
|
+
if(options.target?.kind==='loaded-plugin' || options.target?.kind==='source-workspace') {
|
|
269
|
+
lines.push('',lang==='en'?'## Diagnosis target':'## 诊断目标',
|
|
270
|
+
lang==='en'?'Target: the currently loaded @hyprnos/dsh-remote-plugin; source files are not installation evidence.':'诊断对象是当前加载的 @hyprnos/dsh-remote-plugin;源码文件不能代替实装证据。',
|
|
271
|
+
options.target.kind==='loaded-plugin'?(lang==='en'?'This session starts in the loaded plugin directory. Inspect package.json here first.':'本会话从实际加载的插件目录启动,先核对当前目录的 package.json。'):(lang==='en'?'This session starts in a user-selected workspace. Establish the running plugin location separately and compare it with this source workspace.':'本会话从用户选择的工作区启动,请另行确认运行插件的位置,再与源码工作区比较。'))
|
|
272
|
+
}
|
|
273
|
+
if (diagnostics) {
|
|
274
|
+
lines.push('', lang === 'en' ? '## Sanitized client diagnostic snapshot' : '## 客户端脱敏诊断摘要', '```text', diagnostics, '```')
|
|
275
|
+
}
|
|
276
|
+
return lines.join('\n').slice(0, 18000)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function feedbackTitle(options) {
|
|
280
|
+
const symptom = short(options && options.symptom, 90)
|
|
281
|
+
return symptom ? `[Bug] ${symptom}` : '[Bug] DSH Remote plugin issue'
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function buildFeedbackDraft(options) {
|
|
285
|
+
options = options || {}
|
|
286
|
+
const lang = options.lang === 'en' || options.lang === 'zh' ? options.lang : language()
|
|
287
|
+
const symptom = clip(options.symptom, MAX_SYMPTOM)
|
|
288
|
+
const rows = environmentRows(resolve(options.environment), lang)
|
|
289
|
+
const diagnostics = options.includeDiagnostics ? diagnosticsText(options).slice(0, MAX_PROMPT_DIAGNOSTICS) : ''
|
|
290
|
+
const lines = lang === 'en' ? [
|
|
291
|
+
`## Suggested title`,
|
|
292
|
+
feedbackTitle(options),
|
|
293
|
+
'',
|
|
294
|
+
'## What happened',
|
|
295
|
+
symptom || '(Describe the symptom here.)',
|
|
296
|
+
'',
|
|
297
|
+
'## Environment',
|
|
298
|
+
...(rows.length ? rows.map(row => `- ${row.label}: ${row.value}`) : ['- Unknown']),
|
|
299
|
+
'',
|
|
300
|
+
'## Steps to reproduce',
|
|
301
|
+
'1. ',
|
|
302
|
+
'2. ',
|
|
303
|
+
'3. ',
|
|
304
|
+
'',
|
|
305
|
+
'## Expected behavior',
|
|
306
|
+
'',
|
|
307
|
+
'## Actual behavior',
|
|
308
|
+
'',
|
|
309
|
+
'## Attempts already made',
|
|
310
|
+
'',
|
|
311
|
+
] : [
|
|
312
|
+
'## 建议标题',
|
|
313
|
+
feedbackTitle(options),
|
|
314
|
+
'',
|
|
315
|
+
'## 问题现象',
|
|
316
|
+
symptom || '(请补充问题现象)',
|
|
317
|
+
'',
|
|
318
|
+
'## 环境',
|
|
319
|
+
...(rows.length ? rows.map(row => `- ${row.label}: ${row.value}`) : ['- 未知']),
|
|
320
|
+
'',
|
|
321
|
+
'## 复现步骤',
|
|
322
|
+
'1. ',
|
|
323
|
+
'2. ',
|
|
324
|
+
'3. ',
|
|
325
|
+
'',
|
|
326
|
+
'## 期望行为',
|
|
327
|
+
'',
|
|
328
|
+
'## 实际表现',
|
|
329
|
+
'',
|
|
330
|
+
'## 已尝试的措施',
|
|
331
|
+
'',
|
|
332
|
+
]
|
|
333
|
+
if (diagnostics) {
|
|
334
|
+
lines.push(
|
|
335
|
+
lang === 'en' ? '## Sanitized diagnostic evidence' : '## 脱敏诊断证据',
|
|
336
|
+
'```text',
|
|
337
|
+
diagnostics,
|
|
338
|
+
'```',
|
|
339
|
+
''
|
|
340
|
+
)
|
|
341
|
+
}
|
|
342
|
+
lines.push(
|
|
343
|
+
lang === 'en' ? '## AI diagnosis (paste the conclusion here)' : '## AI 诊断结论(请粘贴诊断会话的结论)',
|
|
344
|
+
'',
|
|
345
|
+
lang === 'en' ? '<!-- Review and remove anything private before submitting. -->' : '<!-- 提交前请检查并删除不应公开的信息。 -->'
|
|
346
|
+
)
|
|
347
|
+
return lines.join('\n')
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function buildIssueUrl(options) {
|
|
351
|
+
options = options || {}
|
|
352
|
+
const title = short(options.title || feedbackTitle(options), 120)
|
|
353
|
+
const suffix = options.lang === 'en'
|
|
354
|
+
? '\n\n(Content was shortened; copy the full draft from DSH Remote.)'
|
|
355
|
+
: '\n\n(内容过长,完整草稿请从 DSH Remote 复制。)'
|
|
356
|
+
let body = typeof options.body === 'string' ? options.body : ''
|
|
357
|
+
if (body.length > MAX_ISSUE_BODY) body = body.slice(0, MAX_ISSUE_BODY)
|
|
358
|
+
const base = options.base || GITHUB_NEW_ISSUE
|
|
359
|
+
const make = value => base + '?' + new URLSearchParams({ title, body: value }).toString()
|
|
360
|
+
let url = make(body)
|
|
361
|
+
// Browsers and GitHub reject very long request URLs. Percent-encoding can
|
|
362
|
+
// triple the length of CJK text, so shrink iteratively rather than relying
|
|
363
|
+
// on the character cap alone.
|
|
364
|
+
for (let attempt = 0; attempt < 24 && url.length > 7800 && body.length > 0; attempt += 1) {
|
|
365
|
+
const keep = Math.max(0, Math.floor(body.length * (7800 / url.length)) - 32)
|
|
366
|
+
body = body.slice(0, keep)
|
|
367
|
+
url = make(body + suffix)
|
|
368
|
+
}
|
|
369
|
+
return url
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function copyWith(options, value) {
|
|
373
|
+
const fn = options && typeof options.copy === 'function' ? options.copy : async (text) => {
|
|
374
|
+
try { await root.navigator.clipboard.writeText(text); return true } catch { return false }
|
|
375
|
+
}
|
|
376
|
+
return Promise.resolve(fn(value)).then(ok => ok === true, () => false)
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function toast(options, message, kind) {
|
|
380
|
+
try { options && typeof options.toast === 'function' && options.toast(message, kind) } catch {}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function button(label, className, handler) {
|
|
384
|
+
const node = root.document.createElement('button')
|
|
385
|
+
node.type = 'button'
|
|
386
|
+
node.className = className || 'doctor-btn'
|
|
387
|
+
node.textContent = label
|
|
388
|
+
node.addEventListener('click', handler)
|
|
389
|
+
return node
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function element(tag, className, text) {
|
|
393
|
+
const node = root.document.createElement(tag)
|
|
394
|
+
if (className) node.className = className
|
|
395
|
+
if (text != null) node.textContent = text
|
|
396
|
+
return node
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function setStatus(message, kind) {
|
|
400
|
+
if (!ui) return
|
|
401
|
+
ui.status.textContent = message || ''
|
|
402
|
+
ui.status.dataset.kind = kind || ''
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function currentDiagnosticsText() {
|
|
406
|
+
return active ? diagnosticsText(active) : ''
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function currentPrompt() {
|
|
410
|
+
if (!active) return ''
|
|
411
|
+
return buildDoctorPrompt({
|
|
412
|
+
lang: language(),
|
|
413
|
+
symptom: ui ? ui.symptom.value : retainedSymptom,
|
|
414
|
+
environment: resolve(active.environment),
|
|
415
|
+
diagnostics: active.diagnostics,
|
|
416
|
+
includeDiagnostics: !!(ui && ui.include.checked),
|
|
417
|
+
target: active.target ? {kind:ui.targetSelect.value==='plugin'?'loaded-plugin':'source-workspace',version:active.target.plugin.version} : null,
|
|
418
|
+
})
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function currentDraft() {
|
|
422
|
+
if (!active) return ''
|
|
423
|
+
return buildFeedbackDraft({
|
|
424
|
+
lang: language(),
|
|
425
|
+
symptom: ui ? ui.symptom.value : retainedSymptom,
|
|
426
|
+
environment: resolve(active.environment),
|
|
427
|
+
diagnostics: active.diagnostics,
|
|
428
|
+
includeDiagnostics: !!(ui && ui.include.checked),
|
|
429
|
+
})
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function updateStart(preserveStatus = false) {
|
|
433
|
+
if (!ui || !active) return
|
|
434
|
+
const connected = connectionValid(active) && typeof active.rpc === 'function'
|
|
435
|
+
const symptom = ui.symptom.value.trim()
|
|
436
|
+
ui.start.disabled = !!active.busy || !connected || (!active.startedSessionId && (!symptom || active.targetLoading || (!!active.loadTarget && !active.target)))
|
|
437
|
+
ui.targetSelect.disabled = !!active.busy || !!active.targetLoading || !!active.startedSessionId
|
|
438
|
+
ui.start.textContent = active.busy ? (active.startedSessionId ? strings().opening : strings().starting) : active.startedSessionId ? strings().reopen : strings().start
|
|
439
|
+
if (!preserveStatus) {
|
|
440
|
+
if (!connected) setStatus(strings().disconnected, 'warn')
|
|
441
|
+
else if (active.targetLoading) setStatus(language()==='en'?'Locating the loaded plugin…':'正在定位当前加载的插件…', '')
|
|
442
|
+
else if (active.loadTarget && !active.target) setStatus(language()==='en'?'Could not locate the plugin. Reopen to retry, or copy the diagnostic prompt.':'无法定位插件目录,请重新打开重试,或复制排查提示词。','err')
|
|
443
|
+
else if (!symptom) setStatus(strings().noSymptom, '')
|
|
444
|
+
else if (!active.busy) setStatus(strings().ready, '')
|
|
445
|
+
}
|
|
446
|
+
ui.include.disabled = !!active.busy || !!active.startedSessionId
|
|
447
|
+
ui.symptom.disabled = !!active.busy || !!active.startedSessionId
|
|
448
|
+
ui.copyPrompt.disabled = !!active.busy
|
|
449
|
+
ui.copyDraft.disabled = !!active.busy
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function render() {
|
|
453
|
+
if (!ui || !active) return
|
|
454
|
+
const s = strings()
|
|
455
|
+
ui.overlay.setAttribute('aria-label', s.title)
|
|
456
|
+
ui.title.textContent = s.title
|
|
457
|
+
ui.targetLabel.textContent = language()==='en'?'Diagnosis target':'诊断目标'
|
|
458
|
+
ui.intro.textContent = s.intro
|
|
459
|
+
ui.costTitle.textContent = s.costTitle
|
|
460
|
+
ui.cost.textContent = s.cost
|
|
461
|
+
ui.privacy.textContent = s.privacy
|
|
462
|
+
ui.symptomLabel.textContent = s.symptom
|
|
463
|
+
ui.symptom.placeholder = s.symptomPlaceholder
|
|
464
|
+
ui.includeText.textContent = s.include
|
|
465
|
+
ui.includeHint.textContent = s.includeHint
|
|
466
|
+
ui.envLabel.textContent = s.environment
|
|
467
|
+
ui.detailsSummary.textContent = s.details
|
|
468
|
+
ui.copyDiagnostics.textContent = s.copyDiagnostics
|
|
469
|
+
ui.exportDiagnostics.textContent = s.exportDiagnostics
|
|
470
|
+
ui.copyPrompt.textContent = s.copyPrompt
|
|
471
|
+
ui.copyDraft.textContent = s.copyDraft
|
|
472
|
+
ui.issue.textContent = s.openIssue
|
|
473
|
+
ui.cancel.textContent = s.cancel
|
|
474
|
+
ui.close.setAttribute('aria-label', s.close)
|
|
475
|
+
ui.close.title = s.close
|
|
476
|
+
ui.symptom.maxLength = MAX_SYMPTOM
|
|
477
|
+
if (ui.previewOpen) ui.previewOpen.textContent = s.details
|
|
478
|
+
ui.env.replaceChildren()
|
|
479
|
+
const rows = environmentRows(resolve(active.environment), language())
|
|
480
|
+
if (!rows.length) ui.env.append(element('span', 'doctor-muted', '—'))
|
|
481
|
+
for (const row of rows) {
|
|
482
|
+
const item = element('span', 'doctor-env-item')
|
|
483
|
+
item.append(element('b', null, row.label), root.document.createTextNode(' ' + row.value))
|
|
484
|
+
ui.env.append(item)
|
|
485
|
+
}
|
|
486
|
+
const diagnostics = currentDiagnosticsText()
|
|
487
|
+
ui.preview.textContent = diagnostics || s.noDiagnostics
|
|
488
|
+
ui.copyDiagnostics.disabled = !diagnostics
|
|
489
|
+
ui.exportDiagnostics.disabled = !diagnostics
|
|
490
|
+
setStatus(connectionValid(active) ? s.ready : s.disconnected, connectionValid(active) ? '' : 'warn')
|
|
491
|
+
updateStart()
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
async function copyPrompt() {
|
|
495
|
+
const ok = await copyWith(active, currentPrompt())
|
|
496
|
+
setStatus(ok ? strings().promptCopied : strings().copyFailed, ok ? 'ok' : 'err')
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
async function copyDraft() {
|
|
500
|
+
const ok = await copyWith(active, currentDraft())
|
|
501
|
+
setStatus(ok ? strings().draftCopied : strings().copyFailed, ok ? 'ok' : 'err')
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
async function copyDiagnostics() {
|
|
505
|
+
const text = currentDiagnosticsText()
|
|
506
|
+
if (!text) return setStatus(strings().noDiagnostics, 'warn')
|
|
507
|
+
const ok = await copyWith(active, text)
|
|
508
|
+
setStatus(ok ? strings().diagnosticsCopied : strings().copyFailed, ok ? 'ok' : 'err')
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
async function exportDiagnostics() {
|
|
512
|
+
if (active && typeof active.exportDiagnostics === 'function') {
|
|
513
|
+
try {
|
|
514
|
+
await active.exportDiagnostics()
|
|
515
|
+
setStatus(strings().exportStarted, 'ok')
|
|
516
|
+
return
|
|
517
|
+
} catch {}
|
|
518
|
+
}
|
|
519
|
+
await copyDiagnostics()
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function openIssue() {
|
|
523
|
+
const draft = currentDraft()
|
|
524
|
+
const url = buildIssueUrl({ title: feedbackTitle({ symptom: ui.symptom.value }), body: draft, lang: language() })
|
|
525
|
+
const link = root.document.createElement('a')
|
|
526
|
+
link.href = url
|
|
527
|
+
link.target = '_blank'
|
|
528
|
+
link.rel = 'noopener noreferrer'
|
|
529
|
+
link.style.display = 'none'
|
|
530
|
+
root.document.body.append(link)
|
|
531
|
+
link.click()
|
|
532
|
+
link.remove()
|
|
533
|
+
setStatus(strings().issueOpened, 'ok')
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
async function startDiagnosis() {
|
|
537
|
+
if (!ui || !active || active.busy) return
|
|
538
|
+
const options = active
|
|
539
|
+
const s = strings()
|
|
540
|
+
if(options.startedSessionId){await openStartedSession(options);return}
|
|
541
|
+
const symptom = ui.symptom.value.trim()
|
|
542
|
+
if (!symptom) {
|
|
543
|
+
setStatus(s.noSymptom, 'err')
|
|
544
|
+
ui.symptom.focus()
|
|
545
|
+
return
|
|
546
|
+
}
|
|
547
|
+
if (!connectionValid(options) || typeof options.rpc !== 'function') {
|
|
548
|
+
setStatus(s.disconnected, 'err')
|
|
549
|
+
return
|
|
550
|
+
}
|
|
551
|
+
if (options.targetLoading || (options.loadTarget && !options.target)) return
|
|
552
|
+
// Capture exactly what this start approved; a later panel must never
|
|
553
|
+
// supply its contents to an older in-flight request.
|
|
554
|
+
const prompt = currentPrompt()
|
|
555
|
+
const current = () => active === options && connectionValid(options)
|
|
556
|
+
options.busy = true
|
|
557
|
+
updateStart()
|
|
558
|
+
setStatus(s.starting, 'pending')
|
|
559
|
+
let sessionId = ''
|
|
560
|
+
try {
|
|
561
|
+
const location = {}
|
|
562
|
+
const selected = options.target && ui.targetSelect.value !== 'plugin' ? options.target.workspaces[Number(ui.targetSelect.value)] : null
|
|
563
|
+
const workspaceId = options.target ? selected?.workspaceId : resolve(options.workspaceId)
|
|
564
|
+
const cwd = options.target ? selected?.path || options.target.plugin.path : resolve(options.cwd)
|
|
565
|
+
if (workspaceId) location.workspaceId = workspaceId
|
|
566
|
+
else if (cwd) location.cwd = cwd
|
|
567
|
+
const created = await options.rpc('session.create', location)
|
|
568
|
+
if (!current()) return
|
|
569
|
+
sessionId = short(created && created.sessionId, 200)
|
|
570
|
+
if (!sessionId) throw new Error(s.createFailed)
|
|
571
|
+
setStatus(s.sending, 'pending')
|
|
572
|
+
const value = await options.rpc('session.prompt', {
|
|
573
|
+
sessionId,
|
|
574
|
+
mode: 'queue',
|
|
575
|
+
content: [{ type: 'text', text: prompt }],
|
|
576
|
+
})
|
|
577
|
+
if (!current()) return
|
|
578
|
+
if (value && value.accepted === false) throw new Error(s.promptRejected)
|
|
579
|
+
options.startedSessionId=sessionId
|
|
580
|
+
await openStartedSession(options)
|
|
581
|
+
} catch (error) {
|
|
582
|
+
if (!current()) return
|
|
583
|
+
options.busy = false
|
|
584
|
+
if (sessionId) {
|
|
585
|
+
const copied = await copyWith(options, prompt)
|
|
586
|
+
if (!current()) return
|
|
587
|
+
options.startedSessionId=sessionId
|
|
588
|
+
options.fallbackNotice=copied ? s.createdPromptCopied : s.createdPromptManual
|
|
589
|
+
await openStartedSession(options)
|
|
590
|
+
} else if (active === options) {
|
|
591
|
+
setStatus(format(s.startFailed, { msg: short(error && error.message, 240) || 'unknown' }), 'err')
|
|
592
|
+
}
|
|
593
|
+
} finally {
|
|
594
|
+
options.busy = false
|
|
595
|
+
if (active === options && ui) updateStart(connectionValid(options))
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
async function openStartedSession(options) {
|
|
600
|
+
const current=()=>active===options && connectionValid(options)
|
|
601
|
+
if(!current()){if(active===options)updateStart();return}
|
|
602
|
+
options.busy=true
|
|
603
|
+
updateStart(true)
|
|
604
|
+
setStatus(strings().opening,'pending')
|
|
605
|
+
try {
|
|
606
|
+
const opened=await options.openSession(options.startedSessionId)
|
|
607
|
+
if(!current())return
|
|
608
|
+
if(opened===false)throw new Error(language()==='en'?'Conversation did not open.':'未能切换到诊断会话。')
|
|
609
|
+
close()
|
|
610
|
+
retainedSymptom='';retainedInclude=false
|
|
611
|
+
toast(options,options.fallbackNotice || strings().started,options.fallbackNotice ? 'err' : 'ok')
|
|
612
|
+
} catch(error) {
|
|
613
|
+
if(current())setStatus(format(strings().openFailed,{msg:short(error?.message,180)}),'err')
|
|
614
|
+
} finally {
|
|
615
|
+
options.busy=false
|
|
616
|
+
if(active===options)updateStart(connectionValid(options))
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function close() {
|
|
621
|
+
if (!ui) return
|
|
622
|
+
retainedSymptom = ui.symptom.value
|
|
623
|
+
retainedInclude = ui.include.checked
|
|
624
|
+
ui.overlay.classList.add('hidden')
|
|
625
|
+
ui.overlay.setAttribute('aria-hidden', 'true')
|
|
626
|
+
root.document.body.classList.remove('doctor-open')
|
|
627
|
+
active = null
|
|
628
|
+
try { lastFocus && lastFocus.focus && lastFocus.focus() } catch {}
|
|
629
|
+
lastFocus = null
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function ensureUi() {
|
|
633
|
+
if (ui) return ui
|
|
634
|
+
const overlay = element('div', 'doctor-overlay hidden')
|
|
635
|
+
overlay.setAttribute('role', 'dialog')
|
|
636
|
+
overlay.setAttribute('aria-modal', 'true')
|
|
637
|
+
overlay.setAttribute('aria-hidden', 'true')
|
|
638
|
+
const card = element('section', 'doctor-card')
|
|
639
|
+
const head = element('div', 'doctor-head')
|
|
640
|
+
const title = element('h2', 'doctor-title')
|
|
641
|
+
title.id = 'doctor-title'
|
|
642
|
+
overlay.setAttribute('aria-labelledby', title.id)
|
|
643
|
+
const closeButton = button('×', 'doctor-close', close)
|
|
644
|
+
head.append(title, closeButton)
|
|
645
|
+
const intro = element('p', 'doctor-intro')
|
|
646
|
+
const targetField = element('label','doctor-field doctor-target')
|
|
647
|
+
const targetLabel = element('span','doctor-label')
|
|
648
|
+
const targetSelect = element('select','doctor-target-select')
|
|
649
|
+
targetSelect.setAttribute('aria-label',language()==='en'?'Diagnosis target':'诊断目标')
|
|
650
|
+
const targetPath = element('code','doctor-target-path')
|
|
651
|
+
const targetHint = element('small','doctor-muted')
|
|
652
|
+
targetField.append(targetLabel,targetSelect,targetPath,targetHint)
|
|
653
|
+
const notice = element('div', 'doctor-notice')
|
|
654
|
+
const costTitle = element('strong', null)
|
|
655
|
+
const cost = element('p', null)
|
|
656
|
+
const privacy = element('p', 'doctor-privacy')
|
|
657
|
+
notice.append(costTitle, cost, privacy)
|
|
658
|
+
const field = element('label', 'doctor-field')
|
|
659
|
+
const symptomLabel = element('span', 'doctor-label')
|
|
660
|
+
const symptom = element('textarea', 'doctor-textarea')
|
|
661
|
+
symptom.rows = 5
|
|
662
|
+
symptom.setAttribute('autocomplete', 'off')
|
|
663
|
+
field.append(symptomLabel, symptom)
|
|
664
|
+
const envLabel = element('div', 'doctor-label doctor-env-label')
|
|
665
|
+
const env = element('div', 'doctor-env')
|
|
666
|
+
const includeLabel = element('label', 'doctor-include')
|
|
667
|
+
const include = element('input')
|
|
668
|
+
include.type = 'checkbox'
|
|
669
|
+
const includeText = element('span')
|
|
670
|
+
const includeHint = element('small', null)
|
|
671
|
+
includeLabel.append(include, includeText, includeHint)
|
|
672
|
+
const details = element('details', 'doctor-details')
|
|
673
|
+
const detailsSummary = element('summary')
|
|
674
|
+
const detailsBody = element('div', 'doctor-details-body')
|
|
675
|
+
const preview = element('pre', 'doctor-preview')
|
|
676
|
+
const diagnosticActions = element('div', 'doctor-diagnostic-actions')
|
|
677
|
+
const copyDiagnosticsButton = button('', 'doctor-btn small', () => { void copyDiagnostics() })
|
|
678
|
+
const exportButton = button('', 'doctor-btn small', () => { void exportDiagnostics() })
|
|
679
|
+
diagnosticActions.append(copyDiagnosticsButton, exportButton)
|
|
680
|
+
detailsBody.append(preview, diagnosticActions)
|
|
681
|
+
details.append(detailsSummary, detailsBody)
|
|
682
|
+
const status = element('p', 'doctor-status')
|
|
683
|
+
status.setAttribute('role', 'status')
|
|
684
|
+
status.setAttribute('aria-live', 'polite')
|
|
685
|
+
const actions = element('div', 'doctor-actions')
|
|
686
|
+
const copyPromptButton = button('', 'doctor-btn', () => { void copyPrompt() })
|
|
687
|
+
const copyDraftButton = button('', 'doctor-btn', () => { void copyDraft() })
|
|
688
|
+
const issueButton = button('', 'doctor-btn', openIssue)
|
|
689
|
+
const cancel = button('', 'doctor-btn ghost', close)
|
|
690
|
+
const start = button('', 'doctor-btn primary', () => { void startDiagnosis() })
|
|
691
|
+
actions.append(copyPromptButton, copyDraftButton, issueButton, start, cancel)
|
|
692
|
+
card.append(head, intro, targetField, notice, field, envLabel, env, includeLabel, details, status, actions)
|
|
693
|
+
overlay.append(card)
|
|
694
|
+
root.document.body.append(overlay)
|
|
695
|
+
overlay.addEventListener('click', event => { if (event.target === overlay) close() })
|
|
696
|
+
symptom.addEventListener('input', () => {
|
|
697
|
+
retainedSymptom = symptom.value
|
|
698
|
+
updateStart()
|
|
699
|
+
})
|
|
700
|
+
include.addEventListener('change', () => {
|
|
701
|
+
retainedInclude = include.checked
|
|
702
|
+
})
|
|
703
|
+
targetSelect.addEventListener('change',()=>{
|
|
704
|
+
if(!active?.target)return
|
|
705
|
+
const row=targetSelect.value==='plugin'?active.target.plugin:active.target.workspaces[Number(targetSelect.value)]
|
|
706
|
+
targetPath.textContent=row?.path || ''
|
|
707
|
+
})
|
|
708
|
+
root.document.addEventListener('keydown', event => {
|
|
709
|
+
if (event.key === 'Escape' && !overlay.classList.contains('hidden')) close()
|
|
710
|
+
})
|
|
711
|
+
ui = {
|
|
712
|
+
overlay, title, close: closeButton, intro, costTitle, cost, privacy,
|
|
713
|
+
targetField,targetLabel,targetSelect,targetPath,targetHint,
|
|
714
|
+
symptomLabel, symptom, envLabel, env, include, includeText, includeHint,
|
|
715
|
+
details, detailsSummary, preview, previewOpen: detailsSummary, copyDiagnostics: copyDiagnosticsButton, exportDiagnostics: exportButton,
|
|
716
|
+
status, actions, copyPrompt: copyPromptButton, copyDraft: copyDraftButton, issue: issueButton,
|
|
717
|
+
cancel, start,
|
|
718
|
+
}
|
|
719
|
+
return ui
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
function open(options) {
|
|
723
|
+
if (!root.document || !root.document.body) return false
|
|
724
|
+
const opts = options || {}
|
|
725
|
+
if (active) active.busy = false
|
|
726
|
+
active = { ...opts, busy: false }
|
|
727
|
+
lastFocus = root.document.activeElement
|
|
728
|
+
ensureUi()
|
|
729
|
+
ui.symptom.value = retainedSymptom || ''
|
|
730
|
+
ui.include.checked = retainedInclude
|
|
731
|
+
ui.targetField.hidden = typeof opts.loadTarget !== 'function'
|
|
732
|
+
ui.targetSelect.replaceChildren()
|
|
733
|
+
ui.targetPath.textContent = ''
|
|
734
|
+
if(typeof opts.loadTarget==='function') {
|
|
735
|
+
const owner=active;owner.targetLoading=true
|
|
736
|
+
ui.targetHint.textContent=language()==='en'?'Uses the installed plugin by default. A source workspace is checked against the running installation.':'默认使用实际加载的插件目录;选择源码工作区时,仍会核对运行实例与安装包。'
|
|
737
|
+
Promise.resolve().then(()=>opts.loadTarget()).then(target=>{
|
|
738
|
+
if(active!==owner || !connectionValid(owner))return
|
|
739
|
+
if(target?.ok!==true || target.schema!==1 || typeof target.plugin?.path!=='string' || !target.plugin.path || !Array.isArray(target.workspaces))throw Error('invalid-target')
|
|
740
|
+
owner.target=target
|
|
741
|
+
const add=(value,text)=>{const option=element('option',null,text);option.value=value;ui.targetSelect.append(option)}
|
|
742
|
+
add('plugin',language()==='en'?'Loaded Remote plugin (recommended)':'已加载的 Remote 插件(推荐)')
|
|
743
|
+
target.workspaces.forEach((row,index)=>add(String(index),(language()==='en'?'Workspace · ':'工作区 · ')+(row.title||row.path)))
|
|
744
|
+
ui.targetSelect.value='plugin';ui.targetPath.textContent=target.plugin.path
|
|
745
|
+
const registered=target.skill?.status==='registered'
|
|
746
|
+
ui.targetHint.textContent+=(registered?(language()==='en'?' Doctor skill registered.':' Doctor 技能已注册。'):(language()==='en'?' Skill registration unconfirmed; the full prompt remains available.':' 技能注册尚未确认,可使用完整提示词兜底。'))
|
|
747
|
+
}).catch(()=>{}).finally(()=>{if(active===owner){owner.targetLoading=false;updateStart()}})
|
|
748
|
+
}
|
|
749
|
+
render()
|
|
750
|
+
ui.overlay.classList.remove('hidden')
|
|
751
|
+
ui.overlay.setAttribute('aria-hidden', 'false')
|
|
752
|
+
root.document.body.classList.add('doctor-open')
|
|
753
|
+
setTimeout(() => { try { ui.symptom.focus() } catch {} }, 40)
|
|
754
|
+
return true
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
const api = {
|
|
758
|
+
open,
|
|
759
|
+
close,
|
|
760
|
+
buildDoctorPrompt,
|
|
761
|
+
buildFeedbackDraft,
|
|
762
|
+
buildIssueUrl,
|
|
763
|
+
feedbackTitle,
|
|
764
|
+
diagnosticsText,
|
|
765
|
+
environmentRows,
|
|
766
|
+
}
|
|
767
|
+
if (typeof module !== 'undefined' && module.exports) module.exports = api
|
|
768
|
+
else root.DshDoctor = api
|
|
769
|
+
})(typeof window === 'undefined' ? globalThis : window)
|