dsh-vscode-mode 0.1.47 → 0.1.48

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 CHANGED
@@ -2601,6 +2601,154 @@ window.__ModuleLoader__.load({
2601
2601
  };
2602
2602
  }
2603
2603
  //#endregion
2604
+ //#region src/client/addToConversation.ts
2605
+ /** 把追加引用结果映射为可读文案(ok 用 okText;busy 提示已降级纯文本;unavailable 提示不可用)。
2606
+ * @author ddj 2026年09月03号
2607
+ * @param outcome 追加结果状态
2608
+ * @param okText 成功文案(如「已添加文件引用」/「已添加文件夹引用」)
2609
+ * @returns 状态栏/通知用文案
2610
+ */
2611
+ function statusOfAdd(outcome, okText) {
2612
+ if (outcome === "ok") return okText;
2613
+ if (outcome === "busy") return okText + "(输入框忙,已降级纯文本)";
2614
+ return "无法添加到对话(无会话或输入框不可用)";
2615
+ }
2616
+ /** DSH reference source 名(dsh-client-ui-reference 注册的 @file/@session 统一源)。 */
2617
+ const REF_SOURCE = "reference";
2618
+ /**
2619
+ * 生成 DSH @file 语法引用串:cwd 相对化、\ → /、含空白时按 @"path" 语法加引号。
2620
+ * cwd 外/无法相对化的路径回退原路径。
2621
+ * @author ddj 2026年08月25号
2622
+ * @param path 打开的文件路径(相对 cwd 或绝对)
2623
+ * @param cwd 会话工作区目录(可选)
2624
+ * @returns 引用串(如 @src/index.ts 或 @"a b.ts")
2625
+ */
2626
+ function mentionOf(path, cwd) {
2627
+ const raw = String(path);
2628
+ let rel = raw;
2629
+ if (cwd) {
2630
+ const base = String(cwd).replace(/[\\/]+$/, "");
2631
+ const up = raw.replace(/\\/g, "/");
2632
+ const baseUp = base.replace(/\\/g, "/");
2633
+ if (up.startsWith(baseUp + "/")) rel = up.slice(baseUp.length + 1);
2634
+ else if (up === baseUp) rel = "";
2635
+ }
2636
+ rel = rel.replace(/\\/g, "/").replace(/^\.\//, "");
2637
+ if (!rel) rel = raw.replace(/\\/g, "/");
2638
+ if (/[\u0000-\u001f\u007f-\u009f"]/u.test(rel)) return "@" + raw;
2639
+ return /\s/u.test(rel) ? `@"${rel}"` : `@${rel}`;
2640
+ }
2641
+ /** 引用标签:文件名 + 可选行区间(chip 内展示,不带 @ 前缀)。
2642
+ * @author ddj 2026年08月25号 */
2643
+ function labelOf(path, range) {
2644
+ const base = String(path).split(/[\\/]/).pop() || String(path);
2645
+ if (!range || range.endLine < range.startLine) return base;
2646
+ return range.startLine === range.endLine ? `${base} L${range.startLine}` : `${base} L${range.startLine}-${range.endLine}`;
2647
+ }
2648
+ /** 引用 ref:引用串 + 可选行区间(序列化直出,agent 据此读取对应片段)。
2649
+ * @author ddj 2026年08月25号 */
2650
+ function refOf(mention, range) {
2651
+ if (!range || range.endLine < range.startLine) return mention;
2652
+ return range.startLine === range.endLine ? `${mention} L${range.startLine}` : `${mention} L${range.startLine}-${range.endLine}`;
2653
+ }
2654
+ /** 构造 DSH 文件引用插入载荷(source=reference,发送序列化为 mention(+range) 文本)。
2655
+ * @param path 目标路径(相对 cwd 或绝对)
2656
+ * @param cwd 会话工作区目录(可选)
2657
+ * @param range 行区间(可选)
2658
+ * @param appearance 引用外观:'file'(默认)| 'folder'
2659
+ */
2660
+ function buildFileRef(path, cwd, range, appearance = "file") {
2661
+ const mention = mentionOf(path, cwd);
2662
+ return {
2663
+ mention,
2664
+ reference: {
2665
+ source: REF_SOURCE,
2666
+ ref: refOf(mention, range),
2667
+ label: labelOf(path, range),
2668
+ appearance,
2669
+ clipboardText: mention
2670
+ }
2671
+ };
2672
+ }
2673
+ /**
2674
+ * 解析会话输入门面;缺失时返回 undefined(动作侧守卫降级)。
2675
+ * @author ddj 2026年08月25号
2676
+ * @param ctx 客户端服务上下文
2677
+ * @param sessionId 会话 id
2678
+ * @returns SessionInput 或 undefined
2679
+ */
2680
+ function inputFor(ctx, sessionId) {
2681
+ if (!sessionId) return void 0;
2682
+ try {
2683
+ const sessions = ctx.get("sessions");
2684
+ const conversation = ctx.get("conversation");
2685
+ const actx = sessions?.scope?.(sessionId);
2686
+ const shell = actx && conversation?.input?.for?.(actx);
2687
+ return shell && typeof shell.setDraft === "function" ? shell : void 0;
2688
+ } catch {
2689
+ return;
2690
+ }
2691
+ }
2692
+ /** 取当前草稿长度与版本;无输入门面时返回 null。
2693
+ * @author ddj 2026年08月25号 */
2694
+ function draftCursor(input) {
2695
+ try {
2696
+ const s = input?.state?.getSnapshot?.();
2697
+ if (!s) return null;
2698
+ return {
2699
+ draft: String(s.draft ?? ""),
2700
+ draftRev: Number(s.draftRev ?? 0)
2701
+ };
2702
+ } catch {
2703
+ return null;
2704
+ }
2705
+ }
2706
+ /** 从 sessions 列表快照读会话工作区目录(与 index.ts 既有读取方式一致)。
2707
+ * @author ddj 2026年08月25号 */
2708
+ function cwdOf(ctx, sessionId) {
2709
+ if (!sessionId) return void 0;
2710
+ try {
2711
+ return ctx.get("sessions")?.list?.getSnapshot?.()?.byId?.[sessionId]?.cwd;
2712
+ } catch {
2713
+ return;
2714
+ }
2715
+ }
2716
+ /** 输入门面插入引用(拦截异常视作未应用,走降级)。
2717
+ * @author ddj 2026年08月25号 */
2718
+ function safeInsert(input, reference, span) {
2719
+ try {
2720
+ return input.insertReference(reference, span) === true;
2721
+ } catch {
2722
+ return false;
2723
+ }
2724
+ }
2725
+ /**
2726
+ * 创建「添加到对话」动作集(apply 阶段构建一次,随 props 传给 EditorView)。
2727
+ * @author ddj 2026年08月25号
2728
+ * @param ctx 客户端服务上下文(sessions + conversation)
2729
+ * @returns 动作集
2730
+ */
2731
+ function createAddToConversation(ctx) {
2732
+ const appendReference = async (sessionId, path, range, appearance) => {
2733
+ const input = inputFor(ctx, sessionId);
2734
+ if (!input) return "unavailable";
2735
+ const cur = draftCursor(input);
2736
+ if (!cur) return "unavailable";
2737
+ const { reference, mention } = buildFileRef(path, cwdOf(ctx, sessionId), range, appearance);
2738
+ if (!safeInsert(input, reference, {
2739
+ start: cur.draft.length,
2740
+ end: cur.draft.length,
2741
+ draftRev: cur.draftRev
2742
+ })) {
2743
+ const gap = cur.draft.length > 0 && !/\s$/.test(cur.draft) ? " " : "";
2744
+ input.setDraft(cur.draft + gap + mention + " ");
2745
+ return "busy";
2746
+ }
2747
+ return "ok";
2748
+ };
2749
+ return { appendReference };
2750
+ }
2751
+ //#endregion
2604
2752
  //#region src/shared/lsp.ts
2605
2753
  /** LSP semantic token 标准类型(host 归一化后,client 与 Monaco 共用)。 */
2606
2754
  const LSP_SEMANTIC_TOKEN_TYPES = [
@@ -4551,14 +4699,7 @@ window.__ModuleLoader__.load({
4551
4699
  const dismissMenus = () => {
4552
4700
  setTabMenu(null);
4553
4701
  };
4554
- /** 把「添加到对话」返回状态映射为状态栏文案。
4555
- * @author ddj 2026年08月25号 */
4556
- const statusOfAdd = (outcome, okText) => {
4557
- if (outcome === "ok") return okText;
4558
- if (outcome === "busy") return okText + "(输入框忙,已降级纯文本)";
4559
- return "无法添加到对话(无会话或输入框不可用)";
4560
- };
4561
- /** 添加文件/选中区引用到对话(异步,状态栏反馈)。 */
4702
+ /** 添加文件/选中区引用到对话(异步,状态栏反馈;状态文案走共享 statusOfAdd)。 */
4562
4703
  const addRefToChat = (path, range) => {
4563
4704
  if (!path) {
4564
4705
  setStatus("无活动文件");
@@ -4957,6 +5098,7 @@ window.__ModuleLoader__.load({
4957
5098
  editor: () => editorRef.current,
4958
5099
  outlineSources: props.outlineSources,
4959
5100
  fileMenuItems: props.fileMenuItems,
5101
+ addToConversation,
4960
5102
  notify: (message) => setStatus(message)
4961
5103
  };
4962
5104
  const editorArea = react.default.createElement("div", { className: "edrv-editor-area" }, body, hoverEl, overlay);
@@ -7230,147 +7372,6 @@ window.__ModuleLoader__.load({
7230
7372
  });
7231
7373
  }
7232
7374
  //#endregion
7233
- //#region src/client/addToConversation.ts
7234
- /** DSH reference source 名(dsh-client-ui-reference 注册的 @file/@session 统一源)。 */
7235
- const REF_SOURCE = "reference";
7236
- /**
7237
- * 生成 DSH @file 语法引用串:cwd 相对化、\ → /、含空白时按 @"path" 语法加引号。
7238
- * cwd 外/无法相对化的路径回退原路径。
7239
- * @author ddj 2026年08月25号
7240
- * @param path 打开的文件路径(相对 cwd 或绝对)
7241
- * @param cwd 会话工作区目录(可选)
7242
- * @returns 引用串(如 @src/index.ts 或 @"a b.ts")
7243
- */
7244
- function mentionOf(path, cwd) {
7245
- const raw = String(path);
7246
- let rel = raw;
7247
- if (cwd) {
7248
- const base = String(cwd).replace(/[\\/]+$/, "");
7249
- const up = raw.replace(/\\/g, "/");
7250
- const baseUp = base.replace(/\\/g, "/");
7251
- if (up.startsWith(baseUp + "/")) rel = up.slice(baseUp.length + 1);
7252
- else if (up === baseUp) rel = "";
7253
- }
7254
- rel = rel.replace(/\\/g, "/").replace(/^\.\//, "");
7255
- if (!rel) rel = raw.replace(/\\/g, "/");
7256
- if (/[\u0000-\u001f\u007f-\u009f"]/u.test(rel)) return "@" + raw;
7257
- return /\s/u.test(rel) ? `@"${rel}"` : `@${rel}`;
7258
- }
7259
- /** 引用标签:文件名 + 可选行区间(chip 内展示,不带 @ 前缀)。
7260
- * @author ddj 2026年08月25号 */
7261
- function labelOf(path, range) {
7262
- const base = String(path).split(/[\\/]/).pop() || String(path);
7263
- if (!range || range.endLine < range.startLine) return base;
7264
- return range.startLine === range.endLine ? `${base} L${range.startLine}` : `${base} L${range.startLine}-${range.endLine}`;
7265
- }
7266
- /** 引用 ref:引用串 + 可选行区间(序列化直出,agent 据此读取对应片段)。
7267
- * @author ddj 2026年08月25号 */
7268
- function refOf(mention, range) {
7269
- if (!range || range.endLine < range.startLine) return mention;
7270
- return range.startLine === range.endLine ? `${mention} L${range.startLine}` : `${mention} L${range.startLine}-${range.endLine}`;
7271
- }
7272
- /** 构造 DSH 文件引用插入载荷(source=reference,发送序列化为 mention(+range) 文本)。 */
7273
- function buildFileRef(path, cwd, range) {
7274
- const mention = mentionOf(path, cwd);
7275
- return {
7276
- mention,
7277
- reference: {
7278
- source: REF_SOURCE,
7279
- ref: refOf(mention, range),
7280
- label: labelOf(path, range),
7281
- appearance: "file",
7282
- clipboardText: mention
7283
- }
7284
- };
7285
- }
7286
- /**
7287
- * 解析会话输入门面;缺失时返回 undefined(动作侧守卫降级)。
7288
- * @author ddj 2026年08月25号
7289
- * @param ctx 客户端服务上下文
7290
- * @param sessionId 会话 id
7291
- * @returns SessionInput 或 undefined
7292
- */
7293
- function inputFor(ctx, sessionId) {
7294
- if (!sessionId) return void 0;
7295
- try {
7296
- const sessions = ctx.get("sessions");
7297
- const conversation = ctx.get("conversation");
7298
- const actx = sessions?.scope?.(sessionId);
7299
- const shell = actx && conversation?.input?.for?.(actx);
7300
- return shell && typeof shell.setDraft === "function" ? shell : void 0;
7301
- } catch {
7302
- return;
7303
- }
7304
- }
7305
- /** 取当前草稿长度与版本;无输入门面时返回 null。
7306
- * @author ddj 2026年08月25号 */
7307
- function draftCursor(input) {
7308
- try {
7309
- const s = input?.state?.getSnapshot?.();
7310
- if (!s) return null;
7311
- return {
7312
- draft: String(s.draft ?? ""),
7313
- draftRev: Number(s.draftRev ?? 0)
7314
- };
7315
- } catch {
7316
- return null;
7317
- }
7318
- }
7319
- /** 从 sessions 列表快照读会话工作区目录(与 index.ts 既有读取方式一致)。
7320
- * @author ddj 2026年08月25号 */
7321
- function cwdOf(ctx, sessionId) {
7322
- if (!sessionId) return void 0;
7323
- try {
7324
- return ctx.get("sessions")?.list?.getSnapshot?.()?.byId?.[sessionId]?.cwd;
7325
- } catch {
7326
- return;
7327
- }
7328
- }
7329
- /** 写入成功后的 composer 内联提示(门面可用时;失败静默)。
7330
- * @author ddj 2026年08月25号 */
7331
- function notify(input, text) {
7332
- try {
7333
- input.notify?.("info", text);
7334
- } catch {}
7335
- }
7336
- /** 输入门面插入引用(拦截异常视作未应用,走降级)。
7337
- * @author ddj 2026年08月25号 */
7338
- function safeInsert(input, reference, span) {
7339
- try {
7340
- return input.insertReference(reference, span) === true;
7341
- } catch {
7342
- return false;
7343
- }
7344
- }
7345
- /**
7346
- * 创建「添加到对话」动作集(apply 阶段构建一次,随 props 传给 EditorView)。
7347
- * @author ddj 2026年08月25号
7348
- * @param ctx 客户端服务上下文(sessions + conversation)
7349
- * @returns 动作集
7350
- */
7351
- function createAddToConversation(ctx) {
7352
- const appendReference = async (sessionId, path, range) => {
7353
- const input = inputFor(ctx, sessionId);
7354
- if (!input) return "unavailable";
7355
- const cur = draftCursor(input);
7356
- if (!cur) return "unavailable";
7357
- const { reference, mention } = buildFileRef(path, cwdOf(ctx, sessionId), range);
7358
- if (!safeInsert(input, reference, {
7359
- start: cur.draft.length,
7360
- end: cur.draft.length,
7361
- draftRev: cur.draftRev
7362
- })) {
7363
- const gap = cur.draft.length > 0 && !/\s$/.test(cur.draft) ? " " : "";
7364
- input.setDraft(cur.draft + gap + mention + " ");
7365
- notify(input, "已添加文件引用 " + mention);
7366
- return "busy";
7367
- }
7368
- notify(input, "已添加文件引用 " + mention);
7369
- return "ok";
7370
- };
7371
- return { appendReference };
7372
- }
7373
- //#endregion
7374
7375
  //#region src/client/sidebar/registry.ts
7375
7376
  /** 校验面板定义并写入注册表(缺 id/render 抛 TypeError)。 */
7376
7377
  function panelRegister(entries, notify, panel) {
@@ -7428,24 +7429,6 @@ window.__ModuleLoader__.load({
7428
7429
  top: Math.max(4, Math.min(y, maxTop))
7429
7430
  };
7430
7431
  }
7431
- /**
7432
- * 将文件树行右键菜单锚定到目标行右侧;无法测量时回退到鼠标坐标。
7433
- * @author ddj 2026年08月28号
7434
- * @param rect 目标行的布局矩形
7435
- * @param fallbackX 鼠标 viewport x 坐标
7436
- * @param fallbackY 鼠标 viewport y 坐标
7437
- * @returns 菜单初始位置
7438
- */
7439
- function rowMenuPosition(rect, fallbackX, fallbackY) {
7440
- if (!rect || rect.width <= 0 || rect.height <= 0) return {
7441
- left: fallbackX,
7442
- top: fallbackY
7443
- };
7444
- return {
7445
- left: rect.right + 4,
7446
- top: rect.top
7447
- };
7448
- }
7449
7432
  //#endregion
7450
7433
  //#region src/client/ui/ContextMenu.ts
7451
7434
  /**
@@ -8039,11 +8022,9 @@ window.__ModuleLoader__.load({
8039
8022
  onContextMenu: (ev) => {
8040
8023
  ev.preventDefault();
8041
8024
  ev.stopPropagation();
8042
- const rect = ev.currentTarget?.getBoundingClientRect?.();
8043
- const position = rowMenuPosition(rect, ev.clientX, ev.clientY);
8044
8025
  setMenu({
8045
- x: position.left,
8046
- y: position.top,
8026
+ x: ev.clientX,
8027
+ y: ev.clientY,
8047
8028
  target: {
8048
8029
  path: e.path,
8049
8030
  type: e.type
@@ -8496,9 +8477,10 @@ window.__ModuleLoader__.load({
8496
8477
  //#region src/client/sidebar/menuItems.ts
8497
8478
  /**
8498
8479
  * dsh-vscode-mode client — 文件管理右键菜单内置项。
8499
- * 首个内置项:「在文件浏览器中打开」(文件→OS Explorer 定位选中、目录→打开目录)。
8480
+ * 内置项:「在文件浏览器中打开」(文件→OS Explorer 定位选中、目录→打开目录);
8481
+ * 「添加引用到对话」(文件/文件夹引用注入当前会话对话输入框)。
8500
8482
  * 反馈统一走 ctx.notify(由 EditorView 提供,落到编辑区路径栏状态)。
8501
- * 作者 ddj 2026-08-27
8483
+ * 作者 ddj 2026-08-27 / 2026-09-03
8502
8484
  */
8503
8485
  /**
8504
8486
  * 构造内置右键菜单项列表(后续内置项直接追加)。
@@ -8515,6 +8497,23 @@ window.__ModuleLoader__.load({
8515
8497
  ctx.notify?.(outcome.ok ? "已在文件浏览器中打开" : "打开失败:" + (outcome.error ?? "未知错误"));
8516
8498
  });
8517
8499
  }
8500
+ }, {
8501
+ id: "add-to-conversation",
8502
+ label: "添加引用到对话",
8503
+ order: 1,
8504
+ visible: (target, ctx) => Boolean(target.path && ctx.sessionId && ctx.addToConversation),
8505
+ run: (target, ctx) => {
8506
+ const isDir = target.type === "directory";
8507
+ const add = ctx.addToConversation;
8508
+ if (!add) {
8509
+ ctx.notify?.("添加到对话不可用");
8510
+ return;
8511
+ }
8512
+ const okText = isDir ? "已添加文件夹引用" : "已添加文件引用";
8513
+ add.appendReference(ctx.sessionId, target.path, void 0, isDir ? "folder" : "file").then((outcome) => {
8514
+ ctx.notify?.(statusOfAdd(outcome, okText));
8515
+ });
8516
+ }
8518
8517
  }];
8519
8518
  }
8520
8519
  //#endregion