dsh-mcviseron-plugin 0.6.4 → 0.6.5
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/CHANGELOG.md +21 -5
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/docs/release.md +3 -3
- package/docs/session-end.md +1 -1
- package/lib/client.js +102 -162
- package/lib/index.js +64 -16
- package/package.json +1 -1
- package/src/client/SessionEndControl.tsx +113 -166
- package/src/client/locales.ts +2 -2
- package/src/client/primitives.d.ts +37 -1
- package/src/session-end/index.ts +74 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
本项目的所有重要变更都记录在此文件中,格式基于 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循 [Semantic Versioning](https://semver.org/lang/zh-CN/)。
|
|
4
|
-
|
|
5
1
|
## [Unreleased]
|
|
6
2
|
|
|
7
3
|
### 计划中
|
|
@@ -11,6 +7,26 @@
|
|
|
11
7
|
- Restart 组件支持 macOS/Linux(当前仅 Windows 桌面版)。
|
|
12
8
|
- 把定时巡检任务 prompt 更新为当前单条目架构。
|
|
13
9
|
|
|
10
|
+
## [0.6.5] - 2026-10-23
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **AI 重启判断指引**:为 `set_session_end_action` 增加明确的 WHEN / WHEN NOT 规则,并注册 `plugin:mcviseron-session-end` system prompt 段落:只有本轮修改了 DSH 插件源码 / `lib` / `cordis.patch.yml` / profile loader / 仅启动时读取的配置,且已构建验证时才建议重启;普通项目文件、文档、仅测试、live 设置、EDA/MATLAB/STM32、todo 变更不触发。AI 在最终回复前设置,动作在最终文字显示完后执行。
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- **`set_session_end_action` 注册失败**:DSH 的 tool output JSON Schema 不支持在 boolean/string 字段上写 `required: true`;原定义导致整个工具注册被拒,AI 工具列表里根本没有它。改为对象级 `required: ['ok','action','requestedBy','message']`,并补回归测试。
|
|
19
|
+
- **会话后动作设置后不触发**:`session/event` 监听注册在嵌套子上下文时收不到 `turn/end`,state 会一直停在 restart 但不会重启;改为注册在 `ctx.root` 并用 effect 清理。新 turn 开始时不再删除动作,而是取消本次计时并在该 turn 结束后重新排队,避免用户追问时把重启静默吞掉。
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- **会话后动作下拉改用官方原语**:触发按钮/菜单改用 `@deepseek-ai/dsh-client-ui-primitives` 的 `Menu`、`IconChevronDownOutlineRegular` 等组件,列表宽度(144–360px)、行高 34px、13px 字号、图标尺寸、勾选标记与键盘/portal 行为都与「自动审查」下拉一致;加入随动作变化的官方图标(时钟/刷新/关闭/停止)。
|
|
24
|
+
- **“关闭”选项改名“不做操作”**:避免与“关闭 DSH / 关闭电脑”混淆;英文为 “No action”。
|
|
25
|
+
|
|
26
|
+
### Tests
|
|
27
|
+
|
|
28
|
+
- 合计 **92 项测试**。
|
|
29
|
+
|
|
14
30
|
## [0.6.4] - 2026-10-23
|
|
15
31
|
|
|
16
32
|
### Fixed
|
|
@@ -21,7 +37,7 @@
|
|
|
21
37
|
|
|
22
38
|
### Added
|
|
23
39
|
|
|
24
|
-
-
|
|
40
|
+
- **会话后动作**:输入框左侧「会话后重启」下拉(不做操作 / 重启 DSH / 关闭 DSH / 关闭电脑),默认关闭且每次 DSH 启动重置;最终回复完整显示后执行一次。
|
|
25
41
|
- **AI 工具** `set_session_end_action`:AI 可在改完插件后设置重启/关闭 DSH;AI 设置时输入框显示醒目非弹窗提示,关机仅用户可选。
|
|
26
42
|
- **重启任务探寻**:会话后重启会等待所有运行中的 agent turn(含等待审批/回答)与后台 job 结束;设置页的重启按钮仍立即执行。
|
|
27
43
|
- **邮件联动**:已安装且配置可发送的 `dsh-email-notify` 时,AI 开启动作会复用其 SMTP 配置发送提醒邮件(不修改邮件插件);可在设置页关闭或改模板。
|
package/README.en.md
CHANGED
|
@@ -50,7 +50,7 @@ MCviseron's **master plugin for DeepSeek Harness (DSH)**: one npm package and on
|
|
|
50
50
|
|
|
51
51
|
### 5. After-session action
|
|
52
52
|
|
|
53
|
-
- A **“Restart after session”** dropdown left of the composer:
|
|
53
|
+
- A **“Restart after session”** dropdown left of the composer: No action / Restart DSH / Close DSH / Shut down PC. It starts with No action on every DSH launch.
|
|
54
54
|
- Runs once after the final reply has fully rendered (3 s grace by default); sending a new message during the grace cancels it.
|
|
55
55
|
- The AI can arm **restart** or **close DSH** through `set_session_end_action` (never shutdown). The composer shows a colored, non-modal reminder; shutdown is user-only.
|
|
56
56
|
- **Restart performs a task probe**: it waits while any agent turn (including one waiting for approval/answer) or background job is running, then restarts. Close/shutdown do not wait. **The Settings restart button is not affected** and still runs immediately.
|
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ MCviseron 的 **DeepSeek Harness(DSH)总插件**:一个 npm 包、一个 `
|
|
|
54
54
|
|
|
55
55
|
### 5. 会话后动作
|
|
56
56
|
|
|
57
|
-
- 对话输入框左侧新增 **「会话后重启」**
|
|
57
|
+
- 对话输入框左侧新增 **「会话后重启」** 下拉:不做操作 / 重启 DSH / 关闭 DSH / 关闭电脑;默认不做操作,每次 DSH 启动都从不做操作开始。
|
|
58
58
|
- 本轮最终回复完整显示后(默认再等 3 秒)执行一次;如果用户在这段等待内发了新消息,动作取消。
|
|
59
59
|
- AI 通过工具 `set_session_end_action` 设置 **重启** 或 **关闭 DSH**(不能设置关机)。AI 设置后,输入框出现醒目的非弹窗提示;关机只能由用户在下拉里选择。
|
|
60
60
|
- **重启会先做任务探寻**:只要还有运行中的 agent 会话(含等待审批/回答)或后台 job,就持续等待,直到全部结束;关闭 DSH / 关机不等待。**设置页的重启按钮不受此约束**,仍然立即执行。
|
package/docs/release.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## 当前状态(2026-10-23)
|
|
4
4
|
|
|
5
|
-
- 包名 **`dsh-mcviseron-plugin`
|
|
5
|
+
- 包名 **`dsh-mcviseron-plugin` 当前发布 0.6.5**;v0.6.3 的 host bundle 导入缺陷由 v0.6.4 修复,v0.6.5 修复会话后动作工具注册与 turn/end 监听。
|
|
6
6
|
- npm 账号 `mcviseron` 已恢复正常,可执行首次手动发布。
|
|
7
7
|
- 本机全局 registry 指向 npmmirror,发布时必须显式指定 `--registry=https://registry.npmjs.org/`。
|
|
8
8
|
- 首次发布 **v0.6.1 已手动完成**;从 **v0.6.2** 起由 `.github/workflows/publish.yml` 通过 OIDC Trusted Publishing 发布,tag 推送即发布。
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
|
|
50
50
|
```powershell
|
|
51
51
|
npm view dsh-mcviseron-plugin version dist-tags.latest --registry=https://registry.npmjs.org/
|
|
52
|
-
curl.exe -sI https://registry.npmjs.org/dsh-mcviseron-plugin/-/dsh-mcviseron-plugin-0.6.
|
|
52
|
+
curl.exe -sI https://registry.npmjs.org/dsh-mcviseron-plugin/-/dsh-mcviseron-plugin-0.6.5.tgz | Select-Object -First 1
|
|
53
53
|
curl.exe -X PUT "https://registry.npmmirror.com/-/package/dsh-mcviseron-plugin/syncs"
|
|
54
54
|
```
|
|
55
55
|
|
|
@@ -77,7 +77,7 @@ Trusted Publisher 绑定后,**推送 `v*` tag 即直接发布**,不再需要
|
|
|
77
77
|
|
|
78
78
|
> `workflow_dispatch` 默认只做 `npm pack --dry-run`;要发布当前 `main` 的版本,取消勾选 `dry-run` 再运行。
|
|
79
79
|
>
|
|
80
|
-
> 从 v0.6.3 起 tag 推送直接发布;v0.6.4 覆盖 v0.6.3
|
|
80
|
+
> 从 v0.6.3 起 tag 推送直接发布;v0.6.4 覆盖 v0.6.3 的启动导入缺陷;v0.6.5 修复会话后动作。
|
|
81
81
|
|
|
82
82
|
## 回滚与故障
|
|
83
83
|
|
package/docs/session-end.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
| 动作 | 谁可以设置 | 执行时机 | 是否等待任务 |
|
|
8
8
|
| --- | --- | --- | --- |
|
|
9
|
-
|
|
|
9
|
+
| 不做操作 | 用户 / AI | — | — |
|
|
10
10
|
| 重启 DSH | 用户 / AI | 本轮最终回复显示完 + `graceMs` | **是**:等待所有运行中的 agent turn 和后台 job |
|
|
11
11
|
| 关闭 DSH | 用户 / AI | 同上 | 否 |
|
|
12
12
|
| 关闭电脑 | **仅用户** | 同上 | 否 |
|
package/lib/client.js
CHANGED
|
@@ -456,6 +456,7 @@ function FallbackRestartRow({ t }) {
|
|
|
456
456
|
|
|
457
457
|
// src/client/SessionEndControl.tsx
|
|
458
458
|
var import_react4 = require("react");
|
|
459
|
+
var import_dsh_client_ui_primitives2 = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
459
460
|
|
|
460
461
|
// src/api.ts
|
|
461
462
|
var MCVISERON_API = {
|
|
@@ -478,13 +479,21 @@ var INITIAL = {
|
|
|
478
479
|
runningJobs: 0,
|
|
479
480
|
available: { restart: true, close: true, shutdown: true }
|
|
480
481
|
};
|
|
482
|
+
var TRIGGER_CSS = [
|
|
483
|
+
".mcviseron-session-end-trigger:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}",
|
|
484
|
+
".mcviseron-session-end-trigger:focus-visible{box-shadow:0 0 0 2px var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline:none}",
|
|
485
|
+
".mcviseron-session-end-trigger:disabled{color:var(--dsw-alias-label-dimmed);cursor:default}",
|
|
486
|
+
".mcviseron-session-end-trigger svg{width:14px;height:14px}",
|
|
487
|
+
".mcviseron-session-end-chevron{display:inline-flex;transition:transform .12s;color:var(--dsw-alias-label-caption)}",
|
|
488
|
+
".mcviseron-session-end-chevron.open{transform:rotate(180deg)}"
|
|
489
|
+
].join("\n");
|
|
481
490
|
var labelStyle = {
|
|
482
491
|
display: "inline-flex",
|
|
483
492
|
alignItems: "center",
|
|
484
|
-
gap:
|
|
485
|
-
padding: "0
|
|
493
|
+
gap: 4,
|
|
494
|
+
padding: "0 4px",
|
|
486
495
|
height: 28,
|
|
487
|
-
borderRadius:
|
|
496
|
+
borderRadius: "var(--dsw-radius-sm)",
|
|
488
497
|
fontSize: 12,
|
|
489
498
|
lineHeight: 1.3,
|
|
490
499
|
color: "var(--dsw-alias-label-secondary)",
|
|
@@ -493,47 +502,20 @@ var labelStyle = {
|
|
|
493
502
|
var triggerStyle = {
|
|
494
503
|
display: "inline-flex",
|
|
495
504
|
alignItems: "center",
|
|
496
|
-
|
|
497
|
-
gap: 6,
|
|
505
|
+
gap: 4,
|
|
498
506
|
height: 28,
|
|
499
|
-
minWidth:
|
|
500
|
-
maxWidth:
|
|
501
|
-
|
|
502
|
-
border: "
|
|
503
|
-
|
|
504
|
-
color: "var(--dsw-alias-label-primary)",
|
|
505
|
-
fontSize: 12,
|
|
506
|
-
lineHeight: 1.3,
|
|
507
|
-
padding: "0 8px",
|
|
508
|
-
cursor: "pointer"
|
|
509
|
-
};
|
|
510
|
-
var menuStyle = {
|
|
511
|
-
position: "fixed",
|
|
512
|
-
zIndex: 1e4,
|
|
513
|
-
padding: 6,
|
|
514
|
-
display: "flex",
|
|
515
|
-
flexDirection: "column",
|
|
516
|
-
gap: 2,
|
|
517
|
-
borderRadius: 14,
|
|
518
|
-
border: "1px solid var(--dsw-alias-border-l3)",
|
|
519
|
-
background: "var(--dsw-alias-bg-layer-2)",
|
|
520
|
-
boxShadow: "0 18px 44px rgba(0, 0, 0, 0.32)"
|
|
521
|
-
};
|
|
522
|
-
var menuOptionStyle = {
|
|
523
|
-
display: "flex",
|
|
524
|
-
alignItems: "center",
|
|
525
|
-
justifyContent: "space-between",
|
|
526
|
-
gap: 10,
|
|
527
|
-
width: "100%",
|
|
528
|
-
border: 0,
|
|
529
|
-
borderRadius: 10,
|
|
507
|
+
minWidth: 0,
|
|
508
|
+
maxWidth: 220,
|
|
509
|
+
padding: "0 4px 0 8px",
|
|
510
|
+
border: "none",
|
|
511
|
+
borderRadius: "var(--dsw-radius-sm)",
|
|
530
512
|
background: "transparent",
|
|
531
|
-
color: "var(--dsw-alias-label-
|
|
513
|
+
color: "var(--dsw-alias-label-secondary)",
|
|
514
|
+
cursor: "pointer",
|
|
515
|
+
outline: "none",
|
|
532
516
|
fontSize: 13,
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
textAlign: "left",
|
|
536
|
-
cursor: "pointer"
|
|
517
|
+
fontWeight: 500,
|
|
518
|
+
lineHeight: "20px"
|
|
537
519
|
};
|
|
538
520
|
var noticeStyle = {
|
|
539
521
|
display: "inline-flex",
|
|
@@ -555,15 +537,18 @@ var shutdownNoticeStyle = {
|
|
|
555
537
|
background: "var(--dsw-alias-state-error-tertiary)",
|
|
556
538
|
color: "var(--dsw-alias-state-error-primary)"
|
|
557
539
|
};
|
|
540
|
+
function triggerIcon(mode) {
|
|
541
|
+
if (mode === "restart") return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_dsh_client_ui_primitives2.IconRefreshOutlineRegular, {});
|
|
542
|
+
if (mode === "close") return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_dsh_client_ui_primitives2.IconCloseCircleFillRegular, {});
|
|
543
|
+
if (mode === "shutdown") return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_dsh_client_ui_primitives2.IconStopFillRegular, {});
|
|
544
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_dsh_client_ui_primitives2.IconClockOutlineRegular, {});
|
|
545
|
+
}
|
|
558
546
|
function SessionEndControl(props) {
|
|
559
547
|
const { t } = props;
|
|
560
548
|
const sessionId = props.sessionId;
|
|
561
549
|
const [state, setState] = (0, import_react4.useState)(INITIAL);
|
|
562
550
|
const [busy, setBusy] = (0, import_react4.useState)(false);
|
|
563
551
|
const [open, setOpen] = (0, import_react4.useState)(false);
|
|
564
|
-
const [menu, setMenu] = (0, import_react4.useState)({ left: 0, bottom: 0, minWidth: 0 });
|
|
565
|
-
const triggerRef = (0, import_react4.useRef)(null);
|
|
566
|
-
const menuRef = (0, import_react4.useRef)(null);
|
|
567
552
|
(0, import_react4.useEffect)(() => {
|
|
568
553
|
if (sessionId === void 0 || sessionId === "") {
|
|
569
554
|
setState(INITIAL);
|
|
@@ -579,11 +564,7 @@ function SessionEndControl(props) {
|
|
|
579
564
|
});
|
|
580
565
|
const body = await response.json();
|
|
581
566
|
if (cancelled || body.ok !== true) return;
|
|
582
|
-
setState((prev) => ({
|
|
583
|
-
...prev,
|
|
584
|
-
...body,
|
|
585
|
-
available: body.available ?? prev.available
|
|
586
|
-
}));
|
|
567
|
+
setState((prev) => ({ ...prev, ...body, available: body.available ?? prev.available }));
|
|
587
568
|
} catch {
|
|
588
569
|
}
|
|
589
570
|
};
|
|
@@ -596,46 +577,7 @@ function SessionEndControl(props) {
|
|
|
596
577
|
clearInterval(timer);
|
|
597
578
|
};
|
|
598
579
|
}, [sessionId]);
|
|
599
|
-
(0, import_react4.useEffect)(() => {
|
|
600
|
-
if (!open) return;
|
|
601
|
-
const close = () => {
|
|
602
|
-
setOpen(false);
|
|
603
|
-
};
|
|
604
|
-
const onPointer = (event) => {
|
|
605
|
-
const target = event.target;
|
|
606
|
-
if (triggerRef.current?.contains(target) || menuRef.current?.contains(target)) return;
|
|
607
|
-
setOpen(false);
|
|
608
|
-
};
|
|
609
|
-
const onKey = (event) => {
|
|
610
|
-
if (event.key === "Escape") setOpen(false);
|
|
611
|
-
};
|
|
612
|
-
document.addEventListener("mousedown", onPointer);
|
|
613
|
-
document.addEventListener("keydown", onKey);
|
|
614
|
-
window.addEventListener("resize", close);
|
|
615
|
-
window.addEventListener("scroll", close, true);
|
|
616
|
-
return () => {
|
|
617
|
-
document.removeEventListener("mousedown", onPointer);
|
|
618
|
-
document.removeEventListener("keydown", onKey);
|
|
619
|
-
window.removeEventListener("resize", close);
|
|
620
|
-
window.removeEventListener("scroll", close, true);
|
|
621
|
-
};
|
|
622
|
-
}, [open]);
|
|
623
580
|
if (sessionId === void 0 || sessionId === "") return null;
|
|
624
|
-
const toggleMenu = () => {
|
|
625
|
-
if (open) {
|
|
626
|
-
setOpen(false);
|
|
627
|
-
return;
|
|
628
|
-
}
|
|
629
|
-
const rect = triggerRef.current?.getBoundingClientRect();
|
|
630
|
-
if (rect === void 0) return;
|
|
631
|
-
const minWidth = Math.max(rect.width, 176);
|
|
632
|
-
const left = Math.min(
|
|
633
|
-
Math.max(8, rect.left),
|
|
634
|
-
Math.max(8, window.innerWidth - minWidth - 8)
|
|
635
|
-
);
|
|
636
|
-
setMenu({ left, bottom: window.innerHeight - rect.top + 6, minWidth });
|
|
637
|
-
setOpen(true);
|
|
638
|
-
};
|
|
639
581
|
const change = (mode) => {
|
|
640
582
|
setOpen(false);
|
|
641
583
|
if (mode === "shutdown" && typeof window !== "undefined" && typeof window.confirm === "function") {
|
|
@@ -654,11 +596,7 @@ function SessionEndControl(props) {
|
|
|
654
596
|
body: JSON.stringify({ sessionId, mode })
|
|
655
597
|
}).then(async (response) => await response.json()).then((body) => {
|
|
656
598
|
if (body.ok === true) {
|
|
657
|
-
setState((prev) => ({
|
|
658
|
-
...prev,
|
|
659
|
-
...body,
|
|
660
|
-
available: body.available ?? prev.available
|
|
661
|
-
}));
|
|
599
|
+
setState((prev) => ({ ...prev, ...body, available: body.available ?? prev.available }));
|
|
662
600
|
}
|
|
663
601
|
}).catch(() => {
|
|
664
602
|
}).finally(() => {
|
|
@@ -669,7 +607,60 @@ function SessionEndControl(props) {
|
|
|
669
607
|
const aiRequested = state.mode !== "off" && state.requestedBy === "ai";
|
|
670
608
|
const shutdown = state.mode === "shutdown";
|
|
671
609
|
const notice = shutdown ? t("sessionEnd.userShutdown") : aiRequested ? state.mode === "close" ? t("sessionEnd.aiClose") : state.waiting ? t("sessionEnd.aiWaiting") : t("sessionEnd.aiRestart") : "";
|
|
610
|
+
const items = [
|
|
611
|
+
{ id: "off", label: t("sessionEnd.off"), icon: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_dsh_client_ui_primitives2.IconClockOutlineRegular, {}) },
|
|
612
|
+
{
|
|
613
|
+
id: "restart",
|
|
614
|
+
label: t("sessionEnd.restart"),
|
|
615
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_dsh_client_ui_primitives2.IconRefreshOutlineRegular, {}),
|
|
616
|
+
disabled: !state.available.restart
|
|
617
|
+
},
|
|
618
|
+
{
|
|
619
|
+
id: "close",
|
|
620
|
+
label: t("sessionEnd.close"),
|
|
621
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_dsh_client_ui_primitives2.IconCloseCircleFillRegular, {}),
|
|
622
|
+
disabled: !state.available.close
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
id: "shutdown",
|
|
626
|
+
label: t("sessionEnd.shutdown"),
|
|
627
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_dsh_client_ui_primitives2.IconStopFillRegular, {}),
|
|
628
|
+
disabled: !state.available.shutdown,
|
|
629
|
+
danger: true
|
|
630
|
+
}
|
|
631
|
+
];
|
|
632
|
+
const anchor = /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
633
|
+
"button",
|
|
634
|
+
{
|
|
635
|
+
type: "button",
|
|
636
|
+
className: "mcviseron-session-end-trigger",
|
|
637
|
+
"aria-label": t("sessionEnd.label"),
|
|
638
|
+
"aria-haspopup": "menu",
|
|
639
|
+
"aria-expanded": open,
|
|
640
|
+
title: t("sessionEnd.hint"),
|
|
641
|
+
style: triggerStyle,
|
|
642
|
+
disabled: busy,
|
|
643
|
+
onClick: () => {
|
|
644
|
+
setOpen((value) => !value);
|
|
645
|
+
},
|
|
646
|
+
children: [
|
|
647
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { display: "inline-flex", flex: "none" }, children: triggerIcon(state.mode) }),
|
|
648
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: t(
|
|
649
|
+
state.mode === "off" ? "sessionEnd.off" : state.mode === "restart" ? "sessionEnd.restart" : state.mode === "close" ? "sessionEnd.close" : "sessionEnd.shutdown"
|
|
650
|
+
) }),
|
|
651
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
652
|
+
"span",
|
|
653
|
+
{
|
|
654
|
+
className: open ? "mcviseron-session-end-chevron open" : "mcviseron-session-end-chevron",
|
|
655
|
+
"aria-hidden": true,
|
|
656
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_dsh_client_ui_primitives2.IconChevronDownOutlineRegular, {})
|
|
657
|
+
}
|
|
658
|
+
)
|
|
659
|
+
]
|
|
660
|
+
}
|
|
661
|
+
);
|
|
672
662
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { style: { display: "inline-flex", alignItems: "center", gap: 6, flexWrap: "wrap" }, children: [
|
|
663
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("style", { children: TRIGGER_CSS }),
|
|
673
664
|
notice !== "" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
674
665
|
"span",
|
|
675
666
|
{
|
|
@@ -678,75 +669,24 @@ function SessionEndControl(props) {
|
|
|
678
669
|
children: notice
|
|
679
670
|
}
|
|
680
671
|
),
|
|
681
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("style", { children: `
|
|
682
|
-
.mcviseron-session-end-trigger { transition: background 120ms ease, border-color 120ms ease; }
|
|
683
|
-
.mcviseron-session-end-trigger:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, var(--dsw-alias-bg-layer-3)); }
|
|
684
|
-
.mcviseron-session-end-option { transition: background 120ms ease; }
|
|
685
|
-
.mcviseron-session-end-option:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, var(--dsw-alias-bg-layer-3)); }
|
|
686
|
-
` }),
|
|
687
672
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { style: labelStyle, title: t("sessionEnd.hint"), children: [
|
|
688
673
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: t("sessionEnd.label") }),
|
|
689
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.
|
|
690
|
-
|
|
674
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
675
|
+
import_dsh_client_ui_primitives2.Menu,
|
|
691
676
|
{
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
title: t("sessionEnd.hint"),
|
|
699
|
-
style: {
|
|
700
|
-
...triggerStyle,
|
|
701
|
-
borderColor: aiRequested ? "var(--dsw-alias-state-warn-primary)" : "var(--dsw-alias-border-l3)"
|
|
677
|
+
open,
|
|
678
|
+
anchor,
|
|
679
|
+
items,
|
|
680
|
+
selectedId: state.mode,
|
|
681
|
+
onSelect: (id) => {
|
|
682
|
+
change(id);
|
|
702
683
|
},
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "aria-hidden": true, style: { fontSize: 10, opacity: 0.75 }, children: open ? "\u25B4" : "\u25BE" })
|
|
710
|
-
]
|
|
711
|
-
}
|
|
712
|
-
),
|
|
713
|
-
open && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
714
|
-
"div",
|
|
715
|
-
{
|
|
716
|
-
ref: menuRef,
|
|
717
|
-
role: "listbox",
|
|
718
|
-
"aria-label": t("sessionEnd.label"),
|
|
719
|
-
style: { ...menuStyle, left: menu.left, bottom: menu.bottom, minWidth: menu.minWidth },
|
|
720
|
-
children: [
|
|
721
|
-
["off", "sessionEnd.off", false],
|
|
722
|
-
["restart", "sessionEnd.restart", !state.available.restart],
|
|
723
|
-
["close", "sessionEnd.close", !state.available.close],
|
|
724
|
-
["shutdown", "sessionEnd.shutdown", !state.available.shutdown]
|
|
725
|
-
].map(([value, label, disabled]) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
726
|
-
"button",
|
|
727
|
-
{
|
|
728
|
-
type: "button",
|
|
729
|
-
role: "option",
|
|
730
|
-
"aria-selected": state.mode === value,
|
|
731
|
-
disabled,
|
|
732
|
-
className: "mcviseron-session-end-option",
|
|
733
|
-
style: {
|
|
734
|
-
...menuOptionStyle,
|
|
735
|
-
color: state.mode === value ? "var(--dsw-alias-brand-primary)" : menuOptionStyle.color,
|
|
736
|
-
fontWeight: state.mode === value ? 600 : 400,
|
|
737
|
-
opacity: disabled ? 0.45 : 1,
|
|
738
|
-
cursor: disabled ? "default" : "pointer"
|
|
739
|
-
},
|
|
740
|
-
onClick: () => {
|
|
741
|
-
if (!disabled) change(value);
|
|
742
|
-
},
|
|
743
|
-
children: [
|
|
744
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: t(label) }),
|
|
745
|
-
state.mode === value ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "aria-hidden": true, children: "\u2713" }) : null
|
|
746
|
-
]
|
|
747
|
-
},
|
|
748
|
-
value
|
|
749
|
-
))
|
|
684
|
+
onClose: () => {
|
|
685
|
+
setOpen(false);
|
|
686
|
+
},
|
|
687
|
+
align: "end",
|
|
688
|
+
side: "top",
|
|
689
|
+
portal: true
|
|
750
690
|
}
|
|
751
691
|
)
|
|
752
692
|
] })
|
|
@@ -836,7 +776,7 @@ async function writePluginConfig(path, value) {
|
|
|
836
776
|
}
|
|
837
777
|
|
|
838
778
|
// src/client/ConfigForm.tsx
|
|
839
|
-
var
|
|
779
|
+
var import_dsh_client_ui_primitives3 = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
840
780
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
841
781
|
function readPath(config, path) {
|
|
842
782
|
let current = config;
|
|
@@ -957,7 +897,7 @@ function renderControl(field, value, disabled, commit, t) {
|
|
|
957
897
|
switch (field.kind) {
|
|
958
898
|
case "switch":
|
|
959
899
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
960
|
-
|
|
900
|
+
import_dsh_client_ui_primitives3.Switch,
|
|
961
901
|
{
|
|
962
902
|
checked: value === true,
|
|
963
903
|
label: t(field.label),
|
|
@@ -1379,7 +1319,7 @@ var zh = {
|
|
|
1379
1319
|
"restart.confirm": "\u786E\u5B9A\u8981\u91CD\u542F DeepSeek Harness \u5417\uFF1F\u6B63\u5728\u8FD0\u884C\u7684\u4EFB\u52A1\u4F1A\u88AB\u4E2D\u65AD\u3002",
|
|
1380
1320
|
"sessionEnd.label": "\u4F1A\u8BDD\u540E\u91CD\u542F",
|
|
1381
1321
|
"sessionEnd.hint": "\u672C\u8F6E\u6700\u7EC8\u56DE\u590D\u5B8C\u6574\u663E\u793A\u540E\u6267\u884C\uFF1BAI \u9700\u8981\u91CD\u542F\u63D2\u4EF6\u65F6\u53EF\u81EA\u52A8\u8BBE\u7F6E\u3002",
|
|
1382
|
-
"sessionEnd.off": "\
|
|
1322
|
+
"sessionEnd.off": "\u4E0D\u505A\u64CD\u4F5C",
|
|
1383
1323
|
"sessionEnd.restart": "\u91CD\u542F DSH",
|
|
1384
1324
|
"sessionEnd.close": "\u5173\u95ED DSH",
|
|
1385
1325
|
"sessionEnd.shutdown": "\u5173\u95ED\u7535\u8111",
|
|
@@ -1500,7 +1440,7 @@ var en = {
|
|
|
1500
1440
|
"restart.confirm": "Restart DeepSeek Harness now? Running tasks will be interrupted.",
|
|
1501
1441
|
"sessionEnd.label": "Restart after session",
|
|
1502
1442
|
"sessionEnd.hint": "Runs after the final reply is fully displayed; the AI can arm it when a plugin change needs a restart.",
|
|
1503
|
-
"sessionEnd.off": "
|
|
1443
|
+
"sessionEnd.off": "No action",
|
|
1504
1444
|
"sessionEnd.restart": "Restart DSH",
|
|
1505
1445
|
"sessionEnd.close": "Close DSH",
|
|
1506
1446
|
"sessionEnd.shutdown": "Shut down PC",
|
package/lib/index.js
CHANGED
|
@@ -12323,6 +12323,13 @@ var DEFAULT_SESSION_END_CONFIG = {
|
|
|
12323
12323
|
"\u7406\u7531\uFF1A{{reason}}"
|
|
12324
12324
|
].join("\n")
|
|
12325
12325
|
};
|
|
12326
|
+
var SESSION_END_GUIDANCE = [
|
|
12327
|
+
"[session-end action] set_session_end_action arms one one-shot action after this turn.",
|
|
12328
|
+
"Use it only when this turn changed DSH plugin host/client source, build output (lib/), cordis.patch.yml, profile loader entries, or a setting that is read only at startup, and the change has been built and verified.",
|
|
12329
|
+
"Do not arm it for ordinary project files, docs/README, tests-only changes, live-applied settings, EDA/MATLAB/STM32 project work, or todo-only changes. Do not arm it when nothing was built, installed, or loaded.",
|
|
12330
|
+
"Arm it during the turn, after verification and before the final answer. It runs after the final reply is fully displayed and waits for all running agent turns and background jobs.",
|
|
12331
|
+
"Use close only when the user explicitly asks to close DSH. Shutdown is user-only. If you are unsure whether a restart is required, ask the user instead of arming."
|
|
12332
|
+
].join(" ");
|
|
12326
12333
|
var Config4 = z4.object({
|
|
12327
12334
|
enabled: z4.boolean().default(DEFAULT_SESSION_END_CONFIG.enabled).volatile(),
|
|
12328
12335
|
graceMs: z4.number().min(0).max(15e3).default(DEFAULT_SESSION_END_CONFIG.graceMs).volatile(),
|
|
@@ -12520,9 +12527,13 @@ function createSessionEndController(deps = {}) {
|
|
|
12520
12527
|
return view(sessionId);
|
|
12521
12528
|
},
|
|
12522
12529
|
onTurnStart(sessionId) {
|
|
12523
|
-
|
|
12530
|
+
const entry = entries.get(sessionId);
|
|
12531
|
+
if (entry !== void 0) {
|
|
12532
|
+
entry.waiting = false;
|
|
12533
|
+
entry.runningAgents = 0;
|
|
12534
|
+
entry.runningJobs = 0;
|
|
12535
|
+
}
|
|
12524
12536
|
cancel(sessionId);
|
|
12525
|
-
entries.delete(sessionId);
|
|
12526
12537
|
},
|
|
12527
12538
|
onTurnEnd(sessionId) {
|
|
12528
12539
|
const entry = entries.get(sessionId);
|
|
@@ -12561,6 +12572,7 @@ function bodySessionId(body) {
|
|
|
12561
12572
|
return typeof value === "string" && value !== "" ? value : void 0;
|
|
12562
12573
|
}
|
|
12563
12574
|
function makeSessionEndRoutes(controller) {
|
|
12575
|
+
const seen = /* @__PURE__ */ new Set();
|
|
12564
12576
|
const state = {
|
|
12565
12577
|
kind: "exact",
|
|
12566
12578
|
path: SESSION_END_API.state,
|
|
@@ -12570,6 +12582,10 @@ function makeSessionEndRoutes(controller) {
|
|
|
12570
12582
|
if (!isLoopbackRequest(req)) return json3(res, 403, { ok: false, error: "forbidden" });
|
|
12571
12583
|
const sessionId = bodySessionId(await readJsonBody3(req));
|
|
12572
12584
|
if (sessionId === void 0) return json3(res, 400, { ok: false, error: "sessionId-required" });
|
|
12585
|
+
if (!seen.has(sessionId)) {
|
|
12586
|
+
seen.add(sessionId);
|
|
12587
|
+
defaultLog("state request: session=" + sessionId);
|
|
12588
|
+
}
|
|
12573
12589
|
json3(res, 200, { ok: true, ...controller.get(sessionId) });
|
|
12574
12590
|
} catch (error) {
|
|
12575
12591
|
json3(res, 500, { ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
@@ -12609,6 +12625,27 @@ function serviceOf2(ctx, name) {
|
|
|
12609
12625
|
return void 0;
|
|
12610
12626
|
}
|
|
12611
12627
|
}
|
|
12628
|
+
function installGuidance(ctx) {
|
|
12629
|
+
const inject4 = ctx.inject;
|
|
12630
|
+
if (typeof inject4 !== "function") return;
|
|
12631
|
+
try {
|
|
12632
|
+
inject4.call(ctx, ["systemPrompt"], (scope) => {
|
|
12633
|
+
const systemPrompt = serviceOf2(scope, "systemPrompt");
|
|
12634
|
+
if (systemPrompt === void 0 || typeof systemPrompt.section !== "function") return;
|
|
12635
|
+
try {
|
|
12636
|
+
systemPrompt.section({
|
|
12637
|
+
name: "plugin:mcviseron-session-end",
|
|
12638
|
+
order: 230,
|
|
12639
|
+
text: SESSION_END_GUIDANCE
|
|
12640
|
+
});
|
|
12641
|
+
} catch (error) {
|
|
12642
|
+
defaultLog("guidance registration failed: " + (error instanceof Error ? error.message : String(error)));
|
|
12643
|
+
}
|
|
12644
|
+
});
|
|
12645
|
+
} catch (error) {
|
|
12646
|
+
defaultLog("guidance injection failed: " + (error instanceof Error ? error.message : String(error)));
|
|
12647
|
+
}
|
|
12648
|
+
}
|
|
12612
12649
|
var emailed = /* @__PURE__ */ new Map();
|
|
12613
12650
|
function installAgentTool(ctx, controller, options, log) {
|
|
12614
12651
|
const inject4 = ctx.inject;
|
|
@@ -12621,9 +12658,10 @@ function installAgentTool(ctx, controller, options, log) {
|
|
|
12621
12658
|
name: "set_session_end_action",
|
|
12622
12659
|
description: [
|
|
12623
12660
|
"Set the action DSH performs after the current turn has fully finished.",
|
|
12624
|
-
"
|
|
12625
|
-
"
|
|
12626
|
-
"
|
|
12661
|
+
"WHEN TO USE: this turn changed DSH plugin host/client source, build output (lib/), cordis.patch.yml, profile loader entries, or a setting read only at startup, and the change is built and verified.",
|
|
12662
|
+
"WHEN NOT TO USE: ordinary project files, docs/README, tests-only changes, live-applied settings, EDA/MATLAB/STM32 work, todo-only changes, or when nothing was built/installed/loaded.",
|
|
12663
|
+
"Arm restart during the turn, after verification and before the final answer. It runs after the final reply is fully displayed and waits for all running agent turns and background jobs.",
|
|
12664
|
+
"Use close only when the user explicitly asks to close DSH. Shutdown is user-only. If unsure whether a restart is required, ask the user instead of arming."
|
|
12627
12665
|
].join(" "),
|
|
12628
12666
|
parameters: {
|
|
12629
12667
|
action: {
|
|
@@ -12641,11 +12679,12 @@ function installAgentTool(ctx, controller, options, log) {
|
|
|
12641
12679
|
schema: {
|
|
12642
12680
|
type: "object",
|
|
12643
12681
|
additionalProperties: false,
|
|
12682
|
+
required: ["ok", "action", "requestedBy", "message"],
|
|
12644
12683
|
properties: {
|
|
12645
|
-
ok: { type: "boolean"
|
|
12646
|
-
action: { type: "string",
|
|
12647
|
-
requestedBy: { type: "string",
|
|
12648
|
-
message: { type: "string"
|
|
12684
|
+
ok: { type: "boolean" },
|
|
12685
|
+
action: { type: "string", enum: ["off", "restart", "close"] },
|
|
12686
|
+
requestedBy: { type: "string", enum: ["ai"] },
|
|
12687
|
+
message: { type: "string" }
|
|
12649
12688
|
}
|
|
12650
12689
|
},
|
|
12651
12690
|
render: (_args, value) => [{
|
|
@@ -12756,13 +12795,22 @@ function apply4(ctx, config) {
|
|
|
12756
12795
|
};
|
|
12757
12796
|
}, "mcviseron-session-end: routes");
|
|
12758
12797
|
if (options.enabled) {
|
|
12759
|
-
;
|
|
12760
|
-
|
|
12761
|
-
|
|
12762
|
-
|
|
12763
|
-
|
|
12764
|
-
|
|
12765
|
-
|
|
12798
|
+
const root = ctx.root;
|
|
12799
|
+
const eventBus = root ?? ctx;
|
|
12800
|
+
if (typeof eventBus.on === "function") {
|
|
12801
|
+
ctx.effect(() => {
|
|
12802
|
+
const dispose = eventBus.on?.("session/event", (session, event) => {
|
|
12803
|
+
const sessionId = sessionIdOf2(session);
|
|
12804
|
+
if (sessionId === "") return;
|
|
12805
|
+
if (event?.type === "turn/start") controller.onTurnStart(sessionId);
|
|
12806
|
+
else if (event?.type === "turn/end") controller.onTurnEnd(sessionId);
|
|
12807
|
+
});
|
|
12808
|
+
return () => {
|
|
12809
|
+
if (typeof dispose === "function") dispose();
|
|
12810
|
+
};
|
|
12811
|
+
}, "mcviseron-session-end: session events");
|
|
12812
|
+
}
|
|
12813
|
+
installGuidance(ctx);
|
|
12766
12814
|
installAgentTool(ctx, controller, options, log);
|
|
12767
12815
|
}
|
|
12768
12816
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mcviseron-plugin",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"description": "DeepSeek Harness (DSH) master plugin — one package hosting MCviseron's DSH components as separate bundle entries: a time-based light/dark Appearance schedule, an Auto-review fix (shutdown preset guard + Chinese approval-reason translation), and a todo plan guard that keeps multi-stage work advancing, and one-shot after-session restart/close actions with task-aware waiting.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import { useEffect,
|
|
1
|
+
import { useEffect, useState, type CSSProperties } from 'react'
|
|
2
|
+
import {
|
|
3
|
+
IconChevronDownOutlineRegular,
|
|
4
|
+
IconClockOutlineRegular,
|
|
5
|
+
IconCloseCircleFillRegular,
|
|
6
|
+
IconRefreshOutlineRegular,
|
|
7
|
+
IconStopFillRegular,
|
|
8
|
+
Menu,
|
|
9
|
+
} from '@deepseek-ai/dsh-client-ui-primitives'
|
|
2
10
|
import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
|
|
3
11
|
import { SESSION_END_API } from '../api.ts'
|
|
4
12
|
import type { McviseronKey } from './locales.ts'
|
|
@@ -26,6 +34,15 @@ const INITIAL: State = {
|
|
|
26
34
|
available: { restart: true, close: true, shutdown: true },
|
|
27
35
|
}
|
|
28
36
|
|
|
37
|
+
const TRIGGER_CSS = [
|
|
38
|
+
'.mcviseron-session-end-trigger:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}',
|
|
39
|
+
'.mcviseron-session-end-trigger:focus-visible{box-shadow:0 0 0 2px var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline:none}',
|
|
40
|
+
'.mcviseron-session-end-trigger:disabled{color:var(--dsw-alias-label-dimmed);cursor:default}',
|
|
41
|
+
'.mcviseron-session-end-trigger svg{width:14px;height:14px}',
|
|
42
|
+
'.mcviseron-session-end-chevron{display:inline-flex;transition:transform .12s;color:var(--dsw-alias-label-caption)}',
|
|
43
|
+
'.mcviseron-session-end-chevron.open{transform:rotate(180deg)}',
|
|
44
|
+
].join('\n')
|
|
45
|
+
|
|
29
46
|
export type SessionEndControlProps =
|
|
30
47
|
PropsRuntime<'conversation.input.left'>
|
|
31
48
|
& PropsLocale<'mcviseron'>
|
|
@@ -33,10 +50,10 @@ export type SessionEndControlProps =
|
|
|
33
50
|
const labelStyle: CSSProperties = {
|
|
34
51
|
display: 'inline-flex',
|
|
35
52
|
alignItems: 'center',
|
|
36
|
-
gap:
|
|
37
|
-
padding: '0
|
|
53
|
+
gap: 4,
|
|
54
|
+
padding: '0 4px',
|
|
38
55
|
height: 28,
|
|
39
|
-
borderRadius:
|
|
56
|
+
borderRadius: 'var(--dsw-radius-sm)',
|
|
40
57
|
fontSize: 12,
|
|
41
58
|
lineHeight: 1.3,
|
|
42
59
|
color: 'var(--dsw-alias-label-secondary)',
|
|
@@ -46,49 +63,20 @@ const labelStyle: CSSProperties = {
|
|
|
46
63
|
const triggerStyle: CSSProperties = {
|
|
47
64
|
display: 'inline-flex',
|
|
48
65
|
alignItems: 'center',
|
|
49
|
-
|
|
50
|
-
gap: 6,
|
|
66
|
+
gap: 4,
|
|
51
67
|
height: 28,
|
|
52
|
-
minWidth:
|
|
53
|
-
maxWidth:
|
|
54
|
-
|
|
55
|
-
border: '
|
|
56
|
-
|
|
57
|
-
color: 'var(--dsw-alias-label-primary)',
|
|
58
|
-
fontSize: 12,
|
|
59
|
-
lineHeight: 1.3,
|
|
60
|
-
padding: '0 8px',
|
|
61
|
-
cursor: 'pointer',
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const menuStyle: CSSProperties = {
|
|
65
|
-
position: 'fixed',
|
|
66
|
-
zIndex: 10000,
|
|
67
|
-
padding: 6,
|
|
68
|
-
display: 'flex',
|
|
69
|
-
flexDirection: 'column',
|
|
70
|
-
gap: 2,
|
|
71
|
-
borderRadius: 14,
|
|
72
|
-
border: '1px solid var(--dsw-alias-border-l3)',
|
|
73
|
-
background: 'var(--dsw-alias-bg-layer-2)',
|
|
74
|
-
boxShadow: '0 18px 44px rgba(0, 0, 0, 0.32)',
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const menuOptionStyle: CSSProperties = {
|
|
78
|
-
display: 'flex',
|
|
79
|
-
alignItems: 'center',
|
|
80
|
-
justifyContent: 'space-between',
|
|
81
|
-
gap: 10,
|
|
82
|
-
width: '100%',
|
|
83
|
-
border: 0,
|
|
84
|
-
borderRadius: 10,
|
|
68
|
+
minWidth: 0,
|
|
69
|
+
maxWidth: 220,
|
|
70
|
+
padding: '0 4px 0 8px',
|
|
71
|
+
border: 'none',
|
|
72
|
+
borderRadius: 'var(--dsw-radius-sm)',
|
|
85
73
|
background: 'transparent',
|
|
86
|
-
color: 'var(--dsw-alias-label-
|
|
74
|
+
color: 'var(--dsw-alias-label-secondary)',
|
|
75
|
+
cursor: 'pointer',
|
|
76
|
+
outline: 'none',
|
|
87
77
|
fontSize: 13,
|
|
78
|
+
fontWeight: 500,
|
|
88
79
|
lineHeight: '20px',
|
|
89
|
-
padding: '7px 10px',
|
|
90
|
-
textAlign: 'left',
|
|
91
|
-
cursor: 'pointer',
|
|
92
80
|
}
|
|
93
81
|
|
|
94
82
|
const noticeStyle: CSSProperties = {
|
|
@@ -113,12 +101,21 @@ const shutdownNoticeStyle: CSSProperties = {
|
|
|
113
101
|
color: 'var(--dsw-alias-state-error-primary)',
|
|
114
102
|
}
|
|
115
103
|
|
|
104
|
+
function triggerIcon(mode: Mode) {
|
|
105
|
+
if (mode === 'restart') return <IconRefreshOutlineRegular />
|
|
106
|
+
if (mode === 'close') return <IconCloseCircleFillRegular />
|
|
107
|
+
if (mode === 'shutdown') return <IconStopFillRegular />
|
|
108
|
+
return <IconClockOutlineRegular />
|
|
109
|
+
}
|
|
110
|
+
|
|
116
111
|
/**
|
|
117
112
|
* Composer control for the one-shot session-end action.
|
|
118
113
|
*
|
|
119
|
-
* The
|
|
120
|
-
*
|
|
121
|
-
*
|
|
114
|
+
* The trigger and menu are the official DSH primitives: the menu geometry,
|
|
115
|
+
* icons, check marker, portal placement, and keyboard handling therefore match
|
|
116
|
+
* the Auto-review permission selector. The dropdown is off by default; the
|
|
117
|
+
* server state is polled because the agent can arm it through
|
|
118
|
+
* set_session_end_action while a turn is running.
|
|
122
119
|
*/
|
|
123
120
|
export function SessionEndControl(props: SessionEndControlProps) {
|
|
124
121
|
const { t } = props
|
|
@@ -126,9 +123,6 @@ export function SessionEndControl(props: SessionEndControlProps) {
|
|
|
126
123
|
const [state, setState] = useState<State>(INITIAL)
|
|
127
124
|
const [busy, setBusy] = useState(false)
|
|
128
125
|
const [open, setOpen] = useState(false)
|
|
129
|
-
const [menu, setMenu] = useState({ left: 0, bottom: 0, minWidth: 0 })
|
|
130
|
-
const triggerRef = useRef<HTMLButtonElement>(null)
|
|
131
|
-
const menuRef = useRef<HTMLDivElement>(null)
|
|
132
126
|
|
|
133
127
|
useEffect(() => {
|
|
134
128
|
if (sessionId === undefined || sessionId === '') {
|
|
@@ -145,11 +139,7 @@ export function SessionEndControl(props: SessionEndControlProps) {
|
|
|
145
139
|
})
|
|
146
140
|
const body = await response.json() as Partial<State> & { ok?: boolean }
|
|
147
141
|
if (cancelled || body.ok !== true) return
|
|
148
|
-
setState(prev => ({
|
|
149
|
-
...prev,
|
|
150
|
-
...body,
|
|
151
|
-
available: body.available ?? prev.available,
|
|
152
|
-
}))
|
|
142
|
+
setState(prev => ({ ...prev, ...body, available: body.available ?? prev.available }))
|
|
153
143
|
} catch {
|
|
154
144
|
/* a transient poll failure leaves the last known state in place */
|
|
155
145
|
}
|
|
@@ -162,48 +152,8 @@ export function SessionEndControl(props: SessionEndControlProps) {
|
|
|
162
152
|
}
|
|
163
153
|
}, [sessionId])
|
|
164
154
|
|
|
165
|
-
useEffect(() => {
|
|
166
|
-
if (!open) return
|
|
167
|
-
const close = (): void => { setOpen(false) }
|
|
168
|
-
const onPointer = (event: MouseEvent): void => {
|
|
169
|
-
const target = event.target as Node
|
|
170
|
-
if (triggerRef.current?.contains(target) || menuRef.current?.contains(target)) return
|
|
171
|
-
setOpen(false)
|
|
172
|
-
}
|
|
173
|
-
const onKey = (event: KeyboardEvent): void => {
|
|
174
|
-
if (event.key === 'Escape') setOpen(false)
|
|
175
|
-
}
|
|
176
|
-
document.addEventListener('mousedown', onPointer)
|
|
177
|
-
document.addEventListener('keydown', onKey)
|
|
178
|
-
window.addEventListener('resize', close)
|
|
179
|
-
window.addEventListener('scroll', close, true)
|
|
180
|
-
return () => {
|
|
181
|
-
document.removeEventListener('mousedown', onPointer)
|
|
182
|
-
document.removeEventListener('keydown', onKey)
|
|
183
|
-
window.removeEventListener('resize', close)
|
|
184
|
-
window.removeEventListener('scroll', close, true)
|
|
185
|
-
}
|
|
186
|
-
}, [open])
|
|
187
|
-
|
|
188
155
|
if (sessionId === undefined || sessionId === '') return null
|
|
189
156
|
|
|
190
|
-
|
|
191
|
-
const toggleMenu = (): void => {
|
|
192
|
-
if (open) {
|
|
193
|
-
setOpen(false)
|
|
194
|
-
return
|
|
195
|
-
}
|
|
196
|
-
const rect = triggerRef.current?.getBoundingClientRect()
|
|
197
|
-
if (rect === undefined) return
|
|
198
|
-
const minWidth = Math.max(rect.width, 176)
|
|
199
|
-
const left = Math.min(
|
|
200
|
-
Math.max(8, rect.left),
|
|
201
|
-
Math.max(8, window.innerWidth - minWidth - 8),
|
|
202
|
-
)
|
|
203
|
-
setMenu({ left, bottom: window.innerHeight - rect.top + 6, minWidth })
|
|
204
|
-
setOpen(true)
|
|
205
|
-
}
|
|
206
|
-
|
|
207
157
|
const change = (mode: Mode): void => {
|
|
208
158
|
setOpen(false)
|
|
209
159
|
if (mode === 'shutdown' && typeof window !== 'undefined' && typeof window.confirm === 'function') {
|
|
@@ -224,11 +174,7 @@ export function SessionEndControl(props: SessionEndControlProps) {
|
|
|
224
174
|
.then(async response => await response.json() as Partial<State> & { ok?: boolean })
|
|
225
175
|
.then(body => {
|
|
226
176
|
if (body.ok === true) {
|
|
227
|
-
setState(prev => ({
|
|
228
|
-
...prev,
|
|
229
|
-
...body,
|
|
230
|
-
available: body.available ?? prev.available,
|
|
231
|
-
}))
|
|
177
|
+
setState(prev => ({ ...prev, ...body, available: body.available ?? prev.available }))
|
|
232
178
|
}
|
|
233
179
|
})
|
|
234
180
|
.catch(() => { /* the next poll reconciles */ })
|
|
@@ -247,8 +193,65 @@ export function SessionEndControl(props: SessionEndControlProps) {
|
|
|
247
193
|
: state.waiting ? t('sessionEnd.aiWaiting') : t('sessionEnd.aiRestart')
|
|
248
194
|
: ''
|
|
249
195
|
|
|
196
|
+
const items = [
|
|
197
|
+
{ id: 'off', label: t('sessionEnd.off'), icon: <IconClockOutlineRegular /> },
|
|
198
|
+
{
|
|
199
|
+
id: 'restart',
|
|
200
|
+
label: t('sessionEnd.restart'),
|
|
201
|
+
icon: <IconRefreshOutlineRegular />,
|
|
202
|
+
disabled: !state.available.restart,
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
id: 'close',
|
|
206
|
+
label: t('sessionEnd.close'),
|
|
207
|
+
icon: <IconCloseCircleFillRegular />,
|
|
208
|
+
disabled: !state.available.close,
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
id: 'shutdown',
|
|
212
|
+
label: t('sessionEnd.shutdown'),
|
|
213
|
+
icon: <IconStopFillRegular />,
|
|
214
|
+
disabled: !state.available.shutdown,
|
|
215
|
+
danger: true,
|
|
216
|
+
},
|
|
217
|
+
]
|
|
218
|
+
|
|
219
|
+
const anchor = (
|
|
220
|
+
<button
|
|
221
|
+
type="button"
|
|
222
|
+
className="mcviseron-session-end-trigger"
|
|
223
|
+
aria-label={t('sessionEnd.label')}
|
|
224
|
+
aria-haspopup="menu"
|
|
225
|
+
aria-expanded={open}
|
|
226
|
+
title={t('sessionEnd.hint')}
|
|
227
|
+
style={triggerStyle}
|
|
228
|
+
disabled={busy}
|
|
229
|
+
onClick={() => { setOpen(value => !value) }}
|
|
230
|
+
>
|
|
231
|
+
<span style={{ display: 'inline-flex', flex: 'none' }}>{triggerIcon(state.mode)}</span>
|
|
232
|
+
<span style={{ minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
|
233
|
+
{t(
|
|
234
|
+
state.mode === 'off'
|
|
235
|
+
? 'sessionEnd.off'
|
|
236
|
+
: state.mode === 'restart'
|
|
237
|
+
? 'sessionEnd.restart'
|
|
238
|
+
: state.mode === 'close'
|
|
239
|
+
? 'sessionEnd.close'
|
|
240
|
+
: 'sessionEnd.shutdown',
|
|
241
|
+
)}
|
|
242
|
+
</span>
|
|
243
|
+
<span
|
|
244
|
+
className={open ? 'mcviseron-session-end-chevron open' : 'mcviseron-session-end-chevron'}
|
|
245
|
+
aria-hidden
|
|
246
|
+
>
|
|
247
|
+
<IconChevronDownOutlineRegular />
|
|
248
|
+
</span>
|
|
249
|
+
</button>
|
|
250
|
+
)
|
|
251
|
+
|
|
250
252
|
return (
|
|
251
253
|
<span style={{ display: 'inline-flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
|
|
254
|
+
<style>{TRIGGER_CSS}</style>
|
|
252
255
|
{notice !== '' && (
|
|
253
256
|
<span
|
|
254
257
|
style={shutdown ? shutdownNoticeStyle : noticeStyle}
|
|
@@ -257,75 +260,19 @@ export function SessionEndControl(props: SessionEndControlProps) {
|
|
|
257
260
|
{notice}
|
|
258
261
|
</span>
|
|
259
262
|
)}
|
|
260
|
-
<style>{`
|
|
261
|
-
.mcviseron-session-end-trigger { transition: background 120ms ease, border-color 120ms ease; }
|
|
262
|
-
.mcviseron-session-end-trigger:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, var(--dsw-alias-bg-layer-3)); }
|
|
263
|
-
.mcviseron-session-end-option { transition: background 120ms ease; }
|
|
264
|
-
.mcviseron-session-end-option:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, var(--dsw-alias-bg-layer-3)); }
|
|
265
|
-
`}</style>
|
|
266
263
|
<span style={labelStyle} title={t('sessionEnd.hint')}>
|
|
267
264
|
<span>{t('sessionEnd.label')}</span>
|
|
268
|
-
<
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}}
|
|
280
|
-
disabled={busy}
|
|
281
|
-
onClick={toggleMenu}
|
|
282
|
-
>
|
|
283
|
-
<span>{t(
|
|
284
|
-
state.mode === 'off'
|
|
285
|
-
? 'sessionEnd.off'
|
|
286
|
-
: state.mode === 'restart'
|
|
287
|
-
? 'sessionEnd.restart'
|
|
288
|
-
: state.mode === 'close'
|
|
289
|
-
? 'sessionEnd.close'
|
|
290
|
-
: 'sessionEnd.shutdown',
|
|
291
|
-
)}</span>
|
|
292
|
-
<span aria-hidden style={{ fontSize: 10, opacity: 0.75 }}>{open ? '▴' : '▾'}</span>
|
|
293
|
-
</button>
|
|
294
|
-
{open && (
|
|
295
|
-
<div
|
|
296
|
-
ref={menuRef}
|
|
297
|
-
role="listbox"
|
|
298
|
-
aria-label={t('sessionEnd.label')}
|
|
299
|
-
style={{ ...menuStyle, left: menu.left, bottom: menu.bottom, minWidth: menu.minWidth }}
|
|
300
|
-
>
|
|
301
|
-
{([
|
|
302
|
-
['off', 'sessionEnd.off', false],
|
|
303
|
-
['restart', 'sessionEnd.restart', !state.available.restart],
|
|
304
|
-
['close', 'sessionEnd.close', !state.available.close],
|
|
305
|
-
['shutdown', 'sessionEnd.shutdown', !state.available.shutdown],
|
|
306
|
-
] as const).map(([value, label, disabled]) => (
|
|
307
|
-
<button
|
|
308
|
-
key={value}
|
|
309
|
-
type="button"
|
|
310
|
-
role="option"
|
|
311
|
-
aria-selected={state.mode === value}
|
|
312
|
-
disabled={disabled}
|
|
313
|
-
className="mcviseron-session-end-option"
|
|
314
|
-
style={{
|
|
315
|
-
...menuOptionStyle,
|
|
316
|
-
color: state.mode === value ? 'var(--dsw-alias-brand-primary)' : menuOptionStyle.color,
|
|
317
|
-
fontWeight: state.mode === value ? 600 : 400,
|
|
318
|
-
opacity: disabled ? 0.45 : 1,
|
|
319
|
-
cursor: disabled ? 'default' : 'pointer',
|
|
320
|
-
}}
|
|
321
|
-
onClick={() => { if (!disabled) change(value) }}
|
|
322
|
-
>
|
|
323
|
-
<span>{t(label)}</span>
|
|
324
|
-
{state.mode === value ? <span aria-hidden>✓</span> : null}
|
|
325
|
-
</button>
|
|
326
|
-
))}
|
|
327
|
-
</div>
|
|
328
|
-
)}
|
|
265
|
+
<Menu
|
|
266
|
+
open={open}
|
|
267
|
+
anchor={anchor}
|
|
268
|
+
items={items}
|
|
269
|
+
selectedId={state.mode}
|
|
270
|
+
onSelect={id => { change(id as Mode) }}
|
|
271
|
+
onClose={() => { setOpen(false) }}
|
|
272
|
+
align="end"
|
|
273
|
+
side="top"
|
|
274
|
+
portal
|
|
275
|
+
/>
|
|
329
276
|
</span>
|
|
330
277
|
</span>
|
|
331
278
|
)
|
package/src/client/locales.ts
CHANGED
|
@@ -25,7 +25,7 @@ export const zh = {
|
|
|
25
25
|
'restart.confirm': '确定要重启 DeepSeek Harness 吗?正在运行的任务会被中断。',
|
|
26
26
|
'sessionEnd.label': '会话后重启',
|
|
27
27
|
'sessionEnd.hint': '本轮最终回复完整显示后执行;AI 需要重启插件时可自动设置。',
|
|
28
|
-
'sessionEnd.off': '
|
|
28
|
+
'sessionEnd.off': '不做操作',
|
|
29
29
|
'sessionEnd.restart': '重启 DSH',
|
|
30
30
|
'sessionEnd.close': '关闭 DSH',
|
|
31
31
|
'sessionEnd.shutdown': '关闭电脑',
|
|
@@ -149,7 +149,7 @@ export const en = {
|
|
|
149
149
|
'restart.confirm': 'Restart DeepSeek Harness now? Running tasks will be interrupted.',
|
|
150
150
|
'sessionEnd.label': 'Restart after session',
|
|
151
151
|
'sessionEnd.hint': 'Runs after the final reply is fully displayed; the AI can arm it when a plugin change needs a restart.',
|
|
152
|
-
'sessionEnd.off': '
|
|
152
|
+
'sessionEnd.off': 'No action',
|
|
153
153
|
'sessionEnd.restart': 'Restart DSH',
|
|
154
154
|
'sessionEnd.close': 'Close DSH',
|
|
155
155
|
'sessionEnd.shutdown': 'Shut down PC',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare module '@deepseek-ai/dsh-client-ui-primitives' {
|
|
2
|
-
import type { ReactElement } from 'react'
|
|
2
|
+
import type { CSSProperties, ReactElement, ReactNode } from 'react'
|
|
3
3
|
|
|
4
4
|
export interface SwitchProps {
|
|
5
5
|
checked: boolean
|
|
@@ -12,4 +12,40 @@ declare module '@deepseek-ai/dsh-client-ui-primitives' {
|
|
|
12
12
|
|
|
13
13
|
/** The official settings switch supplied by the DSH client shell. */
|
|
14
14
|
export function Switch(props: SwitchProps): ReactElement | null
|
|
15
|
+
|
|
16
|
+
export interface IconProps {
|
|
17
|
+
className?: string
|
|
18
|
+
style?: CSSProperties
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function IconChevronDownOutlineRegular(props?: IconProps): ReactElement
|
|
22
|
+
export function IconClockOutlineRegular(props?: IconProps): ReactElement
|
|
23
|
+
export function IconCloseOutlineRegular(props?: IconProps): ReactElement
|
|
24
|
+
export function IconCloseCircleFillRegular(props?: IconProps): ReactElement
|
|
25
|
+
export function IconRefreshOutlineRegular(props?: IconProps): ReactElement
|
|
26
|
+
export function IconStopFillRegular(props?: IconProps): ReactElement
|
|
27
|
+
|
|
28
|
+
export interface MenuItem {
|
|
29
|
+
id: string
|
|
30
|
+
label: ReactNode
|
|
31
|
+
disabled?: boolean
|
|
32
|
+
icon?: ReactNode
|
|
33
|
+
danger?: boolean
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface MenuProps {
|
|
37
|
+
open: boolean
|
|
38
|
+
anchor: ReactNode
|
|
39
|
+
items?: readonly MenuItem[]
|
|
40
|
+
selectedId?: string
|
|
41
|
+
onSelect?: (id: string) => void
|
|
42
|
+
onClose: () => void
|
|
43
|
+
align?: 'start' | 'end'
|
|
44
|
+
side?: 'bottom' | 'top' | 'right'
|
|
45
|
+
portal?: boolean
|
|
46
|
+
selection?: 'check' | 'fill'
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The official anchored dropdown menu and its keyboard/portal behavior. */
|
|
50
|
+
export function Menu(props: MenuProps): ReactElement
|
|
15
51
|
}
|
package/src/session-end/index.ts
CHANGED
|
@@ -31,6 +31,15 @@ export const DEFAULT_SESSION_END_CONFIG = {
|
|
|
31
31
|
].join('\n'),
|
|
32
32
|
} as const
|
|
33
33
|
|
|
34
|
+
/** Model-facing policy: when the session-end action is appropriate. */
|
|
35
|
+
const SESSION_END_GUIDANCE = [
|
|
36
|
+
'[session-end action] set_session_end_action arms one one-shot action after this turn.',
|
|
37
|
+
'Use it only when this turn changed DSH plugin host/client source, build output (lib/), cordis.patch.yml, profile loader entries, or a setting that is read only at startup, and the change has been built and verified.',
|
|
38
|
+
'Do not arm it for ordinary project files, docs/README, tests-only changes, live-applied settings, EDA/MATLAB/STM32 project work, or todo-only changes. Do not arm it when nothing was built, installed, or loaded.',
|
|
39
|
+
'Arm it during the turn, after verification and before the final answer. It runs after the final reply is fully displayed and waits for all running agent turns and background jobs.',
|
|
40
|
+
'Use close only when the user explicitly asks to close DSH. Shutdown is user-only. If you are unsure whether a restart is required, ask the user instead of arming.',
|
|
41
|
+
].join(' ')
|
|
42
|
+
|
|
34
43
|
export const Config = z.object({
|
|
35
44
|
enabled: z.boolean().default(DEFAULT_SESSION_END_CONFIG.enabled).volatile(),
|
|
36
45
|
graceMs: z.number().min(0).max(15000).default(DEFAULT_SESSION_END_CONFIG.graceMs).volatile(),
|
|
@@ -322,12 +331,16 @@ export function createSessionEndController(deps: SessionEndDeps = {}): SessionEn
|
|
|
322
331
|
return view(sessionId)
|
|
323
332
|
},
|
|
324
333
|
onTurnStart(sessionId) {
|
|
325
|
-
// A new turn
|
|
326
|
-
//
|
|
327
|
-
//
|
|
328
|
-
|
|
334
|
+
// A new turn cancels only the pending timer; it keeps the armed entry so
|
|
335
|
+
// the action is rescheduled at this turn's end instead of being silently
|
|
336
|
+
// lost when the user follows up during the grace period.
|
|
337
|
+
const entry = entries.get(sessionId)
|
|
338
|
+
if (entry !== undefined) {
|
|
339
|
+
entry.waiting = false
|
|
340
|
+
entry.runningAgents = 0
|
|
341
|
+
entry.runningJobs = 0
|
|
342
|
+
}
|
|
329
343
|
cancel(sessionId)
|
|
330
|
-
entries.delete(sessionId)
|
|
331
344
|
},
|
|
332
345
|
onTurnEnd(sessionId) {
|
|
333
346
|
const entry = entries.get(sessionId)
|
|
@@ -371,6 +384,7 @@ function bodySessionId(body: unknown): string | undefined {
|
|
|
371
384
|
|
|
372
385
|
/** Build the state and set routes for the composer control. */
|
|
373
386
|
export function makeSessionEndRoutes(controller: SessionEndController): WebRoute[] {
|
|
387
|
+
const seen = new Set<string>()
|
|
374
388
|
const state: WebRoute = {
|
|
375
389
|
kind: 'exact',
|
|
376
390
|
path: SESSION_END_API.state,
|
|
@@ -380,6 +394,10 @@ export function makeSessionEndRoutes(controller: SessionEndController): WebRoute
|
|
|
380
394
|
if (!isLoopbackRequest(req)) return json(res, 403, { ok: false, error: 'forbidden' })
|
|
381
395
|
const sessionId = bodySessionId(await readJsonBody(req))
|
|
382
396
|
if (sessionId === undefined) return json(res, 400, { ok: false, error: 'sessionId-required' })
|
|
397
|
+
if (!seen.has(sessionId)) {
|
|
398
|
+
seen.add(sessionId)
|
|
399
|
+
defaultLog('state request: session=' + sessionId)
|
|
400
|
+
}
|
|
383
401
|
json(res, 200, { ok: true, ...controller.get(sessionId) })
|
|
384
402
|
} catch (error) {
|
|
385
403
|
json(res, 500, { ok: false, error: error instanceof Error ? error.message : String(error) })
|
|
@@ -424,6 +442,30 @@ function serviceOf(ctx: Context, name: string): unknown {
|
|
|
424
442
|
}
|
|
425
443
|
}
|
|
426
444
|
|
|
445
|
+
function installGuidance(ctx: Context): void {
|
|
446
|
+
const inject = (ctx as unknown as { inject?: (deps: string[], callback: (scope: Context) => void) => unknown }).inject
|
|
447
|
+
if (typeof inject !== 'function') return
|
|
448
|
+
try {
|
|
449
|
+
inject.call(ctx, ['systemPrompt'], (scope) => {
|
|
450
|
+
const systemPrompt = serviceOf(scope, 'systemPrompt') as {
|
|
451
|
+
section?: (section: { name: string; order: number; text: string }) => unknown
|
|
452
|
+
} | undefined
|
|
453
|
+
if (systemPrompt === undefined || typeof systemPrompt.section !== 'function') return
|
|
454
|
+
try {
|
|
455
|
+
systemPrompt.section({
|
|
456
|
+
name: 'plugin:mcviseron-session-end',
|
|
457
|
+
order: 230,
|
|
458
|
+
text: SESSION_END_GUIDANCE,
|
|
459
|
+
})
|
|
460
|
+
} catch (error) {
|
|
461
|
+
defaultLog('guidance registration failed: ' + (error instanceof Error ? error.message : String(error)))
|
|
462
|
+
}
|
|
463
|
+
})
|
|
464
|
+
} catch (error) {
|
|
465
|
+
defaultLog('guidance injection failed: ' + (error instanceof Error ? error.message : String(error)))
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
427
469
|
const emailed = new Map<string, number>()
|
|
428
470
|
|
|
429
471
|
function installAgentTool(ctx: Context, controller: SessionEndController, options: Required<SessionEndOptions>, log: (message: string) => void): void {
|
|
@@ -439,9 +481,10 @@ function installAgentTool(ctx: Context, controller: SessionEndController, option
|
|
|
439
481
|
name: 'set_session_end_action',
|
|
440
482
|
description: [
|
|
441
483
|
'Set the action DSH performs after the current turn has fully finished.',
|
|
442
|
-
'
|
|
443
|
-
'
|
|
444
|
-
'
|
|
484
|
+
'WHEN TO USE: this turn changed DSH plugin host/client source, build output (lib/), cordis.patch.yml, profile loader entries, or a setting read only at startup, and the change is built and verified.',
|
|
485
|
+
'WHEN NOT TO USE: ordinary project files, docs/README, tests-only changes, live-applied settings, EDA/MATLAB/STM32 work, todo-only changes, or when nothing was built/installed/loaded.',
|
|
486
|
+
'Arm restart during the turn, after verification and before the final answer. It runs after the final reply is fully displayed and waits for all running agent turns and background jobs.',
|
|
487
|
+
'Use close only when the user explicitly asks to close DSH. Shutdown is user-only. If unsure whether a restart is required, ask the user instead of arming.',
|
|
445
488
|
].join(' '),
|
|
446
489
|
parameters: {
|
|
447
490
|
action: {
|
|
@@ -459,11 +502,12 @@ function installAgentTool(ctx: Context, controller: SessionEndController, option
|
|
|
459
502
|
schema: {
|
|
460
503
|
type: 'object',
|
|
461
504
|
additionalProperties: false,
|
|
505
|
+
required: ['ok', 'action', 'requestedBy', 'message'],
|
|
462
506
|
properties: {
|
|
463
|
-
ok: { type: 'boolean'
|
|
464
|
-
action: { type: 'string',
|
|
465
|
-
requestedBy: { type: 'string',
|
|
466
|
-
message: { type: 'string'
|
|
507
|
+
ok: { type: 'boolean' },
|
|
508
|
+
action: { type: 'string', enum: ['off', 'restart', 'close'] },
|
|
509
|
+
requestedBy: { type: 'string', enum: ['ai'] },
|
|
510
|
+
message: { type: 'string' },
|
|
467
511
|
},
|
|
468
512
|
},
|
|
469
513
|
render: (_args: unknown, value: { message?: unknown }) => [{
|
|
@@ -590,13 +634,24 @@ export function apply(ctx: Context, config?: SessionEndConfig): void {
|
|
|
590
634
|
}, 'mcviseron-session-end: routes')
|
|
591
635
|
|
|
592
636
|
if (options.enabled) {
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
637
|
+
const root = (ctx as unknown as { root?: unknown }).root
|
|
638
|
+
const eventBus = (root ?? ctx) as {
|
|
639
|
+
on?: (event: string, handler: (session: unknown, event: { type?: unknown }) => void) => unknown
|
|
640
|
+
}
|
|
641
|
+
if (typeof eventBus.on === 'function') {
|
|
642
|
+
ctx.effect(() => {
|
|
643
|
+
const dispose = eventBus.on?.('session/event', (session, event) => {
|
|
644
|
+
const sessionId = sessionIdOf(session)
|
|
645
|
+
if (sessionId === '') return
|
|
646
|
+
if (event?.type === 'turn/start') controller.onTurnStart(sessionId)
|
|
647
|
+
else if (event?.type === 'turn/end') controller.onTurnEnd(sessionId)
|
|
648
|
+
})
|
|
649
|
+
return () => {
|
|
650
|
+
if (typeof dispose === 'function') dispose()
|
|
651
|
+
}
|
|
652
|
+
}, 'mcviseron-session-end: session events')
|
|
653
|
+
}
|
|
654
|
+
installGuidance(ctx)
|
|
600
655
|
installAgentTool(ctx, controller, options, log)
|
|
601
656
|
}
|
|
602
657
|
|