dsh-vscode-mode 0.1.57 → 0.1.58
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/lib/client.js +101 -15
- package/lib/client.js.map +1 -1
- package/lib/index.js +207 -88
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/capture.ts +2 -1
- package/src/client/compat.ts +3 -2
- package/src/client/externalOpen.ts +3 -2
- package/src/client/index.ts +7 -6
- package/src/client/log.ts +10 -0
- package/src/client/sidebarBridge.ts +6 -5
- package/src/debugLog.ts +84 -0
- package/src/fileOpenSettings.ts +6 -5
- package/src/index.ts +14 -12
- package/src/log.ts +19 -0
- package/src/mcpIsolation.ts +2 -1
- package/src/rpc.ts +5 -75
- package/src/shared/logger.ts +114 -0
- package/src/store.ts +3 -2
- package/src/workspace.ts +2 -1
package/lib/client.js
CHANGED
|
@@ -107,6 +107,92 @@ window.__ModuleLoader__.load({
|
|
|
107
107
|
} catch (e) {}
|
|
108
108
|
}
|
|
109
109
|
//#endregion
|
|
110
|
+
//#region src/shared/logger.ts
|
|
111
|
+
/**
|
|
112
|
+
* dsh-vscode-mode — 统一日志核心(双面共享,平台中立)。
|
|
113
|
+
* 输出规范:
|
|
114
|
+
* - 格式:`[dsh-vscode-mode][:scope] 消息`;前缀只在模块内部拼接,业务代码禁止手写前缀
|
|
115
|
+
* - 级别语义:debug=诊断明细 / info=装配与路由里程碑 / warn=降级与兼容回退 / error=失败
|
|
116
|
+
* - 出口:host 面经 bindHostLog(ctx) 绑定 ctx.logger(缺失回退 console);client 面固定 console
|
|
117
|
+
* - 诊断文件通道(edrv.debug → ~/.dsh/dsh-vscode-mode/logs/)见 debugLog.ts,与本模块前缀共用
|
|
118
|
+
* 新增日志一律 `import { log } from '../log.js'`(client 为 './log.js')后调 log.debug/info/warn/error;
|
|
119
|
+
* 子域日志用 log.child('scope'),禁止另起 console。
|
|
120
|
+
* 作者 ddj 2026-09-08
|
|
121
|
+
*/
|
|
122
|
+
/** 插件统一日志前缀(与包安装名一致)。 */
|
|
123
|
+
const LOG_PREFIX = "[dsh-vscode-mode]";
|
|
124
|
+
/** 默认级别到 console 方法名的映射。 */
|
|
125
|
+
const CONSOLE_METHODS = {
|
|
126
|
+
debug: "debug",
|
|
127
|
+
info: "info",
|
|
128
|
+
warn: "warn",
|
|
129
|
+
error: "error"
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* 默认出口:console(级别直映方法;方法缺失时静默丢弃,不抛错)。
|
|
133
|
+
* @author ddj 2026年09月08号
|
|
134
|
+
* @returns console 出口
|
|
135
|
+
*/
|
|
136
|
+
function consoleSink() {
|
|
137
|
+
return (level, line) => {
|
|
138
|
+
const emit = console[CONSOLE_METHODS[level]];
|
|
139
|
+
if (typeof emit === "function") emit.call(console, line);
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* 拼一行日志:`[dsh-vscode-mode][:scope] 消息`(scope 为空省略冒号段)。
|
|
144
|
+
* @author ddj 2026年09月08号
|
|
145
|
+
* @param scope 子域(可空)
|
|
146
|
+
* @param message 消息文本
|
|
147
|
+
* @returns 整行文本
|
|
148
|
+
*/
|
|
149
|
+
function formatLine(scope, message) {
|
|
150
|
+
const text = String(message);
|
|
151
|
+
return scope ? LOG_PREFIX + ":" + scope + " " + text : LOG_PREFIX + " " + text;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* 日志器工厂(内部):emit 时读共享出口状态,保证父 bind 后子实例跟随。
|
|
155
|
+
* @author ddj 2026年09月08号
|
|
156
|
+
* @param state 共享出口状态
|
|
157
|
+
* @param scope 子域文本(可空)
|
|
158
|
+
* @returns 日志器
|
|
159
|
+
*/
|
|
160
|
+
function makeLogger(state, scope) {
|
|
161
|
+
const emit = (level, message) => state.sink(level, formatLine(scope, message));
|
|
162
|
+
return {
|
|
163
|
+
debug: (message) => emit("debug", message),
|
|
164
|
+
info: (message) => emit("info", message),
|
|
165
|
+
warn: (message) => emit("warn", message),
|
|
166
|
+
error: (message) => emit("error", message),
|
|
167
|
+
bind(next) {
|
|
168
|
+
state.sink = next;
|
|
169
|
+
},
|
|
170
|
+
child(next) {
|
|
171
|
+
return makeLogger(state, scope ? scope + "." + next : next);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* 创建插件日志器(默认 console 出口;host 面单例由 bindHostLog 换到 ctx.logger)。
|
|
177
|
+
* @author ddj 2026年09月08号
|
|
178
|
+
* @param sink 初始出口(缺省 console)
|
|
179
|
+
* @param scope 初始子域(业务方一般经 child 派生,不直接传)
|
|
180
|
+
* @returns 日志器
|
|
181
|
+
*/
|
|
182
|
+
function createLogger(sink = consoleSink(), scope = "") {
|
|
183
|
+
return makeLogger({ sink }, scope);
|
|
184
|
+
}
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/client/log.ts
|
|
187
|
+
/**
|
|
188
|
+
* dsh-vscode-mode client — 日志单例(全 client 面唯一日志入口)。
|
|
189
|
+
* client 无 ctx.logger 服务,固定 console 出口;格式/级别语义与 host 面一致(shared/logger.ts)。
|
|
190
|
+
* 用法:`import { log } from './log.js'` → `log.debug/info/warn/error(msg)`;子域用 `log.child('scope')`。
|
|
191
|
+
* 作者 ddj 2026-09-08
|
|
192
|
+
*/
|
|
193
|
+
/** client 面插件日志单例。 */
|
|
194
|
+
const log = createLogger();
|
|
195
|
+
//#endregion
|
|
110
196
|
//#region src/client/sidebarBridge.ts
|
|
111
197
|
/**
|
|
112
198
|
* dsh-vscode-mode client — 侧边栏编辑区桥:可选探测 dsh-better-sidebar 的
|
|
@@ -224,7 +310,7 @@ window.__ModuleLoader__.load({
|
|
|
224
310
|
try {
|
|
225
311
|
return ensureSideEditor(path, focusDiff) === true;
|
|
226
312
|
} catch (error) {
|
|
227
|
-
|
|
313
|
+
log.warn("侧栏编辑器打开失败(" + String(error) + "),已回退");
|
|
228
314
|
return false;
|
|
229
315
|
}
|
|
230
316
|
}
|
|
@@ -260,7 +346,7 @@ window.__ModuleLoader__.load({
|
|
|
260
346
|
try {
|
|
261
347
|
registerLegacyFallback();
|
|
262
348
|
} catch (error) {
|
|
263
|
-
|
|
349
|
+
log.warn("回退注册失败(" + String(error) + ")");
|
|
264
350
|
}
|
|
265
351
|
}
|
|
266
352
|
return false;
|
|
@@ -282,7 +368,7 @@ window.__ModuleLoader__.load({
|
|
|
282
368
|
cwd: scope?.cwd
|
|
283
369
|
});
|
|
284
370
|
} catch (error) {
|
|
285
|
-
|
|
371
|
+
log.warn("openTab 失败(" + String(error) + ")");
|
|
286
372
|
return false;
|
|
287
373
|
}
|
|
288
374
|
if (sideEditorMounted) window.dispatchEvent(new CustomEvent("edrv:open-editor", { detail: {
|
|
@@ -303,13 +389,13 @@ window.__ModuleLoader__.load({
|
|
|
303
389
|
component: renderTab
|
|
304
390
|
});
|
|
305
391
|
} catch (error) {
|
|
306
|
-
|
|
392
|
+
log.warn("侧边栏 Tab 注册失败(" + String(error) + ")");
|
|
307
393
|
if (!fallbackInstalled) {
|
|
308
394
|
fallbackInstalled = true;
|
|
309
395
|
try {
|
|
310
396
|
registerLegacyFallback();
|
|
311
397
|
} catch (inner) {
|
|
312
|
-
|
|
398
|
+
log.warn("回退注册失败(" + String(inner) + ")");
|
|
313
399
|
}
|
|
314
400
|
}
|
|
315
401
|
return () => {};
|
|
@@ -6413,14 +6499,14 @@ window.__ModuleLoader__.load({
|
|
|
6413
6499
|
function registerSlotSafely(ctx, spec, render) {
|
|
6414
6500
|
const slots = ctx?.slots;
|
|
6415
6501
|
if (!slots || typeof slots.inject !== "function" || typeof slots.register !== "function") {
|
|
6416
|
-
|
|
6502
|
+
log.warn("slots 服务不可用,跳过 slot " + spec.name);
|
|
6417
6503
|
return null;
|
|
6418
6504
|
}
|
|
6419
6505
|
try {
|
|
6420
6506
|
const disposer = slots.inject(spec.name, () => slots.register(spec, render));
|
|
6421
6507
|
return typeof disposer === "function" ? disposer : null;
|
|
6422
6508
|
} catch (error) {
|
|
6423
|
-
|
|
6509
|
+
log.warn("slot " + spec.name + " 注册失败(" + String(error) + "),已跳过");
|
|
6424
6510
|
return null;
|
|
6425
6511
|
}
|
|
6426
6512
|
}
|
|
@@ -8914,12 +9000,12 @@ window.__ModuleLoader__.load({
|
|
|
8914
9000
|
if (!params) return;
|
|
8915
9001
|
const referrer = options.referrer ?? (typeof document !== "undefined" ? document.referrer : "");
|
|
8916
9002
|
if (!referrerAllowed(referrer, options.origin ?? (typeof location !== "undefined" ? location.origin : ""))) {
|
|
8917
|
-
|
|
9003
|
+
log.warn("已忽略跨源深链请求(referrer=" + referrer + ")");
|
|
8918
9004
|
return;
|
|
8919
9005
|
}
|
|
8920
9006
|
stripCurrentUrl();
|
|
8921
9007
|
openDeepLink(ctx, params).catch((error) => {
|
|
8922
|
-
|
|
9008
|
+
log.warn("深链打开失败:" + String(error));
|
|
8923
9009
|
toastDom("深链打开失败:" + String(error?.message ?? error));
|
|
8924
9010
|
});
|
|
8925
9011
|
}
|
|
@@ -11776,8 +11862,8 @@ window.__ModuleLoader__.load({
|
|
|
11776
11862
|
let selected = autoValue("auto");
|
|
11777
11863
|
/** 0.1.3+ 会话文件链接路由(remote.session.openWorkspacePath)是否已安装(compatSummary 展示用)。 */
|
|
11778
11864
|
let remoteOpenInstalled = false;
|
|
11779
|
-
/** 两条文件链接路由共用的路由日志(openPathRouter / remoteOpenRouter
|
|
11780
|
-
const routeLogger = (message) =>
|
|
11865
|
+
/** 两条文件链接路由共用的路由日志(openPathRouter / remoteOpenRouter;统一走插件日志器)。 */
|
|
11866
|
+
const routeLogger = (message) => log.warn(message);
|
|
11781
11867
|
/** 两条路由共用的 FileOpenContext:当前会话 id 与工作区 cwd。 */
|
|
11782
11868
|
const openContext = () => {
|
|
11783
11869
|
const current = sessions?.list?.getSnapshot?.();
|
|
@@ -11877,7 +11963,7 @@ window.__ModuleLoader__.load({
|
|
|
11877
11963
|
let remoteRetries = 0;
|
|
11878
11964
|
const retryRemoteOpen = () => {
|
|
11879
11965
|
if (remoteOpenInstalled || remoteRetries >= 15) {
|
|
11880
|
-
if (!remoteOpenInstalled)
|
|
11966
|
+
if (!remoteOpenInstalled) log.warn("未探测到 remote.session.openWorkspacePath,0.1.3+ 会话文件链接路由未安装");
|
|
11881
11967
|
return;
|
|
11882
11968
|
}
|
|
11883
11969
|
remoteRetries += 1;
|
|
@@ -11895,12 +11981,12 @@ window.__ModuleLoader__.load({
|
|
|
11895
11981
|
logger: routeLogger
|
|
11896
11982
|
});
|
|
11897
11983
|
if (!disposer) {
|
|
11898
|
-
|
|
11984
|
+
log.warn("remote.session 存在但 openWorkspacePath 不可补丁,会话文件链接路由未安装");
|
|
11899
11985
|
return;
|
|
11900
11986
|
}
|
|
11901
11987
|
remoteOpenInstalled = true;
|
|
11902
11988
|
ctx.effect(() => disposer, "vscode-mode: remote file link routing");
|
|
11903
|
-
|
|
11989
|
+
log.info("已安装 0.1.3+ 会话文件链接路由(remote.session.openWorkspacePath)");
|
|
11904
11990
|
}, 2e3);
|
|
11905
11991
|
};
|
|
11906
11992
|
retryRemoteOpen();
|
|
@@ -11971,7 +12057,7 @@ window.__ModuleLoader__.load({
|
|
|
11971
12057
|
if (sideService !== void 0) return;
|
|
11972
12058
|
sideService = detectSidebarService(ctx);
|
|
11973
12059
|
if (sideService !== void 0) {
|
|
11974
|
-
|
|
12060
|
+
log.info("检测到 dsh-better-sidebar,切换侧边栏编辑形态");
|
|
11975
12061
|
applySideForm();
|
|
11976
12062
|
} else retrySideService();
|
|
11977
12063
|
}, 2e3);
|