@kangyishuai/dsh-btw 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -6
- package/README.zh-CN.md +10 -6
- package/lib/client.js +201 -87
- package/lib/service.js +18 -12
- package/lib/settings.js +25 -4
- package/lib/threads.js +19 -0
- package/locale/en.json +2 -1
- package/locale/zh.json +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ Unofficial plugin for [DeepSeek Harness (DSH)](https://github.com/deepseek-ai/de
|
|
|
18
18
|
- **Streaming.** The drawer renders the answer as it is generated instead of waiting for the whole reply (the host buffers the child's text deltas; the panel reads them through `btw/live`).
|
|
19
19
|
- **Markdown.** Headings, lists, tables, quotes, fenced code and inline styles render properly. The promote draft keeps its Markdown source, so it renders correctly once you send it.
|
|
20
20
|
- **Readable numbers.** The cost badge adapts tokens to `K/M/B/T` and duration to `ms/s/m/h` (for example `new 12.3K · cached 988K · 32.5s`).
|
|
21
|
-
- **Promote to draft.** Turn the
|
|
21
|
+
- **Promote to draft.** Turn the **whole thread** into a four-section Markdown draft (first question / latest conclusion / key details / still unresolved) and **insert it into the composer — never send it**. You decide whether to send.
|
|
22
22
|
- **Native right sidebar.** The「旁问」button opens a tab in the DSH right sidebar: the conversation becomes narrower but is **never covered**.the sidebar's own collapse button (⌥⌘B) collapses the column and clicking the「旁问」button expands it again. Hosts without the sidebar service fall back to a right-edge overlay drawer.
|
|
23
23
|
- **Chat order.** Threads list oldest first with every turn expanded, the newest answer at the bottom, and the view follows the latest content.
|
|
24
24
|
- **Honest scope badge.** The drawer states how many side questions exist and reminds you that **the model can see the whole conversation**; a scope choice only narrows the instruction, it does not cut context.
|
|
@@ -79,13 +79,16 @@ Plugin config (set when adding the plugin to a profile):
|
|
|
79
79
|
|
|
80
80
|
Runtime settings (editable in **Settings → Side questions**, stored in `<dataRoot>/btw/settings.json`):
|
|
81
81
|
|
|
82
|
-
| Key | Default | Meaning
|
|
83
|
-
| -------------- | ------- |
|
|
84
|
-
| `allowedTools` | `[]` | Overrides the plugin config above when non-empty.
|
|
85
|
-
| `historyLimit` | `50` | Records kept per session (1–200).
|
|
82
|
+
| Key | Default | Meaning |
|
|
83
|
+
| -------------- | ------- | ---------------------------------------------------------------- |
|
|
84
|
+
| `allowedTools` | `[]` | Overrides the plugin config above when non-empty. |
|
|
85
|
+
| `historyLimit` | `50` | Records kept per session (1–200). |
|
|
86
|
+
| `echoAnswer` | `true` | Also show the full answer in the conversation; off = panel only. |
|
|
86
87
|
|
|
87
88
|
The settings file is re-read on every use, so edits take effect without restarting the host.
|
|
88
89
|
|
|
90
|
+
Panel details: the bottom「New question」input hides while a thread follow-up is open (no two similar inputs); the follow-up button reads「Follow up」/「Cancel follow-up」. `Esc` closes the panel, the input is focused when the panel opens, and expanding a long answer keeps the current reading position.
|
|
91
|
+
|
|
89
92
|
## Side effects & risks
|
|
90
93
|
|
|
91
94
|
- **Spends one model call** per side question (a fork of the current conversation).
|
|
@@ -101,7 +104,7 @@ The settings file is re-read on every use, so edits take effect without restarti
|
|
|
101
104
|
|
|
102
105
|
The underlying host seams (command dispatch while busy, fork cache reuse, `tools.guard`, `workspaceRegistry.archiveSession`) were verified on DSH 0.2.2-rc.3.
|
|
103
106
|
|
|
104
|
-
End-to-end status: the web smoke (temporary `DSH_HOME`, right-sidebar tab, collapse/expand, Markdown rendering) and a real `/btw` round trip pass. The desktop regression was
|
|
107
|
+
End-to-end status: the web smoke (temporary `DSH_HOME`, right-sidebar tab, collapse/expand, Markdown rendering) and a real `/btw` round trip pass. The desktop regression was rerun against the installed 0.4.0 in the live desktop profile: 14 PASS / 1 SKIP / 0 FAIL (the SKIP is a visible session with no side-question records yet).
|
|
105
108
|
|
|
106
109
|
## License
|
|
107
110
|
|
package/README.zh-CN.md
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
- **流式输出**:抽屉里答案边生成边显示,不用等整段返回(host 缓冲子会话的 text-delta,面板通过 `btw/live` 读取)。
|
|
19
19
|
- **Markdown 渲染**:标题、列表、表格、引用、代码块与行内样式都会正常渲染;转正草稿保留 Markdown 源码,发送后由 DSH 正常渲染。
|
|
20
20
|
- **数字可读**:成本徽章的 token 数自适应 `K/M/B/T`,耗时自适应 `ms/s/m/h`(例如 `新增 12.3K · 命中缓存 988K · 32.5s`)。
|
|
21
|
-
-
|
|
21
|
+
- **一键转正**:把**整条线程**整理成四节 **Markdown** 草稿(首问 / 最后一轮结论 / 关键细节 / 仍未解决),**只插进输入框、绝不发送**,发不发由你决定。
|
|
22
22
|
- **原生右侧栏**:点「旁问」在 DSH 右侧边栏打开一个「旁问」tab,主对话变窄但**不被遮挡**;点右侧栏右上角的收起按钮(⌥⌘B)收起整栏,再点「旁问」展开。宿主没有右侧栏服务时回退到右侧浮层抽屉。
|
|
23
23
|
- **聊天式顺序**:线程从旧到新、每轮问答按时间展开,最新一条在最下面,打开或新内容到达时自动滚到底。
|
|
24
24
|
- **诚实的范围徽章**:抽屉会说明有多少条旁问,并提示**模型能看到完整会话**;范围档位只缩窄指令,不裁剪上下文。
|
|
@@ -83,13 +83,17 @@ dsh plugin --profile desktop add @kangyishuai/dsh-btw
|
|
|
83
83
|
|
|
84
84
|
运行期设置(在**设置 → 旁问**里改,落在 `<dataRoot>/btw/settings.json`):
|
|
85
85
|
|
|
86
|
-
| 键 | 默认
|
|
87
|
-
| -------------- |
|
|
88
|
-
| `allowedTools` | `[]`
|
|
89
|
-
| `historyLimit` | `50`
|
|
86
|
+
| 键 | 默认 | 含义 |
|
|
87
|
+
| -------------- | ------ | ------------------------------------------------ |
|
|
88
|
+
| `allowedTools` | `[]` | 非空时覆盖上面的插件配置。 |
|
|
89
|
+
| `historyLimit` | `50` | 每会话保留的旁问条数(1–200)。 |
|
|
90
|
+
| `echoAnswer` | `true` | 主对话是否回显完整答案;关闭后只在旁问面板展示。 |
|
|
90
91
|
|
|
91
92
|
设置文件每次使用前重读,改完不需要重启宿主。
|
|
92
93
|
|
|
94
|
+
面板交互细节:追问输入框打开时底部「新旁问」输入会暂时隐藏(避免两个输入框),追问按钮叫「追问」/「取消追问」;
|
|
95
|
+
`Esc` 关闭面板;面板可见时自动聚焦输入框;展开长答案会保持当前阅读位置。
|
|
96
|
+
|
|
93
97
|
## 副作用与风险
|
|
94
98
|
|
|
95
99
|
- 每次旁问**多花一次模型调用**(fork 当前对话)。
|
|
@@ -105,7 +109,7 @@ dsh plugin --profile desktop add @kangyishuai/dsh-btw
|
|
|
105
109
|
|
|
106
110
|
底层宿主 seam(busy 时命令派发、fork 缓存复用、`tools.guard`、`workspaceRegistry.archiveSession`)已在 DSH 0.2.2-rc.3 上实测。
|
|
107
111
|
|
|
108
|
-
端到端情况:web 冒烟(临时 `DSH_HOME`,覆盖右侧栏 tab、收起/展开、Markdown 渲染)与真实模型往返都通过;桌面回归(`pnpm smoke:btw-desktop --require
|
|
112
|
+
端到端情况:web 冒烟(临时 `DSH_HOME`,覆盖右侧栏 tab、收起/展开、Markdown 渲染)与真实模型往返都通过;桌面回归(`pnpm smoke:btw-desktop --require`)已在真实 desktop profile 的 0.4.0 上重跑:**14 PASS / 1 SKIP / 0 FAIL**(SKIP 是当前会话还没有旁问记录)。
|
|
109
113
|
|
|
110
114
|
## 许可证
|
|
111
115
|
|
package/lib/client.js
CHANGED
|
@@ -56,6 +56,12 @@ window.__ModuleLoader__.load({
|
|
|
56
56
|
followUp: "追问",
|
|
57
57
|
followPlaceholder: "在这个线程里追问…",
|
|
58
58
|
followUpLabel: "追问",
|
|
59
|
+
followSend: "追问",
|
|
60
|
+
followCancel: "取消追问",
|
|
61
|
+
followInputLabel: "追问该线程",
|
|
62
|
+
thinking: "思考中",
|
|
63
|
+
threadCount: "{count} 个线程",
|
|
64
|
+
resizeHint: "拖动右侧栏分隔条可调宽度;⌥⌘B 收起侧栏",
|
|
59
65
|
turns: "轮",
|
|
60
66
|
promote: "转正",
|
|
61
67
|
promoted: "已插入输入框草稿(未发送)",
|
|
@@ -85,6 +91,8 @@ window.__ModuleLoader__.load({
|
|
|
85
91
|
"settings.failed": "保存失败",
|
|
86
92
|
"settings.mode": "模式",
|
|
87
93
|
"settings.readOnly": "只读",
|
|
94
|
+
"settings.echo": "主对话显示完整答案",
|
|
95
|
+
"settings.echoHint": "关闭后只在旁问面板展示,/btw 命令只回一行提示。",
|
|
88
96
|
};
|
|
89
97
|
const en = {
|
|
90
98
|
button: "btw",
|
|
@@ -103,6 +111,12 @@ window.__ModuleLoader__.load({
|
|
|
103
111
|
followUp: "Follow up",
|
|
104
112
|
followPlaceholder: "Ask a follow-up in this thread…",
|
|
105
113
|
followUpLabel: "Follow-up",
|
|
114
|
+
followSend: "Follow up",
|
|
115
|
+
followCancel: "Cancel follow-up",
|
|
116
|
+
followInputLabel: "Follow up in this thread",
|
|
117
|
+
thinking: "Thinking",
|
|
118
|
+
threadCount: "{count} threads",
|
|
119
|
+
resizeHint: "Drag the sidebar divider to resize; ⌥⌘B collapses the sidebar",
|
|
106
120
|
turns: "turns",
|
|
107
121
|
promote: "Promote",
|
|
108
122
|
promoted: "Inserted into the composer as a draft (not sent)",
|
|
@@ -133,6 +147,9 @@ window.__ModuleLoader__.load({
|
|
|
133
147
|
"settings.failed": "Save failed",
|
|
134
148
|
"settings.mode": "Mode",
|
|
135
149
|
"settings.readOnly": "read-only",
|
|
150
|
+
"settings.echo": "Show full answer in the conversation",
|
|
151
|
+
"settings.echoHint":
|
|
152
|
+
"When off, the answer is only in the side-question panel; /btw returns one line.",
|
|
136
153
|
};
|
|
137
154
|
|
|
138
155
|
const CSS = [
|
|
@@ -459,13 +476,16 @@ window.__ModuleLoader__.load({
|
|
|
459
476
|
* @param {any} props
|
|
460
477
|
*/
|
|
461
478
|
function MarkdownBody(props) {
|
|
462
|
-
const { blocks, streaming, clamped } = props;
|
|
479
|
+
const { blocks, streaming, clamped, answerId } = props;
|
|
463
480
|
return h(
|
|
464
481
|
"div",
|
|
465
482
|
{
|
|
466
483
|
className: `dsh-btw-a${clamped ? " is-clamped" : ""}`,
|
|
467
484
|
"data-btw-answer": "true",
|
|
468
485
|
"data-btw-md": "true",
|
|
486
|
+
...(typeof answerId === "string" && answerId !== ""
|
|
487
|
+
? { "data-btw-answer-id": answerId }
|
|
488
|
+
: {}),
|
|
469
489
|
},
|
|
470
490
|
h("div", { className: "dsh-btw-md" }, ...renderBlocks(blocks, streaming === true)),
|
|
471
491
|
);
|
|
@@ -750,6 +770,7 @@ window.__ModuleLoader__.load({
|
|
|
750
770
|
const liveRef = React.useRef(/** @type {any[]} */ ([]));
|
|
751
771
|
const scrollRef = React.useRef(/** @type {any} */ (null));
|
|
752
772
|
const pinnedRef = React.useRef(true);
|
|
773
|
+
const questionRef = React.useRef(/** @type {any} */ (null));
|
|
753
774
|
|
|
754
775
|
React.useEffect(
|
|
755
776
|
() => () => {
|
|
@@ -769,6 +790,19 @@ window.__ModuleLoader__.load({
|
|
|
769
790
|
pinnedRef.current = true;
|
|
770
791
|
}, [sessionId]);
|
|
771
792
|
|
|
793
|
+
// 面板可见且没开追问输入时,自动聚焦「新旁问」输入框,省一次点击。
|
|
794
|
+
React.useEffect(() => {
|
|
795
|
+
if (!visible || sessionId === "" || activeId !== "") return undefined;
|
|
796
|
+
const timer = setTimeout(() => {
|
|
797
|
+
try {
|
|
798
|
+
questionRef.current?.focus();
|
|
799
|
+
} catch {
|
|
800
|
+
/* 忽略焦点失败 */
|
|
801
|
+
}
|
|
802
|
+
}, 0);
|
|
803
|
+
return () => clearTimeout(timer);
|
|
804
|
+
}, [visible, sessionId, activeId]);
|
|
805
|
+
|
|
772
806
|
/**
|
|
773
807
|
* 拉线程列表。quiet = 后台轮询:失败不把界面打红。
|
|
774
808
|
* @param {boolean} [quiet]
|
|
@@ -792,7 +826,8 @@ window.__ModuleLoader__.load({
|
|
|
792
826
|
[sessionId],
|
|
793
827
|
);
|
|
794
828
|
|
|
795
|
-
|
|
829
|
+
/** 重新拉徽章(记录数/范围)。提交完成、live 结束、切范围时都要刷新,避免计数落后。 */
|
|
830
|
+
const refreshBadge = React.useCallback(() => {
|
|
796
831
|
const scopeLabel =
|
|
797
832
|
scope === ""
|
|
798
833
|
? ""
|
|
@@ -803,11 +838,17 @@ window.__ModuleLoader__.load({
|
|
|
803
838
|
? "scopeRecent"
|
|
804
839
|
: "scopeSelection",
|
|
805
840
|
).replace(/^范围:|^Scope:\s*/i, "");
|
|
806
|
-
callRemote("stats", { sessionId, scope: scopeLabel, lang: langOf() }).then(
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
841
|
+
return callRemote("stats", { sessionId, scope: scopeLabel, lang: langOf() }).then(
|
|
842
|
+
(/** @type {any} */ value) => {
|
|
843
|
+
if (!aliveRef.current) return;
|
|
844
|
+
if (value && typeof value.badge === "string") setBadge(value.badge);
|
|
845
|
+
},
|
|
846
|
+
);
|
|
847
|
+
}, [sessionId, scope, t]);
|
|
848
|
+
|
|
849
|
+
React.useEffect(() => {
|
|
850
|
+
void refreshBadge();
|
|
851
|
+
}, [refreshBadge]);
|
|
811
852
|
|
|
812
853
|
// 面板挂载(tab 打开 / 抽屉展开)时先读一次历史。
|
|
813
854
|
React.useEffect(() => {
|
|
@@ -839,8 +880,10 @@ window.__ModuleLoader__.load({
|
|
|
839
880
|
// 空闲轮询(无 run)不重复 set 空数组,省掉每秒一次无意义的重渲染。
|
|
840
881
|
if (hasLive || hadLive) setLiveRuns(runs);
|
|
841
882
|
// 只在 live 结束后刷一次历史(run 进行中 threads 不会变,少传大 payload)。
|
|
842
|
-
if (hadLive && !hasLive)
|
|
843
|
-
|
|
883
|
+
if (hadLive && !hasLive) {
|
|
884
|
+
void loadThreads(true);
|
|
885
|
+
void refreshBadge();
|
|
886
|
+
} else if (!hasLive && ticks % LIVE_IDLE_REFRESH_EVERY === 0) void loadThreads(true);
|
|
844
887
|
ticks += 1;
|
|
845
888
|
if (!cancelled)
|
|
846
889
|
timer = setTimeout(tick, runs.length > 0 ? LIVE_ACTIVE_MS : LIVE_IDLE_MS);
|
|
@@ -850,17 +893,24 @@ window.__ModuleLoader__.load({
|
|
|
850
893
|
cancelled = true;
|
|
851
894
|
clearTimeout(timer);
|
|
852
895
|
};
|
|
853
|
-
}, [sessionId, visible, loadThreads]);
|
|
896
|
+
}, [sessionId, visible, loadThreads, refreshBadge]);
|
|
854
897
|
|
|
855
|
-
// Esc
|
|
898
|
+
// Esc 关闭面板(tab 与回退抽屉同一手感)。用捕获阶段先于宿主/菜单处理,
|
|
899
|
+
// 否则宿主会把 Esc preventDefault 掉,面板永远收不到。
|
|
856
900
|
React.useEffect(() => {
|
|
857
|
-
if (mode !== "drawer") return undefined;
|
|
858
901
|
const onKey = (/** @type {any} */ event) => {
|
|
859
|
-
if (event?.key
|
|
902
|
+
if (event?.key !== "Escape") return;
|
|
903
|
+
// 只在焦点位于面板内时才关闭:设置对话框/斜杠菜单的 Esc 归它们自己,
|
|
904
|
+
// 不会因为面板开着而被一起关掉。
|
|
905
|
+
const inPanel =
|
|
906
|
+
typeof event?.target?.closest === "function" &&
|
|
907
|
+
event.target.closest("[data-btw-panel]") !== null;
|
|
908
|
+
if (!inPanel) return;
|
|
909
|
+
onClose();
|
|
860
910
|
};
|
|
861
|
-
document.addEventListener("keydown", onKey);
|
|
862
|
-
return () => document.removeEventListener("keydown", onKey);
|
|
863
|
-
}, [
|
|
911
|
+
document.addEventListener("keydown", onKey, true);
|
|
912
|
+
return () => document.removeEventListener("keydown", onKey, true);
|
|
913
|
+
}, [onClose]);
|
|
864
914
|
|
|
865
915
|
// 自动滚到底:只有用户本来就在底部时才跟随(向上翻历史时不抢滚动条)。
|
|
866
916
|
const onScroll = () => {
|
|
@@ -949,6 +999,7 @@ window.__ModuleLoader__.load({
|
|
|
949
999
|
break;
|
|
950
1000
|
}
|
|
951
1001
|
}
|
|
1002
|
+
void refreshBadge();
|
|
952
1003
|
setNotice(refreshed ? "" : t("sentPending"));
|
|
953
1004
|
} finally {
|
|
954
1005
|
if (aliveRef.current) setBusy(false);
|
|
@@ -979,7 +1030,8 @@ window.__ModuleLoader__.load({
|
|
|
979
1030
|
}
|
|
980
1031
|
const result = await callRemote("promote", {
|
|
981
1032
|
sessionId,
|
|
982
|
-
|
|
1033
|
+
// 线程级转正:host 用首问 + 最后一轮答案组四节草稿。
|
|
1034
|
+
threadId: String(thread?.threadId ?? ""),
|
|
983
1035
|
lang: langOf(),
|
|
984
1036
|
});
|
|
985
1037
|
if (result?.ok !== true || typeof result?.text !== "string") {
|
|
@@ -998,12 +1050,51 @@ window.__ModuleLoader__.load({
|
|
|
998
1050
|
setNotice(t("promoted"));
|
|
999
1051
|
};
|
|
1000
1052
|
|
|
1001
|
-
//
|
|
1002
|
-
const
|
|
1053
|
+
// 折叠按钮:展开/收起单条长答案。展开后保持被点答案的视口位置,避免列表跳回顶部。
|
|
1054
|
+
const answerAnchorRef = React.useRef(/** @type {any} */ (null));
|
|
1055
|
+
const toggleAnswer = (/** @type {string} */ key) => {
|
|
1056
|
+
const list = scrollRef.current;
|
|
1057
|
+
/** @type {any} */
|
|
1058
|
+
const el =
|
|
1059
|
+
list === null || list === undefined
|
|
1060
|
+
? null
|
|
1061
|
+
: list.querySelector(`[data-btw-answer-id="${key}"]`);
|
|
1062
|
+
answerAnchorRef.current = {
|
|
1063
|
+
key,
|
|
1064
|
+
top: el === null || el === undefined ? null : el.getBoundingClientRect().top,
|
|
1065
|
+
};
|
|
1003
1066
|
setExpandedAnswers((/** @type {any} */ previous) => ({
|
|
1004
1067
|
...previous,
|
|
1005
1068
|
[key]: !previous[key],
|
|
1006
1069
|
}));
|
|
1070
|
+
};
|
|
1071
|
+
React.useLayoutEffect(() => {
|
|
1072
|
+
const pending = answerAnchorRef.current;
|
|
1073
|
+
if (pending === null || pending === undefined) return;
|
|
1074
|
+
answerAnchorRef.current = null;
|
|
1075
|
+
const list = scrollRef.current;
|
|
1076
|
+
if (list === null || list === undefined || pending.top === null) return;
|
|
1077
|
+
const el = list.querySelector(`[data-btw-answer-id="${pending.key}"]`);
|
|
1078
|
+
if (el === null || el === undefined) return;
|
|
1079
|
+
list.scrollTop += el.getBoundingClientRect().top - pending.top;
|
|
1080
|
+
}, [expandedAnswers]);
|
|
1081
|
+
|
|
1082
|
+
/** 范围档位选择器:底部「新旁问」和线程内追问共用同一个 scope 状态。 */
|
|
1083
|
+
const renderScopeSelect = (/** @type {string} */ key) =>
|
|
1084
|
+
h(
|
|
1085
|
+
"select",
|
|
1086
|
+
{
|
|
1087
|
+
key,
|
|
1088
|
+
className: "dsh-btw-select",
|
|
1089
|
+
"data-btw-scope": "true",
|
|
1090
|
+
value: scope,
|
|
1091
|
+
onChange: (/** @type {any} */ event) => setScope(String(event?.target?.value ?? "")),
|
|
1092
|
+
},
|
|
1093
|
+
h("option", { value: "" }, t("scopeAny")),
|
|
1094
|
+
h("option", { value: "session" }, t("scopeSession")),
|
|
1095
|
+
h("option", { value: "recent" }, t("scopeRecent")),
|
|
1096
|
+
h("option", { value: "selection" }, t("scopeSelection")),
|
|
1097
|
+
);
|
|
1007
1098
|
|
|
1008
1099
|
/** @param {any} thread @param {number} index */
|
|
1009
1100
|
const renderThread = (thread, index) => {
|
|
@@ -1035,7 +1126,12 @@ window.__ModuleLoader__.load({
|
|
|
1035
1126
|
: h("span", { className: "dsh-btw-q-label" }, t("followUpLabel")),
|
|
1036
1127
|
String(item.question),
|
|
1037
1128
|
),
|
|
1038
|
-
h(MarkdownBody, {
|
|
1129
|
+
h(MarkdownBody, {
|
|
1130
|
+
blocks: item?.blocks,
|
|
1131
|
+
streaming: false,
|
|
1132
|
+
clamped,
|
|
1133
|
+
answerId: itemKey,
|
|
1134
|
+
}),
|
|
1039
1135
|
clamped
|
|
1040
1136
|
? h(
|
|
1041
1137
|
"button",
|
|
@@ -1069,7 +1165,7 @@ window.__ModuleLoader__.load({
|
|
|
1069
1165
|
setFollowQuestion("");
|
|
1070
1166
|
},
|
|
1071
1167
|
},
|
|
1072
|
-
expanded ? t("
|
|
1168
|
+
expanded ? t("followCancel") : t("followUp"),
|
|
1073
1169
|
),
|
|
1074
1170
|
h(
|
|
1075
1171
|
"button",
|
|
@@ -1087,7 +1183,8 @@ window.__ModuleLoader__.load({
|
|
|
1087
1183
|
expanded && isLast
|
|
1088
1184
|
? h(
|
|
1089
1185
|
"div",
|
|
1090
|
-
{ className: "dsh-btw-
|
|
1186
|
+
{ className: "dsh-btw-composer", "data-btw-thread-input": "true" },
|
|
1187
|
+
h("span", { className: "dsh-btw-composer-label" }, t("followInputLabel")),
|
|
1091
1188
|
h("textarea", {
|
|
1092
1189
|
className: "dsh-btw-input",
|
|
1093
1190
|
"data-btw-input": "true",
|
|
@@ -1104,15 +1201,20 @@ window.__ModuleLoader__.load({
|
|
|
1104
1201
|
},
|
|
1105
1202
|
}),
|
|
1106
1203
|
h(
|
|
1107
|
-
"
|
|
1108
|
-
{
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1204
|
+
"div",
|
|
1205
|
+
{ className: "dsh-btw-row" },
|
|
1206
|
+
h(
|
|
1207
|
+
"button",
|
|
1208
|
+
{
|
|
1209
|
+
type: "button",
|
|
1210
|
+
className: "dsh-btw-btn",
|
|
1211
|
+
"data-btw-send": "true",
|
|
1212
|
+
disabled: busy || followQuestion.trim() === "",
|
|
1213
|
+
onClick: () => void submit(threadId),
|
|
1214
|
+
},
|
|
1215
|
+
t("followSend"),
|
|
1216
|
+
),
|
|
1217
|
+
renderScopeSelect("follow-scope"),
|
|
1116
1218
|
),
|
|
1117
1219
|
)
|
|
1118
1220
|
: null,
|
|
@@ -1162,7 +1264,9 @@ window.__ModuleLoader__.load({
|
|
|
1162
1264
|
h(
|
|
1163
1265
|
"div",
|
|
1164
1266
|
{ className: "dsh-btw-meta", "data-btw-elapsed": "true" },
|
|
1165
|
-
`${
|
|
1267
|
+
`${
|
|
1268
|
+
Array.isArray(run?.blocks) && run.blocks.length > 0 ? t("streaming") : t("thinking")
|
|
1269
|
+
} · ${formatDuration(run?.ms)}`,
|
|
1166
1270
|
),
|
|
1167
1271
|
);
|
|
1168
1272
|
};
|
|
@@ -1202,7 +1306,7 @@ window.__ModuleLoader__.load({
|
|
|
1202
1306
|
? h(
|
|
1203
1307
|
"span",
|
|
1204
1308
|
{ className: "dsh-btw-dim", "data-btw-count": "true" },
|
|
1205
|
-
|
|
1309
|
+
fmt(t("threadCount"), { count: threads.length }),
|
|
1206
1310
|
)
|
|
1207
1311
|
: null,
|
|
1208
1312
|
mode === "tab"
|
|
@@ -1256,59 +1360,56 @@ window.__ModuleLoader__.load({
|
|
|
1256
1360
|
},
|
|
1257
1361
|
...(Array.isArray(list) ? list : [list]),
|
|
1258
1362
|
),
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
onKeyDown: (/** @type {any} */ event) => {
|
|
1272
|
-
if (event?.key === "Enter" && (event.metaKey || event.ctrlKey)) {
|
|
1273
|
-
event.preventDefault();
|
|
1274
|
-
void submit("");
|
|
1275
|
-
}
|
|
1276
|
-
},
|
|
1277
|
-
}),
|
|
1278
|
-
h(
|
|
1279
|
-
"div",
|
|
1280
|
-
{ className: "dsh-btw-row" },
|
|
1281
|
-
h(
|
|
1282
|
-
"button",
|
|
1283
|
-
{
|
|
1284
|
-
type: "button",
|
|
1285
|
-
className: "dsh-btw-btn is-primary",
|
|
1286
|
-
"data-btw-send": "true",
|
|
1287
|
-
disabled: busy || question.trim() === "",
|
|
1288
|
-
onClick: () => void submit(""),
|
|
1289
|
-
},
|
|
1290
|
-
t("send"),
|
|
1291
|
-
),
|
|
1292
|
-
h(
|
|
1293
|
-
"select",
|
|
1294
|
-
{
|
|
1295
|
-
className: "dsh-btw-select",
|
|
1296
|
-
"data-btw-scope": "true",
|
|
1297
|
-
value: scope,
|
|
1363
|
+
activeId === ""
|
|
1364
|
+
? h(
|
|
1365
|
+
"div",
|
|
1366
|
+
{ className: "dsh-btw-composer" },
|
|
1367
|
+
h("span", { className: "dsh-btw-composer-label" }, t("newQuestionLabel")),
|
|
1368
|
+
h("textarea", {
|
|
1369
|
+
className: "dsh-btw-input",
|
|
1370
|
+
"data-btw-input": "true",
|
|
1371
|
+
placeholder: t("placeholder"),
|
|
1372
|
+
value: question,
|
|
1373
|
+
rows: 2,
|
|
1374
|
+
ref: questionRef,
|
|
1298
1375
|
onChange: (/** @type {any} */ event) =>
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1376
|
+
setQuestion(String(event?.target?.value ?? "")),
|
|
1377
|
+
onKeyDown: (/** @type {any} */ event) => {
|
|
1378
|
+
if (event?.key === "Enter" && (event.metaKey || event.ctrlKey)) {
|
|
1379
|
+
event.preventDefault();
|
|
1380
|
+
void submit("");
|
|
1381
|
+
}
|
|
1382
|
+
},
|
|
1383
|
+
}),
|
|
1384
|
+
h(
|
|
1385
|
+
"div",
|
|
1386
|
+
{ className: "dsh-btw-row" },
|
|
1387
|
+
h(
|
|
1388
|
+
"button",
|
|
1389
|
+
{
|
|
1390
|
+
type: "button",
|
|
1391
|
+
className: "dsh-btw-btn is-primary",
|
|
1392
|
+
"data-btw-send": "true",
|
|
1393
|
+
disabled: busy || question.trim() === "",
|
|
1394
|
+
onClick: () => void submit(""),
|
|
1395
|
+
},
|
|
1396
|
+
t("send"),
|
|
1397
|
+
),
|
|
1398
|
+
renderScopeSelect("new-scope"),
|
|
1399
|
+
),
|
|
1400
|
+
)
|
|
1401
|
+
: null,
|
|
1402
|
+
h("div", { className: "dsh-btw-meta", "data-btw-hint": "true" }, t("submitHint")),
|
|
1403
|
+
mode === "tab"
|
|
1404
|
+
? h(
|
|
1405
|
+
"div",
|
|
1406
|
+
{ className: "dsh-btw-meta", "data-btw-resize-hint": "true" },
|
|
1407
|
+
t("resizeHint"),
|
|
1408
|
+
)
|
|
1409
|
+
: null,
|
|
1410
|
+
badge === ""
|
|
1411
|
+
? null
|
|
1412
|
+
: h("div", { className: "dsh-btw-meta", "data-btw-badge": "true" }, badge),
|
|
1312
1413
|
);
|
|
1313
1414
|
}
|
|
1314
1415
|
|
|
@@ -1388,6 +1489,7 @@ window.__ModuleLoader__.load({
|
|
|
1388
1489
|
const [loaded, setLoaded] = React.useState(/** @type {any} */ (null));
|
|
1389
1490
|
const [tools, setTools] = React.useState("");
|
|
1390
1491
|
const [limit, setLimit] = React.useState("");
|
|
1492
|
+
const [echo, setEcho] = React.useState(true);
|
|
1391
1493
|
const [saving, setSaving] = React.useState(false);
|
|
1392
1494
|
const [notice, setNotice] = React.useState("");
|
|
1393
1495
|
const [expanded, setExpanded] = React.useState(false);
|
|
@@ -1397,6 +1499,7 @@ window.__ModuleLoader__.load({
|
|
|
1397
1499
|
setLoaded(value);
|
|
1398
1500
|
setTools(Array.isArray(value.allowedTools) ? value.allowedTools.join(", ") : "");
|
|
1399
1501
|
setLimit(String(value.historyLimit ?? ""));
|
|
1502
|
+
setEcho(value.echoAnswer !== false);
|
|
1400
1503
|
}, []);
|
|
1401
1504
|
|
|
1402
1505
|
React.useEffect(() => {
|
|
@@ -1408,7 +1511,8 @@ window.__ModuleLoader__.load({
|
|
|
1408
1511
|
const dirty =
|
|
1409
1512
|
loaded !== null &&
|
|
1410
1513
|
(tools !== (loaded.allowedTools ?? []).join(", ") ||
|
|
1411
|
-
limit !== String(loaded.historyLimit ?? "")
|
|
1514
|
+
limit !== String(loaded.historyLimit ?? "") ||
|
|
1515
|
+
echo !== (loaded.echoAnswer !== false));
|
|
1412
1516
|
|
|
1413
1517
|
const save = async () => {
|
|
1414
1518
|
const call =
|
|
@@ -1417,7 +1521,7 @@ window.__ModuleLoader__.load({
|
|
|
1417
1521
|
setSaving(true);
|
|
1418
1522
|
setNotice("");
|
|
1419
1523
|
const next = await Promise.resolve(
|
|
1420
|
-
call({ allowedTools: tools, historyLimit: Number(limit) }),
|
|
1524
|
+
call({ allowedTools: tools, historyLimit: Number(limit), echoAnswer: echo }),
|
|
1421
1525
|
).catch(() => undefined);
|
|
1422
1526
|
setSaving(false);
|
|
1423
1527
|
if (next && typeof next === "object") {
|
|
@@ -1457,6 +1561,16 @@ window.__ModuleLoader__.load({
|
|
|
1457
1561
|
? t("settings.readOnly")
|
|
1458
1562
|
: `${loaded.allowedTools.length}`,
|
|
1459
1563
|
),
|
|
1564
|
+
h("span", { className: "dsh-btw-grow" }),
|
|
1565
|
+
h("input", {
|
|
1566
|
+
type: "checkbox",
|
|
1567
|
+
"data-btw-setting-echo": "true",
|
|
1568
|
+
"aria-label": t("settings.echo"),
|
|
1569
|
+
title: t("settings.echoHint"),
|
|
1570
|
+
checked: echo,
|
|
1571
|
+
onChange: (/** @type {any} */ event) => setEcho(event?.target?.checked === true),
|
|
1572
|
+
}),
|
|
1573
|
+
h("span", { className: "dsh-btw-setlabel" }, t("settings.echo")),
|
|
1460
1574
|
),
|
|
1461
1575
|
row(
|
|
1462
1576
|
t("settings.tools"),
|
package/lib/service.js
CHANGED
|
@@ -13,12 +13,13 @@ import { createLiveTracker } from "./live.js";
|
|
|
13
13
|
import { parseMarkdown } from "./markdown.js";
|
|
14
14
|
import { format, loadMessages, pickLanguage } from "./messages.js";
|
|
15
15
|
import { historyFile, resolveDataRoot } from "./paths.js";
|
|
16
|
-
import { loadSettings, saveSettings } from "./settings.js";
|
|
16
|
+
import { buildSettingsPatch, loadSettings, saveSettings } from "./settings.js";
|
|
17
17
|
import { observeUsage, runSideQuestion } from "./subagent.js";
|
|
18
18
|
import {
|
|
19
19
|
listThreads,
|
|
20
20
|
newThreadId,
|
|
21
21
|
parseCommandArgs,
|
|
22
|
+
promoteRecordForThread,
|
|
22
23
|
renderPromoteDraft,
|
|
23
24
|
threadHistory,
|
|
24
25
|
} from "./threads.js";
|
|
@@ -57,6 +58,7 @@ const FALLBACK = {
|
|
|
57
58
|
tooLong: "That question is too long ({length} characters, limit {max}).",
|
|
58
59
|
threadFull: "This side-question thread is full ({max} turns). Start a new one.",
|
|
59
60
|
meta: "btw · new {newTokens} tokens · cached {cachedTokens} · {ms}",
|
|
61
|
+
panelOnly: "Side question answered; the full answer is in the side-question panel.",
|
|
60
62
|
reopen: "Last side question: {question}",
|
|
61
63
|
};
|
|
62
64
|
|
|
@@ -240,6 +242,10 @@ export class BtwService extends TypertRemoteService {
|
|
|
240
242
|
at: Date.now(),
|
|
241
243
|
};
|
|
242
244
|
await appendRecord(file, record).catch(() => {});
|
|
245
|
+
// 设置里关掉「主对话显示完整答案」时,只回一行提示;面板历史里仍有完整答案。
|
|
246
|
+
if (stored !== undefined && stored.echoAnswer === false) {
|
|
247
|
+
return { kind: "success", text: this.messages.panelOnly ?? FALLBACK.panelOnly };
|
|
248
|
+
}
|
|
243
249
|
return { kind: "success", text: this.formatAnswer(record) };
|
|
244
250
|
}
|
|
245
251
|
|
|
@@ -320,7 +326,7 @@ export class BtwService extends TypertRemoteService {
|
|
|
320
326
|
/**
|
|
321
327
|
* 生成「一键转正」草稿文本。**只返回文本,不插入、不发送**——
|
|
322
328
|
* 语义已与用户确认:插入 composer 草稿,由用户自己决定发不发。
|
|
323
|
-
* @param {{ sessionId?: string, recordId?: string, lang?: string, details?: string, unresolved?: string } | undefined} request
|
|
329
|
+
* @param {{ sessionId?: string, threadId?: string, recordId?: string, lang?: string, details?: string, unresolved?: string } | undefined} request
|
|
324
330
|
* @returns {Promise<{ ok: boolean, text?: string, reason?: string }>}
|
|
325
331
|
*/
|
|
326
332
|
async promote(request) {
|
|
@@ -329,14 +335,17 @@ export class BtwService extends TypertRemoteService {
|
|
|
329
335
|
historyFile(this.dataRoot, String(input.sessionId ?? "")),
|
|
330
336
|
LIMITS.perSessionRecords,
|
|
331
337
|
);
|
|
338
|
+
const threadId = String(input.threadId ?? "");
|
|
332
339
|
const wanted = String(input.recordId ?? "");
|
|
333
340
|
const record =
|
|
334
|
-
|
|
335
|
-
? records
|
|
336
|
-
:
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
341
|
+
threadId !== ""
|
|
342
|
+
? promoteRecordForThread(records, threadId)
|
|
343
|
+
: wanted === ""
|
|
344
|
+
? records[records.length - 1]
|
|
345
|
+
: records
|
|
346
|
+
.slice()
|
|
347
|
+
.reverse()
|
|
348
|
+
.find((entry) => String(entry?.id ?? "") === wanted);
|
|
340
349
|
if (record === undefined) return { ok: false, reason: "no_record" };
|
|
341
350
|
const text = renderPromoteDraft(record, {
|
|
342
351
|
lang: String(input.lang ?? ""),
|
|
@@ -396,10 +405,7 @@ export class BtwService extends TypertRemoteService {
|
|
|
396
405
|
*/
|
|
397
406
|
async updateSettings(request) {
|
|
398
407
|
const input = request ?? {};
|
|
399
|
-
const saved = await saveSettings(this.dataRoot,
|
|
400
|
-
...(input.allowedTools === undefined ? {} : { allowedTools: input.allowedTools }),
|
|
401
|
-
...(input.historyLimit === undefined ? {} : { historyLimit: input.historyLimit }),
|
|
402
|
-
});
|
|
408
|
+
const saved = await saveSettings(this.dataRoot, buildSettingsPatch(input));
|
|
403
409
|
this.allowedTools = new Set(saved.allowedTools);
|
|
404
410
|
return { ...saved, readOnly: saved.allowedTools.length === 0 };
|
|
405
411
|
}
|
package/lib/settings.js
CHANGED
|
@@ -17,6 +17,8 @@ export const DEFAULT_SETTINGS = Object.freeze({
|
|
|
17
17
|
allowedTools: Object.freeze([]),
|
|
18
18
|
/** 每会话保留的旁问条数。 */
|
|
19
19
|
historyLimit: LIMITS.perSessionRecords,
|
|
20
|
+
/** 主对话里是否还回显完整答案;false = 只在旁问面板展示。 */
|
|
21
|
+
echoAnswer: true,
|
|
20
22
|
});
|
|
21
23
|
|
|
22
24
|
/** @param {string} dataRoot @returns {string} */
|
|
@@ -27,7 +29,7 @@ export function settingsPath(dataRoot) {
|
|
|
27
29
|
/**
|
|
28
30
|
* 把任意输入夹紧成合法设置。
|
|
29
31
|
* @param {any} raw
|
|
30
|
-
* @returns {{ schemaVersion: number, allowedTools: string[], historyLimit: number }}
|
|
32
|
+
* @returns {{ schemaVersion: number, allowedTools: string[], historyLimit: number, echoAnswer: boolean }}
|
|
31
33
|
*/
|
|
32
34
|
export function sanitizeSettings(raw) {
|
|
33
35
|
const input = raw !== null && typeof raw === "object" ? raw : {};
|
|
@@ -49,13 +51,32 @@ export function sanitizeSettings(raw) {
|
|
|
49
51
|
const historyLimit = Number.isFinite(limitRaw)
|
|
50
52
|
? Math.min(Math.max(Math.trunc(limitRaw), 1), 200)
|
|
51
53
|
: LIMITS.perSessionRecords;
|
|
52
|
-
|
|
54
|
+
// 只有显式 false 关闭;缺省/other 值保持 true(旧设置文件与向后兼容)。
|
|
55
|
+
const echoAnswer = input.echoAnswer === false ? false : true;
|
|
56
|
+
return { schemaVersion: SETTINGS_SCHEMA_VERSION, allowedTools, historyLimit, echoAnswer };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 把 updateSettings 的入参收敛成「只含已知字段」的补丁。
|
|
61
|
+
* **单独抽出来**是为了单测能直接断言 `echoAnswer` 没被漏掉(2026-11-18 真机踩到:
|
|
62
|
+
* updateSettings 手写 spread 时漏了这个新字段,设置保存后又被默认值覆盖)。
|
|
63
|
+
* @param {any} input
|
|
64
|
+
* @returns {Record<string, unknown>}
|
|
65
|
+
*/
|
|
66
|
+
export function buildSettingsPatch(input) {
|
|
67
|
+
const source = input !== null && typeof input === "object" ? input : {};
|
|
68
|
+
/** @type {Record<string, unknown>} */
|
|
69
|
+
const patch = {};
|
|
70
|
+
if (source.allowedTools !== undefined) patch.allowedTools = source.allowedTools;
|
|
71
|
+
if (source.historyLimit !== undefined) patch.historyLimit = source.historyLimit;
|
|
72
|
+
if (source.echoAnswer !== undefined) patch.echoAnswer = source.echoAnswer;
|
|
73
|
+
return patch;
|
|
53
74
|
}
|
|
54
75
|
|
|
55
76
|
/**
|
|
56
77
|
* 读设置;文件缺失、坏 JSON、坏字段一律静默回落到默认值。
|
|
57
78
|
* @param {string} dataRoot
|
|
58
|
-
* @returns {Promise<{ schemaVersion: number, allowedTools: string[], historyLimit: number }>}
|
|
79
|
+
* @returns {Promise<{ schemaVersion: number, allowedTools: string[], historyLimit: number, echoAnswer: boolean }>}
|
|
59
80
|
*/
|
|
60
81
|
export async function loadSettings(dataRoot) {
|
|
61
82
|
let text;
|
|
@@ -75,7 +96,7 @@ export async function loadSettings(dataRoot) {
|
|
|
75
96
|
* 原子写设置(先写临时文件再 rename)。
|
|
76
97
|
* @param {string} dataRoot
|
|
77
98
|
* @param {any} patch 只合并已知字段
|
|
78
|
-
* @returns {Promise<{ schemaVersion: number, allowedTools: string[], historyLimit: number }>}
|
|
99
|
+
* @returns {Promise<{ schemaVersion: number, allowedTools: string[], historyLimit: number, echoAnswer: boolean }>}
|
|
79
100
|
*/
|
|
80
101
|
export async function saveSettings(dataRoot, patch) {
|
|
81
102
|
const current = await loadSettings(dataRoot);
|
package/lib/threads.js
CHANGED
|
@@ -144,6 +144,25 @@ export function listThreads(records) {
|
|
|
144
144
|
.sort((a, b) => a.at - b.at);
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
/**
|
|
148
|
+
* 线程级转正:用**首问**当「我问了什么」,用**最后一轮答案**当「结论」。
|
|
149
|
+
*
|
|
150
|
+
* 为什么不是只取最后一轮:线程追问两次后,用户说「转正」通常指整条旁问线索,
|
|
151
|
+
* 只把最后一次追问塞进草稿会丢掉原始问题(2026-11-18 可用性测试发现)。
|
|
152
|
+
* @param {any[]} records 该会话的历史记录
|
|
153
|
+
* @param {string} threadId
|
|
154
|
+
* @returns {any | undefined}
|
|
155
|
+
*/
|
|
156
|
+
export function promoteRecordForThread(records, threadId) {
|
|
157
|
+
const wanted = String(threadId ?? "");
|
|
158
|
+
if (wanted === "") return undefined;
|
|
159
|
+
const thread = groupThreads(records).find((entry) => entry.threadId === wanted);
|
|
160
|
+
if (thread === undefined) return undefined;
|
|
161
|
+
const first = thread.items[0];
|
|
162
|
+
const last = thread.items[thread.items.length - 1];
|
|
163
|
+
return { ...last, question: String(first?.question ?? last?.question ?? "") };
|
|
164
|
+
}
|
|
165
|
+
|
|
147
166
|
/**
|
|
148
167
|
* 把一条旁问渲染成可插入草稿的文本(**只生成文本,绝不发送**)。
|
|
149
168
|
*
|
package/locale/en.json
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"meta": "btw · new {newTokens} tokens · cached {cachedTokens} · {ms}",
|
|
14
14
|
"reopen": "Last side question: {question}",
|
|
15
15
|
"truncated": "The answer was cut off; ask again to retry.",
|
|
16
|
-
"questionHeading": "Side question: {question}"
|
|
16
|
+
"questionHeading": "Side question: {question}",
|
|
17
|
+
"panelOnly": "Side question answered; the full answer is in the side-question panel."
|
|
17
18
|
},
|
|
18
19
|
"error": {
|
|
19
20
|
"forkUnavailable": "Side questions are unavailable right now (the subagent runtime is not loaded).",
|
package/locale/zh.json
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"meta": "旁问 · 新增 {newTokens} tokens · 命中缓存 {cachedTokens} · {ms}",
|
|
14
14
|
"reopen": "上一条旁问:{question}",
|
|
15
15
|
"truncated": "答案被截断,可再问一次重试。",
|
|
16
|
-
"questionHeading": "旁问:{question}"
|
|
16
|
+
"questionHeading": "旁问:{question}",
|
|
17
|
+
"panelOnly": "旁问已完成,完整答案见旁问面板。"
|
|
17
18
|
},
|
|
18
19
|
"error": {
|
|
19
20
|
"forkUnavailable": "暂时无法旁问(子代理运行时未加载)。",
|